Completed
Push — release-2.1 ( 4bdd41...11eb43 )
by Mathias
07:36
created
Sources/ManageSearch.php 1 patch
Braces   +109 added lines, -90 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Main entry point for the admin search settings screen.
@@ -107,11 +108,13 @@  discard block
 block discarded – undo
107 108
 	// Perhaps the search method wants to add some settings?
108 109
 	require_once($sourcedir . '/Search.php');
109 110
 	$searchAPI = findSearchAPI();
110
-	if (is_callable(array($searchAPI, 'searchSettings')))
111
-		call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars));
111
+	if (is_callable(array($searchAPI, 'searchSettings'))) {
112
+			call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars));
113
+	}
112 114
 
113
-	if ($return_config)
114
-		return $config_vars;
115
+	if ($return_config) {
116
+			return $config_vars;
117
+	}
115 118
 
116 119
 	$context['page_title'] = $txt['search_settings_title'];
117 120
 	$context['sub_template'] = 'show_settings';
@@ -126,8 +129,9 @@  discard block
 block discarded – undo
126 129
 
127 130
 		call_integration_hook('integrate_save_search_settings');
128 131
 
129
-		if (empty($_POST['search_results_per_page']))
130
-			$_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages'];
132
+		if (empty($_POST['search_results_per_page'])) {
133
+					$_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages'];
134
+		}
131 135
 		saveDBSettings($config_vars);
132 136
 		$_SESSION['adm-save'] = true;
133 137
 		redirectexit('action=admin;area=managesearch;sa=settings;' . $context['session_var'] . '=' . $context['session_id']);
@@ -177,17 +181,20 @@  discard block
 block discarded – undo
177 181
 		call_integration_hook('integrate_save_search_weights');
178 182
 
179 183
 		$changes = array();
180
-		foreach ($factors as $factor)
181
-			$changes[$factor] = (int) $_POST[$factor];
184
+		foreach ($factors as $factor) {
185
+					$changes[$factor] = (int) $_POST[$factor];
186
+		}
182 187
 		updateSettings($changes);
183 188
 	}
184 189
 
185 190
 	$context['relative_weights'] = array('total' => 0);
186
-	foreach ($factors as $factor)
187
-		$context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0;
191
+	foreach ($factors as $factor) {
192
+			$context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0;
193
+	}
188 194
 
189
-	foreach ($factors as $factor)
190
-		$context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1);
195
+	foreach ($factors as $factor) {
196
+			$context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1);
197
+	}
191 198
 
192 199
 	createToken('admin-msw');
193 200
 }
@@ -215,8 +222,9 @@  discard block
 block discarded – undo
215 222
 	$context['search_apis'] = loadSearchAPIs();
216 223
 
217 224
 	// Detect whether a fulltext index is set.
218
-	if ($context['supports_fulltext'])
219
-		detectFulltextIndex();
225
+	if ($context['supports_fulltext']) {
226
+			detectFulltextIndex();
227
+	}
220 228
 
221 229
 	if (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'createfulltext')
222 230
 	{
@@ -240,8 +248,7 @@  discard block
 block discarded – undo
240 248
 					'language' => $language_ftx
241 249
 				)
242 250
 			);
243
-		}
244
-		else
251
+		} else
245 252
 		{
246 253
 			// Make sure it's gone before creating it.
247 254
 			$smcFunc['db_query']('', '
@@ -259,8 +266,7 @@  discard block
 block discarded – undo
259 266
 				)
260 267
 			);
261 268
 		}
262
-	}
263
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
269
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
264 270
 	{
265 271
 		checkSession('get');
266 272
 		validateToken('admin-msm', 'get');
@@ -277,12 +283,12 @@  discard block
 block discarded – undo
277 283
 		$context['fulltext_index'] = array();
278 284
 
279 285
 		// Go back to the default search method.
280
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext')
281
-			updateSettings(array(
286
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') {
287
+					updateSettings(array(
282 288
 				'search_index' => '',
283 289
 			));
284
-	}
285
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
290
+		}
291
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
286 292
 	{
287 293
 		checkSession('get');
288 294
 		validateToken('admin-msm', 'get');
@@ -304,12 +310,12 @@  discard block
 block discarded – undo
304 310
 		));
305 311
 
306 312
 		// Go back to the default search method.
307
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
308
-			updateSettings(array(
313
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
314
+					updateSettings(array(
309 315
 				'search_index' => '',
310 316
 			));
311
-	}
312
-	elseif (isset($_POST['save']))
317
+		}
318
+	} elseif (isset($_POST['save']))
313 319
 	{
314 320
 		checkSession();
315 321
 		validateToken('admin-msmpost');
@@ -331,8 +337,8 @@  discard block
 block discarded – undo
331 337
 	// Get some info about the messages table, to show its size and index size.
332 338
 	if ($db_type == 'mysql')
333 339
 	{
334
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
335
-			$request = $smcFunc['db_query']('', '
340
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
341
+					$request = $smcFunc['db_query']('', '
336 342
 				SHOW TABLE STATUS
337 343
 				FROM {string:database_name}
338 344
 				LIKE {string:table_name}',
@@ -341,14 +347,15 @@  discard block
 block discarded – undo
341 347
 					'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
342 348
 				)
343 349
 			);
344
-		else
345
-			$request = $smcFunc['db_query']('', '
350
+		} else {
351
+					$request = $smcFunc['db_query']('', '
346 352
 				SHOW TABLE STATUS
347 353
 				LIKE {string:table_name}',
348 354
 				array(
349 355
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
350 356
 				)
351 357
 			);
358
+		}
352 359
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
353 360
 		{
354 361
 			// Only do this if the user has permission to execute this query.
@@ -360,8 +367,8 @@  discard block
 block discarded – undo
360 367
 		}
361 368
 
362 369
 		// Now check the custom index table, if it exists at all.
363
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
364
-			$request = $smcFunc['db_query']('', '
370
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
371
+					$request = $smcFunc['db_query']('', '
365 372
 				SHOW TABLE STATUS
366 373
 				FROM {string:database_name}
367 374
 				LIKE {string:table_name}',
@@ -370,14 +377,15 @@  discard block
 block discarded – undo
370 377
 					'table_name' => str_replace('_', '\_', $match[2]) . 'log_search_words',
371 378
 				)
372 379
 			);
373
-		else
374
-			$request = $smcFunc['db_query']('', '
380
+		} else {
381
+					$request = $smcFunc['db_query']('', '
375 382
 				SHOW TABLE STATUS
376 383
 				LIKE {string:table_name}',
377 384
 				array(
378 385
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'log_search_words',
379 386
 				)
380 387
 			);
388
+		}
381 389
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
382 390
 		{
383 391
 			// Only do this if the user has permission to execute this query.
@@ -386,8 +394,7 @@  discard block
 block discarded – undo
386 394
 			$context['table_info']['custom_index_length'] = $row['Data_length'] + $row['Index_length'];
387 395
 			$smcFunc['db_free_result']($request);
388 396
 		}
389
-	}
390
-	elseif ($db_type == 'postgresql')
397
+	} elseif ($db_type == 'postgresql')
391 398
 	{
392 399
 		// In order to report the sizes correctly we need to perform vacuum (optimize) on the tables we will be using.
393 400
 		//db_extend();
@@ -429,38 +436,38 @@  discard block
 block discarded – undo
429 436
 					$context['table_info']['data_length'] = (int) $row['table_size'];
430 437
 					$context['table_info']['index_length'] = (int) $row['index_size'];
431 438
 					$context['table_info']['fulltext_length'] = (int) $row['index_size'];
432
-				}
433
-				elseif ($row['indexname'] == $db_prefix . 'log_search_words')
439
+				} elseif ($row['indexname'] == $db_prefix . 'log_search_words')
434 440
 				{
435 441
 					$context['table_info']['index_length'] = (int) $row['index_size'];
436 442
 					$context['table_info']['custom_index_length'] = (int) $row['index_size'];
437 443
 				}
438 444
 			}
439 445
 			$smcFunc['db_free_result']($request);
440
-		}
441
-		else
442
-			// Didn't work for some reason...
446
+		} else {
447
+					// Didn't work for some reason...
443 448
 			$context['table_info'] = array(
444 449
 				'data_length' => $txt['not_applicable'],
445 450
 				'index_length' => $txt['not_applicable'],
446 451
 				'fulltext_length' => $txt['not_applicable'],
447 452
 				'custom_index_length' => $txt['not_applicable'],
448 453
 			);
449
-	}
450
-	else
451
-		$context['table_info'] = array(
454
+		}
455
+	} else {
456
+			$context['table_info'] = array(
452 457
 			'data_length' => $txt['not_applicable'],
453 458
 			'index_length' => $txt['not_applicable'],
454 459
 			'fulltext_length' => $txt['not_applicable'],
455 460
 			'custom_index_length' => $txt['not_applicable'],
456 461
 		);
462
+	}
457 463
 
458 464
 	// Format the data and index length in kilobytes.
459 465
 	foreach ($context['table_info'] as $type => $size)
460 466
 	{
461 467
 		// If it's not numeric then just break.  This database engine doesn't support size.
462
-		if (!is_numeric($size))
463
-			break;
468
+		if (!is_numeric($size)) {
469
+					break;
470
+		}
464 471
 
465 472
 		$context['table_info'][$type] = comma_format($context['table_info'][$type] / 1024) . ' ' . $txt['search_method_kilobytes'];
466 473
 	}
@@ -489,8 +496,9 @@  discard block
 block discarded – undo
489 496
 
490 497
 	// Scotty, we need more time...
491 498
 	@set_time_limit(600);
492
-	if (function_exists('apache_reset_timeout'))
493
-		@apache_reset_timeout();
499
+	if (function_exists('apache_reset_timeout')) {
500
+			@apache_reset_timeout();
501
+	}
494 502
 
495 503
 	$context[$context['admin_menu_name']]['current_subsection'] = 'method';
496 504
 	$context['page_title'] = $txt['search_index_custom'];
@@ -520,8 +528,7 @@  discard block
 block discarded – undo
520 528
 		$context['start'] = (int) $context['index_settings']['resume_at'];
521 529
 		unset($context['index_settings']['resume_at']);
522 530
 		$context['step'] = 1;
523
-	}
524
-	else
531
+	} else
525 532
 	{
526 533
 		$context['index_settings'] = array(
527 534
 			'bytes_per_word' => isset($_REQUEST['bytes_per_word']) && isset($index_properties[$_REQUEST['bytes_per_word']]) ? (int) $_REQUEST['bytes_per_word'] : 2,
@@ -530,12 +537,14 @@  discard block
 block discarded – undo
530 537
 		$context['step'] = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0;
531 538
 
532 539
 		// admin timeouts are painful when building these long indexes - but only if we actually have such things enabled
533
-		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1)
534
-			$_SESSION['admin_time'] = time();
540
+		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) {
541
+					$_SESSION['admin_time'] = time();
542
+		}
535 543
 	}
536 544
 
537
-	if ($context['step'] !== 0)
538
-		checkSession('request');
545
+	if ($context['step'] !== 0) {
546
+			checkSession('request');
547
+	}
539 548
 
540 549
 	// Step 0: let the user determine how they like their index.
541 550
 	if ($context['step'] === 0)
@@ -564,12 +573,14 @@  discard block
 block discarded – undo
564 573
 			$smcFunc['db_create_word_search']($index_properties[$context['index_settings']['bytes_per_word']]['column_definition']);
565 574
 
566 575
 			// Temporarily switch back to not using a search index.
567
-			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
568
-				updateSettings(array('search_index' => ''));
576
+			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
577
+							updateSettings(array('search_index' => ''));
578
+			}
569 579
 
570 580
 			// Don't let simultanious processes be updating the search index.
571
-			if (!empty($modSettings['search_custom_index_config']))
572
-				updateSettings(array('search_custom_index_config' => ''));
581
+			if (!empty($modSettings['search_custom_index_config'])) {
582
+							updateSettings(array('search_custom_index_config' => ''));
583
+			}
573 584
 		}
574 585
 
575 586
 		$num_messages = array(
@@ -585,16 +596,16 @@  discard block
 block discarded – undo
585 596
 				'starting_id' => $context['start'],
586 597
 			)
587 598
 		);
588
-		while ($row = $smcFunc['db_fetch_assoc']($request))
589
-			$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
599
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
600
+					$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
601
+		}
590 602
 
591 603
 		if (empty($num_messages['todo']))
592 604
 		{
593 605
 			$context['step'] = 2;
594 606
 			$context['percentage'] = 80;
595 607
 			$context['start'] = 0;
596
-		}
597
-		else
608
+		} else
598 609
 		{
599 610
 			// Number of seconds before the next step.
600 611
 			$stop = time() + 3;
@@ -635,21 +646,22 @@  discard block
 block discarded – undo
635 646
 
636 647
 				$context['start'] += $forced_break ? $number_processed : $messages_per_batch;
637 648
 
638
-				if (!empty($inserts))
639
-					$smcFunc['db_insert']('ignore',
649
+				if (!empty($inserts)) {
650
+									$smcFunc['db_insert']('ignore',
640 651
 						'{db_prefix}log_search_words',
641 652
 						array('id_word' => 'int', 'id_msg' => 'int'),
642 653
 						$inserts,
643 654
 						array('id_word', 'id_msg')
644 655
 					);
656
+				}
645 657
 				if ($num_messages['todo'] === 0)
646 658
 				{
647 659
 					$context['step'] = 2;
648 660
 					$context['start'] = 0;
649 661
 					break;
662
+				} else {
663
+									updateSettings(array('search_custom_index_resume' => $smcFunc['json_encode'](array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
650 664
 				}
651
-				else
652
-					updateSettings(array('search_custom_index_resume' => $smcFunc['json_encode'](array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
653 665
 			}
654 666
 
655 667
 			// Since there are still two steps to go, 80% is the maximum here.
@@ -660,9 +672,9 @@  discard block
 block discarded – undo
660 672
 	// Step 2: removing the words that occur too often and are of no use.
661 673
 	elseif ($context['step'] === 2)
662 674
 	{
663
-		if ($context['index_settings']['bytes_per_word'] < 4)
664
-			$context['step'] = 3;
665
-		else
675
+		if ($context['index_settings']['bytes_per_word'] < 4) {
676
+					$context['step'] = 3;
677
+		} else
666 678
 		{
667 679
 			$stop_words = $context['start'] === 0 || empty($modSettings['search_stopwords']) ? array() : explode(',', $modSettings['search_stopwords']);
668 680
 			$stop = time() + 3;
@@ -683,20 +695,22 @@  discard block
 block discarded – undo
683 695
 						'minimum_messages' => $max_messages,
684 696
 					)
685 697
 				);
686
-				while ($row = $smcFunc['db_fetch_assoc']($request))
687
-					$stop_words[] = $row['id_word'];
698
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
699
+									$stop_words[] = $row['id_word'];
700
+				}
688 701
 				$smcFunc['db_free_result']($request);
689 702
 
690 703
 				updateSettings(array('search_stopwords' => implode(',', $stop_words)));
691 704
 
692
-				if (!empty($stop_words))
693
-					$smcFunc['db_query']('', '
705
+				if (!empty($stop_words)) {
706
+									$smcFunc['db_query']('', '
694 707
 						DELETE FROM {db_prefix}log_search_words
695 708
 						WHERE id_word in ({array_int:stop_words})',
696 709
 						array(
697 710
 							'stop_words' => $stop_words,
698 711
 						)
699 712
 					);
713
+				}
700 714
 
701 715
 				$context['start'] += $index_properties[$context['index_settings']['bytes_per_word']]['step_size'];
702 716
 				if ($context['start'] > $index_properties[$context['index_settings']['bytes_per_word']]['max_size'])
@@ -757,8 +771,9 @@  discard block
 block discarded – undo
757 771
 					$searchAPI = new $search_class_name();
758 772
 
759 773
 					// No Support?  NEXT!
760
-					if (!$searchAPI->is_supported)
761
-						continue;
774
+					if (!$searchAPI->is_supported) {
775
+											continue;
776
+					}
762 777
 
763 778
 					$apis[$index_name] = array(
764 779
 						'filename' => $file,
@@ -805,10 +820,10 @@  discard block
 block discarded – undo
805 820
 				'messages_ftx' => $db_prefix . 'messages_ftx',
806 821
 			)
807 822
 		);
808
-		while ($row = $smcFunc['db_fetch_assoc']($request))
809
-			$context['fulltext_index'][] = $row['indexname'];
810
-	}
811
-	else
823
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
824
+					$context['fulltext_index'][] = $row['indexname'];
825
+		}
826
+	} else
812 827
 	{
813 828
 		$request = $smcFunc['db_query']('', '
814 829
 			SHOW INDEX
@@ -819,17 +834,19 @@  discard block
 block discarded – undo
819 834
 		$context['fulltext_index'] = array();
820 835
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
821 836
 		{
822
-			while ($row = $smcFunc['db_fetch_assoc']($request))
823
-			if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
837
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
838
+						if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
824 839
 				$context['fulltext_index'][] = $row['Key_name'];
840
+			}
825 841
 			$smcFunc['db_free_result']($request);
826 842
 
827
-			if (is_array($context['fulltext_index']))
828
-				$context['fulltext_index'] = array_unique($context['fulltext_index']);
843
+			if (is_array($context['fulltext_index'])) {
844
+							$context['fulltext_index'] = array_unique($context['fulltext_index']);
845
+			}
829 846
 		}
830 847
 
831
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
832
-			$request = $smcFunc['db_query']('', '
848
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
849
+					$request = $smcFunc['db_query']('', '
833 850
 			SHOW TABLE STATUS
834 851
 			FROM {string:database_name}
835 852
 			LIKE {string:table_name}',
@@ -838,20 +855,22 @@  discard block
 block discarded – undo
838 855
 				'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
839 856
 			)
840 857
 			);
841
-		else
842
-			$request = $smcFunc['db_query']('', '
858
+		} else {
859
+					$request = $smcFunc['db_query']('', '
843 860
 			SHOW TABLE STATUS
844 861
 			LIKE {string:table_name}',
845 862
 			array(
846 863
 				'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
847 864
 			)
848 865
 			);
866
+		}
849 867
 
850 868
 		if ($request !== false)
851 869
 		{
852
-			while ($row = $smcFunc['db_fetch_assoc']($request))
853
-			if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>=')))
870
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
871
+						if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>=')))
854 872
 				$context['cannot_create_fulltext'] = true;
873
+			}
855 874
 			$smcFunc['db_free_result']($request);
856 875
 		}
857 876
 	}
Please login to merge, or discard this patch.
Sources/SearchAPI-Custom.php 1 patch
Braces   +48 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 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * Used for the "custom search index" option
@@ -54,8 +55,9 @@  discard block
 block discarded – undo
54 55
 			return;
55 56
 		}
56 57
 
57
-		if (empty($modSettings['search_custom_index_config']))
58
-			return;
58
+		if (empty($modSettings['search_custom_index_config'])) {
59
+					return;
60
+		}
59 61
 
60 62
 		$this->indexSettings = $smcFunc['json_decode']($modSettings['search_custom_index_config'], true);
61 63
 
@@ -117,21 +119,23 @@  discard block
 block discarded – undo
117 119
 
118 120
 		$subwords = text2words($word, $this->min_word_length, true);
119 121
 
120
-		if (empty($modSettings['search_force_index']))
121
-			$wordsSearch['words'][] = $word;
122
+		if (empty($modSettings['search_force_index'])) {
123
+					$wordsSearch['words'][] = $word;
124
+		}
122 125
 
123 126
 		// Excluded phrases don't benefit from being split into subwords.
124
-		if (count($subwords) > 1 && $isExcluded)
125
-			return;
126
-		else
127
+		if (count($subwords) > 1 && $isExcluded) {
128
+					return;
129
+		} else
127 130
 		{
128 131
 			foreach ($subwords as $subword)
129 132
 			{
130 133
 				if ($smcFunc['strlen']($subword) >= $this->min_word_length && !in_array($subword, $this->bannedWords))
131 134
 				{
132 135
 					$wordsSearch['indexed_words'][] = $subword;
133
-					if ($isExcluded)
134
-						$wordsExclude[] = $subword;
136
+					if ($isExcluded) {
137
+											$wordsExclude[] = $subword;
138
+					}
135 139
 				}
136 140
 			}
137 141
 		}
@@ -152,8 +156,9 @@  discard block
 block discarded – undo
152 156
 		$query_where = array();
153 157
 		$query_params = $search_data['params'];
154 158
 
155
-		if ($query_params['id_search'])
156
-			$query_select['id_search'] = '{int:id_search}';
159
+		if ($query_params['id_search']) {
160
+					$query_select['id_search'] = '{int:id_search}';
161
+		}
157 162
 
158 163
 		$count = 0;
159 164
 		foreach ($words['words'] as $regularWord)
@@ -162,30 +167,37 @@  discard block
 block discarded – undo
162 167
 			$query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]';
163 168
 		}
164 169
 
165
-		if ($query_params['user_query'])
166
-			$query_where[] = '{raw:user_query}';
167
-		if ($query_params['board_query'])
168
-			$query_where[] = 'm.id_board {raw:board_query}';
170
+		if ($query_params['user_query']) {
171
+					$query_where[] = '{raw:user_query}';
172
+		}
173
+		if ($query_params['board_query']) {
174
+					$query_where[] = 'm.id_board {raw:board_query}';
175
+		}
169 176
 
170
-		if ($query_params['topic'])
171
-			$query_where[] = 'm.id_topic = {int:topic}';
172
-		if ($query_params['min_msg_id'])
173
-			$query_where[] = 'm.id_msg >= {int:min_msg_id}';
174
-		if ($query_params['max_msg_id'])
175
-			$query_where[] = 'm.id_msg <= {int:max_msg_id}';
177
+		if ($query_params['topic']) {
178
+					$query_where[] = 'm.id_topic = {int:topic}';
179
+		}
180
+		if ($query_params['min_msg_id']) {
181
+					$query_where[] = 'm.id_msg >= {int:min_msg_id}';
182
+		}
183
+		if ($query_params['max_msg_id']) {
184
+					$query_where[] = 'm.id_msg <= {int:max_msg_id}';
185
+		}
176 186
 
177 187
 		$count = 0;
178
-		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index']))
179
-			foreach ($query_params['excluded_phrases'] as $phrase)
188
+		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) {
189
+					foreach ($query_params['excluded_phrases'] as $phrase)
180 190
 			{
181 191
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_phrase_' . $count . '}';
192
+		}
182 193
 				$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), '\\\'') . '[[:>:]]';
183 194
 			}
184 195
 		$count = 0;
185
-		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index']))
186
-			foreach ($query_params['excluded_subject_words'] as $excludedWord)
196
+		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) {
197
+					foreach ($query_params['excluded_subject_words'] as $excludedWord)
187 198
 			{
188 199
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_words_' . $count . '}';
200
+		}
189 201
 				$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), '\\\'') . '[[:>:]]';
190 202
 			}
191 203
 
@@ -198,8 +210,7 @@  discard block
 block discarded – undo
198 210
 			{
199 211
 				$query_left_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_word = ' . $indexedWord . ' AND lsw' . $numTables . '.id_msg = m.id_msg)';
200 212
 				$query_where[] = '(lsw' . $numTables . '.id_word IS NULL)';
201
-			}
202
-			else
213
+			} else
203 214
 			{
204 215
 				$query_inner_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_msg = ' . ($prev_join === 0 ? 'm' : 'lsw' . $prev_join) . '.id_msg)';
205 216
 				$query_where[] = 'lsw' . $numTables . '.id_word = ' . $indexedWord;
@@ -235,16 +246,18 @@  discard block
 block discarded – undo
235 246
 		$customIndexSettings = $smcFunc['json_decode']($modSettings['search_custom_index_config'], true);
236 247
 
237 248
 		$inserts = array();
238
-		foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word)
239
-			$inserts[] = array($word, $msgOptions['id']);
249
+		foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word) {
250
+					$inserts[] = array($word, $msgOptions['id']);
251
+		}
240 252
 
241
-		if (!empty($inserts))
242
-			$smcFunc['db_insert']('ignore',
253
+		if (!empty($inserts)) {
254
+					$smcFunc['db_insert']('ignore',
243 255
 				'{db_prefix}log_search_words',
244 256
 				array('id_word' => 'int', 'id_msg' => 'int'),
245 257
 				$inserts,
246 258
 				array('id_word', 'id_msg')
247 259
 			);
260
+		}
248 261
 	}
249 262
 
250 263
 	/**
@@ -287,8 +300,9 @@  discard block
 block discarded – undo
287 300
 			if (!empty($inserted_words))
288 301
 			{
289 302
 				$inserts = array();
290
-				foreach ($inserted_words as $word)
291
-					$inserts[] = array($word, $msgOptions['id']);
303
+				foreach ($inserted_words as $word) {
304
+									$inserts[] = array($word, $msgOptions['id']);
305
+				}
292 306
 				$smcFunc['db_insert']('insert',
293 307
 					'{db_prefix}log_search_words',
294 308
 					array('id_word' => 'string', 'id_msg' => 'int'),
Please login to merge, or discard this patch.
Sources/Memberlist.php 1 patch
Braces   +81 added lines, -63 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Shows a listing of registered members.
@@ -110,8 +111,9 @@  discard block
 block discarded – undo
110 111
 
111 112
 	$context['custom_profile_fields'] = getCustFieldsMList();
112 113
 
113
-	if (!empty($context['custom_profile_fields']['columns']))
114
-		$context['columns'] += $context['custom_profile_fields']['columns'];
114
+	if (!empty($context['custom_profile_fields']['columns'])) {
115
+			$context['columns'] += $context['custom_profile_fields']['columns'];
116
+	}
115 117
 
116 118
 	$context['colspan'] = 0;
117 119
 	$context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
@@ -147,12 +149,12 @@  discard block
 block discarded – undo
147 149
 	call_integration_hook('integrate_memberlist_buttons');
148 150
 
149 151
 	// Jump to the sub action.
150
-	if (isset($subActions[$context['listing_by']]))
151
-		call_helper($subActions[$context['listing_by']][1]);
152
-
153
-	else
154
-		call_helper($subActions['all'][1]);
155
-}
152
+	if (isset($subActions[$context['listing_by']])) {
153
+			call_helper($subActions[$context['listing_by']][1]);
154
+	} else {
155
+			call_helper($subActions['all'][1]);
156
+	}
157
+	}
156 158
 
157 159
 /**
158 160
  * List all members, page by page, with sorting.
@@ -177,8 +179,9 @@  discard block
 block discarded – undo
177 179
 	if ($use_cache)
178 180
 	{
179 181
 		// Maybe there's something cached already.
180
-		if (!empty($modSettings['memberlist_cache']))
181
-			$memberlist_cache = $smcFunc['json_decode']($modSettings['memberlist_cache'], true);
182
+		if (!empty($modSettings['memberlist_cache'])) {
183
+					$memberlist_cache = $smcFunc['json_decode']($modSettings['memberlist_cache'], true);
184
+		}
182 185
 
183 186
 		// The chunk size for the cached index.
184 187
 		$cache_step_size = 500;
@@ -234,13 +237,15 @@  discard block
 block discarded – undo
234 237
 	}
235 238
 
236 239
 	// Set defaults for sort (real_name) and start. (0)
237
-	if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']]))
238
-		$_REQUEST['sort'] = 'real_name';
240
+	if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) {
241
+			$_REQUEST['sort'] = 'real_name';
242
+	}
239 243
 
240 244
 	if (!is_numeric($_REQUEST['start']))
241 245
 	{
242
-		if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0)
243
-			fatal_error('Hacker?', false);
246
+		if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) {
247
+					fatal_error('Hacker?', false);
248
+		}
244 249
 
245 250
 		$_REQUEST['start'] = $match[0];
246 251
 
@@ -259,16 +264,18 @@  discard block
 block discarded – undo
259 264
 	}
260 265
 
261 266
 	$context['letter_links'] = '';
262
-	for ($i = 97; $i < 123; $i++)
263
-		$context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> ';
267
+	for ($i = 97; $i < 123; $i++) {
268
+			$context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> ';
269
+	}
264 270
 
265 271
 	// Sort out the column information.
266 272
 	foreach ($context['columns'] as $col => $column_details)
267 273
 	{
268 274
 		$context['columns'][$col]['href'] = $scripturl . '?action=mlist;sort=' . $col . ';start=0';
269 275
 
270
-		if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev'])))
271
-			$context['columns'][$col]['href'] .= ';desc';
276
+		if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) {
277
+					$context['columns'][$col]['href'] .= ';desc';
278
+		}
272 279
 
273 280
 		$context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>';
274 281
 		$context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col;
@@ -317,8 +324,9 @@  discard block
 block discarded – undo
317 324
 	elseif ($use_cache && $_REQUEST['sort'] === 'real_name')
318 325
 	{
319 326
 		$first_offset = floor(($memberlist_cache['num_members'] - $modSettings['defaultMaxMembers'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size;
320
-		if ($first_offset < 0)
321
-			$first_offset = 0;
327
+		if ($first_offset < 0) {
328
+					$first_offset = 0;
329
+		}
322 330
 		$second_offset = ceil(($memberlist_cache['num_members'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size;
323 331
 
324 332
 		$where = 'mem.real_name BETWEEN {string:real_name_low} AND {string:real_name_high}';
@@ -328,8 +336,9 @@  discard block
 block discarded – undo
328 336
 	}
329 337
 
330 338
 	$custom_fields_qry = '';
331
-	if (!empty($context['custom_profile_fields']['join'][$_REQUEST['sort']]))
332
-		$custom_fields_qry = $context['custom_profile_fields']['join'][$_REQUEST['sort']];
339
+	if (!empty($context['custom_profile_fields']['join'][$_REQUEST['sort']])) {
340
+			$custom_fields_qry = $context['custom_profile_fields']['join'][$_REQUEST['sort']];
341
+	}
333 342
 
334 343
 	// Select the members from the database.
335 344
 	$request = $smcFunc['db_query']('', '
@@ -399,12 +408,13 @@  discard block
 block discarded – undo
399 408
 		)
400 409
 	);
401 410
 	$context['custom_search_fields'] = array();
402
-	while ($row = $smcFunc['db_fetch_assoc']($request))
403
-		$context['custom_search_fields'][$row['col_name']] = array(
411
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
412
+			$context['custom_search_fields'][$row['col_name']] = array(
404 413
 			'colname' => $row['col_name'],
405 414
 			'name' => $row['field_name'],
406 415
 			'desc' => $row['field_desc'],
407 416
 		);
417
+	}
408 418
 	$smcFunc['db_free_result']($request);
409 419
 
410 420
 	// They're searching..
@@ -417,23 +427,27 @@  discard block
 block discarded – undo
417 427
 		$context['old_search_value'] = urlencode($_REQUEST['search']);
418 428
 
419 429
 		// No fields?  Use default...
420
-		if (empty($_POST['fields']))
421
-			$_POST['fields'] = array('name');
430
+		if (empty($_POST['fields'])) {
431
+					$_POST['fields'] = array('name');
432
+		}
422 433
 
423 434
 		// Set defaults for how the results are sorted
424
-		if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']]))
425
-			$_REQUEST['sort'] = 'real_name';
435
+		if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) {
436
+					$_REQUEST['sort'] = 'real_name';
437
+		}
426 438
 
427 439
 		// Build the column link / sort information.
428 440
 		foreach ($context['columns'] as $col => $column_details)
429 441
 		{
430 442
 			$context['columns'][$col]['href'] = $scripturl . '?action=mlist;sa=search;start=0;sort=' . $col;
431 443
 
432
-			if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev'])))
433
-				$context['columns'][$col]['href'] .= ';desc';
444
+			if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) {
445
+							$context['columns'][$col]['href'] .= ';desc';
446
+			}
434 447
 
435
-			if (isset($_POST['search']) && isset($_POST['fields']))
436
-				$context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']);
448
+			if (isset($_POST['search']) && isset($_POST['fields'])) {
449
+							$context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']);
450
+			}
437 451
 
438 452
 			$context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>';
439 453
 			$context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col;
@@ -456,8 +470,7 @@  discard block
 block discarded – undo
456 470
 		{
457 471
 			$fields = allowedTo('moderate_forum') ? array('member_name', 'real_name') : array('real_name');
458 472
 			$search_fields[] = 'name';
459
-		}
460
-		else
473
+		} else
461 474
 		{
462 475
 			$fields = array();
463 476
 			$search_fields = array();
@@ -482,9 +495,10 @@  discard block
 block discarded – undo
482 495
 			$search_fields[] = 'email';
483 496
 		}
484 497
 
485
-		if ($smcFunc['db_case_sensitive'])
486
-			foreach ($fields as $key => $field)
498
+		if ($smcFunc['db_case_sensitive']) {
499
+					foreach ($fields as $key => $field)
487 500
 				$fields[$key] = 'LOWER(' . $field . ')';
501
+		}
488 502
 
489 503
 		$customJoin = array();
490 504
 		$customCount = 10;
@@ -503,8 +517,9 @@  discard block
 block discarded – undo
503 517
 		}
504 518
 
505 519
 		// No search fields? That means you're trying to hack things
506
-		if (empty($search_fields))
507
-			fatal_lang_error('invalid_search_string', false);
520
+		if (empty($search_fields)) {
521
+					fatal_lang_error('invalid_search_string', false);
522
+		}
508 523
 
509 524
 		$query = $_POST['search'] == '' ? '= {string:blank_string}' : ($smcFunc['db_case_sensitive'] ? 'LIKE LOWER({string:search})' : 'LIKE {string:search}');
510 525
 
@@ -542,8 +557,7 @@  discard block
 block discarded – undo
542 557
 		);
543 558
 		printMemberListRows($request);
544 559
 		$smcFunc['db_free_result']($request);
545
-	}
546
-	else
560
+	} else
547 561
 	{
548 562
 		// These are all the possible fields.
549 563
 		$context['search_fields'] = array(
@@ -558,14 +572,14 @@  discard block
 block discarded – undo
558 572
 		{
559 573
 			unset($context['search_fields']['email']);
560 574
 			$context['search_defaults'] = array('name');
561
-		}
562
-		else
575
+		} else
563 576
 		{
564 577
 			$context['search_defaults'] = array('name', 'email');
565 578
 		}
566 579
 
567
-		foreach ($context['custom_search_fields'] as $field)
568
-			$context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']);
580
+		foreach ($context['custom_search_fields'] as $field) {
581
+					$context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']);
582
+		}
569 583
 
570 584
 		$context['sub_template'] = 'search';
571 585
 		$context['old_search'] = isset($_GET['search']) ? $_GET['search'] : (isset($_POST['search']) ? $smcFunc['htmlspecialchars']($_POST['search']) : '');
@@ -607,12 +621,14 @@  discard block
 block discarded – undo
607 621
 	$smcFunc['db_free_result']($result);
608 622
 
609 623
 	// Avoid division by zero...
610
-	if ($most_posts == 0)
611
-		$most_posts = 1;
624
+	if ($most_posts == 0) {
625
+			$most_posts = 1;
626
+	}
612 627
 
613 628
 	$members = array();
614
-	while ($row = $smcFunc['db_fetch_assoc']($request))
615
-		$members[] = $row['id_member'];
629
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
630
+			$members[] = $row['id_member'];
631
+	}
616 632
 
617 633
 	// Load all the members for display.
618 634
 	loadMemberData($members);
@@ -620,8 +636,9 @@  discard block
 block discarded – undo
620 636
 	$context['members'] = array();
621 637
 	foreach ($members as $member)
622 638
 	{
623
-		if (!loadMemberContext($member))
624
-			continue;
639
+		if (!loadMemberContext($member)) {
640
+					continue;
641
+		}
625 642
 
626 643
 		$context['members'][$member] = $memberContext[$member];
627 644
 		$context['members'][$member]['post_percent'] = round(($context['members'][$member]['real_posts'] * 100) / $most_posts);
@@ -638,20 +655,21 @@  discard block
 block discarded – undo
638 655
 					continue;
639 656
 				}
640 657
 
641
-				if ($column['bbc'] && !empty($context['members'][$member]['options'][$key]))
642
-					$context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key]));
643
-
644
-				elseif ($column['type'] == 'check')
645
-					$context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
658
+				if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) {
659
+									$context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key]));
660
+				} elseif ($column['type'] == 'check') {
661
+									$context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
662
+				}
646 663
 
647 664
 				// Enclosing the user input within some other text?
648
-				if (!empty($column['enclose']))
649
-					$context['members'][$member]['options'][$key] = strtr($column['enclose'], array(
665
+				if (!empty($column['enclose'])) {
666
+									$context['members'][$member]['options'][$key] = strtr($column['enclose'], array(
650 667
 						'{SCRIPTURL}' => $scripturl,
651 668
 						'{IMAGES_URL}' => $settings['images_url'],
652 669
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
653 670
 						'{INPUT}' => $context['members'][$member]['options'][$key],
654 671
 					));
672
+				}
655 673
 			}
656 674
 		}
657 675
 	}
@@ -692,17 +710,17 @@  discard block
 block discarded – undo
692 710
 		);
693 711
 
694 712
 		// Get the right sort method depending on the cust field type.
695
-		if ($row['field_type'] != 'check')
696
-			$cpf['columns'][$row['col_name']]['sort'] = array(
713
+		if ($row['field_type'] != 'check') {
714
+					$cpf['columns'][$row['col_name']]['sort'] = array(
697 715
 				'down' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 ASC, COALESCE(t' . $row['col_name'] . '.value, \'\') DESC',
698 716
 				'up' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 DESC, COALESCE(t' . $row['col_name'] . '.value, \'\') ASC'
699 717
 			);
700
-
701
-		else
702
-			$cpf['columns'][$row['col_name']]['sort'] = array(
718
+		} else {
719
+					$cpf['columns'][$row['col_name']]['sort'] = array(
703 720
 				'down' => 't' . $row['col_name'] . '.value DESC',
704 721
 				'up' => 't' . $row['col_name'] . '.value ASC'
705 722
 			);
723
+		}
706 724
 
707 725
 		$cpf['join'][$row['col_name']] = 'LEFT JOIN {db_prefix}themes AS t' . $row['col_name'] . ' ON (t' . $row['col_name'] . '.variable = {literal:' . $row['col_name'] . '} AND t' . $row['col_name'] . '.id_theme = 1 AND t' . $row['col_name'] . '.id_member = mem.id_member)';
708 726
 	}
Please login to merge, or discard this patch.
Sources/ManageSearchEngines.php 1 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 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * 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 = $smcFunc['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' => $smcFunc['json_encode']($spiders)));
Please login to merge, or discard this patch.
cron.php 1 patch
Braces   +36 added lines, -28 removed lines patch added patch discarded remove patch
@@ -41,37 +41,43 @@  discard block
 block discarded – undo
41 41
 define('TIME_START', microtime(true));
42 42
 
43 43
 // Just being safe...
44
-foreach (array('db_character_set', 'cachedir') as $variable)
44
+foreach (array('db_character_set', 'cachedir') as $variable) {
45 45
 	if (isset($GLOBALS[$variable]))
46 46
 		unset($GLOBALS[$variable]);
47
+}
47 48
 
48 49
 // Get the forum's settings for database and file paths.
49 50
 require_once(dirname(__FILE__) . '/Settings.php');
50 51
 
51 52
 // Make absolutely sure the cache directory is defined.
52
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
53
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
53 54
 	$cachedir = $boarddir . '/cache';
55
+}
54 56
 
55 57
 // Don't do john didley if the forum's been shut down competely.
56
-if ($maintenance == 2)
58
+if ($maintenance == 2) {
57 59
 	die($mmessage);
60
+}
58 61
 
59 62
 // Fix for using the current directory as a path.
60
-if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.')
63
+if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') {
61 64
 	$sourcedir = dirname(__FILE__) . substr($sourcedir, 1);
65
+}
62 66
 
63 67
 // Have we already turned this off? If so, exist gracefully.
64
-if (file_exists($cachedir . '/cron.lock'))
68
+if (file_exists($cachedir . '/cron.lock')) {
65 69
 	obExit_cron();
70
+}
66 71
 
67 72
 // Before we go any further, if this is not a CLI request, we need to do some checking.
68 73
 if (!FROM_CLI)
69 74
 {
70 75
 	// We will clean up $_GET shortly. But we want to this ASAP.
71 76
 	$ts = isset($_GET['ts']) ? (int) $_GET['ts'] : 0;
72
-	if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20)
73
-		obExit_cron();
74
-}
77
+	if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20) {
78
+			obExit_cron();
79
+	}
80
+	}
75 81
 
76 82
 // Load the most important includes. In general, a background should be loading its own dependencies.
77 83
 require_once($sourcedir . '/Errors.php');
@@ -123,8 +129,9 @@  discard block
 block discarded – undo
123 129
 	global $smcFunc;
124 130
 
125 131
 	// Check we haven't run over our time limit.
126
-	if (microtime(true) - TIME_START > MAX_CRON_TIME)
127
-		return false;
132
+	if (microtime(true) - TIME_START > MAX_CRON_TIME) {
133
+			return false;
134
+	}
128 135
 
129 136
 	// Try to find a task. Specifically, try to find one that hasn't been claimed previously, or failing that,
130 137
 	// a task that was claimed but failed for whatever reason and failed long enough ago. We should not care
@@ -159,14 +166,12 @@  discard block
 block discarded – undo
159 166
 			// Update the time and go back.
160 167
 			$row['claimed_time'] = time();
161 168
 			return $row;
162
-		}
163
-		else
169
+		} else
164 170
 		{
165 171
 			// Uh oh, we just missed it. Try to claim another one, and let it fall through if there aren't any.
166 172
 			return fetch_task();
167 173
 		}
168
-	}
169
-	else
174
+	} else
170 175
 	{
171 176
 		// No dice. Clean up and go home.
172 177
 		$smcFunc['db_free_result']($request);
@@ -187,8 +192,9 @@  discard block
 block discarded – undo
187 192
 	if (!empty($task_details['task_file']))
188 193
 	{
189 194
 		$include = strtr(trim($task_details['task_file']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
190
-		if (file_exists($include))
191
-			require_once($include);
195
+		if (file_exists($include)) {
196
+					require_once($include);
197
+		}
192 198
 	}
193 199
 
194 200
 	if (empty($task_details['task_class']))
@@ -204,8 +210,7 @@  discard block
 block discarded – undo
204 210
 		$details = empty($task_details['task_data']) ? array() : $smcFunc['json_decode']($task_details['task_data'], true);
205 211
 		$bgtask = new $task_details['task_class']($details);
206 212
 		return $bgtask->execute();
207
-	}
208
-	else
213
+	} else
209 214
 	{
210 215
 		log_error('Invalid background task specified: (class: ' . $task_details['task_class'] . ', ' . (empty($task_details['task_file']) ? ' no file' : ' to load ' . $task_details['task_file']) . ')');
211 216
 		return true; // So we clear it from the queue.
@@ -224,8 +229,9 @@  discard block
 block discarded – undo
224 229
 	$scripturl = $boardurl . '/index.php';
225 230
 
226 231
 	// These keys shouldn't be set...ever.
227
-	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
228
-		die('Invalid request variable.');
232
+	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
233
+			die('Invalid request variable.');
234
+	}
229 235
 
230 236
 	// Save some memory.. (since we don't use these anyway.)
231 237
 	unset($GLOBALS['HTTP_POST_VARS'], $GLOBALS['HTTP_POST_VARS']);
@@ -246,26 +252,28 @@  discard block
 block discarded – undo
246 252
 	global $modSettings;
247 253
 
248 254
 	// Ignore errors if we're ignoring them or they are strict notices from PHP 5 (which cannot be solved without breaking PHP 4.)
249
-	if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging'])))
250
-		return;
255
+	if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) {
256
+			return;
257
+	}
251 258
 
252 259
 	$error_type = 'cron';
253 260
 
254 261
 	log_error($error_level . ': ' . $error_string, $error_type, $file, $line);
255 262
 
256 263
 	// If this is an E_ERROR or E_USER_ERROR.... die.  Violently so.
257
-	if ($error_level % 255 == E_ERROR)
258
-		die('No direct access...');
259
-}
264
+	if ($error_level % 255 == E_ERROR) {
265
+			die('No direct access...');
266
+	}
267
+	}
260 268
 
261 269
 /**
262 270
  * The exit function
263 271
  */
264 272
 function obExit_cron()
265 273
 {
266
-	if (FROM_CLI)
267
-		die(0);
268
-	else
274
+	if (FROM_CLI) {
275
+			die(0);
276
+	} else
269 277
 	{
270 278
 		header('Content-Type: image/gif');
271 279
 		die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
Please login to merge, or discard this patch.
subscriptions.php 1 patch
Braces   +38 added lines, -28 removed lines patch added patch discarded remove patch
@@ -16,8 +16,9 @@  discard block
 block discarded – undo
16 16
 
17 17
 // Start things rolling by getting SMF alive...
18 18
 $ssi_guest_access = true;
19
-if (!file_exists(dirname(__FILE__) . '/SSI.php'))
19
+if (!file_exists(dirname(__FILE__) . '/SSI.php')) {
20 20
 	die('Cannot find SSI.php');
21
+}
21 22
 
22 23
 require_once(dirname(__FILE__) . '/SSI.php');
23 24
 require_once($sourcedir . '/ManagePaid.php');
@@ -35,20 +36,22 @@  discard block
 block discarded – undo
35 36
 }
36 37
 
37 38
 // I assume we're even active?
38
-if (empty($modSettings['paid_enabled']))
39
+if (empty($modSettings['paid_enabled'])) {
39 40
 	exit;
41
+}
40 42
 
41 43
 // If we have some custom people who find out about problems load them here.
42 44
 $notify_users = array();
43 45
 if (!empty($modSettings['paid_email_to']))
44 46
 {
45
-	foreach (explode(',', $modSettings['paid_email_to']) as $email)
46
-		$notify_users[] = array(
47
+	foreach (explode(',', $modSettings['paid_email_to']) as $email) {
48
+			$notify_users[] = array(
47 49
 			'email' => $email,
48 50
 			'name' => $txt['who_member'],
49 51
 			'id' => 0,
50 52
 		);
51
-}
53
+	}
54
+	}
52 55
 
53 56
 // We need to see whether we can find the correct payment gateway,
54 57
 // we'll going to go through all our gateway scripts and find out
@@ -65,8 +68,9 @@  discard block
 block discarded – undo
65 68
 	}
66 69
 }
67 70
 
68
-if (empty($txnType))
71
+if (empty($txnType)) {
69 72
 	generateSubscriptionError($txt['paid_unknown_transaction_type']);
73
+}
70 74
 
71 75
 // Get the subscription and member ID amoungst others...
72 76
 @list($subscription_id, $member_id) = $gatewayClass->precheck();
@@ -76,8 +80,9 @@  discard block
 block discarded – undo
76 80
 $member_id = (int) $member_id;
77 81
 
78 82
 // This would be bad...
79
-if (empty($member_id))
83
+if (empty($member_id)) {
80 84
 	generateSubscriptionError($txt['paid_empty_member']);
85
+}
81 86
 
82 87
 // Verify the member.
83 88
 $request = $smcFunc['db_query']('', '
@@ -89,8 +94,9 @@  discard block
 block discarded – undo
89 94
 	)
90 95
 );
91 96
 // Didn't find them?
92
-if ($smcFunc['db_num_rows']($request) === 0)
97
+if ($smcFunc['db_num_rows']($request) === 0) {
93 98
 	generateSubscriptionError(sprintf($txt['paid_could_not_find_member'], $member_id));
99
+}
94 100
 $member_info = $smcFunc['db_fetch_assoc']($request);
95 101
 $smcFunc['db_free_result']($request);
96 102
 
@@ -105,8 +111,9 @@  discard block
 block discarded – undo
105 111
 );
106 112
 
107 113
 // Didn't find it?
108
-if ($smcFunc['db_num_rows']($request) === 0)
114
+if ($smcFunc['db_num_rows']($request) === 0) {
109 115
 	generateSubscriptionError(sprintf($txt['paid_count_not_find_subscription'], $member_id, $subscription_id));
116
+}
110 117
 
111 118
 $subscription_info = $smcFunc['db_fetch_assoc']($request);
112 119
 $smcFunc['db_free_result']($request);
@@ -123,8 +130,9 @@  discard block
 block discarded – undo
123 130
 		'current_member' => $member_id,
124 131
 	)
125 132
 );
126
-if ($smcFunc['db_num_rows']($request) === 0)
133
+if ($smcFunc['db_num_rows']($request) === 0) {
127 134
 	generateSubscriptionError(sprintf($txt['paid_count_not_find_subscription_log'], $member_id, $subscription_id));
135
+}
128 136
 $subscription_info += $smcFunc['db_fetch_assoc']($request);
129 137
 $smcFunc['db_free_result']($request);
130 138
 
@@ -139,8 +147,7 @@  discard block
 block discarded – undo
139 147
 		removeSubscription($subscription_id, $member_id);
140 148
 		$subscription_act = time();
141 149
 		$status = 0;
142
-	}
143
-	else
150
+	} else
144 151
 	{
145 152
 		loadSubscriptions();
146 153
 		$subscription_act = $subscription_info['end_time'] - $context['subscriptions'][$subscription_id]['num_length'];
@@ -188,16 +195,18 @@  discard block
 block discarded – undo
188 195
 	if (!$gatewayClass->isSubscription())
189 196
 	{
190 197
 		$real_details = $smcFunc['json_decode']($subscription_info['pending_details'], true);
191
-		if (empty($real_details))
192
-			generateSubscriptionError(sprintf($txt['paid_count_not_find_outstanding_payment'], $member_id, $subscription_id));
198
+		if (empty($real_details)) {
199
+					generateSubscriptionError(sprintf($txt['paid_count_not_find_outstanding_payment'], $member_id, $subscription_id));
200
+		}
193 201
 
194 202
 		// Now we just try to find anything pending.
195 203
 		// We don't really care which it is as security happens later.
196 204
 		foreach ($real_details as $id => $detail)
197 205
 		{
198 206
 			unset($real_details[$id]);
199
-			if ($detail[3] == 'payback' && $subscription_info['payments_pending'])
200
-				$subscription_info['payments_pending']--;
207
+			if ($detail[3] == 'payback' && $subscription_info['payments_pending']) {
208
+							$subscription_info['payments_pending']--;
209
+			}
201 210
 			break;
202 211
 		}
203 212
 
@@ -223,10 +232,11 @@  discard block
 block discarded – undo
223 232
 		// This is a little harder, can we find the right duration?
224 233
 		foreach ($cost as $duration => $value)
225 234
 		{
226
-			if ($duration == 'fixed')
227
-				continue;
228
-			elseif ((float) $value == (float) $total_cost)
229
-				$found_duration = strtoupper(substr($duration, 0, 1));
235
+			if ($duration == 'fixed') {
236
+							continue;
237
+			} elseif ((float) $value == (float) $total_cost) {
238
+							$found_duration = strtoupper(substr($duration, 0, 1));
239
+			}
230 240
 		}
231 241
 
232 242
 		// If we have the duration then we're done.
@@ -235,8 +245,7 @@  discard block
 block discarded – undo
235 245
 			$notify = true;
236 246
 			addSubscription($subscription_id, $member_id, $found_duration);
237 247
 		}
238
-	}
239
-	else
248
+	} else
240 249
 	{
241 250
 		$actual_cost = $cost['fixed'];
242 251
 
@@ -268,10 +277,10 @@  discard block
 block discarded – undo
268 277
 // Maybe they're cancelling. Some subscriptions may require actively doing something, but PayPal doesn't, for example.
269 278
 elseif ($gatewayClass->isCancellation())
270 279
 {
271
-	if (method_exists($gatewayClass, 'performCancel'))
272
-		$gatewayClass->performCancel($subscription_id, $member_id, $subscription_info);
273
-}
274
-else
280
+	if (method_exists($gatewayClass, 'performCancel')) {
281
+			$gatewayClass->performCancel($subscription_id, $member_id, $subscription_info);
282
+	}
283
+	} else
275 284
 {
276 285
 	// Some other "valid" transaction such as:
277 286
 	//
@@ -308,8 +317,9 @@  discard block
 block discarded – undo
308 317
 	// Maybe we can try to give them the post data?
309 318
 	if (!empty($_POST))
310 319
 	{
311
-		foreach ($_POST as $key => $val)
312
-			$text .= '<br>' . $smcFunc['htmlspecialchars']($key) . ': ' . $smcFunc['htmlspecialchars']($val);
320
+		foreach ($_POST as $key => $val) {
321
+					$text .= '<br>' . $smcFunc['htmlspecialchars']($key) . ': ' . $smcFunc['htmlspecialchars']($val);
322
+		}
313 323
 	}
314 324
 
315 325
 	// Then just log and die.
Please login to merge, or discard this patch.
Themes/default/MessageIndex.template.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@
 block discarded – undo
86 86
 				foreach ($board['children'] as $child)
87 87
 				{
88 88
 					if (!$child['is_redirect'])
89
-						$child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>';
89
+						$child['link'] = '' . ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>';
90 90
 					else
91 91
 						$child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . '">' . $child['name'] . '</a>';
92 92
 
Please login to merge, or discard this patch.
Braces   +94 added lines, -65 removed lines patch added patch discarded remove patch
@@ -48,17 +48,19 @@  discard block
 block discarded – undo
48 48
 						</a>';
49 49
 
50 50
 			// Has it outstanding posts for approval?
51
-			if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics']))
52
-				echo '
51
+			if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics'])) {
52
+							echo '
53 53
 						<a href="', $scripturl, '?action=moderate;area=postmod;sa=', ($board['unapproved_topics'] > 0 ? 'topics' : 'posts'), ';brd=', $board['id'], ';', $context['session_var'], '=', $context['session_id'], '" title="', sprintf($txt['unapproved_posts'], $board['unapproved_topics'], $board['unapproved_posts']), '" class="moderation_link">(!)</a>';
54
+			}
54 55
 
55 56
 			echo '
56 57
 						<p class="board_description">', $board['description'], '</p>';
57 58
 
58 59
 			// Show the "Moderators: ". Each has name, href, link, and id. (but we're gonna use link_moderators.)
59
-			if (!empty($board['moderators']) || !empty($board['moderator_groups']))
60
-				echo '
60
+			if (!empty($board['moderators']) || !empty($board['moderator_groups'])) {
61
+							echo '
61 62
 						<p class="moderators">', count($board['link_moderators']) === 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $board['link_moderators']), '</p>';
63
+			}
62 64
 
63 65
 			// Show some basic information about the number of posts, etc.
64 66
 			echo '
@@ -70,9 +72,10 @@  discard block
 block discarded – undo
70 72
 					</div>
71 73
 					<div class="lastpost lpr_border">';
72 74
 
73
-			if (!empty($board['last_post']['id']))
74
-				echo '
75
+			if (!empty($board['last_post']['id'])) {
76
+							echo '
75 77
 						<p>', $board['last_post']['last_post_message'], '</p>';
78
+			}
76 79
 			echo '
77 80
 					</div>';
78 81
 
@@ -85,14 +88,16 @@  discard block
 block discarded – undo
85 88
 						id, name, description, new (is it new?), topics (#), posts (#), href, link, and last_post. */
86 89
 				foreach ($board['children'] as $child)
87 90
 				{
88
-					if (!$child['is_redirect'])
89
-						$child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>';
90
-					else
91
-						$child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . '">' . $child['name'] . '</a>';
91
+					if (!$child['is_redirect']) {
92
+											$child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>';
93
+					} else {
94
+											$child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . '">' . $child['name'] . '</a>';
95
+					}
92 96
 
93 97
 					// Has it posts awaiting approval?
94
-					if ($child['can_approve_posts'] && ($child['unapproved_posts'] | $child['unapproved_topics']))
95
-						$child['link'] .= ' <a href="' . $scripturl . '?action=moderate;area=postmod;sa=' . ($child['unapproved_topics'] > 0 ? 'topics' : 'posts') . ';brd=' . $child['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" title="' . sprintf($txt['unapproved_posts'], $child['unapproved_topics'], $child['unapproved_posts']) . '" class="moderation_link">(!)</a>';
98
+					if ($child['can_approve_posts'] && ($child['unapproved_posts'] | $child['unapproved_topics'])) {
99
+											$child['link'] .= ' <a href="' . $scripturl . '?action=moderate;area=postmod;sa=' . ($child['unapproved_topics'] > 0 ? 'topics' : 'posts') . ';brd=' . $child['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" title="' . sprintf($txt['unapproved_posts'], $child['unapproved_topics'], $child['unapproved_posts']) . '" class="moderation_link">(!)</a>';
100
+					}
96 101
 
97 102
 					$children[] = $child['new'] ? '<span class="strong">' . $child['link'] . '</span>' : '<span>' . $child['link'] . '</span>';
98 103
 				}
@@ -111,8 +116,9 @@  discard block
 block discarded – undo
111 116
 	}
112 117
 
113 118
 	// They can only mark read if they are logged in and it's enabled!
114
-	if (!$context['user']['is_logged'])
115
-		unset($context['normal_buttons']['markread']);
119
+	if (!$context['user']['is_logged']) {
120
+			unset($context['normal_buttons']['markread']);
121
+	}
116 122
 
117 123
 	if (!$context['no_topic_listing'])
118 124
 	{
@@ -138,13 +144,15 @@  discard block
 block discarded – undo
138 144
 	<div id="description_board" class="generic_list_wrapper">
139 145
 		<h3>', $context['name'], '</h3>
140 146
 		<p>';
141
-	if ($context['description'] != '')
142
-	echo '
147
+	if ($context['description'] != '') {
148
+		echo '
143 149
 		', $context['description'], '&nbsp;';
150
+	}
144 151
 
145
-	if (!empty($context['moderators']))
146
-	echo '
152
+	if (!empty($context['moderators'])) {
153
+		echo '
147 154
 		', count($context['moderators']) === 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $context['link_moderators']), '.';
155
+	}
148 156
 
149 157
 	echo '
150 158
 		</p>
@@ -152,9 +160,10 @@  discard block
 block discarded – undo
152 160
 		}
153 161
 
154 162
 		// If Quick Moderation is enabled start the form.
155
-		if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics']))
156
-			echo '
163
+		if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics'])) {
164
+					echo '
157 165
 	<form action="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], '" method="post" accept-charset="', $context['character_set'], '" class="clear" name="quickModForm" id="quickModForm">';
166
+		}
158 167
 
159 168
 		echo '
160 169
 		<div id="messageindex">';
@@ -162,10 +171,11 @@  discard block
 block discarded – undo
162 171
 		{
163 172
 		echo '
164 173
 			<div class="information">';
165
-			if ($settings['display_who_viewing'] == 1)
166
-				echo count($context['view_members']), ' ', count($context['view_members']) === 1 ? $txt['who_member'] : $txt['members'];
167
-		else
168
-				echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . (empty($context['view_num_hidden']) || $context['can_moderate_forum'] ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
174
+			if ($settings['display_who_viewing'] == 1) {
175
+							echo count($context['view_members']), ' ', count($context['view_members']) === 1 ? $txt['who_member'] : $txt['members'];
176
+			} else {
177
+						echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . (empty($context['view_num_hidden']) || $context['can_moderate_forum'] ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
178
+		}
169 179
 			echo $txt['who_and'], $context['view_num_guests'], ' ', $context['view_num_guests'] == 1 ? $txt['guest'] : $txt['guests'], $txt['who_viewing_board'];
170 180
 
171 181
 		echo '
@@ -184,19 +194,22 @@  discard block
 block discarded – undo
184 194
 					<div class="lastpost">', $context['topics_headers']['last_post'], '</div>';
185 195
 
186 196
 			// Show a "select all" box for quick moderation?
187
-			if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1)
188
-				echo '
197
+			if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1) {
198
+							echo '
189 199
 					<div class="moderation"><input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');"></div>';
200
+			}
190 201
 
191 202
 			// If it's on in "image" mode, don't show anything but the column.
192
-			elseif (!empty($context['can_quick_mod']))
193
-				echo '
203
+			elseif (!empty($context['can_quick_mod'])) {
204
+							echo '
194 205
 					<div class="moderation">&nbsp;</div>';
206
+			}
195 207
 		}
196 208
 		// No topics.... just say, "sorry bub".
197
-		else
198
-			echo '
209
+		else {
210
+					echo '
199 211
 					<h3 class="titlebg">', $txt['topic_alert_none'], '</h3>';
212
+		}
200 213
 
201 214
 		echo '
202 215
 		</div>';
@@ -228,21 +241,26 @@  discard block
 block discarded – undo
228 241
 			// Now we handle the icons
229 242
 			echo '
230 243
 							<div class="icons floatright">';
231
-			if ($topic['is_watched'])
232
-				echo '
244
+			if ($topic['is_watched']) {
245
+							echo '
233 246
 								<span class="generic_icons watch" title="', $txt['watching_this_topic'], '"></span>';
234
-			if ($topic['is_locked'])
235
-				echo '
247
+			}
248
+			if ($topic['is_locked']) {
249
+							echo '
236 250
 								<span class="generic_icons lock"></span>';
237
-			if ($topic['is_sticky'])
238
-				echo '
251
+			}
252
+			if ($topic['is_sticky']) {
253
+							echo '
239 254
 								<span class="generic_icons sticky"></span>';
240
-			if ($topic['is_redirect'])
241
-				echo '
255
+			}
256
+			if ($topic['is_redirect']) {
257
+							echo '
242 258
 								<span class="generic_icons move"></span>';
243
-			if ($topic['is_poll'])
244
-				echo '
259
+			}
260
+			if ($topic['is_poll']) {
261
+							echo '
245 262
 								<span class="generic_icons poll"></span>';
263
+			}
246 264
 			echo '
247 265
 							</div>';
248 266
 
@@ -268,26 +286,31 @@  discard block
 block discarded – undo
268 286
 			{
269 287
 				echo '
270 288
 					<div class="moderation">';
271
-				if ($options['display_quick_mod'] == 1)
272
-					echo '
289
+				if ($options['display_quick_mod'] == 1) {
290
+									echo '
273 291
 						<input type="checkbox" name="topics[]" value="', $topic['id'], '">';
274
-				else
292
+				} else
275 293
 				{
276 294
 					// Check permissions on each and show only the ones they are allowed to use.
277
-					if ($topic['quick_mod']['remove'])
278
-						echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=remove;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons delete" title="', $txt['remove_topic'], '"></span></a>';
295
+					if ($topic['quick_mod']['remove']) {
296
+											echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=remove;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons delete" title="', $txt['remove_topic'], '"></span></a>';
297
+					}
279 298
 
280
-					if ($topic['quick_mod']['lock'])
281
-						echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=lock;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons lock" title="', $topic['is_locked'] ? $txt['set_unlock'] : $txt['set_lock'], '"></span></a>';
299
+					if ($topic['quick_mod']['lock']) {
300
+											echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=lock;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons lock" title="', $topic['is_locked'] ? $txt['set_unlock'] : $txt['set_lock'], '"></span></a>';
301
+					}
282 302
 
283
-					if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove'])
284
-						echo '<br>';
303
+					if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove']) {
304
+											echo '<br>';
305
+					}
285 306
 
286
-					if ($topic['quick_mod']['sticky'])
287
-						echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=sticky;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons sticky" title="', $topic['is_sticky'] ? $txt['set_nonsticky'] : $txt['set_sticky'], '"></span></a>';
307
+					if ($topic['quick_mod']['sticky']) {
308
+											echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=sticky;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons sticky" title="', $topic['is_sticky'] ? $txt['set_nonsticky'] : $txt['set_sticky'], '"></span></a>';
309
+					}
288 310
 
289
-					if ($topic['quick_mod']['move'])
290
-						echo '<a href="', $scripturl, '?action=movetopic;current_board=', $context['current_board'], ';board=', $context['current_board'], '.', $context['start'], ';topic=', $topic['id'], '.0"><span class="generic_icons move" title="', $txt['move_topic'], '"></span></a>';
311
+					if ($topic['quick_mod']['move']) {
312
+											echo '<a href="', $scripturl, '?action=movetopic;current_board=', $context['current_board'], ';board=', $context['current_board'], '.', $context['start'], ';topic=', $topic['id'], '.0"><span class="generic_icons move" title="', $txt['move_topic'], '"></span></a>';
313
+					}
291 314
 				}
292 315
 				echo '
293 316
 					</div>';
@@ -305,18 +328,20 @@  discard block
 block discarded – undo
305 328
 					<select class="qaction" name="qaction"', $context['can_move'] ? ' onchange="this.form.move_to.disabled = (this.options[this.selectedIndex].value != \'move\');"' : '', '>
306 329
 						<option value="">--------</option>';
307 330
 
308
-			foreach ($context['qmod_actions'] as $qmod_action)
309
-				if ($context['can_' . $qmod_action])
331
+			foreach ($context['qmod_actions'] as $qmod_action) {
332
+							if ($context['can_' . $qmod_action])
310 333
 					echo '
311 334
 						<option value="' . $qmod_action . '">' . $txt['quick_mod_' . $qmod_action] . '</option>';
335
+			}
312 336
 
313 337
 			echo '
314 338
 					</select>';
315 339
 
316 340
 			// Show a list of boards they can move the topic to.
317
-			if ($context['can_move'])
318
-				echo '
341
+			if ($context['can_move']) {
342
+							echo '
319 343
 			<span id="quick_mod_jump_to">&nbsp;</span>';
344
+			}
320 345
 
321 346
 			echo '
322 347
 					<input type="submit" value="', $txt['quick_mod_go'], '" onclick="return document.forms.quickModForm.qaction.value != \'\' &amp;&amp; confirm(\'', $txt['quickmod_confirm'], '\');" class="button qaction">
@@ -327,10 +352,11 @@  discard block
 block discarded – undo
327 352
 	</div>';
328 353
 
329 354
 		// Finish off the form - again.
330
-		if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics']))
331
-			echo '
355
+		if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics'])) {
356
+					echo '
332 357
 	<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '">
333 358
 	</form>';
359
+		}
334 360
 
335 361
 	// Mobile action buttons (bottom)
336 362
 	echo '
@@ -352,8 +378,8 @@  discard block
 block discarded – undo
352 378
 	// Show breadcrumbs at the bottom too.
353 379
 	theme_linktree();
354 380
 
355
-	if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']) && $context['can_move'])
356
-		echo '
381
+	if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']) && $context['can_move']) {
382
+			echo '
357 383
 			<script>
358 384
 				if (typeof(window.XMLHttpRequest) != "undefined")
359 385
 					aJumpTo[aJumpTo.length] = new JumpTo({
@@ -372,6 +398,7 @@  discard block
 block discarded – undo
372 398
 						sCustomName: "move_to"
373 399
 					});
374 400
 			</script>';
401
+	}
375 402
 
376 403
 	// Javascript for inline editing.
377 404
 	echo '
@@ -407,8 +434,8 @@  discard block
 block discarded – undo
407 434
 		<div class="information">
408 435
 			<p class="floatright" id="message_index_jump_to">&nbsp;</p>';
409 436
 
410
-	if (empty($context['no_topic_listing']))
411
-		echo '
437
+	if (empty($context['no_topic_listing'])) {
438
+			echo '
412 439
 			<p class="floatleft">', !empty($modSettings['enableParticipation']) && $context['user']['is_logged'] ? '
413 440
 				<img src="' . $settings['images_url'] . '/icons/profile_sm.png" alt="" class="centericon"> ' . $txt['participation_caption'] . '<br>' : '', '
414 441
 				'. ($modSettings['pollMode'] == '1' ? '<span class="generic_icons poll centericon"></span> ' . $txt['poll'] : '') . '<br>
@@ -418,9 +445,10 @@  discard block
 block discarded – undo
418 445
 				<span class="generic_icons lock centericon"></span> ' . $txt['locked_topic'] . '<br>
419 446
 				<span class="generic_icons sticky centericon"></span> ' . $txt['sticky_topic'] . '<br>
420 447
 			</p>';
448
+	}
421 449
 
422
-	if (!empty($context['jump_to']))
423
-		echo '
450
+	if (!empty($context['jump_to'])) {
451
+			echo '
424 452
 			<script>
425 453
 				if (typeof(window.XMLHttpRequest) != "undefined")
426 454
 					aJumpTo[aJumpTo.length] = new JumpTo({
@@ -436,6 +464,7 @@  discard block
 block discarded – undo
436 464
 						sGoButtonLabel: "', $txt['quick_mod_go'], '"
437 465
 					});
438 466
 			</script>';
467
+	}
439 468
 
440 469
 	echo '
441 470
 			<br class="clear">
Please login to merge, or discard this patch.
Sources/Load.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -2259,9 +2259,9 @@  discard block
 block discarded – undo
2259 2259
  *
2260 2260
  * @uses the template_include() function to include the file.
2261 2261
  * @param string $template_name The name of the template to load
2262
- * @param array|string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load
2262
+ * @param string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load
2263 2263
  * @param bool $fatal If true, dies with an error message if the template cannot be found
2264
- * @return boolean Whether or not the template was loaded
2264
+ * @return boolean|null Whether or not the template was loaded
2265 2265
  */
2266 2266
 function loadTemplate($template_name, $style_sheets = array(), $fatal = true)
2267 2267
 {
@@ -2444,7 +2444,7 @@  discard block
 block discarded – undo
2444 2444
  * - all code added with this function is added to the same <style> tag so do make sure your css is valid!
2445 2445
  *
2446 2446
  * @param string $css Some css code
2447
- * @return void|bool Adds the CSS to the $context['css_header'] array or returns if no CSS is specified
2447
+ * @return false|null Adds the CSS to the $context['css_header'] array or returns if no CSS is specified
2448 2448
  */
2449 2449
 function addInlineCss($css)
2450 2450
 {
@@ -2558,7 +2558,7 @@  discard block
 block discarded – undo
2558 2558
  *
2559 2559
  * @param string $javascript Some JS code
2560 2560
  * @param bool $defer Whether the script should load in <head> or before the closing <html> tag
2561
- * @return void|bool Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified
2561
+ * @return false|null Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified
2562 2562
  */
2563 2563
 function addInlineJavaScript($javascript, $defer = false)
2564 2564
 {
@@ -2791,7 +2791,7 @@  discard block
 block discarded – undo
2791 2791
  * It will try to choose only utf8 or non-utf8 languages.
2792 2792
  *
2793 2793
  * @param bool $use_cache Whether or not to use the cache
2794
- * @return array An array of information about available languages
2794
+ * @return string An array of information about available languages
2795 2795
  */
2796 2796
 function getLanguages($use_cache = true)
2797 2797
 {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1719,7 +1719,7 @@
 block discarded – undo
1719 1719
 		$id_theme = $modSettings['theme_guests'];
1720 1720
 
1721 1721
 	// We already load the basic stuff?
1722
-	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme )
1722
+	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme)
1723 1723
 	{
1724 1724
 		// Verify the id_theme... no foul play.
1725 1725
 		// Always allow the board specific theme, if they are overriding.
Please login to merge, or discard this patch.
Braces   +785 added lines, -595 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,28 +48,36 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65 73
 		// We excpiclity do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded.
66
-		if (!is_array($modSettings['attachmentUploadDir']))
67
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
74
+		if (!is_array($modSettings['attachmentUploadDir'])) {
75
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
76
+		}
68 77
 
69
-		if (!empty($cache_enable))
70
-			cache_put_data('modSettings', $modSettings, 90);
78
+		if (!empty($cache_enable)) {
79
+					cache_put_data('modSettings', $modSettings, 90);
80
+		}
71 81
 	}
72 82
 
73 83
 	$modSettings['cache_enable'] = $cache_enable;
@@ -87,8 +97,9 @@  discard block
 block discarded – undo
87 97
 		};
88 98
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
89 99
 	{
90
-		if (!$utf8 || $smcFunc['db_mb4'])
91
-			return $string;
100
+		if (!$utf8 || $smcFunc['db_mb4']) {
101
+					return $string;
102
+		}
92 103
 
93 104
 		$i = 0;
94 105
 		$len = strlen($string);
@@ -100,18 +111,15 @@  discard block
 block discarded – undo
100 111
 			{
101 112
 				$new_string .= $string[$i];
102 113
 				$i++;
103
-			}
104
-			elseif ($ord < 224)
114
+			} elseif ($ord < 224)
105 115
 			{
106 116
 				$new_string .= $string[$i] . $string[$i + 1];
107 117
 				$i += 2;
108
-			}
109
-			elseif ($ord < 240)
118
+			} elseif ($ord < 240)
110 119
 			{
111 120
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
112 121
 				$i += 3;
113
-			}
114
-			elseif ($ord < 248)
122
+			} elseif ($ord < 248)
115 123
 			{
116 124
 				// Magic happens.
117 125
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -155,8 +163,7 @@  discard block
 block discarded – undo
155 163
 			{
156 164
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
157 165
 				return is_int($result) ? $result + $offset : false;
158
-			}
159
-			else
166
+			} else
160 167
 			{
161 168
 				$needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
162 169
 				$needle_size = count($needle_arr);
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 				while ((int) $result === $result)
166 173
 				{
167 174
 					$offset += $result;
168
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
169
-						return $offset;
175
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
176
+											return $offset;
177
+					}
170 178
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
171 179
 				}
172 180
 				return false;
@@ -204,8 +212,9 @@  discard block
 block discarded – undo
204 212
 			$string = $ent_check($string);
205 213
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
206 214
 			$string = $matches[0];
207
-			while (strlen($string) > $length)
208
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
215
+			while (strlen($string) > $length) {
216
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
217
+			}
209 218
 			return $string;
210 219
 		},
211 220
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -215,8 +224,9 @@  discard block
 block discarded – undo
215 224
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
216 225
 		{
217 226
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
218
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
219
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
227
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
228
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
229
+			}
220 230
 			return implode('', $words);
221 231
 		} : 'ucwords',
222 232
 		'json_decode' => 'smf_json_decode',
@@ -224,16 +234,17 @@  discard block
 block discarded – undo
224 234
 	);
225 235
 
226 236
 	// Setting the timezone is a requirement for some functions.
227
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
228
-		date_default_timezone_set($modSettings['default_timezone']);
229
-	else
237
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
238
+			date_default_timezone_set($modSettings['default_timezone']);
239
+	} else
230 240
 	{
231 241
 		// Get PHP's default timezone, if set
232 242
 		$ini_tz = ini_get('date.timezone');
233
-		if (!empty($ini_tz))
234
-			$modSettings['default_timezone'] = $ini_tz;
235
-		else
236
-			$modSettings['default_timezone'] = '';
243
+		if (!empty($ini_tz)) {
244
+					$modSettings['default_timezone'] = $ini_tz;
245
+		} else {
246
+					$modSettings['default_timezone'] = '';
247
+		}
237 248
 
238 249
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
239 250
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -251,22 +262,26 @@  discard block
 block discarded – undo
251 262
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
252 263
 		{
253 264
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
254
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
255
-				$modSettings['load_average'] = (float) $matches[1];
256
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
257
-				$modSettings['load_average'] = (float) $matches[1];
258
-			else
259
-				unset($modSettings['load_average']);
265
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
266
+							$modSettings['load_average'] = (float) $matches[1];
267
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
268
+							$modSettings['load_average'] = (float) $matches[1];
269
+			} else {
270
+							unset($modSettings['load_average']);
271
+			}
260 272
 
261
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
262
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
273
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
274
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
275
+			}
263 276
 		}
264 277
 
265
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
266
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
278
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
279
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
280
+		}
267 281
 
268
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
269
-			display_loadavg_error();
282
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
283
+					display_loadavg_error();
284
+		}
270 285
 	}
271 286
 
272 287
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -287,8 +302,9 @@  discard block
 block discarded – undo
287 302
 	if (defined('SMF_INTEGRATION_SETTINGS'))
288 303
 	{
289 304
 		$integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true);
290
-		foreach ($integration_settings as $hook => $function)
291
-			add_integration_function($hook, $function, '', false);
305
+		foreach ($integration_settings as $hook => $function) {
306
+					add_integration_function($hook, $function, '', false);
307
+		}
292 308
 	}
293 309
 
294 310
 	// Any files to pre include?
@@ -298,8 +314,9 @@  discard block
 block discarded – undo
298 314
 		foreach ($pre_includes as $include)
299 315
 		{
300 316
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
301
-			if (file_exists($include))
302
-				require_once($include);
317
+			if (file_exists($include)) {
318
+							require_once($include);
319
+			}
303 320
 		}
304 321
 	}
305 322
 
@@ -403,27 +420,28 @@  discard block
 block discarded – undo
403 420
 				break;
404 421
 			}
405 422
 		}
423
+	} else {
424
+			$id_member = 0;
406 425
 	}
407
-	else
408
-		$id_member = 0;
409 426
 
410 427
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
411 428
 	{
412 429
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
413 430
 
414
-		if (empty($cookie_data))
415
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
431
+		if (empty($cookie_data)) {
432
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
433
+		}
416 434
 
417 435
 		list ($id_member, $password) = $cookie_data;
418 436
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
419
-	}
420
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
437
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
421 438
 	{
422 439
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
423 440
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
424 441
 
425
-		if (empty($cookie_data))
426
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
442
+		if (empty($cookie_data)) {
443
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
444
+		}
427 445
 
428 446
 		list ($id_member, $password, $login_span) = $cookie_data;
429 447
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -448,24 +466,28 @@  discard block
 block discarded – undo
448 466
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
449 467
 			$smcFunc['db_free_result']($request);
450 468
 
451
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
452
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
469
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
470
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
471
+			}
453 472
 
454
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
455
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
473
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
474
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
475
+			}
456 476
 		}
457 477
 
458 478
 		// Did we find 'im?  If not, junk it.
459 479
 		if (!empty($user_settings))
460 480
 		{
461 481
 			// As much as the password should be right, we can assume the integration set things up.
462
-			if (!empty($already_verified) && $already_verified === true)
463
-				$check = true;
482
+			if (!empty($already_verified) && $already_verified === true) {
483
+							$check = true;
484
+			}
464 485
 			// SHA-512 hash should be 128 characters long.
465
-			elseif (strlen($password) == 128)
466
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
467
-			else
468
-				$check = false;
486
+			elseif (strlen($password) == 128) {
487
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
488
+			} else {
489
+							$check = false;
490
+			}
469 491
 
470 492
 			// Wrong password or not activated - either way, you're going nowhere.
471 493
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
@@ -474,9 +496,9 @@  discard block
 block discarded – undo
474 496
 				setLoginCookie(-3600, 0);
475 497
 				$user_settings = array();
476 498
 			}
499
+		} else {
500
+					$id_member = 0;
477 501
 		}
478
-		else
479
-			$id_member = 0;
480 502
 
481 503
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
482 504
 		if (!empty($id_member))
@@ -505,8 +527,9 @@  discard block
 block discarded – undo
505 527
 
506 528
 					list ($tfamember, $tfasecret) = $tfa_data;
507 529
 
508
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
509
-						$tfasecret = null;
530
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
531
+											$tfasecret = null;
532
+					}
510 533
 				}
511 534
 
512 535
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -526,10 +549,12 @@  discard block
 block discarded – undo
526 549
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
527 550
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
528 551
 		{
529
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
552
+			if ($modSettings['tfa_mode'] == 2) {
553
+				//only do this if we are just forcing SOME membergroups
530 554
 			{
531 555
 				//Build an array of ALL user membergroups.
532 556
 				$full_groups = array($user_settings['id_group']);
557
+			}
533 558
 				if (!empty($user_settings['additional_groups']))
534 559
 				{
535 560
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -549,17 +574,18 @@  discard block
 block discarded – undo
549 574
 				);
550 575
 				$row = $smcFunc['db_fetch_assoc']($request);
551 576
 				$smcFunc['db_free_result']($request);
577
+			} else {
578
+							$row['total'] = 1;
552 579
 			}
553
-			else
554
-				$row['total'] = 1; //simplifies logics in the next "if"
580
+			//simplifies logics in the next "if"
555 581
 
556 582
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
557 583
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
558 584
 
559
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
560
-				redirectexit('action=profile;area=tfasetup;forced');
561
-		}
562
-		else if (!empty($user_settings) && empty($id_member))
585
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
586
+							redirectexit('action=profile;area=tfasetup;forced');
587
+			}
588
+		} else if (!empty($user_settings) && empty($id_member))
563 589
 		{
564 590
 			$user_settings = array();
565 591
 		}
@@ -598,33 +624,37 @@  discard block
 block discarded – undo
598 624
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
599 625
 				$user_settings['last_login'] = time();
600 626
 
601
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
602
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
627
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
628
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
629
+				}
603 630
 
604
-				if (!empty($modSettings['cache_enable']))
605
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
631
+				if (!empty($modSettings['cache_enable'])) {
632
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
633
+				}
606 634
 			}
635
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
636
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
607 637
 		}
608
-		elseif (empty($_SESSION['id_msg_last_visit']))
609
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
610 638
 
611 639
 		$username = $user_settings['member_name'];
612 640
 
613
-		if (empty($user_settings['additional_groups']))
614
-			$user_info = array(
641
+		if (empty($user_settings['additional_groups'])) {
642
+					$user_info = array(
615 643
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
616 644
 			);
617
-		else
618
-			$user_info = array(
645
+		} else {
646
+					$user_info = array(
619 647
 				'groups' => array_merge(
620 648
 					array($user_settings['id_group'], $user_settings['id_post_group']),
621 649
 					explode(',', $user_settings['additional_groups'])
622 650
 				)
623 651
 			);
652
+		}
624 653
 
625 654
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
626
-		foreach ($user_info['groups'] as $k => $v)
627
-			$user_info['groups'][$k] = (int) $v;
655
+		foreach ($user_info['groups'] as $k => $v) {
656
+					$user_info['groups'][$k] = (int) $v;
657
+		}
628 658
 
629 659
 		// This is a logged in user, so definitely not a spider.
630 660
 		$user_info['possibly_robot'] = false;
@@ -638,8 +668,7 @@  discard block
 block discarded – undo
638 668
 			$time_system = new DateTime('now', $tz_system);
639 669
 			$time_user = new DateTime('now', $tz_user);
640 670
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
641
-		}
642
-		else
671
+		} else
643 672
 		{
644 673
 			// !!! Compatibility.
645 674
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -653,8 +682,9 @@  discard block
 block discarded – undo
653 682
 		$user_info = array('groups' => array(-1));
654 683
 		$user_settings = array();
655 684
 
656
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
657
-			$_COOKIE[$cookiename] = '';
685
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
686
+					$_COOKIE[$cookiename] = '';
687
+		}
658 688
 
659 689
 		// Expire the 2FA cookie
660 690
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -671,19 +701,20 @@  discard block
 block discarded – undo
671 701
 		}
672 702
 
673 703
 		// Create a login token if it doesn't exist yet.
674
-		if (!isset($_SESSION['token']['post-login']))
675
-			createToken('login');
676
-		else
677
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
704
+		if (!isset($_SESSION['token']['post-login'])) {
705
+					createToken('login');
706
+		} else {
707
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
708
+		}
678 709
 
679 710
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
680 711
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
681 712
 		{
682 713
 			require_once($sourcedir . '/ManageSearchEngines.php');
683 714
 			$user_info['possibly_robot'] = SpiderCheck();
715
+		} elseif (!empty($modSettings['spider_mode'])) {
716
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
684 717
 		}
685
-		elseif (!empty($modSettings['spider_mode']))
686
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
687 718
 		// If we haven't turned on proper spider hunts then have a guess!
688 719
 		else
689 720
 		{
@@ -731,8 +762,9 @@  discard block
 block discarded – undo
731 762
 	$user_info['groups'] = array_unique($user_info['groups']);
732 763
 
733 764
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
734
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
735
-		unset($user_info['ignoreboards'][$tmp]);
765
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
766
+			unset($user_info['ignoreboards'][$tmp]);
767
+	}
736 768
 
737 769
 	// Allow the user to change their language.
738 770
 	if (!empty($modSettings['userLanguage']))
@@ -745,13 +777,14 @@  discard block
 block discarded – undo
745 777
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
746 778
 
747 779
 			// Make it permanent for members.
748
-			if (!empty($user_info['id']))
749
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
750
-			else
751
-				$_SESSION['language'] = $user_info['language'];
780
+			if (!empty($user_info['id'])) {
781
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
782
+			} else {
783
+							$_SESSION['language'] = $user_info['language'];
784
+			}
785
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
786
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
752 787
 		}
753
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
754
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
755 788
 	}
756 789
 
757 790
 	$temp = build_query_board($user_info['id']);
@@ -814,9 +847,9 @@  discard block
 block discarded – undo
814 847
 		}
815 848
 
816 849
 		// Remember redirection is the key to avoiding fallout from your bosses.
817
-		if (!empty($topic))
818
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
819
-		else
850
+		if (!empty($topic)) {
851
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
852
+		} else
820 853
 		{
821 854
 			loadPermissions();
822 855
 			loadTheme();
@@ -834,10 +867,11 @@  discard block
 block discarded – undo
834 867
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
835 868
 	{
836 869
 		// @todo SLOW?
837
-		if (!empty($topic))
838
-			$temp = cache_get_data('topic_board-' . $topic, 120);
839
-		else
840
-			$temp = cache_get_data('board-' . $board, 120);
870
+		if (!empty($topic)) {
871
+					$temp = cache_get_data('topic_board-' . $topic, 120);
872
+		} else {
873
+					$temp = cache_get_data('board-' . $board, 120);
874
+		}
841 875
 
842 876
 		if (!empty($temp))
843 877
 		{
@@ -875,8 +909,9 @@  discard block
 block discarded – undo
875 909
 			$row = $smcFunc['db_fetch_assoc']($request);
876 910
 
877 911
 			// Set the current board.
878
-			if (!empty($row['id_board']))
879
-				$board = $row['id_board'];
912
+			if (!empty($row['id_board'])) {
913
+							$board = $row['id_board'];
914
+			}
880 915
 
881 916
 			// Basic operating information. (globals... :/)
882 917
 			$board_info = array(
@@ -912,21 +947,23 @@  discard block
 block discarded – undo
912 947
 
913 948
 			do
914 949
 			{
915
-				if (!empty($row['id_moderator']))
916
-					$board_info['moderators'][$row['id_moderator']] = array(
950
+				if (!empty($row['id_moderator'])) {
951
+									$board_info['moderators'][$row['id_moderator']] = array(
917 952
 						'id' => $row['id_moderator'],
918 953
 						'name' => $row['real_name'],
919 954
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
920 955
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
921 956
 					);
957
+				}
922 958
 
923
-				if (!empty($row['id_moderator_group']))
924
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
959
+				if (!empty($row['id_moderator_group'])) {
960
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
925 961
 						'id' => $row['id_moderator_group'],
926 962
 						'name' => $row['group_name'],
927 963
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
928 964
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
929 965
 					);
966
+				}
930 967
 			}
931 968
 			while ($row = $smcFunc['db_fetch_assoc']($request));
932 969
 
@@ -958,12 +995,12 @@  discard block
 block discarded – undo
958 995
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
959 996
 			{
960 997
 				// @todo SLOW?
961
-				if (!empty($topic))
962
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
998
+				if (!empty($topic)) {
999
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1000
+				}
963 1001
 				cache_put_data('board-' . $board, $board_info, 120);
964 1002
 			}
965
-		}
966
-		else
1003
+		} else
967 1004
 		{
968 1005
 			// Otherwise the topic is invalid, there are no moderators, etc.
969 1006
 			$board_info = array(
@@ -977,8 +1014,9 @@  discard block
 block discarded – undo
977 1014
 		$smcFunc['db_free_result']($request);
978 1015
 	}
979 1016
 
980
-	if (!empty($topic))
981
-		$_GET['board'] = (int) $board;
1017
+	if (!empty($topic)) {
1018
+			$_GET['board'] = (int) $board;
1019
+	}
982 1020
 
983 1021
 	if (!empty($board))
984 1022
 	{
@@ -988,10 +1026,12 @@  discard block
 block discarded – undo
988 1026
 		// Now check if the user is a moderator.
989 1027
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
990 1028
 
991
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
992
-			$board_info['error'] = 'access';
993
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
994
-			$board_info['error'] = 'access';
1029
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1030
+					$board_info['error'] = 'access';
1031
+		}
1032
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1033
+					$board_info['error'] = 'access';
1034
+		}
995 1035
 
996 1036
 		// Build up the linktree.
997 1037
 		$context['linktree'] = array_merge(
@@ -1014,8 +1054,9 @@  discard block
 block discarded – undo
1014 1054
 	$context['current_board'] = $board;
1015 1055
 
1016 1056
 	// No posting in redirection boards!
1017
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1018
-		$board_info['error'] == 'post_in_redirect';
1057
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1058
+			$board_info['error'] == 'post_in_redirect';
1059
+	}
1019 1060
 
1020 1061
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1021 1062
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1041,24 +1082,23 @@  discard block
 block discarded – undo
1041 1082
 			ob_end_clean();
1042 1083
 			header('HTTP/1.1 403 Forbidden');
1043 1084
 			die;
1044
-		}
1045
-		elseif ($board_info['error'] == 'post_in_redirect')
1085
+		} elseif ($board_info['error'] == 'post_in_redirect')
1046 1086
 		{
1047 1087
 			// Slightly different error message here...
1048 1088
 			fatal_lang_error('cannot_post_redirect', false);
1049
-		}
1050
-		elseif ($user_info['is_guest'])
1089
+		} elseif ($user_info['is_guest'])
1051 1090
 		{
1052 1091
 			loadLanguage('Errors');
1053 1092
 			is_not_guest($txt['topic_gone']);
1093
+		} else {
1094
+					fatal_lang_error('topic_gone', false);
1054 1095
 		}
1055
-		else
1056
-			fatal_lang_error('topic_gone', false);
1057 1096
 	}
1058 1097
 
1059
-	if ($user_info['is_mod'])
1060
-		$user_info['groups'][] = 3;
1061
-}
1098
+	if ($user_info['is_mod']) {
1099
+			$user_info['groups'][] = 3;
1100
+	}
1101
+	}
1062 1102
 
1063 1103
 /**
1064 1104
  * Load this user's permissions.
@@ -1079,8 +1119,9 @@  discard block
 block discarded – undo
1079 1119
 		asort($cache_groups);
1080 1120
 		$cache_groups = implode(',', $cache_groups);
1081 1121
 		// If it's a spider then cache it different.
1082
-		if ($user_info['possibly_robot'])
1083
-			$cache_groups .= '-spider';
1122
+		if ($user_info['possibly_robot']) {
1123
+					$cache_groups .= '-spider';
1124
+		}
1084 1125
 
1085 1126
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1086 1127
 		{
@@ -1088,9 +1129,9 @@  discard block
 block discarded – undo
1088 1129
 			banPermissions();
1089 1130
 
1090 1131
 			return;
1132
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1133
+					list ($user_info['permissions'], $removals) = $temp;
1091 1134
 		}
1092
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1093
-			list ($user_info['permissions'], $removals) = $temp;
1094 1135
 	}
1095 1136
 
1096 1137
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1112,23 +1153,26 @@  discard block
 block discarded – undo
1112 1153
 		$removals = array();
1113 1154
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1114 1155
 		{
1115
-			if (empty($row['add_deny']))
1116
-				$removals[] = $row['permission'];
1117
-			else
1118
-				$user_info['permissions'][] = $row['permission'];
1156
+			if (empty($row['add_deny'])) {
1157
+							$removals[] = $row['permission'];
1158
+			} else {
1159
+							$user_info['permissions'][] = $row['permission'];
1160
+			}
1119 1161
 		}
1120 1162
 		$smcFunc['db_free_result']($request);
1121 1163
 
1122
-		if (isset($cache_groups))
1123
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1164
+		if (isset($cache_groups)) {
1165
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1166
+		}
1124 1167
 	}
1125 1168
 
1126 1169
 	// Get the board permissions.
1127 1170
 	if (!empty($board))
1128 1171
 	{
1129 1172
 		// Make sure the board (if any) has been loaded by loadBoard().
1130
-		if (!isset($board_info['profile']))
1131
-			fatal_lang_error('no_board');
1173
+		if (!isset($board_info['profile'])) {
1174
+					fatal_lang_error('no_board');
1175
+		}
1132 1176
 
1133 1177
 		$request = $smcFunc['db_query']('', '
1134 1178
 			SELECT permission, add_deny
@@ -1144,20 +1188,23 @@  discard block
 block discarded – undo
1144 1188
 		);
1145 1189
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1146 1190
 		{
1147
-			if (empty($row['add_deny']))
1148
-				$removals[] = $row['permission'];
1149
-			else
1150
-				$user_info['permissions'][] = $row['permission'];
1191
+			if (empty($row['add_deny'])) {
1192
+							$removals[] = $row['permission'];
1193
+			} else {
1194
+							$user_info['permissions'][] = $row['permission'];
1195
+			}
1151 1196
 		}
1152 1197
 		$smcFunc['db_free_result']($request);
1153 1198
 	}
1154 1199
 
1155 1200
 	// Remove all the permissions they shouldn't have ;).
1156
-	if (!empty($modSettings['permission_enable_deny']))
1157
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1201
+	if (!empty($modSettings['permission_enable_deny'])) {
1202
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1203
+	}
1158 1204
 
1159
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1160
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1205
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1206
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1207
+	}
1161 1208
 
1162 1209
 	// Banned?  Watch, don't touch..
1163 1210
 	banPermissions();
@@ -1169,17 +1216,18 @@  discard block
 block discarded – undo
1169 1216
 		{
1170 1217
 			require_once($sourcedir . '/Subs-Auth.php');
1171 1218
 			rebuildModCache();
1219
+		} else {
1220
+					$user_info['mod_cache'] = $_SESSION['mc'];
1172 1221
 		}
1173
-		else
1174
-			$user_info['mod_cache'] = $_SESSION['mc'];
1175 1222
 
1176 1223
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1177 1224
 		// For example this drastically simplifies certain changes to the profile area.
1178 1225
 		$user_info['permissions'][] = 'is_not_guest';
1179 1226
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1180 1227
 		$user_info['permissions'][] = 'profile_view_own';
1181
-		if (in_array('profile_view', $user_info['permissions']))
1182
-			$user_info['permissions'][] = 'profile_view_any';
1228
+		if (in_array('profile_view', $user_info['permissions'])) {
1229
+					$user_info['permissions'][] = 'profile_view_any';
1230
+		}
1183 1231
 	}
1184 1232
 }
1185 1233
 
@@ -1197,8 +1245,9 @@  discard block
 block discarded – undo
1197 1245
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1198 1246
 
1199 1247
 	// Can't just look for no users :P.
1200
-	if (empty($users))
1201
-		return array();
1248
+	if (empty($users)) {
1249
+			return array();
1250
+	}
1202 1251
 
1203 1252
 	// Pass the set value
1204 1253
 	$context['loadMemberContext_set'] = $set;
@@ -1213,8 +1262,9 @@  discard block
 block discarded – undo
1213 1262
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1214 1263
 		{
1215 1264
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1216
-			if ($data == null)
1217
-				continue;
1265
+			if ($data == null) {
1266
+							continue;
1267
+			}
1218 1268
 
1219 1269
 			$loaded_ids[] = $data['id_member'];
1220 1270
 			$user_profile[$data['id_member']] = $data;
@@ -1281,16 +1331,19 @@  discard block
 block discarded – undo
1281 1331
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1282 1332
 
1283 1333
 			// Take care of proxying avatar if required, do this here for maximum reach
1284
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1285
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1334
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1335
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1336
+			}
1286 1337
 
1287 1338
 			// Keep track of the member's normal member group
1288 1339
 			$row['primary_group'] = $row['member_group'];
1289 1340
 
1290
-			if (isset($row['member_ip']))
1291
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1292
-			if (isset($row['member_ip2']))
1293
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1341
+			if (isset($row['member_ip'])) {
1342
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1343
+			}
1344
+			if (isset($row['member_ip2'])) {
1345
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1346
+			}
1294 1347
 			$new_loaded_ids[] = $row['id_member'];
1295 1348
 			$loaded_ids[] = $row['id_member'];
1296 1349
 			$row['options'] = array();
@@ -1309,8 +1362,9 @@  discard block
 block discarded – undo
1309 1362
 				'loaded_ids' => $new_loaded_ids,
1310 1363
 			)
1311 1364
 		);
1312
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1313
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1365
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1366
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1367
+		}
1314 1368
 		$smcFunc['db_free_result']($request);
1315 1369
 	}
1316 1370
 
@@ -1321,10 +1375,11 @@  discard block
 block discarded – undo
1321 1375
 	{
1322 1376
 		foreach ($loaded_ids as $a_member)
1323 1377
 		{
1324
-			if (!empty($user_profile[$a_member]['additional_groups']))
1325
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1326
-			else
1327
-				$groups = array($user_profile[$a_member]['id_group']);
1378
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1379
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1380
+			} else {
1381
+							$groups = array($user_profile[$a_member]['id_group']);
1382
+			}
1328 1383
 
1329 1384
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1330 1385
 
@@ -1337,8 +1392,9 @@  discard block
 block discarded – undo
1337 1392
 
1338 1393
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1339 1394
 	{
1340
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1341
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1395
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1396
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1397
+		}
1342 1398
 	}
1343 1399
 
1344 1400
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1364,14 +1420,17 @@  discard block
 block discarded – undo
1364 1420
 		foreach ($temp_mods as $id)
1365 1421
 		{
1366 1422
 			// By popular demand, don't show admins or global moderators as moderators.
1367
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1368
-				$user_profile[$id]['member_group'] = $row['member_group'];
1423
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1424
+							$user_profile[$id]['member_group'] = $row['member_group'];
1425
+			}
1369 1426
 
1370 1427
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1371
-			if (!empty($row['icons']))
1372
-				$user_profile[$id]['icons'] = $row['icons'];
1373
-			if (!empty($row['member_group_color']))
1374
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1428
+			if (!empty($row['icons'])) {
1429
+							$user_profile[$id]['icons'] = $row['icons'];
1430
+			}
1431
+			if (!empty($row['member_group_color'])) {
1432
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1433
+			}
1375 1434
 		}
1376 1435
 	}
1377 1436
 
@@ -1393,12 +1452,14 @@  discard block
 block discarded – undo
1393 1452
 	static $loadedLanguages = array();
1394 1453
 
1395 1454
 	// If this person's data is already loaded, skip it.
1396
-	if (isset($dataLoaded[$user]))
1397
-		return true;
1455
+	if (isset($dataLoaded[$user])) {
1456
+			return true;
1457
+	}
1398 1458
 
1399 1459
 	// We can't load guests or members not loaded by loadMemberData()!
1400
-	if ($user == 0)
1401
-		return false;
1460
+	if ($user == 0) {
1461
+			return false;
1462
+	}
1402 1463
 	if (!isset($user_profile[$user]))
1403 1464
 	{
1404 1465
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1424,12 +1485,16 @@  discard block
 block discarded – undo
1424 1485
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1425 1486
 
1426 1487
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1427
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1488
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1489
+		//icon is set and exists
1428 1490
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1429
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1491
+	} elseif (isset($profile['icons'][1])) {
1492
+		//icon is set and doesn't exist, fallback to default
1430 1493
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1431
-	else //not set, bye bye
1494
+	} else {
1495
+		//not set, bye bye
1432 1496
 		$group_icon_url = '';
1497
+	}
1433 1498
 
1434 1499
 	// These minimal values are always loaded
1435 1500
 	$memberContext[$user] = array(
@@ -1448,8 +1513,9 @@  discard block
 block discarded – undo
1448 1513
 	if ($context['loadMemberContext_set'] != 'minimal')
1449 1514
 	{
1450 1515
 		// Go the extra mile and load the user's native language name.
1451
-		if (empty($loadedLanguages))
1452
-			$loadedLanguages = getLanguages();
1516
+		if (empty($loadedLanguages)) {
1517
+					$loadedLanguages = getLanguages();
1518
+		}
1453 1519
 
1454 1520
 		$memberContext[$user] += array(
1455 1521
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1504,31 +1570,33 @@  discard block
 block discarded – undo
1504 1570
 	{
1505 1571
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1506 1572
 		{
1507
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1508
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1509
-			else
1510
-				$image = get_gravatar_url($profile['email_address']);
1511
-		}
1512
-		else
1573
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1574
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1575
+			} else {
1576
+							$image = get_gravatar_url($profile['email_address']);
1577
+			}
1578
+		} else
1513 1579
 		{
1514 1580
 			// So it's stored in the member table?
1515 1581
 			if (!empty($profile['avatar']))
1516 1582
 			{
1517 1583
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1584
+			} elseif (!empty($profile['filename'])) {
1585
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1518 1586
 			}
1519
-			elseif (!empty($profile['filename']))
1520
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1521 1587
 			// Right... no avatar...use the default one
1522
-			else
1523
-				$image = $modSettings['avatar_url'] . '/default.png';
1588
+			else {
1589
+							$image = $modSettings['avatar_url'] . '/default.png';
1590
+			}
1524 1591
 		}
1525
-		if (!empty($image))
1526
-			$memberContext[$user]['avatar'] = array(
1592
+		if (!empty($image)) {
1593
+					$memberContext[$user]['avatar'] = array(
1527 1594
 				'name' => $profile['avatar'],
1528 1595
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1529 1596
 				'href' => $image,
1530 1597
 				'url' => $image,
1531 1598
 			);
1599
+		}
1532 1600
 	}
1533 1601
 
1534 1602
 	// Are we also loading the members custom fields into context?
@@ -1536,35 +1604,41 @@  discard block
 block discarded – undo
1536 1604
 	{
1537 1605
 		$memberContext[$user]['custom_fields'] = array();
1538 1606
 
1539
-		if (!isset($context['display_fields']))
1540
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1607
+		if (!isset($context['display_fields'])) {
1608
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1609
+		}
1541 1610
 
1542 1611
 		foreach ($context['display_fields'] as $custom)
1543 1612
 		{
1544
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1545
-				continue;
1613
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1614
+							continue;
1615
+			}
1546 1616
 
1547 1617
 			$value = $profile['options'][$custom['col_name']];
1548 1618
 
1549 1619
 			// Don't show the "disabled" option for the "gender" field.
1550
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1551
-				continue;
1620
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1621
+							continue;
1622
+			}
1552 1623
 
1553 1624
 			// BBC?
1554
-			if ($custom['bbc'])
1555
-				$value = parse_bbc($value);
1625
+			if ($custom['bbc']) {
1626
+							$value = parse_bbc($value);
1627
+			}
1556 1628
 			// ... or checkbox?
1557
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1558
-				$value = $value ? $txt['yes'] : $txt['no'];
1629
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1630
+							$value = $value ? $txt['yes'] : $txt['no'];
1631
+			}
1559 1632
 
1560 1633
 			// Enclosing the user input within some other text?
1561
-			if (!empty($custom['enclose']))
1562
-				$value = strtr($custom['enclose'], array(
1634
+			if (!empty($custom['enclose'])) {
1635
+							$value = strtr($custom['enclose'], array(
1563 1636
 					'{SCRIPTURL}' => $scripturl,
1564 1637
 					'{IMAGES_URL}' => $settings['images_url'],
1565 1638
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1566 1639
 					'{INPUT}' => $value,
1567 1640
 				));
1641
+			}
1568 1642
 
1569 1643
 			$memberContext[$user]['custom_fields'][] = array(
1570 1644
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1591,8 +1665,9 @@  discard block
 block discarded – undo
1591 1665
 	global $smcFunc, $txt, $scripturl, $settings;
1592 1666
 
1593 1667
 	// Do not waste my time...
1594
-	if (empty($users) || empty($params))
1595
-		return false;
1668
+	if (empty($users) || empty($params)) {
1669
+			return false;
1670
+	}
1596 1671
 
1597 1672
 	// Make sure it's an array.
1598 1673
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1616,31 +1691,36 @@  discard block
 block discarded – undo
1616 1691
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1617 1692
 	{
1618 1693
 		// BBC?
1619
-		if (!empty($row['bbc']))
1620
-			$row['value'] = parse_bbc($row['value']);
1694
+		if (!empty($row['bbc'])) {
1695
+					$row['value'] = parse_bbc($row['value']);
1696
+		}
1621 1697
 
1622 1698
 		// ... or checkbox?
1623
-		elseif (isset($row['type']) && $row['type'] == 'check')
1624
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1699
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1700
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1701
+		}
1625 1702
 
1626 1703
 		// Enclosing the user input within some other text?
1627
-		if (!empty($row['enclose']))
1628
-			$row['value'] = strtr($row['enclose'], array(
1704
+		if (!empty($row['enclose'])) {
1705
+					$row['value'] = strtr($row['enclose'], array(
1629 1706
 				'{SCRIPTURL}' => $scripturl,
1630 1707
 				'{IMAGES_URL}' => $settings['images_url'],
1631 1708
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1632 1709
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1633 1710
 			));
1711
+		}
1634 1712
 
1635 1713
 		// Send a simple array if there is just 1 param
1636
-		if (count($params) == 1)
1637
-			$return[$row['id_member']] = $row;
1714
+		if (count($params) == 1) {
1715
+					$return[$row['id_member']] = $row;
1716
+		}
1638 1717
 
1639 1718
 		// More than 1? knock yourself out...
1640 1719
 		else
1641 1720
 		{
1642
-			if (!isset($return[$row['id_member']]))
1643
-				$return[$row['id_member']] = array();
1721
+			if (!isset($return[$row['id_member']])) {
1722
+							$return[$row['id_member']] = array();
1723
+			}
1644 1724
 
1645 1725
 			$return[$row['id_member']][$row['variable']] = $row;
1646 1726
 		}
@@ -1674,8 +1754,9 @@  discard block
 block discarded – undo
1674 1754
 	global $context;
1675 1755
 
1676 1756
 	// Don't know any browser!
1677
-	if (empty($context['browser']))
1678
-		detectBrowser();
1757
+	if (empty($context['browser'])) {
1758
+			detectBrowser();
1759
+	}
1679 1760
 
1680 1761
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1681 1762
 }
@@ -1693,8 +1774,9 @@  discard block
 block discarded – undo
1693 1774
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1694 1775
 
1695 1776
 	// The theme was specified by parameter.
1696
-	if (!empty($id_theme))
1697
-		$id_theme = (int) $id_theme;
1777
+	if (!empty($id_theme)) {
1778
+			$id_theme = (int) $id_theme;
1779
+	}
1698 1780
 	// The theme was specified by REQUEST.
1699 1781
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1700 1782
 	{
@@ -1702,54 +1784,61 @@  discard block
 block discarded – undo
1702 1784
 		$_SESSION['id_theme'] = $id_theme;
1703 1785
 	}
1704 1786
 	// The theme was specified by REQUEST... previously.
1705
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1706
-		$id_theme = (int) $_SESSION['id_theme'];
1787
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1788
+			$id_theme = (int) $_SESSION['id_theme'];
1789
+	}
1707 1790
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1708
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1709
-		$id_theme = $user_info['theme'];
1791
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1792
+			$id_theme = $user_info['theme'];
1793
+	}
1710 1794
 	// The theme was specified by the board.
1711
-	elseif (!empty($board_info['theme']))
1712
-		$id_theme = $board_info['theme'];
1795
+	elseif (!empty($board_info['theme'])) {
1796
+			$id_theme = $board_info['theme'];
1797
+	}
1713 1798
 	// The theme is the forum's default.
1714
-	else
1715
-		$id_theme = $modSettings['theme_guests'];
1799
+	else {
1800
+			$id_theme = $modSettings['theme_guests'];
1801
+	}
1716 1802
 
1717 1803
 	// We already load the basic stuff?
1718 1804
 	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme )
1719 1805
 	{
1720 1806
 		// Verify the id_theme... no foul play.
1721 1807
 		// Always allow the board specific theme, if they are overriding.
1722
-		if (!empty($board_info['theme']) && $board_info['override_theme'])
1723
-			$id_theme = $board_info['theme'];
1808
+		if (!empty($board_info['theme']) && $board_info['override_theme']) {
1809
+					$id_theme = $board_info['theme'];
1810
+		}
1724 1811
 		// If they have specified a particular theme to use with SSI allow it to be used.
1725
-		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1726
-			$id_theme = (int) $id_theme;
1727
-		elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1812
+		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1813
+					$id_theme = (int) $id_theme;
1814
+		} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1728 1815
 		{
1729 1816
 			$themes = explode(',', $modSettings['enableThemes']);
1730
-			if (!in_array($id_theme, $themes))
1731
-				$id_theme = $modSettings['theme_guests'];
1732
-			else
1733
-				$id_theme = (int) $id_theme;
1817
+			if (!in_array($id_theme, $themes)) {
1818
+							$id_theme = $modSettings['theme_guests'];
1819
+			} else {
1820
+							$id_theme = (int) $id_theme;
1821
+			}
1822
+		} else {
1823
+					$id_theme = (int) $id_theme;
1734 1824
 		}
1735
-		else
1736
-			$id_theme = (int) $id_theme;
1737 1825
 
1738 1826
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1739 1827
 
1740 1828
 		// Disable image proxy if we don't have SSL enabled
1741
-		if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1742
-			$image_proxy_enabled = false;
1829
+		if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1830
+					$image_proxy_enabled = false;
1831
+		}
1743 1832
 
1744 1833
 		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1745 1834
 		{
1746 1835
 			$themeData = $temp;
1747 1836
 			$flag = true;
1837
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1838
+					$themeData = $temp + array($member => array());
1839
+		} else {
1840
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1748 1841
 		}
1749
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1750
-			$themeData = $temp + array($member => array());
1751
-		else
1752
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1753 1842
 
1754 1843
 		if (empty($flag))
1755 1844
 		{
@@ -1768,31 +1857,37 @@  discard block
 block discarded – undo
1768 1857
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1769 1858
 			{
1770 1859
 				// There are just things we shouldn't be able to change as members.
1771
-				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1772
-					continue;
1860
+				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1861
+									continue;
1862
+				}
1773 1863
 
1774 1864
 				// If this is the theme_dir of the default theme, store it.
1775
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1776
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1865
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1866
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1867
+				}
1777 1868
 
1778 1869
 				// If this isn't set yet, is a theme option, or is not the default theme..
1779
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1780
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1870
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1871
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1872
+				}
1781 1873
 			}
1782 1874
 			$smcFunc['db_free_result']($result);
1783 1875
 
1784
-			if (!empty($themeData[-1]))
1785
-				foreach ($themeData[-1] as $k => $v)
1876
+			if (!empty($themeData[-1])) {
1877
+							foreach ($themeData[-1] as $k => $v)
1786 1878
 				{
1787 1879
 					if (!isset($themeData[$member][$k]))
1788 1880
 						$themeData[$member][$k] = $v;
1881
+			}
1789 1882
 				}
1790 1883
 
1791
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1792
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1884
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1885
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1886
+			}
1793 1887
 			// Only if we didn't already load that part of the cache...
1794
-			elseif (!isset($temp))
1795
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1888
+			elseif (!isset($temp)) {
1889
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1890
+			}
1796 1891
 		}
1797 1892
 
1798 1893
 		$settings = $themeData[0];
@@ -1809,22 +1904,26 @@  discard block
 block discarded – undo
1809 1904
 		$settings['template_dirs'][] = $settings['theme_dir'];
1810 1905
 
1811 1906
 		// Based on theme (if there is one).
1812
-		if (!empty($settings['base_theme_dir']))
1813
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1907
+		if (!empty($settings['base_theme_dir'])) {
1908
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1909
+		}
1814 1910
 
1815 1911
 		// Lastly the default theme.
1816
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1817
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1912
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1913
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1914
+		}
1818 1915
 	}
1819 1916
 	
1820 1917
 
1821
-	if (!$initialize)
1822
-		return;
1918
+	if (!$initialize) {
1919
+			return;
1920
+	}
1823 1921
 
1824 1922
 	// Check to see if we're forcing SSL
1825 1923
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1826
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1827
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1924
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1925
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1926
+	}
1828 1927
 
1829 1928
 	// Check to see if they're accessing it from the wrong place.
1830 1929
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1832,8 +1931,9 @@  discard block
 block discarded – undo
1832 1931
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1833 1932
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1834 1933
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1835
-		if ($temp != '/')
1836
-			$detected_url .= $temp;
1934
+		if ($temp != '/') {
1935
+					$detected_url .= $temp;
1936
+		}
1837 1937
 	}
1838 1938
 	if (isset($detected_url) && $detected_url != $boardurl)
1839 1939
 	{
@@ -1845,8 +1945,9 @@  discard block
 block discarded – undo
1845 1945
 			foreach ($aliases as $alias)
1846 1946
 			{
1847 1947
 				// Rip off all the boring parts, spaces, etc.
1848
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1849
-					$do_fix = true;
1948
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1949
+									$do_fix = true;
1950
+				}
1850 1951
 			}
1851 1952
 		}
1852 1953
 
@@ -1854,20 +1955,22 @@  discard block
 block discarded – undo
1854 1955
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1855 1956
 		{
1856 1957
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1857
-			if (empty($_GET))
1858
-				redirectexit('wwwRedirect');
1859
-			else
1958
+			if (empty($_GET)) {
1959
+							redirectexit('wwwRedirect');
1960
+			} else
1860 1961
 			{
1861 1962
 				list ($k, $v) = each($_GET);
1862 1963
 
1863
-				if ($k != 'wwwRedirect')
1864
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1964
+				if ($k != 'wwwRedirect') {
1965
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1966
+				}
1865 1967
 			}
1866 1968
 		}
1867 1969
 
1868 1970
 		// #3 is just a check for SSL...
1869
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1870
-			$do_fix = true;
1971
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1972
+					$do_fix = true;
1973
+		}
1871 1974
 
1872 1975
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1873 1976
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1901,8 +2004,9 @@  discard block
 block discarded – undo
1901 2004
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1902 2005
 				}
1903 2006
 			}
1904
-			foreach ($context['linktree'] as $k => $dummy)
1905
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2007
+			foreach ($context['linktree'] as $k => $dummy) {
2008
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2009
+			}
1906 2010
 		}
1907 2011
 	}
1908 2012
 	// Set up the contextual user array.
@@ -1921,16 +2025,16 @@  discard block
 block discarded – undo
1921 2025
 			'email' => $user_info['email'],
1922 2026
 			'ignoreusers' => $user_info['ignoreusers'],
1923 2027
 		);
1924
-		if (!$context['user']['is_guest'])
1925
-			$context['user']['name'] = $user_info['name'];
1926
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1927
-			$context['user']['name'] = $txt['guest_title'];
2028
+		if (!$context['user']['is_guest']) {
2029
+					$context['user']['name'] = $user_info['name'];
2030
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2031
+					$context['user']['name'] = $txt['guest_title'];
2032
+		}
1928 2033
 
1929 2034
 		// Determine the current smiley set.
1930 2035
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1931 2036
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1932
-	}
1933
-	else
2037
+	} else
1934 2038
 	{
1935 2039
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1936 2040
 		$context['user'] = array(
@@ -1964,18 +2068,24 @@  discard block
 block discarded – undo
1964 2068
 	}
1965 2069
 
1966 2070
 	// Some basic information...
1967
-	if (!isset($context['html_headers']))
1968
-		$context['html_headers'] = '';
1969
-	if (!isset($context['javascript_files']))
1970
-		$context['javascript_files'] = array();
1971
-	if (!isset($context['css_files']))
1972
-		$context['css_files'] = array();
1973
-	if (!isset($context['css_header']))
1974
-		$context['css_header'] = array();
1975
-	if (!isset($context['javascript_inline']))
1976
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1977
-	if (!isset($context['javascript_vars']))
1978
-		$context['javascript_vars'] = array();
2071
+	if (!isset($context['html_headers'])) {
2072
+			$context['html_headers'] = '';
2073
+	}
2074
+	if (!isset($context['javascript_files'])) {
2075
+			$context['javascript_files'] = array();
2076
+	}
2077
+	if (!isset($context['css_files'])) {
2078
+			$context['css_files'] = array();
2079
+	}
2080
+	if (!isset($context['css_header'])) {
2081
+			$context['css_header'] = array();
2082
+	}
2083
+	if (!isset($context['javascript_inline'])) {
2084
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2085
+	}
2086
+	if (!isset($context['javascript_vars'])) {
2087
+			$context['javascript_vars'] = array();
2088
+	}
1979 2089
 
1980 2090
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1981 2091
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1987,16 +2097,18 @@  discard block
 block discarded – undo
1987 2097
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1988 2098
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1989 2099
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1990
-	if (isset($modSettings['load_average']))
1991
-		$context['load_average'] = $modSettings['load_average'];
2100
+	if (isset($modSettings['load_average'])) {
2101
+			$context['load_average'] = $modSettings['load_average'];
2102
+	}
1992 2103
 
1993 2104
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1994 2105
 	detectBrowser();
1995 2106
 
1996 2107
 	// Set the top level linktree up.
1997 2108
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
1998
-	if (empty($context['linktree']))
1999
-		$context['linktree'] = array();
2109
+	if (empty($context['linktree'])) {
2110
+			$context['linktree'] = array();
2111
+	}
2000 2112
 	array_unshift($context['linktree'], array(
2001 2113
 		'url' => $scripturl,
2002 2114
 		'name' => $context['forum_name_html_safe']
@@ -2005,8 +2117,9 @@  discard block
 block discarded – undo
2005 2117
 	// This allows sticking some HTML on the page output - useful for controls.
2006 2118
 	$context['insert_after_template'] = '';
2007 2119
 
2008
-	if (!isset($txt))
2009
-		$txt = array();
2120
+	if (!isset($txt)) {
2121
+			$txt = array();
2122
+	}
2010 2123
 
2011 2124
 	$simpleActions = array(
2012 2125
 		'findmember',
@@ -2052,9 +2165,10 @@  discard block
 block discarded – undo
2052 2165
 
2053 2166
 	// See if theres any extra param to check.
2054 2167
 	$requiresXML = false;
2055
-	foreach ($extraParams as $key => $extra)
2056
-		if (isset($_REQUEST[$extra]))
2168
+	foreach ($extraParams as $key => $extra) {
2169
+			if (isset($_REQUEST[$extra]))
2057 2170
 			$requiresXML = true;
2171
+	}
2058 2172
 
2059 2173
 	// Output is fully XML, so no need for the index template.
2060 2174
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2069,37 +2183,39 @@  discard block
 block discarded – undo
2069 2183
 	{
2070 2184
 		loadLanguage('index+Modifications');
2071 2185
 		$context['template_layers'] = array();
2072
-	}
2073
-
2074
-	else
2186
+	} else
2075 2187
 	{
2076 2188
 		// Custom templates to load, or just default?
2077
-		if (isset($settings['theme_templates']))
2078
-			$templates = explode(',', $settings['theme_templates']);
2079
-		else
2080
-			$templates = array('index');
2189
+		if (isset($settings['theme_templates'])) {
2190
+					$templates = explode(',', $settings['theme_templates']);
2191
+		} else {
2192
+					$templates = array('index');
2193
+		}
2081 2194
 
2082 2195
 		// Load each template...
2083
-		foreach ($templates as $template)
2084
-			loadTemplate($template);
2196
+		foreach ($templates as $template) {
2197
+					loadTemplate($template);
2198
+		}
2085 2199
 
2086 2200
 		// ...and attempt to load their associated language files.
2087 2201
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2088 2202
 		loadLanguage($required_files, '', false);
2089 2203
 
2090 2204
 		// Custom template layers?
2091
-		if (isset($settings['theme_layers']))
2092
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2093
-		else
2094
-			$context['template_layers'] = array('html', 'body');
2205
+		if (isset($settings['theme_layers'])) {
2206
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2207
+		} else {
2208
+					$context['template_layers'] = array('html', 'body');
2209
+		}
2095 2210
 	}
2096 2211
 
2097 2212
 	// Initialize the theme.
2098 2213
 	loadSubTemplate('init', 'ignore');
2099 2214
 
2100 2215
 	// Allow overriding the board wide time/number formats.
2101
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2102
-		$user_info['time_format'] = $txt['time_format'];
2216
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2217
+			$user_info['time_format'] = $txt['time_format'];
2218
+	}
2103 2219
 
2104 2220
 	// Set the character set from the template.
2105 2221
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2107,12 +2223,14 @@  discard block
 block discarded – undo
2107 2223
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2108 2224
 
2109 2225
 	// Guests may still need a name.
2110
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2111
-		$context['user']['name'] = $txt['guest_title'];
2226
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2227
+			$context['user']['name'] = $txt['guest_title'];
2228
+	}
2112 2229
 
2113 2230
 	// Any theme-related strings that need to be loaded?
2114
-	if (!empty($settings['require_theme_strings']))
2115
-		loadLanguage('ThemeStrings', '', false);
2231
+	if (!empty($settings['require_theme_strings'])) {
2232
+			loadLanguage('ThemeStrings', '', false);
2233
+	}
2116 2234
 
2117 2235
 	// Make a special URL for the language.
2118 2236
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2123,8 +2241,9 @@  discard block
 block discarded – undo
2123 2241
 	// Here is my luvly Responsive CSS
2124 2242
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2125 2243
 
2126
-	if ($context['right_to_left'])
2127
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2244
+	if ($context['right_to_left']) {
2245
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2246
+	}
2128 2247
 
2129 2248
 	// We allow theme variants, because we're cool.
2130 2249
 	$context['theme_variant'] = '';
@@ -2132,14 +2251,17 @@  discard block
 block discarded – undo
2132 2251
 	if (!empty($settings['theme_variants']))
2133 2252
 	{
2134 2253
 		// Overriding - for previews and that ilk.
2135
-		if (!empty($_REQUEST['variant']))
2136
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2254
+		if (!empty($_REQUEST['variant'])) {
2255
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2256
+		}
2137 2257
 		// User selection?
2138
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2139
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2258
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2259
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2260
+		}
2140 2261
 		// If not a user variant, select the default.
2141
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2142
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2262
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2263
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2264
+		}
2143 2265
 
2144 2266
 		// Do this to keep things easier in the templates.
2145 2267
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2148,20 +2270,23 @@  discard block
 block discarded – undo
2148 2270
 		if (!empty($context['theme_variant']))
2149 2271
 		{
2150 2272
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2151
-			if ($context['right_to_left'])
2152
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2273
+			if ($context['right_to_left']) {
2274
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2275
+			}
2153 2276
 		}
2154 2277
 	}
2155 2278
 
2156 2279
 	// Let's be compatible with old themes!
2157
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2158
-		$context['template_layers'] = array('main');
2280
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2281
+			$context['template_layers'] = array('main');
2282
+	}
2159 2283
 
2160 2284
 	$context['tabindex'] = 1;
2161 2285
 
2162 2286
 	// Compatibility.
2163
-	if (!isset($settings['theme_version']))
2164
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2287
+	if (!isset($settings['theme_version'])) {
2288
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2289
+	}
2165 2290
 
2166 2291
 	// Default JS variables for use in every theme
2167 2292
 	$context['javascript_vars'] = array(
@@ -2180,18 +2305,18 @@  discard block
 block discarded – undo
2180 2305
 	);
2181 2306
 
2182 2307
 	// Add the JQuery library to the list of files to load.
2183
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2184
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2185
-
2186
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2187
-		loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2188
-
2189
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2190
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2308
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2309
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2310
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2311
+			loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2312
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2313
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2314
+	}
2191 2315
 
2192 2316
 	// Auto loading? template_javascript() will take care of the local half of this.
2193
-	else
2194
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2317
+	else {
2318
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2319
+	}
2195 2320
 
2196 2321
 	// Queue our JQuery plugins!
2197 2322
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2214,12 +2339,12 @@  discard block
 block discarded – undo
2214 2339
 			require_once($sourcedir . '/ScheduledTasks.php');
2215 2340
 
2216 2341
 			// What to do, what to do?!
2217
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2218
-				AutoTask();
2219
-			else
2220
-				ReduceMailQueue();
2221
-		}
2222
-		else
2342
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2343
+							AutoTask();
2344
+			} else {
2345
+							ReduceMailQueue();
2346
+			}
2347
+		} else
2223 2348
 		{
2224 2349
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2225 2350
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2270,8 +2395,9 @@  discard block
 block discarded – undo
2270 2395
 		foreach ($theme_includes as $include)
2271 2396
 		{
2272 2397
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2273
-			if (file_exists($include))
2274
-				require_once($include);
2398
+			if (file_exists($include)) {
2399
+							require_once($include);
2400
+			}
2275 2401
 		}
2276 2402
 	}
2277 2403
 
@@ -2301,16 +2427,19 @@  discard block
 block discarded – undo
2301 2427
 	// Do any style sheets first, cause we're easy with those.
2302 2428
 	if (!empty($style_sheets))
2303 2429
 	{
2304
-		if (!is_array($style_sheets))
2305
-			$style_sheets = array($style_sheets);
2430
+		if (!is_array($style_sheets)) {
2431
+					$style_sheets = array($style_sheets);
2432
+		}
2306 2433
 
2307
-		foreach ($style_sheets as $sheet)
2308
-			loadCSSFile($sheet . '.css', array(), $sheet);
2434
+		foreach ($style_sheets as $sheet) {
2435
+					loadCSSFile($sheet . '.css', array(), $sheet);
2436
+		}
2309 2437
 	}
2310 2438
 
2311 2439
 	// No template to load?
2312
-	if ($template_name === false)
2313
-		return true;
2440
+	if ($template_name === false) {
2441
+			return true;
2442
+	}
2314 2443
 
2315 2444
 	$loaded = false;
2316 2445
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2325,12 +2454,14 @@  discard block
 block discarded – undo
2325 2454
 
2326 2455
 	if ($loaded)
2327 2456
 	{
2328
-		if ($db_show_debug === true)
2329
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2457
+		if ($db_show_debug === true) {
2458
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2459
+		}
2330 2460
 
2331 2461
 		// If they have specified an initialization function for this template, go ahead and call it now.
2332
-		if (function_exists('template_' . $template_name . '_init'))
2333
-			call_user_func('template_' . $template_name . '_init');
2462
+		if (function_exists('template_' . $template_name . '_init')) {
2463
+					call_user_func('template_' . $template_name . '_init');
2464
+		}
2334 2465
 	}
2335 2466
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2336 2467
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2350,13 +2481,14 @@  discard block
 block discarded – undo
2350 2481
 		loadTemplate($template_name);
2351 2482
 	}
2352 2483
 	// Cause an error otherwise.
2353
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2354
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2355
-	elseif ($fatal)
2356
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2357
-	else
2358
-		return false;
2359
-}
2484
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2485
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2486
+	} elseif ($fatal) {
2487
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2488
+	} else {
2489
+			return false;
2490
+	}
2491
+	}
2360 2492
 
2361 2493
 /**
2362 2494
  * Load a sub-template.
@@ -2374,17 +2506,19 @@  discard block
 block discarded – undo
2374 2506
 {
2375 2507
 	global $context, $txt, $db_show_debug;
2376 2508
 
2377
-	if ($db_show_debug === true)
2378
-		$context['debug']['sub_templates'][] = $sub_template_name;
2509
+	if ($db_show_debug === true) {
2510
+			$context['debug']['sub_templates'][] = $sub_template_name;
2511
+	}
2379 2512
 
2380 2513
 	// Figure out what the template function is named.
2381 2514
 	$theme_function = 'template_' . $sub_template_name;
2382
-	if (function_exists($theme_function))
2383
-		$theme_function();
2384
-	elseif ($fatal === false)
2385
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2386
-	elseif ($fatal !== 'ignore')
2387
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2515
+	if (function_exists($theme_function)) {
2516
+			$theme_function();
2517
+	} elseif ($fatal === false) {
2518
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2519
+	} elseif ($fatal !== 'ignore') {
2520
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2521
+	}
2388 2522
 
2389 2523
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2390 2524
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2421,8 +2555,9 @@  discard block
 block discarded – undo
2421 2555
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2422 2556
 
2423 2557
 	// If this is an external file, automatically set this to false.
2424
-	if (!empty($params['external']))
2425
-		$params['minimize'] = false;
2558
+	if (!empty($params['external'])) {
2559
+			$params['minimize'] = false;
2560
+	}
2426 2561
 
2427 2562
 	// Account for shorthand like admin.css?alp21 filenames
2428 2563
 	$has_seed = strpos($fileName, '.css?');
@@ -2439,13 +2574,10 @@  discard block
 block discarded – undo
2439 2574
 			{
2440 2575
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2441 2576
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2577
+			} else {
2578
+							$fileUrl = false;
2442 2579
 			}
2443
-
2444
-			else
2445
-				$fileUrl = false;
2446
-		}
2447
-
2448
-		else
2580
+		} else
2449 2581
 		{
2450 2582
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2451 2583
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2460,12 +2592,14 @@  discard block
 block discarded – undo
2460 2592
 	}
2461 2593
 
2462 2594
 	// Add it to the array for use in the template
2463
-	if (!empty($fileName))
2464
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2595
+	if (!empty($fileName)) {
2596
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2597
+	}
2465 2598
 
2466
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2467
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2468
-}
2599
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2600
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2601
+	}
2602
+	}
2469 2603
 
2470 2604
 /**
2471 2605
  * Add a block of inline css code to be executed later
@@ -2482,8 +2616,9 @@  discard block
 block discarded – undo
2482 2616
 	global $context;
2483 2617
 
2484 2618
 	// Gotta add something...
2485
-	if (empty($css))
2486
-		return false;
2619
+	if (empty($css)) {
2620
+			return false;
2621
+	}
2487 2622
 
2488 2623
 	$context['css_header'][] = $css;
2489 2624
 }
@@ -2518,8 +2653,9 @@  discard block
 block discarded – undo
2518 2653
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2519 2654
 
2520 2655
 	// If this is an external file, automatically set this to false.
2521
-	if (!empty($params['external']))
2522
-		$params['minimize'] = false;
2656
+	if (!empty($params['external'])) {
2657
+			$params['minimize'] = false;
2658
+	}
2523 2659
 
2524 2660
 	// Account for shorthand like admin.js?alp21 filenames
2525 2661
 	$has_seed = strpos($fileName, '.js?');
@@ -2536,16 +2672,12 @@  discard block
 block discarded – undo
2536 2672
 			{
2537 2673
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2538 2674
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2539
-			}
2540
-
2541
-			else
2675
+			} else
2542 2676
 			{
2543 2677
 				$fileUrl = false;
2544 2678
 				$filePath = false;
2545 2679
 			}
2546
-		}
2547
-
2548
-		else
2680
+		} else
2549 2681
 		{
2550 2682
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2551 2683
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2560,9 +2692,10 @@  discard block
 block discarded – undo
2560 2692
 	}
2561 2693
 
2562 2694
 	// Add it to the array for use in the template
2563
-	if (!empty($fileName))
2564
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2565
-}
2695
+	if (!empty($fileName)) {
2696
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2697
+	}
2698
+	}
2566 2699
 
2567 2700
 /**
2568 2701
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2576,9 +2709,10 @@  discard block
 block discarded – undo
2576 2709
 {
2577 2710
 	global $context;
2578 2711
 
2579
-	if (!empty($key) && (!empty($value) || $value === '0'))
2580
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2581
-}
2712
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2713
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2714
+	}
2715
+	}
2582 2716
 
2583 2717
 /**
2584 2718
  * Add a block of inline Javascript code to be executed later
@@ -2595,8 +2729,9 @@  discard block
 block discarded – undo
2595 2729
 {
2596 2730
 	global $context;
2597 2731
 
2598
-	if (empty($javascript))
2599
-		return false;
2732
+	if (empty($javascript)) {
2733
+			return false;
2734
+	}
2600 2735
 
2601 2736
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2602 2737
 }
@@ -2617,15 +2752,18 @@  discard block
 block discarded – undo
2617 2752
 	static $already_loaded = array();
2618 2753
 
2619 2754
 	// Default to the user's language.
2620
-	if ($lang == '')
2621
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2755
+	if ($lang == '') {
2756
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2757
+	}
2622 2758
 
2623 2759
 	// Do we want the English version of language file as fallback?
2624
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2625
-		loadLanguage($template_name, 'english', false);
2760
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2761
+			loadLanguage($template_name, 'english', false);
2762
+	}
2626 2763
 
2627
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2628
-		return $lang;
2764
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2765
+			return $lang;
2766
+	}
2629 2767
 
2630 2768
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2631 2769
 	if (empty($settings['default_theme_dir']))
@@ -2636,8 +2774,9 @@  discard block
 block discarded – undo
2636 2774
 
2637 2775
 	// What theme are we in?
2638 2776
 	$theme_name = basename($settings['theme_url']);
2639
-	if (empty($theme_name))
2640
-		$theme_name = 'unknown';
2777
+	if (empty($theme_name)) {
2778
+			$theme_name = 'unknown';
2779
+	}
2641 2780
 
2642 2781
 	// For each file open it up and write it out!
2643 2782
 	foreach (explode('+', $template_name) as $template)
@@ -2679,8 +2818,9 @@  discard block
 block discarded – undo
2679 2818
 				$found = true;
2680 2819
 
2681 2820
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2682
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2683
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2821
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2822
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2823
+				}
2684 2824
 
2685 2825
 				break;
2686 2826
 			}
@@ -2720,8 +2860,9 @@  discard block
 block discarded – undo
2720 2860
 	}
2721 2861
 
2722 2862
 	// Keep track of what we're up to soldier.
2723
-	if ($db_show_debug === true)
2724
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2863
+	if ($db_show_debug === true) {
2864
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2865
+	}
2725 2866
 
2726 2867
 	// Remember what we have loaded, and in which language.
2727 2868
 	$already_loaded[$template_name] = $lang;
@@ -2767,8 +2908,9 @@  discard block
 block discarded – undo
2767 2908
 				)
2768 2909
 			);
2769 2910
 			// In the EXTREMELY unlikely event this happens, give an error message.
2770
-			if ($smcFunc['db_num_rows']($result) == 0)
2771
-				fatal_lang_error('parent_not_found', 'critical');
2911
+			if ($smcFunc['db_num_rows']($result) == 0) {
2912
+							fatal_lang_error('parent_not_found', 'critical');
2913
+			}
2772 2914
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2773 2915
 			{
2774 2916
 				if (!isset($boards[$row['id_board']]))
@@ -2785,8 +2927,8 @@  discard block
 block discarded – undo
2785 2927
 					);
2786 2928
 				}
2787 2929
 				// If a moderator exists for this board, add that moderator for all children too.
2788
-				if (!empty($row['id_moderator']))
2789
-					foreach ($boards as $id => $dummy)
2930
+				if (!empty($row['id_moderator'])) {
2931
+									foreach ($boards as $id => $dummy)
2790 2932
 					{
2791 2933
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2792 2934
 							'id' => $row['id_moderator'],
@@ -2794,11 +2936,12 @@  discard block
 block discarded – undo
2794 2936
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2795 2937
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2796 2938
 						);
2939
+				}
2797 2940
 					}
2798 2941
 
2799 2942
 				// If a moderator group exists for this board, add that moderator group for all children too
2800
-				if (!empty($row['id_moderator_group']))
2801
-					foreach ($boards as $id => $dummy)
2943
+				if (!empty($row['id_moderator_group'])) {
2944
+									foreach ($boards as $id => $dummy)
2802 2945
 					{
2803 2946
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2804 2947
 							'id' => $row['id_moderator_group'],
@@ -2806,6 +2949,7 @@  discard block
 block discarded – undo
2806 2949
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2807 2950
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2808 2951
 						);
2952
+				}
2809 2953
 					}
2810 2954
 			}
2811 2955
 			$smcFunc['db_free_result']($result);
@@ -2832,23 +2976,27 @@  discard block
 block discarded – undo
2832 2976
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2833 2977
 	{
2834 2978
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2835
-		if (empty($smcFunc['ucwords']))
2836
-			reloadSettings();
2979
+		if (empty($smcFunc['ucwords'])) {
2980
+					reloadSettings();
2981
+		}
2837 2982
 
2838 2983
 		// If we don't have our theme information yet, let's get it.
2839
-		if (empty($settings['default_theme_dir']))
2840
-			loadTheme(0, false);
2984
+		if (empty($settings['default_theme_dir'])) {
2985
+					loadTheme(0, false);
2986
+		}
2841 2987
 
2842 2988
 		// Default language directories to try.
2843 2989
 		$language_directories = array(
2844 2990
 			$settings['default_theme_dir'] . '/languages',
2845 2991
 		);
2846
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2847
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2992
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2993
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2994
+		}
2848 2995
 
2849 2996
 		// We possibly have a base theme directory.
2850
-		if (!empty($settings['base_theme_dir']))
2851
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2997
+		if (!empty($settings['base_theme_dir'])) {
2998
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2999
+		}
2852 3000
 
2853 3001
 		// Remove any duplicates.
2854 3002
 		$language_directories = array_unique($language_directories);
@@ -2862,20 +3010,21 @@  discard block
 block discarded – undo
2862 3010
 		foreach ($language_directories as $language_dir)
2863 3011
 		{
2864 3012
 			// Can't look in here... doesn't exist!
2865
-			if (!file_exists($language_dir))
2866
-				continue;
3013
+			if (!file_exists($language_dir)) {
3014
+							continue;
3015
+			}
2867 3016
 
2868 3017
 			$dir = dir($language_dir);
2869 3018
 			while ($entry = $dir->read())
2870 3019
 			{
2871 3020
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2872
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2873
-					continue;
2874
-
2875
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2876
-					$langName = $langList[$matches[1]];
3021
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3022
+									continue;
3023
+				}
2877 3024
 
2878
-				else
3025
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3026
+									$langName = $langList[$matches[1]];
3027
+				} else
2879 3028
 				{
2880 3029
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2881 3030
 
@@ -2916,12 +3065,14 @@  discard block
 block discarded – undo
2916 3065
 		}
2917 3066
 
2918 3067
 		// Do we need to store the lang list?
2919
-		if (empty($langList))
2920
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3068
+		if (empty($langList)) {
3069
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3070
+		}
2921 3071
 
2922 3072
 		// Let's cash in on this deal.
2923
-		if (!empty($modSettings['cache_enable']))
2924
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3073
+		if (!empty($modSettings['cache_enable'])) {
3074
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3075
+		}
2925 3076
 	}
2926 3077
 
2927 3078
 	return $context['languages'];
@@ -2944,8 +3095,9 @@  discard block
 block discarded – undo
2944 3095
 	global $modSettings, $options, $txt;
2945 3096
 	static $censor_vulgar = null, $censor_proper;
2946 3097
 
2947
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2948
-		return $text;
3098
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3099
+			return $text;
3100
+	}
2949 3101
 
2950 3102
 	// If they haven't yet been loaded, load them.
2951 3103
 	if ($censor_vulgar == null)
@@ -2973,9 +3125,9 @@  discard block
 block discarded – undo
2973 3125
 	{
2974 3126
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2975 3127
 		$text = $func($censor_vulgar, $censor_proper, $text);
3128
+	} else {
3129
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2976 3130
 	}
2977
-	else
2978
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2979 3131
 
2980 3132
 	return $text;
2981 3133
 }
@@ -3001,38 +3153,42 @@  discard block
 block discarded – undo
3001 3153
 	@ini_set('track_errors', '1');
3002 3154
 
3003 3155
 	// Don't include the file more than once, if $once is true.
3004
-	if ($once && in_array($filename, $templates))
3005
-		return;
3156
+	if ($once && in_array($filename, $templates)) {
3157
+			return;
3158
+	}
3006 3159
 	// Add this file to the include list, whether $once is true or not.
3007
-	else
3008
-		$templates[] = $filename;
3160
+	else {
3161
+			$templates[] = $filename;
3162
+	}
3009 3163
 
3010 3164
 	// Are we going to use eval?
3011 3165
 	if (empty($modSettings['disableTemplateEval']))
3012 3166
 	{
3013 3167
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
3014 3168
 		$settings['current_include_filename'] = $filename;
3015
-	}
3016
-	else
3169
+	} else
3017 3170
 	{
3018 3171
 		$file_found = file_exists($filename);
3019 3172
 
3020
-		if ($once && $file_found)
3021
-			require_once($filename);
3022
-		elseif ($file_found)
3023
-			require($filename);
3173
+		if ($once && $file_found) {
3174
+					require_once($filename);
3175
+		} elseif ($file_found) {
3176
+					require($filename);
3177
+		}
3024 3178
 	}
3025 3179
 
3026 3180
 	if ($file_found !== true)
3027 3181
 	{
3028 3182
 		ob_end_clean();
3029
-		if (!empty($modSettings['enableCompressedOutput']))
3030
-			@ob_start('ob_gzhandler');
3031
-		else
3032
-			ob_start();
3183
+		if (!empty($modSettings['enableCompressedOutput'])) {
3184
+					@ob_start('ob_gzhandler');
3185
+		} else {
3186
+					ob_start();
3187
+		}
3033 3188
 
3034
-		if (isset($_GET['debug']))
3035
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3189
+		if (isset($_GET['debug'])) {
3190
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3191
+		}
3036 3192
 
3037 3193
 		// Don't cache error pages!!
3038 3194
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3051,12 +3207,13 @@  discard block
 block discarded – undo
3051 3207
 		echo '<!DOCTYPE html>
3052 3208
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3053 3209
 	<head>';
3054
-		if (isset($context['character_set']))
3055
-			echo '
3210
+		if (isset($context['character_set'])) {
3211
+					echo '
3056 3212
 		<meta charset="', $context['character_set'], '">';
3213
+		}
3057 3214
 
3058
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3059
-			echo '
3215
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3216
+					echo '
3060 3217
 		<title>', $mtitle, '</title>
3061 3218
 	</head>
3062 3219
 	<body>
@@ -3064,8 +3221,8 @@  discard block
 block discarded – undo
3064 3221
 		', $mmessage, '
3065 3222
 	</body>
3066 3223
 </html>';
3067
-		elseif (!allowedTo('admin_forum'))
3068
-			echo '
3224
+		} elseif (!allowedTo('admin_forum')) {
3225
+					echo '
3069 3226
 		<title>', $txt['template_parse_error'], '</title>
3070 3227
 	</head>
3071 3228
 	<body>
@@ -3073,16 +3230,18 @@  discard block
 block discarded – undo
3073 3230
 		', $txt['template_parse_error_message'], '
3074 3231
 	</body>
3075 3232
 </html>';
3076
-		else
3233
+		} else
3077 3234
 		{
3078 3235
 			require_once($sourcedir . '/Subs-Package.php');
3079 3236
 
3080 3237
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3081 3238
 			$error_array = error_get_last();
3082
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3083
-				$error = $error_array['message'];
3084
-			if (empty($error))
3085
-				$error = $txt['template_parse_errmsg'];
3239
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3240
+							$error = $error_array['message'];
3241
+			}
3242
+			if (empty($error)) {
3243
+							$error = $txt['template_parse_errmsg'];
3244
+			}
3086 3245
 
3087 3246
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3088 3247
 
@@ -3093,11 +3252,12 @@  discard block
 block discarded – undo
3093 3252
 		<h3>', $txt['template_parse_error'], '</h3>
3094 3253
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3095 3254
 
3096
-			if (!empty($error))
3097
-				echo '
3255
+			if (!empty($error)) {
3256
+							echo '
3098 3257
 		<hr>
3099 3258
 
3100 3259
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3260
+			}
3101 3261
 
3102 3262
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3103 3263
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3107,10 +3267,11 @@  discard block
 block discarded – undo
3107 3267
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3108 3268
 
3109 3269
 				// Fix the PHP code stuff...
3110
-				if (!isBrowser('gecko'))
3111
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3112
-				else
3113
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3270
+				if (!isBrowser('gecko')) {
3271
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3272
+				} else {
3273
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3274
+				}
3114 3275
 
3115 3276
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3116 3277
 				$j = -1;
@@ -3118,8 +3279,9 @@  discard block
 block discarded – undo
3118 3279
 				{
3119 3280
 					$j++;
3120 3281
 
3121
-					if (substr_count($line, '<br>') == 0)
3122
-						continue;
3282
+					if (substr_count($line, '<br>') == 0) {
3283
+											continue;
3284
+					}
3123 3285
 
3124 3286
 					$n = substr_count($line, '<br>');
3125 3287
 					for ($i = 0; $i < $n; $i++)
@@ -3138,38 +3300,42 @@  discard block
 block discarded – undo
3138 3300
 				// Figure out what the color coding was before...
3139 3301
 				$line = max($match[1] - 9, 1);
3140 3302
 				$last_line = '';
3141
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3142
-					if (strpos($data2[$line2], '<') !== false)
3303
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3304
+									if (strpos($data2[$line2], '<') !== false)
3143 3305
 					{
3144 3306
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3145 3307
 							$last_line = $color_match[1];
3308
+				}
3146 3309
 						break;
3147 3310
 					}
3148 3311
 
3149 3312
 				// Show the relevant lines...
3150 3313
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3151 3314
 				{
3152
-					if ($line == $match[1])
3153
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3315
+					if ($line == $match[1]) {
3316
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3317
+					}
3154 3318
 
3155 3319
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3156
-					if (isset($data2[$line]) && $data2[$line] != '')
3157
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3320
+					if (isset($data2[$line]) && $data2[$line] != '') {
3321
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3322
+					}
3158 3323
 
3159 3324
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3160 3325
 					{
3161 3326
 						$last_line = $color_match[1];
3162 3327
 						echo '</', substr($last_line, 1, 4), '>';
3328
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3329
+											$last_line = '';
3330
+					} elseif ($last_line != '' && $data2[$line] != '') {
3331
+											echo '</', substr($last_line, 1, 4), '>';
3163 3332
 					}
3164
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3165
-						$last_line = '';
3166
-					elseif ($last_line != '' && $data2[$line] != '')
3167
-						echo '</', substr($last_line, 1, 4), '>';
3168 3333
 
3169
-					if ($line == $match[1])
3170
-						echo '</pre></div><pre style="margin: 0;">';
3171
-					else
3172
-						echo "\n";
3334
+					if ($line == $match[1]) {
3335
+											echo '</pre></div><pre style="margin: 0;">';
3336
+					} else {
3337
+											echo "\n";
3338
+					}
3173 3339
 				}
3174 3340
 
3175 3341
 				echo '</pre></div>';
@@ -3193,8 +3359,9 @@  discard block
 block discarded – undo
3193 3359
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3194 3360
 
3195 3361
 	// Figure out what type of database we are using.
3196
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3197
-		$db_type = 'mysql';
3362
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3363
+			$db_type = 'mysql';
3364
+	}
3198 3365
 
3199 3366
 	// Load the file for the database.
3200 3367
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3202,8 +3369,9 @@  discard block
 block discarded – undo
3202 3369
 	$db_options = array();
3203 3370
 
3204 3371
 	// Add in the port if needed
3205
-	if (!empty($db_port))
3206
-		$db_options['port'] = $db_port;
3372
+	if (!empty($db_port)) {
3373
+			$db_options['port'] = $db_port;
3374
+	}
3207 3375
 
3208 3376
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3209 3377
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3222,13 +3390,15 @@  discard block
 block discarded – undo
3222 3390
 	}
3223 3391
 
3224 3392
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3225
-	if (!$db_connection)
3226
-		display_db_error();
3393
+	if (!$db_connection) {
3394
+			display_db_error();
3395
+	}
3227 3396
 
3228 3397
 	// If in SSI mode fix up the prefix.
3229
-	if (SMF == 'SSI')
3230
-		db_fix_prefix($db_prefix, $db_name);
3231
-}
3398
+	if (SMF == 'SSI') {
3399
+			db_fix_prefix($db_prefix, $db_name);
3400
+	}
3401
+	}
3232 3402
 
3233 3403
 /**
3234 3404
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3242,10 +3412,11 @@  discard block
 block discarded – undo
3242 3412
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3243 3413
 
3244 3414
 	// Not overriding this and we have a cacheAPI, send it back.
3245
-	if (empty($overrideCache) && is_object($cacheAPI))
3246
-		return $cacheAPI;
3247
-	elseif (is_null($cacheAPI))
3248
-		$cacheAPI = false;
3415
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3416
+			return $cacheAPI;
3417
+	} elseif (is_null($cacheAPI)) {
3418
+			$cacheAPI = false;
3419
+	}
3249 3420
 
3250 3421
 	// Make sure our class is in session.
3251 3422
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3266,8 +3437,9 @@  discard block
 block discarded – undo
3266 3437
 		if (!$testAPI->isSupported())
3267 3438
 		{
3268 3439
 			// Can we save ourselves?
3269
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3270
-				return loadCacheAccelerator(null, false);
3440
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3441
+							return loadCacheAccelerator(null, false);
3442
+			}
3271 3443
 			return false;
3272 3444
 		}
3273 3445
 
@@ -3279,9 +3451,9 @@  discard block
 block discarded – undo
3279 3451
 		{
3280 3452
 			$cacheAPI = $testAPI;
3281 3453
 			return $cacheAPI;
3454
+		} else {
3455
+					return $testAPI;
3282 3456
 		}
3283
-		else
3284
-			return $testAPI;
3285 3457
 	}
3286 3458
 }
3287 3459
 
@@ -3301,8 +3473,9 @@  discard block
 block discarded – undo
3301 3473
 
3302 3474
 	// @todo Why are we doing this if caching is disabled?
3303 3475
 
3304
-	if (function_exists('call_integration_hook'))
3305
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3476
+	if (function_exists('call_integration_hook')) {
3477
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3478
+	}
3306 3479
 
3307 3480
 	/* Refresh the cache if either:
3308 3481
 		1. Caching is disabled.
@@ -3316,16 +3489,19 @@  discard block
 block discarded – undo
3316 3489
 		require_once($sourcedir . '/' . $file);
3317 3490
 		$cache_block = call_user_func_array($function, $params);
3318 3491
 
3319
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3320
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3492
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3493
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3494
+		}
3321 3495
 	}
3322 3496
 
3323 3497
 	// Some cached data may need a freshening up after retrieval.
3324
-	if (!empty($cache_block['post_retri_eval']))
3325
-		eval($cache_block['post_retri_eval']);
3498
+	if (!empty($cache_block['post_retri_eval'])) {
3499
+			eval($cache_block['post_retri_eval']);
3500
+	}
3326 3501
 
3327
-	if (function_exists('call_integration_hook'))
3328
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3502
+	if (function_exists('call_integration_hook')) {
3503
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3504
+	}
3329 3505
 
3330 3506
 	return $cache_block['data'];
3331 3507
 }
@@ -3352,8 +3528,9 @@  discard block
 block discarded – undo
3352 3528
 	global $smcFunc, $cache_enable, $cacheAPI;
3353 3529
 	global $cache_hits, $cache_count, $db_show_debug;
3354 3530
 
3355
-	if (empty($cache_enable) || empty($cacheAPI))
3356
-		return;
3531
+	if (empty($cache_enable) || empty($cacheAPI)) {
3532
+			return;
3533
+	}
3357 3534
 
3358 3535
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3359 3536
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3366,12 +3543,14 @@  discard block
 block discarded – undo
3366 3543
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3367 3544
 	$cacheAPI->putData($key, $value, $ttl);
3368 3545
 
3369
-	if (function_exists('call_integration_hook'))
3370
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3546
+	if (function_exists('call_integration_hook')) {
3547
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3548
+	}
3371 3549
 
3372
-	if (isset($db_show_debug) && $db_show_debug === true)
3373
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3374
-}
3550
+	if (isset($db_show_debug) && $db_show_debug === true) {
3551
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3552
+	}
3553
+	}
3375 3554
 
3376 3555
 /**
3377 3556
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3387,8 +3566,9 @@  discard block
 block discarded – undo
3387 3566
 	global $smcFunc, $cache_enable, $cacheAPI;
3388 3567
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3389 3568
 
3390
-	if (empty($cache_enable) || empty($cacheAPI))
3391
-		return;
3569
+	if (empty($cache_enable) || empty($cacheAPI)) {
3570
+			return;
3571
+	}
3392 3572
 
3393 3573
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3394 3574
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3408,16 +3588,18 @@  discard block
 block discarded – undo
3408 3588
 
3409 3589
 		if (empty($value))
3410 3590
 		{
3411
-			if (!is_array($cache_misses))
3412
-				$cache_misses = array();
3591
+			if (!is_array($cache_misses)) {
3592
+							$cache_misses = array();
3593
+			}
3413 3594
 
3414 3595
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3415 3596
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3416 3597
 		}
3417 3598
 	}
3418 3599
 
3419
-	if (function_exists('call_integration_hook') && isset($value))
3420
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3600
+	if (function_exists('call_integration_hook') && isset($value)) {
3601
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3602
+	}
3421 3603
 
3422 3604
 	return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3423 3605
 }
@@ -3439,8 +3621,9 @@  discard block
 block discarded – undo
3439 3621
 	global $cacheAPI;
3440 3622
 
3441 3623
 	// If we can't get to the API, can't do this.
3442
-	if (empty($cacheAPI))
3443
-		return;
3624
+	if (empty($cacheAPI)) {
3625
+			return;
3626
+	}
3444 3627
 
3445 3628
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3446 3629
 	$cacheAPI->cleanCache($type);
@@ -3465,8 +3648,9 @@  discard block
 block discarded – undo
3465 3648
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3466 3649
 
3467 3650
 	// Come on!
3468
-	if (empty($data))
3469
-		return array();
3651
+	if (empty($data)) {
3652
+			return array();
3653
+	}
3470 3654
 
3471 3655
 	// Set a nice default var.
3472 3656
 	$image = '';
@@ -3474,11 +3658,11 @@  discard block
 block discarded – undo
3474 3658
 	// Gravatar has been set as mandatory!
3475 3659
 	if (!empty($modSettings['gravatarOverride']))
3476 3660
 	{
3477
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3478
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3479
-
3480
-		else if (!empty($data['email']))
3481
-			$image = get_gravatar_url($data['email']);
3661
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3662
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3663
+		} else if (!empty($data['email'])) {
3664
+					$image = get_gravatar_url($data['email']);
3665
+		}
3482 3666
 	}
3483 3667
 
3484 3668
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3490,54 +3674,60 @@  discard block
 block discarded – undo
3490 3674
 			// Gravatar.
3491 3675
 			if (stristr($data['avatar'], 'gravatar://'))
3492 3676
 			{
3493
-				if ($data['avatar'] == 'gravatar://')
3494
-					$image = get_gravatar_url($data['email']);
3495
-
3496
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3497
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3677
+				if ($data['avatar'] == 'gravatar://') {
3678
+									$image = get_gravatar_url($data['email']);
3679
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3680
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3681
+				}
3498 3682
 			}
3499 3683
 
3500 3684
 			// External url.
3501 3685
 			else
3502 3686
 			{
3503 3687
 				// Using ssl?
3504
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3505
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3688
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3689
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3690
+				}
3506 3691
 
3507 3692
 				// Just a plain external url.
3508
-				else
3509
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3693
+				else {
3694
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3695
+				}
3510 3696
 			}
3511 3697
 		}
3512 3698
 
3513 3699
 		// Perhaps this user has an attachment as avatar...
3514
-		else if (!empty($data['filename']))
3515
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3700
+		else if (!empty($data['filename'])) {
3701
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3702
+		}
3516 3703
 
3517 3704
 		// Right... no avatar... use our default image.
3518
-		else
3519
-			$image = $modSettings['avatar_url'] . '/default.png';
3705
+		else {
3706
+					$image = $modSettings['avatar_url'] . '/default.png';
3707
+		}
3520 3708
 	}
3521 3709
 
3522 3710
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3523 3711
 
3524 3712
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3525
-	if (!empty($image))
3526
-		return array(
3713
+	if (!empty($image)) {
3714
+			return array(
3527 3715
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3528 3716
 			'image' => '<img class="avatar" src="' . $image . '" />',
3529 3717
 			'href' => $image,
3530 3718
 			'url' => $image,
3531 3719
 		);
3720
+	}
3532 3721
 
3533 3722
 	// Fallback to make life easier for everyone...
3534
-	else
3535
-		return array(
3723
+	else {
3724
+			return array(
3536 3725
 			'name' => '',
3537 3726
 			'image' => '',
3538 3727
 			'href' => '',
3539 3728
 			'url' => '',
3540 3729
 		);
3541
-}
3730
+	}
3731
+	}
3542 3732
 
3543 3733
 ?>
3544 3734
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/Errors.template.php 1 patch
Braces   +24 added lines, -17 removed lines patch added patch discarded remove patch
@@ -23,13 +23,13 @@  discard block
 block discarded – undo
23 23
 {
24 24
 	global $context, $txt;
25 25
 
26
-	if (!empty($context['simple_action']))
27
-		echo '
26
+	if (!empty($context['simple_action'])) {
27
+			echo '
28 28
 		<strong>
29 29
 			', $context['error_title'], '
30 30
 		</strong><br>
31 31
 		<div ', $context['error_code'], 'class="padding">', $context['error_message'], '</div>';
32
-	else
32
+	} else
33 33
 	{
34 34
 		echo '
35 35
 	<div id="fatal_error">
@@ -82,21 +82,23 @@  discard block
 block discarded – undo
82 82
 						&nbsp;&nbsp;', $txt['apply_filter_of_type'], ':';
83 83
 
84 84
 	$error_types = array();
85
-	foreach ($context['error_types'] as $type => $details)
86
-		$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
85
+	foreach ($context['error_types'] as $type => $details) {
86
+			$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
87
+	}
87 88
 
88 89
 	echo '
89 90
 						', implode('&nbsp;|&nbsp;', $error_types), '
90 91
 					</td>
91 92
 				</tr>';
92 93
 
93
-	if ($context['has_filter'])
94
-		echo '
94
+	if ($context['has_filter']) {
95
+			echo '
95 96
 				<tr>
96 97
 					<td colspan="3" class="windowbg">
97 98
 						<strong>&nbsp;&nbsp;', $txt['applying_filter'], ':</strong> ', $context['filter']['entity'], ' ', $context['filter']['value']['html'], '&nbsp;&nbsp;[<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', '">', $txt['clear_filter'], '</a>]
98 99
 					</td>
99 100
 				</tr>';
101
+	}
100 102
 
101 103
 	echo '
102 104
 				<tr>
@@ -107,11 +109,12 @@  discard block
 block discarded – undo
107 109
 				</tr>';
108 110
 
109 111
 	// No errors, then show a message
110
-	if (count($context['errors']) == 0)
111
-		echo '
112
+	if (count($context['errors']) == 0) {
113
+			echo '
112 114
 				<tr class="windowbg">
113 115
 					<td class="centertext" colspan="2">', $txt['errlog_no_entries'], '</td>
114 116
 				</tr>';
117
+	}
115 118
 
116 119
 	// we have some errors, must be some mods installed :P
117 120
 	foreach ($context['errors'] as $error)
@@ -125,19 +128,21 @@  discard block
 block discarded – undo
125 128
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? '' : ';desc', $context['has_filter'] ? $context['filter']['href'] : '', '" title="', $txt['reverse_direction'], '"><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></a>
126 129
 							', $error['time'], '<br>';
127 130
 
128
-		if (!empty($error['member']['ip']))
129
-			echo '
131
+		if (!empty($error['member']['ip'])) {
132
+					echo '
130 133
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=ip;value=', $error['member']['ip'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '"><span class="generic_icons filter centericon"></span></a>
131 134
 							<strong><a href="', $scripturl, '?action=trackip;searchip=', $error['member']['ip'], '">', $error['member']['ip'], '</a></strong>&nbsp;&nbsp;<br>';
135
+		}
132 136
 
133 137
 		echo '
134 138
 						</div>
135 139
 						<div style="float: left; width: 50%; line-height: 1.8em; padding: 0 4px;">';
136 140
 
137
-		if ($error['member']['session'] != '')
138
-			echo '
141
+		if ($error['member']['session'] != '') {
142
+					echo '
139 143
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=session;value=', $error['member']['session'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '"><span class="generic_icons filter centericon"></span></a>
140 144
 							', $error['member']['session'], '<br>';
145
+		}
141 146
 
142 147
 		echo '
143 148
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=error_type;value=', $error['error_type']['type'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_type'], '"><span class="generic_icons filter centericon"></span></a>
@@ -151,8 +156,8 @@  discard block
 block discarded – undo
151 156
 							<a style="display: table-cell;" href="', $error['url']['html'], '">', $error['url']['html'], '</a>
152 157
 						</div>';
153 158
 
154
-		if (!empty($error['file']))
155
-			echo '
159
+		if (!empty($error['file'])) {
160
+					echo '
156 161
 						<div style="float: left; width: 100%; padding: 4px 0; line-height: 1.6em; border-top: 1px solid #e3e3e3;">
157 162
 							<a style="display: table-cell; padding: 4px; width: 20px; vertical-align: top;" href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=file;value=', $error['file']['search'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '"><span class="generic_icons filter"></span></a>
158 163
 							<div>
@@ -160,6 +165,7 @@  discard block
 block discarded – undo
160 165
 								', $txt['line'], ': ', $error['file']['line'], '
161 166
 							</div>
162 167
 						</div>';
168
+		}
163 169
 
164 170
 		echo '
165 171
 					</td>
@@ -187,9 +193,10 @@  discard block
 block discarded – undo
187 193
 				</div>
188 194
 			</div>';
189 195
 
190
-	if ($context['sort_direction'] == 'down')
191
-		echo '
196
+	if ($context['sort_direction'] == 'down') {
197
+			echo '
192 198
 			<input type="hidden" name="desc" value="1">';
199
+	}
193 200
 
194 201
 	echo '
195 202
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
Please login to merge, or discard this patch.