Completed
Push — release-2.1 ( aa21c4...a79db9 )
by Colin
19:42 queued 09:42
created
Sources/Subs-Notify.php 1 patch
Braces   +17 added lines, -11 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * Fetches the list of preferences (or a single/subset of preferences) for
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 	// We want this as an array whether it is or not.
31 32
 	$members = is_array($members) ? $members : (array) $members;
32 33
 
33
-	if (!empty($prefs))
34
-		$prefs = is_array($prefs) ? $prefs : (array) $prefs;
34
+	if (!empty($prefs)) {
35
+			$prefs = is_array($prefs) ? $prefs : (array) $prefs;
36
+	}
35 37
 
36 38
 	$result = array();
37 39
 
@@ -56,9 +58,10 @@  discard block
 block discarded – undo
56 58
 	// We may want to keep the default values separate from a given user's. Or we might not.
57 59
 	if ($process_default && isset($result[0]))
58 60
 	{
59
-		foreach ($members as $member)
60
-			if (!isset($result[$member]))
61
+		foreach ($members as $member) {
62
+					if (!isset($result[$member]))
61 63
 				$result[$member] = $result[0];
64
+		}
62 65
 
63 66
 		unset ($result[0]);
64 67
 	}
@@ -76,12 +79,14 @@  discard block
 block discarded – undo
76 79
 {
77 80
 	global $smcFunc;
78 81
 
79
-	if (empty($prefs) || !is_int($memID))
80
-		return;
82
+	if (empty($prefs) || !is_int($memID)) {
83
+			return;
84
+	}
81 85
 
82 86
 	$update_rows = array();
83
-	foreach ($prefs as $k => $v)
84
-		$update_rows[] = array($memID, $k, $v);
87
+	foreach ($prefs as $k => $v) {
88
+			$update_rows[] = array($memID, $k, $v);
89
+	}
85 90
 
86 91
 	$smcFunc['db_insert']('replace',
87 92
 		'{db_prefix}user_alerts_prefs',
@@ -101,8 +106,9 @@  discard block
 block discarded – undo
101 106
 {
102 107
 	global $smcFunc;
103 108
 
104
-	if (empty($prefs) || empty($memID))
105
-		return;
109
+	if (empty($prefs) || empty($memID)) {
110
+			return;
111
+	}
106 112
 
107 113
 	$smcFunc['db_query']('', '
108 114
 		DELETE FROM {db_prefix}user_alerts_prefs
Please login to merge, or discard this patch.
Sources/CacheAPI-sqlite.php 1 patch
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * SQLite Cache API class
@@ -161,8 +162,7 @@  discard block
 block discarded – undo
161 162
 		if (is_null($dir) || !is_writable($dir))
162 163
 		{
163 164
 			$this->cachedir = $cachedir_sqlite;
164
-		}
165
-		else
165
+		} else
166 166
 		{
167 167
 			$this->cachedir = $dir;
168 168
 		}
Please login to merge, or discard this patch.
Sources/ManageLanguages.php 1 patch
Braces   +190 added lines, -142 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * This is the main function for the languages area.
@@ -153,11 +154,11 @@  discard block
 block discarded – undo
153 154
 	$language_list = new xmlArray(fetch_web_data($url), true);
154 155
 
155 156
 	// Check that the site responded and that the language exists.
156
-	if (!$language_list->exists('languages'))
157
-		$context['smf_error'] = 'no_response';
158
-	elseif (!$language_list->exists('languages/language'))
159
-		$context['smf_error'] = 'no_files';
160
-	else
157
+	if (!$language_list->exists('languages')) {
158
+			$context['smf_error'] = 'no_response';
159
+	} elseif (!$language_list->exists('languages/language')) {
160
+			$context['smf_error'] = 'no_files';
161
+	} else
161 162
 	{
162 163
 		$language_list = $language_list->path('languages[0]');
163 164
 		$lang_files = $language_list->set('language');
@@ -165,8 +166,9 @@  discard block
 block discarded – undo
165 166
 		foreach ($lang_files as $file)
166 167
 		{
167 168
 			// Were we searching?
168
-			if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false)
169
-				continue;
169
+			if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) {
170
+							continue;
171
+			}
170 172
 
171 173
 			$smf_languages[] = array(
172 174
 				'id' => $file->fetch('id'),
@@ -177,10 +179,11 @@  discard block
 block discarded – undo
177 179
 				'install_link' => '<a href="' . $scripturl . '?action=admin;area=languages;sa=downloadlang;did=' . $file->fetch('id') . ';' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['add_language_smf_install'] . '</a>',
178 180
 			);
179 181
 		}
180
-		if (empty($smf_languages))
181
-			$context['smf_error'] = 'no_files';
182
-		else
183
-			return $smf_languages;
182
+		if (empty($smf_languages)) {
183
+					$context['smf_error'] = 'no_files';
184
+		} else {
185
+					return $smf_languages;
186
+		}
184 187
 	}
185 188
 }
186 189
 
@@ -202,8 +205,9 @@  discard block
 block discarded – undo
202 205
 	require_once($sourcedir . '/Subs-Package.php');
203 206
 
204 207
 	// Clearly we need to know what to request.
205
-	if (!isset($_GET['did']))
206
-		fatal_lang_error('no_access', false);
208
+	if (!isset($_GET['did'])) {
209
+			fatal_lang_error('no_access', false);
210
+	}
207 211
 
208 212
 	// Some lovely context.
209 213
 	$context['download_id'] = $_GET['did'];
@@ -223,8 +227,9 @@  discard block
 block discarded – undo
223 227
 		foreach ($_POST['copy_file'] as $file)
224 228
 		{
225 229
 			// Check it's not very bad.
226
-			if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file)))
227
-				fatal_error($txt['languages_download_illegal_paths']);
230
+			if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) {
231
+							fatal_error($txt['languages_download_illegal_paths']);
232
+			}
228 233
 
229 234
 			$chmod_files[] = $boarddir . '/' . $file;
230 235
 			$install_files[] = $file;
@@ -235,8 +240,9 @@  discard block
 block discarded – undo
235 240
 		$files_left = $file_status['files']['notwritable'];
236 241
 
237 242
 		// Something not writable?
238
-		if (!empty($files_left))
239
-			$context['error_message'] = $txt['languages_download_not_chmod'];
243
+		if (!empty($files_left)) {
244
+					$context['error_message'] = $txt['languages_download_not_chmod'];
245
+		}
240 246
 		// Otherwise, go go go!
241 247
 		elseif (!empty($install_files))
242 248
 		{
@@ -251,11 +257,13 @@  discard block
 block discarded – undo
251 257
 	}
252 258
 
253 259
 	// Open up the old china.
254
-	if (!isset($archive_content))
255
-		$archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
260
+	if (!isset($archive_content)) {
261
+			$archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
262
+	}
256 263
 
257
-	if (empty($archive_content))
258
-		fatal_error($txt['add_language_error_no_response']);
264
+	if (empty($archive_content)) {
265
+			fatal_error($txt['add_language_error_no_response']);
266
+	}
259 267
 
260 268
 	// Now for each of the files, let's do some *stuff*
261 269
 	$context['files'] = array(
@@ -270,8 +278,9 @@  discard block
 block discarded – undo
270 278
 		$extension = substr($filename, strrpos($filename, '.') + 1);
271 279
 
272 280
 		// Don't do anything with files we don't understand.
273
-		if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt')))
274
-			continue;
281
+		if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) {
282
+					continue;
283
+		}
275 284
 
276 285
 		// Basic data.
277 286
 		$context_data = array(
@@ -290,8 +299,9 @@  discard block
 block discarded – undo
290 299
 		// Does the file exist, is it different and can we overwrite?
291 300
 		if (file_exists($boarddir . '/' . $file['filename']))
292 301
 		{
293
-			if (is_writable($boarddir . '/' . $file['filename']))
294
-				$context_data['writable'] = true;
302
+			if (is_writable($boarddir . '/' . $file['filename'])) {
303
+							$context_data['writable'] = true;
304
+			}
295 305
 
296 306
 			// Finally, do we actually think the content has changed?
297 307
 			if ($file['size'] == filesize($boarddir . '/' . $file['filename']) && $file['md5'] == md5_file($boarddir . '/' . $file['filename']))
@@ -304,16 +314,17 @@  discard block
 block discarded – undo
304 314
 			{
305 315
 				$context_data['exists'] = 'same';
306 316
 				$context_data['default_copy'] = false;
317
+			} else {
318
+							$context_data['exists'] = 'different';
307 319
 			}
308
-			else
309
-				$context_data['exists'] = 'different';
310 320
 		}
311 321
 		// No overwrite?
312 322
 		else
313 323
 		{
314 324
 			// Can we at least stick it in the directory...
315
-			if (is_writable($boarddir . '/' . $dirname))
316
-				$context_data['writable'] = true;
325
+			if (is_writable($boarddir . '/' . $dirname)) {
326
+							$context_data['writable'] = true;
327
+			}
317 328
 		}
318 329
 
319 330
 		// I love PHP files, that's why I'm a developer and not an artistic type spending my time drinking absinth and living a life of sin...
@@ -328,8 +339,9 @@  discard block
 block discarded – undo
328 339
 			list ($name, $language) = explode('.', $filename);
329 340
 
330 341
 			// Let's get the new version, I like versions, they tell me that I'm up to date.
331
-			if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1)
332
-				$context_data['version'] = $match[1];
342
+			if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) {
343
+							$context_data['version'] = $match[1];
344
+			}
333 345
 
334 346
 			// Now does the old file exist - if so what is it's version?
335 347
 			if (file_exists($boarddir . '/' . $file['filename']))
@@ -345,34 +357,35 @@  discard block
 block discarded – undo
345 357
 					$context_data['cur_version'] = $match[1];
346 358
 
347 359
 					// How does this compare?
348
-					if ($context_data['cur_version'] == $context_data['version'])
349
-						$context_data['version_compare'] = 'same';
350
-					elseif ($context_data['cur_version'] > $context_data['version'])
351
-						$context_data['version_compare'] = 'older';
360
+					if ($context_data['cur_version'] == $context_data['version']) {
361
+											$context_data['version_compare'] = 'same';
362
+					} elseif ($context_data['cur_version'] > $context_data['version']) {
363
+											$context_data['version_compare'] = 'older';
364
+					}
352 365
 
353 366
 					// Don't recommend copying if the version is the same.
354
-					if ($context_data['version_compare'] != 'newer')
355
-						$context_data['default_copy'] = false;
367
+					if ($context_data['version_compare'] != 'newer') {
368
+											$context_data['default_copy'] = false;
369
+					}
356 370
 				}
357 371
 			}
358 372
 
359 373
 			// Add the context data to the main set.
360 374
 			$context['files']['lang'][] = $context_data;
361
-		}
362
-		elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false)
375
+		} elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false)
363 376
 		{
364 377
 			// Registration agreement is a primary file
365 378
 			$context['files']['lang'][] = $context_data;
366
-		}
367
-		else
379
+		} else
368 380
 		{
369 381
 			// There shouldn't be anything else, but load this into "other" in case we decide to handle it in the future
370 382
 			$context['files']['other'][] = $context_data;
371 383
 		}
372 384
 
373 385
 		// Collect together all non-writable areas.
374
-		if (!$context_data['writable'])
375
-			$context['make_writable'][] = $context_data['destination'];
386
+		if (!$context_data['writable']) {
387
+					$context['make_writable'][] = $context_data['destination'];
388
+		}
376 389
 	}
377 390
 
378 391
 	// Before we go to far can we make anything writable, eh, eh?
@@ -387,22 +400,24 @@  discard block
 block discarded – undo
387 400
 		{
388 401
 			if ($type == 'lang')
389 402
 			{
390
-				foreach ($data as $k => $file)
391
-					if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
403
+				foreach ($data as $k => $file) {
404
+									if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
392 405
 						$context['files'][$type][$k]['writable'] = true;
393
-			}
394
-			else
406
+				}
407
+			} else
395 408
 			{
396
-				foreach ($data as $theme => $files)
397
-					foreach ($files as $k => $file)
409
+				foreach ($data as $theme => $files) {
410
+									foreach ($files as $k => $file)
398 411
 						if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
399 412
 							$context['files'][$type][$theme][$k]['writable'] = true;
413
+				}
400 414
 			}
401 415
 		}
402 416
 
403 417
 		// Are we going to need more language stuff?
404
-		if (!empty($context['still_not_writable']))
405
-			loadLanguage('Packages');
418
+		if (!empty($context['still_not_writable'])) {
419
+					loadLanguage('Packages');
420
+		}
406 421
 	}
407 422
 
408 423
 	// This is the list for the main files.
@@ -615,12 +630,13 @@  discard block
 block discarded – undo
615 630
 	highlightSelected("list_language_list_' . ($language == '' ? 'english' : $language) . '");', true);
616 631
 
617 632
 	// Display a warning if we cannot edit the default setting.
618
-	if (!is_writable($boarddir . '/Settings.php'))
619
-		$listOptions['additional_rows'][] = array(
633
+	if (!is_writable($boarddir . '/Settings.php')) {
634
+			$listOptions['additional_rows'][] = array(
620 635
 				'position' => 'after_title',
621 636
 				'value' => $txt['language_settings_writable'],
622 637
 				'class' => 'smalltext alert',
623 638
 			);
639
+	}
624 640
 
625 641
 	require_once($sourcedir . '/Subs-List.php');
626 642
 	createList($listOptions);
@@ -662,10 +678,11 @@  discard block
 block discarded – undo
662 678
 
663 679
 	// Put them back.
664 680
 	$settings['actual_theme_dir'] = $backup_actual_theme_dir;
665
-	if (!empty($backup_base_theme_dir))
666
-		$settings['base_theme_dir'] = $backup_base_theme_dir;
667
-	else
668
-		unset($settings['base_theme_dir']);
681
+	if (!empty($backup_base_theme_dir)) {
682
+			$settings['base_theme_dir'] = $backup_base_theme_dir;
683
+	} else {
684
+			unset($settings['base_theme_dir']);
685
+	}
669 686
 
670 687
 	// Get the language files and data...
671 688
 	foreach ($context['languages'] as $lang)
@@ -694,13 +711,15 @@  discard block
 block discarded – undo
694 711
 	while ($row = $smcFunc['db_fetch_assoc']($request))
695 712
 	{
696 713
 		// Default?
697
-		if (empty($row['lngfile']) || !isset($languages[$row['lngfile']]))
698
-			$row['lngfile'] = $language;
714
+		if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) {
715
+					$row['lngfile'] = $language;
716
+		}
699 717
 
700
-		if (!isset($languages[$row['lngfile']]) && isset($languages['english']))
701
-			$languages['english']['count'] += $row['num_users'];
702
-		elseif (isset($languages[$row['lngfile']]))
703
-			$languages[$row['lngfile']]['count'] += $row['num_users'];
718
+		if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) {
719
+					$languages['english']['count'] += $row['num_users'];
720
+		} elseif (isset($languages[$row['lngfile']])) {
721
+					$languages[$row['lngfile']]['count'] += $row['num_users'];
722
+		}
704 723
 	}
705 724
 	$smcFunc['db_free_result']($request);
706 725
 
@@ -740,13 +759,15 @@  discard block
 block discarded – undo
740 759
 
741 760
 	call_integration_hook('integrate_language_settings', array(&$config_vars));
742 761
 
743
-	if ($return_config)
744
-		return $config_vars;
762
+	if ($return_config) {
763
+			return $config_vars;
764
+	}
745 765
 
746 766
 	// Get our languages. No cache
747 767
 	getLanguages(false);
748
-	foreach ($context['languages'] as $lang)
749
-		$config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']);
768
+	foreach ($context['languages'] as $lang) {
769
+			$config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']);
770
+	}
750 771
 
751 772
 	// Saving settings?
752 773
 	if (isset($_REQUEST['save']))
@@ -756,8 +777,9 @@  discard block
 block discarded – undo
756 777
 		call_integration_hook('integrate_save_language_settings', array(&$config_vars));
757 778
 
758 779
 		saveSettings($config_vars);
759
-		if (!$settings_not_writable && !$settings_backup_fail)
760
-			$_SESSION['adm-save'] = true;
780
+		if (!$settings_not_writable && !$settings_backup_fail) {
781
+					$_SESSION['adm-save'] = true;
782
+		}
761 783
 		redirectexit('action=admin;area=languages;sa=settings');
762 784
 	}
763 785
 
@@ -766,10 +788,11 @@  discard block
 block discarded – undo
766 788
 	$context['settings_title'] = $txt['language_settings'];
767 789
 	$context['save_disabled'] = $settings_not_writable;
768 790
 
769
-	if ($settings_not_writable)
770
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
771
-	elseif ($settings_backup_fail)
772
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
791
+	if ($settings_not_writable) {
792
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
793
+	} elseif ($settings_backup_fail) {
794
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
795
+	}
773 796
 
774 797
 	// Fill the config array.
775 798
 	prepareServerSettingsContext($config_vars);
@@ -816,8 +839,9 @@  discard block
 block discarded – undo
816 839
 			'theme_dir' => $settings['default_theme_dir'],
817 840
 		),
818 841
 	);
819
-	while ($row = $smcFunc['db_fetch_assoc']($request))
820
-		$themes[$row['id_theme']][$row['variable']] = $row['value'];
842
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
843
+			$themes[$row['id_theme']][$row['variable']] = $row['value'];
844
+	}
821 845
 	$smcFunc['db_free_result']($request);
822 846
 
823 847
 	// This will be where we look
@@ -829,14 +853,16 @@  discard block
 block discarded – undo
829 853
 	// Check we have themes with a path and a name - just in case - and add the path.
830 854
 	foreach ($themes as $id => $data)
831 855
 	{
832
-		if (count($data) != 2)
833
-			unset($themes[$id]);
834
-		elseif (is_dir($data['theme_dir'] . '/languages'))
835
-			$lang_dirs[$id] = $data['theme_dir'] . '/languages';
856
+		if (count($data) != 2) {
857
+					unset($themes[$id]);
858
+		} elseif (is_dir($data['theme_dir'] . '/languages')) {
859
+					$lang_dirs[$id] = $data['theme_dir'] . '/languages';
860
+		}
836 861
 
837 862
 		// How about image directories?
838
-		if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id']))
839
-			$images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
863
+		if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) {
864
+					$images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
865
+		}
840 866
 	}
841 867
 
842 868
 	$current_file = $file_id ? $lang_dirs[$theme_id] . '/' . $file_id . '.' . $context['lang_id'] . '.php' : '';
@@ -850,15 +876,17 @@  discard block
 block discarded – undo
850 876
 		while ($entry = $dir->read())
851 877
 		{
852 878
 			// We're only after the files for this language.
853
-			if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0)
854
-				continue;
879
+			if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) {
880
+							continue;
881
+			}
855 882
 
856
-			if (!isset($context['possible_files'][$theme]))
857
-				$context['possible_files'][$theme] = array(
883
+			if (!isset($context['possible_files'][$theme])) {
884
+							$context['possible_files'][$theme] = array(
858 885
 					'id' => $theme,
859 886
 					'name' => $themes[$theme]['name'],
860 887
 					'files' => array(),
861 888
 				);
889
+			}
862 890
 
863 891
 			$context['possible_files'][$theme]['files'][] = array(
864 892
 				'id' => $matches[1],
@@ -887,31 +915,36 @@  discard block
 block discarded – undo
887 915
 		{
888 916
 			$_SESSION['last_backup_for'] = $context['lang_id'] . '$$$';
889 917
 			$result = package_create_backup('backup_lang_' . $context['lang_id']);
890
-			if (!$result)
891
-				fatal_lang_error('could_not_language_backup', false);
918
+			if (!$result) {
919
+							fatal_lang_error('could_not_language_backup', false);
920
+			}
892 921
 		}
893 922
 
894 923
 		// Second, loop through the array to remove the files.
895 924
 		foreach ($lang_dirs as $curPath)
896 925
 		{
897
-			foreach ($context['possible_files'][1]['files'] as $lang)
898
-				if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'))
926
+			foreach ($context['possible_files'][1]['files'] as $lang) {
927
+							if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'))
899 928
 					unlink($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php');
929
+			}
900 930
 
901 931
 			// Check for the email template.
902
-			if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'))
903
-				unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
932
+			if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) {
933
+							unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
934
+			}
904 935
 		}
905 936
 
906 937
 		// Third, the agreement file.
907
-		if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt'))
908
-			unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
938
+		if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) {
939
+					unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
940
+		}
909 941
 
910 942
 		// Fourth, a related images folder, if it exists...
911
-		if (!empty($images_dirs))
912
-			foreach ($images_dirs as $curPath)
943
+		if (!empty($images_dirs)) {
944
+					foreach ($images_dirs as $curPath)
913 945
 				if (is_dir($curPath))
914 946
 					deltree($curPath);
947
+		}
915 948
 
916 949
 		// Members can no longer use this language.
917 950
 		$smcFunc['db_query']('', '
@@ -995,8 +1028,9 @@  discard block
 block discarded – undo
995 1028
 		foreach ($_POST['entry'] as $k => $v)
996 1029
 		{
997 1030
 			// Only try to save if it's changed!
998
-			if ($_POST['entry'][$k] != $_POST['comp'][$k])
999
-				$save_strings[$k] = cleanLangString($v, false);
1031
+			if ($_POST['entry'][$k] != $_POST['comp'][$k]) {
1032
+							$save_strings[$k] = cleanLangString($v, false);
1033
+			}
1000 1034
 		}
1001 1035
 	}
1002 1036
 
@@ -1030,12 +1064,13 @@  discard block
 block discarded – undo
1030 1064
 		if ($multiline_cache)
1031 1065
 		{
1032 1066
 			preg_match('~\$(helptxt|txt|editortxt)\[\'(.+)\'\]\s?=\s?(.+);~ms', strtr($multiline_cache, array("\r" => '')), $matches);
1033
-			if (!empty($matches[3]))
1034
-				$entries[$matches[2]] = array(
1067
+			if (!empty($matches[3])) {
1068
+							$entries[$matches[2]] = array(
1035 1069
 					'type' => $matches[1],
1036 1070
 					'full' => $matches[0],
1037 1071
 					'entry' => $matches[3],
1038 1072
 				);
1073
+			}
1039 1074
 		}
1040 1075
 
1041 1076
 		// These are the entries we can definitely save.
@@ -1046,8 +1081,9 @@  discard block
 block discarded – undo
1046 1081
 		{
1047 1082
 			// Ignore some things we set separately.
1048 1083
 			$ignore_files = array('lang_character_set', 'lang_locale', 'lang_dictionary', 'lang_spelling', 'lang_rtl');
1049
-			if (in_array($entryKey, $ignore_files))
1050
-				continue;
1084
+			if (in_array($entryKey, $ignore_files)) {
1085
+							continue;
1086
+			}
1051 1087
 
1052 1088
 			// These are arrays that need breaking out.
1053 1089
 			$arrays = array('days', 'days_short', 'months', 'months_titles', 'months_short', 'happy_birthday_author', 'karlbenson1_author', 'nite0859_author', 'zwaldowski_author', 'geezmo_author', 'karlbenson2_author');
@@ -1080,9 +1116,9 @@  discard block
 block discarded – undo
1080 1116
 					{
1081 1117
 						$save_cache['entries'][$cur_index] = strtr($save_strings[$entryKey . '-+- ' . $cur_index], array('\'' => ''));
1082 1118
 						$save_cache['enabled'] = true;
1119
+					} else {
1120
+											$save_cache['entries'][$cur_index] = $subValue;
1083 1121
 					}
1084
-					else
1085
-						$save_cache['entries'][$cur_index] = $subValue;
1086 1122
 
1087 1123
 					$context['file_entries'][] = array(
1088 1124
 						'key' => $entryKey . '-+- ' . $cur_index,
@@ -1105,9 +1141,9 @@  discard block
 block discarded – undo
1105 1141
 						{
1106 1142
 							$items[] = $k2 . ' => \'' . $v2 . '\'';
1107 1143
 							$cur_index = $k2;
1144
+						} else {
1145
+													$items[] = '\'' . $v2 . '\'';
1108 1146
 						}
1109
-						else
1110
-							$items[] = '\'' . $v2 . '\'';
1111 1147
 
1112 1148
 						$cur_index++;
1113 1149
 					}
@@ -1117,15 +1153,15 @@  discard block
 block discarded – undo
1117 1153
 						'replace' => '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = array(' . implode(', ', $items) . ');',
1118 1154
 					);
1119 1155
 				}
1120
-			}
1121
-			else
1156
+			} else
1122 1157
 			{
1123 1158
 				// Saving?
1124 1159
 				if (isset($save_strings[$entryKey]) && $save_strings[$entryKey] != $entryValue['entry'])
1125 1160
 				{
1126 1161
 					// @todo Fix this properly.
1127
-					if ($save_strings[$entryKey] == '')
1128
-						$save_strings[$entryKey] = '\'\'';
1162
+					if ($save_strings[$entryKey] == '') {
1163
+											$save_strings[$entryKey] = '\'\'';
1164
+					}
1129 1165
 
1130 1166
 					// Set the new value.
1131 1167
 					$entryValue['entry'] = $save_strings[$entryKey];
@@ -1151,8 +1187,9 @@  discard block
 block discarded – undo
1151 1187
 			checkSession();
1152 1188
 
1153 1189
 			$file_contents = implode('', file($current_file));
1154
-			foreach ($final_saves as $save)
1155
-				$file_contents = strtr($file_contents, array($save['find'] => $save['replace']));
1190
+			foreach ($final_saves as $save) {
1191
+							$file_contents = strtr($file_contents, array($save['find'] => $save['replace']));
1192
+			}
1156 1193
 
1157 1194
 			// Save the actual changes.
1158 1195
 			$fp = fopen($current_file, 'w+');
@@ -1167,8 +1204,9 @@  discard block
 block discarded – undo
1167 1204
 	}
1168 1205
 
1169 1206
 	// If we saved, redirect.
1170
-	if ($madeSave)
1171
-		redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']);
1207
+	if ($madeSave) {
1208
+			redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']);
1209
+	}
1172 1210
 
1173 1211
 	createToken('admin-mlang');
1174 1212
 }
@@ -1200,8 +1238,9 @@  discard block
 block discarded – undo
1200 1238
 				// Toggle the escape.
1201 1239
 				$is_escape = !$is_escape;
1202 1240
 				// If we're now escaped don't add this string.
1203
-				if ($is_escape)
1204
-					continue;
1241
+				if ($is_escape) {
1242
+									continue;
1243
+				}
1205 1244
 			}
1206 1245
 			// Special case - parsed string with line break etc?
1207 1246
 			elseif (($string{$i} == 'n' || $string{$i} == 't') && $in_string == 2 && $is_escape)
@@ -1218,11 +1257,13 @@  discard block
 block discarded – undo
1218 1257
 				if ($in_string != 2 && ($in_string != 1 || !$is_escape))
1219 1258
 				{
1220 1259
 					// Is it the end of a single quote string?
1221
-					if ($in_string == 1)
1222
-						$in_string = 0;
1260
+					if ($in_string == 1) {
1261
+											$in_string = 0;
1262
+					}
1223 1263
 					// Otherwise it's the start!
1224
-					else
1225
-						$in_string = 1;
1264
+					else {
1265
+											$in_string = 1;
1266
+					}
1226 1267
 
1227 1268
 					// Don't actually include this character!
1228 1269
 					continue;
@@ -1235,19 +1276,22 @@  discard block
 block discarded – undo
1235 1276
 				if ($in_string != 1 && ($in_string != 2 || !$is_escape))
1236 1277
 				{
1237 1278
 					// Is it the end of a double quote string?
1238
-					if ($in_string == 2)
1239
-						$in_string = 0;
1279
+					if ($in_string == 2) {
1280
+											$in_string = 0;
1281
+					}
1240 1282
 					// Otherwise it's the start!
1241
-					else
1242
-						$in_string = 2;
1283
+					else {
1284
+											$in_string = 2;
1285
+					}
1243 1286
 
1244 1287
 					// Don't actually include this character!
1245 1288
 					continue;
1246 1289
 				}
1247 1290
 			}
1248 1291
 			// A join/space outside of a string is simply removed.
1249
-			elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.'))
1250
-				continue;
1292
+			elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.')) {
1293
+							continue;
1294
+			}
1251 1295
 			// Start of a variable?
1252 1296
 			elseif ($in_string == 0 && $string{$i} == '$')
1253 1297
 			{
@@ -1281,8 +1325,7 @@  discard block
 block discarded – undo
1281 1325
 
1282 1326
 		// Unhtml then rehtml the whole thing!
1283 1327
 		$new_string = $smcFunc['htmlspecialchars'](un_htmlspecialchars($new_string));
1284
-	}
1285
-	else
1328
+	} else
1286 1329
 	{
1287 1330
 		// Keep track of what we're doing...
1288 1331
 		$in_string = 0;
@@ -1311,10 +1354,11 @@  discard block
 block discarded – undo
1311 1354
 				preg_match('~\{%([\$A-Za-z0-9\'\[\]_-]+)%\}~', substr($string, $i), $matches);
1312 1355
 				if (!empty($matches[1]))
1313 1356
 				{
1314
-					if ($in_string == 1)
1315
-						$new_string .= '\' . ';
1316
-					elseif ($new_string)
1317
-						$new_string .= ' . ';
1357
+					if ($in_string == 1) {
1358
+											$new_string .= '\' . ';
1359
+					} elseif ($new_string) {
1360
+											$new_string .= ' . ';
1361
+					}
1318 1362
 
1319 1363
 					$new_string .= $matches[1];
1320 1364
 					$i += strlen($matches[1]) + 3;
@@ -1327,8 +1371,9 @@  discard block
 block discarded – undo
1327 1371
 			elseif ($string{$i} == '<')
1328 1372
 			{
1329 1373
 				// Probably HTML?
1330
-				if ($string{$i + 1} != ' ')
1331
-					$in_html = true;
1374
+				if ($string{$i + 1} != ' ') {
1375
+									$in_html = true;
1376
+				}
1332 1377
 				// Assume we need an entity...
1333 1378
 				else
1334 1379
 				{
@@ -1340,8 +1385,9 @@  discard block
 block discarded – undo
1340 1385
 			elseif ($string{$i} == '>')
1341 1386
 			{
1342 1387
 				// Will it be HTML?
1343
-				if ($in_html)
1344
-					$in_html = false;
1388
+				if ($in_html) {
1389
+									$in_html = false;
1390
+				}
1345 1391
 				// Otherwise we need an entity...
1346 1392
 				else
1347 1393
 				{
@@ -1350,8 +1396,9 @@  discard block
 block discarded – undo
1350 1396
 				}
1351 1397
 			}
1352 1398
 			// Is it a slash? If so escape it...
1353
-			if ($string{$i} == '\\')
1354
-				$new_string .= '\\';
1399
+			if ($string{$i} == '\\') {
1400
+							$new_string .= '\\';
1401
+			}
1355 1402
 			// The infamous double quote?
1356 1403
 			elseif ($string{$i} == '"')
1357 1404
 			{
@@ -1374,10 +1421,11 @@  discard block
 block discarded – undo
1374 1421
 		}
1375 1422
 
1376 1423
 		// If we ended as a string then close it off.
1377
-		if ($in_string == 1)
1378
-			$new_string .= '\'';
1379
-		elseif ($in_string == 2)
1380
-			$new_string .= '"';
1424
+		if ($in_string == 1) {
1425
+					$new_string .= '\'';
1426
+		} elseif ($in_string == 2) {
1427
+					$new_string .= '"';
1428
+		}
1381 1429
 	}
1382 1430
 
1383 1431
 	return $new_string;
Please login to merge, or discard this patch.
Sources/Errors.php 1 patch
Braces   +117 added lines, -83 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Log an error, if the error logging is enabled.
@@ -36,8 +37,9 @@  discard block
 block discarded – undo
36 37
 	static $tried_hook = false;
37 38
 
38 39
 	// Check if error logging is actually on.
39
-	if (empty($modSettings['enableErrorLogging']))
40
-		return $error_message;
40
+	if (empty($modSettings['enableErrorLogging'])) {
41
+			return $error_message;
42
+	}
41 43
 
42 44
 	// Basically, htmlspecialchars it minus &. (for entities!)
43 45
 	$error_message = strtr($error_message, array('<' => '&lt;', '>' => '&gt;', '"' => '&quot;'));
@@ -45,22 +47,26 @@  discard block
 block discarded – undo
45 47
 
46 48
 	// Add a file and line to the error message?
47 49
 	// Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line
48
-	if ($file == null)
49
-		$file = '';
50
-	else
51
-		// Window style slashes don't play well, lets convert them to the unix style.
50
+	if ($file == null) {
51
+			$file = '';
52
+	} else {
53
+			// Window style slashes don't play well, lets convert them to the unix style.
52 54
 		$file = str_replace('\\', '/', $file);
55
+	}
53 56
 
54
-	if ($line == null)
55
-		$line = 0;
56
-	else
57
-		$line = (int) $line;
57
+	if ($line == null) {
58
+			$line = 0;
59
+	} else {
60
+			$line = (int) $line;
61
+	}
58 62
 
59 63
 	// Just in case there's no id_member or IP set yet.
60
-	if (empty($user_info['id']))
61
-		$user_info['id'] = 0;
62
-	if (empty($user_info['ip']))
63
-		$user_info['ip'] = '';
64
+	if (empty($user_info['id'])) {
65
+			$user_info['id'] = 0;
66
+	}
67
+	if (empty($user_info['ip'])) {
68
+			$user_info['ip'] = '';
69
+	}
64 70
 
65 71
 	// Find the best query string we can...
66 72
 	$query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING'];
@@ -69,8 +75,9 @@  discard block
 block discarded – undo
69 75
 	$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
70 76
 
71 77
 	// Just so we know what board error messages are from.
72
-	if (isset($_POST['board']) && !isset($_GET['board']))
73
-		$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
78
+	if (isset($_POST['board']) && !isset($_GET['board'])) {
79
+			$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
80
+	}
74 81
 
75 82
 	// What types of categories do we have?
76 83
 	$known_error_types = array(
@@ -132,12 +139,14 @@  discard block
 block discarded – undo
132 139
 	global $txt;
133 140
 
134 141
 	// Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all
135
-	if (!empty($status))
136
-		send_http_status($status);
142
+	if (!empty($status)) {
143
+			send_http_status($status);
144
+	}
137 145
 
138 146
 	// We don't have $txt yet, but that's okay...
139
-	if (empty($txt))
140
-		die($error);
147
+	if (empty($txt)) {
148
+			die($error);
149
+	}
141 150
 
142 151
 	log_error_online($error, false);
143 152
 	setup_fatal_error_context($log ? log_error($error, $log) : $error);
@@ -164,8 +173,9 @@  discard block
 block discarded – undo
164 173
 	static $fatal_error_called = false;
165 174
 
166 175
 	// Send the status header - set this to 0 or false if you don't want to send one at all
167
-	if (!empty($status))
168
-		send_http_status($status);
176
+	if (!empty($status)) {
177
+			send_http_status($status);
178
+	}
169 179
 
170 180
 	// Try to load a theme if we don't have one.
171 181
 	if (empty($context['theme_loaded']) && empty($fatal_error_called))
@@ -175,8 +185,9 @@  discard block
 block discarded – undo
175 185
 	}
176 186
 
177 187
 	// If we have no theme stuff we can't have the language file...
178
-	if (empty($context['theme_loaded']))
179
-		die($error);
188
+	if (empty($context['theme_loaded'])) {
189
+			die($error);
190
+	}
180 191
 
181 192
 	$reload_lang_file = true;
182 193
 	// Log the error in the forum's language, but don't waste the time if we aren't logging
@@ -212,8 +223,9 @@  discard block
 block discarded – undo
212 223
 	global $settings, $modSettings, $db_show_debug;
213 224
 
214 225
 	// Ignore errors if we're ignoring them or they are strict notices from PHP 5 (which cannot be solved without breaking PHP 4.)
215
-	if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging'])))
216
-		return;
226
+	if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) {
227
+			return;
228
+	}
217 229
 
218 230
 	if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename']))
219 231
 	{
@@ -221,19 +233,22 @@  discard block
 block discarded – undo
221 233
 		$count = count($array);
222 234
 		for ($i = 0; $i < $count; $i++)
223 235
 		{
224
-			if ($array[$i]['function'] != 'loadSubTemplate')
225
-				continue;
236
+			if ($array[$i]['function'] != 'loadSubTemplate') {
237
+							continue;
238
+			}
226 239
 
227 240
 			// This is a bug in PHP, with eval, it seems!
228
-			if (empty($array[$i]['args']))
229
-				$i++;
241
+			if (empty($array[$i]['args'])) {
242
+							$i++;
243
+			}
230 244
 			break;
231 245
 		}
232 246
 
233
-		if (isset($array[$i]) && !empty($array[$i]['args']))
234
-			$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
235
-		else
236
-			$file = realpath($settings['current_include_filename']) . ' (eval?)';
247
+		if (isset($array[$i]) && !empty($array[$i]['args'])) {
248
+					$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
249
+		} else {
250
+					$file = realpath($settings['current_include_filename']) . ' (eval?)';
251
+		}
237 252
 	}
238 253
 
239 254
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -242,8 +257,9 @@  discard block
 block discarded – undo
242 257
 		if ($error_level % 255 != E_ERROR)
243 258
 		{
244 259
 			$temporary = ob_get_contents();
245
-			if (substr($temporary, -2) == '="')
246
-				echo '"';
260
+			if (substr($temporary, -2) == '="') {
261
+							echo '"';
262
+			}
247 263
 		}
248 264
 
249 265
 		// Debugging!  This should look like a PHP error message.
@@ -259,23 +275,27 @@  discard block
 block discarded – undo
259 275
 	call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line));
260 276
 
261 277
 	// Dying on these errors only causes MORE problems (blank pages!)
262
-	if ($file == 'Unknown')
263
-		return;
278
+	if ($file == 'Unknown') {
279
+			return;
280
+	}
264 281
 
265 282
 	// If this is an E_ERROR or E_USER_ERROR.... die.  Violently so.
266
-	if ($error_level % 255 == E_ERROR)
267
-		obExit(false);
268
-	else
269
-		return;
283
+	if ($error_level % 255 == E_ERROR) {
284
+			obExit(false);
285
+	} else {
286
+			return;
287
+	}
270 288
 
271 289
 	// If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die.  Violently so.
272
-	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING)
273
-		fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
290
+	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) {
291
+			fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
292
+	}
274 293
 
275 294
 	// We should NEVER get to this point.  Any fatal error MUST quit, or very bad things can happen.
276
-	if ($error_level % 255 == E_ERROR)
277
-		die('No direct access...');
278
-}
295
+	if ($error_level % 255 == E_ERROR) {
296
+			die('No direct access...');
297
+	}
298
+	}
279 299
 
280 300
 /**
281 301
  * It is called by {@link fatal_error()} and {@link fatal_lang_error()}.
@@ -291,24 +311,28 @@  discard block
 block discarded – undo
291 311
 
292 312
 	// Attempt to prevent a recursive loop.
293 313
 	++$level;
294
-	if ($level > 1)
295
-		return false;
314
+	if ($level > 1) {
315
+			return false;
316
+	}
296 317
 
297 318
 	// Maybe they came from dlattach or similar?
298
-	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded']))
299
-		loadTheme();
319
+	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) {
320
+			loadTheme();
321
+	}
300 322
 
301 323
 	// Don't bother indexing errors mate...
302 324
 	$context['robot_no_index'] = true;
303 325
 
304
-	if (!isset($context['error_title']))
305
-		$context['error_title'] = $txt['error_occured'];
326
+	if (!isset($context['error_title'])) {
327
+			$context['error_title'] = $txt['error_occured'];
328
+	}
306 329
 	$context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message;
307 330
 
308 331
 	$context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : '';
309 332
 
310
-	if (empty($context['page_title']))
311
-		$context['page_title'] = $context['error_title'];
333
+	if (empty($context['page_title'])) {
334
+			$context['page_title'] = $context['error_title'];
335
+	}
312 336
 
313 337
 	loadTemplate('Errors');
314 338
 	$context['sub_template'] = 'fatal_error';
@@ -316,23 +340,26 @@  discard block
 block discarded – undo
316 340
 	// If this is SSI, what do they want us to do?
317 341
 	if (SMF == 'SSI')
318 342
 	{
319
-		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method))
320
-			$ssi_on_error_method();
321
-		elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
322
-			loadSubTemplate('fatal_error');
343
+		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) {
344
+					$ssi_on_error_method();
345
+		} elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
346
+					loadSubTemplate('fatal_error');
347
+		}
323 348
 
324 349
 		// No layers?
325
-		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
326
-			exit;
350
+		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
351
+					exit;
352
+		}
327 353
 	}
328 354
 	// Alternatively from the cron call?
329 355
 	elseif (SMF == 'BACKGROUND')
330 356
 	{
331 357
 		// We can't rely on even having language files available.
332
-		if (defined('FROM_CLI') && FROM_CLI)
333
-			echo 'cron error: ', $context['error_message'];
334
-		else
335
-			echo 'An error occurred. More information may be available in your logs.';
358
+		if (defined('FROM_CLI') && FROM_CLI) {
359
+					echo 'cron error: ', $context['error_message'];
360
+		} else {
361
+					echo 'An error occurred. More information may be available in your logs.';
362
+		}
336 363
 		exit;
337 364
 	}
338 365
 
@@ -360,8 +387,8 @@  discard block
 block discarded – undo
360 387
 
361 388
 	set_fatal_error_headers();
362 389
 
363
-	if (!empty($maintenance))
364
-		echo '<!DOCTYPE html>
390
+	if (!empty($maintenance)) {
391
+			echo '<!DOCTYPE html>
365 392
 <html>
366 393
 	<head>
367 394
 		<meta name="robots" content="noindex">
@@ -372,6 +399,7 @@  discard block
 block discarded – undo
372 399
 		', $mmessage, '
373 400
 	</body>
374 401
 </html>';
402
+	}
375 403
 
376 404
 	die();
377 405
 }
@@ -393,15 +421,17 @@  discard block
 block discarded – undo
393 421
 	// For our purposes, we're gonna want this on if at all possible.
394 422
 	$modSettings['cache_enable'] = '1';
395 423
 
396
-	if (($temp = cache_get_data('db_last_error', 600)) !== null)
397
-		$db_last_error = max($db_last_error, $temp);
424
+	if (($temp = cache_get_data('db_last_error', 600)) !== null) {
425
+			$db_last_error = max($db_last_error, $temp);
426
+	}
398 427
 
399 428
 	if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send))
400 429
 	{
401 430
 		// Avoid writing to the Settings.php file if at all possible; use shared memory instead.
402 431
 		cache_put_data('db_last_error', time(), 600);
403
-		if (($temp = cache_get_data('db_last_error', 600)) === null)
404
-			logLastDatabaseError();
432
+		if (($temp = cache_get_data('db_last_error', 600)) === null) {
433
+					logLastDatabaseError();
434
+		}
405 435
 
406 436
 		// Language files aren't loaded yet :(.
407 437
 		$db_error = @$smcFunc['db_error']($db_connection);
@@ -482,12 +512,14 @@  discard block
 block discarded – undo
482 512
 	global $smcFunc, $user_info, $modSettings;
483 513
 
484 514
 	// Don't bother if Who's Online is disabled.
485
-	if (empty($modSettings['who_enabled']))
486
-		return;
515
+	if (empty($modSettings['who_enabled'])) {
516
+			return;
517
+	}
487 518
 
488 519
 	// Maybe they came from SSI or similar where sessions are not recorded?
489
-	if (SMF == 'SSI' || SMF == 'BACKGROUND')
490
-		return;
520
+	if (SMF == 'SSI' || SMF == 'BACKGROUND') {
521
+			return;
522
+	}
491 523
 
492 524
 	$session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id();
493 525
 
@@ -506,8 +538,9 @@  discard block
 block discarded – undo
506 538
 		$url = smf_json_decode($url, true);
507 539
 		$url['error'] = $error;
508 540
 
509
-		if (!empty($sprintf))
510
-			$url['error_params'] = $sprintf;
541
+		if (!empty($sprintf)) {
542
+					$url['error_params'] = $sprintf;
543
+		}
511 544
 
512 545
 		$smcFunc['db_query']('', '
513 546
 			UPDATE {db_prefix}log_online
@@ -538,10 +571,11 @@  discard block
 block discarded – undo
538 571
 
539 572
 	$protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
540 573
 
541
-	if (!isset($statuses[$code]))
542
-		header($protocol . ' 500 Internal Server Error');
543
-	else
544
-		header($protocol . ' ' . $code . ' ' . $statuses[$code]);
545
-}
574
+	if (!isset($statuses[$code])) {
575
+			header($protocol . ' 500 Internal Server Error');
576
+	} else {
577
+			header($protocol . ' ' . $code . ' ' . $statuses[$code]);
578
+	}
579
+	}
546 580
 
547 581
 ?>
548 582
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/ManageServer.php 1 patch
Braces   +265 added lines, -204 removed lines patch added patch discarded remove patch
@@ -59,8 +59,9 @@  discard block
 block discarded – undo
59 59
  * @version 2.1 Beta 4
60 60
  */
61 61
 
62
-if (!defined('SMF'))
62
+if (!defined('SMF')) {
63 63
 	die('No direct access...');
64
+}
64 65
 
65 66
 /**
66 67
  * This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects
@@ -111,10 +112,11 @@  discard block
 block discarded – undo
111 112
 	$settings_not_writable = !is_writable($boarddir . '/Settings.php');
112 113
 	$settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
113 114
 
114
-	if ($settings_not_writable)
115
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
116
-	elseif ($settings_backup_fail)
117
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
115
+	if ($settings_not_writable) {
116
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
117
+	} elseif ($settings_backup_fail) {
118
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
119
+	}
118 120
 
119 121
 	$context['settings_not_writable'] = $settings_not_writable;
120 122
 
@@ -168,8 +170,9 @@  discard block
 block discarded – undo
168 170
 
169 171
 	call_integration_hook('integrate_general_settings', array(&$config_vars));
170 172
 
171
-	if ($return_config)
172
-		return $config_vars;
173
+	if ($return_config) {
174
+			return $config_vars;
175
+	}
173 176
 
174 177
 	// Setup the template stuff.
175 178
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=general;save';
@@ -186,8 +189,9 @@  discard block
 block discarded – undo
186 189
 			$registerSMStats = registerSMStats();
187 190
 
188 191
 			// Failed to register, disable it again.
189
-			if (empty($registerSMStats))
190
-				$_POST['enable_sm_stats'] = 0;
192
+			if (empty($registerSMStats)) {
193
+							$_POST['enable_sm_stats'] = 0;
194
+			}
191 195
 		}
192 196
 
193 197
 		saveSettings($config_vars);
@@ -248,8 +252,9 @@  discard block
 block discarded – undo
248 252
 		$request = $smcFunc['db_query']('', 'SELECT cfgname FROM pg_ts_config', array());
249 253
 		$fts_language = array();
250 254
 
251
-		while ($row = $smcFunc['db_fetch_assoc']($request))
252
-			$fts_language[$row['cfgname']] = $row['cfgname'];
255
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
256
+					$fts_language[$row['cfgname']] = $row['cfgname'];
257
+		}
253 258
 
254 259
 		$config_vars = array_merge ($config_vars, array(
255 260
 				'',
@@ -261,8 +266,9 @@  discard block
 block discarded – undo
261 266
 
262 267
 	call_integration_hook('integrate_database_settings', array(&$config_vars));
263 268
 
264
-	if ($return_config)
265
-		return $config_vars;
269
+	if ($return_config) {
270
+			return $config_vars;
271
+	}
266 272
 
267 273
 	// Setup the template stuff.
268 274
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save';
@@ -337,13 +343,15 @@  discard block
 block discarded – undo
337 343
 		hideGlobalCookies();
338 344
 	});', true);
339 345
 
340
-	if (empty($user_settings['tfa_secret']))
341
-		addInlineJavaScript('');
346
+	if (empty($user_settings['tfa_secret'])) {
347
+			addInlineJavaScript('');
348
+	}
342 349
 
343 350
 	call_integration_hook('integrate_cookie_settings', array(&$config_vars));
344 351
 
345
-	if ($return_config)
346
-		return $config_vars;
352
+	if ($return_config) {
353
+			return $config_vars;
354
+	}
347 355
 
348 356
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save';
349 357
 	$context['settings_title'] = $txt['cookies_sessions_settings'];
@@ -354,11 +362,13 @@  discard block
 block discarded – undo
354 362
 		call_integration_hook('integrate_save_cookie_settings');
355 363
 
356 364
 		// Local and global do not play nicely together.
357
-		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies']))
358
-			unset ($_POST['globalCookies']);
365
+		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) {
366
+					unset ($_POST['globalCookies']);
367
+		}
359 368
 
360
-		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false)
361
-			fatal_lang_error('invalid_cookie_domain', false);
369
+		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) {
370
+					fatal_lang_error('invalid_cookie_domain', false);
371
+		}
362 372
 
363 373
 		saveSettings($config_vars);
364 374
 
@@ -441,8 +451,9 @@  discard block
 block discarded – undo
441 451
 
442 452
 	call_integration_hook('integrate_general_security_settings', array(&$config_vars));
443 453
 
444
-	if ($return_config)
445
-		return $config_vars;
454
+	if ($return_config) {
455
+			return $config_vars;
456
+	}
446 457
 
447 458
 	// Saving?
448 459
 	if (isset($_GET['save']))
@@ -481,8 +492,7 @@  discard block
 block discarded – undo
481 492
 		$txt['cache_settings_message'] = $txt['detected_no_caching'];
482 493
 		$cache_level = array($txt['cache_off']);
483 494
 		$detected['none'] = $txt['cache_off'];
484
-	}
485
-	else
495
+	} else
486 496
 	{
487 497
 		$txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected));
488 498
 		$cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']);
@@ -519,8 +529,9 @@  discard block
 block discarded – undo
519 529
 			}
520 530
 		}
521 531
 	}
522
-	if ($return_config)
523
-		return $config_vars;
532
+	if ($return_config) {
533
+			return $config_vars;
534
+	}
524 535
 
525 536
 	// Saving again?
526 537
 	if (isset($_GET['save']))
@@ -548,8 +559,9 @@  discard block
 block discarded – undo
548 559
 	$context['save_disabled'] = $context['settings_not_writable'];
549 560
 
550 561
 	// Decide what message to show.
551
-	if (!$context['save_disabled'])
552
-		$context['settings_message'] = $txt['caching_information'];
562
+	if (!$context['save_disabled']) {
563
+			$context['settings_message'] = $txt['caching_information'];
564
+	}
553 565
 
554 566
 	// Prepare the template.
555 567
 	prepareServerSettingsContext($config_vars);
@@ -572,24 +584,25 @@  discard block
 block discarded – undo
572 584
 	if (stripos(PHP_OS, 'win') === 0)
573 585
 	{
574 586
 		$context['settings_message'] = $txt['loadavg_disabled_windows'];
575
-		if (isset($_GET['save']))
576
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
577
-	}
578
-	elseif (stripos(PHP_OS, 'darwin') === 0)
587
+		if (isset($_GET['save'])) {
588
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
589
+		}
590
+	} elseif (stripos(PHP_OS, 'darwin') === 0)
579 591
 	{
580 592
 		$context['settings_message'] = $txt['loadavg_disabled_osx'];
581
-		if (isset($_GET['save']))
582
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
583
-	}
584
-	else
593
+		if (isset($_GET['save'])) {
594
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
595
+		}
596
+	} else
585 597
 	{
586 598
 		$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
587
-		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0)
588
-			$modSettings['load_average'] = (float) $matches[1];
589
-		elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0)
590
-			$modSettings['load_average'] = (float) $matches[1];
591
-		else
592
-			unset($modSettings['load_average']);
599
+		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) {
600
+					$modSettings['load_average'] = (float) $matches[1];
601
+		} elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) {
602
+					$modSettings['load_average'] = (float) $matches[1];
603
+		} else {
604
+					unset($modSettings['load_average']);
605
+		}
593 606
 
594 607
 		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
595 608
 		{
@@ -625,8 +638,9 @@  discard block
 block discarded – undo
625 638
 
626 639
 	call_integration_hook('integrate_loadavg_settings', array(&$config_vars));
627 640
 
628
-	if ($return_config)
629
-		return $config_vars;
641
+	if ($return_config) {
642
+			return $config_vars;
643
+	}
630 644
 
631 645
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save';
632 646
 	$context['settings_title'] = $txt['load_balancing_settings'];
@@ -637,24 +651,27 @@  discard block
 block discarded – undo
637 651
 		// Stupidity is not allowed.
638 652
 		foreach ($_POST as $key => $value)
639 653
 		{
640
-			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values)))
641
-				continue;
642
-			else
643
-				$_POST[$key] = (float) $value;
644
-
645
-			if ($key == 'loadavg_auto_opt' && $value <= 1)
646
-				$_POST['loadavg_auto_opt'] = 1.0;
647
-			elseif ($key == 'loadavg_forum' && $value < 10)
648
-				$_POST['loadavg_forum'] = 10.0;
649
-			elseif ($value < 2)
650
-				$_POST[$key] = 2.0;
654
+			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) {
655
+							continue;
656
+			} else {
657
+							$_POST[$key] = (float) $value;
658
+			}
659
+
660
+			if ($key == 'loadavg_auto_opt' && $value <= 1) {
661
+							$_POST['loadavg_auto_opt'] = 1.0;
662
+			} elseif ($key == 'loadavg_forum' && $value < 10) {
663
+							$_POST['loadavg_forum'] = 10.0;
664
+			} elseif ($value < 2) {
665
+							$_POST[$key] = 2.0;
666
+			}
651 667
 		}
652 668
 
653 669
 		call_integration_hook('integrate_save_loadavg_settings');
654 670
 
655 671
 		saveDBSettings($config_vars);
656
-		if (!isset($_SESSION['adm-save']))
657
-			$_SESSION['adm-save'] = true;
672
+		if (!isset($_SESSION['adm-save'])) {
673
+					$_SESSION['adm-save'] = true;
674
+		}
658 675
 		redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']);
659 676
 	}
660 677
 
@@ -690,10 +707,11 @@  discard block
 block discarded – undo
690 707
 
691 708
 	if (isset($_SESSION['adm-save']))
692 709
 	{
693
-		if ($_SESSION['adm-save'] === true)
694
-			$context['saved_successful'] = true;
695
-		else
696
-			$context['saved_failed'] = $_SESSION['adm-save'];
710
+		if ($_SESSION['adm-save'] === true) {
711
+					$context['saved_successful'] = true;
712
+		} else {
713
+					$context['saved_failed'] = $_SESSION['adm-save'];
714
+		}
697 715
 
698 716
 		unset($_SESSION['adm-save']);
699 717
 	}
@@ -701,9 +719,9 @@  discard block
 block discarded – undo
701 719
 	$context['config_vars'] = array();
702 720
 	foreach ($config_vars as $identifier => $config_var)
703 721
 	{
704
-		if (!is_array($config_var) || !isset($config_var[1]))
705
-			$context['config_vars'][] = $config_var;
706
-		else
722
+		if (!is_array($config_var) || !isset($config_var[1])) {
723
+					$context['config_vars'][] = $config_var;
724
+		} else
707 725
 		{
708 726
 			$varname = $config_var[0];
709 727
 			global $$varname;
@@ -738,16 +756,19 @@  discard block
 block discarded – undo
738 756
 			if ($config_var[3] == 'int' || $config_var[3] == 'float')
739 757
 			{
740 758
 				// Default to a min of 0 if one isn't set
741
-				if (isset($config_var['min']))
742
-					$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
743
-				else
744
-					$context['config_vars'][$config_var[0]]['min'] = 0;
759
+				if (isset($config_var['min'])) {
760
+									$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
761
+				} else {
762
+									$context['config_vars'][$config_var[0]]['min'] = 0;
763
+				}
745 764
 
746
-				if (isset($config_var['max']))
747
-					$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
765
+				if (isset($config_var['max'])) {
766
+									$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
767
+				}
748 768
 
749
-				if (isset($config_var['step']))
750
-					$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
769
+				if (isset($config_var['step'])) {
770
+									$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
771
+				}
751 772
 			}
752 773
 
753 774
 			// If this is a select box handle any data.
@@ -755,12 +776,13 @@  discard block
 block discarded – undo
755 776
 			{
756 777
 				// If it's associative
757 778
 				$config_values = array_values($config_var[4]);
758
-				if (isset($config_values[0]) && is_array($config_values[0]))
759
-					$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
760
-				else
779
+				if (isset($config_values[0]) && is_array($config_values[0])) {
780
+									$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
781
+				} else
761 782
 				{
762
-					foreach ($config_var[4] as $key => $item)
763
-						$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
783
+					foreach ($config_var[4] as $key => $item) {
784
+											$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
785
+					}
764 786
 				}
765 787
 			}
766 788
 		}
@@ -785,10 +807,11 @@  discard block
 block discarded – undo
785 807
 
786 808
 	if (isset($_SESSION['adm-save']))
787 809
 	{
788
-		if ($_SESSION['adm-save'] === true)
789
-			$context['saved_successful'] = true;
790
-		else
791
-			$context['saved_failed'] = $_SESSION['adm-save'];
810
+		if ($_SESSION['adm-save'] === true) {
811
+					$context['saved_successful'] = true;
812
+		} else {
813
+					$context['saved_failed'] = $_SESSION['adm-save'];
814
+		}
792 815
 
793 816
 		unset($_SESSION['adm-save']);
794 817
 	}
@@ -800,26 +823,30 @@  discard block
 block discarded – undo
800 823
 	foreach ($config_vars as $config_var)
801 824
 	{
802 825
 		// HR?
803
-		if (!is_array($config_var))
804
-			$context['config_vars'][] = $config_var;
805
-		else
826
+		if (!is_array($config_var)) {
827
+					$context['config_vars'][] = $config_var;
828
+		} else
806 829
 		{
807 830
 			// If it has no name it doesn't have any purpose!
808
-			if (empty($config_var[1]))
809
-				continue;
831
+			if (empty($config_var[1])) {
832
+							continue;
833
+			}
810 834
 
811 835
 			// Special case for inline permissions
812
-			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions'))
813
-				$inlinePermissions[] = $config_var[1];
814
-			elseif ($config_var[0] == 'permissions')
815
-				continue;
836
+			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) {
837
+							$inlinePermissions[] = $config_var[1];
838
+			} elseif ($config_var[0] == 'permissions') {
839
+							continue;
840
+			}
816 841
 
817
-			if ($config_var[0] == 'boards')
818
-				$board_list = true;
842
+			if ($config_var[0] == 'boards') {
843
+							$board_list = true;
844
+			}
819 845
 
820 846
 			// Are we showing the BBC selection box?
821
-			if ($config_var[0] == 'bbc')
822
-				$bbcChoice[] = $config_var[1];
847
+			if ($config_var[0] == 'bbc') {
848
+							$bbcChoice[] = $config_var[1];
849
+			}
823 850
 
824 851
 			// We need to do some parsing of the value before we pass it in.
825 852
 			if (isset($modSettings[$config_var[1]]))
@@ -838,8 +865,7 @@  discard block
 block discarded – undo
838 865
 					default:
839 866
 						$value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]);
840 867
 				}
841
-			}
842
-			else
868
+			} else
843 869
 			{
844 870
 				// Darn, it's empty. What type is expected?
845 871
 				switch ($config_var[0])
@@ -879,16 +905,19 @@  discard block
 block discarded – undo
879 905
 			if ($config_var[0] == 'int' || $config_var[0] == 'float')
880 906
 			{
881 907
 				// Default to a min of 0 if one isn't set
882
-				if (isset($config_var['min']))
883
-					$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
884
-				else
885
-					$context['config_vars'][$config_var[1]]['min'] = 0;
908
+				if (isset($config_var['min'])) {
909
+									$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
910
+				} else {
911
+									$context['config_vars'][$config_var[1]]['min'] = 0;
912
+				}
886 913
 
887
-				if (isset($config_var['max']))
888
-					$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
914
+				if (isset($config_var['max'])) {
915
+									$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
916
+				}
889 917
 
890
-				if (isset($config_var['step']))
891
-					$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
918
+				if (isset($config_var['step'])) {
919
+									$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
920
+				}
892 921
 			}
893 922
 
894 923
 			// If this is a select box handle any data.
@@ -902,12 +931,13 @@  discard block
 block discarded – undo
902 931
 				}
903 932
 
904 933
 				// If it's associative
905
-				if (isset($config_var[2][0]) && is_array($config_var[2][0]))
906
-					$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
907
-				else
934
+				if (isset($config_var[2][0]) && is_array($config_var[2][0])) {
935
+									$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
936
+				} else
908 937
 				{
909
-					foreach ($config_var[2] as $key => $item)
910
-						$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
938
+					foreach ($config_var[2] as $key => $item) {
939
+											$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
940
+					}
911 941
 				}
912 942
 			}
913 943
 
@@ -916,17 +946,19 @@  discard block
 block discarded – undo
916 946
 			{
917 947
 				if (!is_numeric($k))
918 948
 				{
919
-					if (substr($k, 0, 2) == 'on')
920
-						$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
921
-					else
922
-						$context['config_vars'][$config_var[1]][$k] = $v;
949
+					if (substr($k, 0, 2) == 'on') {
950
+											$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
951
+					} else {
952
+											$context['config_vars'][$config_var[1]][$k] = $v;
953
+					}
923 954
 				}
924 955
 
925 956
 				// See if there are any other labels that might fit?
926
-				if (isset($txt['setting_' . $config_var[1]]))
927
-					$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
928
-				elseif (isset($txt['groups_' . $config_var[1]]))
929
-					$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
957
+				if (isset($txt['setting_' . $config_var[1]])) {
958
+									$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
959
+				} elseif (isset($txt['groups_' . $config_var[1]])) {
960
+									$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
961
+				}
930 962
 			}
931 963
 
932 964
 			// Set the subtext in case it's part of the label.
@@ -959,8 +991,9 @@  discard block
 block discarded – undo
959 991
 		// What are the options, eh?
960 992
 		$temp = parse_bbc(false);
961 993
 		$bbcTags = array();
962
-		foreach ($temp as $tag)
963
-			$bbcTags[] = $tag['tag'];
994
+		foreach ($temp as $tag) {
995
+					$bbcTags[] = $tag['tag'];
996
+		}
964 997
 
965 998
 		$bbcTags = array_unique($bbcTags);
966 999
 		$totalTags = count($bbcTags);
@@ -975,8 +1008,9 @@  discard block
 block discarded – undo
975 1008
 		$col = 0; $i = 0;
976 1009
 		foreach ($bbcTags as $tag)
977 1010
 		{
978
-			if ($i % $tagsPerColumn == 0 && $i != 0)
979
-				$col++;
1011
+			if ($i % $tagsPerColumn == 0 && $i != 0) {
1012
+							$col++;
1013
+			}
980 1014
 
981 1015
 			$context['bbc_columns'][$col][] = array(
982 1016
 				'tag' => $tag,
@@ -1019,18 +1053,21 @@  discard block
 block discarded – undo
1019 1053
 	validateToken('admin-ssc');
1020 1054
 
1021 1055
 	// Fix the darn stupid cookiename! (more may not be allowed, but these for sure!)
1022
-	if (isset($_POST['cookiename']))
1023
-		$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1056
+	if (isset($_POST['cookiename'])) {
1057
+			$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1058
+	}
1024 1059
 
1025 1060
 	// Fix the forum's URL if necessary.
1026 1061
 	if (isset($_POST['boardurl']))
1027 1062
 	{
1028
-		if (substr($_POST['boardurl'], -10) == '/index.php')
1029
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1030
-		elseif (substr($_POST['boardurl'], -1) == '/')
1031
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1032
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
1033
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1063
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1064
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1065
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1066
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1067
+		}
1068
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1069
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1070
+		}
1034 1071
 	}
1035 1072
 
1036 1073
 	// Any passwords?
@@ -1065,21 +1102,21 @@  discard block
 block discarded – undo
1065 1102
 	// Figure out which config vars we're saving here...
1066 1103
 	foreach ($config_vars as $var)
1067 1104
 	{
1068
-		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]])))
1069
-			continue;
1105
+		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) {
1106
+					continue;
1107
+		}
1070 1108
 
1071 1109
 		$config_var = $var[0];
1072 1110
 
1073 1111
 		if (in_array($config_var, $config_passwords))
1074 1112
 		{
1075
-			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1])
1076
-				$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1077
-		}
1078
-		elseif (in_array($config_var, $config_strs))
1113
+			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) {
1114
+							$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1115
+			}
1116
+		} elseif (in_array($config_var, $config_strs))
1079 1117
 		{
1080 1118
 			$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var], '\'\\') . '\'';
1081
-		}
1082
-		elseif (in_array($config_var, $config_ints))
1119
+		} elseif (in_array($config_var, $config_ints))
1083 1120
 		{
1084 1121
 			$new_settings[$config_var] = (int) $_POST[$config_var];
1085 1122
 
@@ -1088,17 +1125,17 @@  discard block
 block discarded – undo
1088 1125
 			$new_settings[$config_var] = max($min, $new_settings[$config_var]);
1089 1126
 
1090 1127
 			// Is there a max value for this as well?
1091
-			if (isset($var['max']))
1092
-				$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1093
-		}
1094
-		elseif (in_array($config_var, $config_bools))
1128
+			if (isset($var['max'])) {
1129
+							$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1130
+			}
1131
+		} elseif (in_array($config_var, $config_bools))
1095 1132
 		{
1096
-			if (!empty($_POST[$config_var]))
1097
-				$new_settings[$config_var] = '1';
1098
-			else
1099
-				$new_settings[$config_var] = '0';
1100
-		}
1101
-		else
1133
+			if (!empty($_POST[$config_var])) {
1134
+							$new_settings[$config_var] = '1';
1135
+			} else {
1136
+							$new_settings[$config_var] = '0';
1137
+			}
1138
+		} else
1102 1139
 		{
1103 1140
 			// This shouldn't happen, but it might...
1104 1141
 			fatal_error('Unknown config_var \'' . $config_var . '\'');
@@ -1114,30 +1151,35 @@  discard block
 block discarded – undo
1114 1151
 	foreach ($config_vars as $config_var)
1115 1152
 	{
1116 1153
 		// We just saved the file-based settings, so skip their definitions.
1117
-		if (!is_array($config_var) || $config_var[2] == 'file')
1118
-			continue;
1154
+		if (!is_array($config_var) || $config_var[2] == 'file') {
1155
+					continue;
1156
+		}
1119 1157
 
1120 1158
 		$new_setting = array($config_var[3], $config_var[0]);
1121 1159
 
1122 1160
 		// Select options need carried over, too.
1123
-		if (isset($config_var[4]))
1124
-			$new_setting[] = $config_var[4];
1161
+		if (isset($config_var[4])) {
1162
+					$new_setting[] = $config_var[4];
1163
+		}
1125 1164
 
1126 1165
 		// Include min and max if necessary
1127
-		if (isset($config_var['min']))
1128
-			$new_setting['min'] = $config_var['min'];
1166
+		if (isset($config_var['min'])) {
1167
+					$new_setting['min'] = $config_var['min'];
1168
+		}
1129 1169
 
1130
-		if (isset($config_var['max']))
1131
-			$new_setting['max'] = $config_var['max'];
1170
+		if (isset($config_var['max'])) {
1171
+					$new_setting['max'] = $config_var['max'];
1172
+		}
1132 1173
 
1133 1174
 		// Rewrite the definition a bit.
1134 1175
 		$new_settings[] = $new_setting;
1135 1176
 	}
1136 1177
 
1137 1178
 	// Save the new database-based settings, if any.
1138
-	if (!empty($new_settings))
1139
-		saveDBSettings($new_settings);
1140
-}
1179
+	if (!empty($new_settings)) {
1180
+			saveDBSettings($new_settings);
1181
+	}
1182
+	}
1141 1183
 
1142 1184
 /**
1143 1185
  * Helper function for saving database settings.
@@ -1155,22 +1197,25 @@  discard block
 block discarded – undo
1155 1197
 	$inlinePermissions = array();
1156 1198
 	foreach ($config_vars as $var)
1157 1199
 	{
1158
-		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags']))))
1159
-			continue;
1200
+		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) {
1201
+					continue;
1202
+		}
1160 1203
 
1161 1204
 		// Checkboxes!
1162
-		elseif ($var[0] == 'check')
1163
-			$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1205
+		elseif ($var[0] == 'check') {
1206
+					$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1207
+		}
1164 1208
 		// Select boxes!
1165
-		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2])))
1166
-			$setArray[$var[1]] = $_POST[$var[1]];
1167
-		elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1209
+		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) {
1210
+					$setArray[$var[1]] = $_POST[$var[1]];
1211
+		} elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1168 1212
 		{
1169 1213
 			// For security purposes we validate this line by line.
1170 1214
 			$lOptions = array();
1171
-			foreach ($_POST[$var[1]] as $invar)
1172
-				if (in_array($invar, array_keys($var[2])))
1215
+			foreach ($_POST[$var[1]] as $invar) {
1216
+							if (in_array($invar, array_keys($var[2])))
1173 1217
 					$lOptions[] = $invar;
1218
+			}
1174 1219
 
1175 1220
 			$setArray[$var[1]] = json_encode($lOptions);
1176 1221
 		}
@@ -1184,18 +1229,20 @@  discard block
 block discarded – undo
1184 1229
 				$request = $smcFunc['db_query']('', '
1185 1230
 					SELECT id_board
1186 1231
 					FROM {db_prefix}boards');
1187
-				while ($row = $smcFunc['db_fetch_row']($request))
1188
-					$board_list[$row[0]] = true;
1232
+				while ($row = $smcFunc['db_fetch_row']($request)) {
1233
+									$board_list[$row[0]] = true;
1234
+				}
1189 1235
 
1190 1236
 				$smcFunc['db_free_result']($request);
1191 1237
 			}
1192 1238
 
1193 1239
 			$lOptions = array();
1194 1240
 
1195
-			if (!empty($_POST[$var[1]]))
1196
-				foreach ($_POST[$var[1]] as $invar => $dummy)
1241
+			if (!empty($_POST[$var[1]])) {
1242
+							foreach ($_POST[$var[1]] as $invar => $dummy)
1197 1243
 					if (isset($board_list[$invar]))
1198 1244
 						$lOptions[] = $invar;
1245
+			}
1199 1246
 
1200 1247
 			$setArray[$var[1]] = !empty($lOptions) ? implode(',', $lOptions) : '';
1201 1248
 		}
@@ -1209,8 +1256,9 @@  discard block
 block discarded – undo
1209 1256
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1210 1257
 
1211 1258
 			// Do we have a max value for this as well?
1212
-			if (isset($var['max']))
1213
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1259
+			if (isset($var['max'])) {
1260
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1261
+			}
1214 1262
 		}
1215 1263
 		// Floating point!
1216 1264
 		elseif ($var[0] == 'float')
@@ -1222,40 +1270,47 @@  discard block
 block discarded – undo
1222 1270
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1223 1271
 
1224 1272
 			// Do we have a max value for this as well?
1225
-			if (isset($var['max']))
1226
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1273
+			if (isset($var['max'])) {
1274
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1275
+			}
1227 1276
 		}
1228 1277
 		// Text!
1229
-		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time')))
1230
-			$setArray[$var[1]] = $_POST[$var[1]];
1278
+		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) {
1279
+					$setArray[$var[1]] = $_POST[$var[1]];
1280
+		}
1231 1281
 		// Passwords!
1232 1282
 		elseif ($var[0] == 'password')
1233 1283
 		{
1234
-			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1])
1235
-				$setArray[$var[1]] = $_POST[$var[1]][0];
1284
+			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) {
1285
+							$setArray[$var[1]] = $_POST[$var[1]][0];
1286
+			}
1236 1287
 		}
1237 1288
 		// BBC.
1238 1289
 		elseif ($var[0] == 'bbc')
1239 1290
 		{
1240 1291
 
1241 1292
 			$bbcTags = array();
1242
-			foreach (parse_bbc(false) as $tag)
1243
-				$bbcTags[] = $tag['tag'];
1293
+			foreach (parse_bbc(false) as $tag) {
1294
+							$bbcTags[] = $tag['tag'];
1295
+			}
1244 1296
 
1245
-			if (!isset($_POST[$var[1] . '_enabledTags']))
1246
-				$_POST[$var[1] . '_enabledTags'] = array();
1247
-			elseif (!is_array($_POST[$var[1] . '_enabledTags']))
1248
-				$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1297
+			if (!isset($_POST[$var[1] . '_enabledTags'])) {
1298
+							$_POST[$var[1] . '_enabledTags'] = array();
1299
+			} elseif (!is_array($_POST[$var[1] . '_enabledTags'])) {
1300
+							$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1301
+			}
1249 1302
 
1250 1303
 			$setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags']));
1251 1304
 		}
1252 1305
 		// Permissions?
1253
-		elseif ($var[0] == 'permissions')
1254
-			$inlinePermissions[] = $var[1];
1306
+		elseif ($var[0] == 'permissions') {
1307
+					$inlinePermissions[] = $var[1];
1308
+		}
1255 1309
 	}
1256 1310
 
1257
-	if (!empty($setArray))
1258
-		updateSettings($setArray);
1311
+	if (!empty($setArray)) {
1312
+			updateSettings($setArray);
1313
+	}
1259 1314
 
1260 1315
 	// If we have inline permissions we need to save them.
1261 1316
 	if (!empty($inlinePermissions) && allowedTo('manage_permissions'))
@@ -1292,18 +1347,21 @@  discard block
 block discarded – undo
1292 1347
 	// put all of it into an array
1293 1348
 	foreach ($info_lines as $line)
1294 1349
 	{
1295
-		if (preg_match('~(' . $remove . ')~', $line))
1296
-			continue;
1350
+		if (preg_match('~(' . $remove . ')~', $line)) {
1351
+					continue;
1352
+		}
1297 1353
 
1298 1354
 		// new category?
1299
-		if (strpos($line, '<h2>') !== false)
1300
-			$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1355
+		if (strpos($line, '<h2>') !== false) {
1356
+					$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1357
+		}
1301 1358
 
1302 1359
 		// load it as setting => value or the old setting local master
1303
-		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1304
-			$pinfo[$category][$val[1]] = $val[2];
1305
-		elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1306
-			$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1360
+		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1361
+					$pinfo[$category][$val[1]] = $val[2];
1362
+		} elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1363
+					$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1364
+		}
1307 1365
 	}
1308 1366
 
1309 1367
 	// load it in to context and display it
@@ -1338,8 +1396,9 @@  discard block
 block discarded – undo
1338 1396
 				$testAPI = new $cache_class_name();
1339 1397
 
1340 1398
 				// No Support?  NEXT!
1341
-				if (!$testAPI->isSupported(true))
1342
-					continue;
1399
+				if (!$testAPI->isSupported(true)) {
1400
+									continue;
1401
+				}
1343 1402
 
1344 1403
 				$apis[$tryCache] = isset($txt[$tryCache . '_cache']) ? $txt[$tryCache . '_cache'] : $tryCache;
1345 1404
 			}
@@ -1364,8 +1423,9 @@  discard block
 block discarded – undo
1364 1423
 	global $modSettings, $boardurl, $smcFunc;
1365 1424
 
1366 1425
 	// Already have a key?  Can't register again.
1367
-	if (!empty($modSettings['sm_stats_key']))
1368
-		return true;
1426
+	if (!empty($modSettings['sm_stats_key'])) {
1427
+			return true;
1428
+	}
1369 1429
 
1370 1430
 	$fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr);
1371 1431
 	if ($fp)
@@ -1376,8 +1436,9 @@  discard block
 block discarded – undo
1376 1436
 		fwrite($fp, $out);
1377 1437
 
1378 1438
 		$return_data = '';
1379
-		while (!feof($fp))
1380
-			$return_data .= fgets($fp, 128);
1439
+		while (!feof($fp)) {
1440
+					$return_data .= fgets($fp, 128);
1441
+		}
1381 1442
 
1382 1443
 		fclose($fp);
1383 1444
 
Please login to merge, or discard this patch.
Sources/Profile-Actions.php 1 patch
Braces   +117 added lines, -86 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Activate an account.
@@ -48,8 +49,9 @@  discard block
 block discarded – undo
48 49
 		logAction('approve_member', array('member' => $memID), 'admin');
49 50
 
50 51
 		// If we are doing approval, update the stats for the member just in case.
51
-		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15)))
52
-			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
52
+		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15))) {
53
+					updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
54
+		}
53 55
 
54 56
 		// Make sure we update the stats too.
55 57
 		updateStats('member', false);
@@ -76,8 +78,9 @@  discard block
 block discarded – undo
76 78
 	$issueErrors = array();
77 79
 
78 80
 	// Doesn't hurt to be overly cautious.
79
-	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning'))
80
-		fatal_lang_error('no_access', false);
81
+	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning')) {
82
+			fatal_lang_error('no_access', false);
83
+	}
81 84
 
82 85
 	// Get the base (errors related) stuff done.
83 86
 	loadLanguage('Errors');
@@ -135,16 +138,18 @@  discard block
 block discarded – undo
135 138
 
136 139
 		// This cannot be empty!
137 140
 		$_POST['warn_reason'] = isset($_POST['warn_reason']) ? trim($_POST['warn_reason']) : '';
138
-		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner'])
139
-			$issueErrors[] = 'warning_no_reason';
141
+		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner']) {
142
+					$issueErrors[] = 'warning_no_reason';
143
+		}
140 144
 		$_POST['warn_reason'] = $smcFunc['htmlspecialchars']($_POST['warn_reason']);
141 145
 
142 146
 		$_POST['warning_level'] = (int) $_POST['warning_level'];
143 147
 		$_POST['warning_level'] = max(0, min(100, $_POST['warning_level']));
144
-		if ($_POST['warning_level'] < $context['min_allowed'])
145
-			$_POST['warning_level'] = $context['min_allowed'];
146
-		elseif ($_POST['warning_level'] > $context['max_allowed'])
147
-			$_POST['warning_level'] = $context['max_allowed'];
148
+		if ($_POST['warning_level'] < $context['min_allowed']) {
149
+					$_POST['warning_level'] = $context['min_allowed'];
150
+		} elseif ($_POST['warning_level'] > $context['max_allowed']) {
151
+					$_POST['warning_level'] = $context['max_allowed'];
152
+		}
148 153
 
149 154
 		// Do we actually have to issue them with a PM?
150 155
 		$id_notice = 0;
@@ -152,8 +157,9 @@  discard block
 block discarded – undo
152 157
 		{
153 158
 			$_POST['warn_sub'] = trim($_POST['warn_sub']);
154 159
 			$_POST['warn_body'] = trim($_POST['warn_body']);
155
-			if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
156
-				$issueErrors[] = 'warning_notify_blank';
160
+			if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
161
+							$issueErrors[] = 'warning_notify_blank';
162
+			}
157 163
 			// Send the PM?
158 164
 			else
159 165
 			{
@@ -190,8 +196,8 @@  discard block
 block discarded – undo
190 196
 		if (empty($issueErrors))
191 197
 		{
192 198
 			// Log what we've done!
193
-			if (!$context['user']['is_owner'])
194
-				$smcFunc['db_insert']('',
199
+			if (!$context['user']['is_owner']) {
200
+							$smcFunc['db_insert']('',
195 201
 					'{db_prefix}log_comments',
196 202
 					array(
197 203
 						'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int', 'recipient_name' => 'string-255',
@@ -203,14 +209,14 @@  discard block
 block discarded – undo
203 209
 					),
204 210
 					array('id_comment')
205 211
 				);
212
+			}
206 213
 
207 214
 			// Make the change.
208 215
 			updateMemberData($memID, array('warning' => $_POST['warning_level']));
209 216
 
210 217
 			// Leave a lovely message.
211 218
 			$context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : $txt['profile_warning_success'];
212
-		}
213
-		else
219
+		} else
214 220
 		{
215 221
 			// Try to remember some bits.
216 222
 			$context['warning_data'] = array(
@@ -229,8 +235,9 @@  discard block
 block discarded – undo
229 235
 	{
230 236
 		$warning_body = !empty($_POST['warn_body']) ? trim(censorText($_POST['warn_body'])) : '';
231 237
 		$context['preview_subject'] = !empty($_POST['warn_sub']) ? trim($smcFunc['htmlspecialchars']($_POST['warn_sub'])) : '';
232
-		if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
233
-			$issueErrors[] = 'warning_notify_blank';
238
+		if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
239
+					$issueErrors[] = 'warning_notify_blank';
240
+		}
234 241
 
235 242
 		if (!empty($_POST['warn_body']))
236 243
 		{
@@ -254,8 +261,9 @@  discard block
 block discarded – undo
254 261
 	{
255 262
 		// Fill in the suite of errors.
256 263
 		$context['post_errors'] = array();
257
-		foreach ($issueErrors as $error)
258
-			$context['post_errors'][] = $txt[$error];
264
+		foreach ($issueErrors as $error) {
265
+					$context['post_errors'][] = $txt[$error];
266
+		}
259 267
 	}
260 268
 
261 269
 
@@ -272,9 +280,10 @@  discard block
 block discarded – undo
272 280
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_mute'],
273 281
 	);
274 282
 	$context['current_level'] = 0;
275
-	foreach ($context['level_effects'] as $limit => $dummy)
276
-		if ($context['member']['warning'] >= $limit)
283
+	foreach ($context['level_effects'] as $limit => $dummy) {
284
+			if ($context['member']['warning'] >= $limit)
277 285
 			$context['current_level'] = $limit;
286
+	}
278 287
 
279 288
 	$listOptions = array(
280 289
 		'id' => 'view_warnings',
@@ -337,11 +346,12 @@  discard block
 block discarded – undo
337 346
 							' . $warning['reason'] . '
338 347
 						</div>';
339 348
 
340
-						if (!empty($warning['id_notice']))
341
-							$ret .= '
349
+						if (!empty($warning['id_notice'])) {
350
+													$ret .= '
342 351
 						<div class="floatright">
343 352
 							<a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $warning['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" class="new_win" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a>
344 353
 						</div>';
354
+						}
345 355
 
346 356
 						return $ret;
347 357
 					},
@@ -413,8 +423,9 @@  discard block
 block discarded – undo
413 423
 	while ($row = $smcFunc['db_fetch_assoc']($request))
414 424
 	{
415 425
 		// If we're not warning for a message skip any that are.
416
-		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false)
417
-			continue;
426
+		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false) {
427
+					continue;
428
+		}
418 429
 
419 430
 		$context['notification_templates'][] = array(
420 431
 			'title' => $row['template_title'],
@@ -424,16 +435,18 @@  discard block
 block discarded – undo
424 435
 	$smcFunc['db_free_result']($request);
425 436
 
426 437
 	// Setup the "default" templates.
427
-	foreach (array('spamming', 'offence', 'insulting') as $type)
428
-		$context['notification_templates'][] = array(
438
+	foreach (array('spamming', 'offence', 'insulting') as $type) {
439
+			$context['notification_templates'][] = array(
429 440
 			'title' => $txt['profile_warning_notify_title_' . $type],
430 441
 			'body' => sprintf($txt['profile_warning_notify_template_outline' . (!empty($context['warning_for_message']) ? '_post' : '')], $txt['profile_warning_notify_for_' . $type]),
431 442
 		);
443
+	}
432 444
 
433 445
 	// Replace all the common variables in the templates.
434
-	foreach ($context['notification_templates'] as $k => $name)
435
-		$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
436
-}
446
+	foreach ($context['notification_templates'] as $k => $name) {
447
+			$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
448
+	}
449
+	}
437 450
 
438 451
 /**
439 452
  * Get the number of warnings a user has. Callback for $listOptions['get_count'] in issueWarning()
@@ -517,10 +530,11 @@  discard block
 block discarded – undo
517 530
 {
518 531
 	global $txt, $context, $modSettings, $cur_profile;
519 532
 
520
-	if (!$context['user']['is_owner'])
521
-		isAllowedTo('profile_remove_any');
522
-	elseif (!allowedTo('profile_remove_any'))
523
-		isAllowedTo('profile_remove_own');
533
+	if (!$context['user']['is_owner']) {
534
+			isAllowedTo('profile_remove_any');
535
+	} elseif (!allowedTo('profile_remove_any')) {
536
+			isAllowedTo('profile_remove_own');
537
+	}
524 538
 
525 539
 	// Permissions for removing stuff...
526 540
 	$context['can_delete_posts'] = !$context['user']['is_owner'] && allowedTo('moderate_forum');
@@ -547,10 +561,11 @@  discard block
 block discarded – undo
547 561
 
548 562
 	// @todo Add a way to delete pms as well?
549 563
 
550
-	if (!$context['user']['is_owner'])
551
-		isAllowedTo('profile_remove_any');
552
-	elseif (!allowedTo('profile_remove_any'))
553
-		isAllowedTo('profile_remove_own');
564
+	if (!$context['user']['is_owner']) {
565
+			isAllowedTo('profile_remove_any');
566
+	} elseif (!allowedTo('profile_remove_any')) {
567
+			isAllowedTo('profile_remove_own');
568
+	}
554 569
 
555 570
 	checkSession();
556 571
 
@@ -576,8 +591,9 @@  discard block
 block discarded – undo
576 591
 		list ($another) = $smcFunc['db_fetch_row']($request);
577 592
 		$smcFunc['db_free_result']($request);
578 593
 
579
-		if (empty($another))
580
-			fatal_lang_error('at_least_one_admin', 'critical');
594
+		if (empty($another)) {
595
+					fatal_lang_error('at_least_one_admin', 'critical');
596
+		}
581 597
 	}
582 598
 
583 599
 	// This file is needed for the deleteMembers function.
@@ -656,8 +672,9 @@  discard block
 block discarded – undo
656 672
 					)
657 673
 				);
658 674
 				$topicIDs = array();
659
-				while ($row = $smcFunc['db_fetch_assoc']($request))
660
-					$topicIDs[] = $row['id_topic'];
675
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
676
+									$topicIDs[] = $row['id_topic'];
677
+				}
661 678
 				$smcFunc['db_free_result']($request);
662 679
 
663 680
 				// Actually remove the topics. Ignore recycling if we want to perma-delete things...
@@ -680,8 +697,9 @@  discard block
 block discarded – undo
680 697
 			// This could take a while... but ya know it's gonna be worth it in the end.
681 698
 			while ($row = $smcFunc['db_fetch_assoc']($request))
682 699
 			{
683
-				if (function_exists('apache_reset_timeout'))
684
-					@apache_reset_timeout();
700
+				if (function_exists('apache_reset_timeout')) {
701
+									@apache_reset_timeout();
702
+				}
685 703
 
686 704
 				removeMessage($row['id_msg']);
687 705
 			}
@@ -689,8 +707,9 @@  discard block
 block discarded – undo
689 707
 		}
690 708
 
691 709
 		// Only delete this poor members account if they are actually being booted out of camp.
692
-		if (isset($_POST['deleteAccount']))
693
-			deleteMembers($memID);
710
+		if (isset($_POST['deleteAccount'])) {
711
+					deleteMembers($memID);
712
+		}
694 713
 	}
695 714
 	// Do they need approval to delete?
696 715
 	elseif (!empty($modSettings['approveAccountDeletion']) && !allowedTo('moderate_forum'))
@@ -741,18 +760,18 @@  discard block
 block discarded – undo
741 760
 		{
742 761
 			foreach ($costs as $duration => $cost)
743 762
 			{
744
-				if ($cost != 0)
745
-					$cost_array[$duration] = $cost;
763
+				if ($cost != 0) {
764
+									$cost_array[$duration] = $cost;
765
+				}
746 766
 			}
747
-		}
748
-		else
767
+		} else
749 768
 		{
750 769
 			$cost_array['fixed'] = $costs['fixed'];
751 770
 		}
752 771
 
753
-		if (empty($cost_array))
754
-			unset($context['subscriptions'][$id]);
755
-		else
772
+		if (empty($cost_array)) {
773
+					unset($context['subscriptions'][$id]);
774
+		} else
756 775
 		{
757 776
 			$context['subscriptions'][$id]['member'] = 0;
758 777
 			$context['subscriptions'][$id]['subscribed'] = false;
@@ -765,13 +784,15 @@  discard block
 block discarded – undo
765 784
 	foreach ($gateways as $id => $gateway)
766 785
 	{
767 786
 		$gateways[$id] = new $gateway['display_class']();
768
-		if (!$gateways[$id]->gatewayEnabled())
769
-			unset($gateways[$id]);
787
+		if (!$gateways[$id]->gatewayEnabled()) {
788
+					unset($gateways[$id]);
789
+		}
770 790
 	}
771 791
 
772 792
 	// No gateways yet?
773
-	if (empty($gateways))
774
-		fatal_error($txt['paid_admin_not_setup_gateway']);
793
+	if (empty($gateways)) {
794
+			fatal_error($txt['paid_admin_not_setup_gateway']);
795
+	}
775 796
 
776 797
 	// Get the current subscriptions.
777 798
 	$request = $smcFunc['db_query']('', '
@@ -786,8 +807,9 @@  discard block
 block discarded – undo
786 807
 	while ($row = $smcFunc['db_fetch_assoc']($request))
787 808
 	{
788 809
 		// The subscription must exist!
789
-		if (!isset($context['subscriptions'][$row['id_subscribe']]))
790
-			continue;
810
+		if (!isset($context['subscriptions'][$row['id_subscribe']])) {
811
+					continue;
812
+		}
791 813
 
792 814
 		$context['current'][$row['id_subscribe']] = array(
793 815
 			'id' => $row['id_sublog'],
@@ -801,8 +823,9 @@  discard block
 block discarded – undo
801 823
 			'status_text' => $row['status'] == 0 ? ($row['payments_pending'] ? $txt['paid_pending'] : $txt['paid_finished']) : $txt['paid_active'],
802 824
 		);
803 825
 
804
-		if ($row['status'] == 1)
805
-			$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
826
+		if ($row['status'] == 1) {
827
+					$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
828
+		}
806 829
 	}
807 830
 	$smcFunc['db_free_result']($request);
808 831
 
@@ -853,21 +876,25 @@  discard block
 block discarded – undo
853 876
 	if (isset($_GET['confirm']) && isset($_POST['sub_id']) && is_array($_POST['sub_id']))
854 877
 	{
855 878
 		// Hopefully just one.
856
-		foreach ($_POST['sub_id'] as $k => $v)
857
-			$ID_SUB = (int) $k;
879
+		foreach ($_POST['sub_id'] as $k => $v) {
880
+					$ID_SUB = (int) $k;
881
+		}
858 882
 
859
-		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0)
860
-			fatal_lang_error('paid_sub_not_active');
883
+		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0) {
884
+					fatal_lang_error('paid_sub_not_active');
885
+		}
861 886
 
862 887
 		// Simplify...
863 888
 		$context['sub'] = $context['subscriptions'][$ID_SUB];
864 889
 		$period = 'xx';
865
-		if ($context['sub']['flexible'])
866
-			$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
890
+		if ($context['sub']['flexible']) {
891
+					$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
892
+		}
867 893
 
868 894
 		// Check we have a valid cost.
869
-		if ($context['sub']['flexible'] && $period == 'xx')
870
-			fatal_lang_error('paid_sub_not_active');
895
+		if ($context['sub']['flexible'] && $period == 'xx') {
896
+					fatal_lang_error('paid_sub_not_active');
897
+		}
871 898
 
872 899
 		// Sort out the cost/currency.
873 900
 		$context['currency'] = $modSettings['paid_currency_code'];
@@ -880,8 +907,7 @@  discard block
 block discarded – undo
880 907
 			$context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']) . '/' . $txt[$_POST['cur'][$ID_SUB]];
881 908
 			// The period value for paypal.
882 909
 			$context['paypal_period'] = strtoupper(substr($_POST['cur'][$ID_SUB], 0, 1));
883
-		}
884
-		else
910
+		} else
885 911
 		{
886 912
 			// Real cost...
887 913
 			$context['value'] = $context['sub']['costs']['fixed'];
@@ -898,13 +924,15 @@  discard block
 block discarded – undo
898 924
 		foreach ($gateways as $id => $gateway)
899 925
 		{
900 926
 			$fields = $gateways[$id]->fetchGatewayFields($context['sub']['id'] . '+' . $memID, $context['sub'], $context['value'], $period, $scripturl . '?action=profile;u=' . $memID . ';area=subscriptions;sub_id=' . $context['sub']['id'] . ';done');
901
-			if (!empty($fields['form']))
902
-				$context['gateways'][] = $fields;
927
+			if (!empty($fields['form'])) {
928
+							$context['gateways'][] = $fields;
929
+			}
903 930
 		}
904 931
 
905 932
 		// Bugger?!
906
-		if (empty($context['gateways']))
907
-			fatal_error($txt['paid_admin_not_setup_gateway']);
933
+		if (empty($context['gateways'])) {
934
+					fatal_error($txt['paid_admin_not_setup_gateway']);
935
+		}
908 936
 
909 937
 		// Now we are going to assume they want to take this out ;)
910 938
 		$new_data = array($context['sub']['id'], $context['value'], $period, 'prepay');
@@ -912,16 +940,19 @@  discard block
 block discarded – undo
912 940
 		{
913 941
 			// What are the details like?
914 942
 			$current_pending = array();
915
-			if ($context['current'][$context['sub']['id']]['pending_details'] != '')
916
-				$current_pending = smf_json_decode($context['current'][$context['sub']['id']]['pending_details'], true);
943
+			if ($context['current'][$context['sub']['id']]['pending_details'] != '') {
944
+							$current_pending = smf_json_decode($context['current'][$context['sub']['id']]['pending_details'], true);
945
+			}
917 946
 			// Don't get silly.
918
-			if (count($current_pending) > 9)
919
-				$current_pending = array();
947
+			if (count($current_pending) > 9) {
948
+							$current_pending = array();
949
+			}
920 950
 			$pending_count = 0;
921 951
 			// Only record real pending payments as will otherwise confuse the admin!
922
-			foreach ($current_pending as $pending)
923
-				if ($pending[3] == 'payback')
952
+			foreach ($current_pending as $pending) {
953
+							if ($pending[3] == 'payback')
924 954
 					$pending_count++;
955
+			}
925 956
 
926 957
 			if (!in_array($new_data, $current_pending))
927 958
 			{
@@ -966,9 +997,9 @@  discard block
 block discarded – undo
966 997
 
967 998
 		// Quit.
968 999
 		return;
1000
+	} else {
1001
+			$context['sub_template'] = 'user_subscription';
1002
+	}
969 1003
 	}
970
-	else
971
-		$context['sub_template'] = 'user_subscription';
972
-}
973 1004
 
974 1005
 ?>
975 1006
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/ManageBans.php 1 patch
Braces   +258 added lines, -207 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ban center. The main entrance point for all ban center functions.
@@ -120,10 +121,11 @@  discard block
 block discarded – undo
120 121
 	}
121 122
 
122 123
 	// Create a date string so we don't overload them with date info.
123
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
124
-		$context['ban_time_format'] = $user_info['time_format'];
125
-	else
126
-		$context['ban_time_format'] = $matches[0];
124
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
125
+			$context['ban_time_format'] = $user_info['time_format'];
126
+	} else {
127
+			$context['ban_time_format'] = $matches[0];
128
+	}
127 129
 
128 130
 	$listOptions = array(
129 131
 		'id' => 'ban_list',
@@ -201,16 +203,19 @@  discard block
 block discarded – undo
201 203
 					'function' => function($rowData) use ($txt)
202 204
 					{
203 205
 						// This ban never expires...whahaha.
204
-						if ($rowData['expire_time'] === null)
205
-							return $txt['never'];
206
+						if ($rowData['expire_time'] === null) {
207
+													return $txt['never'];
208
+						}
206 209
 
207 210
 						// This ban has already expired.
208
-						elseif ($rowData['expire_time'] < time())
209
-							return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']);
211
+						elseif ($rowData['expire_time'] < time()) {
212
+													return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']);
213
+						}
210 214
 
211 215
 						// Still need to wait a few days for this ban to expire.
212
-						else
213
-							return sprintf('%1$d&nbsp;%2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']);
216
+						else {
217
+													return sprintf('%1$d&nbsp;%2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']);
218
+						}
214 219
 					},
215 220
 				),
216 221
 				'sort' => array(
@@ -309,8 +314,9 @@  discard block
 block discarded – undo
309 314
 		)
310 315
 	);
311 316
 	$bans = array();
312
-	while ($row = $smcFunc['db_fetch_assoc']($request))
313
-		$bans[] = $row;
317
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
318
+			$bans[] = $row;
319
+	}
314 320
 
315 321
 	$smcFunc['db_free_result']($request);
316 322
 
@@ -352,8 +358,9 @@  discard block
 block discarded – undo
352 358
 {
353 359
 	global $txt, $modSettings, $context, $scripturl, $smcFunc, $sourcedir;
354 360
 
355
-	if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors']))
356
-		BanEdit2();
361
+	if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors'])) {
362
+			BanEdit2();
363
+	}
357 364
 
358 365
 	$ban_group_id = isset($context['ban']['id']) ? $context['ban']['id'] : (isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0);
359 366
 
@@ -364,10 +371,10 @@  discard block
 block discarded – undo
364 371
 
365 372
 	if (!empty($context['ban_errors']))
366 373
 	{
367
-		foreach ($context['ban_errors'] as $error)
368
-			$context['error_messages'][$error] = $txt[$error];
369
-	}
370
-	else
374
+		foreach ($context['ban_errors'] as $error) {
375
+					$context['error_messages'][$error] = $txt[$error];
376
+		}
377
+	} else
371 378
 	{
372 379
 		// If we're editing an existing ban, get it from the database.
373 380
 		if (!empty($ban_group_id))
@@ -403,12 +410,13 @@  discard block
 block discarded – undo
403 410
 						'data' => array(
404 411
 							'function' => function($ban_item) use ($txt)
405 412
 							{
406
-								if (in_array($ban_item['type'], array('ip', 'hostname', 'email')))
407
-									return '<strong>' . $txt[$ban_item['type']] . ':</strong>&nbsp;' . $ban_item[$ban_item['type']];
408
-								elseif ($ban_item['type'] == 'user')
409
-									return '<strong>' . $txt['username'] . ':</strong>&nbsp;' . $ban_item['user']['link'];
410
-								else
411
-									return '<strong>' . $txt['unknown'] . ':</strong>&nbsp;' . $ban_item['no_bantype_selected'];
413
+								if (in_array($ban_item['type'], array('ip', 'hostname', 'email'))) {
414
+																	return '<strong>' . $txt[$ban_item['type']] . ':</strong>&nbsp;' . $ban_item[$ban_item['type']];
415
+								} elseif ($ban_item['type'] == 'user') {
416
+																	return '<strong>' . $txt['username'] . ':</strong>&nbsp;' . $ban_item['user']['link'];
417
+								} else {
418
+																	return '<strong>' . $txt['unknown'] . ':</strong>&nbsp;' . $ban_item['no_bantype_selected'];
419
+								}
412 420
 							},
413 421
 							'style' => 'text-align: left;',
414 422
 						),
@@ -546,8 +554,9 @@  discard block
 block discarded – undo
546 554
 					$context['ban']['from_user'] = true;
547 555
 
548 556
 					// Would be nice if we could also ban the hostname.
549
-					if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup']))
550
-						$context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
557
+					if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup'])) {
558
+											$context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
559
+					}
551 560
 
552 561
 					$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
553 562
 				}
@@ -615,8 +624,9 @@  discard block
 block discarded – undo
615 624
 			'items_per_page' => $items_per_page,
616 625
 		)
617 626
 	);
618
-	if ($smcFunc['db_num_rows']($request) == 0)
619
-		fatal_lang_error('ban_not_found', false);
627
+	if ($smcFunc['db_num_rows']($request) == 0) {
628
+			fatal_lang_error('ban_not_found', false);
629
+	}
620 630
 
621 631
 	while ($row = $smcFunc['db_fetch_assoc']($request))
622 632
 	{
@@ -653,18 +663,15 @@  discard block
 block discarded – undo
653 663
 			{
654 664
 				$ban_items[$row['id_ban']]['type'] = 'ip';
655 665
 				$ban_items[$row['id_ban']]['ip'] = range2ip($row['ip_low'], $row['ip_high']);
656
-			}
657
-			elseif (!empty($row['hostname']))
666
+			} elseif (!empty($row['hostname']))
658 667
 			{
659 668
 				$ban_items[$row['id_ban']]['type'] = 'hostname';
660 669
 				$ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']);
661
-			}
662
-			elseif (!empty($row['email_address']))
670
+			} elseif (!empty($row['email_address']))
663 671
 			{
664 672
 				$ban_items[$row['id_ban']]['type'] = 'email';
665 673
 				$ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']);
666
-			}
667
-			elseif (!empty($row['id_member']))
674
+			} elseif (!empty($row['id_member']))
668 675
 			{
669 676
 				$ban_items[$row['id_ban']]['type'] = 'user';
670 677
 				$ban_items[$row['id_ban']]['user'] = array(
@@ -730,9 +737,10 @@  discard block
 block discarded – undo
730 737
 	$search_list += array('ips_in_messages' => 'banLoadAdditionalIPsMember', 'ips_in_errors' => 'banLoadAdditionalIPsError');
731 738
 
732 739
 	$return = array();
733
-	foreach ($search_list as $key => $callable)
734
-		if (is_callable($callable))
740
+	foreach ($search_list as $key => $callable) {
741
+			if (is_callable($callable))
735 742
 			$return[$key] = call_user_func($callable, $member_id);
743
+	}
736 744
 
737 745
 	return $return;
738 746
 }
@@ -757,8 +765,9 @@  discard block
 block discarded – undo
757 765
 			'current_user' => $member_id,
758 766
 		)
759 767
 	);
760
-	while ($row = $smcFunc['db_fetch_assoc']($request))
761
-		$message_ips[] = inet_dtop($row['poster_ip']);
768
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
769
+			$message_ips[] = inet_dtop($row['poster_ip']);
770
+	}
762 771
 	$smcFunc['db_free_result']($request);
763 772
 
764 773
 	return $message_ips;
@@ -783,8 +792,9 @@  discard block
 block discarded – undo
783 792
 			'current_user' => $member_id,
784 793
 		)
785 794
 	);
786
-	while ($row = $smcFunc['db_fetch_assoc']($request))
787
-	    $error_ips[] = inet_dtop($row['ip']);
795
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
796
+		    $error_ips[] = inet_dtop($row['ip']);
797
+	}
788 798
 	$smcFunc['db_free_result']($request);
789 799
 
790 800
 	return $error_ips;
@@ -825,11 +835,13 @@  discard block
 block discarded – undo
825 835
 		$ban_info['cannot']['login'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_login']) ? 0 : 1;
826 836
 
827 837
 		// Adding a new ban group
828
-		if (empty($_REQUEST['bg']))
829
-			$ban_group_id = insertBanGroup($ban_info);
838
+		if (empty($_REQUEST['bg'])) {
839
+					$ban_group_id = insertBanGroup($ban_info);
840
+		}
830 841
 		// Editing an existing ban group
831
-		else
832
-			$ban_group_id = updateBanGroup($ban_info);
842
+		else {
843
+					$ban_group_id = updateBanGroup($ban_info);
844
+		}
833 845
 
834 846
 		if (is_numeric($ban_group_id))
835 847
 		{
@@ -840,9 +852,10 @@  discard block
 block discarded – undo
840 852
 		$context['ban'] = $ban_info;
841 853
 	}
842 854
 
843
-	if (isset($_POST['ban_suggestions']))
844
-		// @TODO: is $_REQUEST['bi'] ever set?
855
+	if (isset($_POST['ban_suggestions'])) {
856
+			// @TODO: is $_REQUEST['bi'] ever set?
845 857
 		$saved_triggers = saveTriggers($_POST['ban_suggestions'], $ban_info['id'], isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0, isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0);
858
+	}
846 859
 
847 860
 	// Something went wrong somewhere... Oh well, let's go back.
848 861
 	if (!empty($context['ban_errors']))
@@ -852,8 +865,9 @@  discard block
 block discarded – undo
852 865
 		$context['ban_suggestions'] = array_merge($context['ban_suggestions'], getMemberData((int) $_REQUEST['u']));
853 866
 
854 867
 		// Not strictly necessary, but it's nice
855
-		if (!empty($context['ban_suggestions']['member']['id']))
856
-			$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
868
+		if (!empty($context['ban_suggestions']['member']['id'])) {
869
+					$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
870
+		}
857 871
 		return BanEdit();
858 872
 	}
859 873
 	$context['ban_suggestions']['saved_triggers'] = !empty($saved_triggers) ? $saved_triggers : array();
@@ -900,10 +914,11 @@  discard block
 block discarded – undo
900 914
 
901 915
 	foreach ($suggestions as $key => $value)
902 916
 	{
903
-		if (is_array($value))
904
-			$triggers[$key] = $value;
905
-		else
906
-			$triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : '';
917
+		if (is_array($value)) {
918
+					$triggers[$key] = $value;
919
+		} else {
920
+					$triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : '';
921
+		}
907 922
 	}
908 923
 
909 924
 	$ban_triggers = validateTriggers($triggers);
@@ -911,16 +926,18 @@  discard block
 block discarded – undo
911 926
 	// Time to save!
912 927
 	if (!empty($ban_triggers['ban_triggers']) && empty($context['ban_errors']))
913 928
 	{
914
-		if (empty($ban_id))
915
-			addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']);
916
-		else
917
-			updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']);
929
+		if (empty($ban_id)) {
930
+					addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']);
931
+		} else {
932
+					updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']);
933
+		}
934
+	}
935
+	if (!empty($context['ban_errors'])) {
936
+			return $triggers;
937
+	} else {
938
+			return false;
939
+	}
918 940
 	}
919
-	if (!empty($context['ban_errors']))
920
-		return $triggers;
921
-	else
922
-		return false;
923
-}
924 941
 
925 942
 /**
926 943
  * This function removes a bunch of triggers based on ids
@@ -934,14 +951,17 @@  discard block
 block discarded – undo
934 951
 {
935 952
 	global $smcFunc, $scripturl;
936 953
 
937
-	if ($group_id !== false)
938
-		$group_id = (int) $group_id;
954
+	if ($group_id !== false) {
955
+			$group_id = (int) $group_id;
956
+	}
939 957
 
940
-	if (empty($group_id) && empty($items_ids))
941
-		return false;
958
+	if (empty($group_id) && empty($items_ids)) {
959
+			return false;
960
+	}
942 961
 
943
-	if (!is_array($items_ids))
944
-		$items_ids = array($items_ids);
962
+	if (!is_array($items_ids)) {
963
+			$items_ids = array($items_ids);
964
+	}
945 965
 
946 966
 	$log_info = array();
947 967
 	$ban_items = array();
@@ -979,8 +999,7 @@  discard block
 block discarded – undo
979 999
 					'bantype' => ($is_range ? 'ip_range' : 'main_ip'),
980 1000
 					'value' => $ban_items[$row['id_ban']]['ip'],
981 1001
 				);
982
-			}
983
-			elseif (!empty($row['hostname']))
1002
+			} elseif (!empty($row['hostname']))
984 1003
 			{
985 1004
 				$ban_items[$row['id_ban']]['type'] = 'hostname';
986 1005
 				$ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']);
@@ -988,8 +1007,7 @@  discard block
 block discarded – undo
988 1007
 					'bantype' => 'hostname',
989 1008
 					'value' => $row['hostname'],
990 1009
 				);
991
-			}
992
-			elseif (!empty($row['email_address']))
1010
+			} elseif (!empty($row['email_address']))
993 1011
 			{
994 1012
 				$ban_items[$row['id_ban']]['type'] = 'email';
995 1013
 				$ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']);
@@ -997,8 +1015,7 @@  discard block
 block discarded – undo
997 1015
 					'bantype' => 'email',
998 1016
 					'value' => $ban_items[$row['id_ban']]['email'],
999 1017
 				);
1000
-			}
1001
-			elseif (!empty($row['id_member']))
1018
+			} elseif (!empty($row['id_member']))
1002 1019
 			{
1003 1020
 				$ban_items[$row['id_ban']]['type'] = 'user';
1004 1021
 				$ban_items[$row['id_ban']]['user'] = array(
@@ -1031,8 +1048,7 @@  discard block
 block discarded – undo
1031 1048
 				'ban_group' => $group_id,
1032 1049
 			)
1033 1050
 		);
1034
-	}
1035
-	elseif (!empty($items_ids))
1051
+	} elseif (!empty($items_ids))
1036 1052
 	{
1037 1053
 		$smcFunc['db_query']('', '
1038 1054
 			DELETE FROM {db_prefix}ban_items
@@ -1057,13 +1073,15 @@  discard block
 block discarded – undo
1057 1073
 {
1058 1074
 	global $smcFunc;
1059 1075
 
1060
-	if (!is_array($group_ids))
1061
-		$group_ids = array($group_ids);
1076
+	if (!is_array($group_ids)) {
1077
+			$group_ids = array($group_ids);
1078
+	}
1062 1079
 
1063 1080
 	$group_ids = array_unique($group_ids);
1064 1081
 
1065
-	if (empty($group_ids))
1066
-		return false;
1082
+	if (empty($group_ids)) {
1083
+			return false;
1084
+	}
1067 1085
 
1068 1086
 	$smcFunc['db_query']('', '
1069 1087
 		DELETE FROM {db_prefix}ban_groups
@@ -1087,21 +1105,23 @@  discard block
 block discarded – undo
1087 1105
 {
1088 1106
 	global $smcFunc;
1089 1107
 
1090
-	if (empty($ids))
1091
-		$smcFunc['db_query']('truncate_table', '
1108
+	if (empty($ids)) {
1109
+			$smcFunc['db_query']('truncate_table', '
1092 1110
 			TRUNCATE {db_prefix}log_banned',
1093 1111
 			array(
1094 1112
 			)
1095 1113
 		);
1096
-	else
1114
+	} else
1097 1115
 	{
1098
-		if (!is_array($ids))
1099
-			$ids = array($ids);
1116
+		if (!is_array($ids)) {
1117
+					$ids = array($ids);
1118
+		}
1100 1119
 
1101 1120
 		$ids = array_unique($ids);
1102 1121
 
1103
-		if (empty($ids))
1104
-			return false;
1122
+		if (empty($ids)) {
1123
+					return false;
1124
+		}
1105 1125
 
1106 1126
 		$smcFunc['db_query']('', '
1107 1127
 			DELETE FROM {db_prefix}log_banned
@@ -1127,8 +1147,9 @@  discard block
 block discarded – undo
1127 1147
 {
1128 1148
 	global $context, $smcFunc;
1129 1149
 
1130
-	if (empty($triggers))
1131
-		$context['ban_erros'][] = 'ban_empty_triggers';
1150
+	if (empty($triggers)) {
1151
+			$context['ban_erros'][] = 'ban_empty_triggers';
1152
+	}
1132 1153
 
1133 1154
 	$ban_triggers = array();
1134 1155
 	$log_info = array();
@@ -1137,39 +1158,39 @@  discard block
 block discarded – undo
1137 1158
 	{
1138 1159
 		if (!empty($value))
1139 1160
 		{
1140
-			if ($key == 'member')
1141
-				continue;
1161
+			if ($key == 'member') {
1162
+							continue;
1163
+			}
1142 1164
 
1143 1165
 			if ($key == 'main_ip')
1144 1166
 			{
1145 1167
 				$value = trim($value);
1146 1168
 				$ip_parts = ip2range($value);
1147
-				if (!checkExistingTriggerIP($ip_parts, $value))
1148
-					$context['ban_erros'][] = 'invalid_ip';
1149
-				else
1169
+				if (!checkExistingTriggerIP($ip_parts, $value)) {
1170
+									$context['ban_erros'][] = 'invalid_ip';
1171
+				} else
1150 1172
 				{
1151 1173
 					$ban_triggers['main_ip'] = array(
1152 1174
 						'ip_low' => $ip_parts['low'],
1153 1175
 						'ip_high' => $ip_parts['high']
1154 1176
 					);
1155 1177
 				}
1156
-			}
1157
-			elseif ($key == 'hostname')
1178
+			} elseif ($key == 'hostname')
1158 1179
 			{
1159
-				if (preg_match('/[^\w.\-*]/', $value) == 1)
1160
-					$context['ban_erros'][] = 'invalid_hostname';
1161
-				else
1180
+				if (preg_match('/[^\w.\-*]/', $value) == 1) {
1181
+									$context['ban_erros'][] = 'invalid_hostname';
1182
+				} else
1162 1183
 				{
1163 1184
 					// Replace the * wildcard by a MySQL wildcard %.
1164 1185
 					$value = substr(str_replace('*', '%', $value), 0, 255);
1165 1186
 
1166 1187
 					$ban_triggers['hostname']['hostname'] = $value;
1167 1188
 				}
1168
-			}
1169
-			elseif ($key == 'email')
1189
+			} elseif ($key == 'email')
1170 1190
 			{
1171
-				if (preg_match('/[^\w.\-\+*@]/', $value) == 1)
1172
-					$context['ban_erros'][] = 'invalid_email';
1191
+				if (preg_match('/[^\w.\-\+*@]/', $value) == 1) {
1192
+									$context['ban_erros'][] = 'invalid_email';
1193
+				}
1173 1194
 
1174 1195
 				// Check the user is not banning an admin.
1175 1196
 				$request = $smcFunc['db_query']('', '
@@ -1183,15 +1204,15 @@  discard block
 block discarded – undo
1183 1204
 						'email' => $value,
1184 1205
 					)
1185 1206
 				);
1186
-				if ($smcFunc['db_num_rows']($request) != 0)
1187
-					$context['ban_erros'][] = 'no_ban_admin';
1207
+				if ($smcFunc['db_num_rows']($request) != 0) {
1208
+									$context['ban_erros'][] = 'no_ban_admin';
1209
+				}
1188 1210
 				$smcFunc['db_free_result']($request);
1189 1211
 
1190 1212
 				$value = substr(strtolower(str_replace('*', '%', $value)), 0, 255);
1191 1213
 
1192 1214
 				$ban_triggers['email']['email_address'] = $value;
1193
-			}
1194
-			elseif ($key == 'user')
1215
+			} elseif ($key == 'user')
1195 1216
 			{
1196 1217
 				$user = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $smcFunc['htmlspecialchars']($value, ENT_QUOTES));
1197 1218
 
@@ -1205,8 +1226,9 @@  discard block
 block discarded – undo
1205 1226
 						'username' => $user,
1206 1227
 					)
1207 1228
 				);
1208
-				if ($smcFunc['db_num_rows']($request) == 0)
1209
-					$context['ban_erros'][] = 'invalid_username';
1229
+				if ($smcFunc['db_num_rows']($request) == 0) {
1230
+									$context['ban_erros'][] = 'invalid_username';
1231
+				}
1210 1232
 				list ($value, $isAdmin) = $smcFunc['db_fetch_row']($request);
1211 1233
 				$smcFunc['db_free_result']($request);
1212 1234
 
@@ -1214,25 +1236,25 @@  discard block
 block discarded – undo
1214 1236
 				{
1215 1237
 					unset($value);
1216 1238
 					$context['ban_erros'][] = 'no_ban_admin';
1239
+				} else {
1240
+									$ban_triggers['user']['id_member'] = $value;
1217 1241
 				}
1218
-				else
1219
-					$ban_triggers['user']['id_member'] = $value;
1220
-			}
1221
-			elseif (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1242
+			} elseif (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1222 1243
 			{
1223 1244
 				// Special case, those two are arrays themselves
1224 1245
 				$values = array_unique($value);
1225 1246
 				// Don't add the main IP again.
1226
-				if (isset($triggers['main_ip']))
1227
-					$values = array_diff($values, array($triggers['main_ip']));
1247
+				if (isset($triggers['main_ip'])) {
1248
+									$values = array_diff($values, array($triggers['main_ip']));
1249
+				}
1228 1250
 				unset($value);
1229 1251
 				foreach ($values as $val)
1230 1252
 				{
1231 1253
 					$val = trim($val);
1232 1254
 					$ip_parts = ip2range($val);
1233
-					if (!checkExistingTriggerIP($ip_parts, $val))
1234
-						$context['ban_erros'][] = 'invalid_ip';
1235
-					else
1255
+					if (!checkExistingTriggerIP($ip_parts, $val)) {
1256
+											$context['ban_erros'][] = 'invalid_ip';
1257
+					} else
1236 1258
 					{
1237 1259
 						$ban_triggers[$key][] = array(
1238 1260
 							'ip_low' => $ip_parts['low'],
@@ -1245,15 +1267,16 @@  discard block
 block discarded – undo
1245 1267
 						);
1246 1268
 					}
1247 1269
 				}
1270
+			} else {
1271
+							$context['ban_erros'][] = 'no_bantype_selected';
1248 1272
 			}
1249
-			else
1250
-				$context['ban_erros'][] = 'no_bantype_selected';
1251 1273
 
1252
-			if (isset($value) && !is_array($value))
1253
-				$log_info[] = array(
1274
+			if (isset($value) && !is_array($value)) {
1275
+							$log_info[] = array(
1254 1276
 					'value' => $value,
1255 1277
 					'bantype' => $key,
1256 1278
 				);
1279
+			}
1257 1280
 		}
1258 1281
 	}
1259 1282
 	return array('ban_triggers' => $ban_triggers, 'log_info' => $log_info);
@@ -1273,8 +1296,9 @@  discard block
 block discarded – undo
1273 1296
 {
1274 1297
 	global $smcFunc, $context;
1275 1298
 
1276
-	if (empty($group_id))
1277
-		$context['ban_errors'][] = 'ban_id_empty';
1299
+	if (empty($group_id)) {
1300
+			$context['ban_errors'][] = 'ban_id_empty';
1301
+	}
1278 1302
 
1279 1303
 	// Preset all values that are required.
1280 1304
 	$values = array(
@@ -1299,18 +1323,21 @@  discard block
 block discarded – undo
1299 1323
 	foreach ($triggers as $key => $trigger)
1300 1324
 	{
1301 1325
 		// Exceptions, exceptions, exceptions...always exceptions... :P
1302
-		if (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1303
-			foreach ($trigger as $real_trigger)
1326
+		if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) {
1327
+					foreach ($trigger as $real_trigger)
1304 1328
 				$insertTriggers[] = array_merge($values, $real_trigger);
1305
-		else
1306
-			$insertTriggers[] = array_merge($values, $trigger);
1329
+		} else {
1330
+					$insertTriggers[] = array_merge($values, $trigger);
1331
+		}
1307 1332
 	}
1308 1333
 
1309
-	if (empty($insertTriggers))
1310
-		$context['ban_errors'][] = 'ban_no_triggers';
1334
+	if (empty($insertTriggers)) {
1335
+			$context['ban_errors'][] = 'ban_no_triggers';
1336
+	}
1311 1337
 
1312
-	if (!empty($context['ban_errors']))
1313
-		return false;
1338
+	if (!empty($context['ban_errors'])) {
1339
+			return false;
1340
+	}
1314 1341
 
1315 1342
 	$smcFunc['db_insert']('',
1316 1343
 		'{db_prefix}ban_items',
@@ -1338,15 +1365,19 @@  discard block
 block discarded – undo
1338 1365
 {
1339 1366
 	global $smcFunc, $context;
1340 1367
 
1341
-	if (empty($ban_item))
1342
-		$context['ban_errors'][] = 'ban_ban_item_empty';
1343
-	if (empty($group_id))
1344
-		$context['ban_errors'][] = 'ban_id_empty';
1345
-	if (empty($trigger))
1346
-		$context['ban_errors'][] = 'ban_no_triggers';
1368
+	if (empty($ban_item)) {
1369
+			$context['ban_errors'][] = 'ban_ban_item_empty';
1370
+	}
1371
+	if (empty($group_id)) {
1372
+			$context['ban_errors'][] = 'ban_id_empty';
1373
+	}
1374
+	if (empty($trigger)) {
1375
+			$context['ban_errors'][] = 'ban_no_triggers';
1376
+	}
1347 1377
 
1348
-	if (!empty($context['ban_errors']))
1349
-		return;
1378
+	if (!empty($context['ban_errors'])) {
1379
+			return;
1380
+	}
1350 1381
 
1351 1382
 	// Preset all values that are required.
1352 1383
 	$values = array(
@@ -1387,8 +1418,9 @@  discard block
 block discarded – undo
1387 1418
  */
1388 1419
 function logTriggersUpdates($logs, $new = true, $removal = false)
1389 1420
 {
1390
-	if (empty($logs))
1391
-		return;
1421
+	if (empty($logs)) {
1422
+			return;
1423
+	}
1392 1424
 
1393 1425
 	$log_name_map = array(
1394 1426
 		'main_ip' => 'ip_range',
@@ -1399,14 +1431,15 @@  discard block
 block discarded – undo
1399 1431
 	);
1400 1432
 
1401 1433
 	// Log the addion of the ban entries into the moderation log.
1402
-	foreach ($logs as $log)
1403
-		logAction('ban' . ($removal == true ? 'remove' : ''), array(
1434
+	foreach ($logs as $log) {
1435
+			logAction('ban' . ($removal == true ? 'remove' : ''), array(
1404 1436
 			$log_name_map[$log['bantype']] => $log['value'],
1405 1437
 			'new' => empty($new) ? 0 : 1,
1406 1438
 			'remove' => empty($removal) ? 0 : 1,
1407 1439
 			'type' => $log['bantype'],
1408 1440
 		));
1409
-}
1441
+	}
1442
+	}
1410 1443
 
1411 1444
 /**
1412 1445
  * Updates an existing ban group
@@ -1420,12 +1453,15 @@  discard block
 block discarded – undo
1420 1453
 {
1421 1454
 	global $smcFunc, $context;
1422 1455
 
1423
-	if (empty($ban_info['name']))
1424
-		$context['ban_errors'][] = 'ban_name_empty';
1425
-	if (empty($ban_info['id']))
1426
-		$context['ban_errors'][] = 'ban_id_empty';
1427
-	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1428
-		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1456
+	if (empty($ban_info['name'])) {
1457
+			$context['ban_errors'][] = 'ban_name_empty';
1458
+	}
1459
+	if (empty($ban_info['id'])) {
1460
+			$context['ban_errors'][] = 'ban_id_empty';
1461
+	}
1462
+	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) {
1463
+			$context['ban_errors'][] = 'ban_unknown_restriction_type';
1464
+	}
1429 1465
 
1430 1466
 	if (!empty($ban_info['id']))
1431 1467
 	{
@@ -1440,8 +1476,9 @@  discard block
 block discarded – undo
1440 1476
 			)
1441 1477
 		);
1442 1478
 
1443
-		if ($smcFunc['db_num_rows']($request) == 0)
1444
-			$context['ban_errors'][] = 'ban_not_found';
1479
+		if ($smcFunc['db_num_rows']($request) == 0) {
1480
+					$context['ban_errors'][] = 'ban_not_found';
1481
+		}
1445 1482
 		$smcFunc['db_free_result']($request);
1446 1483
 	}
1447 1484
 
@@ -1459,13 +1496,15 @@  discard block
 block discarded – undo
1459 1496
 				'new_ban_name' => $ban_info['name'],
1460 1497
 			)
1461 1498
 		);
1462
-		if ($smcFunc['db_num_rows']($request) != 0)
1463
-			$context['ban_errors'][] = 'ban_name_exists';
1499
+		if ($smcFunc['db_num_rows']($request) != 0) {
1500
+					$context['ban_errors'][] = 'ban_name_exists';
1501
+		}
1464 1502
 		$smcFunc['db_free_result']($request);
1465 1503
 	}
1466 1504
 
1467
-	if (!empty($context['ban_errors']))
1468
-		return $ban_info['id'];
1505
+	if (!empty($context['ban_errors'])) {
1506
+			return $ban_info['id'];
1507
+	}
1469 1508
 
1470 1509
 	$smcFunc['db_query']('', '
1471 1510
 		UPDATE {db_prefix}ban_groups
@@ -1509,10 +1548,12 @@  discard block
 block discarded – undo
1509 1548
 {
1510 1549
 	global $smcFunc, $context;
1511 1550
 
1512
-	if (empty($ban_info['name']))
1513
-		$context['ban_errors'][] = 'ban_name_empty';
1514
-	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1515
-		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1551
+	if (empty($ban_info['name'])) {
1552
+			$context['ban_errors'][] = 'ban_name_empty';
1553
+	}
1554
+	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) {
1555
+			$context['ban_errors'][] = 'ban_unknown_restriction_type';
1556
+	}
1516 1557
 
1517 1558
 	if (!empty($ban_info['name']))
1518 1559
 	{
@@ -1527,13 +1568,15 @@  discard block
 block discarded – undo
1527 1568
 			)
1528 1569
 		);
1529 1570
 
1530
-		if ($smcFunc['db_num_rows']($request) == 1)
1531
-			$context['ban_errors'][] = 'ban_name_exists';
1571
+		if ($smcFunc['db_num_rows']($request) == 1) {
1572
+					$context['ban_errors'][] = 'ban_name_exists';
1573
+		}
1532 1574
 		$smcFunc['db_free_result']($request);
1533 1575
 	}
1534 1576
 
1535
-	if (!empty($context['ban_errors']))
1536
-		return;
1577
+	if (!empty($context['ban_errors'])) {
1578
+			return;
1579
+	}
1537 1580
 
1538 1581
 	// Yes yes, we're ready to add now.
1539 1582
 	$ban_info['id'] = $smcFunc['db_insert']('',
@@ -1550,8 +1593,9 @@  discard block
 block discarded – undo
1550 1593
 		1
1551 1594
 	);
1552 1595
 
1553
-	if (empty($ban_info['id']))
1554
-		$context['ban_errors'][] = 'impossible_insert_new_bangroup';
1596
+	if (empty($ban_info['id'])) {
1597
+			$context['ban_errors'][] = 'impossible_insert_new_bangroup';
1598
+	}
1555 1599
 
1556 1600
 	return $ban_info['id'];
1557 1601
 }
@@ -1576,24 +1620,24 @@  discard block
 block discarded – undo
1576 1620
 	$ban_group = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0;
1577 1621
 	$ban_id = isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0;
1578 1622
 
1579
-	if (empty($ban_group))
1580
-		fatal_lang_error('ban_not_found', false);
1623
+	if (empty($ban_group)) {
1624
+			fatal_lang_error('ban_not_found', false);
1625
+	}
1581 1626
 
1582 1627
 	if (isset($_POST['add_new_trigger']) && !empty($_POST['ban_suggestions']))
1583 1628
 	{
1584 1629
 		saveTriggers($_POST['ban_suggestions'], $ban_group, 0, $ban_id);
1585 1630
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
1586
-	}
1587
-	elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions']))
1631
+	} elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions']))
1588 1632
 	{
1589 1633
 		// The first replaces the old one, the others are added new (simplification, otherwise it would require another query and some work...)
1590 1634
 		saveTriggers(array_shift($_POST['ban_suggestions']), $ban_group, 0, $ban_id);
1591
-		if (!empty($_POST['ban_suggestions']))
1592
-			saveTriggers($_POST['ban_suggestions'], $ban_group);
1635
+		if (!empty($_POST['ban_suggestions'])) {
1636
+					saveTriggers($_POST['ban_suggestions'], $ban_group);
1637
+		}
1593 1638
 
1594 1639
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
1595
-	}
1596
-	elseif (isset($_POST['edit_trigger']))
1640
+	} elseif (isset($_POST['edit_trigger']))
1597 1641
 	{
1598 1642
 		removeBanTriggers($ban_id);
1599 1643
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
@@ -1624,8 +1668,7 @@  discard block
 block discarded – undo
1624 1668
 			),
1625 1669
 			'is_new' => true,
1626 1670
 		);
1627
-	}
1628
-	else
1671
+	} else
1629 1672
 	{
1630 1673
 		$request = $smcFunc['db_query']('', '
1631 1674
 			SELECT
@@ -1642,8 +1685,9 @@  discard block
 block discarded – undo
1642 1685
 				'ban_group' => $ban_group,
1643 1686
 			)
1644 1687
 		);
1645
-		if ($smcFunc['db_num_rows']($request) == 0)
1646
-			fatal_lang_error('ban_not_found', false);
1688
+		if ($smcFunc['db_num_rows']($request) == 0) {
1689
+					fatal_lang_error('ban_not_found', false);
1690
+		}
1647 1691
 		$row = $smcFunc['db_fetch_assoc']($request);
1648 1692
 		$smcFunc['db_free_result']($request);
1649 1693
 
@@ -1692,8 +1736,9 @@  discard block
 block discarded – undo
1692 1736
 		removeBanTriggers($_POST['remove']);
1693 1737
 
1694 1738
 		// Rehabilitate some members.
1695
-		if ($_REQUEST['entity'] == 'member')
1696
-			updateBanMembers();
1739
+		if ($_REQUEST['entity'] == 'member') {
1740
+					updateBanMembers();
1741
+		}
1697 1742
 
1698 1743
 		// Make sure the ban cache is refreshed.
1699 1744
 		updateSettings(array('banLastUpdated' => time()));
@@ -1806,8 +1851,7 @@  discard block
 block discarded – undo
1806 1851
 			'default' => 'bi.ip_low, bi.ip_high, bi.ip_low',
1807 1852
 			'reverse' => 'bi.ip_low DESC, bi.ip_high DESC',
1808 1853
 		);
1809
-	}
1810
-	elseif ($context['selected_entity'] === 'hostname')
1854
+	} elseif ($context['selected_entity'] === 'hostname')
1811 1855
 	{
1812 1856
 		$listOptions['columns']['banned_entity']['data'] = array(
1813 1857
 			'function' => function($rowData) use ($smcFunc)
@@ -1819,8 +1863,7 @@  discard block
 block discarded – undo
1819 1863
 			'default' => 'bi.hostname',
1820 1864
 			'reverse' => 'bi.hostname DESC',
1821 1865
 		);
1822
-	}
1823
-	elseif ($context['selected_entity'] === 'email')
1866
+	} elseif ($context['selected_entity'] === 'email')
1824 1867
 	{
1825 1868
 		$listOptions['columns']['banned_entity']['data'] = array(
1826 1869
 			'function' => function($rowData) use ($smcFunc)
@@ -1832,8 +1875,7 @@  discard block
 block discarded – undo
1832 1875
 			'default' => 'bi.email_address',
1833 1876
 			'reverse' => 'bi.email_address DESC',
1834 1877
 		);
1835
-	}
1836
-	elseif ($context['selected_entity'] === 'member')
1878
+	} elseif ($context['selected_entity'] === 'member')
1837 1879
 	{
1838 1880
 		$listOptions['columns']['banned_entity']['data'] = array(
1839 1881
 			'sprintf' => array(
@@ -1897,8 +1939,9 @@  discard block
 block discarded – undo
1897 1939
 		)
1898 1940
 	);
1899 1941
 	$ban_triggers = array();
1900
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1901
-		$ban_triggers[] = $row;
1942
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1943
+			$ban_triggers[] = $row;
1944
+	}
1902 1945
 	$smcFunc['db_free_result']($request);
1903 1946
 
1904 1947
 	return $ban_triggers;
@@ -1954,8 +1997,9 @@  discard block
 block discarded – undo
1954 1997
 		validateToken('admin-bl');
1955 1998
 
1956 1999
 		// 'Delete all entries' button was pressed.
1957
-		if (!empty($_POST['removeAll']))
1958
-			removeBanLogs();
2000
+		if (!empty($_POST['removeAll'])) {
2001
+					removeBanLogs();
2002
+		}
1959 2003
 		// 'Delete selection' button was pressed.
1960 2004
 		else
1961 2005
 		{
@@ -2164,12 +2208,15 @@  discard block
 block discarded – undo
2164 2208
 	$low = inet_dtop($low);
2165 2209
 	$high = inet_dtop($high);
2166 2210
 
2167
-	if ($low == '255.255.255.255') return 'unknown';
2168
-	if ($low == $high)
2169
-	    return $low;
2170
-	else
2171
-	    return $low . '-' . $high;
2172
-}
2211
+	if ($low == '255.255.255.255') {
2212
+		return 'unknown';
2213
+	}
2214
+	if ($low == $high) {
2215
+		    return $low;
2216
+	} else {
2217
+		    return $low . '-' . $high;
2218
+	}
2219
+	}
2173 2220
 
2174 2221
 /**
2175 2222
  * Checks whether a given IP range already exists in the trigger list.
@@ -2245,15 +2292,17 @@  discard block
 block discarded – undo
2245 2292
 	$memberEmailWild = array();
2246 2293
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2247 2294
 	{
2248
-		if ($row['id_member'])
2249
-			$memberIDs[$row['id_member']] = $row['id_member'];
2295
+		if ($row['id_member']) {
2296
+					$memberIDs[$row['id_member']] = $row['id_member'];
2297
+		}
2250 2298
 		if ($row['email_address'])
2251 2299
 		{
2252 2300
 			// Does it have a wildcard - if so we can't do a IN on it.
2253
-			if (strpos($row['email_address'], '%') !== false)
2254
-				$memberEmailWild[$row['email_address']] = $row['email_address'];
2255
-			else
2256
-				$memberEmails[$row['email_address']] = $row['email_address'];
2301
+			if (strpos($row['email_address'], '%') !== false) {
2302
+							$memberEmailWild[$row['email_address']] = $row['email_address'];
2303
+			} else {
2304
+							$memberEmails[$row['email_address']] = $row['email_address'];
2305
+			}
2257 2306
 		}
2258 2307
 	}
2259 2308
 	$smcFunc['db_free_result']($request);
@@ -2304,14 +2353,15 @@  discard block
 block discarded – undo
2304 2353
 	}
2305 2354
 
2306 2355
 	// We welcome our new members in the realm of the banned.
2307
-	if (!empty($newMembers))
2308
-		$smcFunc['db_query']('', '
2356
+	if (!empty($newMembers)) {
2357
+			$smcFunc['db_query']('', '
2309 2358
 			DELETE FROM {db_prefix}log_online
2310 2359
 			WHERE id_member IN ({array_int:new_banned_members})',
2311 2360
 			array(
2312 2361
 				'new_banned_members' => $newMembers,
2313 2362
 			)
2314 2363
 		);
2364
+	}
2315 2365
 
2316 2366
 	// Find members that are wrongfully marked as banned.
2317 2367
 	$request = $smcFunc['db_query']('', '
@@ -2338,9 +2388,10 @@  discard block
 block discarded – undo
2338 2388
 	}
2339 2389
 	$smcFunc['db_free_result']($request);
2340 2390
 
2341
-	if (!empty($updates))
2342
-		foreach ($updates as $newStatus => $members)
2391
+	if (!empty($updates)) {
2392
+			foreach ($updates as $newStatus => $members)
2343 2393
 			updateMemberData($members, array('is_activated' => $newStatus));
2394
+	}
2344 2395
 
2345 2396
 	// Update the latest member and our total members as banning may change them.
2346 2397
 	updateStats('member');
Please login to merge, or discard this patch.
Sources/Subs-Sound.php 1 patch
Braces   +32 added lines, -20 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Creates a wave file that spells the letters of $word.
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 	global $settings, $user_info;
33 34
 
34 35
 	// Allow max 2 requests per 20 seconds.
35
-	if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2)
36
-		die(header('HTTP/1.1 400 Bad Request'));
36
+	if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) {
37
+			die(header('HTTP/1.1 400 Bad Request'));
38
+	}
37 39
 	cache_put_data('wave_file/' . $user_info['ip'], $ip ? $ip + 1 : 1, 20);
38 40
 	cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20);
39 41
 
@@ -42,16 +44,19 @@  discard block
 block discarded – undo
42 44
 	mt_srand(end($tmp));
43 45
 
44 46
 	// Try to see if there's a sound font in the user's language.
45
-	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav'))
46
-		$sound_language = $user_info['language'];
47
+	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) {
48
+			$sound_language = $user_info['language'];
49
+	}
47 50
 
48 51
 	// English should be there.
49
-	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav'))
50
-		$sound_language = 'english';
52
+	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) {
53
+			$sound_language = 'english';
54
+	}
51 55
 
52 56
 	// Guess not...
53
-	else
54
-		return false;
57
+	else {
58
+			return false;
59
+	}
55 60
 
56 61
 	// File names are in lower case so lets make sure that we are only using a lower case string
57 62
 	$word = strtolower($word);
@@ -61,20 +66,25 @@  discard block
 block discarded – undo
61 66
 	for ($i = 0; $i < strlen($word); $i++)
62 67
 	{
63 68
 		$sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav'));
64
-		if (strpos($sound_letter, 'data') === false)
65
-			return false;
69
+		if (strpos($sound_letter, 'data') === false) {
70
+					return false;
71
+		}
66 72
 
67 73
 		$sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8);
68 74
 		switch ($word{$i} === 's' ? 0 : mt_rand(0, 2))
69 75
 		{
70
-			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
71
-					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
72
-						$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
76
+			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) {
77
+								for ($k = 0, $m = round(mt_rand(15, 25) / 10);
78
+			}
79
+			$k < $m; $k++) {
80
+											$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
81
+					}
73 82
 			break;
74 83
 
75 84
 			case 1:
76
-				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2)
77
-					$sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : '');
85
+				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) {
86
+									$sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : '');
87
+				}
78 88
 				$sound_word .= str_repeat($sound_letter{$n}, 2);
79 89
 			break;
80 90
 
@@ -82,10 +92,12 @@  discard block
 block discarded – undo
82 92
 				$shift = 0;
83 93
 				for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
84 94
 				{
85
-					if (mt_rand(0, 10) === 0)
86
-						$shift += mt_rand(-3, 3);
87
-					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
88
-						$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
95
+					if (mt_rand(0, 10) === 0) {
96
+											$shift += mt_rand(-3, 3);
97
+					}
98
+					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) {
99
+											$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
100
+					}
89 101
 				}
90 102
 			break;
91 103
 
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 4
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.