Completed
Push — release-2.1 ( bed43e...620050 )
by Jeremy
06:54
created
Sources/ManageLanguages.php 2 patches
Braces   +241 added lines, -181 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.
@@ -150,11 +151,11 @@  discard block
 block discarded – undo
150 151
 	$language_list = new xmlArray(fetch_web_data($url), true);
151 152
 
152 153
 	// Check that the site responded and that the language exists.
153
-	if (!$language_list->exists('languages'))
154
-		$context['smf_error'] = 'no_response';
155
-	elseif (!$language_list->exists('languages/language'))
156
-		$context['smf_error'] = 'no_files';
157
-	else
154
+	if (!$language_list->exists('languages')) {
155
+			$context['smf_error'] = 'no_response';
156
+	} elseif (!$language_list->exists('languages/language')) {
157
+			$context['smf_error'] = 'no_files';
158
+	} else
158 159
 	{
159 160
 		$language_list = $language_list->path('languages[0]');
160 161
 		$lang_files = $language_list->set('language');
@@ -162,8 +163,9 @@  discard block
 block discarded – undo
162 163
 		foreach ($lang_files as $file)
163 164
 		{
164 165
 			// Were we searching?
165
-			if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false)
166
-				continue;
166
+			if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) {
167
+							continue;
168
+			}
167 169
 
168 170
 			$smf_languages[] = array(
169 171
 				'id' => $file->fetch('id'),
@@ -174,10 +176,11 @@  discard block
 block discarded – undo
174 176
 				'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>',
175 177
 			);
176 178
 		}
177
-		if (empty($smf_languages))
178
-			$context['smf_error'] = 'no_files';
179
-		else
180
-			return $smf_languages;
179
+		if (empty($smf_languages)) {
180
+					$context['smf_error'] = 'no_files';
181
+		} else {
182
+					return $smf_languages;
183
+		}
181 184
 	}
182 185
 }
183 186
 
@@ -199,8 +202,9 @@  discard block
 block discarded – undo
199 202
 	require_once($sourcedir . '/Subs-Package.php');
200 203
 
201 204
 	// Clearly we need to know what to request.
202
-	if (!isset($_GET['did']))
203
-		fatal_lang_error('no_access', false);
205
+	if (!isset($_GET['did'])) {
206
+			fatal_lang_error('no_access', false);
207
+	}
204 208
 
205 209
 	// Some lovely context.
206 210
 	$context['download_id'] = $_GET['did'];
@@ -220,8 +224,9 @@  discard block
 block discarded – undo
220 224
 		foreach ($_POST['copy_file'] as $file)
221 225
 		{
222 226
 			// Check it's not very bad.
223
-			if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file)))
224
-				fatal_error($txt['languages_download_illegal_paths']);
227
+			if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) {
228
+							fatal_error($txt['languages_download_illegal_paths']);
229
+			}
225 230
 
226 231
 			$chmod_files[] = $boarddir . '/' . $file;
227 232
 			$install_files[] = $file;
@@ -232,8 +237,9 @@  discard block
 block discarded – undo
232 237
 		$files_left = $file_status['files']['notwritable'];
233 238
 
234 239
 		// Something not writable?
235
-		if (!empty($files_left))
236
-			$context['error_message'] = $txt['languages_download_not_chmod'];
240
+		if (!empty($files_left)) {
241
+					$context['error_message'] = $txt['languages_download_not_chmod'];
242
+		}
237 243
 		// Otherwise, go go go!
238 244
 		elseif (!empty($install_files))
239 245
 		{
@@ -248,11 +254,13 @@  discard block
 block discarded – undo
248 254
 	}
249 255
 
250 256
 	// Open up the old china.
251
-	if (!isset($archive_content))
252
-		$archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
257
+	if (!isset($archive_content)) {
258
+			$archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
259
+	}
253 260
 
254
-	if (empty($archive_content))
255
-		fatal_error($txt['add_language_error_no_response']);
261
+	if (empty($archive_content)) {
262
+			fatal_error($txt['add_language_error_no_response']);
263
+	}
256 264
 
257 265
 	// Now for each of the files, let's do some *stuff*
258 266
 	$context['files'] = array(
@@ -267,8 +275,9 @@  discard block
 block discarded – undo
267 275
 		$extension = substr($filename, strrpos($filename, '.') + 1);
268 276
 
269 277
 		// Don't do anything with files we don't understand.
270
-		if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt')))
271
-			continue;
278
+		if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) {
279
+					continue;
280
+		}
272 281
 
273 282
 		// Basic data.
274 283
 		$context_data = array(
@@ -287,8 +296,9 @@  discard block
 block discarded – undo
287 296
 		// Does the file exist, is it different and can we overwrite?
288 297
 		if (file_exists($boarddir . '/' . $file['filename']))
289 298
 		{
290
-			if (is_writable($boarddir . '/' . $file['filename']))
291
-				$context_data['writable'] = true;
299
+			if (is_writable($boarddir . '/' . $file['filename'])) {
300
+							$context_data['writable'] = true;
301
+			}
292 302
 
293 303
 			// Finally, do we actually think the content has changed?
294 304
 			if ($file['size'] == filesize($boarddir . '/' . $file['filename']) && $file['md5'] == md5_file($boarddir . '/' . $file['filename']))
@@ -301,16 +311,17 @@  discard block
 block discarded – undo
301 311
 			{
302 312
 				$context_data['exists'] = 'same';
303 313
 				$context_data['default_copy'] = false;
314
+			} else {
315
+							$context_data['exists'] = 'different';
304 316
 			}
305
-			else
306
-				$context_data['exists'] = 'different';
307 317
 		}
308 318
 		// No overwrite?
309 319
 		else
310 320
 		{
311 321
 			// Can we at least stick it in the directory...
312
-			if (is_writable($boarddir . '/' . $dirname))
313
-				$context_data['writable'] = true;
322
+			if (is_writable($boarddir . '/' . $dirname)) {
323
+							$context_data['writable'] = true;
324
+			}
314 325
 		}
315 326
 
316 327
 		// 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...
@@ -325,8 +336,9 @@  discard block
 block discarded – undo
325 336
 			list ($name, $language) = explode('.', $filename);
326 337
 
327 338
 			// Let's get the new version, I like versions, they tell me that I'm up to date.
328
-			if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1)
329
-				$context_data['version'] = $match[1];
339
+			if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) {
340
+							$context_data['version'] = $match[1];
341
+			}
330 342
 
331 343
 			// Now does the old file exist - if so what is it's version?
332 344
 			if (file_exists($boarddir . '/' . $file['filename']))
@@ -342,34 +354,35 @@  discard block
 block discarded – undo
342 354
 					$context_data['cur_version'] = $match[1];
343 355
 
344 356
 					// How does this compare?
345
-					if ($context_data['cur_version'] == $context_data['version'])
346
-						$context_data['version_compare'] = 'same';
347
-					elseif ($context_data['cur_version'] > $context_data['version'])
348
-						$context_data['version_compare'] = 'older';
357
+					if ($context_data['cur_version'] == $context_data['version']) {
358
+											$context_data['version_compare'] = 'same';
359
+					} elseif ($context_data['cur_version'] > $context_data['version']) {
360
+											$context_data['version_compare'] = 'older';
361
+					}
349 362
 
350 363
 					// Don't recommend copying if the version is the same.
351
-					if ($context_data['version_compare'] != 'newer')
352
-						$context_data['default_copy'] = false;
364
+					if ($context_data['version_compare'] != 'newer') {
365
+											$context_data['default_copy'] = false;
366
+					}
353 367
 				}
354 368
 			}
355 369
 
356 370
 			// Add the context data to the main set.
357 371
 			$context['files']['lang'][] = $context_data;
358
-		}
359
-		elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false)
372
+		} elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false)
360 373
 		{
361 374
 			// Registration agreement is a primary file
362 375
 			$context['files']['lang'][] = $context_data;
363
-		}
364
-		else
376
+		} else
365 377
 		{
366 378
 			// There shouldn't be anything else, but load this into "other" in case we decide to handle it in the future
367 379
 			$context['files']['other'][] = $context_data;
368 380
 		}
369 381
 
370 382
 		// Collect together all non-writable areas.
371
-		if (!$context_data['writable'])
372
-			$context['make_writable'][] = $context_data['destination'];
383
+		if (!$context_data['writable']) {
384
+					$context['make_writable'][] = $context_data['destination'];
385
+		}
373 386
 	}
374 387
 
375 388
 	// Before we go to far can we make anything writable, eh, eh?
@@ -384,22 +397,24 @@  discard block
 block discarded – undo
384 397
 		{
385 398
 			if ($type == 'lang')
386 399
 			{
387
-				foreach ($data as $k => $file)
388
-					if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
400
+				foreach ($data as $k => $file) {
401
+									if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
389 402
 						$context['files'][$type][$k]['writable'] = true;
390
-			}
391
-			else
403
+				}
404
+			} else
392 405
 			{
393
-				foreach ($data as $theme => $files)
394
-					foreach ($files as $k => $file)
406
+				foreach ($data as $theme => $files) {
407
+									foreach ($files as $k => $file)
395 408
 						if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
396 409
 							$context['files'][$type][$theme][$k]['writable'] = true;
410
+				}
397 411
 			}
398 412
 		}
399 413
 
400 414
 		// Are we going to need more language stuff?
401
-		if (!empty($context['still_not_writable']))
402
-			loadLanguage('Packages');
415
+		if (!empty($context['still_not_writable'])) {
416
+					loadLanguage('Packages');
417
+		}
403 418
 	}
404 419
 
405 420
 	// This is the list for the main files.
@@ -612,12 +627,13 @@  discard block
 block discarded – undo
612 627
 	highlightSelected("list_language_list_' . ($language == '' ? 'english' : $language) . '");', true);
613 628
 
614 629
 	// Display a warning if we cannot edit the default setting.
615
-	if (!is_writable($boarddir . '/Settings.php'))
616
-		$listOptions['additional_rows'][] = array(
630
+	if (!is_writable($boarddir . '/Settings.php')) {
631
+			$listOptions['additional_rows'][] = array(
617 632
 				'position' => 'after_title',
618 633
 				'value' => $txt['language_settings_writable'],
619 634
 				'class' => 'smalltext alert',
620 635
 			);
636
+	}
621 637
 
622 638
 	require_once($sourcedir . '/Subs-List.php');
623 639
 	createList($listOptions);
@@ -659,10 +675,11 @@  discard block
 block discarded – undo
659 675
 
660 676
 	// Put them back.
661 677
 	$settings['actual_theme_dir'] = $backup_actual_theme_dir;
662
-	if (!empty($backup_base_theme_dir))
663
-		$settings['base_theme_dir'] = $backup_base_theme_dir;
664
-	else
665
-		unset($settings['base_theme_dir']);
678
+	if (!empty($backup_base_theme_dir)) {
679
+			$settings['base_theme_dir'] = $backup_base_theme_dir;
680
+	} else {
681
+			unset($settings['base_theme_dir']);
682
+	}
666 683
 
667 684
 	// Get the language files and data...
668 685
 	foreach ($context['languages'] as $lang)
@@ -691,13 +708,15 @@  discard block
 block discarded – undo
691 708
 	while ($row = $smcFunc['db_fetch_assoc']($request))
692 709
 	{
693 710
 		// Default?
694
-		if (empty($row['lngfile']) || !isset($languages[$row['lngfile']]))
695
-			$row['lngfile'] = $language;
711
+		if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) {
712
+					$row['lngfile'] = $language;
713
+		}
696 714
 
697
-		if (!isset($languages[$row['lngfile']]) && isset($languages['english']))
698
-			$languages['english']['count'] += $row['num_users'];
699
-		elseif (isset($languages[$row['lngfile']]))
700
-			$languages[$row['lngfile']]['count'] += $row['num_users'];
715
+		if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) {
716
+					$languages['english']['count'] += $row['num_users'];
717
+		} elseif (isset($languages[$row['lngfile']])) {
718
+					$languages[$row['lngfile']]['count'] += $row['num_users'];
719
+		}
701 720
 	}
702 721
 	$smcFunc['db_free_result']($request);
703 722
 
@@ -737,13 +756,15 @@  discard block
 block discarded – undo
737 756
 
738 757
 	call_integration_hook('integrate_language_settings', array(&$config_vars));
739 758
 
740
-	if ($return_config)
741
-		return $config_vars;
759
+	if ($return_config) {
760
+			return $config_vars;
761
+	}
742 762
 
743 763
 	// Get our languages. No cache
744 764
 	getLanguages(false);
745
-	foreach ($context['languages'] as $lang)
746
-		$config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']);
765
+	foreach ($context['languages'] as $lang) {
766
+			$config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']);
767
+	}
747 768
 
748 769
 	// Saving settings?
749 770
 	if (isset($_REQUEST['save']))
@@ -753,8 +774,9 @@  discard block
 block discarded – undo
753 774
 		call_integration_hook('integrate_save_language_settings', array(&$config_vars));
754 775
 
755 776
 		saveSettings($config_vars);
756
-		if (!$settings_not_writable && !$settings_backup_fail)
757
-			$_SESSION['adm-save'] = true;
777
+		if (!$settings_not_writable && !$settings_backup_fail) {
778
+					$_SESSION['adm-save'] = true;
779
+		}
758 780
 		redirectexit('action=admin;area=languages;sa=settings');
759 781
 	}
760 782
 
@@ -763,10 +785,11 @@  discard block
 block discarded – undo
763 785
 	$context['settings_title'] = $txt['language_settings'];
764 786
 	$context['save_disabled'] = $settings_not_writable;
765 787
 
766
-	if ($settings_not_writable)
767
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
768
-	elseif ($settings_backup_fail)
769
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
788
+	if ($settings_not_writable) {
789
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
790
+	} elseif ($settings_backup_fail) {
791
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
792
+	}
770 793
 
771 794
 	// Fill the config array.
772 795
 	prepareServerSettingsContext($config_vars);
@@ -813,8 +836,9 @@  discard block
 block discarded – undo
813 836
 			'theme_dir' => $settings['default_theme_dir'],
814 837
 		),
815 838
 	);
816
-	while ($row = $smcFunc['db_fetch_assoc']($request))
817
-		$themes[$row['id_theme']][$row['variable']] = $row['value'];
839
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
840
+			$themes[$row['id_theme']][$row['variable']] = $row['value'];
841
+	}
818 842
 	$smcFunc['db_free_result']($request);
819 843
 
820 844
 	// This will be where we look
@@ -847,14 +871,16 @@  discard block
 block discarded – undo
847 871
 	// Check we have themes with a path and a name - just in case - and add the path.
848 872
 	foreach ($themes as $id => $data)
849 873
 	{
850
-		if (count($data) != 2)
851
-			unset($themes[$id]);
852
-		elseif (is_dir($data['theme_dir'] . '/languages'))
853
-			$lang_dirs[$id] = $data['theme_dir'] . '/languages';
874
+		if (count($data) != 2) {
875
+					unset($themes[$id]);
876
+		} elseif (is_dir($data['theme_dir'] . '/languages')) {
877
+					$lang_dirs[$id] = $data['theme_dir'] . '/languages';
878
+		}
854 879
 
855 880
 		// How about image directories?
856
-		if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id']))
857
-			$images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
881
+		if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) {
882
+					$images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
883
+		}
858 884
 	}
859 885
 
860 886
 	$current_file = $file_id ? $lang_dirs[$theme_id] . '/' . $file_id . '.' . $context['lang_id'] . '.php' : '';
@@ -868,15 +894,17 @@  discard block
 block discarded – undo
868 894
 		while ($entry = $dir->read())
869 895
 		{
870 896
 			// We're only after the files for this language.
871
-			if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0)
872
-				continue;
897
+			if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) {
898
+							continue;
899
+			}
873 900
 
874
-			if (!isset($context['possible_files'][$theme]))
875
-				$context['possible_files'][$theme] = array(
901
+			if (!isset($context['possible_files'][$theme])) {
902
+							$context['possible_files'][$theme] = array(
876 903
 					'id' => $theme,
877 904
 					'name' => $themes[$theme]['name'],
878 905
 					'files' => array(),
879 906
 				);
907
+			}
880 908
 
881 909
 			$context['possible_files'][$theme]['files'][] = array(
882 910
 				'id' => $matches[1],
@@ -905,31 +933,36 @@  discard block
 block discarded – undo
905 933
 		{
906 934
 			$_SESSION['last_backup_for'] = $context['lang_id'] . '$$$';
907 935
 			$result = package_create_backup('backup_lang_' . $context['lang_id']);
908
-			if (!$result)
909
-				fatal_lang_error('could_not_language_backup', false);
936
+			if (!$result) {
937
+							fatal_lang_error('could_not_language_backup', false);
938
+			}
910 939
 		}
911 940
 
912 941
 		// Second, loop through the array to remove the files.
913 942
 		foreach ($lang_dirs as $curPath)
914 943
 		{
915
-			foreach ($context['possible_files'][1]['files'] as $lang)
916
-				if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'))
944
+			foreach ($context['possible_files'][1]['files'] as $lang) {
945
+							if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'))
917 946
 					unlink($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php');
947
+			}
918 948
 
919 949
 			// Check for the email template.
920
-			if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'))
921
-				unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
950
+			if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) {
951
+							unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
952
+			}
922 953
 		}
923 954
 
924 955
 		// Third, the agreement file.
925
-		if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt'))
926
-			unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
956
+		if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) {
957
+					unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
958
+		}
927 959
 
928 960
 		// Fourth, a related images folder, if it exists...
929
-		if (!empty($images_dirs))
930
-			foreach ($images_dirs as $curPath)
961
+		if (!empty($images_dirs)) {
962
+					foreach ($images_dirs as $curPath)
931 963
 				if (is_dir($curPath))
932 964
 					deltree($curPath);
965
+		}
933 966
 
934 967
 		// Members can no longer use this language.
935 968
 		$smcFunc['db_query']('', '
@@ -973,8 +1006,9 @@  discard block
 block discarded – undo
973 1006
 
974 1007
 		// Build the replacements. old => new
975 1008
 		$replace_array = array();
976
-		foreach ($primary_settings as $setting => $type)
977
-			$replace_array['~\$txt\[\'' . $setting . '\'\]\s*=\s*[^\r\n]+~'] = '$txt[\'' . $setting . '\'] = ' . ($type === 'bool' ? (!empty($_POST[$setting]) ? 'true' : 'false') : '\'' . ($setting = 'native_name' ? htmlentities(un_htmlspecialchars($_POST[$setting]), ENT_QUOTES, $context['character_set']) : preg_replace('~[^\w-]~i', '', $_POST[$setting])) . '\'') . ';';
1009
+		foreach ($primary_settings as $setting => $type) {
1010
+					$replace_array['~\$txt\[\'' . $setting . '\'\]\s*=\s*[^\r\n]+~'] = '$txt[\'' . $setting . '\'] = ' . ($type === 'bool' ? (!empty($_POST[$setting]) ? 'true' : 'false') : '\'' . ($setting = 'native_name' ? htmlentities(un_htmlspecialchars($_POST[$setting]), ENT_QUOTES, $context['character_set']) : preg_replace('~[^\w-]~i', '', $_POST[$setting])) . '\'') . ';';
1011
+		}
978 1012
 
979 1013
 		$current_data = preg_replace(array_keys($replace_array), array_values($replace_array), $current_data);
980 1014
 		$fp = fopen($settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php', 'w+');
@@ -1017,30 +1051,29 @@  discard block
 block discarded – undo
1017 1051
 				if (is_string($v))
1018 1052
 				{
1019 1053
 					// Only try to save if 'edit' was specified and if the string has changed
1020
-					if ($v == 'edit' && isset($_POST['entry'][$k]) && isset($_POST['comp'][$k]) && $_POST['entry'][$k] != $_POST['comp'][$k])
1021
-						$save_strings[$k] = cleanLangString($_POST['entry'][$k], false);
1054
+					if ($v == 'edit' && isset($_POST['entry'][$k]) && isset($_POST['comp'][$k]) && $_POST['entry'][$k] != $_POST['comp'][$k]) {
1055
+											$save_strings[$k] = cleanLangString($_POST['entry'][$k], false);
1056
+					}
1022 1057
 
1023 1058
 					// Record any add or remove requests. We'll decide on them later.
1024
-					elseif ($v == 'remove')
1025
-						$remove_strings[] = $k;
1026
-					elseif ($v == 'add' && isset($_POST['entry'][$k]))
1059
+					elseif ($v == 'remove') {
1060
+											$remove_strings[] = $k;
1061
+					} elseif ($v == 'add' && isset($_POST['entry'][$k]))
1027 1062
 					{
1028 1063
 						$add_strings[$k] = array(
1029 1064
 							'group' => isset($_POST['grp'][$k]) ? $_POST['grp'][$k] : 'txt',
1030 1065
 							'string' => cleanLangString($_POST['entry'][$k], false),
1031 1066
 						);
1032 1067
 					}
1033
-				}
1034
-				elseif (is_array($v))
1068
+				} elseif (is_array($v))
1035 1069
 				{
1036 1070
 					foreach ($v as $subk => $subv)
1037 1071
 					{
1038
-						if ($subv == 'edit' && isset($_POST['entry'][$k][$subk]) && isset($_POST['comp'][$k][$subk]) && $_POST['entry'][$k][$subk] != $_POST['comp'][$k][$subk])
1039
-							$save_strings[$k][$subk] = cleanLangString($_POST['entry'][$k][$subk], false);
1040
-
1041
-						elseif ($subv == 'remove')
1042
-							$remove_strings[$k][] = $subk;
1043
-						elseif ($subv == 'add' && isset($_POST['entry'][$k][$subk]))
1072
+						if ($subv == 'edit' && isset($_POST['entry'][$k][$subk]) && isset($_POST['comp'][$k][$subk]) && $_POST['entry'][$k][$subk] != $_POST['comp'][$k][$subk]) {
1073
+													$save_strings[$k][$subk] = cleanLangString($_POST['entry'][$k][$subk], false);
1074
+						} elseif ($subv == 'remove') {
1075
+													$remove_strings[$k][] = $subk;
1076
+						} elseif ($subv == 'add' && isset($_POST['entry'][$k][$subk]))
1044 1077
 						{
1045 1078
 							$add_strings[$k][$subk] = array(
1046 1079
 								'group' => isset($_POST['grp'][$k]) ? $_POST['grp'][$k] : 'txt',
@@ -1076,8 +1109,9 @@  discard block
 block discarded – undo
1076 1109
 			foreach ($allows_add_remove[$file_id]['add'] as $var_group)
1077 1110
 			{
1078 1111
 				$group = !empty($special_groups[$file_id][$var_group]) ? $special_groups[$file_id][$var_group] : $var_group;
1079
-				if (in_array($var_group, $allows_add_remove[$file_id]['add']))
1080
-					$context['can_add_lang_entry'][$group] = true;
1112
+				if (in_array($var_group, $allows_add_remove[$file_id]['add'])) {
1113
+									$context['can_add_lang_entry'][$group] = true;
1114
+				}
1081 1115
 			}
1082 1116
 		}
1083 1117
 
@@ -1115,15 +1149,17 @@  discard block
 block discarded – undo
1115 1149
 		foreach ($entries as $entryKey => $entryValue)
1116 1150
 		{
1117 1151
 			// Ignore some things we set separately.
1118
-			if (in_array($entryKey, array_keys($primary_settings)))
1119
-				continue;
1152
+			if (in_array($entryKey, array_keys($primary_settings))) {
1153
+							continue;
1154
+			}
1120 1155
 
1121 1156
 			// These are arrays that need breaking out.
1122 1157
 			if (strpos($entryValue['entry'], 'array(') === 0 && strpos($entryValue['entry'], ')', -1) === strlen($entryValue['entry']) - 1)
1123 1158
 			{
1124 1159
 				// No, you may not use multidimensional arrays of $txt strings. Madness stalks that path.
1125
-				if (isset($entryValue['subkey']))
1126
-					continue;
1160
+				if (isset($entryValue['subkey'])) {
1161
+									continue;
1162
+				}
1127 1163
 
1128 1164
 				// Trim off the array construct bits.
1129 1165
 				$entryValue['entry'] = substr($entryValue['entry'], strpos($entryValue['entry'], 'array(') + 6, -1);
@@ -1166,8 +1202,9 @@  discard block
 block discarded – undo
1166 1202
 
1167 1203
 					/x' . ($context['utf8'] ? 'u' : ''), $entryValue['entry'], $matches);
1168 1204
 
1169
-				if (empty($m))
1170
-					continue;
1205
+				if (empty($m)) {
1206
+									continue;
1207
+				}
1171 1208
 
1172 1209
 				$entryValue['entry'] = $matches[0];
1173 1210
 
@@ -1184,19 +1221,21 @@  discard block
 block discarded – undo
1184 1221
 					{
1185 1222
 						$subKey = trim($matches[1], '\'"');
1186 1223
 
1187
-						if (ctype_digit($subKey))
1188
-							$cur_index = $subKey;
1224
+						if (ctype_digit($subKey)) {
1225
+													$cur_index = $subKey;
1226
+						}
1189 1227
 
1190 1228
 						$subValue = trim(substr($subValue, strpos($subValue, '=>') + 2));
1229
+					} else {
1230
+											$subKey = $cur_index++;
1191 1231
 					}
1192
-					else
1193
-						$subKey = $cur_index++;
1194 1232
 
1195 1233
 					// Clean up some bits.
1196
-					if (strpos($subValue, '\'') === 0)
1197
-						$subValue = trim($subValue, '\'');
1198
-					elseif (strpos($subValue, '"') === 0)
1199
-						$subValue = trim($subValue, '"');
1234
+					if (strpos($subValue, '\'') === 0) {
1235
+											$subValue = trim($subValue, '\'');
1236
+					} elseif (strpos($subValue, '"') === 0) {
1237
+											$subValue = trim($subValue, '"');
1238
+					}
1200 1239
 
1201 1240
 					// Can we save?
1202 1241
 					if (isset($save_strings[$entryKey][$subKey]))
@@ -1205,11 +1244,13 @@  discard block
 block discarded – undo
1205 1244
 						$save_cache['enabled'] = true;
1206 1245
 					}
1207 1246
 					// Should we remove this one?
1208
-					elseif (isset($remove_strings[$entryKey]) && in_array($subKey, $remove_strings[$entryKey]) && $entryValue['can_remove'])
1209
-						$save_cache['enabled'] = true;
1247
+					elseif (isset($remove_strings[$entryKey]) && in_array($subKey, $remove_strings[$entryKey]) && $entryValue['can_remove']) {
1248
+											$save_cache['enabled'] = true;
1249
+					}
1210 1250
 					// Just keep this one as it is
1211
-					else
1212
-						$save_cache['entries'][$subKey] = $subValue;
1251
+					else {
1252
+											$save_cache['entries'][$subKey] = $subValue;
1253
+					}
1213 1254
 
1214 1255
 					$context['file_entries'][$entryValue['group']][] = array(
1215 1256
 						'key' => $entryKey,
@@ -1223,15 +1264,17 @@  discard block
 block discarded – undo
1223 1264
 				// Should we add a new string to this array?
1224 1265
 				if (!empty($context['can_add_lang_entry'][$entryValue['type']]) && isset($add_strings[$entryKey]))
1225 1266
 				{
1226
-					foreach ($add_strings[$entryKey] as $string_key => $string_val)
1227
-						$save_cache['entries'][$string_key] = strtr($string_val['string'], array('\'' => ''));
1267
+					foreach ($add_strings[$entryKey] as $string_key => $string_val) {
1268
+											$save_cache['entries'][$string_key] = strtr($string_val['string'], array('\'' => ''));
1269
+					}
1228 1270
 
1229 1271
 					$save_cache['enabled'] = true;
1230 1272
 
1231 1273
 					// Make sure we don't add this again as an independent line
1232 1274
 					unset($add_strings[$entryKey][$string_key]);
1233
-					if (empty($add_strings[$entryKey]))
1234
-						unset($add_strings[$entryKey]);
1275
+					if (empty($add_strings[$entryKey])) {
1276
+											unset($add_strings[$entryKey]);
1277
+					}
1235 1278
 				}
1236 1279
 
1237 1280
 
@@ -1248,9 +1291,9 @@  discard block
 block discarded – undo
1248 1291
 						{
1249 1292
 							$items[] = $k2 . ' => \'' . $v2 . '\'';
1250 1293
 							$cur_index = $k2;
1294
+						} else {
1295
+													$items[] = '\'' . $v2 . '\'';
1251 1296
 						}
1252
-						else
1253
-							$items[] = '\'' . $v2 . '\'';
1254 1297
 
1255 1298
 						$cur_index++;
1256 1299
 					}
@@ -1267,8 +1310,9 @@  discard block
 block discarded – undo
1267 1310
 				// Saving?
1268 1311
 				if (isset($save_strings[$entryValue['key']][$entryValue['subkey']]) && $save_strings[$entryValue['key']][$entryValue['subkey']] != $entryValue['entry'])
1269 1312
 				{
1270
-					if ($save_strings[$entryValue['key']][$entryValue['subkey']] == '')
1271
-						$save_strings[$entryValue['key']][$entryValue['subkey']] = '\'\'';
1313
+					if ($save_strings[$entryValue['key']][$entryValue['subkey']] == '') {
1314
+											$save_strings[$entryValue['key']][$entryValue['subkey']] = '\'\'';
1315
+					}
1272 1316
 
1273 1317
 					// Preserve subkey as either digit or string
1274 1318
 					$subKey = ctype_digit($entryValue['subkey']) ? $entryValue['subkey'] : '\'' . $entryValue['subkey'] . '\'';
@@ -1309,8 +1353,9 @@  discard block
 block discarded – undo
1309 1353
 				if (isset($save_strings[$entryValue['key']]) && $save_strings[$entryValue['key']] != $entryValue['entry'])
1310 1354
 				{
1311 1355
 					// @todo Fix this properly.
1312
-					if ($save_strings[$entryValue['key']] == '')
1313
-						$save_strings[$entryValue['key']] = '\'\'';
1356
+					if ($save_strings[$entryValue['key']] == '') {
1357
+											$save_strings[$entryValue['key']] = '\'\'';
1358
+					}
1314 1359
 
1315 1360
 					// Set the new value.
1316 1361
 					$entryValue['entry'] = $save_strings[$entryValue['key']];
@@ -1353,8 +1398,9 @@  discard block
 block discarded – undo
1353 1398
 				{
1354 1399
 					$type = isset($special_types[$string_val['group']]) ? $special_types[$string_val['group']] : $string_val['group'];
1355 1400
 
1356
-					if (empty($context['can_add_lang_entry'][$type]))
1357
-						continue;
1401
+					if (empty($context['can_add_lang_entry'][$type])) {
1402
+											continue;
1403
+					}
1358 1404
 
1359 1405
 					$final_saves[$string_key] = array(
1360 1406
 						'find' => "\s*\?".'>$',
@@ -1369,8 +1415,9 @@  discard block
 block discarded – undo
1369 1415
 					{
1370 1416
 						$type = isset($special_types[$substring_val['group']]) ? $special_types[$substring_val['group']] : $substring_val['group'];
1371 1417
 
1372
-						if (empty($context['can_add_lang_entry'][$type]))
1373
-							continue;
1418
+						if (empty($context['can_add_lang_entry'][$type])) {
1419
+													continue;
1420
+						}
1374 1421
 
1375 1422
 						$subKey = ctype_digit(trim($substring_key, '\'')) ? trim($substring_key, '\'') : '\'' . $substring_key . '\'';
1376 1423
 
@@ -1393,10 +1440,11 @@  discard block
 block discarded – undo
1393 1440
 
1394 1441
 			foreach ($final_saves as $save)
1395 1442
 			{
1396
-				if (!empty($save['is_regex']))
1397
-					$file_contents = preg_replace('~' . $save['find'] . '~' . ($context['utf8'] ? 'u' : ''), $save['replace'], $file_contents);
1398
-				else
1399
-					$file_contents = str_replace($save['find'], $save['replace'], $file_contents);
1443
+				if (!empty($save['is_regex'])) {
1444
+									$file_contents = preg_replace('~' . $save['find'] . '~' . ($context['utf8'] ? 'u' : ''), $save['replace'], $file_contents);
1445
+				} else {
1446
+									$file_contents = str_replace($save['find'], $save['replace'], $file_contents);
1447
+				}
1400 1448
 			}
1401 1449
 
1402 1450
 			// Save the actual changes.
@@ -1414,8 +1462,9 @@  discard block
 block discarded – undo
1414 1462
 			// Make sure the Add button has a place to show up.
1415 1463
 			foreach ($context['can_add_lang_entry'] as $group => $value)
1416 1464
 			{
1417
-				if (!isset($context['file_entries'][$group]))
1418
-					$context['file_entries'][$group] = array();
1465
+				if (!isset($context['file_entries'][$group])) {
1466
+									$context['file_entries'][$group] = array();
1467
+				}
1419 1468
 			}
1420 1469
 
1421 1470
 			addInlineJavaScript('
@@ -1507,8 +1556,9 @@  discard block
 block discarded – undo
1507 1556
 	}
1508 1557
 
1509 1558
 	// If we saved, redirect.
1510
-	if ($madeSave)
1511
-		redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id'] . (!empty($file_id) ? ';entries;tfid=' . $theme_id . rawurlencode('+') . $file_id : ''));
1559
+	if ($madeSave) {
1560
+			redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id'] . (!empty($file_id) ? ';entries;tfid=' . $theme_id . rawurlencode('+') . $file_id : ''));
1561
+	}
1512 1562
 
1513 1563
 	createToken('admin-mlang');
1514 1564
 }
@@ -1540,8 +1590,9 @@  discard block
 block discarded – undo
1540 1590
 				// Toggle the escape.
1541 1591
 				$is_escape = !$is_escape;
1542 1592
 				// If we're now escaped don't add this string.
1543
-				if ($is_escape)
1544
-					continue;
1593
+				if ($is_escape) {
1594
+									continue;
1595
+				}
1545 1596
 			}
1546 1597
 			// Special case - parsed string with line break etc?
1547 1598
 			elseif (($string{$i} == 'n' || $string{$i} == 't') && $in_string == 2 && $is_escape)
@@ -1558,11 +1609,13 @@  discard block
 block discarded – undo
1558 1609
 				if ($in_string != 2 && ($in_string != 1 || !$is_escape))
1559 1610
 				{
1560 1611
 					// Is it the end of a single quote string?
1561
-					if ($in_string == 1)
1562
-						$in_string = 0;
1612
+					if ($in_string == 1) {
1613
+											$in_string = 0;
1614
+					}
1563 1615
 					// Otherwise it's the start!
1564
-					else
1565
-						$in_string = 1;
1616
+					else {
1617
+											$in_string = 1;
1618
+					}
1566 1619
 
1567 1620
 					// Don't actually include this character!
1568 1621
 					continue;
@@ -1575,19 +1628,22 @@  discard block
 block discarded – undo
1575 1628
 				if ($in_string != 1 && ($in_string != 2 || !$is_escape))
1576 1629
 				{
1577 1630
 					// Is it the end of a double quote string?
1578
-					if ($in_string == 2)
1579
-						$in_string = 0;
1631
+					if ($in_string == 2) {
1632
+											$in_string = 0;
1633
+					}
1580 1634
 					// Otherwise it's the start!
1581
-					else
1582
-						$in_string = 2;
1635
+					else {
1636
+											$in_string = 2;
1637
+					}
1583 1638
 
1584 1639
 					// Don't actually include this character!
1585 1640
 					continue;
1586 1641
 				}
1587 1642
 			}
1588 1643
 			// A join/space outside of a string is simply removed.
1589
-			elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.'))
1590
-				continue;
1644
+			elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.')) {
1645
+							continue;
1646
+			}
1591 1647
 			// Start of a variable?
1592 1648
 			elseif ($in_string == 0 && $string{$i} == '$')
1593 1649
 			{
@@ -1621,8 +1677,7 @@  discard block
 block discarded – undo
1621 1677
 
1622 1678
 		// Unhtml then rehtml the whole thing!
1623 1679
 		$new_string = $smcFunc['htmlspecialchars'](un_htmlspecialchars($new_string));
1624
-	}
1625
-	else
1680
+	} else
1626 1681
 	{
1627 1682
 		// Keep track of what we're doing...
1628 1683
 		$in_string = 0;
@@ -1651,10 +1706,11 @@  discard block
 block discarded – undo
1651 1706
 				preg_match('~\{%([\$A-Za-z0-9\'\[\]_-]+)%\}~', substr($string, $i), $matches);
1652 1707
 				if (!empty($matches[1]))
1653 1708
 				{
1654
-					if ($in_string == 1)
1655
-						$new_string .= '\' . ';
1656
-					elseif ($new_string)
1657
-						$new_string .= ' . ';
1709
+					if ($in_string == 1) {
1710
+											$new_string .= '\' . ';
1711
+					} elseif ($new_string) {
1712
+											$new_string .= ' . ';
1713
+					}
1658 1714
 
1659 1715
 					$new_string .= $matches[1];
1660 1716
 					$i += strlen($matches[1]) + 3;
@@ -1667,8 +1723,9 @@  discard block
 block discarded – undo
1667 1723
 			elseif ($string{$i} == '<')
1668 1724
 			{
1669 1725
 				// Probably HTML?
1670
-				if ($string{$i + 1} != ' ')
1671
-					$in_html = true;
1726
+				if ($string{$i + 1} != ' ') {
1727
+									$in_html = true;
1728
+				}
1672 1729
 				// Assume we need an entity...
1673 1730
 				else
1674 1731
 				{
@@ -1680,8 +1737,9 @@  discard block
 block discarded – undo
1680 1737
 			elseif ($string{$i} == '>')
1681 1738
 			{
1682 1739
 				// Will it be HTML?
1683
-				if ($in_html)
1684
-					$in_html = false;
1740
+				if ($in_html) {
1741
+									$in_html = false;
1742
+				}
1685 1743
 				// Otherwise we need an entity...
1686 1744
 				else
1687 1745
 				{
@@ -1690,8 +1748,9 @@  discard block
 block discarded – undo
1690 1748
 				}
1691 1749
 			}
1692 1750
 			// Is it a slash? If so escape it...
1693
-			if ($string{$i} == '\\')
1694
-				$new_string .= '\\';
1751
+			if ($string{$i} == '\\') {
1752
+							$new_string .= '\\';
1753
+			}
1695 1754
 			// The infamous double quote?
1696 1755
 			elseif ($string{$i} == '"')
1697 1756
 			{
@@ -1714,10 +1773,11 @@  discard block
 block discarded – undo
1714 1773
 		}
1715 1774
 
1716 1775
 		// If we ended as a string then close it off.
1717
-		if ($in_string == 1)
1718
-			$new_string .= '\'';
1719
-		elseif ($in_string == 2)
1720
-			$new_string .= '"';
1776
+		if ($in_string == 1) {
1777
+					$new_string .= '\'';
1778
+		} elseif ($in_string == 2) {
1779
+					$new_string .= '"';
1780
+		}
1721 1781
 	}
1722 1782
 
1723 1783
 	return $new_string;
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 			'editlang' => array(
593 593
 				'header' => array(
594 594
 					'value' => '',
595
-				),'data' => array(
595
+				), 'data' => array(
596 596
 					'function' => function($rowData) use ($scripturl, $txt)
597 597
 					{
598 598
 						return sprintf('<a href="%1$s?action=admin;area=languages;sa=editlang;lid=%2$s" class="button">%3$s</a>', $scripturl, $rowData['id'], $txt['edit']);
@@ -1269,7 +1269,7 @@  discard block
 block discarded – undo
1269 1269
 					// Now create the string!
1270 1270
 					$final_saves[$entryKey] = array(
1271 1271
 						'find' => $entryValue['full'],
1272
-						'replace' => '// ' . implode("\n// ", explode("\n", rtrim($entryValue['full'], "\n")))  . "\n" . '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = array(' . implode(', ', $items) . ');' . $entryValue['cruft'],
1272
+						'replace' => '// ' . implode("\n// ", explode("\n", rtrim($entryValue['full'], "\n"))) . "\n" . '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = array(' . implode(', ', $items) . ');' . $entryValue['cruft'],
1273 1273
 					);
1274 1274
 				}
1275 1275
 			}
@@ -1291,7 +1291,7 @@  discard block
 block discarded – undo
1291 1291
 					// And save it
1292 1292
 					$final_saves[$entryKey] = array(
1293 1293
 						'find' => $entryValue['full'],
1294
-						'replace' => '// ' . implode("\n// ", explode("\n", rtrim($entryValue['full'], "\n")))  . "\n" . '$' . $entryValue['type'] . '[\'' . $entryValue['key'] . '\'][' . $subKey . '] = ' . $save_strings[$entryValue['key']][$entryValue['subkey']] . ';' . $entryValue['cruft'],
1294
+						'replace' => '// ' . implode("\n// ", explode("\n", rtrim($entryValue['full'], "\n"))) . "\n" . '$' . $entryValue['type'] . '[\'' . $entryValue['key'] . '\'][' . $subKey . '] = ' . $save_strings[$entryValue['key']][$entryValue['subkey']] . ';' . $entryValue['cruft'],
1295 1295
 					);
1296 1296
 				}
1297 1297
 
@@ -1301,7 +1301,7 @@  discard block
 block discarded – undo
1301 1301
 					$entryValue['entry'] = '\'\'';
1302 1302
 					$final_saves[$entryKey] = array(
1303 1303
 						'find' => $entryValue['full'],
1304
-						'replace' => '// ' . implode("\n// ", explode("\n", rtrim($entryValue['full'], "\n")))  . "\n",
1304
+						'replace' => '// ' . implode("\n// ", explode("\n", rtrim($entryValue['full'], "\n"))) . "\n",
1305 1305
 					);
1306 1306
 				}
1307 1307
 
@@ -1329,7 +1329,7 @@  discard block
 block discarded – undo
1329 1329
 					// And we know what to save now!
1330 1330
 					$final_saves[$entryKey] = array(
1331 1331
 						'find' => $entryValue['full'],
1332
-						'replace' => '// ' . implode("\n// ", explode("\n", rtrim($entryValue['full'], "\n")))  . "\n" . '$' . $entryValue['type'] . '[\'' . $entryValue['key'] . '\'] = ' . $save_strings[$entryValue['key']] . ';' . $entryValue['cruft'],
1332
+						'replace' => '// ' . implode("\n// ", explode("\n", rtrim($entryValue['full'], "\n"))) . "\n" . '$' . $entryValue['type'] . '[\'' . $entryValue['key'] . '\'] = ' . $save_strings[$entryValue['key']] . ';' . $entryValue['cruft'],
1333 1333
 					);
1334 1334
 				}
1335 1335
 				// Remove this entry only if it is allowed
@@ -1338,7 +1338,7 @@  discard block
 block discarded – undo
1338 1338
 					$entryValue['entry'] = '\'\'';
1339 1339
 					$final_saves[$entryKey] = array(
1340 1340
 						'find' => $entryValue['full'],
1341
-						'replace' => '// ' . implode("\n// ", explode("\n", rtrim($entryValue['full'], "\n")))  . "\n",
1341
+						'replace' => '// ' . implode("\n// ", explode("\n", rtrim($entryValue['full'], "\n"))) . "\n",
1342 1342
 					);
1343 1343
 				}
1344 1344
 
@@ -1369,8 +1369,8 @@  discard block
 block discarded – undo
1369 1369
 						continue;
1370 1370
 
1371 1371
 					$final_saves[$string_key] = array(
1372
-						'find' => "\s*\?".'>$',
1373
-						'replace' => "\n\$" . $type . '[\'' . $string_key . '\'] = ' . $string_val['string'] . ';' . "\n\n?".'>',
1372
+						'find' => "\s*\?" . '>$',
1373
+						'replace' => "\n\$" . $type . '[\'' . $string_key . '\'] = ' . $string_val['string'] . ';' . "\n\n?" . '>',
1374 1374
 						'is_regex' => true,
1375 1375
 					);
1376 1376
 				}
@@ -1387,8 +1387,8 @@  discard block
 block discarded – undo
1387 1387
 						$subKey = ctype_digit(trim($substring_key, '\'')) ? trim($substring_key, '\'') : '\'' . $substring_key . '\'';
1388 1388
 
1389 1389
 						$final_saves[$string_key . '[' . $substring_key . ']'] = array(
1390
-							'find' => "\s*\?".'>$',
1391
-							'replace' => "\n\$" . $type . '[\'' . $string_key . '\'][' . $subKey . '] = ' . $substring_val['string'] . ';' . "\n\n?".'>',
1390
+							'find' => "\s*\?" . '>$',
1391
+							'replace' => "\n\$" . $type . '[\'' . $string_key . '\'][' . $subKey . '] = ' . $substring_val['string'] . ';' . "\n\n?" . '>',
1392 1392
 							'is_regex' => true,
1393 1393
 						);
1394 1394
 					}
Please login to merge, or discard this patch.
Sources/Subs-Editor.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1112,7 +1112,7 @@  discard block
 block discarded – undo
1112 1112
 		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1113 1113
 
1114 1114
 	// Need to sort the tags by name length.
1115
-	uksort($valid_tags, function ($a, $b) {
1115
+	uksort($valid_tags, function($a, $b) {
1116 1116
 		return strlen($a) < strlen($b) ? 1 : -1;
1117 1117
 	});
1118 1118
 
@@ -1980,7 +1980,7 @@  discard block
 block discarded – undo
1980 1980
 		}
1981 1981
 
1982 1982
 		// Set proper extensions; do this post caching so cache doesn't become extension-specific
1983
-		array_walk_recursive($context['smileys'], function (&$filename, $key)
1983
+		array_walk_recursive($context['smileys'], function(&$filename, $key)
1984 1984
 			{
1985 1985
 				global $context, $user_info, $modSettings;
1986 1986
 				if ($key == 'filename')
Please login to merge, or discard this patch.
Braces   +408 added lines, -307 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
  * As of SMF 2.1, this is unused. But it is available if any mod wants to use it.
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 {
31 32
 	global $modSettings;
32 33
 
33
-	if (!$compat_mode)
34
-		return $text;
34
+	if (!$compat_mode) {
35
+			return $text;
36
+	}
35 37
 
36 38
 	// Turn line breaks back into br's.
37 39
 	$text = strtr($text, array("\r" => '', "\n" => '<br>'));
@@ -48,8 +50,9 @@  discard block
 block discarded – undo
48 50
 			for ($i = 0, $n = count($parts); $i < $n; $i++)
49 51
 			{
50 52
 				// Value of 2 means we're inside the tag.
51
-				if ($i % 4 == 2)
52
-					$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
53
+				if ($i % 4 == 2) {
54
+									$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
55
+				}
53 56
 			}
54 57
 			// Put our humpty dumpty message back together again.
55 58
 			$text = implode('', $parts);
@@ -104,8 +107,9 @@  discard block
 block discarded – undo
104 107
 	$text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text);
105 108
 
106 109
 	// Safari/webkit wraps lines in Wysiwyg in <div>'s.
107
-	if (isBrowser('webkit'))
108
-		$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
110
+	if (isBrowser('webkit')) {
111
+			$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
112
+	}
109 113
 
110 114
 	// If there's a trailing break get rid of it - Firefox tends to add one.
111 115
 	$text = preg_replace('~<br\s?/?' . '>$~i', '', $text);
@@ -120,8 +124,9 @@  discard block
 block discarded – undo
120 124
 		for ($i = 0, $n = count($parts); $i < $n; $i++)
121 125
 		{
122 126
 			// Value of 2 means we're inside the tag.
123
-			if ($i % 4 == 2)
124
-				$parts[$i] = strip_tags($parts[$i]);
127
+			if ($i % 4 == 2) {
128
+							$parts[$i] = strip_tags($parts[$i]);
129
+			}
125 130
 		}
126 131
 
127 132
 		$text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>'));
@@ -147,18 +152,19 @@  discard block
 block discarded – undo
147 152
 			{
148 153
 				$found = array_search($file, $smileysto);
149 154
 				// Note the weirdness here is to stop double spaces between smileys.
150
-				if ($found)
151
-					$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
152
-				else
153
-					$matches[1][$k] = '';
155
+				if ($found) {
156
+									$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
157
+				} else {
158
+									$matches[1][$k] = '';
159
+				}
154 160
 			}
155
-		}
156
-		else
161
+		} else
157 162
 		{
158 163
 			// Load all the smileys.
159 164
 			$names = array();
160
-			foreach ($matches[1] as $file)
161
-				$names[] = $file;
165
+			foreach ($matches[1] as $file) {
166
+							$names[] = $file;
167
+			}
162 168
 			$names = array_unique($names);
163 169
 
164 170
 			if (!empty($names))
@@ -172,13 +178,15 @@  discard block
 block discarded – undo
172 178
 					)
173 179
 				);
174 180
 				$mappings = array();
175
-				while ($row = $smcFunc['db_fetch_assoc']($request))
176
-					$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
181
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
182
+									$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
183
+				}
177 184
 				$smcFunc['db_free_result']($request);
178 185
 
179
-				foreach ($matches[1] as $k => $file)
180
-					if (isset($mappings[$file]))
186
+				foreach ($matches[1] as $k => $file) {
187
+									if (isset($mappings[$file]))
181 188
 						$matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#';
189
+				}
182 190
 			}
183 191
 		}
184 192
 
@@ -190,8 +198,9 @@  discard block
 block discarded – undo
190 198
 	}
191 199
 
192 200
 	// Only try to buy more time if the client didn't quit.
193
-	if (connection_aborted() && $context['server']['is_apache'])
194
-		@apache_reset_timeout();
201
+	if (connection_aborted() && $context['server']['is_apache']) {
202
+			@apache_reset_timeout();
203
+	}
195 204
 
196 205
 	$parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
197 206
 	$replacement = '';
@@ -202,9 +211,9 @@  discard block
 block discarded – undo
202 211
 		if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1)
203 212
 		{
204 213
 			// If it's being closed instantly, we can't deal with it...yet.
205
-			if ($matches[5] === '/')
206
-				continue;
207
-			else
214
+			if ($matches[5] === '/') {
215
+							continue;
216
+			} else
208 217
 			{
209 218
 				// Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.)
210 219
 				$styles = explode(';', strtr($matches[3], array('&quot;' => '')));
@@ -220,8 +229,9 @@  discard block
 block discarded – undo
220 229
 					$clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':'));
221 230
 
222 231
 					// Something like 'font-weight: bold' is expected here.
223
-					if (strpos($clean_type_value_pair, ':') === false)
224
-						continue;
232
+					if (strpos($clean_type_value_pair, ':') === false) {
233
+											continue;
234
+					}
225 235
 
226 236
 					// Capture the elements of a single style item (e.g. 'font-weight' and 'bold').
227 237
 					list ($style_type, $style_value) = explode(':', $type_value_pair);
@@ -243,8 +253,7 @@  discard block
 block discarded – undo
243 253
 							{
244 254
 								$curCloseTags .= '[/u]';
245 255
 								$replacement .= '[u]';
246
-							}
247
-							elseif ($style_value == 'line-through')
256
+							} elseif ($style_value == 'line-through')
248 257
 							{
249 258
 								$curCloseTags .= '[/s]';
250 259
 								$replacement .= '[s]';
@@ -256,13 +265,11 @@  discard block
 block discarded – undo
256 265
 							{
257 266
 								$curCloseTags .= '[/left]';
258 267
 								$replacement .= '[left]';
259
-							}
260
-							elseif ($style_value == 'center')
268
+							} elseif ($style_value == 'center')
261 269
 							{
262 270
 								$curCloseTags .= '[/center]';
263 271
 								$replacement .= '[center]';
264
-							}
265
-							elseif ($style_value == 'right')
272
+							} elseif ($style_value == 'right')
266 273
 							{
267 274
 								$curCloseTags .= '[/right]';
268 275
 								$replacement .= '[right]';
@@ -284,8 +291,9 @@  discard block
 block discarded – undo
284 291
 
285 292
 						case 'font-size':
286 293
 							// Sometimes people put decimals where decimals should not be.
287
-							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1)
288
-								$style_value = $dec_matches[1] . $dec_matches[2];
294
+							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) {
295
+															$style_value = $dec_matches[1] . $dec_matches[2];
296
+							}
289 297
 
290 298
 							$curCloseTags .= '[/size]';
291 299
 							$replacement .= '[size=' . $style_value . ']';
@@ -293,8 +301,9 @@  discard block
 block discarded – undo
293 301
 
294 302
 						case 'font-family':
295 303
 							// Only get the first freaking font if there's a list!
296
-							if (strpos($style_value, ',') !== false)
297
-								$style_value = substr($style_value, 0, strpos($style_value, ','));
304
+							if (strpos($style_value, ',') !== false) {
305
+															$style_value = substr($style_value, 0, strpos($style_value, ','));
306
+							}
298 307
 
299 308
 							$curCloseTags .= '[/font]';
300 309
 							$replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']';
@@ -303,13 +312,15 @@  discard block
 block discarded – undo
303 312
 						// This is a hack for images with dimensions embedded.
304 313
 						case 'width':
305 314
 						case 'height':
306
-							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1)
307
-								$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
315
+							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) {
316
+															$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
317
+							}
308 318
 						break;
309 319
 
310 320
 						case 'list-style-type':
311
-							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1)
312
-								$extra_attr .= ' listtype="' . $listType[0] . '"';
321
+							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) {
322
+															$extra_attr .= ' listtype="' . $listType[0] . '"';
323
+							}
313 324
 						break;
314 325
 					}
315 326
 				}
@@ -322,18 +333,17 @@  discard block
 block discarded – undo
322 333
 				}
323 334
 
324 335
 				// If there's something that still needs closing, push it to the stack.
325
-				if (!empty($curCloseTags))
326
-					array_push($stack, array(
336
+				if (!empty($curCloseTags)) {
337
+									array_push($stack, array(
327 338
 							'element' => strtolower($curElement),
328 339
 							'closeTags' => $curCloseTags
329 340
 						)
330 341
 					);
331
-				elseif (!empty($extra_attr))
332
-					$replacement .= $precedingStyle . $extra_attr . $afterStyle;
342
+				} elseif (!empty($extra_attr)) {
343
+									$replacement .= $precedingStyle . $extra_attr . $afterStyle;
344
+				}
333 345
 			}
334
-		}
335
-
336
-		elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
346
+		} elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
337 347
 		{
338 348
 			// Is this the element that we've been waiting for to be closed?
339 349
 			if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element'])
@@ -343,28 +353,32 @@  discard block
 block discarded – undo
343 353
 			}
344 354
 
345 355
 			// Must've been something else.
346
-			else
347
-				$replacement .= $part;
356
+			else {
357
+							$replacement .= $part;
358
+			}
348 359
 		}
349 360
 		// In all other cases, just add the part to the replacement.
350
-		else
351
-			$replacement .= $part;
361
+		else {
362
+					$replacement .= $part;
363
+		}
352 364
 	}
353 365
 
354 366
 	// Now put back the replacement in the text.
355 367
 	$text = $replacement;
356 368
 
357 369
 	// We are not finished yet, request more time.
358
-	if (connection_aborted() && $context['server']['is_apache'])
359
-		@apache_reset_timeout();
370
+	if (connection_aborted() && $context['server']['is_apache']) {
371
+			@apache_reset_timeout();
372
+	}
360 373
 
361 374
 	// Let's pull out any legacy alignments.
362 375
 	while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1)
363 376
 	{
364 377
 		// Find the position in the text of this tag over again.
365 378
 		$start_pos = strpos($text, $matches[0]);
366
-		if ($start_pos === false)
367
-			break;
379
+		if ($start_pos === false) {
380
+					break;
381
+		}
368 382
 
369 383
 		// End tag?
370 384
 		if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false)
@@ -378,8 +392,7 @@  discard block
 block discarded – undo
378 392
 
379 393
 			// Put the tags back into the body.
380 394
 			$text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos);
381
-		}
382
-		else
395
+		} else
383 396
 		{
384 397
 			// Just get rid of this evil tag.
385 398
 			$text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0]));
@@ -392,8 +405,9 @@  discard block
 block discarded – undo
392 405
 		// Find the position of this again.
393 406
 		$start_pos = strpos($text, $matches[0]);
394 407
 		$end_pos = false;
395
-		if ($start_pos === false)
396
-			break;
408
+		if ($start_pos === false) {
409
+					break;
410
+		}
397 411
 
398 412
 		// This must have an end tag - and we must find the right one.
399 413
 		$lower_text = strtolower($text);
@@ -426,8 +440,9 @@  discard block
 block discarded – undo
426 440
 				break;
427 441
 			}
428 442
 		}
429
-		if ($end_pos === false)
430
-			break;
443
+		if ($end_pos === false) {
444
+					break;
445
+		}
431 446
 
432 447
 		// Now work out what the attributes are.
433 448
 		$attribs = fetchTagAttributes($matches[1]);
@@ -441,11 +456,11 @@  discard block
 block discarded – undo
441 456
 				$v = (int) trim($v);
442 457
 				$v = empty($v) ? 1 : $v;
443 458
 				$tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]');
459
+			} elseif ($s == 'face') {
460
+							$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
461
+			} elseif ($s == 'color') {
462
+							$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
444 463
 			}
445
-			elseif ($s == 'face')
446
-				$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
447
-			elseif ($s == 'color')
448
-				$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
449 464
 		}
450 465
 
451 466
 		// As before add in our tags.
@@ -453,8 +468,9 @@  discard block
 block discarded – undo
453 468
 		foreach ($tags as $tag)
454 469
 		{
455 470
 			$before .= $tag[0];
456
-			if (isset($tag[1]))
457
-				$after = $tag[1] . $after;
471
+			if (isset($tag[1])) {
472
+							$after = $tag[1] . $after;
473
+			}
458 474
 		}
459 475
 
460 476
 		// Remove the tag so it's never checked again.
@@ -465,8 +481,9 @@  discard block
 block discarded – undo
465 481
 	}
466 482
 
467 483
 	// Almost there, just a little more time.
468
-	if (connection_aborted() && $context['server']['is_apache'])
469
-		@apache_reset_timeout();
484
+	if (connection_aborted() && $context['server']['is_apache']) {
485
+			@apache_reset_timeout();
486
+	}
470 487
 
471 488
 	if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1)
472 489
 	{
@@ -522,12 +539,13 @@  discard block
 block discarded – undo
522 539
 						{
523 540
 							$inList = true;
524 541
 
525
-							if ($tag === 'ol')
526
-								$listType = 'decimal';
527
-							elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1)
528
-								$listType = $listTypeMapping[$match[1]];
529
-							else
530
-								$listType = null;
542
+							if ($tag === 'ol') {
543
+															$listType = 'decimal';
544
+							} elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) {
545
+															$listType = $listTypeMapping[$match[1]];
546
+							} else {
547
+															$listType = null;
548
+							}
531 549
 
532 550
 							$listDepth++;
533 551
 
@@ -591,9 +609,7 @@  discard block
 block discarded – undo
591 609
 							$parts[$i + 1] = '';
592 610
 							$parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]';
593 611
 							$parts[$i + 3] = '';
594
-						}
595
-
596
-						else
612
+						} else
597 613
 						{
598 614
 							// We're in a list item.
599 615
 							if ($listDepth > 0)
@@ -630,9 +646,7 @@  discard block
 block discarded – undo
630 646
 							$parts[$i + 1] = '';
631 647
 							$parts[$i + 2] = '';
632 648
 							$parts[$i + 3] = '';
633
-						}
634
-
635
-						else
649
+						} else
636 650
 						{
637 651
 							// Remove the trailing breaks from the list item.
638 652
 							$parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]);
@@ -670,8 +684,9 @@  discard block
 block discarded – undo
670 684
 			$text .= str_repeat("\t", $listDepth) . '[/list]';
671 685
 		}
672 686
 
673
-		for ($i = $listDepth; $i > 0; $i--)
674
-			$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
687
+		for ($i = $listDepth; $i > 0; $i--) {
688
+					$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
689
+		}
675 690
 	}
676 691
 
677 692
 	// I love my own image...
@@ -679,8 +694,9 @@  discard block
 block discarded – undo
679 694
 	{
680 695
 		// Find the position of the image.
681 696
 		$start_pos = strpos($text, $matches[0]);
682
-		if ($start_pos === false)
683
-			break;
697
+		if ($start_pos === false) {
698
+					break;
699
+		}
684 700
 		$end_pos = $start_pos + strlen($matches[0]);
685 701
 
686 702
 		$params = '';
@@ -689,12 +705,13 @@  discard block
 block discarded – undo
689 705
 		$attrs = fetchTagAttributes($matches[1]);
690 706
 		foreach ($attrs as $attrib => $value)
691 707
 		{
692
-			if (in_array($attrib, array('width', 'height')))
693
-				$params .= ' ' . $attrib . '=' . (int) $value;
694
-			elseif ($attrib == 'alt' && trim($value) != '')
695
-				$params .= ' alt=' . trim($value);
696
-			elseif ($attrib == 'src')
697
-				$src = trim($value);
708
+			if (in_array($attrib, array('width', 'height'))) {
709
+							$params .= ' ' . $attrib . '=' . (int) $value;
710
+			} elseif ($attrib == 'alt' && trim($value) != '') {
711
+							$params .= ' alt=' . trim($value);
712
+			} elseif ($attrib == 'src') {
713
+							$src = trim($value);
714
+			}
698 715
 		}
699 716
 
700 717
 		$tag = '';
@@ -705,10 +722,11 @@  discard block
 block discarded – undo
705 722
 			{
706 723
 				$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
707 724
 
708
-				if (substr($src, 0, 1) === '/')
709
-					$src = $baseURL . $src;
710
-				else
711
-					$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
725
+				if (substr($src, 0, 1) === '/') {
726
+									$src = $baseURL . $src;
727
+				} else {
728
+									$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
729
+				}
712 730
 			}
713 731
 
714 732
 			$tag = '[img' . $params . ']' . $src . '[/img]';
@@ -886,20 +904,23 @@  discard block
 block discarded – undo
886 904
 		},
887 905
 	);
888 906
 
889
-	foreach ($tags as $tag => $replace)
890
-		$text = preg_replace_callback($tag, $replace, $text);
907
+	foreach ($tags as $tag => $replace) {
908
+			$text = preg_replace_callback($tag, $replace, $text);
909
+	}
891 910
 
892 911
 	// Please give us just a little more time.
893
-	if (connection_aborted() && $context['server']['is_apache'])
894
-		@apache_reset_timeout();
912
+	if (connection_aborted() && $context['server']['is_apache']) {
913
+			@apache_reset_timeout();
914
+	}
895 915
 
896 916
 	// What about URL's - the pain in the ass of the tag world.
897 917
 	while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1)
898 918
 	{
899 919
 		// Find the position of the URL.
900 920
 		$start_pos = strpos($text, $matches[0]);
901
-		if ($start_pos === false)
902
-			break;
921
+		if ($start_pos === false) {
922
+					break;
923
+		}
903 924
 		$end_pos = $start_pos + strlen($matches[0]);
904 925
 
905 926
 		$tag_type = 'url';
@@ -913,8 +934,9 @@  discard block
 block discarded – undo
913 934
 				$href = trim($value);
914 935
 
915 936
 				// Are we dealing with an FTP link?
916
-				if (preg_match('~^ftps?://~', $href) === 1)
917
-					$tag_type = 'ftp';
937
+				if (preg_match('~^ftps?://~', $href) === 1) {
938
+									$tag_type = 'ftp';
939
+				}
918 940
 
919 941
 				// Or is this a link to an email address?
920 942
 				elseif (substr($href, 0, 7) == 'mailto:')
@@ -928,28 +950,31 @@  discard block
 block discarded – undo
928 950
 				{
929 951
 					$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
930 952
 
931
-					if (substr($href, 0, 1) === '/')
932
-						$href = $baseURL . $href;
933
-					else
934
-						$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
953
+					if (substr($href, 0, 1) === '/') {
954
+											$href = $baseURL . $href;
955
+					} else {
956
+											$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
957
+					}
935 958
 				}
936 959
 			}
937 960
 
938 961
 			// External URL?
939 962
 			if ($attrib == 'target' && $tag_type == 'url')
940 963
 			{
941
-				if (trim($value) == '_blank')
942
-					$tag_type == 'iurl';
964
+				if (trim($value) == '_blank') {
965
+									$tag_type == 'iurl';
966
+				}
943 967
 			}
944 968
 		}
945 969
 
946 970
 		$tag = '';
947 971
 		if ($href != '')
948 972
 		{
949
-			if ($matches[2] == $href)
950
-				$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
951
-			else
952
-				$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
973
+			if ($matches[2] == $href) {
974
+							$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
975
+			} else {
976
+							$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
977
+			}
953 978
 		}
954 979
 
955 980
 		// Replace the tag
@@ -985,17 +1010,18 @@  discard block
 block discarded – undo
985 1010
 		// We're either moving from the key to the attribute or we're in a string and this is fine.
986 1011
 		if ($text[$i] == '=')
987 1012
 		{
988
-			if ($tag_state == 0)
989
-				$tag_state = 1;
990
-			elseif ($tag_state == 2)
991
-				$value .= '=';
1013
+			if ($tag_state == 0) {
1014
+							$tag_state = 1;
1015
+			} elseif ($tag_state == 2) {
1016
+							$value .= '=';
1017
+			}
992 1018
 		}
993 1019
 		// A space is either moving from an attribute back to a potential key or in a string is fine.
994 1020
 		elseif ($text[$i] == ' ')
995 1021
 		{
996
-			if ($tag_state == 2)
997
-				$value .= ' ';
998
-			elseif ($tag_state == 1)
1022
+			if ($tag_state == 2) {
1023
+							$value .= ' ';
1024
+			} elseif ($tag_state == 1)
999 1025
 			{
1000 1026
 				$attribs[$key] = $value;
1001 1027
 				$key = $value = '';
@@ -1006,24 +1032,27 @@  discard block
 block discarded – undo
1006 1032
 		elseif ($text[$i] == '"')
1007 1033
 		{
1008 1034
 			// Must be either going into or out of a string.
1009
-			if ($tag_state == 1)
1010
-				$tag_state = 2;
1011
-			else
1012
-				$tag_state = 1;
1035
+			if ($tag_state == 1) {
1036
+							$tag_state = 2;
1037
+			} else {
1038
+							$tag_state = 1;
1039
+			}
1013 1040
 		}
1014 1041
 		// Otherwise it's fine.
1015 1042
 		else
1016 1043
 		{
1017
-			if ($tag_state == 0)
1018
-				$key .= $text[$i];
1019
-			else
1020
-				$value .= $text[$i];
1044
+			if ($tag_state == 0) {
1045
+							$key .= $text[$i];
1046
+			} else {
1047
+							$value .= $text[$i];
1048
+			}
1021 1049
 		}
1022 1050
 	}
1023 1051
 
1024 1052
 	// Anything left?
1025
-	if ($key != '' && $value != '')
1026
-		$attribs[$key] = $value;
1053
+	if ($key != '' && $value != '') {
1054
+			$attribs[$key] = $value;
1055
+	}
1027 1056
 
1028 1057
 	return $attribs;
1029 1058
 }
@@ -1039,8 +1068,9 @@  discard block
 block discarded – undo
1039 1068
 	global $modSettings;
1040 1069
 
1041 1070
 	// Don't care about the texts that are too short.
1042
-	if (strlen($text) < 3)
1043
-		return $text;
1071
+	if (strlen($text) < 3) {
1072
+			return $text;
1073
+	}
1044 1074
 
1045 1075
 	// A list of tags that's disabled by the admin.
1046 1076
 	$disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC'])));
@@ -1051,10 +1081,12 @@  discard block
 block discarded – undo
1051 1081
 	$self_closing_tags = array();
1052 1082
 	foreach ($all_tags as $tag)
1053 1083
 	{
1054
-		if (!isset($disabled[$tag['tag']]))
1055
-			$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1056
-		if (isset($tag['type']) && $tag['type'] == 'closed')
1057
-			$self_closing_tags[] = $tag['tag'];
1084
+		if (!isset($disabled[$tag['tag']])) {
1085
+					$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1086
+		}
1087
+		if (isset($tag['type']) && $tag['type'] == 'closed') {
1088
+					$self_closing_tags[] = $tag['tag'];
1089
+		}
1058 1090
 	}
1059 1091
 
1060 1092
 	// Right - we're going to start by going through the whole lot to make sure we don't have align stuff crossed as this happens load and is stupid!
@@ -1081,16 +1113,19 @@  discard block
 block discarded – undo
1081 1113
 				$tagName = substr($match, $isClosingTag ? 2 : 1, -1);
1082 1114
 
1083 1115
 				// We're closing the exact same tag that we opened.
1084
-				if ($isClosingTag && $insideTag === $tagName)
1085
-					$insideTag = null;
1116
+				if ($isClosingTag && $insideTag === $tagName) {
1117
+									$insideTag = null;
1118
+				}
1086 1119
 
1087 1120
 				// We're opening a tag and we're not yet inside one either
1088
-				elseif (!$isClosingTag && $insideTag === null)
1089
-					$insideTag = $tagName;
1121
+				elseif (!$isClosingTag && $insideTag === null) {
1122
+									$insideTag = $tagName;
1123
+				}
1090 1124
 
1091 1125
 				// In all other cases, this tag must be invalid
1092
-				else
1093
-					unset($matches[$i]);
1126
+				else {
1127
+									unset($matches[$i]);
1128
+				}
1094 1129
 			}
1095 1130
 
1096 1131
 			// The next one is gonna be the other one.
@@ -1098,8 +1133,9 @@  discard block
 block discarded – undo
1098 1133
 		}
1099 1134
 
1100 1135
 		// We're still inside a tag and had no chance for closure?
1101
-		if ($insideTag !== null)
1102
-			$matches[] = '[/' . $insideTag . ']';
1136
+		if ($insideTag !== null) {
1137
+					$matches[] = '[/' . $insideTag . ']';
1138
+		}
1103 1139
 
1104 1140
 		// And a complete text string again.
1105 1141
 		$text = implode('', $matches);
@@ -1108,8 +1144,9 @@  discard block
 block discarded – undo
1108 1144
 	// Quickly remove any tags which are back to back.
1109 1145
 	$backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~';
1110 1146
 	$lastlen = 0;
1111
-	while (strlen($text) !== $lastlen)
1112
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1147
+	while (strlen($text) !== $lastlen) {
1148
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1149
+	}
1113 1150
 
1114 1151
 	// Need to sort the tags by name length.
1115 1152
 	uksort($valid_tags, function ($a, $b) {
@@ -1148,8 +1185,9 @@  discard block
 block discarded – undo
1148 1185
 			$isCompetingTag = in_array($tag, $competing_tags);
1149 1186
 
1150 1187
 			// Check if this might be one of those cleaned out tags.
1151
-			if ($tag === '')
1152
-				continue;
1188
+			if ($tag === '') {
1189
+							continue;
1190
+			}
1153 1191
 
1154 1192
 			// Special case: inside [code] blocks any code is left untouched.
1155 1193
 			elseif ($tag === 'code')
@@ -1160,8 +1198,9 @@  discard block
 block discarded – undo
1160 1198
 					$inCode = false;
1161 1199
 
1162 1200
 					// Reopen tags that were closed before the code block.
1163
-					if (!empty($inlineElements))
1164
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1201
+					if (!empty($inlineElements)) {
1202
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1203
+					}
1165 1204
 				}
1166 1205
 
1167 1206
 				// We're outside a coding and nobbc block and opening it.
@@ -1190,8 +1229,9 @@  discard block
 block discarded – undo
1190 1229
 					$inNoBbc = false;
1191 1230
 
1192 1231
 					// Some inline elements might've been closed that need reopening.
1193
-					if (!empty($inlineElements))
1194
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1232
+					if (!empty($inlineElements)) {
1233
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1234
+					}
1195 1235
 				}
1196 1236
 
1197 1237
 				// We're outside a nobbc and coding block and opening it.
@@ -1211,8 +1251,9 @@  discard block
 block discarded – undo
1211 1251
 			}
1212 1252
 
1213 1253
 			// So, we're inside one of the special blocks: ignore any tag.
1214
-			elseif ($inCode || $inNoBbc)
1215
-				continue;
1254
+			elseif ($inCode || $inNoBbc) {
1255
+							continue;
1256
+			}
1216 1257
 
1217 1258
 			// We're dealing with an opening tag.
1218 1259
 			if ($isOpeningTag)
@@ -1253,8 +1294,9 @@  discard block
 block discarded – undo
1253 1294
 							if ($parts[$j + 3] === $tag)
1254 1295
 							{
1255 1296
 								// If it's an opening tag, increase the level.
1256
-								if ($parts[$j + 2] === '')
1257
-									$curLevel++;
1297
+								if ($parts[$j + 2] === '') {
1298
+																	$curLevel++;
1299
+								}
1258 1300
 
1259 1301
 								// A closing tag, decrease the level.
1260 1302
 								else
@@ -1277,13 +1319,15 @@  discard block
 block discarded – undo
1277 1319
 					{
1278 1320
 						if ($isCompetingTag)
1279 1321
 						{
1280
-							if (!isset($competingElements[$tag]))
1281
-								$competingElements[$tag] = array();
1322
+							if (!isset($competingElements[$tag])) {
1323
+															$competingElements[$tag] = array();
1324
+							}
1282 1325
 
1283 1326
 							$competingElements[$tag][] = $parts[$i + 4];
1284 1327
 
1285
-							if (count($competingElements[$tag]) > 1)
1286
-								$parts[$i] .= '[/' . $tag . ']';
1328
+							if (count($competingElements[$tag]) > 1) {
1329
+															$parts[$i] .= '[/' . $tag . ']';
1330
+							}
1287 1331
 						}
1288 1332
 
1289 1333
 						$inlineElements[$elementContent] = $tag;
@@ -1303,15 +1347,17 @@  discard block
 block discarded – undo
1303 1347
 						$addClosingTags = array();
1304 1348
 						while ($element = array_pop($blockElements))
1305 1349
 						{
1306
-							if ($element === $tag)
1307
-								break;
1350
+							if ($element === $tag) {
1351
+															break;
1352
+							}
1308 1353
 
1309 1354
 							// Still a block tag was open not equal to this tag.
1310 1355
 							$addClosingTags[] = $element['type'];
1311 1356
 						}
1312 1357
 
1313
-						if (!empty($addClosingTags))
1314
-							$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1358
+						if (!empty($addClosingTags)) {
1359
+													$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1360
+						}
1315 1361
 
1316 1362
 						// Apparently the closing tag was not found on the stack.
1317 1363
 						if (!is_string($element) || $element !== $tag)
@@ -1321,8 +1367,7 @@  discard block
 block discarded – undo
1321 1367
 							$parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1322 1368
 							continue;
1323 1369
 						}
1324
-					}
1325
-					else
1370
+					} else
1326 1371
 					{
1327 1372
 						// Get rid of this closing tag!
1328 1373
 						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
@@ -1351,53 +1396,62 @@  discard block
 block discarded – undo
1351 1396
 							unset($inlineElements[$tagContentToBeClosed]);
1352 1397
 
1353 1398
 							// Was this the tag we were looking for?
1354
-							if ($tagToBeClosed === $tag)
1355
-								break;
1399
+							if ($tagToBeClosed === $tag) {
1400
+															break;
1401
+							}
1356 1402
 
1357 1403
 							// Nope, close it and look further!
1358
-							else
1359
-								$parts[$i] .= '[/' . $tagToBeClosed . ']';
1404
+							else {
1405
+															$parts[$i] .= '[/' . $tagToBeClosed . ']';
1406
+							}
1360 1407
 						}
1361 1408
 
1362 1409
 						if ($isCompetingTag && !empty($competingElements[$tag]))
1363 1410
 						{
1364 1411
 							array_pop($competingElements[$tag]);
1365 1412
 
1366
-							if (count($competingElements[$tag]) > 0)
1367
-								$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1413
+							if (count($competingElements[$tag]) > 0) {
1414
+															$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1415
+							}
1368 1416
 						}
1369 1417
 					}
1370 1418
 
1371 1419
 					// Unexpected closing tag, ex-ter-mi-nate.
1372
-					else
1373
-						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1420
+					else {
1421
+											$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1422
+					}
1374 1423
 				}
1375 1424
 			}
1376 1425
 		}
1377 1426
 
1378 1427
 		// Close the code tags.
1379
-		if ($inCode)
1380
-			$parts[$i] .= '[/code]';
1428
+		if ($inCode) {
1429
+					$parts[$i] .= '[/code]';
1430
+		}
1381 1431
 
1382 1432
 		// The same for nobbc tags.
1383
-		elseif ($inNoBbc)
1384
-			$parts[$i] .= '[/nobbc]';
1433
+		elseif ($inNoBbc) {
1434
+					$parts[$i] .= '[/nobbc]';
1435
+		}
1385 1436
 
1386 1437
 		// Still inline tags left unclosed? Close them now, better late than never.
1387
-		elseif (!empty($inlineElements))
1388
-			$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1438
+		elseif (!empty($inlineElements)) {
1439
+					$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1440
+		}
1389 1441
 
1390 1442
 		// Now close the block elements.
1391
-		if (!empty($blockElements))
1392
-			$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1443
+		if (!empty($blockElements)) {
1444
+					$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1445
+		}
1393 1446
 
1394 1447
 		$text = implode('', $parts);
1395 1448
 	}
1396 1449
 
1397 1450
 	// Final clean up of back to back tags.
1398 1451
 	$lastlen = 0;
1399
-	while (strlen($text) !== $lastlen)
1400
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1452
+	while (strlen($text) !== $lastlen) {
1453
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1454
+	}
1401 1455
 
1402 1456
 	return $text;
1403 1457
 }
@@ -1414,22 +1468,25 @@  discard block
 block discarded – undo
1414 1468
 	$context['template_layers'] = array();
1415 1469
 	// Lets make sure we aren't going to output anything nasty.
1416 1470
 	@ob_end_clean();
1417
-	if (!empty($modSettings['enableCompressedOutput']))
1418
-		@ob_start('ob_gzhandler');
1419
-	else
1420
-		@ob_start();
1471
+	if (!empty($modSettings['enableCompressedOutput'])) {
1472
+			@ob_start('ob_gzhandler');
1473
+	} else {
1474
+			@ob_start();
1475
+	}
1421 1476
 
1422 1477
 	// If we don't have any locale better avoid broken js
1423
-	if (empty($txt['lang_locale']))
1424
-		die();
1478
+	if (empty($txt['lang_locale'])) {
1479
+			die();
1480
+	}
1425 1481
 
1426 1482
 	$file_data = '(function ($) {
1427 1483
 	\'use strict\';
1428 1484
 
1429 1485
 	$.sceditor.locale[' . JavaScriptEscape($txt['lang_locale']) . '] = {';
1430
-	foreach ($editortxt as $key => $val)
1431
-		$file_data .= '
1486
+	foreach ($editortxt as $key => $val) {
1487
+			$file_data .= '
1432 1488
 		' . JavaScriptEscape($key) . ': ' . JavaScriptEscape($val) . ',';
1489
+	}
1433 1490
 
1434 1491
 	$file_data .= '
1435 1492
 		dateFormat: "day.month.year"
@@ -1497,8 +1554,9 @@  discard block
 block discarded – undo
1497 1554
 				)
1498 1555
 			);
1499 1556
 			$icon_data = array();
1500
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1501
-				$icon_data[] = $row;
1557
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1558
+							$icon_data[] = $row;
1559
+			}
1502 1560
 			$smcFunc['db_free_result']($request);
1503 1561
 
1504 1562
 			$icons = array();
@@ -1513,9 +1571,9 @@  discard block
 block discarded – undo
1513 1571
 			}
1514 1572
 
1515 1573
 			cache_put_data('posting_icons-' . $board_id, $icons, 480);
1574
+		} else {
1575
+					$icons = $temp;
1516 1576
 		}
1517
-		else
1518
-			$icons = $temp;
1519 1577
 	}
1520 1578
 	call_integration_hook('integrate_load_message_icons', array(&$icons));
1521 1579
 
@@ -1544,8 +1602,9 @@  discard block
 block discarded – undo
1544 1602
 	{
1545 1603
 		// Some general stuff.
1546 1604
 		$settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set'];
1547
-		if (!empty($context['drafts_autosave']))
1548
-			$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1605
+		if (!empty($context['drafts_autosave'])) {
1606
+					$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1607
+		}
1549 1608
 
1550 1609
 		// This really has some WYSIWYG stuff.
1551 1610
 		loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor');
@@ -1562,8 +1621,9 @@  discard block
 block discarded – undo
1562 1621
 		var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\';
1563 1622
 		var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';');
1564 1623
 		// editor language file
1565
-		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US')
1566
-			loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1624
+		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') {
1625
+					loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1626
+		}
1567 1627
 
1568 1628
 		$context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (stripos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== false ? '_mac' : (isBrowser('is_firefox') ? '_firefox' : ''))];
1569 1629
 		$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_character_set'] == 'UTF-8' || function_exists('iconv'))));
@@ -1572,11 +1632,12 @@  discard block
 block discarded – undo
1572 1632
 			loadJavaScriptFile('spellcheck.js', array('minimize' => true), 'smf_spellcheck');
1573 1633
 
1574 1634
 			// Some hidden information is needed in order to make the spell checking work.
1575
-			if (!isset($_REQUEST['xml']))
1576
-				$context['insert_after_template'] .= '
1635
+			if (!isset($_REQUEST['xml'])) {
1636
+							$context['insert_after_template'] .= '
1577 1637
 		<form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck">
1578 1638
 			<input type="hidden" name="spellstring" value="">
1579 1639
 		</form>';
1640
+			}
1580 1641
 		}
1581 1642
 	}
1582 1643
 
@@ -1768,8 +1829,9 @@  discard block
 block discarded – undo
1768 1829
 
1769 1830
 		// Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
1770 1831
 		$disabled_tags = array();
1771
-		if (!empty($modSettings['disabledBBC']))
1772
-			$disabled_tags = explode(',', $modSettings['disabledBBC']);
1832
+		if (!empty($modSettings['disabledBBC'])) {
1833
+					$disabled_tags = explode(',', $modSettings['disabledBBC']);
1834
+		}
1773 1835
 
1774 1836
 		foreach ($disabled_tags as $tag)
1775 1837
 		{
@@ -1781,9 +1843,10 @@  discard block
 block discarded – undo
1781 1843
 				$context['disabled_tags']['orderedlist'] = true;
1782 1844
 			}
1783 1845
 
1784
-			foreach ($editor_tag_map as $thisTag => $tagNameBBC)
1785
-				if ($tag === $thisTag)
1846
+			foreach ($editor_tag_map as $thisTag => $tagNameBBC) {
1847
+							if ($tag === $thisTag)
1786 1848
 					$context['disabled_tags'][$tagNameBBC] = true;
1849
+			}
1787 1850
 
1788 1851
 			$context['disabled_tags'][$tag] = true;
1789 1852
 		}
@@ -1794,8 +1857,9 @@  discard block
 block discarded – undo
1794 1857
 
1795 1858
 		foreach ($context['bbc_tags'] as $row => $tagRow)
1796 1859
 		{
1797
-			if (!isset($context['bbc_toolbar'][$row]))
1798
-				$context['bbc_toolbar'][$row] = array();
1860
+			if (!isset($context['bbc_toolbar'][$row])) {
1861
+							$context['bbc_toolbar'][$row] = array();
1862
+			}
1799 1863
 
1800 1864
 			$tagsRow = array();
1801 1865
 
@@ -1831,20 +1895,21 @@  discard block
 block discarded – undo
1831 1895
 
1832 1896
 					$context['bbcodes_handlers'] .= '
1833 1897
 						});';
1834
-				}
1835
-				else
1898
+				} else
1836 1899
 				{
1837 1900
 					$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1838 1901
 					$tagsRow = array();
1839 1902
 				}
1840 1903
 			}
1841 1904
 
1842
-			if (!empty($tagsRow))
1843
-				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1905
+			if (!empty($tagsRow)) {
1906
+							$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1907
+			}
1844 1908
 		}
1845 1909
 
1846
-		if (!empty($bbcodes_styles))
1847
-			addInlineCss($bbcodes_styles);
1910
+		if (!empty($bbcodes_styles)) {
1911
+					addInlineCss($bbcodes_styles);
1912
+		}
1848 1913
 	}
1849 1914
 
1850 1915
 	// Initialize smiley array... if not loaded before.
@@ -1856,8 +1921,8 @@  discard block
 block discarded – undo
1856 1921
 		);
1857 1922
 
1858 1923
 		// Load smileys - don't bother to run a query if we're not using the database's ones anyhow.
1859
-		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none')
1860
-			$context['smileys']['postform'][] = array(
1924
+		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') {
1925
+					$context['smileys']['postform'][] = array(
1861 1926
 				'smileys' => array(
1862 1927
 					array(
1863 1928
 						'code' => ':)',
@@ -1943,7 +2008,7 @@  discard block
 block discarded – undo
1943 2008
 				),
1944 2009
 				'isLast' => true,
1945 2010
 			);
1946
-		elseif ($user_info['smiley_set'] != 'none')
2011
+		} elseif ($user_info['smiley_set'] != 'none')
1947 2012
 		{
1948 2013
 			if (($temp = cache_get_data('posting_smileys', 480)) == null)
1949 2014
 			{
@@ -1966,29 +2031,32 @@  discard block
 block discarded – undo
1966 2031
 
1967 2032
 				foreach ($context['smileys'] as $section => $smileyRows)
1968 2033
 				{
1969
-					foreach ($smileyRows as $rowIndex => $smileys)
1970
-						$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2034
+					foreach ($smileyRows as $rowIndex => $smileys) {
2035
+											$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2036
+					}
1971 2037
 
1972
-					if (!empty($smileyRows))
1973
-						$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2038
+					if (!empty($smileyRows)) {
2039
+											$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2040
+					}
1974 2041
 				}
1975 2042
 
1976 2043
 				cache_put_data('posting_smileys', $context['smileys'], 480);
2044
+			} else {
2045
+							$context['smileys'] = $temp;
1977 2046
 			}
1978
-			else
1979
-				$context['smileys'] = $temp;
1980 2047
 		}
1981 2048
 
1982 2049
 		// Set proper extensions; do this post caching so cache doesn't become extension-specific
1983 2050
 		array_walk_recursive($context['smileys'], function (&$filename, $key)
1984 2051
 			{
1985 2052
 				global $context, $user_info, $modSettings;
1986
-				if ($key == 'filename')
1987
-					// Need to use the default if user selection is disabled
2053
+				if ($key == 'filename') {
2054
+									// Need to use the default if user selection is disabled
1988 2055
 					if (empty($modSettings['smiley_sets_enable']))
1989 2056
 						$filename .= $context['user']['smiley_set_default_ext'];
1990
-					else
1991
-						$filename .= $user_info['smiley_set_ext'];
2057
+				} else {
2058
+											$filename .= $user_info['smiley_set_ext'];
2059
+					}
1992 2060
 				
1993 2061
 			}
1994 2062
 		);
@@ -2006,12 +2074,15 @@  discard block
 block discarded – undo
2006 2074
 		'plugins' => '',
2007 2075
 		'bbcodeTrim' => true,
2008 2076
 	);
2009
-	if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale']))
2010
-		$sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale'];
2011
-	if (!empty($context['right_to_left']))
2012
-		$sce_options['rtl'] = true;
2013
-	if ($editorOptions['id'] != 'quickReply')
2014
-		$sce_options['autofocus'] = true;
2077
+	if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale'])) {
2078
+			$sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale'];
2079
+	}
2080
+	if (!empty($context['right_to_left'])) {
2081
+			$sce_options['rtl'] = true;
2082
+	}
2083
+	if ($editorOptions['id'] != 'quickReply') {
2084
+			$sce_options['autofocus'] = true;
2085
+	}
2015 2086
 
2016 2087
 	$sce_options['emoticons'] = array();
2017 2088
 	$sce_options['emoticonsDescriptions'] = array();
@@ -2028,10 +2099,11 @@  discard block
 block discarded – undo
2028 2099
 			$countLocations--;
2029 2100
 
2030 2101
 			unset($smiley_location);
2031
-			if ($location == 'postform')
2032
-				$smiley_location = &$sce_options['emoticons']['dropdown'];
2033
-			elseif ($location == 'popup')
2034
-				$smiley_location = &$sce_options['emoticons']['popup'];
2102
+			if ($location == 'postform') {
2103
+							$smiley_location = &$sce_options['emoticons']['dropdown'];
2104
+			} elseif ($location == 'popup') {
2105
+							$smiley_location = &$sce_options['emoticons']['popup'];
2106
+			}
2035 2107
 
2036 2108
 			$numRows = count($smileyRows);
2037 2109
 
@@ -2045,8 +2117,9 @@  discard block
 block discarded – undo
2045 2117
 					$sce_options['emoticonsDescriptions'][$smiley['code']] = $smiley['description'];
2046 2118
 				}
2047 2119
 
2048
-				if (empty($smileyRow['isLast']) && $numRows != 1)
2049
-					$smiley_location['-' . $emptyPlaceholder++] = '';
2120
+				if (empty($smileyRow['isLast']) && $numRows != 1) {
2121
+									$smiley_location['-' . $emptyPlaceholder++] = '';
2122
+				}
2050 2123
 			}
2051 2124
 		}
2052 2125
 	}
@@ -2061,8 +2134,9 @@  discard block
 block discarded – undo
2061 2134
 
2062 2135
 			$count_tags--;
2063 2136
 
2064
-			if (!empty($count_tags))
2065
-				$sce_options['toolbar'] .= '||';
2137
+			if (!empty($count_tags)) {
2138
+							$sce_options['toolbar'] .= '||';
2139
+			}
2066 2140
 		}
2067 2141
 	}
2068 2142
 
@@ -2090,8 +2164,9 @@  discard block
 block discarded – undo
2090 2164
 		loadTemplate('GenericControls');
2091 2165
 
2092 2166
 		// Some javascript ma'am?
2093
-		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])))
2094
-			loadJavaScriptFile('captcha.js', array('minimize' => true), 'smf_captcha');
2167
+		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) {
2168
+					loadJavaScriptFile('captcha.js', array('minimize' => true), 'smf_captcha');
2169
+		}
2095 2170
 
2096 2171
 		$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
2097 2172
 
@@ -2104,8 +2179,8 @@  discard block
 block discarded – undo
2104 2179
 	$isNew = !isset($context['controls']['verification'][$verificationOptions['id']]);
2105 2180
 
2106 2181
 	// Log this into our collection.
2107
-	if ($isNew)
2108
-		$context['controls']['verification'][$verificationOptions['id']] = array(
2182
+	if ($isNew) {
2183
+			$context['controls']['verification'][$verificationOptions['id']] = array(
2109 2184
 			'id' => $verificationOptions['id'],
2110 2185
 			'empty_field' => empty($verificationOptions['no_empty_field']),
2111 2186
 			'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])),
@@ -2116,13 +2191,15 @@  discard block
 block discarded – undo
2116 2191
 			'questions' => array(),
2117 2192
 			'can_recaptcha' => !empty($modSettings['recaptcha_enabled']) && !empty($modSettings['recaptcha_site_key']) && !empty($modSettings['recaptcha_secret_key']),
2118 2193
 		);
2194
+	}
2119 2195
 	$thisVerification = &$context['controls']['verification'][$verificationOptions['id']];
2120 2196
 
2121 2197
 	// Is there actually going to be anything?
2122
-	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha']))
2123
-		return false;
2124
-	elseif (!$isNew && !$do_test)
2125
-		return true;
2198
+	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) {
2199
+			return false;
2200
+	} elseif (!$isNew && !$do_test) {
2201
+			return true;
2202
+	}
2126 2203
 
2127 2204
 	// Sanitize reCAPTCHA fields?
2128 2205
 	if ($thisVerification['can_recaptcha'])
@@ -2135,11 +2212,12 @@  discard block
 block discarded – undo
2135 2212
 	}
2136 2213
 
2137 2214
 	// Add javascript for the object.
2138
-	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual'])
2139
-		$context['insert_after_template'] .= '
2215
+	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) {
2216
+			$context['insert_after_template'] .= '
2140 2217
 			<script>
2141 2218
 				var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . ');
2142 2219
 			</script>';
2220
+	}
2143 2221
 
2144 2222
 	// If we want questions do we have a cache of all the IDs?
2145 2223
 	if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache']))
@@ -2162,8 +2240,9 @@  discard block
 block discarded – undo
2162 2240
 				unset ($row['id_question']);
2163 2241
 				// Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh?
2164 2242
 				$row['answers'] = $smcFunc['json_decode']($row['answers'], true);
2165
-				foreach ($row['answers'] as $k => $v)
2166
-					$row['answers'][$k] = $smcFunc['strtolower']($v);
2243
+				foreach ($row['answers'] as $k => $v) {
2244
+									$row['answers'][$k] = $smcFunc['strtolower']($v);
2245
+				}
2167 2246
 
2168 2247
 				$modSettings['question_id_cache']['questions'][$id_question] = $row;
2169 2248
 				$modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question;
@@ -2174,35 +2253,42 @@  discard block
 block discarded – undo
2174 2253
 		}
2175 2254
 	}
2176 2255
 
2177
-	if (!isset($_SESSION[$verificationOptions['id'] . '_vv']))
2178
-		$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2256
+	if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) {
2257
+			$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2258
+	}
2179 2259
 
2180 2260
 	// Do we need to refresh the verification?
2181
-	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh']))
2182
-		$force_refresh = true;
2183
-	else
2184
-		$force_refresh = false;
2261
+	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) {
2262
+			$force_refresh = true;
2263
+	} else {
2264
+			$force_refresh = false;
2265
+	}
2185 2266
 
2186 2267
 	// This can also force a fresh, although unlikely.
2187
-	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q'])))
2188
-		$force_refresh = true;
2268
+	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) {
2269
+			$force_refresh = true;
2270
+	}
2189 2271
 
2190 2272
 	$verification_errors = array();
2191 2273
 	// Start with any testing.
2192 2274
 	if ($do_test)
2193 2275
 	{
2194 2276
 		// This cannot happen!
2195
-		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count']))
2196
-			fatal_lang_error('no_access', false);
2277
+		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) {
2278
+					fatal_lang_error('no_access', false);
2279
+		}
2197 2280
 		// ... nor this!
2198
-		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'])))
2199
-			fatal_lang_error('no_access', false);
2281
+		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) {
2282
+					fatal_lang_error('no_access', false);
2283
+		}
2200 2284
 		// Hmm, it's requested but not actually declared. This shouldn't happen.
2201
-		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2202
-			fatal_lang_error('no_access', false);
2285
+		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) {
2286
+					fatal_lang_error('no_access', false);
2287
+		}
2203 2288
 		// While we're here, did the user do something bad?
2204
-		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']]))
2205
-			$verification_errors[] = 'wrong_verification_answer';
2289
+		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) {
2290
+					$verification_errors[] = 'wrong_verification_answer';
2291
+		}
2206 2292
 
2207 2293
 		if ($thisVerification['can_recaptcha'])
2208 2294
 		{
@@ -2213,22 +2299,25 @@  discard block
 block discarded – undo
2213 2299
 			{
2214 2300
 				$resp = $reCaptcha->verify($_POST['g-recaptcha-response'], $user_info['ip']);
2215 2301
 
2216
-				if (!$resp->isSuccess())
2217
-					$verification_errors[] = 'wrong_verification_code';
2302
+				if (!$resp->isSuccess()) {
2303
+									$verification_errors[] = 'wrong_verification_code';
2304
+				}
2305
+			} else {
2306
+							$verification_errors[] = 'wrong_verification_code';
2218 2307
 			}
2219
-			else
2220
-				$verification_errors[] = 'wrong_verification_code';
2221 2308
 		}
2222
-		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code']))
2223
-			$verification_errors[] = 'wrong_verification_code';
2309
+		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) {
2310
+					$verification_errors[] = 'wrong_verification_code';
2311
+		}
2224 2312
 		if ($thisVerification['number_questions'])
2225 2313
 		{
2226 2314
 			$incorrectQuestions = array();
2227 2315
 			foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q)
2228 2316
 			{
2229 2317
 				// We don't have this question any more, thus no answers.
2230
-				if (!isset($modSettings['question_id_cache']['questions'][$q]))
2231
-					continue;
2318
+				if (!isset($modSettings['question_id_cache']['questions'][$q])) {
2319
+									continue;
2320
+				}
2232 2321
 				// This is quite complex. We have our question but it might have multiple answers.
2233 2322
 				// First, did they actually answer this question?
2234 2323
 				if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '')
@@ -2240,24 +2329,28 @@  discard block
 block discarded – undo
2240 2329
 				else
2241 2330
 				{
2242 2331
 					$given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q])));
2243
-					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers']))
2244
-						$incorrectQuestions[] = $q;
2332
+					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) {
2333
+											$incorrectQuestions[] = $q;
2334
+					}
2245 2335
 				}
2246 2336
 			}
2247 2337
 
2248
-			if (!empty($incorrectQuestions))
2249
-				$verification_errors[] = 'wrong_verification_answer';
2338
+			if (!empty($incorrectQuestions)) {
2339
+							$verification_errors[] = 'wrong_verification_answer';
2340
+			}
2250 2341
 		}
2251 2342
 	}
2252 2343
 
2253 2344
 	// Any errors means we refresh potentially.
2254 2345
 	if (!empty($verification_errors))
2255 2346
 	{
2256
-		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors']))
2257
-			$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2347
+		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) {
2348
+					$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2349
+		}
2258 2350
 		// Too many errors?
2259
-		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors'])
2260
-			$force_refresh = true;
2351
+		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) {
2352
+					$force_refresh = true;
2353
+		}
2261 2354
 
2262 2355
 		// Keep a track of these.
2263 2356
 		$_SESSION[$verificationOptions['id'] . '_vv']['errors']++;
@@ -2290,8 +2383,9 @@  discard block
 block discarded – undo
2290 2383
 			// Are we overriding the range?
2291 2384
 			$character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range'];
2292 2385
 
2293
-			for ($i = 0; $i < 6; $i++)
2294
-				$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2386
+			for ($i = 0; $i < 6; $i++) {
2387
+							$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2388
+			}
2295 2389
 		}
2296 2390
 
2297 2391
 		// Getting some new questions?
@@ -2299,8 +2393,9 @@  discard block
 block discarded – undo
2299 2393
 		{
2300 2394
 			// Attempt to try the current page's language, followed by the user's preference, followed by the site default.
2301 2395
 			$possible_langs = array();
2302
-			if (isset($_SESSION['language']))
2303
-				$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2396
+			if (isset($_SESSION['language'])) {
2397
+							$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2398
+			}
2304 2399
 			if (!empty($user_info['language']));
2305 2400
 			$possible_langs[] = $user_info['language'];
2306 2401
 			$possible_langs[] = $language;
@@ -2319,8 +2414,7 @@  discard block
 block discarded – undo
2319 2414
 				}
2320 2415
 			}
2321 2416
 		}
2322
-	}
2323
-	else
2417
+	} else
2324 2418
 	{
2325 2419
 		// Same questions as before.
2326 2420
 		$questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array();
@@ -2330,8 +2424,9 @@  discard block
 block discarded – undo
2330 2424
 	// If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway.
2331 2425
 	if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2332 2426
 	{
2333
-		if (!isset($context['html_headers']))
2334
-			$context['html_headers'] = '';
2427
+		if (!isset($context['html_headers'])) {
2428
+					$context['html_headers'] = '';
2429
+		}
2335 2430
 		$context['html_headers'] .= '<style>.vv_special { display:none; }</style>';
2336 2431
 	}
2337 2432
 
@@ -2357,11 +2452,13 @@  discard block
 block discarded – undo
2357 2452
 	$_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1;
2358 2453
 
2359 2454
 	// Return errors if we have them.
2360
-	if (!empty($verification_errors))
2361
-		return $verification_errors;
2455
+	if (!empty($verification_errors)) {
2456
+			return $verification_errors;
2457
+	}
2362 2458
 	// If we had a test that one, make a note.
2363
-	elseif ($do_test)
2364
-		$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2459
+	elseif ($do_test) {
2460
+			$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2461
+	}
2365 2462
 
2366 2463
 	// Say that everything went well chaps.
2367 2464
 	return true;
@@ -2386,8 +2483,9 @@  discard block
 block discarded – undo
2386 2483
 	call_integration_hook('integrate_autosuggest', array(&$searchTypes));
2387 2484
 
2388 2485
 	// If we're just checking the callback function is registered return true or false.
2389
-	if ($checkRegistered != null)
2390
-		return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2486
+	if ($checkRegistered != null) {
2487
+			return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2488
+	}
2391 2489
 
2392 2490
 	checkSession('get');
2393 2491
 	loadTemplate('Xml');
@@ -2538,24 +2636,27 @@  discard block
 block discarded – undo
2538 2636
 		foreach ($possible_versions as $ver)
2539 2637
 		{
2540 2638
 			$ver = trim($ver);
2541
-			if (strpos($ver, 'SMF') === 0)
2542
-				$versions[] = $ver;
2639
+			if (strpos($ver, 'SMF') === 0) {
2640
+							$versions[] = $ver;
2641
+			}
2543 2642
 		}
2544 2643
 	}
2545 2644
 	$smcFunc['db_free_result']($request);
2546 2645
 
2547 2646
 	// Just in case we don't have ANYthing.
2548
-	if (empty($versions))
2549
-		$versions = array('SMF 2.0');
2647
+	if (empty($versions)) {
2648
+			$versions = array('SMF 2.0');
2649
+	}
2550 2650
 
2551
-	foreach ($versions as $id => $version)
2552
-		if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2651
+	foreach ($versions as $id => $version) {
2652
+			if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2553 2653
 			$xml_data['items']['children'][] = array(
2554 2654
 				'attributes' => array(
2555 2655
 					'id' => $id,
2556 2656
 				),
2557 2657
 				'value' => $version,
2558 2658
 			);
2659
+	}
2559 2660
 
2560 2661
 	return $xml_data;
2561 2662
 }
Please login to merge, or discard this patch.
Sources/ManageMembers.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 			// INET.
356 356
 			elseif ($param_info['type'] == 'inet')
357 357
 			{
358
-				if(count($search_params[$param_name]) === 1)
358
+				if (count($search_params[$param_name]) === 1)
359 359
 				{
360 360
 					$query_parts[] = '(' . $param_info['db_fields'][0] . ' = {inet:' . $param_name . '})';
361 361
 					$where_params[$param_name] = $search_params[$param_name][0];
@@ -363,8 +363,8 @@  discard block
 block discarded – undo
363 363
 				elseif (count($search_params[$param_name]) === 2)
364 364
 				{
365 365
 					$query_parts[] = '(' . $param_info['db_fields'][0] . ' <= {inet:' . $param_name . '_high} and ' . $param_info['db_fields'][0] . ' >= {inet:' . $param_name . '_low})';
366
-					$where_params[$param_name.'_low'] = $search_params[$param_name]['low'];
367
-					$where_params[$param_name.'_high'] = $search_params[$param_name]['high'];
366
+					$where_params[$param_name . '_low'] = $search_params[$param_name]['low'];
367
+					$where_params[$param_name . '_high'] = $search_params[$param_name]['high'];
368 368
 				}
369 369
 				
370 370
 			}
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
 	if (!empty($context['show_filter']) && !empty($context['available_filters']))
1013 1013
 		$listOptions['additional_rows'][] = array(
1014 1014
 			'position' => 'above_column_headers',
1015
-			'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . ((isset($context['current_filter']) && isset($txt['admin_browse_filter_type_'.$context['current_filter']])) ? $txt['admin_browse_filter_type_'.$context['current_filter']] : $context['available_filters'][0]['desc']),
1015
+			'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . ((isset($context['current_filter']) && isset($txt['admin_browse_filter_type_' . $context['current_filter']])) ? $txt['admin_browse_filter_type_' . $context['current_filter']] : $context['available_filters'][0]['desc']),
1016 1016
 			'class' => 'filter_row generic_list_wrapper smalltext',
1017 1017
 		);
1018 1018
 
Please login to merge, or discard this patch.
Braces   +165 added lines, -124 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main entrance point for the Manage Members screen.
@@ -109,12 +110,13 @@  discard block
 block discarded – undo
109 110
 	$context['tabs'][$context['last_tab']]['is_last'] = true;
110 111
 
111 112
 	// Find the active tab.
112
-	if (isset($context['tabs'][$context['current_subaction']]))
113
-		$context['tabs'][$context['current_subaction']]['is_selected'] = true;
114
-	elseif (isset($context['current_subaction']))
115
-		foreach ($context['tabs'] as $id_tab => $tab_data)
113
+	if (isset($context['tabs'][$context['current_subaction']])) {
114
+			$context['tabs'][$context['current_subaction']]['is_selected'] = true;
115
+	} elseif (isset($context['current_subaction'])) {
116
+			foreach ($context['tabs'] as $id_tab => $tab_data)
116 117
 			if (!empty($tab_data['selected_actions']) && in_array($context['current_subaction'], $tab_data['selected_actions']))
117 118
 				$context['tabs'][$id_tab]['is_selected'] = true;
119
+	}
118 120
 
119 121
 	call_helper($subActions[$context['current_subaction']][0]);
120 122
 }
@@ -141,8 +143,9 @@  discard block
 block discarded – undo
141 143
 		foreach ($_POST['delete'] as $key => $value)
142 144
 		{
143 145
 			// Don't delete yourself, idiot.
144
-			if ($value != $user_info['id'])
145
-				$delete[$key] = (int) $value;
146
+			if ($value != $user_info['id']) {
147
+							$delete[$key] = (int) $value;
148
+			}
146 149
 		}
147 150
 
148 151
 		if (!empty($delete))
@@ -178,17 +181,18 @@  discard block
 block discarded – undo
178 181
 		);
179 182
 		while ($row = $smcFunc['db_fetch_assoc']($request))
180 183
 		{
181
-			if ($row['min_posts'] == -1)
182
-				$context['membergroups'][] = array(
184
+			if ($row['min_posts'] == -1) {
185
+							$context['membergroups'][] = array(
183 186
 					'id' => $row['id_group'],
184 187
 					'name' => $row['group_name'],
185 188
 					'can_be_additional' => true
186 189
 				);
187
-			else
188
-				$context['postgroups'][] = array(
190
+			} else {
191
+							$context['postgroups'][] = array(
189 192
 					'id' => $row['id_group'],
190 193
 					'name' => $row['group_name']
191 194
 				);
195
+			}
192 196
 		}
193 197
 		$smcFunc['db_free_result']($request);
194 198
 
@@ -260,14 +264,15 @@  discard block
 block discarded – undo
260 264
 		call_integration_hook('integrate_view_members_params', array(&$params));
261 265
 
262 266
 		$search_params = array();
263
-		if ($context['current_subaction'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types']))
264
-			$search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true);
265
-		elseif (!empty($_POST))
267
+		if ($context['current_subaction'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) {
268
+					$search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true);
269
+		} elseif (!empty($_POST))
266 270
 		{
267 271
 			$search_params['types'] = $_POST['types'];
268
-			foreach ($params as $param_name => $param_info)
269
-				if (isset($_POST[$param_name]))
272
+			foreach ($params as $param_name => $param_info) {
273
+							if (isset($_POST[$param_name]))
270 274
 					$search_params[$param_name] = $_POST[$param_name];
275
+			}
271 276
 		}
272 277
 
273 278
 		$search_url_params = isset($search_params) ? base64_encode($smcFunc['json_encode']($search_params)) : null;
@@ -280,34 +285,38 @@  discard block
 block discarded – undo
280 285
 		foreach ($params as $param_name => $param_info)
281 286
 		{
282 287
 			// Not filled in?
283
-			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '')
284
-				continue;
288
+			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') {
289
+							continue;
290
+			}
285 291
 
286 292
 			// Make sure numeric values are really numeric.
287
-			if (in_array($param_info['type'], array('int', 'age')))
288
-				$search_params[$param_name] = (int) $search_params[$param_name];
293
+			if (in_array($param_info['type'], array('int', 'age'))) {
294
+							$search_params[$param_name] = (int) $search_params[$param_name];
295
+			}
289 296
 			// Date values have to match the specified format.
290 297
 			elseif ($param_info['type'] == 'date')
291 298
 			{
292 299
 				// Check if this date format is valid.
293
-				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0)
294
-					continue;
300
+				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) {
301
+									continue;
302
+				}
295 303
 
296 304
 				$search_params[$param_name] = strtotime($search_params[$param_name]);
297
-			}
298
-			elseif ($param_info['type'] == 'inet')
305
+			} elseif ($param_info['type'] == 'inet')
299 306
 			{
300 307
 				$search_params[$param_name] = ip2range($search_params[$param_name]);
301
-				if (empty($search_params[$param_name]))
302
-					continue;
308
+				if (empty($search_params[$param_name])) {
309
+									continue;
310
+				}
303 311
 			}
304 312
 
305 313
 			// Those values that are in some kind of range (<, <=, =, >=, >).
306 314
 			if (!empty($param_info['range']))
307 315
 			{
308 316
 				// Default to '=', just in case...
309
-				if (empty($range_trans[$search_params['types'][$param_name]]))
310
-					$search_params['types'][$param_name] = '=';
317
+				if (empty($range_trans[$search_params['types'][$param_name]])) {
318
+									$search_params['types'][$param_name] = '=';
319
+				}
311 320
 
312 321
 				// Handle special case 'age'.
313 322
 				if ($param_info['type'] == 'age')
@@ -335,16 +344,17 @@  discard block
 block discarded – undo
335 344
 				elseif ($param_info['type'] == 'date' && $search_params['types'][$param_name] == '=')
336 345
 				{
337 346
 					$query_parts[] = $param_info['db_fields'][0] . ' > ' . $search_params[$param_name] . ' AND ' . $param_info['db_fields'][0] . ' < ' . ($search_params[$param_name] + 86400);
347
+				} else {
348
+									$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
338 349
 				}
339
-				else
340
-					$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
341 350
 			}
342 351
 			// Checkboxes.
343 352
 			elseif ($param_info['type'] == 'checkbox')
344 353
 			{
345 354
 				// Each checkbox or no checkbox at all is checked -> ignore.
346
-				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values']))
347
-					continue;
355
+				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) {
356
+									continue;
357
+				}
348 358
 
349 359
 				$query_parts[] = ($param_info['db_fields'][0]) . ' IN ({array_string:' . $param_name . '_check})';
350 360
 				$where_params[$param_name . '_check'] = $search_params[$param_name];
@@ -356,24 +366,23 @@  discard block
 block discarded – undo
356 366
 				{
357 367
 					$query_parts[] = '(' . $param_info['db_fields'][0] . ' = {inet:' . $param_name . '})';
358 368
 					$where_params[$param_name] = $search_params[$param_name][0];
359
-				}
360
-				elseif (count($search_params[$param_name]) === 2)
369
+				} elseif (count($search_params[$param_name]) === 2)
361 370
 				{
362 371
 					$query_parts[] = '(' . $param_info['db_fields'][0] . ' <= {inet:' . $param_name . '_high} and ' . $param_info['db_fields'][0] . ' >= {inet:' . $param_name . '_low})';
363 372
 					$where_params[$param_name.'_low'] = $search_params[$param_name]['low'];
364 373
 					$where_params[$param_name.'_high'] = $search_params[$param_name]['high'];
365 374
 				}
366 375
 				
367
-			}
368
-			elseif ($param_info['type'] != 'groups')
376
+			} elseif ($param_info['type'] != 'groups')
369 377
 			{
370 378
 				// Replace the wildcard characters ('*' and '?') into MySQL ones.
371 379
 				$parameter = strtolower(strtr($smcFunc['htmlspecialchars']($search_params[$param_name], ENT_QUOTES), array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')));
372 380
 
373
-				if ($smcFunc['db_case_sensitive'])
374
-					$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
375
-				else
376
-					$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
381
+				if ($smcFunc['db_case_sensitive']) {
382
+									$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
383
+				} else {
384
+									$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
385
+				}
377 386
 				$where_params[$param_name . '_normal'] = '%' . $parameter . '%';
378 387
 			}
379 388
 		}
@@ -389,16 +398,18 @@  discard block
 block discarded – undo
389 398
 		}
390 399
 
391 400
 		// Additional membergroups (these are only relevant if not all primary groups where selected!).
392
-		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1])))
393
-			foreach ($search_params['membergroups'][2] as $mg)
401
+		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) {
402
+					foreach ($search_params['membergroups'][2] as $mg)
394 403
 			{
395 404
 				$mg_query_parts[] = 'FIND_IN_SET({int:add_group_' . $mg . '}, mem.additional_groups) != 0';
405
+		}
396 406
 				$where_params['add_group_' . $mg] = $mg;
397 407
 			}
398 408
 
399 409
 		// Combine the one or two membergroup parts into one query part linked with an OR.
400
-		if (!empty($mg_query_parts))
401
-			$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
410
+		if (!empty($mg_query_parts)) {
411
+					$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
412
+		}
402 413
 
403 414
 		// Get all selected post count related membergroups.
404 415
 		if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($context['postgroups']))
@@ -410,9 +421,9 @@  discard block
 block discarded – undo
410 421
 		// Construct the where part of the query.
411 422
 		$where = empty($query_parts) ? '1=1' : implode('
412 423
 			AND ', $query_parts);
424
+	} else {
425
+			$search_url_params = null;
413 426
 	}
414
-	else
415
-		$search_url_params = null;
416 427
 
417 428
 	// Construct the additional URL part with the query info in it.
418 429
 	$context['params_url'] = $context['current_subaction'] == 'query' ? ';sa=query;params=' . $search_url_params : '';
@@ -535,28 +546,32 @@  discard block
 block discarded – undo
535 546
 					'function' => function($rowData) use ($txt)
536 547
 					{
537 548
 						// Calculate number of days since last online.
538
-						if (empty($rowData['last_login']))
539
-							$difference = $txt['never'];
540
-						else
549
+						if (empty($rowData['last_login'])) {
550
+													$difference = $txt['never'];
551
+						} else
541 552
 						{
542 553
 							$num_days_difference = jeffsdatediff($rowData['last_login']);
543 554
 
544 555
 							// Today.
545
-							if (empty($num_days_difference))
546
-								$difference = $txt['viewmembers_today'];
556
+							if (empty($num_days_difference)) {
557
+															$difference = $txt['viewmembers_today'];
558
+							}
547 559
 
548 560
 							// Yesterday.
549
-							elseif ($num_days_difference == 1)
550
-								$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
561
+							elseif ($num_days_difference == 1) {
562
+															$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
563
+							}
551 564
 
552 565
 							// X days ago.
553
-							else
554
-								$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
566
+							else {
567
+															$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
568
+							}
555 569
 						}
556 570
 
557 571
 						// Show it in italics if they're not activated...
558
-						if ($rowData['is_activated'] % 10 != 1)
559
-							$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
572
+						if ($rowData['is_activated'] % 10 != 1) {
573
+													$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
574
+						}
560 575
 
561 576
 						return $difference;
562 577
 					},
@@ -608,8 +623,9 @@  discard block
 block discarded – undo
608 623
 	);
609 624
 
610 625
 	// Without enough permissions, don't show 'delete members' checkboxes.
611
-	if (!allowedTo('profile_remove_any'))
612
-		unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
626
+	if (!allowedTo('profile_remove_any')) {
627
+			unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
628
+	}
613 629
 
614 630
 	require_once($sourcedir . '/Subs-List.php');
615 631
 	createList($listOptions);
@@ -652,17 +668,18 @@  discard block
 block discarded – undo
652 668
 	);
653 669
 	while ($row = $smcFunc['db_fetch_assoc']($request))
654 670
 	{
655
-		if ($row['min_posts'] == -1)
656
-			$context['membergroups'][] = array(
671
+		if ($row['min_posts'] == -1) {
672
+					$context['membergroups'][] = array(
657 673
 				'id' => $row['id_group'],
658 674
 				'name' => $row['group_name'],
659 675
 				'can_be_additional' => true
660 676
 			);
661
-		else
662
-			$context['postgroups'][] = array(
677
+		} else {
678
+					$context['postgroups'][] = array(
663 679
 				'id' => $row['id_group'],
664 680
 				'name' => $row['group_name']
665 681
 			);
682
+		}
666 683
 	}
667 684
 	$smcFunc['db_free_result']($request);
668 685
 
@@ -689,8 +706,9 @@  discard block
 block discarded – undo
689 706
 	$context['page_title'] = $txt['admin_members'];
690 707
 	$context['sub_template'] = 'admin_browse';
691 708
 	$context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve');
692
-	if (isset($context['tabs'][$context['browse_type']]))
693
-		$context['tabs'][$context['browse_type']]['is_selected'] = true;
709
+	if (isset($context['tabs'][$context['browse_type']])) {
710
+			$context['tabs'][$context['browse_type']]['is_selected'] = true;
711
+	}
694 712
 
695 713
 	// Allowed filters are those we can have, in theory.
696 714
 	$context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2);
@@ -701,18 +719,20 @@  discard block
 block discarded – undo
701 719
 	foreach ($context['activation_numbers'] as $type => $amount)
702 720
 	{
703 721
 		// We have some of these...
704
-		if (in_array($type, $context['allowed_filters']) && $amount > 0)
705
-			$context['available_filters'][] = array(
722
+		if (in_array($type, $context['allowed_filters']) && $amount > 0) {
723
+					$context['available_filters'][] = array(
706 724
 				'type' => $type,
707 725
 				'amount' => $amount,
708 726
 				'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?',
709 727
 				'selected' => $type == $context['current_filter']
710 728
 			);
729
+		}
711 730
 	}
712 731
 
713 732
 	// If the filter was not sent, set it to whatever has people in it!
714
-	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount']))
715
-		$context['current_filter'] = $context['available_filters'][0]['type'];
733
+	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) {
734
+			$context['current_filter'] = $context['available_filters'][0]['type'];
735
+	}
716 736
 
717 737
 	// This little variable is used to determine if we should flag where we are looking.
718 738
 	$context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1;
@@ -727,44 +747,47 @@  discard block
 block discarded – undo
727 747
 	);
728 748
 
729 749
 	// Are we showing duplicate information?
730
-	if (isset($_GET['showdupes']))
731
-		$_SESSION['showdupes'] = (int) $_GET['showdupes'];
750
+	if (isset($_GET['showdupes'])) {
751
+			$_SESSION['showdupes'] = (int) $_GET['showdupes'];
752
+	}
732 753
 	$context['show_duplicates'] = !empty($_SESSION['showdupes']);
733 754
 
734 755
 	// Determine which actions we should allow on this page.
735 756
 	if ($context['browse_type'] == 'approve')
736 757
 	{
737 758
 		// If we are approving deleted accounts we have a slightly different list... actually a mirror ;)
738
-		if ($context['current_filter'] == 4)
739
-			$context['allowed_actions'] = array(
759
+		if ($context['current_filter'] == 4) {
760
+					$context['allowed_actions'] = array(
740 761
 				'reject' => $txt['admin_browse_w_approve_deletion'],
741 762
 				'ok' => $txt['admin_browse_w_reject'],
742 763
 			);
743
-		else
744
-			$context['allowed_actions'] = array(
764
+		} else {
765
+					$context['allowed_actions'] = array(
745 766
 				'ok' => $txt['admin_browse_w_approve'],
746 767
 				'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'],
747 768
 				'require_activation' => $txt['admin_browse_w_approve_require_activate'],
748 769
 				'reject' => $txt['admin_browse_w_reject'],
749 770
 				'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'],
750 771
 			);
751
-	}
752
-	elseif ($context['browse_type'] == 'activate')
753
-		$context['allowed_actions'] = array(
772
+		}
773
+	} elseif ($context['browse_type'] == 'activate') {
774
+			$context['allowed_actions'] = array(
754 775
 			'ok' => $txt['admin_browse_w_activate'],
755 776
 			'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'],
756 777
 			'delete' => $txt['admin_browse_w_delete'],
757 778
 			'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'],
758 779
 			'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'],
759 780
 		);
781
+	}
760 782
 
761 783
 	// Create an option list for actions allowed to be done with selected members.
762 784
 	$allowed_actions = '
763 785
 			<option selected value="">' . $txt['admin_browse_with_selected'] . ':</option>
764 786
 			<option value="" disabled>-----------------------------</option>';
765
-	foreach ($context['allowed_actions'] as $key => $desc)
766
-		$allowed_actions .= '
787
+	foreach ($context['allowed_actions'] as $key => $desc) {
788
+			$allowed_actions .= '
767 789
 			<option value="' . $key . '">' . $desc . '</option>';
790
+	}
768 791
 
769 792
 	// Setup the Javascript function for selecting an action for the list.
770 793
 	$javascript = '
@@ -776,15 +799,16 @@  discard block
 block discarded – undo
776 799
 			var message = "";';
777 800
 
778 801
 	// We have special messages for approving deletion of accounts - it's surprisingly logical - honest.
779
-	if ($context['current_filter'] == 4)
780
-		$javascript .= '
802
+	if ($context['current_filter'] == 4) {
803
+			$javascript .= '
781 804
 			if (document.forms.postForm.todo.value.indexOf("reject") != -1)
782 805
 				message = "' . $txt['admin_browse_w_delete'] . '";
783 806
 			else
784 807
 				message = "' . $txt['admin_browse_w_reject'] . '";';
808
+	}
785 809
 	// Otherwise a nice standard message.
786
-	else
787
-		$javascript .= '
810
+	else {
811
+			$javascript .= '
788 812
 			if (document.forms.postForm.todo.value.indexOf("delete") != -1)
789 813
 				message = "' . $txt['admin_browse_w_delete'] . '";
790 814
 			else if (document.forms.postForm.todo.value.indexOf("reject") != -1)
@@ -793,6 +817,7 @@  discard block
 block discarded – undo
793 817
 				message = "' . $txt['admin_browse_w_remind'] . '";
794 818
 			else
795 819
 				message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";';
820
+	}
796 821
 	$javascript .= '
797 822
 			if (confirm(message + " ' . $txt['admin_browse_warn'] . '"))
798 823
 				document.forms.postForm.submit();
@@ -925,10 +950,11 @@  discard block
 block discarded – undo
925 950
 						$member_links = array();
926 951
 						foreach ($rowData['duplicate_members'] as $member)
927 952
 						{
928
-							if ($member['id'])
929
-								$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
930
-							else
931
-								$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
953
+							if ($member['id']) {
954
+															$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
955
+							} else {
956
+															$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
957
+							}
932 958
 						}
933 959
 						return implode(', ', $member_links);
934 960
 					},
@@ -977,14 +1003,16 @@  discard block
 block discarded – undo
977 1003
 	);
978 1004
 
979 1005
 	// Pick what column to actually include if we're showing duplicates.
980
-	if ($context['show_duplicates'])
981
-		unset($listOptions['columns']['email']);
982
-	else
983
-		unset($listOptions['columns']['duplicates']);
1006
+	if ($context['show_duplicates']) {
1007
+			unset($listOptions['columns']['email']);
1008
+	} else {
1009
+			unset($listOptions['columns']['duplicates']);
1010
+	}
984 1011
 
985 1012
 	// Only show hostname on duplicates as it takes a lot of time.
986
-	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup']))
987
-		unset($listOptions['columns']['hostname']);
1013
+	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) {
1014
+			unset($listOptions['columns']['hostname']);
1015
+	}
988 1016
 
989 1017
 	// Is there any need to show filters?
990 1018
 	if (isset($context['available_filters']) && count($context['available_filters']) > 1)
@@ -992,9 +1020,10 @@  discard block
 block discarded – undo
992 1020
 		$filterOptions = '
993 1021
 			<strong>' . $txt['admin_browse_filter_by'] . ':</strong>
994 1022
 			<select name="filter" onchange="this.form.submit();">';
995
-		foreach ($context['available_filters'] as $filter)
996
-			$filterOptions .= '
1023
+		foreach ($context['available_filters'] as $filter) {
1024
+					$filterOptions .= '
997 1025
 				<option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>';
1026
+		}
998 1027
 		$filterOptions .= '
999 1028
 			</select>
1000 1029
 			<noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button"></noscript>';
@@ -1006,12 +1035,13 @@  discard block
 block discarded – undo
1006 1035
 	}
1007 1036
 
1008 1037
 	// What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at.
1009
-	if (!empty($context['show_filter']) && !empty($context['available_filters']))
1010
-		$listOptions['additional_rows'][] = array(
1038
+	if (!empty($context['show_filter']) && !empty($context['available_filters'])) {
1039
+			$listOptions['additional_rows'][] = array(
1011 1040
 			'position' => 'above_column_headers',
1012 1041
 			'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . ((isset($context['current_filter']) && isset($txt['admin_browse_filter_type_'.$context['current_filter']])) ? $txt['admin_browse_filter_type_'.$context['current_filter']] : $context['available_filters'][0]['desc']),
1013 1042
 			'class' => 'filter_row generic_list_wrapper smalltext',
1014 1043
 		);
1044
+	}
1015 1045
 
1016 1046
 	// Now that we have all the options, create the list.
1017 1047
 	require_once($sourcedir . '/Subs-List.php');
@@ -1041,12 +1071,14 @@  discard block
 block discarded – undo
1041 1071
 	$current_filter = (int) $_REQUEST['orig_filter'];
1042 1072
 
1043 1073
 	// If we are applying a filter do just that - then redirect.
1044
-	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter'])
1045
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1074
+	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) {
1075
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1076
+	}
1046 1077
 
1047 1078
 	// Nothing to do?
1048
-	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed']))
1049
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1079
+	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) {
1080
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1081
+	}
1050 1082
 
1051 1083
 	// Are we dealing with members who have been waiting for > set amount of time?
1052 1084
 	if (isset($_POST['time_passed']))
@@ -1059,8 +1091,9 @@  discard block
 block discarded – undo
1059 1091
 	else
1060 1092
 	{
1061 1093
 		$members = array();
1062
-		foreach ($_POST['todoAction'] as $id)
1063
-			$members[] = (int) $id;
1094
+		foreach ($_POST['todoAction'] as $id) {
1095
+					$members[] = (int) $id;
1096
+		}
1064 1097
 		$condition = '
1065 1098
 			AND id_member IN ({array_int:members})';
1066 1099
 	}
@@ -1081,8 +1114,9 @@  discard block
 block discarded – undo
1081 1114
 	$member_count = $smcFunc['db_num_rows']($request);
1082 1115
 
1083 1116
 	// If no results then just return!
1084
-	if ($member_count == 0)
1085
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1117
+	if ($member_count == 0) {
1118
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1119
+	}
1086 1120
 
1087 1121
 	$member_info = array();
1088 1122
 	$members = array();
@@ -1121,8 +1155,9 @@  discard block
 block discarded – undo
1121 1155
 		// Do we have to let the integration code know about the activations?
1122 1156
 		if (!empty($modSettings['integrate_activate']))
1123 1157
 		{
1124
-			foreach ($member_info as $member)
1125
-				call_integration_hook('integrate_activate', array($member['username']));
1158
+			foreach ($member_info as $member) {
1159
+							call_integration_hook('integrate_activate', array($member['username']));
1160
+			}
1126 1161
 		}
1127 1162
 
1128 1163
 		// Check for email.
@@ -1252,20 +1287,23 @@  discard block
 block discarded – undo
1252 1287
 		$log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member';
1253 1288
 
1254 1289
 		require_once($sourcedir . '/Logging.php');
1255
-		foreach ($member_info as $member)
1256
-			logAction($log_action, array('member' => $member['id']), 'admin');
1290
+		foreach ($member_info as $member) {
1291
+					logAction($log_action, array('member' => $member['id']), 'admin');
1292
+		}
1257 1293
 	}
1258 1294
 
1259 1295
 	// Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers).
1260
-	if (in_array($current_filter, array(3, 4, 5)))
1261
-		updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1296
+	if (in_array($current_filter, array(3, 4, 5))) {
1297
+			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1298
+	}
1262 1299
 
1263 1300
 	// Update the member's stats. (but, we know the member didn't change their name.)
1264 1301
 	updateStats('member', false);
1265 1302
 
1266 1303
 	// If they haven't been deleted, update the post group statistics on them...
1267
-	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind')))
1268
-		updateStats('postgroups', $members);
1304
+	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) {
1305
+			updateStats('postgroups', $members);
1306
+	}
1269 1307
 
1270 1308
 	redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1271 1309
 }
@@ -1290,10 +1328,11 @@  discard block
 block discarded – undo
1290 1328
 	$dis = time() - $old;
1291 1329
 
1292 1330
 	// Before midnight?
1293
-	if ($dis < $sinceMidnight)
1294
-		return 0;
1295
-	else
1296
-		$dis -= $sinceMidnight;
1331
+	if ($dis < $sinceMidnight) {
1332
+			return 0;
1333
+	} else {
1334
+			$dis -= $sinceMidnight;
1335
+	}
1297 1336
 
1298 1337
 	// Divide out the seconds in a day to get the number of days.
1299 1338
 	return ceil($dis / (24 * 60 * 60));
@@ -1320,16 +1359,18 @@  discard block
 block discarded – undo
1320 1359
 	$context['activation_numbers'] = array();
1321 1360
 	$context['awaiting_activation'] = 0;
1322 1361
 	$context['awaiting_approval'] = 0;
1323
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1324
-		$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
1362
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1363
+			$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
1364
+	}
1325 1365
 	$smcFunc['db_free_result']($request);
1326 1366
 
1327 1367
 	foreach ($context['activation_numbers'] as $activation_type => $total_members)
1328 1368
 	{
1329
-		if (in_array($activation_type, array(0, 2)))
1330
-			$context['awaiting_activation'] += $total_members;
1331
-		elseif (in_array($activation_type, array(3, 4, 5)))
1332
-			$context['awaiting_approval'] += $total_members;
1369
+		if (in_array($activation_type, array(0, 2))) {
1370
+					$context['awaiting_activation'] += $total_members;
1371
+		} elseif (in_array($activation_type, array(3, 4, 5))) {
1372
+					$context['awaiting_approval'] += $total_members;
1373
+		}
1333 1374
 	}
1334 1375
 
1335 1376
 }
Please login to merge, or discard this patch.
other/Settings.php 1 patch
Braces   +13 added lines, -8 removed lines patch added patch discarded remove patch
@@ -191,12 +191,15 @@  discard block
 block discarded – undo
191 191
 $tasksdir = $sourcedir . '/tasks';
192 192
 
193 193
 # Make sure the paths are correct... at least try to fix them.
194
-if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt'))
194
+if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt')) {
195 195
 	$boarddir = dirname(__FILE__);
196
-if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources'))
196
+}
197
+if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources')) {
197 198
 	$sourcedir = $boarddir . '/Sources';
198
-if (!file_exists($cachedir) && file_exists($boarddir . '/cache'))
199
+}
200
+if (!file_exists($cachedir) && file_exists($boarddir . '/cache')) {
199 201
 	$cachedir = $boarddir . '/cache';
202
+}
200 203
 
201 204
 ######### Legacy Settings #########
202 205
 # UTF-8 is now the only character set supported in 2.1.
@@ -204,8 +207,9 @@  discard block
 block discarded – undo
204 207
 
205 208
 ########## Error-Catching ##########
206 209
 # Note: You shouldn't touch these settings.
207
-if (file_exists((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php'))
210
+if (file_exists((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php')) {
208 211
 	include((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php');
212
+}
209 213
 
210 214
 if (!isset($db_last_error))
211 215
 {
@@ -217,10 +221,11 @@  discard block
 block discarded – undo
217 221
 if (file_exists(dirname(__FILE__) . '/install.php'))
218 222
 {
219 223
 	$secure = false;
220
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
221
-		$secure = true;
222
-	elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
223
-		$secure = true;
224
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
225
+			$secure = true;
226
+	} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
227
+			$secure = true;
228
+	}
224 229
 
225 230
 	header('location: http' . ($secure ? 's' : '') . '://' . (empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']) . (strtr(dirname($_SERVER['PHP_SELF']), '\\', '/') == '/' ? '' : strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')) . '/install.php'); exit;
226 231
 }
Please login to merge, or discard this patch.
Sources/ManageScheduledTasks.php 1 patch
Braces   +57 added lines, -40 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
  * Scheduled tasks management dispatcher. This function checks permissions and delegates
@@ -41,10 +42,11 @@  discard block
 block discarded – undo
41 42
 	);
42 43
 
43 44
 	// We need to find what's the action.
44
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
45
-		$context['sub_action'] = $_REQUEST['sa'];
46
-	else
47
-		$context['sub_action'] = 'tasks';
45
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
46
+			$context['sub_action'] = $_REQUEST['sa'];
47
+	} else {
48
+			$context['sub_action'] = 'tasks';
49
+	}
48 50
 
49 51
 	// Now for the lovely tabs. That we all love.
50 52
 	$context[$context['admin_menu_name']]['tab_data'] = array(
@@ -94,9 +96,10 @@  discard block
 block discarded – undo
94 96
 
95 97
 		// Enable and disable as required.
96 98
 		$enablers = array(0);
97
-		foreach ($_POST['enable_task'] as $id => $enabled)
98
-			if ($enabled)
99
+		foreach ($_POST['enable_task'] as $id => $enabled) {
100
+					if ($enabled)
99 101
 				$enablers[] = (int) $id;
102
+		}
100 103
 
101 104
 		// Do the update!
102 105
 		$smcFunc['db_query']('', '
@@ -134,8 +137,9 @@  discard block
 block discarded – undo
134 137
 
135 138
 		// Lets figure out which ones they want to run.
136 139
 		$tasks = array();
137
-		foreach ($_POST['run_task'] as $task => $dummy)
138
-			$tasks[] = (int) $task;
140
+		foreach ($_POST['run_task'] as $task => $dummy) {
141
+					$tasks[] = (int) $task;
142
+		}
139 143
 
140 144
 		// Load up the tasks.
141 145
 		$request = $smcFunc['db_query']('', '
@@ -155,36 +159,41 @@  discard block
 block discarded – undo
155 159
 		while ($row = $smcFunc['db_fetch_assoc']($request))
156 160
 		{
157 161
 			// What kind of task are we handling?
158
-			if (!empty($row['callable']))
159
-				$task_string = $row['callable'];
162
+			if (!empty($row['callable'])) {
163
+							$task_string = $row['callable'];
164
+			}
160 165
 
161 166
 			// Default SMF task or old mods?
162
-			elseif (function_exists('scheduled_' . $row['task']))
163
-				$task_string = 'scheduled_' . $row['task'];
167
+			elseif (function_exists('scheduled_' . $row['task'])) {
168
+							$task_string = 'scheduled_' . $row['task'];
169
+			}
164 170
 
165 171
 			// One last resource, the task name.
166
-			elseif (!empty($row['task']))
167
-				$task_string = $row['task'];
172
+			elseif (!empty($row['task'])) {
173
+							$task_string = $row['task'];
174
+			}
168 175
 
169 176
 			$start_time = microtime(true);
170 177
 			// The functions got to exist for us to use it.
171
-			if (empty($task_string))
172
-				continue;
178
+			if (empty($task_string)) {
179
+							continue;
180
+			}
173 181
 
174 182
 			// Try to stop a timeout, this would be bad...
175 183
 			@set_time_limit(300);
176
-			if (function_exists('apache_reset_timeout'))
177
-				@apache_reset_timeout();
184
+			if (function_exists('apache_reset_timeout')) {
185
+							@apache_reset_timeout();
186
+			}
178 187
 
179 188
 			// Get the callable.
180 189
 			$callable_task = call_helper($task_string, true);
181 190
 
182 191
 			// Perform the task.
183
-			if (!empty($callable_task))
184
-				$completed = call_user_func($callable_task);
185
-
186
-			else
187
-				$completed = false;
192
+			if (!empty($callable_task)) {
193
+							$completed = call_user_func($callable_task);
194
+			} else {
195
+							$completed = false;
196
+			}
188 197
 
189 198
 			// Log that we did it ;)
190 199
 			if ($completed)
@@ -201,8 +210,9 @@  discard block
 block discarded – undo
201 210
 		$smcFunc['db_free_result']($request);
202 211
 
203 212
 		// If we had any errors, push them to session so we can pick them up next time to tell the user.
204
-		if (!empty($context['scheduled_errors']))
205
-			$_SESSION['st_error'] = $context['scheduled_errors'];
213
+		if (!empty($context['scheduled_errors'])) {
214
+					$_SESSION['st_error'] = $context['scheduled_errors'];
215
+		}
206 216
 
207 217
 		redirectexit('action=admin;area=scheduledtasks;done');
208 218
 	}
@@ -374,8 +384,9 @@  discard block
 block discarded – undo
374 384
 	$context['server_time'] = timeformat(time(), false, 'server');
375 385
 
376 386
 	// Cleaning...
377
-	if (!isset($_GET['tid']))
378
-		fatal_lang_error('no_access', false);
387
+	if (!isset($_GET['tid'])) {
388
+			fatal_lang_error('no_access', false);
389
+	}
379 390
 	$_GET['tid'] = (int) $_GET['tid'];
380 391
 
381 392
 	// Saving?
@@ -391,10 +402,12 @@  discard block
 block discarded – undo
391 402
 		preg_match('~(\d{1,2}):(\d{1,2})~', $_POST['offset'], $matches);
392 403
 
393 404
 		// If a half is empty then assume zero offset!
394
-		if (!isset($matches[2]) || $matches[2] > 59)
395
-			$matches[2] = 0;
396
-		if (!isset($matches[1]) || $matches[1] > 23)
397
-			$matches[1] = 0;
405
+		if (!isset($matches[2]) || $matches[2] > 59) {
406
+					$matches[2] = 0;
407
+		}
408
+		if (!isset($matches[1]) || $matches[1] > 23) {
409
+					$matches[1] = 0;
410
+		}
398 411
 
399 412
 		// Now the offset is easy; easy peasy - except we need to offset by a few hours...
400 413
 		$offset = $matches[1] * 3600 + $matches[2] * 60 - date('Z');
@@ -404,8 +417,9 @@  discard block
 block discarded – undo
404 417
 		$unit = in_array(substr($_POST['unit'], 0, 1), array('m', 'h', 'd', 'w')) ? substr($_POST['unit'], 0, 1) : 'd';
405 418
 
406 419
 		// Don't allow one minute intervals.
407
-		if ($interval == 1 && $unit == 'm')
408
-			$interval = 2;
420
+		if ($interval == 1 && $unit == 'm') {
421
+					$interval = 2;
422
+		}
409 423
 
410 424
 		// Is it disabled?
411 425
 		$disabled = !isset($_POST['enabled']) ? 1 : 0;
@@ -443,8 +457,9 @@  discard block
 block discarded – undo
443 457
 	);
444 458
 
445 459
 	// Should never, ever, happen!
446
-	if ($smcFunc['db_num_rows']($request) == 0)
447
-		fatal_lang_error('no_access', false);
460
+	if ($smcFunc['db_num_rows']($request) == 0) {
461
+			fatal_lang_error('no_access', false);
462
+	}
448 463
 
449 464
 	while ($row = $smcFunc['db_fetch_assoc']($request))
450 465
 	{
@@ -602,13 +617,14 @@  discard block
 block discarded – undo
602 617
 		)
603 618
 	);
604 619
 	$log_entries = array();
605
-	while ($row = $smcFunc['db_fetch_assoc']($request))
606
-		$log_entries[] = array(
620
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
621
+			$log_entries[] = array(
607 622
 			'id' => $row['id_log'],
608 623
 			'name' => isset($txt['scheduled_task_' . $row['task']]) ? $txt['scheduled_task_' . $row['task']] : $row['task'],
609 624
 			'time_run' => $row['time_run'],
610 625
 			'time_taken' => $row['time_taken'],
611 626
 		);
627
+	}
612 628
 	$smcFunc['db_free_result']($request);
613 629
 
614 630
 	return $log_entries;
@@ -649,8 +665,9 @@  discard block
 block discarded – undo
649 665
 
650 666
 	call_integration_hook('integrate_scheduled_tasks_settings', array(&$config_vars));
651 667
 
652
-	if ($return_config)
653
-		return $config_vars;
668
+	if ($return_config) {
669
+			return $config_vars;
670
+	}
654 671
 
655 672
 	// Set up the template.
656 673
 	$context['page_title'] = $txt['scheduled_tasks_settings'];
Please login to merge, or discard this patch.
Sources/Subs-BoardIndex.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 	$smcFunc['db_free_result']($result_boards);
136 136
 
137 137
 	// Run through the categories and boards (or only boards)....
138
-	for (reset($row_boards); key($row_boards)!==null; next($row_boards))
138
+	for (reset($row_boards); key($row_boards) !== null; next($row_boards))
139 139
 	{
140 140
 		$row_board = current($row_boards);
141 141
 
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 					$row_boards[$row_board['id_parent']]['id_msg'] = $row_board['id_msg'];
304 304
 					$row_boards[$row_board['id_parent']]['subject'] = $row_board['subject'];
305 305
 					$row_boards[$row_board['id_parent']]['poster_time'] = $row_board['poster_time'];
306
-					$row_boards[$row_board['id_parent']]['short_subject'] = (!empty($row_board['short_subject']) ? $row_board['short_subject'] : '') ;
306
+					$row_boards[$row_board['id_parent']]['short_subject'] = (!empty($row_board['short_subject']) ? $row_board['short_subject'] : '');
307 307
 					$row_boards[$row_board['id_parent']]['poster_name'] = $row_board['poster_name'];
308 308
 					$row_boards[$row_board['id_parent']]['real_name'] = $row_board['real_name'];
309 309
 					$row_boards[$row_board['id_parent']]['id_member'] = $row_board['id_member'];
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 
369 369
 		// Set the last post in the root board 
370 370
 		if (!$isChild && !empty($row_board['poster_time'])
371
-			&& ( empty($this_category[$row_board['id_board']]['last_post']['timestamp'])
371
+			&& (empty($this_category[$row_board['id_board']]['last_post']['timestamp'])
372 372
 				|| $this_category[$row_board['id_board']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time'])
373 373
 				)
374 374
 			)
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 	if ($boardIndexOptions['include_categories'])
399 399
 		foreach ($categories as &$category)
400 400
 		{
401
-			foreach ($category['boards'] as &$board )
401
+			foreach ($category['boards'] as &$board)
402 402
 			{
403 403
 				if (!empty($moderators[$board['id']]))
404 404
 				{
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
 			}
421 421
 		}
422 422
 	else
423
-		foreach ($this_category as &$board )
423
+		foreach ($this_category as &$board)
424 424
 		{
425 425
 			if (!empty($moderators[$board['id']]))
426 426
 			{
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
 				$board['last_post']['last_post_message'] = sprintf($txt['last_post_message'], $board['last_post']['member']['link'], $board['last_post']['link'], $board['last_post']['time'] > 0 ? timeformat($board['last_post']['time']) : $txt['not_applicable']);
442 442
 		}
443 443
 
444
-	unset($category,$board);
444
+	unset($category, $board);
445 445
 
446 446
 	if ($boardIndexOptions['include_categories'])
447 447
 		sortCategories($categories);
Please login to merge, or discard this patch.
Braces   +85 added lines, -64 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
  * Fetches a list of boards and (optional) categories including
@@ -37,19 +38,21 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Boards.php');
38 39
 
39 40
 	// For performance, track the latest post while going through the boards.
40
-	if (!empty($boardIndexOptions['set_latest_post']))
41
-		$latest_post = array(
41
+	if (!empty($boardIndexOptions['set_latest_post'])) {
42
+			$latest_post = array(
42 43
 			'timestamp' => 0,
43 44
 			'ref' => 0,
44 45
 		);
46
+	}
45 47
 
46 48
 	// This setting is not allowed to be empty
47
-	if (empty($modSettings['boardindex_max_depth']))
48
-		$modSettings['boardindex_max_depth'] = 1;
49
+	if (empty($modSettings['boardindex_max_depth'])) {
50
+			$modSettings['boardindex_max_depth'] = 1;
51
+	}
49 52
 
50 53
 	// Find all boards and categories, as well as related information.  This will be sorted by the natural order of boards and categories, which we control.
51
-	if ($boardIndexOptions['parent_id'] != 0 && $smcFunc['db_cte_support']())
52
-		$result_boards = $smcFunc['db_query']('', '
54
+	if ($boardIndexOptions['parent_id'] != 0 && $smcFunc['db_cte_support']()) {
55
+			$result_boards = $smcFunc['db_query']('', '
53 56
 			WITH RECURSIVE 
54 57
 				boards_cte (child_level, id_board, name , description, redirect, num_posts, num_topics, unapproved_posts, unapproved_topics, id_parent, id_msg_updated, id_cat, id_last_msg, board_order)
55 58
 			as
@@ -91,8 +94,8 @@  discard block
 block discarded – undo
91 94
 				'id_parent' => $boardIndexOptions['parent_id'],
92 95
 			)
93 96
 		);
94
-	else
95
-		$result_boards = $smcFunc['db_query']('', '
97
+	} else {
98
+			$result_boards = $smcFunc['db_query']('', '
96 99
 			SELECT' . ($boardIndexOptions['include_categories'] ? '
97 100
 				c.id_cat, c.name AS cat_name, c.description AS cat_desc,' : '') . '
98 101
 				b.id_board, b.name AS board_name, b.description,
@@ -120,18 +123,21 @@  discard block
 block discarded – undo
120 123
 				'blank_string' => '',
121 124
 			)
122 125
 		);
126
+	}
123 127
 
124 128
 	// Start with an empty array.
125
-	if ($boardIndexOptions['include_categories'])
126
-		$categories = array();
127
-	else
128
-		$this_category = array();
129
+	if ($boardIndexOptions['include_categories']) {
130
+			$categories = array();
131
+	} else {
132
+			$this_category = array();
133
+	}
129 134
 	$boards = array();
130 135
 
131 136
 	// Children can affect parents, so we need to gather all the boards first and then process them after.
132 137
 	$row_boards = array();
133
-	while ($row_board = $smcFunc['db_fetch_assoc']($result_boards))
134
-		$row_boards[$row_board['id_board']] = $row_board;
138
+	while ($row_board = $smcFunc['db_fetch_assoc']($result_boards)) {
139
+			$row_boards[$row_board['id_board']] = $row_board;
140
+	}
135 141
 	$smcFunc['db_free_result']($result_boards);
136 142
 
137 143
 	// Run through the categories and boards (or only boards)....
@@ -144,8 +150,9 @@  discard block
 block discarded – undo
144 150
 		$row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0';
145 151
 
146 152
 		// Add parent boards to the $boards list later used to fetch moderators
147
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'])
148
-			$boards[] = $row_board['id_board'];
153
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) {
154
+					$boards[] = $row_board['id_board'];
155
+		}
149 156
 
150 157
 		if ($boardIndexOptions['include_categories'])
151 158
 		{
@@ -167,8 +174,9 @@  discard block
 block discarded – undo
167 174
 			}
168 175
 
169 176
 			// If this board has new posts in it (and isn't the recycle bin!) then the category is new.
170
-			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board'])
171
-				$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']);
177
+			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) {
178
+							$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']);
179
+			}
172 180
 
173 181
 			// Avoid showing category unread link where it only has redirection boards.
174 182
 			$categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect'];
@@ -187,8 +195,9 @@  discard block
 block discarded – undo
187 195
 				$isChild = false;
188 196
 
189 197
 				// We might or might not have already added this board, so...
190
-				if (!isset($this_category[$row_board['id_board']]))
191
-					$this_category[$row_board['id_board']] = array();
198
+				if (!isset($this_category[$row_board['id_board']])) {
199
+									$this_category[$row_board['id_board']] = array();
200
+				}
192 201
 
193 202
 				$this_category[$row_board['id_board']] += array(
194 203
 					'new' => empty($row_board['is_read']),
@@ -221,14 +230,12 @@  discard block
 block discarded – undo
221 230
 				{
222 231
 					$this_category[$row_board['id_board']]['board_class'] = 'redirect';
223 232
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board'];
224
-				}
225
-				elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
233
+				} elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
226 234
 				{
227 235
 					// If we're showing to guests, we want to give them the idea that something interesting is going on!
228 236
 					$this_category[$row_board['id_board']]['board_class'] = 'on';
229 237
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts'];
230
-				}
231
-				else
238
+				} else
232 239
 				{
233 240
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts'];
234 241
 				}
@@ -240,12 +247,13 @@  discard block
 block discarded – undo
240 247
 			$isChild = true;
241 248
 
242 249
 			// Ensure the parent has at least the most important info defined
243
-			if (!isset($this_category[$row_board['id_parent']]))
244
-				$this_category[$row_board['id_parent']] = array(
250
+			if (!isset($this_category[$row_board['id_parent']])) {
251
+							$this_category[$row_board['id_parent']] = array(
245 252
 					'children' => array(),
246 253
 					'children_new' => false,
247 254
 					'board_class' => 'off',
248 255
 				);
256
+			}
249 257
 
250 258
 			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']] = array(
251 259
 				'id' => $row_board['id_board'],
@@ -289,8 +297,9 @@  discard block
 block discarded – undo
289 297
 			// Propagate some values to the parent board
290 298
 			if (isset($row_boards[$row_board['id_parent']]))
291 299
 			{
292
-				if (empty($row_board['is_read']))
293
-					$row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read'];
300
+				if (empty($row_board['is_read'])) {
301
+									$row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read'];
302
+				}
294 303
 
295 304
 				if (!empty($boardIndexOptions['countChildPosts']) && !$row_board['is_redirect'])
296 305
 				{
@@ -341,20 +350,20 @@  discard block
 block discarded – undo
341 350
 			'topic' => $row_board['id_topic']
342 351
 		);
343 352
 
344
-		if (!empty($settings['avatars_on_boardIndex']))
345
-			$this_last_post['member']['avatar'] = set_avatar_data(array(
353
+		if (!empty($settings['avatars_on_boardIndex'])) {
354
+					$this_last_post['member']['avatar'] = set_avatar_data(array(
346 355
 				'avatar' => $row_board['avatar'],
347 356
 				'email' => $row_board['email_address'],
348 357
 				'filename' => !empty($row_board['member_filename']) ? $row_board['member_filename'] : '',
349 358
 			));
359
+		}
350 360
 
351 361
 		// Provide the href and link.
352 362
 		if ($row_board['subject'] != '')
353 363
 		{
354 364
 			$this_last_post['href'] = $scripturl . '?topic=' . $row_board['id_topic'] . '.msg' . ($user_info['is_guest'] ? $row_board['id_msg'] : $row_board['new_from']) . (empty($row_board['is_read']) ? ';boardseen' : '') . '#new';
355 365
 			$this_last_post['link'] = '<a href="' . $this_last_post['href'] . '" title="' . $row_board['subject'] . '">' . $row_board['short_subject'] . '</a>';
356
-		}
357
-		else
366
+		} else
358 367
 		{
359 368
 			$this_last_post['href'] = '';
360 369
 			$this_last_post['link'] = $txt['not_applicable'];
@@ -363,27 +372,31 @@  discard block
 block discarded – undo
363 372
 
364 373
 		// Set the last post in the parent board.
365 374
 		if ($isChild && !empty($row_board['poster_time']) 
366
-				&& $row_boards[$row_board['id_parent']]['poster_time'] < $row_board['poster_time'])
367
-			$this_category[$row_board['id_parent']]['last_post'] = $this_last_post;
375
+				&& $row_boards[$row_board['id_parent']]['poster_time'] < $row_board['poster_time']) {
376
+					$this_category[$row_board['id_parent']]['last_post'] = $this_last_post;
377
+		}
368 378
 
369 379
 		// Set the last post in the root board 
370 380
 		if (!$isChild && !empty($row_board['poster_time'])
371 381
 			&& ( empty($this_category[$row_board['id_board']]['last_post']['timestamp'])
372 382
 				|| $this_category[$row_board['id_board']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time'])
373 383
 				)
374
-			)
375
-			$this_category[$row_board['id_board']]['last_post'] = $this_last_post;
384
+			) {
385
+					$this_category[$row_board['id_board']]['last_post'] = $this_last_post;
386
+		}
376 387
 
377 388
 		// Just in the child...?
378
-		if ($isChild)
379
-			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post;
389
+		if ($isChild) {
390
+					$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post;
391
+		}
380 392
 
381 393
 		// Determine a global most recent topic.
382
-		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard)
383
-			$latest_post = array(
394
+		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) {
395
+					$latest_post = array(
384 396
 				'timestamp' => $row_board['poster_time'],
385 397
 				'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'],
386 398
 			);
399
+		}
387 400
 	}
388 401
 	
389 402
 	/* The board's and children's 'last_post's have:
@@ -395,16 +408,18 @@  discard block
 block discarded – undo
395 408
 	$boards = array_unique($boards);
396 409
 	$moderators = getBoardModerators($boards);
397 410
 	$groups = getBoardModeratorGroups($boards);
398
-	if ($boardIndexOptions['include_categories'])
399
-		foreach ($categories as &$category)
411
+	if ($boardIndexOptions['include_categories']) {
412
+			foreach ($categories as &$category)
400 413
 		{
401 414
 			foreach ($category['boards'] as &$board )
402 415
 			{
403 416
 				if (!empty($moderators[$board['id']]))
404 417
 				{
405 418
 					$board['moderators'] = $moderators[$board['id']];
406
-					foreach ($moderators[$board['id']] as $moderator)
407
-						$board['link_moderators'][] = $moderator['link'];
419
+	}
420
+					foreach ($moderators[$board['id']] as $moderator) {
421
+											$board['link_moderators'][] = $moderator['link'];
422
+					}
408 423
 				}
409 424
 				if (!empty($groups[$board['id']]))
410 425
 				{
@@ -415,18 +430,20 @@  discard block
 block discarded – undo
415 430
 						$board['link_moderator_groups'][] = $group['link'];
416 431
 					}
417 432
 				}
418
-				if (!empty($board['last_post']))
419
-					$board['last_post']['last_post_message'] = sprintf($txt['last_post_message'], $board['last_post']['member']['link'], $board['last_post']['link'], $board['last_post']['time'] > 0 ? timeformat($board['last_post']['time']) : $txt['not_applicable']);
433
+				if (!empty($board['last_post'])) {
434
+									$board['last_post']['last_post_message'] = sprintf($txt['last_post_message'], $board['last_post']['member']['link'], $board['last_post']['link'], $board['last_post']['time'] > 0 ? timeformat($board['last_post']['time']) : $txt['not_applicable']);
435
+				}
420 436
 			}
421
-		}
422
-	else
423
-		foreach ($this_category as &$board )
437
+		} else {
438
+			foreach ($this_category as &$board )
424 439
 		{
425 440
 			if (!empty($moderators[$board['id']]))
426 441
 			{
427 442
 				$board['moderators'] = $moderators[$board['id']];
428
-				foreach ($moderators[$board['id']] as $moderator)
429
-					$board['link_moderators'][] = $moderator['link'];
443
+	}
444
+				foreach ($moderators[$board['id']] as $moderator) {
445
+									$board['link_moderators'][] = $moderator['link'];
446
+				}
430 447
 			}
431 448
 			if (!empty($groups[$board['id']]))
432 449
 			{
@@ -437,26 +454,30 @@  discard block
 block discarded – undo
437 454
 					$board['link_moderator_groups'][] = $group['link'];
438 455
 				}
439 456
 			}
440
-			if (!empty($board['last_post']))
441
-				$board['last_post']['last_post_message'] = sprintf($txt['last_post_message'], $board['last_post']['member']['link'], $board['last_post']['link'], $board['last_post']['time'] > 0 ? timeformat($board['last_post']['time']) : $txt['not_applicable']);
457
+			if (!empty($board['last_post'])) {
458
+							$board['last_post']['last_post_message'] = sprintf($txt['last_post_message'], $board['last_post']['member']['link'], $board['last_post']['link'], $board['last_post']['time'] > 0 ? timeformat($board['last_post']['time']) : $txt['not_applicable']);
459
+			}
442 460
 		}
443 461
 
444 462
 	unset($category,$board);
445 463
 
446
-	if ($boardIndexOptions['include_categories'])
447
-		sortCategories($categories);
448
-	else
449
-		sortBoards($this_category);
464
+	if ($boardIndexOptions['include_categories']) {
465
+			sortCategories($categories);
466
+	} else {
467
+			sortBoards($this_category);
468
+	}
450 469
 
451 470
 	// By now we should know the most recent post...if we wanna know it that is.
452
-	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref']))
453
-		$context['latest_post'] = $latest_post['ref'];
471
+	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) {
472
+			$context['latest_post'] = $latest_post['ref'];
473
+	}
454 474
 
455 475
 	// I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea.
456
-	if ($boardIndexOptions['include_categories'])
457
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
458
-	else
459
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
476
+	if ($boardIndexOptions['include_categories']) {
477
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
478
+	} else {
479
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
480
+	}
460 481
 
461 482
 	return $boardIndexOptions['include_categories'] ? $categories : $this_category;
462 483
 }
Please login to merge, or discard this patch.