Completed
Pull Request — release-2.1 (#3890)
by Fran
12:33 queued 05:26
created
Sources/ManageLanguages.php 1 patch
Braces   +190 added lines, -142 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * This is the main function for the languages area.
@@ -153,11 +154,11 @@  discard block
 block discarded – undo
153 154
 	$language_list = new xmlArray(fetch_web_data($url), true);
154 155
 
155 156
 	// Check that the site responded and that the language exists.
156
-	if (!$language_list->exists('languages'))
157
-		$context['smf_error'] = 'no_response';
158
-	elseif (!$language_list->exists('languages/language'))
159
-		$context['smf_error'] = 'no_files';
160
-	else
157
+	if (!$language_list->exists('languages')) {
158
+			$context['smf_error'] = 'no_response';
159
+	} elseif (!$language_list->exists('languages/language')) {
160
+			$context['smf_error'] = 'no_files';
161
+	} else
161 162
 	{
162 163
 		$language_list = $language_list->path('languages[0]');
163 164
 		$lang_files = $language_list->set('language');
@@ -165,8 +166,9 @@  discard block
 block discarded – undo
165 166
 		foreach ($lang_files as $file)
166 167
 		{
167 168
 			// Were we searching?
168
-			if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false)
169
-				continue;
169
+			if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) {
170
+							continue;
171
+			}
170 172
 
171 173
 			$smf_languages[] = array(
172 174
 				'id' => $file->fetch('id'),
@@ -177,10 +179,11 @@  discard block
 block discarded – undo
177 179
 				'install_link' => '<a href="' . $scripturl . '?action=admin;area=languages;sa=downloadlang;did=' . $file->fetch('id') . ';' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['add_language_smf_install'] . '</a>',
178 180
 			);
179 181
 		}
180
-		if (empty($smf_languages))
181
-			$context['smf_error'] = 'no_files';
182
-		else
183
-			return $smf_languages;
182
+		if (empty($smf_languages)) {
183
+					$context['smf_error'] = 'no_files';
184
+		} else {
185
+					return $smf_languages;
186
+		}
184 187
 	}
185 188
 }
186 189
 
@@ -202,8 +205,9 @@  discard block
 block discarded – undo
202 205
 	require_once($sourcedir . '/Subs-Package.php');
203 206
 
204 207
 	// Clearly we need to know what to request.
205
-	if (!isset($_GET['did']))
206
-		fatal_lang_error('no_access', false);
208
+	if (!isset($_GET['did'])) {
209
+			fatal_lang_error('no_access', false);
210
+	}
207 211
 
208 212
 	// Some lovely context.
209 213
 	$context['download_id'] = $_GET['did'];
@@ -223,8 +227,9 @@  discard block
 block discarded – undo
223 227
 		foreach ($_POST['copy_file'] as $file)
224 228
 		{
225 229
 			// Check it's not very bad.
226
-			if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file)))
227
-				fatal_error($txt['languages_download_illegal_paths']);
230
+			if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) {
231
+							fatal_error($txt['languages_download_illegal_paths']);
232
+			}
228 233
 
229 234
 			$chmod_files[] = $boarddir . '/' . $file;
230 235
 			$install_files[] = $file;
@@ -235,8 +240,9 @@  discard block
 block discarded – undo
235 240
 		$files_left = $file_status['files']['notwritable'];
236 241
 
237 242
 		// Something not writable?
238
-		if (!empty($files_left))
239
-			$context['error_message'] = $txt['languages_download_not_chmod'];
243
+		if (!empty($files_left)) {
244
+					$context['error_message'] = $txt['languages_download_not_chmod'];
245
+		}
240 246
 		// Otherwise, go go go!
241 247
 		elseif (!empty($install_files))
242 248
 		{
@@ -250,11 +256,13 @@  discard block
 block discarded – undo
250 256
 	}
251 257
 
252 258
 	// Open up the old china.
253
-	if (!isset($archive_content))
254
-		$archive_content = read_tgz_file('http://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
259
+	if (!isset($archive_content)) {
260
+			$archive_content = read_tgz_file('http://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
261
+	}
255 262
 
256
-	if (empty($archive_content))
257
-		fatal_error($txt['add_language_error_no_response']);
263
+	if (empty($archive_content)) {
264
+			fatal_error($txt['add_language_error_no_response']);
265
+	}
258 266
 
259 267
 	// Now for each of the files, let's do some *stuff*
260 268
 	$context['files'] = array(
@@ -269,8 +277,9 @@  discard block
 block discarded – undo
269 277
 		$extension = substr($filename, strrpos($filename, '.') + 1);
270 278
 
271 279
 		// Don't do anything with files we don't understand.
272
-		if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt')))
273
-			continue;
280
+		if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) {
281
+					continue;
282
+		}
274 283
 
275 284
 		// Basic data.
276 285
 		$context_data = array(
@@ -289,8 +298,9 @@  discard block
 block discarded – undo
289 298
 		// Does the file exist, is it different and can we overwrite?
290 299
 		if (file_exists($boarddir . '/' . $file['filename']))
291 300
 		{
292
-			if (is_writable($boarddir . '/' . $file['filename']))
293
-				$context_data['writable'] = true;
301
+			if (is_writable($boarddir . '/' . $file['filename'])) {
302
+							$context_data['writable'] = true;
303
+			}
294 304
 
295 305
 			// Finally, do we actually think the content has changed?
296 306
 			if ($file['size'] == filesize($boarddir . '/' . $file['filename']) && $file['md5'] == md5_file($boarddir . '/' . $file['filename']))
@@ -303,16 +313,17 @@  discard block
 block discarded – undo
303 313
 			{
304 314
 				$context_data['exists'] = 'same';
305 315
 				$context_data['default_copy'] = false;
316
+			} else {
317
+							$context_data['exists'] = 'different';
306 318
 			}
307
-			else
308
-				$context_data['exists'] = 'different';
309 319
 		}
310 320
 		// No overwrite?
311 321
 		else
312 322
 		{
313 323
 			// Can we at least stick it in the directory...
314
-			if (is_writable($boarddir . '/' . $dirname))
315
-				$context_data['writable'] = true;
324
+			if (is_writable($boarddir . '/' . $dirname)) {
325
+							$context_data['writable'] = true;
326
+			}
316 327
 		}
317 328
 
318 329
 		// 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...
@@ -327,8 +338,9 @@  discard block
 block discarded – undo
327 338
 			list ($name, $language) = explode('.', $filename);
328 339
 
329 340
 			// Let's get the new version, I like versions, they tell me that I'm up to date.
330
-			if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1)
331
-				$context_data['version'] = $match[1];
341
+			if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) {
342
+							$context_data['version'] = $match[1];
343
+			}
332 344
 
333 345
 			// Now does the old file exist - if so what is it's version?
334 346
 			if (file_exists($boarddir . '/' . $file['filename']))
@@ -344,34 +356,35 @@  discard block
 block discarded – undo
344 356
 					$context_data['cur_version'] = $match[1];
345 357
 
346 358
 					// How does this compare?
347
-					if ($context_data['cur_version'] == $context_data['version'])
348
-						$context_data['version_compare'] = 'same';
349
-					elseif ($context_data['cur_version'] > $context_data['version'])
350
-						$context_data['version_compare'] = 'older';
359
+					if ($context_data['cur_version'] == $context_data['version']) {
360
+											$context_data['version_compare'] = 'same';
361
+					} elseif ($context_data['cur_version'] > $context_data['version']) {
362
+											$context_data['version_compare'] = 'older';
363
+					}
351 364
 
352 365
 					// Don't recommend copying if the version is the same.
353
-					if ($context_data['version_compare'] != 'newer')
354
-						$context_data['default_copy'] = false;
366
+					if ($context_data['version_compare'] != 'newer') {
367
+											$context_data['default_copy'] = false;
368
+					}
355 369
 				}
356 370
 			}
357 371
 
358 372
 			// Add the context data to the main set.
359 373
 			$context['files']['lang'][] = $context_data;
360
-		}
361
-		elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false)
374
+		} elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false)
362 375
 		{
363 376
 			// Registration agreement is a primary file
364 377
 			$context['files']['lang'][] = $context_data;
365
-		}
366
-		else
378
+		} else
367 379
 		{
368 380
 			// There shouldn't be anything else, but load this into "other" in case we decide to handle it in the future
369 381
 			$context['files']['other'][] = $context_data;
370 382
 		}
371 383
 
372 384
 		// Collect together all non-writable areas.
373
-		if (!$context_data['writable'])
374
-			$context['make_writable'][] = $context_data['destination'];
385
+		if (!$context_data['writable']) {
386
+					$context['make_writable'][] = $context_data['destination'];
387
+		}
375 388
 	}
376 389
 
377 390
 	// Before we go to far can we make anything writable, eh, eh?
@@ -386,22 +399,24 @@  discard block
 block discarded – undo
386 399
 		{
387 400
 			if ($type == 'lang')
388 401
 			{
389
-				foreach ($data as $k => $file)
390
-					if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
402
+				foreach ($data as $k => $file) {
403
+									if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
391 404
 						$context['files'][$type][$k]['writable'] = true;
392
-			}
393
-			else
405
+				}
406
+			} else
394 407
 			{
395
-				foreach ($data as $theme => $files)
396
-					foreach ($files as $k => $file)
408
+				foreach ($data as $theme => $files) {
409
+									foreach ($files as $k => $file)
397 410
 						if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
398 411
 							$context['files'][$type][$theme][$k]['writable'] = true;
412
+				}
399 413
 			}
400 414
 		}
401 415
 
402 416
 		// Are we going to need more language stuff?
403
-		if (!empty($context['still_not_writable']))
404
-			loadLanguage('Packages');
417
+		if (!empty($context['still_not_writable'])) {
418
+					loadLanguage('Packages');
419
+		}
405 420
 	}
406 421
 
407 422
 	// This is the list for the main files.
@@ -614,12 +629,13 @@  discard block
 block discarded – undo
614 629
 	highlightSelected("list_language_list_' . ($language == '' ? 'english' : $language) . '");', true);
615 630
 
616 631
 	// Display a warning if we cannot edit the default setting.
617
-	if (!is_writable($boarddir . '/Settings.php'))
618
-		$listOptions['additional_rows'][] = array(
632
+	if (!is_writable($boarddir . '/Settings.php')) {
633
+			$listOptions['additional_rows'][] = array(
619 634
 				'position' => 'after_title',
620 635
 				'value' => $txt['language_settings_writable'],
621 636
 				'class' => 'smalltext alert',
622 637
 			);
638
+	}
623 639
 
624 640
 	require_once($sourcedir . '/Subs-List.php');
625 641
 	createList($listOptions);
@@ -661,10 +677,11 @@  discard block
 block discarded – undo
661 677
 
662 678
 	// Put them back.
663 679
 	$settings['actual_theme_dir'] = $backup_actual_theme_dir;
664
-	if (!empty($backup_base_theme_dir))
665
-		$settings['base_theme_dir'] = $backup_base_theme_dir;
666
-	else
667
-		unset($settings['base_theme_dir']);
680
+	if (!empty($backup_base_theme_dir)) {
681
+			$settings['base_theme_dir'] = $backup_base_theme_dir;
682
+	} else {
683
+			unset($settings['base_theme_dir']);
684
+	}
668 685
 
669 686
 	// Get the language files and data...
670 687
 	foreach ($context['languages'] as $lang)
@@ -693,13 +710,15 @@  discard block
 block discarded – undo
693 710
 	while ($row = $smcFunc['db_fetch_assoc']($request))
694 711
 	{
695 712
 		// Default?
696
-		if (empty($row['lngfile']) || !isset($languages[$row['lngfile']]))
697
-			$row['lngfile'] = $language;
713
+		if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) {
714
+					$row['lngfile'] = $language;
715
+		}
698 716
 
699
-		if (!isset($languages[$row['lngfile']]) && isset($languages['english']))
700
-			$languages['english']['count'] += $row['num_users'];
701
-		elseif (isset($languages[$row['lngfile']]))
702
-			$languages[$row['lngfile']]['count'] += $row['num_users'];
717
+		if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) {
718
+					$languages['english']['count'] += $row['num_users'];
719
+		} elseif (isset($languages[$row['lngfile']])) {
720
+					$languages[$row['lngfile']]['count'] += $row['num_users'];
721
+		}
703 722
 	}
704 723
 	$smcFunc['db_free_result']($request);
705 724
 
@@ -739,13 +758,15 @@  discard block
 block discarded – undo
739 758
 
740 759
 	call_integration_hook('integrate_language_settings', array(&$config_vars));
741 760
 
742
-	if ($return_config)
743
-		return $config_vars;
761
+	if ($return_config) {
762
+			return $config_vars;
763
+	}
744 764
 
745 765
 	// Get our languages. No cache and use utf8.
746 766
 	getLanguages(false, false);
747
-	foreach ($context['languages'] as $lang)
748
-		$config_vars['language'][4][$lang['filename']] = array($lang['filename'], strtr($lang['name'], array('-utf8' => ' (UTF-8)')));
767
+	foreach ($context['languages'] as $lang) {
768
+			$config_vars['language'][4][$lang['filename']] = array($lang['filename'], strtr($lang['name'], array('-utf8' => ' (UTF-8)')));
769
+	}
749 770
 
750 771
 	// Saving settings?
751 772
 	if (isset($_REQUEST['save']))
@@ -755,8 +776,9 @@  discard block
 block discarded – undo
755 776
 		call_integration_hook('integrate_save_language_settings', array(&$config_vars));
756 777
 
757 778
 		saveSettings($config_vars);
758
-		if (!$settings_not_writable && !$settings_backup_fail)
759
-			$_SESSION['adm-save'] = true;
779
+		if (!$settings_not_writable && !$settings_backup_fail) {
780
+					$_SESSION['adm-save'] = true;
781
+		}
760 782
 		redirectexit('action=admin;area=languages;sa=settings');
761 783
 	}
762 784
 
@@ -765,10 +787,11 @@  discard block
 block discarded – undo
765 787
 	$context['settings_title'] = $txt['language_settings'];
766 788
 	$context['save_disabled'] = $settings_not_writable;
767 789
 
768
-	if ($settings_not_writable)
769
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
770
-	elseif ($settings_backup_fail)
771
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
790
+	if ($settings_not_writable) {
791
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
792
+	} elseif ($settings_backup_fail) {
793
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
794
+	}
772 795
 
773 796
 	// Fill the config array.
774 797
 	prepareServerSettingsContext($config_vars);
@@ -815,8 +838,9 @@  discard block
 block discarded – undo
815 838
 			'theme_dir' => $settings['default_theme_dir'],
816 839
 		),
817 840
 	);
818
-	while ($row = $smcFunc['db_fetch_assoc']($request))
819
-		$themes[$row['id_theme']][$row['variable']] = $row['value'];
841
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
842
+			$themes[$row['id_theme']][$row['variable']] = $row['value'];
843
+	}
820 844
 	$smcFunc['db_free_result']($request);
821 845
 
822 846
 	// This will be where we look
@@ -828,14 +852,16 @@  discard block
 block discarded – undo
828 852
 	// Check we have themes with a path and a name - just in case - and add the path.
829 853
 	foreach ($themes as $id => $data)
830 854
 	{
831
-		if (count($data) != 2)
832
-			unset($themes[$id]);
833
-		elseif (is_dir($data['theme_dir'] . '/languages'))
834
-			$lang_dirs[$id] = $data['theme_dir'] . '/languages';
855
+		if (count($data) != 2) {
856
+					unset($themes[$id]);
857
+		} elseif (is_dir($data['theme_dir'] . '/languages')) {
858
+					$lang_dirs[$id] = $data['theme_dir'] . '/languages';
859
+		}
835 860
 
836 861
 		// How about image directories?
837
-		if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id']))
838
-			$images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
862
+		if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) {
863
+					$images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
864
+		}
839 865
 	}
840 866
 
841 867
 	$current_file = $file_id ? $lang_dirs[$theme_id] . '/' . $file_id . '.' . $context['lang_id'] . '.php' : '';
@@ -849,15 +875,17 @@  discard block
 block discarded – undo
849 875
 		while ($entry = $dir->read())
850 876
 		{
851 877
 			// We're only after the files for this language.
852
-			if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0)
853
-				continue;
878
+			if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) {
879
+							continue;
880
+			}
854 881
 
855
-			if (!isset($context['possible_files'][$theme]))
856
-				$context['possible_files'][$theme] = array(
882
+			if (!isset($context['possible_files'][$theme])) {
883
+							$context['possible_files'][$theme] = array(
857 884
 					'id' => $theme,
858 885
 					'name' => $themes[$theme]['name'],
859 886
 					'files' => array(),
860 887
 				);
888
+			}
861 889
 
862 890
 			$context['possible_files'][$theme]['files'][] = array(
863 891
 				'id' => $matches[1],
@@ -886,31 +914,36 @@  discard block
 block discarded – undo
886 914
 		{
887 915
 			$_SESSION['last_backup_for'] = $context['lang_id'] . '$$$';
888 916
 			$result = package_create_backup('backup_lang_' . $context['lang_id']);
889
-			if (!$result)
890
-				fatal_lang_error('could_not_language_backup', false);
917
+			if (!$result) {
918
+							fatal_lang_error('could_not_language_backup', false);
919
+			}
891 920
 		}
892 921
 
893 922
 		// Second, loop through the array to remove the files.
894 923
 		foreach ($lang_dirs as $curPath)
895 924
 		{
896
-			foreach ($context['possible_files'][1]['files'] as $lang)
897
-				if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'))
925
+			foreach ($context['possible_files'][1]['files'] as $lang) {
926
+							if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'))
898 927
 					unlink($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php');
928
+			}
899 929
 
900 930
 			// Check for the email template.
901
-			if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'))
902
-				unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
931
+			if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) {
932
+							unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
933
+			}
903 934
 		}
904 935
 
905 936
 		// Third, the agreement file.
906
-		if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt'))
907
-			unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
937
+		if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) {
938
+					unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
939
+		}
908 940
 
909 941
 		// Fourth, a related images folder, if it exists...
910
-		if (!empty($images_dirs))
911
-			foreach ($images_dirs as $curPath)
942
+		if (!empty($images_dirs)) {
943
+					foreach ($images_dirs as $curPath)
912 944
 				if (is_dir($curPath))
913 945
 					deltree($curPath);
946
+		}
914 947
 
915 948
 		// Members can no longer use this language.
916 949
 		$smcFunc['db_query']('', '
@@ -995,8 +1028,9 @@  discard block
 block discarded – undo
995 1028
 		foreach ($_POST['entry'] as $k => $v)
996 1029
 		{
997 1030
 			// Only try to save if it's changed!
998
-			if ($_POST['entry'][$k] != $_POST['comp'][$k])
999
-				$save_strings[$k] = cleanLangString($v, false);
1031
+			if ($_POST['entry'][$k] != $_POST['comp'][$k]) {
1032
+							$save_strings[$k] = cleanLangString($v, false);
1033
+			}
1000 1034
 		}
1001 1035
 	}
1002 1036
 
@@ -1030,12 +1064,13 @@  discard block
 block discarded – undo
1030 1064
 		if ($multiline_cache)
1031 1065
 		{
1032 1066
 			preg_match('~\$(helptxt|txt|editortxt)\[\'(.+)\'\]\s?=\s?(.+);~ms', strtr($multiline_cache, array("\r" => '')), $matches);
1033
-			if (!empty($matches[3]))
1034
-				$entries[$matches[2]] = array(
1067
+			if (!empty($matches[3])) {
1068
+							$entries[$matches[2]] = array(
1035 1069
 					'type' => $matches[1],
1036 1070
 					'full' => $matches[0],
1037 1071
 					'entry' => $matches[3],
1038 1072
 				);
1073
+			}
1039 1074
 		}
1040 1075
 
1041 1076
 		// These are the entries we can definitely save.
@@ -1046,8 +1081,9 @@  discard block
 block discarded – undo
1046 1081
 		{
1047 1082
 			// Ignore some things we set separately.
1048 1083
 			$ignore_files = array('lang_character_set', 'lang_locale', 'lang_dictionary', 'lang_spelling', 'lang_rtl');
1049
-			if (in_array($entryKey, $ignore_files))
1050
-				continue;
1084
+			if (in_array($entryKey, $ignore_files)) {
1085
+							continue;
1086
+			}
1051 1087
 
1052 1088
 			// These are arrays that need breaking out.
1053 1089
 			$arrays = array('days', 'days_short', 'months', 'months_titles', 'months_short', 'happy_birthday_author', 'karlbenson1_author', 'nite0859_author', 'zwaldowski_author', 'geezmo_author', 'karlbenson2_author');
@@ -1080,9 +1116,9 @@  discard block
 block discarded – undo
1080 1116
 					{
1081 1117
 						$save_cache['entries'][$cur_index] = strtr($save_strings[$entryKey . '-+- ' . $cur_index], array('\'' => ''));
1082 1118
 						$save_cache['enabled'] = true;
1119
+					} else {
1120
+											$save_cache['entries'][$cur_index] = $subValue;
1083 1121
 					}
1084
-					else
1085
-						$save_cache['entries'][$cur_index] = $subValue;
1086 1122
 
1087 1123
 					$context['file_entries'][] = array(
1088 1124
 						'key' => $entryKey . '-+- ' . $cur_index,
@@ -1105,9 +1141,9 @@  discard block
 block discarded – undo
1105 1141
 						{
1106 1142
 							$items[] = $k2 . ' => \'' . $v2 . '\'';
1107 1143
 							$cur_index = $k2;
1144
+						} else {
1145
+													$items[] = '\'' . $v2 . '\'';
1108 1146
 						}
1109
-						else
1110
-							$items[] = '\'' . $v2 . '\'';
1111 1147
 
1112 1148
 						$cur_index++;
1113 1149
 					}
@@ -1117,15 +1153,15 @@  discard block
 block discarded – undo
1117 1153
 						'replace' => '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = array(' . implode(', ', $items) . ');',
1118 1154
 					);
1119 1155
 				}
1120
-			}
1121
-			else
1156
+			} else
1122 1157
 			{
1123 1158
 				// Saving?
1124 1159
 				if (isset($save_strings[$entryKey]) && $save_strings[$entryKey] != $entryValue['entry'])
1125 1160
 				{
1126 1161
 					// @todo Fix this properly.
1127
-					if ($save_strings[$entryKey] == '')
1128
-						$save_strings[$entryKey] = '\'\'';
1162
+					if ($save_strings[$entryKey] == '') {
1163
+											$save_strings[$entryKey] = '\'\'';
1164
+					}
1129 1165
 
1130 1166
 					// Set the new value.
1131 1167
 					$entryValue['entry'] = $save_strings[$entryKey];
@@ -1151,8 +1187,9 @@  discard block
 block discarded – undo
1151 1187
 			checkSession();
1152 1188
 
1153 1189
 			$file_contents = implode('', file($current_file));
1154
-			foreach ($final_saves as $save)
1155
-				$file_contents = strtr($file_contents, array($save['find'] => $save['replace']));
1190
+			foreach ($final_saves as $save) {
1191
+							$file_contents = strtr($file_contents, array($save['find'] => $save['replace']));
1192
+			}
1156 1193
 
1157 1194
 			// Save the actual changes.
1158 1195
 			$fp = fopen($current_file, 'w+');
@@ -1167,8 +1204,9 @@  discard block
 block discarded – undo
1167 1204
 	}
1168 1205
 
1169 1206
 	// If we saved, redirect.
1170
-	if ($madeSave)
1171
-		redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']);
1207
+	if ($madeSave) {
1208
+			redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']);
1209
+	}
1172 1210
 
1173 1211
 	createToken('admin-mlang');
1174 1212
 }
@@ -1200,8 +1238,9 @@  discard block
 block discarded – undo
1200 1238
 				// Toggle the escape.
1201 1239
 				$is_escape = !$is_escape;
1202 1240
 				// If we're now escaped don't add this string.
1203
-				if ($is_escape)
1204
-					continue;
1241
+				if ($is_escape) {
1242
+									continue;
1243
+				}
1205 1244
 			}
1206 1245
 			// Special case - parsed string with line break etc?
1207 1246
 			elseif (($string{$i} == 'n' || $string{$i} == 't') && $in_string == 2 && $is_escape)
@@ -1218,11 +1257,13 @@  discard block
 block discarded – undo
1218 1257
 				if ($in_string != 2 && ($in_string != 1 || !$is_escape))
1219 1258
 				{
1220 1259
 					// Is it the end of a single quote string?
1221
-					if ($in_string == 1)
1222
-						$in_string = 0;
1260
+					if ($in_string == 1) {
1261
+											$in_string = 0;
1262
+					}
1223 1263
 					// Otherwise it's the start!
1224
-					else
1225
-						$in_string = 1;
1264
+					else {
1265
+											$in_string = 1;
1266
+					}
1226 1267
 
1227 1268
 					// Don't actually include this character!
1228 1269
 					continue;
@@ -1235,19 +1276,22 @@  discard block
 block discarded – undo
1235 1276
 				if ($in_string != 1 && ($in_string != 2 || !$is_escape))
1236 1277
 				{
1237 1278
 					// Is it the end of a double quote string?
1238
-					if ($in_string == 2)
1239
-						$in_string = 0;
1279
+					if ($in_string == 2) {
1280
+											$in_string = 0;
1281
+					}
1240 1282
 					// Otherwise it's the start!
1241
-					else
1242
-						$in_string = 2;
1283
+					else {
1284
+											$in_string = 2;
1285
+					}
1243 1286
 
1244 1287
 					// Don't actually include this character!
1245 1288
 					continue;
1246 1289
 				}
1247 1290
 			}
1248 1291
 			// A join/space outside of a string is simply removed.
1249
-			elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.'))
1250
-				continue;
1292
+			elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.')) {
1293
+							continue;
1294
+			}
1251 1295
 			// Start of a variable?
1252 1296
 			elseif ($in_string == 0 && $string{$i} == '$')
1253 1297
 			{
@@ -1281,8 +1325,7 @@  discard block
 block discarded – undo
1281 1325
 
1282 1326
 		// Unhtml then rehtml the whole thing!
1283 1327
 		$new_string = $smcFunc['htmlspecialchars'](un_htmlspecialchars($new_string));
1284
-	}
1285
-	else
1328
+	} else
1286 1329
 	{
1287 1330
 		// Keep track of what we're doing...
1288 1331
 		$in_string = 0;
@@ -1311,10 +1354,11 @@  discard block
 block discarded – undo
1311 1354
 				preg_match('~\{%([\$A-Za-z0-9\'\[\]_-]+)%\}~', substr($string, $i), $matches);
1312 1355
 				if (!empty($matches[1]))
1313 1356
 				{
1314
-					if ($in_string == 1)
1315
-						$new_string .= '\' . ';
1316
-					elseif ($new_string)
1317
-						$new_string .= ' . ';
1357
+					if ($in_string == 1) {
1358
+											$new_string .= '\' . ';
1359
+					} elseif ($new_string) {
1360
+											$new_string .= ' . ';
1361
+					}
1318 1362
 
1319 1363
 					$new_string .= $matches[1];
1320 1364
 					$i += strlen($matches[1]) + 3;
@@ -1327,8 +1371,9 @@  discard block
 block discarded – undo
1327 1371
 			elseif ($string{$i} == '<')
1328 1372
 			{
1329 1373
 				// Probably HTML?
1330
-				if ($string{$i + 1} != ' ')
1331
-					$in_html = true;
1374
+				if ($string{$i + 1} != ' ') {
1375
+									$in_html = true;
1376
+				}
1332 1377
 				// Assume we need an entity...
1333 1378
 				else
1334 1379
 				{
@@ -1340,8 +1385,9 @@  discard block
 block discarded – undo
1340 1385
 			elseif ($string{$i} == '>')
1341 1386
 			{
1342 1387
 				// Will it be HTML?
1343
-				if ($in_html)
1344
-					$in_html = false;
1388
+				if ($in_html) {
1389
+									$in_html = false;
1390
+				}
1345 1391
 				// Otherwise we need an entity...
1346 1392
 				else
1347 1393
 				{
@@ -1350,8 +1396,9 @@  discard block
 block discarded – undo
1350 1396
 				}
1351 1397
 			}
1352 1398
 			// Is it a slash? If so escape it...
1353
-			if ($string{$i} == '\\')
1354
-				$new_string .= '\\';
1399
+			if ($string{$i} == '\\') {
1400
+							$new_string .= '\\';
1401
+			}
1355 1402
 			// The infamous double quote?
1356 1403
 			elseif ($string{$i} == '"')
1357 1404
 			{
@@ -1374,10 +1421,11 @@  discard block
 block discarded – undo
1374 1421
 		}
1375 1422
 
1376 1423
 		// If we ended as a string then close it off.
1377
-		if ($in_string == 1)
1378
-			$new_string .= '\'';
1379
-		elseif ($in_string == 2)
1380
-			$new_string .= '"';
1424
+		if ($in_string == 1) {
1425
+					$new_string .= '\'';
1426
+		} elseif ($in_string == 2) {
1427
+					$new_string .= '"';
1428
+		}
1381 1429
 	}
1382 1430
 
1383 1431
 	return $new_string;
Please login to merge, or discard this patch.
Sources/MoveTopic.php 1 patch
Braces   +101 added lines, -72 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * This function allows to move a topic, making sure to ask the moderator
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 {
33 34
 	global $txt, $board, $topic, $user_info, $context, $language, $scripturl, $smcFunc, $modSettings, $sourcedir;
34 35
 
35
-	if (empty($topic))
36
-		fatal_lang_error('no_access', false);
36
+	if (empty($topic)) {
37
+			fatal_lang_error('no_access', false);
38
+	}
37 39
 
38 40
 	$request = $smcFunc['db_query']('', '
39 41
 		SELECT t.id_member_started, ms.subject, t.approved
@@ -49,8 +51,9 @@  discard block
 block discarded – undo
49 51
 	$smcFunc['db_free_result']($request);
50 52
 
51 53
 	// Can they see it - if not approved?
52
-	if ($modSettings['postmod_active'] && !$context['is_approved'])
53
-		isAllowedTo('approve_posts');
54
+	if ($modSettings['postmod_active'] && !$context['is_approved']) {
55
+			isAllowedTo('approve_posts');
56
+	}
54 57
 
55 58
 	// Permission check!
56 59
 	// @todo
@@ -59,9 +62,9 @@  discard block
 block discarded – undo
59 62
 		if ($id_member_started == $user_info['id'])
60 63
 		{
61 64
 			isAllowedTo('move_own');
65
+		} else {
66
+					isAllowedTo('move_any');
62 67
 		}
63
-		else
64
-			isAllowedTo('move_any');
65 68
 	}
66 69
 
67 70
 	$context['move_any'] = $user_info['is_admin'] || $modSettings['topic_move_any'];
@@ -83,11 +86,13 @@  discard block
 block discarded – undo
83 86
 		'not_redirection' => true,
84 87
 	);
85 88
 
86
-	if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board)
87
-		$options['selected_board'] = $_SESSION['move_to_topic'];
89
+	if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) {
90
+			$options['selected_board'] = $_SESSION['move_to_topic'];
91
+	}
88 92
 
89
-	if (!$context['move_any'])
90
-		$options['included_boards'] = $boards;
93
+	if (!$context['move_any']) {
94
+			$options['included_boards'] = $boards;
95
+	}
91 96
 
92 97
 	require_once($sourcedir . '/Subs-MessageIndex.php');
93 98
 	$context['categories'] = getBoardList($options);
@@ -138,12 +143,14 @@  discard block
 block discarded – undo
138 143
 	global $txt, $board, $topic, $scripturl, $sourcedir, $modSettings, $context;
139 144
 	global $board, $language, $user_info, $smcFunc;
140 145
 
141
-	if (empty($topic))
142
-		fatal_lang_error('no_access', false);
146
+	if (empty($topic)) {
147
+			fatal_lang_error('no_access', false);
148
+	}
143 149
 
144 150
 	// You can't choose to have a redirection topic and use an empty reason.
145
-	if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == ''))
146
-		fatal_lang_error('movetopic_no_reason', false);
151
+	if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) {
152
+			fatal_lang_error('movetopic_no_reason', false);
153
+	}
147 154
 
148 155
 	moveTopicConcurrence();
149 156
 
@@ -163,16 +170,18 @@  discard block
 block discarded – undo
163 170
 	$smcFunc['db_free_result']($request);
164 171
 
165 172
 	// Can they see it?
166
-	if (!$context['is_approved'])
167
-		isAllowedTo('approve_posts');
173
+	if (!$context['is_approved']) {
174
+			isAllowedTo('approve_posts');
175
+	}
168 176
 
169 177
 	// Can they move topics on this board?
170 178
 	if (!allowedTo('move_any'))
171 179
 	{
172
-		if ($id_member_started == $user_info['id'])
173
-			isAllowedTo('move_own');
174
-		else
175
-			isAllowedTo('move_any');
180
+		if ($id_member_started == $user_info['id']) {
181
+					isAllowedTo('move_own');
182
+		} else {
183
+					isAllowedTo('move_any');
184
+		}
176 185
 	}
177 186
 
178 187
 	checkSession();
@@ -197,8 +206,9 @@  discard block
 block discarded – undo
197 206
 			'blank_redirect' => '',
198 207
 		)
199 208
 	);
200
-	if ($smcFunc['db_num_rows']($request) == 0)
201
-		fatal_lang_error('no_board');
209
+	if ($smcFunc['db_num_rows']($request) == 0) {
210
+			fatal_lang_error('no_board');
211
+	}
202 212
 	list ($pcounter, $board_name, $subject) = $smcFunc['db_fetch_row']($request);
203 213
 	$smcFunc['db_free_result']($request);
204 214
 
@@ -210,8 +220,9 @@  discard block
 block discarded – undo
210 220
 	{
211 221
 		$_POST['custom_subject'] = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => ''));
212 222
 		// Keep checking the length.
213
-		if ($smcFunc['strlen']($_POST['custom_subject']) > 100)
214
-			$_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100);
223
+		if ($smcFunc['strlen']($_POST['custom_subject']) > 100) {
224
+					$_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100);
225
+		}
215 226
 
216 227
 		// If it's still valid move onwards and upwards.
217 228
 		if ($_POST['custom_subject'] != '')
@@ -221,9 +232,9 @@  discard block
 block discarded – undo
221 232
 				// Get a response prefix, but in the forum's default language.
222 233
 				if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
223 234
 				{
224
-					if ($language === $user_info['language'])
225
-						$context['response_prefix'] = $txt['response_prefix'];
226
-					else
235
+					if ($language === $user_info['language']) {
236
+											$context['response_prefix'] = $txt['response_prefix'];
237
+					} else
227 238
 					{
228 239
 						loadLanguage('index', $language, false);
229 240
 						$context['response_prefix'] = $txt['response_prefix'];
@@ -263,8 +274,9 @@  discard block
 block discarded – undo
263 274
 	if (isset($_POST['postRedirect']))
264 275
 	{
265 276
 		// Should be in the boardwide language.
266
-		if ($user_info['language'] != $language)
267
-			loadLanguage('index', $language);
277
+		if ($user_info['language'] != $language) {
278
+					loadLanguage('index', $language);
279
+		}
268 280
 
269 281
 		$_POST['reason'] = $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES);
270 282
 		preparsecode($_POST['reason']);
@@ -328,8 +340,9 @@  discard block
 block discarded – undo
328 340
 		$posters = array();
329 341
 		while ($row = $smcFunc['db_fetch_assoc']($request))
330 342
 		{
331
-			if (!isset($posters[$row['id_member']]))
332
-				$posters[$row['id_member']] = 0;
343
+			if (!isset($posters[$row['id_member']])) {
344
+							$posters[$row['id_member']] = 0;
345
+			}
333 346
 
334 347
 			$posters[$row['id_member']]++;
335 348
 		}
@@ -338,11 +351,13 @@  discard block
 block discarded – undo
338 351
 		foreach ($posters as $id_member => $posts)
339 352
 		{
340 353
 			// The board we're moving from counted posts, but not to.
341
-			if (empty($pcounter_from))
342
-				updateMemberData($id_member, array('posts' => 'posts - ' . $posts));
354
+			if (empty($pcounter_from)) {
355
+							updateMemberData($id_member, array('posts' => 'posts - ' . $posts));
356
+			}
343 357
 			// The reverse: from didn't, to did.
344
-			else
345
-				updateMemberData($id_member, array('posts' => 'posts + ' . $posts));
358
+			else {
359
+							updateMemberData($id_member, array('posts' => 'posts + ' . $posts));
360
+			}
346 361
 		}
347 362
 	}
348 363
 
@@ -350,17 +365,19 @@  discard block
 block discarded – undo
350 365
 	moveTopics($topic, $_POST['toboard']);
351 366
 
352 367
 	// Log that they moved this topic.
353
-	if (!allowedTo('move_own') || $id_member_started != $user_info['id'])
354
-		logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard']));
368
+	if (!allowedTo('move_own') || $id_member_started != $user_info['id']) {
369
+			logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard']));
370
+	}
355 371
 	// Notify people that this topic has been moved?
356 372
 	sendNotifications($topic, 'move');
357 373
 
358 374
 	// Why not go back to the original board in case they want to keep moving?
359
-	if (!isset($_REQUEST['goback']))
360
-		redirectexit('board=' . $board . '.0');
361
-	else
362
-		redirectexit('topic=' . $topic . '.0');
363
-}
375
+	if (!isset($_REQUEST['goback'])) {
376
+			redirectexit('board=' . $board . '.0');
377
+	} else {
378
+			redirectexit('topic=' . $topic . '.0');
379
+	}
380
+	}
364 381
 
365 382
 /**
366 383
  * Moves one or more topics to a specific board. (doesn't check permissions.)
@@ -376,18 +393,21 @@  discard block
 block discarded – undo
376 393
 	global $sourcedir, $user_info, $modSettings, $smcFunc;
377 394
 
378 395
 	// Empty array?
379
-	if (empty($topics))
380
-		return;
396
+	if (empty($topics)) {
397
+			return;
398
+	}
381 399
 
382 400
 	// Only a single topic.
383
-	if (is_numeric($topics))
384
-		$topics = array($topics);
401
+	if (is_numeric($topics)) {
402
+			$topics = array($topics);
403
+	}
385 404
 
386 405
 	$fromBoards = array();
387 406
 
388 407
 	// Destination board empty or equal to 0?
389
-	if (empty($toBoard))
390
-		return;
408
+	if (empty($toBoard)) {
409
+			return;
410
+	}
391 411
 
392 412
 	// Are we moving to the recycle board?
393 413
 	$isRecycleDest = !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $toBoard;
@@ -395,8 +415,9 @@  discard block
 block discarded – undo
395 415
 	// Callback for search APIs to do their thing
396 416
 	require_once($sourcedir . '/Search.php');
397 417
 	$searchAPI = findSearchAPI();
398
-	if ($searchAPI->supportsMethod('topicsMoved'))
399
-		$searchAPI->topicsMoved($topics, $toBoard);
418
+	if ($searchAPI->supportsMethod('topicsMoved')) {
419
+			$searchAPI->topicsMoved($topics, $toBoard);
420
+	}
400 421
 
401 422
 	// Determine the source boards...
402 423
 	$request = $smcFunc['db_query']('', '
@@ -410,8 +431,9 @@  discard block
 block discarded – undo
410 431
 		)
411 432
 	);
412 433
 	// Num of rows = 0 -> no topics found. Num of rows > 1 -> topics are on multiple boards.
413
-	if ($smcFunc['db_num_rows']($request) == 0)
414
-		return;
434
+	if ($smcFunc['db_num_rows']($request) == 0) {
435
+			return;
436
+	}
415 437
 	while ($row = $smcFunc['db_fetch_assoc']($request))
416 438
 	{
417 439
 		if (!isset($fromBoards[$row['id_board']]['num_posts']))
@@ -429,10 +451,11 @@  discard block
 block discarded – undo
429 451
 		$fromBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts'];
430 452
 
431 453
 		// Add the topics to the right type.
432
-		if ($row['approved'])
433
-			$fromBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
434
-		else
435
-			$fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
454
+		if ($row['approved']) {
455
+					$fromBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
456
+		} else {
457
+					$fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
458
+		}
436 459
 	}
437 460
 	$smcFunc['db_free_result']($request);
438 461
 
@@ -558,13 +581,14 @@  discard block
 block discarded – undo
558 581
 			)
559 582
 		);
560 583
 		$approval_msgs = array();
561
-		while ($row = $smcFunc['db_fetch_assoc']($request))
562
-			$approval_msgs[] = $row['id_msg'];
584
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
585
+					$approval_msgs[] = $row['id_msg'];
586
+		}
563 587
 		$smcFunc['db_free_result']($request);
564 588
 
565 589
 		// Empty the approval queue for these, as we're going to approve them next.
566
-		if (!empty($approval_msgs))
567
-			$smcFunc['db_query']('', '
590
+		if (!empty($approval_msgs)) {
591
+					$smcFunc['db_query']('', '
568 592
 				DELETE FROM {db_prefix}approval_queue
569 593
 				WHERE id_msg IN ({array_int:message_list})
570 594
 					AND id_attach = {int:id_attach}',
@@ -573,6 +597,7 @@  discard block
 block discarded – undo
573 597
 					'id_attach' => 0,
574 598
 				)
575 599
 			);
600
+		}
576 601
 
577 602
 		// Get all the current max and mins.
578 603
 		$request = $smcFunc['db_query']('', '
@@ -606,8 +631,8 @@  discard block
 block discarded – undo
606 631
 		while ($row = $smcFunc['db_fetch_assoc']($request))
607 632
 		{
608 633
 			// If not, update.
609
-			if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max'])
610
-				$smcFunc['db_query']('', '
634
+			if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) {
635
+							$smcFunc['db_query']('', '
611 636
 					UPDATE {db_prefix}topics
612 637
 					SET id_first_msg = {int:first_msg}, id_last_msg = {int:last_msg}
613 638
 					WHERE id_topic = {int:selected_topic}',
@@ -617,6 +642,7 @@  discard block
 block discarded – undo
617 642
 						'selected_topic' => $row['id_topic'],
618 643
 					)
619 644
 				);
645
+			}
620 646
 		}
621 647
 		$smcFunc['db_free_result']($request);
622 648
 	}
@@ -675,9 +701,10 @@  discard block
 block discarded – undo
675 701
 	}
676 702
 
677 703
 	// Update the cache?
678
-	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
679
-		foreach ($topics as $topic_id)
704
+	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) {
705
+			foreach ($topics as $topic_id)
680 706
 			cache_put_data('topic_board-' . $topic_id, null, 120);
707
+	}
681 708
 
682 709
 	require_once($sourcedir . '/Subs-Post.php');
683 710
 
@@ -701,15 +728,17 @@  discard block
 block discarded – undo
701 728
 {
702 729
 	global $board, $topic, $smcFunc, $scripturl;
703 730
 
704
-	if (isset($_GET['current_board']))
705
-		$move_from = (int) $_GET['current_board'];
731
+	if (isset($_GET['current_board'])) {
732
+			$move_from = (int) $_GET['current_board'];
733
+	}
706 734
 
707
-	if (empty($move_from) || empty($board) || empty($topic))
708
-		return true;
735
+	if (empty($move_from) || empty($board) || empty($topic)) {
736
+			return true;
737
+	}
709 738
 
710
-	if ($move_from == $board)
711
-		return true;
712
-	else
739
+	if ($move_from == $board) {
740
+			return true;
741
+	} else
713 742
 	{
714 743
 		$request = $smcFunc['db_query']('', '
715 744
 			SELECT m.subject, b.name
Please login to merge, or discard this patch.
Sources/Session.php 1 patch
Braces   +31 added lines, -21 removed lines patch added patch discarded remove patch
@@ -17,8 +17,9 @@  discard block
 block discarded – undo
17 17
  * @version 2.1 Beta 3
18 18
  */
19 19
 
20
-if (!defined('SMF'))
20
+if (!defined('SMF')) {
21 21
 	die('No direct access...');
22
+}
22 23
 
23 24
 /**
24 25
  * Attempt to start the session, unless it already has been.
@@ -38,8 +39,9 @@  discard block
 block discarded – undo
38 39
 	{
39 40
 		$parsed_url = parse_url($boardurl);
40 41
 
41
-		if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
42
-			@ini_set('session.cookie_domain', '.' . $parts[1]);
42
+		if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
43
+					@ini_set('session.cookie_domain', '.' . $parts[1]);
44
+		}
43 45
 	}
44 46
 	// @todo Set the session cookie path?
45 47
 
@@ -47,8 +49,9 @@  discard block
 block discarded – undo
47 49
 	if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '')
48 50
 	{
49 51
 		// Attempt to end the already-started session.
50
-		if (ini_get('session.auto_start') == 1)
51
-			session_write_close();
52
+		if (ini_get('session.auto_start') == 1) {
53
+					session_write_close();
54
+		}
52 55
 
53 56
 		// This is here to stop people from using bad junky PHPSESSIDs.
54 57
 		if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()]))
@@ -65,19 +68,21 @@  discard block
 block discarded – undo
65 68
 			@ini_set('session.serialize_handler', 'php');
66 69
 			session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC');
67 70
 			@ini_set('session.gc_probability', '1');
71
+		} elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) {
72
+					@ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60));
68 73
 		}
69
-		elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime']))
70
-			@ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60));
71 74
 
72 75
 		// Use cache setting sessions?
73
-		if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli')
74
-			call_integration_hook('integrate_session_handlers');
76
+		if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') {
77
+					call_integration_hook('integrate_session_handlers');
78
+		}
75 79
 
76 80
 		session_start();
77 81
 
78 82
 		// Change it so the cache settings are a little looser than default.
79
-		if (!empty($modSettings['databaseSession_loose']))
80
-			header('Cache-Control: private');
83
+		if (!empty($modSettings['databaseSession_loose'])) {
84
+					header('Cache-Control: private');
85
+		}
81 86
 	}
82 87
 
83 88
 	// Set the randomly generated code.
@@ -123,8 +128,9 @@  discard block
 block discarded – undo
123 128
 {
124 129
 	global $smcFunc;
125 130
 
126
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
127
-		return '';
131
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
132
+			return '';
133
+	}
128 134
 
129 135
 	// Look for it in the database.
130 136
 	$result = $smcFunc['db_query']('', '
@@ -153,8 +159,9 @@  discard block
 block discarded – undo
153 159
 {
154 160
 	global $smcFunc;
155 161
 
156
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
157
-		return false;
162
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
163
+			return false;
164
+	}
158 165
 
159 166
 	// First try to update an existing row...
160 167
 	$smcFunc['db_query']('', '
@@ -169,13 +176,14 @@  discard block
 block discarded – undo
169 176
 	);
170 177
 
171 178
 	// If that didn't work, try inserting a new one.
172
-	if ($smcFunc['db_affected_rows']() == 0)
173
-		$smcFunc['db_insert']('ignore',
179
+	if ($smcFunc['db_affected_rows']() == 0) {
180
+			$smcFunc['db_insert']('ignore',
174 181
 			'{db_prefix}sessions',
175 182
 			array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'),
176 183
 			array($session_id, $data, time()),
177 184
 			array('session_id')
178 185
 		);
186
+	}
179 187
 
180 188
 	return ($smcFunc['db_affected_rows']() == 0 ? false : true);
181 189
 }
@@ -190,8 +198,9 @@  discard block
 block discarded – undo
190 198
 {
191 199
 	global $smcFunc;
192 200
 
193
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
194
-		return false;
201
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
202
+			return false;
203
+	}
195 204
 
196 205
 	// Just delete the row...
197 206
 	$smcFunc['db_query']('', '
@@ -217,8 +226,9 @@  discard block
 block discarded – undo
217 226
 	global $modSettings, $smcFunc;
218 227
 
219 228
 	// Just set to the default or lower?  Ignore it for a higher value. (hopefully)
220
-	if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime))
221
-		$max_lifetime = max($modSettings['databaseSession_lifetime'], 60);
229
+	if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) {
230
+			$max_lifetime = max($modSettings['databaseSession_lifetime'], 60);
231
+	}
222 232
 
223 233
 	// Clean up after yerself ;).
224 234
 	$smcFunc['db_query']('', '
Please login to merge, or discard this patch.
Sources/ShowAttachments.php 1 patch
Braces   +54 added lines, -48 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Shows an avatar based on $_GET['attach']
@@ -35,11 +36,11 @@  discard block
 block discarded – undo
35 36
 
36 37
 	if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0)
37 38
 	{
38
-		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler')
39
-			$modSettings['enableCompressedOutput'] = 0;
40
-
41
-		else
42
-			ob_start('ob_gzhandler');
39
+		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') {
40
+					$modSettings['enableCompressedOutput'] = 0;
41
+		} else {
42
+					ob_start('ob_gzhandler');
43
+		}
43 44
 	}
44 45
 
45 46
 	if (empty($modSettings['enableCompressedOutput']))
@@ -71,8 +72,9 @@  discard block
 block discarded – undo
71 72
 	}
72 73
 
73 74
 	// Use cache when possible.
74
-	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null)
75
-		list($file, $thumbFile) = $cache;
75
+	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) {
76
+			list($file, $thumbFile) = $cache;
77
+	}
76 78
 
77 79
 	// Get the info from the DB.
78 80
 	if (empty($file) || empty($thumbFile) && !empty($file['id_thumb']))
@@ -80,10 +82,9 @@  discard block
 block discarded – undo
80 82
 		// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
81 83
 		$attachRequest = null;
82 84
 		call_integration_hook('integrate_download_request', array(&$attachRequest));
83
-		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest))
84
-			$request = $attachRequest;
85
-
86
-		else
85
+		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) {
86
+					$request = $attachRequest;
87
+		} else
87 88
 		{
88 89
 			// Make sure this attachment is on this board and load its info while we are at it.
89 90
 			$request = $smcFunc['db_query']('', '
@@ -176,13 +177,14 @@  discard block
 block discarded – undo
176 177
 		}
177 178
 
178 179
 		// Cache it.
179
-		if (!empty($file) || !empty($thumbFile))
180
-			cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
180
+		if (!empty($file) || !empty($thumbFile)) {
181
+					cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
182
+		}
181 183
 	}
182 184
 
183 185
 	// Update the download counter (unless it's a thumbnail).
184
-	if ($file['attachment_type'] != 3 && empty($showThumb))
185
-		$smcFunc['db_query']('attach_download_increase', '
186
+	if ($file['attachment_type'] != 3 && empty($showThumb)) {
187
+			$smcFunc['db_query']('attach_download_increase', '
186 188
 			UPDATE LOW_PRIORITY {db_prefix}attachments
187 189
 			SET downloads = downloads + 1
188 190
 			WHERE id_attach = {int:id_attach}',
@@ -190,10 +192,12 @@  discard block
 block discarded – undo
190 192
 				'id_attach' => $attachId,
191 193
 			)
192 194
 		);
195
+	}
193 196
 
194 197
 	// Replace the normal file with its thumbnail if it has one!
195
-	if (!empty($showThumb) && !empty($thumbFile))
196
-		$file = $thumbFile;
198
+	if (!empty($showThumb) && !empty($thumbFile)) {
199
+			$file = $thumbFile;
200
+	}
197 201
 
198 202
 	// No point in a nicer message, because this is supposed to be an attachment anyway...
199 203
 	if (!file_exists($file['filePath']))
@@ -232,8 +236,9 @@  discard block
 block discarded – undo
232 236
 	// Send the attachment headers.
233 237
 	header('Pragma: ');
234 238
 
235
-	if (!isBrowser('gecko'))
236
-		header('Content-Transfer-Encoding: binary');
239
+	if (!isBrowser('gecko')) {
240
+			header('Content-Transfer-Encoding: binary');
241
+	}
237 242
 
238 243
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
239 244
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($file['filePath'])) . ' GMT');
@@ -242,18 +247,19 @@  discard block
 block discarded – undo
242 247
 	header('ETag: ' . $eTag);
243 248
 
244 249
 	// Make sure the mime type warrants an inline display.
245
-	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0)
246
-		unset($_REQUEST['image']);
250
+	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) {
251
+			unset($_REQUEST['image']);
252
+	}
247 253
 
248 254
 	// Does this have a mime type?
249
-	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff'))))
250
-		header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
251
-
252
-	else
255
+	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) {
256
+			header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
257
+	} else
253 258
 	{
254 259
 		header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
255
-		if (isset($_REQUEST['image']))
256
-			unset($_REQUEST['image']);
260
+		if (isset($_REQUEST['image'])) {
261
+					unset($_REQUEST['image']);
262
+		}
257 263
 	}
258 264
 
259 265
 	// Convert the file to UTF-8, cuz most browsers dig that.
@@ -261,24 +267,22 @@  discard block
 block discarded – undo
261 267
 	$disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline';
262 268
 
263 269
 	// Different browsers like different standards...
264
-	if (isBrowser('firefox'))
265
-		header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
266
-
267
-	elseif (isBrowser('opera'))
268
-		header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
269
-
270
-	elseif (isBrowser('ie'))
271
-		header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
272
-
273
-	else
274
-		header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
270
+	if (isBrowser('firefox')) {
271
+			header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
272
+	} elseif (isBrowser('opera')) {
273
+			header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
274
+	} elseif (isBrowser('ie')) {
275
+			header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
276
+	} else {
277
+			header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
278
+	}
275 279
 
276 280
 	// If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE.
277
-	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff')))
278
-		header('Cache-Control: no-cache');
279
-
280
-	else
281
-		header('Cache-Control: max-age=' . (525600 * 60) . ', private');
281
+	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) {
282
+			header('Cache-Control: no-cache');
283
+	} else {
284
+			header('Cache-Control: max-age=' . (525600 * 60) . ', private');
285
+	}
282 286
 
283 287
 	header('Content-Length: ' . filesize($file['filePath']));
284 288
 
@@ -289,8 +293,9 @@  discard block
 block discarded – undo
289 293
 	if (filesize($file['filePath']) > 4194304)
290 294
 	{
291 295
 		// Forcibly end any output buffering going on.
292
-		while (@ob_get_level() > 0)
293
-			@ob_end_clean();
296
+		while (@ob_get_level() > 0) {
297
+					@ob_end_clean();
298
+		}
294 299
 
295 300
 		$fp = fopen($file['filePath'], 'rb');
296 301
 		while (!feof($fp))
@@ -302,8 +307,9 @@  discard block
 block discarded – undo
302 307
 	}
303 308
 
304 309
 	// On some of the less-bright hosts, readfile() is disabled.  It's just a faster, more byte safe, version of what's in the if.
305
-	elseif (@readfile($file['filePath']) === null)
306
-		echo file_get_contents($file['filePath']);
310
+	elseif (@readfile($file['filePath']) === null) {
311
+			echo file_get_contents($file['filePath']);
312
+	}
307 313
 
308 314
 	die();
309 315
 }
Please login to merge, or discard this patch.
Sources/Subs-Boards.php 1 patch
Braces   +247 added lines, -175 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Mark a board or multiple boards read.
@@ -28,14 +29,16 @@  discard block
 block discarded – undo
28 29
 	global $user_info, $modSettings, $smcFunc;
29 30
 
30 31
 	// Force $boards to be an array.
31
-	if (!is_array($boards))
32
-		$boards = array($boards);
33
-	else
34
-		$boards = array_unique($boards);
32
+	if (!is_array($boards)) {
33
+			$boards = array($boards);
34
+	} else {
35
+			$boards = array_unique($boards);
36
+	}
35 37
 
36 38
 	// No boards, nothing to mark as read.
37
-	if (empty($boards))
38
-		return;
39
+	if (empty($boards)) {
40
+			return;
41
+	}
39 42
 
40 43
 	// Allow the user to mark a board as unread.
41 44
 	if ($unread)
@@ -65,8 +68,9 @@  discard block
 block discarded – undo
65 68
 	else
66 69
 	{
67 70
 		$markRead = array();
68
-		foreach ($boards as $board)
69
-			$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $board);
71
+		foreach ($boards as $board) {
72
+					$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $board);
73
+		}
70 74
 
71 75
 		// Update log_mark_read and log_boards.
72 76
 		$smcFunc['db_insert']('replace',
@@ -99,8 +103,9 @@  discard block
 block discarded – undo
99 103
 	list ($lowest_topic) = $smcFunc['db_fetch_row']($result);
100 104
 	$smcFunc['db_free_result']($result);
101 105
 
102
-	if (empty($lowest_topic))
103
-		return;
106
+	if (empty($lowest_topic)) {
107
+			return;
108
+	}
104 109
 
105 110
 	// @todo SLOW This query seems to eat it sometimes.
106 111
 	$result = $smcFunc['db_query']('', '
@@ -118,12 +123,13 @@  discard block
 block discarded – undo
118 123
 		)
119 124
 	);
120 125
 	$topics = array();
121
-	while ($row = $smcFunc['db_fetch_assoc']($result))
122
-		$topics[] = $row['id_topic'];
126
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
127
+			$topics[] = $row['id_topic'];
128
+	}
123 129
 	$smcFunc['db_free_result']($result);
124 130
 
125
-	if (!empty($topics))
126
-		$smcFunc['db_query']('', '
131
+	if (!empty($topics)) {
132
+			$smcFunc['db_query']('', '
127 133
 			DELETE FROM {db_prefix}log_topics
128 134
 			WHERE id_member = {int:current_member}
129 135
 				AND id_topic IN ({array_int:topic_list})',
@@ -132,7 +138,8 @@  discard block
 block discarded – undo
132 138
 				'topic_list' => $topics,
133 139
 			)
134 140
 		);
135
-}
141
+	}
142
+	}
136 143
 
137 144
 /**
138 145
  * Mark one or more boards as read.
@@ -157,23 +164,26 @@  discard block
 block discarded – undo
157 164
 			)
158 165
 		);
159 166
 		$boards = array();
160
-		while ($row = $smcFunc['db_fetch_assoc']($result))
161
-			$boards[] = $row['id_board'];
167
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
168
+					$boards[] = $row['id_board'];
169
+		}
162 170
 		$smcFunc['db_free_result']($result);
163 171
 
164
-		if (!empty($boards))
165
-			markBoardsRead($boards, isset($_REQUEST['unread']));
172
+		if (!empty($boards)) {
173
+					markBoardsRead($boards, isset($_REQUEST['unread']));
174
+		}
166 175
 
167 176
 		$_SESSION['id_msg_last_visit'] = $modSettings['maxMsgID'];
168
-		if (!empty($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'action=unread') !== false)
169
-			redirectexit('action=unread');
177
+		if (!empty($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'action=unread') !== false) {
178
+					redirectexit('action=unread');
179
+		}
170 180
 
171
-		if (isset($_SESSION['topicseen_cache']))
172
-			$_SESSION['topicseen_cache'] = array();
181
+		if (isset($_SESSION['topicseen_cache'])) {
182
+					$_SESSION['topicseen_cache'] = array();
183
+		}
173 184
 
174 185
 		redirectexit();
175
-	}
176
-	elseif (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'unreadreplies')
186
+	} elseif (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'unreadreplies')
177 187
 	{
178 188
 		// Make sure all the topics are integers!
179 189
 		$topics = array_map('intval', explode('-', $_REQUEST['topics']));
@@ -189,13 +199,15 @@  discard block
 block discarded – undo
189 199
 			)
190 200
 		);
191 201
 		$logged_topics = array();
192
-		while ($row = $smcFunc['db_fetch_assoc']($request))
193
-			$logged_topics[$row['id_topic']] = $row['unwatched'];
202
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
203
+					$logged_topics[$row['id_topic']] = $row['unwatched'];
204
+		}
194 205
 		$smcFunc['db_free_result']($request);
195 206
 
196 207
 		$markRead = array();
197
-		foreach ($topics as $id_topic)
198
-			$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $id_topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
208
+		foreach ($topics as $id_topic) {
209
+					$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $id_topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
210
+		}
199 211
 
200 212
 		$smcFunc['db_insert']('replace',
201 213
 			'{db_prefix}log_topics',
@@ -204,8 +216,9 @@  discard block
 block discarded – undo
204 216
 			array('id_member', 'id_topic')
205 217
 		);
206 218
 
207
-		if (isset($_SESSION['topicseen_cache']))
208
-			$_SESSION['topicseen_cache'] = array();
219
+		if (isset($_SESSION['topicseen_cache'])) {
220
+					$_SESSION['topicseen_cache'] = array();
221
+		}
209 222
 
210 223
 		redirectexit('action=unreadreplies');
211 224
 	}
@@ -230,11 +243,13 @@  discard block
 block discarded – undo
230 243
 		if (!empty($_GET['t']))
231 244
 		{
232 245
 			// If they read the whole topic, go back to the beginning.
233
-			if ($_GET['t'] >= $topicinfo['id_last_msg'])
234
-				$earlyMsg = 0;
246
+			if ($_GET['t'] >= $topicinfo['id_last_msg']) {
247
+							$earlyMsg = 0;
248
+			}
235 249
 			// If they want to mark the whole thing read, same.
236
-			elseif ($_GET['t'] <= $topicinfo['id_first_msg'])
237
-				$earlyMsg = 0;
250
+			elseif ($_GET['t'] <= $topicinfo['id_first_msg']) {
251
+							$earlyMsg = 0;
252
+			}
238 253
 			// Otherwise, get the latest message before the named one.
239 254
 			else
240 255
 			{
@@ -255,9 +270,9 @@  discard block
 block discarded – undo
255 270
 			}
256 271
 		}
257 272
 		// Marking read from first page?  That's the whole topic.
258
-		elseif ($_REQUEST['start'] == 0)
259
-			$earlyMsg = 0;
260
-		else
273
+		elseif ($_REQUEST['start'] == 0) {
274
+					$earlyMsg = 0;
275
+		} else
261 276
 		{
262 277
 			$result = $smcFunc['db_query']('', '
263 278
 				SELECT id_msg
@@ -285,8 +300,7 @@  discard block
 block discarded – undo
285 300
 		);
286 301
 
287 302
 		redirectexit('board=' . $board . '.0');
288
-	}
289
-	else
303
+	} else
290 304
 	{
291 305
 		$categories = array();
292 306
 		$boards = array();
@@ -294,17 +308,20 @@  discard block
 block discarded – undo
294 308
 		if (isset($_REQUEST['c']))
295 309
 		{
296 310
 			$_REQUEST['c'] = explode(',', $_REQUEST['c']);
297
-			foreach ($_REQUEST['c'] as $c)
298
-				$categories[] = (int) $c;
311
+			foreach ($_REQUEST['c'] as $c) {
312
+							$categories[] = (int) $c;
313
+			}
299 314
 		}
300 315
 		if (isset($_REQUEST['boards']))
301 316
 		{
302 317
 			$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
303
-			foreach ($_REQUEST['boards'] as $b)
304
-				$boards[] = (int) $b;
318
+			foreach ($_REQUEST['boards'] as $b) {
319
+							$boards[] = (int) $b;
320
+			}
321
+		}
322
+		if (!empty($board)) {
323
+					$boards[] = (int) $board;
305 324
 		}
306
-		if (!empty($board))
307
-			$boards[] = (int) $board;
308 325
 
309 326
 		if (isset($_REQUEST['children']) && !empty($boards))
310 327
 		{
@@ -324,9 +341,10 @@  discard block
 block discarded – undo
324 341
 					'board_list' => $boards,
325 342
 				)
326 343
 			);
327
-			while ($row = $smcFunc['db_fetch_assoc']($request))
328
-				if (in_array($row['id_parent'], $boards))
344
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
345
+							if (in_array($row['id_parent'], $boards))
329 346
 					$boards[] = $row['id_board'];
347
+			}
330 348
 			$smcFunc['db_free_result']($request);
331 349
 		}
332 350
 
@@ -343,8 +361,9 @@  discard block
 block discarded – undo
343 361
 			$clauseParameters['board_list'] = $boards;
344 362
 		}
345 363
 
346
-		if (empty($clauses))
347
-			redirectexit();
364
+		if (empty($clauses)) {
365
+					redirectexit();
366
+		}
348 367
 
349 368
 		$request = $smcFunc['db_query']('', '
350 369
 			SELECT b.id_board
@@ -355,19 +374,22 @@  discard block
 block discarded – undo
355 374
 			))
356 375
 		);
357 376
 		$boards = array();
358
-		while ($row = $smcFunc['db_fetch_assoc']($request))
359
-			$boards[] = $row['id_board'];
377
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
378
+					$boards[] = $row['id_board'];
379
+		}
360 380
 		$smcFunc['db_free_result']($request);
361 381
 
362
-		if (empty($boards))
363
-			redirectexit();
382
+		if (empty($boards)) {
383
+					redirectexit();
384
+		}
364 385
 
365 386
 		markBoardsRead($boards, isset($_REQUEST['unread']));
366 387
 
367 388
 		foreach ($boards as $b)
368 389
 		{
369
-			if (isset($_SESSION['topicseen_cache'][$b]))
370
-				$_SESSION['topicseen_cache'][$b] = array();
390
+			if (isset($_SESSION['topicseen_cache'][$b])) {
391
+							$_SESSION['topicseen_cache'][$b] = array();
392
+			}
371 393
 		}
372 394
 
373 395
 		if (!isset($_REQUEST['unread']))
@@ -385,8 +407,9 @@  discard block
 block discarded – undo
385 407
 			if ($smcFunc['db_num_rows']($result) > 0)
386 408
 			{
387 409
 				$logBoardInserts = '';
388
-				while ($row = $smcFunc['db_fetch_assoc']($result))
389
-					$logBoardInserts[] = array($modSettings['maxMsgID'], $user_info['id'], $row['id_board']);
410
+				while ($row = $smcFunc['db_fetch_assoc']($result)) {
411
+									$logBoardInserts[] = array($modSettings['maxMsgID'], $user_info['id'], $row['id_board']);
412
+				}
390 413
 
391 414
 				$smcFunc['db_insert']('replace',
392 415
 					'{db_prefix}log_boards',
@@ -397,17 +420,18 @@  discard block
 block discarded – undo
397 420
 			}
398 421
 			$smcFunc['db_free_result']($result);
399 422
 
400
-			if (empty($board))
401
-				redirectexit();
402
-			else
403
-				redirectexit('board=' . $board . '.0');
404
-		}
405
-		else
423
+			if (empty($board)) {
424
+							redirectexit();
425
+			} else {
426
+							redirectexit('board=' . $board . '.0');
427
+			}
428
+		} else
406 429
 		{
407
-			if (empty($board_info['parent']))
408
-				redirectexit();
409
-			else
410
-				redirectexit('board=' . $board_info['parent'] . '.0');
430
+			if (empty($board_info['parent'])) {
431
+							redirectexit();
432
+			} else {
433
+							redirectexit('board=' . $board_info['parent'] . '.0');
434
+			}
411 435
 		}
412 436
 	}
413 437
 }
@@ -432,11 +456,13 @@  discard block
 block discarded – undo
432 456
 			'selected_message' => (int) $messageID,
433 457
 		)
434 458
 	);
435
-	if ($smcFunc['db_num_rows']($result) > 0)
436
-		list ($memberID) = $smcFunc['db_fetch_row']($result);
459
+	if ($smcFunc['db_num_rows']($result) > 0) {
460
+			list ($memberID) = $smcFunc['db_fetch_row']($result);
461
+	}
437 462
 	// The message doesn't even exist.
438
-	else
439
-		$memberID = 0;
463
+	else {
464
+			$memberID = 0;
465
+	}
440 466
 	$smcFunc['db_free_result']($result);
441 467
 
442 468
 	return (int) $memberID;
@@ -457,8 +483,9 @@  discard block
 block discarded – undo
457 483
 	getBoardTree();
458 484
 
459 485
 	// Make sure given boards and categories exist.
460
-	if (!isset($boards[$board_id]) || (isset($boardOptions['target_board']) && !isset($boards[$boardOptions['target_board']])) || (isset($boardOptions['target_category']) && !isset($cat_tree[$boardOptions['target_category']])))
461
-		fatal_lang_error('no_board');
486
+	if (!isset($boards[$board_id]) || (isset($boardOptions['target_board']) && !isset($boards[$boardOptions['target_board']])) || (isset($boardOptions['target_category']) && !isset($cat_tree[$boardOptions['target_category']]))) {
487
+			fatal_lang_error('no_board');
488
+	}
462 489
 
463 490
 	$id = $board_id;
464 491
 	call_integration_hook('integrate_pre_modify_board', array($id, &$boardOptions));
@@ -486,8 +513,9 @@  discard block
 block discarded – undo
486 513
 			$child_level = 0;
487 514
 			$id_parent = 0;
488 515
 			$after = 0;
489
-			foreach ($cat_tree[$id_cat]['children'] as $id_board => $dummy)
490
-				$after = max($after, $boards[$id_board]['order']);
516
+			foreach ($cat_tree[$id_cat]['children'] as $id_board => $dummy) {
517
+							$after = max($after, $boards[$id_board]['order']);
518
+			}
491 519
 		}
492 520
 
493 521
 		// Make the board a child of a given board.
@@ -498,17 +526,19 @@  discard block
 block discarded – undo
498 526
 			$id_parent = $boardOptions['target_board'];
499 527
 
500 528
 			// People can be creative, in many ways...
501
-			if (isChildOf($id_parent, $board_id))
502
-				fatal_lang_error('mboards_parent_own_child_error', false);
503
-			elseif ($id_parent == $board_id)
504
-				fatal_lang_error('mboards_board_own_child_error', false);
529
+			if (isChildOf($id_parent, $board_id)) {
530
+							fatal_lang_error('mboards_parent_own_child_error', false);
531
+			} elseif ($id_parent == $board_id) {
532
+							fatal_lang_error('mboards_board_own_child_error', false);
533
+			}
505 534
 
506 535
 			$after = $boards[$boardOptions['target_board']]['order'];
507 536
 
508 537
 			// Check if there are already children and (if so) get the max board order.
509
-			if (!empty($boards[$id_parent]['tree']['children']) && empty($boardOptions['move_first_child']))
510
-				foreach ($boards[$id_parent]['tree']['children'] as $childBoard_id => $dummy)
538
+			if (!empty($boards[$id_parent]['tree']['children']) && empty($boardOptions['move_first_child'])) {
539
+							foreach ($boards[$id_parent]['tree']['children'] as $childBoard_id => $dummy)
511 540
 					$after = max($after, $boards[$childBoard_id]['order']);
541
+			}
512 542
 		}
513 543
 
514 544
 		// Place a board before or after another board, on the same child level.
@@ -521,8 +551,9 @@  discard block
 block discarded – undo
521 551
 		}
522 552
 
523 553
 		// Oops...?
524
-		else
525
-			trigger_error('modifyBoard(): The move_to value \'' . $boardOptions['move_to'] . '\' is incorrect', E_USER_ERROR);
554
+		else {
555
+					trigger_error('modifyBoard(): The move_to value \'' . $boardOptions['move_to'] . '\' is incorrect', E_USER_ERROR);
556
+		}
526 557
 
527 558
 		// Get a list of children of this board.
528 559
 		$childList = array();
@@ -531,14 +562,16 @@  discard block
 block discarded – undo
531 562
 		// See if there are changes that affect children.
532 563
 		$childUpdates = array();
533 564
 		$levelDiff = $child_level - $boards[$board_id]['level'];
534
-		if ($levelDiff != 0)
535
-			$childUpdates[] = 'child_level = child_level ' . ($levelDiff > 0 ? '+ ' : '') . '{int:level_diff}';
536
-		if ($id_cat != $boards[$board_id]['category'])
537
-			$childUpdates[] = 'id_cat = {int:category}';
565
+		if ($levelDiff != 0) {
566
+					$childUpdates[] = 'child_level = child_level ' . ($levelDiff > 0 ? '+ ' : '') . '{int:level_diff}';
567
+		}
568
+		if ($id_cat != $boards[$board_id]['category']) {
569
+					$childUpdates[] = 'id_cat = {int:category}';
570
+		}
538 571
 
539 572
 		// Fix the children of this board.
540
-		if (!empty($childList) && !empty($childUpdates))
541
-			$smcFunc['db_query']('', '
573
+		if (!empty($childList) && !empty($childUpdates)) {
574
+					$smcFunc['db_query']('', '
542 575
 				UPDATE {db_prefix}boards
543 576
 				SET ' . implode(',
544 577
 					', $childUpdates) . '
@@ -549,6 +582,7 @@  discard block
 block discarded – undo
549 582
 					'level_diff' => $levelDiff,
550 583
 				)
551 584
 			);
585
+		}
552 586
 
553 587
 		// Make some room for this spot.
554 588
 		$smcFunc['db_query']('', '
@@ -644,8 +678,8 @@  discard block
 block discarded – undo
644 678
 	call_integration_hook('integrate_modify_board', array($id, &$boardUpdates, &$boardUpdateParameters));
645 679
 
646 680
 	// Do the updates (if any).
647
-	if (!empty($boardUpdates))
648
-		$smcFunc['db_query']('', '
681
+	if (!empty($boardUpdates)) {
682
+			$smcFunc['db_query']('', '
649 683
 			UPDATE {db_prefix}boards
650 684
 			SET
651 685
 				' . implode(',
@@ -655,6 +689,7 @@  discard block
 block discarded – undo
655 689
 				'selected_board' => $board_id,
656 690
 			))
657 691
 		);
692
+	}
658 693
 
659 694
 	// Set moderators of this board.
660 695
 	if (isset($boardOptions['moderators']) || isset($boardOptions['moderator_string']) || isset($boardOptions['moderator_groups']) || isset($boardOptions['moderator_group_string']))
@@ -679,13 +714,15 @@  discard block
 block discarded – undo
679 714
 			{
680 715
 				$moderators[$k] = trim($moderators[$k]);
681 716
 
682
-				if (strlen($moderators[$k]) == 0)
683
-					unset($moderators[$k]);
717
+				if (strlen($moderators[$k]) == 0) {
718
+									unset($moderators[$k]);
719
+				}
684 720
 			}
685 721
 
686 722
 			// Find all the id_member's for the member_name's in the list.
687
-			if (empty($boardOptions['moderators']))
688
-				$boardOptions['moderators'] = array();
723
+			if (empty($boardOptions['moderators'])) {
724
+							$boardOptions['moderators'] = array();
725
+			}
689 726
 			if (!empty($moderators))
690 727
 			{
691 728
 				$request = $smcFunc['db_query']('', '
@@ -698,8 +735,9 @@  discard block
 block discarded – undo
698 735
 						'limit' => count($moderators),
699 736
 					)
700 737
 				);
701
-				while ($row = $smcFunc['db_fetch_assoc']($request))
702
-					$boardOptions['moderators'][] = $row['id_member'];
738
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
739
+									$boardOptions['moderators'][] = $row['id_member'];
740
+				}
703 741
 				$smcFunc['db_free_result']($request);
704 742
 			}
705 743
 		}
@@ -708,8 +746,9 @@  discard block
 block discarded – undo
708 746
 		if (!empty($boardOptions['moderators']))
709 747
 		{
710 748
 			$inserts = array();
711
-			foreach ($boardOptions['moderators'] as $moderator)
712
-				$inserts[] = array($board_id, $moderator);
749
+			foreach ($boardOptions['moderators'] as $moderator) {
750
+							$inserts[] = array($board_id, $moderator);
751
+			}
713 752
 
714 753
 			$smcFunc['db_insert']('insert',
715 754
 				'{db_prefix}moderators',
@@ -739,14 +778,16 @@  discard block
 block discarded – undo
739 778
 			{
740 779
 				$moderator_groups[$k] = trim($moderator_groups[$k]);
741 780
 
742
-				if (strlen($moderator_groups[$k]) == 0)
743
-					unset($moderator_groups[$k]);
781
+				if (strlen($moderator_groups[$k]) == 0) {
782
+									unset($moderator_groups[$k]);
783
+				}
744 784
 			}
745 785
 
746 786
 			/* 	Find all the id_group's for all the group names in the list
747 787
 				But skip any invalid ones (invisible/post groups/Administrator/Moderator) */
748
-			if (empty($boardOptions['moderator_groups']))
749
-				$boardOptions['moderator_groups'] = array();
788
+			if (empty($boardOptions['moderator_groups'])) {
789
+							$boardOptions['moderator_groups'] = array();
790
+			}
750 791
 			if (!empty($moderator_groups))
751 792
 			{
752 793
 				$request = $smcFunc['db_query']('', '
@@ -777,8 +818,9 @@  discard block
 block discarded – undo
777 818
 		if (!empty($boardOptions['moderator_groups']))
778 819
 		{
779 820
 			$inserts = array();
780
-			foreach ($boardOptions['moderator_groups'] as $moderator_group)
781
-				$inserts[] = array($board_id, $moderator_group);
821
+			foreach ($boardOptions['moderator_groups'] as $moderator_group) {
822
+							$inserts[] = array($board_id, $moderator_group);
823
+			}
782 824
 
783 825
 			$smcFunc['db_insert']('insert',
784 826
 				'{db_prefix}moderator_groups',
@@ -792,14 +834,16 @@  discard block
 block discarded – undo
792 834
 		updateSettings(array('settings_updated' => time()));
793 835
 	}
794 836
 
795
-	if (isset($boardOptions['move_to']))
796
-		reorderBoards();
837
+	if (isset($boardOptions['move_to'])) {
838
+			reorderBoards();
839
+	}
797 840
 
798 841
 	clean_cache('data');
799 842
 
800
-	if (empty($boardOptions['dont_log']))
801
-		logAction('edit_board', array('board' => $board_id), 'admin');
802
-}
843
+	if (empty($boardOptions['dont_log'])) {
844
+			logAction('edit_board', array('board' => $board_id), 'admin');
845
+	}
846
+	}
803 847
 
804 848
 /**
805 849
  * Create a new board and set its properties and position.
@@ -815,11 +859,13 @@  discard block
 block discarded – undo
815 859
 	global $boards, $smcFunc;
816 860
 
817 861
 	// Trigger an error if one of the required values is not set.
818
-	if (!isset($boardOptions['board_name']) || trim($boardOptions['board_name']) == '' || !isset($boardOptions['move_to']) || !isset($boardOptions['target_category']))
819
-		trigger_error('createBoard(): One or more of the required options is not set', E_USER_ERROR);
862
+	if (!isset($boardOptions['board_name']) || trim($boardOptions['board_name']) == '' || !isset($boardOptions['move_to']) || !isset($boardOptions['target_category'])) {
863
+			trigger_error('createBoard(): One or more of the required options is not set', E_USER_ERROR);
864
+	}
820 865
 
821
-	if (in_array($boardOptions['move_to'], array('child', 'before', 'after')) && !isset($boardOptions['target_board']))
822
-		trigger_error('createBoard(): Target board is not set', E_USER_ERROR);
866
+	if (in_array($boardOptions['move_to'], array('child', 'before', 'after')) && !isset($boardOptions['target_board'])) {
867
+			trigger_error('createBoard(): Target board is not set', E_USER_ERROR);
868
+	}
823 869
 
824 870
 	// Set every optional value to its default value.
825 871
 	$boardOptions += array(
@@ -853,8 +899,9 @@  discard block
 block discarded – undo
853 899
 	);
854 900
 	$board_id = $smcFunc['db_insert_id']('{db_prefix}boards', 'id_board');
855 901
 
856
-	if (empty($board_id))
857
-		return 0;
902
+	if (empty($board_id)) {
903
+			return 0;
904
+	}
858 905
 
859 906
 	// Change the board according to the given specifications.
860 907
 	modifyBoard($board_id, $boardOptions);
@@ -917,8 +964,9 @@  discard block
 block discarded – undo
917 964
 	global $sourcedir, $boards, $smcFunc;
918 965
 
919 966
 	// No boards to delete? Return!
920
-	if (empty($boards_to_remove))
921
-		return;
967
+	if (empty($boards_to_remove)) {
968
+			return;
969
+	}
922 970
 
923 971
 	getBoardTree();
924 972
 
@@ -929,12 +977,14 @@  discard block
 block discarded – undo
929 977
 	{
930 978
 		// Get a list of the child boards that will also be removed.
931 979
 		$child_boards_to_remove = array();
932
-		foreach ($boards_to_remove as $board_to_remove)
933
-			recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']);
980
+		foreach ($boards_to_remove as $board_to_remove) {
981
+					recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']);
982
+		}
934 983
 
935 984
 		// Merge the children with their parents.
936
-		if (!empty($child_boards_to_remove))
937
-			$boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove));
985
+		if (!empty($child_boards_to_remove)) {
986
+					$boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove));
987
+		}
938 988
 	}
939 989
 	// Move the children to a safe home.
940 990
 	else
@@ -942,10 +992,11 @@  discard block
 block discarded – undo
942 992
 		foreach ($boards_to_remove as $id_board)
943 993
 		{
944 994
 			// @todo Separate category?
945
-			if ($moveChildrenTo === 0)
946
-				fixChildren($id_board, 0, 0);
947
-			else
948
-				fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo);
995
+			if ($moveChildrenTo === 0) {
996
+							fixChildren($id_board, 0, 0);
997
+			} else {
998
+							fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo);
999
+			}
949 1000
 		}
950 1001
 	}
951 1002
 
@@ -959,8 +1010,9 @@  discard block
 block discarded – undo
959 1010
 		)
960 1011
 	);
961 1012
 	$topics = array();
962
-	while ($row = $smcFunc['db_fetch_assoc']($request))
963
-		$topics[] = $row['id_topic'];
1013
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1014
+			$topics[] = $row['id_topic'];
1015
+	}
964 1016
 	$smcFunc['db_free_result']($request);
965 1017
 
966 1018
 	require_once($sourcedir . '/RemoveTopic.php');
@@ -1048,8 +1100,9 @@  discard block
 block discarded – undo
1048 1100
 	clean_cache('data');
1049 1101
 
1050 1102
 	// Let's do some serious logging.
1051
-	foreach ($boards_to_remove as $id_board)
1052
-		logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin');
1103
+	foreach ($boards_to_remove as $id_board) {
1104
+			logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin');
1105
+	}
1053 1106
 
1054 1107
 	reorderBoards();
1055 1108
 }
@@ -1068,8 +1121,8 @@  discard block
 block discarded – undo
1068 1121
 	$board_order = 0;
1069 1122
 	foreach ($cat_tree as $catID => $dummy)
1070 1123
 	{
1071
-		foreach ($boardList[$catID] as $boardID)
1072
-			if ($boards[$boardID]['order'] != ++$board_order)
1124
+		foreach ($boardList[$catID] as $boardID) {
1125
+					if ($boards[$boardID]['order'] != ++$board_order)
1073 1126
 				$smcFunc['db_query']('', '
1074 1127
 					UPDATE {db_prefix}boards
1075 1128
 					SET board_order = {int:new_order}
@@ -1079,6 +1132,7 @@  discard block
 block discarded – undo
1079 1132
 						'selected_board' => $boardID,
1080 1133
 					)
1081 1134
 				);
1135
+		}
1082 1136
 	}
1083 1137
 
1084 1138
 	// Empty the board order cache
@@ -1107,8 +1161,9 @@  discard block
 block discarded – undo
1107 1161
 		)
1108 1162
 	);
1109 1163
 	$children = array();
1110
-	while ($row = $smcFunc['db_fetch_assoc']($result))
1111
-		$children[] = $row['id_board'];
1164
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
1165
+			$children[] = $row['id_board'];
1166
+	}
1112 1167
 	$smcFunc['db_free_result']($result);
1113 1168
 
1114 1169
 	// ...and set it to a new parent and child_level.
@@ -1124,9 +1179,10 @@  discard block
 block discarded – undo
1124 1179
 	);
1125 1180
 
1126 1181
 	// Recursively fix the children of the children.
1127
-	foreach ($children as $child)
1128
-		fixChildren($child, $newLevel + 1, $child);
1129
-}
1182
+	foreach ($children as $child) {
1183
+			fixChildren($child, $newLevel + 1, $child);
1184
+	}
1185
+	}
1130 1186
 
1131 1187
 /**
1132 1188
  * Tries to load up the entire board order and category very very quickly
@@ -1143,8 +1199,9 @@  discard block
 block discarded – undo
1143 1199
 		'boards' => array(),
1144 1200
 	);
1145 1201
 
1146
-	if (!empty($tree_order['boards']))
1147
-		return $tree_order;
1202
+	if (!empty($tree_order['boards'])) {
1203
+			return $tree_order;
1204
+	}
1148 1205
 
1149 1206
 	if (($cached = cache_get_data('board_order', 86400)) !== null)
1150 1207
 	{
@@ -1160,8 +1217,9 @@  discard block
 block discarded – undo
1160 1217
 	);
1161 1218
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1162 1219
 	{
1163
-		if (!in_array($row['id_cat'], $tree_order['cats']))
1164
-			$tree_order['cats'][] = $row['id_cat'];
1220
+		if (!in_array($row['id_cat'], $tree_order['cats'])) {
1221
+					$tree_order['cats'][] = $row['id_cat'];
1222
+		}
1165 1223
 		$tree_order['boards'][] = $row['id_board'];
1166 1224
 	}
1167 1225
 	$smcFunc['db_free_result']($request);
@@ -1181,16 +1239,19 @@  discard block
 block discarded – undo
1181 1239
 	$tree = getTreeOrder();
1182 1240
 
1183 1241
 	$ordered = array();
1184
-	foreach ($tree['boards'] as $board)
1185
-		if (!empty($boards[$board]))
1242
+	foreach ($tree['boards'] as $board) {
1243
+			if (!empty($boards[$board]))
1186 1244
 		{
1187 1245
 			$ordered[$board] = $boards[$board];
1246
+	}
1188 1247
 
1189
-			if (is_array($ordered[$board]) && !empty($ordered[$board]['boards']))
1190
-				sortBoards($ordered[$board]['boards']);
1248
+			if (is_array($ordered[$board]) && !empty($ordered[$board]['boards'])) {
1249
+							sortBoards($ordered[$board]['boards']);
1250
+			}
1191 1251
 
1192
-			if (is_array($ordered[$board]) && !empty($ordered[$board]['children']))
1193
-				sortBoards($ordered[$board]['children']);
1252
+			if (is_array($ordered[$board]) && !empty($ordered[$board]['children'])) {
1253
+							sortBoards($ordered[$board]['children']);
1254
+			}
1194 1255
 		}
1195 1256
 
1196 1257
 	$boards = $ordered;
@@ -1206,12 +1267,14 @@  discard block
 block discarded – undo
1206 1267
 	$tree = getTreeOrder();
1207 1268
 
1208 1269
 	$ordered = array();
1209
-	foreach ($tree['cats'] as $cat)
1210
-		if (!empty($categories[$cat]))
1270
+	foreach ($tree['cats'] as $cat) {
1271
+			if (!empty($categories[$cat]))
1211 1272
 		{
1212 1273
 			$ordered[$cat] = $categories[$cat];
1213
-			if (!empty($ordered[$cat]['boards']))
1214
-				sortBoards($ordered[$cat]['boards']);
1274
+	}
1275
+			if (!empty($ordered[$cat]['boards'])) {
1276
+							sortBoards($ordered[$cat]['boards']);
1277
+			}
1215 1278
 		}
1216 1279
 
1217 1280
 	$categories = $ordered;
@@ -1227,8 +1290,9 @@  discard block
 block discarded – undo
1227 1290
 {
1228 1291
 	global $smcFunc, $scripturl, $txt;
1229 1292
 
1230
-	if (empty($boards))
1231
-		return array();
1293
+	if (empty($boards)) {
1294
+			return array();
1295
+	}
1232 1296
 
1233 1297
 	$request = $smcFunc['db_query']('', '
1234 1298
 		SELECT mem.id_member, mem.real_name, mo.id_board
@@ -1242,8 +1306,9 @@  discard block
 block discarded – undo
1242 1306
 	$moderators = array();
1243 1307
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1244 1308
 	{
1245
-		if (empty($moderators[$row['id_board']]))
1246
-			$moderators[$row['id_board']] = array();
1309
+		if (empty($moderators[$row['id_board']])) {
1310
+					$moderators[$row['id_board']] = array();
1311
+		}
1247 1312
 
1248 1313
 		$moderators[$row['id_board']][] = array(
1249 1314
 			'id' => $row['id_member'],
@@ -1267,8 +1332,9 @@  discard block
 block discarded – undo
1267 1332
 {
1268 1333
 	global $smcFunc, $scripturl, $txt;
1269 1334
 
1270
-	if (empty($boards))
1271
-		return array();
1335
+	if (empty($boards)) {
1336
+			return array();
1337
+	}
1272 1338
 
1273 1339
 	$request = $smcFunc['db_query']('', '
1274 1340
 		SELECT mg.id_group, mg.group_name, bg.id_board
@@ -1282,8 +1348,9 @@  discard block
 block discarded – undo
1282 1348
 	$groups = array();
1283 1349
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1284 1350
 	{
1285
-		if (empty($groups[$row['id_board']]))
1286
-			$groups[$row['id_board']] = array();
1351
+		if (empty($groups[$row['id_board']])) {
1352
+					$groups[$row['id_board']] = array();
1353
+		}
1287 1354
 
1288 1355
 		$groups[$row['id_board']][] = array(
1289 1356
 			'id' => $row['id_group'],
@@ -1345,8 +1412,9 @@  discard block
 block discarded – undo
1345 1412
 
1346 1413
 		if (!empty($row['id_board']))
1347 1414
 		{
1348
-			if ($row['child_level'] != $curLevel)
1349
-				$prevBoard = 0;
1415
+			if ($row['child_level'] != $curLevel) {
1416
+							$prevBoard = 0;
1417
+			}
1350 1418
 
1351 1419
 			$boards[$row['id_board']] = array(
1352 1420
 				'id' => $row['id_board'],
@@ -1378,16 +1446,16 @@  discard block
 block discarded – undo
1378 1446
 					'children' => array()
1379 1447
 				);
1380 1448
 				$boards[$row['id_board']]['tree'] = &$cat_tree[$row['id_cat']]['children'][$row['id_board']];
1381
-			}
1382
-			else
1449
+			} else
1383 1450
 			{
1384 1451
 				// Parent doesn't exist!
1385
-				if (!isset($boards[$row['id_parent']]['tree']))
1386
-					fatal_lang_error('no_valid_parent', false, array($row['board_name']));
1452
+				if (!isset($boards[$row['id_parent']]['tree'])) {
1453
+									fatal_lang_error('no_valid_parent', false, array($row['board_name']));
1454
+				}
1387 1455
 
1388 1456
 				// Wrong childlevel...we can silently fix this...
1389
-				if ($boards[$row['id_parent']]['tree']['node']['level'] != $row['child_level'] - 1)
1390
-					$smcFunc['db_query']('', '
1457
+				if ($boards[$row['id_parent']]['tree']['node']['level'] != $row['child_level'] - 1) {
1458
+									$smcFunc['db_query']('', '
1391 1459
 						UPDATE {db_prefix}boards
1392 1460
 						SET child_level = {int:new_child_level}
1393 1461
 						WHERE id_board = {int:selected_board}',
@@ -1396,6 +1464,7 @@  discard block
 block discarded – undo
1396 1464
 							'selected_board' => $row['id_board'],
1397 1465
 						)
1398 1466
 					);
1467
+				}
1399 1468
 
1400 1469
 				$boards[$row['id_parent']]['tree']['children'][$row['id_board']] = array(
1401 1470
 					'node' => &$boards[$row['id_board']],
@@ -1426,8 +1495,9 @@  discard block
 block discarded – undo
1426 1495
  */
1427 1496
 function recursiveBoards(&$_boardList, &$_tree)
1428 1497
 {
1429
-	if (empty($_tree['children']))
1430
-		return;
1498
+	if (empty($_tree['children'])) {
1499
+			return;
1500
+	}
1431 1501
 
1432 1502
 	foreach ($_tree['children'] as $id => $node)
1433 1503
 	{
@@ -1446,11 +1516,13 @@  discard block
 block discarded – undo
1446 1516
 {
1447 1517
 	global $boards;
1448 1518
 
1449
-	if (empty($boards[$child]['parent']))
1450
-		return false;
1519
+	if (empty($boards[$child]['parent'])) {
1520
+			return false;
1521
+	}
1451 1522
 
1452
-	if ($boards[$child]['parent'] == $parent)
1453
-		return true;
1523
+	if ($boards[$child]['parent'] == $parent) {
1524
+			return true;
1525
+	}
1454 1526
 
1455 1527
 	return isChildOf($boards[$child]['parent'], $parent);
1456 1528
 }
Please login to merge, or discard this patch.
Sources/ManageMembergroups.php 1 patch
Braces   +128 added lines, -88 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 
20 21
 /**
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 	$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_membergroups') ? 'index' : 'settings');
45 46
 
46 47
 	// Is it elsewhere?
47
-	if (isset($subActions[$_REQUEST['sa']][2]))
48
-		require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]);
48
+	if (isset($subActions[$_REQUEST['sa']][2])) {
49
+			require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]);
50
+	}
49 51
 
50 52
 	// Do the permission check, you might not be allowed her.
51 53
 	isAllowedTo($subActions[$_REQUEST['sa']][1]);
@@ -104,19 +106,20 @@  discard block
 block discarded – undo
104 106
 					'function' => function($rowData) use ($scripturl)
105 107
 					{
106 108
 						// Since the moderator group has no explicit members, no link is needed.
107
-						if ($rowData['id_group'] == 3)
108
-							$group_name = $rowData['group_name'];
109
-						else
109
+						if ($rowData['id_group'] == 3) {
110
+													$group_name = $rowData['group_name'];
111
+						} else
110 112
 						{
111 113
 							$color_style = empty($rowData['online_color']) ? '' : sprintf(' style="color: %1$s;"', $rowData['online_color']);
112 114
 							$group_name = sprintf('<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']);
113 115
 						}
114 116
 
115 117
 						// Add a help option for moderator and administrator.
116
-						if ($rowData['id_group'] == 1)
117
-							$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
118
-						elseif ($rowData['id_group'] == 3)
119
-							$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
118
+						if ($rowData['id_group'] == 1) {
119
+													$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
120
+						} elseif ($rowData['id_group'] == 3) {
121
+													$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
122
+						}
120 123
 
121 124
 						return $group_name;
122 125
 					},
@@ -330,12 +333,14 @@  discard block
 block discarded – undo
330 333
 		call_integration_hook('integrate_add_membergroup', array($id_group, $postCountBasedGroup));
331 334
 
332 335
 		// Update the post groups now, if this is a post group!
333
-		if (isset($_POST['min_posts']))
334
-			updateStats('postgroups');
336
+		if (isset($_POST['min_posts'])) {
337
+					updateStats('postgroups');
338
+		}
335 339
 
336 340
 		// You cannot set permissions for post groups if they are disabled.
337
-		if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups']))
338
-			$_POST['perm_type'] = '';
341
+		if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) {
342
+					$_POST['perm_type'] = '';
343
+		}
339 344
 
340 345
 		if ($_POST['perm_type'] == 'predefined')
341 346
 		{
@@ -365,8 +370,9 @@  discard block
 block discarded – undo
365 370
 				$smcFunc['db_free_result']($request);
366 371
 
367 372
 				// Protected groups are... well, protected!
368
-				if ($copy_type == 1)
369
-					fatal_lang_error('membergroup_does_not_exist');
373
+				if ($copy_type == 1) {
374
+									fatal_lang_error('membergroup_does_not_exist');
375
+				}
370 376
 			}
371 377
 
372 378
 			// Don't allow copying of a real priviledged person!
@@ -384,18 +390,20 @@  discard block
 block discarded – undo
384 390
 			$inserts = array();
385 391
 			while ($row = $smcFunc['db_fetch_assoc']($request))
386 392
 			{
387
-				if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions']))
388
-					$inserts[] = array($id_group, $row['permission'], $row['add_deny']);
393
+				if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions'])) {
394
+									$inserts[] = array($id_group, $row['permission'], $row['add_deny']);
395
+				}
389 396
 			}
390 397
 			$smcFunc['db_free_result']($request);
391 398
 
392
-			if (!empty($inserts))
393
-				$smcFunc['db_insert']('insert',
399
+			if (!empty($inserts)) {
400
+							$smcFunc['db_insert']('insert',
394 401
 					'{db_prefix}permissions',
395 402
 					array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
396 403
 					$inserts,
397 404
 					array('id_group', 'permission')
398 405
 				);
406
+			}
399 407
 
400 408
 			$request = $smcFunc['db_query']('', '
401 409
 				SELECT id_profile, permission, add_deny
@@ -406,17 +414,19 @@  discard block
 block discarded – undo
406 414
 				)
407 415
 			);
408 416
 			$inserts = array();
409
-			while ($row = $smcFunc['db_fetch_assoc']($request))
410
-				$inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']);
417
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
418
+							$inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']);
419
+			}
411 420
 			$smcFunc['db_free_result']($request);
412 421
 
413
-			if (!empty($inserts))
414
-				$smcFunc['db_insert']('insert',
422
+			if (!empty($inserts)) {
423
+							$smcFunc['db_insert']('insert',
415 424
 					'{db_prefix}board_permissions',
416 425
 					array('id_group' => 'int', 'id_profile' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
417 426
 					$inserts,
418 427
 					array('id_group', 'id_profile', 'permission')
419 428
 				);
429
+			}
420 430
 
421 431
 			// Also get some membergroup information if we're copying and not copying from guests...
422 432
 			if ($copy_id > 0 && $_POST['perm_type'] == 'copy')
@@ -469,14 +479,15 @@  discard block
 block discarded – undo
469 479
 		$changed_boards['allow'] = array();
470 480
 		$changed_boards['deny'] = array();
471 481
 		$changed_boards['ignore'] = array();
472
-		foreach ($accesses as $group_id => $action)
473
-			$changed_boards[$action][] = (int) $group_id;
482
+		foreach ($accesses as $group_id => $action) {
483
+					$changed_boards[$action][] = (int) $group_id;
484
+		}
474 485
 
475 486
 		foreach (array('allow', 'deny') as $board_action)
476 487
 		{
477 488
 			// Only do this if they have special access requirements.
478
-			if (!empty($changed_boards[$board_action]))
479
-				$smcFunc['db_query']('', '
489
+			if (!empty($changed_boards[$board_action])) {
490
+							$smcFunc['db_query']('', '
480 491
 					UPDATE {db_prefix}boards
481 492
 					SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END
482 493
 					WHERE id_board IN ({array_int:board_list})',
@@ -488,11 +499,13 @@  discard block
 block discarded – undo
488 499
 						'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
489 500
 					)
490 501
 				);
502
+			}
491 503
 		}
492 504
 
493 505
 		// If this is joinable then set it to show group membership in people's profiles.
494
-		if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1)
495
-			updateSettings(array('show_group_membership' => 1));
506
+		if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) {
507
+					updateSettings(array('show_group_membership' => 1));
508
+		}
496 509
 
497 510
 		// Rebuild the group cache.
498 511
 		updateSettings(array(
@@ -513,8 +526,9 @@  discard block
 block discarded – undo
513 526
 	$context['undefined_group'] = !isset($_REQUEST['postgroup']) && !isset($_REQUEST['generalgroup']);
514 527
 	$context['allow_protected'] = allowedTo('admin_forum');
515 528
 
516
-	if (!empty($modSettings['deny_boards_access']))
517
-		loadLanguage('ManagePermissions');
529
+	if (!empty($modSettings['deny_boards_access'])) {
530
+			loadLanguage('ManagePermissions');
531
+	}
518 532
 
519 533
 	$result = $smcFunc['db_query']('', '
520 534
 		SELECT id_group, group_name
@@ -531,11 +545,12 @@  discard block
 block discarded – undo
531 545
 		)
532 546
 	);
533 547
 	$context['groups'] = array();
534
-	while ($row = $smcFunc['db_fetch_assoc']($result))
535
-		$context['groups'][] = array(
548
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
549
+			$context['groups'][] = array(
536 550
 			'id' => $row['id_group'],
537 551
 			'name' => $row['group_name']
538 552
 		);
553
+	}
539 554
 	$smcFunc['db_free_result']($result);
540 555
 
541 556
 	$request = $smcFunc['db_query']('', '
@@ -552,12 +567,13 @@  discard block
 block discarded – undo
552 567
 	while ($row = $smcFunc['db_fetch_assoc']($request))
553 568
 	{
554 569
 		// This category hasn't been set up yet..
555
-		if (!isset($context['categories'][$row['id_cat']]))
556
-			$context['categories'][$row['id_cat']] = array(
570
+		if (!isset($context['categories'][$row['id_cat']])) {
571
+					$context['categories'][$row['id_cat']] = array(
557 572
 				'id' => $row['id_cat'],
558 573
 				'name' => $row['cat_name'],
559 574
 				'boards' => array()
560 575
 			);
576
+		}
561 577
 
562 578
 		// Set this board up, and let the template know when it's a child.  (indent them..)
563 579
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -605,8 +621,9 @@  discard block
 block discarded – undo
605 621
 	require_once($sourcedir . '/Subs-Membergroups.php');
606 622
 	$result = deleteMembergroups((int) $_REQUEST['group']);
607 623
 	// Need to throw a warning if it went wrong, but this is the only one we have a message for...
608
-	if ($result === 'group_cannot_delete_sub')
609
-		fatal_lang_error('membergroups_cannot_delete_paid', false);
624
+	if ($result === 'group_cannot_delete_sub') {
625
+			fatal_lang_error('membergroups_cannot_delete_paid', false);
626
+	}
610 627
 
611 628
 	// Go back to the membergroup index.
612 629
 	redirectexit('action=admin;area=membergroups;');
@@ -628,8 +645,9 @@  discard block
 block discarded – undo
628 645
 
629 646
 	$_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0;
630 647
 
631
-	if (!empty($modSettings['deny_boards_access']))
632
-		loadLanguage('ManagePermissions');
648
+	if (!empty($modSettings['deny_boards_access'])) {
649
+			loadLanguage('ManagePermissions');
650
+	}
633 651
 
634 652
 	// Make sure this group is editable.
635 653
 	if (!empty($_REQUEST['group']))
@@ -651,8 +669,9 @@  discard block
 block discarded – undo
651 669
 	}
652 670
 
653 671
 	// Now, do we have a valid id?
654
-	if (empty($_REQUEST['group']))
655
-		fatal_lang_error('membergroup_does_not_exist', false);
672
+	if (empty($_REQUEST['group'])) {
673
+			fatal_lang_error('membergroup_does_not_exist', false);
674
+	}
656 675
 
657 676
 	// People who can manage boards are a bit special.
658 677
 	require_once($sourcedir . '/Subs-Members.php');
@@ -683,8 +702,9 @@  discard block
 block discarded – undo
683 702
 		require_once($sourcedir . '/Subs-Membergroups.php');
684 703
 		$result = deleteMembergroups($_REQUEST['group']);
685 704
 		// Need to throw a warning if it went wrong, but this is the only one we have a message for...
686
-		if ($result === 'group_cannot_delete_sub')
687
-			fatal_lang_error('membergroups_cannot_delete_paid', false);
705
+		if ($result === 'group_cannot_delete_sub') {
706
+					fatal_lang_error('membergroups_cannot_delete_paid', false);
707
+		}
688 708
 
689 709
 		redirectexit('action=admin;area=membergroups;');
690 710
 	}
@@ -761,16 +781,18 @@  discard block
 block discarded – undo
761 781
 				$request = $smcFunc['db_query']('', '
762 782
 					SELECT id_board
763 783
 					FROM {db_prefix}boards');
764
-				while ($row = $smcFunc['db_fetch_assoc']($request))
765
-					$accesses[(int) $row['id_board']] = 'allow';
784
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
785
+									$accesses[(int) $row['id_board']] = 'allow';
786
+				}
766 787
 				$smcFunc['db_free_result']($request);
767 788
 			}
768 789
 
769 790
 			$changed_boards['allow'] = array();
770 791
 			$changed_boards['deny'] = array();
771 792
 			$changed_boards['ignore'] = array();
772
-			foreach ($accesses as $group_id => $action)
773
-				$changed_boards[$action][] = (int) $group_id;
793
+			foreach ($accesses as $group_id => $action) {
794
+							$changed_boards[$action][] = (int) $group_id;
795
+			}
774 796
 
775 797
 			foreach (array('allow', 'deny') as $board_action)
776 798
 			{
@@ -786,8 +808,8 @@  discard block
 block discarded – undo
786 808
 						'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
787 809
 					)
788 810
 				);
789
-				while ($row = $smcFunc['db_fetch_assoc']($request))
790
-					$smcFunc['db_query']('', '
811
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
812
+									$smcFunc['db_query']('', '
791 813
 						UPDATE {db_prefix}boards
792 814
 						SET {raw:column} = {string:member_group_access}
793 815
 						WHERE id_board = {int:current_board}',
@@ -797,11 +819,12 @@  discard block
 block discarded – undo
797 819
 							'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
798 820
 						)
799 821
 					);
822
+				}
800 823
 				$smcFunc['db_free_result']($request);
801 824
 
802 825
 				// Add the membergroup to all boards that hadn't been set yet.
803
-				if (!empty($changed_boards[$board_action]))
804
-					$smcFunc['db_query']('', '
826
+				if (!empty($changed_boards[$board_action])) {
827
+									$smcFunc['db_query']('', '
805 828
 						UPDATE {db_prefix}boards
806 829
 						SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END
807 830
 						WHERE id_board IN ({array_int:board_list})
@@ -815,6 +838,7 @@  discard block
 block discarded – undo
815 838
 							'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
816 839
 						)
817 840
 					);
841
+				}
818 842
 			}
819 843
 		}
820 844
 
@@ -840,12 +864,14 @@  discard block
 block discarded – undo
840 864
 				)
841 865
 			);
842 866
 			$updates = array();
843
-			while ($row = $smcFunc['db_fetch_assoc']($request))
844
-				$updates[$row['additional_groups']][] = $row['id_member'];
867
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
868
+							$updates[$row['additional_groups']][] = $row['id_member'];
869
+			}
845 870
 			$smcFunc['db_free_result']($request);
846 871
 
847
-			foreach ($updates as $additional_groups => $memberArray)
848
-				updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
872
+			foreach ($updates as $additional_groups => $memberArray) {
873
+							updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
874
+			}
849 875
 
850 876
 			// Sorry, but post groups can't moderate boards
851 877
 			$smcFunc['db_query']('', '
@@ -855,8 +881,7 @@  discard block
 block discarded – undo
855 881
 					'current_group' => (int) $_REQUEST['group'],
856 882
 				)
857 883
 			);
858
-		}
859
-		elseif ($_REQUEST['group'] != 3)
884
+		} elseif ($_REQUEST['group'] != 3)
860 885
 		{
861 886
 			// Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional).
862 887
 			if ($_POST['group_hidden'] == 2)
@@ -871,8 +896,9 @@  discard block
 block discarded – undo
871 896
 					)
872 897
 				);
873 898
 				$updates = array();
874
-				while ($row = $smcFunc['db_fetch_assoc']($request))
875
-					$updates[$row['additional_groups']][] = $row['id_member'];
899
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
900
+									$updates[$row['additional_groups']][] = $row['id_member'];
901
+				}
876 902
 				$smcFunc['db_free_result']($request);
877 903
 
878 904
 				foreach ($updates as $additional_groups => $memberArray)
@@ -914,8 +940,9 @@  discard block
 block discarded – undo
914 940
 			$smcFunc['db_free_result']($request);
915 941
 
916 942
 			// Do we need to update the setting?
917
-			if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable))
918
-				updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0));
943
+			if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) {
944
+							updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0));
945
+			}
919 946
 		}
920 947
 
921 948
 		// Do we need to set inherited permissions?
@@ -948,8 +975,9 @@  discard block
 block discarded – undo
948 975
 				{
949 976
 					$moderators[$k] = trim($moderators[$k]);
950 977
 
951
-					if (strlen($moderators[$k]) == 0)
952
-						unset($moderators[$k]);
978
+					if (strlen($moderators[$k]) == 0) {
979
+											unset($moderators[$k]);
980
+					}
953 981
 				}
954 982
 
955 983
 				// Find all the id_member's for the member_name's in the list.
@@ -965,8 +993,9 @@  discard block
 block discarded – undo
965 993
 							'count' => count($moderators),
966 994
 						)
967 995
 					);
968
-					while ($row = $smcFunc['db_fetch_assoc']($request))
969
-						$group_moderators[] = $row['id_member'];
996
+					while ($row = $smcFunc['db_fetch_assoc']($request)) {
997
+											$group_moderators[] = $row['id_member'];
998
+					}
970 999
 					$smcFunc['db_free_result']($request);
971 1000
 				}
972 1001
 			}
@@ -974,8 +1003,9 @@  discard block
 block discarded – undo
974 1003
 			if (!empty($_POST['moderator_list']))
975 1004
 			{
976 1005
 				$moderators = array();
977
-				foreach ($_POST['moderator_list'] as $moderator)
978
-					$moderators[] = (int) $moderator;
1006
+				foreach ($_POST['moderator_list'] as $moderator) {
1007
+									$moderators[] = (int) $moderator;
1008
+				}
979 1009
 
980 1010
 				if (!empty($moderators))
981 1011
 				{
@@ -989,8 +1019,9 @@  discard block
 block discarded – undo
989 1019
 							'num_moderators' => count($moderators),
990 1020
 						)
991 1021
 					);
992
-					while ($row = $smcFunc['db_fetch_assoc']($request))
993
-						$group_moderators[] = $row['id_member'];
1022
+					while ($row = $smcFunc['db_fetch_assoc']($request)) {
1023
+											$group_moderators[] = $row['id_member'];
1024
+					}
994 1025
 					$smcFunc['db_free_result']($request);
995 1026
 				}
996 1027
 			}
@@ -1002,8 +1033,9 @@  discard block
 block discarded – undo
1002 1033
 			if (!empty($group_moderators))
1003 1034
 			{
1004 1035
 				$mod_insert = array();
1005
-				foreach ($group_moderators as $moderator)
1006
-					$mod_insert[] = array($_REQUEST['group'], $moderator);
1036
+				foreach ($group_moderators as $moderator) {
1037
+									$mod_insert[] = array($_REQUEST['group'], $moderator);
1038
+				}
1007 1039
 
1008 1040
 				$smcFunc['db_insert']('insert',
1009 1041
 					'{db_prefix}group_moderators',
@@ -1037,8 +1069,9 @@  discard block
 block discarded – undo
1037 1069
 			'current_group' => (int) $_REQUEST['group'],
1038 1070
 		)
1039 1071
 	);
1040
-	if ($smcFunc['db_num_rows']($request) == 0)
1041
-		fatal_lang_error('membergroup_does_not_exist', false);
1072
+	if ($smcFunc['db_num_rows']($request) == 0) {
1073
+			fatal_lang_error('membergroup_does_not_exist', false);
1074
+	}
1042 1075
 	$row = $smcFunc['db_fetch_assoc']($request);
1043 1076
 	$smcFunc['db_free_result']($request);
1044 1077
 
@@ -1075,14 +1108,16 @@  discard block
 block discarded – undo
1075 1108
 		)
1076 1109
 	);
1077 1110
 	$context['group']['moderators'] = array();
1078
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1079
-		$context['group']['moderators'][$row['id_member']] = $row['real_name'];
1111
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1112
+			$context['group']['moderators'][$row['id_member']] = $row['real_name'];
1113
+	}
1080 1114
 	$smcFunc['db_free_result']($request);
1081 1115
 
1082 1116
 	$context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '&quot;' . implode('&quot;, &quot;', $context['group']['moderators']) . '&quot;';
1083 1117
 
1084
-	if (!empty($context['group']['moderators']))
1085
-		list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1);
1118
+	if (!empty($context['group']['moderators'])) {
1119
+			list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1);
1120
+	}
1086 1121
 
1087 1122
 	// Get a list of boards this membergroup is allowed to see.
1088 1123
 	$context['boards'] = array();
@@ -1102,12 +1137,13 @@  discard block
 block discarded – undo
1102 1137
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1103 1138
 		{
1104 1139
 			// This category hasn't been set up yet..
1105
-			if (!isset($context['categories'][$row['id_cat']]))
1106
-				$context['categories'][$row['id_cat']] = array(
1140
+			if (!isset($context['categories'][$row['id_cat']])) {
1141
+							$context['categories'][$row['id_cat']] = array(
1107 1142
 					'id' => $row['id_cat'],
1108 1143
 					'name' => $row['cat_name'],
1109 1144
 					'boards' => array()
1110 1145
 				);
1146
+			}
1111 1147
 
1112 1148
 			// Set this board up, and let the template know when it's a child.  (indent them..)
1113 1149
 			$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -1155,19 +1191,22 @@  discard block
 block discarded – undo
1155 1191
 				$image_info = getimagesize($settings['default_theme_dir'] . '/images/membericons/' . $value);
1156 1192
 
1157 1193
 				// If this is bigger than 128 in width or 32 in height, skip this one.
1158
-				if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32)
1159
-					continue;
1194
+				if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32) {
1195
+									continue;
1196
+				}
1160 1197
 
1161 1198
 				// Else it's valid. Add it in.
1162
-				else
1163
-					$context['possible_icons'][] = $value;
1199
+				else {
1200
+									$context['possible_icons'][] = $value;
1201
+				}
1164 1202
 			}
1165 1203
 		}
1166 1204
 	}
1167 1205
 
1168 1206
 	// Insert our JS, if we have possible icons.
1169
-	if (!empty($context['possible_icons']))
1170
-		loadJavaScriptFile('icondropdown.js', array('validate' => true), 'smf_icondropdown');
1207
+	if (!empty($context['possible_icons'])) {
1208
+			loadJavaScriptFile('icondropdown.js', array('validate' => true), 'smf_icondropdown');
1209
+	}
1171 1210
 
1172 1211
 		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
1173 1212
 
@@ -1189,8 +1228,9 @@  discard block
 block discarded – undo
1189 1228
 		)
1190 1229
 	);
1191 1230
 	$context['inheritable_groups'] = array();
1192
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1193
-		$context['inheritable_groups'][$row['id_group']] = $row['group_name'];
1231
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1232
+			$context['inheritable_groups'][$row['id_group']] = $row['group_name'];
1233
+	}
1194 1234
 	$smcFunc['db_free_result']($request);
1195 1235
 
1196 1236
 	call_integration_hook('integrate_view_membergroup');
Please login to merge, or discard this patch.
other/upgrade-helper.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 /**
142 142
  * Make files writable. First try to use regular chmod, but if that fails, try to use FTP.
143 143
  *
144
- * @param $files
144
+ * @param string[] $files
145 145
  * @return bool
146 146
  */
147 147
 function makeFilesWritable(&$files)
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 /**
382 382
  * Prints an error to stderr.
383 383
  *
384
- * @param $message
384
+ * @param string $message
385 385
  * @param bool $fatal
386 386
  */
387 387
 function print_error($message, $fatal = false)
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 /**
401 401
  * Throws a graphical error message.
402 402
  *
403
- * @param $message
403
+ * @param string $message
404 404
  * @return bool
405 405
  */
406 406
 function throw_error($message)
Please login to merge, or discard this patch.
Braces   +90 added lines, -64 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * This file contains helper functions for upgrade.php
14 14
  */
15 15
 
16
-if (!defined('SMF_VERSION'))
16
+if (!defined('SMF_VERSION')) {
17 17
 	die('No direct access!');
18
+}
18 19
 
19 20
 /**
20 21
  * Clean the cache using the SMF 2.1 CacheAPI.
@@ -45,8 +46,9 @@  discard block
 block discarded – undo
45 46
 	global $smcFunc;
46 47
 	static $member_groups = array();
47 48
 
48
-	if (!empty($member_groups))
49
-		return $member_groups;
49
+	if (!empty($member_groups)) {
50
+			return $member_groups;
51
+	}
50 52
 
51 53
 	$request = $smcFunc['db_query']('', '
52 54
 		SELECT group_name, id_group
@@ -71,8 +73,9 @@  discard block
 block discarded – undo
71 73
 			)
72 74
 		);
73 75
 	}
74
-	while ($row = $smcFunc['db_fetch_row']($request))
75
-		$member_groups[trim($row[0])] = $row[1];
76
+	while ($row = $smcFunc['db_fetch_row']($request)) {
77
+			$member_groups[trim($row[0])] = $row[1];
78
+	}
76 79
 	$smcFunc['db_free_result']($request);
77 80
 
78 81
 	return $member_groups;
@@ -88,8 +91,9 @@  discard block
 block discarded – undo
88 91
 {
89 92
 	global $upcontext, $boarddir, $sourcedir;
90 93
 
91
-	if (empty($files))
92
-		return true;
94
+	if (empty($files)) {
95
+			return true;
96
+	}
93 97
 
94 98
 	$failure = false;
95 99
 	// On linux, it's easy - just use is_writable!
@@ -104,14 +108,16 @@  discard block
 block discarded – undo
104 108
 				@chmod($file, 0755);
105 109
 
106 110
 				// Well, 755 hopefully worked... if not, try 777.
107
-				if (!is_writable($file) && !@chmod($file, 0777))
108
-					$failure = true;
111
+				if (!is_writable($file) && !@chmod($file, 0777)) {
112
+									$failure = true;
113
+				}
109 114
 				// Otherwise remove it as it's good!
110
-				else
111
-					unset($files[$k]);
115
+				else {
116
+									unset($files[$k]);
117
+				}
118
+			} else {
119
+							unset($files[$k]);
112 120
 			}
113
-			else
114
-				unset($files[$k]);
115 121
 		}
116 122
 	}
117 123
 	// Windows is trickier.  Let's try opening for r+...
@@ -122,30 +128,35 @@  discard block
 block discarded – undo
122 128
 		foreach ($files as $k => $file)
123 129
 		{
124 130
 			// Folders can't be opened for write... but the index.php in them can ;).
125
-			if (is_dir($file))
126
-				$file .= '/index.php';
131
+			if (is_dir($file)) {
132
+							$file .= '/index.php';
133
+			}
127 134
 
128 135
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
129 136
 			@chmod($file, 0777);
130 137
 			$fp = @fopen($file, 'r+');
131 138
 
132 139
 			// Hmm, okay, try just for write in that case...
133
-			if (!$fp)
134
-				$fp = @fopen($file, 'w');
140
+			if (!$fp) {
141
+							$fp = @fopen($file, 'w');
142
+			}
135 143
 
136
-			if (!$fp)
137
-				$failure = true;
138
-			else
139
-				unset($files[$k]);
144
+			if (!$fp) {
145
+							$failure = true;
146
+			} else {
147
+							unset($files[$k]);
148
+			}
140 149
 			@fclose($fp);
141 150
 		}
142 151
 	}
143 152
 
144
-	if (empty($files))
145
-		return true;
153
+	if (empty($files)) {
154
+			return true;
155
+	}
146 156
 
147
-	if (!isset($_SERVER))
148
-		return !$failure;
157
+	if (!isset($_SERVER)) {
158
+			return !$failure;
159
+	}
149 160
 
150 161
 	// What still needs to be done?
151 162
 	$upcontext['chmod']['files'] = $files;
@@ -197,36 +208,40 @@  discard block
 block discarded – undo
197 208
 
198 209
 		if (!isset($ftp) || $ftp->error !== false)
199 210
 		{
200
-			if (!isset($ftp))
201
-				$ftp = new ftp_connection(null);
211
+			if (!isset($ftp)) {
212
+							$ftp = new ftp_connection(null);
213
+			}
202 214
 			// Save the error so we can mess with listing...
203
-			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error']))
204
-				$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
215
+			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) {
216
+							$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
217
+			}
205 218
 
206 219
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
207 220
 
208
-			if ($found_path || !isset($upcontext['chmod']['path']))
209
-				$upcontext['chmod']['path'] = $detect_path;
221
+			if ($found_path || !isset($upcontext['chmod']['path'])) {
222
+							$upcontext['chmod']['path'] = $detect_path;
223
+			}
210 224
 
211
-			if (!isset($upcontext['chmod']['username']))
212
-				$upcontext['chmod']['username'] = $username;
225
+			if (!isset($upcontext['chmod']['username'])) {
226
+							$upcontext['chmod']['username'] = $username;
227
+			}
213 228
 
214 229
 			// Don't forget the login token.
215 230
 			$upcontext += createToken('login');
216 231
 
217 232
 			return false;
218
-		}
219
-		else
233
+		} else
220 234
 		{
221 235
 			// We want to do a relative path for FTP.
222 236
 			if (!in_array($upcontext['chmod']['path'], array('', '/')))
223 237
 			{
224 238
 				$ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => ''));
225
-				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/'))
226
-					$ftp_root = substr($ftp_root, 0, -1);
239
+				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) {
240
+									$ftp_root = substr($ftp_root, 0, -1);
241
+				}
242
+			} else {
243
+							$ftp_root = $boarddir;
227 244
 			}
228
-			else
229
-				$ftp_root = $boarddir;
230 245
 
231 246
 			// Save the info for next time!
232 247
 			$_SESSION['installer_temp_ftp'] = array(
@@ -240,10 +255,12 @@  discard block
 block discarded – undo
240 255
 
241 256
 			foreach ($files as $k => $file)
242 257
 			{
243
-				if (!is_writable($file))
244
-					$ftp->chmod($file, 0755);
245
-				if (!is_writable($file))
246
-					$ftp->chmod($file, 0777);
258
+				if (!is_writable($file)) {
259
+									$ftp->chmod($file, 0755);
260
+				}
261
+				if (!is_writable($file)) {
262
+									$ftp->chmod($file, 0777);
263
+				}
247 264
 
248 265
 				// Assuming that didn't work calculate the path without the boarddir.
249 266
 				if (!is_writable($file))
@@ -252,19 +269,23 @@  discard block
 block discarded – undo
252 269
 					{
253 270
 						$ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => ''));
254 271
 						$ftp->chmod($ftp_file, 0755);
255
-						if (!is_writable($file))
256
-							$ftp->chmod($ftp_file, 0777);
272
+						if (!is_writable($file)) {
273
+													$ftp->chmod($ftp_file, 0777);
274
+						}
257 275
 						// Sometimes an extra slash can help...
258 276
 						$ftp_file = '/' . $ftp_file;
259
-						if (!is_writable($file))
260
-							$ftp->chmod($ftp_file, 0755);
261
-						if (!is_writable($file))
262
-							$ftp->chmod($ftp_file, 0777);
277
+						if (!is_writable($file)) {
278
+													$ftp->chmod($ftp_file, 0755);
279
+						}
280
+						if (!is_writable($file)) {
281
+													$ftp->chmod($ftp_file, 0777);
282
+						}
263 283
 					}
264 284
 				}
265 285
 
266
-				if (is_writable($file))
267
-					unset($files[$k]);
286
+				if (is_writable($file)) {
287
+									unset($files[$k]);
288
+				}
268 289
 			}
269 290
 
270 291
 			$ftp->close();
@@ -274,8 +295,9 @@  discard block
 block discarded – undo
274 295
 	// What remains?
275 296
 	$upcontext['chmod']['files'] = $files;
276 297
 
277
-	if (empty($files))
278
-		return true;
298
+	if (empty($files)) {
299
+			return true;
300
+	}
279 301
 
280 302
 	return false;
281 303
 }
@@ -288,8 +310,9 @@  discard block
 block discarded – undo
288 310
  */
289 311
 function quickFileWritable($file)
290 312
 {
291
-	if (is_writable($file))
292
-		return true;
313
+	if (is_writable($file)) {
314
+			return true;
315
+	}
293 316
 
294 317
 	@chmod($file, 0755);
295 318
 
@@ -299,10 +322,11 @@  discard block
 block discarded – undo
299 322
 	foreach ($chmod_values as $val)
300 323
 	{
301 324
 		// If it's writable, break out of the loop
302
-		if (is_writable($file))
303
-			break;
304
-		else
305
-			@chmod($file, $val);
325
+		if (is_writable($file)) {
326
+					break;
327
+		} else {
328
+					@chmod($file, $val);
329
+		}
306 330
 	}
307 331
 
308 332
 	return is_writable($file);
@@ -329,14 +353,16 @@  discard block
 block discarded – undo
329 353
 {
330 354
 	static $fp = null;
331 355
 
332
-	if ($fp === null)
333
-		$fp = fopen('php://stderr', 'wb');
356
+	if ($fp === null) {
357
+			$fp = fopen('php://stderr', 'wb');
358
+	}
334 359
 
335 360
 	fwrite($fp, $message . "\n");
336 361
 
337
-	if ($fatal)
338
-		exit;
339
-}
362
+	if ($fatal) {
363
+			exit;
364
+	}
365
+	}
340 366
 
341 367
 /**
342 368
  * Throws a graphical error message.
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 		$connection
758 758
 	);
759 759
 	
760
-	if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
760
+	if (!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
761 761
 	{
762 762
 		if ($returnmode == 1)
763 763
 			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
 			$return_var = array();
767 767
 			$count = count($insertRows);
768 768
 			$start = smf_db_insert_id($table, $keys[0]);
769
-			for ($i = 0; $i < $count; $i++ )
769
+			for ($i = 0; $i < $count; $i++)
770 770
 				$return_var[] = $start + $i;
771 771
 		}
772 772
 		return $return_var;
Please login to merge, or discard this patch.
Braces   +252 added lines, -185 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -58,9 +59,11 @@  discard block
 block discarded – undo
58 59
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
59 60
 			'db_is_resource'            => 'smf_is_resource',
60 61
 		);
62
+	}
61 63
 
62
-	if (!empty($db_options['persist']))
63
-		$db_server = 'p:' . $db_server;
64
+	if (!empty($db_options['persist'])) {
65
+			$db_server = 'p:' . $db_server;
66
+	}
64 67
 
65 68
 	$connection = mysqli_init();
66 69
 	
@@ -69,31 +72,35 @@  discard block
 block discarded – undo
69 72
 	$success = false;
70 73
 	
71 74
 	if ($connection) {
72
-		if (!empty($db_options['port']))
73
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
74
-		else
75
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
75
+		if (!empty($db_options['port'])) {
76
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
77
+		} else {
78
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
79
+		}
76 80
 	}
77 81
 
78 82
 	// Something's wrong, show an error if its fatal (which we assume it is)
79 83
 	if ($success === false)
80 84
 	{
81
-		if (!empty($db_options['non_fatal']))
82
-			return null;
83
-		else
84
-			display_db_error();
85
+		if (!empty($db_options['non_fatal'])) {
86
+					return null;
87
+		} else {
88
+					display_db_error();
89
+		}
85 90
 	}
86 91
 
87 92
 	// Select the database, unless told not to
88
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
89
-		display_db_error();
93
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
94
+			display_db_error();
95
+	}
90 96
 
91 97
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
92
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
93
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
98
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
99
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
94 100
 		array(),
95 101
 		false
96 102
 	);
103
+	}
97 104
 
98 105
 	return $connection;
99 106
 }
@@ -164,37 +171,46 @@  discard block
 block discarded – undo
164 171
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
165 172
 
166 173
 	list ($values, $connection) = $db_callback;
167
-	if (!is_object($connection))
168
-		display_db_error();
174
+	if (!is_object($connection)) {
175
+			display_db_error();
176
+	}
169 177
 
170
-	if ($matches[1] === 'db_prefix')
171
-		return $db_prefix;
178
+	if ($matches[1] === 'db_prefix') {
179
+			return $db_prefix;
180
+	}
172 181
 
173
-	if ($matches[1] === 'query_see_board')
174
-		return $user_info['query_see_board'];
182
+	if ($matches[1] === 'query_see_board') {
183
+			return $user_info['query_see_board'];
184
+	}
175 185
 
176
-	if ($matches[1] === 'query_wanna_see_board')
177
-		return $user_info['query_wanna_see_board'];
186
+	if ($matches[1] === 'query_wanna_see_board') {
187
+			return $user_info['query_wanna_see_board'];
188
+	}
178 189
 
179
-	if ($matches[1] === 'empty')
180
-		return '\'\'';
190
+	if ($matches[1] === 'empty') {
191
+			return '\'\'';
192
+	}
181 193
 
182
-	if (!isset($matches[2]))
183
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
194
+	if (!isset($matches[2])) {
195
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
196
+	}
184 197
 
185
-	if ($matches[1] === 'literal')
186
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
198
+	if ($matches[1] === 'literal') {
199
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
200
+	}
187 201
 
188
-	if (!isset($values[$matches[2]]))
189
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
202
+	if (!isset($values[$matches[2]])) {
203
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
204
+	}
190 205
 
191 206
 	$replacement = $values[$matches[2]];
192 207
 
193 208
 	switch ($matches[1])
194 209
 	{
195 210
 		case 'int':
196
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
197
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
211
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
212
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			}
198 214
 			return (string) (int) $replacement;
199 215
 		break;
200 216
 
@@ -206,56 +222,63 @@  discard block
 block discarded – undo
206 222
 		case 'array_int':
207 223
 			if (is_array($replacement))
208 224
 			{
209
-				if (empty($replacement))
210
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+				if (empty($replacement)) {
226
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227
+				}
211 228
 
212 229
 				foreach ($replacement as $key => $value)
213 230
 				{
214
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
215
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
232
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+					}
216 234
 
217 235
 					$replacement[$key] = (string) (int) $value;
218 236
 				}
219 237
 
220 238
 				return implode(', ', $replacement);
239
+			} else {
240
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221 241
 			}
222
-			else
223
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224 242
 
225 243
 		break;
226 244
 
227 245
 		case 'array_string':
228 246
 			if (is_array($replacement))
229 247
 			{
230
-				if (empty($replacement))
231
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
248
+				if (empty($replacement)) {
249
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
250
+				}
232 251
 
233
-				foreach ($replacement as $key => $value)
234
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
252
+				foreach ($replacement as $key => $value) {
253
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
254
+				}
235 255
 
236 256
 				return implode(', ', $replacement);
257
+			} else {
258
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237 259
 			}
238
-			else
239
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240 260
 		break;
241 261
 
242 262
 		case 'date':
243
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
244
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
245
-			else
246
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
263
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
264
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
265
+			} else {
266
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
267
+			}
247 268
 		break;
248 269
 
249 270
 		case 'time':
250
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
251
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
252
-			else
253
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
271
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
272
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
273
+			} else {
274
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
275
+			}
254 276
 		break;
255 277
 
256 278
 		case 'float':
257
-			if (!is_numeric($replacement))
258
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
279
+			if (!is_numeric($replacement)) {
280
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
281
+			}
259 282
 			return (string) (float) $replacement;
260 283
 		break;
261 284
 
@@ -269,32 +292,37 @@  discard block
 block discarded – undo
269 292
 		break;
270 293
 
271 294
 		case 'inet':
272
-			if ($replacement == 'null' || $replacement == '')
273
-				return 'null';
274
-			if (!isValidIP($replacement))
275
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
295
+			if ($replacement == 'null' || $replacement == '') {
296
+							return 'null';
297
+			}
298
+			if (!isValidIP($replacement)) {
299
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
300
+			}
276 301
 			//we don't use the native support of mysql > 5.6.2
277 302
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
278 303
 
279 304
 		case 'array_inet':
280 305
 			if (is_array($replacement))
281 306
 			{
282
-				if (empty($replacement))
283
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
307
+				if (empty($replacement)) {
308
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
309
+				}
284 310
 
285 311
 				foreach ($replacement as $key => $value)
286 312
 				{
287
-					if ($replacement == 'null' || $replacement == '')
288
-						$replacement[$key] = 'null';
289
-					if (!isValidIP($value))
290
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
313
+					if ($replacement == 'null' || $replacement == '') {
314
+											$replacement[$key] = 'null';
315
+					}
316
+					if (!isValidIP($value)) {
317
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
318
+					}
291 319
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
292 320
 				}
293 321
 
294 322
 				return implode(', ', $replacement);
323
+			} else {
324
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
295 325
 			}
296
-			else
297
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
298 326
 		break;
299 327
 
300 328
 		default:
@@ -370,22 +398,25 @@  discard block
 block discarded – undo
370 398
 		// Are we in SSI mode?  If so try that username and password first
371 399
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
372 400
 		{
373
-			if (empty($db_persist))
374
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
375
-			else
376
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
401
+			if (empty($db_persist)) {
402
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
403
+			} else {
404
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
405
+			}
377 406
 		}
378 407
 		// Fall back to the regular username and password if need be
379 408
 		if (!$db_connection)
380 409
 		{
381
-			if (empty($db_persist))
382
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
383
-			else
384
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
410
+			if (empty($db_persist)) {
411
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
412
+			} else {
413
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
414
+			}
385 415
 		}
386 416
 
387
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
388
-			$db_connection = false;
417
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
418
+					$db_connection = false;
419
+		}
389 420
 
390 421
 		$connection = $db_connection;
391 422
 	}
@@ -393,18 +424,20 @@  discard block
 block discarded – undo
393 424
 	// One more query....
394 425
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
395 426
 
396
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
397
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
427
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
428
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
429
+	}
398 430
 
399 431
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
400 432
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
401 433
 	{
402 434
 		// Add before LIMIT
403
-		if ($pos = strpos($db_string, 'LIMIT '))
404
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
405
-		else
406
-			// Append it.
435
+		if ($pos = strpos($db_string, 'LIMIT ')) {
436
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
437
+		} else {
438
+					// Append it.
407 439
 			$db_string .= "\n\t\t\tORDER BY null";
440
+		}
408 441
 	}
409 442
 
410 443
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -426,8 +459,9 @@  discard block
 block discarded – undo
426 459
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
427 460
 
428 461
 		// Initialize $db_cache if not already initialized.
429
-		if (!isset($db_cache))
430
-			$db_cache = array();
462
+		if (!isset($db_cache)) {
463
+					$db_cache = array();
464
+		}
431 465
 
432 466
 		if (!empty($_SESSION['debug_redirect']))
433 467
 		{
@@ -453,17 +487,18 @@  discard block
 block discarded – undo
453 487
 		while (true)
454 488
 		{
455 489
 			$pos = strpos($db_string, '\'', $pos + 1);
456
-			if ($pos === false)
457
-				break;
490
+			if ($pos === false) {
491
+							break;
492
+			}
458 493
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
459 494
 
460 495
 			while (true)
461 496
 			{
462 497
 				$pos1 = strpos($db_string, '\'', $pos + 1);
463 498
 				$pos2 = strpos($db_string, '\\', $pos + 1);
464
-				if ($pos1 === false)
465
-					break;
466
-				elseif ($pos2 === false || $pos2 > $pos1)
499
+				if ($pos1 === false) {
500
+									break;
501
+				} elseif ($pos2 === false || $pos2 > $pos1)
467 502
 				{
468 503
 					$pos = $pos1;
469 504
 					break;
@@ -479,29 +514,35 @@  discard block
 block discarded – undo
479 514
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
480 515
 
481 516
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
482
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
483
-			$fail = true;
517
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
518
+					$fail = true;
519
+		}
484 520
 		// Trying to change passwords, slow us down, or something?
485
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
486
-			$fail = true;
487
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
488
-			$fail = true;
521
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
522
+					$fail = true;
523
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
524
+					$fail = true;
525
+		}
489 526
 
490
-		if (!empty($fail) && function_exists('log_error'))
491
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
527
+		if (!empty($fail) && function_exists('log_error')) {
528
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
529
+		}
492 530
 	}
493 531
 
494
-	if (empty($db_unbuffered))
495
-		$ret = @mysqli_query($connection, $db_string);
496
-	else
497
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
532
+	if (empty($db_unbuffered)) {
533
+			$ret = @mysqli_query($connection, $db_string);
534
+	} else {
535
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
536
+	}
498 537
 
499
-	if ($ret === false && empty($db_values['db_error_skip']))
500
-		$ret = smf_db_error($db_string, $connection);
538
+	if ($ret === false && empty($db_values['db_error_skip'])) {
539
+			$ret = smf_db_error($db_string, $connection);
540
+	}
501 541
 
502 542
 	// Debugging.
503
-	if (isset($db_show_debug) && $db_show_debug === true)
504
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
543
+	if (isset($db_show_debug) && $db_show_debug === true) {
544
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
545
+	}
505 546
 
506 547
 	return $ret;
507 548
 }
@@ -548,12 +589,13 @@  discard block
 block discarded – undo
548 589
 	// Decide which connection to use
549 590
 	$connection = $connection === null ? $db_connection : $connection;
550 591
 
551
-	if ($type == 'begin')
552
-		return @mysqli_query($connection, 'BEGIN');
553
-	elseif ($type == 'rollback')
554
-		return @mysqli_query($connection, 'ROLLBACK');
555
-	elseif ($type == 'commit')
556
-		return @mysqli_query($connection, 'COMMIT');
592
+	if ($type == 'begin') {
593
+			return @mysqli_query($connection, 'BEGIN');
594
+	} elseif ($type == 'rollback') {
595
+			return @mysqli_query($connection, 'ROLLBACK');
596
+	} elseif ($type == 'commit') {
597
+			return @mysqli_query($connection, 'COMMIT');
598
+	}
557 599
 
558 600
 	return false;
559 601
 }
@@ -593,8 +635,9 @@  discard block
 block discarded – undo
593 635
 	//    2013: Lost connection to server during query.
594 636
 
595 637
 	// Log the error.
596
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
597
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
638
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
639
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
640
+	}
598 641
 
599 642
 	// Database error auto fixing ;).
600 643
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -603,8 +646,9 @@  discard block
 block discarded – undo
603 646
 		$old_cache = @$modSettings['cache_enable'];
604 647
 		$modSettings['cache_enable'] = '1';
605 648
 
606
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
607
-			$db_last_error = max(@$db_last_error, $temp);
649
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
650
+					$db_last_error = max(@$db_last_error, $temp);
651
+		}
608 652
 
609 653
 		if (@$db_last_error < time() - 3600 * 24 * 3)
610 654
 		{
@@ -620,8 +664,9 @@  discard block
 block discarded – undo
620 664
 					foreach ($tables as $table)
621 665
 					{
622 666
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
623
-						if (trim($table) != '')
624
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
667
+						if (trim($table) != '') {
668
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
669
+						}
625 670
 					}
626 671
 				}
627 672
 
@@ -630,8 +675,9 @@  discard block
 block discarded – undo
630 675
 			// Table crashed.  Let's try to fix it.
631 676
 			elseif ($query_errno == 1016)
632 677
 			{
633
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
634
-					$fix_tables = array('`' . $match[1] . '`');
678
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
679
+									$fix_tables = array('`' . $match[1] . '`');
680
+				}
635 681
 			}
636 682
 			// Indexes crashed.  Should be easy to fix!
637 683
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -650,13 +696,15 @@  discard block
 block discarded – undo
650 696
 
651 697
 			// Make a note of the REPAIR...
652 698
 			cache_put_data('db_last_error', time(), 600);
653
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
654
-				updateSettingsFile(array('db_last_error' => time()));
699
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
700
+							updateSettingsFile(array('db_last_error' => time()));
701
+			}
655 702
 
656 703
 			// Attempt to find and repair the broken table.
657
-			foreach ($fix_tables as $table)
658
-				$smcFunc['db_query']('', "
704
+			foreach ($fix_tables as $table) {
705
+							$smcFunc['db_query']('', "
659 706
 					REPAIR TABLE $table", false, false);
707
+			}
660 708
 
661 709
 			// And send off an email!
662 710
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -665,11 +713,12 @@  discard block
 block discarded – undo
665 713
 
666 714
 			// Try the query again...?
667 715
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
668
-			if ($ret !== false)
669
-				return $ret;
716
+			if ($ret !== false) {
717
+							return $ret;
718
+			}
719
+		} else {
720
+					$modSettings['cache_enable'] = $old_cache;
670 721
 		}
671
-		else
672
-			$modSettings['cache_enable'] = $old_cache;
673 722
 
674 723
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
675 724
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -679,22 +728,25 @@  discard block
 block discarded – undo
679 728
 				// Are we in SSI mode?  If so try that username and password first
680 729
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
681 730
 				{
682
-					if (empty($db_persist))
683
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
684
-					else
685
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
731
+					if (empty($db_persist)) {
732
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
733
+					} else {
734
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
735
+					}
686 736
 				}
687 737
 				// Fall back to the regular username and password if need be
688 738
 				if (!$db_connection)
689 739
 				{
690
-					if (empty($db_persist))
691
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
692
-					else
693
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
740
+					if (empty($db_persist)) {
741
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
742
+					} else {
743
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
744
+					}
694 745
 				}
695 746
 
696
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
697
-					$db_connection = false;
747
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
748
+									$db_connection = false;
749
+				}
698 750
 			}
699 751
 
700 752
 			if ($db_connection)
@@ -705,24 +757,27 @@  discard block
 block discarded – undo
705 757
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
706 758
 
707 759
 					$new_errno = mysqli_errno($db_connection);
708
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
709
-						break;
760
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
761
+											break;
762
+					}
710 763
 				}
711 764
 
712 765
 				// If it failed again, shucks to be you... we're not trying it over and over.
713
-				if ($ret !== false)
714
-					return $ret;
766
+				if ($ret !== false) {
767
+									return $ret;
768
+				}
715 769
 			}
716 770
 		}
717 771
 		// Are they out of space, perhaps?
718 772
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
719 773
 		{
720
-			if (!isset($txt))
721
-				$query_error .= ' - check database storage space.';
722
-			else
774
+			if (!isset($txt)) {
775
+							$query_error .= ' - check database storage space.';
776
+			} else
723 777
 			{
724
-				if (!isset($txt['mysql_error_space']))
725
-					loadLanguage('Errors');
778
+				if (!isset($txt['mysql_error_space'])) {
779
+									loadLanguage('Errors');
780
+				}
726 781
 
727 782
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
728 783
 			}
@@ -730,15 +785,17 @@  discard block
 block discarded – undo
730 785
 	}
731 786
 
732 787
 	// Nothing's defined yet... just die with it.
733
-	if (empty($context) || empty($txt))
734
-		die($query_error);
788
+	if (empty($context) || empty($txt)) {
789
+			die($query_error);
790
+	}
735 791
 
736 792
 	// Show an error message, if possible.
737 793
 	$context['error_title'] = $txt['database_error'];
738
-	if (allowedTo('admin_forum'))
739
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
740
-	else
741
-		$context['error_message'] = $txt['try_again'];
794
+	if (allowedTo('admin_forum')) {
795
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
796
+	} else {
797
+			$context['error_message'] = $txt['try_again'];
798
+	}
742 799
 
743 800
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
744 801
 	{
@@ -768,25 +825,28 @@  discard block
 block discarded – undo
768 825
 	$connection = $connection === null ? $db_connection : $connection;
769 826
 
770 827
 	// With nothing to insert, simply return.
771
-	if (empty($data))
772
-		return;
828
+	if (empty($data)) {
829
+			return;
830
+	}
773 831
 
774 832
 	// Replace the prefix holder with the actual prefix.
775 833
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
776 834
 
777 835
 	// Inserting data as a single row can be done as a single array.
778
-	if (!is_array($data[array_rand($data)]))
779
-		$data = array($data);
836
+	if (!is_array($data[array_rand($data)])) {
837
+			$data = array($data);
838
+	}
780 839
 
781 840
 	// Create the mold for a single row insert.
782 841
 	$insertData = '(';
783 842
 	foreach ($columns as $columnName => $type)
784 843
 	{
785 844
 		// Are we restricting the length?
786
-		if (strpos($type, 'string-') !== false)
787
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
788
-		else
789
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
845
+		if (strpos($type, 'string-') !== false) {
846
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
847
+		} else {
848
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
849
+		}
790 850
 	}
791 851
 	$insertData = substr($insertData, 0, -2) . ')';
792 852
 
@@ -795,8 +855,9 @@  discard block
 block discarded – undo
795 855
 
796 856
 	// Here's where the variables are injected to the query.
797 857
 	$insertRows = array();
798
-	foreach ($data as $dataRow)
799
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
858
+	foreach ($data as $dataRow) {
859
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
860
+	}
800 861
 
801 862
 	// Determine the method of insertion.
802 863
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -816,15 +877,16 @@  discard block
 block discarded – undo
816 877
 	
817 878
 	if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
818 879
 	{
819
-		if ($returnmode == 1)
820
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
821
-		else if ($returnmode == 2)
880
+		if ($returnmode == 1) {
881
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
882
+		} else if ($returnmode == 2)
822 883
 		{
823 884
 			$return_var = array();
824 885
 			$count = count($insertRows);
825 886
 			$start = smf_db_insert_id($table, $keys[0]);
826
-			for ($i = 0; $i < $count; $i++ )
827
-				$return_var[] = $start + $i;
887
+			for ($i = 0; $i < $count; $i++ ) {
888
+							$return_var[] = $start + $i;
889
+			}
828 890
 		}
829 891
 		return $return_var;
830 892
 	}
@@ -842,8 +904,9 @@  discard block
 block discarded – undo
842 904
  */
843 905
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
844 906
 {
845
-	if (empty($log_message))
846
-		$log_message = $error_message;
907
+	if (empty($log_message)) {
908
+			$log_message = $error_message;
909
+	}
847 910
 
848 911
 	foreach (debug_backtrace() as $step)
849 912
 	{
@@ -862,12 +925,14 @@  discard block
 block discarded – undo
862 925
 	}
863 926
 
864 927
 	// A special case - we want the file and line numbers for debugging.
865
-	if ($error_type == 'return')
866
-		return array($file, $line);
928
+	if ($error_type == 'return') {
929
+			return array($file, $line);
930
+	}
867 931
 
868 932
 	// Is always a critical error.
869
-	if (function_exists('log_error'))
870
-		log_error($log_message, 'critical', $file, $line);
933
+	if (function_exists('log_error')) {
934
+			log_error($log_message, 'critical', $file, $line);
935
+	}
871 936
 
872 937
 	if (function_exists('fatal_error'))
873 938
 	{
@@ -875,12 +940,12 @@  discard block
 block discarded – undo
875 940
 
876 941
 		// Cannot continue...
877 942
 		exit;
943
+	} elseif ($error_type) {
944
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
945
+	} else {
946
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
947
+	}
878 948
 	}
879
-	elseif ($error_type)
880
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
881
-	else
882
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
883
-}
884 949
 
885 950
 /**
886 951
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -897,10 +962,11 @@  discard block
 block discarded – undo
897 962
 		'\\' => '\\\\',
898 963
 	);
899 964
 
900
-	if ($translate_human_wildcards)
901
-		$replacements += array(
965
+	if ($translate_human_wildcards) {
966
+			$replacements += array(
902 967
 			'*' => '%',
903 968
 		);
969
+	}
904 970
 
905 971
 	return strtr($string, $replacements);
906 972
 }
@@ -914,8 +980,9 @@  discard block
 block discarded – undo
914 980
  */
915 981
 function smf_is_resource($result)
916 982
 {
917
-	if ($result instanceof mysqli_result)
918
-		return true;
983
+	if ($result instanceof mysqli_result) {
984
+			return true;
985
+	}
919 986
 
920 987
 	return false;
921 988
 }
Please login to merge, or discard this patch.
Sources/minify/path-converter/src/Converter.php 2 patches
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -18,178 +18,178 @@
 block discarded – undo
18 18
  */
19 19
 class Converter
20 20
 {
21
-    /**
22
-     * @var string
23
-     */
24
-    protected $from;
25
-
26
-    /**
27
-     * @var string
28
-     */
29
-    protected $to;
30
-
31
-    /**
32
-     * @param string $from The original base path (directory, not file!)
33
-     * @param string $to   The new base path (directory, not file!)
34
-     */
35
-    public function __construct($from, $to)
36
-    {
37
-        $shared = $this->shared($from, $to);
38
-        if ($shared === '') {
39
-            // when both paths have nothing in common, one of them is probably
40
-            // absolute while the other is relative
41
-            $cwd = getcwd();
42
-            $from = strpos($from, $cwd) === 0 ? $from : $cwd.'/'.$from;
43
-            $to = strpos($to, $cwd) === 0 ? $to : $cwd.'/'.$to;
44
-
45
-            // or traveling the tree via `..`
46
-            // attempt to resolve path, or assume it's fine if it doesn't exist
47
-            $from = realpath($from) ?: $from;
48
-            $to = realpath($to) ?: $to;
49
-        }
50
-
51
-        $from = $this->dirname($from);
52
-        $to = $this->dirname($to);
53
-
54
-        $from = $this->normalize($from);
55
-        $to = $this->normalize($to);
56
-
57
-        $this->from = $from;
58
-        $this->to = $to;
59
-    }
60
-
61
-    /**
62
-     * Normalize path.
63
-     *
64
-     * @param string $path
65
-     *
66
-     * @return string
67
-     */
68
-    protected function normalize($path)
69
-    {
70
-        // deal with different operating systems' directory structure
71
-        $path = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $path), '/');
72
-
73
-        /*
21
+	/**
22
+	 * @var string
23
+	 */
24
+	protected $from;
25
+
26
+	/**
27
+	 * @var string
28
+	 */
29
+	protected $to;
30
+
31
+	/**
32
+	 * @param string $from The original base path (directory, not file!)
33
+	 * @param string $to   The new base path (directory, not file!)
34
+	 */
35
+	public function __construct($from, $to)
36
+	{
37
+		$shared = $this->shared($from, $to);
38
+		if ($shared === '') {
39
+			// when both paths have nothing in common, one of them is probably
40
+			// absolute while the other is relative
41
+			$cwd = getcwd();
42
+			$from = strpos($from, $cwd) === 0 ? $from : $cwd.'/'.$from;
43
+			$to = strpos($to, $cwd) === 0 ? $to : $cwd.'/'.$to;
44
+
45
+			// or traveling the tree via `..`
46
+			// attempt to resolve path, or assume it's fine if it doesn't exist
47
+			$from = realpath($from) ?: $from;
48
+			$to = realpath($to) ?: $to;
49
+		}
50
+
51
+		$from = $this->dirname($from);
52
+		$to = $this->dirname($to);
53
+
54
+		$from = $this->normalize($from);
55
+		$to = $this->normalize($to);
56
+
57
+		$this->from = $from;
58
+		$this->to = $to;
59
+	}
60
+
61
+	/**
62
+	 * Normalize path.
63
+	 *
64
+	 * @param string $path
65
+	 *
66
+	 * @return string
67
+	 */
68
+	protected function normalize($path)
69
+	{
70
+		// deal with different operating systems' directory structure
71
+		$path = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $path), '/');
72
+
73
+		/*
74 74
          * Example:
75 75
          *     /home/forkcms/frontend/cache/compiled_templates/../../core/layout/css/../images/img.gif
76 76
          * to
77 77
          *     /home/forkcms/frontend/core/layout/images/img.gif
78 78
          */
79
-        do {
80
-            $path = preg_replace('/[^\/]+(?<!\.\.)\/\.\.\//', '', $path, -1, $count);
81
-        } while ($count);
82
-
83
-        return $path;
84
-    }
85
-
86
-    /**
87
-     * Figure out the shared path of 2 locations.
88
-     *
89
-     * Example:
90
-     *     /home/forkcms/frontend/core/layout/images/img.gif
91
-     * and
92
-     *     /home/forkcms/frontend/cache/minified_css
93
-     * share
94
-     *     /home/forkcms/frontend
95
-     *
96
-     * @param string $path1
97
-     * @param string $path2
98
-     *
99
-     * @return string
100
-     */
101
-    protected function shared($path1, $path2)
102
-    {
103
-        // $path could theoretically be empty (e.g. no path is given), in which
104
-        // case it shouldn't expand to array(''), which would compare to one's
105
-        // root /
106
-        $path1 = $path1 ? explode('/', $path1) : array();
107
-        $path2 = $path2 ? explode('/', $path2) : array();
108
-
109
-        $shared = array();
110
-
111
-        // compare paths & strip identical ancestors
112
-        foreach ($path1 as $i => $chunk) {
113
-            if (isset($path2[$i]) && $path1[$i] == $path2[$i]) {
114
-                $shared[] = $chunk;
115
-            } else {
116
-                break;
117
-            }
118
-        }
119
-
120
-        return implode('/', $shared);
121
-    }
122
-
123
-    /**
124
-     * Convert paths relative from 1 file to another.
125
-     *
126
-     * E.g.
127
-     *     ../images/img.gif relative to /home/forkcms/frontend/core/layout/css
128
-     * should become:
129
-     *     ../../core/layout/images/img.gif relative to
130
-     *     /home/forkcms/frontend/cache/minified_css
131
-     *
132
-     * @param string $path The relative path that needs to be converted.
133
-     *
134
-     * @return string The new relative path.
135
-     */
136
-    public function convert($path)
137
-    {
138
-        // quit early if conversion makes no sense
139
-        if ($this->from === $this->to) {
140
-            return $path;
141
-        }
142
-
143
-        $path = $this->normalize($path);
144
-        // if we're not dealing with a relative path, just return absolute
145
-        if (strpos($path, '/') === 0) {
146
-            return $path;
147
-        }
148
-
149
-        // normalize paths
150
-        $path = $this->normalize($this->from.'/'.$path);
151
-
152
-        // strip shared ancestor paths
153
-        $shared = $this->shared($path, $this->to);
154
-        $path = mb_substr($path, mb_strlen($shared));
155
-        $to = mb_substr($this->to, mb_strlen($shared));
156
-
157
-        // add .. for every directory that needs to be traversed to new path
158
-        $to = str_repeat('../', mb_substr_count($to, '/'));
159
-
160
-        return $to.ltrim($path, '/');
161
-    }
162
-
163
-    /**
164
-     * Attempt to get the directory name from a path.
165
-     *
166
-     * @param string $path
167
-     *
168
-     * @return string
169
-     */
170
-    public function dirname($path)
171
-    {
172
-        if (is_file($path)) {
173
-            return dirname($path);
174
-        }
175
-
176
-        if (is_dir($path)) {
177
-            return rtrim($path, '/');
178
-        }
179
-
180
-        // no known file/dir, start making assumptions
181
-
182
-        // ends in / = dir
183
-        if (mb_substr($path, -1) === '/') {
184
-            return rtrim($path, '/');
185
-        }
186
-
187
-        // has a dot in the name, likely a file
188
-        if (preg_match('/.*\..*$/', basename($path)) !== 0) {
189
-            return dirname($path);
190
-        }
191
-
192
-        // you're on your own here!
193
-        return $path;
194
-    }
79
+		do {
80
+			$path = preg_replace('/[^\/]+(?<!\.\.)\/\.\.\//', '', $path, -1, $count);
81
+		} while ($count);
82
+
83
+		return $path;
84
+	}
85
+
86
+	/**
87
+	 * Figure out the shared path of 2 locations.
88
+	 *
89
+	 * Example:
90
+	 *     /home/forkcms/frontend/core/layout/images/img.gif
91
+	 * and
92
+	 *     /home/forkcms/frontend/cache/minified_css
93
+	 * share
94
+	 *     /home/forkcms/frontend
95
+	 *
96
+	 * @param string $path1
97
+	 * @param string $path2
98
+	 *
99
+	 * @return string
100
+	 */
101
+	protected function shared($path1, $path2)
102
+	{
103
+		// $path could theoretically be empty (e.g. no path is given), in which
104
+		// case it shouldn't expand to array(''), which would compare to one's
105
+		// root /
106
+		$path1 = $path1 ? explode('/', $path1) : array();
107
+		$path2 = $path2 ? explode('/', $path2) : array();
108
+
109
+		$shared = array();
110
+
111
+		// compare paths & strip identical ancestors
112
+		foreach ($path1 as $i => $chunk) {
113
+			if (isset($path2[$i]) && $path1[$i] == $path2[$i]) {
114
+				$shared[] = $chunk;
115
+			} else {
116
+				break;
117
+			}
118
+		}
119
+
120
+		return implode('/', $shared);
121
+	}
122
+
123
+	/**
124
+	 * Convert paths relative from 1 file to another.
125
+	 *
126
+	 * E.g.
127
+	 *     ../images/img.gif relative to /home/forkcms/frontend/core/layout/css
128
+	 * should become:
129
+	 *     ../../core/layout/images/img.gif relative to
130
+	 *     /home/forkcms/frontend/cache/minified_css
131
+	 *
132
+	 * @param string $path The relative path that needs to be converted.
133
+	 *
134
+	 * @return string The new relative path.
135
+	 */
136
+	public function convert($path)
137
+	{
138
+		// quit early if conversion makes no sense
139
+		if ($this->from === $this->to) {
140
+			return $path;
141
+		}
142
+
143
+		$path = $this->normalize($path);
144
+		// if we're not dealing with a relative path, just return absolute
145
+		if (strpos($path, '/') === 0) {
146
+			return $path;
147
+		}
148
+
149
+		// normalize paths
150
+		$path = $this->normalize($this->from.'/'.$path);
151
+
152
+		// strip shared ancestor paths
153
+		$shared = $this->shared($path, $this->to);
154
+		$path = mb_substr($path, mb_strlen($shared));
155
+		$to = mb_substr($this->to, mb_strlen($shared));
156
+
157
+		// add .. for every directory that needs to be traversed to new path
158
+		$to = str_repeat('../', mb_substr_count($to, '/'));
159
+
160
+		return $to.ltrim($path, '/');
161
+	}
162
+
163
+	/**
164
+	 * Attempt to get the directory name from a path.
165
+	 *
166
+	 * @param string $path
167
+	 *
168
+	 * @return string
169
+	 */
170
+	public function dirname($path)
171
+	{
172
+		if (is_file($path)) {
173
+			return dirname($path);
174
+		}
175
+
176
+		if (is_dir($path)) {
177
+			return rtrim($path, '/');
178
+		}
179
+
180
+		// no known file/dir, start making assumptions
181
+
182
+		// ends in / = dir
183
+		if (mb_substr($path, -1) === '/') {
184
+			return rtrim($path, '/');
185
+		}
186
+
187
+		// has a dot in the name, likely a file
188
+		if (preg_match('/.*\..*$/', basename($path)) !== 0) {
189
+			return dirname($path);
190
+		}
191
+
192
+		// you're on your own here!
193
+		return $path;
194
+	}
195 195
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
             // when both paths have nothing in common, one of them is probably
40 40
             // absolute while the other is relative
41 41
             $cwd = getcwd();
42
-            $from = strpos($from, $cwd) === 0 ? $from : $cwd.'/'.$from;
43
-            $to = strpos($to, $cwd) === 0 ? $to : $cwd.'/'.$to;
42
+            $from = strpos($from, $cwd) === 0 ? $from : $cwd . '/' . $from;
43
+            $to = strpos($to, $cwd) === 0 ? $to : $cwd . '/' . $to;
44 44
 
45 45
             // or traveling the tree via `..`
46 46
             // attempt to resolve path, or assume it's fine if it doesn't exist
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
         }
148 148
 
149 149
         // normalize paths
150
-        $path = $this->normalize($this->from.'/'.$path);
150
+        $path = $this->normalize($this->from . '/' . $path);
151 151
 
152 152
         // strip shared ancestor paths
153 153
         $shared = $this->shared($path, $this->to);
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
         // add .. for every directory that needs to be traversed to new path
158 158
         $to = str_repeat('../', mb_substr_count($to, '/'));
159 159
 
160
-        return $to.ltrim($path, '/');
160
+        return $to . ltrim($path, '/');
161 161
     }
162 162
 
163 163
     /**
Please login to merge, or discard this patch.