Completed
Push — release-2.1 ( e6c696...22bfba )
by Mathias
07:04
created
Sources/ManageMaintenance.php 3 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
 
743 743
 	// For each table....
744 744
 	$_SESSION['optimized_tables'] = !empty($_SESSION['optimized_tables']) ? $_SESSION['optimized_tables'] : array();
745
-	for ($key=$_REQUEST['start']; $context['num_tables']-1; $key++)
745
+	for ($key = $_REQUEST['start']; $context['num_tables'] - 1; $key++)
746 746
 	{
747 747
 		if (empty($tables[$key]))
748 748
 			break;
@@ -1905,10 +1905,10 @@  discard block
 block discarded – undo
1905 1905
 					'value' => $txt['hooks_field_function_name'],
1906 1906
 				),
1907 1907
 				'data' => array(
1908
-					'function' => function ($data) use ($txt)
1908
+					'function' => function($data) use ($txt)
1909 1909
 					{
1910 1910
 						// Show a nice icon to indicate this is an instance.
1911
-						$instance = (!empty($data['instance']) ? '<span class="generic_icons news" title="'. $txt['hooks_field_function_method'] .'"></span> ' : '');
1911
+						$instance = (!empty($data['instance']) ? '<span class="generic_icons news" title="' . $txt['hooks_field_function_method'] . '"></span> ' : '');
1912 1912
 
1913 1913
 						if (!empty($data['included_file']))
1914 1914
 							return $instance . $txt['hooks_field_function'] . ': ' . $data['real_function'] . '<br>' . $txt['hooks_field_included_file'] . ': ' . $data['included_file'];
@@ -1940,7 +1940,7 @@  discard block
 block discarded – undo
1940 1940
 					'style' => 'width:3%;',
1941 1941
 				),
1942 1942
 				'data' => array(
1943
-					'function' => function ($data) use ($txt, $scripturl, $context)
1943
+					'function' => function($data) use ($txt, $scripturl, $context)
1944 1944
 					{
1945 1945
 						$change_status = array('before' => '', 'after' => '');
1946 1946
 
@@ -1977,7 +1977,7 @@  discard block
 block discarded – undo
1977 1977
 			'style' => 'width:3%',
1978 1978
 		),
1979 1979
 		'data' => array(
1980
-			'function' => function ($data) use ($txt, $scripturl, $context)
1980
+			'function' => function($data) use ($txt, $scripturl, $context)
1981 1981
 			{
1982 1982
 				if (!$data['hook_exists'])
1983 1983
 					return '
@@ -2113,7 +2113,7 @@  discard block
 block discarded – undo
2113 2113
 		$context['insert_after_template'] .= '
2114 2114
 		<script>
2115 2115
 			var hook_name_header = document.getElementById(\'header_list_integration_hooks_hook_name\');
2116
-			hook_name_header.innerHTML += ' . JavaScriptEscape('<select style="margin-left:15px;" onchange="window.location=(\'' . $scripturl . '?action=admin;area=maintain;sa=hooks\' + (this.value ? \';filter=\' + this.value : \'\'));"><option value="">' . $txt['hooks_reset_filter'] . '</option>' . implode('', $hooks_filters) . '</select>'). ';
2116
+			hook_name_header.innerHTML += ' . JavaScriptEscape('<select style="margin-left:15px;" onchange="window.location=(\'' . $scripturl . '?action=admin;area=maintain;sa=hooks\' + (this.value ? \';filter=\' + this.value : \'\'));"><option value="">' . $txt['hooks_reset_filter'] . '</option>' . implode('', $hooks_filters) . '</select>') . ';
2117 2117
 		</script>';
2118 2118
 
2119 2119
 	$temp_data = array();
Please login to merge, or discard this patch.
Braces   +266 added lines, -197 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Main dispatcher, the maintenance access point.
@@ -96,14 +97,16 @@  discard block
 block discarded – undo
96 97
 	call_integration_hook('integrate_manage_maintenance', array(&$subActions));
97 98
 
98 99
 	// Yep, sub-action time!
99
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
100
-		$subAction = $_REQUEST['sa'];
101
-	else
102
-		$subAction = 'routine';
100
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
101
+			$subAction = $_REQUEST['sa'];
102
+	} else {
103
+			$subAction = 'routine';
104
+	}
103 105
 
104 106
 	// Doing something special?
105
-	if (isset($_REQUEST['activity']) && isset($subActions[$subAction]['activities'][$_REQUEST['activity']]))
106
-		$activity = $_REQUEST['activity'];
107
+	if (isset($_REQUEST['activity']) && isset($subActions[$subAction]['activities'][$_REQUEST['activity']])) {
108
+			$activity = $_REQUEST['activity'];
109
+	}
107 110
 
108 111
 	// Set a few things.
109 112
 	$context['page_title'] = $txt['maintain_title'];
@@ -114,12 +117,14 @@  discard block
 block discarded – undo
114 117
 	call_helper($subActions[$subAction]['function']);
115 118
 
116 119
 	// Any special activity?
117
-	if (isset($activity))
118
-		call_helper($subActions[$subAction]['activities'][$activity]);
120
+	if (isset($activity)) {
121
+			call_helper($subActions[$subAction]['activities'][$activity]);
122
+	}
119 123
 
120 124
 	//converted to UTF-8? show a small maintenance info
121
-	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8')
122
-		$context['maintenance_finished'] = $txt['utf8_title'];
125
+	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8') {
126
+			$context['maintenance_finished'] = $txt['utf8_title'];
127
+	}
123 128
 
124 129
 	// Create a maintenance token.  Kinda hard to do it any other way.
125 130
 	createToken('admin-maint');
@@ -141,19 +146,22 @@  discard block
 block discarded – undo
141 146
 		db_extend('packages');
142 147
 
143 148
 		$colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
144
-		foreach ($colData as $column)
145
-			if ($column['name'] == 'body')
149
+		foreach ($colData as $column) {
150
+					if ($column['name'] == 'body')
146 151
 				$body_type = $column['type'];
152
+		}
147 153
 
148 154
 		$context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text';
149 155
 		$context['convert_to_suggest'] = ($body_type != 'text' && !empty($modSettings['max_messageLength']) && $modSettings['max_messageLength'] < 65536);
150 156
 	}
151 157
 
152
-	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8')
153
-		$context['maintenance_finished'] = $txt['utf8_title'];
154
-	if (isset($_GET['done']) && $_GET['done'] == 'convertentities')
155
-		$context['maintenance_finished'] = $txt['entity_convert_title'];
156
-}
158
+	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8') {
159
+			$context['maintenance_finished'] = $txt['utf8_title'];
160
+	}
161
+	if (isset($_GET['done']) && $_GET['done'] == 'convertentities') {
162
+			$context['maintenance_finished'] = $txt['entity_convert_title'];
163
+	}
164
+	}
157 165
 
158 166
 /**
159 167
  * Supporting function for the routine maintenance area.
@@ -162,9 +170,10 @@  discard block
 block discarded – undo
162 170
 {
163 171
 	global $context, $txt;
164 172
 
165
-	if (isset($_GET['done']) && $_GET['done'] == 'recount')
166
-		$context['maintenance_finished'] = $txt['maintain_recount'];
167
-}
173
+	if (isset($_GET['done']) && $_GET['done'] == 'recount') {
174
+			$context['maintenance_finished'] = $txt['maintain_recount'];
175
+	}
176
+	}
168 177
 
169 178
 /**
170 179
  * Supporting function for the members maintenance area.
@@ -195,8 +204,9 @@  discard block
 block discarded – undo
195 204
 	}
196 205
 	$smcFunc['db_free_result']($result);
197 206
 
198
-	if (isset($_GET['done']) && $_GET['done'] == 'recountposts')
199
-		$context['maintenance_finished'] = $txt['maintain_recountposts'];
207
+	if (isset($_GET['done']) && $_GET['done'] == 'recountposts') {
208
+			$context['maintenance_finished'] = $txt['maintain_recountposts'];
209
+	}
200 210
 
201 211
 	loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
202 212
 }
@@ -222,11 +232,12 @@  discard block
 block discarded – undo
222 232
 	$context['categories'] = array();
223 233
 	while ($row = $smcFunc['db_fetch_assoc']($result))
224 234
 	{
225
-		if (!isset($context['categories'][$row['id_cat']]))
226
-			$context['categories'][$row['id_cat']] = array(
235
+		if (!isset($context['categories'][$row['id_cat']])) {
236
+					$context['categories'][$row['id_cat']] = array(
227 237
 				'name' => $row['cat_name'],
228 238
 				'boards' => array()
229 239
 			);
240
+		}
230 241
 
231 242
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
232 243
 			'id' => $row['id_board'],
@@ -239,11 +250,12 @@  discard block
 block discarded – undo
239 250
 	require_once($sourcedir . '/Subs-Boards.php');
240 251
 	sortCategories($context['categories']);
241 252
 
242
-	if (isset($_GET['done']) && $_GET['done'] == 'purgeold')
243
-		$context['maintenance_finished'] = $txt['maintain_old'];
244
-	elseif (isset($_GET['done']) && $_GET['done'] == 'massmove')
245
-		$context['maintenance_finished'] = $txt['move_topics_maintenance'];
246
-}
253
+	if (isset($_GET['done']) && $_GET['done'] == 'purgeold') {
254
+			$context['maintenance_finished'] = $txt['maintain_old'];
255
+	} elseif (isset($_GET['done']) && $_GET['done'] == 'massmove') {
256
+			$context['maintenance_finished'] = $txt['move_topics_maintenance'];
257
+	}
258
+	}
247 259
 
248 260
 /**
249 261
  * Find and fix all errors on the forum.
@@ -351,15 +363,17 @@  discard block
 block discarded – undo
351 363
 	// Show me your badge!
352 364
 	isAllowedTo('admin_forum');
353 365
 
354
-	if ($db_type != 'mysql' && $db_type != 'mysqli')
355
-		return;
366
+	if ($db_type != 'mysql' && $db_type != 'mysqli') {
367
+			return;
368
+	}
356 369
 
357 370
 	db_extend('packages');
358 371
 
359 372
 	$colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
360
-	foreach ($colData as $column)
361
-		if ($column['name'] == 'body')
373
+	foreach ($colData as $column) {
374
+			if ($column['name'] == 'body')
362 375
 			$body_type = $column['type'];
376
+	}
363 377
 
364 378
 	$context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text';
365 379
 
@@ -369,19 +383,22 @@  discard block
 block discarded – undo
369 383
 		validateToken('admin-maint');
370 384
 
371 385
 		// Make it longer so we can do their limit.
372
-		if ($body_type == 'text')
373
-			$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'mediumtext'));
386
+		if ($body_type == 'text') {
387
+					$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'mediumtext'));
388
+		}
374 389
 		// Shorten the column so we can have a bit (literally per record) less space occupied
375
-		else
376
-			$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'text'));
390
+		else {
391
+					$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'text'));
392
+		}
377 393
 
378 394
 		// 3rd party integrations may be interested in knowning about this.
379 395
 		call_integration_hook('integrate_convert_msgbody', array($body_type));
380 396
 
381 397
 		$colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
382
-		foreach ($colData as $column)
383
-			if ($column['name'] == 'body')
398
+		foreach ($colData as $column) {
399
+					if ($column['name'] == 'body')
384 400
 				$body_type = $column['type'];
401
+		}
385 402
 
386 403
 		$context['maintenance_finished'] = $txt[$context['convert_to'] . '_title'];
387 404
 		$context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text';
@@ -389,14 +406,14 @@  discard block
 block discarded – undo
389 406
 
390 407
 		return;
391 408
 		redirectexit('action=admin;area=maintain;sa=database');
392
-	}
393
-	elseif ($body_type != 'text' && (!isset($_POST['do_conversion']) || isset($_POST['cont'])))
409
+	} elseif ($body_type != 'text' && (!isset($_POST['do_conversion']) || isset($_POST['cont'])))
394 410
 	{
395 411
 		checkSession();
396
-		if (empty($_REQUEST['start']))
397
-			validateToken('admin-maint');
398
-		else
399
-			validateToken('admin-convertMsg');
412
+		if (empty($_REQUEST['start'])) {
413
+					validateToken('admin-maint');
414
+		} else {
415
+					validateToken('admin-convertMsg');
416
+		}
400 417
 
401 418
 		$context['page_title'] = $txt['not_done_title'];
402 419
 		$context['continue_post_data'] = '';
@@ -428,8 +445,9 @@  discard block
 block discarded – undo
428 445
 					'increment' => $increment - 1,
429 446
 				)
430 447
 			);
431
-			while ($row = $smcFunc['db_fetch_assoc']($request))
432
-				$id_msg_exceeding[] = $row['id_msg'];
448
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
449
+							$id_msg_exceeding[] = $row['id_msg'];
450
+			}
433 451
 			$smcFunc['db_free_result']($request);
434 452
 
435 453
 			$_REQUEST['start'] += $increment;
@@ -458,9 +476,9 @@  discard block
 block discarded – undo
458 476
 			{
459 477
 				$query_msg = array_slice($id_msg_exceeding, 0, 100);
460 478
 				$context['exceeding_messages_morethan'] = sprintf($txt['exceeding_messages_morethan'], count($id_msg_exceeding));
479
+			} else {
480
+							$query_msg = $id_msg_exceeding;
461 481
 			}
462
-			else
463
-				$query_msg = $id_msg_exceeding;
464 482
 
465 483
 			$context['exceeding_messages'] = array();
466 484
 			$request = $smcFunc['db_query']('', '
@@ -471,8 +489,9 @@  discard block
 block discarded – undo
471 489
 					'messages' => $query_msg,
472 490
 				)
473 491
 			);
474
-			while ($row = $smcFunc['db_fetch_assoc']($request))
475
-				$context['exceeding_messages'][] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
492
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
493
+							$context['exceeding_messages'][] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
494
+			}
476 495
 			$smcFunc['db_free_result']($request);
477 496
 		}
478 497
 	}
@@ -496,8 +515,9 @@  discard block
 block discarded – undo
496 515
 	isAllowedTo('admin_forum');
497 516
 
498 517
 	// Check to see if UTF-8 is currently the default character set.
499
-	if ($modSettings['global_character_set'] !== 'UTF-8' || !isset($db_character_set) || $db_character_set !== 'utf8')
500
-		fatal_lang_error('entity_convert_only_utf8');
518
+	if ($modSettings['global_character_set'] !== 'UTF-8' || !isset($db_character_set) || $db_character_set !== 'utf8') {
519
+			fatal_lang_error('entity_convert_only_utf8');
520
+	}
501 521
 
502 522
 	// Some starting values.
503 523
 	$context['table'] = empty($_REQUEST['table']) ? 0 : (int) $_REQUEST['table'];
@@ -559,8 +579,9 @@  discard block
 block discarded – undo
559 579
 		// Make sure we keep stuff unique!
560 580
 		$primary_keys = array();
561 581
 
562
-		if (function_exists('apache_reset_timeout'))
563
-			@apache_reset_timeout();
582
+		if (function_exists('apache_reset_timeout')) {
583
+					@apache_reset_timeout();
584
+		}
564 585
 
565 586
 		// Get a list of text columns.
566 587
 		$columns = array();
@@ -571,9 +592,10 @@  discard block
 block discarded – undo
571 592
 				'cur_table' => $cur_table,
572 593
 			)
573 594
 		);
574
-		while ($column_info = $smcFunc['db_fetch_assoc']($request))
575
-			if (strpos($column_info['Type'], 'text') !== false || strpos($column_info['Type'], 'char') !== false)
595
+		while ($column_info = $smcFunc['db_fetch_assoc']($request)) {
596
+					if (strpos($column_info['Type'], 'text') !== false || strpos($column_info['Type'], 'char') !== false)
576 597
 				$columns[] = strtolower($column_info['Field']);
598
+		}
577 599
 
578 600
 		// Get the column with the (first) primary key.
579 601
 		$request = $smcFunc['db_query']('', '
@@ -587,8 +609,9 @@  discard block
 block discarded – undo
587 609
 		{
588 610
 			if ($row['Key_name'] === 'PRIMARY')
589 611
 			{
590
-				if (empty($primary_key) || ($row['Seq_in_index'] == 1 && !in_array(strtolower($row['Column_name']), $columns)))
591
-					$primary_key = $row['Column_name'];
612
+				if (empty($primary_key) || ($row['Seq_in_index'] == 1 && !in_array(strtolower($row['Column_name']), $columns))) {
613
+									$primary_key = $row['Column_name'];
614
+				}
592 615
 
593 616
 				$primary_keys[] = $row['Column_name'];
594 617
 			}
@@ -597,8 +620,9 @@  discard block
 block discarded – undo
597 620
 
598 621
 		// No primary key, no glory.
599 622
 		// Same for columns. Just to be sure we've work to do!
600
-		if (empty($primary_key) || empty($columns))
601
-			continue;
623
+		if (empty($primary_key) || empty($columns)) {
624
+					continue;
625
+		}
602 626
 
603 627
 		// Get the maximum value for the primary key.
604 628
 		$request = $smcFunc['db_query']('', '
@@ -612,8 +636,9 @@  discard block
 block discarded – undo
612 636
 		list($max_value) = $smcFunc['db_fetch_row']($request);
613 637
 		$smcFunc['db_free_result']($request);
614 638
 
615
-		if (empty($max_value))
616
-			continue;
639
+		if (empty($max_value)) {
640
+					continue;
641
+		}
617 642
 
618 643
 		while ($context['start'] <= $max_value)
619 644
 		{
@@ -637,10 +662,11 @@  discard block
 block discarded – undo
637 662
 			{
638 663
 				$insertion_variables = array();
639 664
 				$changes = array();
640
-				foreach ($row as $column_name => $column_value)
641
-					if ($column_name !== $primary_key && strpos($column_value, '&#') !== false)
665
+				foreach ($row as $column_name => $column_value) {
666
+									if ($column_name !== $primary_key && strpos($column_value, '&#') !== false)
642 667
 					{
643 668
 						$changes[] = $column_name . ' = {string:changes_' . $column_name . '}';
669
+				}
644 670
 						$insertion_variables['changes_' . $column_name] = preg_replace_callback('~&#(\d{1,7}|x[0-9a-fA-F]{1,6});~', 'fixchar__callback', $column_value);
645 671
 					}
646 672
 
@@ -652,8 +678,8 @@  discard block
 block discarded – undo
652 678
 				}
653 679
 
654 680
 				// Update the row.
655
-				if (!empty($changes))
656
-					$smcFunc['db_query']('', '
681
+				if (!empty($changes)) {
682
+									$smcFunc['db_query']('', '
657 683
 						UPDATE {db_prefix}' . $cur_table . '
658 684
 						SET
659 685
 							' . implode(',
@@ -661,6 +687,7 @@  discard block
 block discarded – undo
661 687
 						WHERE ' . implode(' AND ', $where),
662 688
 						$insertion_variables
663 689
 					);
690
+				}
664 691
 			}
665 692
 			$smcFunc['db_free_result']($request);
666 693
 			$context['start'] += 500;
@@ -705,10 +732,11 @@  discard block
 block discarded – undo
705 732
 
706 733
 	checkSession('request');
707 734
 
708
-	if (!isset($_SESSION['optimized_tables']))
709
-		validateToken('admin-maint');
710
-	else
711
-		validateToken('admin-optimize', 'post', false);
735
+	if (!isset($_SESSION['optimized_tables'])) {
736
+			validateToken('admin-maint');
737
+	} else {
738
+			validateToken('admin-optimize', 'post', false);
739
+	}
712 740
 
713 741
 	ignore_user_abort(true);
714 742
 	db_extend();
@@ -727,13 +755,15 @@  discard block
 block discarded – undo
727 755
 	// Get a list of tables, as well as how many there are.
728 756
 	$temp_tables = $smcFunc['db_list_tables'](false, $real_prefix . '%');
729 757
 	$tables = array();
730
-	foreach ($temp_tables as $table)
731
-		$tables[] = array('table_name' => $table);
758
+	foreach ($temp_tables as $table) {
759
+			$tables[] = array('table_name' => $table);
760
+	}
732 761
 
733 762
 	// If there aren't any tables then I believe that would mean the world has exploded...
734 763
 	$context['num_tables'] = count($tables);
735
-	if ($context['num_tables'] == 0)
736
-		fatal_error('You appear to be running SMF in a flat file mode... fantastic!', false);
764
+	if ($context['num_tables'] == 0) {
765
+			fatal_error('You appear to be running SMF in a flat file mode... fantastic!', false);
766
+	}
737 767
 
738 768
 	$_REQUEST['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
739 769
 
@@ -744,8 +774,9 @@  discard block
 block discarded – undo
744 774
 	$_SESSION['optimized_tables'] = !empty($_SESSION['optimized_tables']) ? $_SESSION['optimized_tables'] : array();
745 775
 	for ($key=$_REQUEST['start']; $context['num_tables']-1; $key++)
746 776
 	{
747
-		if (empty($tables[$key]))
748
-			break;
777
+		if (empty($tables[$key])) {
778
+					break;
779
+		}
749 780
 
750 781
 		// Continue?
751 782
 		if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)) > 10)
@@ -759,8 +790,9 @@  discard block
 block discarded – undo
759 790
 			createToken('admin-optimize');
760 791
 			$context['continue_post_data'] = '<input type="hidden" name="' . $context['admin-optimize_token_var'] . '" value="' . $context['admin-optimize_token'] . '">';
761 792
 
762
-			if (function_exists('apache_reset_timeout'))
763
-				apache_reset_timeout();
793
+			if (function_exists('apache_reset_timeout')) {
794
+							apache_reset_timeout();
795
+			}
764 796
 
765 797
 			return;
766 798
 		}
@@ -768,11 +800,12 @@  discard block
 block discarded – undo
768 800
 		// Optimize the table!  We use backticks here because it might be a custom table.
769 801
 		$data_freed = $smcFunc['db_optimize_table']($tables[$key]['table_name']);
770 802
 
771
-		if ($data_freed > 0)
772
-			$_SESSION['optimized_tables'][] = array(
803
+		if ($data_freed > 0) {
804
+					$_SESSION['optimized_tables'][] = array(
773 805
 				'name' => $tables[$key]['table_name'],
774 806
 				'data_freed' => $data_freed,
775 807
 			);
808
+		}
776 809
 	}
777 810
 
778 811
 	// Number of tables, etc...
@@ -807,10 +840,11 @@  discard block
 block discarded – undo
807 840
 	checkSession('request');
808 841
 
809 842
 	// validate the request or the loop
810
-	if (!isset($_REQUEST['step']))
811
-		validateToken('admin-maint');
812
-	else
813
-		validateToken('admin-boardrecount');
843
+	if (!isset($_REQUEST['step'])) {
844
+			validateToken('admin-maint');
845
+	} else {
846
+			validateToken('admin-boardrecount');
847
+	}
814 848
 
815 849
 	$context['page_title'] = $txt['not_done_title'];
816 850
 	$context['continue_post_data'] = '';
@@ -831,8 +865,9 @@  discard block
 block discarded – undo
831 865
 	$smcFunc['db_free_result']($request);
832 866
 
833 867
 	$increment = min(max(50, ceil($max_topics / 4)), 2000);
834
-	if (empty($_REQUEST['start']))
835
-		$_REQUEST['start'] = 0;
868
+	if (empty($_REQUEST['start'])) {
869
+			$_REQUEST['start'] = 0;
870
+	}
836 871
 
837 872
 	$total_steps = 8;
838 873
 
@@ -859,8 +894,8 @@  discard block
 block discarded – undo
859 894
 					'max_id' => $_REQUEST['start'] + $increment,
860 895
 				)
861 896
 			);
862
-			while ($row = $smcFunc['db_fetch_assoc']($request))
863
-				$smcFunc['db_query']('', '
897
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
898
+							$smcFunc['db_query']('', '
864 899
 					UPDATE {db_prefix}topics
865 900
 					SET num_replies = {int:num_replies}
866 901
 					WHERE id_topic = {int:id_topic}',
@@ -869,6 +904,7 @@  discard block
 block discarded – undo
869 904
 						'id_topic' => $row['id_topic'],
870 905
 					)
871 906
 				);
907
+			}
872 908
 			$smcFunc['db_free_result']($request);
873 909
 
874 910
 			// Recount unapproved messages
@@ -887,8 +923,8 @@  discard block
 block discarded – undo
887 923
 					'max_id' => $_REQUEST['start'] + $increment,
888 924
 				)
889 925
 			);
890
-			while ($row = $smcFunc['db_fetch_assoc']($request))
891
-				$smcFunc['db_query']('', '
926
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
927
+							$smcFunc['db_query']('', '
892 928
 					UPDATE {db_prefix}topics
893 929
 					SET unapproved_posts = {int:unapproved_posts}
894 930
 					WHERE id_topic = {int:id_topic}',
@@ -897,6 +933,7 @@  discard block
 block discarded – undo
897 933
 						'id_topic' => $row['id_topic'],
898 934
 					)
899 935
 				);
936
+			}
900 937
 			$smcFunc['db_free_result']($request);
901 938
 
902 939
 			$_REQUEST['start'] += $increment;
@@ -919,8 +956,8 @@  discard block
 block discarded – undo
919 956
 	// Update the post count of each board.
920 957
 	if ($_REQUEST['step'] <= 1)
921 958
 	{
922
-		if (empty($_REQUEST['start']))
923
-			$smcFunc['db_query']('', '
959
+		if (empty($_REQUEST['start'])) {
960
+					$smcFunc['db_query']('', '
924 961
 				UPDATE {db_prefix}boards
925 962
 				SET num_posts = {int:num_posts}
926 963
 				WHERE redirect = {string:redirect}',
@@ -929,6 +966,7 @@  discard block
 block discarded – undo
929 966
 					'redirect' => '',
930 967
 				)
931 968
 			);
969
+		}
932 970
 
933 971
 		while ($_REQUEST['start'] < $max_topics)
934 972
 		{
@@ -945,8 +983,8 @@  discard block
 block discarded – undo
945 983
 					'is_approved' => 1,
946 984
 				)
947 985
 			);
948
-			while ($row = $smcFunc['db_fetch_assoc']($request))
949
-				$smcFunc['db_query']('', '
986
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
987
+							$smcFunc['db_query']('', '
950 988
 					UPDATE {db_prefix}boards
951 989
 					SET num_posts = num_posts + {int:real_num_posts}
952 990
 					WHERE id_board = {int:id_board}',
@@ -955,6 +993,7 @@  discard block
 block discarded – undo
955 993
 						'real_num_posts' => $row['real_num_posts'],
956 994
 					)
957 995
 				);
996
+			}
958 997
 			$smcFunc['db_free_result']($request);
959 998
 
960 999
 			$_REQUEST['start'] += $increment;
@@ -977,14 +1016,15 @@  discard block
 block discarded – undo
977 1016
 	// Update the topic count of each board.
978 1017
 	if ($_REQUEST['step'] <= 2)
979 1018
 	{
980
-		if (empty($_REQUEST['start']))
981
-			$smcFunc['db_query']('', '
1019
+		if (empty($_REQUEST['start'])) {
1020
+					$smcFunc['db_query']('', '
982 1021
 				UPDATE {db_prefix}boards
983 1022
 				SET num_topics = {int:num_topics}',
984 1023
 				array(
985 1024
 					'num_topics' => 0,
986 1025
 				)
987 1026
 			);
1027
+		}
988 1028
 
989 1029
 		while ($_REQUEST['start'] < $max_topics)
990 1030
 		{
@@ -1001,8 +1041,8 @@  discard block
 block discarded – undo
1001 1041
 					'id_topic_max' => $_REQUEST['start'] + $increment,
1002 1042
 				)
1003 1043
 			);
1004
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1005
-				$smcFunc['db_query']('', '
1044
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1045
+							$smcFunc['db_query']('', '
1006 1046
 					UPDATE {db_prefix}boards
1007 1047
 					SET num_topics = num_topics + {int:real_num_topics}
1008 1048
 					WHERE id_board = {int:id_board}',
@@ -1011,6 +1051,7 @@  discard block
 block discarded – undo
1011 1051
 						'real_num_topics' => $row['real_num_topics'],
1012 1052
 					)
1013 1053
 				);
1054
+			}
1014 1055
 			$smcFunc['db_free_result']($request);
1015 1056
 
1016 1057
 			$_REQUEST['start'] += $increment;
@@ -1033,14 +1074,15 @@  discard block
 block discarded – undo
1033 1074
 	// Update the unapproved post count of each board.
1034 1075
 	if ($_REQUEST['step'] <= 3)
1035 1076
 	{
1036
-		if (empty($_REQUEST['start']))
1037
-			$smcFunc['db_query']('', '
1077
+		if (empty($_REQUEST['start'])) {
1078
+					$smcFunc['db_query']('', '
1038 1079
 				UPDATE {db_prefix}boards
1039 1080
 				SET unapproved_posts = {int:unapproved_posts}',
1040 1081
 				array(
1041 1082
 					'unapproved_posts' => 0,
1042 1083
 				)
1043 1084
 			);
1085
+		}
1044 1086
 
1045 1087
 		while ($_REQUEST['start'] < $max_topics)
1046 1088
 		{
@@ -1057,8 +1099,8 @@  discard block
 block discarded – undo
1057 1099
 					'is_approved' => 0,
1058 1100
 				)
1059 1101
 			);
1060
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1061
-				$smcFunc['db_query']('', '
1102
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1103
+							$smcFunc['db_query']('', '
1062 1104
 					UPDATE {db_prefix}boards
1063 1105
 					SET unapproved_posts = unapproved_posts + {int:unapproved_posts}
1064 1106
 					WHERE id_board = {int:id_board}',
@@ -1067,6 +1109,7 @@  discard block
 block discarded – undo
1067 1109
 						'unapproved_posts' => $row['real_unapproved_posts'],
1068 1110
 					)
1069 1111
 				);
1112
+			}
1070 1113
 			$smcFunc['db_free_result']($request);
1071 1114
 
1072 1115
 			$_REQUEST['start'] += $increment;
@@ -1089,14 +1132,15 @@  discard block
 block discarded – undo
1089 1132
 	// Update the unapproved topic count of each board.
1090 1133
 	if ($_REQUEST['step'] <= 4)
1091 1134
 	{
1092
-		if (empty($_REQUEST['start']))
1093
-			$smcFunc['db_query']('', '
1135
+		if (empty($_REQUEST['start'])) {
1136
+					$smcFunc['db_query']('', '
1094 1137
 				UPDATE {db_prefix}boards
1095 1138
 				SET unapproved_topics = {int:unapproved_topics}',
1096 1139
 				array(
1097 1140
 					'unapproved_topics' => 0,
1098 1141
 				)
1099 1142
 			);
1143
+		}
1100 1144
 
1101 1145
 		while ($_REQUEST['start'] < $max_topics)
1102 1146
 		{
@@ -1113,8 +1157,8 @@  discard block
 block discarded – undo
1113 1157
 					'id_topic_max' => $_REQUEST['start'] + $increment,
1114 1158
 				)
1115 1159
 			);
1116
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1117
-				$smcFunc['db_query']('', '
1160
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1161
+							$smcFunc['db_query']('', '
1118 1162
 					UPDATE {db_prefix}boards
1119 1163
 					SET unapproved_topics = unapproved_topics + {int:real_unapproved_topics}
1120 1164
 					WHERE id_board = {int:id_board}',
@@ -1123,6 +1167,7 @@  discard block
 block discarded – undo
1123 1167
 						'real_unapproved_topics' => $row['real_unapproved_topics'],
1124 1168
 					)
1125 1169
 				);
1170
+			}
1126 1171
 			$smcFunc['db_free_result']($request);
1127 1172
 
1128 1173
 			$_REQUEST['start'] += $increment;
@@ -1156,8 +1201,9 @@  discard block
 block discarded – undo
1156 1201
 				'is_not_deleted' => 0,
1157 1202
 			)
1158 1203
 		);
1159
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1160
-			updateMemberData($row['id_member'], array('instant_messages' => $row['real_num']));
1204
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1205
+					updateMemberData($row['id_member'], array('instant_messages' => $row['real_num']));
1206
+		}
1161 1207
 		$smcFunc['db_free_result']($request);
1162 1208
 
1163 1209
 		$request = $smcFunc['db_query']('', '
@@ -1172,8 +1218,9 @@  discard block
 block discarded – undo
1172 1218
 				'is_not_read' => 0,
1173 1219
 			)
1174 1220
 		);
1175
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1176
-			updateMemberData($row['id_member'], array('unread_messages' => $row['real_num']));
1221
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1222
+					updateMemberData($row['id_member'], array('unread_messages' => $row['real_num']));
1223
+		}
1177 1224
 		$smcFunc['db_free_result']($request);
1178 1225
 
1179 1226
 		if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)) > 3)
@@ -1205,12 +1252,13 @@  discard block
 block discarded – undo
1205 1252
 				)
1206 1253
 			);
1207 1254
 			$boards = array();
1208
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1209
-				$boards[$row['id_board']][] = $row['id_msg'];
1255
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1256
+							$boards[$row['id_board']][] = $row['id_msg'];
1257
+			}
1210 1258
 			$smcFunc['db_free_result']($request);
1211 1259
 
1212
-			foreach ($boards as $board_id => $messages)
1213
-				$smcFunc['db_query']('', '
1260
+			foreach ($boards as $board_id => $messages) {
1261
+							$smcFunc['db_query']('', '
1214 1262
 					UPDATE {db_prefix}messages
1215 1263
 					SET id_board = {int:id_board}
1216 1264
 					WHERE id_msg IN ({array_int:id_msg_array})',
@@ -1219,6 +1267,7 @@  discard block
 block discarded – undo
1219 1267
 						'id_board' => $board_id,
1220 1268
 					)
1221 1269
 				);
1270
+			}
1222 1271
 
1223 1272
 			$_REQUEST['start'] += $increment;
1224 1273
 
@@ -1248,8 +1297,9 @@  discard block
 block discarded – undo
1248 1297
 		)
1249 1298
 	);
1250 1299
 	$realBoardCounts = array();
1251
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1252
-		$realBoardCounts[$row['id_board']] = $row['local_last_msg'];
1300
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1301
+			$realBoardCounts[$row['id_board']] = $row['local_last_msg'];
1302
+	}
1253 1303
 	$smcFunc['db_free_result']($request);
1254 1304
 
1255 1305
 	$request = $smcFunc['db_query']('', '
@@ -1269,18 +1319,20 @@  discard block
 block discarded – undo
1269 1319
 	krsort($resort_me);
1270 1320
 
1271 1321
 	$lastModifiedMsg = array();
1272
-	foreach ($resort_me as $rows)
1273
-		foreach ($rows as $row)
1322
+	foreach ($resort_me as $rows) {
1323
+			foreach ($rows as $row)
1274 1324
 		{
1275 1325
 			// The latest message is the latest of the current board and its children.
1276 1326
 			if (isset($lastModifiedMsg[$row['id_board']]))
1277 1327
 				$curLastModifiedMsg = max($row['local_last_msg'], $lastModifiedMsg[$row['id_board']]);
1278
-			else
1279
-				$curLastModifiedMsg = $row['local_last_msg'];
1328
+	}
1329
+			else {
1330
+							$curLastModifiedMsg = $row['local_last_msg'];
1331
+			}
1280 1332
 
1281 1333
 			// If what is and what should be the latest message differ, an update is necessary.
1282
-			if ($row['local_last_msg'] != $row['id_last_msg'] || $curLastModifiedMsg != $row['id_msg_updated'])
1283
-				$smcFunc['db_query']('', '
1334
+			if ($row['local_last_msg'] != $row['id_last_msg'] || $curLastModifiedMsg != $row['id_msg_updated']) {
1335
+							$smcFunc['db_query']('', '
1284 1336
 					UPDATE {db_prefix}boards
1285 1337
 					SET id_last_msg = {int:id_last_msg}, id_msg_updated = {int:id_msg_updated}
1286 1338
 					WHERE id_board = {int:id_board}',
@@ -1290,12 +1342,14 @@  discard block
 block discarded – undo
1290 1342
 						'id_board' => $row['id_board'],
1291 1343
 					)
1292 1344
 				);
1345
+			}
1293 1346
 
1294 1347
 			// Parent boards inherit the latest modified message of their children.
1295
-			if (isset($lastModifiedMsg[$row['id_parent']]))
1296
-				$lastModifiedMsg[$row['id_parent']] = max($row['local_last_msg'], $lastModifiedMsg[$row['id_parent']]);
1297
-			else
1298
-				$lastModifiedMsg[$row['id_parent']] = $row['local_last_msg'];
1348
+			if (isset($lastModifiedMsg[$row['id_parent']])) {
1349
+							$lastModifiedMsg[$row['id_parent']] = max($row['local_last_msg'], $lastModifiedMsg[$row['id_parent']]);
1350
+			} else {
1351
+							$lastModifiedMsg[$row['id_parent']] = $row['local_last_msg'];
1352
+			}
1299 1353
 		}
1300 1354
 
1301 1355
 	// Update all the basic statistics.
@@ -1367,8 +1421,9 @@  discard block
 block discarded – undo
1367 1421
 	require_once($sourcedir . '/Subs-Auth.php');
1368 1422
 	$members = findMembers($_POST['to']);
1369 1423
 
1370
-	if (empty($members))
1371
-		fatal_lang_error('reattribute_cannot_find_member');
1424
+	if (empty($members)) {
1425
+			fatal_lang_error('reattribute_cannot_find_member');
1426
+	}
1372 1427
 
1373 1428
 	$memID = array_shift($members);
1374 1429
 	$memID = $memID['id'];
@@ -1398,8 +1453,9 @@  discard block
 block discarded – undo
1398 1453
 		validateToken('admin-maint');
1399 1454
 
1400 1455
 		$groups = array();
1401
-		foreach ($_POST['groups'] as $id => $dummy)
1402
-			$groups[] = (int) $id;
1456
+		foreach ($_POST['groups'] as $id => $dummy) {
1457
+					$groups[] = (int) $id;
1458
+		}
1403 1459
 		$time_limit = (time() - ($_POST['maxdays'] * 24 * 3600));
1404 1460
 		$where_vars = array(
1405 1461
 			'time_limit' => $time_limit,
@@ -1408,9 +1464,9 @@  discard block
 block discarded – undo
1408 1464
 		{
1409 1465
 			$where = 'mem.date_registered < {int:time_limit} AND mem.is_activated = {int:is_activated}';
1410 1466
 			$where_vars['is_activated'] = 0;
1467
+		} else {
1468
+					$where = 'mem.last_login < {int:time_limit} AND (mem.last_login != 0 OR mem.date_registered < {int:time_limit})';
1411 1469
 		}
1412
-		else
1413
-			$where = 'mem.last_login < {int:time_limit} AND (mem.last_login != 0 OR mem.date_registered < {int:time_limit})';
1414 1470
 
1415 1471
 		// Need to get *all* groups then work out which (if any) we avoid.
1416 1472
 		$request = $smcFunc['db_query']('', '
@@ -1429,8 +1485,7 @@  discard block
 block discarded – undo
1429 1485
 				{
1430 1486
 					$where .= ' AND mem.id_post_group != {int:id_post_group_' . $row['id_group'] . '}';
1431 1487
 					$where_vars['id_post_group_' . $row['id_group']] = $row['id_group'];
1432
-				}
1433
-				else
1488
+				} else
1434 1489
 				{
1435 1490
 					$where .= ' AND mem.id_group != {int:id_group_' . $row['id_group'] . '} AND FIND_IN_SET({int:id_group_' . $row['id_group'] . '}, mem.additional_groups) = 0';
1436 1491
 					$where_vars['id_group_' . $row['id_group']] = $row['id_group'];
@@ -1457,8 +1512,9 @@  discard block
 block discarded – undo
1457 1512
 		$members = array();
1458 1513
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1459 1514
 		{
1460
-			if (!$row['is_mod'] || !in_array(3, $groups))
1461
-				$members[] = $row['id_member'];
1515
+			if (!$row['is_mod'] || !in_array(3, $groups)) {
1516
+							$members[] = $row['id_member'];
1517
+			}
1462 1518
 		}
1463 1519
 		$smcFunc['db_free_result']($request);
1464 1520
 
@@ -1505,8 +1561,9 @@  discard block
 block discarded – undo
1505 1561
 		)
1506 1562
 	);
1507 1563
 
1508
-	while ($row = $smcFunc['db_fetch_row']($request))
1509
-		$drafts[] = (int) $row[0];
1564
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1565
+			$drafts[] = (int) $row[0];
1566
+	}
1510 1567
 	$smcFunc['db_free_result']($request);
1511 1568
 
1512 1569
 	// If we have old drafts, remove them
@@ -1549,8 +1606,9 @@  discard block
 block discarded – undo
1549 1606
 	$sticky = isset($_POST['move_type_sticky']) || isset($_GET['sticky']);
1550 1607
 
1551 1608
 	// No boards then this is your stop.
1552
-	if (empty($id_board_from) || empty($id_board_to))
1553
-		return;
1609
+	if (empty($id_board_from) || empty($id_board_to)) {
1610
+			return;
1611
+	}
1554 1612
 
1555 1613
 	// The big WHERE clause
1556 1614
 	$conditions = 'WHERE t.id_board = {int:id_board_from}
@@ -1598,18 +1656,20 @@  discard block
 block discarded – undo
1598 1656
 		);
1599 1657
 		list ($total_topics) = $smcFunc['db_fetch_row']($request);
1600 1658
 		$smcFunc['db_free_result']($request);
1659
+	} else {
1660
+			$total_topics = (int) $_REQUEST['totaltopics'];
1601 1661
 	}
1602
-	else
1603
-		$total_topics = (int) $_REQUEST['totaltopics'];
1604 1662
 
1605 1663
 	// Seems like we need this here.
1606 1664
 	$context['continue_get_data'] = '?action=admin;area=maintain;sa=topics;activity=massmove;id_board_from=' . $id_board_from . ';id_board_to=' . $id_board_to . ';totaltopics=' . $total_topics . ';max_days=' . $max_days;
1607 1665
 
1608
-	if ($locked)
1609
-		$context['continue_get_data'] .= ';locked';
1666
+	if ($locked) {
1667
+			$context['continue_get_data'] .= ';locked';
1668
+	}
1610 1669
 
1611
-	if ($sticky)
1612
-		$context['continue_get_data'] .= ';sticky';
1670
+	if ($sticky) {
1671
+			$context['continue_get_data'] .= ';sticky';
1672
+	}
1613 1673
 
1614 1674
 	$context['continue_get_data'] .= ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1615 1675
 
@@ -1630,8 +1690,9 @@  discard block
 block discarded – undo
1630 1690
 
1631 1691
 			// Get the ids.
1632 1692
 			$topics = array();
1633
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1634
-				$topics[] = $row['id_topic'];
1693
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1694
+							$topics[] = $row['id_topic'];
1695
+			}
1635 1696
 
1636 1697
 			// Just return if we don't have any topics left to move.
1637 1698
 			if (empty($topics))
@@ -1722,9 +1783,9 @@  discard block
 block discarded – undo
1722 1783
 		// save it so we don't do this again for this task
1723 1784
 		list ($_SESSION['total_members']) = $smcFunc['db_fetch_row']($request);
1724 1785
 		$smcFunc['db_free_result']($request);
1786
+	} else {
1787
+			validateToken('admin-recountposts');
1725 1788
 	}
1726
-	else
1727
-		validateToken('admin-recountposts');
1728 1789
 
1729 1790
 	// Lets get a group of members and determine their post count (from the boards that have post count enabled of course).
1730 1791
 	$request = $smcFunc['db_query']('', '
@@ -1770,8 +1831,9 @@  discard block
 block discarded – undo
1770 1831
 		createToken('admin-recountposts');
1771 1832
 		$context['continue_post_data'] = '<input type="hidden" name="' . $context['admin-recountposts_token_var'] . '" value="' . $context['admin-recountposts_token'] . '">';
1772 1833
 
1773
-		if (function_exists('apache_reset_timeout'))
1774
-			apache_reset_timeout();
1834
+		if (function_exists('apache_reset_timeout')) {
1835
+					apache_reset_timeout();
1836
+		}
1775 1837
 		return;
1776 1838
 	}
1777 1839
 
@@ -1857,10 +1919,9 @@  discard block
 block discarded – undo
1857 1919
 		checkSession('request');
1858 1920
 		validateToken('admin-hook', 'request');
1859 1921
 
1860
-		if ($_REQUEST['do'] == 'remove')
1861
-			remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function']));
1862
-
1863
-		else
1922
+		if ($_REQUEST['do'] == 'remove') {
1923
+					remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function']));
1924
+		} else
1864 1925
 		{
1865 1926
 			$function_remove = urldecode($_REQUEST['function']) . (($_REQUEST['do'] == 'disable') ? '' : '!');
1866 1927
 			$function_add = urldecode($_REQUEST['function']) . (($_REQUEST['do'] == 'disable') ? '!' : '');
@@ -1910,11 +1971,11 @@  discard block
 block discarded – undo
1910 1971
 						// Show a nice icon to indicate this is an instance.
1911 1972
 						$instance = (!empty($data['instance']) ? '<span class="generic_icons news" title="'. $txt['hooks_field_function_method'] .'"></span> ' : '');
1912 1973
 
1913
-						if (!empty($data['included_file']))
1914
-							return $instance . $txt['hooks_field_function'] . ': ' . $data['real_function'] . '<br>' . $txt['hooks_field_included_file'] . ': ' . $data['included_file'];
1915
-
1916
-						else
1917
-							return $instance . $data['real_function'];
1974
+						if (!empty($data['included_file'])) {
1975
+													return $instance . $txt['hooks_field_function'] . ': ' . $data['real_function'] . '<br>' . $txt['hooks_field_included_file'] . ': ' . $data['included_file'];
1976
+						} else {
1977
+													return $instance . $data['real_function'];
1978
+						}
1918 1979
 					},
1919 1980
 				),
1920 1981
 				'sort' =>  array(
@@ -1979,11 +2040,12 @@  discard block
 block discarded – undo
1979 2040
 		'data' => array(
1980 2041
 			'function' => function ($data) use ($txt, $scripturl, $context)
1981 2042
 			{
1982
-				if (!$data['hook_exists'])
1983
-					return '
2043
+				if (!$data['hook_exists']) {
2044
+									return '
1984 2045
 					<a href="' . $scripturl . '?action=admin;area=maintain;sa=hooks;do=remove;hook=' . $data['hook_name'] . ';function=' . urlencode($data['function_name']) . $context['filter_url'] . ';' . $context['admin-hook_token_var'] . '=' . $context['admin-hook_token'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" data-confirm="' . $txt['quickmod_confirm'] . '" class="you_sure">
1985 2046
 						<span class="generic_icons delete" title="' . $txt['hooks_button_remove'] . '"></span>
1986 2047
 					</a>';
2048
+				}
1987 2049
 			},
1988 2050
 			'class' => 'centertext',
1989 2051
 		),
@@ -2018,10 +2080,11 @@  discard block
 block discarded – undo
2018 2080
 		{
2019 2081
 			if ($file != '.' && $file != '..')
2020 2082
 			{
2021
-				if (is_dir($dir_path . '/' . $file))
2022
-					$files = array_merge($files, get_files_recursive($dir_path . '/' . $file));
2023
-				else
2024
-					$files[] = array('dir' => $dir_path, 'name' => $file);
2083
+				if (is_dir($dir_path . '/' . $file)) {
2084
+									$files = array_merge($files, get_files_recursive($dir_path . '/' . $file));
2085
+				} else {
2086
+									$files[] = array('dir' => $dir_path, 'name' => $file);
2087
+				}
2025 2088
 			}
2026 2089
 		}
2027 2090
 	}
@@ -2070,16 +2133,16 @@  discard block
 block discarded – undo
2070 2133
 							// I need to know if there is at least one function called in this file.
2071 2134
 							$temp_data['include'][$hookParsedData['pureFunc']] = array('hook' => $hook, 'function' => $hookParsedData['pureFunc']);
2072 2135
 							unset($temp_hooks[$hook][$rawFunc]);
2073
-						}
2074
-						elseif (strpos(str_replace(' (', '(', $fc), 'function ' . trim($hookParsedData['pureFunc']) . '(') !== false)
2136
+						} elseif (strpos(str_replace(' (', '(', $fc), 'function ' . trim($hookParsedData['pureFunc']) . '(') !== false)
2075 2137
 						{
2076 2138
 							$hook_status[$hook][$hookParsedData['pureFunc']] = $hookParsedData;
2077 2139
 							$hook_status[$hook][$hookParsedData['pureFunc']]['exists'] = true;
2078 2140
 							$hook_status[$hook][$hookParsedData['pureFunc']]['in_file'] = (!empty($file['name']) ? $file['name'] : (!empty($hookParsedData['hookFile']) ? $hookParsedData['hookFile'] : ''));
2079 2141
 
2080 2142
 							// Does the hook has its own file?
2081
-							if (!empty($hookParsedData['hookFile']))
2082
-								$temp_data['include'][$hookParsedData['pureFunc']] = array('hook' => $hook, 'function' => $hookParsedData['pureFunc']);
2143
+							if (!empty($hookParsedData['hookFile'])) {
2144
+															$temp_data['include'][$hookParsedData['pureFunc']] = array('hook' => $hook, 'function' => $hookParsedData['pureFunc']);
2145
+							}
2083 2146
 
2084 2147
 							// I want to remember all the functions called within this file (to check later if they are enabled or disabled and decide if the integrare_*_include of that file can be disabled too)
2085 2148
 							$temp_data['function'][$file['name']][$hookParsedData['pureFunc']] = $hookParsedData['enabled'];
@@ -2106,15 +2169,17 @@  discard block
 block discarded – undo
2106 2169
 	$sort = array();
2107 2170
 	$hooks_filters = array();
2108 2171
 
2109
-	foreach ($hooks as $hook => $functions)
2110
-		$hooks_filters[] = '<option' . ($context['current_filter'] == $hook ? ' selected ' : '') . ' value="' . $hook . '">' . $hook . '</option>';
2172
+	foreach ($hooks as $hook => $functions) {
2173
+			$hooks_filters[] = '<option' . ($context['current_filter'] == $hook ? ' selected ' : '') . ' value="' . $hook . '">' . $hook . '</option>';
2174
+	}
2111 2175
 
2112
-	if (!empty($hooks_filters))
2113
-		$context['insert_after_template'] .= '
2176
+	if (!empty($hooks_filters)) {
2177
+			$context['insert_after_template'] .= '
2114 2178
 		<script>
2115 2179
 			var hook_name_header = document.getElementById(\'header_list_integration_hooks_hook_name\');
2116 2180
 			hook_name_header.innerHTML += ' . JavaScriptEscape('<select style="margin-left:15px;" onchange="window.location=(\'' . $scripturl . '?action=admin;area=maintain;sa=hooks\' + (this.value ? \';filter=\' + this.value : \'\'));"><option value="">' . $txt['hooks_reset_filter'] . '</option>' . implode('', $hooks_filters) . '</select>'). ';
2117 2181
 		</script>';
2182
+	}
2118 2183
 
2119 2184
 	$temp_data = array();
2120 2185
 	$id = 0;
@@ -2157,10 +2222,11 @@  discard block
 block discarded – undo
2157 2222
 
2158 2223
 	foreach ($temp_data as $data)
2159 2224
 	{
2160
-		if (++$counter < $start)
2161
-			continue;
2162
-		elseif ($counter == $start + $per_page)
2163
-			break;
2225
+		if (++$counter < $start) {
2226
+					continue;
2227
+		} elseif ($counter == $start + $per_page) {
2228
+					break;
2229
+		}
2164 2230
 
2165 2231
 		$hooks_data[] = $data;
2166 2232
 	}
@@ -2182,13 +2248,15 @@  discard block
 block discarded – undo
2182 2248
 	$hooks_count = 0;
2183 2249
 
2184 2250
 	$context['filter'] = false;
2185
-	if (isset($_GET['filter']))
2186
-		$context['filter'] = $_GET['filter'];
2251
+	if (isset($_GET['filter'])) {
2252
+			$context['filter'] = $_GET['filter'];
2253
+	}
2187 2254
 
2188 2255
 	foreach ($hooks as $hook => $functions)
2189 2256
 	{
2190
-		if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook))
2191
-			$hooks_count += count($functions);
2257
+		if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook)) {
2258
+					$hooks_count += count($functions);
2259
+		}
2192 2260
 	}
2193 2261
 
2194 2262
 	return $hooks_count;
@@ -2209,8 +2277,9 @@  discard block
 block discarded – undo
2209 2277
 		$integration_hooks = array();
2210 2278
 		foreach ($modSettings as $key => $value)
2211 2279
 		{
2212
-			if (!empty($value) && substr($key, 0, 10) === 'integrate_')
2213
-				$integration_hooks[$key] = explode(',', $value);
2280
+			if (!empty($value) && substr($key, 0, 10) === 'integrate_') {
2281
+							$integration_hooks[$key] = explode(',', $value);
2282
+			}
2214 2283
 		}
2215 2284
 	}
2216 2285
 
@@ -2241,8 +2310,9 @@  discard block
 block discarded – undo
2241 2310
 	);
2242 2311
 
2243 2312
 	// Meh...
2244
-	if (empty($rawData))
2245
-		return $hookData;
2313
+	if (empty($rawData)) {
2314
+			return $hookData;
2315
+	}
2246 2316
 
2247 2317
 	// For convenience purposes only!
2248 2318
 	$modFunc = $rawData;
@@ -2253,11 +2323,11 @@  discard block
 block discarded – undo
2253 2323
 		list ($hookData['hookFile'], $modFunc) = explode('|', $modFunc);
2254 2324
 
2255 2325
 		// Does the file exists? who knows!
2256
-		if (empty($settings['theme_dir']))
2257
-			$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
2258
-
2259
-		else
2260
-			$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2326
+		if (empty($settings['theme_dir'])) {
2327
+					$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
2328
+		} else {
2329
+					$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2330
+		}
2261 2331
 
2262 2332
 		$hookData['fileExists'] = file_exists($hookData['absPath']);
2263 2333
 		$hookData['hookFile'] = basename($hookData['hookFile']);
@@ -2282,11 +2352,10 @@  discard block
 block discarded – undo
2282 2352
 	{
2283 2353
 		list ($hookData['class'], $hookData['method']) = explode('::', $modFunc);
2284 2354
 		$hookData['pureFunc'] = $hookData['method'];
2355
+	} else {
2356
+			$hookData['pureFunc'] = $modFunc;
2285 2357
 	}
2286 2358
 
2287
-	else
2288
-		$hookData['pureFunc'] = $modFunc;
2289
-
2290 2359
 	return $hookData;
2291 2360
 }
2292 2361
 
Please login to merge, or discard this patch.
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -2439,7 +2439,6 @@
 block discarded – undo
2439 2439
 
2440 2440
 /**
2441 2441
  * Add a Javascript file for output later
2442
-
2443 2442
  * @param string $filename The name of the file to load
2444 2443
  * @param array $params An array of parameter info
2445 2444
  * Keys are the following:
Please login to merge, or discard this patch.
Sources/Notify.php 1 patch
Braces   +23 added lines, -20 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
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
  * Turn off/on notification for a particular board.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	is_not_guest();
35 36
 
36 37
 	// You have to specify a board to turn notifications on!
37
-	if (empty($board))
38
-		fatal_lang_error('no_board', false);
38
+	if (empty($board)) {
39
+			fatal_lang_error('no_board', false);
40
+	}
39 41
 
40 42
 	// No subaction: find out what to do.
41 43
 	if (isset($_GET['mode']))
@@ -48,16 +50,16 @@  discard block
 block discarded – undo
48 50
 		require_once($sourcedir . '/Subs-Notify.php');
49 51
 		setNotifyPrefs($user_info['id'], array('board_notify_' . $board => $alertPref));
50 52
 
51
-		if ($mode > 1)
52
-			// Turn notification on.  (note this just blows smoke if it's already on.)
53
+		if ($mode > 1) {
54
+					// Turn notification on.  (note this just blows smoke if it's already on.)
53 55
 			$smcFunc['db_insert']('ignore',
54 56
 				'{db_prefix}log_notify',
55 57
 				array('id_member' => 'int', 'id_board' => 'int'),
56 58
 				array($user_info['id'], $board),
57 59
 				array('id_member', 'id_board')
58 60
 			);
59
-		else
60
-			$smcFunc['db_query']('', '
61
+		} else {
62
+					$smcFunc['db_query']('', '
61 63
 				DELETE FROM {db_prefix}log_notify
62 64
 				WHERE id_member = {int:current_member}
63 65
 				AND id_board = {int:current_board}',
@@ -66,6 +68,7 @@  discard block
 block discarded – undo
66 68
 					'current_member' => $user_info['id'],
67 69
 				)
68 70
 			);
71
+		}
69 72
 
70 73
 	}
71 74
 
@@ -81,10 +84,10 @@  discard block
 block discarded – undo
81 84
 			),
82 85
 		);
83 86
 		$context['sub_template'] = 'generic_xml';
87
+	} else {
88
+			redirectexit('board=' . $board . '.' . $_REQUEST['start']);
89
+	}
84 90
 	}
85
-	else
86
-		redirectexit('board=' . $board . '.' . $_REQUEST['start']);
87
-}
88 91
 
89 92
 /**
90 93
  * Turn off/on unread replies subscription for a topic as well as sets individual topic's alert preferences
@@ -108,8 +111,9 @@  discard block
 block discarded – undo
108 111
 			$mode = (int) $_GET['mode'];
109 112
 			$alertPref = $mode <= 1 ? 0 : ($mode == 2 ? 1 : 3);
110 113
 
111
-			if (empty($mode))
112
-				$mode = 1;
114
+			if (empty($mode)) {
115
+							$mode = 1;
116
+			}
113 117
 
114 118
 			$request = $smcFunc['db_query']('', '
115 119
 				SELECT id_member, id_topic, id_msg, unwatched
@@ -132,8 +136,7 @@  discard block
 block discarded – undo
132 136
 					'id_msg' => 0,
133 137
 					'unwatched' => empty($mode) ? 1 : 0,
134 138
 				);
135
-			}
136
-			else
139
+			} else
137 140
 			{
138 141
 				$insert = false;
139 142
 				$log['unwatched'] = empty($mode) ? 1 : 0;
@@ -160,9 +163,8 @@  discard block
 block discarded – undo
160 163
 					array($user_info['id'], $log['id_topic']),
161 164
 					array('id_member', 'id_board')
162 165
 				);
163
-			}
164
-			else
165
-				$smcFunc['db_query']('', '
166
+			} else {
167
+							$smcFunc['db_query']('', '
166 168
 					DELETE FROM {db_prefix}log_notify
167 169
 					WHERE id_topic = {int:topic}
168 170
 						AND id_member = {int:member}',
@@ -170,6 +172,7 @@  discard block
 block discarded – undo
170 172
 						'topic' => $log['id_topic'],
171 173
 						'member' => $user_info['id'],
172 174
 					));
175
+			}
173 176
 
174 177
 		}
175 178
 	}
@@ -186,9 +189,9 @@  discard block
 block discarded – undo
186 189
 			),
187 190
 		);
188 191
 		$context['sub_template'] = 'generic_xml';
192
+	} else {
193
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
194
+	}
189 195
 	}
190
-	else
191
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
192
-}
193 196
 
194 197
 ?>
195 198
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/RepairBoards.php 2 patches
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 					LEFT JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
233 233
 				WHERE t.id_topic IS NULL
234 234
 				GROUP BY m.id_topic, m.id_board',
235
-			'fix_processing' => function ($row) use ($smcFunc)
235
+			'fix_processing' => function($row) use ($smcFunc)
236 236
 			{
237 237
 				global $salvageBoardID;
238 238
 
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 			// Remove all topics that have zero messages in the messages table.
320 320
 			'fix_collect' => array(
321 321
 				'index' => 'id_topic',
322
-				'process' => function ($topics) use ($smcFunc)
322
+				'process' => function($topics) use ($smcFunc)
323 323
 				{
324 324
 					$smcFunc['db_query']('', '
325 325
 						DELETE FROM {db_prefix}topics
@@ -357,21 +357,21 @@  discard block
 block discarded – undo
357 357
 				  AND p.id_poll IS NULL
358 358
 				GROUP BY o.id_poll
359 359
 				  ',
360
-			'fix_processing' => function ($row) use ($smcFunc, $txt)
360
+			'fix_processing' => function($row) use ($smcFunc, $txt)
361 361
 			{
362 362
 				global $salvageBoardID;
363 363
 
364 364
 				$row['poster_name'] = !empty($row['poster_name']) ? $row['poster_name'] : $txt['guest'];
365 365
 				$row['id_poster'] = !empty($row['id_poster']) ? $row['id_poster'] : 0;
366 366
 
367
-				if(empty($row['id_board']))
367
+				if (empty($row['id_board']))
368 368
 				{
369 369
 					// Only if we don't have a reasonable idea of where to put it.
370 370
 					createSalvageArea();
371
-					$row['id_board'] = (int)$salvageBoardID;
371
+					$row['id_board'] = (int) $salvageBoardID;
372 372
 				}
373 373
 
374
-				if(empty($row['id_topic'])) {
374
+				if (empty($row['id_topic'])) {
375 375
 					$smcFunc['db_insert']('',
376 376
 						'{db_prefix}messages',
377 377
 						array(
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 					LEFT JOIN {db_prefix}topics AS t ON (t.id_poll = p.id_poll)
496 496
 				WHERE p.id_poll BETWEEN {STEP_LOW} AND {STEP_HIGH}
497 497
 					AND t.id_poll IS NULL',
498
-			'fix_processing' => function ($row) use ($smcFunc, $txt)
498
+			'fix_processing' => function($row) use ($smcFunc, $txt)
499 499
 			{
500 500
 				global $salvageBoardID;
501 501
 
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 				WHERE t.id_topic BETWEEN {STEP_LOW} AND {STEP_HIGH}
611 611
 				GROUP BY t.id_topic, t.id_first_msg, t.id_last_msg, t.approved, mf.approved
612 612
 				ORDER BY t.id_topic',
613
-			'fix_processing' => function ($row) use ($smcFunc)
613
+			'fix_processing' => function($row) use ($smcFunc)
614 614
 			{
615 615
 				$row['firstmsg_approved'] = (int) $row['firstmsg_approved'];
616 616
 				$row['myid_first_msg'] = (int) $row['myid_first_msg'];
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
 					)
640 640
 				);
641 641
 			},
642
-			'message_function' => function ($row) use ($txt, &$context)
642
+			'message_function' => function($row) use ($txt, &$context)
643 643
 			{
644 644
 				// A pretend error?
645 645
 				if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved'])
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
 				WHERE t.id_topic BETWEEN {STEP_LOW} AND {STEP_HIGH}
674 674
 				GROUP BY t.id_topic, t.num_replies, mf.approved
675 675
 				ORDER BY t.id_topic',
676
-			'fix_processing' => function ($row)
676
+			'fix_processing' => function($row)
677 677
 		{
678 678
 
679 679
 				global $smcFunc;
@@ -694,7 +694,7 @@  discard block
 block discarded – undo
694 694
 				);
695 695
 
696 696
 		},
697
-			'message_function' => function ($row)
697
+			'message_function' => function($row)
698 698
 		{
699 699
 
700 700
 				global $txt, $context;
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
 				GROUP BY t.id_topic, t.unapproved_posts
728 728
 				HAVING unapproved_posts != COUNT(mu.id_msg)
729 729
 				ORDER BY t.id_topic',
730
-			'fix_processing' => function ($row)
730
+			'fix_processing' => function($row)
731 731
 		{
732 732
 
733 733
 				global $smcFunc;
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
 				WHERE b.id_board IS NULL
770 770
 					AND t.id_topic BETWEEN {STEP_LOW} AND {STEP_HIGH}
771 771
 				GROUP BY t.id_board',
772
-			'fix_processing' => function ($row)
772
+			'fix_processing' => function($row)
773 773
 		{
774 774
 
775 775
 				global $smcFunc, $salvageCatID, $txt;
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 				ORDER BY b.id_cat, b.id_board',
819 819
 			'fix_collect' => array(
820 820
 				'index' => 'id_cat',
821
-				'process' => function ($cats)
821
+				'process' => function($cats)
822 822
 				{
823 823
 					global $smcFunc, $salvageCatID;
824 824
 					createSalvageArea();
@@ -854,7 +854,7 @@  discard block
 block discarded – undo
854 854
 			// Last step-make sure all non-guest posters still exist.
855 855
 			'fix_collect' => array(
856 856
 				'index' => 'id_msg',
857
-				'process' => function ($msgs)
857
+				'process' => function($msgs)
858 858
 		{
859 859
 
860 860
 					global $smcFunc;
@@ -883,7 +883,7 @@  discard block
 block discarded – undo
883 883
 				ORDER BY b.id_parent, b.id_board',
884 884
 			'fix_collect' => array(
885 885
 				'index' => 'id_parent',
886
-				'process' => function ($parents)
886
+				'process' => function($parents)
887 887
 				{
888 888
 					global $smcFunc, $salvageBoardID, $salvageCatID;
889 889
 					createSalvageArea();
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
 					AND p.id_poll IS NULL',
918 918
 			'fix_collect' => array(
919 919
 				'index' => 'id_poll',
920
-				'process' => function ($polls)
920
+				'process' => function($polls)
921 921
 		{
922 922
 
923 923
 					global $smcFunc;
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
 				ORDER BY cal.id_topic',
952 952
 			'fix_collect' => array(
953 953
 				'index' => 'id_topic',
954
-				'process' => function ($events)
954
+				'process' => function($events)
955 955
 		{
956 956
 
957 957
 					global $smcFunc;
@@ -983,7 +983,7 @@  discard block
 block discarded – undo
983 983
 					AND lt.id_member BETWEEN {STEP_LOW} AND {STEP_HIGH}',
984 984
 			'fix_collect' => array(
985 985
 				'index' => 'id_topic',
986
-				'process' => function ($topics)
986
+				'process' => function($topics)
987 987
 		{
988 988
 
989 989
 					global $smcFunc;
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
 				GROUP BY lt.id_member',
1016 1016
 			'fix_collect' => array(
1017 1017
 				'index' => 'id_member',
1018
-				'process' => function ($members)
1018
+				'process' => function($members)
1019 1019
 		{
1020 1020
 
1021 1021
 					global $smcFunc;
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
 				GROUP BY lb.id_board',
1048 1048
 			'fix_collect' => array(
1049 1049
 				'index' => 'id_board',
1050
-				'process' => function ($boards)
1050
+				'process' => function($boards)
1051 1051
 		{
1052 1052
 
1053 1053
 					global $smcFunc;
@@ -1079,7 +1079,7 @@  discard block
 block discarded – undo
1079 1079
 				GROUP BY lb.id_member',
1080 1080
 			'fix_collect' => array(
1081 1081
 				'index' => 'id_member',
1082
-				'process' => function ($members) use ($smcFunc)
1082
+				'process' => function($members) use ($smcFunc)
1083 1083
 				{
1084 1084
 					$smcFunc['db_query']('', '
1085 1085
 						DELETE FROM {db_prefix}log_boards
@@ -1108,7 +1108,7 @@  discard block
 block discarded – undo
1108 1108
 				GROUP BY lmr.id_board',
1109 1109
 			'fix_collect' => array(
1110 1110
 				'index' => 'id_board',
1111
-				'process' => function ($boards) use ($smcFunc)
1111
+				'process' => function($boards) use ($smcFunc)
1112 1112
 				{
1113 1113
 					$smcFunc['db_query']('', '
1114 1114
 						DELETE FROM {db_prefix}log_mark_read
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
 				GROUP BY lmr.id_member',
1138 1138
 			'fix_collect' => array(
1139 1139
 				'index' => 'id_member',
1140
-				'process' => function ($members) use ($smcFunc)
1140
+				'process' => function($members) use ($smcFunc)
1141 1141
 				{
1142 1142
 					$smcFunc['db_query']('', '
1143 1143
 						DELETE FROM {db_prefix}log_mark_read
@@ -1166,7 +1166,7 @@  discard block
 block discarded – undo
1166 1166
 				GROUP BY pmr.id_pm',
1167 1167
 			'fix_collect' => array(
1168 1168
 				'index' => 'id_pm',
1169
-				'process' => function ($pms) use ($smcFunc)
1169
+				'process' => function($pms) use ($smcFunc)
1170 1170
 				{
1171 1171
 					$smcFunc['db_query']('', '
1172 1172
 						DELETE FROM {db_prefix}pm_recipients
@@ -1196,7 +1196,7 @@  discard block
 block discarded – undo
1196 1196
 				GROUP BY pmr.id_member',
1197 1197
 			'fix_collect' => array(
1198 1198
 				'index' => 'id_member',
1199
-				'process' => function ($members)
1199
+				'process' => function($members)
1200 1200
 		{
1201 1201
 
1202 1202
 					global $smcFunc;
@@ -1228,7 +1228,7 @@  discard block
 block discarded – undo
1228 1228
 					AND mem.id_member IS NULL',
1229 1229
 			'fix_collect' => array(
1230 1230
 				'index' => 'id_pm',
1231
-				'process' => function ($guestMessages)
1231
+				'process' => function($guestMessages)
1232 1232
 		{
1233 1233
 
1234 1234
 					global $smcFunc;
@@ -1260,7 +1260,7 @@  discard block
 block discarded – undo
1260 1260
 				GROUP BY ln.id_member',
1261 1261
 			'fix_collect' => array(
1262 1262
 				'index' => 'id_member',
1263
-				'process' => function ($members) use ($smcFunc)
1263
+				'process' => function($members) use ($smcFunc)
1264 1264
 				{
1265 1265
 					$smcFunc['db_query']('', '
1266 1266
 						DELETE FROM {db_prefix}log_notify
@@ -1287,7 +1287,7 @@  discard block
 block discarded – undo
1287 1287
 					LEFT JOIN {db_prefix}log_search_subjects AS lss ON (lss.id_topic = t.id_topic)
1288 1288
 				WHERE t.id_topic BETWEEN {STEP_LOW} AND {STEP_HIGH}
1289 1289
 					AND lss.id_topic IS NULL',
1290
-			'fix_full_processing' => function ($result)
1290
+			'fix_full_processing' => function($result)
1291 1291
 		{
1292 1292
 
1293 1293
 				global $smcFunc;
@@ -1319,7 +1319,7 @@  discard block
 block discarded – undo
1319 1319
 					);
1320 1320
 
1321 1321
 		},
1322
-			'message_function' => function ($row)
1322
+			'message_function' => function($row)
1323 1323
 		{
1324 1324
 
1325 1325
 				global $txt, $context;
@@ -1349,7 +1349,7 @@  discard block
 block discarded – undo
1349 1349
 					AND t.id_topic IS NULL',
1350 1350
 			'fix_collect' => array(
1351 1351
 				'index' => 'id_topic',
1352
-				'process' => function ($deleteTopics)
1352
+				'process' => function($deleteTopics)
1353 1353
 		{
1354 1354
 
1355 1355
 					global $smcFunc;
@@ -1381,7 +1381,7 @@  discard block
 block discarded – undo
1381 1381
 					AND mem.id_member IS NULL',
1382 1382
 			'fix_collect' => array(
1383 1383
 				'index' => 'id_member',
1384
-				'process' => function ($members)
1384
+				'process' => function($members)
1385 1385
 		{
1386 1386
 
1387 1387
 					global $smcFunc;
@@ -1412,7 +1412,7 @@  discard block
 block discarded – undo
1412 1412
 					AND p.id_poll IS NULL',
1413 1413
 			'fix_collect' => array(
1414 1414
 				'index' => 'id_poll',
1415
-				'process' => function ($polls)
1415
+				'process' => function($polls)
1416 1416
 		{
1417 1417
 
1418 1418
 					global $smcFunc;
@@ -1443,7 +1443,7 @@  discard block
 block discarded – undo
1443 1443
 					AND lrc.id_report IS NULL',
1444 1444
 			'fix_collect' => array(
1445 1445
 				'index' => 'id_report',
1446
-				'process' => function ($reports)
1446
+				'process' => function($reports)
1447 1447
 		{
1448 1448
 
1449 1449
 					global $smcFunc;
@@ -1474,7 +1474,7 @@  discard block
 block discarded – undo
1474 1474
 					AND lr.id_report IS NULL',
1475 1475
 			'fix_collect' => array(
1476 1476
 				'index' => 'id_report',
1477
-				'process' => function ($reports)
1477
+				'process' => function($reports)
1478 1478
 				{
1479 1479
 					global $smcFunc;
1480 1480
 					$smcFunc['db_query']('', '
@@ -1504,7 +1504,7 @@  discard block
 block discarded – undo
1504 1504
 				GROUP BY lgr.id_member',
1505 1505
 			'fix_collect' => array(
1506 1506
 				'index' => 'id_member',
1507
-				'process' => function ($members)
1507
+				'process' => function($members)
1508 1508
 				{
1509 1509
 					global $smcFunc;
1510 1510
 					$smcFunc['db_query']('', '
@@ -1534,7 +1534,7 @@  discard block
 block discarded – undo
1534 1534
 				GROUP BY lgr.id_group',
1535 1535
 			'fix_collect' => array(
1536 1536
 				'index' => 'id_group',
1537
-				'process' => function ($groups)
1537
+				'process' => function($groups)
1538 1538
 				{
1539 1539
 					global $smcFunc;
1540 1540
 					$smcFunc['db_query']('', '
Please login to merge, or discard this patch.
Braces   +119 added lines, -85 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Finds or repairs errors in the database to fix possible problems.
@@ -50,8 +51,9 @@  discard block
 block discarded – undo
50 51
 	);
51 52
 
52 53
 	// Start displaying errors without fixing them.
53
-	if (isset($_GET['fixErrors']))
54
-		checkSession('get');
54
+	if (isset($_GET['fixErrors'])) {
55
+			checkSession('get');
56
+	}
55 57
 
56 58
 	// Will want this.
57 59
 	loadForumTests();
@@ -69,11 +71,11 @@  discard block
 block discarded – undo
69 71
 			$_SESSION['repairboards_to_fix'] = $context['to_fix'];
70 72
 			$_SESSION['repairboards_to_fix2'] = null;
71 73
 
72
-			if (empty($context['repair_errors']))
73
-				$context['repair_errors'][] = '???';
74
+			if (empty($context['repair_errors'])) {
75
+							$context['repair_errors'][] = '???';
76
+			}
74 77
 		}
75
-	}
76
-	else
78
+	} else
77 79
 	{
78 80
 		$context['error_search'] = false;
79 81
 		$context['to_fix'] = isset($_SESSION['repairboards_to_fix']) ? $_SESSION['repairboards_to_fix'] : array();
@@ -120,16 +122,19 @@  discard block
 block discarded – undo
120 122
 
121 123
 	// More time, I need more time!
122 124
 	@set_time_limit(600);
123
-	if (function_exists('apache_reset_timeout'))
124
-		@apache_reset_timeout();
125
+	if (function_exists('apache_reset_timeout')) {
126
+			@apache_reset_timeout();
127
+	}
125 128
 
126 129
 	// Errr, wait.  How much time has this taken already?
127
-	if (!$force && time() - array_sum(explode(' ', $time_start)) < 3)
128
-		return;
130
+	if (!$force && time() - array_sum(explode(' ', $time_start)) < 3) {
131
+			return;
132
+	}
129 133
 
130 134
 	// Restore the query cache if interested.
131
-	if (!empty($db_temp_cache))
132
-		$db_cache = $db_temp_cache;
135
+	if (!empty($db_temp_cache)) {
136
+			$db_cache = $db_temp_cache;
137
+	}
133 138
 
134 139
 	$context['continue_get_data'] = '?action=admin;area=repairboards' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id'];
135 140
 	$context['page_title'] = $txt['not_done_title'];
@@ -138,10 +143,11 @@  discard block
 block discarded – undo
138 143
 	$context['sub_template'] = 'not_done';
139 144
 
140 145
 	// Change these two if more steps are added!
141
-	if (empty($max_substep))
142
-		$context['continue_percent'] = round(($_GET['step'] * 100) / $context['total_steps']);
143
-	else
144
-		$context['continue_percent'] = round((($_GET['step'] + ($_GET['substep'] / $max_substep)) * 100) / $context['total_steps']);
146
+	if (empty($max_substep)) {
147
+			$context['continue_percent'] = round(($_GET['step'] * 100) / $context['total_steps']);
148
+	} else {
149
+			$context['continue_percent'] = round((($_GET['step'] + ($_GET['substep'] / $max_substep)) * 100) / $context['total_steps']);
150
+	}
145 151
 
146 152
 	// Never more than 100%!
147 153
 	$context['continue_percent'] = min($context['continue_percent'], 100);
@@ -617,8 +623,9 @@  discard block
 block discarded – undo
617 623
 				$row['myid_last_msg'] = (int) $row['myid_last_msg'];
618 624
 
619 625
 				// Not really a problem?
620
-				if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved'])
621
-					return false;
626
+				if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) {
627
+									return false;
628
+				}
622 629
 
623 630
 				$memberStartedID = (int) getMsgMemberID($row['myid_first_msg']);
624 631
 				$memberUpdatedID = (int) getMsgMemberID($row['myid_last_msg']);
@@ -642,15 +649,19 @@  discard block
 block discarded – undo
642 649
 			'message_function' => function ($row) use ($txt, &$context)
643 650
 			{
644 651
 				// A pretend error?
645
-				if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved'])
646
-					return false;
652
+				if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) {
653
+									return false;
654
+				}
647 655
 
648
-				if ($row['id_first_msg'] != $row['myid_first_msg'])
649
-					$context['repair_errors'][] = sprintf($txt['repair_stats_topics_1'], $row['id_topic'], $row['id_first_msg']);
650
-				if ($row['id_last_msg'] != $row['myid_last_msg'])
651
-					$context['repair_errors'][] = sprintf($txt['repair_stats_topics_2'], $row['id_topic'], $row['id_last_msg']);
652
-				if ($row['approved'] != $row['firstmsg_approved'])
653
-					$context['repair_errors'][] = sprintf($txt['repair_stats_topics_5'], $row['id_topic']);
656
+				if ($row['id_first_msg'] != $row['myid_first_msg']) {
657
+									$context['repair_errors'][] = sprintf($txt['repair_stats_topics_1'], $row['id_topic'], $row['id_first_msg']);
658
+				}
659
+				if ($row['id_last_msg'] != $row['myid_last_msg']) {
660
+									$context['repair_errors'][] = sprintf($txt['repair_stats_topics_2'], $row['id_topic'], $row['id_last_msg']);
661
+				}
662
+				if ($row['approved'] != $row['firstmsg_approved']) {
663
+									$context['repair_errors'][] = sprintf($txt['repair_stats_topics_5'], $row['id_topic']);
664
+				}
654 665
 
655 666
 				return true;
656 667
 			},
@@ -680,8 +691,9 @@  discard block
 block discarded – undo
680 691
 				$row['my_num_replies'] = (int) $row['my_num_replies'];
681 692
 
682 693
 				// Not really a problem?
683
-				if ($row['my_num_replies'] == $row['num_replies'])
684
-					return false;
694
+				if ($row['my_num_replies'] == $row['num_replies']) {
695
+									return false;
696
+				}
685 697
 
686 698
 				$smcFunc['db_query']('', '
687 699
 					UPDATE {db_prefix}topics
@@ -700,11 +712,13 @@  discard block
 block discarded – undo
700 712
 				global $txt, $context;
701 713
 
702 714
 				// Just joking?
703
-				if ($row['my_num_replies'] == $row['num_replies'])
704
-					return false;
715
+				if ($row['my_num_replies'] == $row['num_replies']) {
716
+									return false;
717
+				}
705 718
 
706
-				if ($row['num_replies'] != $row['my_num_replies'])
707
-					$context['repair_errors'][] = sprintf($txt['repair_stats_topics_3'], $row['id_topic'], $row['num_replies']);
719
+				if ($row['num_replies'] != $row['my_num_replies']) {
720
+									$context['repair_errors'][] = sprintf($txt['repair_stats_topics_3'], $row['id_topic'], $row['num_replies']);
721
+				}
708 722
 
709 723
 				return true;
710 724
 
@@ -1295,8 +1309,9 @@  discard block
 block discarded – undo
1295 1309
 				$inserts = array();
1296 1310
 				while ($row = $smcFunc['db_fetch_assoc']($result))
1297 1311
 				{
1298
-					foreach (text2words($row['subject']) as $word)
1299
-						$inserts[] = array($word, $row['id_topic']);
1312
+					foreach (text2words($row['subject']) as $word) {
1313
+											$inserts[] = array($word, $row['id_topic']);
1314
+					}
1300 1315
 					if (count($inserts) > 500)
1301 1316
 					{
1302 1317
 						$smcFunc['db_insert']('ignore',
@@ -1310,13 +1325,14 @@  discard block
 block discarded – undo
1310 1325
 
1311 1326
 				}
1312 1327
 
1313
-				if (!empty($inserts))
1314
-					$smcFunc['db_insert']('ignore',
1328
+				if (!empty($inserts)) {
1329
+									$smcFunc['db_insert']('ignore',
1315 1330
 						'{db_prefix}log_search_subjects',
1316 1331
 						array('word' => 'string', 'id_topic' => 'int'),
1317 1332
 						$inserts,
1318 1333
 						array('word', 'id_topic')
1319 1334
 					);
1335
+				}
1320 1336
 
1321 1337
 		},
1322 1338
 			'message_function' => function ($row)
@@ -1586,8 +1602,9 @@  discard block
 block discarded – undo
1586 1602
 		$current_step++;
1587 1603
 
1588 1604
 		// Already done this?
1589
-		if ($_GET['step'] > $current_step)
1590
-			continue;
1605
+		if ($_GET['step'] > $current_step) {
1606
+					continue;
1607
+		}
1591 1608
 
1592 1609
 		// If we're fixing it but it ain't broke why try?
1593 1610
 		if ($do_fix && !in_array($error_type, $to_fix))
@@ -1616,14 +1633,16 @@  discard block
 block discarded – undo
1616 1633
 		while (!$done)
1617 1634
 		{
1618 1635
 			// Make sure there's at least one ID to test.
1619
-			if (isset($test['substeps']) && empty($step_max))
1620
-				break;
1636
+			if (isset($test['substeps']) && empty($step_max)) {
1637
+							break;
1638
+			}
1621 1639
 
1622 1640
 			// What is the testing query (Changes if we are testing or fixing)
1623
-			if (!$do_fix)
1624
-				$test_query = 'check_query';
1625
-			else
1626
-				$test_query = isset($test['fix_query']) ? 'fix_query' : 'check_query';
1641
+			if (!$do_fix) {
1642
+							$test_query = 'check_query';
1643
+			} else {
1644
+							$test_query = isset($test['fix_query']) ? 'fix_query' : 'check_query';
1645
+			}
1627 1646
 
1628 1647
 			// Do the test...
1629 1648
 			$request = $smcFunc['db_query']('',
@@ -1634,10 +1653,11 @@  discard block
 block discarded – undo
1634 1653
 			$needs_fix = false;
1635 1654
 
1636 1655
 			// Does it need a fix?
1637
-			if (!empty($test['check_type']) && $test['check_type'] == 'count')
1638
-				list ($needs_fix) = $smcFunc['db_fetch_row']($request);
1639
-			else
1640
-				$needs_fix = $smcFunc['db_num_rows']($request);
1656
+			if (!empty($test['check_type']) && $test['check_type'] == 'count') {
1657
+							list ($needs_fix) = $smcFunc['db_fetch_row']($request);
1658
+			} else {
1659
+							$needs_fix = $smcFunc['db_num_rows']($request);
1660
+			}
1641 1661
 
1642 1662
 			$total_queries++;
1643 1663
 
@@ -1649,8 +1669,9 @@  discard block
 block discarded – undo
1649 1669
 					// Assume need to fix.
1650 1670
 					$found_errors = true;
1651 1671
 
1652
-					if (isset($test['message']))
1653
-						$context['repair_errors'][] = $txt[$test['message']];
1672
+					if (isset($test['message'])) {
1673
+											$context['repair_errors'][] = $txt[$test['message']];
1674
+					}
1654 1675
 
1655 1676
 					// One per row!
1656 1677
 					elseif (isset($test['messages']))
@@ -1660,10 +1681,11 @@  discard block
 block discarded – undo
1660 1681
 							$variables = $test['messages'];
1661 1682
 							foreach ($variables as $k => $v)
1662 1683
 							{
1663
-								if ($k == 0 && isset($txt[$v]))
1664
-									$variables[$k] = $txt[$v];
1665
-								elseif ($k > 0 && isset($row[$v]))
1666
-									$variables[$k] = $row[$v];
1684
+								if ($k == 0 && isset($txt[$v])) {
1685
+																	$variables[$k] = $txt[$v];
1686
+								} elseif ($k > 0 && isset($row[$v])) {
1687
+																	$variables[$k] = $row[$v];
1688
+								}
1667 1689
 							}
1668 1690
 							$context['repair_errors'][] = call_user_func_array('sprintf', $variables);
1669 1691
 						}
@@ -1674,13 +1696,15 @@  discard block
 block discarded – undo
1674 1696
 					{
1675 1697
 						// Find out if there are actually errors.
1676 1698
 						$found_errors = false;
1677
-						while ($row = $smcFunc['db_fetch_assoc']($request))
1678
-							$found_errors |= $test['message_function']($row);
1699
+						while ($row = $smcFunc['db_fetch_assoc']($request)) {
1700
+													$found_errors |= $test['message_function']($row);
1701
+						}
1679 1702
 					}
1680 1703
 
1681 1704
 					// Actually have something to fix?
1682
-					if ($found_errors)
1683
-						$to_fix[] = $error_type;
1705
+					if ($found_errors) {
1706
+											$to_fix[] = $error_type;
1707
+					}
1684 1708
 				}
1685 1709
 
1686 1710
 				// We want to fix, we need to fix - so work out what exactly to do!
@@ -1690,8 +1714,9 @@  discard block
 block discarded – undo
1690 1714
 					if (isset($test['fix_collect']))
1691 1715
 					{
1692 1716
 						$ids = array();
1693
-						while ($row = $smcFunc['db_fetch_assoc']($request))
1694
-							$ids[] = $row[$test['fix_collect']['index']];
1717
+						while ($row = $smcFunc['db_fetch_assoc']($request)) {
1718
+													$ids[] = $row[$test['fix_collect']['index']];
1719
+						}
1695 1720
 						if (!empty($ids))
1696 1721
 						{
1697 1722
 							// Fix it!
@@ -1700,30 +1725,34 @@  discard block
 block discarded – undo
1700 1725
 					}
1701 1726
 
1702 1727
 					// Simply executing a fix it query?
1703
-					elseif (isset($test['fix_it_query']))
1704
-						$smcFunc['db_query']('',
1728
+					elseif (isset($test['fix_it_query'])) {
1729
+											$smcFunc['db_query']('',
1705 1730
 							$test['fix_it_query'],
1706 1731
 							array(
1707 1732
 							)
1708 1733
 						);
1734
+					}
1709 1735
 
1710 1736
 					// Do we have some processing to do?
1711 1737
 					elseif (isset($test['fix_processing']))
1712 1738
 					{
1713
-						while ($row = $smcFunc['db_fetch_assoc']($request))
1714
-							$test['fix_processing']($row);
1739
+						while ($row = $smcFunc['db_fetch_assoc']($request)) {
1740
+													$test['fix_processing']($row);
1741
+						}
1715 1742
 					}
1716 1743
 
1717 1744
 					// What about the full set of processing?
1718
-					elseif (isset($test['fix_full_processing']))
1719
-						$test['fix_full_processing']($request);
1745
+					elseif (isset($test['fix_full_processing'])) {
1746
+											$test['fix_full_processing']($request);
1747
+					}
1720 1748
 
1721 1749
 					// Do we have other things we need to fix as a result?
1722 1750
 					if (!empty($test['force_fix']))
1723 1751
 					{
1724
-						foreach ($test['force_fix'] as $item)
1725
-							if (!in_array($item, $to_fix))
1752
+						foreach ($test['force_fix'] as $item) {
1753
+													if (!in_array($item, $to_fix))
1726 1754
 								$to_fix[] = $item;
1755
+						}
1727 1756
 					}
1728 1757
 				}
1729 1758
 			}
@@ -1741,16 +1770,17 @@  discard block
 block discarded – undo
1741 1770
 				if ($_GET['substep'] <= $step_max)
1742 1771
 				{
1743 1772
 					pauseRepairProcess($to_fix, $error_type, $step_max);
1773
+				} else {
1774
+									$done = true;
1744 1775
 				}
1745
-				else
1746
-					$done = true;
1776
+			} else {
1777
+							$done = true;
1747 1778
 			}
1748
-			else
1749
-				$done = true;
1750 1779
 
1751 1780
 			// Don't allow more than 1000 queries at a time.
1752
-			if ($total_queries >= 1000)
1753
-				pauseRepairProcess($to_fix, $error_type, $step_max, true);
1781
+			if ($total_queries >= 1000) {
1782
+							pauseRepairProcess($to_fix, $error_type, $step_max, true);
1783
+			}
1754 1784
 		}
1755 1785
 
1756 1786
 		// Keep going.
@@ -1763,8 +1793,9 @@  discard block
 block discarded – undo
1763 1793
 		if ($do_fix)
1764 1794
 		{
1765 1795
 			$key = array_search($error_type, $to_fix);
1766
-			if ($key !== false && isset($to_fix[$key]))
1767
-				unset($to_fix[$key]);
1796
+			if ($key !== false && isset($to_fix[$key])) {
1797
+							unset($to_fix[$key]);
1798
+			}
1768 1799
 		}
1769 1800
 
1770 1801
 		// Are we done?
@@ -1787,10 +1818,11 @@  discard block
 block discarded – undo
1787 1818
 	static $createOnce = false;
1788 1819
 
1789 1820
 	// Have we already created it?
1790
-	if ($createOnce)
1791
-		return;
1792
-	else
1793
-		$createOnce = true;
1821
+	if ($createOnce) {
1822
+			return;
1823
+	} else {
1824
+			$createOnce = true;
1825
+	}
1794 1826
 
1795 1827
 	// Back to the forum's default language.
1796 1828
 	loadLanguage('Admin', $language);
@@ -1805,8 +1837,9 @@  discard block
 block discarded – undo
1805 1837
 			'cat_name' => $txt['salvaged_category_name'],
1806 1838
 		)
1807 1839
 	);
1808
-	if ($smcFunc['db_num_rows']($result) != 0)
1809
-		list ($salvageCatID) = $smcFunc['db_fetch_row']($result);
1840
+	if ($smcFunc['db_num_rows']($result) != 0) {
1841
+			list ($salvageCatID) = $smcFunc['db_fetch_row']($result);
1842
+	}
1810 1843
 	$smcFunc['db_free_result']($result);
1811 1844
 
1812 1845
 	if (empty($salvageCatID))
@@ -1839,8 +1872,9 @@  discard block
 block discarded – undo
1839 1872
 			'board_name' => $txt['salvaged_board_name'],
1840 1873
 		)
1841 1874
 	);
1842
-	if ($smcFunc['db_num_rows']($result) != 0)
1843
-		list ($salvageBoardID) = $smcFunc['db_fetch_row']($result);
1875
+	if ($smcFunc['db_num_rows']($result) != 0) {
1876
+			list ($salvageBoardID) = $smcFunc['db_fetch_row']($result);
1877
+	}
1844 1878
 	$smcFunc['db_free_result']($result);
1845 1879
 
1846 1880
 	if (empty($salvageBoardID))
Please login to merge, or discard this patch.
Sources/DbSearch-mysql.php 1 patch
Braces   +13 added lines, -10 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Add the file functions to the $smcFunc array.
@@ -23,14 +24,15 @@  discard block
 block discarded – undo
23 24
 {
24 25
 	global $smcFunc;
25 26
 
26
-	if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_query')
27
-		$smcFunc += array(
27
+	if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_query') {
28
+			$smcFunc += array(
28 29
 			'db_search_query' => 'smf_db_query',
29 30
 			'db_search_support' => 'smf_db_search_support',
30 31
 			'db_create_word_search' => 'smf_db_create_word_search',
31 32
 			'db_support_ignore' => true,
32 33
 		);
33
-}
34
+	}
35
+	}
34 36
 
35 37
 /**
36 38
  * This function will tell you whether this database type supports this search type.
@@ -54,12 +56,13 @@  discard block
 block discarded – undo
54 56
 {
55 57
 	global $smcFunc;
56 58
 
57
-	if ($size == 'small')
58
-		$size = 'smallint(5)';
59
-	elseif ($size == 'medium')
60
-		$size = 'mediumint(8)';
61
-	else
62
-		$size = 'int(10)';
59
+	if ($size == 'small') {
60
+			$size = 'smallint(5)';
61
+	} elseif ($size == 'medium') {
62
+			$size = 'mediumint(8)';
63
+	} else {
64
+			$size = 'int(10)';
65
+	}
63 66
 
64 67
 	$smcFunc['db_query']('', '
65 68
 		CREATE TABLE {db_prefix}log_search_words (
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 						$replacement[$key] = 'null';
253 253
 					if (!isValidIP($value))
254 254
 						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
255
-					$replacement[$key] =  sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
255
+					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
256 256
 				}
257 257
 
258 258
 				return implode(', ', $replacement);
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
  * @param bool $translate_human_wildcards If true, turns human readable wildcards into SQL wildcards.
812 812
  * @return string The escaped string
813 813
  */
814
-function smf_db_escape_wildcard_string($string, $translate_human_wildcards=false)
814
+function smf_db_escape_wildcard_string($string, $translate_human_wildcards = false)
815 815
 {
816 816
 	$replacements = array(
817 817
 		'%' => '\%',
Please login to merge, or discard this patch.
Braces   +230 added lines, -168 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc')
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc') {
38
+			$smcFunc += array(
38 39
 			'db_query' => 'smf_db_query',
39 40
 			'db_quote' => 'smf_db_quote',
40 41
 			'db_fetch_assoc' => 'mysql_fetch_assoc',
@@ -58,36 +59,42 @@  discard block
 block discarded – undo
58 59
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
59 60
 			'db_is_resource' => 'is_resource',
60 61
 		);
62
+	}
61 63
 
62
-	if (!empty($db_options['port']))
63
-		$db_server .= ':' . $db_options['port'];
64
+	if (!empty($db_options['port'])) {
65
+			$db_server .= ':' . $db_options['port'];
66
+	}
64 67
 	
65 68
 	$flags = 2; //#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
66 69
 
67
-	if (!empty($db_options['persist']))
68
-		$connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags);
69
-	else
70
-		$connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags);
70
+	if (!empty($db_options['persist'])) {
71
+			$connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags);
72
+	} else {
73
+			$connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags);
74
+	}
71 75
 
72 76
 	// Something's wrong, show an error if its fatal (which we assume it is)
73 77
 	if (!$connection)
74 78
 	{
75
-		if (!empty($db_options['non_fatal']))
76
-			return null;
77
-		else
78
-			display_db_error();
79
+		if (!empty($db_options['non_fatal'])) {
80
+					return null;
81
+		} else {
82
+					display_db_error();
83
+		}
79 84
 	}
80 85
 
81 86
 	// Select the database, unless told not to
82
-	if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal']))
83
-		display_db_error();
87
+	if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal'])) {
88
+			display_db_error();
89
+	}
84 90
 
85 91
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
86
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
87
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
92
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
93
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
88 94
 		array(),
89 95
 		false
90 96
 	);
97
+	}
91 98
 
92 99
 	return $connection;
93 100
 }
@@ -134,37 +141,46 @@  discard block
 block discarded – undo
134 141
 	list ($values, $connection) = $db_callback;
135 142
 
136 143
 	// Connection gone???  This should *never* happen at this point, yet it does :'(
137
-	if (!is_resource($connection))
138
-		display_db_error();
144
+	if (!is_resource($connection)) {
145
+			display_db_error();
146
+	}
139 147
 
140
-	if ($matches[1] === 'db_prefix')
141
-		return $db_prefix;
148
+	if ($matches[1] === 'db_prefix') {
149
+			return $db_prefix;
150
+	}
142 151
 
143
-	if ($matches[1] === 'query_see_board')
144
-		return $user_info['query_see_board'];
152
+	if ($matches[1] === 'query_see_board') {
153
+			return $user_info['query_see_board'];
154
+	}
145 155
 
146
-	if ($matches[1] === 'query_wanna_see_board')
147
-		return $user_info['query_wanna_see_board'];
156
+	if ($matches[1] === 'query_wanna_see_board') {
157
+			return $user_info['query_wanna_see_board'];
158
+	}
148 159
 
149
-	if ($matches[1] === 'empty')
150
-		return '\'\'';
160
+	if ($matches[1] === 'empty') {
161
+			return '\'\'';
162
+	}
151 163
 
152
-	if (!isset($matches[2]))
153
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
164
+	if (!isset($matches[2])) {
165
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
166
+	}
154 167
 
155
-	if ($matches[1] === 'literal')
156
-		return '\'' . mysql_real_escape_string($matches[2], $connection) . '\'';
168
+	if ($matches[1] === 'literal') {
169
+			return '\'' . mysql_real_escape_string($matches[2], $connection) . '\'';
170
+	}
157 171
 
158
-	if (!isset($values[$matches[2]]))
159
-		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__);
172
+	if (!isset($values[$matches[2]])) {
173
+			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__);
174
+	}
160 175
 
161 176
 	$replacement = $values[$matches[2]];
162 177
 
163 178
 	switch ($matches[1])
164 179
 	{
165 180
 		case 'int':
166
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
167
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
182
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183
+			}
168 184
 			return (string) (int) $replacement;
169 185
 		break;
170 186
 
@@ -176,56 +192,63 @@  discard block
 block discarded – undo
176 192
 		case 'array_int':
177 193
 			if (is_array($replacement))
178 194
 			{
179
-				if (empty($replacement))
180
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
195
+				if (empty($replacement)) {
196
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
197
+				}
181 198
 
182 199
 				foreach ($replacement as $key => $value)
183 200
 				{
184
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
185
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
201
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
202
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
203
+					}
186 204
 
187 205
 					$replacement[$key] = (string) (int) $value;
188 206
 				}
189 207
 
190 208
 				return implode(', ', $replacement);
209
+			} else {
210
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
191 211
 			}
192
-			else
193
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
194 212
 
195 213
 		break;
196 214
 
197 215
 		case 'array_string':
198 216
 			if (is_array($replacement))
199 217
 			{
200
-				if (empty($replacement))
201
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218
+				if (empty($replacement)) {
219
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220
+				}
202 221
 
203
-				foreach ($replacement as $key => $value)
204
-					$replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection));
222
+				foreach ($replacement as $key => $value) {
223
+									$replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection));
224
+				}
205 225
 
206 226
 				return implode(', ', $replacement);
227
+			} else {
228
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
207 229
 			}
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__);
210 230
 		break;
211 231
 
212 232
 		case 'date':
213
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
214
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
215
-			else
216
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
234
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
235
+			} else {
236
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237
+			}
217 238
 		break;
218 239
 
219 240
 		case 'time':
220
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
221
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
222
-			else
223
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
241
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
242
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
243
+			} else {
244
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
245
+			}
224 246
 		break;
225 247
 
226 248
 		case 'float':
227
-			if (!is_numeric($replacement))
228
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249
+			if (!is_numeric($replacement)) {
250
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
251
+			}
229 252
 			return (string) (float) $replacement;
230 253
 		break;
231 254
 
@@ -239,32 +262,37 @@  discard block
 block discarded – undo
239 262
 		break;
240 263
 
241 264
 		case 'inet':
242
-			if ($replacement == 'null' || $replacement == '')
243
-				return 'null';
244
-			if (!isValidIP($replacement))
245
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265
+			if ($replacement == 'null' || $replacement == '') {
266
+							return 'null';
267
+			}
268
+			if (!isValidIP($replacement)) {
269
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+			}
246 271
 			//we don't use the native support of mysql > 5.6.2
247 272
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
248 273
 
249 274
 		case 'array_inet':
250 275
 			if (is_array($replacement))
251 276
 			{
252
-				if (empty($replacement))
253
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
277
+				if (empty($replacement)) {
278
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
279
+				}
254 280
 
255 281
 				foreach ($replacement as $key => $value)
256 282
 				{
257
-					if ($replacement == 'null' || $replacement == '')
258
-						$replacement[$key] = 'null';
259
-					if (!isValidIP($value))
260
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
283
+					if ($replacement == 'null' || $replacement == '') {
284
+											$replacement[$key] = 'null';
285
+					}
286
+					if (!isValidIP($value)) {
287
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
288
+					}
261 289
 					$replacement[$key] =  sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
262 290
 				}
263 291
 
264 292
 				return implode(', ', $replacement);
293
+			} else {
294
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265 295
 			}
266
-			else
267
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
268 296
 		break;
269 297
 
270 298
 		default:
@@ -335,18 +363,20 @@  discard block
 block discarded – undo
335 363
 	// One more query....
336 364
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
337 365
 
338
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
339
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
366
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
367
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
368
+	}
340 369
 
341 370
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
342 371
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
343 372
 	{
344 373
 		// Add before LIMIT
345
-		if ($pos = strpos($db_string, 'LIMIT '))
346
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
347
-		else
348
-			// Append it.
374
+		if ($pos = strpos($db_string, 'LIMIT ')) {
375
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
376
+		} else {
377
+					// Append it.
349 378
 			$db_string .= "\n\t\t\tORDER BY null";
379
+		}
350 380
 	}
351 381
 
352 382
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -368,8 +398,9 @@  discard block
 block discarded – undo
368 398
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
369 399
 
370 400
 		// Initialize $db_cache if not already initialized.
371
-		if (!isset($db_cache))
372
-			$db_cache = array();
401
+		if (!isset($db_cache)) {
402
+					$db_cache = array();
403
+		}
373 404
 
374 405
 		if (!empty($_SESSION['debug_redirect']))
375 406
 		{
@@ -395,17 +426,18 @@  discard block
 block discarded – undo
395 426
 		while (true)
396 427
 		{
397 428
 			$pos = strpos($db_string, '\'', $pos + 1);
398
-			if ($pos === false)
399
-				break;
429
+			if ($pos === false) {
430
+							break;
431
+			}
400 432
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
401 433
 
402 434
 			while (true)
403 435
 			{
404 436
 				$pos1 = strpos($db_string, '\'', $pos + 1);
405 437
 				$pos2 = strpos($db_string, '\\', $pos + 1);
406
-				if ($pos1 === false)
407
-					break;
408
-				elseif ($pos2 === false || $pos2 > $pos1)
438
+				if ($pos1 === false) {
439
+									break;
440
+				} elseif ($pos2 === false || $pos2 > $pos1)
409 441
 				{
410 442
 					$pos = $pos1;
411 443
 					break;
@@ -421,29 +453,35 @@  discard block
 block discarded – undo
421 453
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
422 454
 
423 455
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
424
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
425
-			$fail = true;
456
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
457
+					$fail = true;
458
+		}
426 459
 		// Trying to change passwords, slow us down, or something?
427
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
428
-			$fail = true;
429
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
430
-			$fail = true;
460
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
461
+					$fail = true;
462
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
463
+					$fail = true;
464
+		}
431 465
 
432
-		if (!empty($fail) && function_exists('log_error'))
433
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
466
+		if (!empty($fail) && function_exists('log_error')) {
467
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
468
+		}
434 469
 	}
435 470
 
436
-	if (empty($db_unbuffered))
437
-		$ret = @mysql_query($db_string, $connection);
438
-	else
439
-		$ret = @mysql_unbuffered_query($db_string, $connection);
471
+	if (empty($db_unbuffered)) {
472
+			$ret = @mysql_query($db_string, $connection);
473
+	} else {
474
+			$ret = @mysql_unbuffered_query($db_string, $connection);
475
+	}
440 476
 
441
-	if ($ret === false && empty($db_values['db_error_skip']))
442
-		$ret = smf_db_error($db_string, $connection);
477
+	if ($ret === false && empty($db_values['db_error_skip'])) {
478
+			$ret = smf_db_error($db_string, $connection);
479
+	}
443 480
 
444 481
 	// Debugging.
445
-	if (isset($db_show_debug) && $db_show_debug === true)
446
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
482
+	if (isset($db_show_debug) && $db_show_debug === true) {
483
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
484
+	}
447 485
 
448 486
 	return $ret;
449 487
 }
@@ -492,12 +530,13 @@  discard block
 block discarded – undo
492 530
 	// Decide which connection to use
493 531
 	$connection = $connection === null ? $db_connection : $connection;
494 532
 
495
-	if ($type == 'begin')
496
-		return @mysql_query('BEGIN', $connection);
497
-	elseif ($type == 'rollback')
498
-		return @mysql_query('ROLLBACK', $connection);
499
-	elseif ($type == 'commit')
500
-		return @mysql_query('COMMIT', $connection);
533
+	if ($type == 'begin') {
534
+			return @mysql_query('BEGIN', $connection);
535
+	} elseif ($type == 'rollback') {
536
+			return @mysql_query('ROLLBACK', $connection);
537
+	} elseif ($type == 'commit') {
538
+			return @mysql_query('COMMIT', $connection);
539
+	}
501 540
 
502 541
 	return false;
503 542
 }
@@ -537,8 +576,9 @@  discard block
 block discarded – undo
537 576
 	//    2013: Lost connection to server during query.
538 577
 
539 578
 	// Log the error.
540
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
541
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
579
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
580
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
581
+	}
542 582
 
543 583
 	// Database error auto fixing ;).
544 584
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -547,8 +587,9 @@  discard block
 block discarded – undo
547 587
 		$old_cache = @$modSettings['cache_enable'];
548 588
 		$modSettings['cache_enable'] = '1';
549 589
 
550
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
551
-			$db_last_error = max(@$db_last_error, $temp);
590
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
591
+					$db_last_error = max(@$db_last_error, $temp);
592
+		}
552 593
 
553 594
 		if (@$db_last_error < time() - 3600 * 24 * 3)
554 595
 		{
@@ -564,8 +605,9 @@  discard block
 block discarded – undo
564 605
 					foreach ($tables as $table)
565 606
 					{
566 607
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
567
-						if (trim($table) != '')
568
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
608
+						if (trim($table) != '') {
609
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
610
+						}
569 611
 					}
570 612
 				}
571 613
 
@@ -574,8 +616,9 @@  discard block
 block discarded – undo
574 616
 			// Table crashed.  Let's try to fix it.
575 617
 			elseif ($query_errno == 1016)
576 618
 			{
577
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
578
-					$fix_tables = array('`' . $match[1] . '`');
619
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
620
+									$fix_tables = array('`' . $match[1] . '`');
621
+				}
579 622
 			}
580 623
 			// Indexes crashed.  Should be easy to fix!
581 624
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -594,13 +637,15 @@  discard block
 block discarded – undo
594 637
 
595 638
 			// Make a note of the REPAIR...
596 639
 			cache_put_data('db_last_error', time(), 600);
597
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
598
-				updateSettingsFile(array('db_last_error' => time()));
640
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
641
+							updateSettingsFile(array('db_last_error' => time()));
642
+			}
599 643
 
600 644
 			// Attempt to find and repair the broken table.
601
-			foreach ($fix_tables as $table)
602
-				$smcFunc['db_query']('', "
645
+			foreach ($fix_tables as $table) {
646
+							$smcFunc['db_query']('', "
603 647
 					REPAIR TABLE $table", false, false);
648
+			}
604 649
 
605 650
 			// And send off an email!
606 651
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -609,11 +654,12 @@  discard block
 block discarded – undo
609 654
 
610 655
 			// Try the query again...?
611 656
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
612
-			if ($ret !== false)
613
-				return $ret;
657
+			if ($ret !== false) {
658
+							return $ret;
659
+			}
660
+		} else {
661
+					$modSettings['cache_enable'] = $old_cache;
614 662
 		}
615
-		else
616
-			$modSettings['cache_enable'] = $old_cache;
617 663
 
618 664
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
619 665
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -623,22 +669,25 @@  discard block
 block discarded – undo
623 669
 				// Are we in SSI mode?  If so try that username and password first
624 670
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
625 671
 				{
626
-					if (empty($db_persist))
627
-						$db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd);
628
-					else
629
-						$db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd);
672
+					if (empty($db_persist)) {
673
+											$db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd);
674
+					} else {
675
+											$db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd);
676
+					}
630 677
 				}
631 678
 				// Fall back to the regular username and password if need be
632 679
 				if (!$db_connection)
633 680
 				{
634
-					if (empty($db_persist))
635
-						$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
636
-					else
637
-						$db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
681
+					if (empty($db_persist)) {
682
+											$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
683
+					} else {
684
+											$db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
685
+					}
638 686
 				}
639 687
 
640
-				if (!$db_connection || !@mysql_select_db($db_name, $db_connection))
641
-					$db_connection = false;
688
+				if (!$db_connection || !@mysql_select_db($db_name, $db_connection)) {
689
+									$db_connection = false;
690
+				}
642 691
 			}
643 692
 
644 693
 			if ($db_connection)
@@ -649,24 +698,27 @@  discard block
 block discarded – undo
649 698
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
650 699
 
651 700
 					$new_errno = mysql_errno($db_connection);
652
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
653
-						break;
701
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
702
+											break;
703
+					}
654 704
 				}
655 705
 
656 706
 				// If it failed again, shucks to be you... we're not trying it over and over.
657
-				if ($ret !== false)
658
-					return $ret;
707
+				if ($ret !== false) {
708
+									return $ret;
709
+				}
659 710
 			}
660 711
 		}
661 712
 		// Are they out of space, perhaps?
662 713
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
663 714
 		{
664
-			if (!isset($txt))
665
-				$query_error .= ' - check database storage space.';
666
-			else
715
+			if (!isset($txt)) {
716
+							$query_error .= ' - check database storage space.';
717
+			} else
667 718
 			{
668
-				if (!isset($txt['mysql_error_space']))
669
-					loadLanguage('Errors');
719
+				if (!isset($txt['mysql_error_space'])) {
720
+									loadLanguage('Errors');
721
+				}
670 722
 
671 723
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
672 724
 			}
@@ -674,15 +726,17 @@  discard block
 block discarded – undo
674 726
 	}
675 727
 
676 728
 	// Nothing's defined yet... just die with it.
677
-	if (empty($context) || empty($txt))
678
-		die($query_error);
729
+	if (empty($context) || empty($txt)) {
730
+			die($query_error);
731
+	}
679 732
 
680 733
 	// Show an error message, if possible.
681 734
 	$context['error_title'] = $txt['database_error'];
682
-	if (allowedTo('admin_forum'))
683
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
684
-	else
685
-		$context['error_message'] = $txt['try_again'];
735
+	if (allowedTo('admin_forum')) {
736
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
737
+	} else {
738
+			$context['error_message'] = $txt['try_again'];
739
+	}
686 740
 
687 741
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
688 742
 	{
@@ -711,25 +765,28 @@  discard block
 block discarded – undo
711 765
 	$connection = $connection === null ? $db_connection : $connection;
712 766
 
713 767
 	// With nothing to insert, simply return.
714
-	if (empty($data))
715
-		return;
768
+	if (empty($data)) {
769
+			return;
770
+	}
716 771
 
717 772
 	// Replace the prefix holder with the actual prefix.
718 773
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
719 774
 
720 775
 	// Inserting data as a single row can be done as a single array.
721
-	if (!is_array($data[array_rand($data)]))
722
-		$data = array($data);
776
+	if (!is_array($data[array_rand($data)])) {
777
+			$data = array($data);
778
+	}
723 779
 
724 780
 	// Create the mold for a single row insert.
725 781
 	$insertData = '(';
726 782
 	foreach ($columns as $columnName => $type)
727 783
 	{
728 784
 		// Are we restricting the length?
729
-		if (strpos($type, 'string-') !== false)
730
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
731
-		else
732
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
785
+		if (strpos($type, 'string-') !== false) {
786
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
787
+		} else {
788
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
789
+		}
733 790
 	}
734 791
 	$insertData = substr($insertData, 0, -2) . ')';
735 792
 
@@ -738,8 +795,9 @@  discard block
 block discarded – undo
738 795
 
739 796
 	// Here's where the variables are injected to the query.
740 797
 	$insertRows = array();
741
-	foreach ($data as $dataRow)
742
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
798
+	foreach ($data as $dataRow) {
799
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
800
+	}
743 801
 
744 802
 	// Determine the method of insertion.
745 803
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -770,8 +828,9 @@  discard block
 block discarded – undo
770 828
  */
771 829
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
772 830
 {
773
-	if (empty($log_message))
774
-		$log_message = $error_message;
831
+	if (empty($log_message)) {
832
+			$log_message = $error_message;
833
+	}
775 834
 
776 835
 	foreach (debug_backtrace() as $step)
777 836
 	{
@@ -790,12 +849,14 @@  discard block
 block discarded – undo
790 849
 	}
791 850
 
792 851
 	// A special case - we want the file and line numbers for debugging.
793
-	if ($error_type == 'return')
794
-		return array($file, $line);
852
+	if ($error_type == 'return') {
853
+			return array($file, $line);
854
+	}
795 855
 
796 856
 	// Is always a critical error.
797
-	if (function_exists('log_error'))
798
-		log_error($log_message, 'critical', $file, $line);
857
+	if (function_exists('log_error')) {
858
+			log_error($log_message, 'critical', $file, $line);
859
+	}
799 860
 
800 861
 	if (function_exists('fatal_error'))
801 862
 	{
@@ -803,12 +864,12 @@  discard block
 block discarded – undo
803 864
 
804 865
 		// Cannot continue...
805 866
 		exit;
867
+	} elseif ($error_type) {
868
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
869
+	} else {
870
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
871
+	}
806 872
 	}
807
-	elseif ($error_type)
808
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
809
-	else
810
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
811
-}
812 873
 
813 874
 /**
814 875
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -825,10 +886,11 @@  discard block
 block discarded – undo
825 886
 		'\\' => '\\\\',
826 887
 	);
827 888
 
828
-	if ($translate_human_wildcards)
829
-		$replacements += array(
889
+	if ($translate_human_wildcards) {
890
+			$replacements += array(
830 891
 			'*' => '%',
831 892
 		);
893
+	}
832 894
 
833 895
 	return strtr($string, $replacements);
834 896
 }
Please login to merge, or discard this patch.
Sources/SearchAPI-Fulltext.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -206,12 +206,12 @@  discard block
 block discarded – undo
206 206
 
207 207
 		if (!empty($modSettings['search_simple_fulltext']))
208 208
 		{
209
-			if($smcFunc['db_title'] == "PostgreSQL")
209
+			if ($smcFunc['db_title'] == "PostgreSQL")
210 210
 			{
211 211
 				//we use the default language "default_text_search_config", otherwise we had to assgine the language here
212 212
 				//to_tsvector(body) -> to_tsvector($language,body) to_tsquery(...) -> to_tsquery($language,...)
213 213
 				$language_ftx = 'english';
214
-				$request = $smcFunc['db_query']('','
214
+				$request = $smcFunc['db_query']('', '
215 215
 					SHOW default_text_search_config',
216 216
 					array()
217 217
 				);
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 			// remove any indexed words that are used in the complex body search terms
236 236
 			$words['indexed_words'] = array_diff($words['indexed_words'], $words['complex_words']);
237 237
 
238
-			if($smcFunc['db_title'] == "PostgreSQL"){
238
+			if ($smcFunc['db_title'] == "PostgreSQL") {
239 239
 				$row = 0;
240 240
 				foreach ($words['indexed_words'] as $fulltextWord) {
241 241
 					$query_params['boolean_match'] .= ($row <> 0 ? '&' : '');
@@ -251,12 +251,12 @@  discard block
 block discarded – undo
251 251
 
252 252
 			// if we have bool terms to search, add them in
253 253
 			if ($query_params['boolean_match']) {
254
-				if($smcFunc['db_title'] == "PostgreSQL")
254
+				if ($smcFunc['db_title'] == "PostgreSQL")
255 255
 				{
256 256
 					//we use the default language "default_text_search_config", otherwise we had to assgine the language here
257 257
 					//to_tsvector(body) -> to_tsvector($language,body) to_tsquery(...) -> to_tsquery($language,...)
258 258
 					$language_ftx = 'english';
259
-					$request = $smcFunc['db_query']('','
259
+					$request = $smcFunc['db_query']('', '
260 260
 						SHOW default_text_search_config',
261 261
 						array()
262 262
 					);
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
 		}
277 277
 
278
-		$ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ( '
278
+		$ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ('
279 279
 			INSERT IGNORE INTO {db_prefix}' . $search_data['insert_into'] . '
280 280
 				(' . implode(', ', array_keys($query_select)) . ')') : '') . '
281 281
 			SELECT ' . implode(', ', $query_select) . '
Please login to merge, or discard this patch.
Braces   +44 added lines, -34 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * 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,41 +168,50 @@  discard block
 block discarded – undo
166 168
 		$query_where = array();
167 169
 		$query_params = $search_data['params'];
168 170
 
169
-		if ($query_params['id_search'])
170
-			$query_select['id_search'] = '{int:id_search}';
171
+		if ($query_params['id_search']) {
172
+					$query_select['id_search'] = '{int:id_search}';
173
+		}
171 174
 
172 175
 		$count = 0;
173
-		if (empty($modSettings['search_simple_fulltext']))
174
-			foreach ($words['words'] as $regularWord)
176
+		if (empty($modSettings['search_simple_fulltext'])) {
177
+					foreach ($words['words'] as $regularWord)
175 178
 			{
176 179
 				$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 . '}';
180
+		}
177 181
 				$query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]';
178 182
 			}
179 183
 
180
-		if ($query_params['user_query'])
181
-			$query_where[] = '{raw:user_query}';
182
-		if ($query_params['board_query'])
183
-			$query_where[] = 'm.id_board {raw:board_query}';
184
+		if ($query_params['user_query']) {
185
+					$query_where[] = '{raw:user_query}';
186
+		}
187
+		if ($query_params['board_query']) {
188
+					$query_where[] = 'm.id_board {raw:board_query}';
189
+		}
184 190
 
185
-		if ($query_params['topic'])
186
-			$query_where[] = 'm.id_topic = {int:topic}';
187
-		if ($query_params['min_msg_id'])
188
-			$query_where[] = 'm.id_msg >= {int:min_msg_id}';
189
-		if ($query_params['max_msg_id'])
190
-			$query_where[] = 'm.id_msg <= {int:max_msg_id}';
191
+		if ($query_params['topic']) {
192
+					$query_where[] = 'm.id_topic = {int:topic}';
193
+		}
194
+		if ($query_params['min_msg_id']) {
195
+					$query_where[] = 'm.id_msg >= {int:min_msg_id}';
196
+		}
197
+		if ($query_params['max_msg_id']) {
198
+					$query_where[] = 'm.id_msg <= {int:max_msg_id}';
199
+		}
191 200
 
192 201
 		$count = 0;
193
-		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index']))
194
-			foreach ($query_params['excluded_phrases'] as $phrase)
202
+		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) {
203
+					foreach ($query_params['excluded_phrases'] as $phrase)
195 204
 			{
196 205
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}';
206
+		}
197 207
 				$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), '\\\'') . '[[:>:]]';
198 208
 			}
199 209
 		$count = 0;
200
-		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index']))
201
-			foreach ($query_params['excluded_subject_words'] as $excludedWord)
210
+		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) {
211
+					foreach ($query_params['excluded_subject_words'] as $excludedWord)
202 212
 			{
203 213
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}';
214
+		}
204 215
 				$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), '\\\'') . '[[:>:]]';
205 216
 			}
206 217
 
@@ -223,12 +234,11 @@  discard block
 block discarded – undo
223 234
 				}
224 235
 				$query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:body_match})';
225 236
 				$query_params['language_ftx'] = $language_ftx;
237
+			} else {
238
+							$query_where[] = 'MATCH (body) AGAINST ({string:body_match})';
226 239
 			}
227
-			else
228
-				$query_where[] = 'MATCH (body) AGAINST ({string:body_match})';
229 240
 			$query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words']));
230
-		}
231
-		else
241
+		} else
232 242
 		{
233 243
 			$query_params['boolean_match'] = '';
234 244
 
@@ -242,10 +252,10 @@  discard block
 block discarded – undo
242 252
 					$query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' ';
243 253
 					$row++;
244 254
 				}
245
-			}
246
-			else
247
-				foreach ($words['indexed_words'] as $fulltextWord)
255
+			} else {
256
+							foreach ($words['indexed_words'] as $fulltextWord)
248 257
 					$query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' ';
258
+			}
249 259
 
250 260
 			$query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1);
251 261
 
@@ -268,9 +278,9 @@  discard block
 block discarded – undo
268 278
 					}
269 279
 					$query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:boolean_match})';
270 280
 					$query_params['language_ftx'] = $language_ftx;
281
+				} else {
282
+									$query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)';
271 283
 				}
272
-				else
273
-					$query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)';
274 284
 			}
275 285
 
276 286
 		}
Please login to merge, or discard this patch.
Sources/ManageSearchEngines.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 					'value' => $txt['spider_name'],
240 240
 				),
241 241
 				'data' => array(
242
-					'function' => function ($rowData) use ($smcFunc, $scripturl)
242
+					'function' => function($rowData) use ($smcFunc, $scripturl)
243 243
 					{
244 244
 						return sprintf('<a href="%1$s?action=admin;area=sengines;sa=editspiders;sid=%2$d">%3$s</a>', $scripturl, $rowData['id_spider'], $smcFunc['htmlspecialchars']($rowData['spider_name']));
245 245
 					},
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 					'value' => $txt['spider_last_seen'],
255 255
 				),
256 256
 				'data' => array(
257
-					'function' => function ($rowData) use ($context, $txt)
257
+					'function' => function($rowData) use ($context, $txt)
258 258
 					{
259 259
 						return isset($context['spider_last_seen'][$rowData['id_spider']]) ? timeformat($context['spider_last_seen'][$rowData['id_spider']]) : $txt['spider_last_never'];
260 260
 					},
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
 
691 691
 		if (!empty($_POST['delete_entries']) && isset($_POST['older']))
692 692
 		{
693
-			$deleteTime = time() - (((int)$_POST['older']) * 24 * 60 * 60);
693
+			$deleteTime = time() - (((int) $_POST['older']) * 24 * 60 * 60);
694 694
 
695 695
 			// Delete the entires.
696 696
 			$smcFunc['db_query']('', '
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
 					'value' => $txt['spider_time'],
743 743
 				),
744 744
 				'data' => array(
745
-					'function' => function ($rowData)
745
+					'function' => function($rowData)
746 746
 					{
747 747
 						return timeformat($rowData['log_time']);
748 748
 					},
Please login to merge, or discard this patch.
Braces   +109 added lines, -77 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Entry point for this section.
@@ -38,8 +39,7 @@  discard block
 block discarded – undo
38 39
 			'stats' => 'SpiderStats',
39 40
 		);
40 41
 		$default = 'stats';
41
-	}
42
-	else
42
+	} else
43 43
 	{
44 44
 		$subActions = array(
45 45
 			'settings' => 'ManageSearchEngineSettings',
@@ -90,11 +90,12 @@  discard block
 block discarded – undo
90 90
 		{
91 91
 			disabledState = document.getElementById(\'spider_mode\').value == 0;';
92 92
 
93
-	foreach ($config_vars as $variable)
94
-		if ($variable[1] != 'spider_mode')
93
+	foreach ($config_vars as $variable) {
94
+			if ($variable[1] != 'spider_mode')
95 95
 			$javascript_function .= '
96 96
 			if (document.getElementById(\'' . $variable[1] . '\'))
97 97
 				document.getElementById(\'' . $variable[1] . '\').disabled = disabledState;';
98
+	}
98 99
 
99 100
 	$javascript_function .= '
100 101
 		}
@@ -102,8 +103,9 @@  discard block
 block discarded – undo
102 103
 
103 104
 	call_integration_hook('integrate_modify_search_engine_settings', array(&$config_vars));
104 105
 
105
-	if ($return_config)
106
-		return $config_vars;
106
+	if ($return_config) {
107
+			return $config_vars;
108
+	}
107 109
 
108 110
 	// We need to load the groups for the spider group thingy.
109 111
 	$request = $smcFunc['db_query']('', '
@@ -116,13 +118,15 @@  discard block
 block discarded – undo
116 118
 			'moderator_group' => 3,
117 119
 		)
118 120
 	);
119
-	while ($row = $smcFunc['db_fetch_assoc']($request))
120
-		$config_vars['spider_group'][2][$row['id_group']] = $row['group_name'];
121
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
122
+			$config_vars['spider_group'][2][$row['id_group']] = $row['group_name'];
123
+	}
121 124
 	$smcFunc['db_free_result']($request);
122 125
 
123 126
 	// Make sure it's valid - note that regular members are given id_group = 1 which is reversed in Load.php - no admins here!
124
-	if (isset($_POST['spider_group']) && !isset($config_vars['spider_group'][2][$_POST['spider_group']]))
125
-		$_POST['spider_group'] = 0;
127
+	if (isset($_POST['spider_group']) && !isset($config_vars['spider_group'][2][$_POST['spider_group']])) {
128
+			$_POST['spider_group'] = 0;
129
+	}
126 130
 
127 131
 	// We'll want this for our easy save.
128 132
 	require_once($sourcedir . '/ManageServer.php');
@@ -166,8 +170,9 @@  discard block
 block discarded – undo
166 170
 	}
167 171
 
168 172
 	// Are we adding a new one?
169
-	if (!empty($_POST['addSpider']))
170
-		return EditSpider();
173
+	if (!empty($_POST['addSpider'])) {
174
+			return EditSpider();
175
+	}
171 176
 	// User pressed the 'remove selection button'.
172 177
 	elseif (!empty($_POST['removeSpiders']) && !empty($_POST['remove']) && is_array($_POST['remove']))
173 178
 	{
@@ -175,8 +180,9 @@  discard block
 block discarded – undo
175 180
 		validateToken('admin-ser');
176 181
 
177 182
 		// Make sure every entry is a proper integer.
178
-		foreach ($_POST['remove'] as $index => $spider_id)
179
-			$_POST['remove'][(int) $index] = (int) $spider_id;
183
+		foreach ($_POST['remove'] as $index => $spider_id) {
184
+					$_POST['remove'][(int) $index] = (int) $spider_id;
185
+		}
180 186
 
181 187
 		// Delete them all!
182 188
 		$smcFunc['db_query']('', '
@@ -215,8 +221,9 @@  discard block
 block discarded – undo
215 221
 	);
216 222
 
217 223
 	$context['spider_last_seen'] = array();
218
-	while ($row = $smcFunc['db_fetch_assoc']($request))
219
-		$context['spider_last_seen'][$row['id_spider']] = $row['last_seen_time'];
224
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
225
+			$context['spider_last_seen'][$row['id_spider']] = $row['last_seen_time'];
226
+	}
220 227
 	$smcFunc['db_free_result']($request);
221 228
 
222 229
 	createToken('admin-ser');
@@ -346,8 +353,9 @@  discard block
 block discarded – undo
346 353
 		)
347 354
 	);
348 355
 	$spiders = array();
349
-	while ($row = $smcFunc['db_fetch_assoc']($request))
350
-		$spiders[$row['id_spider']] = $row;
356
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
357
+			$spiders[$row['id_spider']] = $row;
358
+	}
351 359
 	$smcFunc['db_free_result']($request);
352 360
 
353 361
 	return $spiders;
@@ -397,14 +405,15 @@  discard block
 block discarded – undo
397 405
 		foreach ($ip_sets as $set)
398 406
 		{
399 407
 			$test = ip2range(trim($set));
400
-			if (!empty($test))
401
-				$ips[] = $set;
408
+			if (!empty($test)) {
409
+							$ips[] = $set;
410
+			}
402 411
 		}
403 412
 		$ips = implode(',', $ips);
404 413
 
405 414
 		// Goes in as it is...
406
-		if ($context['id_spider'])
407
-			$smcFunc['db_query']('', '
415
+		if ($context['id_spider']) {
416
+					$smcFunc['db_query']('', '
408 417
 				UPDATE {db_prefix}spiders
409 418
 				SET spider_name = {string:spider_name}, user_agent = {string:spider_agent},
410 419
 					ip_info = {string:ip_info}
@@ -416,8 +425,8 @@  discard block
 block discarded – undo
416 425
 					'ip_info' => $ips,
417 426
 				)
418 427
 			);
419
-		else
420
-			$smcFunc['db_insert']('insert',
428
+		} else {
429
+					$smcFunc['db_insert']('insert',
421 430
 				'{db_prefix}spiders',
422 431
 				array(
423 432
 					'spider_name' => 'string', 'user_agent' => 'string', 'ip_info' => 'string',
@@ -427,6 +436,7 @@  discard block
 block discarded – undo
427 436
 				),
428 437
 				array('id_spider')
429 438
 			);
439
+		}
430 440
 
431 441
 
432 442
 		cache_put_data('spider_search', null);
@@ -454,13 +464,14 @@  discard block
 block discarded – undo
454 464
 				'current_spider' => $context['id_spider'],
455 465
 			)
456 466
 		);
457
-		if ($row = $smcFunc['db_fetch_assoc']($request))
458
-			$context['spider'] = array(
467
+		if ($row = $smcFunc['db_fetch_assoc']($request)) {
468
+					$context['spider'] = array(
459 469
 				'id' => $row['id_spider'],
460 470
 				'name' => $row['spider_name'],
461 471
 				'agent' => $row['user_agent'],
462 472
 				'ip_info' => $row['ip_info'],
463 473
 			);
474
+		}
464 475
 		$smcFunc['db_free_result']($request);
465 476
 	}
466 477
 
@@ -477,8 +488,9 @@  discard block
 block discarded – undo
477 488
 {
478 489
 	global $modSettings, $smcFunc;
479 490
 
480
-	if (isset($_SESSION['id_robot']))
481
-		unset($_SESSION['id_robot']);
491
+	if (isset($_SESSION['id_robot'])) {
492
+			unset($_SESSION['id_robot']);
493
+	}
482 494
 	$_SESSION['robot_check'] = time();
483 495
 
484 496
 	// We cache the spider data for ten minutes if we can.
@@ -492,15 +504,17 @@  discard block
 block discarded – undo
492 504
 			)
493 505
 		);
494 506
 		$spider_data = array();
495
-		while ($row = $smcFunc['db_fetch_assoc']($request))
496
-			$spider_data[] = $row;
507
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
508
+					$spider_data[] = $row;
509
+		}
497 510
 		$smcFunc['db_free_result']($request);
498 511
 
499 512
 		cache_put_data('spider_search', $spider_data, 600);
500 513
 	}
501 514
 
502
-	if (empty($spider_data))
503
-		return false;
515
+	if (empty($spider_data)) {
516
+			return false;
517
+	}
504 518
 
505 519
 	// Only do these bits once.
506 520
 	$ci_user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
@@ -508,33 +522,38 @@  discard block
 block discarded – undo
508 522
 	foreach ($spider_data as $spider)
509 523
 	{
510 524
 		// User agent is easy.
511
-		if (!empty($spider['user_agent']) && strpos($ci_user_agent, strtolower($spider['user_agent'])) !== false)
512
-			$_SESSION['id_robot'] = $spider['id_spider'];
525
+		if (!empty($spider['user_agent']) && strpos($ci_user_agent, strtolower($spider['user_agent'])) !== false) {
526
+					$_SESSION['id_robot'] = $spider['id_spider'];
527
+		}
513 528
 		// IP stuff is harder.
514 529
 		elseif ($_SERVER['REMOTE_ADDR'])
515 530
 		{
516 531
 			$ips = explode(',', $spider['ip_info']);
517 532
 			foreach ($ips as $ip)
518 533
 			{
519
-				if ($ip === '')
520
-					continue;
534
+				if ($ip === '') {
535
+									continue;
536
+				}
521 537
 
522 538
 				$ip = ip2range($ip);
523 539
 				if (!empty($ip))
524 540
 				{
525
-					if (inet_ptod($ip['low']) <= inet_ptod($_SERVER['REMOTE_ADDR']) && inet_ptod($ip['high']) >= inet_ptod($_SERVER['REMOTE_ADDR']))
526
-						$_SESSION['id_robot'] = $spider['id_spider'];
541
+					if (inet_ptod($ip['low']) <= inet_ptod($_SERVER['REMOTE_ADDR']) && inet_ptod($ip['high']) >= inet_ptod($_SERVER['REMOTE_ADDR'])) {
542
+											$_SESSION['id_robot'] = $spider['id_spider'];
543
+					}
527 544
 				}
528 545
 			}
529 546
 		}
530 547
 
531
-		if (isset($_SESSION['id_robot']))
532
-			break;
548
+		if (isset($_SESSION['id_robot'])) {
549
+					break;
550
+		}
533 551
 	}
534 552
 
535 553
 	// If this is low server tracking then log the spider here as opposed to the main logging function.
536
-	if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] == 1 && !empty($_SESSION['id_robot']))
537
-		logSpider();
554
+	if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] == 1 && !empty($_SESSION['id_robot'])) {
555
+			logSpider();
556
+	}
538 557
 
539 558
 	return !empty($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
540 559
 }
@@ -548,8 +567,9 @@  discard block
 block discarded – undo
548 567
 {
549 568
 	global $smcFunc, $modSettings, $context;
550 569
 
551
-	if (empty($modSettings['spider_mode']) || empty($_SESSION['id_robot']))
552
-		return;
570
+	if (empty($modSettings['spider_mode']) || empty($_SESSION['id_robot'])) {
571
+			return;
572
+	}
553 573
 
554 574
 	// Attempt to update today's entry.
555 575
 	if ($modSettings['spider_mode'] == 1)
@@ -590,9 +610,9 @@  discard block
 block discarded – undo
590 610
 			$url = $_GET + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
591 611
 			unset($url['sesc'], $url[$context['session_var']]);
592 612
 			$url = json_encode($url);
613
+		} else {
614
+					$url = '';
593 615
 		}
594
-		else
595
-			$url = '';
596 616
 
597 617
 		$smcFunc['db_insert']('insert',
598 618
 			'{db_prefix}log_spider_hits',
@@ -620,12 +640,14 @@  discard block
 block discarded – undo
620 640
 		)
621 641
 	);
622 642
 	$spider_hits = array();
623
-	while ($row = $smcFunc['db_fetch_assoc']($request))
624
-		$spider_hits[] = $row;
643
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
644
+			$spider_hits[] = $row;
645
+	}
625 646
 	$smcFunc['db_free_result']($request);
626 647
 
627
-	if (empty($spider_hits))
628
-		return;
648
+	if (empty($spider_hits)) {
649
+			return;
650
+	}
629 651
 
630 652
 	// Attempt to update the master data.
631 653
 	$stat_inserts = array();
@@ -646,18 +668,20 @@  discard block
 block discarded – undo
646 668
 				'hits' => $stat['num_hits'],
647 669
 			)
648 670
 		);
649
-		if ($smcFunc['db_affected_rows']() == 0)
650
-			$stat_inserts[] = array($date, $stat['id_spider'], $stat['num_hits'], $stat['last_seen']);
671
+		if ($smcFunc['db_affected_rows']() == 0) {
672
+					$stat_inserts[] = array($date, $stat['id_spider'], $stat['num_hits'], $stat['last_seen']);
673
+		}
651 674
 	}
652 675
 
653 676
 	// New stats?
654
-	if (!empty($stat_inserts))
655
-		$smcFunc['db_insert']('ignore',
677
+	if (!empty($stat_inserts)) {
678
+			$smcFunc['db_insert']('ignore',
656 679
 			'{db_prefix}log_spider_stats',
657 680
 			array('stat_date' => 'date', 'id_spider' => 'int', 'page_hits' => 'int', 'last_seen' => 'int'),
658 681
 			$stat_inserts,
659 682
 			array('stat_date', 'id_spider')
660 683
 		);
684
+	}
661 685
 
662 686
 	// All processed.
663 687
 	$smcFunc['db_query']('', '
@@ -700,8 +724,7 @@  discard block
 block discarded – undo
700 724
 					'delete_period' => $deleteTime,
701 725
 				)
702 726
 			);
703
-		}
704
-		else
727
+		} else
705 728
 		{
706 729
 			// Deleting all of them
707 730
 			$smcFunc['db_query']('', '
@@ -791,10 +814,11 @@  discard block
 block discarded – undo
791 814
 		foreach ($context['spider_logs']['rows'] as $k => $row)
792 815
 		{
793 816
 			// Feature disabled?
794
-			if (empty($row['data']['viewing']['value']) && isset($modSettings['spider_mode']) && $modSettings['spider_mode'] < 3)
795
-				$context['spider_logs']['rows'][$k]['viewing']['value'] = '<em>' . $txt['spider_disabled'] . '</em>';
796
-			else
797
-				$urls[$k] = array($row['data']['viewing']['value'], -1);
817
+			if (empty($row['data']['viewing']['value']) && isset($modSettings['spider_mode']) && $modSettings['spider_mode'] < 3) {
818
+							$context['spider_logs']['rows'][$k]['viewing']['value'] = '<em>' . $txt['spider_disabled'] . '</em>';
819
+			} else {
820
+							$urls[$k] = array($row['data']['viewing']['value'], -1);
821
+			}
798 822
 		}
799 823
 
800 824
 		// Now stick in the new URLs.
@@ -836,8 +860,9 @@  discard block
 block discarded – undo
836 860
 		)
837 861
 	);
838 862
 	$spider_logs = array();
839
-	while ($row = $smcFunc['db_fetch_assoc']($request))
840
-		$spider_logs[] = $row;
863
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
864
+			$spider_logs[] = $row;
865
+	}
841 866
 	$smcFunc['db_free_result']($request);
842 867
 
843 868
 	return $spider_logs;
@@ -913,14 +938,18 @@  discard block
 block discarded – undo
913 938
 
914 939
 	// Prepare the dates for the drop down.
915 940
 	$date_choices = array();
916
-	for ($y = $min_year; $y <= $max_year; $y++)
917
-		for ($m = 1; $m <= 12; $m++)
941
+	for ($y = $min_year; $y <= $max_year; $y++) {
942
+			for ($m = 1;
943
+	}
944
+	$m <= 12; $m++)
918 945
 		{
919 946
 			// This doesn't count?
920
-			if ($y == $min_year && $m < $min_month)
921
-				continue;
922
-			if ($y == $max_year && $m > $max_month)
923
-				break;
947
+			if ($y == $min_year && $m < $min_month) {
948
+							continue;
949
+			}
950
+			if ($y == $max_year && $m > $max_month) {
951
+							break;
952
+			}
924 953
 
925 954
 			$date_choices[$y . $m] = $txt['months_short'][$m] . ' ' . $y;
926 955
 		}
@@ -933,13 +962,14 @@  discard block
 block discarded – undo
933 962
 		' . $txt['spider_stats_select_month'] . ':
934 963
 		<select name="new_date" onchange="document.spider_stat_list.submit();">';
935 964
 
936
-	if (empty($date_choices))
937
-		$date_select .= '
965
+	if (empty($date_choices)) {
966
+			$date_select .= '
938 967
 			<option></option>';
939
-	else
940
-		foreach ($date_choices as $id => $text)
968
+	} else {
969
+			foreach ($date_choices as $id => $text)
941 970
 			$date_select .= '
942 971
 			<option value="' . $id . '"' . ($current_date == $id ? ' selected' : '') . '>' . $text . '</option>';
972
+	}
943 973
 
944 974
 	$date_select .= '
945 975
 		</select>
@@ -1063,8 +1093,9 @@  discard block
 block discarded – undo
1063 1093
 		)
1064 1094
 	);
1065 1095
 	$spider_stats = array();
1066
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1067
-		$spider_stats[] = $row;
1096
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1097
+			$spider_stats[] = $row;
1098
+	}
1068 1099
 	$smcFunc['db_free_result']($request);
1069 1100
 
1070 1101
 	return $spider_stats;
@@ -1105,8 +1136,9 @@  discard block
 block discarded – undo
1105 1136
 		array()
1106 1137
 	);
1107 1138
 	$spiders = array();
1108
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1109
-		$spiders[$row['id_spider']] = $row['spider_name'];
1139
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1140
+			$spiders[$row['id_spider']] = $row['spider_name'];
1141
+	}
1110 1142
 	$smcFunc['db_free_result']($request);
1111 1143
 
1112 1144
 	updateSettings(array('spider_name_cache' => json_encode($spiders)));
Please login to merge, or discard this patch.
Sources/Security.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	require_once($sourcedir . '/Subs-Auth.php');
53 53
 
54 54
 	// Posting the password... check it.
55
-	if (isset($_POST[$type. '_pass']))
55
+	if (isset($_POST[$type . '_pass']))
56 56
 	{
57 57
 		// Check to ensure we're forcing SSL for authentication
58 58
 		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 		{
180 180
 			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip'])
181 181
 				continue;
182
-			$ban_query[] = ' {inet:'.$ip_number.'} BETWEEN bi.ip_low and bi.ip_high';
182
+			$ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high';
183 183
 			$ban_query_vars[$ip_number] = $user_info[$ip_number];
184 184
 			// IP was valid, maybe there's also a hostname...
185 185
 			if (empty($modSettings['disableHostnameLookup']) && $user_info[$ip_number] != 'unknown')
@@ -187,8 +187,8 @@  discard block
 block discarded – undo
187 187
 				$hostname = host_from_ip($user_info[$ip_number]);
188 188
 				if (strlen($hostname) > 0)
189 189
 				{
190
-					$ban_query[] = '({string:hostname'.$ip_number.'} LIKE bi.hostname)';
191
-					$ban_query_vars['hostname'.$ip_number] = $hostname;
190
+					$ban_query[] = '({string:hostname' . $ip_number . '} LIKE bi.hostname)';
191
+					$ban_query_vars['hostname' . $ip_number] = $hostname;
192 192
 				}
193 193
 			}
194 194
 		}
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
912 912
 		return true;
913 913
 
914 914
 	// Let's ensure this is an array.
915
-	$permission = (array)$permission;
915
+	$permission = (array) $permission;
916 916
 
917 917
 	// Are we checking the _current_ board, or some other boards?
918 918
 	if ($boards === null)
Please login to merge, or discard this patch.
Braces   +263 added lines, -203 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
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
  * Check if the user is who he/she says he is
@@ -42,12 +43,14 @@  discard block
 block discarded – undo
42 43
 	$refreshTime = isset($_GET['xml']) ? 4200 : 3600;
43 44
 
44 45
 	// Is the security option off?
45
-	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')]))
46
-		return;
46
+	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) {
47
+			return;
48
+	}
47 49
 
48 50
 	// Or are they already logged in?, Moderator or admin session is need for this area
49
-	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time()))
50
-		return;
51
+	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) {
52
+			return;
53
+	}
51 54
 
52 55
 	require_once($sourcedir . '/Subs-Auth.php');
53 56
 
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 	if (isset($_POST[$type. '_pass']))
56 59
 	{
57 60
 		// Check to ensure we're forcing SSL for authentication
58
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
59
-			fatal_lang_error('login_ssl_required');
61
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
62
+					fatal_lang_error('login_ssl_required');
63
+		}
60 64
 
61 65
 		checkSession();
62 66
 
@@ -72,17 +76,19 @@  discard block
 block discarded – undo
72 76
 	}
73 77
 
74 78
 	// Better be sure to remember the real referer
75
-	if (empty($_SESSION['request_referer']))
76
-		$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
77
-	elseif (empty($_POST))
78
-		unset($_SESSION['request_referer']);
79
+	if (empty($_SESSION['request_referer'])) {
80
+			$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
81
+	} elseif (empty($_POST)) {
82
+			unset($_SESSION['request_referer']);
83
+	}
79 84
 
80 85
 	// Need to type in a password for that, man.
81
-	if (!isset($_GET['xml']))
82
-		adminLogin($type);
83
-	else
84
-		return 'session_verify_fail';
85
-}
86
+	if (!isset($_GET['xml'])) {
87
+			adminLogin($type);
88
+	} else {
89
+			return 'session_verify_fail';
90
+	}
91
+	}
86 92
 
87 93
 /**
88 94
  * Require a user who is logged in. (not a guest.)
@@ -96,25 +102,30 @@  discard block
 block discarded – undo
96 102
 	global $user_info, $txt, $context, $scripturl, $modSettings;
97 103
 
98 104
 	// Luckily, this person isn't a guest.
99
-	if (!$user_info['is_guest'])
100
-		return;
105
+	if (!$user_info['is_guest']) {
106
+			return;
107
+	}
101 108
 
102 109
 	// Log what they were trying to do didn't work)
103
-	if (!empty($modSettings['who_enabled']))
104
-		$_GET['error'] = 'guest_login';
110
+	if (!empty($modSettings['who_enabled'])) {
111
+			$_GET['error'] = 'guest_login';
112
+	}
105 113
 	writeLog(true);
106 114
 
107 115
 	// Just die.
108
-	if (isset($_REQUEST['xml']))
109
-		obExit(false);
116
+	if (isset($_REQUEST['xml'])) {
117
+			obExit(false);
118
+	}
110 119
 
111 120
 	// Attempt to detect if they came from dlattach.
112
-	if (SMF != 'SSI' && empty($context['theme_loaded']))
113
-		loadTheme();
121
+	if (SMF != 'SSI' && empty($context['theme_loaded'])) {
122
+			loadTheme();
123
+	}
114 124
 
115 125
 	// Never redirect to an attachment
116
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
117
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
126
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
127
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
128
+	}
118 129
 
119 130
 	// Load the Login template and language file.
120 131
 	loadLanguage('Login');
@@ -124,8 +135,7 @@  discard block
 block discarded – undo
124 135
 	{
125 136
 		$_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING'];
126 137
 		redirectexit('action=login');
127
-	}
128
-	else
138
+	} else
129 139
 	{
130 140
 		loadTemplate('Login');
131 141
 		$context['sub_template'] = 'kick_guest';
@@ -155,8 +165,9 @@  discard block
 block discarded – undo
155 165
 	global $sourcedir, $cookiename, $user_settings, $smcFunc;
156 166
 
157 167
 	// You cannot be banned if you are an admin - doesn't help if you log out.
158
-	if ($user_info['is_admin'])
159
-		return;
168
+	if ($user_info['is_admin']) {
169
+			return;
170
+	}
160 171
 
161 172
 	// Only check the ban every so often. (to reduce load.)
162 173
 	if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email']))
@@ -177,8 +188,9 @@  discard block
 block discarded – undo
177 188
 		// Check both IP addresses.
178 189
 		foreach (array('ip', 'ip2') as $ip_number)
179 190
 		{
180
-			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip'])
181
-				continue;
191
+			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) {
192
+							continue;
193
+			}
182 194
 			$ban_query[] = ' {inet:'.$ip_number.'} BETWEEN bi.ip_low and bi.ip_high';
183 195
 			$ban_query_vars[$ip_number] = $user_info[$ip_number];
184 196
 			// IP was valid, maybe there's also a hostname...
@@ -228,24 +240,28 @@  discard block
 block discarded – undo
228 240
 			// Store every type of ban that applies to you in your session.
229 241
 			while ($row = $smcFunc['db_fetch_assoc']($request))
230 242
 			{
231
-				foreach ($restrictions as $restriction)
232
-					if (!empty($row[$restriction]))
243
+				foreach ($restrictions as $restriction) {
244
+									if (!empty($row[$restriction]))
233 245
 					{
234 246
 						$_SESSION['ban'][$restriction]['reason'] = $row['reason'];
247
+				}
235 248
 						$_SESSION['ban'][$restriction]['ids'][] = $row['id_ban'];
236
-						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time'])))
237
-							$_SESSION['ban']['expire_time'] = $row['expire_time'];
249
+						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) {
250
+													$_SESSION['ban']['expire_time'] = $row['expire_time'];
251
+						}
238 252
 
239
-						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email']))
240
-							$flag_is_activated = true;
253
+						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) {
254
+													$flag_is_activated = true;
255
+						}
241 256
 					}
242 257
 			}
243 258
 			$smcFunc['db_free_result']($request);
244 259
 		}
245 260
 
246 261
 		// Mark the cannot_access and cannot_post bans as being 'hit'.
247
-		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login']))
248
-			log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
262
+		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) {
263
+					log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
264
+		}
249 265
 
250 266
 		// If for whatever reason the is_activated flag seems wrong, do a little work to clear it up.
251 267
 		if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated)
@@ -260,8 +276,9 @@  discard block
 block discarded – undo
260 276
 	if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_']))
261 277
 	{
262 278
 		$bans = explode(',', $_COOKIE[$cookiename . '_']);
263
-		foreach ($bans as $key => $value)
264
-			$bans[$key] = (int) $value;
279
+		foreach ($bans as $key => $value) {
280
+					$bans[$key] = (int) $value;
281
+		}
265 282
 		$request = $smcFunc['db_query']('', '
266 283
 			SELECT bi.id_ban, bg.reason
267 284
 			FROM {db_prefix}ban_items AS bi
@@ -297,14 +314,15 @@  discard block
 block discarded – undo
297 314
 	if (isset($_SESSION['ban']['cannot_access']))
298 315
 	{
299 316
 		// We don't wanna see you!
300
-		if (!$user_info['is_guest'])
301
-			$smcFunc['db_query']('', '
317
+		if (!$user_info['is_guest']) {
318
+					$smcFunc['db_query']('', '
302 319
 				DELETE FROM {db_prefix}log_online
303 320
 				WHERE id_member = {int:current_member}',
304 321
 				array(
305 322
 					'current_member' => $user_info['id'],
306 323
 				)
307 324
 			);
325
+		}
308 326
 
309 327
 		// 'Log' the user out.  Can't have any funny business... (save the name!)
310 328
 		$old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
@@ -390,9 +408,10 @@  discard block
 block discarded – undo
390 408
 	}
391 409
 
392 410
 	// Fix up the banning permissions.
393
-	if (isset($user_info['permissions']))
394
-		banPermissions();
395
-}
411
+	if (isset($user_info['permissions'])) {
412
+			banPermissions();
413
+	}
414
+	}
396 415
 
397 416
 /**
398 417
  * Fix permissions according to ban status.
@@ -403,8 +422,9 @@  discard block
 block discarded – undo
403 422
 	global $user_info, $sourcedir, $modSettings, $context;
404 423
 
405 424
 	// Somehow they got here, at least take away all permissions...
406
-	if (isset($_SESSION['ban']['cannot_access']))
407
-		$user_info['permissions'] = array();
425
+	if (isset($_SESSION['ban']['cannot_access'])) {
426
+			$user_info['permissions'] = array();
427
+	}
408 428
 	// Okay, well, you can watch, but don't touch a thing.
409 429
 	elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning']))
410 430
 	{
@@ -446,44 +466,45 @@  discard block
 block discarded – undo
446 466
 		call_integration_hook('integrate_warn_permissions', array(&$permission_change));
447 467
 		foreach ($permission_change as $old => $new)
448 468
 		{
449
-			if (!in_array($old, $user_info['permissions']))
450
-				unset($permission_change[$old]);
451
-			else
452
-				$user_info['permissions'][] = $new;
469
+			if (!in_array($old, $user_info['permissions'])) {
470
+							unset($permission_change[$old]);
471
+			} else {
472
+							$user_info['permissions'][] = $new;
473
+			}
453 474
 		}
454 475
 		$user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change));
455 476
 	}
456 477
 
457 478
 	// @todo Find a better place to call this? Needs to be after permissions loaded!
458 479
 	// Finally, some bits we cache in the session because it saves queries.
459
-	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id'])
460
-		$user_info['mod_cache'] = $_SESSION['mc'];
461
-	else
480
+	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) {
481
+			$user_info['mod_cache'] = $_SESSION['mc'];
482
+	} else
462 483
 	{
463 484
 		require_once($sourcedir . '/Subs-Auth.php');
464 485
 		rebuildModCache();
465 486
 	}
466 487
 
467 488
 	// Now that we have the mod cache taken care of lets setup a cache for the number of mod reports still open
468
-	if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id'])
469
-		$context['open_mod_reports'] = $_SESSION['rc']['reports'];
470
-	elseif ($_SESSION['mc']['bq'] != '0=1')
489
+	if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id']) {
490
+			$context['open_mod_reports'] = $_SESSION['rc']['reports'];
491
+	} elseif ($_SESSION['mc']['bq'] != '0=1')
471 492
 	{
472 493
 		require_once($sourcedir . '/Subs-ReportedContent.php');
473 494
 		recountOpenReports('posts');
495
+	} else {
496
+			$context['open_mod_reports'] = 0;
474 497
 	}
475
-	else
476
-		$context['open_mod_reports'] = 0;
477 498
 
478
-	if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id'])
479
-		$context['open_member_reports'] = !empty($_SESSION['rc']['member_reports']) ? $_SESSION['rc']['member_reports'] : 0;
480
-	elseif (allowedTo('moderate_forum'))
499
+	if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id']) {
500
+			$context['open_member_reports'] = !empty($_SESSION['rc']['member_reports']) ? $_SESSION['rc']['member_reports'] : 0;
501
+	} elseif (allowedTo('moderate_forum'))
481 502
 	{
482 503
 		require_once($sourcedir . '/Subs-ReportedContent.php');
483 504
 		recountOpenReports('members');
505
+	} else {
506
+			$context['open_member_reports'] = 0;
484 507
 	}
485
-	else
486
-		$context['open_member_reports'] = 0;
487 508
 
488 509
 }
489 510
 
@@ -500,8 +521,9 @@  discard block
 block discarded – undo
500 521
 	global $user_info, $smcFunc;
501 522
 
502 523
 	// Don't log web accelerators, it's very confusing...
503
-	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
504
-		return;
524
+	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
525
+			return;
526
+	}
505 527
 
506 528
 	$smcFunc['db_insert']('',
507 529
 		'{db_prefix}log_banned',
@@ -511,8 +533,8 @@  discard block
 block discarded – undo
511 533
 	);
512 534
 
513 535
 	// One extra point for these bans.
514
-	if (!empty($ban_ids))
515
-		$smcFunc['db_query']('', '
536
+	if (!empty($ban_ids)) {
537
+			$smcFunc['db_query']('', '
516 538
 			UPDATE {db_prefix}ban_items
517 539
 			SET hits = hits + 1
518 540
 			WHERE id_ban IN ({array_int:ban_ids})',
@@ -520,7 +542,8 @@  discard block
 block discarded – undo
520 542
 				'ban_ids' => $ban_ids,
521 543
 			)
522 544
 		);
523
-}
545
+	}
546
+	}
524 547
 
525 548
 /**
526 549
  * Checks if a given email address might be banned.
@@ -536,8 +559,9 @@  discard block
 block discarded – undo
536 559
 	global $txt, $smcFunc;
537 560
 
538 561
 	// Can't ban an empty email
539
-	if (empty($email) || trim($email) == '')
540
-		return;
562
+	if (empty($email) || trim($email) == '') {
563
+			return;
564
+	}
541 565
 
542 566
 	// Let's start with the bans based on your IP/hostname/memberID...
543 567
 	$ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array();
@@ -610,16 +634,18 @@  discard block
 block discarded – undo
610 634
 	if ($type == 'post')
611 635
 	{
612 636
 		$check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null);
613
-		if ($check !== $sc)
614
-			$error = 'session_timeout';
637
+		if ($check !== $sc) {
638
+					$error = 'session_timeout';
639
+		}
615 640
 	}
616 641
 
617 642
 	// How about $_GET['sesc']?
618 643
 	elseif ($type == 'get')
619 644
 	{
620 645
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null);
621
-		if ($check !== $sc)
622
-			$error = 'session_verify_fail';
646
+		if ($check !== $sc) {
647
+					$error = 'session_verify_fail';
648
+		}
623 649
 	}
624 650
 
625 651
 	// Or can it be in either?
@@ -627,13 +653,15 @@  discard block
 block discarded – undo
627 653
 	{
628 654
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null)));
629 655
 
630
-		if ($check !== $sc)
631
-			$error = 'session_verify_fail';
656
+		if ($check !== $sc) {
657
+					$error = 'session_verify_fail';
658
+		}
632 659
 	}
633 660
 
634 661
 	// Verify that they aren't changing user agents on us - that could be bad.
635
-	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA']))
636
-		$error = 'session_verify_fail';
662
+	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) {
663
+			$error = 'session_verify_fail';
664
+	}
637 665
 
638 666
 	// Make sure a page with session check requirement is not being prefetched.
639 667
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -644,30 +672,35 @@  discard block
 block discarded – undo
644 672
 	}
645 673
 
646 674
 	// Check the referring site - it should be the same server at least!
647
-	if (isset($_SESSION['request_referer']))
648
-		$referrer = $_SESSION['request_referer'];
649
-	else
650
-		$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
675
+	if (isset($_SESSION['request_referer'])) {
676
+			$referrer = $_SESSION['request_referer'];
677
+	} else {
678
+			$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
679
+	}
651 680
 	if (!empty($referrer['host']))
652 681
 	{
653
-		if (strpos($_SERVER['HTTP_HOST'], ':') !== false)
654
-			$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
655
-		else
656
-			$real_host = $_SERVER['HTTP_HOST'];
682
+		if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
683
+					$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
684
+		} else {
685
+					$real_host = $_SERVER['HTTP_HOST'];
686
+		}
657 687
 
658 688
 		$parsed_url = parse_url($boardurl);
659 689
 
660 690
 		// Are global cookies on?  If so, let's check them ;).
661 691
 		if (!empty($modSettings['globalCookies']))
662 692
 		{
663
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
664
-				$parsed_url['host'] = $parts[1];
693
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
694
+							$parsed_url['host'] = $parts[1];
695
+			}
665 696
 
666
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1)
667
-				$referrer['host'] = $parts[1];
697
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) {
698
+							$referrer['host'] = $parts[1];
699
+			}
668 700
 
669
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1)
670
-				$real_host = $parts[1];
701
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) {
702
+							$real_host = $parts[1];
703
+			}
671 704
 		}
672 705
 
673 706
 		// Okay: referrer must either match parsed_url or real_host.
@@ -685,12 +718,14 @@  discard block
 block discarded – undo
685 718
 		$log_error = true;
686 719
 	}
687 720
 
688
-	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker')
689
-		fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
721
+	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') {
722
+			fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
723
+	}
690 724
 
691 725
 	// Everything is ok, return an empty string.
692
-	if (!isset($error))
693
-		return '';
726
+	if (!isset($error)) {
727
+			return '';
728
+	}
694 729
 	// A session error occurred, show the error.
695 730
 	elseif ($is_fatal)
696 731
 	{
@@ -699,13 +734,14 @@  discard block
 block discarded – undo
699 734
 			ob_end_clean();
700 735
 			header('HTTP/1.1 403 Forbidden - Session timeout');
701 736
 			die;
737
+		} else {
738
+					fatal_lang_error($error, isset($log_error) ? 'user' : false);
702 739
 		}
703
-		else
704
-			fatal_lang_error($error, isset($log_error) ? 'user' : false);
705 740
 	}
706 741
 	// A session error occurred, return the error to the calling function.
707
-	else
708
-		return $error;
742
+	else {
743
+			return $error;
744
+	}
709 745
 
710 746
 	// We really should never fall through here, for very important reasons.  Let's make sure.
711 747
 	trigger_error('Hacking attempt...', E_USER_ERROR);
@@ -721,10 +757,9 @@  discard block
 block discarded – undo
721 757
 {
722 758
 	global $modSettings;
723 759
 
724
-	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action])
725
-		return true;
726
-
727
-	else
760
+	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) {
761
+			return true;
762
+	} else
728 763
 	{
729 764
 		$token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']);
730 765
 		$_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']);
@@ -775,9 +810,9 @@  discard block
 block discarded – undo
775 810
 			$return = $_SESSION['token'][$type . '-' . $action][3];
776 811
 			unset($_SESSION['token'][$type . '-' . $action]);
777 812
 			return $return;
813
+		} else {
814
+					return '';
778 815
 		}
779
-		else
780
-			return '';
781 816
 	}
782 817
 
783 818
 	// This nasty piece of code validates a token.
@@ -808,12 +843,14 @@  discard block
 block discarded – undo
808 843
 		fatal_lang_error('token_verify_fail', false);
809 844
 	}
810 845
 	// Remove this token as its useless
811
-	else
812
-		unset($_SESSION['token'][$type . '-' . $action]);
846
+	else {
847
+			unset($_SESSION['token'][$type . '-' . $action]);
848
+	}
813 849
 
814 850
 	// Randomly check if we should remove some older tokens.
815
-	if (mt_rand(0, 138) == 23)
816
-		cleanTokens();
851
+	if (mt_rand(0, 138) == 23) {
852
+			cleanTokens();
853
+	}
817 854
 
818 855
 	return false;
819 856
 }
@@ -828,14 +865,16 @@  discard block
 block discarded – undo
828 865
 function cleanTokens($complete = false)
829 866
 {
830 867
 	// We appreciate cleaning up after yourselves.
831
-	if (!isset($_SESSION['token']))
832
-		return;
868
+	if (!isset($_SESSION['token'])) {
869
+			return;
870
+	}
833 871
 
834 872
 	// Clean up tokens, trying to give enough time still.
835
-	foreach ($_SESSION['token'] as $key => $data)
836
-		if ($data[2] + 10800 < time() || $complete)
873
+	foreach ($_SESSION['token'] as $key => $data) {
874
+			if ($data[2] + 10800 < time() || $complete)
837 875
 			unset($_SESSION['token'][$key]);
838
-}
876
+	}
877
+	}
839 878
 
840 879
 /**
841 880
  * Check whether a form has been submitted twice.
@@ -853,37 +892,40 @@  discard block
 block discarded – undo
853 892
 {
854 893
 	global $context;
855 894
 
856
-	if (!isset($_SESSION['forms']))
857
-		$_SESSION['forms'] = array();
895
+	if (!isset($_SESSION['forms'])) {
896
+			$_SESSION['forms'] = array();
897
+	}
858 898
 
859 899
 	// Register a form number and store it in the session stack. (use this on the page that has the form.)
860 900
 	if ($action == 'register')
861 901
 	{
862 902
 		$context['form_sequence_number'] = 0;
863
-		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms']))
864
-			$context['form_sequence_number'] = mt_rand(1, 16000000);
903
+		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) {
904
+					$context['form_sequence_number'] = mt_rand(1, 16000000);
905
+		}
865 906
 	}
866 907
 	// Check whether the submitted number can be found in the session.
867 908
 	elseif ($action == 'check')
868 909
 	{
869
-		if (!isset($_REQUEST['seqnum']))
870
-			return true;
871
-		elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
910
+		if (!isset($_REQUEST['seqnum'])) {
911
+					return true;
912
+		} elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
872 913
 		{
873 914
 			$_SESSION['forms'][] = (int) $_REQUEST['seqnum'];
874 915
 			return true;
916
+		} elseif ($is_fatal) {
917
+					fatal_lang_error('error_form_already_submitted', false);
918
+		} else {
919
+					return false;
875 920
 		}
876
-		elseif ($is_fatal)
877
-			fatal_lang_error('error_form_already_submitted', false);
878
-		else
879
-			return false;
880 921
 	}
881 922
 	// Don't check, just free the stack number.
882
-	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms']))
883
-		$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
884
-	elseif ($action != 'free')
885
-		trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
886
-}
923
+	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) {
924
+			$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
925
+	} elseif ($action != 'free') {
926
+			trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
927
+	}
928
+	}
887 929
 
888 930
 /**
889 931
  * Check the user's permissions.
@@ -900,16 +942,19 @@  discard block
 block discarded – undo
900 942
 	global $user_info, $smcFunc;
901 943
 
902 944
 	// You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!)
903
-	if (empty($permission))
904
-		return true;
945
+	if (empty($permission)) {
946
+			return true;
947
+	}
905 948
 
906 949
 	// You're never allowed to do something if your data hasn't been loaded yet!
907
-	if (empty($user_info))
908
-		return false;
950
+	if (empty($user_info)) {
951
+			return false;
952
+	}
909 953
 
910 954
 	// Administrators are supermen :P.
911
-	if ($user_info['is_admin'])
912
-		return true;
955
+	if ($user_info['is_admin']) {
956
+			return true;
957
+	}
913 958
 
914 959
 	// Let's ensure this is an array.
915 960
 	$permission = (array)$permission;
@@ -917,14 +962,16 @@  discard block
 block discarded – undo
917 962
 	// Are we checking the _current_ board, or some other boards?
918 963
 	if ($boards === null)
919 964
 	{
920
-		if (count(array_intersect($permission, $user_info['permissions'])) != 0)
921
-			return true;
965
+		if (count(array_intersect($permission, $user_info['permissions'])) != 0) {
966
+					return true;
967
+		}
922 968
 		// You aren't allowed, by default.
923
-		else
924
-			return false;
969
+		else {
970
+					return false;
971
+		}
972
+	} elseif (!is_array($boards)) {
973
+			$boards = array($boards);
925 974
 	}
926
-	elseif (!is_array($boards))
927
-		$boards = array($boards);
928 975
 
929 976
 	$request = $smcFunc['db_query']('', '
930 977
 		SELECT MIN(bp.add_deny) AS add_deny
@@ -947,12 +994,14 @@  discard block
 block discarded – undo
947 994
 	);
948 995
 
949 996
 	// Make sure they can do it on all of the boards.
950
-	if ($smcFunc['db_num_rows']($request) != count($boards))
951
-		return false;
997
+	if ($smcFunc['db_num_rows']($request) != count($boards)) {
998
+			return false;
999
+	}
952 1000
 
953 1001
 	$result = true;
954
-	while ($row = $smcFunc['db_fetch_assoc']($request))
955
-		$result &= !empty($row['add_deny']);
1002
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1003
+			$result &= !empty($row['add_deny']);
1004
+	}
956 1005
 	$smcFunc['db_free_result']($request);
957 1006
 
958 1007
 	// If the query returned 1, they can do it... otherwise, they can't.
@@ -1017,9 +1066,10 @@  discard block
 block discarded – undo
1017 1066
 
1018 1067
 	// If you're doing something on behalf of some "heavy" permissions, validate your session.
1019 1068
 	// (take out the heavy permissions, and if you can't do anything but those, you need a validated session.)
1020
-	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards))
1021
-		validateSession();
1022
-}
1069
+	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) {
1070
+			validateSession();
1071
+	}
1072
+	}
1023 1073
 
1024 1074
 /**
1025 1075
  * Return the boards a user has a certain (board) permission on. (array(0) if all.)
@@ -1038,8 +1088,9 @@  discard block
 block discarded – undo
1038 1088
 	global $user_info, $smcFunc;
1039 1089
 
1040 1090
 	// Arrays are nice, most of the time.
1041
-	if (!is_array($permissions))
1042
-		$permissions = array($permissions);
1091
+	if (!is_array($permissions)) {
1092
+			$permissions = array($permissions);
1093
+	}
1043 1094
 
1044 1095
 	/*
1045 1096
 	 * Set $simple to true to use this function as it were in SMF 2.0.x.
@@ -1051,13 +1102,14 @@  discard block
 block discarded – undo
1051 1102
 	// Administrators are all powerful, sorry.
1052 1103
 	if ($user_info['is_admin'])
1053 1104
 	{
1054
-		if ($simple)
1055
-			return array(0);
1056
-		else
1105
+		if ($simple) {
1106
+					return array(0);
1107
+		} else
1057 1108
 		{
1058 1109
 			$boards = array();
1059
-			foreach ($permissions as $permission)
1060
-				$boards[$permission] = array(0);
1110
+			foreach ($permissions as $permission) {
1111
+							$boards[$permission] = array(0);
1112
+			}
1061 1113
 
1062 1114
 			return $boards;
1063 1115
 		}
@@ -1089,31 +1141,32 @@  discard block
 block discarded – undo
1089 1141
 	{
1090 1142
 		if ($simple)
1091 1143
 		{
1092
-			if (empty($row['add_deny']))
1093
-				$deny_boards[] = $row['id_board'];
1094
-			else
1095
-				$boards[] = $row['id_board'];
1096
-		}
1097
-		else
1144
+			if (empty($row['add_deny'])) {
1145
+							$deny_boards[] = $row['id_board'];
1146
+			} else {
1147
+							$boards[] = $row['id_board'];
1148
+			}
1149
+		} else
1098 1150
 		{
1099
-			if (empty($row['add_deny']))
1100
-				$deny_boards[$row['permission']][] = $row['id_board'];
1101
-			else
1102
-				$boards[$row['permission']][] = $row['id_board'];
1151
+			if (empty($row['add_deny'])) {
1152
+							$deny_boards[$row['permission']][] = $row['id_board'];
1153
+			} else {
1154
+							$boards[$row['permission']][] = $row['id_board'];
1155
+			}
1103 1156
 		}
1104 1157
 	}
1105 1158
 	$smcFunc['db_free_result']($request);
1106 1159
 
1107
-	if ($simple)
1108
-		$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1109
-	else
1160
+	if ($simple) {
1161
+			$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1162
+	} else
1110 1163
 	{
1111 1164
 		foreach ($permissions as $permission)
1112 1165
 		{
1113 1166
 			// never had it to start with
1114
-			if (empty($boards[$permission]))
1115
-				$boards[$permission] = array();
1116
-			else
1167
+			if (empty($boards[$permission])) {
1168
+							$boards[$permission] = array();
1169
+			} else
1117 1170
 			{
1118 1171
 				// Or it may have been removed
1119 1172
 				$deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array();
@@ -1149,10 +1202,11 @@  discard block
 block discarded – undo
1149 1202
 
1150 1203
 
1151 1204
 	// Moderators are free...
1152
-	if (!allowedTo('moderate_board'))
1153
-		$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1154
-	else
1155
-		$timeLimit = 2;
1205
+	if (!allowedTo('moderate_board')) {
1206
+			$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1207
+	} else {
1208
+			$timeLimit = 2;
1209
+	}
1156 1210
 
1157 1211
 	call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit));
1158 1212
 
@@ -1179,8 +1233,9 @@  discard block
 block discarded – undo
1179 1233
 	if ($smcFunc['db_affected_rows']() != 1)
1180 1234
 	{
1181 1235
 		// Spammer!  You only have to wait a *few* seconds!
1182
-		if (!$only_return_result)
1183
-			fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1236
+		if (!$only_return_result) {
1237
+					fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1238
+		}
1184 1239
 
1185 1240
 		return true;
1186 1241
 	}
@@ -1198,11 +1253,13 @@  discard block
 block discarded – undo
1198 1253
  */
1199 1254
 function secureDirectory($path, $attachments = false)
1200 1255
 {
1201
-	if (empty($path))
1202
-		return 'empty_path';
1256
+	if (empty($path)) {
1257
+			return 'empty_path';
1258
+	}
1203 1259
 
1204
-	if (!is_writable($path))
1205
-		return 'path_not_writable';
1260
+	if (!is_writable($path)) {
1261
+			return 'path_not_writable';
1262
+	}
1206 1263
 
1207 1264
 	$directoryname = basename($path);
1208 1265
 
@@ -1214,9 +1271,9 @@  discard block
 block discarded – undo
1214 1271
 
1215 1272
 RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml';
1216 1273
 
1217
-	if (file_exists($path . '/.htaccess'))
1218
-		$errors[] = 'htaccess_exists';
1219
-	else
1274
+	if (file_exists($path . '/.htaccess')) {
1275
+			$errors[] = 'htaccess_exists';
1276
+	} else
1220 1277
 	{
1221 1278
 		$fh = @fopen($path . '/.htaccess', 'w');
1222 1279
 		if ($fh) {
@@ -1228,9 +1285,9 @@  discard block
 block discarded – undo
1228 1285
 		$errors[] = 'htaccess_cannot_create_file';
1229 1286
 	}
1230 1287
 
1231
-	if (file_exists($path . '/index.php'))
1232
-		$errors[] = 'index-php_exists';
1233
-	else
1288
+	if (file_exists($path . '/index.php')) {
1289
+			$errors[] = 'index-php_exists';
1290
+	} else
1234 1291
 	{
1235 1292
 		$fh = @fopen($path . '/index.php', 'w');
1236 1293
 		if ($fh) {
@@ -1257,11 +1314,12 @@  discard block
 block discarded – undo
1257 1314
 		$errors[] = 'index-php_cannot_create_file';
1258 1315
 	}
1259 1316
 
1260
-	if (!empty($errors))
1261
-		return $errors;
1262
-	else
1263
-		return true;
1264
-}
1317
+	if (!empty($errors)) {
1318
+			return $errors;
1319
+	} else {
1320
+			return true;
1321
+	}
1322
+	}
1265 1323
 
1266 1324
 /**
1267 1325
 * This sets the X-Frame-Options header.
@@ -1274,14 +1332,16 @@  discard block
 block discarded – undo
1274 1332
 	global $modSettings;
1275 1333
 
1276 1334
 	$option = 'SAMEORIGIN';
1277
-	if (is_null($override) && !empty($modSettings['frame_security']))
1278
-		$option = $modSettings['frame_security'];
1279
-	elseif (in_array($override, array('SAMEORIGIN', 'DENY')))
1280
-		$option = $override;
1335
+	if (is_null($override) && !empty($modSettings['frame_security'])) {
1336
+			$option = $modSettings['frame_security'];
1337
+	} elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) {
1338
+			$option = $override;
1339
+	}
1281 1340
 
1282 1341
 	// Don't bother setting the header if we have disabled it.
1283
-	if ($option == 'DISABLE')
1284
-		return;
1342
+	if ($option == 'DISABLE') {
1343
+			return;
1344
+	}
1285 1345
 
1286 1346
 	// Finally set it.
1287 1347
 	header('X-Frame-Options: ' . $option);
Please login to merge, or discard this patch.
Sources/PostModeration.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
 		{
177 177
 			if ($curAction == 'approve')
178 178
 			{
179
-				approveMessages ($toAction, $details, $context['current_view']);
179
+				approveMessages($toAction, $details, $context['current_view']);
180 180
 			}
181 181
 			else
182 182
 			{
183
-				removeMessages ($toAction, $details, $context['current_view']);
183
+				removeMessages($toAction, $details, $context['current_view']);
184 184
 			}
185 185
 		}
186 186
 	}
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 					'value' => $txt['mc_unapproved_attach_poster'],
438 438
 				),
439 439
 				'data' => array(
440
-					'function' => function ($data)
440
+					'function' => function($data)
441 441
 					{
442 442
 						return $data['poster']['link'];
443 443
 					},
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 					'value' => $txt['post'],
468 468
 				),
469 469
 				'data' => array(
470
-					'function' => function ($data)
470
+					'function' => function($data)
471 471
 					{
472 472
 						return '<a href="' . $data['message']['href'] . '">' . shorten_subject($data['message']['subject'], 20) . '</a>';
473 473
 					},
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
 			logAction(($approved ? 'un' : '') . 'approve', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
694 694
 	}
695 695
 
696
-	redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg']. '#msg' . $_REQUEST['msg']);
696
+	redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
697 697
 }
698 698
 
699 699
 /**
Please login to merge, or discard this patch.
Braces   +100 added lines, -79 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * This is a handling function for all things post moderation.
@@ -39,8 +40,9 @@  discard block
 block discarded – undo
39 40
 	);
40 41
 
41 42
 	// Pick something valid...
42
-	if (!isset($_REQUEST['sa']) || !isset($subActions[$_REQUEST['sa']]))
43
-		$_REQUEST['sa'] = 'replies';
43
+	if (!isset($_REQUEST['sa']) || !isset($subActions[$_REQUEST['sa']])) {
44
+			$_REQUEST['sa'] = 'replies';
45
+	}
44 46
 
45 47
 	call_integration_hook('integrate_post_moderation', array(&$subActions));
46 48
 
@@ -68,13 +70,15 @@  discard block
 block discarded – undo
68 70
 		$approve_boards = $approve_boards == array(0) ? $filter_board : array_intersect($approve_boards, $filter_board);
69 71
 	}
70 72
 
71
-	if ($approve_boards == array(0))
72
-		$approve_query = '';
73
-	elseif (!empty($approve_boards))
74
-		$approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
73
+	if ($approve_boards == array(0)) {
74
+			$approve_query = '';
75
+	} elseif (!empty($approve_boards)) {
76
+			$approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
77
+	}
75 78
 	// Nada, zip, etc...
76
-	else
77
-		$approve_query = ' AND 1=0';
79
+	else {
80
+			$approve_query = ' AND 1=0';
81
+	}
78 82
 
79 83
 	// We also need to know where we can delete topics and/or replies to.
80 84
 	if ($context['current_view'] == 'topics')
@@ -82,8 +86,7 @@  discard block
 block discarded – undo
82 86
 		$delete_own_boards = boardsAllowedTo('remove_own');
83 87
 		$delete_any_boards = boardsAllowedTo('remove_any');
84 88
 		$delete_own_replies = array();
85
-	}
86
-	else
89
+	} else
87 90
 	{
88 91
 		$delete_own_boards = boardsAllowedTo('delete_own');
89 92
 		$delete_any_boards = boardsAllowedTo('delete_any');
@@ -92,21 +95,25 @@  discard block
 block discarded – undo
92 95
 
93 96
 	$toAction = array();
94 97
 	// Check if we have something to do?
95
-	if (isset($_GET['approve']))
96
-		$toAction[] = (int) $_GET['approve'];
98
+	if (isset($_GET['approve'])) {
99
+			$toAction[] = (int) $_GET['approve'];
100
+	}
97 101
 	// Just a deletion?
98
-	elseif (isset($_GET['delete']))
99
-		$toAction[] = (int) $_GET['delete'];
102
+	elseif (isset($_GET['delete'])) {
103
+			$toAction[] = (int) $_GET['delete'];
104
+	}
100 105
 	// Lots of approvals?
101
-	elseif (isset($_POST['item']))
102
-		foreach ($_POST['item'] as $item)
106
+	elseif (isset($_POST['item'])) {
107
+			foreach ($_POST['item'] as $item)
103 108
 			$toAction[] = (int) $item;
109
+	}
104 110
 
105 111
 	// What are we actually doing.
106
-	if (isset($_GET['approve']) || (isset($_POST['do']) && $_POST['do'] == 'approve'))
107
-		$curAction = 'approve';
108
-	elseif (isset($_GET['delete']) || (isset($_POST['do']) && $_POST['do'] == 'delete'))
109
-		$curAction = 'delete';
112
+	if (isset($_GET['approve']) || (isset($_POST['do']) && $_POST['do'] == 'approve')) {
113
+			$curAction = 'approve';
114
+	} elseif (isset($_GET['delete']) || (isset($_POST['do']) && $_POST['do'] == 'delete')) {
115
+			$curAction = 'delete';
116
+	}
110 117
 
111 118
 	// Right, so we have something to do?
112 119
 	if (!empty($toAction) && isset($curAction))
@@ -135,8 +142,9 @@  discard block
 block discarded – undo
135 142
 		while ($row = $smcFunc['db_fetch_assoc']($request))
136 143
 		{
137 144
 			// If it's not within what our view is ignore it...
138
-			if (($row['id_msg'] == $row['id_first_msg'] && $context['current_view'] != 'topics') || ($row['id_msg'] != $row['id_first_msg'] && $context['current_view'] != 'replies'))
139
-				continue;
145
+			if (($row['id_msg'] == $row['id_first_msg'] && $context['current_view'] != 'topics') || ($row['id_msg'] != $row['id_first_msg'] && $context['current_view'] != 'replies')) {
146
+							continue;
147
+			}
140 148
 
141 149
 			$can_add = false;
142 150
 			// If we're approving this is simple.
@@ -148,18 +156,22 @@  discard block
 block discarded – undo
148 156
 			elseif ($curAction == 'delete')
149 157
 			{
150 158
 				// Own post is easy!
151
-				if ($row['id_member'] == $user_info['id'] && ($delete_own_boards == array(0) || in_array($row['id_board'], $delete_own_boards)))
152
-					$can_add = true;
159
+				if ($row['id_member'] == $user_info['id'] && ($delete_own_boards == array(0) || in_array($row['id_board'], $delete_own_boards))) {
160
+									$can_add = true;
161
+				}
153 162
 				// Is it a reply to their own topic?
154
-				elseif ($row['id_member'] == $row['id_member_started'] && $row['id_msg'] != $row['id_first_msg'] && ($delete_own_replies == array(0) || in_array($row['id_board'], $delete_own_replies)))
155
-					$can_add = true;
163
+				elseif ($row['id_member'] == $row['id_member_started'] && $row['id_msg'] != $row['id_first_msg'] && ($delete_own_replies == array(0) || in_array($row['id_board'], $delete_own_replies))) {
164
+									$can_add = true;
165
+				}
156 166
 				// Someone elses?
157
-				elseif ($row['id_member'] != $user_info['id'] && ($delete_any_boards == array(0) || in_array($row['id_board'], $delete_any_boards)))
158
-					$can_add = true;
167
+				elseif ($row['id_member'] != $user_info['id'] && ($delete_any_boards == array(0) || in_array($row['id_board'], $delete_any_boards))) {
168
+									$can_add = true;
169
+				}
159 170
 			}
160 171
 
161
-			if ($can_add)
162
-				$anItem = $context['current_view'] == 'topics' ? $row['id_topic'] : $row['id_msg'];
172
+			if ($can_add) {
173
+							$anItem = $context['current_view'] == 'topics' ? $row['id_topic'] : $row['id_msg'];
174
+			}
163 175
 			$toAction[] = $anItem;
164 176
 
165 177
 			// All clear. What have we got now, what, what?
@@ -177,8 +189,7 @@  discard block
 block discarded – undo
177 189
 			if ($curAction == 'approve')
178 190
 			{
179 191
 				approveMessages ($toAction, $details, $context['current_view']);
180
-			}
181
-			else
192
+			} else
182 193
 			{
183 194
 				removeMessages ($toAction, $details, $context['current_view']);
184 195
 			}
@@ -265,16 +276,19 @@  discard block
 block discarded – undo
265 276
 	for ($i = 1; $row = $smcFunc['db_fetch_assoc']($request); $i++)
266 277
 	{
267 278
 		// Can delete is complicated, let's solve it first... is it their own post?
268
-		if ($row['id_member'] == $user_info['id'] && ($delete_own_boards == array(0) || in_array($row['id_board'], $delete_own_boards)))
269
-			$can_delete = true;
279
+		if ($row['id_member'] == $user_info['id'] && ($delete_own_boards == array(0) || in_array($row['id_board'], $delete_own_boards))) {
280
+					$can_delete = true;
281
+		}
270 282
 		// Is it a reply to their own topic?
271
-		elseif ($row['id_member'] == $row['id_member_started'] && $row['id_msg'] != $row['id_first_msg'] && ($delete_own_replies == array(0) || in_array($row['id_board'], $delete_own_replies)))
272
-			$can_delete = true;
283
+		elseif ($row['id_member'] == $row['id_member_started'] && $row['id_msg'] != $row['id_first_msg'] && ($delete_own_replies == array(0) || in_array($row['id_board'], $delete_own_replies))) {
284
+					$can_delete = true;
285
+		}
273 286
 		// Someone elses?
274
-		elseif ($row['id_member'] != $user_info['id'] && ($delete_any_boards == array(0) || in_array($row['id_board'], $delete_any_boards)))
275
-			$can_delete = true;
276
-		else
277
-			$can_delete = false;
287
+		elseif ($row['id_member'] != $user_info['id'] && ($delete_any_boards == array(0) || in_array($row['id_board'], $delete_any_boards))) {
288
+					$can_delete = true;
289
+		} else {
290
+					$can_delete = false;
291
+		}
278 292
 
279 293
 		$context['unapproved_items'][] = array(
280 294
 			'id' => $row['id_msg'],
@@ -323,28 +337,31 @@  discard block
 block discarded – undo
323 337
 	// Once again, permissions are king!
324 338
 	$approve_boards = boardsAllowedTo('approve_posts');
325 339
 
326
-	if ($approve_boards == array(0))
327
-		$approve_query = '';
328
-	elseif (!empty($approve_boards))
329
-		$approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
330
-	else
331
-		$approve_query = ' AND 1=0';
340
+	if ($approve_boards == array(0)) {
341
+			$approve_query = '';
342
+	} elseif (!empty($approve_boards)) {
343
+			$approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
344
+	} else {
345
+			$approve_query = ' AND 1=0';
346
+	}
332 347
 
333 348
 	// Get together the array of things to act on, if any.
334 349
 	$attachments = array();
335
-	if (isset($_GET['approve']))
336
-		$attachments[] = (int) $_GET['approve'];
337
-	elseif (isset($_GET['delete']))
338
-		$attachments[] = (int) $_GET['delete'];
339
-	elseif (isset($_POST['item']))
340
-		foreach ($_POST['item'] as $item)
350
+	if (isset($_GET['approve'])) {
351
+			$attachments[] = (int) $_GET['approve'];
352
+	} elseif (isset($_GET['delete'])) {
353
+			$attachments[] = (int) $_GET['delete'];
354
+	} elseif (isset($_POST['item'])) {
355
+			foreach ($_POST['item'] as $item)
341 356
 			$attachments[] = (int) $item;
357
+	}
342 358
 
343 359
 	// Are we approving or deleting?
344
-	if (isset($_GET['approve']) || (isset($_POST['do']) && $_POST['do'] == 'approve'))
345
-		$curAction = 'approve';
346
-	elseif (isset($_GET['delete']) || (isset($_POST['do']) && $_POST['do'] == 'delete'))
347
-		$curAction = 'delete';
360
+	if (isset($_GET['approve']) || (isset($_POST['do']) && $_POST['do'] == 'approve')) {
361
+			$curAction = 'approve';
362
+	} elseif (isset($_GET['delete']) || (isset($_POST['do']) && $_POST['do'] == 'delete')) {
363
+			$curAction = 'delete';
364
+	}
348 365
 
349 366
 	// Something to do, let's do it!
350 367
 	if (!empty($attachments) && isset($curAction))
@@ -372,17 +389,19 @@  discard block
 block discarded – undo
372 389
 			)
373 390
 		);
374 391
 		$attachments = array();
375
-		while ($row = $smcFunc['db_fetch_assoc']($request))
376
-			$attachments[] = $row['id_attach'];
392
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
393
+					$attachments[] = $row['id_attach'];
394
+		}
377 395
 		$smcFunc['db_free_result']($request);
378 396
 
379 397
 		// Assuming it wasn't all like, proper illegal, we can do the approving.
380 398
 		if (!empty($attachments))
381 399
 		{
382
-			if ($curAction == 'approve')
383
-				ApproveAttachments($attachments);
384
-			else
385
-				removeAttachments(array('id_attach' => $attachments, 'do_logging' => true));
400
+			if ($curAction == 'approve') {
401
+							ApproveAttachments($attachments);
402
+			} else {
403
+							removeAttachments(array('id_attach' => $attachments, 'do_logging' => true));
404
+			}
386 405
 		}
387 406
 	}
388 407
 
@@ -682,15 +701,16 @@  discard block
 block discarded – undo
682 701
 	{
683 702
 		approveTopics($topic, !$approved);
684 703
 
685
-		if ($starter != $user_info['id'])
686
-			logAction(($approved ? 'un' : '') . 'approve_topic', array('topic' => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
687
-	}
688
-	else
704
+		if ($starter != $user_info['id']) {
705
+					logAction(($approved ? 'un' : '') . 'approve_topic', array('topic' => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
706
+		}
707
+	} else
689 708
 	{
690 709
 		approvePosts($_REQUEST['msg'], !$approved);
691 710
 
692
-		if ($poster != $user_info['id'])
693
-			logAction(($approved ? 'un' : '') . 'approve', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
711
+		if ($poster != $user_info['id']) {
712
+					logAction(($approved ? 'un' : '') . 'approve', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
713
+		}
694 714
 	}
695 715
 
696 716
 	redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg']. '#msg' . $_REQUEST['msg']);
@@ -716,8 +736,7 @@  discard block
 block discarded – undo
716 736
 		{
717 737
 			logAction('approve_topic', array('topic' => $topic, 'subject' => $messageDetails[$topic]['subject'], 'member' => $messageDetails[$topic]['member'], 'board' => $messageDetails[$topic]['board']));
718 738
 		}
719
-	}
720
-	else
739
+	} else
721 740
 	{
722 741
 		approvePosts($messages);
723 742
 		// and tell the world about it again
@@ -745,8 +764,9 @@  discard block
 block discarded – undo
745 764
 		)
746 765
 	);
747 766
 	$msgs = array();
748
-	while ($row = $smcFunc['db_fetch_row']($request))
749
-		$msgs[] = $row[0];
767
+	while ($row = $smcFunc['db_fetch_row']($request)) {
768
+			$msgs[] = $row[0];
769
+	}
750 770
 	$smcFunc['db_free_result']($request);
751 771
 
752 772
 	if (!empty($msgs))
@@ -765,8 +785,9 @@  discard block
 block discarded – undo
765 785
 		)
766 786
 	);
767 787
 	$attaches = array();
768
-	while ($row = $smcFunc['db_fetch_row']($request))
769
-		$attaches[] = $row[0];
788
+	while ($row = $smcFunc['db_fetch_row']($request)) {
789
+			$attaches[] = $row[0];
790
+	}
770 791
 	$smcFunc['db_free_result']($request);
771 792
 
772 793
 	if (!empty($attaches))
@@ -794,12 +815,12 @@  discard block
 block discarded – undo
794 815
 	{
795 816
 		removeTopics($messages);
796 817
 		// and tell the world about it
797
-		foreach ($messages as $topic)
798
-			// Note, only log topic ID in native form if it's not gone forever.
818
+		foreach ($messages as $topic) {
819
+					// Note, only log topic ID in native form if it's not gone forever.
799 820
 			logAction('remove', array(
800 821
 				(empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $messageDetails[$topic]['board'] ? 'topic' : 'old_topic_id') => $topic, 'subject' => $messageDetails[$topic]['subject'], 'member' => $messageDetails[$topic]['member'], 'board' => $messageDetails[$topic]['board']));
801
-	}
802
-	else
822
+		}
823
+	} else
803 824
 	{
804 825
 		foreach ($messages as $post)
805 826
 		{
Please login to merge, or discard this patch.