Completed
Pull Request — release-2.1 (#3836)
by Michael
10:56
created
Sources/ManageSmileys.php 1 patch
Braces   +297 added lines, -211 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 dispatcher of smileys administration.
@@ -91,8 +92,9 @@  discard block
 block discarded – undo
91 92
 	);
92 93
 
93 94
 	// Some settings may not be enabled, disallow these from the tabs as appropriate.
94
-	if (empty($modSettings['messageIcons_enable']))
95
-		$context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true;
95
+	if (empty($modSettings['messageIcons_enable'])) {
96
+			$context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true;
97
+	}
96 98
 	if (empty($modSettings['smiley_enable']))
97 99
 	{
98 100
 		$context[$context['admin_menu_name']]['tab_data']['tabs']['addsmiley']['disabled'] = true;
@@ -125,8 +127,9 @@  discard block
 block discarded – undo
125 127
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
126 128
 
127 129
 	$smiley_context = array();
128
-	foreach ($smiley_sets as $i => $set)
129
-		$smiley_context[$set] = $set_names[$i];
130
+	foreach ($smiley_sets as $i => $set) {
131
+			$smiley_context[$set] = $set_names[$i];
132
+	}
130 133
 
131 134
 	// All the settings for the page...
132 135
 	$config_vars = array(
@@ -147,8 +150,9 @@  discard block
 block discarded – undo
147 150
 
148 151
 	call_integration_hook('integrate_modify_smiley_settings', array(&$config_vars));
149 152
 
150
-	if ($return_config)
151
-		return $config_vars;
153
+	if ($return_config) {
154
+			return $config_vars;
155
+	}
152 156
 
153 157
 	// Setup the basics of the settings template.
154 158
 	require_once($sourcedir . '/ManageServer.php');
@@ -207,8 +211,9 @@  discard block
 block discarded – undo
207 211
 			foreach ($_POST['smiley_set'] as $id => $val)
208 212
 			{
209 213
 				// If this is the set you've marked as default, or the only one remaining, you can't delete it
210
-				if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id]))
211
-					unset($set_paths[$id], $set_names[$id]);
214
+				if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) {
215
+									unset($set_paths[$id], $set_names[$id]);
216
+				}
212 217
 			}
213 218
 
214 219
 			// Shortcut... array_merge() on a single array resets the numeric keys
@@ -222,8 +227,9 @@  discard block
 block discarded – undo
222 227
 			));
223 228
 		}
224 229
 		// Add a new smiley set.
225
-		elseif (!empty($_POST['add']))
226
-			$context['sub_action'] = 'modifyset';
230
+		elseif (!empty($_POST['add'])) {
231
+					$context['sub_action'] = 'modifyset';
232
+		}
227 233
 		// Create or modify a smiley set.
228 234
 		elseif (isset($_POST['set']))
229 235
 		{
@@ -233,8 +239,9 @@  discard block
 block discarded – undo
233 239
 			// Create a new smiley set.
234 240
 			if ($_POST['set'] == -1 && isset($_POST['smiley_sets_path']))
235 241
 			{
236
-				if (in_array($_POST['smiley_sets_path'], $set_paths))
237
-					fatal_lang_error('smiley_set_already_exists');
242
+				if (in_array($_POST['smiley_sets_path'], $set_paths)) {
243
+									fatal_lang_error('smiley_set_already_exists');
244
+				}
238 245
 
239 246
 				updateSettings(array(
240 247
 					'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $_POST['smiley_sets_path'],
@@ -246,12 +253,14 @@  discard block
 block discarded – undo
246 253
 			else
247 254
 			{
248 255
 				// Make sure the smiley set exists.
249
-				if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']]))
250
-					fatal_lang_error('smiley_set_not_found');
256
+				if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) {
257
+									fatal_lang_error('smiley_set_not_found');
258
+				}
251 259
 
252 260
 				// Make sure the path is not yet used by another smileyset.
253
-				if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']])
254
-					fatal_lang_error('smiley_set_path_already_used');
261
+				if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) {
262
+									fatal_lang_error('smiley_set_path_already_used');
263
+				}
255 264
 
256 265
 				$set_paths[$_POST['set']] = $_POST['smiley_sets_path'];
257 266
 				$set_names[$_POST['set']] = $_POST['smiley_sets_name'];
@@ -263,8 +272,9 @@  discard block
 block discarded – undo
263 272
 			}
264 273
 
265 274
 			// The user might have checked to also import smileys.
266
-			if (!empty($_POST['smiley_sets_import']))
267
-				ImportSmileys($_POST['smiley_sets_path']);
275
+			if (!empty($_POST['smiley_sets_import'])) {
276
+							ImportSmileys($_POST['smiley_sets_path']);
277
+			}
268 278
 		}
269 279
 		cache_put_data('parsing_smileys', null, 480);
270 280
 		cache_put_data('posting_smileys', null, 480);
@@ -273,13 +283,14 @@  discard block
 block discarded – undo
273 283
 	// Load all available smileysets...
274 284
 	$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
275 285
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
276
-	foreach ($context['smiley_sets'] as $i => $set)
277
-		$context['smiley_sets'][$i] = array(
286
+	foreach ($context['smiley_sets'] as $i => $set) {
287
+			$context['smiley_sets'][$i] = array(
278 288
 			'id' => $i,
279 289
 			'path' => $smcFunc['htmlspecialchars']($set),
280 290
 			'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
281 291
 			'selected' => $set == $modSettings['smiley_sets_default']
282 292
 		);
293
+	}
283 294
 
284 295
 	// Importing any smileys from an existing set?
285 296
 	if ($context['sub_action'] == 'import')
@@ -290,8 +301,9 @@  discard block
 block discarded – undo
290 301
 		$_GET['set'] = (int) $_GET['set'];
291 302
 
292 303
 		// Sanity check - then import.
293
-		if (isset($context['smiley_sets'][$_GET['set']]))
294
-			ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path']));
304
+		if (isset($context['smiley_sets'][$_GET['set']])) {
305
+					ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path']));
306
+		}
295 307
 
296 308
 		// Force the process to continue.
297 309
 		$context['sub_action'] = 'modifyset';
@@ -301,15 +313,15 @@  discard block
 block discarded – undo
301 313
 	if ($context['sub_action'] == 'modifyset')
302 314
 	{
303 315
 		$_GET['set'] = !isset($_GET['set']) ? -1 : (int) $_GET['set'];
304
-		if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']]))
305
-			$context['current_set'] = array(
316
+		if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) {
317
+					$context['current_set'] = array(
306 318
 				'id' => '-1',
307 319
 				'path' => '',
308 320
 				'name' => '',
309 321
 				'selected' => false,
310 322
 				'is_new' => true,
311 323
 			);
312
-		else
324
+		} else
313 325
 		{
314 326
 			$context['current_set'] = &$context['smiley_sets'][$_GET['set']];
315 327
 			$context['current_set']['is_new'] = false;
@@ -321,13 +333,15 @@  discard block
 block discarded – undo
321 333
 				$dir = dir($modSettings['smileys_dir'] . '/' . $context['current_set']['path']);
322 334
 				while ($entry = $dir->read())
323 335
 				{
324
-					if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
325
-						$smileys[strtolower($entry)] = $entry;
336
+					if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
337
+											$smileys[strtolower($entry)] = $entry;
338
+					}
326 339
 				}
327 340
 				$dir->close();
328 341
 
329
-				if (empty($smileys))
330
-					fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name']));
342
+				if (empty($smileys)) {
343
+									fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name']));
344
+				}
331 345
 
332 346
 				// Exclude the smileys that are already in the database.
333 347
 				$request = $smcFunc['db_query']('', '
@@ -338,9 +352,10 @@  discard block
 block discarded – undo
338 352
 						'smiley_list' => $smileys,
339 353
 					)
340 354
 				);
341
-				while ($row = $smcFunc['db_fetch_assoc']($request))
342
-					if (isset($smileys[strtolower($row['filename'])]))
355
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
356
+									if (isset($smileys[strtolower($row['filename'])]))
343 357
 						unset($smileys[strtolower($row['filename'])]);
358
+				}
344 359
 				$smcFunc['db_free_result']($request);
345 360
 
346 361
 				$context['current_set']['can_import'] = count($smileys);
@@ -355,13 +370,14 @@  discard block
 block discarded – undo
355 370
 			$dir = dir($modSettings['smileys_dir']);
356 371
 			while ($entry = $dir->read())
357 372
 			{
358
-				if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry))
359
-					$context['smiley_set_dirs'][] = array(
373
+				if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) {
374
+									$context['smiley_set_dirs'][] = array(
360 375
 						'id' => $entry,
361 376
 						'path' => $modSettings['smileys_dir'] . '/' . $entry,
362 377
 						'selectable' => $entry == $context['current_set']['path'] || !in_array($entry, explode(',', $modSettings['smiley_sets_known'])),
363 378
 						'current' => $entry == $context['current_set']['path'],
364 379
 					);
380
+				}
365 381
 			}
366 382
 			$dir->close();
367 383
 		}
@@ -371,8 +387,9 @@  discard block
 block discarded – undo
371 387
 	createToken('admin-mss', 'request');
372 388
 
373 389
 	// In case we need to import smileys, we need to add the token in now.
374
-	if (isset($context['current_set']['import_url']))
375
-		$context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token'];
390
+	if (isset($context['current_set']['import_url'])) {
391
+			$context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token'];
392
+	}
376 393
 
377 394
 	$listOptions = array(
378 395
 		'id' => 'smiley_set_list',
@@ -510,21 +527,23 @@  discard block
 block discarded – undo
510 527
 		$cols['name'][] = $set_names[$i];
511 528
 	}
512 529
 	$sort_flag = strpos($sort, 'DESC') === false ? SORT_ASC : SORT_DESC;
513
-	if (substr($sort, 0, 4) === 'name')
514
-		array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']);
515
-	elseif (substr($sort, 0, 4) === 'path')
516
-		array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']);
517
-	else
518
-		array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']);
530
+	if (substr($sort, 0, 4) === 'name') {
531
+			array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']);
532
+	} elseif (substr($sort, 0, 4) === 'path') {
533
+			array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']);
534
+	} else {
535
+			array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']);
536
+	}
519 537
 
520 538
 	$smiley_sets = array();
521
-	foreach ($cols['id'] as $i => $id)
522
-		$smiley_sets[] = array(
539
+	foreach ($cols['id'] as $i => $id) {
540
+			$smiley_sets[] = array(
523 541
 			'id' => $id,
524 542
 			'path' => $cols['path'][$i],
525 543
 			'name' => $cols['name'][$i],
526 544
 			'selected' => $cols['path'][$i] == $modSettings['smiley_sets_default']
527 545
 		);
546
+	}
528 547
 
529 548
 	return $smiley_sets;
530 549
 }
@@ -553,13 +572,14 @@  discard block
 block discarded – undo
553 572
 	$context['smileys_dir_found'] = is_dir($context['smileys_dir']);
554 573
 	$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
555 574
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
556
-	foreach ($context['smiley_sets'] as $i => $set)
557
-		$context['smiley_sets'][$i] = array(
575
+	foreach ($context['smiley_sets'] as $i => $set) {
576
+			$context['smiley_sets'][$i] = array(
558 577
 			'id' => $i,
559 578
 			'path' => $smcFunc['htmlspecialchars']($set),
560 579
 			'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
561 580
 			'selected' => $set == $modSettings['smiley_sets_default']
562 581
 		);
582
+	}
563 583
 
564 584
 	// Submitting a form?
565 585
 	if (isset($_POST[$context['session_var']], $_POST['smiley_code']))
@@ -575,8 +595,9 @@  discard block
 block discarded – undo
575 595
 		$_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']);
576 596
 
577 597
 		// Make sure some code was entered.
578
-		if (empty($_POST['smiley_code']))
579
-			fatal_lang_error('smiley_has_no_code');
598
+		if (empty($_POST['smiley_code'])) {
599
+					fatal_lang_error('smiley_has_no_code');
600
+		}
580 601
 
581 602
 		// Check whether the new code has duplicates. It should be unique.
582 603
 		$request = $smcFunc['db_query']('', '
@@ -588,8 +609,9 @@  discard block
 block discarded – undo
588 609
 				'smiley_code' => $_POST['smiley_code'],
589 610
 			)
590 611
 		);
591
-		if ($smcFunc['db_num_rows']($request) > 0)
592
-			fatal_lang_error('smiley_not_unique');
612
+		if ($smcFunc['db_num_rows']($request) > 0) {
613
+					fatal_lang_error('smiley_not_unique');
614
+		}
593 615
 		$smcFunc['db_free_result']($request);
594 616
 
595 617
 		// If we are uploading - check all the smiley sets are writable!
@@ -598,38 +620,44 @@  discard block
 block discarded – undo
598 620
 			$writeErrors = array();
599 621
 			foreach ($context['smiley_sets'] as $set)
600 622
 			{
601
-				if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path'])))
602
-					$writeErrors[] = $set['path'];
623
+				if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) {
624
+									$writeErrors[] = $set['path'];
625
+				}
626
+			}
627
+			if (!empty($writeErrors)) {
628
+							fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors)));
603 629
 			}
604
-			if (!empty($writeErrors))
605
-				fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors)));
606 630
 		}
607 631
 
608 632
 		// Uploading just one smiley for all of them?
609 633
 		if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '')
610 634
 		{
611
-			if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name'])))
612
-				fatal_lang_error('smileys_upload_error');
635
+			if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) {
636
+							fatal_lang_error('smileys_upload_error');
637
+			}
613 638
 
614 639
 			// Sorry, no spaces, dots, or anything else but letters allowed.
615 640
 			$_FILES['uploadSmiley']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['uploadSmiley']['name']);
616 641
 
617 642
 			// We only allow image files - it's THAT simple - no messing around here...
618
-			if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes))
619
-				fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
643
+			if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) {
644
+							fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
645
+			}
620 646
 
621 647
 			// We only need the filename...
622 648
 			$destName = basename($_FILES['uploadSmiley']['name']);
623 649
 
624 650
 			// Make sure they aren't trying to upload a nasty file - for their own good here!
625
-			if (in_array(strtolower($destName), $disabledFiles))
626
-				fatal_lang_error('smileys_upload_error_illegal');
651
+			if (in_array(strtolower($destName), $disabledFiles)) {
652
+							fatal_lang_error('smileys_upload_error_illegal');
653
+			}
627 654
 
628 655
 			// Check if the file already exists... and if not move it to EVERY smiley set directory.
629 656
 			$i = 0;
630 657
 			// Keep going until we find a set the file doesn't exist in. (or maybe it exists in all of them?)
631
-			while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName))
632
-				$i++;
658
+			while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) {
659
+							$i++;
660
+			}
633 661
 
634 662
 			// Okay, we're going to put the smiley right here, since it's not there yet!
635 663
 			if (isset($context['smiley_sets'][$i]['path']))
@@ -644,8 +672,9 @@  discard block
 block discarded – undo
644 672
 					$currentPath = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName;
645 673
 
646 674
 					// The file is already there!  Don't overwrite it!
647
-					if (file_exists($currentPath))
648
-						continue;
675
+					if (file_exists($currentPath)) {
676
+											continue;
677
+					}
649 678
 
650 679
 					// Okay, so copy the first one we made to here.
651 680
 					copy($smileyLocation, $currentPath);
@@ -662,13 +691,15 @@  discard block
 block discarded – undo
662 691
 			$newName = '';
663 692
 			foreach ($_FILES as $name => $data)
664 693
 			{
665
-				if ($_FILES[$name]['name'] == '')
666
-					fatal_lang_error('smileys_upload_error_blank');
694
+				if ($_FILES[$name]['name'] == '') {
695
+									fatal_lang_error('smileys_upload_error_blank');
696
+				}
667 697
 
668
-				if (empty($newName))
669
-					$newName = basename($_FILES[$name]['name']);
670
-				elseif (basename($_FILES[$name]['name']) != $newName)
671
-					fatal_lang_error('smileys_upload_error_name');
698
+				if (empty($newName)) {
699
+									$newName = basename($_FILES[$name]['name']);
700
+				} elseif (basename($_FILES[$name]['name']) != $newName) {
701
+									fatal_lang_error('smileys_upload_error_name');
702
+				}
672 703
 			}
673 704
 
674 705
 			foreach ($context['smiley_sets'] as $i => $set)
@@ -676,31 +707,36 @@  discard block
 block discarded – undo
676 707
 				$set['name'] = un_htmlspecialchars($set['name']);
677 708
 				$set['path'] = un_htmlspecialchars($set['path']);
678 709
 
679
-				if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '')
680
-					continue;
710
+				if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') {
711
+									continue;
712
+				}
681 713
 
682 714
 				// Got one...
683
-				if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name'])))
684
-					fatal_lang_error('smileys_upload_error');
715
+				if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) {
716
+									fatal_lang_error('smileys_upload_error');
717
+				}
685 718
 
686 719
 				// Sorry, no spaces, dots, or anything else but letters allowed.
687 720
 				$_FILES['individual_' . $set['name']]['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['individual_' . $set['name']]['name']);
688 721
 
689 722
 				// We only allow image files - it's THAT simple - no messing around here...
690
-				if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes))
691
-					fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
723
+				if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) {
724
+									fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
725
+				}
692 726
 
693 727
 				// We only need the filename...
694 728
 				$destName = basename($_FILES['individual_' . $set['name']]['name']);
695 729
 
696 730
 				// Make sure they aren't trying to upload a nasty file - for their own good here!
697
-				if (in_array(strtolower($destName), $disabledFiles))
698
-					fatal_lang_error('smileys_upload_error_illegal');
731
+				if (in_array(strtolower($destName), $disabledFiles)) {
732
+									fatal_lang_error('smileys_upload_error_illegal');
733
+				}
699 734
 
700 735
 				// If the file exists - ignore it.
701 736
 				$smileyLocation = $context['smileys_dir'] . '/' . $set['path'] . '/' . $destName;
702
-				if (file_exists($smileyLocation))
703
-					continue;
737
+				if (file_exists($smileyLocation)) {
738
+									continue;
739
+				}
704 740
 
705 741
 				// Finally - move the image!
706 742
 				move_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name'], $smileyLocation);
@@ -712,8 +748,9 @@  discard block
 block discarded – undo
712 748
 		}
713 749
 
714 750
 		// Also make sure a filename was given.
715
-		if (empty($_POST['smiley_filename']))
716
-			fatal_lang_error('smiley_has_no_filename');
751
+		if (empty($_POST['smiley_filename'])) {
752
+					fatal_lang_error('smiley_has_no_filename');
753
+		}
717 754
 
718 755
 		// Find the position on the right.
719 756
 		$smiley_order = '0';
@@ -732,8 +769,9 @@  discard block
 block discarded – undo
732 769
 			list ($smiley_order) = $smcFunc['db_fetch_row']($request);
733 770
 			$smcFunc['db_free_result']($request);
734 771
 
735
-			if (empty($smiley_order))
736
-				$smiley_order = '0';
772
+			if (empty($smiley_order)) {
773
+							$smiley_order = '0';
774
+			}
737 775
 		}
738 776
 		$smcFunc['db_insert']('',
739 777
 			'{db_prefix}smileys',
@@ -761,17 +799,19 @@  discard block
 block discarded – undo
761 799
 	{
762 800
 		foreach ($context['smiley_sets'] as $smiley_set)
763 801
 		{
764
-			if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])))
765
-				continue;
802
+			if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) {
803
+							continue;
804
+			}
766 805
 
767 806
 			$dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']));
768 807
 			while ($entry = $dir->read())
769 808
 			{
770
-				if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
771
-					$context['filenames'][strtolower($entry)] = array(
809
+				if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
810
+									$context['filenames'][strtolower($entry)] = array(
772 811
 						'id' => $smcFunc['htmlspecialchars']($entry),
773 812
 						'selected' => false,
774 813
 					);
814
+				}
775 815
 			}
776 816
 			$dir->close();
777 817
 		}
@@ -809,17 +849,19 @@  discard block
 block discarded – undo
809 849
 		// Changing the selected smileys?
810 850
 		if (isset($_POST['smiley_action']) && !empty($_POST['checked_smileys']))
811 851
 		{
812
-			foreach ($_POST['checked_smileys'] as $id => $smiley_id)
813
-				$_POST['checked_smileys'][$id] = (int) $smiley_id;
852
+			foreach ($_POST['checked_smileys'] as $id => $smiley_id) {
853
+							$_POST['checked_smileys'][$id] = (int) $smiley_id;
854
+			}
814 855
 
815
-			if ($_POST['smiley_action'] == 'delete')
816
-				$smcFunc['db_query']('', '
856
+			if ($_POST['smiley_action'] == 'delete') {
857
+							$smcFunc['db_query']('', '
817 858
 					DELETE FROM {db_prefix}smileys
818 859
 					WHERE id_smiley IN ({array_int:checked_smileys})',
819 860
 					array(
820 861
 						'checked_smileys' => $_POST['checked_smileys'],
821 862
 					)
822 863
 				);
864
+			}
823 865
 			// Changing the status of the smiley?
824 866
 			else
825 867
 			{
@@ -829,8 +871,8 @@  discard block
 block discarded – undo
829 871
 					'hidden' => 1,
830 872
 					'popup' => 2
831 873
 				);
832
-				if (isset($displayTypes[$_POST['smiley_action']]))
833
-					$smcFunc['db_query']('', '
874
+				if (isset($displayTypes[$_POST['smiley_action']])) {
875
+									$smcFunc['db_query']('', '
834 876
 						UPDATE {db_prefix}smileys
835 877
 						SET hidden = {int:display_type}
836 878
 						WHERE id_smiley IN ({array_int:checked_smileys})',
@@ -839,6 +881,7 @@  discard block
 block discarded – undo
839 881
 							'display_type' => $displayTypes[$_POST['smiley_action']],
840 882
 						)
841 883
 					);
884
+				}
842 885
 			}
843 886
 		}
844 887
 		// Create/modify a smiley.
@@ -864,12 +907,14 @@  discard block
 block discarded – undo
864 907
 				$_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location'];
865 908
 
866 909
 				// Make sure some code was entered.
867
-				if (empty($_POST['smiley_code']))
868
-					fatal_lang_error('smiley_has_no_code');
910
+				if (empty($_POST['smiley_code'])) {
911
+									fatal_lang_error('smiley_has_no_code');
912
+				}
869 913
 
870 914
 				// Also make sure a filename was given.
871
-				if (empty($_POST['smiley_filename']))
872
-					fatal_lang_error('smiley_has_no_filename');
915
+				if (empty($_POST['smiley_filename'])) {
916
+									fatal_lang_error('smiley_has_no_filename');
917
+				}
873 918
 
874 919
 				// Check whether the new code has duplicates. It should be unique.
875 920
 				$request = $smcFunc['db_query']('', '
@@ -883,8 +928,9 @@  discard block
 block discarded – undo
883 928
 						'smiley_code' => $_POST['smiley_code'],
884 929
 					)
885 930
 				);
886
-				if ($smcFunc['db_num_rows']($request) > 0)
887
-					fatal_lang_error('smiley_not_unique');
931
+				if ($smcFunc['db_num_rows']($request) > 0) {
932
+									fatal_lang_error('smiley_not_unique');
933
+				}
888 934
 				$smcFunc['db_free_result']($request);
889 935
 
890 936
 				$smcFunc['db_query']('', '
@@ -913,13 +959,14 @@  discard block
 block discarded – undo
913 959
 	// Load all known smiley sets.
914 960
 	$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
915 961
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
916
-	foreach ($context['smiley_sets'] as $i => $set)
917
-		$context['smiley_sets'][$i] = array(
962
+	foreach ($context['smiley_sets'] as $i => $set) {
963
+			$context['smiley_sets'][$i] = array(
918 964
 			'id' => $i,
919 965
 			'path' => $smcFunc['htmlspecialchars']($set),
920 966
 			'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
921 967
 			'selected' => $set == $modSettings['smiley_sets_default']
922 968
 		);
969
+	}
923 970
 
924 971
 	// Prepare overview of all (custom) smileys.
925 972
 	if ($context['sub_action'] == 'editsmileys')
@@ -935,9 +982,10 @@  discard block
 block discarded – undo
935 982
 		// Create a list of options for selecting smiley sets.
936 983
 		$smileyset_option_list = '
937 984
 			<select name="set" onchange="changeSet(this.options[this.selectedIndex].value);">';
938
-		foreach ($context['smiley_sets'] as $smiley_set)
939
-			$smileyset_option_list .= '
985
+		foreach ($context['smiley_sets'] as $smiley_set) {
986
+					$smileyset_option_list .= '
940 987
 				<option value="' . $smiley_set['path'] . '"' . ($modSettings['smiley_sets_default'] == $smiley_set['path'] ? ' selected' : '') . '>' . $smiley_set['name'] . '</option>';
988
+		}
941 989
 		$smileyset_option_list .= '
942 990
 			</select>';
943 991
 
@@ -999,12 +1047,13 @@  discard block
 block discarded – undo
999 1047
 					'data' => array(
1000 1048
 						'function' => function ($rowData) use ($txt)
1001 1049
 						{
1002
-							if (empty($rowData['hidden']))
1003
-								return $txt['smileys_location_form'];
1004
-							elseif ($rowData['hidden'] == 1)
1005
-								return $txt['smileys_location_hidden'];
1006
-							else
1007
-								return $txt['smileys_location_popup'];
1050
+							if (empty($rowData['hidden'])) {
1051
+															return $txt['smileys_location_form'];
1052
+							} elseif ($rowData['hidden'] == 1) {
1053
+															return $txt['smileys_location_hidden'];
1054
+							} else {
1055
+															return $txt['smileys_location_popup'];
1056
+							}
1008 1057
 						},
1009 1058
 					),
1010 1059
 					'sort' => array(
@@ -1019,19 +1068,22 @@  discard block
 block discarded – undo
1019 1068
 					'data' => array(
1020 1069
 						'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc)
1021 1070
 						{
1022
-							if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir']))
1023
-								return $smcFunc['htmlspecialchars']($rowData['description']);
1071
+							if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) {
1072
+															return $smcFunc['htmlspecialchars']($rowData['description']);
1073
+							}
1024 1074
 
1025 1075
 							// Check if there are smileys missing in some sets.
1026 1076
 							$missing_sets = array();
1027
-							foreach ($context['smiley_sets'] as $smiley_set)
1028
-								if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename'])))
1077
+							foreach ($context['smiley_sets'] as $smiley_set) {
1078
+															if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename'])))
1029 1079
 									$missing_sets[] = $smiley_set['path'];
1080
+							}
1030 1081
 
1031 1082
 							$description = $smcFunc['htmlspecialchars']($rowData['description']);
1032 1083
 
1033
-							if (!empty($missing_sets))
1034
-								$description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets));
1084
+							if (!empty($missing_sets)) {
1085
+															$description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets));
1086
+							}
1035 1087
 
1036 1088
 							return $description;
1037 1089
 						},
@@ -1147,13 +1199,14 @@  discard block
 block discarded – undo
1147 1199
 		$context['smileys_dir_found'] = is_dir($context['smileys_dir']);
1148 1200
 		$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
1149 1201
 		$set_names = explode("\n", $modSettings['smiley_sets_names']);
1150
-		foreach ($context['smiley_sets'] as $i => $set)
1151
-			$context['smiley_sets'][$i] = array(
1202
+		foreach ($context['smiley_sets'] as $i => $set) {
1203
+					$context['smiley_sets'][$i] = array(
1152 1204
 				'id' => $i,
1153 1205
 				'path' => $smcFunc['htmlspecialchars']($set),
1154 1206
 				'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
1155 1207
 				'selected' => $set == $modSettings['smiley_sets_default']
1156 1208
 			);
1209
+		}
1157 1210
 
1158 1211
 		$context['selected_set'] = $modSettings['smiley_sets_default'];
1159 1212
 
@@ -1163,17 +1216,19 @@  discard block
 block discarded – undo
1163 1216
 		{
1164 1217
 			foreach ($context['smiley_sets'] as $smiley_set)
1165 1218
 			{
1166
-				if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])))
1167
-					continue;
1219
+				if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) {
1220
+									continue;
1221
+				}
1168 1222
 
1169 1223
 				$dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']));
1170 1224
 				while ($entry = $dir->read())
1171 1225
 				{
1172
-					if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
1173
-						$context['filenames'][strtolower($entry)] = array(
1226
+					if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
1227
+											$context['filenames'][strtolower($entry)] = array(
1174 1228
 							'id' => $smcFunc['htmlspecialchars']($entry),
1175 1229
 							'selected' => false,
1176 1230
 						);
1231
+					}
1177 1232
 				}
1178 1233
 				$dir->close();
1179 1234
 			}
@@ -1188,8 +1243,9 @@  discard block
 block discarded – undo
1188 1243
 				'current_smiley' => (int) $_REQUEST['smiley'],
1189 1244
 			)
1190 1245
 		);
1191
-		if ($smcFunc['db_num_rows']($request) != 1)
1192
-			fatal_lang_error('smiley_not_found');
1246
+		if ($smcFunc['db_num_rows']($request) != 1) {
1247
+					fatal_lang_error('smiley_not_found');
1248
+		}
1193 1249
 		$context['current_smiley'] = $smcFunc['db_fetch_assoc']($request);
1194 1250
 		$smcFunc['db_free_result']($request);
1195 1251
 
@@ -1197,8 +1253,9 @@  discard block
 block discarded – undo
1197 1253
 		$context['current_smiley']['filename'] = $smcFunc['htmlspecialchars']($context['current_smiley']['filename']);
1198 1254
 		$context['current_smiley']['description'] = $smcFunc['htmlspecialchars']($context['current_smiley']['description']);
1199 1255
 
1200
-		if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])]))
1201
-			$context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true;
1256
+		if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) {
1257
+					$context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true;
1258
+		}
1202 1259
 	}
1203 1260
 }
1204 1261
 
@@ -1223,8 +1280,9 @@  discard block
 block discarded – undo
1223 1280
 		)
1224 1281
 	);
1225 1282
 	$smileys = array();
1226
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1227
-		$smileys[] = $row;
1283
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1284
+			$smileys[] = $row;
1285
+	}
1228 1286
 	$smcFunc['db_free_result']($request);
1229 1287
 
1230 1288
 	return $smileys;
@@ -1264,8 +1322,9 @@  discard block
 block discarded – undo
1264 1322
 		$_GET['location'] = empty($_GET['location']) || $_GET['location'] != 'popup' ? 0 : 2;
1265 1323
 		$_GET['source'] = empty($_GET['source']) ? 0 : (int) $_GET['source'];
1266 1324
 
1267
-		if (empty($_GET['source']))
1268
-			fatal_lang_error('smiley_not_found');
1325
+		if (empty($_GET['source'])) {
1326
+					fatal_lang_error('smiley_not_found');
1327
+		}
1269 1328
 
1270 1329
 		if (!empty($_GET['after']))
1271 1330
 		{
@@ -1281,12 +1340,12 @@  discard block
 block discarded – undo
1281 1340
 					'after_smiley' => $_GET['after'],
1282 1341
 				)
1283 1342
 			);
1284
-			if ($smcFunc['db_num_rows']($request) != 1)
1285
-				fatal_lang_error('smiley_not_found');
1343
+			if ($smcFunc['db_num_rows']($request) != 1) {
1344
+							fatal_lang_error('smiley_not_found');
1345
+			}
1286 1346
 			list ($smiley_row, $smiley_order, $smileyLocation) = $smcFunc['db_fetch_row']($request);
1287 1347
 			$smcFunc['db_free_result']($request);
1288
-		}
1289
-		else
1348
+		} else
1290 1349
 		{
1291 1350
 			$smiley_row = (int) $_GET['row'];
1292 1351
 			$smiley_order = -1;
@@ -1360,14 +1419,15 @@  discard block
 block discarded – undo
1360 1419
 	$context['move_smiley'] = empty($_REQUEST['move']) ? 0 : (int) $_REQUEST['move'];
1361 1420
 
1362 1421
 	// Make sure all rows are sequential.
1363
-	foreach (array_keys($context['smileys']) as $location)
1364
-		$context['smileys'][$location] = array(
1422
+	foreach (array_keys($context['smileys']) as $location) {
1423
+			$context['smileys'][$location] = array(
1365 1424
 			'id' => $location,
1366 1425
 			'title' => $location == 'postform' ? $txt['smileys_location_form'] : $txt['smileys_location_popup'],
1367 1426
 			'description' => $location == 'postform' ? $txt['smileys_location_form_description'] : $txt['smileys_location_popup_description'],
1368 1427
 			'last_row' => count($context['smileys'][$location]['rows']),
1369 1428
 			'rows' => array_values($context['smileys'][$location]['rows']),
1370 1429
 		);
1430
+	}
1371 1431
 
1372 1432
 	// Check & fix smileys that are not ordered properly in the database.
1373 1433
 	foreach (array_keys($context['smileys']) as $location)
@@ -1392,8 +1452,8 @@  discard block
 block discarded – undo
1392 1452
 				$context['smileys'][$location]['rows'][$id][0]['row'] = $id;
1393 1453
 			}
1394 1454
 			// Make sure the smiley order is always sequential.
1395
-			foreach ($smiley_row as $order_id => $smiley)
1396
-				if ($order_id != $smiley['order'])
1455
+			foreach ($smiley_row as $order_id => $smiley) {
1456
+							if ($order_id != $smiley['order'])
1397 1457
 					$smcFunc['db_query']('', '
1398 1458
 						UPDATE {db_prefix}smileys
1399 1459
 						SET smiley_order = {int:new_order}
@@ -1403,6 +1463,7 @@  discard block
 block discarded – undo
1403 1463
 							'current_smiley' => $smiley['id'],
1404 1464
 						)
1405 1465
 					);
1466
+			}
1406 1467
 		}
1407 1468
 	}
1408 1469
 
@@ -1435,19 +1496,20 @@  discard block
 block discarded – undo
1435 1496
 		$context['filename'] = $base_name;
1436 1497
 
1437 1498
 		// Check that the smiley is from simplemachines.org, for now... maybe add mirroring later.
1438
-		if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false)
1439
-			fatal_lang_error('not_on_simplemachines');
1499
+		if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) {
1500
+					fatal_lang_error('not_on_simplemachines');
1501
+		}
1440 1502
 
1441 1503
 		$destination = $packagesdir . '/' . $base_name;
1442 1504
 
1443
-		if (file_exists($destination))
1444
-			fatal_lang_error('package_upload_error_exists');
1505
+		if (file_exists($destination)) {
1506
+					fatal_lang_error('package_upload_error_exists');
1507
+		}
1445 1508
 
1446 1509
 		// Let's copy it to the Packages directory
1447 1510
 		file_put_contents($destination, fetch_web_data($_REQUEST['set_gz']));
1448 1511
 		$testing = true;
1449
-	}
1450
-	elseif (isset($_REQUEST['package']))
1512
+	} elseif (isset($_REQUEST['package']))
1451 1513
 	{
1452 1514
 		$base_name = basename($_REQUEST['package']);
1453 1515
 		$name = $smcFunc['htmlspecialchars'](strtok(basename($_REQUEST['package']), '.'));
@@ -1456,12 +1518,14 @@  discard block
 block discarded – undo
1456 1518
 		$destination = $packagesdir . '/' . basename($_REQUEST['package']);
1457 1519
 	}
1458 1520
 
1459
-	if (empty($destination) || !file_exists($destination))
1460
-		fatal_lang_error('package_no_file', false);
1521
+	if (empty($destination) || !file_exists($destination)) {
1522
+			fatal_lang_error('package_no_file', false);
1523
+	}
1461 1524
 
1462 1525
 	// Make sure temp directory exists and is empty.
1463
-	if (file_exists($packagesdir . '/temp'))
1464
-		deltree($packagesdir . '/temp', false);
1526
+	if (file_exists($packagesdir . '/temp')) {
1527
+			deltree($packagesdir . '/temp', false);
1528
+	}
1465 1529
 
1466 1530
 	if (!mktree($packagesdir . '/temp', 0755))
1467 1531
 	{
@@ -1473,31 +1537,37 @@  discard block
 block discarded – undo
1473 1537
 			create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=smileys;sa=install;set_gz=' . $_REQUEST['set_gz'], 'crash_on_error' => true));
1474 1538
 
1475 1539
 			deltree($packagesdir . '/temp', false);
1476
-			if (!mktree($packagesdir . '/temp', 0777))
1477
-				fatal_lang_error('package_cant_download', false);
1540
+			if (!mktree($packagesdir . '/temp', 0777)) {
1541
+							fatal_lang_error('package_cant_download', false);
1542
+			}
1478 1543
 		}
1479 1544
 	}
1480 1545
 
1481 1546
 	$extracted = read_tgz_file($destination, $packagesdir . '/temp');
1482
-	if (!$extracted)
1483
-		fatal_lang_error('packageget_unable', false, array('http://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name));
1484
-	if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml'))
1485
-		foreach ($extracted as $file)
1547
+	if (!$extracted) {
1548
+			fatal_lang_error('packageget_unable', false, array('http://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name));
1549
+	}
1550
+	if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) {
1551
+			foreach ($extracted as $file)
1486 1552
 			if (basename($file['filename']) == 'package-info.xml')
1487 1553
 			{
1488 1554
 				$base_path = dirname($file['filename']) . '/';
1555
+	}
1489 1556
 				break;
1490 1557
 			}
1491 1558
 
1492
-	if (!isset($base_path))
1493
-		$base_path = '';
1559
+	if (!isset($base_path)) {
1560
+			$base_path = '';
1561
+	}
1494 1562
 
1495
-	if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml'))
1496
-		fatal_lang_error('package_get_error_missing_xml', false);
1563
+	if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) {
1564
+			fatal_lang_error('package_get_error_missing_xml', false);
1565
+	}
1497 1566
 
1498 1567
 	$smileyInfo = getPackageInfo($context['filename']);
1499
-	if (!is_array($smileyInfo))
1500
-		fatal_lang_error($smileyInfo);
1568
+	if (!is_array($smileyInfo)) {
1569
+			fatal_lang_error($smileyInfo);
1570
+	}
1501 1571
 
1502 1572
 	// See if it is installed?
1503 1573
 	$request = $smcFunc['db_query']('', '
@@ -1513,8 +1583,9 @@  discard block
 block discarded – undo
1513 1583
 		)
1514 1584
 	);
1515 1585
 
1516
-	if ($smcFunc['db_num_rows']($request) > 0)
1517
-		fata_lang_error('package_installed_warning1');
1586
+	if ($smcFunc['db_num_rows']($request) > 0) {
1587
+			fata_lang_error('package_installed_warning1');
1588
+	}
1518 1589
 
1519 1590
 	// Everything is fine, now it's time to do something
1520 1591
 	$actions = parsePackageInfo($smileyInfo['xml'], true, 'install');
@@ -1531,23 +1602,23 @@  discard block
 block discarded – undo
1531 1602
 		{
1532 1603
 			$has_readme = true;
1533 1604
 			$type = 'package_' . $action['type'];
1534
-			if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename']))
1535
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r"));
1536
-			elseif (file_exists($action['filename']))
1537
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
1605
+			if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) {
1606
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r"));
1607
+			} elseif (file_exists($action['filename'])) {
1608
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
1609
+			}
1538 1610
 
1539 1611
 			if (!empty($action['parse_bbc']))
1540 1612
 			{
1541 1613
 				require_once($sourcedir . '/Subs-Post.php');
1542 1614
 				preparsecode($context[$type]);
1543 1615
 				$context[$type] = parse_bbc($context[$type]);
1616
+			} else {
1617
+							$context[$type] = nl2br($context[$type]);
1544 1618
 			}
1545
-			else
1546
-				$context[$type] = nl2br($context[$type]);
1547 1619
 
1548 1620
 			continue;
1549
-		}
1550
-		elseif ($action['type'] == 'require-dir')
1621
+		} elseif ($action['type'] == 'require-dir')
1551 1622
 		{
1552 1623
 			// Do this one...
1553 1624
 			$thisAction = array(
@@ -1566,12 +1637,12 @@  discard block
 block discarded – undo
1566 1637
 				);
1567 1638
 			}
1568 1639
 			// @todo None given?
1569
-			if (empty($thisAction['description']))
1570
-				$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
1640
+			if (empty($thisAction['description'])) {
1641
+							$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
1642
+			}
1571 1643
 
1572 1644
 			$context['actions'][] = $thisAction;
1573
-		}
1574
-		elseif ($action['type'] == 'credits')
1645
+		} elseif ($action['type'] == 'credits')
1575 1646
 		{
1576 1647
 			// Time to build the billboard
1577 1648
 			$credits_tag = array(
@@ -1630,12 +1701,14 @@  discard block
 block discarded – undo
1630 1701
 		cache_put_data('posting_smileys', null, 480);
1631 1702
 	}
1632 1703
 
1633
-	if (file_exists($packagesdir . '/temp'))
1634
-		deltree($packagesdir . '/temp');
1704
+	if (file_exists($packagesdir . '/temp')) {
1705
+			deltree($packagesdir . '/temp');
1706
+	}
1635 1707
 
1636
-	if (!$testing)
1637
-		redirectexit('action=admin;area=smileys');
1638
-}
1708
+	if (!$testing) {
1709
+			redirectexit('action=admin;area=smileys');
1710
+	}
1711
+	}
1639 1712
 
1640 1713
 /**
1641 1714
  * A function to import new smileys from an existing directory into the database.
@@ -1646,15 +1719,17 @@  discard block
 block discarded – undo
1646 1719
 {
1647 1720
 	global $modSettings, $smcFunc;
1648 1721
 
1649
-	if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath))
1650
-		fatal_lang_error('smiley_set_unable_to_import');
1722
+	if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) {
1723
+			fatal_lang_error('smiley_set_unable_to_import');
1724
+	}
1651 1725
 
1652 1726
 	$smileys = array();
1653 1727
 	$dir = dir($modSettings['smileys_dir'] . '/' . $smileyPath);
1654 1728
 	while ($entry = $dir->read())
1655 1729
 	{
1656
-		if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
1657
-			$smileys[strtolower($entry)] = $entry;
1730
+		if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
1731
+					$smileys[strtolower($entry)] = $entry;
1732
+		}
1658 1733
 	}
1659 1734
 	$dir->close();
1660 1735
 
@@ -1667,9 +1742,10 @@  discard block
 block discarded – undo
1667 1742
 			'smiley_list' => $smileys,
1668 1743
 		)
1669 1744
 	);
1670
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1671
-		if (isset($smileys[strtolower($row['filename'])]))
1745
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1746
+			if (isset($smileys[strtolower($row['filename'])]))
1672 1747
 			unset($smileys[strtolower($row['filename'])]);
1748
+	}
1673 1749
 	$smcFunc['db_free_result']($request);
1674 1750
 
1675 1751
 	$request = $smcFunc['db_query']('', '
@@ -1686,9 +1762,10 @@  discard block
 block discarded – undo
1686 1762
 	$smcFunc['db_free_result']($request);
1687 1763
 
1688 1764
 	$new_smileys = array();
1689
-	foreach ($smileys as $smiley)
1690
-		if (strlen($smiley) <= 48)
1765
+	foreach ($smileys as $smiley) {
1766
+			if (strlen($smiley) <= 48)
1691 1767
 			$new_smileys[] = array(':' . strtok($smiley, '.') . ':', $smiley, strtok($smiley, '.'), 0, ++$smiley_order);
1768
+	}
1692 1769
 
1693 1770
 	if (!empty($new_smileys))
1694 1771
 	{
@@ -1753,8 +1830,9 @@  discard block
 block discarded – undo
1753 1830
 		if (isset($_POST['delete']) && !empty($_POST['checked_icons']))
1754 1831
 		{
1755 1832
 			$deleteIcons = array();
1756
-			foreach ($_POST['checked_icons'] as $icon)
1757
-				$deleteIcons[] = (int) $icon;
1833
+			foreach ($_POST['checked_icons'] as $icon) {
1834
+							$deleteIcons[] = (int) $icon;
1835
+			}
1758 1836
 
1759 1837
 			// Do the actual delete!
1760 1838
 			$smcFunc['db_query']('', '
@@ -1771,35 +1849,41 @@  discard block
 block discarded – undo
1771 1849
 			$_GET['icon'] = (int) $_GET['icon'];
1772 1850
 
1773 1851
 			// Do some preperation with the data... like check the icon exists *somewhere*
1774
-			if (strpos($_POST['icon_filename'], '.png') !== false)
1775
-				$_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4);
1776
-			if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png'))
1777
-				fatal_lang_error('icon_not_found');
1852
+			if (strpos($_POST['icon_filename'], '.png') !== false) {
1853
+							$_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4);
1854
+			}
1855
+			if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) {
1856
+							fatal_lang_error('icon_not_found');
1857
+			}
1778 1858
 			// There is a 16 character limit on message icons...
1779
-			elseif (strlen($_POST['icon_filename']) > 16)
1780
-				fatal_lang_error('icon_name_too_long');
1781
-			elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon']))
1782
-				fatal_lang_error('icon_after_itself');
1859
+			elseif (strlen($_POST['icon_filename']) > 16) {
1860
+							fatal_lang_error('icon_name_too_long');
1861
+			} elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) {
1862
+							fatal_lang_error('icon_after_itself');
1863
+			}
1783 1864
 
1784 1865
 			// First do the sorting... if this is an edit reduce the order of everything after it by one ;)
1785 1866
 			if ($_GET['icon'] != 0)
1786 1867
 			{
1787 1868
 				$oldOrder = $context['icons'][$_GET['icon']]['true_order'];
1788
-				foreach ($context['icons'] as $id => $data)
1789
-					if ($data['true_order'] > $oldOrder)
1869
+				foreach ($context['icons'] as $id => $data) {
1870
+									if ($data['true_order'] > $oldOrder)
1790 1871
 						$context['icons'][$id]['true_order']--;
1872
+				}
1791 1873
 			}
1792 1874
 
1793 1875
 			// If there are no existing icons and this is a new one, set the id to 1 (mainly for non-mysql)
1794
-			if (empty($_GET['icon']) && empty($context['icons']))
1795
-				$_GET['icon'] = 1;
1876
+			if (empty($_GET['icon']) && empty($context['icons'])) {
1877
+							$_GET['icon'] = 1;
1878
+			}
1796 1879
 
1797 1880
 			// Get the new order.
1798 1881
 			$newOrder = $_POST['icon_location'] == 0 ? 0 : $context['icons'][$_POST['icon_location']]['true_order'] + 1;
1799 1882
 			// Do the same, but with the one that used to be after this icon, done to avoid conflict.
1800
-			foreach ($context['icons'] as $id => $data)
1801
-				if ($data['true_order'] >= $newOrder)
1883
+			foreach ($context['icons'] as $id => $data) {
1884
+							if ($data['true_order'] >= $newOrder)
1802 1885
 					$context['icons'][$id]['true_order']++;
1886
+			}
1803 1887
 
1804 1888
 			// Finally set the current icon's position!
1805 1889
 			$context['icons'][$_GET['icon']]['true_order'] = $newOrder;
@@ -1817,8 +1901,7 @@  discard block
 block discarded – undo
1817 1901
 				if ($id != 0)
1818 1902
 				{
1819 1903
 					$iconInsert[] = array($id, $icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']);
1820
-				}
1821
-				else
1904
+				} else
1822 1905
 				{
1823 1906
 					$iconInsert_new[] = array($icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']);
1824 1907
 				}
@@ -1843,8 +1926,9 @@  discard block
 block discarded – undo
1843 1926
 		}
1844 1927
 
1845 1928
 		// Unless we're adding a new thing, we'll escape
1846
-		if (!isset($_POST['add']))
1847
-			redirectexit('action=admin;area=smileys;sa=editicons');
1929
+		if (!isset($_POST['add'])) {
1930
+					redirectexit('action=admin;area=smileys;sa=editicons');
1931
+		}
1848 1932
 	}
1849 1933
 
1850 1934
 	$context[$context['admin_menu_name']]['current_subsection'] = 'editicons';
@@ -1954,8 +2038,9 @@  discard block
 block discarded – undo
1954 2038
 		$context['new_icon'] = !isset($_GET['icon']);
1955 2039
 
1956 2040
 		// Get the properties of the current icon from the icon list.
1957
-		if (!$context['new_icon'])
1958
-			$context['icon'] = $context['icons'][$_GET['icon']];
2041
+		if (!$context['new_icon']) {
2042
+					$context['icon'] = $context['icons'][$_GET['icon']];
2043
+		}
1959 2044
 
1960 2045
 		// Get a list of boards needed for assigning this icon to a specific board.
1961 2046
 		$boardListOptions = array(
@@ -1989,8 +2074,9 @@  discard block
 block discarded – undo
1989 2074
 	);
1990 2075
 
1991 2076
 	$message_icons = array();
1992
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1993
-		$message_icons[] = $row;
2077
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2078
+			$message_icons[] = $row;
2079
+	}
1994 2080
 	$smcFunc['db_free_result']($request);
1995 2081
 
1996 2082
 	return $message_icons;
Please login to merge, or discard this patch.
Sources/DbPackages-mysql.php 1 patch
Braces   +124 added lines, -99 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
  * Add the file functions to the $smcFunc array.
@@ -52,8 +53,9 @@  discard block
 block discarded – undo
52 53
 		'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages',
53 54
 		'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys',
54 55
 		'themes', 'topics');
55
-	foreach ($reservedTables as $k => $table_name)
56
-		$reservedTables[$k] = strtolower($db_prefix . $table_name);
56
+	foreach ($reservedTables as $k => $table_name) {
57
+			$reservedTables[$k] = strtolower($db_prefix . $table_name);
58
+	}
57 59
 
58 60
 	// We in turn may need the extra stuff.
59 61
 	db_extend('extra');
@@ -105,8 +107,9 @@  discard block
 block discarded – undo
105 107
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
106 108
 
107 109
 	// First - no way do we touch SMF tables.
108
-	if (in_array(strtolower($table_name), $reservedTables))
109
-		return false;
110
+	if (in_array(strtolower($table_name), $reservedTables)) {
111
+			return false;
112
+	}
110 113
 
111 114
 	// Log that we'll want to remove this on uninstall.
112 115
 	$db_package_log[] = array('remove_table', $table_name);
@@ -116,16 +119,18 @@  discard block
 block discarded – undo
116 119
 	if (in_array($full_table_name, $tables))
117 120
 	{
118 121
 		// This is a sad day... drop the table? If not, return false (error) by default.
119
-		if ($if_exists == 'overwrite')
120
-			$smcFunc['db_drop_table']($table_name);
121
-		else
122
-			return $if_exists == 'ignore';
122
+		if ($if_exists == 'overwrite') {
123
+					$smcFunc['db_drop_table']($table_name);
124
+		} else {
125
+					return $if_exists == 'ignore';
126
+		}
123 127
 	}
124 128
 
125 129
 	// Righty - let's do the damn thing!
126 130
 	$table_query = 'CREATE TABLE ' . $table_name . "\n" . '(';
127
-	foreach ($columns as $column)
128
-		$table_query .= "\n\t" . smf_db_create_query_column($column) . ',';
131
+	foreach ($columns as $column) {
132
+			$table_query .= "\n\t" . smf_db_create_query_column($column) . ',';
133
+	}
129 134
 
130 135
 	// Loop through the indexes next...
131 136
 	foreach ($indexes as $index)
@@ -133,19 +138,21 @@  discard block
 block discarded – undo
133 138
 		$columns = implode(',', $index['columns']);
134 139
 
135 140
 		// Is it the primary?
136
-		if (isset($index['type']) && $index['type'] == 'primary')
137
-			$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
138
-		else
141
+		if (isset($index['type']) && $index['type'] == 'primary') {
142
+					$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
143
+		} else
139 144
 		{
140
-			if (empty($index['name']))
141
-				$index['name'] = implode('_', $index['columns']);
145
+			if (empty($index['name'])) {
146
+							$index['name'] = implode('_', $index['columns']);
147
+			}
142 148
 			$table_query .= "\n\t" . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : 'KEY') . ' ' . $index['name'] . ' (' . $columns . '),';
143 149
 		}
144 150
 	}
145 151
 
146 152
 	// No trailing commas!
147
-	if (substr($table_query, -1) == ',')
148
-		$table_query = substr($table_query, 0, -1);
153
+	if (substr($table_query, -1) == ',') {
154
+			$table_query = substr($table_query, 0, -1);
155
+	}
149 156
 
150 157
 	// Which engine do we want here?
151 158
 	if (empty($engines))
@@ -155,8 +162,9 @@  discard block
 block discarded – undo
155 162
 
156 163
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
157 164
 		{
158
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
159
-				$engines[] = $row['Engine'];
165
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
166
+							$engines[] = $row['Engine'];
167
+			}
160 168
 		}
161 169
 
162 170
 		$smcFunc['db_free_result']($get_engines);
@@ -170,8 +178,9 @@  discard block
 block discarded – undo
170 178
 	}
171 179
 
172 180
 	$table_query .= ') ENGINE=' . $parameters['engine'];
173
-	if (!empty($db_character_set) && $db_character_set == 'utf8')
174
-		$table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
181
+	if (!empty($db_character_set) && $db_character_set == 'utf8') {
182
+			$table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
183
+	}
175 184
 
176 185
 	// Create the table!
177 186
 	$smcFunc['db_query']('', $table_query,
@@ -203,8 +212,9 @@  discard block
 block discarded – undo
203 212
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
204 213
 
205 214
 	// God no - dropping one of these = bad.
206
-	if (in_array(strtolower($table_name), $reservedTables))
207
-		return false;
215
+	if (in_array(strtolower($table_name), $reservedTables)) {
216
+			return false;
217
+	}
208 218
 
209 219
 	// Does it exist?
210 220
 	if (in_array($full_table_name, $smcFunc['db_list_tables']()))
@@ -245,14 +255,16 @@  discard block
 block discarded – undo
245 255
 
246 256
 	// Does it exist - if so don't add it again!
247 257
 	$columns = $smcFunc['db_list_columns']($table_name, false);
248
-	foreach ($columns as $column)
249
-		if ($column == $column_info['name'])
258
+	foreach ($columns as $column) {
259
+			if ($column == $column_info['name'])
250 260
 		{
251 261
 			// If we're going to overwrite then use change column.
252 262
 			if ($if_exists == 'update')
253 263
 				return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
254
-			else
255
-				return false;
264
+	}
265
+			else {
266
+							return false;
267
+			}
256 268
 		}
257 269
 
258 270
 	// Get the specifics...
@@ -288,8 +300,8 @@  discard block
 block discarded – undo
288 300
 
289 301
 	// Does it exist?
290 302
 	$columns = $smcFunc['db_list_columns']($table_name, true);
291
-	foreach ($columns as $column)
292
-		if ($column['name'] == $column_name)
303
+	foreach ($columns as $column) {
304
+			if ($column['name'] == $column_name)
293 305
 		{
294 306
 			$smcFunc['db_query']('', '
295 307
 				ALTER TABLE ' . $table_name . '
@@ -298,6 +310,7 @@  discard block
 block discarded – undo
298 310
 					'security_override' => true,
299 311
 				)
300 312
 			);
313
+	}
301 314
 
302 315
 			return true;
303 316
 		}
@@ -324,37 +337,47 @@  discard block
 block discarded – undo
324 337
 	// Check it does exist!
325 338
 	$columns = $smcFunc['db_list_columns']($table_name, true);
326 339
 	$old_info = null;
327
-	foreach ($columns as $column)
328
-		if ($column['name'] == $old_column)
340
+	foreach ($columns as $column) {
341
+			if ($column['name'] == $old_column)
329 342
 			$old_info = $column;
343
+	}
330 344
 
331 345
 	// Nothing?
332
-	if ($old_info == null)
333
-		return false;
346
+	if ($old_info == null) {
347
+			return false;
348
+	}
334 349
 
335 350
 	// Get the right bits.
336
-	if (!isset($column_info['name']))
337
-		$column_info['name'] = $old_column;
338
-	if (!isset($column_info['default']))
339
-		$column_info['default'] = $old_info['default'];
340
-	if (!isset($column_info['null']))
341
-		$column_info['null'] = $old_info['null'];
342
-	if (!isset($column_info['auto']))
343
-		$column_info['auto'] = $old_info['auto'];
344
-	if (!isset($column_info['type']))
345
-		$column_info['type'] = $old_info['type'];
346
-	if (!isset($column_info['size']) || !is_numeric($column_info['size']))
347
-		$column_info['size'] = $old_info['size'];
348
-	if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')))
349
-		$column_info['unsigned'] = '';
351
+	if (!isset($column_info['name'])) {
352
+			$column_info['name'] = $old_column;
353
+	}
354
+	if (!isset($column_info['default'])) {
355
+			$column_info['default'] = $old_info['default'];
356
+	}
357
+	if (!isset($column_info['null'])) {
358
+			$column_info['null'] = $old_info['null'];
359
+	}
360
+	if (!isset($column_info['auto'])) {
361
+			$column_info['auto'] = $old_info['auto'];
362
+	}
363
+	if (!isset($column_info['type'])) {
364
+			$column_info['type'] = $old_info['type'];
365
+	}
366
+	if (!isset($column_info['size']) || !is_numeric($column_info['size'])) {
367
+			$column_info['size'] = $old_info['size'];
368
+	}
369
+	if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) {
370
+			$column_info['unsigned'] = '';
371
+	}
350 372
 
351 373
 	list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']);
352 374
 
353 375
 	// Allow for unsigned integers (mysql only)
354 376
 	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : '';
355 377
 
356
-	if ($size !== null)
357
-		$type = $type . '(' . $size . ')';
378
+	if ($size !== null) {
379
+			$type = $type . '(' . $size . ')';
380
+	}
358 381
 
359 382
 	$smcFunc['db_query']('', '
360 383
 		ALTER TABLE ' . $table_name . '
@@ -384,21 +407,23 @@  discard block
 block discarded – undo
384 407
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
385 408
 
386 409
 	// No columns = no index.
387
-	if (empty($index_info['columns']))
388
-		return false;
410
+	if (empty($index_info['columns'])) {
411
+			return false;
412
+	}
389 413
 	$columns = implode(',', $index_info['columns']);
390 414
 
391 415
 	// No name - make it up!
392 416
 	if (empty($index_info['name']))
393 417
 	{
394 418
 		// No need for primary.
395
-		if (isset($index_info['type']) && $index_info['type'] == 'primary')
396
-			$index_info['name'] = '';
397
-		else
398
-			$index_info['name'] = implode('_', $index_info['columns']);
419
+		if (isset($index_info['type']) && $index_info['type'] == 'primary') {
420
+					$index_info['name'] = '';
421
+		} else {
422
+					$index_info['name'] = implode('_', $index_info['columns']);
423
+		}
424
+	} else {
425
+			$index_info['name'] = $index_info['name'];
399 426
 	}
400
-	else
401
-		$index_info['name'] = $index_info['name'];
402 427
 
403 428
 	// Log that we are going to want to remove this!
404 429
 	$db_package_log[] = array('remove_index', $table_name, $index_info['name']);
@@ -411,10 +436,11 @@  discard block
 block discarded – undo
411 436
 		if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary'))
412 437
 		{
413 438
 			// If we want to overwrite simply remove the current one then continue.
414
-			if ($if_exists != 'update' || $index['type'] == 'primary')
415
-				return false;
416
-			else
417
-				$smcFunc['db_remove_index']($table_name, $index_info['name']);
439
+			if ($if_exists != 'update' || $index['type'] == 'primary') {
440
+							return false;
441
+			} else {
442
+							$smcFunc['db_remove_index']($table_name, $index_info['name']);
443
+			}
418 444
 		}
419 445
 	}
420 446
 
@@ -428,8 +454,7 @@  discard block
 block discarded – undo
428 454
 				'security_override' => true,
429 455
 			)
430 456
 		);
431
-	}
432
-	else
457
+	} else
433 458
 	{
434 459
 		$smcFunc['db_query']('', '
435 460
 			ALTER TABLE ' . $table_name . '
@@ -513,8 +538,7 @@  discard block
 block discarded – undo
513 538
 		$types = array(
514 539
 			'inet' => 'varbinary',
515 540
 		);
516
-	}
517
-	else
541
+	} else
518 542
 	{
519 543
 		$types = array(
520 544
 			'varbinary' => 'inet',
@@ -528,16 +552,15 @@  discard block
 block discarded – undo
528 552
 		{
529 553
 			$type_size = 16;
530 554
 			$type_name = 'varbinary';
531
-		}
532
-		elseif ($type_name == 'varbinary' && $reverse && $type_size == 16)
555
+		} elseif ($type_name == 'varbinary' && $reverse && $type_size == 16)
533 556
 		{
534 557
 			$type_name = 'inet';
535 558
 			$type_size = null;
559
+		} elseif ($type_name == 'varbinary') {
560
+					$type_name = 'varbinary';
561
+		} else {
562
+					$type_name = $types[$type_name];
536 563
 		}
537
-		elseif ($type_name == 'varbinary')
538
-			$type_name = 'varbinary';
539
-		else
540
-			$type_name = $types[$type_name];
541 564
 	}
542 565
 
543 566
 	return array($type_name, $type_size);
@@ -605,8 +628,7 @@  discard block
 block discarded – undo
605 628
 		if (!$detail)
606 629
 		{
607 630
 			$columns[] = $row['Field'];
608
-		}
609
-		else
631
+		} else
610 632
 		{
611 633
 			// Is there an auto_increment?
612 634
 			$auto = strpos($row['Extra'], 'auto_increment') !== false ? true : false;
@@ -616,10 +638,10 @@  discard block
 block discarded – undo
616 638
 			{
617 639
 				$type = $matches[1];
618 640
 				$size = $matches[2];
619
-				if (!empty($matches[3]) && $matches[3] == 'unsigned')
620
-					$unsigned = true;
621
-			}
622
-			else
641
+				if (!empty($matches[3]) && $matches[3] == 'unsigned') {
642
+									$unsigned = true;
643
+				}
644
+			} else
623 645
 			{
624 646
 				$type = $row['Type'];
625 647
 				$size = null;
@@ -670,19 +692,20 @@  discard block
 block discarded – undo
670 692
 	$indexes = array();
671 693
 	while ($row = $smcFunc['db_fetch_assoc']($result))
672 694
 	{
673
-		if (!$detail)
674
-			$indexes[] = $row['Key_name'];
675
-		else
695
+		if (!$detail) {
696
+					$indexes[] = $row['Key_name'];
697
+		} else
676 698
 		{
677 699
 			// What is the type?
678
-			if ($row['Key_name'] == 'PRIMARY')
679
-				$type = 'primary';
680
-			elseif (empty($row['Non_unique']))
681
-				$type = 'unique';
682
-			elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT')
683
-				$type = 'fulltext';
684
-			else
685
-				$type = 'index';
700
+			if ($row['Key_name'] == 'PRIMARY') {
701
+							$type = 'primary';
702
+			} elseif (empty($row['Non_unique'])) {
703
+							$type = 'unique';
704
+			} elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') {
705
+							$type = 'fulltext';
706
+			} else {
707
+							$type = 'index';
708
+			}
686 709
 
687 710
 			// This is the first column we've seen?
688 711
 			if (empty($indexes[$row['Key_name']]))
@@ -695,10 +718,11 @@  discard block
 block discarded – undo
695 718
 			}
696 719
 
697 720
 			// Is it a partial index?
698
-			if (!empty($row['Sub_part']))
699
-				$indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')';
700
-			else
701
-				$indexes[$row['Key_name']]['columns'][] = $row['Column_name'];
721
+			if (!empty($row['Sub_part'])) {
722
+							$indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')';
723
+			} else {
724
+							$indexes[$row['Key_name']]['columns'][] = $row['Column_name'];
725
+			}
702 726
 		}
703 727
 	}
704 728
 	$smcFunc['db_free_result']($result);
@@ -720,11 +744,11 @@  discard block
 block discarded – undo
720 744
 	if (!empty($column['auto']))
721 745
 	{
722 746
 		$default = 'auto_increment';
747
+	} elseif (isset($column['default']) && $column['default'] !== null) {
748
+			$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
749
+	} else {
750
+			$default = '';
723 751
 	}
724
-	elseif (isset($column['default']) && $column['default'] !== null)
725
-		$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
726
-	else
727
-		$default = '';
728 752
 
729 753
 	// Sort out the size... and stuff...
730 754
 	$column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null;
@@ -733,8 +757,9 @@  discard block
 block discarded – undo
733 757
 	// Allow unsigned integers (mysql only)
734 758
 	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column['unsigned']) ? 'unsigned ' : '';
735 759
 
736
-	if ($size !== null)
737
-		$type = $type . '(' . $size . ')';
760
+	if ($size !== null) {
761
+			$type = $type . '(' . $size . ')';
762
+	}
738 763
 
739 764
 	// Now just put it together!
740 765
 	return '`' . $column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default;
Please login to merge, or discard this patch.
Sources/Profile-Modify.php 1 patch
Braces   +694 added lines, -519 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * This defines every profile field known to man.
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $sourcedir, $profile_vars;
30 31
 
31 32
 	// Don't load this twice!
32
-	if (!empty($profile_fields) && !$force_reload)
33
-		return;
33
+	if (!empty($profile_fields) && !$force_reload) {
34
+			return;
35
+	}
34 36
 
35 37
 	/* This horrific array defines all the profile fields in the whole world!
36 38
 		In general each "field" has one array - the key of which is the database column name associated with said field. Each item
@@ -103,13 +105,14 @@  discard block
 block discarded – undo
103 105
 				if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0)
104 106
 				{
105 107
 					// Set to blank?
106
-					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1)
107
-						$value = '0001-01-01';
108
-					else
109
-						$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01';
108
+					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) {
109
+											$value = '0001-01-01';
110
+					} else {
111
+											$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01';
112
+					}
113
+				} else {
114
+									$value = '0001-01-01';
110 115
 				}
111
-				else
112
-					$value = '0001-01-01';
113 116
 
114 117
 				$profile_vars['birthdate'] = $value;
115 118
 				$cur_profile['birthdate'] = $value;
@@ -127,8 +130,7 @@  discard block
 block discarded – undo
127 130
 				{
128 131
 					$value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf('%04d-%02d-%02d', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : '0001-01-01';
129 132
 					return true;
130
-				}
131
-				else
133
+				} else
132 134
 				{
133 135
 					$value = empty($cur_profile['birthdate']) ? '0001-01-01' : $cur_profile['birthdate'];
134 136
 					return false;
@@ -150,10 +152,11 @@  discard block
 block discarded – undo
150 152
 					return $txt['invalid_registration'] . ' ' . strftime('%d %b %Y ' . (strpos($user_info['time_format'], '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false));
151 153
 				}
152 154
 				// As long as it doesn't equal "N/A"...
153
-				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600)))
154
-					$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
155
-				else
156
-					$value = $cur_profile['date_registered'];
155
+				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) {
156
+									$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
157
+				} else {
158
+									$value = $cur_profile['date_registered'];
159
+				}
157 160
 
158 161
 				return true;
159 162
 			},
@@ -177,8 +180,9 @@  discard block
 block discarded – undo
177 180
 			{
178 181
 				global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
179 182
 
180
-				if (strtolower($value) == strtolower($old_profile['email_address']))
181
-					return false;
183
+				if (strtolower($value) == strtolower($old_profile['email_address'])) {
184
+									return false;
185
+				}
182 186
 
183 187
 				$isValid = profileValidateEmail($value, $context['id_member']);
184 188
 
@@ -254,11 +258,11 @@  discard block
 block discarded – undo
254 258
 
255 259
 				if (isset($context['profile_languages'][$value]))
256 260
 				{
257
-					if ($context['user']['is_owner'] && empty($context['password_auth_failed']))
258
-						$_SESSION['language'] = $value;
261
+					if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) {
262
+											$_SESSION['language'] = $value;
263
+					}
259 264
 					return true;
260
-				}
261
-				else
265
+				} else
262 266
 				{
263 267
 					$value = $cur_profile['lngfile'];
264 268
 					return false;
@@ -282,13 +286,14 @@  discard block
 block discarded – undo
282 286
 
283 287
 					// Maybe they are trying to change their password as well?
284 288
 					$resetPassword = true;
285
-					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null)
286
-						$resetPassword = false;
289
+					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) {
290
+											$resetPassword = false;
291
+					}
287 292
 
288 293
 					// Do the reset... this will send them an email too.
289
-					if ($resetPassword)
290
-						resetPassword($context['id_member'], $value);
291
-					elseif ($value !== null)
294
+					if ($resetPassword) {
295
+											resetPassword($context['id_member'], $value);
296
+					} elseif ($value !== null)
292 297
 					{
293 298
 						validateUsername($context['id_member'], trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value)));
294 299
 						updateMemberData($context['id_member'], array('member_name' => $value));
@@ -312,20 +317,23 @@  discard block
 block discarded – undo
312 317
 			'input_validate' => function(&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
313 318
 			{
314 319
 				// If we didn't try it then ignore it!
315
-				if ($value == '')
316
-					return false;
320
+				if ($value == '') {
321
+									return false;
322
+				}
317 323
 
318 324
 				// Do the two entries for the password even match?
319
-				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2'])
320
-					return 'bad_new_password';
325
+				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) {
326
+									return 'bad_new_password';
327
+				}
321 328
 
322 329
 				// Let's get the validation function into play...
323 330
 				require_once($sourcedir . '/Subs-Auth.php');
324 331
 				$passwordErrors = validatePassword($value, $cur_profile['member_name'], array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email']));
325 332
 
326 333
 				// Were there errors?
327
-				if ($passwordErrors != null)
328
-					return 'password_' . $passwordErrors;
334
+				if ($passwordErrors != null) {
335
+									return 'password_' . $passwordErrors;
336
+				}
329 337
 
330 338
 				// Set up the new password variable... ready for storage.
331 339
 				$value = hash_password($cur_profile['member_name'], un_htmlspecialchars($value));
@@ -350,8 +358,9 @@  discard block
 block discarded – undo
350 358
 			'permission' => 'profile_blurb',
351 359
 			'input_validate' => function(&$value) use ($smcFunc)
352 360
 			{
353
-				if ($smcFunc['strlen']($value) > 50)
354
-					return 'personal_text_too_long';
361
+				if ($smcFunc['strlen']($value) > 50) {
362
+									return 'personal_text_too_long';
363
+				}
355 364
 
356 365
 				return true;
357 366
 			},
@@ -386,10 +395,11 @@  discard block
 block discarded – undo
386 395
 			'permission' => 'moderate_forum',
387 396
 			'input_validate' => function(&$value)
388 397
 			{
389
-				if (!is_numeric($value))
390
-					return 'digits_only';
391
-				else
392
-					$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
398
+				if (!is_numeric($value)) {
399
+									return 'digits_only';
400
+				} else {
401
+									$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
402
+				}
393 403
 				return true;
394 404
 			},
395 405
 		),
@@ -405,15 +415,16 @@  discard block
 block discarded – undo
405 415
 			{
406 416
 				$value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value));
407 417
 
408
-				if (trim($value) == '')
409
-					return 'no_name';
410
-				elseif ($smcFunc['strlen']($value) > 60)
411
-					return 'name_too_long';
412
-				elseif ($cur_profile['real_name'] != $value)
418
+				if (trim($value) == '') {
419
+									return 'no_name';
420
+				} elseif ($smcFunc['strlen']($value) > 60) {
421
+									return 'name_too_long';
422
+				} elseif ($cur_profile['real_name'] != $value)
413 423
 				{
414 424
 					require_once($sourcedir . '/Subs-Members.php');
415
-					if (isReservedName($value, $context['id_member']))
416
-						return 'name_taken';
425
+					if (isReservedName($value, $context['id_member'])) {
426
+											return 'name_taken';
427
+					}
417 428
 				}
418 429
 				return true;
419 430
 			},
@@ -471,8 +482,9 @@  discard block
 block discarded – undo
471 482
 						'selected' => $set == $context['member']['smiley_set']['id']
472 483
 					);
473 484
 
474
-					if ($context['smiley_sets'][$i]['selected'])
475
-						$context['member']['smiley_set']['name'] = $set_names[$i];
485
+					if ($context['smiley_sets'][$i]['selected']) {
486
+											$context['member']['smiley_set']['name'] = $set_names[$i];
487
+					}
476 488
 				}
477 489
 				return true;
478 490
 			},
@@ -481,8 +493,9 @@  discard block
 block discarded – undo
481 493
 				global $modSettings;
482 494
 
483 495
 				$smiley_sets = explode(',', $modSettings['smiley_sets_known']);
484
-				if (!in_array($value, $smiley_sets) && $value != 'none')
485
-					$value = '';
496
+				if (!in_array($value, $smiley_sets) && $value != 'none') {
497
+									$value = '';
498
+				}
486 499
 				return true;
487 500
 			},
488 501
 		),
@@ -497,8 +510,9 @@  discard block
 block discarded – undo
497 510
 				loadLanguage('Settings');
498 511
 
499 512
 				$context['allow_no_censored'] = false;
500
-				if ($user_info['is_admin'] || $context['user']['is_owner'])
501
-					$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
513
+				if ($user_info['is_admin'] || $context['user']['is_owner']) {
514
+									$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
515
+				}
502 516
 
503 517
 				return true;
504 518
 			},
@@ -545,8 +559,9 @@  discard block
 block discarded – undo
545 559
 			'input_validate' => function($value)
546 560
 			{
547 561
 				$tz = smf_list_timezones();
548
-				if (!isset($tz[$value]))
549
-					return 'bad_timezone';
562
+				if (!isset($tz[$value])) {
563
+									return 'bad_timezone';
564
+				}
550 565
 
551 566
 				return true;
552 567
 			},
@@ -561,8 +576,9 @@  discard block
 block discarded – undo
561 576
 			'enabled' => !empty($modSettings['titlesEnable']),
562 577
 			'input_validate' => function(&$value) use ($smcFunc)
563 578
 			{
564
-				if ($smcFunc['strlen']($value) > 50)
565
-					return 'user_title_too_long';
579
+				if ($smcFunc['strlen']($value) > 50) {
580
+									return 'user_title_too_long';
581
+				}
566 582
 
567 583
 				return true;
568 584
 			},
@@ -584,10 +600,12 @@  discard block
 block discarded – undo
584 600
 			// Fix the URL...
585 601
 			'input_validate' => function(&$value)
586 602
 			{
587
-				if (strlen(trim($value)) > 0 && strpos($value, '://') === false)
588
-					$value = 'http://' . $value;
589
-				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://'))
590
-					$value = '';
603
+				if (strlen(trim($value)) > 0 && strpos($value, '://') === false) {
604
+									$value = 'http://' . $value;
605
+				}
606
+				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) {
607
+									$value = '';
608
+				}
591 609
 				return true;
592 610
 			},
593 611
 			'link_with' => 'website',
@@ -601,16 +619,19 @@  discard block
 block discarded – undo
601 619
 	foreach ($profile_fields as $key => $field)
602 620
 	{
603 621
 		// Do we have permission to do this?
604
-		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission']))
605
-			unset($profile_fields[$key]);
622
+		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) {
623
+					unset($profile_fields[$key]);
624
+		}
606 625
 
607 626
 		// Is it enabled?
608
-		if (isset($field['enabled']) && !$field['enabled'])
609
-			unset($profile_fields[$key]);
627
+		if (isset($field['enabled']) && !$field['enabled']) {
628
+					unset($profile_fields[$key]);
629
+		}
610 630
 
611 631
 		// Is it specifically disabled?
612
-		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields)))
613
-			unset($profile_fields[$key]);
632
+		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) {
633
+					unset($profile_fields[$key]);
634
+		}
614 635
 	}
615 636
 }
616 637
 
@@ -635,9 +656,10 @@  discard block
 block discarded – undo
635 656
 	loadProfileFields(true);
636 657
 
637 658
 	// First check for any linked sets.
638
-	foreach ($profile_fields as $key => $field)
639
-		if (isset($field['link_with']) && in_array($field['link_with'], $fields))
659
+	foreach ($profile_fields as $key => $field) {
660
+			if (isset($field['link_with']) && in_array($field['link_with'], $fields))
640 661
 			$fields[] = $key;
662
+	}
641 663
 
642 664
 	$i = 0;
643 665
 	$last_type = '';
@@ -649,38 +671,46 @@  discard block
 block discarded – undo
649 671
 			$cur_field = &$profile_fields[$field];
650 672
 
651 673
 			// Does it have a preload and does that preload succeed?
652
-			if (isset($cur_field['preload']) && !$cur_field['preload']())
653
-				continue;
674
+			if (isset($cur_field['preload']) && !$cur_field['preload']()) {
675
+							continue;
676
+			}
654 677
 
655 678
 			// If this is anything but complex we need to do more cleaning!
656 679
 			if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden')
657 680
 			{
658
-				if (!isset($cur_field['label']))
659
-					$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
681
+				if (!isset($cur_field['label'])) {
682
+									$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
683
+				}
660 684
 
661 685
 				// Everything has a value!
662
-				if (!isset($cur_field['value']))
663
-					$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
686
+				if (!isset($cur_field['value'])) {
687
+									$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
688
+				}
664 689
 
665 690
 				// Any input attributes?
666 691
 				$cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : '';
667 692
 			}
668 693
 
669 694
 			// Was there an error with this field on posting?
670
-			if (isset($context['profile_errors'][$field]))
671
-				$cur_field['is_error'] = true;
695
+			if (isset($context['profile_errors'][$field])) {
696
+							$cur_field['is_error'] = true;
697
+			}
672 698
 
673 699
 			// Any javascript stuff?
674
-			if (!empty($cur_field['js_submit']))
675
-				$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
676
-			if (!empty($cur_field['js']))
677
-				$context['profile_javascript'] .= $cur_field['js'];
700
+			if (!empty($cur_field['js_submit'])) {
701
+							$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
702
+			}
703
+			if (!empty($cur_field['js'])) {
704
+							$context['profile_javascript'] .= $cur_field['js'];
705
+			}
678 706
 
679 707
 			// Any template stuff?
680
-			if (!empty($cur_field['prehtml']))
681
-				$context['profile_prehtml'] .= $cur_field['prehtml'];
682
-			if (!empty($cur_field['posthtml']))
683
-				$context['profile_posthtml'] .= $cur_field['posthtml'];
708
+			if (!empty($cur_field['prehtml'])) {
709
+							$context['profile_prehtml'] .= $cur_field['prehtml'];
710
+			}
711
+			if (!empty($cur_field['posthtml'])) {
712
+							$context['profile_posthtml'] .= $cur_field['posthtml'];
713
+			}
684 714
 
685 715
 			// Finally put it into context?
686 716
 			if ($cur_field['type'] != 'hidden')
@@ -713,12 +743,14 @@  discard block
 block discarded – undo
713 743
 	}, false);' : ''), true);
714 744
 
715 745
 	// Any onsubmit javascript?
716
-	if (!empty($context['profile_onsubmit_javascript']))
717
-		addInlineJavaScript($context['profile_onsubmit_javascript'], true);
746
+	if (!empty($context['profile_onsubmit_javascript'])) {
747
+			addInlineJavaScript($context['profile_onsubmit_javascript'], true);
748
+	}
718 749
 
719 750
 	// Any totally custom stuff?
720
-	if (!empty($context['profile_javascript']))
721
-		addInlineJavaScript($context['profile_javascript'], true);
751
+	if (!empty($context['profile_javascript'])) {
752
+			addInlineJavaScript($context['profile_javascript'], true);
753
+	}
722 754
 
723 755
 	// Free up some memory.
724 756
 	unset($profile_fields);
@@ -739,8 +771,9 @@  discard block
 block discarded – undo
739 771
 
740 772
 	// This allows variables to call activities when they save - by default just to reload their settings
741 773
 	$context['profile_execute_on_save'] = array();
742
-	if ($context['user']['is_owner'])
743
-		$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
774
+	if ($context['user']['is_owner']) {
775
+			$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
776
+	}
744 777
 
745 778
 	// Assume we log nothing.
746 779
 	$context['log_changes'] = array();
@@ -748,8 +781,9 @@  discard block
 block discarded – undo
748 781
 	// Cycle through the profile fields working out what to do!
749 782
 	foreach ($profile_fields as $key => $field)
750 783
 	{
751
-		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature'))
752
-			continue;
784
+		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) {
785
+					continue;
786
+		}
753 787
 
754 788
 		// What gets updated?
755 789
 		$db_key = isset($field['save_key']) ? $field['save_key'] : $key;
@@ -777,12 +811,13 @@  discard block
 block discarded – undo
777 811
 		$field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type'];
778 812
 
779 813
 		// Finally, clean up certain types.
780
-		if ($field['cast_type'] == 'int')
781
-			$_POST[$key] = (int) $_POST[$key];
782
-		elseif ($field['cast_type'] == 'float')
783
-			$_POST[$key] = (float) $_POST[$key];
784
-		elseif ($field['cast_type'] == 'check')
785
-			$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
814
+		if ($field['cast_type'] == 'int') {
815
+					$_POST[$key] = (int) $_POST[$key];
816
+		} elseif ($field['cast_type'] == 'float') {
817
+					$_POST[$key] = (float) $_POST[$key];
818
+		} elseif ($field['cast_type'] == 'check') {
819
+					$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
820
+		}
786 821
 
787 822
 		// If we got here we're doing OK.
788 823
 		if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key]))
@@ -793,11 +828,12 @@  discard block
 block discarded – undo
793 828
 			$cur_profile[$key] = $_POST[$key];
794 829
 
795 830
 			// Are we logging it?
796
-			if (!empty($field['log_change']) && isset($old_profile[$key]))
797
-				$context['log_changes'][$key] = array(
831
+			if (!empty($field['log_change']) && isset($old_profile[$key])) {
832
+							$context['log_changes'][$key] = array(
798 833
 					'previous' => $old_profile[$key],
799 834
 					'new' => $_POST[$key],
800 835
 				);
836
+			}
801 837
 		}
802 838
 
803 839
 		// Logging group changes are a bit different...
@@ -830,10 +866,11 @@  discard block
 block discarded – undo
830 866
 				{
831 867
 					foreach ($groups as $id => $group)
832 868
 					{
833
-						if (isset($context['member_groups'][$group]))
834
-							$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
835
-						else
836
-							unset($additional_groups[$type][$id]);
869
+						if (isset($context['member_groups'][$group])) {
870
+													$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
871
+						} else {
872
+													unset($additional_groups[$type][$id]);
873
+						}
837 874
 					}
838 875
 					$additional_groups[$type] = implode(', ', $additional_groups[$type]);
839 876
 				}
@@ -844,10 +881,11 @@  discard block
 block discarded – undo
844 881
 	}
845 882
 
846 883
 	// @todo Temporary
847
-	if ($context['user']['is_owner'])
848
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
849
-	else
850
-		$changeOther = allowedTo('profile_extra_any');
884
+	if ($context['user']['is_owner']) {
885
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
886
+	} else {
887
+			$changeOther = allowedTo('profile_extra_any');
888
+	}
851 889
 	if ($changeOther && empty($post_errors))
852 890
 	{
853 891
 		makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
@@ -855,8 +893,9 @@  discard block
 block discarded – undo
855 893
 		{
856 894
 			$custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true);
857 895
 
858
-			if (!empty($custom_fields_errors))
859
-				$post_errors = array_merge($post_errors, $custom_fields_errors);
896
+			if (!empty($custom_fields_errors)) {
897
+							$post_errors = array_merge($post_errors, $custom_fields_errors);
898
+			}
860 899
 		}
861 900
 	}
862 901
 
@@ -882,9 +921,9 @@  discard block
 block discarded – undo
882 921
 	if ($context['user']['is_owner'])
883 922
 	{
884 923
 		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own'));
924
+	} else {
925
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
885 926
 	}
886
-	else
887
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
888 927
 
889 928
 	// Arrays of all the changes - makes things easier.
890 929
 	$profile_bools = array();
@@ -895,22 +934,25 @@  discard block
 block discarded – undo
895 934
 		'ignore_boards',
896 935
 	);
897 936
 
898
-	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
899
-		$_POST['ignore_brd'] = array();
937
+	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) {
938
+			$_POST['ignore_brd'] = array();
939
+	}
900 940
 
901 941
 	unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing.  Kinda like our minds.
902 942
 	if (isset($_POST['ignore_brd']))
903 943
 	{
904
-		if (!is_array($_POST['ignore_brd']))
905
-			$_POST['ignore_brd'] = array($_POST['ignore_brd']);
944
+		if (!is_array($_POST['ignore_brd'])) {
945
+					$_POST['ignore_brd'] = array($_POST['ignore_brd']);
946
+		}
906 947
 
907 948
 		foreach ($_POST['ignore_brd'] as $k => $d)
908 949
 		{
909 950
 			$d = (int) $d;
910
-			if ($d != 0)
911
-				$_POST['ignore_brd'][$k] = $d;
912
-			else
913
-				unset($_POST['ignore_brd'][$k]);
951
+			if ($d != 0) {
952
+							$_POST['ignore_brd'][$k] = $d;
953
+			} else {
954
+							unset($_POST['ignore_brd'][$k]);
955
+			}
914 956
 		}
915 957
 		$_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
916 958
 		unset($_POST['ignore_brd']);
@@ -923,21 +965,26 @@  discard block
 block discarded – undo
923 965
 		makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
924 966
 		//makeAvatarChanges($memID, $post_errors);
925 967
 
926
-		if (!empty($_REQUEST['sa']))
927
-			makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
968
+		if (!empty($_REQUEST['sa'])) {
969
+					makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
970
+		}
928 971
 
929
-		foreach ($profile_bools as $var)
930
-			if (isset($_POST[$var]))
972
+		foreach ($profile_bools as $var) {
973
+					if (isset($_POST[$var]))
931 974
 				$profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
932
-		foreach ($profile_ints as $var)
933
-			if (isset($_POST[$var]))
975
+		}
976
+		foreach ($profile_ints as $var) {
977
+					if (isset($_POST[$var]))
934 978
 				$profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
935
-		foreach ($profile_floats as $var)
936
-			if (isset($_POST[$var]))
979
+		}
980
+		foreach ($profile_floats as $var) {
981
+					if (isset($_POST[$var]))
937 982
 				$profile_vars[$var] = (float) $_POST[$var];
938
-		foreach ($profile_strings as $var)
939
-			if (isset($_POST[$var]))
983
+		}
984
+		foreach ($profile_strings as $var) {
985
+					if (isset($_POST[$var]))
940 986
 				$profile_vars[$var] = $_POST[$var];
987
+		}
941 988
 	}
942 989
 }
943 990
 
@@ -971,8 +1018,9 @@  discard block
 block discarded – undo
971 1018
 	);
972 1019
 
973 1020
 	// Can't change reserved vars.
974
-	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0))
975
-		fatal_lang_error('no_access', false);
1021
+	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) {
1022
+			fatal_lang_error('no_access', false);
1023
+	}
976 1024
 
977 1025
 	// Don't allow any overriding of custom fields with default or non-default options.
978 1026
 	$request = $smcFunc['db_query']('', '
@@ -984,8 +1032,9 @@  discard block
 block discarded – undo
984 1032
 		)
985 1033
 	);
986 1034
 	$custom_fields = array();
987
-	while ($row = $smcFunc['db_fetch_assoc']($request))
988
-		$custom_fields[] = $row['col_name'];
1035
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1036
+			$custom_fields[] = $row['col_name'];
1037
+	}
989 1038
 	$smcFunc['db_free_result']($request);
990 1039
 
991 1040
 	// These are the theme changes...
@@ -994,33 +1043,39 @@  discard block
 block discarded – undo
994 1043
 	{
995 1044
 		foreach ($_POST['options'] as $opt => $val)
996 1045
 		{
997
-			if (in_array($opt, $custom_fields))
998
-				continue;
1046
+			if (in_array($opt, $custom_fields)) {
1047
+							continue;
1048
+			}
999 1049
 
1000 1050
 			// These need to be controlled.
1001
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1002
-				$val = max(0, min($val, 50));
1051
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1052
+							$val = max(0, min($val, 50));
1053
+			}
1003 1054
 			// We don't set this per theme anymore.
1004
-			elseif ($opt == 'allow_no_censored')
1005
-				continue;
1055
+			elseif ($opt == 'allow_no_censored') {
1056
+							continue;
1057
+			}
1006 1058
 
1007 1059
 			$themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
1008 1060
 		}
1009 1061
 	}
1010 1062
 
1011 1063
 	$erase_options = array();
1012
-	if (isset($_POST['default_options']) && is_array($_POST['default_options']))
1013
-		foreach ($_POST['default_options'] as $opt => $val)
1064
+	if (isset($_POST['default_options']) && is_array($_POST['default_options'])) {
1065
+			foreach ($_POST['default_options'] as $opt => $val)
1014 1066
 		{
1015 1067
 			if (in_array($opt, $custom_fields))
1016 1068
 				continue;
1069
+	}
1017 1070
 
1018 1071
 			// These need to be controlled.
1019
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1020
-				$val = max(0, min($val, 50));
1072
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1073
+							$val = max(0, min($val, 50));
1074
+			}
1021 1075
 			// Only let admins and owners change the censor.
1022
-			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner'])
1023
-					continue;
1076
+			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) {
1077
+								continue;
1078
+			}
1024 1079
 
1025 1080
 			$themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
1026 1081
 			$erase_options[] = $opt;
@@ -1056,8 +1111,9 @@  discard block
 block discarded – undo
1056 1111
 
1057 1112
 		// Admins can choose any theme, even if it's not enabled...
1058 1113
 		$themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']);
1059
-		foreach ($themes as $t)
1060
-			cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1114
+		foreach ($themes as $t) {
1115
+					cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1116
+		}
1061 1117
 	}
1062 1118
 }
1063 1119
 
@@ -1076,8 +1132,9 @@  discard block
 block discarded – undo
1076 1132
 	if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
1077 1133
 	{
1078 1134
 		// Make sure only integers are deleted.
1079
-		foreach ($_POST['notify_boards'] as $index => $id)
1080
-			$_POST['notify_boards'][$index] = (int) $id;
1135
+		foreach ($_POST['notify_boards'] as $index => $id) {
1136
+					$_POST['notify_boards'][$index] = (int) $id;
1137
+		}
1081 1138
 
1082 1139
 		// id_board = 0 is reserved for topic notifications.
1083 1140
 		$_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
@@ -1096,8 +1153,9 @@  discard block
 block discarded – undo
1096 1153
 	// We are editing topic notifications......
1097 1154
 	elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
1098 1155
 	{
1099
-		foreach ($_POST['notify_topics'] as $index => $id)
1100
-			$_POST['notify_topics'][$index] = (int) $id;
1156
+		foreach ($_POST['notify_topics'] as $index => $id) {
1157
+					$_POST['notify_topics'][$index] = (int) $id;
1158
+		}
1101 1159
 
1102 1160
 		// Make sure there are no zeros left.
1103 1161
 		$_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
@@ -1111,16 +1169,18 @@  discard block
 block discarded – undo
1111 1169
 				'selected_member' => $memID,
1112 1170
 			)
1113 1171
 		);
1114
-		foreach ($_POST['notify_topics'] as $topic)
1115
-			setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1172
+		foreach ($_POST['notify_topics'] as $topic) {
1173
+					setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1174
+		}
1116 1175
 	}
1117 1176
 
1118 1177
 	// We are removing topic preferences
1119 1178
 	elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics']))
1120 1179
 	{
1121 1180
 		$prefs = array();
1122
-		foreach ($_POST['notify_topics'] as $topic)
1123
-			$prefs[] = 'topic_notify_' . $topic;
1181
+		foreach ($_POST['notify_topics'] as $topic) {
1182
+					$prefs[] = 'topic_notify_' . $topic;
1183
+		}
1124 1184
 		deleteNotifyPrefs($memID, $prefs);
1125 1185
 	}
1126 1186
 
@@ -1128,8 +1188,9 @@  discard block
 block discarded – undo
1128 1188
 	elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards']))
1129 1189
 	{
1130 1190
 		$prefs = array();
1131
-		foreach ($_POST['notify_boards'] as $board)
1132
-			$prefs[] = 'board_notify_' . $board;
1191
+		foreach ($_POST['notify_boards'] as $board) {
1192
+					$prefs[] = 'board_notify_' . $board;
1193
+		}
1133 1194
 		deleteNotifyPrefs($memID, $prefs);
1134 1195
 	}
1135 1196
 }
@@ -1150,8 +1211,9 @@  discard block
 block discarded – undo
1150 1211
 
1151 1212
 	$errors = array();
1152 1213
 
1153
-	if ($sanitize && isset($_POST['customfield']))
1154
-		$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1214
+	if ($sanitize && isset($_POST['customfield'])) {
1215
+			$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1216
+	}
1155 1217
 
1156 1218
 	$where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
1157 1219
 
@@ -1176,48 +1238,49 @@  discard block
 block discarded – undo
1176 1238
 			- The data is not invisible to users but editable by the owner (or if it is the user is not the owner)
1177 1239
 			- The area isn't registration, and if it is that the field is not supposed to be shown there.
1178 1240
 		*/
1179
-		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
1180
-			continue;
1241
+		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) {
1242
+					continue;
1243
+		}
1181 1244
 
1182 1245
 		// Validate the user data.
1183
-		if ($row['field_type'] == 'check')
1184
-			$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1185
-		elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1246
+		if ($row['field_type'] == 'check') {
1247
+					$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1248
+		} elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1186 1249
 		{
1187 1250
 			$value = $row['default_value'];
1188
-			foreach (explode(',', $row['field_options']) as $k => $v)
1189
-				if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1251
+			foreach (explode(',', $row['field_options']) as $k => $v) {
1252
+							if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1190 1253
 					$value = $v;
1254
+			}
1191 1255
 		}
1192 1256
 		// Otherwise some form of text!
1193 1257
 		else
1194 1258
 		{
1195 1259
 			$value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
1196
-			if ($row['field_length'])
1197
-				$value = $smcFunc['substr']($value, 0, $row['field_length']);
1260
+			if ($row['field_length']) {
1261
+							$value = $smcFunc['substr']($value, 0, $row['field_length']);
1262
+			}
1198 1263
 
1199 1264
 			// Any masks?
1200 1265
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
1201 1266
 			{
1202 1267
 				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1203 1268
 				{
1204
-					if ($returnErrors)
1205
-						$errors[] = 'custom_field_mail_fail';
1206
-
1207
-					else
1208
-						$value = '';
1209
-				}
1210
-				elseif ($row['mask'] == 'number')
1269
+					if ($returnErrors) {
1270
+											$errors[] = 'custom_field_mail_fail';
1271
+					} else {
1272
+											$value = '';
1273
+					}
1274
+				} elseif ($row['mask'] == 'number')
1211 1275
 				{
1212 1276
 					$value = (int) $value;
1213
-				}
1214
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1277
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1215 1278
 				{
1216
-					if ($returnErrors)
1217
-						$errors[] = 'custom_field_regex_fail';
1218
-
1219
-					else
1220
-						$value = '';
1279
+					if ($returnErrors) {
1280
+											$errors[] = 'custom_field_regex_fail';
1281
+					} else {
1282
+											$value = '';
1283
+					}
1221 1284
 				}
1222 1285
 			}
1223 1286
 		}
@@ -1243,8 +1306,9 @@  discard block
 block discarded – undo
1243 1306
 
1244 1307
 	$hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize));
1245 1308
 
1246
-	if (!empty($hook_errors) && is_array($hook_errors))
1247
-		$errors = array_merge($errors, $hook_errors);
1309
+	if (!empty($hook_errors) && is_array($hook_errors)) {
1310
+			$errors = array_merge($errors, $hook_errors);
1311
+	}
1248 1312
 
1249 1313
 	// Make those changes!
1250 1314
 	if (!empty($changes) && empty($context['password_auth_failed']) && empty($errors))
@@ -1262,9 +1326,10 @@  discard block
 block discarded – undo
1262 1326
 		}
1263 1327
 	}
1264 1328
 
1265
-	if ($returnErrors)
1266
-		return $errors;
1267
-}
1329
+	if ($returnErrors) {
1330
+			return $errors;
1331
+	}
1332
+	}
1268 1333
 
1269 1334
 /**
1270 1335
  * Show all the users buddies, as well as a add/delete interface.
@@ -1276,8 +1341,9 @@  discard block
 block discarded – undo
1276 1341
 	global $context, $txt, $modSettings;
1277 1342
 
1278 1343
 	// Do a quick check to ensure people aren't getting here illegally!
1279
-	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
1280
-		fatal_lang_error('no_access', false);
1344
+	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) {
1345
+			fatal_lang_error('no_access', false);
1346
+	}
1281 1347
 
1282 1348
 	// Can we email the user direct?
1283 1349
 	$context['can_moderate_forum'] = allowedTo('moderate_forum');
@@ -1307,9 +1373,10 @@  discard block
 block discarded – undo
1307 1373
 	$context['sub_template'] = $subActions[$context['list_area']][0];
1308 1374
 	$call = call_helper($subActions[$context['list_area']][0], true);
1309 1375
 
1310
-	if (!empty($call))
1311
-		call_user_func($call, $memID);
1312
-}
1376
+	if (!empty($call)) {
1377
+			call_user_func($call, $memID);
1378
+	}
1379
+	}
1313 1380
 
1314 1381
 /**
1315 1382
  * Show all the users buddies, as well as a add/delete interface.
@@ -1323,9 +1390,10 @@  discard block
 block discarded – undo
1323 1390
 
1324 1391
 	// For making changes!
1325 1392
 	$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
1326
-	foreach ($buddiesArray as $k => $dummy)
1327
-		if ($dummy == '')
1393
+	foreach ($buddiesArray as $k => $dummy) {
1394
+			if ($dummy == '')
1328 1395
 			unset($buddiesArray[$k]);
1396
+	}
1329 1397
 
1330 1398
 	// Removing a buddy?
1331 1399
 	if (isset($_GET['remove']))
@@ -1337,10 +1405,11 @@  discard block
 block discarded – undo
1337 1405
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1338 1406
 
1339 1407
 		// Heh, I'm lazy, do it the easy way...
1340
-		foreach ($buddiesArray as $key => $buddy)
1341
-			if ($buddy == (int) $_GET['remove'])
1408
+		foreach ($buddiesArray as $key => $buddy) {
1409
+					if ($buddy == (int) $_GET['remove'])
1342 1410
 			{
1343 1411
 				unset($buddiesArray[$key]);
1412
+		}
1344 1413
 				$_SESSION['prf-save'] = true;
1345 1414
 			}
1346 1415
 
@@ -1350,8 +1419,7 @@  discard block
 block discarded – undo
1350 1419
 
1351 1420
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1352 1421
 		redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
1353
-	}
1354
-	elseif (isset($_POST['new_buddy']))
1422
+	} elseif (isset($_POST['new_buddy']))
1355 1423
 	{
1356 1424
 		checkSession();
1357 1425
 
@@ -1364,8 +1432,9 @@  discard block
 block discarded – undo
1364 1432
 		{
1365 1433
 			$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
1366 1434
 
1367
-			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1368
-				unset($new_buddies[$k]);
1435
+			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1436
+							unset($new_buddies[$k]);
1437
+			}
1369 1438
 		}
1370 1439
 
1371 1440
 		call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
@@ -1385,16 +1454,18 @@  discard block
 block discarded – undo
1385 1454
 				)
1386 1455
 			);
1387 1456
 
1388
-			if ($smcFunc['db_num_rows']($request) != 0)
1389
-				$_SESSION['prf-save'] = true;
1457
+			if ($smcFunc['db_num_rows']($request) != 0) {
1458
+							$_SESSION['prf-save'] = true;
1459
+			}
1390 1460
 
1391 1461
 			// Add the new member to the buddies array.
1392 1462
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1393 1463
 			{
1394
-				if (in_array($row['id_member'], $buddiesArray))
1395
-					continue;
1396
-				else
1397
-					$buddiesArray[] = (int) $row['id_member'];
1464
+				if (in_array($row['id_member'], $buddiesArray)) {
1465
+									continue;
1466
+				} else {
1467
+									$buddiesArray[] = (int) $row['id_member'];
1468
+				}
1398 1469
 			}
1399 1470
 			$smcFunc['db_free_result']($request);
1400 1471
 
@@ -1424,18 +1495,20 @@  discard block
 block discarded – undo
1424 1495
 
1425 1496
 	$context['custom_pf'] = array();
1426 1497
 	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
1427
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1428
-		if (!isset($disabled_fields[$row['col_name']]))
1498
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1499
+			if (!isset($disabled_fields[$row['col_name']]))
1429 1500
 			$context['custom_pf'][$row['col_name']] = array(
1430 1501
 				'label' => $row['field_name'],
1431 1502
 				'type' => $row['field_type'],
1432 1503
 				'bbc' => !empty($row['bbc']),
1433 1504
 				'enclose' => $row['enclose'],
1434 1505
 			);
1506
+	}
1435 1507
 
1436 1508
 	// Gotta disable the gender option.
1437
-	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled')
1438
-		unset($context['custom_pf']['cust_gender']);
1509
+	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled') {
1510
+			unset($context['custom_pf']['cust_gender']);
1511
+	}
1439 1512
 
1440 1513
 	$smcFunc['db_free_result']($request);
1441 1514
 
@@ -1452,8 +1525,9 @@  discard block
 block discarded – undo
1452 1525
 				'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
1453 1526
 			)
1454 1527
 		);
1455
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1456
-			$buddies[] = $row['id_member'];
1528
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1529
+					$buddies[] = $row['id_member'];
1530
+		}
1457 1531
 		$smcFunc['db_free_result']($result);
1458 1532
 	}
1459 1533
 
@@ -1481,30 +1555,32 @@  discard block
 block discarded – undo
1481 1555
 					continue;
1482 1556
 				}
1483 1557
 
1484
-				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key]))
1485
-					$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1486
-
1487
-				elseif ($column['type'] == 'check')
1488
-					$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1558
+				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) {
1559
+									$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1560
+				} elseif ($column['type'] == 'check') {
1561
+									$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1562
+				}
1489 1563
 
1490 1564
 				// Enclosing the user input within some other text?
1491
-				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key]))
1492
-					$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1565
+				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) {
1566
+									$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1493 1567
 						'{SCRIPTURL}' => $scripturl,
1494 1568
 						'{IMAGES_URL}' => $settings['images_url'],
1495 1569
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1496 1570
 						'{INPUT}' => $context['buddies'][$buddy]['options'][$key],
1497 1571
 					));
1572
+				}
1498 1573
 			}
1499 1574
 		}
1500 1575
 	}
1501 1576
 
1502 1577
 	if (isset($_SESSION['prf-save']))
1503 1578
 	{
1504
-		if ($_SESSION['prf-save'] === true)
1505
-			$context['saved_successful'] = true;
1506
-		else
1507
-			$context['saved_failed'] = $_SESSION['prf-save'];
1579
+		if ($_SESSION['prf-save'] === true) {
1580
+					$context['saved_successful'] = true;
1581
+		} else {
1582
+					$context['saved_failed'] = $_SESSION['prf-save'];
1583
+		}
1508 1584
 
1509 1585
 		unset($_SESSION['prf-save']);
1510 1586
 	}
@@ -1524,9 +1600,10 @@  discard block
 block discarded – undo
1524 1600
 
1525 1601
 	// For making changes!
1526 1602
 	$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
1527
-	foreach ($ignoreArray as $k => $dummy)
1528
-		if ($dummy == '')
1603
+	foreach ($ignoreArray as $k => $dummy) {
1604
+			if ($dummy == '')
1529 1605
 			unset($ignoreArray[$k]);
1606
+	}
1530 1607
 
1531 1608
 	// Removing a member from the ignore list?
1532 1609
 	if (isset($_GET['remove']))
@@ -1536,10 +1613,11 @@  discard block
 block discarded – undo
1536 1613
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1537 1614
 
1538 1615
 		// Heh, I'm lazy, do it the easy way...
1539
-		foreach ($ignoreArray as $key => $id_remove)
1540
-			if ($id_remove == (int) $_GET['remove'])
1616
+		foreach ($ignoreArray as $key => $id_remove) {
1617
+					if ($id_remove == (int) $_GET['remove'])
1541 1618
 			{
1542 1619
 				unset($ignoreArray[$key]);
1620
+		}
1543 1621
 				$_SESSION['prf-save'] = true;
1544 1622
 			}
1545 1623
 
@@ -1549,8 +1627,7 @@  discard block
 block discarded – undo
1549 1627
 
1550 1628
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1551 1629
 		redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
1552
-	}
1553
-	elseif (isset($_POST['new_ignore']))
1630
+	} elseif (isset($_POST['new_ignore']))
1554 1631
 	{
1555 1632
 		checkSession();
1556 1633
 		// Prepare the string for extraction...
@@ -1562,8 +1639,9 @@  discard block
 block discarded – undo
1562 1639
 		{
1563 1640
 			$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
1564 1641
 
1565
-			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1566
-				unset($new_entries[$k]);
1642
+			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1643
+							unset($new_entries[$k]);
1644
+			}
1567 1645
 		}
1568 1646
 
1569 1647
 		$_SESSION['prf-save'] = $txt['could_not_add_person'];
@@ -1581,16 +1659,18 @@  discard block
 block discarded – undo
1581 1659
 				)
1582 1660
 			);
1583 1661
 
1584
-			if ($smcFunc['db_num_rows']($request) != 0)
1585
-				$_SESSION['prf-save'] = true;
1662
+			if ($smcFunc['db_num_rows']($request) != 0) {
1663
+							$_SESSION['prf-save'] = true;
1664
+			}
1586 1665
 
1587 1666
 			// Add the new member to the buddies array.
1588 1667
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1589 1668
 			{
1590
-				if (in_array($row['id_member'], $ignoreArray))
1591
-					continue;
1592
-				else
1593
-					$ignoreArray[] = (int) $row['id_member'];
1669
+				if (in_array($row['id_member'], $ignoreArray)) {
1670
+									continue;
1671
+				} else {
1672
+									$ignoreArray[] = (int) $row['id_member'];
1673
+				}
1594 1674
 			}
1595 1675
 			$smcFunc['db_free_result']($request);
1596 1676
 
@@ -1619,8 +1699,9 @@  discard block
 block discarded – undo
1619 1699
 				'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
1620 1700
 			)
1621 1701
 		);
1622
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1623
-			$ignored[] = $row['id_member'];
1702
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1703
+					$ignored[] = $row['id_member'];
1704
+		}
1624 1705
 		$smcFunc['db_free_result']($result);
1625 1706
 	}
1626 1707
 
@@ -1639,10 +1720,11 @@  discard block
 block discarded – undo
1639 1720
 
1640 1721
 	if (isset($_SESSION['prf-save']))
1641 1722
 	{
1642
-		if ($_SESSION['prf-save'] === true)
1643
-			$context['saved_successful'] = true;
1644
-		else
1645
-			$context['saved_failed'] = $_SESSION['prf-save'];
1723
+		if ($_SESSION['prf-save'] === true) {
1724
+					$context['saved_successful'] = true;
1725
+		} else {
1726
+					$context['saved_failed'] = $_SESSION['prf-save'];
1727
+		}
1646 1728
 
1647 1729
 		unset($_SESSION['prf-save']);
1648 1730
 	}
@@ -1658,8 +1740,9 @@  discard block
 block discarded – undo
1658 1740
 	global $context, $txt;
1659 1741
 
1660 1742
 	loadThemeOptions($memID);
1661
-	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
1662
-		loadCustomFields($memID, 'account');
1743
+	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) {
1744
+			loadCustomFields($memID, 'account');
1745
+	}
1663 1746
 
1664 1747
 	$context['sub_template'] = 'edit_options';
1665 1748
 	$context['page_desc'] = $txt['account_info'];
@@ -1686,8 +1769,9 @@  discard block
 block discarded – undo
1686 1769
 	global $context, $txt;
1687 1770
 
1688 1771
 	loadThemeOptions($memID);
1689
-	if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
1690
-		loadCustomFields($memID, 'forumprofile');
1772
+	if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) {
1773
+			loadCustomFields($memID, 'forumprofile');
1774
+	}
1691 1775
 
1692 1776
 	$context['sub_template'] = 'edit_options';
1693 1777
 	$context['page_desc'] = $txt['forumProfile_info'];
@@ -1720,18 +1804,21 @@  discard block
 block discarded – undo
1720 1804
 	$dirs = array();
1721 1805
 	$files = array();
1722 1806
 
1723
-	if (!$dir)
1724
-		return array();
1807
+	if (!$dir) {
1808
+			return array();
1809
+	}
1725 1810
 
1726 1811
 	while ($line = $dir->read())
1727 1812
 	{
1728
-		if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
1729
-			continue;
1813
+		if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) {
1814
+					continue;
1815
+		}
1730 1816
 
1731
-		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
1732
-			$dirs[] = $line;
1733
-		else
1734
-			$files[] = $line;
1817
+		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) {
1818
+					$dirs[] = $line;
1819
+		} else {
1820
+					$files[] = $line;
1821
+		}
1735 1822
 	}
1736 1823
 	$dir->close();
1737 1824
 
@@ -1752,14 +1839,15 @@  discard block
 block discarded – undo
1752 1839
 	foreach ($dirs as $line)
1753 1840
 	{
1754 1841
 		$tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
1755
-		if (!empty($tmp))
1756
-			$result[] = array(
1842
+		if (!empty($tmp)) {
1843
+					$result[] = array(
1757 1844
 				'filename' => $smcFunc['htmlspecialchars']($line),
1758 1845
 				'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
1759 1846
 				'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
1760 1847
 				'is_dir' => true,
1761 1848
 				'files' => $tmp
1762 1849
 		);
1850
+		}
1763 1851
 		unset($tmp);
1764 1852
 	}
1765 1853
 
@@ -1769,8 +1857,9 @@  discard block
 block discarded – undo
1769 1857
 		$extension = substr(strrchr($line, '.'), 1);
1770 1858
 
1771 1859
 		// Make sure it is an image.
1772
-		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
1773
-			continue;
1860
+		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) {
1861
+					continue;
1862
+		}
1774 1863
 
1775 1864
 		$result[] = array(
1776 1865
 			'filename' => $smcFunc['htmlspecialchars']($line),
@@ -1778,8 +1867,9 @@  discard block
 block discarded – undo
1778 1867
 			'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
1779 1868
 			'is_dir' => false
1780 1869
 		);
1781
-		if ($level == 1)
1782
-			$context['avatar_list'][] = $directory . '/' . $line;
1870
+		if ($level == 1) {
1871
+					$context['avatar_list'][] = $directory . '/' . $line;
1872
+		}
1783 1873
 	}
1784 1874
 
1785 1875
 	return $result;
@@ -1795,8 +1885,9 @@  discard block
 block discarded – undo
1795 1885
 	global $txt, $context;
1796 1886
 
1797 1887
 	loadThemeOptions($memID);
1798
-	if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
1799
-		loadCustomFields($memID, 'theme');
1888
+	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) {
1889
+			loadCustomFields($memID, 'theme');
1890
+	}
1800 1891
 
1801 1892
 	$context['sub_template'] = 'edit_options';
1802 1893
 	$context['page_desc'] = $txt['theme_info'];
@@ -1850,16 +1941,19 @@  discard block
 block discarded – undo
1850 1941
 {
1851 1942
 	global $txt, $user_profile, $context, $modSettings, $smcFunc, $sourcedir;
1852 1943
 
1853
-	if (!isset($context['token_check']))
1854
-		$context['token_check'] = 'profile-nt' . $memID;
1944
+	if (!isset($context['token_check'])) {
1945
+			$context['token_check'] = 'profile-nt' . $memID;
1946
+	}
1855 1947
 
1856 1948
 	is_not_guest();
1857
-	if (!$context['user']['is_owner'])
1858
-		isAllowedTo('profile_extra_any');
1949
+	if (!$context['user']['is_owner']) {
1950
+			isAllowedTo('profile_extra_any');
1951
+	}
1859 1952
 
1860 1953
 	// Set the post action if we're coming from the profile...
1861
-	if (!isset($context['action']))
1862
-		$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1954
+	if (!isset($context['action'])) {
1955
+			$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1956
+	}
1863 1957
 
1864 1958
 	// What options are set
1865 1959
 	loadThemeOptions($memID);
@@ -1946,28 +2040,34 @@  discard block
 block discarded – undo
1946 2040
 	);
1947 2041
 
1948 2042
 	// There are certain things that are disabled at the group level.
1949
-	if (empty($modSettings['cal_enabled']))
1950
-		unset($alert_types['calendar']);
2043
+	if (empty($modSettings['cal_enabled'])) {
2044
+			unset($alert_types['calendar']);
2045
+	}
1951 2046
 
1952 2047
 	// Disable paid subscriptions at group level if they're disabled
1953
-	if (empty($modSettings['paid_enabled']))
1954
-		unset($alert_types['paidsubs']);
2048
+	if (empty($modSettings['paid_enabled'])) {
2049
+			unset($alert_types['paidsubs']);
2050
+	}
1955 2051
 
1956 2052
 	// Disable membergroup requests at group level if they're disabled
1957
-	if (empty($modSettings['show_group_membership']))
1958
-		unset($alert_types['groupr'], $alert_types['members']['request_group']);
2053
+	if (empty($modSettings['show_group_membership'])) {
2054
+			unset($alert_types['groupr'], $alert_types['members']['request_group']);
2055
+	}
1959 2056
 
1960 2057
 	// Disable mentions if they're disabled
1961
-	if (empty($modSettings['enable_mentions']))
1962
-		unset($alert_types['msg']['msg_mention']);
2058
+	if (empty($modSettings['enable_mentions'])) {
2059
+			unset($alert_types['msg']['msg_mention']);
2060
+	}
1963 2061
 
1964 2062
 	// Disable likes if they're disabled
1965
-	if (empty($modSettings['enable_likes']))
1966
-		unset($alert_types['msg']['msg_like']);
2063
+	if (empty($modSettings['enable_likes'])) {
2064
+			unset($alert_types['msg']['msg_like']);
2065
+	}
1967 2066
 
1968 2067
 	// Disable buddy requests if they're disabled
1969
-	if (empty($modSettings['enable_buddylist']))
1970
-		unset($alert_types['members']['buddy_request']);
2068
+	if (empty($modSettings['enable_buddylist'])) {
2069
+			unset($alert_types['members']['buddy_request']);
2070
+	}
1971 2071
 
1972 2072
 	// Now, now, we could pass this through global but we should really get into the habit of
1973 2073
 	// passing content to hooks, not expecting hooks to splatter everything everywhere.
@@ -1995,15 +2095,17 @@  discard block
 block discarded – undo
1995 2095
 			$perms_cache['manage_membergroups'] = in_array($memID, $members);
1996 2096
 		}
1997 2097
 
1998
-		if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
1999
-			unset($alert_types['members']['request_group']);
2098
+		if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) {
2099
+					unset($alert_types['members']['request_group']);
2100
+		}
2000 2101
 
2001 2102
 		foreach ($alert_types as $group => $items)
2002 2103
 		{
2003 2104
 			foreach ($items as $alert_key => $alert_value)
2004 2105
 			{
2005
-				if (!isset($alert_value['permission']))
2006
-					continue;
2106
+				if (!isset($alert_value['permission'])) {
2107
+									continue;
2108
+				}
2007 2109
 				if (!isset($perms_cache[$alert_value['permission']['name']]))
2008 2110
 				{
2009 2111
 					$in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
@@ -2011,12 +2113,14 @@  discard block
 block discarded – undo
2011 2113
 					$perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
2012 2114
 				}
2013 2115
 
2014
-				if (!$perms_cache[$alert_value['permission']['name']])
2015
-					unset ($alert_types[$group][$alert_key]);
2116
+				if (!$perms_cache[$alert_value['permission']['name']]) {
2117
+									unset ($alert_types[$group][$alert_key]);
2118
+				}
2016 2119
 			}
2017 2120
 
2018
-			if (empty($alert_types[$group]))
2019
-				unset ($alert_types[$group]);
2121
+			if (empty($alert_types[$group])) {
2122
+							unset ($alert_types[$group]);
2123
+			}
2020 2124
 		}
2021 2125
 	}
2022 2126
 
@@ -2048,9 +2152,9 @@  discard block
 block discarded – undo
2048 2152
 						$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
2049 2153
 						break;
2050 2154
 					case 'select':
2051
-						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
2052
-							$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2053
-						else
2155
+						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) {
2156
+													$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2157
+						} else
2054 2158
 						{
2055 2159
 							// We didn't have a sane value. Let's grab the first item from the possibles.
2056 2160
 							$keys = array_keys($this_option['opts']);
@@ -2070,23 +2174,28 @@  discard block
 block discarded – undo
2070 2174
 				$this_value = 0;
2071 2175
 				foreach ($context['alert_bits'] as $type => $bitvalue)
2072 2176
 				{
2073
-					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always')
2074
-						$this_value |= $bitvalue;
2177
+					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') {
2178
+											$this_value |= $bitvalue;
2179
+					}
2180
+				}
2181
+				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) {
2182
+									$update_prefs[$item_key] = $this_value;
2075 2183
 				}
2076
-				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value)
2077
-					$update_prefs[$item_key] = $this_value;
2078 2184
 			}
2079 2185
 		}
2080 2186
 
2081
-		if (!empty($_POST['opt_alert_timeout']))
2082
-			$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2187
+		if (!empty($_POST['opt_alert_timeout'])) {
2188
+					$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2189
+		}
2083 2190
 
2084
-		if (!empty($_POST['notify_announcements']))
2085
-			$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2191
+		if (!empty($_POST['notify_announcements'])) {
2192
+					$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2193
+		}
2086 2194
 
2087 2195
 		setNotifyPrefs((int) $memID, $update_prefs);
2088
-		foreach ($update_prefs as $pref => $value)
2089
-			$context['alert_prefs'][$pref] = $value;
2196
+		foreach ($update_prefs as $pref => $value) {
2197
+					$context['alert_prefs'][$pref] = $value;
2198
+		}
2090 2199
 
2091 2200
 		makeNotificationChanges($memID);
2092 2201
 
@@ -2116,8 +2225,9 @@  discard block
 block discarded – undo
2116 2225
 
2117 2226
 	// Now we're all set up.
2118 2227
 	is_not_guest();
2119
-	if (!$context['user']['is_owner'])
2120
-		fatal_error('no_access');
2228
+	if (!$context['user']['is_owner']) {
2229
+			fatal_error('no_access');
2230
+	}
2121 2231
 
2122 2232
 	checkSession('get');
2123 2233
 
@@ -2149,8 +2259,9 @@  discard block
 block discarded – undo
2149 2259
 {
2150 2260
 	global $smcFunc;
2151 2261
 
2152
-	if (empty($toMark) || empty($memID))
2153
-		return false;
2262
+	if (empty($toMark) || empty($memID)) {
2263
+			return false;
2264
+	}
2154 2265
 
2155 2266
 	$toMark = (array) $toMark;
2156 2267
 
@@ -2184,8 +2295,9 @@  discard block
 block discarded – undo
2184 2295
 {
2185 2296
 	global $smcFunc;
2186 2297
 
2187
-	if (empty($toDelete))
2188
-		return false;
2298
+	if (empty($toDelete)) {
2299
+			return false;
2300
+	}
2189 2301
 
2190 2302
 	$toDelete = (array) $toDelete;
2191 2303
 
@@ -2220,8 +2332,9 @@  discard block
 block discarded – undo
2220 2332
 {
2221 2333
 	global $smcFunc;
2222 2334
 
2223
-	if (empty($memID))
2224
-		return false;
2335
+	if (empty($memID)) {
2336
+			return false;
2337
+	}
2225 2338
 
2226 2339
 	$request = $smcFunc['db_query']('', '
2227 2340
 		SELECT id_alert
@@ -2298,8 +2411,9 @@  discard block
 block discarded – undo
2298 2411
 					{
2299 2412
 						$link = $topic['link'];
2300 2413
 
2301
-						if ($topic['new'])
2302
-							$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2414
+						if ($topic['new']) {
2415
+													$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2416
+						}
2303 2417
 
2304 2418
 						$link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>';
2305 2419
 
@@ -2450,8 +2564,9 @@  discard block
 block discarded – undo
2450 2564
 					{
2451 2565
 						$link = $board['link'];
2452 2566
 
2453
-						if ($board['new'])
2454
-							$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2567
+						if ($board['new']) {
2568
+													$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2569
+						}
2455 2570
 
2456 2571
 						return $link;
2457 2572
 					},
@@ -2651,8 +2766,8 @@  discard block
 block discarded – undo
2651 2766
 		)
2652 2767
 	);
2653 2768
 	$notification_boards = array();
2654
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2655
-		$notification_boards[] = array(
2769
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2770
+			$notification_boards[] = array(
2656 2771
 			'id' => $row['id_board'],
2657 2772
 			'name' => $row['name'],
2658 2773
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
@@ -2660,6 +2775,7 @@  discard block
 block discarded – undo
2660 2775
 			'new' => $row['board_read'] < $row['id_msg_updated'],
2661 2776
 			'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0),
2662 2777
 		);
2778
+	}
2663 2779
 	$smcFunc['db_free_result']($request);
2664 2780
 
2665 2781
 	return $notification_boards;
@@ -2674,17 +2790,18 @@  discard block
 block discarded – undo
2674 2790
 {
2675 2791
 	global $context, $options, $cur_profile, $smcFunc;
2676 2792
 
2677
-	if (isset($_POST['default_options']))
2678
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2793
+	if (isset($_POST['default_options'])) {
2794
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2795
+	}
2679 2796
 
2680 2797
 	if ($context['user']['is_owner'])
2681 2798
 	{
2682 2799
 		$context['member']['options'] = $options;
2683
-		if (isset($_POST['options']) && is_array($_POST['options']))
2684
-			foreach ($_POST['options'] as $k => $v)
2800
+		if (isset($_POST['options']) && is_array($_POST['options'])) {
2801
+					foreach ($_POST['options'] as $k => $v)
2685 2802
 				$context['member']['options'][$k] = $v;
2686
-	}
2687
-	else
2803
+		}
2804
+	} else
2688 2805
 	{
2689 2806
 		$request = $smcFunc['db_query']('', '
2690 2807
 			SELECT id_member, variable, value
@@ -2705,8 +2822,9 @@  discard block
 block discarded – undo
2705 2822
 				continue;
2706 2823
 			}
2707 2824
 
2708
-			if (isset($_POST['options'][$row['variable']]))
2709
-				$row['value'] = $_POST['options'][$row['variable']];
2825
+			if (isset($_POST['options'][$row['variable']])) {
2826
+							$row['value'] = $_POST['options'][$row['variable']];
2827
+			}
2710 2828
 			$context['member']['options'][$row['variable']] = $row['value'];
2711 2829
 		}
2712 2830
 		$smcFunc['db_free_result']($request);
@@ -2714,8 +2832,9 @@  discard block
 block discarded – undo
2714 2832
 		// Load up the default theme options for any missing.
2715 2833
 		foreach ($temp as $k => $v)
2716 2834
 		{
2717
-			if (!isset($context['member']['options'][$k]))
2718
-				$context['member']['options'][$k] = $v;
2835
+			if (!isset($context['member']['options'][$k])) {
2836
+							$context['member']['options'][$k] = $v;
2837
+			}
2719 2838
 		}
2720 2839
 	}
2721 2840
 }
@@ -2730,8 +2849,9 @@  discard block
 block discarded – undo
2730 2849
 	global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir;
2731 2850
 
2732 2851
 	// Have the admins enabled this option?
2733
-	if (empty($modSettings['allow_ignore_boards']))
2734
-		fatal_lang_error('ignoreboards_disallowed', 'user');
2852
+	if (empty($modSettings['allow_ignore_boards'])) {
2853
+			fatal_lang_error('ignoreboards_disallowed', 'user');
2854
+	}
2735 2855
 
2736 2856
 	// Find all the boards this user is allowed to see.
2737 2857
 	$request = $smcFunc['db_query']('order_by_board_order', '
@@ -2751,12 +2871,13 @@  discard block
 block discarded – undo
2751 2871
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2752 2872
 	{
2753 2873
 		// This category hasn't been set up yet..
2754
-		if (!isset($context['categories'][$row['id_cat']]))
2755
-			$context['categories'][$row['id_cat']] = array(
2874
+		if (!isset($context['categories'][$row['id_cat']])) {
2875
+					$context['categories'][$row['id_cat']] = array(
2756 2876
 				'id' => $row['id_cat'],
2757 2877
 				'name' => $row['cat_name'],
2758 2878
 				'boards' => array()
2759 2879
 			);
2880
+		}
2760 2881
 
2761 2882
 		// Set this board up, and let the template know when it's a child.  (indent them..)
2762 2883
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -2786,18 +2907,20 @@  discard block
 block discarded – undo
2786 2907
 	}
2787 2908
 
2788 2909
 	$max_boards = ceil(count($temp_boards) / 2);
2789
-	if ($max_boards == 1)
2790
-		$max_boards = 2;
2910
+	if ($max_boards == 1) {
2911
+			$max_boards = 2;
2912
+	}
2791 2913
 
2792 2914
 	// Now, alternate them so they can be shown left and right ;).
2793 2915
 	$context['board_columns'] = array();
2794 2916
 	for ($i = 0; $i < $max_boards; $i++)
2795 2917
 	{
2796 2918
 		$context['board_columns'][] = $temp_boards[$i];
2797
-		if (isset($temp_boards[$i + $max_boards]))
2798
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
2799
-		else
2800
-			$context['board_columns'][] = array();
2919
+		if (isset($temp_boards[$i + $max_boards])) {
2920
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
2921
+		} else {
2922
+					$context['board_columns'][] = array();
2923
+		}
2801 2924
 	}
2802 2925
 
2803 2926
 	loadThemeOptions($memID);
@@ -2866,8 +2989,9 @@  discard block
 block discarded – undo
2866 2989
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2867 2990
 	{
2868 2991
 		// We should skip the administrator group if they don't have the admin_forum permission!
2869
-		if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
2870
-			continue;
2992
+		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) {
2993
+					continue;
2994
+		}
2871 2995
 
2872 2996
 		$context['member_groups'][$row['id_group']] = array(
2873 2997
 			'id' => $row['id_group'],
@@ -2913,16 +3037,17 @@  discard block
 block discarded – undo
2913 3037
 	$context['max_signature_length'] = $context['signature_limits']['max_length'];
2914 3038
 	// Warning message for signature image limits?
2915 3039
 	$context['signature_warning'] = '';
2916
-	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
2917
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
2918
-	elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
2919
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3040
+	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) {
3041
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
3042
+	} elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) {
3043
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3044
+	}
2920 3045
 
2921 3046
 	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
2922 3047
 
2923
-	if (empty($context['do_preview']))
2924
-		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
2925
-	else
3048
+	if (empty($context['do_preview'])) {
3049
+			$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
3050
+	} else
2926 3051
 	{
2927 3052
 		$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
2928 3053
 		$validation = profileValidateSignature($signature);
@@ -2932,8 +3057,9 @@  discard block
 block discarded – undo
2932 3057
 			$context['post_errors'] = array();
2933 3058
 		}
2934 3059
 		$context['post_errors'][] = 'signature_not_yet_saved';
2935
-		if ($validation !== true && $validation !== false)
2936
-			$context['post_errors'][] = $validation;
3060
+		if ($validation !== true && $validation !== false) {
3061
+					$context['post_errors'][] = $validation;
3062
+		}
2937 3063
 
2938 3064
 		censorText($context['member']['signature']);
2939 3065
 		$context['member']['current_signature'] = $context['member']['signature'];
@@ -2943,8 +3069,9 @@  discard block
 block discarded – undo
2943 3069
 	}
2944 3070
 
2945 3071
 	// Load the spell checker?
2946
-	if ($context['show_spellchecking'])
2947
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3072
+	if ($context['show_spellchecking']) {
3073
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3074
+	}
2948 3075
 
2949 3076
 	return true;
2950 3077
 }
@@ -2978,8 +3105,7 @@  discard block
 block discarded – undo
2978 3105
 			'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11)
2979 3106
 		);
2980 3107
 		$context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']);
2981
-	}
2982
-	elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3108
+	} elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
2983 3109
 	{
2984 3110
 		$context['member']['avatar'] += array(
2985 3111
 			'choice' => 'upload',
@@ -2987,34 +3113,34 @@  discard block
 block discarded – undo
2987 3113
 			'external' => 'http://'
2988 3114
 		);
2989 3115
 		$context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename'];
2990
-	}
2991
-	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
2992
-		$context['member']['avatar'] += array(
3116
+	} elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) {
3117
+			$context['member']['avatar'] += array(
2993 3118
 			'choice' => 'external',
2994 3119
 			'server_pic' => 'blank.png',
2995 3120
 			'external' => $cur_profile['avatar']
2996 3121
 		);
2997
-	elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
2998
-		$context['member']['avatar'] += array(
3122
+	} elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) {
3123
+			$context['member']['avatar'] += array(
2999 3124
 			'choice' => 'server_stored',
3000 3125
 			'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
3001 3126
 			'external' => 'http://'
3002 3127
 		);
3003
-	else
3004
-		$context['member']['avatar'] += array(
3128
+	} else {
3129
+			$context['member']['avatar'] += array(
3005 3130
 			'choice' => 'none',
3006 3131
 			'server_pic' => 'blank.png',
3007 3132
 			'external' => 'http://'
3008 3133
 		);
3134
+	}
3009 3135
 
3010 3136
 	// Get a list of all the avatars.
3011 3137
 	if ($context['member']['avatar']['allow_server_stored'])
3012 3138
 	{
3013 3139
 		$context['avatar_list'] = array();
3014 3140
 		$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
3141
+	} else {
3142
+			$context['avatars'] = array();
3015 3143
 	}
3016
-	else
3017
-		$context['avatars'] = array();
3018 3144
 
3019 3145
 	// Second level selected avatar...
3020 3146
 	$context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
@@ -3043,19 +3169,22 @@  discard block
 block discarded – undo
3043 3169
 			)
3044 3170
 		);
3045 3171
 		$protected_groups = array(1);
3046
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3047
-			$protected_groups[] = $row['id_group'];
3172
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3173
+					$protected_groups[] = $row['id_group'];
3174
+		}
3048 3175
 		$smcFunc['db_free_result']($request);
3049 3176
 
3050 3177
 		$protected_groups = array_unique($protected_groups);
3051 3178
 	}
3052 3179
 
3053 3180
 	// The account page allows the change of your id_group - but not to a protected group!
3054
-	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
3055
-		$value = (int) $value;
3181
+	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) {
3182
+			$value = (int) $value;
3183
+	}
3056 3184
 	// ... otherwise it's the old group sir.
3057
-	else
3058
-		$value = $old_profile['id_group'];
3185
+	else {
3186
+			$value = $old_profile['id_group'];
3187
+	}
3059 3188
 
3060 3189
 	// Find the additional membergroups (if any)
3061 3190
 	if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
@@ -3064,16 +3193,18 @@  discard block
 block discarded – undo
3064 3193
 		foreach ($_POST['additional_groups'] as $group_id)
3065 3194
 		{
3066 3195
 			$group_id = (int) $group_id;
3067
-			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
3068
-				$additional_groups[] = $group_id;
3196
+			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) {
3197
+							$additional_groups[] = $group_id;
3198
+			}
3069 3199
 		}
3070 3200
 
3071 3201
 		// Put the protected groups back in there if you don't have permission to take them away.
3072 3202
 		$old_additional_groups = explode(',', $old_profile['additional_groups']);
3073 3203
 		foreach ($old_additional_groups as $group_id)
3074 3204
 		{
3075
-			if (!empty($protected_groups) && in_array($group_id, $protected_groups))
3076
-				$additional_groups[] = $group_id;
3205
+			if (!empty($protected_groups) && in_array($group_id, $protected_groups)) {
3206
+							$additional_groups[] = $group_id;
3207
+			}
3077 3208
 		}
3078 3209
 
3079 3210
 		if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
@@ -3105,18 +3236,20 @@  discard block
 block discarded – undo
3105 3236
 			list ($another) = $smcFunc['db_fetch_row']($request);
3106 3237
 			$smcFunc['db_free_result']($request);
3107 3238
 
3108
-			if (empty($another))
3109
-				fatal_lang_error('at_least_one_admin', 'critical');
3239
+			if (empty($another)) {
3240
+							fatal_lang_error('at_least_one_admin', 'critical');
3241
+			}
3110 3242
 		}
3111 3243
 	}
3112 3244
 
3113 3245
 	// If we are changing group status, update permission cache as necessary.
3114 3246
 	if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
3115 3247
 	{
3116
-		if ($context['user']['is_owner'])
3117
-			$_SESSION['mc']['time'] = 0;
3118
-		else
3119
-			updateSettings(array('settings_updated' => time()));
3248
+		if ($context['user']['is_owner']) {
3249
+					$_SESSION['mc']['time'] = 0;
3250
+		} else {
3251
+					updateSettings(array('settings_updated' => time()));
3252
+		}
3120 3253
 	}
3121 3254
 
3122 3255
 	// Announce to any hooks that we have changed groups, but don't allow them to change it.
@@ -3137,8 +3270,9 @@  discard block
 block discarded – undo
3137 3270
 	global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
3138 3271
 
3139 3272
 	$memID = $context['id_member'];
3140
-	if (empty($memID) && !empty($context['password_auth_failed']))
3141
-		return false;
3273
+	if (empty($memID) && !empty($context['password_auth_failed'])) {
3274
+			return false;
3275
+	}
3142 3276
 
3143 3277
 	require_once($sourcedir . '/ManageAttachments.php');
3144 3278
 
@@ -3149,8 +3283,9 @@  discard block
 block discarded – undo
3149 3283
 	$downloadedExternalAvatar = false;
3150 3284
 	if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external']))
3151 3285
 	{
3152
-		if (!is_writable($uploadDir))
3153
-			fatal_lang_error('attachments_no_write', 'critical');
3286
+		if (!is_writable($uploadDir)) {
3287
+					fatal_lang_error('attachments_no_write', 'critical');
3288
+		}
3154 3289
 
3155 3290
 		require_once($sourcedir . '/Subs-Package.php');
3156 3291
 
@@ -3194,19 +3329,18 @@  discard block
 block discarded – undo
3194 3329
 
3195 3330
 		// Get rid of their old avatar. (if uploaded.)
3196 3331
 		removeAttachments(array('id_member' => $memID));
3197
-	}
3198
-	elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3332
+	} elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3199 3333
 	{
3200 3334
 		// One wasn't specified, or it's not allowed to use extra email addresses, or it's not a valid one, reset to default Gravatar.
3201
-		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL))
3202
-			$profile_vars['avatar'] = 'gravatar://';
3203
-		else
3204
-			$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3335
+		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) {
3336
+					$profile_vars['avatar'] = 'gravatar://';
3337
+		} else {
3338
+					$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3339
+		}
3205 3340
 
3206 3341
 		// Get rid of their old avatar. (if uploaded.)
3207 3342
 		removeAttachments(array('id_member' => $memID));
3208
-	}
3209
-	elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3343
+	} elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3210 3344
 	{
3211 3345
 		// We need these clean...
3212 3346
 		$cur_profile['id_attach'] = 0;
@@ -3218,11 +3352,13 @@  discard block
 block discarded – undo
3218 3352
 
3219 3353
 		$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
3220 3354
 
3221
-		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
3222
-			$profile_vars['avatar'] = '';
3355
+		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') {
3356
+					$profile_vars['avatar'] = '';
3357
+		}
3223 3358
 		// Trying to make us do something we'll regret?
3224
-		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
3225
-			return 'bad_avatar_invalid_url';
3359
+		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') {
3360
+					return 'bad_avatar_invalid_url';
3361
+		}
3226 3362
 		// Should we check dimensions?
3227 3363
 		elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
3228 3364
 		{
@@ -3232,9 +3368,9 @@  discard block
 block discarded – undo
3232 3368
 			if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
3233 3369
 			{
3234 3370
 				// Houston, we have a problem. The avatar is too large!!
3235
-				if ($modSettings['avatar_action_too_large'] == 'option_refuse')
3236
-					return 'bad_avatar_too_large';
3237
-				elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3371
+				if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
3372
+									return 'bad_avatar_too_large';
3373
+				} elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3238 3374
 				{
3239 3375
 					// @todo remove this if appropriate
3240 3376
 					require_once($sourcedir . '/Subs-Graphics.php');
@@ -3244,26 +3380,27 @@  discard block
 block discarded – undo
3244 3380
 						$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
3245 3381
 						$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
3246 3382
 						$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
3383
+					} else {
3384
+											return 'bad_avatar';
3247 3385
 					}
3248
-					else
3249
-						return 'bad_avatar';
3250 3386
 				}
3251 3387
 			}
3252 3388
 		}
3253
-	}
3254
-	elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3389
+	} elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3255 3390
 	{
3256 3391
 		if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
3257 3392
 		{
3258 3393
 			// Get the dimensions of the image.
3259 3394
 			if (!$downloadedExternalAvatar)
3260 3395
 			{
3261
-				if (!is_writable($uploadDir))
3262
-					fatal_lang_error('attachments_no_write', 'critical');
3396
+				if (!is_writable($uploadDir)) {
3397
+									fatal_lang_error('attachments_no_write', 'critical');
3398
+				}
3263 3399
 
3264 3400
 				$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
3265
-				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
3266
-					fatal_lang_error('attach_timeout', 'critical');
3401
+				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) {
3402
+									fatal_lang_error('attach_timeout', 'critical');
3403
+				}
3267 3404
 
3268 3405
 				$_FILES['attachment']['tmp_name'] = $new_filename;
3269 3406
 			}
@@ -3376,17 +3513,19 @@  discard block
 block discarded – undo
3376 3513
 			$profile_vars['avatar'] = '';
3377 3514
 
3378 3515
 			// Delete any temporary file.
3379
-			if (file_exists($_FILES['attachment']['tmp_name']))
3380
-				@unlink($_FILES['attachment']['tmp_name']);
3516
+			if (file_exists($_FILES['attachment']['tmp_name'])) {
3517
+							@unlink($_FILES['attachment']['tmp_name']);
3518
+			}
3381 3519
 		}
3382 3520
 		// Selected the upload avatar option and had one already uploaded before or didn't upload one.
3383
-		else
3521
+		else {
3522
+					$profile_vars['avatar'] = '';
3523
+		}
3524
+	} elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) {
3525
+			$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3526
+	} else {
3384 3527
 			$profile_vars['avatar'] = '';
3385 3528
 	}
3386
-	elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar'))
3387
-		$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3388
-	else
3389
-		$profile_vars['avatar'] = '';
3390 3529
 
3391 3530
 	// Setup the profile variables so it shows things right on display!
3392 3531
 	$cur_profile['avatar'] = $profile_vars['avatar'];
@@ -3434,9 +3573,9 @@  discard block
 block discarded – undo
3434 3573
 		$smiley_parsed = $unparsed_signature;
3435 3574
 		parsesmileys($smiley_parsed);
3436 3575
 		$smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
3437
-		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
3438
-			return 'signature_allow_smileys';
3439
-		elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3576
+		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) {
3577
+					return 'signature_allow_smileys';
3578
+		} elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3440 3579
 		{
3441 3580
 			$txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
3442 3581
 			return 'signature_max_smileys';
@@ -3449,14 +3588,15 @@  discard block
 block discarded – undo
3449 3588
 			{
3450 3589
 				$limit_broke = 0;
3451 3590
 				// Attempt to allow all sizes of abuse, so to speak.
3452
-				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
3453
-					$limit_broke = $sig_limits[7] . 'px';
3454
-				elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
3455
-					$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3456
-				elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
3457
-					$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3458
-				elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
3459
-					$limit_broke = 'large';
3591
+				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
3592
+									$limit_broke = $sig_limits[7] . 'px';
3593
+				} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
3594
+									$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3595
+				} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
3596
+									$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3597
+				} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
3598
+									$limit_broke = 'large';
3599
+				}
3460 3600
 
3461 3601
 				if ($limit_broke)
3462 3602
 				{
@@ -3498,24 +3638,26 @@  discard block
 block discarded – undo
3498 3638
 					$width = -1; $height = -1;
3499 3639
 
3500 3640
 					// Does it have predefined restraints? Width first.
3501
-					if ($matches[6][$key])
3502
-						$matches[2][$key] = $matches[6][$key];
3641
+					if ($matches[6][$key]) {
3642
+											$matches[2][$key] = $matches[6][$key];
3643
+					}
3503 3644
 					if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
3504 3645
 					{
3505 3646
 						$width = $sig_limits[5];
3506 3647
 						$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
3648
+					} elseif ($matches[2][$key]) {
3649
+											$width = $matches[2][$key];
3507 3650
 					}
3508
-					elseif ($matches[2][$key])
3509
-						$width = $matches[2][$key];
3510 3651
 					// ... and height.
3511 3652
 					if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
3512 3653
 					{
3513 3654
 						$height = $sig_limits[6];
3514
-						if ($width != -1)
3515
-							$width = $width * ($height / $matches[4][$key]);
3655
+						if ($width != -1) {
3656
+													$width = $width * ($height / $matches[4][$key]);
3657
+						}
3658
+					} elseif ($matches[4][$key]) {
3659
+											$height = $matches[4][$key];
3516 3660
 					}
3517
-					elseif ($matches[4][$key])
3518
-						$height = $matches[4][$key];
3519 3661
 
3520 3662
 					// If the dimensions are still not fixed - we need to check the actual image.
3521 3663
 					if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -3533,21 +3675,24 @@  discard block
 block discarded – undo
3533 3675
 							if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
3534 3676
 							{
3535 3677
 								$height = $sig_limits[6];
3536
-								if ($width == -1)
3537
-									$width = $sizes[0];
3678
+								if ($width == -1) {
3679
+																	$width = $sizes[0];
3680
+								}
3538 3681
 								$width = $width * ($height / $sizes[1]);
3682
+							} elseif ($width != -1) {
3683
+															$height = $sizes[1];
3539 3684
 							}
3540
-							elseif ($width != -1)
3541
-								$height = $sizes[1];
3542 3685
 						}
3543 3686
 					}
3544 3687
 
3545 3688
 					// Did we come up with some changes? If so remake the string.
3546
-					if ($width != -1 || $height != -1)
3547
-						$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3689
+					if ($width != -1 || $height != -1) {
3690
+											$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3691
+					}
3692
+				}
3693
+				if (!empty($replaces)) {
3694
+									$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3548 3695
 				}
3549
-				if (!empty($replaces))
3550
-					$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3551 3696
 			}
3552 3697
 		}
3553 3698
 
@@ -3591,10 +3736,12 @@  discard block
 block discarded – undo
3591 3736
 	$email = strtr($email, array('&#039;' => '\''));
3592 3737
 
3593 3738
 	// Check the name and email for validity.
3594
-	if (trim($email) == '')
3595
-		return 'no_email';
3596
-	if (!filter_var($email, FILTER_VALIDATE_EMAIL))
3597
-		return 'bad_email';
3739
+	if (trim($email) == '') {
3740
+			return 'no_email';
3741
+	}
3742
+	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
3743
+			return 'bad_email';
3744
+	}
3598 3745
 
3599 3746
 	// Email addresses should be and stay unique.
3600 3747
 	$request = $smcFunc['db_query']('', '
@@ -3609,8 +3756,9 @@  discard block
 block discarded – undo
3609 3756
 		)
3610 3757
 	);
3611 3758
 
3612
-	if ($smcFunc['db_num_rows']($request) > 0)
3613
-		return 'email_taken';
3759
+	if ($smcFunc['db_num_rows']($request) > 0) {
3760
+			return 'email_taken';
3761
+	}
3614 3762
 	$smcFunc['db_free_result']($request);
3615 3763
 
3616 3764
 	return true;
@@ -3623,8 +3771,9 @@  discard block
 block discarded – undo
3623 3771
 {
3624 3772
 	global $modSettings, $context, $cur_profile;
3625 3773
 
3626
-	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
3627
-		setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3774
+	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') {
3775
+			setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3776
+	}
3628 3777
 
3629 3778
 	loadUserSettings();
3630 3779
 	writeLog();
@@ -3640,8 +3789,9 @@  discard block
 block discarded – undo
3640 3789
 	require_once($sourcedir . '/Subs-Post.php');
3641 3790
 
3642 3791
 	// Shouldn't happen but just in case.
3643
-	if (empty($profile_vars['email_address']))
3644
-		return;
3792
+	if (empty($profile_vars['email_address'])) {
3793
+			return;
3794
+	}
3645 3795
 
3646 3796
 	$replacements = array(
3647 3797
 		'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
@@ -3664,8 +3814,9 @@  discard block
 block discarded – undo
3664 3814
 	$_SESSION['log_time'] = 0;
3665 3815
 	$_SESSION['login_' . $cookiename] = json_encode(array(0, '', 0));
3666 3816
 
3667
-	if (isset($_COOKIE[$cookiename]))
3668
-		$_COOKIE[$cookiename] = '';
3817
+	if (isset($_COOKIE[$cookiename])) {
3818
+			$_COOKIE[$cookiename] = '';
3819
+	}
3669 3820
 
3670 3821
 	loadUserSettings();
3671 3822
 
@@ -3698,11 +3849,13 @@  discard block
 block discarded – undo
3698 3849
 	$groups[] = $curMember['id_group'];
3699 3850
 
3700 3851
 	// Ensure the query doesn't croak!
3701
-	if (empty($groups))
3702
-		$groups = array(0);
3852
+	if (empty($groups)) {
3853
+			$groups = array(0);
3854
+	}
3703 3855
 	// Just to be sure...
3704
-	foreach ($groups as $k => $v)
3705
-		$groups[$k] = (int) $v;
3856
+	foreach ($groups as $k => $v) {
3857
+			$groups[$k] = (int) $v;
3858
+	}
3706 3859
 
3707 3860
 	// Get all the membergroups they can join.
3708 3861
 	$request = $smcFunc['db_query']('', '
@@ -3732,12 +3885,14 @@  discard block
 block discarded – undo
3732 3885
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3733 3886
 	{
3734 3887
 		// Can they edit their primary group?
3735
-		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
3736
-			$context['can_edit_primary'] = true;
3888
+		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) {
3889
+					$context['can_edit_primary'] = true;
3890
+		}
3737 3891
 
3738 3892
 		// If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
3739
-		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
3740
-			continue;
3893
+		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) {
3894
+					continue;
3895
+		}
3741 3896
 
3742 3897
 		$context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
3743 3898
 			'id' => $row['id_group'],
@@ -3766,13 +3921,15 @@  discard block
 block discarded – undo
3766 3921
 	);
3767 3922
 
3768 3923
 	// No changing primary one unless you have enough groups!
3769
-	if (count($context['groups']['member']) < 2)
3770
-		$context['can_edit_primary'] = false;
3924
+	if (count($context['groups']['member']) < 2) {
3925
+			$context['can_edit_primary'] = false;
3926
+	}
3771 3927
 
3772 3928
 	// In the special case that someone is requesting membership of a group, setup some special context vars.
3773
-	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
3774
-		$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3775
-}
3929
+	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) {
3930
+			$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3931
+	}
3932
+	}
3776 3933
 
3777 3934
 /**
3778 3935
  * This function actually makes all the group changes
@@ -3787,10 +3944,12 @@  discard block
 block discarded – undo
3787 3944
 	global $user_info, $context, $user_profile, $modSettings, $smcFunc;
3788 3945
 
3789 3946
 	// Let's be extra cautious...
3790
-	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
3791
-		isAllowedTo('manage_membergroups');
3792
-	if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
3793
-		fatal_lang_error('no_access', false);
3947
+	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) {
3948
+			isAllowedTo('manage_membergroups');
3949
+	}
3950
+	if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) {
3951
+			fatal_lang_error('no_access', false);
3952
+	}
3794 3953
 
3795 3954
 	checkSession(isset($_GET['gid']) ? 'get' : 'post');
3796 3955
 
@@ -3809,8 +3968,9 @@  discard block
 block discarded – undo
3809 3968
 	$foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
3810 3969
 
3811 3970
 	// Sanity check!!
3812
-	if ($group_id == 1)
3813
-		isAllowedTo('admin_forum');
3971
+	if ($group_id == 1) {
3972
+			isAllowedTo('admin_forum');
3973
+	}
3814 3974
 	// Protected groups too!
3815 3975
 	else
3816 3976
 	{
@@ -3827,8 +3987,9 @@  discard block
 block discarded – undo
3827 3987
 		list ($is_protected) = $smcFunc['db_fetch_row']($request);
3828 3988
 		$smcFunc['db_free_result']($request);
3829 3989
 
3830
-		if ($is_protected == 1)
3831
-			isAllowedTo('admin_forum');
3990
+		if ($is_protected == 1) {
3991
+					isAllowedTo('admin_forum');
3992
+		}
3832 3993
 	}
3833 3994
 
3834 3995
 	// What ever we are doing, we need to determine if changing primary is possible!
@@ -3850,36 +4011,43 @@  discard block
 block discarded – undo
3850 4011
 			$group_name = $row['group_name'];
3851 4012
 
3852 4013
 			// Does the group type match what we're doing - are we trying to request a non-requestable group?
3853
-			if ($changeType == 'request' && $row['group_type'] != 2)
3854
-				fatal_lang_error('no_access', false);
4014
+			if ($changeType == 'request' && $row['group_type'] != 2) {
4015
+							fatal_lang_error('no_access', false);
4016
+			}
3855 4017
 			// What about leaving a requestable group we are not a member of?
3856
-			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
3857
-				fatal_lang_error('no_access', false);
3858
-			elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
3859
-				fatal_lang_error('no_access', false);
4018
+			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) {
4019
+							fatal_lang_error('no_access', false);
4020
+			} elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) {
4021
+							fatal_lang_error('no_access', false);
4022
+			}
3860 4023
 
3861 4024
 			// We can't change the primary group if this is hidden!
3862
-			if ($row['hidden'] == 2)
3863
-				$canChangePrimary = false;
4025
+			if ($row['hidden'] == 2) {
4026
+							$canChangePrimary = false;
4027
+			}
3864 4028
 		}
3865 4029
 
3866 4030
 		// If this is their old primary, can we change it?
3867
-		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
3868
-			$canChangePrimary = 1;
4031
+		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) {
4032
+					$canChangePrimary = 1;
4033
+		}
3869 4034
 
3870 4035
 		// If we are not doing a force primary move, don't do it automatically if current primary is not 0.
3871
-		if ($changeType != 'primary' && $old_profile['id_group'] != 0)
3872
-			$canChangePrimary = false;
4036
+		if ($changeType != 'primary' && $old_profile['id_group'] != 0) {
4037
+					$canChangePrimary = false;
4038
+		}
3873 4039
 
3874 4040
 		// If this is the one we are acting on, can we even act?
3875
-		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
3876
-			$canChangePrimary = false;
4041
+		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) {
4042
+					$canChangePrimary = false;
4043
+		}
3877 4044
 	}
3878 4045
 	$smcFunc['db_free_result']($request);
3879 4046
 
3880 4047
 	// Didn't find the target?
3881
-	if (!$foundTarget)
3882
-		fatal_lang_error('no_access', false);
4048
+	if (!$foundTarget) {
4049
+			fatal_lang_error('no_access', false);
4050
+	}
3883 4051
 
3884 4052
 	// Final security check, don't allow users to promote themselves to admin.
3885 4053
 	if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
@@ -3899,8 +4067,9 @@  discard block
 block discarded – undo
3899 4067
 		list ($disallow) = $smcFunc['db_fetch_row']($request);
3900 4068
 		$smcFunc['db_free_result']($request);
3901 4069
 
3902
-		if ($disallow)
3903
-			isAllowedTo('admin_forum');
4070
+		if ($disallow) {
4071
+					isAllowedTo('admin_forum');
4072
+		}
3904 4073
 	}
3905 4074
 
3906 4075
 	// If we're requesting, add the note then return.
@@ -3918,8 +4087,9 @@  discard block
 block discarded – undo
3918 4087
 				'status_open' => 0,
3919 4088
 			)
3920 4089
 		);
3921
-		if ($smcFunc['db_num_rows']($request) != 0)
3922
-			fatal_lang_error('profile_error_already_requested_group');
4090
+		if ($smcFunc['db_num_rows']($request) != 0) {
4091
+					fatal_lang_error('profile_error_already_requested_group');
4092
+		}
3923 4093
 		$smcFunc['db_free_result']($request);
3924 4094
 
3925 4095
 		// Log the request.
@@ -3953,10 +4123,11 @@  discard block
 block discarded – undo
3953 4123
 		// Are we leaving?
3954 4124
 		if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
3955 4125
 		{
3956
-			if ($old_profile['id_group'] == $group_id)
3957
-				$newPrimary = 0;
3958
-			else
3959
-				unset($addGroups[$group_id]);
4126
+			if ($old_profile['id_group'] == $group_id) {
4127
+							$newPrimary = 0;
4128
+			} else {
4129
+							unset($addGroups[$group_id]);
4130
+			}
3960 4131
 		}
3961 4132
 		// ... if not, must be joining.
3962 4133
 		else
@@ -3964,36 +4135,42 @@  discard block
 block discarded – undo
3964 4135
 			// Can we change the primary, and do we want to?
3965 4136
 			if ($canChangePrimary)
3966 4137
 			{
3967
-				if ($old_profile['id_group'] != 0)
3968
-					$addGroups[$old_profile['id_group']] = -1;
4138
+				if ($old_profile['id_group'] != 0) {
4139
+									$addGroups[$old_profile['id_group']] = -1;
4140
+				}
3969 4141
 				$newPrimary = $group_id;
3970 4142
 			}
3971 4143
 			// Otherwise it's an additional group...
3972
-			else
3973
-				$addGroups[$group_id] = -1;
4144
+			else {
4145
+							$addGroups[$group_id] = -1;
4146
+			}
3974 4147
 		}
3975 4148
 	}
3976 4149
 	// Finally, we must be setting the primary.
3977 4150
 	elseif ($canChangePrimary)
3978 4151
 	{
3979
-		if ($old_profile['id_group'] != 0)
3980
-			$addGroups[$old_profile['id_group']] = -1;
3981
-		if (isset($addGroups[$group_id]))
3982
-			unset($addGroups[$group_id]);
4152
+		if ($old_profile['id_group'] != 0) {
4153
+					$addGroups[$old_profile['id_group']] = -1;
4154
+		}
4155
+		if (isset($addGroups[$group_id])) {
4156
+					unset($addGroups[$group_id]);
4157
+		}
3983 4158
 		$newPrimary = $group_id;
3984 4159
 	}
3985 4160
 
3986 4161
 	// Finally, we can make the changes!
3987
-	foreach ($addGroups as $id => $dummy)
3988
-		if (empty($id))
4162
+	foreach ($addGroups as $id => $dummy) {
4163
+			if (empty($id))
3989 4164
 			unset($addGroups[$id]);
4165
+	}
3990 4166
 	$addGroups = implode(',', array_flip($addGroups));
3991 4167
 
3992 4168
 	// Ensure that we don't cache permissions if the group is changing.
3993
-	if ($context['user']['is_owner'])
3994
-		$_SESSION['mc']['time'] = 0;
3995
-	else
3996
-		updateSettings(array('settings_updated' => time()));
4169
+	if ($context['user']['is_owner']) {
4170
+			$_SESSION['mc']['time'] = 0;
4171
+	} else {
4172
+			updateSettings(array('settings_updated' => time()));
4173
+	}
3997 4174
 
3998 4175
 	updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
3999 4176
 
@@ -4016,8 +4193,9 @@  discard block
 block discarded – undo
4016 4193
 	if (empty($user_settings['tfa_secret']) && $context['user']['is_owner'])
4017 4194
 	{
4018 4195
 		// Check to ensure we're forcing SSL for authentication
4019
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
4020
-			fatal_lang_error('login_ssl_required');
4196
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
4197
+					fatal_lang_error('login_ssl_required');
4198
+		}
4021 4199
 
4022 4200
 		// In some cases (forced 2FA or backup code) they would be forced to be redirected here,
4023 4201
 		// we do not want too much AJAX to confuse them.
@@ -4054,8 +4232,7 @@  discard block
 block discarded – undo
4054 4232
 				$context['sub_template'] = 'tfasetup_backup';
4055 4233
 
4056 4234
 				return;
4057
-			}
4058
-			else
4235
+			} else
4059 4236
 			{
4060 4237
 				$context['tfa_secret'] = $_SESSION['tfa_secret'];
4061 4238
 				$context['tfa_error'] = !$valid_code;
@@ -4063,8 +4240,7 @@  discard block
 block discarded – undo
4063 4240
 				$context['tfa_pass_value'] = $_POST['passwd'];
4064 4241
 				$context['tfa_value'] = $_POST['tfa_code'];
4065 4242
 			}
4066
-		}
4067
-		else
4243
+		} else
4068 4244
 		{
4069 4245
 			$totp = new \TOTP\Auth();
4070 4246
 			$secret = $totp->generateCode();
@@ -4074,17 +4250,16 @@  discard block
 block discarded – undo
4074 4250
 		}
4075 4251
 
4076 4252
 		$context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']);
4077
-	}
4078
-	elseif (isset($_REQUEST['disable']))
4253
+	} elseif (isset($_REQUEST['disable']))
4079 4254
 	{
4080 4255
 		updateMemberData($memID, array(
4081 4256
 			'tfa_secret' => '',
4082 4257
 			'tfa_backup' => '',
4083 4258
 		));
4084 4259
 		redirectexit('action=profile;area=account;u=' . $memID);
4260
+	} else {
4261
+			redirectexit('action=profile;area=account;u=' . $memID);
4262
+	}
4085 4263
 	}
4086
-	else
4087
-		redirectexit('action=profile;area=account;u=' . $memID);
4088
-}
4089 4264
 
4090 4265
 ?>
4091 4266
\ No newline at end of file
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.
Sources/Subs.php 1 patch
Braces   +1279 added lines, -950 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
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,23 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($type == 'int' && ($val === '+' || $val === '-'))
@@ -390,8 +399,9 @@  discard block
 block discarded – undo
390 399
 		{
391 400
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
392 401
 			{
393
-				if ($match[1] != '+ ')
394
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
402
+				if ($match[1] != '+ ') {
403
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
404
+				}
395 405
 				$type = 'raw';
396 406
 			}
397 407
 		}
@@ -412,8 +422,9 @@  discard block
 block discarded – undo
412 422
 	// Clear any caching?
413 423
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
414 424
 	{
415
-		if (!is_array($members))
416
-			$members = array($members);
425
+		if (!is_array($members)) {
426
+					$members = array($members);
427
+		}
417 428
 
418 429
 		foreach ($members as $member)
419 430
 		{
@@ -446,29 +457,32 @@  discard block
 block discarded – undo
446 457
 {
447 458
 	global $modSettings, $smcFunc;
448 459
 
449
-	if (empty($changeArray) || !is_array($changeArray))
450
-		return;
460
+	if (empty($changeArray) || !is_array($changeArray)) {
461
+			return;
462
+	}
451 463
 
452 464
 	$toRemove = array();
453 465
 
454 466
 	// Go check if there is any setting to be removed.
455
-	foreach ($changeArray as $k => $v)
456
-		if ($v === null)
467
+	foreach ($changeArray as $k => $v) {
468
+			if ($v === null)
457 469
 		{
458 470
 			// Found some, remove them from the original array and add them to ours.
459 471
 			unset($changeArray[$k]);
472
+	}
460 473
 			$toRemove[] = $k;
461 474
 		}
462 475
 
463 476
 	// Proceed with the deletion.
464
-	if (!empty($toRemove))
465
-		$smcFunc['db_query']('', '
477
+	if (!empty($toRemove)) {
478
+			$smcFunc['db_query']('', '
466 479
 			DELETE FROM {db_prefix}settings
467 480
 			WHERE variable IN ({array_string:remove})',
468 481
 			array(
469 482
 				'remove' => $toRemove,
470 483
 			)
471 484
 		);
485
+	}
472 486
 
473 487
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
474 488
 	if ($update)
@@ -497,19 +511,22 @@  discard block
 block discarded – undo
497 511
 	foreach ($changeArray as $variable => $value)
498 512
 	{
499 513
 		// Don't bother if it's already like that ;).
500
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
501
-			continue;
514
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
515
+					continue;
516
+		}
502 517
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
503
-		elseif (!isset($modSettings[$variable]) && empty($value))
504
-			continue;
518
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
519
+					continue;
520
+		}
505 521
 
506 522
 		$replaceArray[] = array($variable, $value);
507 523
 
508 524
 		$modSettings[$variable] = $value;
509 525
 	}
510 526
 
511
-	if (empty($replaceArray))
512
-		return;
527
+	if (empty($replaceArray)) {
528
+			return;
529
+	}
513 530
 
514 531
 	$smcFunc['db_insert']('replace',
515 532
 		'{db_prefix}settings',
@@ -555,14 +572,17 @@  discard block
 block discarded – undo
555 572
 	$start_invalid = $start < 0;
556 573
 
557 574
 	// Make sure $start is a proper variable - not less than 0.
558
-	if ($start_invalid)
559
-		$start = 0;
575
+	if ($start_invalid) {
576
+			$start = 0;
577
+	}
560 578
 	// Not greater than the upper bound.
561
-	elseif ($start >= $max_value)
562
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
579
+	elseif ($start >= $max_value) {
580
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
581
+	}
563 582
 	// And it has to be a multiple of $num_per_page!
564
-	else
565
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
583
+	else {
584
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
585
+	}
566 586
 
567 587
 	$context['current_page'] = $start / $num_per_page;
568 588
 
@@ -592,77 +612,87 @@  discard block
 block discarded – undo
592 612
 
593 613
 		// Show all the pages.
594 614
 		$display_page = 1;
595
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
596
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
615
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
616
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
617
+		}
597 618
 
598 619
 		// Show the right arrow.
599 620
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
600
-		if ($start != $counter - $max_value && !$start_invalid)
601
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
602
-	}
603
-	else
621
+		if ($start != $counter - $max_value && !$start_invalid) {
622
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
623
+		}
624
+	} else
604 625
 	{
605 626
 		// If they didn't enter an odd value, pretend they did.
606 627
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
607 628
 
608 629
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
609
-		if (!empty($start) && $show_prevnext)
610
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
611
-		else
612
-			$pageindex .= '';
630
+		if (!empty($start) && $show_prevnext) {
631
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
632
+		} else {
633
+					$pageindex .= '';
634
+		}
613 635
 
614 636
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
615
-		if ($start > $num_per_page * $PageContiguous)
616
-			$pageindex .= sprintf($base_link, 0, '1');
637
+		if ($start > $num_per_page * $PageContiguous) {
638
+					$pageindex .= sprintf($base_link, 0, '1');
639
+		}
617 640
 
618 641
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
619
-		if ($start > $num_per_page * ($PageContiguous + 1))
620
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
642
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
643
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
621 644
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
622 645
 				'{FIRST_PAGE}' => $num_per_page,
623 646
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
624 647
 				'{PER_PAGE}' => $num_per_page,
625 648
 			));
649
+		}
626 650
 
627 651
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
628
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
629
-			if ($start >= $num_per_page * $nCont)
652
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
653
+					if ($start >= $num_per_page * $nCont)
630 654
 			{
631 655
 				$tmpStart = $start - $num_per_page * $nCont;
656
+		}
632 657
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
633 658
 			}
634 659
 
635 660
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
636
-		if (!$start_invalid)
637
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
638
-		else
639
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
661
+		if (!$start_invalid) {
662
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
663
+		} else {
664
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
665
+		}
640 666
 
641 667
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
642 668
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
643
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
644
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
669
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
670
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
645 671
 			{
646 672
 				$tmpStart = $start + $num_per_page * $nCont;
673
+		}
647 674
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
648 675
 			}
649 676
 
650 677
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
651
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
652
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
678
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
679
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
653 680
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
654 681
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
655 682
 				'{LAST_PAGE}' => $tmpMaxPages,
656 683
 				'{PER_PAGE}' => $num_per_page,
657 684
 			));
685
+		}
658 686
 
659 687
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
660
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
661
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
688
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
689
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
690
+		}
662 691
 
663 692
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
664
-		if ($start != $tmpMaxPages && $show_prevnext)
665
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
693
+		if ($start != $tmpMaxPages && $show_prevnext) {
694
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
695
+		}
666 696
 	}
667 697
 	$pageindex .= $settings['page_index']['extra_after'];
668 698
 
@@ -688,8 +718,9 @@  discard block
 block discarded – undo
688 718
 	if ($decimal_separator === null)
689 719
 	{
690 720
 		// Not set for whatever reason?
691
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
692
-			return $number;
721
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
722
+					return $number;
723
+		}
693 724
 
694 725
 		// Cache these each load...
695 726
 		$thousands_separator = $matches[1];
@@ -721,17 +752,20 @@  discard block
 block discarded – undo
721 752
 	static $non_twelve_hour;
722 753
 
723 754
 	// Offset the time.
724
-	if (!$offset_type)
725
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
755
+	if (!$offset_type) {
756
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
757
+	}
726 758
 	// Just the forum offset?
727
-	elseif ($offset_type == 'forum')
728
-		$time = $log_time + $modSettings['time_offset'] * 3600;
729
-	else
730
-		$time = $log_time;
759
+	elseif ($offset_type == 'forum') {
760
+			$time = $log_time + $modSettings['time_offset'] * 3600;
761
+	} else {
762
+			$time = $log_time;
763
+	}
731 764
 
732 765
 	// We can't have a negative date (on Windows, at least.)
733
-	if ($log_time < 0)
734
-		$log_time = 0;
766
+	if ($log_time < 0) {
767
+			$log_time = 0;
768
+	}
735 769
 
736 770
 	// Today and Yesterday?
737 771
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -748,46 +782,53 @@  discard block
 block discarded – undo
748 782
 		{
749 783
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
750 784
 			$today_fmt = $h . ':%M' . $s . ' %p';
785
+		} else {
786
+					$today_fmt = '%H:%M' . $s;
751 787
 		}
752
-		else
753
-			$today_fmt = '%H:%M' . $s;
754 788
 
755 789
 		// Same day of the year, same year.... Today!
756
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
757
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
790
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
791
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
792
+		}
758 793
 
759 794
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
760
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
761
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
795
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
796
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
797
+		}
762 798
 	}
763 799
 
764 800
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
765 801
 
766 802
 	if (setlocale(LC_TIME, $txt['lang_locale']))
767 803
 	{
768
-		if (!isset($non_twelve_hour))
769
-			$non_twelve_hour = trim(strftime('%p')) === '';
770
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
771
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
804
+		if (!isset($non_twelve_hour)) {
805
+					$non_twelve_hour = trim(strftime('%p')) === '';
806
+		}
807
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
808
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
809
+		}
772 810
 
773
-		foreach (array('%a', '%A', '%b', '%B') as $token)
774
-			if (strpos($str, $token) !== false)
811
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
812
+					if (strpos($str, $token) !== false)
775 813
 				$str = str_replace($token, strftime($token, $time), $str);
776
-	}
777
-	else
814
+		}
815
+	} else
778 816
 	{
779 817
 		// Do-it-yourself time localization.  Fun.
780
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
781
-			if (strpos($str, $token) !== false)
818
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
819
+					if (strpos($str, $token) !== false)
782 820
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
821
+		}
783 822
 
784
-		if (strpos($str, '%p') !== false)
785
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
823
+		if (strpos($str, '%p') !== false) {
824
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
825
+		}
786 826
 	}
787 827
 
788 828
 	// Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that.
789
-	if ($context['server']['is_windows'] && strpos($str, '%e') !== false)
790
-		$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
829
+	if ($context['server']['is_windows'] && strpos($str, '%e') !== false) {
830
+			$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
831
+	}
791 832
 
792 833
 	// Format any other characters..
793 834
 	return strftime($str, $time);
@@ -809,16 +850,19 @@  discard block
 block discarded – undo
809 850
 	static $translation = array();
810 851
 
811 852
 	// Determine the character set... Default to UTF-8
812
-	if (empty($context['character_set']))
813
-		$charset = 'UTF-8';
853
+	if (empty($context['character_set'])) {
854
+			$charset = 'UTF-8';
855
+	}
814 856
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
815
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
816
-		$charset = 'ISO-8859-1';
817
-	else
818
-		$charset = $context['character_set'];
857
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
858
+			$charset = 'ISO-8859-1';
859
+	} else {
860
+			$charset = $context['character_set'];
861
+	}
819 862
 
820
-	if (empty($translation))
821
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
863
+	if (empty($translation)) {
864
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
865
+	}
822 866
 
823 867
 	return strtr($string, $translation);
824 868
 }
@@ -840,8 +884,9 @@  discard block
 block discarded – undo
840 884
 	global $smcFunc;
841 885
 
842 886
 	// It was already short enough!
843
-	if ($smcFunc['strlen']($subject) <= $len)
844
-		return $subject;
887
+	if ($smcFunc['strlen']($subject) <= $len) {
888
+			return $subject;
889
+	}
845 890
 
846 891
 	// Shorten it by the length it was too long, and strip off junk from the end.
847 892
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -860,10 +905,11 @@  discard block
 block discarded – undo
860 905
 {
861 906
 	global $user_info, $modSettings;
862 907
 
863
-	if ($timestamp === null)
864
-		$timestamp = time();
865
-	elseif ($timestamp == 0)
866
-		return 0;
908
+	if ($timestamp === null) {
909
+			$timestamp = time();
910
+	} elseif ($timestamp == 0) {
911
+			return 0;
912
+	}
867 913
 
868 914
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
869 915
 }
@@ -892,8 +938,9 @@  discard block
 block discarded – undo
892 938
 		$array[$i] = $array[$j];
893 939
 		$array[$j] = $temp;
894 940
 
895
-		for ($i = 1; $p[$i] == 0; $i++)
896
-			$p[$i] = 1;
941
+		for ($i = 1; $p[$i] == 0; $i++) {
942
+					$p[$i] = 1;
943
+		}
897 944
 
898 945
 		$orders[] = $array;
899 946
 	}
@@ -925,12 +972,14 @@  discard block
 block discarded – undo
925 972
 	static $disabled;
926 973
 
927 974
 	// Don't waste cycles
928
-	if ($message === '')
929
-		return '';
975
+	if ($message === '') {
976
+			return '';
977
+	}
930 978
 
931 979
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
932
-	if (!isset($context['utf8']))
933
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
980
+	if (!isset($context['utf8'])) {
981
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
982
+	}
934 983
 
935 984
 	// Clean up any cut/paste issues we may have
936 985
 	$message = sanitizeMSCutPaste($message);
@@ -942,13 +991,15 @@  discard block
 block discarded – undo
942 991
 		return $message;
943 992
 	}
944 993
 
945
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
946
-		$smileys = (bool) $smileys;
994
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
995
+			$smileys = (bool) $smileys;
996
+	}
947 997
 
948 998
 	if (empty($modSettings['enableBBC']) && $message !== false)
949 999
 	{
950
-		if ($smileys === true)
951
-			parsesmileys($message);
1000
+		if ($smileys === true) {
1001
+					parsesmileys($message);
1002
+		}
952 1003
 
953 1004
 		return $message;
954 1005
 	}
@@ -961,8 +1012,9 @@  discard block
 block discarded – undo
961 1012
 	}
962 1013
 
963 1014
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
964
-	if (!empty($modSettings['autoLinkUrls']))
965
-		set_tld_regex();
1015
+	if (!empty($modSettings['autoLinkUrls'])) {
1016
+			set_tld_regex();
1017
+	}
966 1018
 
967 1019
 	// Allow mods access before entering the main parse_bbc loop
968 1020
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -976,12 +1028,14 @@  discard block
 block discarded – undo
976 1028
 
977 1029
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
978 1030
 
979
-			foreach ($temp as $tag)
980
-				$disabled[trim($tag)] = true;
1031
+			foreach ($temp as $tag) {
1032
+							$disabled[trim($tag)] = true;
1033
+			}
981 1034
 		}
982 1035
 
983
-		if (empty($modSettings['enableEmbeddedFlash']))
984
-			$disabled['flash'] = true;
1036
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1037
+					$disabled['flash'] = true;
1038
+		}
985 1039
 
986 1040
 		/* The following bbc are formatted as an array, with keys as follows:
987 1041
 
@@ -1102,8 +1156,9 @@  discard block
 block discarded – undo
1102 1156
 					$returnContext = '';
1103 1157
 
1104 1158
 					// BBC or the entire attachments feature is disabled
1105
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1106
-						return $data;
1159
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1160
+											return $data;
1161
+					}
1107 1162
 
1108 1163
 					// Save the attach ID.
1109 1164
 					$attachID = $data;
@@ -1114,8 +1169,9 @@  discard block
 block discarded – undo
1114 1169
 					$currentAttachment = parseAttachBBC($attachID);
1115 1170
 
1116 1171
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1117
-					if (is_string($currentAttachment))
1118
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1172
+					if (is_string($currentAttachment)) {
1173
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1174
+					}
1119 1175
 
1120 1176
 					if (!empty($currentAttachment['is_image']))
1121 1177
 					{
@@ -1131,15 +1187,17 @@  discard block
 block discarded – undo
1131 1187
 							$height = ' height="' . $currentAttachment['height'] . '"';
1132 1188
 						}
1133 1189
 
1134
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1135
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '"></a>';
1136
-						else
1137
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . '/>';
1190
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1191
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '"></a>';
1192
+						} else {
1193
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . '/>';
1194
+						}
1138 1195
 					}
1139 1196
 
1140 1197
 					// No image. Show a link.
1141
-					else
1142
-						$returnContext .= $currentAttachment['link'];
1198
+					else {
1199
+											$returnContext .= $currentAttachment['link'];
1200
+					}
1143 1201
 
1144 1202
 					// Gotta append what we just did.
1145 1203
 					$data = $returnContext;
@@ -1170,8 +1228,9 @@  discard block
 block discarded – undo
1170 1228
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1171 1229
 						{
1172 1230
 							// Do PHP code coloring?
1173
-							if ($php_parts[$php_i] != '&lt;?php')
1174
-								continue;
1231
+							if ($php_parts[$php_i] != '&lt;?php') {
1232
+															continue;
1233
+							}
1175 1234
 
1176 1235
 							$php_string = '';
1177 1236
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1187,8 +1246,9 @@  discard block
 block discarded – undo
1187 1246
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1188 1247
 
1189 1248
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1190
-						if ($context['browser']['is_opera'])
1191
-							$data .= '&nbsp;';
1249
+						if ($context['browser']['is_opera']) {
1250
+													$data .= '&nbsp;';
1251
+						}
1192 1252
 					}
1193 1253
 				},
1194 1254
 				'block_level' => true,
@@ -1207,8 +1267,9 @@  discard block
 block discarded – undo
1207 1267
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1208 1268
 						{
1209 1269
 							// Do PHP code coloring?
1210
-							if ($php_parts[$php_i] != '&lt;?php')
1211
-								continue;
1270
+							if ($php_parts[$php_i] != '&lt;?php') {
1271
+															continue;
1272
+							}
1212 1273
 
1213 1274
 							$php_string = '';
1214 1275
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1224,8 +1285,9 @@  discard block
 block discarded – undo
1224 1285
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1225 1286
 
1226 1287
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1227
-						if ($context['browser']['is_opera'])
1228
-							$data[0] .= '&nbsp;';
1288
+						if ($context['browser']['is_opera']) {
1289
+													$data[0] .= '&nbsp;';
1290
+						}
1229 1291
 					}
1230 1292
 				},
1231 1293
 				'block_level' => true,
@@ -1263,11 +1325,13 @@  discard block
 block discarded – undo
1263 1325
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1264 1326
 				'validate' => function (&$tag, &$data, $disabled)
1265 1327
 				{
1266
-					if (isset($disabled['url']))
1267
-						$tag['content'] = '$1';
1328
+					if (isset($disabled['url'])) {
1329
+											$tag['content'] = '$1';
1330
+					}
1268 1331
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1269
-					if (empty($scheme))
1270
-						$data[0] = '//' . ltrim($data[0], ':/');
1332
+					if (empty($scheme)) {
1333
+											$data[0] = '//' . ltrim($data[0], ':/');
1334
+					}
1271 1335
 				},
1272 1336
 				'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>',
1273 1337
 			),
@@ -1314,14 +1378,16 @@  discard block
 block discarded – undo
1314 1378
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1315 1379
 					if ($image_proxy_enabled)
1316 1380
 					{
1317
-						if (empty($scheme))
1318
-							$data = 'http://' . ltrim($data, ':/');
1381
+						if (empty($scheme)) {
1382
+													$data = 'http://' . ltrim($data, ':/');
1383
+						}
1319 1384
 
1320
-						if ($scheme != 'https')
1321
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1385
+						if ($scheme != 'https') {
1386
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1387
+						}
1388
+					} elseif (empty($scheme)) {
1389
+											$data = '//' . ltrim($data, ':/');
1322 1390
 					}
1323
-					elseif (empty($scheme))
1324
-						$data = '//' . ltrim($data, ':/');
1325 1391
 				},
1326 1392
 				'disabled_content' => '($1)',
1327 1393
 			),
@@ -1337,14 +1403,16 @@  discard block
 block discarded – undo
1337 1403
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1338 1404
 					if ($image_proxy_enabled)
1339 1405
 					{
1340
-						if (empty($scheme))
1341
-							$data = 'http://' . ltrim($data, ':/');
1406
+						if (empty($scheme)) {
1407
+													$data = 'http://' . ltrim($data, ':/');
1408
+						}
1342 1409
 
1343
-						if ($scheme != 'https')
1344
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1410
+						if ($scheme != 'https') {
1411
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1412
+						}
1413
+					} elseif (empty($scheme)) {
1414
+											$data = '//' . ltrim($data, ':/');
1345 1415
 					}
1346
-					elseif (empty($scheme))
1347
-						$data = '//' . ltrim($data, ':/');
1348 1416
 				},
1349 1417
 				'disabled_content' => '($1)',
1350 1418
 			),
@@ -1356,8 +1424,9 @@  discard block
 block discarded – undo
1356 1424
 				{
1357 1425
 					$data = strtr($data, array('<br>' => ''));
1358 1426
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1359
-					if (empty($scheme))
1360
-						$data = '//' . ltrim($data, ':/');
1427
+					if (empty($scheme)) {
1428
+											$data = '//' . ltrim($data, ':/');
1429
+					}
1361 1430
 				},
1362 1431
 			),
1363 1432
 			array(
@@ -1368,13 +1437,14 @@  discard block
 block discarded – undo
1368 1437
 				'after' => '</a>',
1369 1438
 				'validate' => function (&$tag, &$data, $disabled)
1370 1439
 				{
1371
-					if (substr($data, 0, 1) == '#')
1372
-						$data = '#post_' . substr($data, 1);
1373
-					else
1440
+					if (substr($data, 0, 1) == '#') {
1441
+											$data = '#post_' . substr($data, 1);
1442
+					} else
1374 1443
 					{
1375 1444
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1376
-						if (empty($scheme))
1377
-							$data = '//' . ltrim($data, ':/');
1445
+						if (empty($scheme)) {
1446
+													$data = '//' . ltrim($data, ':/');
1447
+						}
1378 1448
 					}
1379 1449
 				},
1380 1450
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1452,8 +1522,9 @@  discard block
 block discarded – undo
1452 1522
 					{
1453 1523
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1454 1524
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1455
-						if ($add_begin)
1456
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1525
+						if ($add_begin) {
1526
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1527
+						}
1457 1528
 					}
1458 1529
 				},
1459 1530
 				'block_level' => false,
@@ -1584,10 +1655,11 @@  discard block
 block discarded – undo
1584 1655
 				'content' => '$1',
1585 1656
 				'validate' => function (&$tag, &$data, $disabled)
1586 1657
 				{
1587
-					if (is_numeric($data))
1588
-						$data = timeformat($data);
1589
-					else
1590
-						$tag['content'] = '[time]$1[/time]';
1658
+					if (is_numeric($data)) {
1659
+											$data = timeformat($data);
1660
+					} else {
1661
+											$tag['content'] = '[time]$1[/time]';
1662
+					}
1591 1663
 				},
1592 1664
 			),
1593 1665
 			array(
@@ -1614,8 +1686,9 @@  discard block
 block discarded – undo
1614 1686
 				{
1615 1687
 					$data = strtr($data, array('<br>' => ''));
1616 1688
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1617
-					if (empty($scheme))
1618
-						$data = '//' . ltrim($data, ':/');
1689
+					if (empty($scheme)) {
1690
+											$data = '//' . ltrim($data, ':/');
1691
+					}
1619 1692
 				},
1620 1693
 			),
1621 1694
 			array(
@@ -1627,8 +1700,9 @@  discard block
 block discarded – undo
1627 1700
 				'validate' => function (&$tag, &$data, $disabled)
1628 1701
 				{
1629 1702
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1630
-					if (empty($scheme))
1631
-						$data = '//' . ltrim($data, ':/');
1703
+					if (empty($scheme)) {
1704
+											$data = '//' . ltrim($data, ':/');
1705
+					}
1632 1706
 				},
1633 1707
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1634 1708
 				'disabled_after' => ' ($1)',
@@ -1648,8 +1722,9 @@  discard block
 block discarded – undo
1648 1722
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1649 1723
 		if ($message === false)
1650 1724
 		{
1651
-			if (isset($temp_bbc))
1652
-				$bbc_codes = $temp_bbc;
1725
+			if (isset($temp_bbc)) {
1726
+							$bbc_codes = $temp_bbc;
1727
+			}
1653 1728
 			usort($codes, function ($a, $b) {
1654 1729
 				return strcmp($a['tag'], $b['tag']);
1655 1730
 			});
@@ -1669,8 +1744,9 @@  discard block
 block discarded – undo
1669 1744
 		);
1670 1745
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1671 1746
 		{
1672
-			foreach ($itemcodes as $c => $dummy)
1673
-				$bbc_codes[$c] = array();
1747
+			foreach ($itemcodes as $c => $dummy) {
1748
+							$bbc_codes[$c] = array();
1749
+			}
1674 1750
 		}
1675 1751
 
1676 1752
 		// Shhhh!
@@ -1691,12 +1767,14 @@  discard block
 block discarded – undo
1691 1767
 		foreach ($codes as $code)
1692 1768
 		{
1693 1769
 			// Make it easier to process parameters later
1694
-			if (!empty($code['parameters']))
1695
-				ksort($code['parameters'], SORT_STRING);
1770
+			if (!empty($code['parameters'])) {
1771
+							ksort($code['parameters'], SORT_STRING);
1772
+			}
1696 1773
 
1697 1774
 			// If we are not doing every tag only do ones we are interested in.
1698
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1699
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1775
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1776
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1777
+			}
1700 1778
 		}
1701 1779
 		$codes = null;
1702 1780
 	}
@@ -1707,8 +1785,9 @@  discard block
 block discarded – undo
1707 1785
 		// It's likely this will change if the message is modified.
1708 1786
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1709 1787
 
1710
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1711
-			return $temp;
1788
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1789
+					return $temp;
1790
+		}
1712 1791
 
1713 1792
 		$cache_t = microtime();
1714 1793
 	}
@@ -1740,8 +1819,9 @@  discard block
 block discarded – undo
1740 1819
 		$disabled['flash'] = true;
1741 1820
 
1742 1821
 		// @todo Change maybe?
1743
-		if (!isset($_GET['images']))
1744
-			$disabled['img'] = true;
1822
+		if (!isset($_GET['images'])) {
1823
+					$disabled['img'] = true;
1824
+		}
1745 1825
 
1746 1826
 		// @todo Interface/setting to add more?
1747 1827
 	}
@@ -1765,8 +1845,9 @@  discard block
 block discarded – undo
1765 1845
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1766 1846
 
1767 1847
 		// Failsafe.
1768
-		if ($pos === false || $last_pos > $pos)
1769
-			$pos = strlen($message) + 1;
1848
+		if ($pos === false || $last_pos > $pos) {
1849
+					$pos = strlen($message) + 1;
1850
+		}
1770 1851
 
1771 1852
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1772 1853
 		if ($last_pos < $pos - 1)
@@ -1785,8 +1866,9 @@  discard block
 block discarded – undo
1785 1866
 
1786 1867
 				// <br> should be empty.
1787 1868
 				$empty_tags = array('br', 'hr');
1788
-				foreach ($empty_tags as $tag)
1789
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1869
+				foreach ($empty_tags as $tag) {
1870
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1871
+				}
1790 1872
 
1791 1873
 				// b, u, i, s, pre... basic tags.
1792 1874
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
@@ -1795,8 +1877,9 @@  discard block
 block discarded – undo
1795 1877
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1796 1878
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1797 1879
 
1798
-					if ($diff > 0)
1799
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1880
+					if ($diff > 0) {
1881
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1882
+					}
1800 1883
 				}
1801 1884
 
1802 1885
 				// Do <img ...> - with security... action= -> action-.
@@ -1809,8 +1892,9 @@  discard block
 block discarded – undo
1809 1892
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1810 1893
 
1811 1894
 						// Remove action= from the URL - no funny business, now.
1812
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1813
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1895
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
1896
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1897
+						}
1814 1898
 
1815 1899
 						// Check if the image is larger than allowed.
1816 1900
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1831,9 +1915,9 @@  discard block
 block discarded – undo
1831 1915
 
1832 1916
 							// Set the new image tag.
1833 1917
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
1918
+						} else {
1919
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1834 1920
 						}
1835
-						else
1836
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1837 1921
 					}
1838 1922
 
1839 1923
 					$data = strtr($data, $replaces);
@@ -1846,16 +1930,18 @@  discard block
 block discarded – undo
1846 1930
 				$no_autolink_area = false;
1847 1931
 				if (!empty($open_tags))
1848 1932
 				{
1849
-					foreach ($open_tags as $open_tag)
1850
-						if (in_array($open_tag['tag'], $no_autolink_tags))
1933
+					foreach ($open_tags as $open_tag) {
1934
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1851 1935
 							$no_autolink_area = true;
1936
+					}
1852 1937
 				}
1853 1938
 
1854 1939
 				// Don't go backwards.
1855 1940
 				// @todo Don't think is the real solution....
1856 1941
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1857
-				if ($pos < $lastAutoPos)
1858
-					$no_autolink_area = true;
1942
+				if ($pos < $lastAutoPos) {
1943
+									$no_autolink_area = true;
1944
+				}
1859 1945
 				$lastAutoPos = $pos;
1860 1946
 
1861 1947
 				if (!$no_autolink_area)
@@ -1964,17 +2050,19 @@  discard block
 block discarded – undo
1964 2050
 							if ($scheme == 'mailto')
1965 2051
 							{
1966 2052
 								$email_address = str_replace('mailto:', '', $url);
1967
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
1968
-									return '[email=' . $email_address . ']' . $url . '[/email]';
1969
-								else
1970
-									return $url;
2053
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2054
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2055
+								} else {
2056
+																	return $url;
2057
+								}
1971 2058
 							}
1972 2059
 
1973 2060
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
1974
-							if (empty($scheme))
1975
-								$fullUrl = '//' . ltrim($url, ':/');
1976
-							else
1977
-								$fullUrl = $url;
2061
+							if (empty($scheme)) {
2062
+															$fullUrl = '//' . ltrim($url, ':/');
2063
+							} else {
2064
+															$fullUrl = $url;
2065
+							}
1978 2066
 
1979 2067
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
1980 2068
 						}, $data);
@@ -2023,16 +2111,18 @@  discard block
 block discarded – undo
2023 2111
 		}
2024 2112
 
2025 2113
 		// Are we there yet?  Are we there yet?
2026
-		if ($pos >= strlen($message) - 1)
2027
-			break;
2114
+		if ($pos >= strlen($message) - 1) {
2115
+					break;
2116
+		}
2028 2117
 
2029 2118
 		$tags = strtolower($message[$pos + 1]);
2030 2119
 
2031 2120
 		if ($tags == '/' && !empty($open_tags))
2032 2121
 		{
2033 2122
 			$pos2 = strpos($message, ']', $pos + 1);
2034
-			if ($pos2 == $pos + 2)
2035
-				continue;
2123
+			if ($pos2 == $pos + 2) {
2124
+							continue;
2125
+			}
2036 2126
 
2037 2127
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2038 2128
 
@@ -2042,8 +2132,9 @@  discard block
 block discarded – undo
2042 2132
 			do
2043 2133
 			{
2044 2134
 				$tag = array_pop($open_tags);
2045
-				if (!$tag)
2046
-					break;
2135
+				if (!$tag) {
2136
+									break;
2137
+				}
2047 2138
 
2048 2139
 				if (!empty($tag['block_level']))
2049 2140
 				{
@@ -2057,10 +2148,11 @@  discard block
 block discarded – undo
2057 2148
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2058 2149
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2059 2150
 					{
2060
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2061
-							if ($temp['tag'] == $look_for)
2151
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2152
+													if ($temp['tag'] == $look_for)
2062 2153
 							{
2063 2154
 								$block_level = !empty($temp['block_level']);
2155
+						}
2064 2156
 								break;
2065 2157
 							}
2066 2158
 					}
@@ -2082,15 +2174,15 @@  discard block
 block discarded – undo
2082 2174
 			{
2083 2175
 				$open_tags = $to_close;
2084 2176
 				continue;
2085
-			}
2086
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2177
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2087 2178
 			{
2088 2179
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2089 2180
 				{
2090
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2091
-						if ($temp['tag'] == $look_for)
2181
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2182
+											if ($temp['tag'] == $look_for)
2092 2183
 						{
2093 2184
 							$block_level = !empty($temp['block_level']);
2185
+					}
2094 2186
 							break;
2095 2187
 						}
2096 2188
 				}
@@ -2098,8 +2190,9 @@  discard block
 block discarded – undo
2098 2190
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2099 2191
 				if (!$block_level)
2100 2192
 				{
2101
-					foreach ($to_close as $tag)
2102
-						array_push($open_tags, $tag);
2193
+					foreach ($to_close as $tag) {
2194
+											array_push($open_tags, $tag);
2195
+					}
2103 2196
 					continue;
2104 2197
 				}
2105 2198
 			}
@@ -2111,10 +2204,12 @@  discard block
 block discarded – undo
2111 2204
 				$pos2 = $pos - 1;
2112 2205
 
2113 2206
 				// See the comment at the end of the big loop - just eating whitespace ;).
2114
-				if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>')
2115
-					$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2116
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0)
2117
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2207
+				if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') {
2208
+									$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2209
+				}
2210
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0) {
2211
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2212
+				}
2118 2213
 			}
2119 2214
 
2120 2215
 			if (!empty($to_close))
@@ -2127,8 +2222,9 @@  discard block
 block discarded – undo
2127 2222
 		}
2128 2223
 
2129 2224
 		// No tags for this character, so just keep going (fastest possible course.)
2130
-		if (!isset($bbc_codes[$tags]))
2131
-			continue;
2225
+		if (!isset($bbc_codes[$tags])) {
2226
+					continue;
2227
+		}
2132 2228
 
2133 2229
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2134 2230
 		$tag = null;
@@ -2137,44 +2233,52 @@  discard block
 block discarded – undo
2137 2233
 			$pt_strlen = strlen($possible['tag']);
2138 2234
 
2139 2235
 			// Not a match?
2140
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2141
-				continue;
2236
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2237
+							continue;
2238
+			}
2142 2239
 
2143 2240
 			$next_c = $message[$pos + 1 + $pt_strlen];
2144 2241
 
2145 2242
 			// A test validation?
2146
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2147
-				continue;
2243
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2244
+							continue;
2245
+			}
2148 2246
 			// Do we want parameters?
2149 2247
 			elseif (!empty($possible['parameters']))
2150 2248
 			{
2151
-				if ($next_c != ' ')
2152
-					continue;
2153
-			}
2154
-			elseif (isset($possible['type']))
2249
+				if ($next_c != ' ') {
2250
+									continue;
2251
+				}
2252
+			} elseif (isset($possible['type']))
2155 2253
 			{
2156 2254
 				// Do we need an equal sign?
2157
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2158
-					continue;
2255
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2256
+									continue;
2257
+				}
2159 2258
 				// Maybe we just want a /...
2160
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2161
-					continue;
2259
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2260
+									continue;
2261
+				}
2162 2262
 				// An immediate ]?
2163
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2164
-					continue;
2263
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2264
+									continue;
2265
+				}
2165 2266
 			}
2166 2267
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2167
-			elseif ($next_c != ']')
2168
-				continue;
2268
+			elseif ($next_c != ']') {
2269
+							continue;
2270
+			}
2169 2271
 
2170 2272
 			// Check allowed tree?
2171
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2172
-				continue;
2173
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2174
-				continue;
2273
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2274
+							continue;
2275
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2276
+							continue;
2277
+			}
2175 2278
 			// If this is in the list of disallowed child tags, don't parse it.
2176
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2177
-				continue;
2279
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2280
+							continue;
2281
+			}
2178 2282
 
2179 2283
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2180 2284
 
@@ -2186,8 +2290,9 @@  discard block
 block discarded – undo
2186 2290
 				foreach ($open_tags as $open_quote)
2187 2291
 				{
2188 2292
 					// Every parent quote this quote has flips the styling
2189
-					if ($open_quote['tag'] == 'quote')
2190
-						$quote_alt = !$quote_alt;
2293
+					if ($open_quote['tag'] == 'quote') {
2294
+											$quote_alt = !$quote_alt;
2295
+					}
2191 2296
 				}
2192 2297
 				// Add a class to the quote to style alternating blockquotes
2193 2298
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2198,8 +2303,9 @@  discard block
 block discarded – undo
2198 2303
 			{
2199 2304
 				// Build a regular expression for each parameter for the current tag.
2200 2305
 				$preg = array();
2201
-				foreach ($possible['parameters'] as $p => $info)
2202
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2306
+				foreach ($possible['parameters'] as $p => $info) {
2307
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2308
+				}
2203 2309
 
2204 2310
 				// Extract the string that potentially holds our parameters.
2205 2311
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2219,24 +2325,27 @@  discard block
 block discarded – undo
2219 2325
 
2220 2326
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2221 2327
 
2222
-					if ($match)
2223
-						$blob_counter = count($blobs) + 1;
2328
+					if ($match) {
2329
+											$blob_counter = count($blobs) + 1;
2330
+					}
2224 2331
 				}
2225 2332
 
2226 2333
 				// Didn't match our parameter list, try the next possible.
2227
-				if (!$match)
2228
-					continue;
2334
+				if (!$match) {
2335
+									continue;
2336
+				}
2229 2337
 
2230 2338
 				$params = array();
2231 2339
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2232 2340
 				{
2233 2341
 					$key = strtok(ltrim($matches[$i]), '=');
2234
-					if (isset($possible['parameters'][$key]['value']))
2235
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2236
-					elseif (isset($possible['parameters'][$key]['validate']))
2237
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2238
-					else
2239
-						$params['{' . $key . '}'] = $matches[$i + 1];
2342
+					if (isset($possible['parameters'][$key]['value'])) {
2343
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2344
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2345
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2346
+					} else {
2347
+											$params['{' . $key . '}'] = $matches[$i + 1];
2348
+					}
2240 2349
 
2241 2350
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2242 2351
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2244,23 +2353,26 @@  discard block
 block discarded – undo
2244 2353
 
2245 2354
 				foreach ($possible['parameters'] as $p => $info)
2246 2355
 				{
2247
-					if (!isset($params['{' . $p . '}']))
2248
-						$params['{' . $p . '}'] = '';
2356
+					if (!isset($params['{' . $p . '}'])) {
2357
+											$params['{' . $p . '}'] = '';
2358
+					}
2249 2359
 				}
2250 2360
 
2251 2361
 				$tag = $possible;
2252 2362
 
2253 2363
 				// Put the parameters into the string.
2254
-				if (isset($tag['before']))
2255
-					$tag['before'] = strtr($tag['before'], $params);
2256
-				if (isset($tag['after']))
2257
-					$tag['after'] = strtr($tag['after'], $params);
2258
-				if (isset($tag['content']))
2259
-					$tag['content'] = strtr($tag['content'], $params);
2364
+				if (isset($tag['before'])) {
2365
+									$tag['before'] = strtr($tag['before'], $params);
2366
+				}
2367
+				if (isset($tag['after'])) {
2368
+									$tag['after'] = strtr($tag['after'], $params);
2369
+				}
2370
+				if (isset($tag['content'])) {
2371
+									$tag['content'] = strtr($tag['content'], $params);
2372
+				}
2260 2373
 
2261 2374
 				$pos1 += strlen($given_param_string);
2262
-			}
2263
-			else
2375
+			} else
2264 2376
 			{
2265 2377
 				$tag = $possible;
2266 2378
 				$params = array();
@@ -2271,8 +2383,9 @@  discard block
 block discarded – undo
2271 2383
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2272 2384
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2273 2385
 		{
2274
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2275
-				continue;
2386
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2387
+							continue;
2388
+			}
2276 2389
 
2277 2390
 			$tag = $itemcodes[$message[$pos + 1]];
2278 2391
 
@@ -2293,9 +2406,9 @@  discard block
 block discarded – undo
2293 2406
 			{
2294 2407
 				array_pop($open_tags);
2295 2408
 				$code = '</li>';
2409
+			} else {
2410
+							$code = '';
2296 2411
 			}
2297
-			else
2298
-				$code = '';
2299 2412
 
2300 2413
 			// Now we open a new tag.
2301 2414
 			$open_tags[] = array(
@@ -2342,12 +2455,14 @@  discard block
 block discarded – undo
2342 2455
 		}
2343 2456
 
2344 2457
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2345
-		if ($tag === null)
2346
-			continue;
2458
+		if ($tag === null) {
2459
+					continue;
2460
+		}
2347 2461
 
2348 2462
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2349
-		if (isset($inside['disallow_children']))
2350
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2463
+		if (isset($inside['disallow_children'])) {
2464
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2465
+		}
2351 2466
 
2352 2467
 		// Is this tag disabled?
2353 2468
 		if (isset($disabled[$tag['tag']]))
@@ -2357,14 +2472,13 @@  discard block
 block discarded – undo
2357 2472
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2358 2473
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2359 2474
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2360
-			}
2361
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2475
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2362 2476
 			{
2363 2477
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2364 2478
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2479
+			} else {
2480
+							$tag['content'] = $tag['disabled_content'];
2365 2481
 			}
2366
-			else
2367
-				$tag['content'] = $tag['disabled_content'];
2368 2482
 		}
2369 2483
 
2370 2484
 		// we use this a lot
@@ -2374,8 +2488,9 @@  discard block
 block discarded – undo
2374 2488
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2375 2489
 		{
2376 2490
 			$n = count($open_tags) - 1;
2377
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2378
-				$n--;
2491
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2492
+							$n--;
2493
+			}
2379 2494
 
2380 2495
 			// Close all the non block level tags so this tag isn't surrounded by them.
2381 2496
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2386,10 +2501,12 @@  discard block
 block discarded – undo
2386 2501
 				$pos1 += $ot_strlen + 2;
2387 2502
 
2388 2503
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2389
-				if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>')
2390
-					$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2391
-				if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0)
2392
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2504
+				if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') {
2505
+									$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2506
+				}
2507
+				if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0) {
2508
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2509
+				}
2393 2510
 
2394 2511
 				array_pop($open_tags);
2395 2512
 			}
@@ -2407,16 +2524,19 @@  discard block
 block discarded – undo
2407 2524
 		elseif ($tag['type'] == 'unparsed_content')
2408 2525
 		{
2409 2526
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2410
-			if ($pos2 === false)
2411
-				continue;
2527
+			if ($pos2 === false) {
2528
+							continue;
2529
+			}
2412 2530
 
2413 2531
 			$data = substr($message, $pos1, $pos2 - $pos1);
2414 2532
 
2415
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2416
-				$data = substr($data, 4);
2533
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2534
+							$data = substr($data, 4);
2535
+			}
2417 2536
 
2418
-			if (isset($tag['validate']))
2419
-				$tag['validate']($tag, $data, $disabled, $params);
2537
+			if (isset($tag['validate'])) {
2538
+							$tag['validate']($tag, $data, $disabled, $params);
2539
+			}
2420 2540
 
2421 2541
 			$code = strtr($tag['content'], array('$1' => $data));
2422 2542
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2432,34 +2552,40 @@  discard block
 block discarded – undo
2432 2552
 			if (isset($tag['quoted']))
2433 2553
 			{
2434 2554
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2435
-				if ($tag['quoted'] != 'optional' && !$quoted)
2436
-					continue;
2555
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2556
+									continue;
2557
+				}
2437 2558
 
2438
-				if ($quoted)
2439
-					$pos1 += 6;
2559
+				if ($quoted) {
2560
+									$pos1 += 6;
2561
+				}
2562
+			} else {
2563
+							$quoted = false;
2440 2564
 			}
2441
-			else
2442
-				$quoted = false;
2443 2565
 
2444 2566
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2445
-			if ($pos2 === false)
2446
-				continue;
2567
+			if ($pos2 === false) {
2568
+							continue;
2569
+			}
2447 2570
 
2448 2571
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2449
-			if ($pos3 === false)
2450
-				continue;
2572
+			if ($pos3 === false) {
2573
+							continue;
2574
+			}
2451 2575
 
2452 2576
 			$data = array(
2453 2577
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2454 2578
 				substr($message, $pos1, $pos2 - $pos1)
2455 2579
 			);
2456 2580
 
2457
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2458
-				$data[0] = substr($data[0], 4);
2581
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2582
+							$data[0] = substr($data[0], 4);
2583
+			}
2459 2584
 
2460 2585
 			// Validation for my parking, please!
2461
-			if (isset($tag['validate']))
2462
-				$tag['validate']($tag, $data, $disabled, $params);
2586
+			if (isset($tag['validate'])) {
2587
+							$tag['validate']($tag, $data, $disabled, $params);
2588
+			}
2463 2589
 
2464 2590
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2465 2591
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2476,23 +2602,27 @@  discard block
 block discarded – undo
2476 2602
 		elseif ($tag['type'] == 'unparsed_commas_content')
2477 2603
 		{
2478 2604
 			$pos2 = strpos($message, ']', $pos1);
2479
-			if ($pos2 === false)
2480
-				continue;
2605
+			if ($pos2 === false) {
2606
+							continue;
2607
+			}
2481 2608
 
2482 2609
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2483
-			if ($pos3 === false)
2484
-				continue;
2610
+			if ($pos3 === false) {
2611
+							continue;
2612
+			}
2485 2613
 
2486 2614
 			// We want $1 to be the content, and the rest to be csv.
2487 2615
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2488 2616
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2489 2617
 
2490
-			if (isset($tag['validate']))
2491
-				$tag['validate']($tag, $data, $disabled, $params);
2618
+			if (isset($tag['validate'])) {
2619
+							$tag['validate']($tag, $data, $disabled, $params);
2620
+			}
2492 2621
 
2493 2622
 			$code = $tag['content'];
2494
-			foreach ($data as $k => $d)
2495
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2623
+			foreach ($data as $k => $d) {
2624
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2625
+			}
2496 2626
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2497 2627
 			$pos += strlen($code) - 1 + 2;
2498 2628
 		}
@@ -2500,24 +2630,28 @@  discard block
 block discarded – undo
2500 2630
 		elseif ($tag['type'] == 'unparsed_commas')
2501 2631
 		{
2502 2632
 			$pos2 = strpos($message, ']', $pos1);
2503
-			if ($pos2 === false)
2504
-				continue;
2633
+			if ($pos2 === false) {
2634
+							continue;
2635
+			}
2505 2636
 
2506 2637
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2507 2638
 
2508
-			if (isset($tag['validate']))
2509
-				$tag['validate']($tag, $data, $disabled, $params);
2639
+			if (isset($tag['validate'])) {
2640
+							$tag['validate']($tag, $data, $disabled, $params);
2641
+			}
2510 2642
 
2511 2643
 			// Fix after, for disabled code mainly.
2512
-			foreach ($data as $k => $d)
2513
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2644
+			foreach ($data as $k => $d) {
2645
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2646
+			}
2514 2647
 
2515 2648
 			$open_tags[] = $tag;
2516 2649
 
2517 2650
 			// Replace them out, $1, $2, $3, $4, etc.
2518 2651
 			$code = $tag['before'];
2519
-			foreach ($data as $k => $d)
2520
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2652
+			foreach ($data as $k => $d) {
2653
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2654
+			}
2521 2655
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2522 2656
 			$pos += strlen($code) - 1 + 2;
2523 2657
 		}
@@ -2528,28 +2662,33 @@  discard block
 block discarded – undo
2528 2662
 			if (isset($tag['quoted']))
2529 2663
 			{
2530 2664
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2531
-				if ($tag['quoted'] != 'optional' && !$quoted)
2532
-					continue;
2665
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2666
+									continue;
2667
+				}
2533 2668
 
2534
-				if ($quoted)
2535
-					$pos1 += 6;
2669
+				if ($quoted) {
2670
+									$pos1 += 6;
2671
+				}
2672
+			} else {
2673
+							$quoted = false;
2536 2674
 			}
2537
-			else
2538
-				$quoted = false;
2539 2675
 
2540 2676
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2541
-			if ($pos2 === false)
2542
-				continue;
2677
+			if ($pos2 === false) {
2678
+							continue;
2679
+			}
2543 2680
 
2544 2681
 			$data = substr($message, $pos1, $pos2 - $pos1);
2545 2682
 
2546 2683
 			// Validation for my parking, please!
2547
-			if (isset($tag['validate']))
2548
-				$tag['validate']($tag, $data, $disabled, $params);
2684
+			if (isset($tag['validate'])) {
2685
+							$tag['validate']($tag, $data, $disabled, $params);
2686
+			}
2549 2687
 
2550 2688
 			// For parsed content, we must recurse to avoid security problems.
2551
-			if ($tag['type'] != 'unparsed_equals')
2552
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2689
+			if ($tag['type'] != 'unparsed_equals') {
2690
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2691
+			}
2553 2692
 
2554 2693
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2555 2694
 
@@ -2561,34 +2700,40 @@  discard block
 block discarded – undo
2561 2700
 		}
2562 2701
 
2563 2702
 		// If this is block level, eat any breaks after it.
2564
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2565
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2703
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2704
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2705
+		}
2566 2706
 
2567 2707
 		// Are we trimming outside this tag?
2568
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2569
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2708
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2709
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2710
+		}
2570 2711
 	}
2571 2712
 
2572 2713
 	// Close any remaining tags.
2573
-	while ($tag = array_pop($open_tags))
2574
-		$message .= "\n" . $tag['after'] . "\n";
2714
+	while ($tag = array_pop($open_tags)) {
2715
+			$message .= "\n" . $tag['after'] . "\n";
2716
+	}
2575 2717
 
2576 2718
 	// Parse the smileys within the parts where it can be done safely.
2577 2719
 	if ($smileys === true)
2578 2720
 	{
2579 2721
 		$message_parts = explode("\n", $message);
2580
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2581
-			parsesmileys($message_parts[$i]);
2722
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2723
+					parsesmileys($message_parts[$i]);
2724
+		}
2582 2725
 
2583 2726
 		$message = implode('', $message_parts);
2584 2727
 	}
2585 2728
 
2586 2729
 	// No smileys, just get rid of the markers.
2587
-	else
2588
-		$message = strtr($message, array("\n" => ''));
2730
+	else {
2731
+			$message = strtr($message, array("\n" => ''));
2732
+	}
2589 2733
 
2590
-	if ($message !== '' && $message[0] === ' ')
2591
-		$message = '&nbsp;' . substr($message, 1);
2734
+	if ($message !== '' && $message[0] === ' ') {
2735
+			$message = '&nbsp;' . substr($message, 1);
2736
+	}
2592 2737
 
2593 2738
 	// Cleanup whitespace.
2594 2739
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2597,15 +2742,16 @@  discard block
 block discarded – undo
2597 2742
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2598 2743
 
2599 2744
 	// Cache the output if it took some time...
2600
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2601
-		cache_put_data($cache_key, $message, 240);
2745
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2746
+			cache_put_data($cache_key, $message, 240);
2747
+	}
2602 2748
 
2603 2749
 	// If this was a force parse revert if needed.
2604 2750
 	if (!empty($parse_tags))
2605 2751
 	{
2606
-		if (empty($temp_bbc))
2607
-			$bbc_codes = array();
2608
-		else
2752
+		if (empty($temp_bbc)) {
2753
+					$bbc_codes = array();
2754
+		} else
2609 2755
 		{
2610 2756
 			$bbc_codes = $temp_bbc;
2611 2757
 			unset($temp_bbc);
@@ -2632,8 +2778,9 @@  discard block
 block discarded – undo
2632 2778
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2633 2779
 
2634 2780
 	// No smiley set at all?!
2635
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2636
-		return;
2781
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2782
+			return;
2783
+	}
2637 2784
 
2638 2785
 	// If smileyPregSearch hasn't been set, do it now.
2639 2786
 	if (empty($smileyPregSearch))
@@ -2644,8 +2791,7 @@  discard block
 block discarded – undo
2644 2791
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2645 2792
 			$smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif');
2646 2793
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2647
-		}
2648
-		else
2794
+		} else
2649 2795
 		{
2650 2796
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2651 2797
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2669,9 +2815,9 @@  discard block
 block discarded – undo
2669 2815
 				$smcFunc['db_free_result']($result);
2670 2816
 
2671 2817
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2818
+			} else {
2819
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2672 2820
 			}
2673
-			else
2674
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2675 2821
 		}
2676 2822
 
2677 2823
 		// The non-breaking-space is a complex thing...
@@ -2748,35 +2894,41 @@  discard block
 block discarded – undo
2748 2894
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2749 2895
 
2750 2896
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2751
-	if (!empty($context['flush_mail']))
2752
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2897
+	if (!empty($context['flush_mail'])) {
2898
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2753 2899
 		AddMailQueue(true);
2900
+	}
2754 2901
 
2755 2902
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2756 2903
 
2757
-	if ($add)
2758
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2904
+	if ($add) {
2905
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2906
+	}
2759 2907
 
2760 2908
 	// Put the session ID in.
2761
-	if (defined('SID') && SID != '')
2762
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2909
+	if (defined('SID') && SID != '') {
2910
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2911
+	}
2763 2912
 	// Keep that debug in their for template debugging!
2764
-	elseif (isset($_GET['debug']))
2765
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2913
+	elseif (isset($_GET['debug'])) {
2914
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2915
+	}
2766 2916
 
2767 2917
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
2768 2918
 	{
2769
-		if (defined('SID') && SID != '')
2770
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2919
+		if (defined('SID') && SID != '') {
2920
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2771 2921
 				function ($m) use ($scripturl)
2772 2922
 				{
2773 2923
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2924
+		}
2774 2925
 				}, $setLocation);
2775
-		else
2776
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2926
+		else {
2927
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2777 2928
 				function ($m) use ($scripturl)
2778 2929
 				{
2779 2930
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2931
+		}
2780 2932
 				}, $setLocation);
2781 2933
 	}
2782 2934
 
@@ -2787,8 +2939,9 @@  discard block
 block discarded – undo
2787 2939
 	header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2788 2940
 
2789 2941
 	// Debugging.
2790
-	if (isset($db_show_debug) && $db_show_debug === true)
2791
-		$_SESSION['debug_redirect'] = $db_cache;
2942
+	if (isset($db_show_debug) && $db_show_debug === true) {
2943
+			$_SESSION['debug_redirect'] = $db_cache;
2944
+	}
2792 2945
 
2793 2946
 	obExit(false);
2794 2947
 }
@@ -2807,51 +2960,60 @@  discard block
 block discarded – undo
2807 2960
 
2808 2961
 	// Attempt to prevent a recursive loop.
2809 2962
 	++$level;
2810
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2811
-		exit;
2812
-	if ($from_fatal_error)
2813
-		$has_fatal_error = true;
2963
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
2964
+			exit;
2965
+	}
2966
+	if ($from_fatal_error) {
2967
+			$has_fatal_error = true;
2968
+	}
2814 2969
 
2815 2970
 	// Clear out the stat cache.
2816 2971
 	trackStats();
2817 2972
 
2818 2973
 	// If we have mail to send, send it.
2819
-	if (!empty($context['flush_mail']))
2820
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2974
+	if (!empty($context['flush_mail'])) {
2975
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2821 2976
 		AddMailQueue(true);
2977
+	}
2822 2978
 
2823 2979
 	$do_header = $header === null ? !$header_done : $header;
2824
-	if ($do_footer === null)
2825
-		$do_footer = $do_header;
2980
+	if ($do_footer === null) {
2981
+			$do_footer = $do_header;
2982
+	}
2826 2983
 
2827 2984
 	// Has the template/header been done yet?
2828 2985
 	if ($do_header)
2829 2986
 	{
2830 2987
 		// Was the page title set last minute? Also update the HTML safe one.
2831
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2832
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
2988
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
2989
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
2990
+		}
2833 2991
 
2834 2992
 		// Start up the session URL fixer.
2835 2993
 		ob_start('ob_sessrewrite');
2836 2994
 
2837
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2838
-			$buffers = explode(',', $settings['output_buffers']);
2839
-		elseif (!empty($settings['output_buffers']))
2840
-			$buffers = $settings['output_buffers'];
2841
-		else
2842
-			$buffers = array();
2995
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
2996
+					$buffers = explode(',', $settings['output_buffers']);
2997
+		} elseif (!empty($settings['output_buffers'])) {
2998
+					$buffers = $settings['output_buffers'];
2999
+		} else {
3000
+					$buffers = array();
3001
+		}
2843 3002
 
2844
-		if (isset($modSettings['integrate_buffer']))
2845
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3003
+		if (isset($modSettings['integrate_buffer'])) {
3004
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3005
+		}
2846 3006
 
2847
-		if (!empty($buffers))
2848
-			foreach ($buffers as $function)
3007
+		if (!empty($buffers)) {
3008
+					foreach ($buffers as $function)
2849 3009
 			{
2850 3010
 				$call = call_helper($function, true);
3011
+		}
2851 3012
 
2852 3013
 				// Is it valid?
2853
-				if (!empty($call))
2854
-					ob_start($call);
3014
+				if (!empty($call)) {
3015
+									ob_start($call);
3016
+				}
2855 3017
 			}
2856 3018
 
2857 3019
 		// Display the screen in the logical order.
@@ -2863,8 +3025,9 @@  discard block
 block discarded – undo
2863 3025
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2864 3026
 
2865 3027
 		// Anything special to put out?
2866
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
2867
-			echo $context['insert_after_template'];
3028
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3029
+					echo $context['insert_after_template'];
3030
+		}
2868 3031
 
2869 3032
 		// Just so we don't get caught in an endless loop of errors from the footer...
2870 3033
 		if (!$footer_done)
@@ -2873,14 +3036,16 @@  discard block
 block discarded – undo
2873 3036
 			template_footer();
2874 3037
 
2875 3038
 			// (since this is just debugging... it's okay that it's after </html>.)
2876
-			if (!isset($_REQUEST['xml']))
2877
-				displayDebug();
3039
+			if (!isset($_REQUEST['xml'])) {
3040
+							displayDebug();
3041
+			}
2878 3042
 		}
2879 3043
 	}
2880 3044
 
2881 3045
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
2882
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
2883
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3046
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3047
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3048
+	}
2884 3049
 
2885 3050
 	// For session check verification.... don't switch browsers...
2886 3051
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -2889,9 +3054,10 @@  discard block
 block discarded – undo
2889 3054
 	call_integration_hook('integrate_exit', array($do_footer));
2890 3055
 
2891 3056
 	// Don't exit if we're coming from index.php; that will pass through normally.
2892
-	if (!$from_index)
2893
-		exit;
2894
-}
3057
+	if (!$from_index) {
3058
+			exit;
3059
+	}
3060
+	}
2895 3061
 
2896 3062
 /**
2897 3063
  * Get the size of a specified image with better error handling.
@@ -2910,8 +3076,9 @@  discard block
 block discarded – undo
2910 3076
 	$url = str_replace(' ', '%20', $url);
2911 3077
 
2912 3078
 	// Can we pull this from the cache... please please?
2913
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
2914
-		return $temp;
3079
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3080
+			return $temp;
3081
+	}
2915 3082
 	$t = microtime();
2916 3083
 
2917 3084
 	// Get the host to pester...
@@ -2921,12 +3088,10 @@  discard block
 block discarded – undo
2921 3088
 	if ($url == '' || $url == 'http://' || $url == 'https://')
2922 3089
 	{
2923 3090
 		return false;
2924
-	}
2925
-	elseif (!isset($match[1]))
3091
+	} elseif (!isset($match[1]))
2926 3092
 	{
2927 3093
 		$size = @getimagesize($url);
2928
-	}
2929
-	else
3094
+	} else
2930 3095
 	{
2931 3096
 		// Try to connect to the server... give it half a second.
2932 3097
 		$temp = 0;
@@ -2965,12 +3130,14 @@  discard block
 block discarded – undo
2965 3130
 	}
2966 3131
 
2967 3132
 	// If we didn't get it, we failed.
2968
-	if (!isset($size))
2969
-		$size = false;
3133
+	if (!isset($size)) {
3134
+			$size = false;
3135
+	}
2970 3136
 
2971 3137
 	// If this took a long time, we may never have to do it again, but then again we might...
2972
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
2973
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3138
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3139
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3140
+	}
2974 3141
 
2975 3142
 	// Didn't work.
2976 3143
 	return $size;
@@ -2988,8 +3155,9 @@  discard block
 block discarded – undo
2988 3155
 
2989 3156
 	// Under SSI this function can be called more then once.  That can cause some problems.
2990 3157
 	//   So only run the function once unless we are forced to run it again.
2991
-	if ($loaded && !$forceload)
2992
-		return;
3158
+	if ($loaded && !$forceload) {
3159
+			return;
3160
+	}
2993 3161
 
2994 3162
 	$loaded = true;
2995 3163
 
@@ -3001,14 +3169,16 @@  discard block
 block discarded – undo
3001 3169
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3002 3170
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3003 3171
 	{
3004
-		if (trim($context['news_lines'][$i]) == '')
3005
-			continue;
3172
+		if (trim($context['news_lines'][$i]) == '') {
3173
+					continue;
3174
+		}
3006 3175
 
3007 3176
 		// Clean it up for presentation ;).
3008 3177
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3009 3178
 	}
3010
-	if (!empty($context['news_lines']))
3011
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3179
+	if (!empty($context['news_lines'])) {
3180
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3181
+	}
3012 3182
 
3013 3183
 	if (!$user_info['is_guest'])
3014 3184
 	{
@@ -3017,40 +3187,48 @@  discard block
 block discarded – undo
3017 3187
 		$context['user']['alerts'] = &$user_info['alerts'];
3018 3188
 
3019 3189
 		// Personal message popup...
3020
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3021
-			$context['user']['popup_messages'] = true;
3022
-		else
3023
-			$context['user']['popup_messages'] = false;
3190
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3191
+					$context['user']['popup_messages'] = true;
3192
+		} else {
3193
+					$context['user']['popup_messages'] = false;
3194
+		}
3024 3195
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3025 3196
 
3026
-		if (allowedTo('moderate_forum'))
3027
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3197
+		if (allowedTo('moderate_forum')) {
3198
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3199
+		}
3028 3200
 
3029 3201
 		$context['user']['avatar'] = array();
3030 3202
 
3031 3203
 		// Check for gravatar first since we might be forcing them...
3032 3204
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3033 3205
 		{
3034
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3035
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3036
-			else
3037
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3206
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3207
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3208
+			} else {
3209
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3210
+			}
3038 3211
 		}
3039 3212
 		// Uploaded?
3040
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3041
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3213
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3214
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3215
+		}
3042 3216
 		// Full URL?
3043
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3044
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3217
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3218
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3219
+		}
3045 3220
 		// Otherwise we assume it's server stored.
3046
-		elseif ($user_info['avatar']['url'] != '')
3047
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3221
+		elseif ($user_info['avatar']['url'] != '') {
3222
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3223
+		}
3048 3224
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3049
-		else
3050
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3225
+		else {
3226
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3227
+		}
3051 3228
 
3052
-		if (!empty($context['user']['avatar']))
3053
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3229
+		if (!empty($context['user']['avatar'])) {
3230
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3231
+		}
3054 3232
 
3055 3233
 		// Figure out how long they've been logged in.
3056 3234
 		$context['user']['total_time_logged_in'] = array(
@@ -3058,8 +3236,7 @@  discard block
 block discarded – undo
3058 3236
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3059 3237
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3060 3238
 		);
3061
-	}
3062
-	else
3239
+	} else
3063 3240
 	{
3064 3241
 		$context['user']['messages'] = 0;
3065 3242
 		$context['user']['unread_messages'] = 0;
@@ -3067,12 +3244,14 @@  discard block
 block discarded – undo
3067 3244
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3068 3245
 		$context['user']['popup_messages'] = false;
3069 3246
 
3070
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3071
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3247
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3248
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3249
+		}
3072 3250
 
3073 3251
 		// If we've upgraded recently, go easy on the passwords.
3074
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3075
-			$context['disable_login_hashing'] = true;
3252
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3253
+					$context['disable_login_hashing'] = true;
3254
+		}
3076 3255
 	}
3077 3256
 
3078 3257
 	// Setup the main menu items.
@@ -3085,8 +3264,8 @@  discard block
 block discarded – undo
3085 3264
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3086 3265
 
3087 3266
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3088
-	if ($context['show_pm_popup'])
3089
-		addInlineJavaScript('
3267
+	if ($context['show_pm_popup']) {
3268
+			addInlineJavaScript('
3090 3269
 		jQuery(document).ready(function($) {
3091 3270
 			new smc_Popup({
3092 3271
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3094,15 +3273,17 @@  discard block
 block discarded – undo
3094 3273
 				icon_class: \'generic_icons mail_new\'
3095 3274
 			});
3096 3275
 		});');
3276
+	}
3097 3277
 
3098 3278
 	// Add a generic "Are you sure?" confirmation message.
3099 3279
 	addInlineJavaScript('
3100 3280
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3101 3281
 
3102 3282
 	// Now add the capping code for avatars.
3103
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3104
-		addInlineCss('
3283
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3284
+			addInlineCss('
3105 3285
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3286
+	}
3106 3287
 
3107 3288
 	// This looks weird, but it's because BoardIndex.php references the variable.
3108 3289
 	$context['common_stats']['latest_member'] = array(
@@ -3119,11 +3300,13 @@  discard block
 block discarded – undo
3119 3300
 	);
3120 3301
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3121 3302
 
3122
-	if (empty($settings['theme_version']))
3123
-		addJavaScriptVar('smf_scripturl', $scripturl);
3303
+	if (empty($settings['theme_version'])) {
3304
+			addJavaScriptVar('smf_scripturl', $scripturl);
3305
+	}
3124 3306
 
3125
-	if (!isset($context['page_title']))
3126
-		$context['page_title'] = '';
3307
+	if (!isset($context['page_title'])) {
3308
+			$context['page_title'] = '';
3309
+	}
3127 3310
 
3128 3311
 	// Set some specific vars.
3129 3312
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3133,21 +3316,23 @@  discard block
 block discarded – undo
3133 3316
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3134 3317
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3135 3318
 
3136
-	if (!empty($context['meta_keywords']))
3137
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3319
+	if (!empty($context['meta_keywords'])) {
3320
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3321
+	}
3138 3322
 
3139
-	if (!empty($context['canonical_url']))
3140
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3323
+	if (!empty($context['canonical_url'])) {
3324
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3325
+	}
3141 3326
 
3142
-	if (!empty($settings['og_image']))
3143
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3327
+	if (!empty($settings['og_image'])) {
3328
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3329
+	}
3144 3330
 
3145 3331
 	if (!empty($context['meta_description']))
3146 3332
 	{
3147 3333
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3148 3334
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3149
-	}
3150
-	else
3335
+	} else
3151 3336
 	{
3152 3337
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3153 3338
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3172,8 +3357,9 @@  discard block
 block discarded – undo
3172 3357
 	$memory_needed = memoryReturnBytes($needed);
3173 3358
 
3174 3359
 	// should we account for how much is currently being used?
3175
-	if ($in_use)
3176
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3360
+	if ($in_use) {
3361
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3362
+	}
3177 3363
 
3178 3364
 	// if more is needed, request it
3179 3365
 	if ($memory_current < $memory_needed)
@@ -3196,8 +3382,9 @@  discard block
 block discarded – undo
3196 3382
  */
3197 3383
 function memoryReturnBytes($val)
3198 3384
 {
3199
-	if (is_integer($val))
3200
-		return $val;
3385
+	if (is_integer($val)) {
3386
+			return $val;
3387
+	}
3201 3388
 
3202 3389
 	// Separate the number from the designator
3203 3390
 	$val = trim($val);
@@ -3233,10 +3420,11 @@  discard block
 block discarded – undo
3233 3420
 		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3234 3421
 
3235 3422
 		// Are we debugging the template/html content?
3236
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3237
-			header('Content-Type: application/xhtml+xml');
3238
-		elseif (!isset($_REQUEST['xml']))
3239
-			header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3423
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3424
+					header('Content-Type: application/xhtml+xml');
3425
+		} elseif (!isset($_REQUEST['xml'])) {
3426
+					header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3427
+		}
3240 3428
 	}
3241 3429
 
3242 3430
 	header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3245,8 +3433,9 @@  discard block
 block discarded – undo
3245 3433
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3246 3434
 	{
3247 3435
 		$position = array_search('body', $context['template_layers']);
3248
-		if ($position === false)
3249
-			$position = array_search('main', $context['template_layers']);
3436
+		if ($position === false) {
3437
+					$position = array_search('main', $context['template_layers']);
3438
+		}
3250 3439
 
3251 3440
 		if ($position !== false)
3252 3441
 		{
@@ -3274,23 +3463,25 @@  discard block
 block discarded – undo
3274 3463
 
3275 3464
 			foreach ($securityFiles as $i => $securityFile)
3276 3465
 			{
3277
-				if (!file_exists($boarddir . '/' . $securityFile))
3278
-					unset($securityFiles[$i]);
3466
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3467
+									unset($securityFiles[$i]);
3468
+				}
3279 3469
 			}
3280 3470
 
3281 3471
 			// We are already checking so many files...just few more doesn't make any difference! :P
3282
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3283
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3284
-
3285
-			else
3286
-				$path = $modSettings['attachmentUploadDir'];
3472
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3473
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3474
+			} else {
3475
+							$path = $modSettings['attachmentUploadDir'];
3476
+			}
3287 3477
 
3288 3478
 			secureDirectory($path, true);
3289 3479
 			secureDirectory($cachedir);
3290 3480
 
3291 3481
 			// If agreement is enabled, at least the english version shall exists
3292
-			if ($modSettings['requireAgreement'])
3293
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3482
+			if ($modSettings['requireAgreement']) {
3483
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3484
+			}
3294 3485
 
3295 3486
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3296 3487
 			{
@@ -3305,18 +3496,21 @@  discard block
 block discarded – undo
3305 3496
 					echo '
3306 3497
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3307 3498
 
3308
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3309
-						echo '
3499
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3500
+											echo '
3310 3501
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3502
+					}
3311 3503
 				}
3312 3504
 
3313
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3314
-					echo '
3505
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3506
+									echo '
3315 3507
 				<strong>', $txt['cache_writable'], '</strong><br>';
3508
+				}
3316 3509
 
3317
-				if (!empty($agreement))
3318
-					echo '
3510
+				if (!empty($agreement)) {
3511
+									echo '
3319 3512
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3513
+				}
3320 3514
 
3321 3515
 				echo '
3322 3516
 			</p>
@@ -3331,16 +3525,18 @@  discard block
 block discarded – undo
3331 3525
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3332 3526
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3333 3527
 
3334
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3335
-				echo '
3528
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3529
+							echo '
3336 3530
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3531
+			}
3337 3532
 
3338
-			if (!empty($_SESSION['ban']['expire_time']))
3339
-				echo '
3533
+			if (!empty($_SESSION['ban']['expire_time'])) {
3534
+							echo '
3340 3535
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3341
-			else
3342
-				echo '
3536
+			} else {
3537
+							echo '
3343 3538
 					<div>', $txt['your_ban_expires_never'], '</div>';
3539
+			}
3344 3540
 
3345 3541
 			echo '
3346 3542
 				</div>';
@@ -3356,8 +3552,9 @@  discard block
 block discarded – undo
3356 3552
 	global $forum_copyright, $software_year, $forum_version;
3357 3553
 
3358 3554
 	// Don't display copyright for things like SSI.
3359
-	if (!isset($forum_version) || !isset($software_year))
3360
-		return;
3555
+	if (!isset($forum_version) || !isset($software_year)) {
3556
+			return;
3557
+	}
3361 3558
 
3362 3559
 	// Put in the version...
3363 3560
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3375,9 +3572,10 @@  discard block
 block discarded – undo
3375 3572
 	$context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3));
3376 3573
 	$context['load_queries'] = $db_count;
3377 3574
 
3378
-	foreach (array_reverse($context['template_layers']) as $layer)
3379
-		loadSubTemplate($layer . '_below', true);
3380
-}
3575
+	foreach (array_reverse($context['template_layers']) as $layer) {
3576
+			loadSubTemplate($layer . '_below', true);
3577
+	}
3578
+	}
3381 3579
 
3382 3580
 /**
3383 3581
  * Output the Javascript files
@@ -3408,8 +3606,7 @@  discard block
 block discarded – undo
3408 3606
 			{
3409 3607
 				echo '
3410 3608
 		var ', $key, ';';
3411
-			}
3412
-			else
3609
+			} else
3413 3610
 			{
3414 3611
 				echo '
3415 3612
 		var ', $key, ' = ', $value, ';';
@@ -3424,26 +3621,27 @@  discard block
 block discarded – undo
3424 3621
 	foreach ($context['javascript_files'] as $id => $js_file)
3425 3622
 	{
3426 3623
 		// Last minute call! allow theme authors to disable single files.
3427
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3428
-			continue;
3624
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3625
+					continue;
3626
+		}
3429 3627
 
3430 3628
 		// By default all files don't get minimized unless the file explicitly says so!
3431 3629
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3432 3630
 		{
3433
-			if ($do_deferred && !empty($js_file['options']['defer']))
3434
-				$toMinifyDefer[] = $js_file;
3435
-
3436
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3437
-				$toMinify[] = $js_file;
3631
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3632
+							$toMinifyDefer[] = $js_file;
3633
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3634
+							$toMinify[] = $js_file;
3635
+			}
3438 3636
 
3439 3637
 			// Grab a random seed.
3440
-			if (!isset($minSeed))
3441
-				$minSeed = $js_file['options']['seed'];
3442
-		}
3443
-
3444
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3445
-			echo '
3638
+			if (!isset($minSeed)) {
3639
+							$minSeed = $js_file['options']['seed'];
3640
+			}
3641
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3642
+					echo '
3446 3643
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3644
+		}
3447 3645
 	}
3448 3646
 
3449 3647
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3451,14 +3649,14 @@  discard block
 block discarded – undo
3451 3649
 		$result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred);
3452 3650
 
3453 3651
 		// Minify process couldn't work, print each individual files.
3454
-		if (!empty($result) && is_array($result))
3455
-			foreach ($result as $minFailedFile)
3652
+		if (!empty($result) && is_array($result)) {
3653
+					foreach ($result as $minFailedFile)
3456 3654
 				echo '
3457 3655
 	<script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>';
3458
-
3459
-		else
3460
-			echo '
3656
+		} else {
3657
+					echo '
3461 3658
 	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3659
+		}
3462 3660
 	}
3463 3661
 
3464 3662
 	// Inline JavaScript - Actually useful some times!
@@ -3469,8 +3667,9 @@  discard block
 block discarded – undo
3469 3667
 			echo '
3470 3668
 <script>';
3471 3669
 
3472
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3473
-				echo $js_code;
3670
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3671
+							echo $js_code;
3672
+			}
3474 3673
 
3475 3674
 			echo '
3476 3675
 </script>';
@@ -3481,8 +3680,9 @@  discard block
 block discarded – undo
3481 3680
 			echo '
3482 3681
 	<script>';
3483 3682
 
3484
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3485
-				echo $js_code;
3683
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3684
+							echo $js_code;
3685
+			}
3486 3686
 
3487 3687
 			echo '
3488 3688
 	</script>';
@@ -3507,8 +3707,9 @@  discard block
 block discarded – undo
3507 3707
 	foreach ($context['css_files'] as $id => $file)
3508 3708
 	{
3509 3709
 		// Last minute call! allow theme authors to disable single files.
3510
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3511
-			continue;
3710
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3711
+					continue;
3712
+		}
3512 3713
 
3513 3714
 		// By default all files don't get minimized unless the file explicitly says so!
3514 3715
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
@@ -3516,12 +3717,12 @@  discard block
 block discarded – undo
3516 3717
 			$toMinify[] = $file;
3517 3718
 
3518 3719
 			// Grab a random seed.
3519
-			if (!isset($minSeed))
3520
-				$minSeed = $file['options']['seed'];
3720
+			if (!isset($minSeed)) {
3721
+							$minSeed = $file['options']['seed'];
3722
+			}
3723
+		} else {
3724
+					$normal[] = $file['fileUrl'];
3521 3725
 		}
3522
-
3523
-		else
3524
-			$normal[] = $file['fileUrl'];
3525 3726
 	}
3526 3727
 
3527 3728
 	if (!empty($toMinify))
@@ -3529,28 +3730,30 @@  discard block
 block discarded – undo
3529 3730
 		$result = custMinify($toMinify, 'css');
3530 3731
 
3531 3732
 		// Minify process couldn't work, print each individual files.
3532
-		if (!empty($result) && is_array($result))
3533
-			foreach ($result as $minFailedFile)
3733
+		if (!empty($result) && is_array($result)) {
3734
+					foreach ($result as $minFailedFile)
3534 3735
 				echo '
3535 3736
 	<link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">';
3536
-
3537
-		else
3538
-			echo '
3737
+		} else {
3738
+					echo '
3539 3739
 	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3740
+		}
3540 3741
 	}
3541 3742
 
3542 3743
 	// Print the rest after the minified files.
3543
-	if (!empty($normal))
3544
-		foreach ($normal as $nf)
3744
+	if (!empty($normal)) {
3745
+			foreach ($normal as $nf)
3545 3746
 			echo '
3546 3747
 	<link rel="stylesheet" href="', $nf ,'">';
3748
+	}
3547 3749
 
3548 3750
 	if ($db_show_debug === true)
3549 3751
 	{
3550 3752
 		// Try to keep only what's useful.
3551 3753
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3552
-		foreach ($context['css_files'] as $file)
3553
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3754
+		foreach ($context['css_files'] as $file) {
3755
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3756
+		}
3554 3757
 	}
3555 3758
 
3556 3759
 	if (!empty($context['css_header']))
@@ -3558,9 +3761,10 @@  discard block
 block discarded – undo
3558 3761
 		echo '
3559 3762
 	<style>';
3560 3763
 
3561
-		foreach ($context['css_header'] as $css)
3562
-			echo $css .'
3764
+		foreach ($context['css_header'] as $css) {
3765
+					echo $css .'
3563 3766
 	';
3767
+		}
3564 3768
 
3565 3769
 		echo'
3566 3770
 	</style>';
@@ -3584,15 +3788,17 @@  discard block
 block discarded – undo
3584 3788
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3585 3789
 	$data = !empty($data) ? $data : false;
3586 3790
 
3587
-	if (empty($type) || empty($data))
3588
-		return false;
3791
+	if (empty($type) || empty($data)) {
3792
+			return false;
3793
+	}
3589 3794
 
3590 3795
 	// Did we already did this?
3591 3796
 	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3592 3797
 
3593 3798
 	// Already done?
3594
-	if (!empty($toCache))
3595
-		return true;
3799
+	if (!empty($toCache)) {
3800
+			return true;
3801
+	}
3596 3802
 
3597 3803
 	// Yep, need a bunch of files.
3598 3804
 	require_once($sourcedir . '/minify/src/Minify.php');
@@ -3680,8 +3886,9 @@  discard block
 block discarded – undo
3680 3886
 	global $modSettings, $smcFunc;
3681 3887
 
3682 3888
 	// Just make up a nice hash...
3683
-	if ($new)
3684
-		return sha1(md5($filename . time()) . mt_rand());
3889
+	if ($new) {
3890
+			return sha1(md5($filename . time()) . mt_rand());
3891
+	}
3685 3892
 
3686 3893
 	// Grab the file hash if it wasn't added.
3687 3894
 	// Left this for legacy.
@@ -3695,23 +3902,25 @@  discard block
 block discarded – undo
3695 3902
 				'id_attach' => $attachment_id,
3696 3903
 			));
3697 3904
 
3698
-		if ($smcFunc['db_num_rows']($request) === 0)
3699
-			return false;
3905
+		if ($smcFunc['db_num_rows']($request) === 0) {
3906
+					return false;
3907
+		}
3700 3908
 
3701 3909
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3702 3910
 		$smcFunc['db_free_result']($request);
3703 3911
 	}
3704 3912
 
3705 3913
 	// Still no hash? mmm...
3706
-	if (empty($file_hash))
3707
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
3914
+	if (empty($file_hash)) {
3915
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
3916
+	}
3708 3917
 
3709 3918
 	// Are we using multiple directories?
3710
-	if (!empty($modSettings['currentAttachmentUploadDir']))
3711
-		$path = $modSettings['attachmentUploadDir'][$dir];
3712
-
3713
-	else
3714
-		$path = $modSettings['attachmentUploadDir'];
3919
+	if (!empty($modSettings['currentAttachmentUploadDir'])) {
3920
+			$path = $modSettings['attachmentUploadDir'][$dir];
3921
+	} else {
3922
+			$path = $modSettings['attachmentUploadDir'];
3923
+	}
3715 3924
 
3716 3925
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3717 3926
 }
@@ -3726,8 +3935,9 @@  discard block
 block discarded – undo
3726 3935
 function ip2range($fullip)
3727 3936
 {
3728 3937
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3729
-	if ($fullip == 'unknown')
3730
-		$fullip = '255.255.255.255';
3938
+	if ($fullip == 'unknown') {
3939
+			$fullip = '255.255.255.255';
3940
+	}
3731 3941
 
3732 3942
 	$ip_parts = explode('-', $fullip);
3733 3943
 	$ip_array = array();
@@ -3751,10 +3961,11 @@  discard block
 block discarded – undo
3751 3961
 		$ip_array['low'] = $ip_parts[0];
3752 3962
 		$ip_array['high'] = $ip_parts[1];
3753 3963
 		return $ip_array;
3754
-	}
3755
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
3964
+	} elseif (count($ip_parts) == 2) {
3965
+		// if ip 22.22.*-22.22.*
3756 3966
 	{
3757 3967
 		$valid_low = isValidIP($ip_parts[0]);
3968
+	}
3758 3969
 		$valid_high = isValidIP($ip_parts[1]);
3759 3970
 		$count = 0;
3760 3971
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3769,7 +3980,9 @@  discard block
 block discarded – undo
3769 3980
 				$ip_parts[0] .= $mode . $min;
3770 3981
 				$valid_low = isValidIP($ip_parts[0]);
3771 3982
 				$count++;
3772
-				if ($count > 9) break;
3983
+				if ($count > 9) {
3984
+					break;
3985
+				}
3773 3986
 			}
3774 3987
 		}
3775 3988
 
@@ -3783,7 +3996,9 @@  discard block
 block discarded – undo
3783 3996
 				$ip_parts[1] .= $mode . $max;
3784 3997
 				$valid_high = isValidIP($ip_parts[1]);
3785 3998
 				$count++;
3786
-				if ($count > 9) break;
3999
+				if ($count > 9) {
4000
+					break;
4001
+				}
3787 4002
 			}
3788 4003
 		}
3789 4004
 
@@ -3808,46 +4023,54 @@  discard block
 block discarded – undo
3808 4023
 {
3809 4024
 	global $modSettings;
3810 4025
 
3811
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3812
-		return $host;
4026
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4027
+			return $host;
4028
+	}
3813 4029
 	$t = microtime();
3814 4030
 
3815 4031
 	// Try the Linux host command, perhaps?
3816 4032
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3817 4033
 	{
3818
-		if (!isset($modSettings['host_to_dis']))
3819
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3820
-		else
3821
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4034
+		if (!isset($modSettings['host_to_dis'])) {
4035
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4036
+		} else {
4037
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4038
+		}
3822 4039
 
3823 4040
 		// Did host say it didn't find anything?
3824
-		if (strpos($test, 'not found') !== false)
3825
-			$host = '';
4041
+		if (strpos($test, 'not found') !== false) {
4042
+					$host = '';
4043
+		}
3826 4044
 		// Invalid server option?
3827
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3828
-			updateSettings(array('host_to_dis' => 1));
4045
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4046
+					updateSettings(array('host_to_dis' => 1));
4047
+		}
3829 4048
 		// Maybe it found something, after all?
3830
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3831
-			$host = $match[1];
4049
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4050
+					$host = $match[1];
4051
+		}
3832 4052
 	}
3833 4053
 
3834 4054
 	// This is nslookup; usually only Windows, but possibly some Unix?
3835 4055
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3836 4056
 	{
3837 4057
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3838
-		if (strpos($test, 'Non-existent domain') !== false)
3839
-			$host = '';
3840
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3841
-			$host = $match[1];
4058
+		if (strpos($test, 'Non-existent domain') !== false) {
4059
+					$host = '';
4060
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4061
+					$host = $match[1];
4062
+		}
3842 4063
 	}
3843 4064
 
3844 4065
 	// This is the last try :/.
3845
-	if (!isset($host) || $host === false)
3846
-		$host = @gethostbyaddr($ip);
4066
+	if (!isset($host) || $host === false) {
4067
+			$host = @gethostbyaddr($ip);
4068
+	}
3847 4069
 
3848 4070
 	// It took a long time, so let's cache it!
3849
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3850
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4071
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4072
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4073
+	}
3851 4074
 
3852 4075
 	return $host;
3853 4076
 }
@@ -3883,20 +4106,21 @@  discard block
 block discarded – undo
3883 4106
 			{
3884 4107
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
3885 4108
 				$total = 0;
3886
-				for ($i = 0; $i < $max_chars; $i++)
3887
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4109
+				for ($i = 0; $i < $max_chars; $i++) {
4110
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4111
+				}
3888 4112
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
3889 4113
 			}
3890 4114
 		}
3891 4115
 		return array_unique($returned_ints);
3892
-	}
3893
-	else
4116
+	} else
3894 4117
 	{
3895 4118
 		// Trim characters before and after and add slashes for database insertion.
3896 4119
 		$returned_words = array();
3897
-		foreach ($words as $word)
3898
-			if (($word = trim($word, '-_\'')) !== '')
4120
+		foreach ($words as $word) {
4121
+					if (($word = trim($word, '-_\'')) !== '')
3899 4122
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4123
+		}
3900 4124
 
3901 4125
 		// Filter out all words that occur more than once.
3902 4126
 		return array_unique($returned_words);
@@ -3918,16 +4142,18 @@  discard block
 block discarded – undo
3918 4142
 	global $settings, $txt;
3919 4143
 
3920 4144
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
3921
-	if (function_exists('template_create_button') && !$force_use)
3922
-		return template_create_button($name, $alt, $label = '', $custom = '');
4145
+	if (function_exists('template_create_button') && !$force_use) {
4146
+			return template_create_button($name, $alt, $label = '', $custom = '');
4147
+	}
3923 4148
 
3924
-	if (!$settings['use_image_buttons'])
3925
-		return $txt[$alt];
3926
-	elseif (!empty($settings['use_buttons']))
3927
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
3928
-	else
3929
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
3930
-}
4149
+	if (!$settings['use_image_buttons']) {
4150
+			return $txt[$alt];
4151
+	} elseif (!empty($settings['use_buttons'])) {
4152
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4153
+	} else {
4154
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4155
+	}
4156
+	}
3931 4157
 
3932 4158
 /**
3933 4159
  * Sets up all of the top menu buttons
@@ -3970,9 +4196,10 @@  discard block
 block discarded – undo
3970 4196
 	var user_menus = new smc_PopupMenu();
3971 4197
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
3972 4198
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
3973
-		if ($context['allow_pm'])
3974
-			addInlineJavaScript('
4199
+		if ($context['allow_pm']) {
4200
+					addInlineJavaScript('
3975 4201
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4202
+		}
3976 4203
 
3977 4204
 		if (!empty($modSettings['enable_ajax_alerts']))
3978 4205
 		{
@@ -4132,88 +4359,96 @@  discard block
 block discarded – undo
4132 4359
 
4133 4360
 		// Now we put the buttons in the context so the theme can use them.
4134 4361
 		$menu_buttons = array();
4135
-		foreach ($buttons as $act => $button)
4136
-			if (!empty($button['show']))
4362
+		foreach ($buttons as $act => $button) {
4363
+					if (!empty($button['show']))
4137 4364
 			{
4138 4365
 				$button['active_button'] = false;
4366
+		}
4139 4367
 
4140 4368
 				// This button needs some action.
4141
-				if (isset($button['action_hook']))
4142
-					$needs_action_hook = true;
4369
+				if (isset($button['action_hook'])) {
4370
+									$needs_action_hook = true;
4371
+				}
4143 4372
 
4144 4373
 				// Make sure the last button truly is the last button.
4145 4374
 				if (!empty($button['is_last']))
4146 4375
 				{
4147
-					if (isset($last_button))
4148
-						unset($menu_buttons[$last_button]['is_last']);
4376
+					if (isset($last_button)) {
4377
+											unset($menu_buttons[$last_button]['is_last']);
4378
+					}
4149 4379
 					$last_button = $act;
4150 4380
 				}
4151 4381
 
4152 4382
 				// Go through the sub buttons if there are any.
4153
-				if (!empty($button['sub_buttons']))
4154
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4383
+				if (!empty($button['sub_buttons'])) {
4384
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4155 4385
 					{
4156 4386
 						if (empty($subbutton['show']))
4157 4387
 							unset($button['sub_buttons'][$key]);
4388
+				}
4158 4389
 
4159 4390
 						// 2nd level sub buttons next...
4160 4391
 						if (!empty($subbutton['sub_buttons']))
4161 4392
 						{
4162 4393
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4163 4394
 							{
4164
-								if (empty($sub_button2['show']))
4165
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4395
+								if (empty($sub_button2['show'])) {
4396
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4397
+								}
4166 4398
 							}
4167 4399
 						}
4168 4400
 					}
4169 4401
 
4170 4402
 				// Does this button have its own icon?
4171
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4172
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4173
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4174
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4175
-				elseif (isset($button['icon']))
4176
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4177
-				else
4178
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4403
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4404
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4405
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4406
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4407
+				} elseif (isset($button['icon'])) {
4408
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4409
+				} else {
4410
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4411
+				}
4179 4412
 
4180 4413
 				$menu_buttons[$act] = $button;
4181 4414
 			}
4182 4415
 
4183
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4184
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4416
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4417
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4418
+		}
4185 4419
 	}
4186 4420
 
4187 4421
 	$context['menu_buttons'] = $menu_buttons;
4188 4422
 
4189 4423
 	// Logging out requires the session id in the url.
4190
-	if (isset($context['menu_buttons']['logout']))
4191
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4424
+	if (isset($context['menu_buttons']['logout'])) {
4425
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4426
+	}
4192 4427
 
4193 4428
 	// Figure out which action we are doing so we can set the active tab.
4194 4429
 	// Default to home.
4195 4430
 	$current_action = 'home';
4196 4431
 
4197
-	if (isset($context['menu_buttons'][$context['current_action']]))
4198
-		$current_action = $context['current_action'];
4199
-	elseif ($context['current_action'] == 'search2')
4200
-		$current_action = 'search';
4201
-	elseif ($context['current_action'] == 'theme')
4202
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4203
-	elseif ($context['current_action'] == 'register2')
4204
-		$current_action = 'register';
4205
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4206
-		$current_action = 'login';
4207
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4208
-		$current_action = 'moderate';
4432
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4433
+			$current_action = $context['current_action'];
4434
+	} elseif ($context['current_action'] == 'search2') {
4435
+			$current_action = 'search';
4436
+	} elseif ($context['current_action'] == 'theme') {
4437
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4438
+	} elseif ($context['current_action'] == 'register2') {
4439
+			$current_action = 'register';
4440
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4441
+			$current_action = 'login';
4442
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4443
+			$current_action = 'moderate';
4444
+	}
4209 4445
 
4210 4446
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4211 4447
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4212 4448
 	{
4213 4449
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4214 4450
 		$context[$current_action] = true;
4215
-	}
4216
-	elseif ($context['current_action'] == 'pm')
4451
+	} elseif ($context['current_action'] == 'pm')
4217 4452
 	{
4218 4453
 		$current_action = 'self_pm';
4219 4454
 		$context['self_pm'] = true;
@@ -4256,12 +4491,14 @@  discard block
 block discarded – undo
4256 4491
 	}
4257 4492
 
4258 4493
 	// Not all actions are simple.
4259
-	if (!empty($needs_action_hook))
4260
-		call_integration_hook('integrate_current_action', array(&$current_action));
4494
+	if (!empty($needs_action_hook)) {
4495
+			call_integration_hook('integrate_current_action', array(&$current_action));
4496
+	}
4261 4497
 
4262
-	if (isset($context['menu_buttons'][$current_action]))
4263
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4264
-}
4498
+	if (isset($context['menu_buttons'][$current_action])) {
4499
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4500
+	}
4501
+	}
4265 4502
 
4266 4503
 /**
4267 4504
  * Generate a random seed and ensure it's stored in settings.
@@ -4285,16 +4522,19 @@  discard block
 block discarded – undo
4285 4522
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4286 4523
 	global $context, $txt;
4287 4524
 
4288
-	if ($db_show_debug === true)
4289
-		$context['debug']['hooks'][] = $hook;
4525
+	if ($db_show_debug === true) {
4526
+			$context['debug']['hooks'][] = $hook;
4527
+	}
4290 4528
 
4291 4529
 	// Need to have some control.
4292
-	if (!isset($context['instances']))
4293
-		$context['instances'] = array();
4530
+	if (!isset($context['instances'])) {
4531
+			$context['instances'] = array();
4532
+	}
4294 4533
 
4295 4534
 	$results = array();
4296
-	if (empty($modSettings[$hook]))
4297
-		return $results;
4535
+	if (empty($modSettings[$hook])) {
4536
+			return $results;
4537
+	}
4298 4538
 
4299 4539
 	// Define some needed vars.
4300 4540
 	$function = false;
@@ -4304,14 +4544,16 @@  discard block
 block discarded – undo
4304 4544
 	foreach ($functions as $function)
4305 4545
 	{
4306 4546
 		// Hook has been marked as "disabled". Skip it!
4307
-		if (strpos($function, '!') !== false)
4308
-			continue;
4547
+		if (strpos($function, '!') !== false) {
4548
+					continue;
4549
+		}
4309 4550
 
4310 4551
 		$call = call_helper($function, true);
4311 4552
 
4312 4553
 		// Is it valid?
4313
-		if (!empty($call))
4314
-			$results[$function] = call_user_func_array($call, $parameters);
4554
+		if (!empty($call)) {
4555
+					$results[$function] = call_user_func_array($call, $parameters);
4556
+		}
4315 4557
 
4316 4558
 		// Whatever it was suppose to call, it failed :(
4317 4559
 		elseif (!empty($function))
@@ -4327,8 +4569,9 @@  discard block
 block discarded – undo
4327 4569
 			}
4328 4570
 
4329 4571
 			// "Assume" the file resides on $boarddir somewhere...
4330
-			else
4331
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4572
+			else {
4573
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4574
+			}
4332 4575
 		}
4333 4576
 	}
4334 4577
 
@@ -4350,12 +4593,14 @@  discard block
 block discarded – undo
4350 4593
 	global $smcFunc, $modSettings;
4351 4594
 
4352 4595
 	// Any objects?
4353
-	if ($object)
4354
-		$function = $function . '#';
4596
+	if ($object) {
4597
+			$function = $function . '#';
4598
+	}
4355 4599
 
4356 4600
 	// Any files  to load?
4357
-	if (!empty($file) && is_string($file))
4358
-		$function = $file . (!empty($function) ? '|' . $function : '');
4601
+	if (!empty($file) && is_string($file)) {
4602
+			$function = $file . (!empty($function) ? '|' . $function : '');
4603
+	}
4359 4604
 
4360 4605
 	// Get the correct string.
4361 4606
 	$integration_call = $function;
@@ -4377,13 +4622,14 @@  discard block
 block discarded – undo
4377 4622
 		if (!empty($current_functions))
4378 4623
 		{
4379 4624
 			$current_functions = explode(',', $current_functions);
4380
-			if (in_array($integration_call, $current_functions))
4381
-				return;
4625
+			if (in_array($integration_call, $current_functions)) {
4626
+							return;
4627
+			}
4382 4628
 
4383 4629
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4630
+		} else {
4631
+					$permanent_functions = array($integration_call);
4384 4632
 		}
4385
-		else
4386
-			$permanent_functions = array($integration_call);
4387 4633
 
4388 4634
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4389 4635
 	}
@@ -4392,8 +4638,9 @@  discard block
 block discarded – undo
4392 4638
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4393 4639
 
4394 4640
 	// Do nothing, if it's already there.
4395
-	if (in_array($integration_call, $functions))
4396
-		return;
4641
+	if (in_array($integration_call, $functions)) {
4642
+			return;
4643
+	}
4397 4644
 
4398 4645
 	$functions[] = $integration_call;
4399 4646
 	$modSettings[$hook] = implode(',', $functions);
@@ -4416,12 +4663,14 @@  discard block
 block discarded – undo
4416 4663
 	global $smcFunc, $modSettings;
4417 4664
 
4418 4665
 	// Any objects?
4419
-	if ($object)
4420
-		$function = $function . '#';
4666
+	if ($object) {
4667
+			$function = $function . '#';
4668
+	}
4421 4669
 
4422 4670
 	// Any files  to load?
4423
-	if (!empty($file) && is_string($file))
4424
-		$function = $file . '|' . $function;
4671
+	if (!empty($file) && is_string($file)) {
4672
+			$function = $file . '|' . $function;
4673
+	}
4425 4674
 
4426 4675
 	// Get the correct string.
4427 4676
 	$integration_call = $function;
@@ -4442,16 +4691,18 @@  discard block
 block discarded – undo
4442 4691
 	{
4443 4692
 		$current_functions = explode(',', $current_functions);
4444 4693
 
4445
-		if (in_array($integration_call, $current_functions))
4446
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4694
+		if (in_array($integration_call, $current_functions)) {
4695
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4696
+		}
4447 4697
 	}
4448 4698
 
4449 4699
 	// Turn the function list into something usable.
4450 4700
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4451 4701
 
4452 4702
 	// You can only remove it if it's available.
4453
-	if (!in_array($integration_call, $functions))
4454
-		return;
4703
+	if (!in_array($integration_call, $functions)) {
4704
+			return;
4705
+	}
4455 4706
 
4456 4707
 	$functions = array_diff($functions, array($integration_call));
4457 4708
 	$modSettings[$hook] = implode(',', $functions);
@@ -4472,17 +4723,20 @@  discard block
 block discarded – undo
4472 4723
 	global $context, $smcFunc, $txt, $db_show_debug;
4473 4724
 
4474 4725
 	// Really?
4475
-	if (empty($string))
4476
-		return false;
4726
+	if (empty($string)) {
4727
+			return false;
4728
+	}
4477 4729
 
4478 4730
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4479 4731
 	// A closure? should be a callable one.
4480
-	if (is_array($string) || $string instanceof Closure)
4481
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4732
+	if (is_array($string) || $string instanceof Closure) {
4733
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4734
+	}
4482 4735
 
4483 4736
 	// No full objects, sorry! pass a method or a property instead!
4484
-	if (is_object($string))
4485
-		return false;
4737
+	if (is_object($string)) {
4738
+			return false;
4739
+	}
4486 4740
 
4487 4741
 	// Stay vitaminized my friends...
4488 4742
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4491,8 +4745,9 @@  discard block
 block discarded – undo
4491 4745
 	$string = load_file($string);
4492 4746
 
4493 4747
 	// Loaded file failed
4494
-	if (empty($string))
4495
-		return false;
4748
+	if (empty($string)) {
4749
+			return false;
4750
+	}
4496 4751
 
4497 4752
 	// Found a method.
4498 4753
 	if (strpos($string, '::') !== false)
@@ -4513,8 +4768,9 @@  discard block
 block discarded – undo
4513 4768
 				// Add another one to the list.
4514 4769
 				if ($db_show_debug === true)
4515 4770
 				{
4516
-					if (!isset($context['debug']['instances']))
4517
-						$context['debug']['instances'] = array();
4771
+					if (!isset($context['debug']['instances'])) {
4772
+											$context['debug']['instances'] = array();
4773
+					}
4518 4774
 
4519 4775
 					$context['debug']['instances'][$class] = $class;
4520 4776
 				}
@@ -4524,13 +4780,15 @@  discard block
 block discarded – undo
4524 4780
 		}
4525 4781
 
4526 4782
 		// Right then. This is a call to a static method.
4527
-		else
4528
-			$func = array($class, $method);
4783
+		else {
4784
+					$func = array($class, $method);
4785
+		}
4529 4786
 	}
4530 4787
 
4531 4788
 	// Nope! just a plain regular function.
4532
-	else
4533
-		$func = $string;
4789
+	else {
4790
+			$func = $string;
4791
+	}
4534 4792
 
4535 4793
 	// Right, we got what we need, time to do some checks.
4536 4794
 	if (!is_callable($func, false, $callable_name))
@@ -4546,17 +4804,18 @@  discard block
 block discarded – undo
4546 4804
 	else
4547 4805
 	{
4548 4806
 		// What are we gonna do about it?
4549
-		if ($return)
4550
-			return $func;
4807
+		if ($return) {
4808
+					return $func;
4809
+		}
4551 4810
 
4552 4811
 		// If this is a plain function, avoid the heat of calling call_user_func().
4553 4812
 		else
4554 4813
 		{
4555
-			if (is_array($func))
4556
-				call_user_func($func);
4557
-
4558
-			else
4559
-				$func();
4814
+			if (is_array($func)) {
4815
+							call_user_func($func);
4816
+			} else {
4817
+							$func();
4818
+			}
4560 4819
 		}
4561 4820
 	}
4562 4821
 }
@@ -4573,31 +4832,34 @@  discard block
 block discarded – undo
4573 4832
 {
4574 4833
 	global $sourcedir, $txt, $boarddir, $settings;
4575 4834
 
4576
-	if (empty($string))
4577
-		return false;
4835
+	if (empty($string)) {
4836
+			return false;
4837
+	}
4578 4838
 
4579 4839
 	if (strpos($string, '|') !== false)
4580 4840
 	{
4581 4841
 		list ($file, $string) = explode('|', $string);
4582 4842
 
4583 4843
 		// Match the wildcards to their regular vars.
4584
-		if (empty($settings['theme_dir']))
4585
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4586
-
4587
-		else
4588
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4844
+		if (empty($settings['theme_dir'])) {
4845
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4846
+		} else {
4847
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4848
+		}
4589 4849
 
4590 4850
 		// Load the file if it can be loaded.
4591
-		if (file_exists($absPath))
4592
-			require_once($absPath);
4851
+		if (file_exists($absPath)) {
4852
+					require_once($absPath);
4853
+		}
4593 4854
 
4594 4855
 		// No? try a fallback to $sourcedir
4595 4856
 		else
4596 4857
 		{
4597 4858
 			$absPath = $sourcedir .'/'. $file;
4598 4859
 
4599
-			if (file_exists($absPath))
4600
-				require_once($absPath);
4860
+			if (file_exists($absPath)) {
4861
+							require_once($absPath);
4862
+			}
4601 4863
 
4602 4864
 			// Sorry, can't do much for you at this point.
4603 4865
 			else
@@ -4624,8 +4886,9 @@  discard block
 block discarded – undo
4624 4886
 	global $user_info, $smcFunc;
4625 4887
 
4626 4888
 	// Make sure we have something to work with.
4627
-	if (empty($topic))
4628
-		return array();
4889
+	if (empty($topic)) {
4890
+			return array();
4891
+	}
4629 4892
 
4630 4893
 
4631 4894
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4648,8 +4911,9 @@  discard block
 block discarded – undo
4648 4911
 				'topic' => $topic,
4649 4912
 			)
4650 4913
 		);
4651
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4652
-			$temp[] = (int) $row['content_id'];
4914
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4915
+					$temp[] = (int) $row['content_id'];
4916
+		}
4653 4917
 
4654 4918
 		cache_put_data($cache_key, $temp, $ttl);
4655 4919
 	}
@@ -4670,8 +4934,9 @@  discard block
 block discarded – undo
4670 4934
 {
4671 4935
 	global $context;
4672 4936
 
4673
-	if (empty($string))
4674
-		return $string;
4937
+	if (empty($string)) {
4938
+			return $string;
4939
+	}
4675 4940
 
4676 4941
 	// UTF-8 occurences of MS special characters
4677 4942
 	$findchars_utf8 = array(
@@ -4712,10 +4977,11 @@  discard block
 block discarded – undo
4712 4977
 		'--',	// &mdash;
4713 4978
 	);
4714 4979
 
4715
-	if ($context['utf8'])
4716
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4717
-	else
4718
-		$string = str_replace($findchars_iso, $replacechars, $string);
4980
+	if ($context['utf8']) {
4981
+			$string = str_replace($findchars_utf8, $replacechars, $string);
4982
+	} else {
4983
+			$string = str_replace($findchars_iso, $replacechars, $string);
4984
+	}
4719 4985
 
4720 4986
 	return $string;
4721 4987
 }
@@ -4734,49 +5000,59 @@  discard block
 block discarded – undo
4734 5000
 {
4735 5001
 	global $context;
4736 5002
 
4737
-	if (!isset($matches[2]))
4738
-		return '';
5003
+	if (!isset($matches[2])) {
5004
+			return '';
5005
+	}
4739 5006
 
4740 5007
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4741 5008
 
4742 5009
 	// remove left to right / right to left overrides
4743
-	if ($num === 0x202D || $num === 0x202E)
4744
-		return '';
5010
+	if ($num === 0x202D || $num === 0x202E) {
5011
+			return '';
5012
+	}
4745 5013
 
4746 5014
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4747
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4748
-		return '&#' . $num . ';';
5015
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5016
+			return '&#' . $num . ';';
5017
+	}
4749 5018
 
4750 5019
 	if (empty($context['utf8']))
4751 5020
 	{
4752 5021
 		// no control characters
4753
-		if ($num < 0x20)
4754
-			return '';
5022
+		if ($num < 0x20) {
5023
+					return '';
5024
+		}
4755 5025
 		// text is text
4756
-		elseif ($num < 0x80)
4757
-			return chr($num);
5026
+		elseif ($num < 0x80) {
5027
+					return chr($num);
5028
+		}
4758 5029
 		// all others get html-ised
4759
-		else
4760
-			return '&#' . $matches[2] . ';';
4761
-	}
4762
-	else
5030
+		else {
5031
+					return '&#' . $matches[2] . ';';
5032
+		}
5033
+	} else
4763 5034
 	{
4764 5035
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4765 5036
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4766
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4767
-			return '';
5037
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5038
+					return '';
5039
+		}
4768 5040
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4769
-		elseif ($num < 0x80)
4770
-			return chr($num);
5041
+		elseif ($num < 0x80) {
5042
+					return chr($num);
5043
+		}
4771 5044
 		// <0x800 (2048)
4772
-		elseif ($num < 0x800)
4773
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5045
+		elseif ($num < 0x800) {
5046
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5047
+		}
4774 5048
 		// < 0x10000 (65536)
4775
-		elseif ($num < 0x10000)
4776
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5049
+		elseif ($num < 0x10000) {
5050
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5051
+		}
4777 5052
 		// <= 0x10FFFF (1114111)
4778
-		else
4779
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5053
+		else {
5054
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5055
+		}
4780 5056
 	}
4781 5057
 }
4782 5058
 
@@ -4792,28 +5068,34 @@  discard block
 block discarded – undo
4792 5068
  */
4793 5069
 function fixchar__callback($matches)
4794 5070
 {
4795
-	if (!isset($matches[1]))
4796
-		return '';
5071
+	if (!isset($matches[1])) {
5072
+			return '';
5073
+	}
4797 5074
 
4798 5075
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4799 5076
 
4800 5077
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4801 5078
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4802
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4803
-		return '';
5079
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5080
+			return '';
5081
+	}
4804 5082
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4805
-	elseif ($num < 0x80)
4806
-		return chr($num);
5083
+	elseif ($num < 0x80) {
5084
+			return chr($num);
5085
+	}
4807 5086
 	// <0x800 (2048)
4808
-	elseif ($num < 0x800)
4809
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5087
+	elseif ($num < 0x800) {
5088
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5089
+	}
4810 5090
 	// < 0x10000 (65536)
4811
-	elseif ($num < 0x10000)
4812
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5091
+	elseif ($num < 0x10000) {
5092
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5093
+	}
4813 5094
 	// <= 0x10FFFF (1114111)
4814
-	else
4815
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4816
-}
5095
+	else {
5096
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5097
+	}
5098
+	}
4817 5099
 
4818 5100
 /**
4819 5101
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4826,17 +5108,19 @@  discard block
 block discarded – undo
4826 5108
  */
4827 5109
 function entity_fix__callback($matches)
4828 5110
 {
4829
-	if (!isset($matches[2]))
4830
-		return '';
5111
+	if (!isset($matches[2])) {
5112
+			return '';
5113
+	}
4831 5114
 
4832 5115
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4833 5116
 
4834 5117
 	// we don't allow control characters, characters out of range, byte markers, etc
4835
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4836
-		return '';
4837
-	else
4838
-		return '&#' . $num . ';';
4839
-}
5118
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5119
+			return '';
5120
+	} else {
5121
+			return '&#' . $num . ';';
5122
+	}
5123
+	}
4840 5124
 
4841 5125
 /**
4842 5126
  * Return a Gravatar URL based on
@@ -4860,18 +5144,23 @@  discard block
 block discarded – undo
4860 5144
 		$ratings = array('G', 'PG', 'R', 'X');
4861 5145
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
4862 5146
 		$url_params = array();
4863
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
4864
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
4865
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
4866
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
4867
-		if (!empty($modSettings['avatar_max_width_external']))
4868
-			$size_string = (int) $modSettings['avatar_max_width_external'];
4869
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
4870
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5147
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5148
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5149
+		}
5150
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5151
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5152
+		}
5153
+		if (!empty($modSettings['avatar_max_width_external'])) {
5154
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5155
+		}
5156
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5157
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
4871 5158
 				$size_string = $modSettings['avatar_max_height_external'];
5159
+		}
4872 5160
 
4873
-		if (!empty($size_string))
4874
-			$url_params[] = 's=' . $size_string;
5161
+		if (!empty($size_string)) {
5162
+					$url_params[] = 's=' . $size_string;
5163
+		}
4875 5164
 	}
4876 5165
 	$http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www';
4877 5166
 
@@ -4890,22 +5179,26 @@  discard block
 block discarded – undo
4890 5179
 	static $timezones = null, $lastwhen = null;
4891 5180
 
4892 5181
 	// No point doing this over if we already did it once
4893
-	if (!empty($timezones) && $when == $lastwhen)
4894
-		return $timezones;
4895
-	else
4896
-		$lastwhen = $when;
5182
+	if (!empty($timezones) && $when == $lastwhen) {
5183
+			return $timezones;
5184
+	} else {
5185
+			$lastwhen = $when;
5186
+	}
4897 5187
 
4898 5188
 	// Parseable datetime string?
4899
-	if (is_int($timestamp = strtotime($when)))
4900
-		$when = $timestamp;
5189
+	if (is_int($timestamp = strtotime($when))) {
5190
+			$when = $timestamp;
5191
+	}
4901 5192
 
4902 5193
 	// A Unix timestamp?
4903
-	elseif (is_numeric($when))
4904
-		$when = intval($when);
5194
+	elseif (is_numeric($when)) {
5195
+			$when = intval($when);
5196
+	}
4905 5197
 
4906 5198
 	// Invalid value? Just get current Unix timestamp.
4907
-	else
4908
-		$when = time();
5199
+	else {
5200
+			$when = time();
5201
+	}
4909 5202
 
4910 5203
 	// We'll need this too
4911 5204
 	$later = (int) date_format(date_add(date_create('@' . $when), date_interval_create_from_date_string('1 year')), 'U');
@@ -4968,8 +5261,9 @@  discard block
 block discarded – undo
4968 5261
 	foreach ($priority_countries as $country)
4969 5262
 	{
4970 5263
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
4971
-		if (!empty($country_tzids))
4972
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5264
+		if (!empty($country_tzids)) {
5265
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5266
+		}
4973 5267
 	}
4974 5268
 
4975 5269
 	// Process the preferred timezones first, then the rest.
@@ -4979,8 +5273,9 @@  discard block
 block discarded – undo
4979 5273
 	foreach ($tzids as $tzid)
4980 5274
 	{
4981 5275
 		// We don't want UTC right now
4982
-		if ($tzid == 'UTC')
4983
-			continue;
5276
+		if ($tzid == 'UTC') {
5277
+					continue;
5278
+		}
4984 5279
 
4985 5280
 		// First, get the set of transition rules for this tzid
4986 5281
 		$tzinfo = timezone_transitions_get(timezone_open($tzid), $when, $later);
@@ -4991,8 +5286,9 @@  discard block
 block discarded – undo
4991 5286
 			$tz_location = timezone_location_get(timezone_open($tzid));
4992 5287
 
4993 5288
 			// Kazakstan
4994
-			if ($tz_location['country_code'] == 'KZ')
4995
-				$tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']);
5289
+			if ($tz_location['country_code'] == 'KZ') {
5290
+							$tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']);
5291
+			}
4996 5292
 
4997 5293
 			// Russia likes to experiment with time zones
4998 5294
 			if ($tz_location['country_code'] == 'RU')
@@ -5003,19 +5299,22 @@  discard block
 block discarded – undo
5003 5299
 			}
5004 5300
 
5005 5301
 			// Still no good? We'll just mark it as a UTC offset
5006
-			if (strspn($tzinfo[0]['abbr'], '+-') > 0)
5007
-				$tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr'];
5302
+			if (strspn($tzinfo[0]['abbr'], '+-') > 0) {
5303
+							$tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr'];
5304
+			}
5008 5305
 		}
5009 5306
 
5010 5307
 		$tzkey = serialize($tzinfo);
5011 5308
 
5012 5309
 		// Don't overwrite our preferred tzids
5013
-		if (empty($zones[$tzkey]['tzid']))
5014
-			$zones[$tzkey]['tzid'] = $tzid;
5310
+		if (empty($zones[$tzkey]['tzid'])) {
5311
+					$zones[$tzkey]['tzid'] = $tzid;
5312
+		}
5015 5313
 
5016 5314
 		// A time zone from a prioritized country?
5017
-		if (in_array($tzid, $priority_tzids))
5018
-			$priority_zones[$tzkey] = true;
5315
+		if (in_array($tzid, $priority_tzids)) {
5316
+					$priority_zones[$tzkey] = true;
5317
+		}
5019 5318
 
5020 5319
 		// Keep track of the location and offset for this tzid
5021 5320
 		$tzid_parts = explode('/', $tzid);
@@ -5033,15 +5332,17 @@  discard block
 block discarded – undo
5033 5332
 	{
5034 5333
 		$tzinfo = unserialize($tzkey);
5035 5334
 
5036
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5037
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5038
-		else
5039
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5335
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5336
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5337
+		} else {
5338
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5339
+		}
5040 5340
 
5041
-		if (isset($priority_zones[$tzkey]))
5042
-			$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5043
-		else
5044
-			$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5341
+		if (isset($priority_zones[$tzkey])) {
5342
+					$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5343
+		} else {
5344
+					$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5345
+		}
5045 5346
 	}
5046 5347
 
5047 5348
 	$timezones = array_merge(
@@ -5059,8 +5360,9 @@  discard block
 block discarded – undo
5059 5360
  */
5060 5361
 function inet_ptod($ip_address)
5061 5362
 {
5062
-	if (!isValidIP($ip_address))
5063
-		return $ip_address;
5363
+	if (!isValidIP($ip_address)) {
5364
+			return $ip_address;
5365
+	}
5064 5366
 
5065 5367
 	$bin = inet_pton($ip_address);
5066 5368
 	return $bin;
@@ -5072,13 +5374,15 @@  discard block
 block discarded – undo
5072 5374
  */
5073 5375
 function inet_dtop($bin)
5074 5376
 {
5075
-	if(empty($bin))
5076
-		return '';
5377
+	if(empty($bin)) {
5378
+			return '';
5379
+	}
5077 5380
 
5078 5381
 	global $db_type;
5079 5382
 
5080
-	if ($db_type == 'postgresql')
5081
-		return $bin;
5383
+	if ($db_type == 'postgresql') {
5384
+			return $bin;
5385
+	}
5082 5386
 
5083 5387
 	$ip_address = inet_ntop($bin);
5084 5388
 
@@ -5103,26 +5407,32 @@  discard block
 block discarded – undo
5103 5407
  */
5104 5408
 function _safe_serialize($value)
5105 5409
 {
5106
-	if(is_null($value))
5107
-		return 'N;';
5410
+	if(is_null($value)) {
5411
+			return 'N;';
5412
+	}
5108 5413
 
5109
-	if(is_bool($value))
5110
-		return 'b:'. (int) $value .';';
5414
+	if(is_bool($value)) {
5415
+			return 'b:'. (int) $value .';';
5416
+	}
5111 5417
 
5112
-	if(is_int($value))
5113
-		return 'i:'. $value .';';
5418
+	if(is_int($value)) {
5419
+			return 'i:'. $value .';';
5420
+	}
5114 5421
 
5115
-	if(is_float($value))
5116
-		return 'd:'. str_replace(',', '.', $value) .';';
5422
+	if(is_float($value)) {
5423
+			return 'd:'. str_replace(',', '.', $value) .';';
5424
+	}
5117 5425
 
5118
-	if(is_string($value))
5119
-		return 's:'. strlen($value) .':"'. $value .'";';
5426
+	if(is_string($value)) {
5427
+			return 's:'. strlen($value) .':"'. $value .'";';
5428
+	}
5120 5429
 
5121 5430
 	if(is_array($value))
5122 5431
 	{
5123 5432
 		$out = '';
5124
-		foreach($value as $k => $v)
5125
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5433
+		foreach($value as $k => $v) {
5434
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5435
+		}
5126 5436
 
5127 5437
 		return 'a:'. count($value) .':{'. $out .'}';
5128 5438
 	}
@@ -5148,8 +5458,9 @@  discard block
 block discarded – undo
5148 5458
 
5149 5459
 	$out = _safe_serialize($value);
5150 5460
 
5151
-	if (isset($mbIntEnc))
5152
-		mb_internal_encoding($mbIntEnc);
5461
+	if (isset($mbIntEnc)) {
5462
+			mb_internal_encoding($mbIntEnc);
5463
+	}
5153 5464
 
5154 5465
 	return $out;
5155 5466
 }
@@ -5166,8 +5477,9 @@  discard block
 block discarded – undo
5166 5477
 function _safe_unserialize($str)
5167 5478
 {
5168 5479
 	// Input  is not a string.
5169
-	if(empty($str) || !is_string($str))
5170
-		return false;
5480
+	if(empty($str) || !is_string($str)) {
5481
+			return false;
5482
+	}
5171 5483
 
5172 5484
 	$stack = array();
5173 5485
 	$expected = array();
@@ -5183,43 +5495,38 @@  discard block
 block discarded – undo
5183 5495
 	while($state != 1)
5184 5496
 	{
5185 5497
 		$type = isset($str[0]) ? $str[0] : '';
5186
-		if($type == '}')
5187
-			$str = substr($str, 1);
5188
-
5189
-		else if($type == 'N' && $str[1] == ';')
5498
+		if($type == '}') {
5499
+					$str = substr($str, 1);
5500
+		} else if($type == 'N' && $str[1] == ';')
5190 5501
 		{
5191 5502
 			$value = null;
5192 5503
 			$str = substr($str, 2);
5193
-		}
5194
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5504
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5195 5505
 		{
5196 5506
 			$value = $matches[1] == '1' ? true : false;
5197 5507
 			$str = substr($str, 4);
5198
-		}
5199
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5508
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5200 5509
 		{
5201 5510
 			$value = (int)$matches[1];
5202 5511
 			$str = $matches[2];
5203
-		}
5204
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5512
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5205 5513
 		{
5206 5514
 			$value = (float)$matches[1];
5207 5515
 			$str = $matches[3];
5208
-		}
5209
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5516
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5210 5517
 		{
5211 5518
 			$value = substr($matches[2], 0, (int)$matches[1]);
5212 5519
 			$str = substr($matches[2], (int)$matches[1] + 2);
5213
-		}
5214
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5520
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5215 5521
 		{
5216 5522
 			$expectedLength = (int)$matches[1];
5217 5523
 			$str = $matches[2];
5218 5524
 		}
5219 5525
 
5220 5526
 		// Object or unknown/malformed type.
5221
-		else
5222
-			return false;
5527
+		else {
5528
+					return false;
5529
+		}
5223 5530
 
5224 5531
 		switch($state)
5225 5532
 		{
@@ -5247,8 +5554,9 @@  discard block
 block discarded – undo
5247 5554
 				if($type == '}')
5248 5555
 				{
5249 5556
 					// Array size is less than expected.
5250
-					if(count($list) < end($expected))
5251
-						return false;
5557
+					if(count($list) < end($expected)) {
5558
+											return false;
5559
+					}
5252 5560
 
5253 5561
 					unset($list);
5254 5562
 					$list = &$stack[count($stack)-1];
@@ -5257,8 +5565,9 @@  discard block
 block discarded – undo
5257 5565
 					// Go to terminal state if we're at the end of the root array.
5258 5566
 					array_pop($expected);
5259 5567
 
5260
-					if(count($expected) == 0)
5261
-						$state = 1;
5568
+					if(count($expected) == 0) {
5569
+											$state = 1;
5570
+					}
5262 5571
 
5263 5572
 					break;
5264 5573
 				}
@@ -5266,8 +5575,9 @@  discard block
 block discarded – undo
5266 5575
 				if($type == 'i' || $type == 's')
5267 5576
 				{
5268 5577
 					// Array size exceeds expected length.
5269
-					if(count($list) >= end($expected))
5270
-						return false;
5578
+					if(count($list) >= end($expected)) {
5579
+											return false;
5580
+					}
5271 5581
 
5272 5582
 					$key = $value;
5273 5583
 					$state = 3;
@@ -5301,8 +5611,9 @@  discard block
 block discarded – undo
5301 5611
 	}
5302 5612
 
5303 5613
 	// Trailing data in input.
5304
-	if(!empty($str))
5305
-		return false;
5614
+	if(!empty($str)) {
5615
+			return false;
5616
+	}
5306 5617
 
5307 5618
 	return $data;
5308 5619
 }
@@ -5325,8 +5636,9 @@  discard block
 block discarded – undo
5325 5636
 
5326 5637
 	$out = _safe_unserialize($str);
5327 5638
 
5328
-	if (isset($mbIntEnc))
5329
-		mb_internal_encoding($mbIntEnc);
5639
+	if (isset($mbIntEnc)) {
5640
+			mb_internal_encoding($mbIntEnc);
5641
+	}
5330 5642
 
5331 5643
 	return $out;
5332 5644
 }
@@ -5341,12 +5653,14 @@  discard block
 block discarded – undo
5341 5653
 function smf_chmod($file, $value = 0)
5342 5654
 {
5343 5655
 	// No file? no checks!
5344
-	if (empty($file))
5345
-		return false;
5656
+	if (empty($file)) {
5657
+			return false;
5658
+	}
5346 5659
 
5347 5660
 	// Already writable?
5348
-	if (is_writable($file))
5349
-		return true;
5661
+	if (is_writable($file)) {
5662
+			return true;
5663
+	}
5350 5664
 
5351 5665
 	// Do we have a file or a dir?
5352 5666
 	$isDir = is_dir($file);
@@ -5362,10 +5676,9 @@  discard block
 block discarded – undo
5362 5676
 		{
5363 5677
 			$isWritable = true;
5364 5678
 			break;
5679
+		} else {
5680
+					@chmod($file, $val);
5365 5681
 		}
5366
-
5367
-		else
5368
-			@chmod($file, $val);
5369 5682
 	}
5370 5683
 
5371 5684
 	return $isWritable;
@@ -5384,8 +5697,9 @@  discard block
 block discarded – undo
5384 5697
 	global $txt;
5385 5698
 
5386 5699
 	// Come on...
5387
-	if (empty($json) || !is_string($json))
5388
-		return array();
5700
+	if (empty($json) || !is_string($json)) {
5701
+			return array();
5702
+	}
5389 5703
 
5390 5704
 	$returnArray = @json_decode($json, $returnAsArray);
5391 5705
 
@@ -5423,11 +5737,11 @@  discard block
 block discarded – undo
5423 5737
 		$jsonDebug = $jsonDebug[0];
5424 5738
 		loadLanguage('Errors');
5425 5739
 
5426
-		if (!empty($jsonDebug))
5427
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5428
-
5429
-		else
5430
-			log_error($txt['json_'. $jsonError], 'critical');
5740
+		if (!empty($jsonDebug)) {
5741
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5742
+		} else {
5743
+					log_error($txt['json_'. $jsonError], 'critical');
5744
+		}
5431 5745
 
5432 5746
 		// Everyone expects an array.
5433 5747
 		return array();
@@ -5457,8 +5771,9 @@  discard block
 block discarded – undo
5457 5771
 	global $db_show_debug, $modSettings;
5458 5772
 
5459 5773
 	// Defensive programming anyone?
5460
-	if (empty($data))
5461
-		return false;
5774
+	if (empty($data)) {
5775
+			return false;
5776
+	}
5462 5777
 
5463 5778
 	// Don't need extra stuff...
5464 5779
 	$db_show_debug = false;
@@ -5466,11 +5781,11 @@  discard block
 block discarded – undo
5466 5781
 	// Kill anything else.
5467 5782
 	ob_end_clean();
5468 5783
 
5469
-	if (!empty($modSettings['CompressedOutput']))
5470
-		@ob_start('ob_gzhandler');
5471
-
5472
-	else
5473
-		ob_start();
5784
+	if (!empty($modSettings['CompressedOutput'])) {
5785
+			@ob_start('ob_gzhandler');
5786
+	} else {
5787
+			ob_start();
5788
+	}
5474 5789
 
5475 5790
 	// Set the header.
5476 5791
 	header($type);
@@ -5502,8 +5817,9 @@  discard block
 block discarded – undo
5502 5817
 	static $done = false;
5503 5818
 
5504 5819
 	// If we don't need to do anything, don't
5505
-	if (!$update && $done)
5506
-		return;
5820
+	if (!$update && $done) {
5821
+			return;
5822
+	}
5507 5823
 
5508 5824
 	// Should we get a new copy of the official list of TLDs?
5509 5825
 	if ($update)
@@ -5524,10 +5840,11 @@  discard block
 block discarded – undo
5524 5840
 		// Clean $tlds and convert it to an array
5525 5841
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5526 5842
 			$line = trim($line);
5527
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5528
-				return false;
5529
-			else
5530
-				return true;
5843
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
5844
+							return false;
5845
+			} else {
5846
+							return true;
5847
+			}
5531 5848
 		});
5532 5849
 
5533 5850
 		// Convert Punycode to Unicode
@@ -5581,8 +5898,9 @@  discard block
 block discarded – undo
5581 5898
 						$idx += $digit * $w;
5582 5899
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5583 5900
 
5584
-						if ($digit < $t)
5585
-							break;
5901
+						if ($digit < $t) {
5902
+													break;
5903
+						}
5586 5904
 
5587 5905
 						$w = (int) ($w * ($base - $t));
5588 5906
 					}
@@ -5591,8 +5909,9 @@  discard block
 block discarded – undo
5591 5909
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5592 5910
 					$delta += intval($delta / ($deco_len + 1));
5593 5911
 
5594
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5595
-						$delta = intval($delta / ($base - $tmin));
5912
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
5913
+											$delta = intval($delta / ($base - $tmin));
5914
+					}
5596 5915
 
5597 5916
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5598 5917
 					$is_first = false;
@@ -5601,8 +5920,9 @@  discard block
 block discarded – undo
5601 5920
 
5602 5921
 					if ($deco_len > 0)
5603 5922
 					{
5604
-						for ($i = $deco_len; $i > $idx; $i--)
5605
-							$decoded[$i] = $decoded[($i - 1)];
5923
+						for ($i = $deco_len; $i > $idx; $i--) {
5924
+													$decoded[$i] = $decoded[($i - 1)];
5925
+						}
5606 5926
 					}
5607 5927
 					$decoded[$idx++] = $char;
5608 5928
 				}
@@ -5610,24 +5930,29 @@  discard block
 block discarded – undo
5610 5930
 				foreach ($decoded as $k => $v)
5611 5931
 				{
5612 5932
 					// 7bit are transferred literally
5613
-					if ($v < 128)
5614
-						$output .= chr($v);
5933
+					if ($v < 128) {
5934
+											$output .= chr($v);
5935
+					}
5615 5936
 
5616 5937
 					// 2 bytes
5617
-					elseif ($v < (1 << 11))
5618
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5938
+					elseif ($v < (1 << 11)) {
5939
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5940
+					}
5619 5941
 
5620 5942
 					// 3 bytes
5621
-					elseif ($v < (1 << 16))
5622
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5943
+					elseif ($v < (1 << 16)) {
5944
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5945
+					}
5623 5946
 
5624 5947
 					// 4 bytes
5625
-					elseif ($v < (1 << 21))
5626
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5948
+					elseif ($v < (1 << 21)) {
5949
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5950
+					}
5627 5951
 
5628 5952
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5629
-					else
5630
-						$output .= $safe_char;
5953
+					else {
5954
+											$output .= $safe_char;
5955
+					}
5631 5956
 				}
5632 5957
 
5633 5958
 				$output_parts[] = $output;
@@ -5722,8 +6047,7 @@  discard block
 block discarded – undo
5722 6047
 
5723 6048
 		$strlen = 'mb_strlen';
5724 6049
 		$substr = 'mb_substr';
5725
-	}
5726
-	else
6050
+	} else
5727 6051
 	{
5728 6052
 		$strlen = $smcFunc['strlen'];
5729 6053
 		$substr = $smcFunc['substr'];
@@ -5737,20 +6061,21 @@  discard block
 block discarded – undo
5737 6061
 
5738 6062
 		$first = $substr($string, 0, 1);
5739 6063
 
5740
-		if (empty($index[$first]))
5741
-			$index[$first] = array();
6064
+		if (empty($index[$first])) {
6065
+					$index[$first] = array();
6066
+		}
5742 6067
 
5743 6068
 		if ($strlen($string) > 1)
5744 6069
 		{
5745 6070
 			// Sanity check on recursion
5746
-			if ($depth > 99)
5747
-				$index[$first][$substr($string, 1)] = '';
5748
-
5749
-			else
5750
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6071
+			if ($depth > 99) {
6072
+							$index[$first][$substr($string, 1)] = '';
6073
+			} else {
6074
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6075
+			}
6076
+		} else {
6077
+					$index[$first][''] = '';
5751 6078
 		}
5752
-		else
5753
-			$index[$first][''] = '';
5754 6079
 
5755 6080
 		$depth--;
5756 6081
 		return $index;
@@ -5773,9 +6098,9 @@  discard block
 block discarded – undo
5773 6098
 			$key_regex = preg_quote($key, $delim);
5774 6099
 			$new_key = $key;
5775 6100
 
5776
-			if (empty($value))
5777
-				$sub_regex = '';
5778
-			else
6101
+			if (empty($value)) {
6102
+							$sub_regex = '';
6103
+			} else
5779 6104
 			{
5780 6105
 				$sub_regex = $index_to_regex($value, $delim);
5781 6106
 
@@ -5783,22 +6108,22 @@  discard block
 block discarded – undo
5783 6108
 				{
5784 6109
 					$new_key_array = explode('(?'.'>', $sub_regex);
5785 6110
 					$new_key .= $new_key_array[0];
6111
+				} else {
6112
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
5786 6113
 				}
5787
-				else
5788
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5789 6114
 			}
5790 6115
 
5791
-			if ($depth > 1)
5792
-				$regex[$new_key] = $key_regex . $sub_regex;
5793
-			else
6116
+			if ($depth > 1) {
6117
+							$regex[$new_key] = $key_regex . $sub_regex;
6118
+			} else
5794 6119
 			{
5795 6120
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
5796 6121
 				{
5797 6122
 					$regex[$new_key] = $key_regex . $sub_regex;
5798 6123
 					unset($index[$key]);
6124
+				} else {
6125
+									break;
5799 6126
 				}
5800
-				else
5801
-					break;
5802 6127
 			}
5803 6128
 		}
5804 6129
 
@@ -5807,10 +6132,11 @@  discard block
 block discarded – undo
5807 6132
 			$l1 = $strlen($k1);
5808 6133
 			$l2 = $strlen($k2);
5809 6134
 
5810
-			if ($l1 == $l2)
5811
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
5812
-			else
5813
-				return $l1 > $l2 ? -1 : 1;
6135
+			if ($l1 == $l2) {
6136
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6137
+			} else {
6138
+							return $l1 > $l2 ? -1 : 1;
6139
+			}
5814 6140
 		});
5815 6141
 
5816 6142
 		$depth--;
@@ -5821,15 +6147,18 @@  discard block
 block discarded – undo
5821 6147
 	$index = array();
5822 6148
 	$regexes = array();
5823 6149
 
5824
-	foreach ($strings as $string)
5825
-		$index = $add_string_to_index($string, $index);
6150
+	foreach ($strings as $string) {
6151
+			$index = $add_string_to_index($string, $index);
6152
+	}
5826 6153
 
5827
-	while (!empty($index))
5828
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6154
+	while (!empty($index)) {
6155
+			$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6156
+	}
5829 6157
 
5830 6158
 	// Restore PHP's internal character encoding to whatever it was originally
5831
-	if (!empty($current_encoding))
5832
-		mb_internal_encoding($current_encoding);
6159
+	if (!empty($current_encoding)) {
6160
+			mb_internal_encoding($current_encoding);
6161
+	}
5833 6162
 
5834 6163
 	return $regexes;
5835 6164
 }
Please login to merge, or discard this patch.
Sources/RemoveTopic.php 1 patch
Braces   +267 added lines, -200 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
 /*	The contents of this file handle the deletion of topics, posts, and related
21 22
 	paraphernalia.  It has the following functions:
@@ -37,8 +38,9 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Post.php');
38 39
 
39 40
 	// Trying to fool us around, are we?
40
-	if (empty($topic))
41
-		redirectexit();
41
+	if (empty($topic)) {
42
+			redirectexit();
43
+	}
42 44
 
43 45
 	removeDeleteConcurrence();
44 46
 
@@ -55,20 +57,23 @@  discard block
 block discarded – undo
55 57
 	list ($starter, $subject, $approved, $locked) = $smcFunc['db_fetch_row']($request);
56 58
 	$smcFunc['db_free_result']($request);
57 59
 
58
-	if ($starter == $user_info['id'] && !allowedTo('remove_any'))
59
-		isAllowedTo('remove_own');
60
-	else
61
-		isAllowedTo('remove_any');
60
+	if ($starter == $user_info['id'] && !allowedTo('remove_any')) {
61
+			isAllowedTo('remove_own');
62
+	} else {
63
+			isAllowedTo('remove_any');
64
+	}
62 65
 
63 66
 	// Can they see the topic?
64
-	if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id'])
65
-		isAllowedTo('approve_posts');
67
+	if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id']) {
68
+			isAllowedTo('approve_posts');
69
+	}
66 70
 
67 71
 	// Ok, we got that far, but is it locked?
68 72
 	if ($locked)
69 73
 	{
70
-		if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any')))
71
-			fatal_lang_error('cannot_remove_locked', 'user');
74
+		if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any'))) {
75
+					fatal_lang_error('cannot_remove_locked', 'user');
76
+		}
72 77
 	}
73 78
 
74 79
 	// Notify people that this topic has been removed.
@@ -77,8 +82,9 @@  discard block
 block discarded – undo
77 82
 	removeTopics($topic);
78 83
 
79 84
 	// Note, only log topic ID in native form if it's not gone forever.
80
-	if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id']))
81
-		logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
85
+	if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id'])) {
86
+			logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
87
+	}
82 88
 
83 89
 	redirectexit('board=' . $board . '.0');
84 90
 }
@@ -96,8 +102,9 @@  discard block
 block discarded – undo
96 102
 	$_REQUEST['msg'] = (int) $_REQUEST['msg'];
97 103
 
98 104
 	// Is $topic set?
99
-	if (empty($topic) && isset($_REQUEST['topic']))
100
-		$topic = (int) $_REQUEST['topic'];
105
+	if (empty($topic) && isset($_REQUEST['topic'])) {
106
+			$topic = (int) $_REQUEST['topic'];
107
+	}
101 108
 
102 109
 	removeDeleteConcurrence();
103 110
 
@@ -116,44 +123,48 @@  discard block
 block discarded – undo
116 123
 	$smcFunc['db_free_result']($request);
117 124
 
118 125
 	// Verify they can see this!
119
-	if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id'])
120
-		isAllowedTo('approve_posts');
126
+	if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id']) {
127
+			isAllowedTo('approve_posts');
128
+	}
121 129
 
122 130
 	if ($poster == $user_info['id'])
123 131
 	{
124 132
 		if (!allowedTo('delete_own'))
125 133
 		{
126
-			if ($starter == $user_info['id'] && !allowedTo('delete_any'))
127
-				isAllowedTo('delete_replies');
128
-			elseif (!allowedTo('delete_any'))
129
-				isAllowedTo('delete_own');
134
+			if ($starter == $user_info['id'] && !allowedTo('delete_any')) {
135
+							isAllowedTo('delete_replies');
136
+			} elseif (!allowedTo('delete_any')) {
137
+							isAllowedTo('delete_own');
138
+			}
139
+		} elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time()) {
140
+					fatal_lang_error('modify_post_time_passed', false);
130 141
 		}
131
-		elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time())
132
-			fatal_lang_error('modify_post_time_passed', false);
142
+	} elseif ($starter == $user_info['id'] && !allowedTo('delete_any')) {
143
+			isAllowedTo('delete_replies');
144
+	} else {
145
+			isAllowedTo('delete_any');
133 146
 	}
134
-	elseif ($starter == $user_info['id'] && !allowedTo('delete_any'))
135
-		isAllowedTo('delete_replies');
136
-	else
137
-		isAllowedTo('delete_any');
138 147
 
139 148
 	// If the full topic was removed go back to the board.
140 149
 	$full_topic = removeMessage($_REQUEST['msg']);
141 150
 
142
-	if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id']))
143
-		logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
151
+	if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id'])) {
152
+			logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
153
+	}
144 154
 
145 155
 	// We want to redirect back to recent action.
146
-	if (isset($_REQUEST['modcenter']))
147
-		redirectexit('action=moderate;area=reportedposts;done');
148
-	elseif (isset($_REQUEST['recent']))
149
-		redirectexit('action=recent');
150
-	elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u']))
151
-		redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']);
152
-	elseif ($full_topic)
153
-		redirectexit('board=' . $board . '.0');
154
-	else
155
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
156
-}
156
+	if (isset($_REQUEST['modcenter'])) {
157
+			redirectexit('action=moderate;area=reportedposts;done');
158
+	} elseif (isset($_REQUEST['recent'])) {
159
+			redirectexit('action=recent');
160
+	} elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u'])) {
161
+			redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']);
162
+	} elseif ($full_topic) {
163
+			redirectexit('board=' . $board . '.0');
164
+	} else {
165
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
166
+	}
167
+	}
157 168
 
158 169
 /**
159 170
  * So long as you are sure... all old posts will be gone.
@@ -167,8 +178,9 @@  discard block
 block discarded – undo
167 178
 	checkSession('post', 'admin');
168 179
 
169 180
 	// No boards at all?  Forget it then :/.
170
-	if (empty($_POST['boards']))
171
-		redirectexit('action=admin;area=maintain;sa=topics');
181
+	if (empty($_POST['boards'])) {
182
+			redirectexit('action=admin;area=maintain;sa=topics');
183
+	}
172 184
 
173 185
 	// This should exist, but we can make sure.
174 186
 	$_POST['delete_type'] = isset($_POST['delete_type']) ? $_POST['delete_type'] : 'nothing';
@@ -222,8 +234,9 @@  discard block
 block discarded – undo
222 234
 		$condition_params
223 235
 	);
224 236
 	$topics = array();
225
-	while ($row = $smcFunc['db_fetch_assoc']($request))
226
-		$topics[] = $row['id_topic'];
237
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
238
+			$topics[] = $row['id_topic'];
239
+	}
227 240
 	$smcFunc['db_free_result']($request);
228 241
 
229 242
 	removeTopics($topics, false, true);
@@ -247,11 +260,13 @@  discard block
 block discarded – undo
247 260
 	global $sourcedir, $modSettings, $smcFunc;
248 261
 
249 262
 	// Nothing to do?
250
-	if (empty($topics))
251
-		return;
263
+	if (empty($topics)) {
264
+			return;
265
+	}
252 266
 	// Only a single topic.
253
-	if (is_numeric($topics))
254
-		$topics = array($topics);
267
+	if (is_numeric($topics)) {
268
+			$topics = array($topics);
269
+	}
255 270
 
256 271
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
257 272
 
@@ -276,8 +291,9 @@  discard block
 block discarded – undo
276 291
 		);
277 292
 		if ($smcFunc['db_num_rows']($requestMembers) > 0)
278 293
 		{
279
-			while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers))
280
-				updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts']));
294
+			while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers)) {
295
+							updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts']));
296
+			}
281 297
 		}
282 298
 		$smcFunc['db_free_result']($requestMembers);
283 299
 	}
@@ -303,8 +319,9 @@  discard block
 block discarded – undo
303 319
 			$recycleTopics = array();
304 320
 			while ($row = $smcFunc['db_fetch_assoc']($request))
305 321
 			{
306
-				if (function_exists('apache_reset_timeout'))
307
-					@apache_reset_timeout();
322
+				if (function_exists('apache_reset_timeout')) {
323
+									@apache_reset_timeout();
324
+				}
308 325
 
309 326
 				$recycleTopics[] = $row['id_topic'];
310 327
 
@@ -346,20 +363,22 @@  discard block
 block discarded – undo
346 363
 
347 364
 			// Topics that were recycled don't need to be deleted, so subtract them.
348 365
 			$topics = array_diff($topics, $recycleTopics);
366
+		} else {
367
+					$smcFunc['db_free_result']($request);
349 368
 		}
350
-		else
351
-			$smcFunc['db_free_result']($request);
352 369
 	}
353 370
 
354 371
 	// Still topics left to delete?
355
-	if (empty($topics))
356
-		return;
372
+	if (empty($topics)) {
373
+			return;
374
+	}
357 375
 
358 376
 	// Callback for search APIs to do their thing
359 377
 	require_once($sourcedir . '/Search.php');
360 378
 	$searchAPI = findSearchAPI();
361
-	if ($searchAPI->supportsMethod('topicsRemoved'))
362
-		$searchAPI->topicsRemoved($topics);
379
+	if ($searchAPI->supportsMethod('topicsRemoved')) {
380
+			$searchAPI->topicsRemoved($topics);
381
+	}
363 382
 
364 383
 	$adjustBoards = array();
365 384
 
@@ -391,10 +410,11 @@  discard block
 block discarded – undo
391 410
 		$adjustBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts'];
392 411
 
393 412
 		// Add the topics to the right type.
394
-		if ($row['approved'])
395
-			$adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
396
-		else
397
-			$adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
413
+		if ($row['approved']) {
414
+					$adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
415
+		} else {
416
+					$adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
417
+		}
398 418
 	}
399 419
 	$smcFunc['db_free_result']($request);
400 420
 
@@ -403,8 +423,9 @@  discard block
 block discarded – undo
403 423
 		// Decrease the posts/topics...
404 424
 		foreach ($adjustBoards as $stats)
405 425
 		{
406
-			if (function_exists('apache_reset_timeout'))
407
-				@apache_reset_timeout();
426
+			if (function_exists('apache_reset_timeout')) {
427
+							@apache_reset_timeout();
428
+			}
408 429
 
409 430
 			$smcFunc['db_query']('', '
410 431
 				UPDATE {db_prefix}boards
@@ -438,8 +459,9 @@  discard block
 block discarded – undo
438 459
 		)
439 460
 	);
440 461
 	$polls = array();
441
-	while ($row = $smcFunc['db_fetch_assoc']($request))
442
-		$polls[] = $row['id_poll'];
462
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
463
+			$polls[] = $row['id_poll'];
464
+	}
443 465
 	$smcFunc['db_free_result']($request);
444 466
 
445 467
 	if (!empty($polls))
@@ -492,8 +514,9 @@  discard block
 block discarded – undo
492 514
 		);
493 515
 		while ($row = $smcFunc['db_fetch_assoc']($request))
494 516
 		{
495
-			if (function_exists('apache_reset_timeout'))
496
-				@apache_reset_timeout();
517
+			if (function_exists('apache_reset_timeout')) {
518
+							@apache_reset_timeout();
519
+			}
497 520
 
498 521
 			$words = array_merge($words, text2words($row['body'], $customIndexSettings['bytes_per_word'], true));
499 522
 			$messages[] = $row['id_msg'];
@@ -501,8 +524,8 @@  discard block
 block discarded – undo
501 524
 		$smcFunc['db_free_result']($request);
502 525
 		$words = array_unique($words);
503 526
 
504
-		if (!empty($words) && !empty($messages))
505
-			$smcFunc['db_query']('', '
527
+		if (!empty($words) && !empty($messages)) {
528
+					$smcFunc['db_query']('', '
506 529
 				DELETE FROM {db_prefix}log_search_words
507 530
 				WHERE id_word IN ({array_int:word_list})
508 531
 					AND id_msg IN ({array_int:message_list})',
@@ -511,6 +534,7 @@  discard block
 block discarded – undo
511 534
 					'message_list' => $messages,
512 535
 				)
513 536
 			);
537
+		}
514 538
 	}
515 539
 
516 540
 	// Delete anything related to the topic.
@@ -569,8 +593,9 @@  discard block
 block discarded – undo
569 593
 
570 594
 	require_once($sourcedir . '/Subs-Post.php');
571 595
 	$updates = array();
572
-	foreach ($adjustBoards as $stats)
573
-		$updates[] = $stats['id_board'];
596
+	foreach ($adjustBoards as $stats) {
597
+			$updates[] = $stats['id_board'];
598
+	}
574 599
 	updateLastMessages($updates);
575 600
 }
576 601
 
@@ -587,8 +612,9 @@  discard block
 block discarded – undo
587 612
 {
588 613
 	global $board, $sourcedir, $modSettings, $user_info, $smcFunc;
589 614
 
590
-	if (empty($message) || !is_numeric($message))
591
-		return false;
615
+	if (empty($message) || !is_numeric($message)) {
616
+			return false;
617
+	}
592 618
 
593 619
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
594 620
 
@@ -607,8 +633,9 @@  discard block
 block discarded – undo
607 633
 			'id_msg' => $message,
608 634
 		)
609 635
 	);
610
-	if ($smcFunc['db_num_rows']($request) == 0)
611
-		return false;
636
+	if ($smcFunc['db_num_rows']($request) == 0) {
637
+			return false;
638
+	}
612 639
 	$row = $smcFunc['db_fetch_assoc']($request);
613 640
 	$smcFunc['db_free_result']($request);
614 641
 
@@ -629,54 +656,57 @@  discard block
 block discarded – undo
629 656
 				{
630 657
 					if ($row['id_member_poster'] == $user_info['id'])
631 658
 					{
632
-						if (!$delete_replies)
633
-							fatal_lang_error('cannot_delete_replies', 'permission');
659
+						if (!$delete_replies) {
660
+													fatal_lang_error('cannot_delete_replies', 'permission');
661
+						}
662
+					} else {
663
+											fatal_lang_error('cannot_delete_own', 'permission');
634 664
 					}
635
-					else
636
-						fatal_lang_error('cannot_delete_own', 'permission');
665
+				} elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
666
+									fatal_lang_error('modify_post_time_passed', false);
637 667
 				}
638
-				elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
639
-					fatal_lang_error('modify_post_time_passed', false);
640
-			}
641
-			elseif ($row['id_member_poster'] == $user_info['id'])
668
+			} elseif ($row['id_member_poster'] == $user_info['id'])
642 669
 			{
643
-				if (!$delete_replies)
644
-					fatal_lang_error('cannot_delete_replies', 'permission');
670
+				if (!$delete_replies) {
671
+									fatal_lang_error('cannot_delete_replies', 'permission');
672
+				}
673
+			} else {
674
+							fatal_lang_error('cannot_delete_any', 'permission');
645 675
 			}
646
-			else
647
-				fatal_lang_error('cannot_delete_any', 'permission');
648 676
 		}
649 677
 
650 678
 		// Can't delete an unapproved message, if you can't see it!
651 679
 		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !(in_array(0, $delete_any) || in_array($row['id_board'], $delete_any)))
652 680
 		{
653 681
 			$approve_posts = boardsAllowedTo('approve_posts');
654
-			if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts))
655
-				return false;
682
+			if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts)) {
683
+							return false;
684
+			}
656 685
 		}
657
-	}
658
-	else
686
+	} else
659 687
 	{
660 688
 		// Check permissions to delete this message.
661 689
 		if ($row['id_member'] == $user_info['id'])
662 690
 		{
663 691
 			if (!allowedTo('delete_own'))
664 692
 			{
665
-				if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any'))
666
-					isAllowedTo('delete_replies');
667
-				elseif (!allowedTo('delete_any'))
668
-					isAllowedTo('delete_own');
693
+				if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
694
+									isAllowedTo('delete_replies');
695
+				} elseif (!allowedTo('delete_any')) {
696
+									isAllowedTo('delete_own');
697
+				}
698
+			} elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
699
+							fatal_lang_error('modify_post_time_passed', false);
669 700
 			}
670
-			elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
671
-				fatal_lang_error('modify_post_time_passed', false);
701
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
702
+					isAllowedTo('delete_replies');
703
+		} else {
704
+					isAllowedTo('delete_any');
672 705
 		}
673
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any'))
674
-			isAllowedTo('delete_replies');
675
-		else
676
-			isAllowedTo('delete_any');
677 706
 
678
-		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own'))
679
-			isAllowedTo('approve_posts');
707
+		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own')) {
708
+					isAllowedTo('approve_posts');
709
+		}
680 710
 	}
681 711
 
682 712
 	// Delete the *whole* topic, but only if the topic consists of one message.
@@ -692,31 +722,34 @@  discard block
 block discarded – undo
692 722
 				$remove_own = in_array(0, $remove_own) || in_array($row['id_board'], $remove_own);
693 723
 			}
694 724
 
695
-			if ($row['id_member'] != $user_info['id'] && !$remove_any)
696
-				fatal_lang_error('cannot_remove_any', 'permission');
697
-			elseif (!$remove_any && !$remove_own)
698
-				fatal_lang_error('cannot_remove_own', 'permission');
699
-		}
700
-		else
725
+			if ($row['id_member'] != $user_info['id'] && !$remove_any) {
726
+							fatal_lang_error('cannot_remove_any', 'permission');
727
+			} elseif (!$remove_any && !$remove_own) {
728
+							fatal_lang_error('cannot_remove_own', 'permission');
729
+			}
730
+		} else
701 731
 		{
702 732
 			// Check permissions to delete a whole topic.
703
-			if ($row['id_member'] != $user_info['id'])
704
-				isAllowedTo('remove_any');
705
-			elseif (!allowedTo('remove_any'))
706
-				isAllowedTo('remove_own');
733
+			if ($row['id_member'] != $user_info['id']) {
734
+							isAllowedTo('remove_any');
735
+			} elseif (!allowedTo('remove_any')) {
736
+							isAllowedTo('remove_own');
737
+			}
707 738
 		}
708 739
 
709 740
 		// ...if there is only one post.
710
-		if (!empty($row['num_replies']))
711
-			fatal_lang_error('delFirstPost', false);
741
+		if (!empty($row['num_replies'])) {
742
+					fatal_lang_error('delFirstPost', false);
743
+		}
712 744
 
713 745
 		removeTopics($row['id_topic']);
714 746
 		return true;
715 747
 	}
716 748
 
717 749
 	// Deleting a recycled message can not lower anyone's post count.
718
-	if (!empty($recycle_board) && $row['id_board'] == $recycle_board)
719
-		$decreasePostCount = false;
750
+	if (!empty($recycle_board) && $row['id_board'] == $recycle_board) {
751
+			$decreasePostCount = false;
752
+	}
720 753
 
721 754
 	// This is the last post, update the last post on the board.
722 755
 	if ($row['id_last_msg'] == $message)
@@ -755,8 +788,8 @@  discard block
 block discarded – undo
755 788
 		);
756 789
 	}
757 790
 	// Only decrease post counts.
758
-	else
759
-		$smcFunc['db_query']('', '
791
+	else {
792
+			$smcFunc['db_query']('', '
760 793
 			UPDATE {db_prefix}topics
761 794
 			SET ' . ($row['approved'] ? '
762 795
 				num_replies = CASE WHEN num_replies = {int:no_replies} THEN 0 ELSE num_replies - 1 END' : '
@@ -768,6 +801,7 @@  discard block
 block discarded – undo
768 801
 				'id_topic' => $row['id_topic'],
769 802
 			)
770 803
 		);
804
+	}
771 805
 
772 806
 	// Default recycle to false.
773 807
 	$recycle = false;
@@ -787,8 +821,9 @@  discard block
 block discarded – undo
787 821
 				'recycle_board' => $modSettings['recycle_board'],
788 822
 			)
789 823
 		);
790
-		if ($smcFunc['db_num_rows']($request) == 0)
791
-			fatal_lang_error('recycle_no_valid_board');
824
+		if ($smcFunc['db_num_rows']($request) == 0) {
825
+					fatal_lang_error('recycle_no_valid_board');
826
+		}
792 827
 		list ($isRead, $last_board_msg) = $smcFunc['db_fetch_row']($request);
793 828
 		$smcFunc['db_free_result']($request);
794 829
 
@@ -807,8 +842,8 @@  discard block
 block discarded – undo
807 842
 		$smcFunc['db_free_result']($request);
808 843
 
809 844
 		// Insert a new topic in the recycle board if $id_recycle_topic is empty.
810
-		if (empty($id_recycle_topic))
811
-			$id_topic = $smcFunc['db_insert']('',
845
+		if (empty($id_recycle_topic)) {
846
+					$id_topic = $smcFunc['db_insert']('',
812 847
 				'{db_prefix}topics',
813 848
 				array(
814 849
 					'id_board' => 'int', 'id_member_started' => 'int', 'id_member_updated' => 'int', 'id_first_msg' => 'int',
@@ -821,6 +856,7 @@  discard block
 block discarded – undo
821 856
 				array('id_topic'),
822 857
 				1
823 858
 			);
859
+		}
824 860
 
825 861
 		// Capture the ID of the new topic...
826 862
 		$topicID = empty($id_recycle_topic) ? $id_topic : $id_recycle_topic;
@@ -858,22 +894,24 @@  discard block
 block discarded – undo
858 894
 			);
859 895
 
860 896
 			// Mark recycled topic as read.
861
-			if (!$user_info['is_guest'])
862
-				$smcFunc['db_insert']('replace',
897
+			if (!$user_info['is_guest']) {
898
+							$smcFunc['db_insert']('replace',
863 899
 					'{db_prefix}log_topics',
864 900
 					array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int', 'unwatched' => 'int'),
865 901
 					array($topicID, $user_info['id'], $modSettings['maxMsgID'], 0),
866 902
 					array('id_topic', 'id_member')
867 903
 				);
904
+			}
868 905
 
869 906
 			// Mark recycle board as seen, if it was marked as seen before.
870
-			if (!empty($isRead) && !$user_info['is_guest'])
871
-				$smcFunc['db_insert']('replace',
907
+			if (!empty($isRead) && !$user_info['is_guest']) {
908
+							$smcFunc['db_insert']('replace',
872 909
 					'{db_prefix}log_boards',
873 910
 					array('id_board' => 'int', 'id_member' => 'int', 'id_msg' => 'int'),
874 911
 					array($modSettings['recycle_board'], $user_info['id'], $modSettings['maxMsgID']),
875 912
 					array('id_board', 'id_member')
876 913
 				);
914
+			}
877 915
 
878 916
 			// Add one topic and post to the recycle bin board.
879 917
 			$smcFunc['db_query']('', '
@@ -891,8 +929,8 @@  discard block
 block discarded – undo
891 929
 			);
892 930
 
893 931
 			// Lets increase the num_replies, and the first/last message ID as appropriate.
894
-			if (!empty($id_recycle_topic))
895
-				$smcFunc['db_query']('', '
932
+			if (!empty($id_recycle_topic)) {
933
+							$smcFunc['db_query']('', '
896 934
 					UPDATE {db_prefix}topics
897 935
 					SET num_replies = num_replies + 1' .
898 936
 						($message > $last_topic_msg ? ', id_last_msg = {int:id_merged_msg}' : '') .
@@ -903,6 +941,7 @@  discard block
 block discarded – undo
903 941
 						'id_merged_msg' => $message,
904 942
 					)
905 943
 				);
944
+			}
906 945
 
907 946
 			// Make sure this message isn't getting deleted later on.
908 947
 			$recycle = true;
@@ -912,8 +951,8 @@  discard block
 block discarded – undo
912 951
 		}
913 952
 
914 953
 		// If it wasn't approved don't keep it in the queue.
915
-		if (!$row['approved'])
916
-			$smcFunc['db_query']('', '
954
+		if (!$row['approved']) {
955
+					$smcFunc['db_query']('', '
917 956
 				DELETE FROM {db_prefix}approval_queue
918 957
 				WHERE id_msg = {int:id_msg}
919 958
 					AND id_attach = {int:id_attach}',
@@ -922,6 +961,7 @@  discard block
 block discarded – undo
922 961
 					'id_attach' => 0,
923 962
 				)
924 963
 			);
964
+		}
925 965
 	}
926 966
 
927 967
 	$smcFunc['db_query']('', '
@@ -939,8 +979,9 @@  discard block
 block discarded – undo
939 979
 
940 980
 	// If the poster was registered and the board this message was on incremented
941 981
 	// the member's posts when it was posted, decrease his or her post count.
942
-	if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved'])
943
-		updateMemberData($row['id_member'], array('posts' => '-'));
982
+	if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved']) {
983
+			updateMemberData($row['id_member'], array('posts' => '-'));
984
+	}
944 985
 
945 986
 	// Only remove posts if they're not recycled.
946 987
 	if (!$recycle)
@@ -948,8 +989,9 @@  discard block
 block discarded – undo
948 989
 		// Callback for search APIs to do their thing
949 990
 		require_once($sourcedir . '/Search.php');
950 991
 		$searchAPI = findSearchAPI();
951
-		if ($searchAPI->supportsMethod('postRemoved'))
952
-			$searchAPI->postRemoved($message);
992
+		if ($searchAPI->supportsMethod('postRemoved')) {
993
+					$searchAPI->postRemoved($message);
994
+		}
953 995
 
954 996
 		// Remove the message!
955 997
 		$smcFunc['db_query']('', '
@@ -964,8 +1006,8 @@  discard block
 block discarded – undo
964 1006
 		{
965 1007
 			$customIndexSettings = smf_json_decode($modSettings['search_custom_index_config'], true);
966 1008
 			$words = text2words($row['body'], $customIndexSettings['bytes_per_word'], true);
967
-			if (!empty($words))
968
-				$smcFunc['db_query']('', '
1009
+			if (!empty($words)) {
1010
+							$smcFunc['db_query']('', '
969 1011
 					DELETE FROM {db_prefix}log_search_words
970 1012
 					WHERE id_word IN ({array_int:word_list})
971 1013
 						AND id_msg = {int:id_msg}',
@@ -974,6 +1016,7 @@  discard block
 block discarded – undo
974 1016
 						'id_msg' => $message,
975 1017
 					)
976 1018
 				);
1019
+			}
977 1020
 		}
978 1021
 
979 1022
 		// Delete attachment(s) if they exist.
@@ -997,10 +1040,11 @@  discard block
 block discarded – undo
997 1040
 
998 1041
 	// And now to update the last message of each board we messed with.
999 1042
 	require_once($sourcedir . '/Subs-Post.php');
1000
-	if ($recycle)
1001
-		updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
1002
-	else
1003
-		updateLastMessages($row['id_board']);
1043
+	if ($recycle) {
1044
+			updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
1045
+	} else {
1046
+			updateLastMessages($row['id_board']);
1047
+	}
1004 1048
 
1005 1049
 	// Close any moderation reports for this message.
1006 1050
 	$smcFunc['db_query']('', '
@@ -1033,8 +1077,9 @@  discard block
 block discarded – undo
1033 1077
 	checkSession('get');
1034 1078
 
1035 1079
 	// Is recycled board enabled?
1036
-	if (empty($modSettings['recycle_enable']))
1037
-		fatal_lang_error('restored_disabled', 'critical');
1080
+	if (empty($modSettings['recycle_enable'])) {
1081
+			fatal_lang_error('restored_disabled', 'critical');
1082
+	}
1038 1083
 
1039 1084
 	// Can we be in here?
1040 1085
 	isAllowedTo('move_any', $modSettings['recycle_board']);
@@ -1049,8 +1094,9 @@  discard block
 block discarded – undo
1049 1094
 	if (!empty($_REQUEST['msgs']))
1050 1095
 	{
1051 1096
 		$msgs = explode(',', $_REQUEST['msgs']);
1052
-		foreach ($msgs as $k => $msg)
1053
-			$msgs[$k] = (int) $msg;
1097
+		foreach ($msgs as $k => $msg) {
1098
+					$msgs[$k] = (int) $msg;
1099
+		}
1054 1100
 
1055 1101
 		// Get the id_previous_board and id_previous_topic.
1056 1102
 		$request = $smcFunc['db_query']('', '
@@ -1084,8 +1130,8 @@  discard block
 block discarded – undo
1084 1130
 			}
1085 1131
 
1086 1132
 			$previous_topics[] = $row['id_previous_topic'];
1087
-			if (empty($actioned_messages[$row['id_previous_topic']]))
1088
-				$actioned_messages[$row['id_previous_topic']] = array(
1133
+			if (empty($actioned_messages[$row['id_previous_topic']])) {
1134
+							$actioned_messages[$row['id_previous_topic']] = array(
1089 1135
 					'msgs' => array(),
1090 1136
 					'count_posts' => $row['count_posts'],
1091 1137
 					'subject' => $row['subject'],
@@ -1095,17 +1141,20 @@  discard block
 block discarded – undo
1095 1141
 					'current_board' => $row['id_board'],
1096 1142
 					'members' => array(),
1097 1143
 				);
1144
+			}
1098 1145
 
1099 1146
 			$actioned_messages[$row['id_previous_topic']]['msgs'][$row['id_msg']] = $row['subject'];
1100
-			if ($row['id_member'])
1101
-				$actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member'];
1147
+			if ($row['id_member']) {
1148
+							$actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member'];
1149
+			}
1102 1150
 		}
1103 1151
 		$smcFunc['db_free_result']($request);
1104 1152
 
1105 1153
 		// Check for topics we are going to fully restore.
1106
-		foreach ($actioned_messages as $topic => $data)
1107
-			if (in_array($topic, $topics_to_restore))
1154
+		foreach ($actioned_messages as $topic => $data) {
1155
+					if (in_array($topic, $topics_to_restore))
1108 1156
 				unset($actioned_messages[$topic]);
1157
+		}
1109 1158
 
1110 1159
 		// Load any previous topics to check they exist.
1111 1160
 		if (!empty($previous_topics))
@@ -1120,11 +1169,12 @@  discard block
 block discarded – undo
1120 1169
 				)
1121 1170
 			);
1122 1171
 			$previous_topics = array();
1123
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1124
-				$previous_topics[$row['id_topic']] = array(
1172
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1173
+							$previous_topics[$row['id_topic']] = array(
1125 1174
 					'board' => $row['id_board'],
1126 1175
 					'subject' => $row['subject'],
1127 1176
 				);
1177
+			}
1128 1178
 			$smcFunc['db_free_result']($request);
1129 1179
 		}
1130 1180
 
@@ -1146,11 +1196,11 @@  discard block
 block discarded – undo
1146 1196
 				// Log em.
1147 1197
 				logAction('restore_posts', array('topic' => $topic, 'subject' => $previous_topics[$topic]['subject'], 'board' => empty($data['previous_board']) ? $data['possible_prev_board'] : $data['previous_board']));
1148 1198
 				$messages = array_merge(array_keys($data['msgs']), $messages);
1149
-			}
1150
-			else
1199
+			} else
1151 1200
 			{
1152
-				foreach ($data['msgs'] as $msg)
1153
-					$unfound_messages[$msg['id']] = $msg['subject'];
1201
+				foreach ($data['msgs'] as $msg) {
1202
+									$unfound_messages[$msg['id']] = $msg['subject'];
1203
+				}
1154 1204
 			}
1155 1205
 		}
1156 1206
 	}
@@ -1159,8 +1209,9 @@  discard block
 block discarded – undo
1159 1209
 	if (!empty($_REQUEST['topics']))
1160 1210
 	{
1161 1211
 		$topics = explode(',', $_REQUEST['topics']);
1162
-		foreach ($topics as $id)
1163
-			$topics_to_restore[] = (int) $id;
1212
+		foreach ($topics as $id) {
1213
+					$topics_to_restore[] = (int) $id;
1214
+		}
1164 1215
 	}
1165 1216
 
1166 1217
 	if (!empty($topics_to_restore))
@@ -1214,8 +1265,9 @@  discard block
 block discarded – undo
1214 1265
 					)
1215 1266
 				);
1216 1267
 
1217
-				while ($member = $smcFunc['db_fetch_assoc']($request2))
1218
-					updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count']));
1268
+				while ($member = $smcFunc['db_fetch_assoc']($request2)) {
1269
+									updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count']));
1270
+				}
1219 1271
 				$smcFunc['db_free_result']($request2);
1220 1272
 			}
1221 1273
 
@@ -1226,8 +1278,9 @@  discard block
 block discarded – undo
1226 1278
 	}
1227 1279
 
1228 1280
 	// Didn't find some things?
1229
-	if (!empty($unfound_messages))
1230
-		fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages)));
1281
+	if (!empty($unfound_messages)) {
1282
+			fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages)));
1283
+	}
1231 1284
 
1232 1285
 	// Just send them to the index if they get here.
1233 1286
 	redirectexit();
@@ -1247,12 +1300,14 @@  discard block
 block discarded – undo
1247 1300
 	//!!! This really needs to be rewritten to take a load of messages from ANY topic, it's also inefficient.
1248 1301
 
1249 1302
 	// Is it an array?
1250
-	if (!is_array($msgs))
1251
-		$msgs = array($msgs);
1303
+	if (!is_array($msgs)) {
1304
+			$msgs = array($msgs);
1305
+	}
1252 1306
 
1253 1307
 	// Lets make sure they are int.
1254
-	foreach ($msgs as $key => $msg)
1255
-		$msgs[$key] = (int) $msg;
1308
+	foreach ($msgs as $key => $msg) {
1309
+			$msgs[$key] = (int) $msg;
1310
+	}
1256 1311
 
1257 1312
 	// Get the source information.
1258 1313
 	$request = $smcFunc['db_query']('', '
@@ -1295,8 +1350,9 @@  discard block
 block discarded – undo
1295 1350
 			)
1296 1351
 		);
1297 1352
 
1298
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1299
-			updateMemberData($row['id_member'], array('posts' => '+'));
1353
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1354
+					updateMemberData($row['id_member'], array('posts' => '+'));
1355
+		}
1300 1356
 	}
1301 1357
 
1302 1358
 	// Time to move the messages.
@@ -1332,13 +1388,15 @@  discard block
 block discarded – undo
1332 1388
 	);
1333 1389
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1334 1390
 	{
1335
-		if ($row['id_first_msg'] < $target_topic_data['id_first_msg'])
1336
-			$target_topic_data['id_first_msg'] = $row['id_first_msg'];
1391
+		if ($row['id_first_msg'] < $target_topic_data['id_first_msg']) {
1392
+					$target_topic_data['id_first_msg'] = $row['id_first_msg'];
1393
+		}
1337 1394
 		$target_topic_data['id_last_msg'] = $row['id_last_msg'];
1338
-		if (!$row['approved'])
1339
-			$target_topic_data['unapproved_posts'] = $row['message_count'];
1340
-		else
1341
-			$target_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1395
+		if (!$row['approved']) {
1396
+					$target_topic_data['unapproved_posts'] = $row['message_count'];
1397
+		} else {
1398
+					$target_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1399
+		}
1342 1400
 	}
1343 1401
 	$smcFunc['db_free_result']($request);
1344 1402
 
@@ -1397,13 +1455,15 @@  discard block
 block discarded – undo
1397 1455
 		);
1398 1456
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1399 1457
 		{
1400
-			if ($row['id_first_msg'] < $source_topic_data['id_first_msg'])
1401
-				$source_topic_data['id_first_msg'] = $row['id_first_msg'];
1458
+			if ($row['id_first_msg'] < $source_topic_data['id_first_msg']) {
1459
+							$source_topic_data['id_first_msg'] = $row['id_first_msg'];
1460
+			}
1402 1461
 			$source_topic_data['id_last_msg'] = $row['id_last_msg'];
1403
-			if (!$row['approved'])
1404
-				$source_topic_data['unapproved_posts'] = $row['message_count'];
1405
-			else
1406
-				$source_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1462
+			if (!$row['approved']) {
1463
+							$source_topic_data['unapproved_posts'] = $row['message_count'];
1464
+			} else {
1465
+							$source_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1466
+			}
1407 1467
 		}
1408 1468
 		$smcFunc['db_free_result']($request);
1409 1469
 
@@ -1467,10 +1527,12 @@  discard block
 block discarded – undo
1467 1527
 
1468 1528
 	// Subject cache?
1469 1529
 	$cache_updates = array();
1470
-	if ($target_first_msg != $target_topic_data['id_first_msg'])
1471
-		$cache_updates[] = $target_topic_data['id_first_msg'];
1472
-	if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg'])
1473
-		$cache_updates[] = $source_topic_data['id_first_msg'];
1530
+	if ($target_first_msg != $target_topic_data['id_first_msg']) {
1531
+			$cache_updates[] = $target_topic_data['id_first_msg'];
1532
+	}
1533
+	if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg']) {
1534
+			$cache_updates[] = $source_topic_data['id_first_msg'];
1535
+	}
1474 1536
 
1475 1537
 	if (!empty($cache_updates))
1476 1538
 	{
@@ -1482,8 +1544,9 @@  discard block
 block discarded – undo
1482 1544
 				'first_messages' => $cache_updates,
1483 1545
 			)
1484 1546
 		);
1485
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1486
-			updateStats('subject', $row['id_topic'], $row['subject']);
1547
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1548
+					updateStats('subject', $row['id_topic'], $row['subject']);
1549
+		}
1487 1550
 		$smcFunc['db_free_result']($request);
1488 1551
 	}
1489 1552
 
@@ -1499,22 +1562,26 @@  discard block
 block discarded – undo
1499 1562
 	global $modSettings, $board, $scripturl, $context;
1500 1563
 
1501 1564
 	// No recycle no need to go further
1502
-	if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board']))
1503
-		return false;
1565
+	if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board'])) {
1566
+			return false;
1567
+	}
1504 1568
 
1505 1569
 	// If it's confirmed go on and delete (from recycle)
1506
-	if (isset($_GET['confirm_delete']))
1507
-		return true;
1570
+	if (isset($_GET['confirm_delete'])) {
1571
+			return true;
1572
+	}
1508 1573
 
1509
-	if (empty($board))
1510
-		return false;
1574
+	if (empty($board)) {
1575
+			return false;
1576
+	}
1511 1577
 
1512
-	if ($modSettings['recycle_board'] != $board)
1513
-		return true;
1514
-	elseif (isset($_REQUEST['msg']))
1515
-		$confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1516
-	else
1517
-		$confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id'];
1578
+	if ($modSettings['recycle_board'] != $board) {
1579
+			return true;
1580
+	} elseif (isset($_REQUEST['msg'])) {
1581
+			$confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1582
+	} else {
1583
+			$confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id'];
1584
+	}
1518 1585
 
1519 1586
 	fatal_lang_error('post_already_deleted', false, array($confirm_url));
1520 1587
 }
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 1 patch
Braces   +214 added lines, -159 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)
@@ -34,8 +35,8 @@  discard block
 block discarded – undo
34 35
 	global $smcFunc;
35 36
 
36 37
 	// Map some database specific functions, only do this once.
37
-	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc')
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc') {
39
+			$smcFunc += array(
39 40
 			'db_query' => 'smf_db_query',
40 41
 			'db_quote' => 'smf_db_quote',
41 42
 			'db_insert' => 'smf_db_insert',
@@ -59,11 +60,13 @@  discard block
 block discarded – undo
59 60
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
60 61
 			'db_is_resource' => 'is_resource',
61 62
 		);
63
+	}
62 64
 
63
-	if (!empty($db_options['persist']))
64
-		$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
65
-	else
66
-		$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
65
+	if (!empty($db_options['persist'])) {
66
+			$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
67
+	} else {
68
+			$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
69
+	}
67 70
 
68 71
 	// Something's wrong, show an error if its fatal (which we assume it is)
69 72
 	if (!$connection)
@@ -71,8 +74,7 @@  discard block
 block discarded – undo
71 74
 		if (!empty($db_options['non_fatal']))
72 75
 		{
73 76
 			return null;
74
-		}
75
-		else
77
+		} else
76 78
 		{
77 79
 			display_db_error();
78 80
 		}
@@ -123,34 +125,42 @@  discard block
 block discarded – undo
123 125
 
124 126
 	list ($values, $connection) = $db_callback;
125 127
 
126
-	if ($matches[1] === 'db_prefix')
127
-		return $db_prefix;
128
+	if ($matches[1] === 'db_prefix') {
129
+			return $db_prefix;
130
+	}
128 131
 
129
-	if ($matches[1] === 'query_see_board')
130
-		return $user_info['query_see_board'];
132
+	if ($matches[1] === 'query_see_board') {
133
+			return $user_info['query_see_board'];
134
+	}
131 135
 
132
-	if ($matches[1] === 'query_wanna_see_board')
133
-		return $user_info['query_wanna_see_board'];
136
+	if ($matches[1] === 'query_wanna_see_board') {
137
+			return $user_info['query_wanna_see_board'];
138
+	}
134 139
 
135
-	if ($matches[1] === 'empty')
136
-		return '\'\'';
140
+	if ($matches[1] === 'empty') {
141
+			return '\'\'';
142
+	}
137 143
 
138
-	if (!isset($matches[2]))
139
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
144
+	if (!isset($matches[2])) {
145
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
146
+	}
140 147
 
141
-	if ($matches[1] === 'literal')
142
-		return '\'' . pg_escape_string($matches[2]) . '\'';
148
+	if ($matches[1] === 'literal') {
149
+			return '\'' . pg_escape_string($matches[2]) . '\'';
150
+	}
143 151
 
144
-	if (!isset($values[$matches[2]]))
145
-		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__);
152
+	if (!isset($values[$matches[2]])) {
153
+			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__);
154
+	}
146 155
 
147 156
 	$replacement = $values[$matches[2]];
148 157
 
149 158
 	switch ($matches[1])
150 159
 	{
151 160
 		case 'int':
152
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
153
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
161
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
162
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
163
+			}
154 164
 			return (string) (int) $replacement;
155 165
 		break;
156 166
 
@@ -162,56 +172,63 @@  discard block
 block discarded – undo
162 172
 		case 'array_int':
163 173
 			if (is_array($replacement))
164 174
 			{
165
-				if (empty($replacement))
166
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
175
+				if (empty($replacement)) {
176
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
177
+				}
167 178
 
168 179
 				foreach ($replacement as $key => $value)
169 180
 				{
170
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
171
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
182
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183
+					}
172 184
 
173 185
 					$replacement[$key] = (string) (int) $value;
174 186
 				}
175 187
 
176 188
 				return implode(', ', $replacement);
189
+			} else {
190
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
177 191
 			}
178
-			else
179
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
180 192
 
181 193
 		break;
182 194
 
183 195
 		case 'array_string':
184 196
 			if (is_array($replacement))
185 197
 			{
186
-				if (empty($replacement))
187
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
198
+				if (empty($replacement)) {
199
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
200
+				}
188 201
 
189
-				foreach ($replacement as $key => $value)
190
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
202
+				foreach ($replacement as $key => $value) {
203
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
204
+				}
191 205
 
192 206
 				return implode(', ', $replacement);
207
+			} else {
208
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
193 209
 			}
194
-			else
195
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
196 210
 		break;
197 211
 
198 212
 		case 'date':
199
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
200
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
201
-			else
202
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
214
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
215
+			} else {
216
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
217
+			}
203 218
 		break;
204 219
 
205 220
 		case 'time':
206
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
207
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
208
-			else
209
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
222
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
223
+			} else {
224
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+			}
210 226
 		break;
211 227
 
212 228
 		case 'float':
213
-			if (!is_numeric($replacement))
214
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
229
+			if (!is_numeric($replacement)) {
230
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+			}
215 232
 			return (string) (float) $replacement;
216 233
 		break;
217 234
 
@@ -224,31 +241,36 @@  discard block
 block discarded – undo
224 241
 		break;
225 242
 
226 243
 		case 'inet':
227
-			if ($replacement == 'null' || $replacement == '')
228
-				return 'null';
229
-			if (inet_pton($replacement) === false)
230
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
244
+			if ($replacement == 'null' || $replacement == '') {
245
+							return 'null';
246
+			}
247
+			if (inet_pton($replacement) === false) {
248
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249
+			}
231 250
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
232 251
 
233 252
 		case 'array_inet':
234 253
 			if (is_array($replacement))
235 254
 			{
236
-				if (empty($replacement))
237
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
255
+				if (empty($replacement)) {
256
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
257
+				}
238 258
 
239 259
 				foreach ($replacement as $key => $value)
240 260
 				{
241
-					if ($replacement == 'null' || $replacement == '')
242
-						$replacement[$key] = 'null';
243
-					if (!isValidIP($value))
244
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
261
+					if ($replacement == 'null' || $replacement == '') {
262
+											$replacement[$key] = 'null';
263
+					}
264
+					if (!isValidIP($value)) {
265
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+					}
245 267
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
246 268
 				}
247 269
 
248 270
 				return implode(', ', $replacement);
271
+			} else {
272
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249 273
 			}
250
-			else
251
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
252 274
 		break;
253 275
 
254 276
 		default:
@@ -335,14 +357,16 @@  discard block
 block discarded – undo
335 357
 		),
336 358
 	);
337 359
 
338
-	if (isset($replacements[$identifier]))
339
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
360
+	if (isset($replacements[$identifier])) {
361
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
362
+	}
340 363
 
341 364
 	// Limits need to be a little different.
342 365
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
343 366
 
344
-	if (trim($db_string) == '')
345
-		return false;
367
+	if (trim($db_string) == '') {
368
+			return false;
369
+	}
346 370
 
347 371
 	// Comments that are allowed in a query are preg_removed.
348 372
 	static $allowed_comments_from = array(
@@ -362,8 +386,9 @@  discard block
 block discarded – undo
362 386
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
363 387
 	$db_replace_result = 0;
364 388
 
365
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
366
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
389
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
390
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
391
+	}
367 392
 
368 393
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
369 394
 	{
@@ -384,8 +409,9 @@  discard block
 block discarded – undo
384 409
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
385 410
 
386 411
 		// Initialize $db_cache if not already initialized.
387
-		if (!isset($db_cache))
388
-			$db_cache = array();
412
+		if (!isset($db_cache)) {
413
+					$db_cache = array();
414
+		}
389 415
 
390 416
 		if (!empty($_SESSION['debug_redirect']))
391 417
 		{
@@ -411,17 +437,18 @@  discard block
 block discarded – undo
411 437
 		while (true)
412 438
 		{
413 439
 			$pos = strpos($db_string, '\'', $pos + 1);
414
-			if ($pos === false)
415
-				break;
440
+			if ($pos === false) {
441
+							break;
442
+			}
416 443
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
417 444
 
418 445
 			while (true)
419 446
 			{
420 447
 				$pos1 = strpos($db_string, '\'', $pos + 1);
421 448
 				$pos2 = strpos($db_string, '\\', $pos + 1);
422
-				if ($pos1 === false)
423
-					break;
424
-				elseif ($pos2 === false || $pos2 > $pos1)
449
+				if ($pos1 === false) {
450
+									break;
451
+				} elseif ($pos2 === false || $pos2 > $pos1)
425 452
 				{
426 453
 					$pos = $pos1;
427 454
 					break;
@@ -437,26 +464,31 @@  discard block
 block discarded – undo
437 464
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
438 465
 
439 466
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
440
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
441
-			$fail = true;
467
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
468
+					$fail = true;
469
+		}
442 470
 		// Trying to change passwords, slow us down, or something?
443
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
444
-			$fail = true;
445
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
446
-			$fail = true;
471
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
472
+					$fail = true;
473
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
474
+					$fail = true;
475
+		}
447 476
 
448
-		if (!empty($fail) && function_exists('log_error'))
449
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
477
+		if (!empty($fail) && function_exists('log_error')) {
478
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
479
+		}
450 480
 	}
451 481
 
452 482
 	$db_last_result = @pg_query($connection, $db_string);
453 483
 
454
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
455
-		$db_last_result = smf_db_error($db_string, $connection);
484
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
485
+			$db_last_result = smf_db_error($db_string, $connection);
486
+	}
456 487
 
457 488
 	// Debugging.
458
-	if (isset($db_show_debug) && $db_show_debug === true)
459
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
489
+	if (isset($db_show_debug) && $db_show_debug === true) {
490
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
491
+	}
460 492
 
461 493
 	return $db_last_result;
462 494
 }
@@ -469,10 +501,11 @@  discard block
 block discarded – undo
469 501
 {
470 502
 	global $db_last_result, $db_replace_result;
471 503
 
472
-	if ($db_replace_result)
473
-		return $db_replace_result;
474
-	elseif ($result === null && !$db_last_result)
475
-		return 0;
504
+	if ($db_replace_result) {
505
+			return $db_replace_result;
506
+	} elseif ($result === null && !$db_last_result) {
507
+			return 0;
508
+	}
476 509
 
477 510
 	return pg_affected_rows($result === null ? $db_last_result : $result);
478 511
 }
@@ -496,8 +529,9 @@  discard block
 block discarded – undo
496 529
 		array(
497 530
 		)
498 531
 	);
499
-	if (!$request)
500
-		return false;
532
+	if (!$request) {
533
+			return false;
534
+	}
501 535
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
502 536
 	$smcFunc['db_free_result']($request);
503 537
 
@@ -518,12 +552,13 @@  discard block
 block discarded – undo
518 552
 	// Decide which connection to use
519 553
 	$connection = $connection === null ? $db_connection : $connection;
520 554
 
521
-	if ($type == 'begin')
522
-		return @pg_query($connection, 'BEGIN');
523
-	elseif ($type == 'rollback')
524
-		return @pg_query($connection, 'ROLLBACK');
525
-	elseif ($type == 'commit')
526
-		return @pg_query($connection, 'COMMIT');
555
+	if ($type == 'begin') {
556
+			return @pg_query($connection, 'BEGIN');
557
+	} elseif ($type == 'rollback') {
558
+			return @pg_query($connection, 'ROLLBACK');
559
+	} elseif ($type == 'commit') {
560
+			return @pg_query($connection, 'COMMIT');
561
+	}
527 562
 
528 563
 	return false;
529 564
 }
@@ -551,19 +586,22 @@  discard block
 block discarded – undo
551 586
 	$query_error = @pg_last_error($connection);
552 587
 
553 588
 	// Log the error.
554
-	if (function_exists('log_error'))
555
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
589
+	if (function_exists('log_error')) {
590
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
591
+	}
556 592
 
557 593
 	// Nothing's defined yet... just die with it.
558
-	if (empty($context) || empty($txt))
559
-		die($query_error);
594
+	if (empty($context) || empty($txt)) {
595
+			die($query_error);
596
+	}
560 597
 
561 598
 	// Show an error message, if possible.
562 599
 	$context['error_title'] = $txt['database_error'];
563
-	if (allowedTo('admin_forum'))
564
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
565
-	else
566
-		$context['error_message'] = $txt['try_again'];
600
+	if (allowedTo('admin_forum')) {
601
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
602
+	} else {
603
+			$context['error_message'] = $txt['try_again'];
604
+	}
567 605
 
568 606
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
569 607
 	{
@@ -585,12 +623,14 @@  discard block
 block discarded – undo
585 623
 {
586 624
 	global $db_row_count;
587 625
 
588
-	if ($counter !== false)
589
-		return pg_fetch_row($request, $counter);
626
+	if ($counter !== false) {
627
+			return pg_fetch_row($request, $counter);
628
+	}
590 629
 
591 630
 	// Reset the row counter...
592
-	if (!isset($db_row_count[(int) $request]))
593
-		$db_row_count[(int) $request] = 0;
631
+	if (!isset($db_row_count[(int) $request])) {
632
+			$db_row_count[(int) $request] = 0;
633
+	}
594 634
 
595 635
 	// Return the right row.
596 636
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -607,12 +647,14 @@  discard block
 block discarded – undo
607 647
 {
608 648
 	global $db_row_count;
609 649
 
610
-	if ($counter !== false)
611
-		return pg_fetch_assoc($request, $counter);
650
+	if ($counter !== false) {
651
+			return pg_fetch_assoc($request, $counter);
652
+	}
612 653
 
613 654
 	// Reset the row counter...
614
-	if (!isset($db_row_count[(int) $request]))
615
-		$db_row_count[(int) $request] = 0;
655
+	if (!isset($db_row_count[(int) $request])) {
656
+			$db_row_count[(int) $request] = 0;
657
+	}
616 658
 
617 659
 	// Return the right row.
618 660
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -665,11 +707,13 @@  discard block
 block discarded – undo
665 707
 
666 708
 	$replace = '';
667 709
 
668
-	if (empty($data))
669
-		return;
710
+	if (empty($data)) {
711
+			return;
712
+	}
670 713
 
671
-	if (!is_array($data[array_rand($data)]))
672
-		$data = array($data);
714
+	if (!is_array($data[array_rand($data)])) {
715
+			$data = array($data);
716
+	}
673 717
 
674 718
 	// Replace the prefix holder with the actual prefix.
675 719
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -688,11 +732,13 @@  discard block
 block discarded – undo
688 732
 			//pg 9.5 got replace support
689 733
 			$pg_version = $smcFunc['db_get_version']();
690 734
 			// if we got a Beta Version
691
-			if (stripos($pg_version, 'beta') !== false)
692
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
735
+			if (stripos($pg_version, 'beta') !== false) {
736
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
737
+			}
693 738
 			// or RC
694
-			if (stripos($pg_version, 'rc') !== false)
695
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
739
+			if (stripos($pg_version, 'rc') !== false) {
740
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
741
+			}
696 742
 
697 743
 			$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
698 744
 		}
@@ -711,8 +757,7 @@  discard block
 block discarded – undo
711 757
 					$key_str .= ($count_pk > 0 ? ',' : '');
712 758
 					$key_str .= $columnName;
713 759
 					$count_pk++;
714
-				}
715
-				else //normal field
760
+				} else //normal field
716 761
 				{
717 762
 					$col_str .= ($count > 0 ? ',' : '');
718 763
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
@@ -720,20 +765,21 @@  discard block
 block discarded – undo
720 765
 				}
721 766
 			}
722 767
 			$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
723
-		}
724
-		else
768
+		} else
725 769
 		{
726 770
 			foreach ($columns as $columnName => $type)
727 771
 			{
728 772
 				// Are we restricting the length?
729
-				if (strpos($type, 'string-') !== false)
730
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
731
-				else
732
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
773
+				if (strpos($type, 'string-') !== false) {
774
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
775
+				} else {
776
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
777
+				}
733 778
 
734 779
 				// A key? That's what we were looking for.
735
-				if (in_array($columnName, $keys))
736
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
780
+				if (in_array($columnName, $keys)) {
781
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
782
+				}
737 783
 				$count++;
738 784
 			}
739 785
 
@@ -769,10 +815,11 @@  discard block
 block discarded – undo
769 815
 		foreach ($columns as $columnName => $type)
770 816
 		{
771 817
 			// Are we restricting the length?
772
-			if (strpos($type, 'string-') !== false)
773
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
774
-			else
775
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
818
+			if (strpos($type, 'string-') !== false) {
819
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
820
+			} else {
821
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
822
+			}
776 823
 		}
777 824
 		$insertData = substr($insertData, 0, -2) . ')';
778 825
 
@@ -781,8 +828,9 @@  discard block
 block discarded – undo
781 828
 
782 829
 		// Here's where the variables are injected to the query.
783 830
 		$insertRows = array();
784
-		foreach ($data as $dataRow)
785
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
831
+		foreach ($data as $dataRow) {
832
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
833
+		}
786 834
 
787 835
 		// Do the insert.
788 836
 		$request = $smcFunc['db_query']('', '
@@ -799,19 +847,21 @@  discard block
 block discarded – undo
799 847
 
800 848
 		if ($with_returning && $request !== false)
801 849
 		{
802
-			if ($returnmode === 2)
803
-				$return_var = array();
850
+			if ($returnmode === 2) {
851
+							$return_var = array();
852
+			}
804 853
 
805 854
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
806 855
 			{
807
-				if (is_numeric($row[0])) // try to emulate mysql limitation
856
+				if (is_numeric($row[0])) {
857
+					// try to emulate mysql limitation
808 858
 				{
809 859
 					if ($returnmode === 1)
810 860
 						$return_var = $row[0];
811
-					elseif ($returnmode === 2)
812
-						$return_var[] = $row[0];
813
-				}
814
-				else
861
+				} elseif ($returnmode === 2) {
862
+											$return_var[] = $row[0];
863
+					}
864
+				} else
815 865
 				{
816 866
 					$with_returning = false;
817 867
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -820,9 +870,10 @@  discard block
 block discarded – undo
820 870
 		}
821 871
 	}
822 872
 	
823
-	if ($with_returning && !empty($return_var))
824
-		return $return_var; 
825
-}
873
+	if ($with_returning && !empty($return_var)) {
874
+			return $return_var;
875
+	}
876
+	}
826 877
 
827 878
 /**
828 879
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -859,8 +910,9 @@  discard block
 block discarded – undo
859 910
  */
860 911
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
861 912
 {
862
-	if (empty($log_message))
863
-		$log_message = $error_message;
913
+	if (empty($log_message)) {
914
+			$log_message = $error_message;
915
+	}
864 916
 
865 917
 	foreach (debug_backtrace() as $step)
866 918
 	{
@@ -879,12 +931,14 @@  discard block
 block discarded – undo
879 931
 	}
880 932
 
881 933
 	// A special case - we want the file and line numbers for debugging.
882
-	if ($error_type == 'return')
883
-		return array($file, $line);
934
+	if ($error_type == 'return') {
935
+			return array($file, $line);
936
+	}
884 937
 
885 938
 	// Is always a critical error.
886
-	if (function_exists('log_error'))
887
-		log_error($log_message, 'critical', $file, $line);
939
+	if (function_exists('log_error')) {
940
+			log_error($log_message, 'critical', $file, $line);
941
+	}
888 942
 
889 943
 	if (function_exists('fatal_error'))
890 944
 	{
@@ -892,12 +946,12 @@  discard block
 block discarded – undo
892 946
 
893 947
 		// Cannot continue...
894 948
 		exit;
949
+	} elseif ($error_type) {
950
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
951
+	} else {
952
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
953
+	}
895 954
 	}
896
-	elseif ($error_type)
897
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
898
-	else
899
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
900
-}
901 955
 
902 956
 /**
903 957
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -914,10 +968,11 @@  discard block
 block discarded – undo
914 968
 		'\\' => '\\\\',
915 969
 	);
916 970
 
917
-	if ($translate_human_wildcards)
918
-		$replacements += array(
971
+	if ($translate_human_wildcards) {
972
+			$replacements += array(
919 973
 			'*' => '%',
920 974
 		);
975
+	}
921 976
 
922 977
 	return strtr($string, $replacements);
923 978
 }
Please login to merge, or discard this patch.
Sources/CacheAPI-sqlite.php 1 patch
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * SQLite Cache API class
@@ -153,8 +154,7 @@  discard block
 block discarded – undo
153 154
 		if (is_null($dir) || !is_writable($dir))
154 155
 		{
155 156
 			$this->cachedir = $cachedir_sqlite;
156
-		}
157
-		else
157
+		} else
158 158
 		{
159 159
 			$this->cachedir = $dir;
160 160
 		}
Please login to merge, or discard this patch.
proxy.php 1 patch
Braces   +33 added lines, -22 removed lines patch added patch discarded remove patch
@@ -63,26 +63,31 @@  discard block
 block discarded – undo
63 63
 	 */
64 64
 	public function checkRequest()
65 65
 	{
66
-		if (!$this->enabled)
67
-			return false;
66
+		if (!$this->enabled) {
67
+					return false;
68
+		}
68 69
 
69 70
 		// Try to create the image cache directory if it doesn't exist
70
-		if (!file_exists($this->cache))
71
-			if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php'))
71
+		if (!file_exists($this->cache)) {
72
+					if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php'))
72 73
 				return false;
74
+		}
73 75
 
74
-		if (empty($_GET['hash']) || empty($_GET['request']))
75
-			return false;
76
+		if (empty($_GET['hash']) || empty($_GET['request'])) {
77
+					return false;
78
+		}
76 79
 
77 80
 		$hash = $_GET['hash'];
78 81
 		$request = $_GET['request'];
79 82
 
80
-		if (md5($request . $this->secret) != $hash)
81
-			return false;
83
+		if (md5($request . $this->secret) != $hash) {
84
+					return false;
85
+		}
82 86
 
83 87
 		// Attempt to cache the request if it doesn't exist
84
-		if (!$this->isCached($request))
85
-			return $this->cacheImage($request);
88
+		if (!$this->isCached($request)) {
89
+					return $this->cacheImage($request);
90
+		}
86 91
 
87 92
 		return true;
88 93
 	}
@@ -103,19 +108,22 @@  discard block
 block discarded – undo
103 108
 		if (!$cached || time() - $cached['time'] > (5 * 86400))
104 109
 		{
105 110
 			@unlink($cached_file);
106
-			if ($this->checkRequest())
107
-				$this->serve();
111
+			if ($this->checkRequest()) {
112
+							$this->serve();
113
+			}
108 114
 			redirectexit($request);
109 115
 		}
110 116
 
111 117
 		// Right, image not cached? Simply redirect, then.
112
-		if (!$this->checkRequest())
113
-		    redirectexit($request);
118
+		if (!$this->checkRequest()) {
119
+				    redirectexit($request);
120
+		}
114 121
 
115 122
 		// Make sure we're serving an image
116 123
 		$contentParts = explode('/', !empty($cached['content_type']) ? $cached['content_type'] : '');
117
-		if ($contentParts[0] != 'image')
118
-			exit;
124
+		if ($contentParts[0] != 'image') {
125
+					exit;
126
+		}
119 127
 
120 128
 		header('Content-type: ' . $cached['content_type']);
121 129
 		header('Content-length: ' . $cached['size']);
@@ -161,19 +169,22 @@  discard block
 block discarded – undo
161 169
 		$request = $curl->get_url_data($request);
162 170
 		$response = $request->result();
163 171
 
164
-		if (empty($response))
165
-			return false;
172
+		if (empty($response)) {
173
+					return false;
174
+		}
166 175
 
167 176
 		$headers = $response['headers'];
168 177
 
169 178
 		// Make sure the url is returning an image
170 179
 		$contentParts = explode('/', !empty($headers['content-type']) ? $headers['content-type'] : '');
171
-		if ($contentParts[0] != 'image')
172
-			return false;
180
+		if ($contentParts[0] != 'image') {
181
+					return false;
182
+		}
173 183
 
174 184
 		// Validate the filesize
175
-		if ($response['size'] > ($this->maxSize * 1024))
176
-			return false;
185
+		if ($response['size'] > ($this->maxSize * 1024)) {
186
+					return false;
187
+		}
177 188
 
178 189
 		return file_put_contents($dest, json_encode(array(
179 190
 			'content_type' => $headers['content-type'],
Please login to merge, or discard this patch.