Completed
Push — release-2.1 ( 978f21...eb09a1 )
by Colin
07:52
created
Sources/ManageBoards.php 1 patch
Braces   +147 added lines, -114 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main dispatcher; doesn't do anything, just delegates.
@@ -92,18 +93,19 @@  discard block
 block discarded – undo
92 93
 		checkSession('get');
93 94
 		validateToken('admin-bm-' . (int) $_REQUEST['src_board'], 'request');
94 95
 
95
-		if ($_REQUEST['move_to'] === 'top')
96
-			$boardOptions = array(
96
+		if ($_REQUEST['move_to'] === 'top') {
97
+					$boardOptions = array(
97 98
 				'move_to' => $_REQUEST['move_to'],
98 99
 				'target_category' => (int) $_REQUEST['target_cat'],
99 100
 				'move_first_child' => true,
100 101
 			);
101
-		else
102
-			$boardOptions = array(
102
+		} else {
103
+					$boardOptions = array(
103 104
 				'move_to' => $_REQUEST['move_to'],
104 105
 				'target_board' => (int) $_REQUEST['target_board'],
105 106
 				'move_first_child' => true,
106 107
 			);
108
+		}
107 109
 		modifyBoard((int) $_REQUEST['src_board'], $boardOptions);
108 110
 	}
109 111
 
@@ -148,15 +150,16 @@  discard block
 block discarded – undo
148 150
 			$security = $context['session_var'] . '=' . $context['session_id'] . ';' . $context['admin-bm-' . $context['move_board'] . '_token_var'] . '=' . $context['admin-bm-' . $context['move_board'] . '_token'];
149 151
 			foreach ($boardList[$catid] as $boardid)
150 152
 			{
151
-				if (!isset($context['categories'][$catid]['move_link']))
152
-					$context['categories'][$catid]['move_link'] = array(
153
+				if (!isset($context['categories'][$catid]['move_link'])) {
154
+									$context['categories'][$catid]['move_link'] = array(
153 155
 						'child_level' => 0,
154 156
 						'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'',
155 157
 						'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_board=' . $boardid . ';move_to=before;' . $security,
156 158
 					);
159
+				}
157 160
 
158
-				if (!$context['categories'][$catid]['boards'][$boardid]['move'])
159
-				$context['categories'][$catid]['boards'][$boardid]['move_links'] = array(
161
+				if (!$context['categories'][$catid]['boards'][$boardid]['move']) {
162
+								$context['categories'][$catid]['boards'][$boardid]['move_links'] = array(
160 163
 					array(
161 164
 						'child_level' => $boards[$boardid]['level'],
162 165
 						'label' => $txt['mboards_order_after'] . '\'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'',
@@ -170,34 +173,39 @@  discard block
 block discarded – undo
170 173
 						'class' => 'here',
171 174
 					),
172 175
 				);
176
+				}
173 177
 
174 178
 				$difference = $boards[$boardid]['level'] - $prev_child_level;
175
-				if ($difference == 1)
176
-					array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null);
177
-				elseif ($difference < 0)
179
+				if ($difference == 1) {
180
+									array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null);
181
+				} elseif ($difference < 0)
178 182
 				{
179
-					if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links']))
180
-						$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array();
181
-					for ($i = 0; $i < -$difference; $i++)
182
-						if (($temp = array_pop($stack)) != null)
183
+					if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) {
184
+											$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array();
185
+					}
186
+					for ($i = 0; $i < -$difference; $i++) {
187
+											if (($temp = array_pop($stack)) != null)
183 188
 							array_unshift($context['categories'][$catid]['boards'][$prev_board]['move_links'], $temp);
189
+					}
184 190
 				}
185 191
 
186 192
 				$prev_board = $boardid;
187 193
 				$prev_child_level = $boards[$boardid]['level'];
188 194
 
189 195
 			}
190
-			if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']))
191
-				$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']);
192
-			elseif (!empty($stack))
193
-				$context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack;
196
+			if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) {
197
+							$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']);
198
+			} elseif (!empty($stack)) {
199
+							$context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack;
200
+			}
194 201
 
195
-			if (empty($boardList[$catid]))
196
-				$context['categories'][$catid]['move_link'] = array(
202
+			if (empty($boardList[$catid])) {
203
+							$context['categories'][$catid]['move_link'] = array(
197 204
 					'child_level' => 0,
198 205
 					'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($tree['node']['name']) . '\'',
199 206
 					'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_cat=' . $catid . ';move_to=top;' . $security,
200 207
 				);
208
+			}
201 209
 		}
202 210
 	}
203 211
 
@@ -253,9 +261,9 @@  discard block
 block discarded – undo
253 261
 		);
254 262
 	}
255 263
 	// Category doesn't exist, man... sorry.
256
-	elseif (!isset($cat_tree[$_REQUEST['cat']]))
257
-		redirectexit('action=admin;area=manageboards');
258
-	else
264
+	elseif (!isset($cat_tree[$_REQUEST['cat']])) {
265
+			redirectexit('action=admin;area=manageboards');
266
+	} else
259 267
 	{
260 268
 		$context['category'] = array(
261 269
 			'id' => $_REQUEST['cat'],
@@ -267,30 +275,31 @@  discard block
 block discarded – undo
267 275
 			'is_empty' => empty($cat_tree[$_REQUEST['cat']]['children'])
268 276
 		);
269 277
 
270
-		foreach ($boardList[$_REQUEST['cat']] as $child_board)
271
-			$context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name'];
278
+		foreach ($boardList[$_REQUEST['cat']] as $child_board) {
279
+					$context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name'];
280
+		}
272 281
 	}
273 282
 
274 283
 	$prevCat = 0;
275 284
 	foreach ($cat_tree as $catid => $tree)
276 285
 	{
277
-		if ($catid == $_REQUEST['cat'] && $prevCat > 0)
278
-			$context['category_order'][$prevCat]['selected'] = true;
279
-		elseif ($catid != $_REQUEST['cat'])
280
-			$context['category_order'][$catid] = array(
286
+		if ($catid == $_REQUEST['cat'] && $prevCat > 0) {
287
+					$context['category_order'][$prevCat]['selected'] = true;
288
+		} elseif ($catid != $_REQUEST['cat']) {
289
+					$context['category_order'][$catid] = array(
281 290
 				'id' => $catid,
282 291
 				'name' => $txt['mboards_order_after'] . $tree['node']['name'],
283 292
 				'selected' => false,
284 293
 				'true_name' => $tree['node']['name']
285 294
 			);
295
+		}
286 296
 		$prevCat = $catid;
287 297
 	}
288 298
 	if (!isset($_REQUEST['delete']))
289 299
 	{
290 300
 		$context['sub_template'] = 'modify_category';
291 301
 		$context['page_title'] = $_REQUEST['sa'] == 'newcat' ? $txt['mboards_new_cat_name'] : $txt['catEdit'];
292
-	}
293
-	else
302
+	} else
294 303
 	{
295 304
 		$context['sub_template'] = 'confirm_category_delete';
296 305
 		$context['page_title'] = $txt['mboards_delete_cat'];
@@ -327,8 +336,9 @@  discard block
 block discarded – undo
327 336
 	{
328 337
 		$catOptions = array();
329 338
 
330
-		if (isset($_POST['cat_order']))
331
-			$catOptions['move_after'] = (int) $_POST['cat_order'];
339
+		if (isset($_POST['cat_order'])) {
340
+					$catOptions['move_after'] = (int) $_POST['cat_order'];
341
+		}
332 342
 
333 343
 		// Change "This & That" to "This &amp; That" but don't change "&cent" to "&amp;cent;"...
334 344
 		$catOptions['cat_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['cat_name']), false, '', $context['description_allowed_tags']);
@@ -336,10 +346,11 @@  discard block
 block discarded – undo
336 346
 
337 347
 		$catOptions['is_collapsible'] = isset($_POST['collapse']);
338 348
 
339
-		if (isset($_POST['add']))
340
-			createCategory($catOptions);
341
-		else
342
-			modifyCategory($_POST['cat'], $catOptions);
349
+		if (isset($_POST['add'])) {
350
+					createCategory($catOptions);
351
+		} else {
352
+					modifyCategory($_POST['cat'], $catOptions);
353
+		}
343 354
 	}
344 355
 	// If they want to delete - first give them confirmation.
345 356
 	elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['empty']))
@@ -353,13 +364,14 @@  discard block
 block discarded – undo
353 364
 		// First off - check if we are moving all the current boards first - before we start deleting!
354 365
 		if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1)
355 366
 		{
356
-			if (empty($_POST['cat_to']))
357
-				fatal_lang_error('mboards_delete_error');
367
+			if (empty($_POST['cat_to'])) {
368
+							fatal_lang_error('mboards_delete_error');
369
+			}
358 370
 
359 371
 			deleteCategories(array($_POST['cat']), (int) $_POST['cat_to']);
372
+		} else {
373
+					deleteCategories(array($_POST['cat']));
360 374
 		}
361
-		else
362
-			deleteCategories(array($_POST['cat']));
363 375
 	}
364 376
 
365 377
 	redirectexit('action=admin;area=manageboards');
@@ -404,8 +416,9 @@  discard block
 block discarded – undo
404 416
 	if ($_REQUEST['sa'] == 'newboard')
405 417
 	{
406 418
 		// Category doesn't exist, man... sorry.
407
-		if (empty($_REQUEST['cat']))
408
-			redirectexit('action=admin;area=manageboards');
419
+		if (empty($_REQUEST['cat'])) {
420
+					redirectexit('action=admin;area=manageboards');
421
+		}
409 422
 
410 423
 		// Some things that need to be setup for a new board.
411 424
 		$curBoard = array(
@@ -429,8 +442,7 @@  discard block
 block discarded – undo
429 442
 			'category' => (int) $_REQUEST['cat'],
430 443
 			'no_children' => true,
431 444
 		);
432
-	}
433
-	else
445
+	} else
434 446
 	{
435 447
 		// Just some easy shortcuts.
436 448
 		$curBoard = &$boards[$_REQUEST['boardid']];
@@ -478,8 +490,9 @@  discard block
 block discarded – undo
478 490
 	);
479 491
 	while ($row = $smcFunc['db_fetch_assoc']($request))
480 492
 	{
481
-		if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1)
482
-			$curBoard['member_groups'][] = $row['id_group'];
493
+		if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) {
494
+					$curBoard['member_groups'][] = $row['id_group'];
495
+		}
483 496
 
484 497
 		$context['groups'][(int) $row['id_group']] = array(
485 498
 			'id' => $row['id_group'],
@@ -492,8 +505,9 @@  discard block
 block discarded – undo
492 505
 	$smcFunc['db_free_result']($request);
493 506
 
494 507
 	// Category doesn't exist, man... sorry.
495
-	if (!isset($boardList[$curBoard['category']]))
496
-		redirectexit('action=admin;area=manageboards');
508
+	if (!isset($boardList[$curBoard['category']])) {
509
+			redirectexit('action=admin;area=manageboards');
510
+	}
497 511
 
498 512
 	foreach ($boardList[$curBoard['category']] as $boardid)
499 513
 	{
@@ -507,8 +521,7 @@  discard block
 block discarded – undo
507 521
 				'is_child' => false,
508 522
 				'selected' => true
509 523
 			);
510
-		}
511
-		else
524
+		} else
512 525
 		{
513 526
 			$context['board_order'][] = array(
514 527
 				'id' => $boardid,
@@ -525,19 +538,21 @@  discard block
 block discarded – undo
525 538
 		$context['can_move_children'] = false;
526 539
 		$context['children'] = $boards[$_REQUEST['boardid']]['tree']['children'];
527 540
 
528
-		foreach ($context['board_order'] as $lBoard)
529
-			if ($lBoard['is_child'] == false && $lBoard['selected'] == false)
541
+		foreach ($context['board_order'] as $lBoard) {
542
+					if ($lBoard['is_child'] == false && $lBoard['selected'] == false)
530 543
 				$context['can_move_children'] = true;
544
+		}
531 545
 	}
532 546
 
533 547
 	// Get other available categories.
534 548
 	$context['categories'] = array();
535
-	foreach ($cat_tree as $catID => $tree)
536
-		$context['categories'][] = array(
549
+	foreach ($cat_tree as $catID => $tree) {
550
+			$context['categories'][] = array(
537 551
 			'id' => $catID == $curBoard['category'] ? 0 : $catID,
538 552
 			'name' => $tree['node']['name'],
539 553
 			'selected' => $catID == $curBoard['category']
540 554
 		);
555
+	}
541 556
 
542 557
 	$request = $smcFunc['db_query']('', '
543 558
 		SELECT mem.id_member, mem.real_name
@@ -549,14 +564,16 @@  discard block
 block discarded – undo
549 564
 		)
550 565
 	);
551 566
 	$context['board']['moderators'] = array();
552
-	while ($row = $smcFunc['db_fetch_assoc']($request))
553
-		$context['board']['moderators'][$row['id_member']] = $row['real_name'];
567
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
568
+			$context['board']['moderators'][$row['id_member']] = $row['real_name'];
569
+	}
554 570
 	$smcFunc['db_free_result']($request);
555 571
 
556 572
 	$context['board']['moderator_list'] = empty($context['board']['moderators']) ? '' : '&quot;' . implode('&quot;, &quot;', $context['board']['moderators']) . '&quot;';
557 573
 
558
-	if (!empty($context['board']['moderators']))
559
-		list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1);
574
+	if (!empty($context['board']['moderators'])) {
575
+			list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1);
576
+	}
560 577
 
561 578
 	// Get all the groups assigned as moderators
562 579
 	$request = $smcFunc['db_query']('', '
@@ -568,14 +585,16 @@  discard block
 block discarded – undo
568 585
 		)
569 586
 	);
570 587
 	$context['board']['moderator_groups'] = array();
571
-	while ($row = $smcFunc['db_fetch_assoc']($request))
572
-		$context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name'];
588
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
589
+			$context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name'];
590
+	}
573 591
 	$smcFunc['db_free_result']($request);
574 592
 
575 593
 	$context['board']['moderator_groups_list'] = empty($context['board']['moderator_groups']) ? '' : '&quot;' . implode('&quot;, &qout;', $context['board']['moderator_groups']) . '&quot;';
576 594
 
577
-	if (!empty($context['board']['moderator_groups']))
578
-		list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1);
595
+	if (!empty($context['board']['moderator_groups'])) {
596
+			list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1);
597
+	}
579 598
 
580 599
 	// Get all the themes...
581 600
 	$request = $smcFunc['db_query']('', '
@@ -587,8 +606,9 @@  discard block
 block discarded – undo
587 606
 		)
588 607
 	);
589 608
 	$context['themes'] = array();
590
-	while ($row = $smcFunc['db_fetch_assoc']($request))
591
-		$context['themes'][] = $row;
609
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
610
+			$context['themes'][] = $row;
611
+	}
592 612
 	$smcFunc['db_free_result']($request);
593 613
 
594 614
 	if (!isset($_REQUEST['delete']))
@@ -596,8 +616,7 @@  discard block
 block discarded – undo
596 616
 		$context['sub_template'] = 'modify_board';
597 617
 		$context['page_title'] = $txt['boardsEdit'];
598 618
 		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
599
-	}
600
-	else
619
+	} else
601 620
 	{
602 621
 		$context['sub_template'] = 'confirm_board_delete';
603 622
 		$context['page_title'] = $txt['mboards_delete_board'];
@@ -641,8 +660,9 @@  discard block
 block discarded – undo
641 660
 		// Change the boardorder of this board?
642 661
 		elseif (!empty($_POST['placement']) && !empty($_POST['board_order']))
643 662
 		{
644
-			if (!in_array($_POST['placement'], array('before', 'after', 'child')))
645
-				fatal_lang_error('mangled_post', false);
663
+			if (!in_array($_POST['placement'], array('before', 'after', 'child'))) {
664
+							fatal_lang_error('mangled_post', false);
665
+			}
646 666
 
647 667
 			$boardOptions['move_to'] = $_POST['placement'];
648 668
 			$boardOptions['target_board'] = (int) $_POST['board_order'];
@@ -655,13 +675,14 @@  discard block
 block discarded – undo
655 675
 		$boardOptions['access_groups'] = array();
656 676
 		$boardOptions['deny_groups'] = array();
657 677
 
658
-		if (!empty($_POST['groups']))
659
-			foreach ($_POST['groups'] as $group => $action)
678
+		if (!empty($_POST['groups'])) {
679
+					foreach ($_POST['groups'] as $group => $action)
660 680
 			{
661 681
 				if ($action == 'allow')
662 682
 					$boardOptions['access_groups'][] = (int) $group;
663
-				elseif ($action == 'deny')
664
-					$boardOptions['deny_groups'][] = (int) $group;
683
+		} elseif ($action == 'deny') {
684
+									$boardOptions['deny_groups'][] = (int) $group;
685
+				}
665 686
 			}
666 687
 
667 688
 		// People with manage-boards are special.
@@ -673,8 +694,9 @@  discard block
 block discarded – undo
673 694
 		// Secondly, make sure those with super cow powers (like apt-get, or in this case manage boards) are upgraded.
674 695
 		$boardOptions['access_groups'] = array_unique(array_merge($boardOptions['access_groups'], $board_managers));
675 696
 
676
-		if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255)
677
-			fatal_lang_error('too_many_groups', false);
697
+		if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) {
698
+					fatal_lang_error('too_many_groups', false);
699
+		}
678 700
 
679 701
 		// Do not allow HTML tags. Parse the string.
680 702
 		$boardOptions['board_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['board_name']), false, '', $context['description_allowed_tags']);
@@ -685,8 +707,9 @@  discard block
 block discarded – undo
685 707
 		if (isset($_POST['moderator_list']) && is_array($_POST['moderator_list']))
686 708
 		{
687 709
 			$moderators = array();
688
-			foreach ($_POST['moderator_list'] as $moderator)
689
-				$moderators[(int) $moderator] = (int) $moderator;
710
+			foreach ($_POST['moderator_list'] as $moderator) {
711
+							$moderators[(int) $moderator] = (int) $moderator;
712
+			}
690 713
 			$boardOptions['moderators'] = $moderators;
691 714
 		}
692 715
 
@@ -695,8 +718,9 @@  discard block
 block discarded – undo
695 718
 		if (isset($_POST['moderator_group_list']) && is_array($_POST['moderator_group_list']))
696 719
 		{
697 720
 			$moderator_groups = array();
698
-			foreach ($_POST['moderator_group_list'] as $moderator_group)
699
-				$moderator_groups[(int) $moderator_group] = (int) $moderator_group;
721
+			foreach ($_POST['moderator_group_list'] as $moderator_group) {
722
+							$moderator_groups[(int) $moderator_group] = (int) $moderator_group;
723
+			}
700 724
 			$boardOptions['moderator_groups'] = $moderator_groups;
701 725
 		}
702 726
 
@@ -722,56 +746,62 @@  discard block
 block discarded – undo
722 746
 			$smcFunc['db_free_result']($request);
723 747
 
724 748
 			// If we're turning redirection on check the board doesn't have posts in it - if it does don't make it a redirection board.
725
-			if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts)
726
-				unset($boardOptions['redirect']);
749
+			if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) {
750
+							unset($boardOptions['redirect']);
751
+			}
727 752
 			// Reset the redirection count when switching on/off.
728
-			elseif (empty($boardOptions['redirect']) != empty($oldRedirect))
729
-				$boardOptions['num_posts'] = 0;
753
+			elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) {
754
+							$boardOptions['num_posts'] = 0;
755
+			}
730 756
 			// Resetting the count?
731
-			elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect']))
732
-				$boardOptions['num_posts'] = 0;
757
+			elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) {
758
+							$boardOptions['num_posts'] = 0;
759
+			}
733 760
 		}
734 761
 
735 762
 		// Create a new board...
736 763
 		if (isset($_POST['add']))
737 764
 		{
738 765
 			// New boards by default go to the bottom of the category.
739
-			if (empty($_POST['new_cat']))
740
-				$boardOptions['target_category'] = (int) $_POST['cur_cat'];
741
-			if (!isset($boardOptions['move_to']))
742
-				$boardOptions['move_to'] = 'bottom';
766
+			if (empty($_POST['new_cat'])) {
767
+							$boardOptions['target_category'] = (int) $_POST['cur_cat'];
768
+			}
769
+			if (!isset($boardOptions['move_to'])) {
770
+							$boardOptions['move_to'] = 'bottom';
771
+			}
743 772
 
744 773
 			createBoard($boardOptions);
745 774
 		}
746 775
 
747 776
 		// ...or update an existing board.
748
-		else
749
-			modifyBoard($_POST['boardid'], $boardOptions);
750
-	}
751
-	elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children']))
777
+		else {
778
+					modifyBoard($_POST['boardid'], $boardOptions);
779
+		}
780
+	} elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children']))
752 781
 	{
753 782
 		EditBoard();
754 783
 		return;
755
-	}
756
-	elseif (isset($_POST['delete']))
784
+	} elseif (isset($_POST['delete']))
757 785
 	{
758 786
 		// First off - check if we are moving all the current child boards first - before we start deleting!
759 787
 		if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1)
760 788
 		{
761
-			if (empty($_POST['board_to']))
762
-				fatal_lang_error('mboards_delete_board_error');
789
+			if (empty($_POST['board_to'])) {
790
+							fatal_lang_error('mboards_delete_board_error');
791
+			}
763 792
 
764 793
 			deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']);
794
+		} else {
795
+					deleteBoards(array($_POST['boardid']), 0);
765 796
 		}
766
-		else
767
-			deleteBoards(array($_POST['boardid']), 0);
768 797
 	}
769 798
 
770
-	if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions')
771
-		redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']);
772
-	else
773
-		redirectexit('action=admin;area=manageboards');
774
-}
799
+	if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') {
800
+			redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']);
801
+	} else {
802
+			redirectexit('action=admin;area=manageboards');
803
+	}
804
+	}
775 805
 
776 806
 /**
777 807
  * Used to retrieve data for modifying a board category
@@ -808,8 +838,9 @@  discard block
 block discarded – undo
808 838
 	$smcFunc['db_free_result']($request);
809 839
 
810 840
 	// This would probably never happen, but just to be sure.
811
-	if ($cat .= $allowed_sa[1])
812
-		die(str_replace(',', ' to', $cat));
841
+	if ($cat .= $allowed_sa[1]) {
842
+			die(str_replace(',', ' to', $cat));
843
+	}
813 844
 
814 845
 	redirectexit();
815 846
 }
@@ -835,8 +866,9 @@  discard block
 block discarded – undo
835 866
 			'empty_string' => '',
836 867
 		)
837 868
 	);
838
-	while ($row = $smcFunc['db_fetch_assoc']($request))
839
-		$recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name'];
869
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
870
+			$recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name'];
871
+	}
840 872
 	$smcFunc['db_free_result']($request);
841 873
 	
842 874
 	if (!empty($recycle_boards))
@@ -844,9 +876,9 @@  discard block
 block discarded – undo
844 876
 		require_once($sourcedir . '/Subs-Boards.php');
845 877
 		sortBoards($recycle_boards);
846 878
 		$recycle_boards = array('') + $recycle_boards;
879
+	} else {
880
+			$recycle_boards = array('');
847 881
 	}
848
-	else
849
-		$recycle_boards = array('');
850 882
 
851 883
 	// Here and the board settings...
852 884
 	$config_vars = array(
@@ -864,8 +896,9 @@  discard block
 block discarded – undo
864 896
 
865 897
 	call_integration_hook('integrate_modify_board_settings', array(&$config_vars));
866 898
 
867
-	if ($return_config)
868
-		return $config_vars;
899
+	if ($return_config) {
900
+			return $config_vars;
901
+	}
869 902
 
870 903
 	// Needed for the settings template.
871 904
 	require_once($sourcedir . '/ManageServer.php');
Please login to merge, or discard this patch.
Sources/Load.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -2259,9 +2259,9 @@  discard block
 block discarded – undo
2259 2259
  *
2260 2260
  * @uses the template_include() function to include the file.
2261 2261
  * @param string $template_name The name of the template to load
2262
- * @param array|string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load
2262
+ * @param string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load
2263 2263
  * @param bool $fatal If true, dies with an error message if the template cannot be found
2264
- * @return boolean Whether or not the template was loaded
2264
+ * @return boolean|null Whether or not the template was loaded
2265 2265
  */
2266 2266
 function loadTemplate($template_name, $style_sheets = array(), $fatal = true)
2267 2267
 {
@@ -2444,7 +2444,7 @@  discard block
 block discarded – undo
2444 2444
  * - all code added with this function is added to the same <style> tag so do make sure your css is valid!
2445 2445
  *
2446 2446
  * @param string $css Some css code
2447
- * @return void|bool Adds the CSS to the $context['css_header'] array or returns if no CSS is specified
2447
+ * @return false|null Adds the CSS to the $context['css_header'] array or returns if no CSS is specified
2448 2448
  */
2449 2449
 function addInlineCss($css)
2450 2450
 {
@@ -2558,7 +2558,7 @@  discard block
 block discarded – undo
2558 2558
  *
2559 2559
  * @param string $javascript Some JS code
2560 2560
  * @param bool $defer Whether the script should load in <head> or before the closing <html> tag
2561
- * @return void|bool Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified
2561
+ * @return false|null Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified
2562 2562
  */
2563 2563
 function addInlineJavaScript($javascript, $defer = false)
2564 2564
 {
@@ -2791,7 +2791,7 @@  discard block
 block discarded – undo
2791 2791
  * It will try to choose only utf8 or non-utf8 languages.
2792 2792
  *
2793 2793
  * @param bool $use_cache Whether or not to use the cache
2794
- * @return array An array of information about available languages
2794
+ * @return string An array of information about available languages
2795 2795
  */
2796 2796
 function getLanguages($use_cache = true)
2797 2797
 {
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1746,7 +1746,7 @@  discard block
 block discarded – undo
1746 1746
 		$id_theme = $modSettings['theme_guests'];
1747 1747
 
1748 1748
 	// We already load the basic stuff?
1749
-	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme )
1749
+	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme)
1750 1750
 	{
1751 1751
 		// Verify the id_theme... no foul play.
1752 1752
 		// Always allow the board specific theme, if they are overriding.
@@ -2018,7 +2018,7 @@  discard block
 block discarded – undo
2018 2018
 	if (!isset($context['javascript_vars']))
2019 2019
 		$context['javascript_vars'] = array();
2020 2020
 
2021
-	$context['login_url'] =  $scripturl . '?action=login2';
2021
+	$context['login_url'] = $scripturl . '?action=login2';
2022 2022
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
2023 2023
 	$context['session_var'] = $_SESSION['session_var'];
2024 2024
 	$context['session_id'] = $_SESSION['session_value'];
Please login to merge, or discard this patch.
Braces   +793 added lines, -599 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,28 +48,36 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65 73
 		// We excpiclity do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded.
66
-		if (!is_array($modSettings['attachmentUploadDir']))
67
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
74
+		if (!is_array($modSettings['attachmentUploadDir'])) {
75
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
76
+		}
68 77
 
69
-		if (!empty($cache_enable))
70
-			cache_put_data('modSettings', $modSettings, 90);
78
+		if (!empty($cache_enable)) {
79
+					cache_put_data('modSettings', $modSettings, 90);
80
+		}
71 81
 	}
72 82
 
73 83
 	$modSettings['cache_enable'] = $cache_enable;
@@ -87,8 +97,9 @@  discard block
 block discarded – undo
87 97
 		};
88 98
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
89 99
 	{
90
-		if (!$utf8 || $smcFunc['db_mb4'])
91
-			return $string;
100
+		if (!$utf8 || $smcFunc['db_mb4']) {
101
+					return $string;
102
+		}
92 103
 
93 104
 		$i = 0;
94 105
 		$len = strlen($string);
@@ -100,18 +111,15 @@  discard block
 block discarded – undo
100 111
 			{
101 112
 				$new_string .= $string[$i];
102 113
 				$i++;
103
-			}
104
-			elseif ($ord < 224)
114
+			} elseif ($ord < 224)
105 115
 			{
106 116
 				$new_string .= $string[$i] . $string[$i + 1];
107 117
 				$i += 2;
108
-			}
109
-			elseif ($ord < 240)
118
+			} elseif ($ord < 240)
110 119
 			{
111 120
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
112 121
 				$i += 3;
113
-			}
114
-			elseif ($ord < 248)
122
+			} elseif ($ord < 248)
115 123
 			{
116 124
 				// Magic happens.
117 125
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -155,8 +163,7 @@  discard block
 block discarded – undo
155 163
 			{
156 164
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
157 165
 				return is_int($result) ? $result + $offset : false;
158
-			}
159
-			else
166
+			} else
160 167
 			{
161 168
 				$needle_arr = preg_split('~(' . $ent_list . '|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
162 169
 				$needle_size = count($needle_arr);
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 				while ((int) $result === $result)
166 173
 				{
167 174
 					$offset += $result;
168
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
169
-						return $offset;
175
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
176
+											return $offset;
177
+					}
170 178
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
171 179
 				}
172 180
 				return false;
@@ -204,8 +212,9 @@  discard block
 block discarded – undo
204 212
 			$string = $ent_check($string);
205 213
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
206 214
 			$string = $matches[0];
207
-			while (strlen($string) > $length)
208
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
215
+			while (strlen($string) > $length) {
216
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
217
+			}
209 218
 			return $string;
210 219
 		},
211 220
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -215,8 +224,9 @@  discard block
 block discarded – undo
215 224
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
216 225
 		{
217 226
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
218
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
219
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
227
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
228
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
229
+			}
220 230
 			return implode('', $words);
221 231
 		} : 'ucwords',
222 232
 		'json_decode' => 'smf_json_decode',
@@ -224,16 +234,17 @@  discard block
 block discarded – undo
224 234
 	);
225 235
 
226 236
 	// Setting the timezone is a requirement for some functions.
227
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
228
-		date_default_timezone_set($modSettings['default_timezone']);
229
-	else
237
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
238
+			date_default_timezone_set($modSettings['default_timezone']);
239
+	} else
230 240
 	{
231 241
 		// Get PHP's default timezone, if set
232 242
 		$ini_tz = ini_get('date.timezone');
233
-		if (!empty($ini_tz))
234
-			$modSettings['default_timezone'] = $ini_tz;
235
-		else
236
-			$modSettings['default_timezone'] = '';
243
+		if (!empty($ini_tz)) {
244
+					$modSettings['default_timezone'] = $ini_tz;
245
+		} else {
246
+					$modSettings['default_timezone'] = '';
247
+		}
237 248
 
238 249
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
239 250
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -251,22 +262,26 @@  discard block
 block discarded – undo
251 262
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
252 263
 		{
253 264
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
254
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
255
-				$modSettings['load_average'] = (float) $matches[1];
256
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
257
-				$modSettings['load_average'] = (float) $matches[1];
258
-			else
259
-				unset($modSettings['load_average']);
265
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
266
+							$modSettings['load_average'] = (float) $matches[1];
267
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
268
+							$modSettings['load_average'] = (float) $matches[1];
269
+			} else {
270
+							unset($modSettings['load_average']);
271
+			}
260 272
 
261
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
262
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
273
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
274
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
275
+			}
263 276
 		}
264 277
 
265
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
266
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
278
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
279
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
280
+		}
267 281
 
268
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
269
-			display_loadavg_error();
282
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
283
+					display_loadavg_error();
284
+		}
270 285
 	}
271 286
 
272 287
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -287,8 +302,9 @@  discard block
 block discarded – undo
287 302
 	if (defined('SMF_INTEGRATION_SETTINGS'))
288 303
 	{
289 304
 		$integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true);
290
-		foreach ($integration_settings as $hook => $function)
291
-			add_integration_function($hook, $function, '', false);
305
+		foreach ($integration_settings as $hook => $function) {
306
+					add_integration_function($hook, $function, '', false);
307
+		}
292 308
 	}
293 309
 
294 310
 	// Any files to pre include?
@@ -298,8 +314,9 @@  discard block
 block discarded – undo
298 314
 		foreach ($pre_includes as $include)
299 315
 		{
300 316
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
301
-			if (file_exists($include))
302
-				require_once($include);
317
+			if (file_exists($include)) {
318
+							require_once($include);
319
+			}
303 320
 		}
304 321
 	}
305 322
 
@@ -392,9 +409,9 @@  discard block
 block discarded – undo
392 409
 				break;
393 410
 			}
394 411
 		}
412
+	} else {
413
+			$id_member = 0;
395 414
 	}
396
-	else
397
-		$id_member = 0;
398 415
 
399 416
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
400 417
 	{
@@ -402,8 +419,9 @@  discard block
 block discarded – undo
402 419
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
403 420
 
404 421
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
405
-		if (empty($cookie_data))
406
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
422
+		if (empty($cookie_data)) {
423
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
424
+		}
407 425
 
408 426
 		list($id_member, $password, $login_span, $cookie_domain, $cookie_path) = array_pad((array) $cookie_data, 5, '');
409 427
 
@@ -411,16 +429,17 @@  discard block
 block discarded – undo
411 429
 
412 430
 		// Make sure the cookie is set to the correct domain and path
413 431
 		require_once($sourcedir . '/Subs-Auth.php');
414
-		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])))
415
-			setLoginCookie((int) $login_span - time(), $id_member);
416
-	}
417
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
432
+		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) {
433
+					setLoginCookie((int) $login_span - time(), $id_member);
434
+		}
435
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
418 436
 	{
419 437
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
420 438
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename], true);
421 439
 
422
-		if (empty($cookie_data))
423
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
440
+		if (empty($cookie_data)) {
441
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
442
+		}
424 443
 
425 444
 		list($id_member, $password, $login_span) = array_pad((array) $cookie_data, 3, '');
426 445
 		$id_member = !empty($id_member) && strlen($password) == 128 && (int) $login_span > time() ? (int) $id_member : 0;
@@ -445,30 +464,34 @@  discard block
 block discarded – undo
445 464
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
446 465
 			$smcFunc['db_free_result']($request);
447 466
 
448
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
449
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
467
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
468
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
469
+			}
450 470
 
451
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
452
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
471
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
472
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
473
+			}
453 474
 		}
454 475
 
455 476
 		// Did we find 'im?  If not, junk it.
456 477
 		if (!empty($user_settings))
457 478
 		{
458 479
 			// As much as the password should be right, we can assume the integration set things up.
459
-			if (!empty($already_verified) && $already_verified === true)
460
-				$check = true;
480
+			if (!empty($already_verified) && $already_verified === true) {
481
+							$check = true;
482
+			}
461 483
 			// SHA-512 hash should be 128 characters long.
462
-			elseif (strlen($password) == 128)
463
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
464
-			else
465
-				$check = false;
484
+			elseif (strlen($password) == 128) {
485
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
486
+			} else {
487
+							$check = false;
488
+			}
466 489
 
467 490
 			// Wrong password or not activated - either way, you're going nowhere.
468 491
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
492
+		} else {
493
+					$id_member = 0;
469 494
 		}
470
-		else
471
-			$id_member = 0;
472 495
 
473 496
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
474 497
 		if (!$id_member)
@@ -497,8 +520,9 @@  discard block
 block discarded – undo
497 520
 
498 521
 					list ($tfamember, $tfasecret) = $tfa_data;
499 522
 
500
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
501
-						$tfasecret = null;
523
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
524
+											$tfasecret = null;
525
+					}
502 526
 				}
503 527
 
504 528
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -518,10 +542,12 @@  discard block
 block discarded – undo
518 542
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
519 543
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
520 544
 		{
521
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
545
+			if ($modSettings['tfa_mode'] == 2) {
546
+				//only do this if we are just forcing SOME membergroups
522 547
 			{
523 548
 				//Build an array of ALL user membergroups.
524 549
 				$full_groups = array($user_settings['id_group']);
550
+			}
525 551
 				if (!empty($user_settings['additional_groups']))
526 552
 				{
527 553
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -541,15 +567,17 @@  discard block
 block discarded – undo
541 567
 				);
542 568
 				$row = $smcFunc['db_fetch_assoc']($request);
543 569
 				$smcFunc['db_free_result']($request);
570
+			} else {
571
+							$row['total'] = 1;
544 572
 			}
545
-			else
546
-				$row['total'] = 1; //simplifies logics in the next "if"
573
+			//simplifies logics in the next "if"
547 574
 
548 575
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
549 576
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
550 577
 
551
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
552
-				redirectexit('action=profile;area=tfasetup;forced');
578
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
579
+							redirectexit('action=profile;area=tfasetup;forced');
580
+			}
553 581
 		}
554 582
 	}
555 583
 
@@ -586,33 +614,37 @@  discard block
 block discarded – undo
586 614
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
587 615
 				$user_settings['last_login'] = time();
588 616
 
589
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
590
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
617
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
618
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
619
+				}
591 620
 
592
-				if (!empty($modSettings['cache_enable']))
593
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
621
+				if (!empty($modSettings['cache_enable'])) {
622
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
623
+				}
594 624
 			}
625
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
626
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
595 627
 		}
596
-		elseif (empty($_SESSION['id_msg_last_visit']))
597
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
598 628
 
599 629
 		$username = $user_settings['member_name'];
600 630
 
601
-		if (empty($user_settings['additional_groups']))
602
-			$user_info = array(
631
+		if (empty($user_settings['additional_groups'])) {
632
+					$user_info = array(
603 633
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
604 634
 			);
605
-		else
606
-			$user_info = array(
635
+		} else {
636
+					$user_info = array(
607 637
 				'groups' => array_merge(
608 638
 					array($user_settings['id_group'], $user_settings['id_post_group']),
609 639
 					explode(',', $user_settings['additional_groups'])
610 640
 				)
611 641
 			);
642
+		}
612 643
 
613 644
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
614
-		foreach ($user_info['groups'] as $k => $v)
615
-			$user_info['groups'][$k] = (int) $v;
645
+		foreach ($user_info['groups'] as $k => $v) {
646
+					$user_info['groups'][$k] = (int) $v;
647
+		}
616 648
 
617 649
 		// This is a logged in user, so definitely not a spider.
618 650
 		$user_info['possibly_robot'] = false;
@@ -626,8 +658,7 @@  discard block
 block discarded – undo
626 658
 			$time_system = new DateTime('now', $tz_system);
627 659
 			$time_user = new DateTime('now', $tz_user);
628 660
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
629
-		}
630
-		else
661
+		} else
631 662
 		{
632 663
 			// !!! Compatibility.
633 664
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -641,8 +672,9 @@  discard block
 block discarded – undo
641 672
 		$user_info = array('groups' => array(-1));
642 673
 		$user_settings = array();
643 674
 
644
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
645
-			$_COOKIE[$cookiename] = '';
675
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
676
+					$_COOKIE[$cookiename] = '';
677
+		}
646 678
 
647 679
 		// Expire the 2FA cookie
648 680
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -659,19 +691,20 @@  discard block
 block discarded – undo
659 691
 		}
660 692
 
661 693
 		// Create a login token if it doesn't exist yet.
662
-		if (!isset($_SESSION['token']['post-login']))
663
-			createToken('login');
664
-		else
665
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
694
+		if (!isset($_SESSION['token']['post-login'])) {
695
+					createToken('login');
696
+		} else {
697
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
698
+		}
666 699
 
667 700
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
668 701
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
669 702
 		{
670 703
 			require_once($sourcedir . '/ManageSearchEngines.php');
671 704
 			$user_info['possibly_robot'] = SpiderCheck();
705
+		} elseif (!empty($modSettings['spider_mode'])) {
706
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
672 707
 		}
673
-		elseif (!empty($modSettings['spider_mode']))
674
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
675 708
 		// If we haven't turned on proper spider hunts then have a guess!
676 709
 		else
677 710
 		{
@@ -719,8 +752,9 @@  discard block
 block discarded – undo
719 752
 	$user_info['groups'] = array_unique($user_info['groups']);
720 753
 
721 754
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
722
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
723
-		unset($user_info['ignoreboards'][$tmp]);
755
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
756
+			unset($user_info['ignoreboards'][$tmp]);
757
+	}
724 758
 
725 759
 	// Allow the user to change their language.
726 760
 	if (!empty($modSettings['userLanguage']))
@@ -733,13 +767,14 @@  discard block
 block discarded – undo
733 767
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
734 768
 
735 769
 			// Make it permanent for members.
736
-			if (!empty($user_info['id']))
737
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
738
-			else
739
-				$_SESSION['language'] = $user_info['language'];
770
+			if (!empty($user_info['id'])) {
771
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
772
+			} else {
773
+							$_SESSION['language'] = $user_info['language'];
774
+			}
775
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
776
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
740 777
 		}
741
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
742
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
743 778
 	}
744 779
 
745 780
 	$temp = build_query_board($user_info['id']);
@@ -802,9 +837,9 @@  discard block
 block discarded – undo
802 837
 		}
803 838
 
804 839
 		// Remember redirection is the key to avoiding fallout from your bosses.
805
-		if (!empty($topic))
806
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
807
-		else
840
+		if (!empty($topic)) {
841
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
842
+		} else
808 843
 		{
809 844
 			loadPermissions();
810 845
 			loadTheme();
@@ -822,10 +857,11 @@  discard block
 block discarded – undo
822 857
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
823 858
 	{
824 859
 		// @todo SLOW?
825
-		if (!empty($topic))
826
-			$temp = cache_get_data('topic_board-' . $topic, 120);
827
-		else
828
-			$temp = cache_get_data('board-' . $board, 120);
860
+		if (!empty($topic)) {
861
+					$temp = cache_get_data('topic_board-' . $topic, 120);
862
+		} else {
863
+					$temp = cache_get_data('board-' . $board, 120);
864
+		}
829 865
 
830 866
 		if (!empty($temp))
831 867
 		{
@@ -863,8 +899,9 @@  discard block
 block discarded – undo
863 899
 			$row = $smcFunc['db_fetch_assoc']($request);
864 900
 
865 901
 			// Set the current board.
866
-			if (!empty($row['id_board']))
867
-				$board = $row['id_board'];
902
+			if (!empty($row['id_board'])) {
903
+							$board = $row['id_board'];
904
+			}
868 905
 
869 906
 			// Basic operating information. (globals... :/)
870 907
 			$board_info = array(
@@ -900,21 +937,23 @@  discard block
 block discarded – undo
900 937
 
901 938
 			do
902 939
 			{
903
-				if (!empty($row['id_moderator']))
904
-					$board_info['moderators'][$row['id_moderator']] = array(
940
+				if (!empty($row['id_moderator'])) {
941
+									$board_info['moderators'][$row['id_moderator']] = array(
905 942
 						'id' => $row['id_moderator'],
906 943
 						'name' => $row['real_name'],
907 944
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
908 945
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
909 946
 					);
947
+				}
910 948
 
911
-				if (!empty($row['id_moderator_group']))
912
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
949
+				if (!empty($row['id_moderator_group'])) {
950
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
913 951
 						'id' => $row['id_moderator_group'],
914 952
 						'name' => $row['group_name'],
915 953
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
916 954
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
917 955
 					);
956
+				}
918 957
 			}
919 958
 			while ($row = $smcFunc['db_fetch_assoc']($request));
920 959
 
@@ -946,12 +985,12 @@  discard block
 block discarded – undo
946 985
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
947 986
 			{
948 987
 				// @todo SLOW?
949
-				if (!empty($topic))
950
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
988
+				if (!empty($topic)) {
989
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
990
+				}
951 991
 				cache_put_data('board-' . $board, $board_info, 120);
952 992
 			}
953
-		}
954
-		else
993
+		} else
955 994
 		{
956 995
 			// Otherwise the topic is invalid, there are no moderators, etc.
957 996
 			$board_info = array(
@@ -965,8 +1004,9 @@  discard block
 block discarded – undo
965 1004
 		$smcFunc['db_free_result']($request);
966 1005
 	}
967 1006
 
968
-	if (!empty($topic))
969
-		$_GET['board'] = (int) $board;
1007
+	if (!empty($topic)) {
1008
+			$_GET['board'] = (int) $board;
1009
+	}
970 1010
 
971 1011
 	if (!empty($board))
972 1012
 	{
@@ -976,10 +1016,12 @@  discard block
 block discarded – undo
976 1016
 		// Now check if the user is a moderator.
977 1017
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
978 1018
 
979
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
980
-			$board_info['error'] = 'access';
981
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
982
-			$board_info['error'] = 'access';
1019
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1020
+					$board_info['error'] = 'access';
1021
+		}
1022
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1023
+					$board_info['error'] = 'access';
1024
+		}
983 1025
 
984 1026
 		// Build up the linktree.
985 1027
 		$context['linktree'] = array_merge(
@@ -1002,8 +1044,9 @@  discard block
 block discarded – undo
1002 1044
 	$context['current_board'] = $board;
1003 1045
 
1004 1046
 	// No posting in redirection boards!
1005
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1006
-		$board_info['error'] == 'post_in_redirect';
1047
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1048
+			$board_info['error'] == 'post_in_redirect';
1049
+	}
1007 1050
 
1008 1051
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1009 1052
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1029,24 +1072,23 @@  discard block
 block discarded – undo
1029 1072
 			ob_end_clean();
1030 1073
 			header('HTTP/1.1 403 Forbidden');
1031 1074
 			die;
1032
-		}
1033
-		elseif ($board_info['error'] == 'post_in_redirect')
1075
+		} elseif ($board_info['error'] == 'post_in_redirect')
1034 1076
 		{
1035 1077
 			// Slightly different error message here...
1036 1078
 			fatal_lang_error('cannot_post_redirect', false);
1037
-		}
1038
-		elseif ($user_info['is_guest'])
1079
+		} elseif ($user_info['is_guest'])
1039 1080
 		{
1040 1081
 			loadLanguage('Errors');
1041 1082
 			is_not_guest($txt['topic_gone']);
1083
+		} else {
1084
+					fatal_lang_error('topic_gone', false);
1042 1085
 		}
1043
-		else
1044
-			fatal_lang_error('topic_gone', false);
1045 1086
 	}
1046 1087
 
1047
-	if ($user_info['is_mod'])
1048
-		$user_info['groups'][] = 3;
1049
-}
1088
+	if ($user_info['is_mod']) {
1089
+			$user_info['groups'][] = 3;
1090
+	}
1091
+	}
1050 1092
 
1051 1093
 /**
1052 1094
  * Load this user's permissions.
@@ -1067,8 +1109,9 @@  discard block
 block discarded – undo
1067 1109
 		asort($cache_groups);
1068 1110
 		$cache_groups = implode(',', $cache_groups);
1069 1111
 		// If it's a spider then cache it different.
1070
-		if ($user_info['possibly_robot'])
1071
-			$cache_groups .= '-spider';
1112
+		if ($user_info['possibly_robot']) {
1113
+					$cache_groups .= '-spider';
1114
+		}
1072 1115
 
1073 1116
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1074 1117
 		{
@@ -1076,9 +1119,9 @@  discard block
 block discarded – undo
1076 1119
 			banPermissions();
1077 1120
 
1078 1121
 			return;
1122
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1123
+					list ($user_info['permissions'], $removals) = $temp;
1079 1124
 		}
1080
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1081
-			list ($user_info['permissions'], $removals) = $temp;
1082 1125
 	}
1083 1126
 
1084 1127
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1100,23 +1143,26 @@  discard block
 block discarded – undo
1100 1143
 		$removals = array();
1101 1144
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1102 1145
 		{
1103
-			if (empty($row['add_deny']))
1104
-				$removals[] = $row['permission'];
1105
-			else
1106
-				$user_info['permissions'][] = $row['permission'];
1146
+			if (empty($row['add_deny'])) {
1147
+							$removals[] = $row['permission'];
1148
+			} else {
1149
+							$user_info['permissions'][] = $row['permission'];
1150
+			}
1107 1151
 		}
1108 1152
 		$smcFunc['db_free_result']($request);
1109 1153
 
1110
-		if (isset($cache_groups))
1111
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1154
+		if (isset($cache_groups)) {
1155
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1156
+		}
1112 1157
 	}
1113 1158
 
1114 1159
 	// Get the board permissions.
1115 1160
 	if (!empty($board))
1116 1161
 	{
1117 1162
 		// Make sure the board (if any) has been loaded by loadBoard().
1118
-		if (!isset($board_info['profile']))
1119
-			fatal_lang_error('no_board');
1163
+		if (!isset($board_info['profile'])) {
1164
+					fatal_lang_error('no_board');
1165
+		}
1120 1166
 
1121 1167
 		$request = $smcFunc['db_query']('', '
1122 1168
 			SELECT permission, add_deny
@@ -1132,20 +1178,23 @@  discard block
 block discarded – undo
1132 1178
 		);
1133 1179
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1134 1180
 		{
1135
-			if (empty($row['add_deny']))
1136
-				$removals[] = $row['permission'];
1137
-			else
1138
-				$user_info['permissions'][] = $row['permission'];
1181
+			if (empty($row['add_deny'])) {
1182
+							$removals[] = $row['permission'];
1183
+			} else {
1184
+							$user_info['permissions'][] = $row['permission'];
1185
+			}
1139 1186
 		}
1140 1187
 		$smcFunc['db_free_result']($request);
1141 1188
 	}
1142 1189
 
1143 1190
 	// Remove all the permissions they shouldn't have ;).
1144
-	if (!empty($modSettings['permission_enable_deny']))
1145
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1191
+	if (!empty($modSettings['permission_enable_deny'])) {
1192
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1193
+	}
1146 1194
 
1147
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1148
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1195
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1196
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1197
+	}
1149 1198
 
1150 1199
 	// Banned?  Watch, don't touch..
1151 1200
 	banPermissions();
@@ -1157,17 +1206,18 @@  discard block
 block discarded – undo
1157 1206
 		{
1158 1207
 			require_once($sourcedir . '/Subs-Auth.php');
1159 1208
 			rebuildModCache();
1209
+		} else {
1210
+					$user_info['mod_cache'] = $_SESSION['mc'];
1160 1211
 		}
1161
-		else
1162
-			$user_info['mod_cache'] = $_SESSION['mc'];
1163 1212
 
1164 1213
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1165 1214
 		// For example this drastically simplifies certain changes to the profile area.
1166 1215
 		$user_info['permissions'][] = 'is_not_guest';
1167 1216
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1168 1217
 		$user_info['permissions'][] = 'profile_view_own';
1169
-		if (in_array('profile_view', $user_info['permissions']))
1170
-			$user_info['permissions'][] = 'profile_view_any';
1218
+		if (in_array('profile_view', $user_info['permissions'])) {
1219
+					$user_info['permissions'][] = 'profile_view_any';
1220
+		}
1171 1221
 	}
1172 1222
 }
1173 1223
 
@@ -1185,8 +1235,9 @@  discard block
 block discarded – undo
1185 1235
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl, $user_info;
1186 1236
 
1187 1237
 	// Can't just look for no users :P.
1188
-	if (empty($users))
1189
-		return array();
1238
+	if (empty($users)) {
1239
+			return array();
1240
+	}
1190 1241
 
1191 1242
 	// Pass the set value
1192 1243
 	$context['loadMemberContext_set'] = $set;
@@ -1201,8 +1252,9 @@  discard block
 block discarded – undo
1201 1252
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1202 1253
 		{
1203 1254
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1204
-			if ($data == null)
1205
-				continue;
1255
+			if ($data == null) {
1256
+							continue;
1257
+			}
1206 1258
 
1207 1259
 			$loaded_ids[] = $data['id_member'];
1208 1260
 			$user_profile[$data['id_member']] = $data;
@@ -1269,16 +1321,19 @@  discard block
 block discarded – undo
1269 1321
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1270 1322
 
1271 1323
 			// Take care of proxying avatar if required, do this here for maximum reach
1272
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
1273
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1324
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
1325
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1326
+			}
1274 1327
 
1275 1328
 			// Keep track of the member's normal member group
1276 1329
 			$row['primary_group'] = $row['member_group'];
1277 1330
 
1278
-			if (isset($row['member_ip']))
1279
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1280
-			if (isset($row['member_ip2']))
1281
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1331
+			if (isset($row['member_ip'])) {
1332
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1333
+			}
1334
+			if (isset($row['member_ip2'])) {
1335
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1336
+			}
1282 1337
 			$new_loaded_ids[] = $row['id_member'];
1283 1338
 			$loaded_ids[] = $row['id_member'];
1284 1339
 			$row['options'] = array();
@@ -1297,8 +1352,9 @@  discard block
 block discarded – undo
1297 1352
 				'loaded_ids' => $new_loaded_ids,
1298 1353
 			)
1299 1354
 		);
1300
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1301
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1355
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1356
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1357
+		}
1302 1358
 		$smcFunc['db_free_result']($request);
1303 1359
 	}
1304 1360
 
@@ -1309,10 +1365,11 @@  discard block
 block discarded – undo
1309 1365
 	{
1310 1366
 		foreach ($loaded_ids as $a_member)
1311 1367
 		{
1312
-			if (!empty($user_profile[$a_member]['additional_groups']))
1313
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1314
-			else
1315
-				$groups = array($user_profile[$a_member]['id_group']);
1368
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1369
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1370
+			} else {
1371
+							$groups = array($user_profile[$a_member]['id_group']);
1372
+			}
1316 1373
 
1317 1374
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1318 1375
 
@@ -1325,8 +1382,9 @@  discard block
 block discarded – undo
1325 1382
 
1326 1383
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1327 1384
 	{
1328
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1329
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1385
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1386
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1387
+		}
1330 1388
 	}
1331 1389
 
1332 1390
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1352,14 +1410,17 @@  discard block
 block discarded – undo
1352 1410
 		foreach ($temp_mods as $id)
1353 1411
 		{
1354 1412
 			// By popular demand, don't show admins or global moderators as moderators.
1355
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1356
-				$user_profile[$id]['member_group'] = $row['member_group'];
1413
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1414
+							$user_profile[$id]['member_group'] = $row['member_group'];
1415
+			}
1357 1416
 
1358 1417
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1359
-			if (!empty($row['icons']))
1360
-				$user_profile[$id]['icons'] = $row['icons'];
1361
-			if (!empty($row['member_group_color']))
1362
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1418
+			if (!empty($row['icons'])) {
1419
+							$user_profile[$id]['icons'] = $row['icons'];
1420
+			}
1421
+			if (!empty($row['member_group_color'])) {
1422
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1423
+			}
1363 1424
 		}
1364 1425
 	}
1365 1426
 
@@ -1381,12 +1442,14 @@  discard block
 block discarded – undo
1381 1442
 	static $loadedLanguages = array();
1382 1443
 
1383 1444
 	// If this person's data is already loaded, skip it.
1384
-	if (isset($dataLoaded[$user]))
1385
-		return true;
1445
+	if (isset($dataLoaded[$user])) {
1446
+			return true;
1447
+	}
1386 1448
 
1387 1449
 	// We can't load guests or members not loaded by loadMemberData()!
1388
-	if ($user == 0)
1389
-		return false;
1450
+	if ($user == 0) {
1451
+			return false;
1452
+	}
1390 1453
 	if (!isset($user_profile[$user]))
1391 1454
 	{
1392 1455
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1412,12 +1475,16 @@  discard block
 block discarded – undo
1412 1475
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1413 1476
 
1414 1477
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1415
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1478
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1479
+		//icon is set and exists
1416 1480
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1417
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1481
+	} elseif (isset($profile['icons'][1])) {
1482
+		//icon is set and doesn't exist, fallback to default
1418 1483
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1419
-	else //not set, bye bye
1484
+	} else {
1485
+		//not set, bye bye
1420 1486
 		$group_icon_url = '';
1487
+	}
1421 1488
 
1422 1489
 	// These minimal values are always loaded
1423 1490
 	$memberContext[$user] = array(
@@ -1436,8 +1503,9 @@  discard block
 block discarded – undo
1436 1503
 	if ($context['loadMemberContext_set'] != 'minimal')
1437 1504
 	{
1438 1505
 		// Go the extra mile and load the user's native language name.
1439
-		if (empty($loadedLanguages))
1440
-			$loadedLanguages = getLanguages();
1506
+		if (empty($loadedLanguages)) {
1507
+					$loadedLanguages = getLanguages();
1508
+		}
1441 1509
 
1442 1510
 		$memberContext[$user] += array(
1443 1511
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1492,31 +1560,33 @@  discard block
 block discarded – undo
1492 1560
 	{
1493 1561
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1494 1562
 		{
1495
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1496
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1497
-			else
1498
-				$image = get_gravatar_url($profile['email_address']);
1499
-		}
1500
-		else
1563
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1564
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1565
+			} else {
1566
+							$image = get_gravatar_url($profile['email_address']);
1567
+			}
1568
+		} else
1501 1569
 		{
1502 1570
 			// So it's stored in the member table?
1503 1571
 			if (!empty($profile['avatar']))
1504 1572
 			{
1505 1573
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1574
+			} elseif (!empty($profile['filename'])) {
1575
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1506 1576
 			}
1507
-			elseif (!empty($profile['filename']))
1508
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1509 1577
 			// Right... no avatar...use the default one
1510
-			else
1511
-				$image = $modSettings['avatar_url'] . '/default.png';
1578
+			else {
1579
+							$image = $modSettings['avatar_url'] . '/default.png';
1580
+			}
1512 1581
 		}
1513
-		if (!empty($image))
1514
-			$memberContext[$user]['avatar'] = array(
1582
+		if (!empty($image)) {
1583
+					$memberContext[$user]['avatar'] = array(
1515 1584
 				'name' => $profile['avatar'],
1516 1585
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1517 1586
 				'href' => $image,
1518 1587
 				'url' => $image,
1519 1588
 			);
1589
+		}
1520 1590
 	}
1521 1591
 
1522 1592
 	// Are we also loading the members custom fields into context?
@@ -1524,13 +1594,15 @@  discard block
 block discarded – undo
1524 1594
 	{
1525 1595
 		$memberContext[$user]['custom_fields'] = array();
1526 1596
 
1527
-		if (!isset($context['display_fields']))
1528
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1597
+		if (!isset($context['display_fields'])) {
1598
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1599
+		}
1529 1600
 
1530 1601
 		foreach ($context['display_fields'] as $custom)
1531 1602
 		{
1532
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1533
-				continue;
1603
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1604
+							continue;
1605
+			}
1534 1606
 
1535 1607
 			$value = $profile['options'][$custom['col_name']];
1536 1608
 
@@ -1538,31 +1610,36 @@  discard block
 block discarded – undo
1538 1610
 			$currentKey = 0;
1539 1611
 
1540 1612
 			// Create a key => value array for multiple options fields
1541
-			if (!empty($custom['options']))
1542
-				foreach ($custom['options'] as $k => $v)
1613
+			if (!empty($custom['options'])) {
1614
+							foreach ($custom['options'] as $k => $v)
1543 1615
 				{
1544 1616
 					$fieldOptions[] = $v;
1545
-					if (empty($currentKey))
1546
-						$currentKey = $v == $value ? $k : 0;
1617
+			}
1618
+					if (empty($currentKey)) {
1619
+											$currentKey = $v == $value ? $k : 0;
1620
+					}
1547 1621
 				}
1548 1622
 
1549 1623
 			// BBC?
1550
-			if ($custom['bbc'])
1551
-				$value = parse_bbc($value);
1624
+			if ($custom['bbc']) {
1625
+							$value = parse_bbc($value);
1626
+			}
1552 1627
 
1553 1628
 			// ... or checkbox?
1554
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1555
-				$value = $value ? $txt['yes'] : $txt['no'];
1629
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1630
+							$value = $value ? $txt['yes'] : $txt['no'];
1631
+			}
1556 1632
 
1557 1633
 			// Enclosing the user input within some other text?
1558
-			if (!empty($custom['enclose']))
1559
-				$value = strtr($custom['enclose'], array(
1634
+			if (!empty($custom['enclose'])) {
1635
+							$value = strtr($custom['enclose'], array(
1560 1636
 					'{SCRIPTURL}' => $scripturl,
1561 1637
 					'{IMAGES_URL}' => $settings['images_url'],
1562 1638
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1563 1639
 					'{INPUT}' => $value,
1564 1640
 					'{KEY}' => $currentKey,
1565 1641
 				));
1642
+			}
1566 1643
 
1567 1644
 			$memberContext[$user]['custom_fields'][] = array(
1568 1645
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1589,8 +1666,9 @@  discard block
 block discarded – undo
1589 1666
 	global $smcFunc, $txt, $scripturl, $settings;
1590 1667
 
1591 1668
 	// Do not waste my time...
1592
-	if (empty($users) || empty($params))
1593
-		return false;
1669
+	if (empty($users) || empty($params)) {
1670
+			return false;
1671
+	}
1594 1672
 
1595 1673
 	// Make sure it's an array.
1596 1674
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1617,41 +1695,48 @@  discard block
 block discarded – undo
1617 1695
 		$currentKey = 0;
1618 1696
 
1619 1697
 		// Create a key => value array for multiple options fields
1620
-		if (!empty($row['field_options']))
1621
-			foreach (explode(',', $row['field_options']) as $k => $v)
1698
+		if (!empty($row['field_options'])) {
1699
+					foreach (explode(',', $row['field_options']) as $k => $v)
1622 1700
 			{
1623 1701
 				$fieldOptions[] = $v;
1624
-				if (empty($currentKey))
1625
-					$currentKey = $v == $row['value'] ? $k : 0;
1702
+		}
1703
+				if (empty($currentKey)) {
1704
+									$currentKey = $v == $row['value'] ? $k : 0;
1705
+				}
1626 1706
 			}
1627 1707
 
1628 1708
 		// BBC?
1629
-		if (!empty($row['bbc']))
1630
-			$row['value'] = parse_bbc($row['value']);
1709
+		if (!empty($row['bbc'])) {
1710
+					$row['value'] = parse_bbc($row['value']);
1711
+		}
1631 1712
 
1632 1713
 		// ... or checkbox?
1633
-		elseif (isset($row['type']) && $row['type'] == 'check')
1634
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1714
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1715
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1716
+		}
1635 1717
 
1636 1718
 		// Enclosing the user input within some other text?
1637
-		if (!empty($row['enclose']))
1638
-			$row['value'] = strtr($row['enclose'], array(
1719
+		if (!empty($row['enclose'])) {
1720
+					$row['value'] = strtr($row['enclose'], array(
1639 1721
 				'{SCRIPTURL}' => $scripturl,
1640 1722
 				'{IMAGES_URL}' => $settings['images_url'],
1641 1723
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1642 1724
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1643 1725
 				'{KEY}' => $currentKey,
1644 1726
 			));
1727
+		}
1645 1728
 
1646 1729
 		// Send a simple array if there is just 1 param
1647
-		if (count($params) == 1)
1648
-			$return[$row['id_member']] = $row;
1730
+		if (count($params) == 1) {
1731
+					$return[$row['id_member']] = $row;
1732
+		}
1649 1733
 
1650 1734
 		// More than 1? knock yourself out...
1651 1735
 		else
1652 1736
 		{
1653
-			if (!isset($return[$row['id_member']]))
1654
-				$return[$row['id_member']] = array();
1737
+			if (!isset($return[$row['id_member']])) {
1738
+							$return[$row['id_member']] = array();
1739
+			}
1655 1740
 
1656 1741
 			$return[$row['id_member']][$row['variable']] = $row;
1657 1742
 		}
@@ -1685,8 +1770,9 @@  discard block
 block discarded – undo
1685 1770
 	global $context;
1686 1771
 
1687 1772
 	// Don't know any browser!
1688
-	if (empty($context['browser']))
1689
-		detectBrowser();
1773
+	if (empty($context['browser'])) {
1774
+			detectBrowser();
1775
+	}
1690 1776
 
1691 1777
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1692 1778
 }
@@ -1704,8 +1790,9 @@  discard block
 block discarded – undo
1704 1790
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1705 1791
 
1706 1792
 	// The theme was specified by parameter.
1707
-	if (!empty($id_theme))
1708
-		$id_theme = (int) $id_theme;
1793
+	if (!empty($id_theme)) {
1794
+			$id_theme = (int) $id_theme;
1795
+	}
1709 1796
 	// The theme was specified by REQUEST.
1710 1797
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1711 1798
 	{
@@ -1713,54 +1800,61 @@  discard block
 block discarded – undo
1713 1800
 		$_SESSION['id_theme'] = $id_theme;
1714 1801
 	}
1715 1802
 	// The theme was specified by REQUEST... previously.
1716
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1717
-		$id_theme = (int) $_SESSION['id_theme'];
1803
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1804
+			$id_theme = (int) $_SESSION['id_theme'];
1805
+	}
1718 1806
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1719
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1720
-		$id_theme = $user_info['theme'];
1807
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1808
+			$id_theme = $user_info['theme'];
1809
+	}
1721 1810
 	// The theme was specified by the board.
1722
-	elseif (!empty($board_info['theme']))
1723
-		$id_theme = $board_info['theme'];
1811
+	elseif (!empty($board_info['theme'])) {
1812
+			$id_theme = $board_info['theme'];
1813
+	}
1724 1814
 	// The theme is the forum's default.
1725
-	else
1726
-		$id_theme = $modSettings['theme_guests'];
1815
+	else {
1816
+			$id_theme = $modSettings['theme_guests'];
1817
+	}
1727 1818
 
1728 1819
 	// We already load the basic stuff?
1729 1820
 	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme )
1730 1821
 	{
1731 1822
 		// Verify the id_theme... no foul play.
1732 1823
 		// Always allow the board specific theme, if they are overriding.
1733
-		if (!empty($board_info['theme']) && $board_info['override_theme'])
1734
-			$id_theme = $board_info['theme'];
1824
+		if (!empty($board_info['theme']) && $board_info['override_theme']) {
1825
+					$id_theme = $board_info['theme'];
1826
+		}
1735 1827
 		// If they have specified a particular theme to use with SSI allow it to be used.
1736
-		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1737
-			$id_theme = (int) $id_theme;
1738
-		elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1828
+		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1829
+					$id_theme = (int) $id_theme;
1830
+		} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1739 1831
 		{
1740 1832
 			$themes = explode(',', $modSettings['enableThemes']);
1741
-			if (!in_array($id_theme, $themes))
1742
-				$id_theme = $modSettings['theme_guests'];
1743
-			else
1744
-				$id_theme = (int) $id_theme;
1833
+			if (!in_array($id_theme, $themes)) {
1834
+							$id_theme = $modSettings['theme_guests'];
1835
+			} else {
1836
+							$id_theme = (int) $id_theme;
1837
+			}
1838
+		} else {
1839
+					$id_theme = (int) $id_theme;
1745 1840
 		}
1746
-		else
1747
-			$id_theme = (int) $id_theme;
1748 1841
 
1749 1842
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1750 1843
 
1751 1844
 		// Disable image proxy if we don't have SSL enabled
1752
-		if (empty($modSettings['force_ssl']))
1753
-			$image_proxy_enabled = false;
1845
+		if (empty($modSettings['force_ssl'])) {
1846
+					$image_proxy_enabled = false;
1847
+		}
1754 1848
 
1755 1849
 		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1756 1850
 		{
1757 1851
 			$themeData = $temp;
1758 1852
 			$flag = true;
1853
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1854
+					$themeData = $temp + array($member => array());
1855
+		} else {
1856
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1759 1857
 		}
1760
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1761
-			$themeData = $temp + array($member => array());
1762
-		else
1763
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1764 1858
 
1765 1859
 		if (empty($flag))
1766 1860
 		{
@@ -1779,31 +1873,37 @@  discard block
 block discarded – undo
1779 1873
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1780 1874
 			{
1781 1875
 				// There are just things we shouldn't be able to change as members.
1782
-				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1783
-					continue;
1876
+				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1877
+									continue;
1878
+				}
1784 1879
 
1785 1880
 				// If this is the theme_dir of the default theme, store it.
1786
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1787
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1881
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1882
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1883
+				}
1788 1884
 
1789 1885
 				// If this isn't set yet, is a theme option, or is not the default theme..
1790
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1791
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1886
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1887
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1888
+				}
1792 1889
 			}
1793 1890
 			$smcFunc['db_free_result']($result);
1794 1891
 
1795
-			if (!empty($themeData[-1]))
1796
-				foreach ($themeData[-1] as $k => $v)
1892
+			if (!empty($themeData[-1])) {
1893
+							foreach ($themeData[-1] as $k => $v)
1797 1894
 				{
1798 1895
 					if (!isset($themeData[$member][$k]))
1799 1896
 						$themeData[$member][$k] = $v;
1897
+			}
1800 1898
 				}
1801 1899
 
1802
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1803
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1900
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1901
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1902
+			}
1804 1903
 			// Only if we didn't already load that part of the cache...
1805
-			elseif (!isset($temp))
1806
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1904
+			elseif (!isset($temp)) {
1905
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1906
+			}
1807 1907
 		}
1808 1908
 
1809 1909
 		$settings = $themeData[0];
@@ -1820,17 +1920,20 @@  discard block
 block discarded – undo
1820 1920
 		$settings['template_dirs'][] = $settings['theme_dir'];
1821 1921
 
1822 1922
 		// Based on theme (if there is one).
1823
-		if (!empty($settings['base_theme_dir']))
1824
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1923
+		if (!empty($settings['base_theme_dir'])) {
1924
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1925
+		}
1825 1926
 
1826 1927
 		// Lastly the default theme.
1827
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1828
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1928
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1929
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1930
+		}
1829 1931
 	}
1830 1932
 
1831 1933
 
1832
-	if (!$initialize)
1833
-		return;
1934
+	if (!$initialize) {
1935
+			return;
1936
+	}
1834 1937
 
1835 1938
 	// Check to see if we're forcing SSL
1836 1939
 	if (!empty($modSettings['force_ssl']) && empty($maintenance) &&
@@ -1851,8 +1954,9 @@  discard block
 block discarded – undo
1851 1954
 		$detected_url = httpsOn() ? 'https://' : 'http://';
1852 1955
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1853 1956
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1854
-		if ($temp != '/')
1855
-			$detected_url .= $temp;
1957
+		if ($temp != '/') {
1958
+					$detected_url .= $temp;
1959
+		}
1856 1960
 	}
1857 1961
 	if (isset($detected_url) && $detected_url != $boardurl)
1858 1962
 	{
@@ -1864,8 +1968,9 @@  discard block
 block discarded – undo
1864 1968
 			foreach ($aliases as $alias)
1865 1969
 			{
1866 1970
 				// Rip off all the boring parts, spaces, etc.
1867
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1868
-					$do_fix = true;
1971
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1972
+									$do_fix = true;
1973
+				}
1869 1974
 			}
1870 1975
 		}
1871 1976
 
@@ -1873,21 +1978,23 @@  discard block
 block discarded – undo
1873 1978
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1874 1979
 		{
1875 1980
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1876
-			if (empty($_GET))
1877
-				redirectexit('wwwRedirect');
1878
-			else
1981
+			if (empty($_GET)) {
1982
+							redirectexit('wwwRedirect');
1983
+			} else
1879 1984
 			{
1880 1985
 				$k = key($_GET);
1881 1986
 				$v = current($_GET);
1882 1987
 
1883
-				if ($k != 'wwwRedirect')
1884
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1988
+				if ($k != 'wwwRedirect') {
1989
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1990
+				}
1885 1991
 			}
1886 1992
 		}
1887 1993
 
1888 1994
 		// #3 is just a check for SSL...
1889
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1890
-			$do_fix = true;
1995
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1996
+					$do_fix = true;
1997
+		}
1891 1998
 
1892 1999
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1893 2000
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1922,8 +2029,9 @@  discard block
 block discarded – undo
1922 2029
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1923 2030
 				}
1924 2031
 			}
1925
-			foreach ($context['linktree'] as $k => $dummy)
1926
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2032
+			foreach ($context['linktree'] as $k => $dummy) {
2033
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2034
+			}
1927 2035
 		}
1928 2036
 	}
1929 2037
 	// Set up the contextual user array.
@@ -1942,16 +2050,16 @@  discard block
 block discarded – undo
1942 2050
 			'email' => $user_info['email'],
1943 2051
 			'ignoreusers' => $user_info['ignoreusers'],
1944 2052
 		);
1945
-		if (!$context['user']['is_guest'])
1946
-			$context['user']['name'] = $user_info['name'];
1947
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1948
-			$context['user']['name'] = $txt['guest_title'];
2053
+		if (!$context['user']['is_guest']) {
2054
+					$context['user']['name'] = $user_info['name'];
2055
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2056
+					$context['user']['name'] = $txt['guest_title'];
2057
+		}
1949 2058
 
1950 2059
 		// Determine the current smiley set.
1951 2060
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1952 2061
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1953
-	}
1954
-	else
2062
+	} else
1955 2063
 	{
1956 2064
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1957 2065
 		$context['user'] = array(
@@ -1985,18 +2093,24 @@  discard block
 block discarded – undo
1985 2093
 	}
1986 2094
 
1987 2095
 	// Some basic information...
1988
-	if (!isset($context['html_headers']))
1989
-		$context['html_headers'] = '';
1990
-	if (!isset($context['javascript_files']))
1991
-		$context['javascript_files'] = array();
1992
-	if (!isset($context['css_files']))
1993
-		$context['css_files'] = array();
1994
-	if (!isset($context['css_header']))
1995
-		$context['css_header'] = array();
1996
-	if (!isset($context['javascript_inline']))
1997
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1998
-	if (!isset($context['javascript_vars']))
1999
-		$context['javascript_vars'] = array();
2096
+	if (!isset($context['html_headers'])) {
2097
+			$context['html_headers'] = '';
2098
+	}
2099
+	if (!isset($context['javascript_files'])) {
2100
+			$context['javascript_files'] = array();
2101
+	}
2102
+	if (!isset($context['css_files'])) {
2103
+			$context['css_files'] = array();
2104
+	}
2105
+	if (!isset($context['css_header'])) {
2106
+			$context['css_header'] = array();
2107
+	}
2108
+	if (!isset($context['javascript_inline'])) {
2109
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2110
+	}
2111
+	if (!isset($context['javascript_vars'])) {
2112
+			$context['javascript_vars'] = array();
2113
+	}
2000 2114
 
2001 2115
 	$context['login_url'] =  $scripturl . '?action=login2';
2002 2116
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -2008,16 +2122,18 @@  discard block
 block discarded – undo
2008 2122
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
2009 2123
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
2010 2124
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
2011
-	if (isset($modSettings['load_average']))
2012
-		$context['load_average'] = $modSettings['load_average'];
2125
+	if (isset($modSettings['load_average'])) {
2126
+			$context['load_average'] = $modSettings['load_average'];
2127
+	}
2013 2128
 
2014 2129
 	// Detect the browser. This is separated out because it's also used in attachment downloads
2015 2130
 	detectBrowser();
2016 2131
 
2017 2132
 	// Set the top level linktree up.
2018 2133
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2019
-	if (empty($context['linktree']))
2020
-		$context['linktree'] = array();
2134
+	if (empty($context['linktree'])) {
2135
+			$context['linktree'] = array();
2136
+	}
2021 2137
 	array_unshift($context['linktree'], array(
2022 2138
 		'url' => $scripturl,
2023 2139
 		'name' => $context['forum_name_html_safe']
@@ -2026,8 +2142,9 @@  discard block
 block discarded – undo
2026 2142
 	// This allows sticking some HTML on the page output - useful for controls.
2027 2143
 	$context['insert_after_template'] = '';
2028 2144
 
2029
-	if (!isset($txt))
2030
-		$txt = array();
2145
+	if (!isset($txt)) {
2146
+			$txt = array();
2147
+	}
2031 2148
 
2032 2149
 	$simpleActions = array(
2033 2150
 		'findmember',
@@ -2073,9 +2190,10 @@  discard block
 block discarded – undo
2073 2190
 
2074 2191
 	// See if theres any extra param to check.
2075 2192
 	$requiresXML = false;
2076
-	foreach ($extraParams as $key => $extra)
2077
-		if (isset($_REQUEST[$extra]))
2193
+	foreach ($extraParams as $key => $extra) {
2194
+			if (isset($_REQUEST[$extra]))
2078 2195
 			$requiresXML = true;
2196
+	}
2079 2197
 
2080 2198
 	// Output is fully XML, so no need for the index template.
2081 2199
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2090,37 +2208,39 @@  discard block
 block discarded – undo
2090 2208
 	{
2091 2209
 		loadLanguage('index+Modifications');
2092 2210
 		$context['template_layers'] = array();
2093
-	}
2094
-
2095
-	else
2211
+	} else
2096 2212
 	{
2097 2213
 		// Custom templates to load, or just default?
2098
-		if (isset($settings['theme_templates']))
2099
-			$templates = explode(',', $settings['theme_templates']);
2100
-		else
2101
-			$templates = array('index');
2214
+		if (isset($settings['theme_templates'])) {
2215
+					$templates = explode(',', $settings['theme_templates']);
2216
+		} else {
2217
+					$templates = array('index');
2218
+		}
2102 2219
 
2103 2220
 		// Load each template...
2104
-		foreach ($templates as $template)
2105
-			loadTemplate($template);
2221
+		foreach ($templates as $template) {
2222
+					loadTemplate($template);
2223
+		}
2106 2224
 
2107 2225
 		// ...and attempt to load their associated language files.
2108 2226
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2109 2227
 		loadLanguage($required_files, '', false);
2110 2228
 
2111 2229
 		// Custom template layers?
2112
-		if (isset($settings['theme_layers']))
2113
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2114
-		else
2115
-			$context['template_layers'] = array('html', 'body');
2230
+		if (isset($settings['theme_layers'])) {
2231
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2232
+		} else {
2233
+					$context['template_layers'] = array('html', 'body');
2234
+		}
2116 2235
 	}
2117 2236
 
2118 2237
 	// Initialize the theme.
2119 2238
 	loadSubTemplate('init', 'ignore');
2120 2239
 
2121 2240
 	// Allow overriding the board wide time/number formats.
2122
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2123
-		$user_info['time_format'] = $txt['time_format'];
2241
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2242
+			$user_info['time_format'] = $txt['time_format'];
2243
+	}
2124 2244
 
2125 2245
 	// Set the character set from the template.
2126 2246
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2128,12 +2248,14 @@  discard block
 block discarded – undo
2128 2248
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2129 2249
 
2130 2250
 	// Guests may still need a name.
2131
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2132
-		$context['user']['name'] = $txt['guest_title'];
2251
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2252
+			$context['user']['name'] = $txt['guest_title'];
2253
+	}
2133 2254
 
2134 2255
 	// Any theme-related strings that need to be loaded?
2135
-	if (!empty($settings['require_theme_strings']))
2136
-		loadLanguage('ThemeStrings', '', false);
2256
+	if (!empty($settings['require_theme_strings'])) {
2257
+			loadLanguage('ThemeStrings', '', false);
2258
+	}
2137 2259
 
2138 2260
 	// Make a special URL for the language.
2139 2261
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2144,8 +2266,9 @@  discard block
 block discarded – undo
2144 2266
 	// Here is my luvly Responsive CSS
2145 2267
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2146 2268
 
2147
-	if ($context['right_to_left'])
2148
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2269
+	if ($context['right_to_left']) {
2270
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2271
+	}
2149 2272
 
2150 2273
 	// We allow theme variants, because we're cool.
2151 2274
 	$context['theme_variant'] = '';
@@ -2153,14 +2276,17 @@  discard block
 block discarded – undo
2153 2276
 	if (!empty($settings['theme_variants']))
2154 2277
 	{
2155 2278
 		// Overriding - for previews and that ilk.
2156
-		if (!empty($_REQUEST['variant']))
2157
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2279
+		if (!empty($_REQUEST['variant'])) {
2280
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2281
+		}
2158 2282
 		// User selection?
2159
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2160
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2283
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2284
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2285
+		}
2161 2286
 		// If not a user variant, select the default.
2162
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2163
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2287
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2288
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2289
+		}
2164 2290
 
2165 2291
 		// Do this to keep things easier in the templates.
2166 2292
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2169,20 +2295,23 @@  discard block
 block discarded – undo
2169 2295
 		if (!empty($context['theme_variant']))
2170 2296
 		{
2171 2297
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2172
-			if ($context['right_to_left'])
2173
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2298
+			if ($context['right_to_left']) {
2299
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2300
+			}
2174 2301
 		}
2175 2302
 	}
2176 2303
 
2177 2304
 	// Let's be compatible with old themes!
2178
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2179
-		$context['template_layers'] = array('main');
2305
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2306
+			$context['template_layers'] = array('main');
2307
+	}
2180 2308
 
2181 2309
 	$context['tabindex'] = 1;
2182 2310
 
2183 2311
 	// Compatibility.
2184
-	if (!isset($settings['theme_version']))
2185
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2312
+	if (!isset($settings['theme_version'])) {
2313
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2314
+	}
2186 2315
 
2187 2316
 	// Default JS variables for use in every theme
2188 2317
 	$context['javascript_vars'] = array(
@@ -2201,18 +2330,18 @@  discard block
 block discarded – undo
2201 2330
 	);
2202 2331
 
2203 2332
 	// Add the JQuery library to the list of files to load.
2204
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2205
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2206
-
2207
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2208
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2209
-
2210
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2211
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2333
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2334
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2335
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2336
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2337
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2338
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2339
+	}
2212 2340
 
2213 2341
 	// Auto loading? template_javascript() will take care of the local half of this.
2214
-	else
2215
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2342
+	else {
2343
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2344
+	}
2216 2345
 
2217 2346
 	// Queue our JQuery plugins!
2218 2347
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2235,12 +2364,12 @@  discard block
 block discarded – undo
2235 2364
 			require_once($sourcedir . '/ScheduledTasks.php');
2236 2365
 
2237 2366
 			// What to do, what to do?!
2238
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2239
-				AutoTask();
2240
-			else
2241
-				ReduceMailQueue();
2242
-		}
2243
-		else
2367
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2368
+							AutoTask();
2369
+			} else {
2370
+							ReduceMailQueue();
2371
+			}
2372
+		} else
2244 2373
 		{
2245 2374
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2246 2375
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2291,8 +2420,9 @@  discard block
 block discarded – undo
2291 2420
 		foreach ($theme_includes as $include)
2292 2421
 		{
2293 2422
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2294
-			if (file_exists($include))
2295
-				require_once($include);
2423
+			if (file_exists($include)) {
2424
+							require_once($include);
2425
+			}
2296 2426
 		}
2297 2427
 	}
2298 2428
 
@@ -2322,16 +2452,19 @@  discard block
 block discarded – undo
2322 2452
 	// Do any style sheets first, cause we're easy with those.
2323 2453
 	if (!empty($style_sheets))
2324 2454
 	{
2325
-		if (!is_array($style_sheets))
2326
-			$style_sheets = array($style_sheets);
2455
+		if (!is_array($style_sheets)) {
2456
+					$style_sheets = array($style_sheets);
2457
+		}
2327 2458
 
2328
-		foreach ($style_sheets as $sheet)
2329
-			loadCSSFile($sheet . '.css', array(), $sheet);
2459
+		foreach ($style_sheets as $sheet) {
2460
+					loadCSSFile($sheet . '.css', array(), $sheet);
2461
+		}
2330 2462
 	}
2331 2463
 
2332 2464
 	// No template to load?
2333
-	if ($template_name === false)
2334
-		return true;
2465
+	if ($template_name === false) {
2466
+			return true;
2467
+	}
2335 2468
 
2336 2469
 	$loaded = false;
2337 2470
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2346,12 +2479,14 @@  discard block
 block discarded – undo
2346 2479
 
2347 2480
 	if ($loaded)
2348 2481
 	{
2349
-		if ($db_show_debug === true)
2350
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2482
+		if ($db_show_debug === true) {
2483
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2484
+		}
2351 2485
 
2352 2486
 		// If they have specified an initialization function for this template, go ahead and call it now.
2353
-		if (function_exists('template_' . $template_name . '_init'))
2354
-			call_user_func('template_' . $template_name . '_init');
2487
+		if (function_exists('template_' . $template_name . '_init')) {
2488
+					call_user_func('template_' . $template_name . '_init');
2489
+		}
2355 2490
 	}
2356 2491
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2357 2492
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2371,13 +2506,14 @@  discard block
 block discarded – undo
2371 2506
 		loadTemplate($template_name);
2372 2507
 	}
2373 2508
 	// Cause an error otherwise.
2374
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2375
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2376
-	elseif ($fatal)
2377
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2378
-	else
2379
-		return false;
2380
-}
2509
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2510
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2511
+	} elseif ($fatal) {
2512
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2513
+	} else {
2514
+			return false;
2515
+	}
2516
+	}
2381 2517
 
2382 2518
 /**
2383 2519
  * Load a sub-template.
@@ -2395,17 +2531,19 @@  discard block
 block discarded – undo
2395 2531
 {
2396 2532
 	global $context, $txt, $db_show_debug;
2397 2533
 
2398
-	if ($db_show_debug === true)
2399
-		$context['debug']['sub_templates'][] = $sub_template_name;
2534
+	if ($db_show_debug === true) {
2535
+			$context['debug']['sub_templates'][] = $sub_template_name;
2536
+	}
2400 2537
 
2401 2538
 	// Figure out what the template function is named.
2402 2539
 	$theme_function = 'template_' . $sub_template_name;
2403
-	if (function_exists($theme_function))
2404
-		$theme_function();
2405
-	elseif ($fatal === false)
2406
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2407
-	elseif ($fatal !== 'ignore')
2408
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2540
+	if (function_exists($theme_function)) {
2541
+			$theme_function();
2542
+	} elseif ($fatal === false) {
2543
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2544
+	} elseif ($fatal !== 'ignore') {
2545
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2546
+	}
2409 2547
 
2410 2548
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2411 2549
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2442,8 +2580,9 @@  discard block
 block discarded – undo
2442 2580
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2443 2581
 
2444 2582
 	// If this is an external file, automatically set this to false.
2445
-	if (!empty($params['external']))
2446
-		$params['minimize'] = false;
2583
+	if (!empty($params['external'])) {
2584
+			$params['minimize'] = false;
2585
+	}
2447 2586
 
2448 2587
 	// Account for shorthand like admin.css?alp21 filenames
2449 2588
 	$has_seed = strpos($fileName, '.css?');
@@ -2460,13 +2599,10 @@  discard block
 block discarded – undo
2460 2599
 			{
2461 2600
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2462 2601
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2602
+			} else {
2603
+							$fileUrl = false;
2463 2604
 			}
2464
-
2465
-			else
2466
-				$fileUrl = false;
2467
-		}
2468
-
2469
-		else
2605
+		} else
2470 2606
 		{
2471 2607
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2472 2608
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2481,12 +2617,14 @@  discard block
 block discarded – undo
2481 2617
 	}
2482 2618
 
2483 2619
 	// Add it to the array for use in the template
2484
-	if (!empty($fileName))
2485
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2620
+	if (!empty($fileName)) {
2621
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2622
+	}
2486 2623
 
2487
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2488
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2489
-}
2624
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2625
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2626
+	}
2627
+	}
2490 2628
 
2491 2629
 /**
2492 2630
  * Add a block of inline css code to be executed later
@@ -2503,8 +2641,9 @@  discard block
 block discarded – undo
2503 2641
 	global $context;
2504 2642
 
2505 2643
 	// Gotta add something...
2506
-	if (empty($css))
2507
-		return false;
2644
+	if (empty($css)) {
2645
+			return false;
2646
+	}
2508 2647
 
2509 2648
 	$context['css_header'][] = $css;
2510 2649
 }
@@ -2539,8 +2678,9 @@  discard block
 block discarded – undo
2539 2678
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2540 2679
 
2541 2680
 	// If this is an external file, automatically set this to false.
2542
-	if (!empty($params['external']))
2543
-		$params['minimize'] = false;
2681
+	if (!empty($params['external'])) {
2682
+			$params['minimize'] = false;
2683
+	}
2544 2684
 
2545 2685
 	// Account for shorthand like admin.js?alp21 filenames
2546 2686
 	$has_seed = strpos($fileName, '.js?');
@@ -2557,16 +2697,12 @@  discard block
 block discarded – undo
2557 2697
 			{
2558 2698
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2559 2699
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2560
-			}
2561
-
2562
-			else
2700
+			} else
2563 2701
 			{
2564 2702
 				$fileUrl = false;
2565 2703
 				$filePath = false;
2566 2704
 			}
2567
-		}
2568
-
2569
-		else
2705
+		} else
2570 2706
 		{
2571 2707
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2572 2708
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2581,9 +2717,10 @@  discard block
 block discarded – undo
2581 2717
 	}
2582 2718
 
2583 2719
 	// Add it to the array for use in the template
2584
-	if (!empty($fileName))
2585
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2586
-}
2720
+	if (!empty($fileName)) {
2721
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2722
+	}
2723
+	}
2587 2724
 
2588 2725
 /**
2589 2726
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2597,9 +2734,10 @@  discard block
 block discarded – undo
2597 2734
 {
2598 2735
 	global $context;
2599 2736
 
2600
-	if (!empty($key) && (!empty($value) || $value === '0'))
2601
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2602
-}
2737
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2738
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2739
+	}
2740
+	}
2603 2741
 
2604 2742
 /**
2605 2743
  * Add a block of inline Javascript code to be executed later
@@ -2616,8 +2754,9 @@  discard block
 block discarded – undo
2616 2754
 {
2617 2755
 	global $context;
2618 2756
 
2619
-	if (empty($javascript))
2620
-		return false;
2757
+	if (empty($javascript)) {
2758
+			return false;
2759
+	}
2621 2760
 
2622 2761
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2623 2762
 }
@@ -2638,15 +2777,18 @@  discard block
 block discarded – undo
2638 2777
 	static $already_loaded = array();
2639 2778
 
2640 2779
 	// Default to the user's language.
2641
-	if ($lang == '')
2642
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2780
+	if ($lang == '') {
2781
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2782
+	}
2643 2783
 
2644 2784
 	// Do we want the English version of language file as fallback?
2645
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2646
-		loadLanguage($template_name, 'english', false);
2785
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2786
+			loadLanguage($template_name, 'english', false);
2787
+	}
2647 2788
 
2648
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2649
-		return $lang;
2789
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2790
+			return $lang;
2791
+	}
2650 2792
 
2651 2793
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2652 2794
 	if (empty($settings['default_theme_dir']))
@@ -2657,8 +2799,9 @@  discard block
 block discarded – undo
2657 2799
 
2658 2800
 	// What theme are we in?
2659 2801
 	$theme_name = basename($settings['theme_url']);
2660
-	if (empty($theme_name))
2661
-		$theme_name = 'unknown';
2802
+	if (empty($theme_name)) {
2803
+			$theme_name = 'unknown';
2804
+	}
2662 2805
 
2663 2806
 	// For each file open it up and write it out!
2664 2807
 	foreach (explode('+', $template_name) as $template)
@@ -2700,8 +2843,9 @@  discard block
 block discarded – undo
2700 2843
 				$found = true;
2701 2844
 
2702 2845
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2703
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2704
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2846
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2847
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2848
+				}
2705 2849
 
2706 2850
 				break;
2707 2851
 			}
@@ -2741,8 +2885,9 @@  discard block
 block discarded – undo
2741 2885
 	}
2742 2886
 
2743 2887
 	// Keep track of what we're up to soldier.
2744
-	if ($db_show_debug === true)
2745
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2888
+	if ($db_show_debug === true) {
2889
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2890
+	}
2746 2891
 
2747 2892
 	// Remember what we have loaded, and in which language.
2748 2893
 	$already_loaded[$template_name] = $lang;
@@ -2788,8 +2933,9 @@  discard block
 block discarded – undo
2788 2933
 				)
2789 2934
 			);
2790 2935
 			// In the EXTREMELY unlikely event this happens, give an error message.
2791
-			if ($smcFunc['db_num_rows']($result) == 0)
2792
-				fatal_lang_error('parent_not_found', 'critical');
2936
+			if ($smcFunc['db_num_rows']($result) == 0) {
2937
+							fatal_lang_error('parent_not_found', 'critical');
2938
+			}
2793 2939
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2794 2940
 			{
2795 2941
 				if (!isset($boards[$row['id_board']]))
@@ -2806,8 +2952,8 @@  discard block
 block discarded – undo
2806 2952
 					);
2807 2953
 				}
2808 2954
 				// If a moderator exists for this board, add that moderator for all children too.
2809
-				if (!empty($row['id_moderator']))
2810
-					foreach ($boards as $id => $dummy)
2955
+				if (!empty($row['id_moderator'])) {
2956
+									foreach ($boards as $id => $dummy)
2811 2957
 					{
2812 2958
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2813 2959
 							'id' => $row['id_moderator'],
@@ -2815,11 +2961,12 @@  discard block
 block discarded – undo
2815 2961
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2816 2962
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2817 2963
 						);
2964
+				}
2818 2965
 					}
2819 2966
 
2820 2967
 				// If a moderator group exists for this board, add that moderator group for all children too
2821
-				if (!empty($row['id_moderator_group']))
2822
-					foreach ($boards as $id => $dummy)
2968
+				if (!empty($row['id_moderator_group'])) {
2969
+									foreach ($boards as $id => $dummy)
2823 2970
 					{
2824 2971
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2825 2972
 							'id' => $row['id_moderator_group'],
@@ -2827,6 +2974,7 @@  discard block
 block discarded – undo
2827 2974
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2828 2975
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2829 2976
 						);
2977
+				}
2830 2978
 					}
2831 2979
 			}
2832 2980
 			$smcFunc['db_free_result']($result);
@@ -2853,23 +3001,27 @@  discard block
 block discarded – undo
2853 3001
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2854 3002
 	{
2855 3003
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2856
-		if (empty($smcFunc['ucwords']))
2857
-			reloadSettings();
3004
+		if (empty($smcFunc['ucwords'])) {
3005
+					reloadSettings();
3006
+		}
2858 3007
 
2859 3008
 		// If we don't have our theme information yet, let's get it.
2860
-		if (empty($settings['default_theme_dir']))
2861
-			loadTheme(0, false);
3009
+		if (empty($settings['default_theme_dir'])) {
3010
+					loadTheme(0, false);
3011
+		}
2862 3012
 
2863 3013
 		// Default language directories to try.
2864 3014
 		$language_directories = array(
2865 3015
 			$settings['default_theme_dir'] . '/languages',
2866 3016
 		);
2867
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2868
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3017
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
3018
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3019
+		}
2869 3020
 
2870 3021
 		// We possibly have a base theme directory.
2871
-		if (!empty($settings['base_theme_dir']))
2872
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3022
+		if (!empty($settings['base_theme_dir'])) {
3023
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3024
+		}
2873 3025
 
2874 3026
 		// Remove any duplicates.
2875 3027
 		$language_directories = array_unique($language_directories);
@@ -2883,20 +3035,21 @@  discard block
 block discarded – undo
2883 3035
 		foreach ($language_directories as $language_dir)
2884 3036
 		{
2885 3037
 			// Can't look in here... doesn't exist!
2886
-			if (!file_exists($language_dir))
2887
-				continue;
3038
+			if (!file_exists($language_dir)) {
3039
+							continue;
3040
+			}
2888 3041
 
2889 3042
 			$dir = dir($language_dir);
2890 3043
 			while ($entry = $dir->read())
2891 3044
 			{
2892 3045
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2893
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2894
-					continue;
2895
-
2896
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2897
-					$langName = $langList[$matches[1]];
3046
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3047
+									continue;
3048
+				}
2898 3049
 
2899
-				else
3050
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3051
+									$langName = $langList[$matches[1]];
3052
+				} else
2900 3053
 				{
2901 3054
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2902 3055
 
@@ -2937,12 +3090,14 @@  discard block
 block discarded – undo
2937 3090
 		}
2938 3091
 
2939 3092
 		// Do we need to store the lang list?
2940
-		if (empty($langList))
2941
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3093
+		if (empty($langList)) {
3094
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3095
+		}
2942 3096
 
2943 3097
 		// Let's cash in on this deal.
2944
-		if (!empty($modSettings['cache_enable']))
2945
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3098
+		if (!empty($modSettings['cache_enable'])) {
3099
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3100
+		}
2946 3101
 	}
2947 3102
 
2948 3103
 	return $context['languages'];
@@ -2965,8 +3120,9 @@  discard block
 block discarded – undo
2965 3120
 	global $modSettings, $options, $txt;
2966 3121
 	static $censor_vulgar = null, $censor_proper;
2967 3122
 
2968
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2969
-		return $text;
3123
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3124
+			return $text;
3125
+	}
2970 3126
 
2971 3127
 	// If they haven't yet been loaded, load them.
2972 3128
 	if ($censor_vulgar == null)
@@ -2997,9 +3153,9 @@  discard block
 block discarded – undo
2997 3153
 	{
2998 3154
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2999 3155
 		$text = $func($censor_vulgar, $censor_proper, $text);
3156
+	} else {
3157
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
3000 3158
 	}
3001
-	else
3002
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
3003 3159
 
3004 3160
 	return $text;
3005 3161
 }
@@ -3025,38 +3181,42 @@  discard block
 block discarded – undo
3025 3181
 	@ini_set('track_errors', '1');
3026 3182
 
3027 3183
 	// Don't include the file more than once, if $once is true.
3028
-	if ($once && in_array($filename, $templates))
3029
-		return;
3184
+	if ($once && in_array($filename, $templates)) {
3185
+			return;
3186
+	}
3030 3187
 	// Add this file to the include list, whether $once is true or not.
3031
-	else
3032
-		$templates[] = $filename;
3188
+	else {
3189
+			$templates[] = $filename;
3190
+	}
3033 3191
 
3034 3192
 	// Are we going to use eval?
3035 3193
 	if (empty($modSettings['disableTemplateEval']))
3036 3194
 	{
3037 3195
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
3038 3196
 		$settings['current_include_filename'] = $filename;
3039
-	}
3040
-	else
3197
+	} else
3041 3198
 	{
3042 3199
 		$file_found = file_exists($filename);
3043 3200
 
3044
-		if ($once && $file_found)
3045
-			require_once($filename);
3046
-		elseif ($file_found)
3047
-			require($filename);
3201
+		if ($once && $file_found) {
3202
+					require_once($filename);
3203
+		} elseif ($file_found) {
3204
+					require($filename);
3205
+		}
3048 3206
 	}
3049 3207
 
3050 3208
 	if ($file_found !== true)
3051 3209
 	{
3052 3210
 		ob_end_clean();
3053
-		if (!empty($modSettings['enableCompressedOutput']))
3054
-			@ob_start('ob_gzhandler');
3055
-		else
3056
-			ob_start();
3211
+		if (!empty($modSettings['enableCompressedOutput'])) {
3212
+					@ob_start('ob_gzhandler');
3213
+		} else {
3214
+					ob_start();
3215
+		}
3057 3216
 
3058
-		if (isset($_GET['debug']))
3059
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3217
+		if (isset($_GET['debug'])) {
3218
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3219
+		}
3060 3220
 
3061 3221
 		// Don't cache error pages!!
3062 3222
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3075,12 +3235,13 @@  discard block
 block discarded – undo
3075 3235
 		echo '<!DOCTYPE html>
3076 3236
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3077 3237
 	<head>';
3078
-		if (isset($context['character_set']))
3079
-			echo '
3238
+		if (isset($context['character_set'])) {
3239
+					echo '
3080 3240
 		<meta charset="', $context['character_set'], '">';
3241
+		}
3081 3242
 
3082
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3083
-			echo '
3243
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3244
+					echo '
3084 3245
 		<title>', $mtitle, '</title>
3085 3246
 	</head>
3086 3247
 	<body>
@@ -3088,8 +3249,8 @@  discard block
 block discarded – undo
3088 3249
 		', $mmessage, '
3089 3250
 	</body>
3090 3251
 </html>';
3091
-		elseif (!allowedTo('admin_forum'))
3092
-			echo '
3252
+		} elseif (!allowedTo('admin_forum')) {
3253
+					echo '
3093 3254
 		<title>', $txt['template_parse_error'], '</title>
3094 3255
 	</head>
3095 3256
 	<body>
@@ -3097,16 +3258,18 @@  discard block
 block discarded – undo
3097 3258
 		', $txt['template_parse_error_message'], '
3098 3259
 	</body>
3099 3260
 </html>';
3100
-		else
3261
+		} else
3101 3262
 		{
3102 3263
 			require_once($sourcedir . '/Subs-Package.php');
3103 3264
 
3104 3265
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3105 3266
 			$error_array = error_get_last();
3106
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3107
-				$error = $error_array['message'];
3108
-			if (empty($error))
3109
-				$error = $txt['template_parse_errmsg'];
3267
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3268
+							$error = $error_array['message'];
3269
+			}
3270
+			if (empty($error)) {
3271
+							$error = $txt['template_parse_errmsg'];
3272
+			}
3110 3273
 
3111 3274
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3112 3275
 
@@ -3117,11 +3280,12 @@  discard block
 block discarded – undo
3117 3280
 		<h3>', $txt['template_parse_error'], '</h3>
3118 3281
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3119 3282
 
3120
-			if (!empty($error))
3121
-				echo '
3283
+			if (!empty($error)) {
3284
+							echo '
3122 3285
 		<hr>
3123 3286
 
3124 3287
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3288
+			}
3125 3289
 
3126 3290
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3127 3291
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3131,10 +3295,11 @@  discard block
 block discarded – undo
3131 3295
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3132 3296
 
3133 3297
 				// Fix the PHP code stuff...
3134
-				if (!isBrowser('gecko'))
3135
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3136
-				else
3137
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3298
+				if (!isBrowser('gecko')) {
3299
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3300
+				} else {
3301
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3302
+				}
3138 3303
 
3139 3304
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3140 3305
 				$j = -1;
@@ -3142,8 +3307,9 @@  discard block
 block discarded – undo
3142 3307
 				{
3143 3308
 					$j++;
3144 3309
 
3145
-					if (substr_count($line, '<br>') == 0)
3146
-						continue;
3310
+					if (substr_count($line, '<br>') == 0) {
3311
+											continue;
3312
+					}
3147 3313
 
3148 3314
 					$n = substr_count($line, '<br>');
3149 3315
 					for ($i = 0; $i < $n; $i++)
@@ -3162,38 +3328,42 @@  discard block
 block discarded – undo
3162 3328
 				// Figure out what the color coding was before...
3163 3329
 				$line = max($match[1] - 9, 1);
3164 3330
 				$last_line = '';
3165
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3166
-					if (strpos($data2[$line2], '<') !== false)
3331
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3332
+									if (strpos($data2[$line2], '<') !== false)
3167 3333
 					{
3168 3334
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3169 3335
 							$last_line = $color_match[1];
3336
+				}
3170 3337
 						break;
3171 3338
 					}
3172 3339
 
3173 3340
 				// Show the relevant lines...
3174 3341
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3175 3342
 				{
3176
-					if ($line == $match[1])
3177
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3343
+					if ($line == $match[1]) {
3344
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3345
+					}
3178 3346
 
3179 3347
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3180
-					if (isset($data2[$line]) && $data2[$line] != '')
3181
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3348
+					if (isset($data2[$line]) && $data2[$line] != '') {
3349
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3350
+					}
3182 3351
 
3183 3352
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3184 3353
 					{
3185 3354
 						$last_line = $color_match[1];
3186 3355
 						echo '</', substr($last_line, 1, 4), '>';
3356
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3357
+											$last_line = '';
3358
+					} elseif ($last_line != '' && $data2[$line] != '') {
3359
+											echo '</', substr($last_line, 1, 4), '>';
3187 3360
 					}
3188
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3189
-						$last_line = '';
3190
-					elseif ($last_line != '' && $data2[$line] != '')
3191
-						echo '</', substr($last_line, 1, 4), '>';
3192 3361
 
3193
-					if ($line == $match[1])
3194
-						echo '</pre></div><pre style="margin: 0;">';
3195
-					else
3196
-						echo "\n";
3362
+					if ($line == $match[1]) {
3363
+											echo '</pre></div><pre style="margin: 0;">';
3364
+					} else {
3365
+											echo "\n";
3366
+					}
3197 3367
 				}
3198 3368
 
3199 3369
 				echo '</pre></div>';
@@ -3217,8 +3387,9 @@  discard block
 block discarded – undo
3217 3387
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3218 3388
 
3219 3389
 	// Figure out what type of database we are using.
3220
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3221
-		$db_type = 'mysql';
3390
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3391
+			$db_type = 'mysql';
3392
+	}
3222 3393
 
3223 3394
 	// Load the file for the database.
3224 3395
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3226,8 +3397,9 @@  discard block
 block discarded – undo
3226 3397
 	$db_options = array();
3227 3398
 
3228 3399
 	// Add in the port if needed
3229
-	if (!empty($db_port))
3230
-		$db_options['port'] = $db_port;
3400
+	if (!empty($db_port)) {
3401
+			$db_options['port'] = $db_port;
3402
+	}
3231 3403
 
3232 3404
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3233 3405
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3246,13 +3418,15 @@  discard block
 block discarded – undo
3246 3418
 	}
3247 3419
 
3248 3420
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3249
-	if (!$db_connection)
3250
-		display_db_error();
3421
+	if (!$db_connection) {
3422
+			display_db_error();
3423
+	}
3251 3424
 
3252 3425
 	// If in SSI mode fix up the prefix.
3253
-	if (SMF == 'SSI')
3254
-		db_fix_prefix($db_prefix, $db_name);
3255
-}
3426
+	if (SMF == 'SSI') {
3427
+			db_fix_prefix($db_prefix, $db_name);
3428
+	}
3429
+	}
3256 3430
 
3257 3431
 /**
3258 3432
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3266,10 +3440,11 @@  discard block
 block discarded – undo
3266 3440
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3267 3441
 
3268 3442
 	// Not overriding this and we have a cacheAPI, send it back.
3269
-	if (empty($overrideCache) && is_object($cacheAPI))
3270
-		return $cacheAPI;
3271
-	elseif (is_null($cacheAPI))
3272
-		$cacheAPI = false;
3443
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3444
+			return $cacheAPI;
3445
+	} elseif (is_null($cacheAPI)) {
3446
+			$cacheAPI = false;
3447
+	}
3273 3448
 
3274 3449
 	// Make sure our class is in session.
3275 3450
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3290,8 +3465,9 @@  discard block
 block discarded – undo
3290 3465
 		if (!$testAPI->isSupported())
3291 3466
 		{
3292 3467
 			// Can we save ourselves?
3293
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3294
-				return loadCacheAccelerator(null, false);
3468
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3469
+							return loadCacheAccelerator(null, false);
3470
+			}
3295 3471
 			return false;
3296 3472
 		}
3297 3473
 
@@ -3303,9 +3479,9 @@  discard block
 block discarded – undo
3303 3479
 		{
3304 3480
 			$cacheAPI = $testAPI;
3305 3481
 			return $cacheAPI;
3482
+		} else {
3483
+					return $testAPI;
3306 3484
 		}
3307
-		else
3308
-			return $testAPI;
3309 3485
 	}
3310 3486
 }
3311 3487
 
@@ -3325,8 +3501,9 @@  discard block
 block discarded – undo
3325 3501
 
3326 3502
 	// @todo Why are we doing this if caching is disabled?
3327 3503
 
3328
-	if (function_exists('call_integration_hook'))
3329
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3504
+	if (function_exists('call_integration_hook')) {
3505
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3506
+	}
3330 3507
 
3331 3508
 	/* Refresh the cache if either:
3332 3509
 		1. Caching is disabled.
@@ -3340,16 +3517,19 @@  discard block
 block discarded – undo
3340 3517
 		require_once($sourcedir . '/' . $file);
3341 3518
 		$cache_block = call_user_func_array($function, $params);
3342 3519
 
3343
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3344
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3520
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3521
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3522
+		}
3345 3523
 	}
3346 3524
 
3347 3525
 	// Some cached data may need a freshening up after retrieval.
3348
-	if (!empty($cache_block['post_retri_eval']))
3349
-		eval($cache_block['post_retri_eval']);
3526
+	if (!empty($cache_block['post_retri_eval'])) {
3527
+			eval($cache_block['post_retri_eval']);
3528
+	}
3350 3529
 
3351
-	if (function_exists('call_integration_hook'))
3352
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3530
+	if (function_exists('call_integration_hook')) {
3531
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3532
+	}
3353 3533
 
3354 3534
 	return $cache_block['data'];
3355 3535
 }
@@ -3376,8 +3556,9 @@  discard block
 block discarded – undo
3376 3556
 	global $smcFunc, $cache_enable, $cacheAPI;
3377 3557
 	global $cache_hits, $cache_count, $db_show_debug;
3378 3558
 
3379
-	if (empty($cache_enable) || empty($cacheAPI))
3380
-		return;
3559
+	if (empty($cache_enable) || empty($cacheAPI)) {
3560
+			return;
3561
+	}
3381 3562
 
3382 3563
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3383 3564
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3390,12 +3571,14 @@  discard block
 block discarded – undo
3390 3571
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3391 3572
 	$cacheAPI->putData($key, $value, $ttl);
3392 3573
 
3393
-	if (function_exists('call_integration_hook'))
3394
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3574
+	if (function_exists('call_integration_hook')) {
3575
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3576
+	}
3395 3577
 
3396
-	if (isset($db_show_debug) && $db_show_debug === true)
3397
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3398
-}
3578
+	if (isset($db_show_debug) && $db_show_debug === true) {
3579
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3580
+	}
3581
+	}
3399 3582
 
3400 3583
 /**
3401 3584
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3411,8 +3594,9 @@  discard block
 block discarded – undo
3411 3594
 	global $smcFunc, $cache_enable, $cacheAPI;
3412 3595
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3413 3596
 
3414
-	if (empty($cache_enable) || empty($cacheAPI))
3415
-		return;
3597
+	if (empty($cache_enable) || empty($cacheAPI)) {
3598
+			return;
3599
+	}
3416 3600
 
3417 3601
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3418 3602
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3432,16 +3616,18 @@  discard block
 block discarded – undo
3432 3616
 
3433 3617
 		if (empty($value))
3434 3618
 		{
3435
-			if (!is_array($cache_misses))
3436
-				$cache_misses = array();
3619
+			if (!is_array($cache_misses)) {
3620
+							$cache_misses = array();
3621
+			}
3437 3622
 
3438 3623
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3439 3624
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3440 3625
 		}
3441 3626
 	}
3442 3627
 
3443
-	if (function_exists('call_integration_hook') && isset($value))
3444
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3628
+	if (function_exists('call_integration_hook') && isset($value)) {
3629
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3630
+	}
3445 3631
 
3446 3632
 	return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3447 3633
 }
@@ -3463,8 +3649,9 @@  discard block
 block discarded – undo
3463 3649
 	global $cacheAPI;
3464 3650
 
3465 3651
 	// If we can't get to the API, can't do this.
3466
-	if (empty($cacheAPI))
3467
-		return;
3652
+	if (empty($cacheAPI)) {
3653
+			return;
3654
+	}
3468 3655
 
3469 3656
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3470 3657
 	$cacheAPI->cleanCache($type);
@@ -3489,8 +3676,9 @@  discard block
 block discarded – undo
3489 3676
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret, $user_info;
3490 3677
 
3491 3678
 	// Come on!
3492
-	if (empty($data))
3493
-		return array();
3679
+	if (empty($data)) {
3680
+			return array();
3681
+	}
3494 3682
 
3495 3683
 	// Set a nice default var.
3496 3684
 	$image = '';
@@ -3498,11 +3686,11 @@  discard block
 block discarded – undo
3498 3686
 	// Gravatar has been set as mandatory!
3499 3687
 	if (!empty($modSettings['gravatarOverride']))
3500 3688
 	{
3501
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3502
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3503
-
3504
-		else if (!empty($data['email']))
3505
-			$image = get_gravatar_url($data['email']);
3689
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3690
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3691
+		} else if (!empty($data['email'])) {
3692
+					$image = get_gravatar_url($data['email']);
3693
+		}
3506 3694
 	}
3507 3695
 
3508 3696
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3514,54 +3702,60 @@  discard block
 block discarded – undo
3514 3702
 			// Gravatar.
3515 3703
 			if (stristr($data['avatar'], 'gravatar://'))
3516 3704
 			{
3517
-				if ($data['avatar'] == 'gravatar://')
3518
-					$image = get_gravatar_url($data['email']);
3519
-
3520
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3521
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3705
+				if ($data['avatar'] == 'gravatar://') {
3706
+									$image = get_gravatar_url($data['email']);
3707
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3708
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3709
+				}
3522 3710
 			}
3523 3711
 
3524 3712
 			// External url.
3525 3713
 			else
3526 3714
 			{
3527 3715
 				// Using ssl?
3528
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
3529
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3716
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
3717
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3718
+				}
3530 3719
 
3531 3720
 				// Just a plain external url.
3532
-				else
3533
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3721
+				else {
3722
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3723
+				}
3534 3724
 			}
3535 3725
 		}
3536 3726
 
3537 3727
 		// Perhaps this user has an attachment as avatar...
3538
-		else if (!empty($data['filename']))
3539
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3728
+		else if (!empty($data['filename'])) {
3729
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3730
+		}
3540 3731
 
3541 3732
 		// Right... no avatar... use our default image.
3542
-		else
3543
-			$image = $modSettings['avatar_url'] . '/default.png';
3733
+		else {
3734
+					$image = $modSettings['avatar_url'] . '/default.png';
3735
+		}
3544 3736
 	}
3545 3737
 
3546 3738
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3547 3739
 
3548 3740
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3549
-	if (!empty($image))
3550
-		return array(
3741
+	if (!empty($image)) {
3742
+			return array(
3551 3743
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3552 3744
 			'image' => '<img class="avatar" src="' . $image . '" />',
3553 3745
 			'href' => $image,
3554 3746
 			'url' => $image,
3555 3747
 		);
3748
+	}
3556 3749
 
3557 3750
 	// Fallback to make life easier for everyone...
3558
-	else
3559
-		return array(
3751
+	else {
3752
+			return array(
3560 3753
 			'name' => '',
3561 3754
 			'image' => '',
3562 3755
 			'href' => '',
3563 3756
 			'url' => '',
3564 3757
 		);
3565
-}
3758
+	}
3759
+	}
3566 3760
 
3567 3761
 ?>
3568 3762
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 /**
501 501
  * Returns the amount of affected rows for a query.
502 502
  *
503
- * @param mixed $result
503
+ * @param resource|null $result
504 504
  *
505 505
  * @return int
506 506
  *
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
  *
870 870
  * @param string $db_name The database name
871 871
  * @param resource $db_connection The database connection
872
- * @return true Always returns true
872
+ * @return boolean Always returns true
873 873
  */
874 874
 function smf_db_select_db($db_name, $db_connection)
875 875
 {
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -199,22 +199,22 @@  discard block
 block discarded – undo
199 199
 
200 200
 		case 'date':
201 201
 			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
202
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
202
+				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]) . '::date';
203 203
 			else
204 204
 				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
205 205
 		break;
206 206
 
207 207
 		case 'time':
208 208
 			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
209
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
209
+				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]) . '::time';
210 210
 			else
211 211
 				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
212 212
 		break;
213 213
 
214 214
 		case 'datetime':
215 215
 			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
216
-				return 'to_timestamp('.
217
-					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
216
+				return 'to_timestamp(' .
217
+					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) .
218 218
 					',\'YYYY-MM-DD HH24:MI:SS\')';
219 219
 			else
220 220
 				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 		$old_pos = 0;
425 425
 		$pos = -1;
426 426
 		// Remove the string escape for better runtime
427
-		$db_string_1 = str_replace('\'\'','',$db_string);
427
+		$db_string_1 = str_replace('\'\'', '', $db_string);
428 428
 		while (true)
429 429
 		{
430 430
 			$pos = strpos($db_string_1, '\'', $pos + 1);
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
 	if (!empty($keys) && (count($keys) > 0) && $returnmode > 0)
803 803
 	{
804 804
 		// we only take the first key
805
-		$returning = ' RETURNING '.$keys[0];
805
+		$returning = ' RETURNING ' . $keys[0];
806 806
 		$with_returning = true;
807 807
 	}
808 808
 
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
 			INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '")
834 834
 			VALUES
835 835
 				' . implode(',
836
-				', $insertRows).$replace.$returning,
836
+				', $insertRows) . $replace . $returning,
837 837
 			array(
838 838
 				'security_override' => true,
839 839
 				'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors',
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 			if ($returnmode === 2)
847 847
 				$return_var = array();
848 848
 
849
-			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
849
+			while (($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
850 850
 			{
851 851
 				if (is_numeric($row[0])) // try to emulate mysql limitation
852 852
 				{
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
  */
1010 1010
 function smf_db_custom_order($field, $array_values, $desc = false)
1011 1011
 {
1012
-	$return = 'CASE '. $field . ' ';
1012
+	$return = 'CASE ' . $field . ' ';
1013 1013
 	$count = count($array_values);
1014 1014
 	$then = ($desc ? ' THEN -' : ' THEN ');
1015 1015
 
Please login to merge, or discard this patch.
Braces   +229 added lines, -169 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Maps the implementations in this file (smf_db_function_name)
@@ -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']))
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_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',
@@ -64,11 +65,13 @@  discard block
 block discarded – undo
64 65
 			'db_error_insert'			=> 'smf_db_error_insert',
65 66
 			'db_custom_order'			=> 'smf_db_custom_order',
66 67
 		);
68
+	}
67 69
 
68
-	if (!empty($db_options['persist']))
69
-		$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
70
-	else
71
-		$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
70
+	if (!empty($db_options['persist'])) {
71
+			$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
72
+	} else {
73
+			$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
74
+	}
72 75
 
73 76
 	// Something's wrong, show an error if its fatal (which we assume it is)
74 77
 	if (!$connection)
@@ -76,8 +79,7 @@  discard block
 block discarded – undo
76 79
 		if (!empty($db_options['non_fatal']))
77 80
 		{
78 81
 			return null;
79
-		}
80
-		else
82
+		} else
81 83
 		{
82 84
 			display_db_error();
83 85
 		}
@@ -128,31 +130,38 @@  discard block
 block discarded – undo
128 130
 
129 131
 	list ($values, $connection) = $db_callback;
130 132
 
131
-	if ($matches[1] === 'db_prefix')
132
-		return $db_prefix;
133
+	if ($matches[1] === 'db_prefix') {
134
+			return $db_prefix;
135
+	}
133 136
 
134
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
135
-		return $user_info[$matches[1]];
137
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
138
+			return $user_info[$matches[1]];
139
+	}
136 140
 
137
-	if ($matches[1] === 'empty')
138
-		return '\'\'';
141
+	if ($matches[1] === 'empty') {
142
+			return '\'\'';
143
+	}
139 144
 
140
-	if (!isset($matches[2]))
141
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
145
+	if (!isset($matches[2])) {
146
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
147
+	}
142 148
 
143
-	if ($matches[1] === 'literal')
144
-		return '\'' . pg_escape_string($matches[2]) . '\'';
149
+	if ($matches[1] === 'literal') {
150
+			return '\'' . pg_escape_string($matches[2]) . '\'';
151
+	}
145 152
 
146
-	if (!isset($values[$matches[2]]))
147
-		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__);
153
+	if (!isset($values[$matches[2]])) {
154
+			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__);
155
+	}
148 156
 
149 157
 	$replacement = $values[$matches[2]];
150 158
 
151 159
 	switch ($matches[1])
152 160
 	{
153 161
 		case 'int':
154
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
155
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
162
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
163
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
164
+			}
156 165
 			return (string) (int) $replacement;
157 166
 		break;
158 167
 
@@ -164,65 +173,73 @@  discard block
 block discarded – undo
164 173
 		case 'array_int':
165 174
 			if (is_array($replacement))
166 175
 			{
167
-				if (empty($replacement))
168
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
176
+				if (empty($replacement)) {
177
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
178
+				}
169 179
 
170 180
 				foreach ($replacement as $key => $value)
171 181
 				{
172
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
173
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
182
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
183
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
184
+					}
174 185
 
175 186
 					$replacement[$key] = (string) (int) $value;
176 187
 				}
177 188
 
178 189
 				return implode(', ', $replacement);
190
+			} else {
191
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
179 192
 			}
180
-			else
181
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
182 193
 
183 194
 		break;
184 195
 
185 196
 		case 'array_string':
186 197
 			if (is_array($replacement))
187 198
 			{
188
-				if (empty($replacement))
189
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
199
+				if (empty($replacement)) {
200
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
201
+				}
190 202
 
191
-				foreach ($replacement as $key => $value)
192
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
203
+				foreach ($replacement as $key => $value) {
204
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
205
+				}
193 206
 
194 207
 				return implode(', ', $replacement);
208
+			} else {
209
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
195 210
 			}
196
-			else
197
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
198 211
 		break;
199 212
 
200 213
 		case 'date':
201
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
202
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
203
-			else
204
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
214
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
215
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
216
+			} else {
217
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218
+			}
205 219
 		break;
206 220
 
207 221
 		case 'time':
208
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
209
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
210
-			else
211
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
223
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
224
+			} else {
225
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
226
+			}
212 227
 		break;
213 228
 
214 229
 		case 'datetime':
215
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
216
-				return 'to_timestamp('.
230
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
231
+							return 'to_timestamp('.
217 232
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
218 233
 					',\'YYYY-MM-DD HH24:MI:SS\')';
219
-			else
220
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
234
+			} else {
235
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
236
+			}
221 237
 		break;
222 238
 
223 239
 		case 'float':
224
-			if (!is_numeric($replacement))
225
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240
+			if (!is_numeric($replacement)) {
241
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
242
+			}
226 243
 			return (string) (float) $replacement;
227 244
 		break;
228 245
 
@@ -235,31 +252,36 @@  discard block
 block discarded – undo
235 252
 		break;
236 253
 
237 254
 		case 'inet':
238
-			if ($replacement == 'null' || $replacement == '')
239
-				return 'null';
240
-			if (inet_pton($replacement) === false)
241
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
255
+			if ($replacement == 'null' || $replacement == '') {
256
+							return 'null';
257
+			}
258
+			if (inet_pton($replacement) === false) {
259
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
260
+			}
242 261
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
243 262
 
244 263
 		case 'array_inet':
245 264
 			if (is_array($replacement))
246 265
 			{
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__);
266
+				if (empty($replacement)) {
267
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
268
+				}
249 269
 
250 270
 				foreach ($replacement as $key => $value)
251 271
 				{
252
-					if ($replacement == 'null' || $replacement == '')
253
-						$replacement[$key] = 'null';
254
-					if (!isValidIP($value))
255
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
272
+					if ($replacement == 'null' || $replacement == '') {
273
+											$replacement[$key] = 'null';
274
+					}
275
+					if (!isValidIP($value)) {
276
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
277
+					}
256 278
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
257 279
 				}
258 280
 
259 281
 				return implode(', ', $replacement);
282
+			} else {
283
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
260 284
 			}
261
-			else
262
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
263 285
 		break;
264 286
 
265 287
 		default:
@@ -350,14 +372,16 @@  discard block
 block discarded – undo
350 372
 		),
351 373
 	);
352 374
 
353
-	if (isset($replacements[$identifier]))
354
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
375
+	if (isset($replacements[$identifier])) {
376
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
377
+	}
355 378
 
356 379
 	// Limits need to be a little different.
357 380
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
358 381
 
359
-	if (trim($db_string) == '')
360
-		return false;
382
+	if (trim($db_string) == '') {
383
+			return false;
384
+	}
361 385
 
362 386
 	// Comments that are allowed in a query are preg_removed.
363 387
 	static $allowed_comments_from = array(
@@ -377,8 +401,9 @@  discard block
 block discarded – undo
377 401
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
378 402
 	$db_replace_result = 0;
379 403
 
380
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
381
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
404
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
405
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
406
+	}
382 407
 
383 408
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
384 409
 	{
@@ -403,17 +428,18 @@  discard block
 block discarded – undo
403 428
 		while (true)
404 429
 		{
405 430
 			$pos = strpos($db_string_1, '\'', $pos + 1);
406
-			if ($pos === false)
407
-				break;
431
+			if ($pos === false) {
432
+							break;
433
+			}
408 434
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
409 435
 
410 436
 			while (true)
411 437
 			{
412 438
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
413 439
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
414
-				if ($pos1 === false)
415
-					break;
416
-				elseif ($pos2 === false || $pos2 > $pos1)
440
+				if ($pos1 === false) {
441
+									break;
442
+				} elseif ($pos2 === false || $pos2 > $pos1)
417 443
 				{
418 444
 					$pos = $pos1;
419 445
 					break;
@@ -429,16 +455,19 @@  discard block
 block discarded – undo
429 455
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
430 456
 
431 457
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
432
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
433
-			$fail = true;
458
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
459
+					$fail = true;
460
+		}
434 461
 		// Trying to change passwords, slow us down, or something?
435
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
436
-			$fail = true;
437
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
438
-			$fail = true;
462
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
463
+					$fail = true;
464
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
465
+					$fail = true;
466
+		}
439 467
 
440
-		if (!empty($fail) && function_exists('log_error'))
441
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
468
+		if (!empty($fail) && function_exists('log_error')) {
469
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
470
+		}
442 471
 	}
443 472
 
444 473
 	// Set optimize stuff
@@ -465,8 +494,9 @@  discard block
 block discarded – undo
465 494
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
466 495
 
467 496
 		// Initialize $db_cache if not already initialized.
468
-		if (!isset($db_cache))
469
-			$db_cache = array();
497
+		if (!isset($db_cache)) {
498
+					$db_cache = array();
499
+		}
470 500
 
471 501
 		if (!empty($_SESSION['debug_redirect']))
472 502
 		{
@@ -484,12 +514,14 @@  discard block
 block discarded – undo
484 514
 
485 515
 	$db_last_result = @pg_query($connection, $db_string);
486 516
 
487
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
488
-		$db_last_result = smf_db_error($db_string, $connection);
517
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
518
+			$db_last_result = smf_db_error($db_string, $connection);
519
+	}
489 520
 
490 521
 	// Debugging.
491
-	if (isset($db_show_debug) && $db_show_debug === true)
492
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
522
+	if (isset($db_show_debug) && $db_show_debug === true) {
523
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
524
+	}
493 525
 
494 526
 	return $db_last_result;
495 527
 }
@@ -506,10 +538,11 @@  discard block
 block discarded – undo
506 538
 {
507 539
 	global $db_last_result, $db_replace_result;
508 540
 
509
-	if ($db_replace_result)
510
-		return $db_replace_result;
511
-	elseif ($result === null && !$db_last_result)
512
-		return 0;
541
+	if ($db_replace_result) {
542
+			return $db_replace_result;
543
+	} elseif ($result === null && !$db_last_result) {
544
+			return 0;
545
+	}
513 546
 
514 547
 	return pg_affected_rows($result === null ? $db_last_result : $result);
515 548
 }
@@ -533,8 +566,9 @@  discard block
 block discarded – undo
533 566
 		array(
534 567
 		)
535 568
 	);
536
-	if (!$request)
537
-		return false;
569
+	if (!$request) {
570
+			return false;
571
+	}
538 572
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
539 573
 	$smcFunc['db_free_result']($request);
540 574
 
@@ -555,12 +589,13 @@  discard block
 block discarded – undo
555 589
 	// Decide which connection to use
556 590
 	$connection = $connection === null ? $db_connection : $connection;
557 591
 
558
-	if ($type == 'begin')
559
-		return @pg_query($connection, 'BEGIN');
560
-	elseif ($type == 'rollback')
561
-		return @pg_query($connection, 'ROLLBACK');
562
-	elseif ($type == 'commit')
563
-		return @pg_query($connection, 'COMMIT');
592
+	if ($type == 'begin') {
593
+			return @pg_query($connection, 'BEGIN');
594
+	} elseif ($type == 'rollback') {
595
+			return @pg_query($connection, 'ROLLBACK');
596
+	} elseif ($type == 'commit') {
597
+			return @pg_query($connection, 'COMMIT');
598
+	}
564 599
 
565 600
 	return false;
566 601
 }
@@ -588,19 +623,22 @@  discard block
 block discarded – undo
588 623
 	$query_error = @pg_last_error($connection);
589 624
 
590 625
 	// Log the error.
591
-	if (function_exists('log_error'))
592
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
626
+	if (function_exists('log_error')) {
627
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
628
+	}
593 629
 
594 630
 	// Nothing's defined yet... just die with it.
595
-	if (empty($context) || empty($txt))
596
-		die($query_error);
631
+	if (empty($context) || empty($txt)) {
632
+			die($query_error);
633
+	}
597 634
 
598 635
 	// Show an error message, if possible.
599 636
 	$context['error_title'] = $txt['database_error'];
600
-	if (allowedTo('admin_forum'))
601
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
602
-	else
603
-		$context['error_message'] = $txt['try_again'];
637
+	if (allowedTo('admin_forum')) {
638
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
639
+	} else {
640
+			$context['error_message'] = $txt['try_again'];
641
+	}
604 642
 
605 643
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
606 644
 	{
@@ -622,12 +660,14 @@  discard block
 block discarded – undo
622 660
 {
623 661
 	global $db_row_count;
624 662
 
625
-	if ($counter !== false)
626
-		return pg_fetch_row($request, $counter);
663
+	if ($counter !== false) {
664
+			return pg_fetch_row($request, $counter);
665
+	}
627 666
 
628 667
 	// Reset the row counter...
629
-	if (!isset($db_row_count[(int) $request]))
630
-		$db_row_count[(int) $request] = 0;
668
+	if (!isset($db_row_count[(int) $request])) {
669
+			$db_row_count[(int) $request] = 0;
670
+	}
631 671
 
632 672
 	// Return the right row.
633 673
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -644,12 +684,14 @@  discard block
 block discarded – undo
644 684
 {
645 685
 	global $db_row_count;
646 686
 
647
-	if ($counter !== false)
648
-		return pg_fetch_assoc($request, $counter);
687
+	if ($counter !== false) {
688
+			return pg_fetch_assoc($request, $counter);
689
+	}
649 690
 
650 691
 	// Reset the row counter...
651
-	if (!isset($db_row_count[(int) $request]))
652
-		$db_row_count[(int) $request] = 0;
692
+	if (!isset($db_row_count[(int) $request])) {
693
+			$db_row_count[(int) $request] = 0;
694
+	}
653 695
 
654 696
 	// Return the right row.
655 697
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -702,11 +744,13 @@  discard block
 block discarded – undo
702 744
 
703 745
 	$replace = '';
704 746
 
705
-	if (empty($data))
706
-		return;
747
+	if (empty($data)) {
748
+			return;
749
+	}
707 750
 
708
-	if (!is_array($data[array_rand($data)]))
709
-		$data = array($data);
751
+	if (!is_array($data[array_rand($data)])) {
752
+			$data = array($data);
753
+	}
710 754
 
711 755
 	// Replace the prefix holder with the actual prefix.
712 756
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -725,11 +769,13 @@  discard block
 block discarded – undo
725 769
 			//pg 9.5 got replace support
726 770
 			$pg_version = $smcFunc['db_get_version']();
727 771
 			// if we got a Beta Version
728
-			if (stripos($pg_version, 'beta') !== false)
729
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
772
+			if (stripos($pg_version, 'beta') !== false) {
773
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
774
+			}
730 775
 			// or RC
731
-			if (stripos($pg_version, 'rc') !== false)
732
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
776
+			if (stripos($pg_version, 'rc') !== false) {
777
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
778
+			}
733 779
 
734 780
 			$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
735 781
 		}
@@ -748,32 +794,35 @@  discard block
 block discarded – undo
748 794
 					$key_str .= ($count_pk > 0 ? ',' : '');
749 795
 					$key_str .= $columnName;
750 796
 					$count_pk++;
751
-				}
752
-				else if ($method == 'replace') //normal field
797
+				} else if ($method == 'replace') {
798
+					//normal field
753 799
 				{
754 800
 					$col_str .= ($count > 0 ? ',' : '');
801
+				}
755 802
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
756 803
 					$count++;
757 804
 				}
758 805
 			}
759
-			if ($method == 'replace')
760
-				$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
761
-			else
762
-				$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
763
-		}
764
-		else if ($method == 'replace')
806
+			if ($method == 'replace') {
807
+							$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
808
+			} else {
809
+							$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
810
+			}
811
+		} else if ($method == 'replace')
765 812
 		{
766 813
 			foreach ($columns as $columnName => $type)
767 814
 			{
768 815
 				// Are we restricting the length?
769
-				if (strpos($type, 'string-') !== false)
770
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
771
-				else
772
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
816
+				if (strpos($type, 'string-') !== false) {
817
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
818
+				} else {
819
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
820
+				}
773 821
 
774 822
 				// A key? That's what we were looking for.
775
-				if (in_array($columnName, $keys))
776
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
823
+				if (in_array($columnName, $keys)) {
824
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
825
+				}
777 826
 				$count++;
778 827
 			}
779 828
 
@@ -809,10 +858,11 @@  discard block
 block discarded – undo
809 858
 		foreach ($columns as $columnName => $type)
810 859
 		{
811 860
 			// Are we restricting the length?
812
-			if (strpos($type, 'string-') !== false)
813
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
814
-			else
815
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
861
+			if (strpos($type, 'string-') !== false) {
862
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
863
+			} else {
864
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
865
+			}
816 866
 		}
817 867
 		$insertData = substr($insertData, 0, -2) . ')';
818 868
 
@@ -821,8 +871,9 @@  discard block
 block discarded – undo
821 871
 
822 872
 		// Here's where the variables are injected to the query.
823 873
 		$insertRows = array();
824
-		foreach ($data as $dataRow)
825
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
874
+		foreach ($data as $dataRow) {
875
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
876
+		}
826 877
 
827 878
 		// Do the insert.
828 879
 		$request = $smcFunc['db_query']('', '
@@ -839,19 +890,21 @@  discard block
 block discarded – undo
839 890
 
840 891
 		if ($with_returning && $request !== false)
841 892
 		{
842
-			if ($returnmode === 2)
843
-				$return_var = array();
893
+			if ($returnmode === 2) {
894
+							$return_var = array();
895
+			}
844 896
 
845 897
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
846 898
 			{
847
-				if (is_numeric($row[0])) // try to emulate mysql limitation
899
+				if (is_numeric($row[0])) {
900
+					// try to emulate mysql limitation
848 901
 				{
849 902
 					if ($returnmode === 1)
850 903
 						$return_var = $row[0];
851
-					elseif ($returnmode === 2)
852
-						$return_var[] = $row[0];
853
-				}
854
-				else
904
+				} elseif ($returnmode === 2) {
905
+											$return_var[] = $row[0];
906
+					}
907
+				} else
855 908
 				{
856 909
 					$with_returning = false;
857 910
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -860,9 +913,10 @@  discard block
 block discarded – undo
860 913
 		}
861 914
 	}
862 915
 
863
-	if ($with_returning && !empty($return_var))
864
-		return $return_var;
865
-}
916
+	if ($with_returning && !empty($return_var)) {
917
+			return $return_var;
918
+	}
919
+	}
866 920
 
867 921
 /**
868 922
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -899,8 +953,9 @@  discard block
 block discarded – undo
899 953
  */
900 954
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
901 955
 {
902
-	if (empty($log_message))
903
-		$log_message = $error_message;
956
+	if (empty($log_message)) {
957
+			$log_message = $error_message;
958
+	}
904 959
 
905 960
 	foreach (debug_backtrace() as $step)
906 961
 	{
@@ -919,12 +974,14 @@  discard block
 block discarded – undo
919 974
 	}
920 975
 
921 976
 	// A special case - we want the file and line numbers for debugging.
922
-	if ($error_type == 'return')
923
-		return array($file, $line);
977
+	if ($error_type == 'return') {
978
+			return array($file, $line);
979
+	}
924 980
 
925 981
 	// Is always a critical error.
926
-	if (function_exists('log_error'))
927
-		log_error($log_message, 'critical', $file, $line);
982
+	if (function_exists('log_error')) {
983
+			log_error($log_message, 'critical', $file, $line);
984
+	}
928 985
 
929 986
 	if (function_exists('fatal_error'))
930 987
 	{
@@ -932,12 +989,12 @@  discard block
 block discarded – undo
932 989
 
933 990
 		// Cannot continue...
934 991
 		exit;
992
+	} elseif ($error_type) {
993
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
994
+	} else {
995
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
996
+	}
935 997
 	}
936
-	elseif ($error_type)
937
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
938
-	else
939
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
940
-}
941 998
 
942 999
 /**
943 1000
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -954,10 +1011,11 @@  discard block
 block discarded – undo
954 1011
 		'\\' => '\\\\',
955 1012
 	);
956 1013
 
957
-	if ($translate_human_wildcards)
958
-		$replacements += array(
1014
+	if ($translate_human_wildcards) {
1015
+			$replacements += array(
959 1016
 			'*' => '%',
960 1017
 		);
1018
+	}
961 1019
 
962 1020
 	return strtr($string, $replacements);
963 1021
 }
@@ -985,11 +1043,12 @@  discard block
 block discarded – undo
985 1043
 	global  $db_prefix, $db_connection;
986 1044
 	static $pg_error_data_prep;
987 1045
 
988
-	if (empty($pg_error_data_prep))
989
-			$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
1046
+	if (empty($pg_error_data_prep)) {
1047
+				$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
990 1048
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line)
991 1049
 													VALUES(		$1,		$2,		$3, $4, 	$5,		$6,			$7,		$8,	$9)'
992 1050
 			);
1051
+	}
993 1052
 
994 1053
 	pg_execute($db_connection, 'smf_log_errors', $error_array);
995 1054
 }
@@ -1009,8 +1068,9 @@  discard block
 block discarded – undo
1009 1068
 	$count = count($array_values);
1010 1069
 	$then = ($desc ? ' THEN -' : ' THEN ');
1011 1070
 
1012
-	for ($i = 0; $i < $count; $i++)
1013
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1071
+	for ($i = 0; $i < $count; $i++) {
1072
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1073
+	}
1014 1074
 
1015 1075
 	$return .= 'END';
1016 1076
 	return $return;
Please login to merge, or discard this patch.
Sources/ManageSettings.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1334,7 +1334,7 @@  discard block
 block discarded – undo
1334 1334
 					'class' => 'centercol',
1335 1335
 				),
1336 1336
 				'data' => array(
1337
-					'function' => function ($rowData)
1337
+					'function' => function($rowData)
1338 1338
 					{
1339 1339
 						$isChecked = $rowData['disabled'] ? '' : ' checked';
1340 1340
 						$onClickHandler = $rowData['can_show_register'] ? sprintf(' onclick="document.getElementById(\'reg_%1$s\').disabled = !this.checked;"', $rowData['id']) : '';
@@ -1350,7 +1350,7 @@  discard block
 block discarded – undo
1350 1350
 					'class' => 'centercol',
1351 1351
 				),
1352 1352
 				'data' => array(
1353
-					'function' => function ($rowData)
1353
+					'function' => function($rowData)
1354 1354
 					{
1355 1355
 						$isChecked = $rowData['on_register'] && !$rowData['disabled'] ? ' checked' : '';
1356 1356
 						$isDisabled = $rowData['can_show_register'] ? '' : ' disabled';
@@ -1397,15 +1397,15 @@  discard block
 block discarded – undo
1397 1397
 					'value' => $txt['custom_profile_fieldorder'],
1398 1398
 				),
1399 1399
 				'data' => array(
1400
-					'function' => function ($rowData) use ($context, $txt, $scripturl)
1400
+					'function' => function($rowData) use ($context, $txt, $scripturl)
1401 1401
 					{
1402
-						$return = '<p class="centertext bold_text">'. $rowData['field_order'] .'<br>';
1402
+						$return = '<p class="centertext bold_text">' . $rowData['field_order'] . '<br>';
1403 1403
 
1404 1404
 						if ($rowData['field_order'] > 1)
1405
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1405
+							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="' . $txt['custom_edit_order_move'] . ' ' . $txt['custom_edit_order_up'] . '"></span></a>';
1406 1406
 
1407 1407
 						if ($rowData['field_order'] < $context['custFieldsMaxOrder'])
1408
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1408
+							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="' . $txt['custom_edit_order_move'] . ' ' . $txt['custom_edit_order_down'] . '"></span></a>';
1409 1409
 
1410 1410
 						$return .= '</p>';
1411 1411
 
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
 					'value' => $txt['custom_profile_fieldname'],
1424 1424
 				),
1425 1425
 				'data' => array(
1426
-					'function' => function ($rowData) use ($scripturl)
1426
+					'function' => function($rowData) use ($scripturl)
1427 1427
 					{
1428 1428
 						return sprintf('<a href="%1$s?action=admin;area=featuresettings;sa=profileedit;fid=%2$d">%3$s</a><div class="smalltext">%4$s</div>', $scripturl, $rowData['id_field'], $rowData['field_name'], $rowData['field_desc']);
1429 1429
 					},
@@ -1439,7 +1439,7 @@  discard block
 block discarded – undo
1439 1439
 					'value' => $txt['custom_profile_fieldtype'],
1440 1440
 				),
1441 1441
 				'data' => array(
1442
-					'function' => function ($rowData) use ($txt)
1442
+					'function' => function($rowData) use ($txt)
1443 1443
 					{
1444 1444
 						$textKey = sprintf('custom_profile_type_%1$s', $rowData['field_type']);
1445 1445
 						return isset($txt[$textKey]) ? $txt[$textKey] : $textKey;
@@ -1457,7 +1457,7 @@  discard block
 block discarded – undo
1457 1457
 					'value' => $txt['custom_profile_active'],
1458 1458
 				),
1459 1459
 				'data' => array(
1460
-					'function' => function ($rowData) use ($txt)
1460
+					'function' => function($rowData) use ($txt)
1461 1461
 					{
1462 1462
 						return $rowData['active'] ? $txt['yes'] : $txt['no'];
1463 1463
 					},
@@ -1474,7 +1474,7 @@  discard block
 block discarded – undo
1474 1474
 					'value' => $txt['custom_profile_placement'],
1475 1475
 				),
1476 1476
 				'data' => array(
1477
-					'function' => function ($rowData)
1477
+					'function' => function($rowData)
1478 1478
 					{
1479 1479
 						global $txt, $context;
1480 1480
 
@@ -1709,7 +1709,7 @@  discard block
 block discarded – undo
1709 1709
 			redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler
1710 1710
 
1711 1711
 		// All good, proceed.
1712
-		$smcFunc['db_query']('','
1712
+		$smcFunc['db_query']('', '
1713 1713
 			UPDATE {db_prefix}custom_fields
1714 1714
 			SET field_order = {int:old_order}
1715 1715
 			WHERE field_order = {int:new_order}',
@@ -1718,7 +1718,7 @@  discard block
 block discarded – undo
1718 1718
 				'old_order' => $context['field']['order'],
1719 1719
 			)
1720 1720
 		);
1721
-		$smcFunc['db_query']('','
1721
+		$smcFunc['db_query']('', '
1722 1722
 			UPDATE {db_prefix}custom_fields
1723 1723
 			SET field_order = {int:new_order}
1724 1724
 			WHERE id_field = {int:id_field}',
@@ -1820,7 +1820,7 @@  discard block
 block discarded – undo
1820 1820
 			$smcFunc['db_free_result']($request);
1821 1821
 
1822 1822
 			$unique = false;
1823
-			for ($i = 0; !$unique && $i < 9; $i ++)
1823
+			for ($i = 0; !$unique && $i < 9; $i++)
1824 1824
 			{
1825 1825
 				if (!in_array($col_name, $current_fields))
1826 1826
 					$unique = true;
@@ -1993,7 +1993,7 @@  discard block
 block discarded – undo
1993 1993
 		);
1994 1994
 
1995 1995
 		// Re-arrange the order.
1996
-		$smcFunc['db_query']('','
1996
+		$smcFunc['db_query']('', '
1997 1997
 			UPDATE {db_prefix}custom_fields
1998 1998
 			SET field_order = field_order - 1
1999 1999
 			WHERE field_order > {int:current_order}',
@@ -2257,7 +2257,7 @@  discard block
 block discarded – undo
2257 2257
 	$context['token_check'] = 'noti-admin';
2258 2258
 
2259 2259
 	// Specify our action since we'll want to post back here instead of the profile
2260
-	$context['action'] = 'action=admin;area=featuresettings;sa=alerts;'. $context['session_var'] .'='. $context['session_id'];
2260
+	$context['action'] = 'action=admin;area=featuresettings;sa=alerts;' . $context['session_var'] . '=' . $context['session_id'];
2261 2261
 
2262 2262
 	loadTemplate('Profile');
2263 2263
 	loadLanguage('Profile');
Please login to merge, or discard this patch.
Braces   +273 added lines, -199 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * This function makes sure the requested subaction does exists, if it doesn't, it sets a default action or.
@@ -206,16 +207,18 @@  discard block
 block discarded – undo
206 207
 	{
207 208
 		$all_zones = timezone_identifiers_list();
208 209
 		// Make sure we set the value to the same as the printed value.
209
-		foreach ($all_zones as $zone)
210
-			$config_vars['default_timezone'][2][$zone] = $zone;
210
+		foreach ($all_zones as $zone) {
211
+					$config_vars['default_timezone'][2][$zone] = $zone;
212
+		}
213
+	} else {
214
+			unset($config_vars['default_timezone']);
211 215
 	}
212
-	else
213
-		unset($config_vars['default_timezone']);
214 216
 
215 217
 	call_integration_hook('integrate_modify_basic_settings', array(&$config_vars));
216 218
 
217
-	if ($return_config)
218
-		return $config_vars;
219
+	if ($return_config) {
220
+			return $config_vars;
221
+	}
219 222
 
220 223
 	// Saving?
221 224
 	if (isset($_GET['save']))
@@ -223,8 +226,9 @@  discard block
 block discarded – undo
223 226
 		checkSession();
224 227
 
225 228
 		// Prevent absurd boundaries here - make it a day tops.
226
-		if (isset($_POST['lastActive']))
227
-			$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
229
+		if (isset($_POST['lastActive'])) {
230
+					$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
231
+		}
228 232
 
229 233
 		call_integration_hook('integrate_save_basic_settings');
230 234
 
@@ -269,8 +273,9 @@  discard block
 block discarded – undo
269 273
 
270 274
 	call_integration_hook('integrate_modify_bbc_settings', array(&$config_vars));
271 275
 
272
-	if ($return_config)
273
-		return $config_vars;
276
+	if ($return_config) {
277
+			return $config_vars;
278
+	}
274 279
 
275 280
 	// Setup the template.
276 281
 	require_once($sourcedir . '/ManageServer.php');
@@ -287,13 +292,15 @@  discard block
 block discarded – undo
287 292
 
288 293
 		// Clean up the tags.
289 294
 		$bbcTags = array();
290
-		foreach (parse_bbc(false) as $tag)
291
-			$bbcTags[] = $tag['tag'];
295
+		foreach (parse_bbc(false) as $tag) {
296
+					$bbcTags[] = $tag['tag'];
297
+		}
292 298
 
293
-		if (!isset($_POST['disabledBBC_enabledTags']))
294
-			$_POST['disabledBBC_enabledTags'] = array();
295
-		elseif (!is_array($_POST['disabledBBC_enabledTags']))
296
-			$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
299
+		if (!isset($_POST['disabledBBC_enabledTags'])) {
300
+					$_POST['disabledBBC_enabledTags'] = array();
301
+		} elseif (!is_array($_POST['disabledBBC_enabledTags'])) {
302
+					$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
303
+		}
297 304
 		// Work out what is actually disabled!
298 305
 		$_POST['disabledBBC'] = implode(',', array_diff($bbcTags, $_POST['disabledBBC_enabledTags']));
299 306
 
@@ -337,8 +344,9 @@  discard block
 block discarded – undo
337 344
 
338 345
 	call_integration_hook('integrate_layout_settings', array(&$config_vars));
339 346
 
340
-	if ($return_config)
341
-		return $config_vars;
347
+	if ($return_config) {
348
+			return $config_vars;
349
+	}
342 350
 
343 351
 	// Saving?
344 352
 	if (isset($_GET['save']))
@@ -379,8 +387,9 @@  discard block
 block discarded – undo
379 387
 
380 388
 	call_integration_hook('integrate_likes_settings', array(&$config_vars));
381 389
 
382
-	if ($return_config)
383
-		return $config_vars;
390
+	if ($return_config) {
391
+			return $config_vars;
392
+	}
384 393
 
385 394
 	// Saving?
386 395
 	if (isset($_GET['save']))
@@ -418,8 +427,9 @@  discard block
 block discarded – undo
418 427
 
419 428
 	call_integration_hook('integrate_mentions_settings', array(&$config_vars));
420 429
 
421
-	if ($return_config)
422
-		return $config_vars;
430
+	if ($return_config) {
431
+			return $config_vars;
432
+	}
423 433
 
424 434
 	// Saving?
425 435
 	if (isset($_GET['save']))
@@ -463,8 +473,8 @@  discard block
 block discarded – undo
463 473
 			'enable' => array('check', 'warning_enable'),
464 474
 	);
465 475
 
466
-	if (!empty($modSettings['warning_settings']) && $currently_enabled)
467
-		$config_vars += array(
476
+	if (!empty($modSettings['warning_settings']) && $currently_enabled) {
477
+			$config_vars += array(
468 478
 			'',
469 479
 				array('int', 'warning_watch', 'subtext' => $txt['setting_warning_watch_note'] . ' ' . $txt['zero_to_disable']),
470 480
 				'moderate' => array('int', 'warning_moderate', 'subtext' => $txt['setting_warning_moderate_note'] . ' ' . $txt['zero_to_disable']),
@@ -473,15 +483,18 @@  discard block
 block discarded – undo
473 483
 				'rem2' => array('int', 'warning_decrement', 'subtext' => $txt['setting_warning_decrement_note'] . ' ' . $txt['zero_to_disable']),
474 484
 				array('permissions', 'view_warning'),
475 485
 		);
486
+	}
476 487
 
477 488
 	call_integration_hook('integrate_warning_settings', array(&$config_vars));
478 489
 
479
-	if ($return_config)
480
-		return $config_vars;
490
+	if ($return_config) {
491
+			return $config_vars;
492
+	}
481 493
 
482 494
 	// Cannot use moderation if post moderation is not enabled.
483
-	if (!$modSettings['postmod_active'])
484
-		unset($config_vars['moderate']);
495
+	if (!$modSettings['postmod_active']) {
496
+			unset($config_vars['moderate']);
497
+	}
485 498
 
486 499
 	// Will need the utility functions from here.
487 500
 	require_once($sourcedir . '/ManageServer.php');
@@ -506,16 +519,16 @@  discard block
 block discarded – undo
506 519
 				'warning_watch' => 10,
507 520
 				'warning_mute' => 60,
508 521
 			);
509
-			if ($modSettings['postmod_active'])
510
-				$vars['warning_moderate'] = 35;
522
+			if ($modSettings['postmod_active']) {
523
+							$vars['warning_moderate'] = 35;
524
+			}
511 525
 
512 526
 			foreach ($vars as $var => $value)
513 527
 			{
514 528
 				$config_vars[] = array('int', $var);
515 529
 				$_POST[$var] = $value;
516 530
 			}
517
-		}
518
-		else
531
+		} else
519 532
 		{
520 533
 			$_POST['warning_watch'] = min($_POST['warning_watch'], 100);
521 534
 			$_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0;
@@ -603,8 +616,9 @@  discard block
 block discarded – undo
603 616
 
604 617
 	call_integration_hook('integrate_spam_settings', array(&$config_vars));
605 618
 
606
-	if ($return_config)
607
-		return $config_vars;
619
+	if ($return_config) {
620
+			return $config_vars;
621
+	}
608 622
 
609 623
 	// You need to be an admin to edit settings!
610 624
 	isAllowedTo('admin_forum');
@@ -638,8 +652,9 @@  discard block
 block discarded – undo
638 652
 
639 653
 	if (empty($context['qa_by_lang'][strtr($language, array('-utf8' => ''))]) && !empty($context['question_answers']))
640 654
 	{
641
-		if (empty($context['settings_insert_above']))
642
-			$context['settings_insert_above'] = '';
655
+		if (empty($context['settings_insert_above'])) {
656
+					$context['settings_insert_above'] = '';
657
+		}
643 658
 
644 659
 		$context['settings_insert_above'] .= '<div class="noticebox">' . sprintf($txt['question_not_defined'], $context['languages'][$language]['name']) . '</div>';
645 660
 	}
@@ -682,8 +697,9 @@  discard block
 block discarded – undo
682 697
 		$_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour'];
683 698
 
684 699
 		// Hack in guest requiring verification!
685
-		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha']))
686
-			$_POST['posts_require_captcha'] = -1;
700
+		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha'])) {
701
+					$_POST['posts_require_captcha'] = -1;
702
+		}
687 703
 
688 704
 		$save_vars = $config_vars;
689 705
 		unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']);
@@ -700,14 +716,16 @@  discard block
 block discarded – undo
700 716
 		foreach ($context['qa_languages'] as $lang_id => $dummy)
701 717
 		{
702 718
 			// If we had some questions for this language before, but don't now, delete everything from that language.
703
-			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id]))
704
-				$changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
719
+			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id])) {
720
+							$changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
721
+			}
705 722
 
706 723
 			// Now step through and see if any existing questions no longer exist.
707
-			if (!empty($context['qa_by_lang'][$lang_id]))
708
-				foreach ($context['qa_by_lang'][$lang_id] as $q_id)
724
+			if (!empty($context['qa_by_lang'][$lang_id])) {
725
+							foreach ($context['qa_by_lang'][$lang_id] as $q_id)
709 726
 					if (empty($_POST['question'][$lang_id][$q_id]))
710 727
 						$changes['delete'][] = $q_id;
728
+			}
711 729
 
712 730
 			// Now let's see if there are new questions or ones that need updating.
713 731
 			if (isset($_POST['question'][$lang_id]))
@@ -716,14 +734,16 @@  discard block
 block discarded – undo
716 734
 				{
717 735
 					// Ignore junky ids.
718 736
 					$q_id = (int) $q_id;
719
-					if ($q_id <= 0)
720
-						continue;
737
+					if ($q_id <= 0) {
738
+											continue;
739
+					}
721 740
 
722 741
 					// Check the question isn't empty (because they want to delete it?)
723 742
 					if (empty($question) || trim($question) == '')
724 743
 					{
725
-						if (isset($context['question_answers'][$q_id]))
726
-							$changes['delete'][] = $q_id;
744
+						if (isset($context['question_answers'][$q_id])) {
745
+													$changes['delete'][] = $q_id;
746
+						}
727 747
 						continue;
728 748
 					}
729 749
 					$question = $smcFunc['htmlspecialchars'](trim($question));
@@ -731,19 +751,22 @@  discard block
 block discarded – undo
731 751
 					// Get the answers. Firstly check there actually might be some.
732 752
 					if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id]))
733 753
 					{
734
-						if (isset($context['question_answers'][$q_id]))
735
-							$changes['delete'][] = $q_id;
754
+						if (isset($context['question_answers'][$q_id])) {
755
+													$changes['delete'][] = $q_id;
756
+						}
736 757
 						continue;
737 758
 					}
738 759
 					// Now get them and check that they might be viable.
739 760
 					$answers = array();
740
-					foreach ($_POST['answer'][$lang_id][$q_id] as $answer)
741
-						if (!empty($answer) && trim($answer) !== '')
761
+					foreach ($_POST['answer'][$lang_id][$q_id] as $answer) {
762
+											if (!empty($answer) && trim($answer) !== '')
742 763
 							$answers[] = $smcFunc['htmlspecialchars'](trim($answer));
764
+					}
743 765
 					if (empty($answers))
744 766
 					{
745
-						if (isset($context['question_answers'][$q_id]))
746
-							$changes['delete'][] = $q_id;
767
+						if (isset($context['question_answers'][$q_id])) {
768
+													$changes['delete'][] = $q_id;
769
+						}
747 770
 						continue;
748 771
 					}
749 772
 					$answers = $smcFunc['json_encode']($answers);
@@ -753,16 +776,17 @@  discard block
 block discarded – undo
753 776
 					{
754 777
 						// New question. Now, we don't want to randomly consume ids, so we'll set those, rather than trusting the browser's supplied ids.
755 778
 						$changes['insert'][] = array($lang_id, $question, $answers);
756
-					}
757
-					else
779
+					} else
758 780
 					{
759 781
 						// It's an existing question. Let's see what's changed, if anything.
760
-						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers'])
761
-							$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
782
+						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers']) {
783
+													$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
784
+						}
762 785
 					}
763 786
 
764
-					if (!isset($qs_per_lang[$lang_id]))
765
-						$qs_per_lang[$lang_id] = 0;
787
+					if (!isset($qs_per_lang[$lang_id])) {
788
+											$qs_per_lang[$lang_id] = 0;
789
+					}
766 790
 					$qs_per_lang[$lang_id]++;
767 791
 				}
768 792
 			}
@@ -812,8 +836,9 @@  discard block
 block discarded – undo
812 836
 
813 837
 		// Lastly, the count of messages needs to be no more than the lowest number of questions for any one language.
814 838
 		$count_questions = empty($qs_per_lang) ? 0 : min($qs_per_lang);
815
-		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions)
816
-			$_POST['qa_verification_number'] = $count_questions;
839
+		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions) {
840
+					$_POST['qa_verification_number'] = $count_questions;
841
+		}
817 842
 
818 843
 		call_integration_hook('integrate_save_spam_settings', array(&$save_vars));
819 844
 
@@ -828,24 +853,27 @@  discard block
 block discarded – undo
828 853
 
829 854
 	$character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y'));
830 855
 	$_SESSION['visual_verification_code'] = '';
831
-	for ($i = 0; $i < 6; $i++)
832
-		$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
856
+	for ($i = 0; $i < 6; $i++) {
857
+			$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
858
+	}
833 859
 
834 860
 	// Some javascript for CAPTCHA.
835 861
 	$context['settings_post_javascript'] = '';
836
-	if ($context['use_graphic_library'])
837
-		$context['settings_post_javascript'] .= '
862
+	if ($context['use_graphic_library']) {
863
+			$context['settings_post_javascript'] .= '
838 864
 		function refreshImages()
839 865
 		{
840 866
 			var imageType = document.getElementById(\'visual_verification_type\').value;
841 867
 			document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType;
842 868
 		}';
869
+	}
843 870
 
844 871
 	// Show the image itself, or text saying we can't.
845
-	if ($context['use_graphic_library'])
846
-		$config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>';
847
-	else
848
-		$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
872
+	if ($context['use_graphic_library']) {
873
+			$config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>';
874
+	} else {
875
+			$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
876
+	}
849 877
 
850 878
 	// Hack for PM spam settings.
851 879
 	list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
@@ -855,9 +883,10 @@  discard block
 block discarded – undo
855 883
 	$modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha'];
856 884
 
857 885
 	// Some minor javascript for the guest post setting.
858
-	if ($modSettings['posts_require_captcha'])
859
-		$context['settings_post_javascript'] .= '
886
+	if ($modSettings['posts_require_captcha']) {
887
+			$context['settings_post_javascript'] .= '
860 888
 		document.getElementById(\'guests_require_captcha\').disabled = true;';
889
+	}
861 890
 
862 891
 	// And everything else.
863 892
 	$context['post_url'] = $scripturl . '?action=admin;area=antispam;save';
@@ -904,8 +933,9 @@  discard block
 block discarded – undo
904 933
 
905 934
 	call_integration_hook('integrate_signature_settings', array(&$config_vars));
906 935
 
907
-	if ($return_config)
908
-		return $config_vars;
936
+	if ($return_config) {
937
+			return $config_vars;
938
+	}
909 939
 
910 940
 	// Setup the template.
911 941
 	$context['page_title'] = $txt['signature_settings'];
@@ -960,8 +990,9 @@  discard block
 block discarded – undo
960 990
 				$sig = strtr($row['signature'], array('<br>' => "\n"));
961 991
 
962 992
 				// Max characters...
963
-				if (!empty($sig_limits[1]))
964
-					$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
993
+				if (!empty($sig_limits[1])) {
994
+									$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
995
+				}
965 996
 				// Max lines...
966 997
 				if (!empty($sig_limits[2]))
967 998
 				{
@@ -971,8 +1002,9 @@  discard block
 block discarded – undo
971 1002
 						if ($sig[$i] == "\n")
972 1003
 						{
973 1004
 							$count++;
974
-							if ($count >= $sig_limits[2])
975
-								$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
1005
+							if ($count >= $sig_limits[2]) {
1006
+															$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
1007
+							}
976 1008
 						}
977 1009
 					}
978 1010
 				}
@@ -983,17 +1015,19 @@  discard block
 block discarded – undo
983 1015
 					{
984 1016
 						$limit_broke = 0;
985 1017
 						// Attempt to allow all sizes of abuse, so to speak.
986
-						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
987
-							$limit_broke = $sig_limits[7] . 'px';
988
-						elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
989
-							$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
990
-						elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
991
-							$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
992
-						elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
993
-							$limit_broke = 'large';
994
-
995
-						if ($limit_broke)
996
-							$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1018
+						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
1019
+													$limit_broke = $sig_limits[7] . 'px';
1020
+						} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
1021
+													$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
1022
+						} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
1023
+													$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
1024
+						} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
1025
+													$limit_broke = 'large';
1026
+						}
1027
+
1028
+						if ($limit_broke) {
1029
+													$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1030
+						}
997 1031
 					}
998 1032
 				}
999 1033
 
@@ -1049,32 +1083,34 @@  discard block
 block discarded – undo
1049 1083
 											$img_offset = false;
1050 1084
 										}
1051 1085
 									}
1086
+								} else {
1087
+																	$replaces[$image] = '';
1052 1088
 								}
1053
-								else
1054
-									$replaces[$image] = '';
1055 1089
 
1056 1090
 								continue;
1057 1091
 							}
1058 1092
 
1059 1093
 							// Does it have predefined restraints? Width first.
1060
-							if ($matches[6][$key])
1061
-								$matches[2][$key] = $matches[6][$key];
1094
+							if ($matches[6][$key]) {
1095
+															$matches[2][$key] = $matches[6][$key];
1096
+							}
1062 1097
 							if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
1063 1098
 							{
1064 1099
 								$width = $sig_limits[5];
1065 1100
 								$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
1101
+							} elseif ($matches[2][$key]) {
1102
+															$width = $matches[2][$key];
1066 1103
 							}
1067
-							elseif ($matches[2][$key])
1068
-								$width = $matches[2][$key];
1069 1104
 							// ... and height.
1070 1105
 							if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
1071 1106
 							{
1072 1107
 								$height = $sig_limits[6];
1073
-								if ($width != -1)
1074
-									$width = $width * ($height / $matches[4][$key]);
1108
+								if ($width != -1) {
1109
+																	$width = $width * ($height / $matches[4][$key]);
1110
+								}
1111
+							} elseif ($matches[4][$key]) {
1112
+															$height = $matches[4][$key];
1075 1113
 							}
1076
-							elseif ($matches[4][$key])
1077
-								$height = $matches[4][$key];
1078 1114
 
1079 1115
 							// If the dimensions are still not fixed - we need to check the actual image.
1080 1116
 							if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -1092,12 +1128,13 @@  discard block
 block discarded – undo
1092 1128
 									if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
1093 1129
 									{
1094 1130
 										$height = $sig_limits[6];
1095
-										if ($width == -1)
1096
-											$width = $sizes[0];
1131
+										if ($width == -1) {
1132
+																					$width = $sizes[0];
1133
+										}
1097 1134
 										$width = $width * ($height / $sizes[1]);
1135
+									} elseif ($width != -1) {
1136
+																			$height = $sizes[1];
1098 1137
 									}
1099
-									elseif ($width != -1)
1100
-										$height = $sizes[1];
1101 1138
 								}
1102 1139
 							}
1103 1140
 
@@ -1110,8 +1147,9 @@  discard block
 block discarded – undo
1110 1147
 							// Record that we got one.
1111 1148
 							$image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1;
1112 1149
 						}
1113
-						if (!empty($replaces))
1114
-							$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1150
+						if (!empty($replaces)) {
1151
+													$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1152
+						}
1115 1153
 					}
1116 1154
 				}
1117 1155
 				// Try to fix disabled tags.
@@ -1123,18 +1161,20 @@  discard block
 block discarded – undo
1123 1161
 
1124 1162
 				$sig = strtr($sig, array("\n" => '<br>'));
1125 1163
 				call_integration_hook('integrate_apply_signature_settings', array(&$sig, $sig_limits, $disabledTags));
1126
-				if ($sig != $row['signature'])
1127
-					$changes[$row['id_member']] = $sig;
1164
+				if ($sig != $row['signature']) {
1165
+									$changes[$row['id_member']] = $sig;
1166
+				}
1167
+			}
1168
+			if ($smcFunc['db_num_rows']($request) == 0) {
1169
+							$done = true;
1128 1170
 			}
1129
-			if ($smcFunc['db_num_rows']($request) == 0)
1130
-				$done = true;
1131 1171
 			$smcFunc['db_free_result']($request);
1132 1172
 
1133 1173
 			// Do we need to delete what we have?
1134 1174
 			if (!empty($changes))
1135 1175
 			{
1136
-				foreach ($changes as $id => $sig)
1137
-					$smcFunc['db_query']('', '
1176
+				foreach ($changes as $id => $sig) {
1177
+									$smcFunc['db_query']('', '
1138 1178
 						UPDATE {db_prefix}members
1139 1179
 						SET signature = {string:signature}
1140 1180
 						WHERE id_member = {int:id_member}',
@@ -1143,11 +1183,13 @@  discard block
 block discarded – undo
1143 1183
 							'signature' => $sig,
1144 1184
 						)
1145 1185
 					);
1186
+				}
1146 1187
 			}
1147 1188
 
1148 1189
 			$_GET['step'] += 50;
1149
-			if (!$done)
1150
-				pauseSignatureApplySettings();
1190
+			if (!$done) {
1191
+							pauseSignatureApplySettings();
1192
+			}
1151 1193
 		}
1152 1194
 		$settings_applied = true;
1153 1195
 	}
@@ -1165,8 +1207,9 @@  discard block
 block discarded – undo
1165 1207
 	);
1166 1208
 
1167 1209
 	// Temporarily make each setting a modSetting!
1168
-	foreach ($context['signature_settings'] as $key => $value)
1169
-		$modSettings['signature_' . $key] = $value;
1210
+	foreach ($context['signature_settings'] as $key => $value) {
1211
+			$modSettings['signature_' . $key] = $value;
1212
+	}
1170 1213
 
1171 1214
 	// Make sure we check the right tags!
1172 1215
 	$modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
@@ -1178,23 +1221,26 @@  discard block
 block discarded – undo
1178 1221
 
1179 1222
 		// Clean up the tag stuff!
1180 1223
 		$bbcTags = array();
1181
-		foreach (parse_bbc(false) as $tag)
1182
-			$bbcTags[] = $tag['tag'];
1224
+		foreach (parse_bbc(false) as $tag) {
1225
+					$bbcTags[] = $tag['tag'];
1226
+		}
1183 1227
 
1184
-		if (!isset($_POST['signature_bbc_enabledTags']))
1185
-			$_POST['signature_bbc_enabledTags'] = array();
1186
-		elseif (!is_array($_POST['signature_bbc_enabledTags']))
1187
-			$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1228
+		if (!isset($_POST['signature_bbc_enabledTags'])) {
1229
+					$_POST['signature_bbc_enabledTags'] = array();
1230
+		} elseif (!is_array($_POST['signature_bbc_enabledTags'])) {
1231
+					$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1232
+		}
1188 1233
 
1189 1234
 		$sig_limits = array();
1190 1235
 		foreach ($context['signature_settings'] as $key => $value)
1191 1236
 		{
1192
-			if ($key == 'allow_smileys')
1193
-				continue;
1194
-			elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys']))
1195
-				$sig_limits[] = -1;
1196
-			else
1197
-				$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1237
+			if ($key == 'allow_smileys') {
1238
+							continue;
1239
+			} elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys'])) {
1240
+							$sig_limits[] = -1;
1241
+			} else {
1242
+							$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1243
+			}
1198 1244
 		}
1199 1245
 
1200 1246
 		call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags));
@@ -1227,12 +1273,14 @@  discard block
 block discarded – undo
1227 1273
 
1228 1274
 	// Try get more time...
1229 1275
 	@set_time_limit(600);
1230
-	if (function_exists('apache_reset_timeout'))
1231
-		@apache_reset_timeout();
1276
+	if (function_exists('apache_reset_timeout')) {
1277
+			@apache_reset_timeout();
1278
+	}
1232 1279
 
1233 1280
 	// Have we exhausted all the time we allowed?
1234
-	if (time() - array_sum(explode(' ', $sig_start)) < 3)
1235
-		return;
1281
+	if (time() - array_sum(explode(' ', $sig_start)) < 3) {
1282
+			return;
1283
+	}
1236 1284
 
1237 1285
 	$context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1238 1286
 	$context['page_title'] = $txt['not_done_title'];
@@ -1278,9 +1326,10 @@  discard block
 block discarded – undo
1278 1326
 		$disable_fields = array_flip($standard_fields);
1279 1327
 		if (!empty($_POST['active']))
1280 1328
 		{
1281
-			foreach ($_POST['active'] as $value)
1282
-				if (isset($disable_fields[$value]))
1329
+			foreach ($_POST['active'] as $value) {
1330
+							if (isset($disable_fields[$value]))
1283 1331
 					unset($disable_fields[$value]);
1332
+			}
1284 1333
 		}
1285 1334
 		// What we have left!
1286 1335
 		$changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields));
@@ -1289,16 +1338,18 @@  discard block
 block discarded – undo
1289 1338
 		$reg_fields = array();
1290 1339
 		if (!empty($_POST['reg']))
1291 1340
 		{
1292
-			foreach ($_POST['reg'] as $value)
1293
-				if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1341
+			foreach ($_POST['reg'] as $value) {
1342
+							if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1294 1343
 					$reg_fields[] = $value;
1344
+			}
1295 1345
 		}
1296 1346
 		// What we have left!
1297 1347
 		$changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
1298 1348
 
1299 1349
 		$_SESSION['adm-save'] = true;
1300
-		if (!empty($changes))
1301
-			updateSettings($changes);
1350
+		if (!empty($changes)) {
1351
+					updateSettings($changes);
1352
+		}
1302 1353
 	}
1303 1354
 
1304 1355
 	createToken('admin-scp');
@@ -1401,11 +1452,13 @@  discard block
 block discarded – undo
1401 1452
 					{
1402 1453
 						$return = '<p class="centertext bold_text">'. $rowData['field_order'] .'<br>';
1403 1454
 
1404
-						if ($rowData['field_order'] > 1)
1405
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1455
+						if ($rowData['field_order'] > 1) {
1456
+													$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1457
+						}
1406 1458
 
1407
-						if ($rowData['field_order'] < $context['custFieldsMaxOrder'])
1408
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1459
+						if ($rowData['field_order'] < $context['custFieldsMaxOrder']) {
1460
+													$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1461
+						}
1409 1462
 
1410 1463
 						$return .= '</p>';
1411 1464
 
@@ -1543,16 +1596,16 @@  discard block
 block discarded – undo
1543 1596
 		$disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
1544 1597
 		$registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array();
1545 1598
 
1546
-		foreach ($standard_fields as $field)
1547
-			$list[] = array(
1599
+		foreach ($standard_fields as $field) {
1600
+					$list[] = array(
1548 1601
 				'id' => $field,
1549 1602
 				'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field),
1550 1603
 				'disabled' => in_array($field, $disabled_fields),
1551 1604
 				'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration),
1552 1605
 				'can_show_register' => !in_array($field, $fields_no_registration),
1553 1606
 			);
1554
-	}
1555
-	else
1607
+		}
1608
+	} else
1556 1609
 	{
1557 1610
 		// Load all the fields.
1558 1611
 		$request = $smcFunc['db_query']('', '
@@ -1566,8 +1619,9 @@  discard block
 block discarded – undo
1566 1619
 				'items_per_page' => $items_per_page,
1567 1620
 			)
1568 1621
 		);
1569
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1570
-			$list[] = $row;
1622
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1623
+					$list[] = $row;
1624
+		}
1571 1625
 		$smcFunc['db_free_result']($request);
1572 1626
 	}
1573 1627
 
@@ -1633,9 +1687,9 @@  discard block
 block discarded – undo
1633 1687
 		$context['field'] = array();
1634 1688
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1635 1689
 		{
1636
-			if ($row['field_type'] == 'textarea')
1637
-				@list ($rows, $cols) = @explode(',', $row['default_value']);
1638
-			else
1690
+			if ($row['field_type'] == 'textarea') {
1691
+							@list ($rows, $cols) = @explode(',', $row['default_value']);
1692
+			} else
1639 1693
 			{
1640 1694
 				$rows = 3;
1641 1695
 				$cols = 30;
@@ -1671,8 +1725,8 @@  discard block
 block discarded – undo
1671 1725
 	}
1672 1726
 
1673 1727
 	// Setup the default values as needed.
1674
-	if (empty($context['field']))
1675
-		$context['field'] = array(
1728
+	if (empty($context['field'])) {
1729
+			$context['field'] = array(
1676 1730
 			'name' => '',
1677 1731
 			'col_name' => '???',
1678 1732
 			'desc' => '',
@@ -1697,6 +1751,7 @@  discard block
 block discarded – undo
1697 1751
 			'enclose' => '',
1698 1752
 			'placement' => 0,
1699 1753
 		);
1754
+	}
1700 1755
 
1701 1756
 	// Are we moving it?
1702 1757
 	if (isset($_GET['move']) && in_array($smcFunc['htmlspecialchars']($_GET['move']), $move_to))
@@ -1705,8 +1760,10 @@  discard block
 block discarded – undo
1705 1760
 		$new_order = ($_GET['move'] == 'up' ? ($context['field']['order'] - 1) : ($context['field']['order'] + 1));
1706 1761
 
1707 1762
 		// Is this a valid position?
1708
-		if ($new_order <= 0 || $new_order > $order_count)
1709
-			redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler
1763
+		if ($new_order <= 0 || $new_order > $order_count) {
1764
+					redirectexit('action=admin;area=featuresettings;sa=profile');
1765
+		}
1766
+		// @todo implement an error handler
1710 1767
 
1711 1768
 		// All good, proceed.
1712 1769
 		$smcFunc['db_query']('','
@@ -1737,12 +1794,14 @@  discard block
 block discarded – undo
1737 1794
 		validateToken('admin-ecp');
1738 1795
 
1739 1796
 		// Everyone needs a name - even the (bracket) unknown...
1740
-		if (trim($_POST['field_name']) == '')
1741
-			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1797
+		if (trim($_POST['field_name']) == '') {
1798
+					redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1799
+		}
1742 1800
 
1743 1801
 		// Regex you say?  Do a very basic test to see if the pattern is valid
1744
-		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false)
1745
-			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1802
+		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false) {
1803
+					redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1804
+		}
1746 1805
 
1747 1806
 		$_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']);
1748 1807
 		$_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']);
@@ -1759,8 +1818,9 @@  discard block
 block discarded – undo
1759 1818
 
1760 1819
 		// Some masking stuff...
1761 1820
 		$mask = isset($_POST['mask']) ? $_POST['mask'] : '';
1762
-		if ($mask == 'regex' && isset($_POST['regex']))
1763
-			$mask .= $_POST['regex'];
1821
+		if ($mask == 'regex' && isset($_POST['regex'])) {
1822
+					$mask .= $_POST['regex'];
1823
+		}
1764 1824
 
1765 1825
 		$field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255;
1766 1826
 		$enclose = isset($_POST['enclose']) ? $_POST['enclose'] : '';
@@ -1779,8 +1839,9 @@  discard block
 block discarded – undo
1779 1839
 				$v = strtr($v, array(',' => ''));
1780 1840
 
1781 1841
 				// Nada, zip, etc...
1782
-				if (trim($v) == '')
1783
-					continue;
1842
+				if (trim($v) == '') {
1843
+									continue;
1844
+				}
1784 1845
 
1785 1846
 				// Otherwise, save it boy.
1786 1847
 				$field_options .= $v . ',';
@@ -1788,15 +1849,17 @@  discard block
 block discarded – undo
1788 1849
 				$newOptions[$k] = $v;
1789 1850
 
1790 1851
 				// Is it default?
1791
-				if (isset($_POST['default_select']) && $_POST['default_select'] == $k)
1792
-					$default = $v;
1852
+				if (isset($_POST['default_select']) && $_POST['default_select'] == $k) {
1853
+									$default = $v;
1854
+				}
1793 1855
 			}
1794 1856
 			$field_options = substr($field_options, 0, -1);
1795 1857
 		}
1796 1858
 
1797 1859
 		// Text area has default has dimensions
1798
-		if ($_POST['field_type'] == 'textarea')
1799
-			$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1860
+		if ($_POST['field_type'] == 'textarea') {
1861
+					$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1862
+		}
1800 1863
 
1801 1864
 		// Come up with the unique name?
1802 1865
 		if (empty($context['fid']))
@@ -1805,32 +1868,36 @@  discard block
 block discarded – undo
1805 1868
 			preg_match('~([\w\d_-]+)~', $col_name, $matches);
1806 1869
 
1807 1870
 			// If there is nothing to the name, then let's start out own - for foreign languages etc.
1808
-			if (isset($matches[1]))
1809
-				$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1810
-			else
1811
-				$col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999);
1871
+			if (isset($matches[1])) {
1872
+							$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1873
+			} else {
1874
+							$col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999);
1875
+			}
1812 1876
 
1813 1877
 			// Make sure this is unique.
1814 1878
 			$current_fields = array();
1815 1879
 			$request = $smcFunc['db_query']('', '
1816 1880
 				SELECT id_field, col_name
1817 1881
 				FROM {db_prefix}custom_fields');
1818
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1819
-				$current_fields[$row['id_field']] = $row['col_name'];
1882
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1883
+							$current_fields[$row['id_field']] = $row['col_name'];
1884
+			}
1820 1885
 			$smcFunc['db_free_result']($request);
1821 1886
 
1822 1887
 			$unique = false;
1823 1888
 			for ($i = 0; !$unique && $i < 9; $i ++)
1824 1889
 			{
1825
-				if (!in_array($col_name, $current_fields))
1826
-					$unique = true;
1827
-				else
1828
-					$col_name = $initial_col_name . $i;
1890
+				if (!in_array($col_name, $current_fields)) {
1891
+									$unique = true;
1892
+				} else {
1893
+									$col_name = $initial_col_name . $i;
1894
+				}
1829 1895
 			}
1830 1896
 
1831 1897
 			// Still not a unique column name? Leave it up to the user, then.
1832
-			if (!$unique)
1833
-				fatal_lang_error('custom_option_not_unique');
1898
+			if (!$unique) {
1899
+							fatal_lang_error('custom_option_not_unique');
1900
+			}
1834 1901
 		}
1835 1902
 		// Work out what to do with the user data otherwise...
1836 1903
 		else
@@ -1858,8 +1925,9 @@  discard block
 block discarded – undo
1858 1925
 				// Work out what's changed!
1859 1926
 				foreach ($context['field']['options'] as $k => $option)
1860 1927
 				{
1861
-					if (trim($option) == '')
1862
-						continue;
1928
+					if (trim($option) == '') {
1929
+											continue;
1930
+					}
1863 1931
 
1864 1932
 					// Still exists?
1865 1933
 					if (in_array($option, $newOptions))
@@ -1873,8 +1941,8 @@  discard block
 block discarded – undo
1873 1941
 				foreach ($optionChanges as $k => $option)
1874 1942
 				{
1875 1943
 					// Just been renamed?
1876
-					if (!in_array($k, $takenKeys) && !empty($newOptions[$k]))
1877
-						$smcFunc['db_query']('', '
1944
+					if (!in_array($k, $takenKeys) && !empty($newOptions[$k])) {
1945
+											$smcFunc['db_query']('', '
1878 1946
 							UPDATE {db_prefix}themes
1879 1947
 							SET value = {string:new_value}
1880 1948
 							WHERE variable = {string:current_column}
@@ -1887,6 +1955,7 @@  discard block
 block discarded – undo
1887 1955
 								'old_value' => $option,
1888 1956
 							)
1889 1957
 						);
1958
+					}
1890 1959
 				}
1891 1960
 			}
1892 1961
 			// @todo Maybe we should adjust based on new text length limits?
@@ -1929,8 +1998,8 @@  discard block
 block discarded – undo
1929 1998
 			);
1930 1999
 
1931 2000
 			// Just clean up any old selects - these are a pain!
1932
-			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions))
1933
-				$smcFunc['db_query']('', '
2001
+			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions)) {
2002
+							$smcFunc['db_query']('', '
1934 2003
 					DELETE FROM {db_prefix}themes
1935 2004
 					WHERE variable = {string:current_column}
1936 2005
 						AND value NOT IN ({array_string:new_option_values})
@@ -1941,8 +2010,8 @@  discard block
 block discarded – undo
1941 2010
 						'current_column' => $context['field']['col_name'],
1942 2011
 					)
1943 2012
 				);
1944
-		}
1945
-		else
2013
+			}
2014
+		} else
1946 2015
 		{
1947 2016
 			// Gotta figure it out the order.
1948 2017
 			$new_order = $order_count > 1 ? ($order_count + 1) : 1;
@@ -2116,11 +2185,13 @@  discard block
 block discarded – undo
2116 2185
 	call_integration_hook('integrate_prune_settings', array(&$config_vars, &$prune_toggle, false));
2117 2186
 
2118 2187
 	$prune_toggle_dt = array();
2119
-	foreach ($prune_toggle as $item)
2120
-		$prune_toggle_dt[] = 'setting_' . $item;
2188
+	foreach ($prune_toggle as $item) {
2189
+			$prune_toggle_dt[] = 'setting_' . $item;
2190
+	}
2121 2191
 
2122
-	if ($return_config)
2123
-		return $config_vars;
2192
+	if ($return_config) {
2193
+			return $config_vars;
2194
+	}
2124 2195
 
2125 2196
 	addInlineJavaScript('
2126 2197
 	function togglePruned()
@@ -2158,15 +2229,16 @@  discard block
 block discarded – undo
2158 2229
 			$vals = array();
2159 2230
 			foreach ($config_vars as $index => $dummy)
2160 2231
 			{
2161
-				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle))
2162
-					continue;
2232
+				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle)) {
2233
+									continue;
2234
+				}
2163 2235
 
2164 2236
 				$vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]];
2165 2237
 			}
2166 2238
 			$_POST['pruningOptions'] = implode(',', $vals);
2239
+		} else {
2240
+					$_POST['pruningOptions'] = '';
2167 2241
 		}
2168
-		else
2169
-			$_POST['pruningOptions'] = '';
2170 2242
 
2171 2243
 		saveDBSettings($savevar);
2172 2244
 		$_SESSION['adm-save'] = true;
@@ -2178,10 +2250,11 @@  discard block
 block discarded – undo
2178 2250
 	$context['sub_template'] = 'show_settings';
2179 2251
 
2180 2252
 	// Get the actual values
2181
-	if (!empty($modSettings['pruningOptions']))
2182
-		@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2183
-	else
2184
-		$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2253
+	if (!empty($modSettings['pruningOptions'])) {
2254
+			@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2255
+	} else {
2256
+			$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2257
+	}
2185 2258
 
2186 2259
 	prepareDBSettingContext($config_vars);
2187 2260
 }
@@ -2203,8 +2276,9 @@  discard block
 block discarded – undo
2203 2276
 	// Make it even easier to add new settings.
2204 2277
 	call_integration_hook('integrate_general_mod_settings', array(&$config_vars));
2205 2278
 
2206
-	if ($return_config)
2207
-		return $config_vars;
2279
+	if ($return_config) {
2280
+			return $config_vars;
2281
+	}
2208 2282
 
2209 2283
 	$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general';
2210 2284
 	$context['settings_title'] = $txt['mods_cat_modifications_misc'];
Please login to merge, or discard this patch.
Sources/SearchAPI-Fulltext.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 		$query_where = array();
167 167
 		$query_params = $search_data['params'];
168 168
 
169
-		if( $smcFunc['db_title'] == "PostgreSQL")
169
+		if ($smcFunc['db_title'] == "PostgreSQL")
170 170
 			$modSettings['search_simple_fulltext'] = true;
171 171
 
172 172
 		if ($query_params['id_search'])
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 
210 210
 		if (!empty($modSettings['search_simple_fulltext']))
211 211
 		{
212
-			if($smcFunc['db_title'] == "PostgreSQL")
212
+			if ($smcFunc['db_title'] == "PostgreSQL")
213 213
 			{
214 214
 				$language_ftx = $smcFunc['db_search_language']();
215 215
 
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 			// remove any indexed words that are used in the complex body search terms
228 228
 			$words['indexed_words'] = array_diff($words['indexed_words'], $words['complex_words']);
229 229
 
230
-			if($smcFunc['db_title'] == "PostgreSQL"){
230
+			if ($smcFunc['db_title'] == "PostgreSQL") {
231 231
 				$row = 0;
232 232
 				foreach ($words['indexed_words'] as $fulltextWord) {
233 233
 					$query_params['boolean_match'] .= ($row <> 0 ? '&' : '');
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 
244 244
 			// if we have bool terms to search, add them in
245 245
 			if ($query_params['boolean_match']) {
246
-				if($smcFunc['db_title'] == "PostgreSQL")
246
+				if ($smcFunc['db_title'] == "PostgreSQL")
247 247
 				{
248 248
 					$language_ftx = $smcFunc['db_search_language']();
249 249
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 
257 257
 		}
258 258
 
259
-		$ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ( '
259
+		$ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ('
260 260
 			INSERT IGNORE INTO {db_prefix}' . $search_data['insert_into'] . '
261 261
 				(' . implode(', ', array_keys($query_select)) . ')') : '') . '
262 262
 			SELECT ' . implode(', ', $query_select) . '
Please login to merge, or discard this patch.
Braces   +47 added lines, -36 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * Class fulltext_search
@@ -98,8 +99,9 @@  discard block
 block discarded – undo
98 99
 			$smcFunc['db_free_result']($request);
99 100
 		}
100 101
 		// 4 is the MySQL default...
101
-		else
102
-			$min_word_length = 4;
102
+		else {
103
+					$min_word_length = 4;
104
+		}
103 105
 
104 106
 		return $min_word_length;
105 107
 	}
@@ -138,8 +140,7 @@  discard block
 block discarded – undo
138 140
 					$wordsSearch['words'][] = trim($word, "/*- ");
139 141
 					$wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"';
140 142
 				}
141
-			}
142
-			elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length)
143
+			} elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length)
143 144
 			{
144 145
 				// short words have feelings too
145 146
 				$wordsSearch['words'][] = trim($word, "/*- ");
@@ -149,8 +150,9 @@  discard block
 block discarded – undo
149 150
 
150 151
 		$fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"';
151 152
 		$wordsSearch['indexed_words'][] = $fulltextWord;
152
-		if ($isExcluded)
153
-			$wordsExclude[] = $fulltextWord;
153
+		if ($isExcluded) {
154
+					$wordsExclude[] = $fulltextWord;
155
+		}
154 156
 	}
155 157
 
156 158
 	/**
@@ -166,44 +168,54 @@  discard block
 block discarded – undo
166 168
 		$query_where = array();
167 169
 		$query_params = $search_data['params'];
168 170
 
169
-		if( $smcFunc['db_title'] == "PostgreSQL")
170
-			$modSettings['search_simple_fulltext'] = true;
171
+		if( $smcFunc['db_title'] == "PostgreSQL") {
172
+					$modSettings['search_simple_fulltext'] = true;
173
+		}
171 174
 
172
-		if ($query_params['id_search'])
173
-			$query_select['id_search'] = '{int:id_search}';
175
+		if ($query_params['id_search']) {
176
+					$query_select['id_search'] = '{int:id_search}';
177
+		}
174 178
 
175 179
 		$count = 0;
176
-		if (empty($modSettings['search_simple_fulltext']))
177
-			foreach ($words['words'] as $regularWord)
180
+		if (empty($modSettings['search_simple_fulltext'])) {
181
+					foreach ($words['words'] as $regularWord)
178 182
 			{
179 183
 				$query_where[] = 'm.body' . (in_array($regularWord, $query_params['excluded_words']) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:complex_body_' . $count . '}';
184
+		}
180 185
 				$query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]';
181 186
 			}
182 187
 
183
-		if ($query_params['user_query'])
184
-			$query_where[] = '{raw:user_query}';
185
-		if ($query_params['board_query'])
186
-			$query_where[] = 'm.id_board {raw:board_query}';
188
+		if ($query_params['user_query']) {
189
+					$query_where[] = '{raw:user_query}';
190
+		}
191
+		if ($query_params['board_query']) {
192
+					$query_where[] = 'm.id_board {raw:board_query}';
193
+		}
187 194
 
188
-		if ($query_params['topic'])
189
-			$query_where[] = 'm.id_topic = {int:topic}';
190
-		if ($query_params['min_msg_id'])
191
-			$query_where[] = 'm.id_msg >= {int:min_msg_id}';
192
-		if ($query_params['max_msg_id'])
193
-			$query_where[] = 'm.id_msg <= {int:max_msg_id}';
195
+		if ($query_params['topic']) {
196
+					$query_where[] = 'm.id_topic = {int:topic}';
197
+		}
198
+		if ($query_params['min_msg_id']) {
199
+					$query_where[] = 'm.id_msg >= {int:min_msg_id}';
200
+		}
201
+		if ($query_params['max_msg_id']) {
202
+					$query_where[] = 'm.id_msg <= {int:max_msg_id}';
203
+		}
194 204
 
195 205
 		$count = 0;
196
-		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index']))
197
-			foreach ($query_params['excluded_phrases'] as $phrase)
206
+		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) {
207
+					foreach ($query_params['excluded_phrases'] as $phrase)
198 208
 			{
199 209
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}';
210
+		}
200 211
 				$query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]';
201 212
 			}
202 213
 		$count = 0;
203
-		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index']))
204
-			foreach ($query_params['excluded_subject_words'] as $excludedWord)
214
+		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) {
215
+					foreach ($query_params['excluded_subject_words'] as $excludedWord)
205 216
 			{
206 217
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}';
218
+		}
207 219
 				$query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]';
208 220
 			}
209 221
 
@@ -215,12 +227,11 @@  discard block
 block discarded – undo
215 227
 
216 228
 				$query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:body_match})';
217 229
 				$query_params['language_ftx'] = $language_ftx;
230
+			} else {
231
+							$query_where[] = 'MATCH (body) AGAINST ({string:body_match})';
218 232
 			}
219
-			else
220
-				$query_where[] = 'MATCH (body) AGAINST ({string:body_match})';
221 233
 			$query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words']));
222
-		}
223
-		else
234
+		} else
224 235
 		{
225 236
 			$query_params['boolean_match'] = '';
226 237
 
@@ -234,10 +245,10 @@  discard block
 block discarded – undo
234 245
 					$query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' ';
235 246
 					$row++;
236 247
 				}
237
-			}
238
-			else
239
-				foreach ($words['indexed_words'] as $fulltextWord)
248
+			} else {
249
+							foreach ($words['indexed_words'] as $fulltextWord)
240 250
 					$query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' ';
251
+			}
241 252
 
242 253
 			$query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1);
243 254
 
@@ -249,9 +260,9 @@  discard block
 block discarded – undo
249 260
 
250 261
 					$query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:boolean_match})';
251 262
 					$query_params['language_ftx'] = $language_ftx;
263
+				} else {
264
+									$query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)';
252 265
 				}
253
-				else
254
-					$query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)';
255 266
 			}
256 267
 
257 268
 		}
Please login to merge, or discard this patch.
Sources/Post.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -256,8 +256,8 @@  discard block
 block discarded – undo
256 256
 			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
257 257
 
258 258
 		$js_time_string = str_replace(
259
-			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
260
-			array('H',  'G',  'h',  'g',  'i',  'A',  'a',  'h:i:s A', 'H:i', 's',  'H:i:s', 'H:i:s'),
259
+			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r', '%R', '%S', '%T', '%X'),
260
+			array('H', 'G', 'h', 'g', 'i', 'A', 'a', 'h:i:s A', 'H:i', 's', 'H:i:s', 'H:i:s'),
261 261
 			$time_string
262 262
 		);
263 263
 
@@ -1305,14 +1305,14 @@  discard block
 block discarded – undo
1305 1305
 	if (isset($context['name']) && isset($context['email']))
1306 1306
 	{
1307 1307
 		$context['posting_fields']['guestname'] = array(
1308
-			'dt' => '<span id="caption_guestname"' .  (isset($context['post_error']['long_name']) || isset($context['post_error']['no_name']) || isset($context['post_error']['bad_name']) ? ' class="error"' : '') . '>' . $txt['name'] . '</span>',
1308
+			'dt' => '<span id="caption_guestname"' . (isset($context['post_error']['long_name']) || isset($context['post_error']['no_name']) || isset($context['post_error']['bad_name']) ? ' class="error"' : '') . '>' . $txt['name'] . '</span>',
1309 1309
 			'dd' => '<input type="text" name="guestname" size="25" value="' . $context['name'] . '" required>',
1310 1310
 		);
1311 1311
 
1312 1312
 		if (empty($modSettings['guest_post_no_email']))
1313 1313
 		{
1314 1314
 			$context['posting_fields']['email'] = array(
1315
-				'dt' => '<span id="caption_email"' .  (isset($context['post_error']['no_email']) || isset($context['post_error']['bad_email']) ? ' class="error"' : '') . '>' . $txt['email'] . '</span>',
1315
+				'dt' => '<span id="caption_email"' . (isset($context['post_error']['no_email']) || isset($context['post_error']['bad_email']) ? ' class="error"' : '') . '>' . $txt['email'] . '</span>',
1316 1316
 				'dd' => '<input type="email" name="email" size="25" value="' . $context['email'] . '" required>',
1317 1317
 			);
1318 1318
 		}
Please login to merge, or discard this patch.
Braces   +674 added lines, -521 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Handles showing the post screen, loading the post to be modified, and loading any post quoted.
@@ -35,12 +36,14 @@  discard block
 block discarded – undo
35 36
 	global $sourcedir, $smcFunc, $language;
36 37
 
37 38
 	loadLanguage('Post');
38
-	if (!empty($modSettings['drafts_post_enabled']))
39
-		loadLanguage('Drafts');
39
+	if (!empty($modSettings['drafts_post_enabled'])) {
40
+			loadLanguage('Drafts');
41
+	}
40 42
 
41 43
 	// You can't reply with a poll... hacker.
42
-	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
43
-		unset($_REQUEST['poll']);
44
+	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) {
45
+			unset($_REQUEST['poll']);
46
+	}
44 47
 
45 48
 	// Posting an event?
46 49
 	$context['make_event'] = isset($_REQUEST['calendar']);
@@ -58,12 +61,14 @@  discard block
 block discarded – undo
58 61
 	{
59 62
 		// Get ids of all the boards they can post in.
60 63
 		$post_permissions = array('post_new');
61
-		if ($modSettings['postmod_active'])
62
-			$post_permissions[] = 'post_unapproved_topics';
64
+		if ($modSettings['postmod_active']) {
65
+					$post_permissions[] = 'post_unapproved_topics';
66
+		}
63 67
 
64 68
 		$boards = boardsAllowedTo($post_permissions);
65
-		if (empty($boards))
66
-			fatal_lang_error('cannot_post_new', 'user');
69
+		if (empty($boards)) {
70
+					fatal_lang_error('cannot_post_new', 'user');
71
+		}
67 72
 
68 73
 		// Get a list of boards for the select menu
69 74
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -76,8 +81,9 @@  discard block
 block discarded – undo
76 81
 		$board_list = getBoardList($boardListOptions);
77 82
 	}
78 83
 	// Let's keep things simple for ourselves below
79
-	else
80
-		$boards = array($board);
84
+	else {
85
+			$boards = array($board);
86
+	}
81 87
 
82 88
 	require_once($sourcedir . '/Subs-Post.php');
83 89
 
@@ -100,10 +106,11 @@  discard block
 block discarded – undo
100 106
 			array(
101 107
 				'msg' => (int) $_REQUEST['msg'],
102 108
 		));
103
-		if ($smcFunc['db_num_rows']($request) != 1)
104
-			unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
105
-		else
106
-			list ($topic) = $smcFunc['db_fetch_row']($request);
109
+		if ($smcFunc['db_num_rows']($request) != 1) {
110
+					unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
111
+		} else {
112
+					list ($topic) = $smcFunc['db_fetch_row']($request);
113
+		}
107 114
 		$smcFunc['db_free_result']($request);
108 115
 	}
109 116
 
@@ -130,33 +137,36 @@  discard block
 block discarded – undo
130 137
 		$smcFunc['db_free_result']($request);
131 138
 
132 139
 		// If this topic already has a poll, they sure can't add another.
133
-		if (isset($_REQUEST['poll']) && $pollID > 0)
134
-			unset($_REQUEST['poll']);
140
+		if (isset($_REQUEST['poll']) && $pollID > 0) {
141
+					unset($_REQUEST['poll']);
142
+		}
135 143
 
136 144
 		if (empty($_REQUEST['msg']))
137 145
 		{
138
-			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
139
-				is_not_guest();
146
+			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) {
147
+							is_not_guest();
148
+			}
140 149
 
141 150
 			// By default the reply will be approved...
142 151
 			$context['becomes_approved'] = true;
143 152
 			if ($id_member_poster != $user_info['id'] || $user_info['is_guest'])
144 153
 			{
145
-				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
146
-					$context['becomes_approved'] = false;
147
-				else
148
-					isAllowedTo('post_reply_any');
149
-			}
150
-			elseif (!allowedTo('post_reply_any'))
154
+				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
155
+									$context['becomes_approved'] = false;
156
+				} else {
157
+									isAllowedTo('post_reply_any');
158
+				}
159
+			} elseif (!allowedTo('post_reply_any'))
151 160
 			{
152
-				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any')))
153
-					$context['becomes_approved'] = false;
154
-				else
155
-					isAllowedTo('post_reply_own');
161
+				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) {
162
+									$context['becomes_approved'] = false;
163
+				} else {
164
+									isAllowedTo('post_reply_own');
165
+				}
156 166
 			}
167
+		} else {
168
+					$context['becomes_approved'] = true;
157 169
 		}
158
-		else
159
-			$context['becomes_approved'] = true;
160 170
 
161 171
 		$context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
162 172
 		$context['can_sticky'] = allowedTo('make_sticky');
@@ -171,17 +181,18 @@  discard block
 block discarded – undo
171 181
 		$context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
172 182
 
173 183
 		// Check whether this is a really old post being bumped...
174
-		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
175
-			$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
176
-	}
177
-	else
184
+		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) {
185
+					$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
186
+		}
187
+	} else
178 188
 	{
179 189
 		// @todo Should use JavaScript to hide and show the warning based on the selection in the board select menu
180 190
 		$context['becomes_approved'] = true;
181
-		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true))
182
-			$context['becomes_approved'] = false;
183
-		else
184
-			isAllowedTo('post_new', $boards, true);
191
+		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true)) {
192
+					$context['becomes_approved'] = false;
193
+		} else {
194
+					isAllowedTo('post_new', $boards, true);
195
+		}
185 196
 
186 197
 		$locked = 0;
187 198
 		$context['already_locked'] = 0;
@@ -211,27 +222,32 @@  discard block
 block discarded – undo
211 222
 	if (empty($_REQUEST['message']) && empty($_REQUEST['preview']) && !empty($_SESSION['already_attached']))
212 223
 	{
213 224
 		require_once($sourcedir . '/ManageAttachments.php');
214
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
215
-			removeAttachments(array('id_attach' => $attachID));
225
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
226
+					removeAttachments(array('id_attach' => $attachID));
227
+		}
216 228
 
217 229
 		unset($_SESSION['already_attached']);
218 230
 	}
219 231
 
220 232
 	// Don't allow a post if it's locked and you aren't all powerful.
221
-	if ($locked && !allowedTo('moderate_board'))
222
-		fatal_lang_error('topic_locked', false);
233
+	if ($locked && !allowedTo('moderate_board')) {
234
+			fatal_lang_error('topic_locked', false);
235
+	}
223 236
 	// Check the users permissions - is the user allowed to add or post a poll?
224 237
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
225 238
 	{
226 239
 		// New topic, new poll.
227
-		if (empty($topic))
228
-			isAllowedTo('poll_post');
240
+		if (empty($topic)) {
241
+					isAllowedTo('poll_post');
242
+		}
229 243
 		// This is an old topic - but it is yours!  Can you add to it?
230
-		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
231
-			isAllowedTo('poll_add_own');
244
+		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) {
245
+					isAllowedTo('poll_add_own');
246
+		}
232 247
 		// If you're not the owner, can you add to any poll?
233
-		else
234
-			isAllowedTo('poll_add_any');
248
+		else {
249
+					isAllowedTo('poll_add_any');
250
+		}
235 251
 
236 252
 		if (!empty($board))
237 253
 		{
@@ -240,8 +256,9 @@  discard block
 block discarded – undo
240 256
 			$guest_vote_enabled = in_array(-1, $allowedVoteGroups['allowed']);
241 257
 		}
242 258
 		// No board, so we'll have to check this again in Post2
243
-		else
244
-			$guest_vote_enabled = true;
259
+		else {
260
+					$guest_vote_enabled = true;
261
+		}
245 262
 
246 263
 		// Set up the poll options.
247 264
 		$context['poll_options'] = array(
@@ -267,8 +284,9 @@  discard block
 block discarded – undo
267 284
 	if ($context['make_event'])
268 285
 	{
269 286
 		// They might want to pick a board.
270
-		if (!isset($context['current_board']))
271
-			$context['current_board'] = 0;
287
+		if (!isset($context['current_board'])) {
288
+					$context['current_board'] = 0;
289
+		}
272 290
 
273 291
 		// Start loading up the event info.
274 292
 		$context['event'] = array();
@@ -282,10 +300,11 @@  discard block
 block discarded – undo
282 300
 		isAllowedTo('calendar_post');
283 301
 
284 302
 		// We want a fairly compact version of the time, but as close as possible to the user's settings.
285
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
286
-			$time_string = '%k:%M';
287
-		else
288
-			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
303
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
304
+					$time_string = '%k:%M';
305
+		} else {
306
+					$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
307
+		}
289 308
 
290 309
 		$js_time_string = str_replace(
291 310
 			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -307,8 +326,7 @@  discard block
 block discarded – undo
307 326
 			require_once($sourcedir . '/Subs-Calendar.php');
308 327
 			$eventProperties = getEventProperties($context['event']['id']);
309 328
 			$context['event'] = array_merge($context['event'], $eventProperties);
310
-		}
311
-		else
329
+		} else
312 330
 		{
313 331
 			// Get the current event information.
314 332
 			require_once($sourcedir . '/Subs-Calendar.php');
@@ -316,10 +334,12 @@  discard block
 block discarded – undo
316 334
 			$context['event'] = array_merge($context['event'], $eventProperties);
317 335
 
318 336
 			// Make sure the year and month are in the valid range.
319
-			if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
320
-				fatal_lang_error('invalid_month', false);
321
-			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
322
-				fatal_lang_error('invalid_year', false);
337
+			if ($context['event']['month'] < 1 || $context['event']['month'] > 12) {
338
+							fatal_lang_error('invalid_month', false);
339
+			}
340
+			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) {
341
+							fatal_lang_error('invalid_year', false);
342
+			}
323 343
 
324 344
 			$context['event']['categories'] = $board_list;
325 345
 		}
@@ -430,10 +450,11 @@  discard block
 block discarded – undo
430 450
 
431 451
 			if (!empty($context['new_replies']))
432 452
 			{
433
-				if ($context['new_replies'] == 1)
434
-					$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
435
-				else
436
-					$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
453
+				if ($context['new_replies'] == 1) {
454
+									$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
455
+				} else {
456
+									$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
457
+				}
437 458
 
438 459
 				$post_errors[] = 'new_replies';
439 460
 
@@ -445,9 +466,9 @@  discard block
 block discarded – undo
445 466
 	// Get a response prefix (like 'Re:') in the default forum language.
446 467
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
447 468
 	{
448
-		if ($language === $user_info['language'])
449
-			$context['response_prefix'] = $txt['response_prefix'];
450
-		else
469
+		if ($language === $user_info['language']) {
470
+					$context['response_prefix'] = $txt['response_prefix'];
471
+		} else
451 472
 		{
452 473
 			loadLanguage('index', $language, false);
453 474
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -460,23 +481,26 @@  discard block
 block discarded – undo
460 481
 	// Do we have a body, but an error happened.
461 482
 	if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error']))
462 483
 	{
463
-		if (isset($_REQUEST['quickReply']))
464
-			$_REQUEST['message'] = $_REQUEST['quickReply'];
484
+		if (isset($_REQUEST['quickReply'])) {
485
+					$_REQUEST['message'] = $_REQUEST['quickReply'];
486
+		}
465 487
 
466 488
 		// Validate inputs.
467 489
 		if (empty($context['post_error']))
468 490
 		{
469 491
 			// This means they didn't click Post and get an error.
470 492
 			$really_previewing = true;
471
-		}
472
-		else
493
+		} else
473 494
 		{
474
-			if (!isset($_REQUEST['subject']))
475
-				$_REQUEST['subject'] = '';
476
-			if (!isset($_REQUEST['message']))
477
-				$_REQUEST['message'] = '';
478
-			if (!isset($_REQUEST['icon']))
479
-				$_REQUEST['icon'] = 'xx';
495
+			if (!isset($_REQUEST['subject'])) {
496
+							$_REQUEST['subject'] = '';
497
+			}
498
+			if (!isset($_REQUEST['message'])) {
499
+							$_REQUEST['message'] = '';
500
+			}
501
+			if (!isset($_REQUEST['icon'])) {
502
+							$_REQUEST['icon'] = 'xx';
503
+			}
480 504
 
481 505
 			// They are previewing if they asked to preview (i.e. came from quick reply).
482 506
 			$really_previewing = !empty($_POST['preview']);
@@ -492,8 +516,9 @@  discard block
 block discarded – undo
492 516
 		$form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
493 517
 
494 518
 		// Make sure the subject isn't too long - taking into account special characters.
495
-		if ($smcFunc['strlen']($form_subject) > 100)
496
-			$form_subject = $smcFunc['substr']($form_subject, 0, 100);
519
+		if ($smcFunc['strlen']($form_subject) > 100) {
520
+					$form_subject = $smcFunc['substr']($form_subject, 0, 100);
521
+		}
497 522
 
498 523
 		if (isset($_REQUEST['poll']))
499 524
 		{
@@ -505,8 +530,9 @@  discard block
 block discarded – undo
505 530
 			$_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
506 531
 			foreach ($_POST['options'] as $option)
507 532
 			{
508
-				if (trim($option) == '')
509
-					continue;
533
+				if (trim($option) == '') {
534
+									continue;
535
+				}
510 536
 
511 537
 				$context['choices'][] = array(
512 538
 					'id' => $choice_id++,
@@ -568,13 +594,14 @@  discard block
 block discarded – undo
568 594
 				$context['preview_subject'] = $form_subject;
569 595
 
570 596
 				censorText($context['preview_subject']);
597
+			} else {
598
+							$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
571 599
 			}
572
-			else
573
-				$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
574 600
 
575 601
 			// Protect any CDATA blocks.
576
-			if (isset($_REQUEST['xml']))
577
-				$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
602
+			if (isset($_REQUEST['xml'])) {
603
+							$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
604
+			}
578 605
 		}
579 606
 
580 607
 		// Set up the checkboxes.
@@ -613,29 +640,32 @@  discard block
 block discarded – undo
613 640
 			);
614 641
 			// The message they were trying to edit was most likely deleted.
615 642
 			// @todo Change this error message?
616
-			if ($smcFunc['db_num_rows']($request) == 0)
617
-				fatal_lang_error('no_board', false);
643
+			if ($smcFunc['db_num_rows']($request) == 0) {
644
+							fatal_lang_error('no_board', false);
645
+			}
618 646
 			$row = $smcFunc['db_fetch_assoc']($request);
619 647
 
620 648
 			$attachment_stuff = array($row);
621
-			while ($row2 = $smcFunc['db_fetch_assoc']($request))
622
-				$attachment_stuff[] = $row2;
649
+			while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
650
+							$attachment_stuff[] = $row2;
651
+			}
623 652
 			$smcFunc['db_free_result']($request);
624 653
 
625 654
 			if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
626 655
 			{
627 656
 				// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
628
-				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
629
-					fatal_lang_error('modify_post_time_passed', false);
630
-				elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
631
-					isAllowedTo('modify_replies');
632
-				else
633
-					isAllowedTo('modify_own');
657
+				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
658
+									fatal_lang_error('modify_post_time_passed', false);
659
+				} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
660
+									isAllowedTo('modify_replies');
661
+				} else {
662
+									isAllowedTo('modify_own');
663
+				}
664
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
665
+							isAllowedTo('modify_replies');
666
+			} else {
667
+							isAllowedTo('modify_any');
634 668
 			}
635
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
636
-				isAllowedTo('modify_replies');
637
-			else
638
-				isAllowedTo('modify_any');
639 669
 
640 670
 			if ($context['can_announce'] && !empty($row['id_action']))
641 671
 			{
@@ -659,8 +689,9 @@  discard block
 block discarded – undo
659 689
 
660 690
 				while ($row = $smcFunc['db_fetch_assoc']($request))
661 691
 				{
662
-					if ($row['filesize'] <= 0)
663
-						continue;
692
+					if ($row['filesize'] <= 0) {
693
+											continue;
694
+					}
664 695
 					$context['current_attachments'][$row['id_attach']] = array(
665 696
 						'name' => $smcFunc['htmlspecialchars']($row['filename']),
666 697
 						'size' => $row['filesize'],
@@ -730,29 +761,32 @@  discard block
 block discarded – undo
730 761
 			)
731 762
 		);
732 763
 		// The message they were trying to edit was most likely deleted.
733
-		if ($smcFunc['db_num_rows']($request) == 0)
734
-			fatal_lang_error('no_message', false);
764
+		if ($smcFunc['db_num_rows']($request) == 0) {
765
+					fatal_lang_error('no_message', false);
766
+		}
735 767
 		$row = $smcFunc['db_fetch_assoc']($request);
736 768
 
737 769
 		$attachment_stuff = array($row);
738
-		while ($row2 = $smcFunc['db_fetch_assoc']($request))
739
-			$attachment_stuff[] = $row2;
770
+		while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
771
+					$attachment_stuff[] = $row2;
772
+		}
740 773
 		$smcFunc['db_free_result']($request);
741 774
 
742 775
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
743 776
 		{
744 777
 			// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
745
-			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
746
-				fatal_lang_error('modify_post_time_passed', false);
747
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
748
-				isAllowedTo('modify_replies');
749
-			else
750
-				isAllowedTo('modify_own');
778
+			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
779
+							fatal_lang_error('modify_post_time_passed', false);
780
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
781
+							isAllowedTo('modify_replies');
782
+			} else {
783
+							isAllowedTo('modify_own');
784
+			}
785
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
786
+					isAllowedTo('modify_replies');
787
+		} else {
788
+					isAllowedTo('modify_any');
751 789
 		}
752
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
753
-			isAllowedTo('modify_replies');
754
-		else
755
-			isAllowedTo('modify_any');
756 790
 
757 791
 		if ($context['can_announce'] && !empty($row['id_action']))
758 792
 		{
@@ -779,15 +813,17 @@  discard block
 block discarded – undo
779 813
 		$context['icon'] = $row['icon'];
780 814
 
781 815
 		// Show an "approve" box if the user can approve it, and the message isn't approved.
782
-		if (!$row['approved'] && !$context['show_approval'])
783
-			$context['show_approval'] = allowedTo('approve_posts');
816
+		if (!$row['approved'] && !$context['show_approval']) {
817
+					$context['show_approval'] = allowedTo('approve_posts');
818
+		}
784 819
 
785 820
 		// Sort the attachments so they are in the order saved
786 821
 		$temp = array();
787 822
 		foreach ($attachment_stuff as $attachment)
788 823
 		{
789
-			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
790
-				$temp[$attachment['id_attach']] = $attachment;
824
+			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) {
825
+							$temp[$attachment['id_attach']] = $attachment;
826
+			}
791 827
 
792 828
 		}
793 829
 		ksort($temp);
@@ -849,14 +885,16 @@  discard block
 block discarded – undo
849 885
 					'is_approved' => 1,
850 886
 				)
851 887
 			);
852
-			if ($smcFunc['db_num_rows']($request) == 0)
853
-				fatal_lang_error('quoted_post_deleted', false);
888
+			if ($smcFunc['db_num_rows']($request) == 0) {
889
+							fatal_lang_error('quoted_post_deleted', false);
890
+			}
854 891
 			list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
855 892
 			$smcFunc['db_free_result']($request);
856 893
 
857 894
 			// Add 'Re: ' to the front of the quoted subject.
858
-			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
859
-				$form_subject = $context['response_prefix'] . $form_subject;
895
+			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
896
+							$form_subject = $context['response_prefix'] . $form_subject;
897
+			}
860 898
 
861 899
 			// Censor the message and subject.
862 900
 			censorText($form_message);
@@ -869,10 +907,11 @@  discard block
 block discarded – undo
869 907
 				for ($i = 0, $n = count($parts); $i < $n; $i++)
870 908
 				{
871 909
 					// It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
872
-					if ($i % 4 == 0)
873
-						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
910
+					if ($i % 4 == 0) {
911
+											$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
874 912
 						{
875 913
 							return '[html]' . preg_replace('~<br\s?/?' . '>~i', '&lt;br /&gt;<br>', "$m[1]") . '[/html]';
914
+					}
876 915
 						}, $parts[$i]);
877 916
 				}
878 917
 				$form_message = implode('', $parts);
@@ -881,8 +920,9 @@  discard block
 block discarded – undo
881 920
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
882 921
 
883 922
 			// Remove any nested quotes, if necessary.
884
-			if (!empty($modSettings['removeNestedQuotes']))
885
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
923
+			if (!empty($modSettings['removeNestedQuotes'])) {
924
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
925
+			}
886 926
 
887 927
 			// Add a quote string on the front and end.
888 928
 			$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
@@ -894,15 +934,15 @@  discard block
 block discarded – undo
894 934
 			$form_subject = $first_subject;
895 935
 
896 936
 			// Add 'Re: ' to the front of the subject.
897
-			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
898
-				$form_subject = $context['response_prefix'] . $form_subject;
937
+			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
938
+							$form_subject = $context['response_prefix'] . $form_subject;
939
+			}
899 940
 
900 941
 			// Censor the subject.
901 942
 			censorText($form_subject);
902 943
 
903 944
 			$form_message = '';
904
-		}
905
-		else
945
+		} else
906 946
 		{
907 947
 			$form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
908 948
 			$form_message = '';
@@ -921,13 +961,15 @@  discard block
 block discarded – undo
921 961
 		if (isset($_REQUEST['msg']))
922 962
 		{
923 963
 			$context['attachments']['quantity'] = count($context['current_attachments']);
924
-			foreach ($context['current_attachments'] as $attachment)
925
-				$context['attachments']['total_size'] += $attachment['size'];
964
+			foreach ($context['current_attachments'] as $attachment) {
965
+							$context['attachments']['total_size'] += $attachment['size'];
966
+			}
926 967
 		}
927 968
 
928 969
 		// A bit of house keeping first.
929
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
930
-			unset($_SESSION['temp_attachments']);
970
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
971
+					unset($_SESSION['temp_attachments']);
972
+		}
931 973
 
932 974
 		if (!empty($_SESSION['temp_attachments']))
933 975
 		{
@@ -936,9 +978,10 @@  discard block
 block discarded – undo
936 978
 			{
937 979
 				foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
938 980
 				{
939
-					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
940
-						if (file_exists($attachment['tmp_name']))
981
+					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) {
982
+											if (file_exists($attachment['tmp_name']))
941 983
 							unlink($attachment['tmp_name']);
984
+					}
942 985
 				}
943 986
 				$post_errors[] = 'temp_attachments_gone';
944 987
 				$_SESSION['temp_attachments'] = array();
@@ -952,8 +995,9 @@  discard block
 block discarded – undo
952 995
 					// See if any files still exist before showing the warning message and the files attached.
953 996
 					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
954 997
 					{
955
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
956
-							continue;
998
+						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
999
+													continue;
1000
+						}
957 1001
 
958 1002
 						if (file_exists($attachment['tmp_name']))
959 1003
 						{
@@ -963,20 +1007,21 @@  discard block
 block discarded – undo
963 1007
 							break;
964 1008
 						}
965 1009
 					}
966
-				}
967
-				else
1010
+				} else
968 1011
 				{
969 1012
 					// Since, they don't belong here. Let's inform the user that they exist..
970
-					if (!empty($topic))
971
-						$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
972
-					else
973
-						$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1013
+					if (!empty($topic)) {
1014
+											$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
1015
+					} else {
1016
+											$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1017
+					}
974 1018
 
975 1019
 					// Compile a list of the files to show the user.
976 1020
 					$file_list = array();
977
-					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
978
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
1021
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
1022
+											if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
979 1023
 							$file_list[] = $attachment['name'];
1024
+					}
980 1025
 
981 1026
 					$_SESSION['temp_attachments']['post']['files'] = $file_list;
982 1027
 					$file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>';
@@ -988,8 +1033,7 @@  discard block
 block discarded – undo
988 1033
 
989 1034
 						$post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list));
990 1035
 						$context['ignore_temp_attachments'] = true;
991
-					}
992
-					else
1036
+					} else
993 1037
 					{
994 1038
 						$post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list));
995 1039
 						$context['ignore_temp_attachments'] = true;
@@ -997,16 +1041,19 @@  discard block
 block discarded – undo
997 1041
 				}
998 1042
 			}
999 1043
 
1000
-			if (!empty($context['we_are_history']))
1001
-				$post_errors[] = $context['we_are_history'];
1044
+			if (!empty($context['we_are_history'])) {
1045
+							$post_errors[] = $context['we_are_history'];
1046
+			}
1002 1047
 
1003 1048
 			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1004 1049
 			{
1005
-				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
1006
-					break;
1050
+				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) {
1051
+									break;
1052
+				}
1007 1053
 
1008
-				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1009
-					continue;
1054
+				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1055
+									continue;
1056
+				}
1010 1057
 
1011 1058
 				if ($attachID == 'initial_error')
1012 1059
 				{
@@ -1021,15 +1068,17 @@  discard block
 block discarded – undo
1021 1068
 				{
1022 1069
 					$txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : '';
1023 1070
 					$txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
1024
-					foreach ($attachment['errors'] as $error)
1025
-						$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1071
+					foreach ($attachment['errors'] as $error) {
1072
+											$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1073
+					}
1026 1074
 					$txt['error_attach_errors'] .= '</div>';
1027 1075
 					$post_errors[] = 'attach_errors';
1028 1076
 
1029 1077
 					// Take out the trash.
1030 1078
 					unset($_SESSION['temp_attachments'][$attachID]);
1031
-					if (file_exists($attachment['tmp_name']))
1032
-						unlink($attachment['tmp_name']);
1079
+					if (file_exists($attachment['tmp_name'])) {
1080
+											unlink($attachment['tmp_name']);
1081
+					}
1033 1082
 					continue;
1034 1083
 				}
1035 1084
 
@@ -1042,8 +1091,9 @@  discard block
 block discarded – undo
1042 1091
 
1043 1092
 				$context['attachments']['quantity']++;
1044 1093
 				$context['attachments']['total_size'] += $attachment['size'];
1045
-				if (!isset($context['files_in_session_warning']))
1046
-					$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1094
+				if (!isset($context['files_in_session_warning'])) {
1095
+									$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1096
+				}
1047 1097
 
1048 1098
 				$context['current_attachments'][$attachID] = array(
1049 1099
 					'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>',
@@ -1071,8 +1121,9 @@  discard block
 block discarded – undo
1071 1121
 	}
1072 1122
 
1073 1123
 	// If they came from quick reply, and have to enter verification details, give them some notice.
1074
-	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
1075
-		$post_errors[] = 'need_qr_verification';
1124
+	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) {
1125
+			$post_errors[] = 'need_qr_verification';
1126
+	}
1076 1127
 
1077 1128
 	/*
1078 1129
 	 * There are two error types: serious and minor. Serious errors
@@ -1089,52 +1140,56 @@  discard block
 block discarded – undo
1089 1140
 	{
1090 1141
 		loadLanguage('Errors');
1091 1142
 		$context['error_type'] = 'minor';
1092
-		foreach ($post_errors as $post_error)
1093
-			if (is_array($post_error))
1143
+		foreach ($post_errors as $post_error) {
1144
+					if (is_array($post_error))
1094 1145
 			{
1095 1146
 				$post_error_id = $post_error[0];
1147
+		}
1096 1148
 				$context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]);
1097 1149
 
1098 1150
 				// If it's not a minor error flag it as such.
1099
-				if (!in_array($post_error_id, $minor_errors))
1100
-					$context['error_type'] = 'serious';
1101
-			}
1102
-			else
1151
+				if (!in_array($post_error_id, $minor_errors)) {
1152
+									$context['error_type'] = 'serious';
1153
+				}
1154
+			} else
1103 1155
 			{
1104 1156
 				$context['post_error'][$post_error] = $txt['error_' . $post_error];
1105 1157
 
1106 1158
 				// If it's not a minor error flag it as such.
1107
-				if (!in_array($post_error, $minor_errors))
1108
-					$context['error_type'] = 'serious';
1159
+				if (!in_array($post_error, $minor_errors)) {
1160
+									$context['error_type'] = 'serious';
1161
+				}
1109 1162
 			}
1110 1163
 	}
1111 1164
 
1112 1165
 	// What are you doing? Posting a poll, modifying, previewing, new post, or reply...
1113
-	if (isset($_REQUEST['poll']))
1114
-		$context['page_title'] = $txt['new_poll'];
1115
-	elseif ($context['make_event'])
1116
-		$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1117
-	elseif (isset($_REQUEST['msg']))
1118
-		$context['page_title'] = $txt['modify_msg'];
1119
-	elseif (isset($_REQUEST['subject'], $context['preview_subject']))
1120
-		$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1121
-	elseif (empty($topic))
1122
-		$context['page_title'] = $txt['start_new_topic'];
1123
-	else
1124
-		$context['page_title'] = $txt['post_reply'];
1166
+	if (isset($_REQUEST['poll'])) {
1167
+			$context['page_title'] = $txt['new_poll'];
1168
+	} elseif ($context['make_event']) {
1169
+			$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1170
+	} elseif (isset($_REQUEST['msg'])) {
1171
+			$context['page_title'] = $txt['modify_msg'];
1172
+	} elseif (isset($_REQUEST['subject'], $context['preview_subject'])) {
1173
+			$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1174
+	} elseif (empty($topic)) {
1175
+			$context['page_title'] = $txt['start_new_topic'];
1176
+	} else {
1177
+			$context['page_title'] = $txt['post_reply'];
1178
+	}
1125 1179
 
1126 1180
 	// Build the link tree.
1127
-	if (empty($topic))
1128
-		$context['linktree'][] = array(
1181
+	if (empty($topic)) {
1182
+			$context['linktree'][] = array(
1129 1183
 			'name' => '<em>' . $txt['start_new_topic'] . '</em>'
1130 1184
 		);
1131
-	else
1132
-		$context['linktree'][] = array(
1185
+	} else {
1186
+			$context['linktree'][] = array(
1133 1187
 			'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
1134 1188
 			'name' => $form_subject,
1135 1189
 			'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>',
1136 1190
 			'extra_after' => '<span><strong class="nav">)</strong></span>'
1137 1191
 		);
1192
+	}
1138 1193
 
1139 1194
 	$context['subject'] = addcslashes($form_subject, '"');
1140 1195
 	$context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
@@ -1178,8 +1233,9 @@  discard block
 block discarded – undo
1178 1233
 	// Message icons - customized icons are off?
1179 1234
 	$context['icons'] = getMessageIcons(!empty($board) ? $board : 0);
1180 1235
 
1181
-	if (!empty($context['icons']))
1182
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1236
+	if (!empty($context['icons'])) {
1237
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1238
+	}
1183 1239
 
1184 1240
 	// Are we starting a poll? if set the poll icon as selected if its available
1185 1241
 	if (isset($_REQUEST['poll']))
@@ -1199,8 +1255,9 @@  discard block
 block discarded – undo
1199 1255
 	for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
1200 1256
 	{
1201 1257
 		$context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
1202
-		if ($context['icons'][$i]['selected'])
1203
-			$context['icon_url'] = $context['icons'][$i]['url'];
1258
+		if ($context['icons'][$i]['selected']) {
1259
+					$context['icon_url'] = $context['icons'][$i]['url'];
1260
+		}
1204 1261
 	}
1205 1262
 	if (empty($context['icon_url']))
1206 1263
 	{
@@ -1214,8 +1271,9 @@  discard block
 block discarded – undo
1214 1271
 		));
1215 1272
 	}
1216 1273
 
1217
-	if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
1218
-		getTopic();
1274
+	if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) {
1275
+			getTopic();
1276
+	}
1219 1277
 
1220 1278
 	// If the user can post attachments prepare the warning labels.
1221 1279
 	if ($context['can_post_attachment'])
@@ -1226,12 +1284,13 @@  discard block
 block discarded – undo
1226 1284
 		$context['attachment_restrictions'] = array();
1227 1285
 		$context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
1228 1286
 		$attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
1229
-		foreach ($attachmentRestrictionTypes as $type)
1230
-			if (!empty($modSettings[$type]))
1287
+		foreach ($attachmentRestrictionTypes as $type) {
1288
+					if (!empty($modSettings[$type]))
1231 1289
 			{
1232 1290
 				// Show the max number of attachments if not 0.
1233 1291
 				if ($type == 'attachmentNumPerPostLimit')
1234 1292
 					$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1293
+		}
1235 1294
 			}
1236 1295
 	}
1237 1296
 
@@ -1265,8 +1324,8 @@  discard block
 block discarded – undo
1265 1324
 
1266 1325
 	if (!empty($context['current_attachments']))
1267 1326
 	{
1268
-		foreach ($context['current_attachments'] as $key => $mock)
1269
-			addInlineJavaScript('
1327
+		foreach ($context['current_attachments'] as $key => $mock) {
1328
+					addInlineJavaScript('
1270 1329
 	current_attachments.push({
1271 1330
 		name: '. JavaScriptEscape($mock['name']) . ',
1272 1331
 		size: '. $mock['size'] . ',
@@ -1275,6 +1334,7 @@  discard block
 block discarded – undo
1275 1334
 		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ',
1276 1335
 		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . '
1277 1336
 	});', true);
1337
+		}
1278 1338
 	}
1279 1339
 
1280 1340
 	// File Upload.
@@ -1349,9 +1409,10 @@  discard block
 block discarded – undo
1349 1409
 			$context['posting_fields']['board']['dd'] .= '
1350 1410
 							<optgroup label="' . $category['name'] . '">';
1351 1411
 
1352
-			foreach ($category['boards'] as $brd)
1353
-				$context['posting_fields']['board']['dd'] .= '
1412
+			foreach ($category['boards'] as $brd) {
1413
+							$context['posting_fields']['board']['dd'] .= '
1354 1414
 								<option value="' . $brd['id'] . '"' . ($brd['selected'] ? ' selected' : '') . '>' . ($brd['child_level'] > 0 ? str_repeat('==' . $brd['child_level'] - 1) . '=&gt;' : '') . ' ' . $brd['name'] . '</option>';
1415
+			}
1355 1416
 
1356 1417
 			$context['posting_fields']['board']['dd'] .= '
1357 1418
 							</optgroup>';
@@ -1382,8 +1443,9 @@  discard block
 block discarded – undo
1382 1443
 
1383 1444
 
1384 1445
 	// Finally, load the template.
1385
-	if (!isset($_REQUEST['xml']))
1386
-		loadTemplate('Post');
1446
+	if (!isset($_REQUEST['xml'])) {
1447
+			loadTemplate('Post');
1448
+	}
1387 1449
 
1388 1450
 	call_integration_hook('integrate_post_end');
1389 1451
 }
@@ -1404,13 +1466,14 @@  discard block
 block discarded – undo
1404 1466
 	// Sneaking off, are we?
1405 1467
 	if (empty($_POST) && empty($topic))
1406 1468
 	{
1407
-		if (empty($_SERVER['CONTENT_LENGTH']))
1408
-			redirectexit('action=post;board=' . $board . '.0');
1409
-		else
1410
-			fatal_lang_error('post_upload_error', false);
1469
+		if (empty($_SERVER['CONTENT_LENGTH'])) {
1470
+					redirectexit('action=post;board=' . $board . '.0');
1471
+		} else {
1472
+					fatal_lang_error('post_upload_error', false);
1473
+		}
1474
+	} elseif (empty($_POST) && !empty($topic)) {
1475
+			redirectexit('action=post;topic=' . $topic . '.0');
1411 1476
 	}
1412
-	elseif (empty($_POST) && !empty($topic))
1413
-		redirectexit('action=post;topic=' . $topic . '.0');
1414 1477
 
1415 1478
 	// No need!
1416 1479
 	$context['robot_no_index'] = true;
@@ -1422,8 +1485,9 @@  discard block
 block discarded – undo
1422 1485
 	$post_errors = array();
1423 1486
 
1424 1487
 	// If the session has timed out, let the user re-submit their form.
1425
-	if (checkSession('post', '', false) != '')
1426
-		$post_errors[] = 'session_timeout';
1488
+	if (checkSession('post', '', false) != '') {
1489
+			$post_errors[] = 'session_timeout';
1490
+	}
1427 1491
 
1428 1492
 	// Wrong verification code?
1429 1493
 	if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))
@@ -1433,33 +1497,38 @@  discard block
 block discarded – undo
1433 1497
 			'id' => 'post',
1434 1498
 		);
1435 1499
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
1436
-		if (is_array($context['require_verification']))
1437
-			$post_errors = array_merge($post_errors, $context['require_verification']);
1500
+		if (is_array($context['require_verification'])) {
1501
+					$post_errors = array_merge($post_errors, $context['require_verification']);
1502
+		}
1438 1503
 	}
1439 1504
 
1440 1505
 	require_once($sourcedir . '/Subs-Post.php');
1441 1506
 	loadLanguage('Post');
1442 1507
 
1443 1508
 	// Drafts enabled and needed?
1444
-	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
1445
-		require_once($sourcedir . '/Drafts.php');
1509
+	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) {
1510
+			require_once($sourcedir . '/Drafts.php');
1511
+	}
1446 1512
 
1447 1513
 	// First check to see if they are trying to delete any current attachments.
1448 1514
 	if (isset($_POST['attach_del']))
1449 1515
 	{
1450 1516
 		$keep_temp = array();
1451 1517
 		$keep_ids = array();
1452
-		foreach ($_POST['attach_del'] as $dummy)
1453
-			if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1518
+		foreach ($_POST['attach_del'] as $dummy) {
1519
+					if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1454 1520
 				$keep_temp[] = $dummy;
1455
-			else
1456
-				$keep_ids[] = (int) $dummy;
1521
+		}
1522
+			else {
1523
+							$keep_ids[] = (int) $dummy;
1524
+			}
1457 1525
 
1458
-		if (isset($_SESSION['temp_attachments']))
1459
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1526
+		if (isset($_SESSION['temp_attachments'])) {
1527
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1460 1528
 			{
1461 1529
 				if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1462 1530
 					continue;
1531
+		}
1463 1532
 
1464 1533
 				unset($_SESSION['temp_attachments'][$attachID]);
1465 1534
 				unlink($attachment['tmp_name']);
@@ -1491,8 +1560,9 @@  discard block
 block discarded – undo
1491 1560
 	{
1492 1561
 		require_once($sourcedir . '/ManageAttachments.php');
1493 1562
 
1494
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
1495
-			removeAttachments(array('id_attach' => $attachID));
1563
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
1564
+					removeAttachments(array('id_attach' => $attachID));
1565
+		}
1496 1566
 
1497 1567
 		unset($_SESSION['already_attached']);
1498 1568
 
@@ -1515,12 +1585,14 @@  discard block
 block discarded – undo
1515 1585
 		$smcFunc['db_free_result']($request);
1516 1586
 
1517 1587
 		// Though the topic should be there, it might have vanished.
1518
-		if (!is_array($topic_info))
1519
-			fatal_lang_error('topic_doesnt_exist', 404);
1588
+		if (!is_array($topic_info)) {
1589
+					fatal_lang_error('topic_doesnt_exist', 404);
1590
+		}
1520 1591
 
1521 1592
 		// Did this topic suddenly move? Just checking...
1522
-		if ($topic_info['id_board'] != $board)
1523
-			fatal_lang_error('not_a_topic');
1593
+		if ($topic_info['id_board'] != $board) {
1594
+					fatal_lang_error('not_a_topic');
1595
+		}
1524 1596
 
1525 1597
 		// Do the permissions and approval stuff...
1526 1598
 		$becomesApproved = true;
@@ -1543,49 +1615,50 @@  discard block
 block discarded – undo
1543 1615
 	if (!empty($topic) && !isset($_REQUEST['msg']))
1544 1616
 	{
1545 1617
 		// Don't allow a post if it's locked.
1546
-		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
1547
-			fatal_lang_error('topic_locked', false);
1618
+		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) {
1619
+					fatal_lang_error('topic_locked', false);
1620
+		}
1548 1621
 
1549 1622
 		// Sorry, multiple polls aren't allowed... yet.  You should stop giving me ideas :P.
1550
-		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
1551
-			unset($_REQUEST['poll']);
1552
-
1553
-		elseif ($topic_info['id_member_started'] != $user_info['id'])
1554
-		{
1555
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
1556
-				$becomesApproved = false;
1557
-
1558
-			else
1559
-				isAllowedTo('post_reply_any');
1560
-		}
1561
-		elseif (!allowedTo('post_reply_any'))
1623
+		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) {
1624
+					unset($_REQUEST['poll']);
1625
+		} elseif ($topic_info['id_member_started'] != $user_info['id'])
1626
+		{
1627
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
1628
+							$becomesApproved = false;
1629
+			} else {
1630
+							isAllowedTo('post_reply_any');
1631
+			}
1632
+		} elseif (!allowedTo('post_reply_any'))
1562 1633
 		{
1563
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
1564
-				$becomesApproved = false;
1565
-
1566
-			else
1567
-				isAllowedTo('post_reply_own');
1634
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) {
1635
+							$becomesApproved = false;
1636
+			} else {
1637
+							isAllowedTo('post_reply_own');
1638
+			}
1568 1639
 		}
1569 1640
 
1570 1641
 		if (isset($_POST['lock']))
1571 1642
 		{
1572 1643
 			// Nothing is changed to the lock.
1573
-			if (empty($topic_info['locked']) == empty($_POST['lock']))
1574
-				unset($_POST['lock']);
1644
+			if (empty($topic_info['locked']) == empty($_POST['lock'])) {
1645
+							unset($_POST['lock']);
1646
+			}
1575 1647
 
1576 1648
 			// You're have no permission to lock this topic.
1577
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1578
-				unset($_POST['lock']);
1649
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1650
+							unset($_POST['lock']);
1651
+			}
1579 1652
 
1580 1653
 			// You are allowed to (un)lock your own topic only.
1581 1654
 			elseif (!allowedTo('lock_any'))
1582 1655
 			{
1583 1656
 				// You cannot override a moderator lock.
1584
-				if ($topic_info['locked'] == 1)
1585
-					unset($_POST['lock']);
1586
-
1587
-				else
1588
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1657
+				if ($topic_info['locked'] == 1) {
1658
+									unset($_POST['lock']);
1659
+				} else {
1660
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1661
+				}
1589 1662
 			}
1590 1663
 			// Hail mighty moderator, (un)lock this topic immediately.
1591 1664
 			else
@@ -1593,19 +1666,21 @@  discard block
 block discarded – undo
1593 1666
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1594 1667
 
1595 1668
 				// Did someone (un)lock this while you were posting?
1596
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1597
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1669
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1670
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1671
+				}
1598 1672
 			}
1599 1673
 		}
1600 1674
 
1601 1675
 		// So you wanna (un)sticky this...let's see.
1602
-		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
1603
-			unset($_POST['sticky']);
1604
-		elseif (isset($_POST['sticky']))
1676
+		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) {
1677
+					unset($_POST['sticky']);
1678
+		} elseif (isset($_POST['sticky']))
1605 1679
 		{
1606 1680
 			// Did someone (un)sticky this while you were posting?
1607
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1608
-				$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1681
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1682
+							$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1683
+			}
1609 1684
 		}
1610 1685
 
1611 1686
 		// If drafts are enabled, then pass this off
@@ -1632,26 +1707,31 @@  discard block
 block discarded – undo
1632 1707
 
1633 1708
 		// Do like, the permissions, for safety and stuff...
1634 1709
 		$becomesApproved = true;
1635
-		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
1636
-			$becomesApproved = false;
1637
-		else
1638
-			isAllowedTo('post_new');
1710
+		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
1711
+					$becomesApproved = false;
1712
+		} else {
1713
+					isAllowedTo('post_new');
1714
+		}
1639 1715
 
1640 1716
 		if (isset($_POST['lock']))
1641 1717
 		{
1642 1718
 			// New topics are by default not locked.
1643
-			if (empty($_POST['lock']))
1644
-				unset($_POST['lock']);
1719
+			if (empty($_POST['lock'])) {
1720
+							unset($_POST['lock']);
1721
+			}
1645 1722
 			// Besides, you need permission.
1646
-			elseif (!allowedTo(array('lock_any', 'lock_own')))
1647
-				unset($_POST['lock']);
1723
+			elseif (!allowedTo(array('lock_any', 'lock_own'))) {
1724
+							unset($_POST['lock']);
1725
+			}
1648 1726
 			// A moderator-lock (1) can override a user-lock (2).
1649
-			else
1650
-				$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1727
+			else {
1728
+							$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1729
+			}
1651 1730
 		}
1652 1731
 
1653
-		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky')))
1654
-			unset($_POST['sticky']);
1732
+		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) {
1733
+					unset($_POST['sticky']);
1734
+		}
1655 1735
 
1656 1736
 		// Saving your new topic as a draft first?
1657 1737
 		if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft']))
@@ -1676,31 +1756,37 @@  discard block
 block discarded – undo
1676 1756
 				'id_msg' => $_REQUEST['msg'],
1677 1757
 			)
1678 1758
 		);
1679
-		if ($smcFunc['db_num_rows']($request) == 0)
1680
-			fatal_lang_error('cant_find_messages', false);
1759
+		if ($smcFunc['db_num_rows']($request) == 0) {
1760
+					fatal_lang_error('cant_find_messages', false);
1761
+		}
1681 1762
 		$row = $smcFunc['db_fetch_assoc']($request);
1682 1763
 		$smcFunc['db_free_result']($request);
1683 1764
 
1684
-		if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
1685
-			fatal_lang_error('topic_locked', false);
1765
+		if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) {
1766
+					fatal_lang_error('topic_locked', false);
1767
+		}
1686 1768
 
1687 1769
 		if (isset($_POST['lock']))
1688 1770
 		{
1689 1771
 			// Nothing changes to the lock status.
1690
-			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1691
-				unset($_POST['lock']);
1772
+			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1773
+							unset($_POST['lock']);
1774
+			}
1692 1775
 			// You're simply not allowed to (un)lock this.
1693
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1694
-				unset($_POST['lock']);
1776
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1777
+							unset($_POST['lock']);
1778
+			}
1695 1779
 			// You're only allowed to lock your own topics.
1696 1780
 			elseif (!allowedTo('lock_any'))
1697 1781
 			{
1698 1782
 				// You're not allowed to break a moderator's lock.
1699
-				if ($topic_info['locked'] == 1)
1700
-					unset($_POST['lock']);
1783
+				if ($topic_info['locked'] == 1) {
1784
+									unset($_POST['lock']);
1785
+				}
1701 1786
 				// Lock it with a soft lock or unlock it.
1702
-				else
1703
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1787
+				else {
1788
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1789
+				}
1704 1790
 			}
1705 1791
 			// You must be the moderator.
1706 1792
 			else
@@ -1708,44 +1794,46 @@  discard block
 block discarded – undo
1708 1794
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1709 1795
 
1710 1796
 				// Did someone (un)lock this while you were posting?
1711
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1712
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1797
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1798
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1799
+				}
1713 1800
 			}
1714 1801
 		}
1715 1802
 
1716 1803
 		// Change the sticky status of this topic?
1717
-		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
1718
-			unset($_POST['sticky']);
1719
-		elseif (isset($_POST['sticky']))
1804
+		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) {
1805
+					unset($_POST['sticky']);
1806
+		} elseif (isset($_POST['sticky']))
1720 1807
 		{
1721 1808
 			// Did someone (un)sticky this while you were posting?
1722
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1723
-				$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1809
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1810
+							$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1811
+			}
1724 1812
 		}
1725 1813
 
1726 1814
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
1727 1815
 		{
1728
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
1729
-				fatal_lang_error('modify_post_time_passed', false);
1730
-			elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
1731
-				isAllowedTo('modify_replies');
1732
-			else
1733
-				isAllowedTo('modify_own');
1734
-		}
1735
-		elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1816
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
1817
+							fatal_lang_error('modify_post_time_passed', false);
1818
+			} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
1819
+							isAllowedTo('modify_replies');
1820
+			} else {
1821
+							isAllowedTo('modify_own');
1822
+			}
1823
+		} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1736 1824
 		{
1737 1825
 			isAllowedTo('modify_replies');
1738 1826
 
1739 1827
 			// If you're modifying a reply, I say it better be logged...
1740 1828
 			$moderationAction = true;
1741
-		}
1742
-		else
1829
+		} else
1743 1830
 		{
1744 1831
 			isAllowedTo('modify_any');
1745 1832
 
1746 1833
 			// Log it, assuming you're not modifying your own post.
1747
-			if ($row['id_member'] != $user_info['id'])
1748
-				$moderationAction = true;
1834
+			if ($row['id_member'] != $user_info['id']) {
1835
+							$moderationAction = true;
1836
+			}
1749 1837
 		}
1750 1838
 
1751 1839
 		// If drafts are enabled, then lets send this off to save
@@ -1783,20 +1871,24 @@  discard block
 block discarded – undo
1783 1871
 		$_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
1784 1872
 		$_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
1785 1873
 
1786
-		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
1787
-			$post_errors[] = 'no_name';
1788
-		if ($smcFunc['strlen']($_POST['guestname']) > 25)
1789
-			$post_errors[] = 'long_name';
1874
+		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') {
1875
+					$post_errors[] = 'no_name';
1876
+		}
1877
+		if ($smcFunc['strlen']($_POST['guestname']) > 25) {
1878
+					$post_errors[] = 'long_name';
1879
+		}
1790 1880
 
1791 1881
 		if (empty($modSettings['guest_post_no_email']))
1792 1882
 		{
1793 1883
 			// Only check if they changed it!
1794 1884
 			if (!isset($row) || $row['poster_email'] != $_POST['email'])
1795 1885
 			{
1796
-				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
1797
-					$post_errors[] = 'no_email';
1798
-				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
1799
-					$post_errors[] = 'bad_email';
1886
+				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) {
1887
+									$post_errors[] = 'no_email';
1888
+				}
1889
+				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
1890
+									$post_errors[] = 'bad_email';
1891
+				}
1800 1892
 			}
1801 1893
 
1802 1894
 			// Now make sure this email address is not banned from posting.
@@ -1812,75 +1904,89 @@  discard block
 block discarded – undo
1812 1904
 	}
1813 1905
 
1814 1906
 	// Coming from the quickReply?
1815
-	if (isset($_POST['quickReply']))
1816
-		$_POST['message'] = $_POST['quickReply'];
1907
+	if (isset($_POST['quickReply'])) {
1908
+			$_POST['message'] = $_POST['quickReply'];
1909
+	}
1817 1910
 
1818 1911
 	// Check the subject and message.
1819
-	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
1820
-		$post_errors[] = 'no_subject';
1821
-	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
1822
-		$post_errors[] = 'no_message';
1823
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
1824
-		$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1825
-	else
1912
+	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') {
1913
+			$post_errors[] = 'no_subject';
1914
+	}
1915
+	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') {
1916
+			$post_errors[] = 'no_message';
1917
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) {
1918
+			$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1919
+	} else
1826 1920
 	{
1827 1921
 		// Prepare the message a bit for some additional testing.
1828 1922
 		$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
1829 1923
 
1830 1924
 		// Preparse code. (Zef)
1831
-		if ($user_info['is_guest'])
1832
-			$user_info['name'] = $_POST['guestname'];
1925
+		if ($user_info['is_guest']) {
1926
+					$user_info['name'] = $_POST['guestname'];
1927
+		}
1833 1928
 		preparsecode($_POST['message']);
1834 1929
 
1835 1930
 		// Let's see if there's still some content left without the tags.
1836
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
1837
-			$post_errors[] = 'no_message';
1931
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) {
1932
+					$post_errors[] = 'no_message';
1933
+		}
1934
+	}
1935
+	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') {
1936
+			$post_errors[] = 'no_event';
1838 1937
 	}
1839
-	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
1840
-		$post_errors[] = 'no_event';
1841 1938
 	// You are not!
1842
-	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
1843
-		fatal_error('Knave! Masquerader! Charlatan!', false);
1939
+	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) {
1940
+			fatal_error('Knave! Masquerader! Charlatan!', false);
1941
+	}
1844 1942
 
1845 1943
 	// Validate the poll...
1846 1944
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
1847 1945
 	{
1848
-		if (!empty($topic) && !isset($_REQUEST['msg']))
1849
-			fatal_lang_error('no_access', false);
1946
+		if (!empty($topic) && !isset($_REQUEST['msg'])) {
1947
+					fatal_lang_error('no_access', false);
1948
+		}
1850 1949
 
1851 1950
 		// This is a new topic... so it's a new poll.
1852
-		if (empty($topic))
1853
-			isAllowedTo('poll_post');
1951
+		if (empty($topic)) {
1952
+					isAllowedTo('poll_post');
1953
+		}
1854 1954
 		// Can you add to your own topics?
1855
-		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
1856
-			isAllowedTo('poll_add_own');
1955
+		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) {
1956
+					isAllowedTo('poll_add_own');
1957
+		}
1857 1958
 		// Can you add polls to any topic, then?
1858
-		else
1859
-			isAllowedTo('poll_add_any');
1959
+		else {
1960
+					isAllowedTo('poll_add_any');
1961
+		}
1860 1962
 
1861
-		if (!isset($_POST['question']) || trim($_POST['question']) == '')
1862
-			$post_errors[] = 'no_question';
1963
+		if (!isset($_POST['question']) || trim($_POST['question']) == '') {
1964
+					$post_errors[] = 'no_question';
1965
+		}
1863 1966
 
1864 1967
 		$_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
1865 1968
 
1866 1969
 		// Get rid of empty ones.
1867
-		foreach ($_POST['options'] as $k => $option)
1868
-			if ($option == '')
1970
+		foreach ($_POST['options'] as $k => $option) {
1971
+					if ($option == '')
1869 1972
 				unset($_POST['options'][$k], $_POST['options'][$k]);
1973
+		}
1870 1974
 
1871 1975
 		// What are you going to vote between with one choice?!?
1872
-		if (count($_POST['options']) < 2)
1873
-			$post_errors[] = 'poll_few';
1874
-		elseif (count($_POST['options']) > 256)
1875
-			$post_errors[] = 'poll_many';
1976
+		if (count($_POST['options']) < 2) {
1977
+					$post_errors[] = 'poll_few';
1978
+		} elseif (count($_POST['options']) > 256) {
1979
+					$post_errors[] = 'poll_many';
1980
+		}
1876 1981
 	}
1877 1982
 
1878 1983
 	if ($posterIsGuest)
1879 1984
 	{
1880 1985
 		// If user is a guest, make sure the chosen name isn't taken.
1881 1986
 		require_once($sourcedir . '/Subs-Members.php');
1882
-		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
1883
-			$post_errors[] = 'bad_name';
1987
+		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) {
1988
+					$post_errors[] = 'bad_name';
1989
+		}
1884 1990
 	}
1885 1991
 	// If the user isn't a guest, get his or her name and email.
1886 1992
 	elseif (!isset($_REQUEST['msg']))
@@ -1911,8 +2017,9 @@  discard block
 block discarded – undo
1911 2017
 	}
1912 2018
 
1913 2019
 	// Make sure the user isn't spamming the board.
1914
-	if (!isset($_REQUEST['msg']))
1915
-		spamProtection('post');
2020
+	if (!isset($_REQUEST['msg'])) {
2021
+			spamProtection('post');
2022
+	}
1916 2023
 
1917 2024
 	// At about this point, we're posting and that's that.
1918 2025
 	ignore_user_abort(true);
@@ -1925,32 +2032,36 @@  discard block
 block discarded – undo
1925 2032
 	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
1926 2033
 
1927 2034
 	// At this point, we want to make sure the subject isn't too long.
1928
-	if ($smcFunc['strlen']($_POST['subject']) > 100)
1929
-		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2035
+	if ($smcFunc['strlen']($_POST['subject']) > 100) {
2036
+			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2037
+	}
1930 2038
 
1931 2039
 	// Same with the "why did you edit this" text.
1932
-	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
1933
-		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2040
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
2041
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2042
+	}
1934 2043
 
1935 2044
 	// Make the poll...
1936 2045
 	if (isset($_REQUEST['poll']))
1937 2046
 	{
1938 2047
 		// Make sure that the user has not entered a ridiculous number of options..
1939
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
1940
-			$_POST['poll_max_votes'] = 1;
1941
-		elseif ($_POST['poll_max_votes'] > count($_POST['options']))
1942
-			$_POST['poll_max_votes'] = count($_POST['options']);
1943
-		else
1944
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2048
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
2049
+					$_POST['poll_max_votes'] = 1;
2050
+		} elseif ($_POST['poll_max_votes'] > count($_POST['options'])) {
2051
+					$_POST['poll_max_votes'] = count($_POST['options']);
2052
+		} else {
2053
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2054
+		}
1945 2055
 
1946 2056
 		$_POST['poll_expire'] = (int) $_POST['poll_expire'];
1947 2057
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
1948 2058
 
1949 2059
 		// Just set it to zero if it's not there..
1950
-		if (!isset($_POST['poll_hide']))
1951
-			$_POST['poll_hide'] = 0;
1952
-		else
1953
-			$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2060
+		if (!isset($_POST['poll_hide'])) {
2061
+					$_POST['poll_hide'] = 0;
2062
+		} else {
2063
+					$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2064
+		}
1954 2065
 		$_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
1955 2066
 
1956 2067
 		$_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
@@ -1959,16 +2070,19 @@  discard block
 block discarded – undo
1959 2070
 		{
1960 2071
 			require_once($sourcedir . '/Subs-Members.php');
1961 2072
 			$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
1962
-			if (!in_array(-1, $allowedVoteGroups['allowed']))
1963
-				$_POST['poll_guest_vote'] = 0;
2073
+			if (!in_array(-1, $allowedVoteGroups['allowed'])) {
2074
+							$_POST['poll_guest_vote'] = 0;
2075
+			}
1964 2076
 		}
1965 2077
 
1966 2078
 		// If the user tries to set the poll too far in advance, don't let them.
1967
-		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
1968
-			fatal_lang_error('poll_range_error', false);
2079
+		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
2080
+					fatal_lang_error('poll_range_error', false);
2081
+		}
1969 2082
 		// Don't allow them to select option 2 for hidden results if it's not time limited.
1970
-		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
1971
-			$_POST['poll_hide'] = 1;
2083
+		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
2084
+					$_POST['poll_hide'] = 1;
2085
+		}
1972 2086
 
1973 2087
 		// Clean up the question and answers.
1974 2088
 		$_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']);
@@ -1982,13 +2096,15 @@  discard block
 block discarded – undo
1982 2096
 	{
1983 2097
 		$attachIDs = array();
1984 2098
 		$attach_errors = array();
1985
-		if (!empty($context['we_are_history']))
1986
-			$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2099
+		if (!empty($context['we_are_history'])) {
2100
+					$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2101
+		}
1987 2102
 
1988 2103
 		foreach ($_SESSION['temp_attachments'] as  $attachID => $attachment)
1989 2104
 		{
1990
-			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1991
-				continue;
2105
+			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
2106
+							continue;
2107
+			}
1992 2108
 
1993 2109
 			// If there was an initial error just show that message.
1994 2110
 			if ($attachID == 'initial_error')
@@ -2017,12 +2133,13 @@  discard block
 block discarded – undo
2017 2133
 				if (createAttachment($attachmentOptions))
2018 2134
 				{
2019 2135
 					$attachIDs[] = $attachmentOptions['id'];
2020
-					if (!empty($attachmentOptions['thumb']))
2021
-						$attachIDs[] = $attachmentOptions['thumb'];
2136
+					if (!empty($attachmentOptions['thumb'])) {
2137
+											$attachIDs[] = $attachmentOptions['thumb'];
2138
+					}
2022 2139
 				}
2140
+			} else {
2141
+							$attach_errors[] = '<dt>&nbsp;</dt>';
2023 2142
 			}
2024
-			else
2025
-				$attach_errors[] = '<dt>&nbsp;</dt>';
2026 2143
 
2027 2144
 			if (!empty($attachmentOptions['errors']))
2028 2145
 			{
@@ -2034,14 +2151,16 @@  discard block
 block discarded – undo
2034 2151
 					if (!is_array($error))
2035 2152
 					{
2036 2153
 						$attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
2037
-						if (in_array($error, $log_these))
2038
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2154
+						if (in_array($error, $log_these)) {
2155
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2156
+						}
2157
+					} else {
2158
+											$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2039 2159
 					}
2040
-					else
2041
-						$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2042 2160
 				}
2043
-				if (file_exists($attachment['tmp_name']))
2044
-					unlink($attachment['tmp_name']);
2161
+				if (file_exists($attachment['tmp_name'])) {
2162
+									unlink($attachment['tmp_name']);
2163
+				}
2045 2164
 			}
2046 2165
 		}
2047 2166
 		unset($_SESSION['temp_attachments']);
@@ -2082,24 +2201,24 @@  discard block
 block discarded – undo
2082 2201
 		);
2083 2202
 
2084 2203
 		call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
2204
+	} else {
2205
+			$id_poll = 0;
2085 2206
 	}
2086
-	else
2087
-		$id_poll = 0;
2088 2207
 
2089 2208
 	// Creating a new topic?
2090 2209
 	$newTopic = empty($_REQUEST['msg']) && empty($topic);
2091 2210
 
2092 2211
 	// Check the icon.
2093
-	if (!isset($_POST['icon']))
2094
-		$_POST['icon'] = 'xx';
2095
-
2096
-	else
2212
+	if (!isset($_POST['icon'])) {
2213
+			$_POST['icon'] = 'xx';
2214
+	} else
2097 2215
 	{
2098 2216
 		$_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']);
2099 2217
 
2100 2218
 		// Need to figure it out if this is a valid icon name.
2101
-		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')))
2102
-			$_POST['icon'] = 'xx';
2219
+		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) {
2220
+					$_POST['icon'] = 'xx';
2221
+		}
2103 2222
 	}
2104 2223
 
2105 2224
 	// Collect all parameters for the creation or modification of a post.
@@ -2140,8 +2259,9 @@  discard block
 block discarded – undo
2140 2259
 		}
2141 2260
 
2142 2261
 		// This will save some time...
2143
-		if (empty($approve_has_changed))
2144
-			unset($msgOptions['approved']);
2262
+		if (empty($approve_has_changed)) {
2263
+					unset($msgOptions['approved']);
2264
+		}
2145 2265
 
2146 2266
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2147 2267
 	}
@@ -2150,8 +2270,9 @@  discard block
 block discarded – undo
2150 2270
 	{
2151 2271
 		createPost($msgOptions, $topicOptions, $posterOptions);
2152 2272
 
2153
-		if (isset($topicOptions['id']))
2154
-			$topic = $topicOptions['id'];
2273
+		if (isset($topicOptions['id'])) {
2274
+					$topic = $topicOptions['id'];
2275
+		}
2155 2276
 	}
2156 2277
 
2157 2278
 	// Are there attachments already uploaded and waiting to be assigned?
@@ -2163,8 +2284,9 @@  discard block
 block discarded – undo
2163 2284
 	}
2164 2285
 
2165 2286
 	// If we had a draft for this, its time to remove it since it was just posted
2166
-	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft']))
2167
-		DeleteDraft($_POST['id_draft']);
2287
+	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) {
2288
+			DeleteDraft($_POST['id_draft']);
2289
+	}
2168 2290
 
2169 2291
 	// Editing or posting an event?
2170 2292
 	if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
@@ -2183,8 +2305,7 @@  discard block
 block discarded – undo
2183 2305
 			'member' => $user_info['id'],
2184 2306
 		);
2185 2307
 		insertEvent($eventOptions);
2186
-	}
2187
-	elseif (isset($_POST['calendar']))
2308
+	} elseif (isset($_POST['calendar']))
2188 2309
 	{
2189 2310
 		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
2190 2311
 
@@ -2212,14 +2333,15 @@  discard block
 block discarded – undo
2212 2333
 		}
2213 2334
 
2214 2335
 		// Delete it?
2215
-		if (isset($_REQUEST['deleteevent']))
2216
-			$smcFunc['db_query']('', '
2336
+		if (isset($_REQUEST['deleteevent'])) {
2337
+					$smcFunc['db_query']('', '
2217 2338
 				DELETE FROM {db_prefix}calendar
2218 2339
 				WHERE id_event = {int:id_event}',
2219 2340
 				array(
2220 2341
 					'id_event' => $_REQUEST['eventid'],
2221 2342
 				)
2222 2343
 			);
2344
+		}
2223 2345
 		// ... or just update it?
2224 2346
 		else
2225 2347
 		{
@@ -2261,9 +2383,8 @@  discard block
 block discarded – undo
2261 2383
 			array($user_info['id'], $topic, 0),
2262 2384
 			array('id_member', 'id_topic', 'id_board')
2263 2385
 		);
2264
-	}
2265
-	elseif (!$newTopic)
2266
-		$smcFunc['db_query']('', '
2386
+	} elseif (!$newTopic) {
2387
+			$smcFunc['db_query']('', '
2267 2388
 			DELETE FROM {db_prefix}log_notify
2268 2389
 			WHERE id_member = {int:current_member}
2269 2390
 				AND id_topic = {int:current_topic}',
@@ -2272,16 +2393,20 @@  discard block
 block discarded – undo
2272 2393
 				'current_topic' => $topic,
2273 2394
 			)
2274 2395
 		);
2396
+	}
2275 2397
 
2276 2398
 	// Log an act of moderation - modifying.
2277
-	if (!empty($moderationAction))
2278
-		logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2399
+	if (!empty($moderationAction)) {
2400
+			logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2401
+	}
2279 2402
 
2280
-	if (isset($_POST['lock']) && $_POST['lock'] != 2)
2281
-		logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2403
+	if (isset($_POST['lock']) && $_POST['lock'] != 2) {
2404
+			logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2405
+	}
2282 2406
 
2283
-	if (isset($_POST['sticky']))
2284
-		logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2407
+	if (isset($_POST['sticky'])) {
2408
+			logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2409
+	}
2285 2410
 
2286 2411
 	// Returning to the topic?
2287 2412
 	if (!empty($_REQUEST['goback']))
@@ -2300,26 +2425,31 @@  discard block
 block discarded – undo
2300 2425
 		);
2301 2426
 	}
2302 2427
 
2303
-	if ($board_info['num_topics'] == 0)
2304
-		cache_put_data('board-' . $board, null, 120);
2428
+	if ($board_info['num_topics'] == 0) {
2429
+			cache_put_data('board-' . $board, null, 120);
2430
+	}
2305 2431
 
2306 2432
 	call_integration_hook('integrate_post2_end');
2307 2433
 
2308
-	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic'))
2309
-		redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2434
+	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic')) {
2435
+			redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2436
+	}
2310 2437
 
2311
-	if (!empty($_POST['move']) && allowedTo('move_any'))
2312
-		redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2438
+	if (!empty($_POST['move']) && allowedTo('move_any')) {
2439
+			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2440
+	}
2313 2441
 
2314 2442
 	// Return to post if the mod is on.
2315
-	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
2316
-		redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2317
-	elseif (!empty($_REQUEST['goback']))
2318
-		redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2443
+	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) {
2444
+			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2445
+	} elseif (!empty($_REQUEST['goback'])) {
2446
+			redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2447
+	}
2319 2448
 	// Dut-dut-duh-duh-DUH-duh-dut-duh-duh!  *dances to the Final Fantasy Fanfare...*
2320
-	else
2321
-		redirectexit('board=' . $board . '.0');
2322
-}
2449
+	else {
2450
+			redirectexit('board=' . $board . '.0');
2451
+	}
2452
+	}
2323 2453
 
2324 2454
 /**
2325 2455
  * Handle the announce topic function (action=announce).
@@ -2337,8 +2467,9 @@  discard block
 block discarded – undo
2337 2467
 
2338 2468
 	validateSession();
2339 2469
 
2340
-	if (empty($topic))
2341
-		fatal_lang_error('topic_gone', false);
2470
+	if (empty($topic)) {
2471
+			fatal_lang_error('topic_gone', false);
2472
+	}
2342 2473
 
2343 2474
 	loadLanguage('Post');
2344 2475
 	loadTemplate('Post');
@@ -2365,8 +2496,9 @@  discard block
 block discarded – undo
2365 2496
 	global $txt, $context, $topic, $board_info, $smcFunc;
2366 2497
 
2367 2498
 	$groups = array_merge($board_info['groups'], array(1));
2368
-	foreach ($groups as $id => $group)
2369
-		$groups[$id] = (int) $group;
2499
+	foreach ($groups as $id => $group) {
2500
+			$groups[$id] = (int) $group;
2501
+	}
2370 2502
 
2371 2503
 	$context['groups'] = array();
2372 2504
 	if (in_array(0, $groups))
@@ -2409,8 +2541,9 @@  discard block
 block discarded – undo
2409 2541
 			'group_list' => $groups,
2410 2542
 		)
2411 2543
 	);
2412
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2413
-		$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2544
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2545
+			$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2546
+	}
2414 2547
 	$smcFunc['db_free_result']($request);
2415 2548
 
2416 2549
 	// Get the subject of the topic we're about to announce.
@@ -2452,16 +2585,19 @@  discard block
 block discarded – undo
2452 2585
 	$context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
2453 2586
 	$groups = array_merge($board_info['groups'], array(1));
2454 2587
 
2455
-	if (isset($_POST['membergroups']))
2456
-		$_POST['who'] = explode(',', $_POST['membergroups']);
2588
+	if (isset($_POST['membergroups'])) {
2589
+			$_POST['who'] = explode(',', $_POST['membergroups']);
2590
+	}
2457 2591
 
2458 2592
 	// Check whether at least one membergroup was selected.
2459
-	if (empty($_POST['who']))
2460
-		fatal_lang_error('no_membergroup_selected');
2593
+	if (empty($_POST['who'])) {
2594
+			fatal_lang_error('no_membergroup_selected');
2595
+	}
2461 2596
 
2462 2597
 	// Make sure all membergroups are integers and can access the board of the announcement.
2463
-	foreach ($_POST['who'] as $id => $mg)
2464
-		$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2598
+	foreach ($_POST['who'] as $id => $mg) {
2599
+			$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2600
+	}
2465 2601
 
2466 2602
 	// Get the topic subject and censor it.
2467 2603
 	$request = $smcFunc['db_query']('', '
@@ -2507,12 +2643,13 @@  discard block
 block discarded – undo
2507 2643
 	if ($smcFunc['db_num_rows']($request) == 0)
2508 2644
 	{
2509 2645
 		logAction('announce_topic', array('topic' => $topic), 'user');
2510
-		if (!empty($_REQUEST['move']) && allowedTo('move_any'))
2511
-			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2512
-		elseif (!empty($_REQUEST['goback']))
2513
-			redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2514
-		else
2515
-			redirectexit('board=' . $board . '.0');
2646
+		if (!empty($_REQUEST['move']) && allowedTo('move_any')) {
2647
+					redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2648
+		} elseif (!empty($_REQUEST['goback'])) {
2649
+					redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2650
+		} else {
2651
+					redirectexit('board=' . $board . '.0');
2652
+		}
2516 2653
 	}
2517 2654
 
2518 2655
 	$announcements = array();
@@ -2531,8 +2668,9 @@  discard block
 block discarded – undo
2531 2668
 	foreach ($rows as $row)
2532 2669
 	{
2533 2670
 		// Force them to have it?
2534
-		if (empty($prefs[$row['id_member']]['announcements']))
2535
-			continue;
2671
+		if (empty($prefs[$row['id_member']]['announcements'])) {
2672
+					continue;
2673
+		}
2536 2674
 
2537 2675
 		$cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
2538 2676
 
@@ -2560,8 +2698,9 @@  discard block
 block discarded – undo
2560 2698
 	}
2561 2699
 
2562 2700
 	// For each language send a different mail - low priority...
2563
-	foreach ($announcements as $lang => $mail)
2564
-		sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2701
+	foreach ($announcements as $lang => $mail) {
2702
+			sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2703
+	}
2565 2704
 
2566 2705
 	$context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
2567 2706
 
@@ -2571,9 +2710,10 @@  discard block
 block discarded – undo
2571 2710
 	$context['sub_template'] = 'announcement_send';
2572 2711
 
2573 2712
 	// Go back to the correct language for the user ;).
2574
-	if (!empty($modSettings['userLanguage']))
2575
-		loadLanguage('Post');
2576
-}
2713
+	if (!empty($modSettings['userLanguage'])) {
2714
+			loadLanguage('Post');
2715
+	}
2716
+	}
2577 2717
 
2578 2718
 /**
2579 2719
  * Get the topic for display purposes.
@@ -2586,12 +2726,13 @@  discard block
 block discarded – undo
2586 2726
 {
2587 2727
 	global $topic, $modSettings, $context, $smcFunc, $counter, $options;
2588 2728
 
2589
-	if (isset($_REQUEST['xml']))
2590
-		$limit = '
2729
+	if (isset($_REQUEST['xml'])) {
2730
+			$limit = '
2591 2731
 		LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
2592
-	else
2593
-		$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2732
+	} else {
2733
+			$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2594 2734
 		LIMIT ' . (int) $modSettings['topicSummaryPosts'];
2735
+	}
2595 2736
 
2596 2737
 	// If you're modifying, get only those posts before the current one. (otherwise get all.)
2597 2738
 	$request = $smcFunc['db_query']('', '
@@ -2629,8 +2770,9 @@  discard block
 block discarded – undo
2629 2770
 			'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
2630 2771
 		);
2631 2772
 
2632
-		if (!empty($context['new_replies']))
2633
-			$context['new_replies']--;
2773
+		if (!empty($context['new_replies'])) {
2774
+					$context['new_replies']--;
2775
+		}
2634 2776
 	}
2635 2777
 	$smcFunc['db_free_result']($request);
2636 2778
 }
@@ -2647,8 +2789,9 @@  discard block
 block discarded – undo
2647 2789
 	global $sourcedir, $smcFunc;
2648 2790
 
2649 2791
 	loadLanguage('Post');
2650
-	if (!isset($_REQUEST['xml']))
2651
-		loadTemplate('Post');
2792
+	if (!isset($_REQUEST['xml'])) {
2793
+			loadTemplate('Post');
2794
+	}
2652 2795
 
2653 2796
 	include_once($sourcedir . '/Subs-Post.php');
2654 2797
 
@@ -2679,8 +2822,9 @@  discard block
 block discarded – undo
2679 2822
 	$smcFunc['db_free_result']($request);
2680 2823
 
2681 2824
 	$context['sub_template'] = 'quotefast';
2682
-	if (!empty($row))
2683
-		$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2825
+	if (!empty($row)) {
2826
+			$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2827
+	}
2684 2828
 
2685 2829
 	if (!empty($can_view_post))
2686 2830
 	{
@@ -2713,8 +2857,9 @@  discard block
 block discarded – undo
2713 2857
 		}
2714 2858
 
2715 2859
 		// Remove any nested quotes.
2716
-		if (!empty($modSettings['removeNestedQuotes']))
2717
-			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2860
+		if (!empty($modSettings['removeNestedQuotes'])) {
2861
+					$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2862
+		}
2718 2863
 
2719 2864
 		$lb = "\n";
2720 2865
 
@@ -2740,14 +2885,14 @@  discard block
 block discarded – undo
2740 2885
 				'time' => '',
2741 2886
 			),
2742 2887
 		);
2743
-	}
2744
-	else
2745
-		$context['quote'] = array(
2888
+	} else {
2889
+			$context['quote'] = array(
2746 2890
 			'xml' => '',
2747 2891
 			'mozilla' => '',
2748 2892
 			'text' => '',
2749 2893
 		);
2750
-}
2894
+	}
2895
+	}
2751 2896
 
2752 2897
 /**
2753 2898
  * Used to edit the body or subject of a message inline
@@ -2759,8 +2904,9 @@  discard block
 block discarded – undo
2759 2904
 	global $user_info, $context, $smcFunc, $language, $board_info;
2760 2905
 
2761 2906
 	// We have to have a topic!
2762
-	if (empty($topic))
2763
-		obExit(false);
2907
+	if (empty($topic)) {
2908
+			obExit(false);
2909
+	}
2764 2910
 
2765 2911
 	checkSession('get');
2766 2912
 	require_once($sourcedir . '/Subs-Post.php');
@@ -2786,31 +2932,35 @@  discard block
 block discarded – undo
2786 2932
 			'guest_id' => 0,
2787 2933
 		)
2788 2934
 	);
2789
-	if ($smcFunc['db_num_rows']($request) == 0)
2790
-		fatal_lang_error('no_board', false);
2935
+	if ($smcFunc['db_num_rows']($request) == 0) {
2936
+			fatal_lang_error('no_board', false);
2937
+	}
2791 2938
 	$row = $smcFunc['db_fetch_assoc']($request);
2792 2939
 	$smcFunc['db_free_result']($request);
2793 2940
 
2794 2941
 	// Change either body or subject requires permissions to modify messages.
2795 2942
 	if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
2796 2943
 	{
2797
-		if (!empty($row['locked']))
2798
-			isAllowedTo('moderate_board');
2944
+		if (!empty($row['locked'])) {
2945
+					isAllowedTo('moderate_board');
2946
+		}
2799 2947
 
2800 2948
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
2801 2949
 		{
2802
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
2803
-				fatal_lang_error('modify_post_time_passed', false);
2804
-			elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
2805
-				isAllowedTo('modify_replies');
2806
-			else
2807
-				isAllowedTo('modify_own');
2950
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
2951
+							fatal_lang_error('modify_post_time_passed', false);
2952
+			} elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
2953
+							isAllowedTo('modify_replies');
2954
+			} else {
2955
+							isAllowedTo('modify_own');
2956
+			}
2808 2957
 		}
2809 2958
 		// Otherwise, they're locked out; someone who can modify the replies is needed.
2810
-		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
2811
-			isAllowedTo('modify_replies');
2812
-		else
2813
-			isAllowedTo('modify_any');
2959
+		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
2960
+					isAllowedTo('modify_replies');
2961
+		} else {
2962
+					isAllowedTo('modify_any');
2963
+		}
2814 2964
 
2815 2965
 		// Only log this action if it wasn't your message.
2816 2966
 		$moderationAction = $row['id_member'] != $user_info['id'];
@@ -2822,10 +2972,10 @@  discard block
 block discarded – undo
2822 2972
 		$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
2823 2973
 
2824 2974
 		// Maximum number of characters.
2825
-		if ($smcFunc['strlen']($_POST['subject']) > 100)
2826
-			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2827
-	}
2828
-	elseif (isset($_POST['subject']))
2975
+		if ($smcFunc['strlen']($_POST['subject']) > 100) {
2976
+					$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2977
+		}
2978
+	} elseif (isset($_POST['subject']))
2829 2979
 	{
2830 2980
 		$post_errors[] = 'no_subject';
2831 2981
 		unset($_POST['subject']);
@@ -2837,13 +2987,11 @@  discard block
 block discarded – undo
2837 2987
 		{
2838 2988
 			$post_errors[] = 'no_message';
2839 2989
 			unset($_POST['message']);
2840
-		}
2841
-		elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2990
+		} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2842 2991
 		{
2843 2992
 			$post_errors[] = 'long_message';
2844 2993
 			unset($_POST['message']);
2845
-		}
2846
-		else
2994
+		} else
2847 2995
 		{
2848 2996
 			$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
2849 2997
 
@@ -2859,31 +3007,34 @@  discard block
 block discarded – undo
2859 3007
 
2860 3008
 	if (isset($_POST['lock']))
2861 3009
 	{
2862
-		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
2863
-			unset($_POST['lock']);
2864
-		elseif (!allowedTo('lock_any'))
3010
+		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) {
3011
+					unset($_POST['lock']);
3012
+		} elseif (!allowedTo('lock_any'))
2865 3013
 		{
2866
-			if ($row['locked'] == 1)
2867
-				unset($_POST['lock']);
2868
-			else
2869
-				$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3014
+			if ($row['locked'] == 1) {
3015
+							unset($_POST['lock']);
3016
+			} else {
3017
+							$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3018
+			}
3019
+		} elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
3020
+					unset($_POST['lock']);
3021
+		} else {
3022
+					$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2870 3023
 		}
2871
-		elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
2872
-			unset($_POST['lock']);
2873
-		else
2874
-			$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2875 3024
 	}
2876 3025
 
2877
-	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
2878
-		unset($_POST['sticky']);
3026
+	if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
3027
+			unset($_POST['sticky']);
3028
+	}
2879 3029
 
2880 3030
 	if (isset($_POST['modify_reason']))
2881 3031
 	{
2882 3032
 		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
2883 3033
 
2884 3034
 		// Maximum number of characters.
2885
-		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
2886
-			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3035
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
3036
+					$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3037
+		}
2887 3038
 	}
2888 3039
 
2889 3040
 	if (empty($post_errors))
@@ -2920,8 +3071,9 @@  discard block
 block discarded – undo
2920 3071
 			}
2921 3072
 		}
2922 3073
 		// If nothing was changed there's no need to add an entry to the moderation log.
2923
-		else
2924
-			$moderationAction = false;
3074
+		else {
3075
+					$moderationAction = false;
3076
+		}
2925 3077
 
2926 3078
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2927 3079
 
@@ -2939,9 +3091,9 @@  discard block
 block discarded – undo
2939 3091
 			// Get the proper (default language) response prefix first.
2940 3092
 			if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
2941 3093
 			{
2942
-				if ($language === $user_info['language'])
2943
-					$context['response_prefix'] = $txt['response_prefix'];
2944
-				else
3094
+				if ($language === $user_info['language']) {
3095
+									$context['response_prefix'] = $txt['response_prefix'];
3096
+				} else
2945 3097
 				{
2946 3098
 					loadLanguage('index', $language, false);
2947 3099
 					$context['response_prefix'] = $txt['response_prefix'];
@@ -2963,8 +3115,9 @@  discard block
 block discarded – undo
2963 3115
 			);
2964 3116
 		}
2965 3117
 
2966
-		if (!empty($moderationAction))
2967
-			logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3118
+		if (!empty($moderationAction)) {
3119
+					logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3120
+		}
2968 3121
 	}
2969 3122
 
2970 3123
 	if (isset($_REQUEST['xml']))
@@ -3005,8 +3158,7 @@  discard block
 block discarded – undo
3005 3158
 			);
3006 3159
 
3007 3160
 			censorText($context['message']['subject']);
3008
-		}
3009
-		else
3161
+		} else
3010 3162
 		{
3011 3163
 			$context['message'] = array(
3012 3164
 				'id' => $row['id_msg'],
@@ -3018,15 +3170,16 @@  discard block
 block discarded – undo
3018 3170
 			loadLanguage('Errors');
3019 3171
 			foreach ($post_errors as $post_error)
3020 3172
 			{
3021
-				if ($post_error == 'long_message')
3022
-					$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3023
-				else
3024
-					$context['message']['errors'][] = $txt['error_' . $post_error];
3173
+				if ($post_error == 'long_message') {
3174
+									$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3175
+				} else {
3176
+									$context['message']['errors'][] = $txt['error_' . $post_error];
3177
+				}
3025 3178
 			}
3026 3179
 		}
3180
+	} else {
3181
+			obExit(false);
3182
+	}
3027 3183
 	}
3028
-	else
3029
-		obExit(false);
3030
-}
3031 3184
 
3032 3185
 ?>
3033 3186
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Modlog.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 					'class' => 'centercol',
257 257
 				),
258 258
 				'data' => array(
259
-					'function' => function ($entry)
259
+					'function' => function($entry)
260 260
 					{
261 261
 						return '<input type="checkbox" name="delete[]" value="' . $entry['id'] . '"' . ($entry['editable'] ? '' : ' disabled') . '>';
262 262
 					},
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 		if (empty($entries[$k]['action_text']))
639 639
 			$entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action'];
640 640
 		$entries[$k]['action_text'] = preg_replace_callback('~\{([A-Za-z\d_]+)\}~i',
641
-			function ($matches) use ($entries, $k)
641
+			function($matches) use ($entries, $k)
642 642
 			{
643 643
 				return isset($entries[$k]['extra'][$matches[1]]) ? $entries[$k]['extra'][$matches[1]] : '';
644 644
 			}, $entries[$k]['action_text']);
Please login to merge, or discard this patch.
Braces   +99 added lines, -75 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Prepares the information from the moderation log for viewing.
@@ -32,14 +33,16 @@  discard block
 block discarded – undo
32 33
 
33 34
 	// Are we looking at the moderation log or the administration log.
34 35
 	$context['log_type'] = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 3 : 1;
35
-	if ($context['log_type'] == 3)
36
-		isAllowedTo('admin_forum');
36
+	if ($context['log_type'] == 3) {
37
+			isAllowedTo('admin_forum');
38
+	}
37 39
 
38 40
 	// These change dependant on whether we are viewing the moderation or admin log.
39
-	if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin')
40
-		$context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type'];
41
-	else
42
-		$context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type'];
41
+	if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin') {
42
+			$context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type'];
43
+	} else {
44
+			$context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type'];
45
+	}
43 46
 
44 47
 	$context['can_delete'] = allowedTo('admin_forum');
45 48
 
@@ -67,8 +70,7 @@  discard block
 block discarded – undo
67 70
 		$log_type = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 'admin' : 'moderate';
68 71
 		logAction('clearlog_' . $log_type, array(), $log_type);
69 72
 
70
-	}
71
-	elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete'])
73
+	} elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete'])
72 74
 	{
73 75
 		checkSession();
74 76
 		validateToken('mod-ml');
@@ -114,15 +116,17 @@  discard block
 block discarded – undo
114 116
 		'ip' => array('sql' => 'lm.ip', 'label' => $txt['modlog_ip'])
115 117
 	);
116 118
 
117
-	if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search']))
118
-		$search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
119
-	else
120
-		$search_params_string = $search_params['string'];
119
+	if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) {
120
+			$search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
121
+	} else {
122
+			$search_params_string = $search_params['string'];
123
+	}
121 124
 
122
-	if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']]))
123
-		$search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
124
-	else
125
-		$search_params_type = $search_params['type'];
125
+	if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) {
126
+			$search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
127
+	} else {
128
+			$search_params_type = $search_params['type'];
129
+	}
126 130
 
127 131
 	$search_params_column = $searchTypes[$search_params_type]['sql'];
128 132
 	$search_params = array(
@@ -301,15 +305,16 @@  discard block
 block discarded – undo
301 305
 	$context['default_list'] = 'moderation_log_list';
302 306
 
303 307
 	// If a hook has changed this, respect it.
304
-	if (!empty($moderation_menu_name))
305
-		$context[$context['moderation_menu_name']]['tab_data'] = $moderation_menu_name;
306
-	elseif (isset($context['moderation_menu_name']))
307
-		$context[$context['moderation_menu_name']]['tab_data'] = array(
308
+	if (!empty($moderation_menu_name)) {
309
+			$context[$context['moderation_menu_name']]['tab_data'] = $moderation_menu_name;
310
+	} elseif (isset($context['moderation_menu_name'])) {
311
+			$context[$context['moderation_menu_name']]['tab_data'] = array(
308 312
 			'title' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log'],
309 313
 			'help' => $context['log_type'] == 3 ? 'adminlog' : 'modlog',
310 314
 			'description' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log_desc']
311 315
 		);
312
-}
316
+	}
317
+	}
313 318
 
314 319
 /**
315 320
  * Get the number of mod log entries.
@@ -413,30 +418,35 @@  discard block
 block discarded – undo
413 418
 		// Add on some of the column stuff info
414 419
 		if (!empty($row['id_board']))
415 420
 		{
416
-			if ($row['action'] == 'move')
417
-				$row['extra']['board_to'] = $row['id_board'];
418
-			else
419
-				$row['extra']['board'] = $row['id_board'];
421
+			if ($row['action'] == 'move') {
422
+							$row['extra']['board_to'] = $row['id_board'];
423
+			} else {
424
+							$row['extra']['board'] = $row['id_board'];
425
+			}
420 426
 		}
421 427
 
422
-		if (!empty($row['id_topic']))
423
-			$row['extra']['topic'] = $row['id_topic'];
424
-		if (!empty($row['id_msg']))
425
-			$row['extra']['message'] = $row['id_msg'];
428
+		if (!empty($row['id_topic'])) {
429
+					$row['extra']['topic'] = $row['id_topic'];
430
+		}
431
+		if (!empty($row['id_msg'])) {
432
+					$row['extra']['message'] = $row['id_msg'];
433
+		}
426 434
 
427 435
 		// Is this associated with a topic?
428
-		if (isset($row['extra']['topic']))
429
-			$topics[(int) $row['extra']['topic']][] = $row['id_action'];
430
-		if (isset($row['extra']['new_topic']))
431
-			$topics[(int) $row['extra']['new_topic']][] = $row['id_action'];
436
+		if (isset($row['extra']['topic'])) {
437
+					$topics[(int) $row['extra']['topic']][] = $row['id_action'];
438
+		}
439
+		if (isset($row['extra']['new_topic'])) {
440
+					$topics[(int) $row['extra']['new_topic']][] = $row['id_action'];
441
+		}
432 442
 
433 443
 		// How about a member?
434 444
 		if (isset($row['extra']['member']))
435 445
 		{
436 446
 			// Guests don't have names!
437
-			if (empty($row['extra']['member']))
438
-				$row['extra']['member'] = $txt['modlog_parameter_guest'];
439
-			else
447
+			if (empty($row['extra']['member'])) {
448
+							$row['extra']['member'] = $txt['modlog_parameter_guest'];
449
+			} else
440 450
 			{
441 451
 				// Try to find it...
442 452
 				$members[(int) $row['extra']['member']][] = $row['id_action'];
@@ -444,35 +454,42 @@  discard block
 block discarded – undo
444 454
 		}
445 455
 
446 456
 		// Associated with a board?
447
-		if (isset($row['extra']['board_to']))
448
-			$boards[(int) $row['extra']['board_to']][] = $row['id_action'];
449
-		if (isset($row['extra']['board_from']))
450
-			$boards[(int) $row['extra']['board_from']][] = $row['id_action'];
451
-		if (isset($row['extra']['board']))
452
-			$boards[(int) $row['extra']['board']][] = $row['id_action'];
457
+		if (isset($row['extra']['board_to'])) {
458
+					$boards[(int) $row['extra']['board_to']][] = $row['id_action'];
459
+		}
460
+		if (isset($row['extra']['board_from'])) {
461
+					$boards[(int) $row['extra']['board_from']][] = $row['id_action'];
462
+		}
463
+		if (isset($row['extra']['board'])) {
464
+					$boards[(int) $row['extra']['board']][] = $row['id_action'];
465
+		}
453 466
 
454 467
 		// A message?
455
-		if (isset($row['extra']['message']))
456
-			$messages[(int) $row['extra']['message']][] = $row['id_action'];
468
+		if (isset($row['extra']['message'])) {
469
+					$messages[(int) $row['extra']['message']][] = $row['id_action'];
470
+		}
457 471
 
458 472
 		// IP Info?
459
-		if (isset($row['extra']['ip_range']))
460
-			if ($seeIP)
473
+		if (isset($row['extra']['ip_range'])) {
474
+					if ($seeIP)
461 475
 				$row['extra']['ip_range'] = '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['extra']['ip_range'] . '">' . $row['extra']['ip_range'] . '</a>';
462
-			else
463
-				$row['extra']['ip_range'] = $txt['logged'];
476
+		} else {
477
+							$row['extra']['ip_range'] = $txt['logged'];
478
+			}
464 479
 
465 480
 		// Email?
466
-		if (isset($row['extra']['email']))
467
-			$row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>';
481
+		if (isset($row['extra']['email'])) {
482
+					$row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>';
483
+		}
468 484
 
469 485
 		// Bans are complex.
470 486
 		if ($row['action'] == 'ban' || $row['action'] == 'banremove')
471 487
 		{
472 488
 			$row['action_text'] = $txt['modlog_ac_ban' . ($row['action'] == 'banremove' ? '_remove' : '')];
473
-			foreach (array('member', 'email', 'ip_range', 'hostname') as $type)
474
-				if (isset($row['extra'][$type]))
489
+			foreach (array('member', 'email', 'ip_range', 'hostname') as $type) {
490
+							if (isset($row['extra'][$type]))
475 491
 					$row['action_text'] .= $txt['modlog_ac_ban_trigger_' . $type];
492
+			}
476 493
 		}
477 494
 
478 495
 		// The array to go to the template. Note here that action is set to a "default" value of the action doesn't match anything in the descriptions. Allows easy adding of logging events with basic details.
@@ -508,12 +525,13 @@  discard block
 block discarded – undo
508 525
 			foreach ($boards[$row['id_board']] as $action)
509 526
 			{
510 527
 				// Make the board number into a link - dealing with moving too.
511
-				if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board'])
512
-					$entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
513
-				elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board'])
514
-					$entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
515
-				elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board'])
516
-					$entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
528
+				if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board']) {
529
+									$entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
530
+				} elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board']) {
531
+									$entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
532
+				} elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board']) {
533
+									$entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
534
+				}
517 535
 			}
518 536
 		}
519 537
 		$smcFunc['db_free_result']($request);
@@ -547,10 +565,11 @@  discard block
 block discarded – undo
547 565
 				);
548 566
 
549 567
 				// Make the topic number into a link - dealing with splitting too.
550
-				if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic'])
551
-					$this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
552
-				elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic'])
553
-					$this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
568
+				if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic']) {
569
+									$this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
570
+				} elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic']) {
571
+									$this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
572
+				}
554 573
 			}
555 574
 		}
556 575
 		$smcFunc['db_free_result']($request);
@@ -583,8 +602,9 @@  discard block
 block discarded – undo
583 602
 				);
584 603
 
585 604
 				// Make the message number into a link.
586
-				if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg'])
587
-					$this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
605
+				if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg']) {
606
+									$this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
607
+				}
588 608
 			}
589 609
 		}
590 610
 		$smcFunc['db_free_result']($request);
@@ -624,25 +644,29 @@  discard block
 block discarded – undo
624 644
 	foreach ($entries as $k => $entry)
625 645
 	{
626 646
 		// Make any message info links so its easier to go find that message.
627
-		if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id'])))
628
-			$entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>';
647
+		if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id']))) {
648
+					$entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>';
649
+		}
629 650
 
630 651
 		// Mark up any deleted members, topics and boards.
631
-		foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type)
632
-			if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type]))
652
+		foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type) {
653
+					if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type]))
633 654
 				$entries[$k]['extra'][$type] = sprintf($txt['modlog_id'], $entry['extra'][$type]);
655
+		}
634 656
 
635 657
 		if (isset($entry['extra']['report']))
636 658
 		{
637 659
 			// Member profile reports go in a different area
638
-			if (stristr($entry['action'], 'user_report'))
639
-				$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
640
-			else
641
-				$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
660
+			if (stristr($entry['action'], 'user_report')) {
661
+							$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
662
+			} else {
663
+							$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
664
+			}
642 665
 		}
643 666
 
644
-		if (empty($entries[$k]['action_text']))
645
-			$entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action'];
667
+		if (empty($entries[$k]['action_text'])) {
668
+					$entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action'];
669
+		}
646 670
 		$entries[$k]['action_text'] = preg_replace_callback('~\{([A-Za-z\d_]+)\}~i',
647 671
 			function ($matches) use ($entries, $k)
648 672
 			{
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 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * 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 = $smcFunc['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 = $smcFunc['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($smcFunc['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"></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');
@@ -1027,12 +1060,14 @@  discard block
 block discarded – undo
1027 1060
 	$current_filter = (int) $_REQUEST['orig_filter'];
1028 1061
 
1029 1062
 	// If we are applying a filter do just that - then redirect.
1030
-	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter'])
1031
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1063
+	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) {
1064
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1065
+	}
1032 1066
 
1033 1067
 	// Nothing to do?
1034
-	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed']))
1035
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1068
+	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) {
1069
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1070
+	}
1036 1071
 
1037 1072
 	// Are we dealing with members who have been waiting for > set amount of time?
1038 1073
 	if (isset($_POST['time_passed']))
@@ -1045,8 +1080,9 @@  discard block
 block discarded – undo
1045 1080
 	else
1046 1081
 	{
1047 1082
 		$members = array();
1048
-		foreach ($_POST['todoAction'] as $id)
1049
-			$members[] = (int) $id;
1083
+		foreach ($_POST['todoAction'] as $id) {
1084
+					$members[] = (int) $id;
1085
+		}
1050 1086
 		$condition = '
1051 1087
 			AND id_member IN ({array_int:members})';
1052 1088
 	}
@@ -1067,8 +1103,9 @@  discard block
 block discarded – undo
1067 1103
 	$member_count = $smcFunc['db_num_rows']($request);
1068 1104
 
1069 1105
 	// If no results then just return!
1070
-	if ($member_count == 0)
1071
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1106
+	if ($member_count == 0) {
1107
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1108
+	}
1072 1109
 
1073 1110
 	$member_info = array();
1074 1111
 	$members = array();
@@ -1107,8 +1144,9 @@  discard block
 block discarded – undo
1107 1144
 		// Do we have to let the integration code know about the activations?
1108 1145
 		if (!empty($modSettings['integrate_activate']))
1109 1146
 		{
1110
-			foreach ($member_info as $member)
1111
-				call_integration_hook('integrate_activate', array($member['username']));
1147
+			foreach ($member_info as $member) {
1148
+							call_integration_hook('integrate_activate', array($member['username']));
1149
+			}
1112 1150
 		}
1113 1151
 
1114 1152
 		// Check for email.
@@ -1238,20 +1276,23 @@  discard block
 block discarded – undo
1238 1276
 		$log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member';
1239 1277
 
1240 1278
 		require_once($sourcedir . '/Logging.php');
1241
-		foreach ($member_info as $member)
1242
-			logAction($log_action, array('member' => $member['id']), 'admin');
1279
+		foreach ($member_info as $member) {
1280
+					logAction($log_action, array('member' => $member['id']), 'admin');
1281
+		}
1243 1282
 	}
1244 1283
 
1245 1284
 	// Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers).
1246
-	if (in_array($current_filter, array(3, 4, 5)))
1247
-		updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1285
+	if (in_array($current_filter, array(3, 4, 5))) {
1286
+			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1287
+	}
1248 1288
 
1249 1289
 	// Update the member's stats. (but, we know the member didn't change their name.)
1250 1290
 	updateStats('member', false);
1251 1291
 
1252 1292
 	// If they haven't been deleted, update the post group statistics on them...
1253
-	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind')))
1254
-		updateStats('postgroups', $members);
1293
+	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) {
1294
+			updateStats('postgroups', $members);
1295
+	}
1255 1296
 
1256 1297
 	redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1257 1298
 }
@@ -1276,10 +1317,11 @@  discard block
 block discarded – undo
1276 1317
 	$dis = time() - $old;
1277 1318
 
1278 1319
 	// Before midnight?
1279
-	if ($dis < $sinceMidnight)
1280
-		return 0;
1281
-	else
1282
-		$dis -= $sinceMidnight;
1320
+	if ($dis < $sinceMidnight) {
1321
+			return 0;
1322
+	} else {
1323
+			$dis -= $sinceMidnight;
1324
+	}
1283 1325
 
1284 1326
 	// Divide out the seconds in a day to get the number of days.
1285 1327
 	return ceil($dis / (24 * 60 * 60));
Please login to merge, or discard this patch.
Sources/Likes.php 1 patch
Braces   +103 added lines, -75 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Class Likes
@@ -106,8 +107,9 @@  discard block
 block discarded – undo
106 107
 		$this->_extra = isset($_GET['extra']) ? $_GET['extra'] : false;
107 108
 
108 109
 		// We do not want to output debug information here.
109
-		if ($this->_js)
110
-			$db_show_debug = false;
110
+		if ($this->_js) {
111
+					$db_show_debug = false;
112
+		}
111 113
 	}
112 114
 
113 115
 	/**
@@ -141,8 +143,9 @@  discard block
 block discarded – undo
141 143
 			$call = $this->_sa;
142 144
 
143 145
 			// Guest can only view likes.
144
-			if ($call != 'view')
145
-				is_not_guest();
146
+			if ($call != 'view') {
147
+							is_not_guest();
148
+			}
146 149
 
147 150
 			checkSession('get');
148 151
 
@@ -180,15 +183,17 @@  discard block
 block discarded – undo
180 183
 		global $smcFunc, $modSettings;
181 184
 
182 185
 		// This feature is currently disable.
183
-		if (empty($modSettings['enable_likes']))
184
-			return $this->_error = 'like_disable';
186
+		if (empty($modSettings['enable_likes'])) {
187
+					return $this->_error = 'like_disable';
188
+		}
185 189
 
186 190
 		// Zerothly, they did indicate some kind of content to like, right?
187 191
 		preg_match('~^([a-z0-9\-\_]{1,6})~i', $this->_type, $matches);
188 192
 		$this->_type = isset($matches[1]) ? $matches[1] : '';
189 193
 
190
-		if ($this->_type == '' || $this->_content <= 0)
191
-			return $this->_error = 'cannot_';
194
+		if ($this->_type == '' || $this->_content <= 0) {
195
+					return $this->_error = 'cannot_';
196
+		}
192 197
 
193 198
 		// First we need to verify if the user can see the type of content or not. This is set up to be extensible,
194 199
 		// so we'll check for the one type we do know about, and if it's not that, we'll defer to any hooks.
@@ -207,12 +212,14 @@  discard block
 block discarded – undo
207 212
 					'msg' => $this->_content,
208 213
 				)
209 214
 			);
210
-			if ($smcFunc['db_num_rows']($request) == 1)
211
-				list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request);
215
+			if ($smcFunc['db_num_rows']($request) == 1) {
216
+							list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request);
217
+			}
212 218
 
213 219
 			$smcFunc['db_free_result']($request);
214
-			if (empty($this->_idTopic))
215
-				return $this->_error = 'cannot_';
220
+			if (empty($this->_idTopic)) {
221
+							return $this->_error = 'cannot_';
222
+			}
216 223
 
217 224
 			// So we know what topic it's in and more importantly we know the user can see it.
218 225
 			// If we're not viewing, we need some info set up.
@@ -221,9 +228,7 @@  discard block
 block discarded – undo
221 228
 			$this->_validLikes['redirect'] = 'topic=' . $this->_idTopic . '.msg' . $this->_content . '#msg' . $this->_content;
222 229
 
223 230
 			$this->_validLikes['can_like'] = ($this->_user['id'] == $topicOwner ? 'cannot_like_content' : (allowedTo('likes_like') ? true : 'cannot_like_content'));
224
-		}
225
-
226
-		else
231
+		} else
227 232
 		{
228 233
 			// Modders: This will give you whatever the user offers up in terms of liking, e.g. $this->_type=msg, $this->_content=1
229 234
 			// When you hook this, check $this->_type first. If it is not something your mod worries about, return false.
@@ -241,8 +246,9 @@  discard block
 block discarded – undo
241 246
 					if ($result !== false)
242 247
 					{
243 248
 						// Match the type with what we already have.
244
-						if (!isset($result['type']) || $result['type'] != $this->_type)
245
-							return $this->_error = 'not_valid_like_type';
249
+						if (!isset($result['type']) || $result['type'] != $this->_type) {
250
+													return $this->_error = 'not_valid_like_type';
251
+						}
246 252
 
247 253
 						// Fill out the rest.
248 254
 						$this->_type = $result['type'];
@@ -253,13 +259,15 @@  discard block
 block discarded – undo
253 259
 				}
254 260
 			}
255 261
 
256
-			if (!$found)
257
-				return $this->_error = 'cannot_';
262
+			if (!$found) {
263
+							return $this->_error = 'cannot_';
264
+			}
258 265
 		}
259 266
 
260 267
 		// Does the user can like this? Viewing a list of likes doesn't require this permission.
261
-			if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like']))
262
-				return $this->_error = $this->_validLikes['can_like'];
268
+			if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like'])) {
269
+							return $this->_error = $this->_validLikes['can_like'];
270
+			}
263 271
 	}
264 272
 
265 273
 	/**
@@ -284,8 +292,9 @@  discard block
 block discarded – undo
284 292
 		);
285 293
 
286 294
 		// Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name.
287
-		if ($this->_sa == __FUNCTION__)
288
-			$this->_data = __FUNCTION__;
295
+		if ($this->_sa == __FUNCTION__) {
296
+					$this->_data = __FUNCTION__;
297
+		}
289 298
 	}
290 299
 
291 300
 	/**
@@ -315,8 +324,8 @@  discard block
 block discarded – undo
315 324
 
316 325
 		// Add a background task to process sending alerts.
317 326
 		// Mod author, you can add your own background task for your own custom like event using the "integrate_issue_like" hook or your callback, both are immediately called after this.
318
-		if ($this->_type == 'msg')
319
-			$smcFunc['db_insert']('insert',
327
+		if ($this->_type == 'msg') {
328
+					$smcFunc['db_insert']('insert',
320 329
 				'{db_prefix}background_tasks',
321 330
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
322 331
 				array('$sourcedir/tasks/Likes-Notify.php', 'Likes_Notify_Background', $smcFunc['json_encode'](array(
@@ -328,10 +337,12 @@  discard block
 block discarded – undo
328 337
 				)), 0),
329 338
 				array('id_task')
330 339
 			);
340
+		}
331 341
 
332 342
 		// Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name.
333
-		if ($this->_sa == __FUNCTION__)
334
-			$this->_data = __FUNCTION__;
343
+		if ($this->_sa == __FUNCTION__) {
344
+					$this->_data = __FUNCTION__;
345
+		}
335 346
 	}
336 347
 
337 348
 	/**
@@ -357,8 +368,9 @@  discard block
 block discarded – undo
357 368
 		$smcFunc['db_free_result']($request);
358 369
 
359 370
 		// If you want to call this directly, fill out _data property too.
360
-		if ($this->_sa == __FUNCTION__)
361
-			$this->_data = $this->_numLikes;
371
+		if ($this->_sa == __FUNCTION__) {
372
+					$this->_data = $this->_numLikes;
373
+		}
362 374
 	}
363 375
 
364 376
 	/**
@@ -371,8 +383,9 @@  discard block
 block discarded – undo
371 383
 		global $smcFunc;
372 384
 
373 385
 		// Safety first!
374
-		if (empty($this->_type) || empty($this->_content))
375
-			return $this->_error = 'cannot_';
386
+		if (empty($this->_type) || empty($this->_content)) {
387
+					return $this->_error = 'cannot_';
388
+		}
376 389
 
377 390
 		// Do we already like this?
378 391
 		$request = $smcFunc['db_query']('', '
@@ -390,26 +403,28 @@  discard block
 block discarded – undo
390 403
 		$this->_alreadyLiked = (bool) $smcFunc['db_num_rows']($request) != 0;
391 404
 		$smcFunc['db_free_result']($request);
392 405
 
393
-		if ($this->_alreadyLiked)
394
-			$this->delete();
395
-
396
-		else
397
-			$this->insert();
406
+		if ($this->_alreadyLiked) {
407
+					$this->delete();
408
+		} else {
409
+					$this->insert();
410
+		}
398 411
 
399 412
 		// Now, how many people like this content now? We *could* just +1 / -1 the relevant container but that has proven to become unstable.
400 413
 		$this->_count();
401 414
 
402 415
 		// Update the likes count for messages.
403
-		if ($this->_type == 'msg')
404
-			$this->msgIssueLike();
416
+		if ($this->_type == 'msg') {
417
+					$this->msgIssueLike();
418
+		}
405 419
 
406 420
 		// Any callbacks?
407 421
 		elseif (!empty($this->_validLikes['callback']))
408 422
 		{
409 423
 			$call = call_helper($this->_validLikes['callback'], true);
410 424
 
411
-			if (!empty($call))
412
-				call_user_func_array($call, array($this));
425
+			if (!empty($call)) {
426
+							call_user_func_array($call, array($this));
427
+			}
413 428
 		}
414 429
 
415 430
 		// Sometimes there might be other things that need updating after we do this like.
@@ -418,8 +433,9 @@  discard block
 block discarded – undo
418 433
 		// Now some clean up. This is provided here for any like handlers that want to do any cache flushing.
419 434
 		// This way a like handler doesn't need to explicitly declare anything in integrate_issue_like, but do so
420 435
 		// in integrate_valid_likes where it absolutely has to exist.
421
-		if (!empty($this->_validLikes['flush_cache']))
422
-			cache_put_data($this->_validLikes['flush_cache'], null);
436
+		if (!empty($this->_validLikes['flush_cache'])) {
437
+					cache_put_data($this->_validLikes['flush_cache'], null);
438
+		}
423 439
 
424 440
 		// All done, start building the data to pass as response.
425 441
 		$this->_data = array(
@@ -442,8 +458,9 @@  discard block
 block discarded – undo
442 458
 	{
443 459
 		global $smcFunc;
444 460
 
445
-		if ($this->_type !== 'msg')
446
-			return;
461
+		if ($this->_type !== 'msg') {
462
+					return;
463
+		}
447 464
 
448 465
 		$smcFunc['db_query']('', '
449 466
 			UPDATE {db_prefix}messages
@@ -484,8 +501,9 @@  discard block
 block discarded – undo
484 501
 				'like_type' => $this->_type,
485 502
 			)
486 503
 		);
487
-		while ($row = $smcFunc['db_fetch_assoc']($request))
488
-			$context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']);
504
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
505
+					$context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']);
506
+		}
489 507
 
490 508
 		// Now to get member data, including avatars and so on.
491 509
 		$members = array_keys($context['likers']);
@@ -493,8 +511,9 @@  discard block
 block discarded – undo
493 511
 		if (count($loaded) != count($members))
494 512
 		{
495 513
 			$members = array_diff($members, $loaded);
496
-			foreach ($members as $not_loaded)
497
-				unset ($context['likers'][$not_loaded]);
514
+			foreach ($members as $not_loaded) {
515
+							unset ($context['likers'][$not_loaded]);
516
+			}
498 517
 		}
499 518
 
500 519
 		foreach ($context['likers'] as $liker => $dummy)
@@ -536,12 +555,14 @@  discard block
 block discarded – undo
536 555
 		global $context, $txt;
537 556
 
538 557
 		// Don't do anything if someone else has already take care of the response.
539
-		if (!$this->_setResponse)
540
-			return;
558
+		if (!$this->_setResponse) {
559
+					return;
560
+		}
541 561
 
542 562
 		// Want a json response huh?
543
-		if ($this->_validLikes['json'])
544
-			return $this->jsonResponse();
563
+		if ($this->_validLikes['json']) {
564
+					return $this->jsonResponse();
565
+		}
545 566
 
546 567
 		// Set everything up for display.
547 568
 		loadTemplate('Likes');
@@ -551,8 +572,9 @@  discard block
 block discarded – undo
551 572
 		if ($this->_error)
552 573
 		{
553 574
 			// If this is a generic error, set it up good.
554
-			if ($this->_error == 'cannot_')
555
-				$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
575
+			if ($this->_error == 'cannot_') {
576
+							$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
577
+			}
556 578
 
557 579
 			// Is this request coming from an ajax call?
558 580
 			if ($this->_js)
@@ -562,8 +584,9 @@  discard block
 block discarded – undo
562 584
 			}
563 585
 
564 586
 			// Nope?  then just do a redirect to whatever URL was provided.
565
-			else
566
-				redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : '');
587
+			else {
588
+							redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : '');
589
+			}
567 590
 
568 591
 			return;
569 592
 		}
@@ -572,8 +595,9 @@  discard block
 block discarded – undo
572 595
 		else
573 596
 		{
574 597
 			// Not an ajax request so send the user back to the previous location or the main page.
575
-			if (!$this->_js)
576
-				redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : '');
598
+			if (!$this->_js) {
599
+							redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : '');
600
+			}
577 601
 
578 602
 			// These fine gentlemen all share the same template.
579 603
 			$generic = array('delete', 'insert', '_count');
@@ -606,8 +630,9 @@  discard block
 block discarded – undo
606 630
 		// If there is an error, send it.
607 631
 		if ($this->_error)
608 632
 		{
609
-			if ($this->_error == 'cannot_')
610
-				$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
633
+			if ($this->_error == 'cannot_') {
634
+							$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
635
+			}
611 636
 
612 637
 			$print['error'] = $this->_error;
613 638
 		}
@@ -643,33 +668,36 @@  discard block
 block discarded – undo
643 668
 	<body style="background-color: #444455; color: white; font-style: italic; font-family: serif;">
644 669
 		<div style="margin-top: 12%; font-size: 1.1em; line-height: 1.4; text-align: center;">';
645 670
 
646
-	if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2'))
647
-		$_GET['verse'] = '4:16';
671
+	if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2')) {
672
+			$_GET['verse'] = '4:16';
673
+	}
648 674
 
649
-	if ($_GET['verse'] == '2:18')
650
-		echo '
675
+	if ($_GET['verse'] == '2:18') {
676
+			echo '
651 677
 			Woe, it was that his name wasn\'t <em>known</em>, that he came in mystery, and was recognized by none.&nbsp;And it became to be in those days <em>something</em>.&nbsp; Something not yet <em id="unknown" name="[Unknown]">unknown</em> to mankind.&nbsp; And thus what was to be known the <em>secret project</em> began into its existence.&nbsp; Henceforth the opposition was only <em>weary</em> and <em>fearful</em>, for now their match was at arms against them.';
652
-	elseif ($_GET['verse'] == '4:16')
653
-		echo '
678
+	} elseif ($_GET['verse'] == '4:16') {
679
+			echo '
654 680
 			And it came to pass that the <em>unbelievers</em> dwindled in number and saw rise of many <em>proselytizers</em>, and the opposition found fear in the face of the <em>x</em> and the <em>j</em> while those who stood with the <em>something</em> grew stronger and came together.&nbsp; Still, this was only the <em>beginning</em>, and what lay in the future was <em id="unknown" name="[Unknown]">unknown</em> to all, even those on the right side.';
655
-	elseif ($_GET['verse'] == '22:1-2')
656
-		echo '
681
+	} elseif ($_GET['verse'] == '22:1-2') {
682
+			echo '
657 683
 			<p>Now <em>behold</em>, that which was once the secret project was <em id="unknown" name="[Unknown]">unknown</em> no longer.&nbsp; Alas, it needed more than <em>only one</em>, but yet even thought otherwise.&nbsp; It became that the opposition <em>rumored</em> and lied, but still to no avail.&nbsp; Their match, though not <em>perfect</em>, had them outdone.</p>
658 684
 			<p style="margin: 2ex 1ex 0 1ex; font-size: 1.05em; line-height: 1.5; text-align: center;">Let it continue.&nbsp; <em>The end</em>.</p>';
685
+	}
659 686
 
660 687
 	echo '
661 688
 		</div>
662 689
 		<div style="margin-top: 2ex; font-size: 2em; text-align: right;">';
663 690
 
664
-	if ($_GET['verse'] == '2:18')
665
-		echo '
691
+	if ($_GET['verse'] == '2:18') {
692
+			echo '
666 693
 			from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=4:16" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 2:18</span>';
667
-	elseif ($_GET['verse'] == '4:16')
668
-		echo '
694
+	} elseif ($_GET['verse'] == '4:16') {
695
+			echo '
669 696
 			from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=22:1-2" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 4:16</span>';
670
-	elseif ($_GET['verse'] == '22:1-2')
671
-		echo '
697
+	} elseif ($_GET['verse'] == '22:1-2') {
698
+			echo '
672 699
 			from <span style="font-family: Georgia, serif;"><strong>The Book of Unknown</strong>, 22:1-2</span>';
700
+	}
673 701
 
674 702
 	echo '
675 703
 		</div>
Please login to merge, or discard this patch.