Completed
Pull Request — release-2.1 (#4090)
by Rick
08:07
created
Sources/tasks/index.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Try to handle it with the upper level index.php. (it should know what to do.)
4
-if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
4
+if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) {
5 5
 	include (dirname(dirname(__FILE__)) . '/index.php');
6
-else
6
+} else {
7 7
 	exit;
8
+}
8 9
 
9 10
 ?>
10 11
\ No newline at end of file
Please login to merge, or discard this patch.
avatars/Oxygen/index.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Try to handle it with the upper level index.php. (it should know what to do.)
4
-if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
4
+if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) {
5 5
 	include (dirname(dirname(__FILE__)) . '/index.php');
6
-else
6
+} else {
7 7
 	exit;
8
+}
8 9
 
9 10
 ?>
10 11
\ No newline at end of file
Please login to merge, or discard this patch.
avatars/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('Location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Themes.php 1 patch
Braces   +348 added lines, -271 removed lines patch added patch discarded remove patch
@@ -30,8 +30,9 @@  discard block
 block discarded – undo
30 30
  * @version 2.1 Beta 3
31 31
  */
32 32
 
33
-if (!defined('SMF'))
33
+if (!defined('SMF')) {
34 34
 	die('No direct access...');
35
+}
35 36
 
36 37
 /**
37 38
  * Subaction handler - manages the action and delegates control to the proper
@@ -103,12 +104,12 @@  discard block
 block discarded – undo
103 104
 	cache_put_data('minimized_css', null);
104 105
 
105 106
 	// Follow the sa or just go to administration.
106
-	if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']]))
107
-		call_helper($subActions[$_GET['sa']]);
108
-
109
-	else
110
-		call_helper($subActions['admin']);
111
-}
107
+	if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']])) {
108
+			call_helper($subActions[$_GET['sa']]);
109
+	} else {
110
+			call_helper($subActions['admin']);
111
+	}
112
+	}
112 113
 
113 114
 /**
114 115
  * This function allows administration of themes and their settings,
@@ -130,15 +131,16 @@  discard block
 block discarded – undo
130 131
 		checkSession();
131 132
 		validateToken('admin-tm');
132 133
 
133
-		if (isset($_POST['options']['known_themes']))
134
-			foreach ($_POST['options']['known_themes'] as $key => $id)
134
+		if (isset($_POST['options']['known_themes'])) {
135
+					foreach ($_POST['options']['known_themes'] as $key => $id)
135 136
 				$_POST['options']['known_themes'][$key] = (int) $id;
137
+		} else {
138
+					fatal_lang_error('themes_none_selectable', false);
139
+		}
136 140
 
137
-		else
138
-			fatal_lang_error('themes_none_selectable', false);
139
-
140
-		if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes']))
141
-			fatal_lang_error('themes_default_selectable', false);
141
+		if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes'])) {
142
+					fatal_lang_error('themes_default_selectable', false);
143
+		}
142 144
 
143 145
 		// Commit the new settings.
144 146
 		updateSettings(array(
@@ -146,8 +148,9 @@  discard block
 block discarded – undo
146 148
 			'theme_guests' => $_POST['options']['theme_guests'],
147 149
 			'knownThemes' => implode(',', $_POST['options']['known_themes']),
148 150
 		));
149
-		if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes']))
150
-			updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset']));
151
+		if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes'])) {
152
+					updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset']));
153
+		}
151 154
 
152 155
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=admin');
153 156
 	}
@@ -166,8 +169,9 @@  discard block
 block discarded – undo
166 169
 	// Look for a non existent theme directory. (ie theme87.)
167 170
 	$theme_dir = $boarddir . '/Themes/theme';
168 171
 	$i = 1;
169
-	while (file_exists($theme_dir . $i))
170
-		$i++;
172
+	while (file_exists($theme_dir . $i)) {
173
+			$i++;
174
+	}
171 175
 
172 176
 	$context['new_theme_name'] = 'theme' . $i;
173 177
 
@@ -189,8 +193,9 @@  discard block
 block discarded – undo
189 193
 	loadLanguage('Admin');
190 194
 	isAllowedTo('admin_forum');
191 195
 
192
-	if (isset($_REQUEST['th']))
193
-		return SetThemeSettings();
196
+	if (isset($_REQUEST['th'])) {
197
+			return SetThemeSettings();
198
+	}
194 199
 
195 200
 	if (isset($_POST['save']))
196 201
 	{
@@ -274,12 +279,13 @@  discard block
 block discarded – undo
274 279
 		$context['themes'] = array();
275 280
 		while ($row = $smcFunc['db_fetch_assoc']($request))
276 281
 		{
277
-			if (!isset($context['themes'][$row['id_theme']]))
278
-				$context['themes'][$row['id_theme']] = array(
282
+			if (!isset($context['themes'][$row['id_theme']])) {
283
+							$context['themes'][$row['id_theme']] = array(
279 284
 					'id' => $row['id_theme'],
280 285
 					'num_default_options' => 0,
281 286
 					'num_members' => 0,
282 287
 				);
288
+			}
283 289
 			$context['themes'][$row['id_theme']][$row['variable']] = $row['value'];
284 290
 		}
285 291
 		$smcFunc['db_free_result']($request);
@@ -293,8 +299,9 @@  discard block
 block discarded – undo
293 299
 				'guest_member' => -1,
294 300
 			)
295 301
 		);
296
-		while ($row = $smcFunc['db_fetch_assoc']($request))
297
-			$context['themes'][$row['id_theme']]['num_default_options'] = $row['value'];
302
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
303
+					$context['themes'][$row['id_theme']]['num_default_options'] = $row['value'];
304
+		}
298 305
 		$smcFunc['db_free_result']($request);
299 306
 
300 307
 		// Need to make sure we don't do custom fields.
@@ -305,8 +312,9 @@  discard block
 block discarded – undo
305 312
 			)
306 313
 		);
307 314
 		$customFields = array();
308
-		while ($row = $smcFunc['db_fetch_assoc']($request))
309
-			$customFields[] = $row['col_name'];
315
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
316
+					$customFields[] = $row['col_name'];
317
+		}
310 318
 		$smcFunc['db_free_result']($request);
311 319
 		$customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})');
312 320
 
@@ -321,14 +329,16 @@  discard block
 block discarded – undo
321 329
 				'custom_fields' => empty($customFields) ? array() : $customFields,
322 330
 			)
323 331
 		);
324
-		while ($row = $smcFunc['db_fetch_assoc']($request))
325
-			$context['themes'][$row['id_theme']]['num_members'] = $row['value'];
332
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
333
+					$context['themes'][$row['id_theme']]['num_members'] = $row['value'];
334
+		}
326 335
 		$smcFunc['db_free_result']($request);
327 336
 
328 337
 		// There has to be a Settings template!
329
-		foreach ($context['themes'] as $k => $v)
330
-			if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members'])))
338
+		foreach ($context['themes'] as $k => $v) {
339
+					if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members'])))
331 340
 				unset($context['themes'][$k]);
341
+		}
332 342
 
333 343
 		loadTemplate('Themes');
334 344
 		$context['sub_template'] = 'reset_list';
@@ -343,16 +353,19 @@  discard block
 block discarded – undo
343 353
 		checkSession();
344 354
 		validateToken('admin-sto');
345 355
 
346
-		if (empty($_POST['options']))
347
-			$_POST['options'] = array();
348
-		if (empty($_POST['default_options']))
349
-			$_POST['default_options'] = array();
356
+		if (empty($_POST['options'])) {
357
+					$_POST['options'] = array();
358
+		}
359
+		if (empty($_POST['default_options'])) {
360
+					$_POST['default_options'] = array();
361
+		}
350 362
 
351 363
 		// Set up the sql query.
352 364
 		$setValues = array();
353 365
 
354
-		foreach ($_POST['options'] as $opt => $val)
355
-			$setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
366
+		foreach ($_POST['options'] as $opt => $val) {
367
+					$setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
368
+		}
356 369
 
357 370
 		$old_settings = array();
358 371
 		foreach ($_POST['default_options'] as $opt => $val)
@@ -366,8 +379,8 @@  discard block
 block discarded – undo
366 379
 		if (!empty($setValues))
367 380
 		{
368 381
 			// Are there options in non-default themes set that should be cleared?
369
-			if (!empty($old_settings))
370
-				$smcFunc['db_query']('', '
382
+			if (!empty($old_settings)) {
383
+							$smcFunc['db_query']('', '
371 384
 					DELETE FROM {db_prefix}themes
372 385
 					WHERE id_theme != {int:default_theme}
373 386
 						AND id_member = {int:guest_member}
@@ -378,6 +391,7 @@  discard block
 block discarded – undo
378 391
 						'old_settings' => $old_settings,
379 392
 					)
380 393
 				);
394
+			}
381 395
 
382 396
 			$smcFunc['db_insert']('replace',
383 397
 				'{db_prefix}themes',
@@ -391,8 +405,7 @@  discard block
 block discarded – undo
391 405
 		cache_put_data('theme_settings-1', null, 90);
392 406
 
393 407
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
394
-	}
395
-	elseif (isset($_POST['submit']) && $_POST['who'] == 1)
408
+	} elseif (isset($_POST['submit']) && $_POST['who'] == 1)
396 409
 	{
397 410
 		checkSession();
398 411
 		validateToken('admin-sto');
@@ -405,9 +418,9 @@  discard block
 block discarded – undo
405 418
 		$old_settings = array();
406 419
 		foreach ($_POST['default_options'] as $opt => $val)
407 420
 		{
408
-			if ($_POST['default_options_master'][$opt] == 0)
409
-				continue;
410
-			elseif ($_POST['default_options_master'][$opt] == 1)
421
+			if ($_POST['default_options_master'][$opt] == 0) {
422
+							continue;
423
+			} elseif ($_POST['default_options_master'][$opt] == 1)
411 424
 			{
412 425
 				// Delete then insert for ease of database compatibility!
413 426
 				$smcFunc['db_query']('substring', '
@@ -433,8 +446,7 @@  discard block
 block discarded – undo
433 446
 				);
434 447
 
435 448
 				$old_settings[] = $opt;
436
-			}
437
-			elseif ($_POST['default_options_master'][$opt] == 2)
449
+			} elseif ($_POST['default_options_master'][$opt] == 2)
438 450
 			{
439 451
 				$smcFunc['db_query']('', '
440 452
 					DELETE FROM {db_prefix}themes
@@ -449,8 +461,8 @@  discard block
 block discarded – undo
449 461
 		}
450 462
 
451 463
 		// Delete options from other themes.
452
-		if (!empty($old_settings))
453
-			$smcFunc['db_query']('', '
464
+		if (!empty($old_settings)) {
465
+					$smcFunc['db_query']('', '
454 466
 				DELETE FROM {db_prefix}themes
455 467
 				WHERE id_theme != {int:default_theme}
456 468
 					AND id_member > {int:no_member}
@@ -461,12 +473,13 @@  discard block
 block discarded – undo
461 473
 					'old_settings' => $old_settings,
462 474
 				)
463 475
 			);
476
+		}
464 477
 
465 478
 		foreach ($_POST['options'] as $opt => $val)
466 479
 		{
467
-			if ($_POST['options_master'][$opt] == 0)
468
-				continue;
469
-			elseif ($_POST['options_master'][$opt] == 1)
480
+			if ($_POST['options_master'][$opt] == 0) {
481
+							continue;
482
+			} elseif ($_POST['options_master'][$opt] == 1)
470 483
 			{
471 484
 				// Delete then insert for ease of database compatibility - again!
472 485
 				$smcFunc['db_query']('substring', '
@@ -491,8 +504,7 @@  discard block
 block discarded – undo
491 504
 						'value' => (is_array($val) ? implode(',', $val) : $val),
492 505
 					)
493 506
 				);
494
-			}
495
-			elseif ($_POST['options_master'][$opt] == 2)
507
+			} elseif ($_POST['options_master'][$opt] == 2)
496 508
 			{
497 509
 				$smcFunc['db_query']('', '
498 510
 					DELETE FROM {db_prefix}themes
@@ -509,8 +521,7 @@  discard block
 block discarded – undo
509 521
 		}
510 522
 
511 523
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
512
-	}
513
-	elseif (!empty($_GET['who']) && $_GET['who'] == 2)
524
+	} elseif (!empty($_GET['who']) && $_GET['who'] == 2)
514 525
 	{
515 526
 		checkSession('get');
516 527
 		validateToken('admin-stor', 'request');
@@ -525,8 +536,9 @@  discard block
 block discarded – undo
525 536
 				)
526 537
 			);
527 538
 			$customFields = array();
528
-			while ($row = $smcFunc['db_fetch_assoc']($request))
529
-				$customFields[] = $row['col_name'];
539
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
540
+							$customFields[] = $row['col_name'];
541
+			}
530 542
 			$smcFunc['db_free_result']($request);
531 543
 		}
532 544
 		$customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})');
@@ -578,13 +590,13 @@  discard block
 block discarded – undo
578 590
 			)
579 591
 		);
580 592
 		$context['theme_options'] = array();
581
-		while ($row = $smcFunc['db_fetch_assoc']($request))
582
-			$context['theme_options'][$row['variable']] = $row['value'];
593
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
594
+					$context['theme_options'][$row['variable']] = $row['value'];
595
+		}
583 596
 		$smcFunc['db_free_result']($request);
584 597
 
585 598
 		$context['theme_options_reset'] = false;
586
-	}
587
-	else
599
+	} else
588 600
 	{
589 601
 		$context['theme_options'] = array();
590 602
 		$context['theme_options_reset'] = true;
@@ -593,30 +605,32 @@  discard block
 block discarded – undo
593 605
 	foreach ($context['options'] as $i => $setting)
594 606
 	{
595 607
 		// Just skip separators
596
-		if (!is_array($setting))
597
-			continue;
608
+		if (!is_array($setting)) {
609
+					continue;
610
+		}
598 611
 
599 612
 		// Is this disabled?
600 613
 		if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled']))
601 614
 		{
602 615
 			unset($context['options'][$i]);
603 616
 			continue;
604
-		}
605
-		elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
617
+		} elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
606 618
 		{
607 619
 			unset($context['options'][$i]);
608 620
 			continue;
609 621
 		}
610 622
 
611
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
612
-			$context['options'][$i]['type'] = 'checkbox';
613
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
614
-			$context['options'][$i]['type'] = 'number';
615
-		elseif ($setting['type'] == 'string')
616
-			$context['options'][$i]['type'] = 'text';
623
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
624
+					$context['options'][$i]['type'] = 'checkbox';
625
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
626
+					$context['options'][$i]['type'] = 'number';
627
+		} elseif ($setting['type'] == 'string') {
628
+					$context['options'][$i]['type'] = 'text';
629
+		}
617 630
 
618
-		if (isset($setting['options']))
619
-			$context['options'][$i]['type'] = 'list';
631
+		if (isset($setting['options'])) {
632
+					$context['options'][$i]['type'] = 'list';
633
+		}
620 634
 
621 635
 		$context['options'][$i]['value'] = !isset($context['theme_options'][$setting['id']]) ? '' : $context['theme_options'][$setting['id']];
622 636
 	}
@@ -641,8 +655,9 @@  discard block
 block discarded – undo
641 655
 {
642 656
 	global $txt, $context, $settings, $modSettings, $smcFunc;
643 657
 
644
-	if (empty($_GET['th']) && empty($_GET['id']))
645
-		return ThemeAdmin();
658
+	if (empty($_GET['th']) && empty($_GET['id'])) {
659
+			return ThemeAdmin();
660
+	}
646 661
 
647 662
 	$_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
648 663
 
@@ -653,8 +668,9 @@  discard block
 block discarded – undo
653 668
 	isAllowedTo('admin_forum');
654 669
 
655 670
 	// Validate inputs/user.
656
-	if (empty($_GET['th']))
657
-		fatal_lang_error('no_theme', false);
671
+	if (empty($_GET['th'])) {
672
+			fatal_lang_error('no_theme', false);
673
+	}
658 674
 
659 675
 	// Fetch the smiley sets...
660 676
 	$sets = explode(',', 'none,' . $modSettings['smiley_sets_known']);
@@ -662,8 +678,9 @@  discard block
 block discarded – undo
662 678
 	$context['smiley_sets'] = array(
663 679
 		'' => $txt['smileys_no_default']
664 680
 	);
665
-	foreach ($sets as $i => $set)
666
-		$context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]);
681
+	foreach ($sets as $i => $set) {
682
+			$context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]);
683
+	}
667 684
 
668 685
 	$old_id = $settings['theme_id'];
669 686
 	$old_settings = $settings;
@@ -688,8 +705,9 @@  discard block
 block discarded – undo
688 705
 	if (file_exists($settings['theme_dir'] . '/index.template.php'))
689 706
 	{
690 707
 		$file_contents = implode('', file($settings['theme_dir'] . '/index.template.php'));
691
-		if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches))
692
-				eval('global $settings;' . $matches[0]);
708
+		if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches)) {
709
+						eval('global $settings;' . $matches[0]);
710
+		}
693 711
 	}
694 712
 
695 713
 	// Submitting!
@@ -698,37 +716,45 @@  discard block
 block discarded – undo
698 716
 		checkSession();
699 717
 		validateToken('admin-sts');
700 718
 
701
-		if (empty($_POST['options']))
702
-			$_POST['options'] = array();
703
-		if (empty($_POST['default_options']))
704
-			$_POST['default_options'] = array();
719
+		if (empty($_POST['options'])) {
720
+					$_POST['options'] = array();
721
+		}
722
+		if (empty($_POST['default_options'])) {
723
+					$_POST['default_options'] = array();
724
+		}
705 725
 
706 726
 		// Make sure items are cast correctly.
707 727
 		foreach ($context['theme_settings'] as $item)
708 728
 		{
709 729
 			// Disregard this item if this is just a separator.
710
-			if (!is_array($item))
711
-				continue;
730
+			if (!is_array($item)) {
731
+							continue;
732
+			}
712 733
 
713 734
 			foreach (array('options', 'default_options') as $option)
714 735
 			{
715
-				if (!isset($_POST[$option][$item['id']]))
716
-					continue;
736
+				if (!isset($_POST[$option][$item['id']])) {
737
+									continue;
738
+				}
717 739
 				// Checkbox.
718
-				elseif (empty($item['type']))
719
-					$_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
740
+				elseif (empty($item['type'])) {
741
+									$_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
742
+				}
720 743
 				// Number
721
-				elseif ($item['type'] == 'number')
722
-					$_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
744
+				elseif ($item['type'] == 'number') {
745
+									$_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
746
+				}
723 747
 			}
724 748
 		}
725 749
 
726 750
 		// Set up the sql query.
727 751
 		$inserts = array();
728
-		foreach ($_POST['options'] as $opt => $val)
729
-			$inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
730
-		foreach ($_POST['default_options'] as $opt => $val)
731
-			$inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val);
752
+		foreach ($_POST['options'] as $opt => $val) {
753
+					$inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
754
+		}
755
+		foreach ($_POST['default_options'] as $opt => $val) {
756
+					$inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val);
757
+		}
732 758
 		// If we're actually inserting something..
733 759
 		if (!empty($inserts))
734 760
 		{
@@ -754,8 +780,9 @@  discard block
 block discarded – undo
754 780
 
755 781
 	foreach ($settings as $setting => $dummy)
756 782
 	{
757
-		if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs')))
758
-			$settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
783
+		if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) {
784
+					$settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
785
+		}
759 786
 	}
760 787
 
761 788
 	$context['settings'] = $context['theme_settings'];
@@ -764,18 +791,21 @@  discard block
 block discarded – undo
764 791
 	foreach ($context['settings'] as $i => $setting)
765 792
 	{
766 793
 		// Separators are dummies, so leave them alone.
767
-		if (!is_array($setting))
768
-			continue;
794
+		if (!is_array($setting)) {
795
+					continue;
796
+		}
769 797
 
770
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
771
-			$context['settings'][$i]['type'] = 'checkbox';
772
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
773
-			$context['settings'][$i]['type'] = 'number';
774
-		elseif ($setting['type'] == 'string')
775
-			$context['settings'][$i]['type'] = 'text';
798
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
799
+					$context['settings'][$i]['type'] = 'checkbox';
800
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
801
+					$context['settings'][$i]['type'] = 'number';
802
+		} elseif ($setting['type'] == 'string') {
803
+					$context['settings'][$i]['type'] = 'text';
804
+		}
776 805
 
777
-		if (isset($setting['options']))
778
-			$context['settings'][$i]['type'] = 'list';
806
+		if (isset($setting['options'])) {
807
+					$context['settings'][$i]['type'] = 'list';
808
+		}
779 809
 
780 810
 		$context['settings'][$i]['value'] = !isset($settings[$setting['id']]) ? '' : $settings[$setting['id']];
781 811
 	}
@@ -828,8 +858,9 @@  discard block
 block discarded – undo
828 858
 	$themeID = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
829 859
 
830 860
 	// You can't delete the default theme!
831
-	if ($themeID == 1)
832
-		fatal_lang_error('no_access', false);
861
+	if ($themeID == 1) {
862
+			fatal_lang_error('no_access', false);
863
+	}
833 864
 
834 865
 	$theme_info = get_single_theme($themeID);
835 866
 
@@ -837,8 +868,9 @@  discard block
 block discarded – undo
837 868
 	remove_theme($themeID);
838 869
 
839 870
 	// And remove all its files and folders too.
840
-	if (!empty($theme_info) && !empty($theme_info['theme_dir']))
841
-		remove_dir($theme_info['theme_dir']);
871
+	if (!empty($theme_info) && !empty($theme_info['theme_dir'])) {
872
+			remove_dir($theme_info['theme_dir']);
873
+	}
842 874
 
843 875
 	// Go back to the list page.
844 876
 	redirectexit('action=admin;area=theme;sa=list;' . $context['session_var'] . '=' . $context['session_id'] . ';done=removing');
@@ -863,12 +895,14 @@  discard block
 block discarded – undo
863 895
 	$enableThemes = explode(',', $modSettings['enableThemes']);
864 896
 
865 897
 	// Are we disabling it?
866
-	if (isset($_GET['disabled']))
867
-		$enableThemes = array_diff($enableThemes, array($themeID));
898
+	if (isset($_GET['disabled'])) {
899
+			$enableThemes = array_diff($enableThemes, array($themeID));
900
+	}
868 901
 
869 902
 	// Nope? then enable it!
870
-	else
871
-		$enableThemes[] = (string) $themeID;
903
+	else {
904
+			$enableThemes[] = (string) $themeID;
905
+	}
872 906
 
873 907
 	// Update the setting.
874 908
 	$enableThemes = strtr(implode(',', $enableThemes), array(',,' => ','));
@@ -903,18 +937,21 @@  discard block
 block discarded – undo
903 937
 
904 938
 	$_SESSION['id_theme'] = 0;
905 939
 
906
-	if (isset($_GET['id']))
907
-		$_GET['th'] = $_GET['id'];
940
+	if (isset($_GET['id'])) {
941
+			$_GET['th'] = $_GET['id'];
942
+	}
908 943
 
909 944
 	// Saving a variant cause JS doesn't work - pretend it did ;)
910 945
 	if (isset($_POST['save']))
911 946
 	{
912 947
 		// Which theme?
913
-		foreach ($_POST['save'] as $k => $v)
914
-			$_GET['th'] = (int) $k;
948
+		foreach ($_POST['save'] as $k => $v) {
949
+					$_GET['th'] = (int) $k;
950
+		}
915 951
 
916
-		if (isset($_POST['vrt'][$k]))
917
-			$_GET['vrt'] = $_POST['vrt'][$k];
952
+		if (isset($_POST['vrt'][$k])) {
953
+					$_GET['vrt'] = $_POST['vrt'][$k];
954
+		}
918 955
 	}
919 956
 
920 957
 	// Have we made a decision, or are we just browsing?
@@ -992,8 +1029,9 @@  discard block
 block discarded – undo
992 1029
 		else
993 1030
 		{
994 1031
 			// The forum's default theme is always 0 and we
995
-			if (isset($_GET['th']) && $_GET['th'] == 0)
996
-					$_GET['th'] = $modSettings['theme_guests'];
1032
+			if (isset($_GET['th']) && $_GET['th'] == 0) {
1033
+								$_GET['th'] = $modSettings['theme_guests'];
1034
+			}
997 1035
 
998 1036
 			updateMemberData((int) $_REQUEST['u'], array('id_theme' => (int) $_GET['th']));
999 1037
 
@@ -1007,8 +1045,9 @@  discard block
 block discarded – undo
1007 1045
 				);
1008 1046
 				cache_put_data('theme_settings-' . $_GET['th'] . ':' . (int) $_REQUEST['u'], null, 90);
1009 1047
 
1010
-				if ($user_info['id'] == $_REQUEST['u'])
1011
-					$_SESSION['id_variant'] = 0;
1048
+				if ($user_info['id'] == $_REQUEST['u']) {
1049
+									$_SESSION['id_variant'] = 0;
1050
+				}
1012 1051
 			}
1013 1052
 
1014 1053
 			redirectexit('action=profile;u=' . (int) $_REQUEST['u'] . ';area=theme');
@@ -1077,12 +1116,13 @@  discard block
 block discarded – undo
1077 1116
 		);
1078 1117
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1079 1118
 		{
1080
-			if (!isset($context['available_themes'][$row['id_theme']]))
1081
-				$context['available_themes'][$row['id_theme']] = array(
1119
+			if (!isset($context['available_themes'][$row['id_theme']])) {
1120
+							$context['available_themes'][$row['id_theme']] = array(
1082 1121
 					'id' => $row['id_theme'],
1083 1122
 					'selected' => $context['current_theme'] == $row['id_theme'],
1084 1123
 					'num_users' => 0
1085 1124
 				);
1125
+			}
1086 1126
 			$context['available_themes'][$row['id_theme']][$row['variable']] = $row['value'];
1087 1127
 		}
1088 1128
 		$smcFunc['db_free_result']($request);
@@ -1095,9 +1135,9 @@  discard block
 block discarded – undo
1095 1135
 			'num_users' => 0
1096 1136
 		);
1097 1137
 		$guest_theme = 0;
1138
+	} else {
1139
+			$guest_theme = $modSettings['theme_guests'];
1098 1140
 	}
1099
-	else
1100
-		$guest_theme = $modSettings['theme_guests'];
1101 1141
 
1102 1142
 	$request = $smcFunc['db_query']('', '
1103 1143
 		SELECT id_theme, COUNT(*) AS the_count
@@ -1110,15 +1150,17 @@  discard block
 block discarded – undo
1110 1150
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1111 1151
 	{
1112 1152
 		// Figure out which theme it is they are REALLY using.
1113
-		if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes'])))
1114
-			$row['id_theme'] = $guest_theme;
1115
-		elseif (empty($modSettings['theme_allow']))
1116
-			$row['id_theme'] = $guest_theme;
1153
+		if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes']))) {
1154
+					$row['id_theme'] = $guest_theme;
1155
+		} elseif (empty($modSettings['theme_allow'])) {
1156
+					$row['id_theme'] = $guest_theme;
1157
+		}
1117 1158
 
1118
-		if (isset($context['available_themes'][$row['id_theme']]))
1119
-			$context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count'];
1120
-		else
1121
-			$context['available_themes'][$guest_theme]['num_users'] += $row['the_count'];
1159
+		if (isset($context['available_themes'][$row['id_theme']])) {
1160
+					$context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count'];
1161
+		} else {
1162
+					$context['available_themes'][$guest_theme]['num_users'] += $row['the_count'];
1163
+		}
1122 1164
 	}
1123 1165
 	$smcFunc['db_free_result']($request);
1124 1166
 
@@ -1137,8 +1179,9 @@  discard block
 block discarded – undo
1137 1179
 				'id_member' => isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? array(-1, $context['current_member']) : array(-1),
1138 1180
 			)
1139 1181
 		);
1140
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1141
-			$variant_preferences[$row['id_theme']] = $row['value'];
1182
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1183
+					$variant_preferences[$row['id_theme']] = $row['value'];
1184
+		}
1142 1185
 		$smcFunc['db_free_result']($request);
1143 1186
 	}
1144 1187
 
@@ -1149,17 +1192,18 @@  discard block
 block discarded – undo
1149 1192
 	foreach ($context['available_themes'] as $id_theme => $theme_data)
1150 1193
 	{
1151 1194
 		// Don't try to load the forum or board default theme's data... it doesn't have any!
1152
-		if ($id_theme == 0)
1153
-			continue;
1195
+		if ($id_theme == 0) {
1196
+					continue;
1197
+		}
1154 1198
 
1155 1199
 		// The thumbnail needs the correct path.
1156 1200
 		$settings['images_url'] = &$theme_data['images_url'];
1157 1201
 
1158
-		if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'))
1159
-			include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
1160
-		elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php'))
1161
-			include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php');
1162
-		else
1202
+		if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php')) {
1203
+					include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
1204
+		} elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php')) {
1205
+					include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php');
1206
+		} else
1163 1207
 		{
1164 1208
 			$txt['theme_thumbnail_href'] = $theme_data['images_url'] . '/thumbnail.png';
1165 1209
 			$txt['theme_description'] = '';
@@ -1184,15 +1228,17 @@  discard block
 block discarded – undo
1184 1228
 					loadLanguage('Settings');
1185 1229
 
1186 1230
 					$context['available_themes'][$id_theme]['variants'] = array();
1187
-					foreach ($settings['theme_variants'] as $variant)
1188
-						$context['available_themes'][$id_theme]['variants'][$variant] = array(
1231
+					foreach ($settings['theme_variants'] as $variant) {
1232
+											$context['available_themes'][$id_theme]['variants'][$variant] = array(
1189 1233
 							'label' => isset($txt['variant_' . $variant]) ? $txt['variant_' . $variant] : $variant,
1190 1234
 							'thumbnail' => !file_exists($theme_data['theme_dir'] . '/images/thumbnail.png') || file_exists($theme_data['theme_dir'] . '/images/thumbnail_' . $variant . '.png') ? $theme_data['images_url'] . '/thumbnail_' . $variant . '.png' : ($theme_data['images_url'] . '/thumbnail.png'),
1191 1235
 						);
1236
+					}
1192 1237
 
1193 1238
 					$context['available_themes'][$id_theme]['selected_variant'] = isset($_GET['vrt']) ? $_GET['vrt'] : (!empty($variant_preferences[$id_theme]) ? $variant_preferences[$id_theme] : (!empty($settings['default_variant']) ? $settings['default_variant'] : $settings['theme_variants'][0]));
1194
-					if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail']))
1195
-						$context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0];
1239
+					if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'])) {
1240
+											$context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0];
1241
+					}
1196 1242
 
1197 1243
 					$context['available_themes'][$id_theme]['thumbnail_href'] = $context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'];
1198 1244
 					// Allow themes to override the text.
@@ -1208,8 +1254,9 @@  discard block
 block discarded – undo
1208 1254
 	// As long as we're not doing the default theme...
1209 1255
 	if (!isset($_REQUEST['u']) || $_REQUEST['u'] >= 0)
1210 1256
 	{
1211
-		if ($guest_theme != 0)
1212
-			$context['available_themes'][0] = $context['available_themes'][$guest_theme];
1257
+		if ($guest_theme != 0) {
1258
+					$context['available_themes'][0] = $context['available_themes'][$guest_theme];
1259
+		}
1213 1260
 
1214 1261
 		$context['available_themes'][0]['id'] = 0;
1215 1262
 		$context['available_themes'][0]['name'] = $txt['theme_forum_default'];
@@ -1258,14 +1305,16 @@  discard block
 block discarded – undo
1258 1305
 		$action = $smcFunc['htmlspecialchars'](trim($_GET['do']));
1259 1306
 
1260 1307
 		// Got any info from the specific form?
1261
-		if (!isset($_POST['save_' . $action]))
1262
-			fatal_lang_error('theme_install_no_action', false);
1308
+		if (!isset($_POST['save_' . $action])) {
1309
+					fatal_lang_error('theme_install_no_action', false);
1310
+		}
1263 1311
 
1264 1312
 		validateToken('admin-t-' . $action);
1265 1313
 
1266 1314
 		// Hopefully the themes directory is writable, or we might have a problem.
1267
-		if (!is_writable($themedir))
1268
-			fatal_lang_error('theme_install_write_error', 'critical');
1315
+		if (!is_writable($themedir)) {
1316
+					fatal_lang_error('theme_install_write_error', 'critical');
1317
+		}
1269 1318
 
1270 1319
 		// Call the function and handle the result.
1271 1320
 		$result = $subActions[$action]();
@@ -1280,9 +1329,10 @@  discard block
 block discarded – undo
1280 1329
 	}
1281 1330
 
1282 1331
 	// Nope, show a nice error.
1283
-	else
1284
-		fatal_lang_error('theme_install_no_action', false);
1285
-}
1332
+	else {
1333
+			fatal_lang_error('theme_install_no_action', false);
1334
+	}
1335
+	}
1286 1336
 
1287 1337
 /**
1288 1338
  * Installs a theme from a theme package.
@@ -1298,8 +1348,9 @@  discard block
 block discarded – undo
1298 1348
 	$dirtemp = $themedir . '/temp';
1299 1349
 
1300 1350
 	// Make sure the temp dir doesn't already exist
1301
-	if (file_exists($dirtemp))
1302
-		remove_dir($dirtemp);
1351
+	if (file_exists($dirtemp)) {
1352
+			remove_dir($dirtemp);
1353
+	}
1303 1354
 
1304 1355
 	// Create the temp dir.
1305 1356
 	mkdir($dirtemp, 0777);
@@ -1311,17 +1362,20 @@  discard block
 block discarded – undo
1311 1362
 		smf_chmod($dirtemp, '0755');
1312 1363
 
1313 1364
 		// How about now?
1314
-		if (!is_writable($dirtemp))
1315
-			fatal_lang_error('theme_install_write_error', 'critical');
1365
+		if (!is_writable($dirtemp)) {
1366
+					fatal_lang_error('theme_install_write_error', 'critical');
1367
+		}
1316 1368
 	}
1317 1369
 
1318 1370
 	// This happens when the admin session is gone and the user has to login again.
1319
-	if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz']))
1320
-		redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
1371
+	if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz'])) {
1372
+			redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
1373
+	}
1321 1374
 
1322 1375
 	// Another error check layer, something went wrong with the upload.
1323
-	if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0)
1324
-		fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false);
1376
+	if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0) {
1377
+			fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false);
1378
+	}
1325 1379
 
1326 1380
 	// Get the theme's name.
1327 1381
 	$name = pathinfo($_FILES['theme_gz']['name'], PATHINFO_FILENAME);
@@ -1352,11 +1406,10 @@  discard block
 block discarded – undo
1352 1406
 
1353 1407
 		// return all the info.
1354 1408
 		return $context['to_install'];
1409
+	} else {
1410
+			fatal_lang_error('theme_install_error_title', false);
1411
+	}
1355 1412
 	}
1356
-
1357
-	else
1358
-		fatal_lang_error('theme_install_error_title', false);
1359
-}
1360 1413
 
1361 1414
 /**
1362 1415
  * Makes a copy from the default theme, assigns a name for it and installs it.
@@ -1370,15 +1423,17 @@  discard block
 block discarded – undo
1370 1423
 	global $forum_version;
1371 1424
 
1372 1425
 	// There's gotta be something to work with.
1373
-	if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy']))
1374
-		fatal_lang_error('theme_install_error_title', false);
1426
+	if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy'])) {
1427
+			fatal_lang_error('theme_install_error_title', false);
1428
+	}
1375 1429
 
1376 1430
 	// Get a cleaner version.
1377 1431
 	$name = preg_replace('~[^A-Za-z0-9_\- ]~', '', $_REQUEST['copy']);
1378 1432
 
1379 1433
 	// Is there a theme already named like this?
1380
-	if (file_exists($themedir . '/' . $name))
1381
-		fatal_lang_error('theme_install_already_dir', false);
1434
+	if (file_exists($themedir . '/' . $name)) {
1435
+			fatal_lang_error('theme_install_already_dir', false);
1436
+	}
1382 1437
 
1383 1438
 	// This is a brand new theme so set all possible values.
1384 1439
 	$context['to_install'] = array(
@@ -1398,8 +1453,9 @@  discard block
 block discarded – undo
1398 1453
 
1399 1454
 	// Buy some time.
1400 1455
 	@set_time_limit(600);
1401
-	if (function_exists('apache_reset_timeout'))
1402
-		@apache_reset_timeout();
1456
+	if (function_exists('apache_reset_timeout')) {
1457
+			@apache_reset_timeout();
1458
+	}
1403 1459
 
1404 1460
 	// Create subdirectories for css and javascript files.
1405 1461
 	mkdir($context['to_install']['theme_dir'] . '/css', 0777);
@@ -1435,12 +1491,13 @@  discard block
 block discarded – undo
1435 1491
 
1436 1492
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1437 1493
 	{
1438
-		if ($row['variable'] == 'theme_templates')
1439
-			$theme_templates = $row['value'];
1440
-		elseif ($row['variable'] == 'theme_layers')
1441
-			$theme_layers = $row['value'];
1442
-		else
1443
-			continue;
1494
+		if ($row['variable'] == 'theme_templates') {
1495
+					$theme_templates = $row['value'];
1496
+		} elseif ($row['variable'] == 'theme_layers') {
1497
+					$theme_layers = $row['value'];
1498
+		} else {
1499
+					continue;
1500
+		}
1444 1501
 	}
1445 1502
 
1446 1503
 	$smcFunc['db_free_result']($request);
@@ -1499,12 +1556,14 @@  discard block
 block discarded – undo
1499 1556
 	global $themedir, $themeurl, $context;
1500 1557
 
1501 1558
 	// Cannot use the theme dir as a theme dir.
1502
-	if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir))
1503
-		fatal_lang_error('theme_install_invalid_dir', false);
1559
+	if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir)) {
1560
+			fatal_lang_error('theme_install_invalid_dir', false);
1561
+	}
1504 1562
 
1505 1563
 	// Check is there is "something" on the dir.
1506
-	elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml'))
1507
-		fatal_lang_error('theme_install_error', false);
1564
+	elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml')) {
1565
+			fatal_lang_error('theme_install_error', false);
1566
+	}
1508 1567
 
1509 1568
 	$name = basename($_REQUEST['theme_dir']);
1510 1569
 	$name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $name);
@@ -1548,24 +1607,27 @@  discard block
 block discarded – undo
1548 1607
 	}
1549 1608
 
1550 1609
 	// Any special layers?
1551
-	if (isset($settings['catch_action']['layers']))
1552
-		$context['template_layers'] = $settings['catch_action']['layers'];
1610
+	if (isset($settings['catch_action']['layers'])) {
1611
+			$context['template_layers'] = $settings['catch_action']['layers'];
1612
+	}
1553 1613
 
1554 1614
 	// Any function to call?
1555 1615
 	if (isset($settings['catch_action']['function']))
1556 1616
 	{
1557 1617
 		$hook = $settings['catch_action']['function'];
1558 1618
 
1559
-		if (!isset($settings['catch_action']['filename']))
1560
-			$settings['catch_action']['filename'] = '';
1619
+		if (!isset($settings['catch_action']['filename'])) {
1620
+					$settings['catch_action']['filename'] = '';
1621
+		}
1561 1622
 
1562 1623
 		add_integration_function('integrate_wrap_action', $hook, false, $settings['catch_action']['filename'], false);
1563 1624
 		call_integration_hook('integrate_wrap_action');
1564 1625
 	}
1565 1626
 	// And finally, the main sub template ;).
1566
-	if (isset($settings['catch_action']['sub_template']))
1567
-		$context['sub_template'] = $settings['catch_action']['sub_template'];
1568
-}
1627
+	if (isset($settings['catch_action']['sub_template'])) {
1628
+			$context['sub_template'] = $settings['catch_action']['sub_template'];
1629
+	}
1630
+	}
1569 1631
 
1570 1632
 /**
1571 1633
  * Set an option via javascript.
@@ -1584,12 +1646,14 @@  discard block
 block discarded – undo
1584 1646
 	checkSession('get');
1585 1647
 
1586 1648
 	// This good-for-nothing pixel is being used to keep the session alive.
1587
-	if (empty($_GET['var']) || !isset($_GET['val']))
1588
-		redirectexit($settings['images_url'] . '/blank.png');
1649
+	if (empty($_GET['var']) || !isset($_GET['val'])) {
1650
+			redirectexit($settings['images_url'] . '/blank.png');
1651
+	}
1589 1652
 
1590 1653
 	// Sorry, guests can't go any further than this.
1591
-	if ($user_info['is_guest'] || $user_info['id'] == 0)
1592
-		obExit(false);
1654
+	if ($user_info['is_guest'] || $user_info['id'] == 0) {
1655
+			obExit(false);
1656
+	}
1593 1657
 
1594 1658
 	$reservedVars = array(
1595 1659
 		'actual_theme_url',
@@ -1612,8 +1676,9 @@  discard block
 block discarded – undo
1612 1676
 	);
1613 1677
 
1614 1678
 	// Can't change reserved vars.
1615
-	if (in_array(strtolower($_GET['var']), $reservedVars))
1616
-		redirectexit($settings['images_url'] . '/blank.png');
1679
+	if (in_array(strtolower($_GET['var']), $reservedVars)) {
1680
+			redirectexit($settings['images_url'] . '/blank.png');
1681
+	}
1617 1682
 
1618 1683
 	// Use a specific theme?
1619 1684
 	if (isset($_GET['th']) || isset($_GET['id']))
@@ -1629,8 +1694,9 @@  discard block
 block discarded – undo
1629 1694
 	{
1630 1695
 		$options['admin_preferences'] = !empty($options['admin_preferences']) ? smf_json_decode($options['admin_preferences'], true) : array();
1631 1696
 		// New thingy...
1632
-		if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5)
1633
-			$options['admin_preferences'][$_GET['admin_key']] = $_GET['val'];
1697
+		if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5) {
1698
+					$options['admin_preferences'][$_GET['admin_key']] = $_GET['val'];
1699
+		}
1634 1700
 
1635 1701
 		// Change the value to be something nice,
1636 1702
 		$_GET['val'] = json_encode($options['admin_preferences']);
@@ -1660,8 +1726,9 @@  discard block
 block discarded – undo
1660 1726
 	global $context, $scripturl, $boarddir, $smcFunc, $txt;
1661 1727
 
1662 1728
 	// @todo Should this be removed?
1663
-	if (isset($_REQUEST['preview']))
1664
-		die('die() with fire');
1729
+	if (isset($_REQUEST['preview'])) {
1730
+			die('die() with fire');
1731
+	}
1665 1732
 
1666 1733
 	isAllowedTo('admin_forum');
1667 1734
 	loadTemplate('Themes');
@@ -1675,11 +1742,11 @@  discard block
 block discarded – undo
1675 1742
 		foreach ($context['themes'] as $key => $theme)
1676 1743
 		{
1677 1744
 			// There has to be a Settings template!
1678
-			if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css'))
1679
-				unset($context['themes'][$key]);
1680
-
1681
-			else
1682
-				$context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css');
1745
+			if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css')) {
1746
+							unset($context['themes'][$key]);
1747
+			} else {
1748
+							$context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css');
1749
+			}
1683 1750
 		}
1684 1751
 
1685 1752
 		$context['sub_template'] = 'edit_list';
@@ -1694,22 +1761,24 @@  discard block
 block discarded – undo
1694 1761
 	$context['theme_id'] = $currentTheme['id'];
1695 1762
 	$context['browse_title'] = sprintf($txt['themeadmin_browsing_theme'], $currentTheme['name']);
1696 1763
 
1697
-	if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css'))
1698
-		fatal_lang_error('theme_edit_missing', false);
1764
+	if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css')) {
1765
+			fatal_lang_error('theme_edit_missing', false);
1766
+	}
1699 1767
 
1700 1768
 	if (!isset($_REQUEST['filename']))
1701 1769
 	{
1702 1770
 		if (isset($_GET['directory']))
1703 1771
 		{
1704
-			if (substr($_GET['directory'], 0, 1) == '.')
1705
-				$_GET['directory'] = '';
1706
-			else
1772
+			if (substr($_GET['directory'], 0, 1) == '.') {
1773
+							$_GET['directory'] = '';
1774
+			} else
1707 1775
 			{
1708 1776
 				$_GET['directory'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_GET['directory']);
1709 1777
 
1710 1778
 				$temp = realpath($currentTheme['theme_dir'] . '/' . $_GET['directory']);
1711
-				if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir']))
1712
-					$_GET['directory'] = '';
1779
+				if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) {
1780
+									$_GET['directory'] = '';
1781
+				}
1713 1782
 			}
1714 1783
 		}
1715 1784
 
@@ -1728,37 +1797,39 @@  discard block
 block discarded – undo
1728 1797
 				'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $temp,
1729 1798
 				'size' => '',
1730 1799
 			));
1800
+		} else {
1801
+					$context['theme_files'] = get_file_listing($currentTheme['theme_dir'], '');
1731 1802
 		}
1732
-		else
1733
-			$context['theme_files'] = get_file_listing($currentTheme['theme_dir'], '');
1734 1803
 
1735 1804
 		$context['sub_template'] = 'edit_browse';
1736 1805
 
1737 1806
 		return;
1738
-	}
1739
-	else
1807
+	} else
1740 1808
 	{
1741
-		if (substr($_REQUEST['filename'], 0, 1) == '.')
1742
-			$_REQUEST['filename'] = '';
1743
-		else
1809
+		if (substr($_REQUEST['filename'], 0, 1) == '.') {
1810
+					$_REQUEST['filename'] = '';
1811
+		} else
1744 1812
 		{
1745 1813
 			$_REQUEST['filename'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_REQUEST['filename']);
1746 1814
 
1747 1815
 			$temp = realpath($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1748
-			if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir']))
1749
-				$_REQUEST['filename'] = '';
1816
+			if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) {
1817
+							$_REQUEST['filename'] = '';
1818
+			}
1750 1819
 		}
1751 1820
 
1752
-		if (empty($_REQUEST['filename']))
1753
-			fatal_lang_error('theme_edit_missing', false);
1821
+		if (empty($_REQUEST['filename'])) {
1822
+					fatal_lang_error('theme_edit_missing', false);
1823
+		}
1754 1824
 	}
1755 1825
 
1756 1826
 	if (isset($_POST['save']))
1757 1827
 	{
1758 1828
 		if (checkSession('post', '', false) == '' && validateToken('admin-te-' . md5($_GET['th'] . '-' . $_REQUEST['filename']), 'post', false) == true)
1759 1829
 		{
1760
-			if (is_array($_POST['entire_file']))
1761
-				$_POST['entire_file'] = implode("\n", $_POST['entire_file']);
1830
+			if (is_array($_POST['entire_file'])) {
1831
+							$_POST['entire_file'] = implode("\n", $_POST['entire_file']);
1832
+			}
1762 1833
 
1763 1834
 			$_POST['entire_file'] = rtrim(strtr($_POST['entire_file'], array("\r" => '', '   ' => "\t")));
1764 1835
 
@@ -1770,10 +1841,11 @@  discard block
 block discarded – undo
1770 1841
 				fclose($fp);
1771 1842
 
1772 1843
 				$error = @file_get_contents($currentTheme['theme_url'] . '/tmp_' . session_id() . '.php');
1773
-				if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0)
1774
-					$error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php';
1775
-				else
1776
-					unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php');
1844
+				if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0) {
1845
+									$error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php';
1846
+				} else {
1847
+									unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php');
1848
+				}
1777 1849
 			}
1778 1850
 
1779 1851
 			if (!isset($error_file))
@@ -1794,10 +1866,11 @@  discard block
 block discarded – undo
1794 1866
 			$context['sub_template'] = 'edit_file';
1795 1867
 
1796 1868
 			// Recycle the submitted data.
1797
-			if (is_array($_POST['entire_file']))
1798
-				$context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file']));
1799
-			else
1800
-				$context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']);
1869
+			if (is_array($_POST['entire_file'])) {
1870
+							$context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file']));
1871
+			} else {
1872
+							$context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']);
1873
+			}
1801 1874
 
1802 1875
 			$context['edit_filename'] = $smcFunc['htmlspecialchars']($_POST['filename']);
1803 1876
 
@@ -1820,17 +1893,17 @@  discard block
 block discarded – undo
1820 1893
 		$context['sub_template'] = 'edit_style';
1821 1894
 
1822 1895
 		$context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(file_get_contents($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']), array("\t" => '   ')));
1823
-	}
1824
-	elseif (substr($_REQUEST['filename'], -13) == '.template.php')
1896
+	} elseif (substr($_REQUEST['filename'], -13) == '.template.php')
1825 1897
 	{
1826 1898
 		$context['sub_template'] = 'edit_template';
1827 1899
 
1828
-		if (!isset($error_file))
1829
-			$file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1830
-		else
1900
+		if (!isset($error_file)) {
1901
+					$file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1902
+		} else
1831 1903
 		{
1832
-			if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0)
1833
-				$context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2];
1904
+			if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0) {
1905
+							$context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2];
1906
+			}
1834 1907
 			$file_data = file($error_file);
1835 1908
 			unlink($error_file);
1836 1909
 		}
@@ -1844,8 +1917,9 @@  discard block
 block discarded – undo
1844 1917
 				// Try to format the functions a little nicer...
1845 1918
 				$context['file_parts'][$j]['data'] = trim($context['file_parts'][$j]['data']) . "\n";
1846 1919
 
1847
-				if (empty($context['file_parts'][$j]['lines']))
1848
-					unset($context['file_parts'][$j]);
1920
+				if (empty($context['file_parts'][$j]['lines'])) {
1921
+									unset($context['file_parts'][$j]);
1922
+				}
1849 1923
 				$context['file_parts'][++$j] = array('lines' => 0, 'line' => $i + 1, 'data' => '');
1850 1924
 			}
1851 1925
 
@@ -1854,8 +1928,7 @@  discard block
 block discarded – undo
1854 1928
 		}
1855 1929
 
1856 1930
 		$context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(implode('', $file_data), array("\t" => '   ')));
1857
-	}
1858
-	else
1931
+	} else
1859 1932
 	{
1860 1933
 		$context['sub_template'] = 'edit_file';
1861 1934
 
@@ -1881,8 +1954,9 @@  discard block
 block discarded – undo
1881 1954
 
1882 1955
 	$_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
1883 1956
 
1884
-	if (empty($_GET['th']))
1885
-		fatal_lang_error('theme_install_invalid_id');
1957
+	if (empty($_GET['th'])) {
1958
+			fatal_lang_error('theme_install_invalid_id');
1959
+	}
1886 1960
 
1887 1961
 	// Get the theme info.
1888 1962
 	$theme = get_single_theme($_GET['th']);
@@ -1890,25 +1964,24 @@  discard block
 block discarded – undo
1890 1964
 
1891 1965
 	if (isset($_REQUEST['template']) && preg_match('~[\./\\\\:\0]~', $_REQUEST['template']) == 0)
1892 1966
 	{
1893
-		if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php'))
1894
-			$filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php';
1895
-
1896
-		else
1897
-			fatal_lang_error('no_access', false);
1967
+		if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php')) {
1968
+					$filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php';
1969
+		} else {
1970
+					fatal_lang_error('no_access', false);
1971
+		}
1898 1972
 
1899 1973
 		$fp = fopen($theme['theme_dir'] . '/' . $_REQUEST['template'] . '.template.php', 'w');
1900 1974
 		fwrite($fp, file_get_contents($filename));
1901 1975
 		fclose($fp);
1902 1976
 
1903 1977
 		redirectexit('action=admin;area=theme;th=' . $context['theme_id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=copy');
1904
-	}
1905
-	elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0)
1978
+	} elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0)
1906 1979
 	{
1907
-		if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php'))
1908
-			$filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php';
1909
-
1910
-		else
1911
-			fatal_lang_error('no_access', false);
1980
+		if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php')) {
1981
+					$filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php';
1982
+		} else {
1983
+					fatal_lang_error('no_access', false);
1984
+		}
1912 1985
 
1913 1986
 		$fp = fopen($theme['theme_dir'] . '/languages/' . $_REQUEST['lang_file'] . '.php', 'w');
1914 1987
 		fwrite($fp, file_get_contents($filename));
@@ -1923,16 +1996,18 @@  discard block
 block discarded – undo
1923 1996
 	$dir = dir($settings['default_theme_dir']);
1924 1997
 	while ($entry = $dir->read())
1925 1998
 	{
1926
-		if (substr($entry, -13) == '.template.php')
1927
-			$templates[] = substr($entry, 0, -13);
1999
+		if (substr($entry, -13) == '.template.php') {
2000
+					$templates[] = substr($entry, 0, -13);
2001
+		}
1928 2002
 	}
1929 2003
 	$dir->close();
1930 2004
 
1931 2005
 	$dir = dir($settings['default_theme_dir'] . '/languages');
1932 2006
 	while ($entry = $dir->read())
1933 2007
 	{
1934
-		if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches))
1935
-			$lang_files[] = $matches[1];
2008
+		if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches)) {
2009
+					$lang_files[] = $matches[1];
2010
+		}
1936 2011
 	}
1937 2012
 	$dir->close();
1938 2013
 
@@ -1940,21 +2015,23 @@  discard block
 block discarded – undo
1940 2015
 	natcasesort($lang_files);
1941 2016
 
1942 2017
 	$context['available_templates'] = array();
1943
-	foreach ($templates as $template)
1944
-		$context['available_templates'][$template] = array(
2018
+	foreach ($templates as $template) {
2019
+			$context['available_templates'][$template] = array(
1945 2020
 			'filename' => $template . '.template.php',
1946 2021
 			'value' => $template,
1947 2022
 			'already_exists' => false,
1948 2023
 			'can_copy' => is_writable($theme['theme_dir']),
1949 2024
 		);
2025
+	}
1950 2026
 	$context['available_language_files'] = array();
1951
-	foreach ($lang_files as $file)
1952
-		$context['available_language_files'][$file] = array(
2027
+	foreach ($lang_files as $file) {
2028
+			$context['available_language_files'][$file] = array(
1953 2029
 			'filename' => $file . '.php',
1954 2030
 			'value' => $file,
1955 2031
 			'already_exists' => false,
1956 2032
 			'can_copy' => file_exists($theme['theme_dir'] . '/languages') ? is_writable($theme['theme_dir'] . '/languages') : is_writable($theme['theme_dir']),
1957 2033
 		);
2034
+	}
1958 2035
 
1959 2036
 	$dir = dir($theme['theme_dir']);
1960 2037
 	while ($entry = $dir->read())
Please login to merge, or discard this patch.
Themes/default/Themes.template.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -645,12 +645,12 @@
 block discarded – undo
645 645
 					</dd>';
646 646
 		}
647 647
 		// A Textarea?
648
-        	elseif ($setting['type'] == 'textarea')
648
+			elseif ($setting['type'] == 'textarea')
649 649
 		{
650 650
 			echo '
651 651
 					<dd>
652 652
 						<textarea rows="4" style="width: 95%;" cols="40" name="', !empty($setting['default']) ? 'default_' : '', 'options[', $setting['id'], ']" id="', $setting['id'], '">', $setting['value'], '</textarea>';
653
-                echo '
653
+				echo '
654 654
                 			</dd>';
655 655
 		}
656 656
 		// A regular input box, then?
Please login to merge, or discard this patch.
Braces   +103 added lines, -80 removed lines patch added patch discarded remove patch
@@ -54,9 +54,10 @@  discard block
 block discarded – undo
54 54
 					<dd>
55 55
 						<div id="known_themes_list">';
56 56
 
57
-	foreach ($context['themes'] as $theme)
58
-		echo '
57
+	foreach ($context['themes'] as $theme) {
58
+			echo '
59 59
 							<label for="options-known_themes_', $theme['id'], '"><input type="checkbox" name="options[known_themes][]" id="options-known_themes_', $theme['id'], '" value="', $theme['id'], '"', $theme['known'] ? ' checked' : '', ' class="input_check"> ', $theme['name'], '</label><br>';
60
+	}
60 61
 
61 62
 		echo '
62 63
 						</div>
@@ -73,9 +74,10 @@  discard block
 block discarded – undo
73 74
 						<select name="options[theme_guests]" id="theme_guests">';
74 75
 
75 76
 	// Put an option for each theme in the select box.
76
-	foreach ($context['themes'] as $theme)
77
-		echo '
77
+	foreach ($context['themes'] as $theme) {
78
+			echo '
78 79
 							<option value="', $theme['id'], '"', $modSettings['theme_guests'] == $theme['id'] ? ' selected' : '', '>', $theme['name'], '</option>';
80
+	}
79 81
 
80 82
 	echo '
81 83
 						</select>
@@ -90,9 +92,10 @@  discard block
 block discarded – undo
90 92
 							<option value="0">', $txt['theme_forum_default'], '</option>';
91 93
 
92 94
 	// Same thing, this time for changing the theme of everyone.
93
-	foreach ($context['themes'] as $theme)
94
-		echo '
95
+	foreach ($context['themes'] as $theme) {
96
+			echo '
95 97
 							<option value="', $theme['id'], '">', $theme['name'], '</option>';
98
+	}
96 99
 
97 100
 	echo '
98 101
 						</select>
@@ -189,11 +192,12 @@  discard block
 block discarded – undo
189 192
 	global $context, $scripturl, $txt;
190 193
 
191 194
 	// Show a nice confirmation message.
192
-	if (isset($_GET['done']))
193
-		echo '
195
+	if (isset($_GET['done'])) {
196
+			echo '
194 197
 	<div class="infobox">
195 198
 		', $txt['theme_confirmed_' . $_GET['done']], '
196 199
 	</div>';
200
+	}
197 201
 
198 202
 	echo '
199 203
 	<div id="admincenter">';
@@ -356,11 +360,12 @@  discard block
 block discarded – undo
356 360
 		if (empty($setting) || !is_array($setting))
357 361
 		{
358 362
 			// Insert a separator (unless this is the first item in the list)
359
-			if ($i !== $first_option_key)
360
-				echo '
363
+			if ($i !== $first_option_key) {
364
+							echo '
361 365
 				</dl>
362 366
 				<hr>
363 367
 				<dl class="settings">';
368
+			}
364 369
 
365 370
 			// Should we give a name to this section?
366 371
 			if (is_string($setting) && !empty($setting))
@@ -368,9 +373,9 @@  discard block
 block discarded – undo
368 373
 				$titled_section = true;
369 374
 				echo '
370 375
 					<dt><b>' . $setting . '</b></dt><dd></dd>';
376
+			} else {
377
+							$titled_section = false;
371 378
 			}
372
-			else
373
-				$titled_section = false;
374 379
 
375 380
 			continue;
376 381
 		}
@@ -379,19 +384,21 @@  discard block
 block discarded – undo
379 384
 					<dt ', $context['theme_options_reset'] ? 'style="width:50%"' : '', '>';
380 385
 
381 386
 		// Show the change option box ?
382
-		if ($context['theme_options_reset'])
383
-			echo '
387
+		if ($context['theme_options_reset']) {
388
+					echo '
384 389
 						<span class="floatleft"><select name="', !empty($setting['default']) ? 'default_' : '', 'options_master[', $setting['id'], ']" onchange="this.form.options_', $setting['id'], '.disabled = this.selectedIndex != 1;">
385 390
 							<option value="0" selected>', $txt['themeadmin_reset_options_none'], '</option>
386 391
 							<option value="1">', $txt['themeadmin_reset_options_change'], '</option>
387 392
 							<option value="2">', $txt['themeadmin_reset_options_default'], '</option>
388 393
 						</select>&nbsp;</span>';
394
+		}
389 395
 
390 396
 		echo '
391 397
 						<label for="options_', $setting['id'], '">', !$titled_section ? '<b>' : '', $setting['label'], !$titled_section ? '</b>' : '', '</label>';
392
-		if (isset($setting['description']))
393
-			echo '
398
+		if (isset($setting['description'])) {
399
+					echo '
394 400
 						<br><span class="smalltext">', $setting['description'], '</span>';
401
+		}
395 402
 		echo '
396 403
 					</dt>';
397 404
 
@@ -433,13 +440,11 @@  discard block
 block discarded – undo
433 440
 
434 441
 				echo '
435 442
 						<input type="number"', $min . $max . $step;
436
-			}
437
-			else if (isset($setting['type']) && $setting['type'] == 'url')
443
+			} else if (isset($setting['type']) && $setting['type'] == 'url')
438 444
 			{
439 445
 				echo'
440 446
 						<input type="url"';
441
-			}
442
-			else
447
+			} else
443 448
 			{
444 449
 				echo '
445 450
 						<input type="text"';
@@ -483,8 +488,8 @@  discard block
 block discarded – undo
483 488
 			<br>';
484 489
 
485 490
 	// @todo Why can't I edit the default theme popup.
486
-	if ($context['theme_settings']['theme_id'] != 1)
487
-		echo '
491
+	if ($context['theme_settings']['theme_id'] != 1) {
492
+			echo '
488 493
 			<div class="cat_bar">
489 494
 				<h3 class="catbg config_hd">
490 495
 					', $txt['theme_edit'], '
@@ -500,6 +505,7 @@  discard block
 block discarded – undo
500 505
 					</li>
501 506
 				</ul>
502 507
 			</div>';
508
+	}
503 509
 
504 510
 	echo '
505 511
 			<div class="cat_bar">
@@ -553,9 +559,10 @@  discard block
 block discarded – undo
553 559
 					<dd>
554 560
 						<select id="variant" name="options[default_variant]" onchange="changeVariant(this.value)">';
555 561
 
556
-		foreach ($context['theme_variants'] as $key => $variant)
557
-			echo '
562
+		foreach ($context['theme_variants'] as $key => $variant) {
563
+					echo '
558 564
 							<option value="', $key, '"', $context['default_variant'] == $key ? ' selected' : '', '>', $variant['label'], '</option>';
565
+		}
559 566
 
560 567
 		echo '
561 568
 						</select>
@@ -590,11 +597,12 @@  discard block
 block discarded – undo
590 597
 		if (empty($setting) || !is_array($setting))
591 598
 		{
592 599
 			// We don't need a separator before the first list element
593
-			if ($i !== $first_setting_key)
594
-				echo '
600
+			if ($i !== $first_setting_key) {
601
+							echo '
595 602
 				</dl>
596 603
 				<hr>
597 604
 				<dl class="settings">';
605
+			}
598 606
 
599 607
 			// Add a fake heading?
600 608
 			if (is_string($setting) && !empty($setting))
@@ -602,9 +610,9 @@  discard block
 block discarded – undo
602 610
 				$titled_section = true;
603 611
 				echo '
604 612
 					<dt><b>' . $setting . '</b></dt><dd></dd>';
613
+			} else {
614
+							$titled_section = false;
605 615
 			}
606
-			else
607
-				$titled_section = false;
608 616
 
609 617
 			continue;
610 618
 		}
@@ -613,9 +621,10 @@  discard block
 block discarded – undo
613 621
 					<dt>
614 622
 						<label for="', $setting['id'], '">', !$titled_section ? '<b>' : '', $setting['label'], !$titled_section ? '</b>' : '', '</label>:';
615 623
 
616
-		if (isset($setting['description']))
617
-			echo '<br>
624
+		if (isset($setting['description'])) {
625
+					echo '<br>
618 626
 						<span class="smalltext">', $setting['description'], '</span>';
627
+		}
619 628
 
620 629
 		echo '
621 630
 					</dt>';
@@ -636,9 +645,10 @@  discard block
 block discarded – undo
636 645
 					<dd>
637 646
 						<select name="', !empty($setting['default']) ? 'default_' : '', 'options[', $setting['id'], ']" id="', $setting['id'], '">';
638 647
 
639
-			foreach ($setting['options'] as $value => $label)
640
-				echo '
648
+			foreach ($setting['options'] as $value => $label) {
649
+							echo '
641 650
 							<option value="', $value, '"', $value == $setting['value'] ? ' selected' : '', '>', $label, '</option>';
651
+			}
642 652
 
643 653
 			echo '
644 654
 						</select>
@@ -667,13 +677,11 @@  discard block
 block discarded – undo
667 677
 
668 678
 				echo '
669 679
 						<input type="number"', $min . $max . $step;
670
-			}
671
-			else if (isset($setting['type']) && $setting['type'] == 'url')
680
+			} else if (isset($setting['type']) && $setting['type'] == 'url')
672 681
 			{
673 682
 				echo'
674 683
 						<input type="url"';
675
-			}
676
-			else
684
+			} else
677 685
 			{
678 686
 				echo '
679 687
 						<input type="text"';
@@ -826,21 +834,23 @@  discard block
 block discarded – undo
826 834
 		<div class="windowbg">';
827 835
 
828 836
 	// Oops! there was an error :(
829
-	if (!empty($context['error_message']))
830
-		echo '
837
+	if (!empty($context['error_message'])) {
838
+			echo '
831 839
 			<p>
832 840
 				', $context['error_message'], '
833 841
 			</p>';
842
+	}
834 843
 
835 844
 	// Not much to show except a link back...
836
-	else
837
-		echo '
845
+	else {
846
+			echo '
838 847
 			<p>
839 848
 				<a href="', $scripturl, '?action=admin;area=theme;sa=list;th=', $context['installed_theme']['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $context['installed_theme']['name'], '</a> ', $txt['theme_' . (isset($context['installed_theme']['updated']) ? 'updated' : 'installed') . '_message'], '
840 849
 			</p>
841 850
 			<p>
842 851
 				<a href="', $scripturl, '?action=admin;area=theme;sa=admin;', $context['session_var'], '=', $context['session_id'], '">', $txt['back'], '</a>
843 852
 			</p>';
853
+	}
844 854
 
845 855
 	echo '
846 856
 		</div>
@@ -907,10 +917,11 @@  discard block
 block discarded – undo
907 917
 					<span class="floatleft">', $template['filename'], $template['already_exists'] ? ' <span class="error">(' . $txt['themeadmin_edit_exists'] . ')</span>' : '', '</span>
908 918
 					<span class="floatright">';
909 919
 
910
-		if ($template['can_copy'])
911
-			echo '<a href="', $scripturl, '?action=admin;area=theme;th=', $context['theme_id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=copy;template=', $template['value'], '" data-confirm="', $template['already_exists'] ? $txt['themeadmin_edit_overwrite_confirm'] : $txt['themeadmin_edit_copy_confirm'], '" class="you_sure">', $txt['themeadmin_edit_do_copy'], '</a>';
912
-		else
913
-			echo $txt['themeadmin_edit_no_copy'];
920
+		if ($template['can_copy']) {
921
+					echo '<a href="', $scripturl, '?action=admin;area=theme;th=', $context['theme_id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=copy;template=', $template['value'], '" data-confirm="', $template['already_exists'] ? $txt['themeadmin_edit_overwrite_confirm'] : $txt['themeadmin_edit_copy_confirm'], '" class="you_sure">', $txt['themeadmin_edit_do_copy'], '</a>';
922
+		} else {
923
+					echo $txt['themeadmin_edit_no_copy'];
924
+		}
914 925
 
915 926
 		echo '
916 927
 					</span>
@@ -933,11 +944,12 @@  discard block
 block discarded – undo
933 944
 	echo '
934 945
 	<div id="admincenter">';
935 946
 
936
-	if (!empty($context['browse_title']))
937
-		echo '
947
+	if (!empty($context['browse_title'])) {
948
+			echo '
938 949
 		<div class="cat_bar">
939 950
 			<h3 class="catbg">', $context['browse_title'], '</h3>
940 951
 		</div>';
952
+	}
941 953
 
942 954
 	echo '
943 955
 		<table class="table_grid tborder">
@@ -957,14 +969,13 @@  discard block
 block discarded – undo
957 969
 			<tr class="windowbg">
958 970
 				<td>';
959 971
 
960
-		if ($file['is_editable'])
961
-			echo '<a href="', $file['href'], '"', $file['is_template'] ? ' style="font-weight: bold;"' : '', '>', $file['filename'], '</a>';
962
-
963
-		elseif ($file['is_directory'])
964
-			echo '<a href="', $file['href'], '" class="is_directory"><span class="generic_icons folder"></span>', $file['filename'], '</a>';
965
-
966
-		else
967
-			echo $file['filename'];
972
+		if ($file['is_editable']) {
973
+					echo '<a href="', $file['href'], '"', $file['is_template'] ? ' style="font-weight: bold;"' : '', '>', $file['filename'], '</a>';
974
+		} elseif ($file['is_directory']) {
975
+					echo '<a href="', $file['href'], '" class="is_directory"><span class="generic_icons folder"></span>', $file['filename'], '</a>';
976
+		} else {
977
+					echo $file['filename'];
978
+		}
968 979
 
969 980
 		echo '
970 981
 				</td>
@@ -986,11 +997,12 @@  discard block
 block discarded – undo
986 997
 {
987 998
 	global $context, $settings, $scripturl, $txt;
988 999
 
989
-	if ($context['session_error'])
990
-		echo '
1000
+	if ($context['session_error']) {
1001
+			echo '
991 1002
 	<div class="errorbox">
992 1003
 		', $txt['error_session_timeout'], '
993 1004
 	</div>';
1005
+	}
994 1006
 
995 1007
 	// From now on no one can complain that editing css is difficult. If you disagree, go to www.w3schools.com.
996 1008
 	echo '
@@ -1053,17 +1065,18 @@  discard block
 block discarded – undo
1053 1065
 					try
1054 1066
 					{
1055 1067
 					';
1056
-	if (isBrowser('is_ie'))
1057
-		echo '
1068
+	if (isBrowser('is_ie')) {
1069
+			echo '
1058 1070
 						var sheets = frames["css_preview_box"].document.styleSheets;
1059 1071
 						for (var j = 0; j < sheets.length; j++)
1060 1072
 						{
1061 1073
 							if (sheets[j].id == "css_preview_box")
1062 1074
 								sheets[j].cssText = document.forms.stylesheetForm.entire_file.value;
1063 1075
 						}';
1064
-	else
1065
-		echo '
1076
+	} else {
1077
+			echo '
1066 1078
 						setInnerHTML(frames["css_preview_box"].document.getElementById("css_preview_sheet"), document.forms.stylesheetForm.entire_file.value);';
1079
+	}
1067 1080
 	echo '
1068 1081
 					}
1069 1082
 					catch (e)
@@ -1115,9 +1128,10 @@  discard block
 block discarded – undo
1115 1128
 			</div>
1116 1129
 			<div class="windowbg">';
1117 1130
 
1118
-	if (!$context['allow_save'])
1119
-		echo '
1131
+	if (!$context['allow_save']) {
1132
+			echo '
1120 1133
 				', $txt['theme_edit_no_save'], ': ', $context['allow_save_filename'], '<br>';
1134
+	}
1121 1135
 
1122 1136
 	echo '
1123 1137
 				<textarea name="entire_file" cols="80" rows="20" style="width: 96%; font-family: monospace; margin-top: 1ex; white-space: pre;" onkeyup="setPreviewTimeout();" onchange="refreshPreview(true);">', $context['entire_file'], '</textarea><br>
@@ -1130,9 +1144,10 @@  discard block
 block discarded – undo
1130 1144
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">';
1131 1145
 
1132 1146
 	// Hopefully it exists.
1133
-	if (isset($context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token']))
1134
-		echo '
1147
+	if (isset($context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token'])) {
1148
+			echo '
1135 1149
 			<input type="hidden" name="', $context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token_var'], '" value="', $context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token'], '">';
1150
+	}
1136 1151
 
1137 1152
 	echo '
1138 1153
 		</form>
@@ -1146,18 +1161,20 @@  discard block
 block discarded – undo
1146 1161
 {
1147 1162
 	global $context, $scripturl, $txt;
1148 1163
 
1149
-	if ($context['session_error'])
1150
-		echo '
1164
+	if ($context['session_error']) {
1165
+			echo '
1151 1166
 	<div class="errorbox">
1152 1167
 		', $txt['error_session_timeout'], '
1153 1168
 	</div>';
1169
+	}
1154 1170
 
1155
-	if (isset($context['parse_error']))
1156
-		echo '
1171
+	if (isset($context['parse_error'])) {
1172
+			echo '
1157 1173
 	<div class="errorbox">
1158 1174
 		', $txt['themeadmin_edit_error'], '
1159 1175
 			<div><pre>', $context['parse_error'], '</pre></div>
1160 1176
 	</div>';
1177
+	}
1161 1178
 
1162 1179
 	// Just show a big box.... gray out the Save button if it's not saveable... (ie. not 777.)
1163 1180
 	echo '
@@ -1168,16 +1185,18 @@  discard block
 block discarded – undo
1168 1185
 			</div>
1169 1186
 			<div class="windowbg">';
1170 1187
 
1171
-	if (!$context['allow_save'])
1172
-		echo '
1188
+	if (!$context['allow_save']) {
1189
+			echo '
1173 1190
 				', $txt['theme_edit_no_save'], ': ', $context['allow_save_filename'], '<br>';
1191
+	}
1174 1192
 
1175
-	foreach ($context['file_parts'] as $part)
1176
-		echo '
1193
+	foreach ($context['file_parts'] as $part) {
1194
+			echo '
1177 1195
 				<label for="on_line', $part['line'], '">', $txt['themeadmin_edit_on_line'], ' ', $part['line'], '</label>:<br>
1178 1196
 				<div class="centertext">
1179 1197
 					<textarea id="on_line', $part['line'], '" name="entire_file[]" cols="80" rows="', $part['lines'] > 14 ? '14' : $part['lines'], '" class="edit_file">', $part['data'], '</textarea>
1180 1198
 				</div>';
1199
+	}
1181 1200
 
1182 1201
 	echo '
1183 1202
 				<div class="padding righttext">
@@ -1186,9 +1205,10 @@  discard block
 block discarded – undo
1186 1205
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">';
1187 1206
 
1188 1207
 	// Hopefully it exists.
1189
-	if (isset($context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token']))
1190
-		echo '
1208
+	if (isset($context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token'])) {
1209
+			echo '
1191 1210
 					<input type="hidden" name="', $context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token_var'], '" value="', $context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token'], '">';
1211
+	}
1192 1212
 
1193 1213
 	echo '
1194 1214
 				</div>
@@ -1204,18 +1224,20 @@  discard block
 block discarded – undo
1204 1224
 {
1205 1225
 	global $context, $scripturl, $txt;
1206 1226
 
1207
-	if ($context['session_error'])
1208
-		echo '
1227
+	if ($context['session_error']) {
1228
+			echo '
1209 1229
 	<div class="errorbox">
1210 1230
 		', $txt['error_session_timeout'], '
1211 1231
 	</div>';
1232
+	}
1212 1233
 
1213 1234
 	//Is this file writeable?
1214
-	if (!$context['allow_save'])
1215
-		echo '
1235
+	if (!$context['allow_save']) {
1236
+			echo '
1216 1237
 	<div class="errorbox">
1217 1238
 		', $txt['theme_edit_no_save'], ': ', $context['allow_save_filename'], '
1218 1239
 	</div>';
1240
+	}
1219 1241
 
1220 1242
 	// Just show a big box.... gray out the Save button if it's not saveable... (ie. not 777.)
1221 1243
 	echo '
@@ -1231,9 +1253,10 @@  discard block
 block discarded – undo
1231 1253
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">';
1232 1254
 
1233 1255
 	// Hopefully it exists.
1234
-	if (isset($context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token']))
1235
-		echo '
1256
+	if (isset($context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token'])) {
1257
+			echo '
1236 1258
 				<input type="hidden" name="', $context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token_var'], '" value="', $context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token'], '">';
1259
+	}
1237 1260
 
1238 1261
 	echo '
1239 1262
 			</div>
Please login to merge, or discard this patch.
Sources/Subs-MembersOnline.php 1 patch
Braces   +27 added lines, -21 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Retrieve a list and several other statistics of the users currently online.
@@ -45,8 +46,9 @@  discard block
 block discarded – undo
45 46
 	}
46 47
 
47 48
 	// Not allowed sort method? Bang! Error!
48
-	elseif (!in_array($membersOnlineOptions['sort'], $allowed_sort_options))
49
-		trigger_error('Sort method for getMembersOnlineStats() function is not allowed', E_USER_NOTICE);
49
+	elseif (!in_array($membersOnlineOptions['sort'], $allowed_sort_options)) {
50
+			trigger_error('Sort method for getMembersOnlineStats() function is not allowed', E_USER_NOTICE);
51
+	}
50 52
 
51 53
 	// Initialize the array that'll be returned later on.
52 54
 	$membersOnlineStats = array(
@@ -63,8 +65,9 @@  discard block
 block discarded – undo
63 65
 	// Get any spiders if enabled.
64 66
 	$spiders = array();
65 67
 	$spider_finds = array();
66
-	if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] < 3 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache']))
67
-		$spiders = smf_json_decode($modSettings['spider_name_cache'], true);
68
+	if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] < 3 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache'])) {
69
+			$spiders = smf_json_decode($modSettings['spider_name_cache'], true);
70
+	}
68 71
 
69 72
 	// Load the users online right now.
70 73
 	$request = $smcFunc['db_query']('', '
@@ -92,9 +95,7 @@  discard block
 block discarded – undo
92 95
 			$membersOnlineStats['num_guests']++;
93 96
 
94 97
 			continue;
95
-		}
96
-
97
-		elseif (empty($row['show_online']) && empty($membersOnlineOptions['show_hidden']))
98
+		} elseif (empty($row['show_online']) && empty($membersOnlineOptions['show_hidden']))
98 99
 		{
99 100
 			// Just increase the stats and don't add this hidden user to any list.
100 101
 			$membersOnlineStats['num_users_hidden']++;
@@ -102,10 +103,11 @@  discard block
 block discarded – undo
102 103
 		}
103 104
 
104 105
 		// Some basic color coding...
105
-		if (!empty($row['online_color']))
106
-			$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
107
-		else
108
-			$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
106
+		if (!empty($row['online_color'])) {
107
+					$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
108
+		} else {
109
+					$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
110
+		}
109 111
 
110 112
 		// Buddies get counted and highlighted.
111 113
 		$is_buddy = in_array($row['id_member'], $user_info['buddies']);
@@ -132,12 +134,13 @@  discard block
 block discarded – undo
132 134
 		$membersOnlineStats['list_users_online'][$row[$membersOnlineOptions['sort']] . '_' . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
133 135
 
134 136
 		// Store all distinct (primary) membergroups that are shown.
135
-		if (!isset($membersOnlineStats['online_groups'][$row['id_group']]))
136
-			$membersOnlineStats['online_groups'][$row['id_group']] = array(
137
+		if (!isset($membersOnlineStats['online_groups'][$row['id_group']])) {
138
+					$membersOnlineStats['online_groups'][$row['id_group']] = array(
137 139
 				'id' => $row['id_group'],
138 140
 				'name' => $row['group_name'],
139 141
 				'color' => $row['online_color']
140 142
 			);
143
+		}
141 144
 	}
142 145
 	$smcFunc['db_free_result']($request);
143 146
 
@@ -198,11 +201,12 @@  discard block
 block discarded – undo
198 201
 	$settingsToUpdate = array();
199 202
 
200 203
 	// More members on now than ever were?  Update it!
201
-	if (!isset($modSettings['mostOnline']) || $total_users_online >= $modSettings['mostOnline'])
202
-		$settingsToUpdate = array(
204
+	if (!isset($modSettings['mostOnline']) || $total_users_online >= $modSettings['mostOnline']) {
205
+			$settingsToUpdate = array(
203 206
 			'mostOnline' => $total_users_online,
204 207
 			'mostDate' => time()
205 208
 		);
209
+	}
206 210
 
207 211
 	$date = strftime('%Y-%m-%d', forum_time(false));
208 212
 
@@ -234,8 +238,9 @@  discard block
 block discarded – undo
234 238
 		{
235 239
 			list ($modSettings['mostOnlineToday']) = $smcFunc['db_fetch_row']($request);
236 240
 
237
-			if ($total_users_online > $modSettings['mostOnlineToday'])
238
-				trackStats(array('most_on' => $total_users_online));
241
+			if ($total_users_online > $modSettings['mostOnlineToday']) {
242
+							trackStats(array('most_on' => $total_users_online));
243
+			}
239 244
 
240 245
 			$total_users_online = max($total_users_online, $modSettings['mostOnlineToday']);
241 246
 		}
@@ -252,8 +257,9 @@  discard block
 block discarded – undo
252 257
 		$settingsToUpdate['mostOnlineToday'] = $total_users_online;
253 258
 	}
254 259
 
255
-	if (!empty($settingsToUpdate))
256
-		updateSettings($settingsToUpdate);
257
-}
260
+	if (!empty($settingsToUpdate)) {
261
+			updateSettings($settingsToUpdate);
262
+	}
263
+	}
258 264
 
259 265
 ?>
260 266
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -255,8 +255,8 @@  discard block
 block discarded – undo
255 255
 		
256 256
 		case 'datetime':
257 257
 			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
258
-				return 'str_to_date('.
259
-					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
258
+				return 'str_to_date(' .
259
+					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) .
260 260
 					',\'%Y-%m-%d %h:%i:%s\')';
261 261
 			else
262 262
 				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
 		$connection
824 824
 	);
825 825
 	
826
-	if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
826
+	if (!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
827 827
 	{
828 828
 		if ($returnmode == 1)
829 829
 			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
 			$return_var = array();
833 833
 			$count = count($insertRows);
834 834
 			$start = smf_db_insert_id($table, $keys[0]);
835
-			for ($i = 0; $i < $count; $i++ )
835
+			for ($i = 0; $i < $count; $i++)
836 836
 				$return_var[] = $start + $i;
837 837
 		}
838 838
 		return $return_var;
Please login to merge, or discard this patch.
Braces   +257 added lines, -189 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -60,9 +61,11 @@  discard block
 block discarded – undo
60 61
 			'db_mb4'                    => false,
61 62
 			'db_ping'                   => 'mysqli_ping',
62 63
 		);
64
+	}
63 65
 
64
-	if (!empty($db_options['persist']))
65
-		$db_server = 'p:' . $db_server;
66
+	if (!empty($db_options['persist'])) {
67
+			$db_server = 'p:' . $db_server;
68
+	}
66 69
 
67 70
 	$connection = mysqli_init();
68 71
 	
@@ -71,31 +74,35 @@  discard block
 block discarded – undo
71 74
 	$success = false;
72 75
 	
73 76
 	if ($connection) {
74
-		if (!empty($db_options['port']))
75
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
76
-		else
77
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
77
+		if (!empty($db_options['port'])) {
78
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
79
+		} else {
80
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
81
+		}
78 82
 	}
79 83
 
80 84
 	// Something's wrong, show an error if its fatal (which we assume it is)
81 85
 	if ($success === false)
82 86
 	{
83
-		if (!empty($db_options['non_fatal']))
84
-			return null;
85
-		else
86
-			display_db_error();
87
+		if (!empty($db_options['non_fatal'])) {
88
+					return null;
89
+		} else {
90
+					display_db_error();
91
+		}
87 92
 	}
88 93
 
89 94
 	// Select the database, unless told not to
90
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
91
-		display_db_error();
95
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
96
+			display_db_error();
97
+	}
92 98
 
93 99
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
94
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
95
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
100
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
101
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
96 102
 		array(),
97 103
 		false
98 104
 	);
105
+	}
99 106
 
100 107
 	return $connection;
101 108
 }
@@ -166,37 +173,46 @@  discard block
 block discarded – undo
166 173
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
167 174
 
168 175
 	list ($values, $connection) = $db_callback;
169
-	if (!is_object($connection))
170
-		display_db_error();
176
+	if (!is_object($connection)) {
177
+			display_db_error();
178
+	}
171 179
 
172
-	if ($matches[1] === 'db_prefix')
173
-		return $db_prefix;
180
+	if ($matches[1] === 'db_prefix') {
181
+			return $db_prefix;
182
+	}
174 183
 
175
-	if ($matches[1] === 'query_see_board')
176
-		return $user_info['query_see_board'];
184
+	if ($matches[1] === 'query_see_board') {
185
+			return $user_info['query_see_board'];
186
+	}
177 187
 
178
-	if ($matches[1] === 'query_wanna_see_board')
179
-		return $user_info['query_wanna_see_board'];
188
+	if ($matches[1] === 'query_wanna_see_board') {
189
+			return $user_info['query_wanna_see_board'];
190
+	}
180 191
 
181
-	if ($matches[1] === 'empty')
182
-		return '\'\'';
192
+	if ($matches[1] === 'empty') {
193
+			return '\'\'';
194
+	}
183 195
 
184
-	if (!isset($matches[2]))
185
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
196
+	if (!isset($matches[2])) {
197
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
198
+	}
186 199
 
187
-	if ($matches[1] === 'literal')
188
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
200
+	if ($matches[1] === 'literal') {
201
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
202
+	}
189 203
 
190
-	if (!isset($values[$matches[2]]))
191
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
204
+	if (!isset($values[$matches[2]])) {
205
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
206
+	}
192 207
 
193 208
 	$replacement = $values[$matches[2]];
194 209
 
195 210
 	switch ($matches[1])
196 211
 	{
197 212
 		case 'int':
198
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
199
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
214
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
215
+			}
200 216
 			return (string) (int) $replacement;
201 217
 		break;
202 218
 
@@ -208,65 +224,73 @@  discard block
 block discarded – undo
208 224
 		case 'array_int':
209 225
 			if (is_array($replacement))
210 226
 			{
211
-				if (empty($replacement))
212
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227
+				if (empty($replacement)) {
228
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
229
+				}
213 230
 
214 231
 				foreach ($replacement as $key => $value)
215 232
 				{
216
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
217
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
234
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
235
+					}
218 236
 
219 237
 					$replacement[$key] = (string) (int) $value;
220 238
 				}
221 239
 
222 240
 				return implode(', ', $replacement);
241
+			} else {
242
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
223 243
 			}
224
-			else
225
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
226 244
 
227 245
 		break;
228 246
 
229 247
 		case 'array_string':
230 248
 			if (is_array($replacement))
231 249
 			{
232
-				if (empty($replacement))
233
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
250
+				if (empty($replacement)) {
251
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
252
+				}
234 253
 
235
-				foreach ($replacement as $key => $value)
236
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
254
+				foreach ($replacement as $key => $value) {
255
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
256
+				}
237 257
 
238 258
 				return implode(', ', $replacement);
259
+			} else {
260
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
239 261
 			}
240
-			else
241
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
242 262
 		break;
243 263
 
244 264
 		case 'date':
245
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
246
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
247
-			else
248
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
266
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
267
+			} else {
268
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
269
+			}
249 270
 		break;
250 271
 
251 272
 		case 'time':
252
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
253
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
254
-			else
255
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
273
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
274
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
275
+			} else {
276
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
277
+			}
256 278
 		break;
257 279
 		
258 280
 		case 'datetime':
259
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
260
-				return 'str_to_date('.
281
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
282
+							return 'str_to_date('.
261 283
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
262 284
 					',\'%Y-%m-%d %h:%i:%s\')';
263
-			else
264
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
285
+			} else {
286
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
287
+			}
265 288
 		break;
266 289
 
267 290
 		case 'float':
268
-			if (!is_numeric($replacement))
269
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
291
+			if (!is_numeric($replacement)) {
292
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
293
+			}
270 294
 			return (string) (float) $replacement;
271 295
 		break;
272 296
 
@@ -280,32 +304,37 @@  discard block
 block discarded – undo
280 304
 		break;
281 305
 
282 306
 		case 'inet':
283
-			if ($replacement == 'null' || $replacement == '')
284
-				return 'null';
285
-			if (!isValidIP($replacement))
286
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
307
+			if ($replacement == 'null' || $replacement == '') {
308
+							return 'null';
309
+			}
310
+			if (!isValidIP($replacement)) {
311
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
312
+			}
287 313
 			//we don't use the native support of mysql > 5.6.2
288 314
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
289 315
 
290 316
 		case 'array_inet':
291 317
 			if (is_array($replacement))
292 318
 			{
293
-				if (empty($replacement))
294
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
319
+				if (empty($replacement)) {
320
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
321
+				}
295 322
 
296 323
 				foreach ($replacement as $key => $value)
297 324
 				{
298
-					if ($replacement == 'null' || $replacement == '')
299
-						$replacement[$key] = 'null';
300
-					if (!isValidIP($value))
301
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
325
+					if ($replacement == 'null' || $replacement == '') {
326
+											$replacement[$key] = 'null';
327
+					}
328
+					if (!isValidIP($value)) {
329
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
330
+					}
302 331
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
303 332
 				}
304 333
 
305 334
 				return implode(', ', $replacement);
335
+			} else {
336
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
306 337
 			}
307
-			else
308
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
309 338
 		break;
310 339
 
311 340
 		default:
@@ -381,22 +410,25 @@  discard block
 block discarded – undo
381 410
 		// Are we in SSI mode?  If so try that username and password first
382 411
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
383 412
 		{
384
-			if (empty($db_persist))
385
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
386
-			else
387
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
413
+			if (empty($db_persist)) {
414
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
415
+			} else {
416
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
417
+			}
388 418
 		}
389 419
 		// Fall back to the regular username and password if need be
390 420
 		if (!$db_connection)
391 421
 		{
392
-			if (empty($db_persist))
393
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
394
-			else
395
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
422
+			if (empty($db_persist)) {
423
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
424
+			} else {
425
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
426
+			}
396 427
 		}
397 428
 
398
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
399
-			$db_connection = false;
429
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
430
+					$db_connection = false;
431
+		}
400 432
 
401 433
 		$connection = $db_connection;
402 434
 	}
@@ -404,18 +436,20 @@  discard block
 block discarded – undo
404 436
 	// One more query....
405 437
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
406 438
 
407
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
408
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
439
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
440
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
441
+	}
409 442
 
410 443
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
411 444
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
412 445
 	{
413 446
 		// Add before LIMIT
414
-		if ($pos = strpos($db_string, 'LIMIT '))
415
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
416
-		else
417
-			// Append it.
447
+		if ($pos = strpos($db_string, 'LIMIT ')) {
448
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
449
+		} else {
450
+					// Append it.
418 451
 			$db_string .= "\n\t\t\tORDER BY null";
452
+		}
419 453
 	}
420 454
 
421 455
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -437,8 +471,9 @@  discard block
 block discarded – undo
437 471
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
438 472
 
439 473
 		// Initialize $db_cache if not already initialized.
440
-		if (!isset($db_cache))
441
-			$db_cache = array();
474
+		if (!isset($db_cache)) {
475
+					$db_cache = array();
476
+		}
442 477
 
443 478
 		if (!empty($_SESSION['debug_redirect']))
444 479
 		{
@@ -464,17 +499,18 @@  discard block
 block discarded – undo
464 499
 		while (true)
465 500
 		{
466 501
 			$pos = strpos($db_string, '\'', $pos + 1);
467
-			if ($pos === false)
468
-				break;
502
+			if ($pos === false) {
503
+							break;
504
+			}
469 505
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
470 506
 
471 507
 			while (true)
472 508
 			{
473 509
 				$pos1 = strpos($db_string, '\'', $pos + 1);
474 510
 				$pos2 = strpos($db_string, '\\', $pos + 1);
475
-				if ($pos1 === false)
476
-					break;
477
-				elseif ($pos2 === false || $pos2 > $pos1)
511
+				if ($pos1 === false) {
512
+									break;
513
+				} elseif ($pos2 === false || $pos2 > $pos1)
478 514
 				{
479 515
 					$pos = $pos1;
480 516
 					break;
@@ -490,29 +526,35 @@  discard block
 block discarded – undo
490 526
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
491 527
 
492 528
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
493
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
494
-			$fail = true;
529
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
530
+					$fail = true;
531
+		}
495 532
 		// Trying to change passwords, slow us down, or something?
496
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
497
-			$fail = true;
498
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
499
-			$fail = true;
533
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
534
+					$fail = true;
535
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
536
+					$fail = true;
537
+		}
500 538
 
501
-		if (!empty($fail) && function_exists('log_error'))
502
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
539
+		if (!empty($fail) && function_exists('log_error')) {
540
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
541
+		}
503 542
 	}
504 543
 
505
-	if (empty($db_unbuffered))
506
-		$ret = @mysqli_query($connection, $db_string);
507
-	else
508
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
544
+	if (empty($db_unbuffered)) {
545
+			$ret = @mysqli_query($connection, $db_string);
546
+	} else {
547
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
548
+	}
509 549
 
510
-	if ($ret === false && empty($db_values['db_error_skip']))
511
-		$ret = smf_db_error($db_string, $connection);
550
+	if ($ret === false && empty($db_values['db_error_skip'])) {
551
+			$ret = smf_db_error($db_string, $connection);
552
+	}
512 553
 
513 554
 	// Debugging.
514
-	if (isset($db_show_debug) && $db_show_debug === true)
515
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
555
+	if (isset($db_show_debug) && $db_show_debug === true) {
556
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
557
+	}
516 558
 
517 559
 	return $ret;
518 560
 }
@@ -559,12 +601,13 @@  discard block
 block discarded – undo
559 601
 	// Decide which connection to use
560 602
 	$connection = $connection === null ? $db_connection : $connection;
561 603
 
562
-	if ($type == 'begin')
563
-		return @mysqli_query($connection, 'BEGIN');
564
-	elseif ($type == 'rollback')
565
-		return @mysqli_query($connection, 'ROLLBACK');
566
-	elseif ($type == 'commit')
567
-		return @mysqli_query($connection, 'COMMIT');
604
+	if ($type == 'begin') {
605
+			return @mysqli_query($connection, 'BEGIN');
606
+	} elseif ($type == 'rollback') {
607
+			return @mysqli_query($connection, 'ROLLBACK');
608
+	} elseif ($type == 'commit') {
609
+			return @mysqli_query($connection, 'COMMIT');
610
+	}
568 611
 
569 612
 	return false;
570 613
 }
@@ -604,8 +647,9 @@  discard block
 block discarded – undo
604 647
 	//    2013: Lost connection to server during query.
605 648
 
606 649
 	// Log the error.
607
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
608
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
650
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
651
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
652
+	}
609 653
 
610 654
 	// Database error auto fixing ;).
611 655
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -614,8 +658,9 @@  discard block
 block discarded – undo
614 658
 		$old_cache = @$modSettings['cache_enable'];
615 659
 		$modSettings['cache_enable'] = '1';
616 660
 
617
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
618
-			$db_last_error = max(@$db_last_error, $temp);
661
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
662
+					$db_last_error = max(@$db_last_error, $temp);
663
+		}
619 664
 
620 665
 		if (@$db_last_error < time() - 3600 * 24 * 3)
621 666
 		{
@@ -631,8 +676,9 @@  discard block
 block discarded – undo
631 676
 					foreach ($tables as $table)
632 677
 					{
633 678
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
634
-						if (trim($table) != '')
635
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
679
+						if (trim($table) != '') {
680
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
681
+						}
636 682
 					}
637 683
 				}
638 684
 
@@ -641,8 +687,9 @@  discard block
 block discarded – undo
641 687
 			// Table crashed.  Let's try to fix it.
642 688
 			elseif ($query_errno == 1016)
643 689
 			{
644
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
645
-					$fix_tables = array('`' . $match[1] . '`');
690
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
691
+									$fix_tables = array('`' . $match[1] . '`');
692
+				}
646 693
 			}
647 694
 			// Indexes crashed.  Should be easy to fix!
648 695
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -661,13 +708,15 @@  discard block
 block discarded – undo
661 708
 
662 709
 			// Make a note of the REPAIR...
663 710
 			cache_put_data('db_last_error', time(), 600);
664
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
665
-				updateSettingsFile(array('db_last_error' => time()));
711
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
712
+							updateSettingsFile(array('db_last_error' => time()));
713
+			}
666 714
 
667 715
 			// Attempt to find and repair the broken table.
668
-			foreach ($fix_tables as $table)
669
-				$smcFunc['db_query']('', "
716
+			foreach ($fix_tables as $table) {
717
+							$smcFunc['db_query']('', "
670 718
 					REPAIR TABLE $table", false, false);
719
+			}
671 720
 
672 721
 			// And send off an email!
673 722
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -676,11 +725,12 @@  discard block
 block discarded – undo
676 725
 
677 726
 			// Try the query again...?
678 727
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
679
-			if ($ret !== false)
680
-				return $ret;
728
+			if ($ret !== false) {
729
+							return $ret;
730
+			}
731
+		} else {
732
+					$modSettings['cache_enable'] = $old_cache;
681 733
 		}
682
-		else
683
-			$modSettings['cache_enable'] = $old_cache;
684 734
 
685 735
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
686 736
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -690,22 +740,25 @@  discard block
 block discarded – undo
690 740
 				// Are we in SSI mode?  If so try that username and password first
691 741
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
692 742
 				{
693
-					if (empty($db_persist))
694
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
695
-					else
696
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
743
+					if (empty($db_persist)) {
744
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
745
+					} else {
746
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
747
+					}
697 748
 				}
698 749
 				// Fall back to the regular username and password if need be
699 750
 				if (!$db_connection)
700 751
 				{
701
-					if (empty($db_persist))
702
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
703
-					else
704
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
752
+					if (empty($db_persist)) {
753
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
754
+					} else {
755
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
756
+					}
705 757
 				}
706 758
 
707
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
708
-					$db_connection = false;
759
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
760
+									$db_connection = false;
761
+				}
709 762
 			}
710 763
 
711 764
 			if ($db_connection)
@@ -716,24 +769,27 @@  discard block
 block discarded – undo
716 769
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
717 770
 
718 771
 					$new_errno = mysqli_errno($db_connection);
719
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
720
-						break;
772
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
773
+											break;
774
+					}
721 775
 				}
722 776
 
723 777
 				// If it failed again, shucks to be you... we're not trying it over and over.
724
-				if ($ret !== false)
725
-					return $ret;
778
+				if ($ret !== false) {
779
+									return $ret;
780
+				}
726 781
 			}
727 782
 		}
728 783
 		// Are they out of space, perhaps?
729 784
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
730 785
 		{
731
-			if (!isset($txt))
732
-				$query_error .= ' - check database storage space.';
733
-			else
786
+			if (!isset($txt)) {
787
+							$query_error .= ' - check database storage space.';
788
+			} else
734 789
 			{
735
-				if (!isset($txt['mysql_error_space']))
736
-					loadLanguage('Errors');
790
+				if (!isset($txt['mysql_error_space'])) {
791
+									loadLanguage('Errors');
792
+				}
737 793
 
738 794
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
739 795
 			}
@@ -741,15 +797,17 @@  discard block
 block discarded – undo
741 797
 	}
742 798
 
743 799
 	// Nothing's defined yet... just die with it.
744
-	if (empty($context) || empty($txt))
745
-		die($query_error);
800
+	if (empty($context) || empty($txt)) {
801
+			die($query_error);
802
+	}
746 803
 
747 804
 	// Show an error message, if possible.
748 805
 	$context['error_title'] = $txt['database_error'];
749
-	if (allowedTo('admin_forum'))
750
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
751
-	else
752
-		$context['error_message'] = $txt['try_again'];
806
+	if (allowedTo('admin_forum')) {
807
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
808
+	} else {
809
+			$context['error_message'] = $txt['try_again'];
810
+	}
753 811
 
754 812
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
755 813
 	{
@@ -779,25 +837,28 @@  discard block
 block discarded – undo
779 837
 	$connection = $connection === null ? $db_connection : $connection;
780 838
 
781 839
 	// With nothing to insert, simply return.
782
-	if (empty($data))
783
-		return;
840
+	if (empty($data)) {
841
+			return;
842
+	}
784 843
 
785 844
 	// Replace the prefix holder with the actual prefix.
786 845
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
787 846
 
788 847
 	// Inserting data as a single row can be done as a single array.
789
-	if (!is_array($data[array_rand($data)]))
790
-		$data = array($data);
848
+	if (!is_array($data[array_rand($data)])) {
849
+			$data = array($data);
850
+	}
791 851
 
792 852
 	// Create the mold for a single row insert.
793 853
 	$insertData = '(';
794 854
 	foreach ($columns as $columnName => $type)
795 855
 	{
796 856
 		// Are we restricting the length?
797
-		if (strpos($type, 'string-') !== false)
798
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
799
-		else
800
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
857
+		if (strpos($type, 'string-') !== false) {
858
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
859
+		} else {
860
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
861
+		}
801 862
 	}
802 863
 	$insertData = substr($insertData, 0, -2) . ')';
803 864
 
@@ -806,8 +867,9 @@  discard block
 block discarded – undo
806 867
 
807 868
 	// Here's where the variables are injected to the query.
808 869
 	$insertRows = array();
809
-	foreach ($data as $dataRow)
810
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
870
+	foreach ($data as $dataRow) {
871
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
872
+	}
811 873
 
812 874
 	// Determine the method of insertion.
813 875
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -827,15 +889,16 @@  discard block
 block discarded – undo
827 889
 	
828 890
 	if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
829 891
 	{
830
-		if ($returnmode == 1)
831
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
832
-		else if ($returnmode == 2)
892
+		if ($returnmode == 1) {
893
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
894
+		} else if ($returnmode == 2)
833 895
 		{
834 896
 			$return_var = array();
835 897
 			$count = count($insertRows);
836 898
 			$start = smf_db_insert_id($table, $keys[0]);
837
-			for ($i = 0; $i < $count; $i++ )
838
-				$return_var[] = $start + $i;
899
+			for ($i = 0; $i < $count; $i++ ) {
900
+							$return_var[] = $start + $i;
901
+			}
839 902
 		}
840 903
 		return $return_var;
841 904
 	}
@@ -853,8 +916,9 @@  discard block
 block discarded – undo
853 916
  */
854 917
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
855 918
 {
856
-	if (empty($log_message))
857
-		$log_message = $error_message;
919
+	if (empty($log_message)) {
920
+			$log_message = $error_message;
921
+	}
858 922
 
859 923
 	foreach (debug_backtrace() as $step)
860 924
 	{
@@ -873,12 +937,14 @@  discard block
 block discarded – undo
873 937
 	}
874 938
 
875 939
 	// A special case - we want the file and line numbers for debugging.
876
-	if ($error_type == 'return')
877
-		return array($file, $line);
940
+	if ($error_type == 'return') {
941
+			return array($file, $line);
942
+	}
878 943
 
879 944
 	// Is always a critical error.
880
-	if (function_exists('log_error'))
881
-		log_error($log_message, 'critical', $file, $line);
945
+	if (function_exists('log_error')) {
946
+			log_error($log_message, 'critical', $file, $line);
947
+	}
882 948
 
883 949
 	if (function_exists('fatal_error'))
884 950
 	{
@@ -886,12 +952,12 @@  discard block
 block discarded – undo
886 952
 
887 953
 		// Cannot continue...
888 954
 		exit;
955
+	} elseif ($error_type) {
956
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
957
+	} else {
958
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
959
+	}
889 960
 	}
890
-	elseif ($error_type)
891
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
892
-	else
893
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
894
-}
895 961
 
896 962
 /**
897 963
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -908,10 +974,11 @@  discard block
 block discarded – undo
908 974
 		'\\' => '\\\\',
909 975
 	);
910 976
 
911
-	if ($translate_human_wildcards)
912
-		$replacements += array(
977
+	if ($translate_human_wildcards) {
978
+			$replacements += array(
913 979
 			'*' => '%',
914 980
 		);
981
+	}
915 982
 
916 983
 	return strtr($string, $replacements);
917 984
 }
@@ -925,8 +992,9 @@  discard block
 block discarded – undo
925 992
  */
926 993
 function smf_is_resource($result)
927 994
 {
928
-	if ($result instanceof mysqli_result)
929
-		return true;
995
+	if ($result instanceof mysqli_result) {
996
+			return true;
997
+	}
930 998
 
931 999
 	return false;
932 1000
 }
Please login to merge, or discard this patch.
Sources/tasks/CreatePost-Notify.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 class CreatePost_Notify_Background extends SMF_BackgroundTask
19 19
 {
20 20
 	/**
21
-     * This handles notifications when a new post is created - new topic, reply, quotes and mentions.
21
+	 * This handles notifications when a new post is created - new topic, reply, quotes and mentions.
22 22
 	 * @return bool Always returns true
23 23
 	 */
24 24
 	public function execute()
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 
107 107
 			// Don't send a notification if the watching member ignored the member who made the action.
108 108
 			if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list'])))
109
-			    continue;
109
+				continue;
110 110
 			if (!in_array($type, array('reply', 'topic')) && $notify_types == 2 && $member != $data['id_member_started'])
111 111
 				continue;
112 112
 			elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id'])
Please login to merge, or discard this patch.
Braces   +62 added lines, -46 removed lines patch added patch discarded remove patch
@@ -73,8 +73,9 @@  discard block
 block discarded – undo
73 73
 		while ($row = $smcFunc['db_fetch_assoc']($request))
74 74
 		{
75 75
 			$groups = array_merge(array($row['id_group'], $row['id_post_group']), (empty($row['additional_groups']) ? array() : explode(',', $row['additional_groups'])));
76
-			if (!in_array(1, $groups) && count(array_intersect($groups, explode(',', $row['member_groups']))) == 0)
77
-				continue;
76
+			if (!in_array(1, $groups) && count(array_intersect($groups, explode(',', $row['member_groups']))) == 0) {
77
+							continue;
78
+			}
78 79
 
79 80
 			$members[] = $row['id_member'];
80 81
 			$watched[$row['id_member']] = $row;
@@ -82,8 +83,9 @@  discard block
 block discarded – undo
82 83
 
83 84
 		$smcFunc['db_free_result']($request);
84 85
 
85
-		if (empty($members))
86
-			return true;
86
+		if (empty($members)) {
87
+					return true;
88
+		}
87 89
 
88 90
 		$members = array_unique($members);
89 91
 		$prefs = getNotifyPrefs($members, '', true);
@@ -105,20 +107,23 @@  discard block
 block discarded – undo
105 107
 			$notify_types = !empty($prefs[$member]['msg_notify_type']) ? $prefs[$member]['msg_notify_type'] : 1;
106 108
 
107 109
 			// Don't send a notification if the watching member ignored the member who made the action.
108
-			if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list'])))
109
-			    continue;
110
-			if (!in_array($type, array('reply', 'topic')) && $notify_types == 2 && $member != $data['id_member_started'])
111
-				continue;
112
-			elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id'])
113
-				continue;
114
-			elseif (!in_array($type, array('reply', 'topic')) && $notify_types == 3)
115
-				continue;
116
-			elseif ($notify_types == 4)
117
-				continue;
110
+			if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list']))) {
111
+						    continue;
112
+			}
113
+			if (!in_array($type, array('reply', 'topic')) && $notify_types == 2 && $member != $data['id_member_started']) {
114
+							continue;
115
+			} elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id']) {
116
+							continue;
117
+			} elseif (!in_array($type, array('reply', 'topic')) && $notify_types == 3) {
118
+							continue;
119
+			} elseif ($notify_types == 4) {
120
+							continue;
121
+			}
118 122
 
119 123
 			if ($frequency > 2 || (!empty($frequency) && $data['sent']) || in_array($member, $done_members)
120
-				|| (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only'])))
121
-				continue;
124
+				|| (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only']))) {
125
+							continue;
126
+			}
122 127
 
123 128
 			// Watched topic?
124 129
 			if (!empty($data['id_topic']) && $type != 'topic' && !empty($prefs[$member]))
@@ -128,10 +133,12 @@  discard block
 block discarded – undo
128 133
 
129 134
 				if ($type == 'reply')
130 135
 				{
131
-					if (!empty($prefs[$member]['msg_receive_body']))
132
-						$message_type .= '_body';
133
-					if (!empty($frequency))
134
-						$message_type .= '_once';
136
+					if (!empty($prefs[$member]['msg_receive_body'])) {
137
+											$message_type .= '_body';
138
+					}
139
+					if (!empty($frequency)) {
140
+											$message_type .= '_once';
141
+					}
135 142
 				}
136 143
 
137 144
 				$content_type = 'topic';
@@ -144,12 +151,14 @@  discard block
 block discarded – undo
144 151
 				$content_type = 'board';
145 152
 
146 153
 				$message_type = !empty($frequency) ? 'notify_boards_once' : 'notify_boards';
147
-				if (!empty($prefs[$member]['msg_receive_body']))
148
-					$message_type .= '_body';
154
+				if (!empty($prefs[$member]['msg_receive_body'])) {
155
+									$message_type .= '_body';
156
+				}
149 157
 			}
150 158
 			// If neither of the above, this might be a redundent row due to the OR clause in our SQL query, skip
151
-			else
152
-				continue;
159
+			else {
160
+							continue;
161
+			}
153 162
 
154 163
 			if ($pref & 0x02)
155 164
 			{
@@ -212,14 +221,15 @@  discard block
 block discarded – undo
212 221
 		);
213 222
 
214 223
 		// Insert the alerts if any
215
-		if (!empty($alert_rows))
216
-			$smcFunc['db_insert']('',
224
+		if (!empty($alert_rows)) {
225
+					$smcFunc['db_insert']('',
217 226
 				'{db_prefix}user_alerts',
218 227
 				array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
219 228
 					'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
220 229
 				$alert_rows,
221 230
 				array()
222 231
 			);
232
+		}
223 233
 
224 234
 		return true;
225 235
 	}
@@ -230,8 +240,9 @@  discard block
 block discarded – undo
230 240
 
231 241
 		foreach ($quotedMembers as $id => $member)
232 242
 		{
233
-			if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote']))
234
-				continue;
243
+			if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote'])) {
244
+							continue;
245
+			}
235 246
 
236 247
 			$done_members[] = $id;
237 248
 
@@ -283,32 +294,35 @@  discard block
 block discarded – undo
283 294
 		{
284 295
 			if (preg_match('/\[quote(.*)?\]/i', $block, $matches))
285 296
 			{
286
-				if ($quote_level == 0)
287
-					$message .= '[quote' . $matches[1] . ']';
297
+				if ($quote_level == 0) {
298
+									$message .= '[quote' . $matches[1] . ']';
299
+				}
288 300
 				$quote_level++;
289
-			}
290
-			elseif (preg_match('/\[\/quote\]/i', $block))
301
+			} elseif (preg_match('/\[\/quote\]/i', $block))
291 302
 			{
292
-				if ($quote_level <= 1)
293
-					$message .= '[/quote]';
303
+				if ($quote_level <= 1) {
304
+									$message .= '[/quote]';
305
+				}
294 306
 				if ($quote_level >= 1)
295 307
 				{
296 308
 					$quote_level--;
297 309
 					$message .= "\n";
298 310
 				}
311
+			} elseif ($quote_level <= 1) {
312
+							$message .= $block;
299 313
 			}
300
-			elseif ($quote_level <= 1)
301
-				$message .= $block;
302 314
 		}
303 315
 
304 316
 		preg_match_all('/\[quote.*?link=msg=([0-9]+).*?\]/i', $message, $matches);
305 317
 
306 318
 		$id_msgs = $matches[1];
307
-		foreach ($id_msgs as $k => $id_msg)
308
-			$id_msgs[$k] = (int) $id_msg;
319
+		foreach ($id_msgs as $k => $id_msg) {
320
+					$id_msgs[$k] = (int) $id_msg;
321
+		}
309 322
 
310
-		if (empty($id_msgs))
311
-			return array();
323
+		if (empty($id_msgs)) {
324
+					return array();
325
+		}
312 326
 
313 327
 		// Get the messages
314 328
 		$request = $smcFunc['db_query']('', '
@@ -326,8 +340,9 @@  discard block
 block discarded – undo
326 340
 		$members = array();
327 341
 		while ($row = $smcFunc['db_fetch_assoc']($request))
328 342
 		{
329
-			if ($posterOptions['id'] == $row['id_member'])
330
-				continue;
343
+			if ($posterOptions['id'] == $row['id_member']) {
344
+							continue;
345
+			}
331 346
 
332 347
 			$members[$row['id_member']] = $row;
333 348
 		}
@@ -341,10 +356,11 @@  discard block
 block discarded – undo
341 356
 
342 357
 		foreach ($members as $id => $member)
343 358
 		{
344
-			if (!empty($prefs[$id]['msg_mention']))
345
-				$done_members[] = $id;
346
-			else
347
-				continue;
359
+			if (!empty($prefs[$id]['msg_mention'])) {
360
+							$done_members[] = $id;
361
+			} else {
362
+							continue;
363
+			}
348 364
 
349 365
 			// Alerts' emails are always instant
350 366
 			if ($prefs[$id]['msg_mention'] & 0x02)
Please login to merge, or discard this patch.
Sources/Subs-BoardIndex.php 1 patch
Braces   +60 added lines, -47 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Fetches a list of boards and (optional) categories including
@@ -37,11 +38,12 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Boards.php');
38 39
 
39 40
 	// For performance, track the latest post while going through the boards.
40
-	if (!empty($boardIndexOptions['set_latest_post']))
41
-		$latest_post = array(
41
+	if (!empty($boardIndexOptions['set_latest_post'])) {
42
+			$latest_post = array(
42 43
 			'timestamp' => 0,
43 44
 			'ref' => 0,
44 45
 		);
46
+	}
45 47
 
46 48
 	// Find all boards and categories, as well as related information.  This will be sorted by the natural order of boards and categories, which we control.
47 49
 	$result_boards = $smcFunc['db_query']('', '
@@ -74,10 +76,11 @@  discard block
 block discarded – undo
74 76
 	);
75 77
 
76 78
 	// Start with an empty array.
77
-	if ($boardIndexOptions['include_categories'])
78
-		$categories = array();
79
-	else
80
-		$this_category = array();
79
+	if ($boardIndexOptions['include_categories']) {
80
+			$categories = array();
81
+	} else {
82
+			$this_category = array();
83
+	}
81 84
 	$boards = array();
82 85
 
83 86
 	// Run through the categories and boards (or only boards)....
@@ -88,8 +91,9 @@  discard block
 block discarded – undo
88 91
 		$row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0';
89 92
 
90 93
 		// Add parent boards to the $boards list later used to fetch moderators
91
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'])
92
-			$boards[] = $row_board['id_board'];
94
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) {
95
+					$boards[] = $row_board['id_board'];
96
+		}
93 97
 
94 98
 		if ($boardIndexOptions['include_categories'])
95 99
 		{
@@ -111,8 +115,9 @@  discard block
 block discarded – undo
111 115
 			}
112 116
 
113 117
 			// If this board has new posts in it (and isn't the recycle bin!) then the category is new.
114
-			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board'])
115
-				$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != '';
118
+			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) {
119
+							$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != '';
120
+			}
116 121
 
117 122
 			// Avoid showing category unread link where it only has redirection boards.
118 123
 			$categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect'];
@@ -160,14 +165,12 @@  discard block
 block discarded – undo
160 165
 				{
161 166
 					$this_category[$row_board['id_board']]['board_class'] = 'redirect';
162 167
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board'];
163
-				}
164
-				elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
168
+				} elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
165 169
 				{
166 170
 					// If we're showing to guests, we want to give them the idea that something interesting is going on!
167 171
 					$this_category[$row_board['id_board']]['board_class'] = 'on';
168 172
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts'];
169
-				}
170
-				else
173
+				} else
171 174
 				{
172 175
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts'];
173 176
 				}
@@ -218,14 +221,16 @@  discard block
 block discarded – undo
218 221
 		// Child of a child... just add it on...
219 222
 		elseif (!empty($boardIndexOptions['countChildPosts']))
220 223
 		{
221
-			if (!isset($parent_map))
222
-				$parent_map = array();
224
+			if (!isset($parent_map)) {
225
+							$parent_map = array();
226
+			}
223 227
 
224
-			if (!isset($parent_map[$row_board['id_parent']]))
225
-				foreach ($this_category as $id => $board)
228
+			if (!isset($parent_map[$row_board['id_parent']])) {
229
+							foreach ($this_category as $id => $board)
226 230
 				{
227 231
 					if (!isset($board['children'][$row_board['id_parent']]))
228 232
 						continue;
233
+			}
229 234
 
230 235
 					$parent_map[$row_board['id_parent']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]);
231 236
 					$parent_map[$row_board['id_board']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]);
@@ -246,8 +251,9 @@  discard block
 block discarded – undo
246 251
 			continue;
247 252
 		}
248 253
 		// Found a child of a child - skip.
249
-		else
250
-			continue;
254
+		else {
255
+					continue;
256
+		}
251 257
 
252 258
 		// Prepare the subject, and make sure it's not too long.
253 259
 		censorText($row_board['subject']);
@@ -268,12 +274,13 @@  discard block
 block discarded – undo
268 274
 			'topic' => $row_board['id_topic']
269 275
 		);
270 276
 
271
-		if (!empty($settings['avatars_on_boardIndex']))
272
-			$this_last_post['member']['avatar'] = set_avatar_data(array(
277
+		if (!empty($settings['avatars_on_boardIndex'])) {
278
+					$this_last_post['member']['avatar'] = set_avatar_data(array(
273 279
 				'avatar' => $row_board['avatar'],
274 280
 				'email' => $row_board['email_address'],
275 281
 				'filename' => !empty($row['member_filename']) ? $row_board['member_filename'] : '',
276 282
 			));
283
+		}
277 284
 
278 285
 		// Provide the href and link.
279 286
 		if ($row_board['subject'] != '')
@@ -285,8 +292,7 @@  discard block
 block discarded – undo
285 292
 			link, href, subject, start (where they should go for the first unread post.),
286 293
 			and member. (which has id, name, link, href, username in it.) */
287 294
 			$this_last_post['last_post_message'] = sprintf($txt['last_post_message'], $this_last_post['member']['link'], $this_last_post['link'], $this_last_post['time']);
288
-		}
289
-		else
295
+		} else
290 296
 		{
291 297
 			$this_last_post['href'] = '';
292 298
 			$this_last_post['link'] = $txt['not_applicable'];
@@ -294,8 +300,9 @@  discard block
 block discarded – undo
294 300
 		}
295 301
 
296 302
 		// Set the last post in the parent board.
297
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time'])))
298
-			$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
303
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time']))) {
304
+					$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
305
+		}
299 306
 		// Just in the child...?
300 307
 		if ($isChild)
301 308
 		{
@@ -305,15 +312,17 @@  discard block
 block discarded – undo
305 312
 			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['new'] &= $row_board['poster_name'] != '';
306 313
 		}
307 314
 		// No last post for this board?  It's not new then, is it..?
308
-		elseif ($row_board['poster_name'] == '')
309
-			$this_category[$row_board['id_board']]['new'] = false;
315
+		elseif ($row_board['poster_name'] == '') {
316
+					$this_category[$row_board['id_board']]['new'] = false;
317
+		}
310 318
 
311 319
 		// Determine a global most recent topic.
312
-		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard)
313
-			$latest_post = array(
320
+		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) {
321
+					$latest_post = array(
314 322
 				'timestamp' => $row_board['poster_time'],
315 323
 				'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'],
316 324
 			);
325
+		}
317 326
 	}
318 327
 	$smcFunc['db_free_result']($result_boards);
319 328
 
@@ -330,8 +339,9 @@  discard block
 block discarded – undo
330 339
 				if (!empty($moderators[$board['id']]))
331 340
 				{
332 341
 					$categories[$k]['boards'][$j]['moderators'] = $moderators[$board['id']];
333
-					foreach ($moderators[$board['id']] as $moderator)
334
-						$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
342
+					foreach ($moderators[$board['id']] as $moderator) {
343
+											$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
344
+					}
335 345
 				}
336 346
 				if (!empty($groups[$board['id']]))
337 347
 				{
@@ -344,16 +354,16 @@  discard block
 block discarded – undo
344 354
 				}
345 355
 			}
346 356
 		}
347
-	}
348
-	else
357
+	} else
349 358
 	{
350 359
 		foreach ($this_category as $k => $board)
351 360
 		{
352 361
 			if (!empty($moderators[$board['id']]))
353 362
 			{
354 363
 				$this_category[$k]['moderators'] = $moderators[$board['id']];
355
-				foreach ($moderators[$board['id']] as $moderator)
356
-					$this_category[$k]['link_moderators'][] = $moderator['link'];
364
+				foreach ($moderators[$board['id']] as $moderator) {
365
+									$this_category[$k]['link_moderators'][] = $moderator['link'];
366
+				}
357 367
 			}
358 368
 			if (!empty($groups[$board['id']]))
359 369
 			{
@@ -367,20 +377,23 @@  discard block
 block discarded – undo
367 377
 		}
368 378
 	}
369 379
 
370
-	if ($boardIndexOptions['include_categories'])
371
-		sortCategories($categories);
372
-	else
373
-		sortBoards($this_category);
380
+	if ($boardIndexOptions['include_categories']) {
381
+			sortCategories($categories);
382
+	} else {
383
+			sortBoards($this_category);
384
+	}
374 385
 
375 386
 	// By now we should know the most recent post...if we wanna know it that is.
376
-	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref']))
377
-		$context['latest_post'] = $latest_post['ref'];
387
+	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) {
388
+			$context['latest_post'] = $latest_post['ref'];
389
+	}
378 390
 
379 391
 	// I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea.
380
-	if ($boardIndexOptions['include_categories'])
381
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
382
-	else
383
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
392
+	if ($boardIndexOptions['include_categories']) {
393
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
394
+	} else {
395
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
396
+	}
384 397
 
385 398
 	return $boardIndexOptions['include_categories'] ? $categories : $this_category;
386 399
 }
Please login to merge, or discard this patch.