Completed
Pull Request — release-2.1 (#4016)
by Jeremy
08:36
created
Sources/ScheduledTasks.php 1 patch
Braces   +285 added lines, -207 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 function works out what to do!
@@ -24,9 +25,9 @@  discard block
 block discarded – undo
24 25
 	global $time_start, $smcFunc, $modSettings;
25 26
 
26 27
 	// Special case for doing the mail queue.
27
-	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq')
28
-		ReduceMailQueue();
29
-	else
28
+	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') {
29
+			ReduceMailQueue();
30
+	} else
30 31
 	{
31 32
 		$task_string = '';
32 33
 
@@ -53,18 +54,20 @@  discard block
 block discarded – undo
53 54
 
54 55
 			// How long in seconds it the gap?
55 56
 			$duration = $row['time_regularity'];
56
-			if ($row['time_unit'] == 'm')
57
-				$duration *= 60;
58
-			elseif ($row['time_unit'] == 'h')
59
-				$duration *= 3600;
60
-			elseif ($row['time_unit'] == 'd')
61
-				$duration *= 86400;
62
-			elseif ($row['time_unit'] == 'w')
63
-				$duration *= 604800;
57
+			if ($row['time_unit'] == 'm') {
58
+							$duration *= 60;
59
+			} elseif ($row['time_unit'] == 'h') {
60
+							$duration *= 3600;
61
+			} elseif ($row['time_unit'] == 'd') {
62
+							$duration *= 86400;
63
+			} elseif ($row['time_unit'] == 'w') {
64
+							$duration *= 604800;
65
+			}
64 66
 
65 67
 			// If we were really late running this task actually skip the next one.
66
-			if (time() + ($duration / 2) > $next_time)
67
-				$next_time += $duration;
68
+			if (time() + ($duration / 2) > $next_time) {
69
+							$next_time += $duration;
70
+			}
68 71
 
69 72
 			// Update it now, so no others run this!
70 73
 			$smcFunc['db_query']('', '
@@ -81,16 +84,19 @@  discard block
 block discarded – undo
81 84
 			$affected_rows = $smcFunc['db_affected_rows']();
82 85
 
83 86
 			// What kind of task are we handling?
84
-			if (!empty($row['callable']))
85
-				$task_string = $row['callable'];
87
+			if (!empty($row['callable'])) {
88
+							$task_string = $row['callable'];
89
+			}
86 90
 
87 91
 			// Default SMF task or old mods?
88
-			elseif (function_exists('scheduled_' . $row['task']))
89
-				$task_string = 'scheduled_' . $row['task'];
92
+			elseif (function_exists('scheduled_' . $row['task'])) {
93
+							$task_string = 'scheduled_' . $row['task'];
94
+			}
90 95
 
91 96
 			// One last resource, the task name.
92
-			elseif (!empty($row['task']))
93
-				$task_string = $row['task'];
97
+			elseif (!empty($row['task'])) {
98
+							$task_string = $row['task'];
99
+			}
94 100
 
95 101
 			// The function must exist or we are wasting our time, plus do some timestamp checking, and database check!
96 102
 			if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows)
@@ -101,11 +107,11 @@  discard block
 block discarded – undo
101 107
 				$callable_task = call_helper($task_string, true);
102 108
 
103 109
 				// Perform the task.
104
-				if (!empty($callable_task))
105
-					$completed = call_user_func($callable_task);
106
-
107
-				else
108
-					$completed = false;
110
+				if (!empty($callable_task)) {
111
+									$completed = call_user_func($callable_task);
112
+				} else {
113
+									$completed = false;
114
+				}
109 115
 
110 116
 				// Log that we did it ;)
111 117
 				if ($completed)
@@ -138,18 +144,20 @@  discard block
 block discarded – undo
138 144
 			)
139 145
 		);
140 146
 		// No new task scheduled yet?
141
-		if ($smcFunc['db_num_rows']($request) === 0)
142
-			$nextEvent = time() + 86400;
143
-		else
144
-			list ($nextEvent) = $smcFunc['db_fetch_row']($request);
147
+		if ($smcFunc['db_num_rows']($request) === 0) {
148
+					$nextEvent = time() + 86400;
149
+		} else {
150
+					list ($nextEvent) = $smcFunc['db_fetch_row']($request);
151
+		}
145 152
 		$smcFunc['db_free_result']($request);
146 153
 
147 154
 		updateSettings(array('next_task_time' => $nextEvent));
148 155
 	}
149 156
 
150 157
 	// Shall we return?
151
-	if (!isset($_GET['scheduled']))
152
-		return true;
158
+	if (!isset($_GET['scheduled'])) {
159
+			return true;
160
+	}
153 161
 
154 162
 	// Finally, send some stuff...
155 163
 	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -181,16 +189,18 @@  discard block
 block discarded – undo
181 189
 	while ($row = $smcFunc['db_fetch_assoc']($request))
182 190
 	{
183 191
 		// If this is no longer around we'll ignore it.
184
-		if (empty($row['id_topic']))
185
-			continue;
192
+		if (empty($row['id_topic'])) {
193
+					continue;
194
+		}
186 195
 
187 196
 		// What type is it?
188
-		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg'])
189
-			$type = 'topic';
190
-		elseif ($row['id_attach'])
191
-			$type = 'attach';
192
-		else
193
-			$type = 'msg';
197
+		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) {
198
+					$type = 'topic';
199
+		} elseif ($row['id_attach']) {
200
+					$type = 'attach';
201
+		} else {
202
+					$type = 'msg';
203
+		}
194 204
 
195 205
 		// Add it to the array otherwise.
196 206
 		$notices[$row['id_board']][$type][] = array(
@@ -211,8 +221,9 @@  discard block
 block discarded – undo
211 221
 	);
212 222
 
213 223
 	// If nothing quit now.
214
-	if (empty($notices))
215
-		return true;
224
+	if (empty($notices)) {
225
+			return true;
226
+	}
216 227
 
217 228
 	// Now we need to think about finding out *who* can approve - this is hard!
218 229
 
@@ -231,14 +242,16 @@  discard block
 block discarded – undo
231 242
 	while ($row = $smcFunc['db_fetch_assoc']($request))
232 243
 	{
233 244
 		// Sorry guys, but we have to ignore guests AND members - it would be too many otherwise.
234
-		if ($row['id_group'] < 2)
235
-			continue;
245
+		if ($row['id_group'] < 2) {
246
+					continue;
247
+		}
236 248
 
237 249
 		$perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group'];
238 250
 
239 251
 		// Anyone who can access has to be considered.
240
-		if ($row['add_deny'])
241
-			$addGroups[] = $row['id_group'];
252
+		if ($row['add_deny']) {
253
+					$addGroups[] = $row['id_group'];
254
+		}
242 255
 	}
243 256
 	$smcFunc['db_free_result']($request);
244 257
 
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 		if (!empty($row['mod_prefs']))
284 297
 		{
285 298
 			list(,, $pref_binary) = explode('|', $row['mod_prefs']);
286
-			if (!($pref_binary & 4))
287
-				continue;
299
+			if (!($pref_binary & 4)) {
300
+							continue;
301
+			}
288 302
 		}
289 303
 
290 304
 		$members[$row['id_member']] = array(
@@ -309,8 +323,9 @@  discard block
 block discarded – undo
309 323
 		$emailbody = '';
310 324
 
311 325
 		// Load the language file as required.
312
-		if (empty($current_language) || $current_language != $member['language'])
313
-			$current_language = loadLanguage('EmailTemplates', $member['language'], false);
326
+		if (empty($current_language) || $current_language != $member['language']) {
327
+					$current_language = loadLanguage('EmailTemplates', $member['language'], false);
328
+		}
314 329
 
315 330
 		// Loop through each notice...
316 331
 		foreach ($notices as $board => $notice)
@@ -318,29 +333,34 @@  discard block
 block discarded – undo
318 333
 			$access = false;
319 334
 
320 335
 			// Can they mod in this board?
321
-			if (isset($mods[$id][$board]))
322
-				$access = true;
336
+			if (isset($mods[$id][$board])) {
337
+							$access = true;
338
+			}
323 339
 
324 340
 			// Do the group check...
325 341
 			if (!$access && isset($perms[$profiles[$board]]['add']))
326 342
 			{
327 343
 				// They can access?!
328
-				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups']))
329
-					$access = true;
344
+				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) {
345
+									$access = true;
346
+				}
330 347
 
331 348
 				// If they have deny rights don't consider them!
332
-				if (isset($perms[$profiles[$board]]['deny']))
333
-					if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
349
+				if (isset($perms[$profiles[$board]]['deny'])) {
350
+									if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
334 351
 						$access = false;
352
+				}
335 353
 			}
336 354
 
337 355
 			// Finally, fix it for admins!
338
-			if (in_array(1, $member['groups']))
339
-				$access = true;
356
+			if (in_array(1, $member['groups'])) {
357
+							$access = true;
358
+			}
340 359
 
341 360
 			// If they can't access it then give it a break!
342
-			if (!$access)
343
-				continue;
361
+			if (!$access) {
362
+							continue;
363
+			}
344 364
 
345 365
 			foreach ($notice as $type => $items)
346 366
 			{
@@ -348,15 +368,17 @@  discard block
 block discarded – undo
348 368
 				$emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" .
349 369
 					'------------------------------------------------------' . "\n";
350 370
 
351
-				foreach ($items as $item)
352
-					$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
371
+				foreach ($items as $item) {
372
+									$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
373
+				}
353 374
 
354 375
 				$emailbody .= "\n";
355 376
 			}
356 377
 		}
357 378
 
358
-		if ($emailbody == '')
359
-			continue;
379
+		if ($emailbody == '') {
380
+					continue;
381
+		}
360 382
 
361 383
 		$replacements = array(
362 384
 			'REALNAME' => $member['name'],
@@ -397,8 +419,9 @@  discard block
 block discarded – undo
397 419
 			)
398 420
 		);
399 421
 		$members = array();
400
-		while ($row = $smcFunc['db_fetch_assoc']($request))
401
-			$members[$row['id_member']] = $row['warning'];
422
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
423
+					$members[$row['id_member']] = $row['warning'];
424
+		}
402 425
 		$smcFunc['db_free_result']($request);
403 426
 
404 427
 		// Have some members to check?
@@ -420,17 +443,18 @@  discard block
 block discarded – undo
420 443
 			while ($row = $smcFunc['db_fetch_assoc']($request))
421 444
 			{
422 445
 				// More than 24 hours ago?
423
-				if ($row['last_warning'] <= time() - 86400)
424
-					$member_changes[] = array(
446
+				if ($row['last_warning'] <= time() - 86400) {
447
+									$member_changes[] = array(
425 448
 						'id' => $row['id_recipient'],
426 449
 						'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0,
427 450
 					);
451
+				}
428 452
 			}
429 453
 			$smcFunc['db_free_result']($request);
430 454
 
431 455
 			// Have some members to change?
432
-			if (!empty($member_changes))
433
-				foreach ($member_changes as $change)
456
+			if (!empty($member_changes)) {
457
+							foreach ($member_changes as $change)
434 458
 					$smcFunc['db_query']('', '
435 459
 						UPDATE {db_prefix}members
436 460
 						SET warning = {int:warning}
@@ -440,6 +464,7 @@  discard block
 block discarded – undo
440 464
 							'id_member' => $change['id'],
441 465
 						)
442 466
 					);
467
+			}
443 468
 		}
444 469
 	}
445 470
 
@@ -452,16 +477,17 @@  discard block
 block discarded – undo
452 477
 
453 478
 	// Check the database version - for some buggy MySQL version.
454 479
 	$server_version = $smcFunc['db_server_info']();
455
-	if (($db_type == 'mysql') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
456
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
457
-	elseif (!empty($modSettings['db_mysql_group_by_fix']))
458
-		$smcFunc['db_query']('', '
480
+	if (($db_type == 'mysql') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
481
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
482
+	} elseif (!empty($modSettings['db_mysql_group_by_fix'])) {
483
+			$smcFunc['db_query']('', '
459 484
 			DELETE FROM {db_prefix}settings
460 485
 			WHERE variable = {string:mysql_fix}',
461 486
 			array(
462 487
 				'mysql_fix' => 'db_mysql_group_by_fix',
463 488
 			)
464 489
 		);
490
+	}
465 491
 
466 492
 	// Clean up some old login history information.
467 493
 	$smcFunc['db_query']('', '
@@ -519,15 +545,17 @@  discard block
 block discarded – undo
519 545
 
520 546
 		// Store this useful data!
521 547
 		$boards[$row['id_board']] = $row['id_board'];
522
-		if ($row['id_topic'])
523
-			$notify['topics'][$row['id_topic']][] = $row['id_member'];
524
-		else
525
-			$notify['boards'][$row['id_board']][] = $row['id_member'];
548
+		if ($row['id_topic']) {
549
+					$notify['topics'][$row['id_topic']][] = $row['id_member'];
550
+		} else {
551
+					$notify['boards'][$row['id_board']][] = $row['id_member'];
552
+		}
526 553
 	}
527 554
 	$smcFunc['db_free_result']($request);
528 555
 
529
-	if (empty($boards))
530
-		return true;
556
+	if (empty($boards)) {
557
+			return true;
558
+	}
531 559
 
532 560
 	// Just get the board names.
533 561
 	$request = $smcFunc['db_query']('', '
@@ -539,12 +567,14 @@  discard block
 block discarded – undo
539 567
 		)
540 568
 	);
541 569
 	$boards = array();
542
-	while ($row = $smcFunc['db_fetch_assoc']($request))
543
-		$boards[$row['id_board']] = $row['name'];
570
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
571
+			$boards[$row['id_board']] = $row['name'];
572
+	}
544 573
 	$smcFunc['db_free_result']($request);
545 574
 
546
-	if (empty($boards))
547
-		return true;
575
+	if (empty($boards)) {
576
+			return true;
577
+	}
548 578
 
549 579
 	// Get the actual topics...
550 580
 	$request = $smcFunc['db_query']('', '
@@ -564,52 +594,57 @@  discard block
 block discarded – undo
564 594
 	$types = array();
565 595
 	while ($row = $smcFunc['db_fetch_assoc']($request))
566 596
 	{
567
-		if (!isset($types[$row['note_type']][$row['id_board']]))
568
-			$types[$row['note_type']][$row['id_board']] = array(
597
+		if (!isset($types[$row['note_type']][$row['id_board']])) {
598
+					$types[$row['note_type']][$row['id_board']] = array(
569 599
 				'lines' => array(),
570 600
 				'name' => $row['board_name'],
571 601
 				'id' => $row['id_board'],
572 602
 			);
603
+		}
573 604
 
574 605
 		if ($row['note_type'] == 'reply')
575 606
 		{
576
-			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
577
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
578
-			else
579
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
607
+			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
608
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
609
+			} else {
610
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
580 611
 					'id' => $row['id_topic'],
581 612
 					'subject' => un_htmlspecialchars($row['subject']),
582 613
 					'count' => 1,
583 614
 				);
584
-		}
585
-		elseif ($row['note_type'] == 'topic')
615
+			}
616
+		} elseif ($row['note_type'] == 'topic')
586 617
 		{
587
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
588
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
618
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
619
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
589 620
 					'id' => $row['id_topic'],
590 621
 					'subject' => un_htmlspecialchars($row['subject']),
591 622
 				);
592
-		}
593
-		else
623
+			}
624
+		} else
594 625
 		{
595
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
596
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
626
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
627
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
597 628
 					'id' => $row['id_topic'],
598 629
 					'subject' => un_htmlspecialchars($row['subject']),
599 630
 					'starter' => $row['id_member_started'],
600 631
 				);
632
+			}
601 633
 		}
602 634
 
603 635
 		$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
604
-		if (!empty($notify['topics'][$row['id_topic']]))
605
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
606
-		if (!empty($notify['boards'][$row['id_board']]))
607
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
636
+		if (!empty($notify['topics'][$row['id_topic']])) {
637
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
638
+		}
639
+		if (!empty($notify['boards'][$row['id_board']])) {
640
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
641
+		}
608 642
 	}
609 643
 	$smcFunc['db_free_result']($request);
610 644
 
611
-	if (empty($types))
612
-		return true;
645
+	if (empty($types)) {
646
+			return true;
647
+	}
613 648
 
614 649
 	// Let's load all the languages into a cache thingy.
615 650
 	$langtxt = array();
@@ -650,8 +685,9 @@  discard block
 block discarded – undo
650 685
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
651 686
 
652 687
 		// Did they not elect to choose this?
653
-		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
654
-			continue;
688
+		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
689
+					continue;
690
+		}
655 691
 
656 692
 		// Right character set!
657 693
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -667,39 +703,43 @@  discard block
 block discarded – undo
667 703
 		if (isset($types['topic']))
668 704
 		{
669 705
 			$titled = false;
670
-			foreach ($types['topic'] as $id => $board)
671
-				foreach ($board['lines'] as $topic)
706
+			foreach ($types['topic'] as $id => $board) {
707
+							foreach ($board['lines'] as $topic)
672 708
 					if (in_array($mid, $topic['members']))
673 709
 					{
674 710
 						if (!$titled)
675 711
 						{
676 712
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
713
+			}
677 714
 							$titled = true;
678 715
 						}
679 716
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
680 717
 					}
681
-			if ($titled)
682
-				$email['body'] .= "\n";
718
+			if ($titled) {
719
+							$email['body'] .= "\n";
720
+			}
683 721
 		}
684 722
 
685 723
 		// What about replies?
686 724
 		if (isset($types['reply']))
687 725
 		{
688 726
 			$titled = false;
689
-			foreach ($types['reply'] as $id => $board)
690
-				foreach ($board['lines'] as $topic)
727
+			foreach ($types['reply'] as $id => $board) {
728
+							foreach ($board['lines'] as $topic)
691 729
 					if (in_array($mid, $topic['members']))
692 730
 					{
693 731
 						if (!$titled)
694 732
 						{
695 733
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
734
+			}
696 735
 							$titled = true;
697 736
 						}
698 737
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
699 738
 					}
700 739
 
701
-			if ($titled)
702
-				$email['body'] .= "\n";
740
+			if ($titled) {
741
+							$email['body'] .= "\n";
742
+			}
703 743
 		}
704 744
 
705 745
 		// Finally, moderation actions!
@@ -708,24 +748,27 @@  discard block
 block discarded – undo
708 748
 			$titled = false;
709 749
 			foreach ($types as $note_type => $type)
710 750
 			{
711
-				if ($note_type == 'topic' || $note_type == 'reply')
712
-					continue;
751
+				if ($note_type == 'topic' || $note_type == 'reply') {
752
+									continue;
753
+				}
713 754
 
714
-				foreach ($type as $id => $board)
715
-					foreach ($board['lines'] as $topic)
755
+				foreach ($type as $id => $board) {
756
+									foreach ($board['lines'] as $topic)
716 757
 						if (in_array($mid, $topic['members']))
717 758
 						{
718 759
 							if (!$titled)
719 760
 							{
720 761
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
762
+				}
721 763
 								$titled = true;
722 764
 							}
723 765
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
724 766
 						}
725 767
 			}
726 768
 		}
727
-		if ($titled)
728
-			$email['body'] .= "\n";
769
+		if ($titled) {
770
+					$email['body'] .= "\n";
771
+		}
729 772
 
730 773
 		// Then just say our goodbyes!
731 774
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -753,8 +796,7 @@  discard block
 block discarded – undo
753 796
 				'not_daily' => 0,
754 797
 			)
755 798
 		);
756
-	}
757
-	else
799
+	} else
758 800
 	{
759 801
 		// Clear any only weekly ones, and stop us from sending daily again.
760 802
 		$smcFunc['db_query']('', '
@@ -816,16 +858,19 @@  discard block
 block discarded – undo
816 858
 	global $modSettings, $smcFunc, $sourcedir;
817 859
 
818 860
 	// Are we intending another script to be sending out the queue?
819
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
820
-		return false;
861
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
862
+			return false;
863
+	}
821 864
 
822 865
 	// By default send 5 at once.
823
-	if (!$number)
824
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
866
+	if (!$number) {
867
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
868
+	}
825 869
 
826 870
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
827
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
828
-		return false;
871
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
872
+			return false;
873
+	}
829 874
 
830 875
 	// By default move the next sending on by 10 seconds, and require an affected row.
831 876
 	if (!$override_limit)
@@ -842,8 +887,9 @@  discard block
 block discarded – undo
842 887
 				'last_send' => $modSettings['mail_next_send'],
843 888
 			)
844 889
 		);
845
-		if ($smcFunc['db_affected_rows']() == 0)
846
-			return false;
890
+		if ($smcFunc['db_affected_rows']() == 0) {
891
+					return false;
892
+		}
847 893
 		$modSettings['mail_next_send'] = time() + $delay;
848 894
 	}
849 895
 
@@ -864,8 +910,9 @@  discard block
 block discarded – undo
864 910
 			$mn += $number;
865 911
 		}
866 912
 		// No more I'm afraid, return!
867
-		else
868
-			return false;
913
+		else {
914
+					return false;
915
+		}
869 916
 
870 917
 		// Reflect that we're about to send some, do it now to be safe.
871 918
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -900,14 +947,15 @@  discard block
 block discarded – undo
900 947
 	$smcFunc['db_free_result']($request);
901 948
 
902 949
 	// Delete, delete, delete!!!
903
-	if (!empty($ids))
904
-		$smcFunc['db_query']('', '
950
+	if (!empty($ids)) {
951
+			$smcFunc['db_query']('', '
905 952
 			DELETE FROM {db_prefix}mail_queue
906 953
 			WHERE id_mail IN ({array_int:mail_list})',
907 954
 			array(
908 955
 				'mail_list' => $ids,
909 956
 			)
910 957
 		);
958
+	}
911 959
 
912 960
 	// Don't believe we have any left?
913 961
 	if (count($ids) < $number)
@@ -925,11 +973,13 @@  discard block
 block discarded – undo
925 973
 		);
926 974
 	}
927 975
 
928
-	if (empty($ids))
929
-		return false;
976
+	if (empty($ids)) {
977
+			return false;
978
+	}
930 979
 
931
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
932
-		require_once($sourcedir . '/Subs-Post.php');
980
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
981
+			require_once($sourcedir . '/Subs-Post.php');
982
+	}
933 983
 
934 984
 	// Send each email, yea!
935 985
 	$failed_emails = array();
@@ -949,15 +999,17 @@  discard block
 block discarded – undo
949 999
 
950 1000
 			// Try to stop a timeout, this would be bad...
951 1001
 			@set_time_limit(300);
952
-			if (function_exists('apache_reset_timeout'))
953
-				@apache_reset_timeout();
1002
+			if (function_exists('apache_reset_timeout')) {
1003
+							@apache_reset_timeout();
1004
+			}
1005
+		} else {
1006
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
954 1007
 		}
955
-		else
956
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
957 1008
 
958 1009
 		// Hopefully it sent?
959
-		if (!$result)
960
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1010
+		if (!$result) {
1011
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1012
+		}
961 1013
 	}
962 1014
 
963 1015
 	// Any emails that didn't send?
@@ -972,8 +1024,8 @@  discard block
 block discarded – undo
972 1024
 		);
973 1025
 
974 1026
 		// If we have failed to many times, tell mail to wait a bit and try again.
975
-		if ($modSettings['mail_failed_attempts'] > 5)
976
-			$smcFunc['db_query']('', '
1027
+		if ($modSettings['mail_failed_attempts'] > 5) {
1028
+					$smcFunc['db_query']('', '
977 1029
 				UPDATE {db_prefix}settings
978 1030
 				SET value = {string:next_mail_send}
979 1031
 				WHERE variable = {literal:mail_next_send}
@@ -982,6 +1034,7 @@  discard block
 block discarded – undo
982 1034
 					'next_mail_send' => time() + 60,
983 1035
 					'last_send' => $modSettings['mail_next_send'],
984 1036
 			));
1037
+		}
985 1038
 
986 1039
 		// Add our email back to the queue, manually.
987 1040
 		$smcFunc['db_insert']('insert',
@@ -994,8 +1047,8 @@  discard block
 block discarded – undo
994 1047
 		return false;
995 1048
 	}
996 1049
 	// We where unable to send the email, clear our failed attempts.
997
-	elseif (!empty($modSettings['mail_failed_attempts']))
998
-		$smcFunc['db_query']('', '
1050
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1051
+			$smcFunc['db_query']('', '
999 1052
 			UPDATE {db_prefix}settings
1000 1053
 			SET value = {string:zero}
1001 1054
 			WHERE variable = {string:mail_failed_attempts}',
@@ -1003,6 +1056,7 @@  discard block
 block discarded – undo
1003 1056
 				'zero' => '0',
1004 1057
 				'mail_failed_attempts' => 'mail_failed_attempts',
1005 1058
 		));
1059
+	}
1006 1060
 
1007 1061
 	// Had something to send...
1008 1062
 	return true;
@@ -1019,16 +1073,18 @@  discard block
 block discarded – undo
1019 1073
 	global $modSettings, $smcFunc;
1020 1074
 
1021 1075
 	$task_query = '';
1022
-	if (!is_array($tasks))
1023
-		$tasks = array($tasks);
1076
+	if (!is_array($tasks)) {
1077
+			$tasks = array($tasks);
1078
+	}
1024 1079
 
1025 1080
 	// Actually have something passed?
1026 1081
 	if (!empty($tasks))
1027 1082
 	{
1028
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1029
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1030
-		else
1031
-			$task_query = ' AND task IN ({array_string:tasks})';
1083
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1084
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1085
+		} else {
1086
+					$task_query = ' AND task IN ({array_string:tasks})';
1087
+		}
1032 1088
 	}
1033 1089
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1034 1090
 
@@ -1049,20 +1105,22 @@  discard block
 block discarded – undo
1049 1105
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1050 1106
 
1051 1107
 		// Only bother moving the task if it's out of place or we're forcing it!
1052
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1053
-			$tasks[$row['id_task']] = $next_time;
1054
-		else
1055
-			$next_time = $row['next_time'];
1108
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1109
+					$tasks[$row['id_task']] = $next_time;
1110
+		} else {
1111
+					$next_time = $row['next_time'];
1112
+		}
1056 1113
 
1057 1114
 		// If this is sooner than the current next task, make this the next task.
1058
-		if ($next_time < $nextTaskTime)
1059
-			$nextTaskTime = $next_time;
1115
+		if ($next_time < $nextTaskTime) {
1116
+					$nextTaskTime = $next_time;
1117
+		}
1060 1118
 	}
1061 1119
 	$smcFunc['db_free_result']($request);
1062 1120
 
1063 1121
 	// Now make the changes!
1064
-	foreach ($tasks as $id => $time)
1065
-		$smcFunc['db_query']('', '
1122
+	foreach ($tasks as $id => $time) {
1123
+			$smcFunc['db_query']('', '
1066 1124
 			UPDATE {db_prefix}scheduled_tasks
1067 1125
 			SET next_time = {int:next_time}
1068 1126
 			WHERE id_task = {int:id_task}',
@@ -1071,11 +1129,13 @@  discard block
 block discarded – undo
1071 1129
 				'id_task' => $id,
1072 1130
 			)
1073 1131
 		);
1132
+	}
1074 1133
 
1075 1134
 	// If the next task is now different update.
1076
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1077
-		updateSettings(array('next_task_time' => $nextTaskTime));
1078
-}
1135
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1136
+			updateSettings(array('next_task_time' => $nextTaskTime));
1137
+	}
1138
+	}
1079 1139
 
1080 1140
 /**
1081 1141
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1088,8 +1148,9 @@  discard block
 block discarded – undo
1088 1148
 function next_time($regularity, $unit, $offset)
1089 1149
 {
1090 1150
 	// Just in case!
1091
-	if ($regularity == 0)
1092
-		$regularity = 2;
1151
+	if ($regularity == 0) {
1152
+			$regularity = 2;
1153
+	}
1093 1154
 
1094 1155
 	$curMin = date('i', time());
1095 1156
 
@@ -1099,15 +1160,16 @@  discard block
 block discarded – undo
1099 1160
 		$off = date('i', $offset);
1100 1161
 
1101 1162
 		// If it's now just pretend it ain't,
1102
-		if ($off == $curMin)
1103
-			$next_time = time() + $regularity;
1104
-		else
1163
+		if ($off == $curMin) {
1164
+					$next_time = time() + $regularity;
1165
+		} else
1105 1166
 		{
1106 1167
 			// Make sure that the offset is always in the past.
1107 1168
 			$off = $off > $curMin ? $off - 60 : $off;
1108 1169
 
1109
-			while ($off <= $curMin)
1110
-				$off += $regularity;
1170
+			while ($off <= $curMin) {
1171
+							$off += $regularity;
1172
+			}
1111 1173
 
1112 1174
 			// Now we know when the time should be!
1113 1175
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1127,11 +1189,13 @@  discard block
 block discarded – undo
1127 1189
 		// Default we'll jump in hours.
1128 1190
 		$applyOffset = 3600;
1129 1191
 		// 24 hours = 1 day.
1130
-		if ($unit == 'd')
1131
-			$applyOffset = 86400;
1192
+		if ($unit == 'd') {
1193
+					$applyOffset = 86400;
1194
+		}
1132 1195
 		// Otherwise a week.
1133
-		if ($unit == 'w')
1134
-			$applyOffset = 604800;
1196
+		if ($unit == 'w') {
1197
+					$applyOffset = 604800;
1198
+		}
1135 1199
 
1136 1200
 		$applyOffset *= $regularity;
1137 1201
 
@@ -1168,8 +1232,9 @@  discard block
 block discarded – undo
1168 1232
 		$settings[$row['variable']] = $row['value'];
1169 1233
 
1170 1234
 		// Is this the default theme?
1171
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1172
-			$settings['default_' . $row['variable']] = $row['value'];
1235
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1236
+					$settings['default_' . $row['variable']] = $row['value'];
1237
+		}
1173 1238
 	}
1174 1239
 	$smcFunc['db_free_result']($result);
1175 1240
 
@@ -1179,12 +1244,14 @@  discard block
 block discarded – undo
1179 1244
 		$settings['template_dirs'] = array($settings['theme_dir']);
1180 1245
 
1181 1246
 		// Based on theme (if there is one).
1182
-		if (!empty($settings['base_theme_dir']))
1183
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1247
+		if (!empty($settings['base_theme_dir'])) {
1248
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1249
+		}
1184 1250
 
1185 1251
 		// Lastly the default theme.
1186
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1187
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1252
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1253
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1254
+		}
1188 1255
 	}
1189 1256
 
1190 1257
 	// Assume we want this.
@@ -1253,8 +1320,9 @@  discard block
 block discarded – undo
1253 1320
 		$file_data = fetch_web_data($url);
1254 1321
 
1255 1322
 		// If we got an error - maybe https isn't working, try http?
1256
-		if ($file_data === false && substr($url, 0, 30) == 'https://www.simplemachines.org')
1257
-			$file_data = fetch_web_data(str_replace('https://www.simplemachines.org', 'http://www.simplemachines.org', $url));
1323
+		if ($file_data === false && substr($url, 0, 30) == 'https://www.simplemachines.org') {
1324
+					$file_data = fetch_web_data(str_replace('https://www.simplemachines.org', 'http://www.simplemachines.org', $url));
1325
+		}
1258 1326
 
1259 1327
 		// If we got an error - give up - the site might be down. And if we should happen to be coming from elsewhere, let's also make a note of it.
1260 1328
 		if ($file_data === false)
@@ -1334,8 +1402,9 @@  discard block
 block discarded – undo
1334 1402
 	// Ok should we prune the logs?
1335 1403
 	if (!empty($modSettings['pruningOptions']))
1336 1404
 	{
1337
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1338
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1405
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1406
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1407
+		}
1339 1408
 
1340 1409
 		if (!empty($modSettings['pruneErrorLog']))
1341 1410
 		{
@@ -1401,8 +1470,9 @@  discard block
 block discarded – undo
1401 1470
 				)
1402 1471
 			);
1403 1472
 
1404
-			while ($row = $smcFunc['db_fetch_row']($result))
1405
-				$reports[] = $row[0];
1473
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1474
+							$reports[] = $row[0];
1475
+			}
1406 1476
 
1407 1477
 			$smcFunc['db_free_result']($result);
1408 1478
 
@@ -1564,8 +1634,9 @@  discard block
 block discarded – undo
1564 1634
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1565 1635
 
1566 1636
 		// Send the actual email.
1567
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1568
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1637
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1638
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1639
+		}
1569 1640
 
1570 1641
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1571 1642
 		{
@@ -1588,18 +1659,19 @@  discard block
 block discarded – undo
1588 1659
 	}
1589 1660
 
1590 1661
 	// Insert the alerts if any
1591
-	if (!empty($alert_rows))
1592
-		$smcFunc['db_insert']('',
1662
+	if (!empty($alert_rows)) {
1663
+			$smcFunc['db_insert']('',
1593 1664
 			'{db_prefix}user_alerts',
1594 1665
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1595 1666
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1596 1667
 			$alert_rows,
1597 1668
 			array()
1598 1669
 		);
1670
+	}
1599 1671
 
1600 1672
 	// Mark the reminder as sent.
1601
-	if (!empty($subs_reminded))
1602
-		$smcFunc['db_query']('', '
1673
+	if (!empty($subs_reminded)) {
1674
+			$smcFunc['db_query']('', '
1603 1675
 			UPDATE {db_prefix}log_subscribed
1604 1676
 			SET reminder_sent = {int:reminder_sent}
1605 1677
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1608,6 +1680,7 @@  discard block
 block discarded – undo
1608 1680
 				'reminder_sent' => 1,
1609 1681
 			)
1610 1682
 		);
1683
+	}
1611 1684
 
1612 1685
 	return true;
1613 1686
 }
@@ -1623,13 +1696,13 @@  discard block
 block discarded – undo
1623 1696
 	// We need to know where this thing is going.
1624 1697
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1625 1698
 	{
1626
-		if (!is_array($modSettings['attachmentUploadDir']))
1627
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1699
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1700
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1701
+		}
1628 1702
 
1629 1703
 		// Just use the current path for temp files.
1630 1704
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1631
-	}
1632
-	else
1705
+	} else
1633 1706
 	{
1634 1707
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1635 1708
 	}
@@ -1648,14 +1721,16 @@  discard block
 block discarded – undo
1648 1721
 
1649 1722
 		while ($file = readdir($dir))
1650 1723
 		{
1651
-			if ($file == '.' || $file == '..')
1652
-				continue;
1724
+			if ($file == '.' || $file == '..') {
1725
+							continue;
1726
+			}
1653 1727
 
1654 1728
 			if (strpos($file, 'post_tmp_') !== false)
1655 1729
 			{
1656 1730
 				// Temp file is more than 5 hours old!
1657
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1658
-					@unlink($attach_dir . '/' . $file);
1731
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1732
+									@unlink($attach_dir . '/' . $file);
1733
+				}
1659 1734
 			}
1660 1735
 		}
1661 1736
 		closedir($dir);
@@ -1688,8 +1763,9 @@  discard block
 block discarded – undo
1688 1763
 		)
1689 1764
 	);
1690 1765
 
1691
-	while ($row = $smcFunc['db_fetch_row']($request))
1692
-		$topics[] = $row[0];
1766
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1767
+			$topics[] = $row[0];
1768
+	}
1693 1769
 	$smcFunc['db_free_result']($request);
1694 1770
 
1695 1771
 	// Zap, your gone
@@ -1709,8 +1785,9 @@  discard block
 block discarded – undo
1709 1785
 {
1710 1786
 	global $smcFunc, $sourcedir, $modSettings;
1711 1787
 
1712
-	if (empty($modSettings['drafts_keep_days']))
1713
-		return true;
1788
+	if (empty($modSettings['drafts_keep_days'])) {
1789
+			return true;
1790
+	}
1714 1791
 
1715 1792
 	// init
1716 1793
 	$drafts = array();
@@ -1728,8 +1805,9 @@  discard block
 block discarded – undo
1728 1805
 		)
1729 1806
 	);
1730 1807
 
1731
-	while ($row = $smcFunc['db_fetch_row']($request))
1732
-		$drafts[] = (int) $row[0];
1808
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1809
+			$drafts[] = (int) $row[0];
1810
+	}
1733 1811
 	$smcFunc['db_free_result']($request);
1734 1812
 
1735 1813
 	// If we have old one, remove them
Please login to merge, or discard this patch.
other/install.php 1 patch
Braces   +438 added lines, -326 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -63,10 +64,11 @@  discard block
 block discarded – undo
63 64
 			
64 65
 			list ($charcode) = pg_fetch_row($request);
65 66
 			
66
-			if ($charcode == 'UTF8')			
67
-				return true;
68
-			else
69
-				return false;
67
+			if ($charcode == 'UTF8') {
68
+							return true;
69
+			} else {
70
+							return false;
71
+			}
70 72
 		},
71 73
 		'utf8_version' => '8.0',
72 74
 		'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
@@ -74,12 +76,14 @@  discard block
 block discarded – undo
74 76
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
75 77
 
76 78
 			// Is it reserved?
77
-			if ($value == 'pg_')
78
-				return $txt['error_db_prefix_reserved'];
79
+			if ($value == 'pg_') {
80
+							return $txt['error_db_prefix_reserved'];
81
+			}
79 82
 
80 83
 			// Is the prefix numeric?
81
-			if (preg_match('~^\d~', $value))
82
-				return $txt['error_db_prefix_numeric'];
84
+			if (preg_match('~^\d~', $value)) {
85
+							return $txt['error_db_prefix_numeric'];
86
+			}
83 87
 
84 88
 			return true;
85 89
 		},
@@ -124,10 +128,11 @@  discard block
 block discarded – undo
124 128
 		$incontext['skip'] = false;
125 129
 
126 130
 		// Call the step and if it returns false that means pause!
127
-		if (function_exists($step[2]) && $step[2]() === false)
128
-			break;
129
-		elseif (function_exists($step[2]))
130
-			$incontext['current_step']++;
131
+		if (function_exists($step[2]) && $step[2]() === false) {
132
+					break;
133
+		} elseif (function_exists($step[2])) {
134
+					$incontext['current_step']++;
135
+		}
131 136
 
132 137
 		// No warnings pass on.
133 138
 		$incontext['warning'] = '';
@@ -143,12 +148,14 @@  discard block
 block discarded – undo
143 148
 	global $databases, $incontext;
144 149
 
145 150
 	// Just so people using older versions of PHP aren't left in the cold.
146
-	if (!isset($_SERVER['PHP_SELF']))
147
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
151
+	if (!isset($_SERVER['PHP_SELF'])) {
152
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
153
+	}
148 154
 
149 155
 	// Turn off magic quotes runtime and enable error reporting.
150
-	if (function_exists('set_magic_quotes_runtime'))
151
-		@set_magic_quotes_runtime(0);
156
+	if (function_exists('set_magic_quotes_runtime')) {
157
+			@set_magic_quotes_runtime(0);
158
+	}
152 159
 	error_reporting(E_ALL);
153 160
 
154 161
 	// Fun.  Low PHP version...
@@ -162,21 +169,23 @@  discard block
 block discarded – undo
162 169
 	{
163 170
 		ob_start();
164 171
 
165
-		if (ini_get('session.save_handler') == 'user')
166
-			@ini_set('session.save_handler', 'files');
167
-		if (function_exists('session_start'))
168
-			@session_start();
169
-	}
170
-	else
172
+		if (ini_get('session.save_handler') == 'user') {
173
+					@ini_set('session.save_handler', 'files');
174
+		}
175
+		if (function_exists('session_start')) {
176
+					@session_start();
177
+		}
178
+	} else
171 179
 	{
172 180
 		ob_start('ob_gzhandler');
173 181
 
174
-		if (ini_get('session.save_handler') == 'user')
175
-			@ini_set('session.save_handler', 'files');
182
+		if (ini_get('session.save_handler') == 'user') {
183
+					@ini_set('session.save_handler', 'files');
184
+		}
176 185
 		session_start();
177 186
 
178
-		if (!headers_sent())
179
-			echo '<!DOCTYPE html>
187
+		if (!headers_sent()) {
188
+					echo '<!DOCTYPE html>
180 189
 <html>
181 190
 	<head>
182 191
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -185,14 +194,16 @@  discard block
 block discarded – undo
185 194
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
186 195
 	</body>
187 196
 </html>';
197
+		}
188 198
 		exit;
189 199
 	}
190 200
 
191 201
 	// Add slashes, as long as they aren't already being added.
192
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
193
-		foreach ($_POST as $k => $v)
202
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
203
+			foreach ($_POST as $k => $v)
194 204
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
195 205
 				$_POST[$k] = addslashes($v);
206
+	}
196 207
 
197 208
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
198 209
 	if (isset($_GET['delete']))
@@ -213,8 +224,7 @@  discard block
 block discarded – undo
213 224
 			$ftp->close();
214 225
 
215 226
 			unset($_SESSION['installer_temp_ftp']);
216
-		}
217
-		else
227
+		} else
218 228
 		{
219 229
 			@unlink(__FILE__);
220 230
 
@@ -235,10 +245,11 @@  discard block
 block discarded – undo
235 245
 	{
236 246
 		// Get PHP's default timezone, if set
237 247
 		$ini_tz = ini_get('date.timezone');
238
-		if (!empty($ini_tz))
239
-			$timezone_id = $ini_tz;
240
-		else
241
-			$timezone_id = '';
248
+		if (!empty($ini_tz)) {
249
+					$timezone_id = $ini_tz;
250
+		} else {
251
+					$timezone_id = '';
252
+		}
242 253
 
243 254
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
244 255
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -268,8 +279,9 @@  discard block
 block discarded – undo
268 279
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
269 280
 		while ($entry = $dir->read())
270 281
 		{
271
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
272
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
282
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
283
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
284
+			}
273 285
 		}
274 286
 		$dir->close();
275 287
 	}
@@ -304,10 +316,11 @@  discard block
 block discarded – undo
304 316
 	}
305 317
 
306 318
 	// Override the language file?
307
-	if (isset($_GET['lang_file']))
308
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
309
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
310
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
319
+	if (isset($_GET['lang_file'])) {
320
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
321
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
322
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
323
+	}
311 324
 
312 325
 	// Make sure it exists, if it doesn't reset it.
313 326
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -316,8 +329,9 @@  discard block
 block discarded – undo
316 329
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
317 330
 
318 331
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
319
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
320
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
332
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
333
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
334
+		}
321 335
 	}
322 336
 
323 337
 	// And now include the actual language file itself.
@@ -330,15 +344,18 @@  discard block
 block discarded – undo
330 344
 	global $db_prefix, $db_connection, $sourcedir;
331 345
 	global $smcFunc, $modSettings, $db_type, $db_name, $db_user, $db_persist;
332 346
 
333
-	if (empty($sourcedir))
334
-		$sourcedir = dirname(__FILE__) . '/Sources';
347
+	if (empty($sourcedir)) {
348
+			$sourcedir = dirname(__FILE__) . '/Sources';
349
+	}
335 350
 
336 351
 	// Need this to check whether we need the database password.
337 352
 	require(dirname(__FILE__) . '/Settings.php');
338
-	if (!defined('SMF'))
339
-		define('SMF', 1);
340
-	if (empty($smcFunc))
341
-		$smcFunc = array();
353
+	if (!defined('SMF')) {
354
+			define('SMF', 1);
355
+	}
356
+	if (empty($smcFunc)) {
357
+			$smcFunc = array();
358
+	}
342 359
 
343 360
 	$modSettings['disableQueryCheck'] = true;
344 361
 
@@ -346,8 +363,9 @@  discard block
 block discarded – undo
346 363
 	if (!$db_connection)
347 364
 	{
348 365
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
349
-		if (version_compare(PHP_VERSION, '5', '<'))
350
-			require_once($sourcedir . '/Subs-Compat.php');
366
+		if (version_compare(PHP_VERSION, '5', '<')) {
367
+					require_once($sourcedir . '/Subs-Compat.php');
368
+		}
351 369
 
352 370
 		$db_options = array('persist' => $db_persist);
353 371
 		$port = '';
@@ -358,19 +376,20 @@  discard block
 block discarded – undo
358 376
 			if ($db_type == 'mysql')
359 377
 			{
360 378
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
361
-			}
362
-			elseif ($db_type == 'postgresql')
379
+			} elseif ($db_type == 'postgresql')
363 380
 			{
364 381
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
365 382
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
366 383
 			}
367 384
 		}
368 385
 
369
-		if (!empty($port))
370
-			$db_options['port'] = $port;
386
+		if (!empty($port)) {
387
+					$db_options['port'] = $port;
388
+		}
371 389
 
372
-		if (!$db_connection)
373
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
390
+		if (!$db_connection) {
391
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
392
+		}
374 393
 	}
375 394
 }
376 395
 
@@ -398,8 +417,9 @@  discard block
 block discarded – undo
398 417
 		// @todo REMOVE THIS!!
399 418
 		else
400 419
 		{
401
-			if (function_exists('doStep' . $_GET['step']))
402
-				call_user_func('doStep' . $_GET['step']);
420
+			if (function_exists('doStep' . $_GET['step'])) {
421
+							call_user_func('doStep' . $_GET['step']);
422
+			}
403 423
 		}
404 424
 		// Show the footer.
405 425
 		template_install_below();
@@ -417,8 +437,9 @@  discard block
 block discarded – undo
417 437
 	$incontext['sub_template'] = 'welcome_message';
418 438
 
419 439
 	// Done the submission?
420
-	if (isset($_POST['contbutt']))
421
-		return true;
440
+	if (isset($_POST['contbutt'])) {
441
+			return true;
442
+	}
422 443
 
423 444
 	// See if we think they have already installed it?
424 445
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -426,14 +447,17 @@  discard block
 block discarded – undo
426 447
 		$probably_installed = 0;
427 448
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
428 449
 		{
429
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
430
-				$probably_installed++;
431
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
432
-				$probably_installed++;
450
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
451
+							$probably_installed++;
452
+			}
453
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
454
+							$probably_installed++;
455
+			}
433 456
 		}
434 457
 
435
-		if ($probably_installed == 2)
436
-			$incontext['warning'] = $txt['error_already_installed'];
458
+		if ($probably_installed == 2) {
459
+					$incontext['warning'] = $txt['error_already_installed'];
460
+		}
437 461
 	}
438 462
 
439 463
 	// Is some database support even compiled in?
@@ -448,36 +472,43 @@  discard block
 block discarded – undo
448 472
 				$databases[$key]['supported'] = false;
449 473
 				$notFoundSQLFile = true;
450 474
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
475
+			} else {
476
+							$incontext['supported_databases'][] = $db;
451 477
 			}
452
-			else
453
-				$incontext['supported_databases'][] = $db;
454 478
 		}
455 479
 	}
456 480
 
457 481
 	// Check the PHP version.
458
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>')))
459
-		$error = 'error_php_too_low';
482
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) {
483
+			$error = 'error_php_too_low';
484
+	}
460 485
 	// Make sure we have a supported database
461
-	elseif (empty($incontext['supported_databases']))
462
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
486
+	elseif (empty($incontext['supported_databases'])) {
487
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
488
+	}
463 489
 	// How about session support?  Some crazy sysadmin remove it?
464
-	elseif (!function_exists('session_start'))
465
-		$error = 'error_session_missing';
490
+	elseif (!function_exists('session_start')) {
491
+			$error = 'error_session_missing';
492
+	}
466 493
 	// Make sure they uploaded all the files.
467
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
468
-		$error = 'error_missing_files';
494
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
495
+			$error = 'error_missing_files';
496
+	}
469 497
 	// Very simple check on the session.save_path for Windows.
470 498
 	// @todo Move this down later if they don't use database-driven sessions?
471
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
472
-		$error = 'error_session_save_path';
499
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
500
+			$error = 'error_session_save_path';
501
+	}
473 502
 
474 503
 	// Since each of the three messages would look the same, anyway...
475
-	if (isset($error))
476
-		$incontext['error'] = $txt[$error];
504
+	if (isset($error)) {
505
+			$incontext['error'] = $txt[$error];
506
+	}
477 507
 
478 508
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
479
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
480
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
509
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
510
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
511
+	}
481 512
 
482 513
 	return false;
483 514
 }
@@ -503,12 +534,14 @@  discard block
 block discarded – undo
503 534
 		'db_last_error.php',
504 535
 	);
505 536
 
506
-	foreach ($incontext['detected_languages'] as $lang => $temp)
507
-		$extra_files[] = 'Themes/default/languages/' . $lang;
537
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
538
+			$extra_files[] = 'Themes/default/languages/' . $lang;
539
+	}
508 540
 
509 541
 	// With mod_security installed, we could attempt to fix it with .htaccess.
510
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
511
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
542
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
543
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
544
+	}
512 545
 
513 546
 	$failed_files = array();
514 547
 
@@ -524,12 +557,14 @@  discard block
 block discarded – undo
524 557
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
525 558
 
526 559
 				// Well, 755 hopefully worked... if not, try 777.
527
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
528
-					$failed_files[] = $file;
560
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
561
+									$failed_files[] = $file;
562
+				}
529 563
 			}
530 564
 		}
531
-		foreach ($extra_files as $file)
532
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
565
+		foreach ($extra_files as $file) {
566
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
567
+		}
533 568
 	}
534 569
 	// Windows is trickier.  Let's try opening for r+...
535 570
 	else
@@ -539,30 +574,35 @@  discard block
 block discarded – undo
539 574
 		foreach ($writable_files as $file)
540 575
 		{
541 576
 			// Folders can't be opened for write... but the index.php in them can ;)
542
-			if (is_dir(dirname(__FILE__) . '/' . $file))
543
-				$file .= '/index.php';
577
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
578
+							$file .= '/index.php';
579
+			}
544 580
 
545 581
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
546 582
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
547 583
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
548 584
 
549 585
 			// Hmm, okay, try just for write in that case...
550
-			if (!is_resource($fp))
551
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
586
+			if (!is_resource($fp)) {
587
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
588
+			}
552 589
 
553
-			if (!is_resource($fp))
554
-				$failed_files[] = $file;
590
+			if (!is_resource($fp)) {
591
+							$failed_files[] = $file;
592
+			}
555 593
 
556 594
 			@fclose($fp);
557 595
 		}
558
-		foreach ($extra_files as $file)
559
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
596
+		foreach ($extra_files as $file) {
597
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
598
+		}
560 599
 	}
561 600
 
562 601
 	$failure = count($failed_files) >= 1;
563 602
 
564
-	if (!isset($_SERVER))
565
-		return !$failure;
603
+	if (!isset($_SERVER)) {
604
+			return !$failure;
605
+	}
566 606
 
567 607
 	// Put the list into context.
568 608
 	$incontext['failed_files'] = $failed_files;
@@ -610,19 +650,23 @@  discard block
 block discarded – undo
610 650
 
611 651
 		if (!isset($ftp) || $ftp->error !== false)
612 652
 		{
613
-			if (!isset($ftp))
614
-				$ftp = new ftp_connection(null);
653
+			if (!isset($ftp)) {
654
+							$ftp = new ftp_connection(null);
655
+			}
615 656
 			// Save the error so we can mess with listing...
616
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
617
-				$incontext['ftp_errors'][] = $ftp->last_message;
657
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
658
+							$incontext['ftp_errors'][] = $ftp->last_message;
659
+			}
618 660
 
619 661
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
620 662
 
621
-			if (empty($_POST['ftp_path']) && $found_path)
622
-				$_POST['ftp_path'] = $detect_path;
663
+			if (empty($_POST['ftp_path']) && $found_path) {
664
+							$_POST['ftp_path'] = $detect_path;
665
+			}
623 666
 
624
-			if (!isset($_POST['ftp_username']))
625
-				$_POST['ftp_username'] = $username;
667
+			if (!isset($_POST['ftp_username'])) {
668
+							$_POST['ftp_username'] = $username;
669
+			}
626 670
 
627 671
 			// Set the username etc, into context.
628 672
 			$incontext['ftp'] = array(
@@ -634,8 +678,7 @@  discard block
 block discarded – undo
634 678
 			);
635 679
 
636 680
 			return false;
637
-		}
638
-		else
681
+		} else
639 682
 		{
640 683
 			$_SESSION['installer_temp_ftp'] = array(
641 684
 				'server' => $_POST['ftp_server'],
@@ -649,10 +692,12 @@  discard block
 block discarded – undo
649 692
 
650 693
 			foreach ($failed_files as $file)
651 694
 			{
652
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
653
-					$ftp->chmod($file, 0755);
654
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
655
-					$ftp->chmod($file, 0777);
695
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
696
+									$ftp->chmod($file, 0755);
697
+				}
698
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
699
+									$ftp->chmod($file, 0777);
700
+				}
656 701
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
657 702
 				{
658 703
 					$failed_files_updated[] = $file;
@@ -707,15 +752,17 @@  discard block
 block discarded – undo
707 752
 
708 753
 			if (!$foundOne)
709 754
 			{
710
-				if (isset($db['default_host']))
711
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
755
+				if (isset($db['default_host'])) {
756
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
757
+				}
712 758
 				if (isset($db['default_user']))
713 759
 				{
714 760
 					$incontext['db']['user'] = ini_get($db['default_user']);
715 761
 					$incontext['db']['name'] = ini_get($db['default_user']);
716 762
 				}
717
-				if (isset($db['default_password']))
718
-					$incontext['db']['pass'] = ini_get($db['default_password']);
763
+				if (isset($db['default_password'])) {
764
+									$incontext['db']['pass'] = ini_get($db['default_password']);
765
+				}
719 766
 
720 767
 				// For simplicity and less confusion, leave the port blank by default
721 768
 				$incontext['db']['port'] = '';
@@ -734,10 +781,10 @@  discard block
 block discarded – undo
734 781
 		$incontext['db']['server'] = $_POST['db_server'];
735 782
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
736 783
 
737
-		if (!empty($_POST['db_port']))
738
-			$incontext['db']['port'] = $_POST['db_port'];
739
-	}
740
-	else
784
+		if (!empty($_POST['db_port'])) {
785
+					$incontext['db']['port'] = $_POST['db_port'];
786
+		}
787
+	} else
741 788
 	{
742 789
 		$incontext['db']['prefix'] = 'smf_';
743 790
 	}
@@ -773,10 +820,11 @@  discard block
 block discarded – undo
773 820
 		if (!empty($_POST['db_port']))
774 821
 		{
775 822
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
776
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
777
-				$vars['db_port'] = (int) $_POST['db_port'];
778
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
779
-				$vars['db_port'] = (int) $_POST['db_port'];
823
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
824
+							$vars['db_port'] = (int) $_POST['db_port'];
825
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
826
+							$vars['db_port'] = (int) $_POST['db_port'];
827
+			}
780 828
 		}
781 829
 
782 830
 		// God I hope it saved!
@@ -789,8 +837,9 @@  discard block
 block discarded – undo
789 837
 		// Make sure it works.
790 838
 		require(dirname(__FILE__) . '/Settings.php');
791 839
 
792
-		if (empty($sourcedir))
793
-			$sourcedir = dirname(__FILE__) . '/Sources';
840
+		if (empty($sourcedir)) {
841
+					$sourcedir = dirname(__FILE__) . '/Sources';
842
+		}
794 843
 
795 844
 		// Better find the database file!
796 845
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -800,18 +849,21 @@  discard block
 block discarded – undo
800 849
 		}
801 850
 
802 851
 		// Now include it for database functions!
803
-		if (!defined('SMF'))
804
-			define('SMF', 1);
852
+		if (!defined('SMF')) {
853
+					define('SMF', 1);
854
+		}
805 855
 
806 856
 		$modSettings['disableQueryCheck'] = true;
807
-		if (empty($smcFunc))
808
-			$smcFunc = array();
857
+		if (empty($smcFunc)) {
858
+					$smcFunc = array();
859
+		}
809 860
 
810 861
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
811 862
 
812 863
 		// What - running PHP4? The shame!
813
-		if (version_compare(PHP_VERSION, '5', '<'))
814
-			require_once($sourcedir . '/Subs-Compat.php');
864
+		if (version_compare(PHP_VERSION, '5', '<')) {
865
+					require_once($sourcedir . '/Subs-Compat.php');
866
+		}
815 867
 
816 868
 		// Attempt a connection.
817 869
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -899,12 +951,14 @@  discard block
 block discarded – undo
899 951
 	$incontext['page_title'] = $txt['install_settings'];
900 952
 
901 953
 	// Let's see if we got the database type correct.
902
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
903
-		$db_type = $_POST['db_type'];
954
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
955
+			$db_type = $_POST['db_type'];
956
+	}
904 957
 
905 958
 	// Else we'd better be able to get the connection.
906
-	else
907
-		load_database();
959
+	else {
960
+			load_database();
961
+	}
908 962
 
909 963
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
910 964
 
@@ -924,12 +978,14 @@  discard block
 block discarded – undo
924 978
 	// Submitting?
925 979
 	if (isset($_POST['boardurl']))
926 980
 	{
927
-		if (substr($_POST['boardurl'], -10) == '/index.php')
928
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
929
-		elseif (substr($_POST['boardurl'], -1) == '/')
930
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
931
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
932
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
981
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
982
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
983
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
984
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
985
+		}
986
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
987
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
988
+		}
933 989
 
934 990
 		// Save these variables.
935 991
 		$vars = array(
@@ -966,10 +1022,10 @@  discard block
 block discarded – undo
966 1022
 			{
967 1023
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
968 1024
 				return false;
969
-			}
970
-			else
971
-				// Set the character set here.
1025
+			} else {
1026
+							// Set the character set here.
972 1027
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1028
+			}
973 1029
 		}
974 1030
 
975 1031
 		// Good, skip on.
@@ -989,8 +1045,9 @@  discard block
 block discarded – undo
989 1045
 	$incontext['continue'] = 1;
990 1046
 
991 1047
 	// Already done?
992
-	if (isset($_POST['pop_done']))
993
-		return true;
1048
+	if (isset($_POST['pop_done'])) {
1049
+			return true;
1050
+	}
994 1051
 
995 1052
 	// Reload settings.
996 1053
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1008,8 +1065,9 @@  discard block
 block discarded – undo
1008 1065
 	$modSettings = array();
1009 1066
 	if ($result !== false)
1010 1067
 	{
1011
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1012
-			$modSettings[$row['variable']] = $row['value'];
1068
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1069
+					$modSettings[$row['variable']] = $row['value'];
1070
+		}
1013 1071
 		$smcFunc['db_free_result']($result);
1014 1072
 
1015 1073
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1022,20 +1080,22 @@  discard block
 block discarded – undo
1022 1080
 	$modSettings['disableQueryCheck'] = true;
1023 1081
 
1024 1082
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1025
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1026
-		$smcFunc['db_query']('', '
1083
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1084
+			$smcFunc['db_query']('', '
1027 1085
 			SET NAMES {string:utf8}',
1028 1086
 			array(
1029 1087
 				'db_error_skip' => true,
1030 1088
 				'utf8' => 'utf8',
1031 1089
 			)
1032 1090
 		);
1091
+	}
1033 1092
 
1034 1093
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1035
-	if (substr(__DIR__, -1) == '\\')
1036
-		$attachdir = __DIR__ . 'attachments';
1037
-	else
1038
-		$attachdir = __DIR__ . '/attachments';
1094
+	if (substr(__DIR__, -1) == '\\') {
1095
+			$attachdir = __DIR__ . 'attachments';
1096
+	} else {
1097
+			$attachdir = __DIR__ . '/attachments';
1098
+	}
1039 1099
 
1040 1100
 	$replaces = array(
1041 1101
 		'{$db_prefix}' => $db_prefix,
@@ -1052,8 +1112,9 @@  discard block
 block discarded – undo
1052 1112
 
1053 1113
 	foreach ($txt as $key => $value)
1054 1114
 	{
1055
-		if (substr($key, 0, 8) == 'default_')
1056
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1115
+		if (substr($key, 0, 8) == 'default_') {
1116
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1117
+		}
1057 1118
 	}
1058 1119
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1059 1120
 
@@ -1068,8 +1129,9 @@  discard block
 block discarded – undo
1068 1129
 
1069 1130
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1070 1131
 		{
1071
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1072
-				$engines[] = $row['Engine'];
1132
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1133
+							$engines[] = $row['Engine'];
1134
+			}
1073 1135
 		}
1074 1136
 
1075 1137
 		// Done with this now
@@ -1093,8 +1155,7 @@  discard block
 block discarded – undo
1093 1155
 			$replaces['START TRANSACTION;'] = '';
1094 1156
 			$replaces['COMMIT;'] = '';
1095 1157
 		}
1096
-	}
1097
-	else
1158
+	} else
1098 1159
 	{
1099 1160
 		$has_innodb = false;
1100 1161
 	}
@@ -1116,21 +1177,24 @@  discard block
 block discarded – undo
1116 1177
 	foreach ($sql_lines as $count => $line)
1117 1178
 	{
1118 1179
 		// No comments allowed!
1119
-		if (substr(trim($line), 0, 1) != '#')
1120
-			$current_statement .= "\n" . rtrim($line);
1180
+		if (substr(trim($line), 0, 1) != '#') {
1181
+					$current_statement .= "\n" . rtrim($line);
1182
+		}
1121 1183
 
1122 1184
 		// Is this the end of the query string?
1123
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1124
-			continue;
1185
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1186
+					continue;
1187
+		}
1125 1188
 
1126 1189
 		// Does this table already exist?  If so, don't insert more data into it!
1127 1190
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1128 1191
 		{
1129 1192
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1130
-			if (!empty($matches[0]))
1131
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1132
-			else
1133
-				$incontext['sql_results']['insert_dups']++;
1193
+			if (!empty($matches[0])) {
1194
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1195
+			} else {
1196
+							$incontext['sql_results']['insert_dups']++;
1197
+			}
1134 1198
 
1135 1199
 			$current_statement = '';
1136 1200
 			continue;
@@ -1139,8 +1203,9 @@  discard block
 block discarded – undo
1139 1203
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1140 1204
 		{
1141 1205
 			// Use the appropriate function based on the DB type
1142
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1143
-				$db_errorno = $db_type . '_errno';
1206
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1207
+							$db_errorno = $db_type . '_errno';
1208
+			}
1144 1209
 
1145 1210
 			// Error 1050: Table already exists!
1146 1211
 			// @todo Needs to be made better!
@@ -1155,18 +1220,18 @@  discard block
 block discarded – undo
1155 1220
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1156 1221
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1157 1222
 			}
1158
-		}
1159
-		else
1223
+		} else
1160 1224
 		{
1161
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1162
-				$incontext['sql_results']['tables']++;
1163
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1225
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1226
+							$incontext['sql_results']['tables']++;
1227
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1164 1228
 			{
1165 1229
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1166
-				if (!empty($matches[0]))
1167
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1168
-				else
1169
-					$incontext['sql_results']['inserts']++;
1230
+				if (!empty($matches[0])) {
1231
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1232
+				} else {
1233
+									$incontext['sql_results']['inserts']++;
1234
+				}
1170 1235
 			}
1171 1236
 		}
1172 1237
 
@@ -1179,15 +1244,17 @@  discard block
 block discarded – undo
1179 1244
 	// Sort out the context for the SQL.
1180 1245
 	foreach ($incontext['sql_results'] as $key => $number)
1181 1246
 	{
1182
-		if ($number == 0)
1183
-			unset($incontext['sql_results'][$key]);
1184
-		else
1185
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1247
+		if ($number == 0) {
1248
+					unset($incontext['sql_results'][$key]);
1249
+		} else {
1250
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1251
+		}
1186 1252
 	}
1187 1253
 
1188 1254
 	// Make sure UTF will be used globally.
1189
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1190
-		$newSettings[] = array('global_character_set', 'UTF-8');
1255
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1256
+			$newSettings[] = array('global_character_set', 'UTF-8');
1257
+	}
1191 1258
 
1192 1259
 	// Maybe we can auto-detect better cookie settings?
1193 1260
 	preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
@@ -1198,16 +1265,20 @@  discard block
 block discarded – undo
1198 1265
 		$globalCookies = false;
1199 1266
 
1200 1267
 		// Okay... let's see.  Using a subdomain other than www.? (not a perfect check.)
1201
-		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
1202
-			$globalCookies = true;
1268
+		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) {
1269
+					$globalCookies = true;
1270
+		}
1203 1271
 		// If there's a / in the middle of the path, or it starts with ~... we want local.
1204
-		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
1205
-			$localCookies = true;
1272
+		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) {
1273
+					$localCookies = true;
1274
+		}
1206 1275
 
1207
-		if ($globalCookies)
1208
-			$newSettings[] = array('globalCookies', '1');
1209
-		if ($localCookies)
1210
-			$newSettings[] = array('localCookies', '1');
1276
+		if ($globalCookies) {
1277
+					$newSettings[] = array('globalCookies', '1');
1278
+		}
1279
+		if ($localCookies) {
1280
+					$newSettings[] = array('localCookies', '1');
1281
+		}
1211 1282
 	}
1212 1283
 
1213 1284
 	// Are we allowing stat collection?
@@ -1223,32 +1294,36 @@  discard block
 block discarded – undo
1223 1294
 			fwrite($fp, $out);
1224 1295
 
1225 1296
 			$return_data = '';
1226
-			while (!feof($fp))
1227
-				$return_data .= fgets($fp, 128);
1297
+			while (!feof($fp)) {
1298
+							$return_data .= fgets($fp, 128);
1299
+			}
1228 1300
 
1229 1301
 			fclose($fp);
1230 1302
 
1231 1303
 			// Get the unique site ID.
1232 1304
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1233 1305
 
1234
-			if (!empty($ID[1]))
1235
-				$newSettings[] = array('allow_sm_stats', $ID[1]);
1306
+			if (!empty($ID[1])) {
1307
+							$newSettings[] = array('allow_sm_stats', $ID[1]);
1308
+			}
1236 1309
 		}
1237 1310
 	}
1238 1311
 
1239 1312
 	// Are we enabling SSL?
1240
-	if (!empty($_POST['force_ssl']))
1241
-		$newSettings[] = array('force_ssl', 2);
1313
+	if (!empty($_POST['force_ssl'])) {
1314
+			$newSettings[] = array('force_ssl', 2);
1315
+	}
1242 1316
 
1243 1317
 	// Setting a timezone is required.
1244 1318
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1245 1319
 	{
1246 1320
 		// Get PHP's default timezone, if set
1247 1321
 		$ini_tz = ini_get('date.timezone');
1248
-		if (!empty($ini_tz))
1249
-			$timezone_id = $ini_tz;
1250
-		else
1251
-			$timezone_id = '';
1322
+		if (!empty($ini_tz)) {
1323
+					$timezone_id = $ini_tz;
1324
+		} else {
1325
+					$timezone_id = '';
1326
+		}
1252 1327
 
1253 1328
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1254 1329
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1257,8 +1332,9 @@  discard block
 block discarded – undo
1257 1332
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1258 1333
 		}
1259 1334
 
1260
-		if (date_default_timezone_set($timezone_id))
1261
-			$newSettings[] = array('default_timezone', $timezone_id);
1335
+		if (date_default_timezone_set($timezone_id)) {
1336
+					$newSettings[] = array('default_timezone', $timezone_id);
1337
+		}
1262 1338
 	}
1263 1339
 
1264 1340
 	if (!empty($newSettings))
@@ -1289,16 +1365,18 @@  discard block
 block discarded – undo
1289 1365
 	}
1290 1366
 
1291 1367
 	// MySQL specific stuff
1292
-	if (substr($db_type, 0, 5) != 'mysql')
1293
-		return false;
1368
+	if (substr($db_type, 0, 5) != 'mysql') {
1369
+			return false;
1370
+	}
1294 1371
 
1295 1372
 	// Find database user privileges.
1296 1373
 	$privs = array();
1297 1374
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1298 1375
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1299 1376
 	{
1300
-		if ($row['Privilege'] == 'Alter')
1301
-			$privs[] = $row['Privilege'];
1377
+		if ($row['Privilege'] == 'Alter') {
1378
+					$privs[] = $row['Privilege'];
1379
+		}
1302 1380
 	}
1303 1381
 	$smcFunc['db_free_result']($get_privs);
1304 1382
 
@@ -1328,8 +1406,9 @@  discard block
 block discarded – undo
1328 1406
 	$incontext['continue'] = 1;
1329 1407
 
1330 1408
 	// Skipping?
1331
-	if (!empty($_POST['skip']))
1332
-		return true;
1409
+	if (!empty($_POST['skip'])) {
1410
+			return true;
1411
+	}
1333 1412
 
1334 1413
 	// Need this to check whether we need the database password.
1335 1414
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1342,18 +1421,22 @@  discard block
 block discarded – undo
1342 1421
 	// We need this to properly hash the password for Admin
1343 1422
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1344 1423
 			global $sourcedir;
1345
-			if (function_exists('mb_strtolower'))
1346
-				return mb_strtolower($string, 'UTF-8');
1424
+			if (function_exists('mb_strtolower')) {
1425
+							return mb_strtolower($string, 'UTF-8');
1426
+			}
1347 1427
 			require_once($sourcedir . '/Subs-Charset.php');
1348 1428
 			return utf8_strtolower($string);
1349 1429
 		};
1350 1430
 
1351
-	if (!isset($_POST['username']))
1352
-		$_POST['username'] = '';
1353
-	if (!isset($_POST['email']))
1354
-		$_POST['email'] = '';
1355
-	if (!isset($_POST['server_email']))
1356
-		$_POST['server_email'] = '';
1431
+	if (!isset($_POST['username'])) {
1432
+			$_POST['username'] = '';
1433
+	}
1434
+	if (!isset($_POST['email'])) {
1435
+			$_POST['email'] = '';
1436
+	}
1437
+	if (!isset($_POST['server_email'])) {
1438
+			$_POST['server_email'] = '';
1439
+	}
1357 1440
 
1358 1441
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1359 1442
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1372,8 +1455,9 @@  discard block
 block discarded – undo
1372 1455
 			'admin_group' => 1,
1373 1456
 		)
1374 1457
 	);
1375
-	if ($smcFunc['db_num_rows']($request) != 0)
1376
-		$incontext['skip'] = 1;
1458
+	if ($smcFunc['db_num_rows']($request) != 0) {
1459
+			$incontext['skip'] = 1;
1460
+	}
1377 1461
 	$smcFunc['db_free_result']($request);
1378 1462
 
1379 1463
 	// Trying to create an account?
@@ -1404,8 +1488,9 @@  discard block
 block discarded – undo
1404 1488
 		}
1405 1489
 
1406 1490
 		// Update the webmaster's email?
1407
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1408
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1491
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1492
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1493
+		}
1409 1494
 
1410 1495
 		// Work out whether we're going to have dodgy characters and remove them.
1411 1496
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1428,32 +1513,27 @@  discard block
 block discarded – undo
1428 1513
 			$smcFunc['db_free_result']($result);
1429 1514
 
1430 1515
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1431
-		}
1432
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1516
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1433 1517
 		{
1434 1518
 			// Try the previous step again.
1435 1519
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1436 1520
 			return false;
1437
-		}
1438
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1521
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1439 1522
 		{
1440 1523
 			// Try the previous step again.
1441 1524
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1442 1525
 			return false;
1443
-		}
1444
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1526
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1445 1527
 		{
1446 1528
 			// One step back, this time fill out a proper admin email address.
1447 1529
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1448 1530
 			return false;
1449
-		}
1450
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1531
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1451 1532
 		{
1452 1533
 			// One step back, this time fill out a proper admin email address.
1453 1534
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1454 1535
 			return false;
1455
-		}
1456
-		elseif ($_POST['username'] != '')
1536
+		} elseif ($_POST['username'] != '')
1457 1537
 		{
1458 1538
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1459 1539
 
@@ -1519,17 +1599,19 @@  discard block
 block discarded – undo
1519 1599
 	require_once($sourcedir . '/Subs-Auth.php');
1520 1600
 
1521 1601
 	// Bring a warning over.
1522
-	if (!empty($incontext['account_existed']))
1523
-		$incontext['warning'] = $incontext['account_existed'];
1602
+	if (!empty($incontext['account_existed'])) {
1603
+			$incontext['warning'] = $incontext['account_existed'];
1604
+	}
1524 1605
 
1525
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1526
-		$smcFunc['db_query']('', '
1606
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1607
+			$smcFunc['db_query']('', '
1527 1608
 			SET NAMES {string:db_character_set}',
1528 1609
 			array(
1529 1610
 				'db_character_set' => $db_character_set,
1530 1611
 				'db_error_skip' => true,
1531 1612
 			)
1532 1613
 		);
1614
+	}
1533 1615
 
1534 1616
 	// As track stats is by default enabled let's add some activity.
1535 1617
 	$smcFunc['db_insert']('ignore',
@@ -1550,14 +1632,16 @@  discard block
 block discarded – undo
1550 1632
 	// Only proceed if we can load the data.
1551 1633
 	if ($request)
1552 1634
 	{
1553
-		while ($row = $smcFunc['db_fetch_row']($request))
1554
-			$modSettings[$row[0]] = $row[1];
1635
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1636
+					$modSettings[$row[0]] = $row[1];
1637
+		}
1555 1638
 		$smcFunc['db_free_result']($request);
1556 1639
 	}
1557 1640
 
1558 1641
 	// Automatically log them in ;)
1559
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1560
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1642
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1643
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1644
+	}
1561 1645
 
1562 1646
 	$result = $smcFunc['db_query']('', '
1563 1647
 		SELECT value
@@ -1568,13 +1652,14 @@  discard block
 block discarded – undo
1568 1652
 			'db_error_skip' => true,
1569 1653
 		)
1570 1654
 	);
1571
-	if ($smcFunc['db_num_rows']($result) != 0)
1572
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1655
+	if ($smcFunc['db_num_rows']($result) != 0) {
1656
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1657
+	}
1573 1658
 	$smcFunc['db_free_result']($result);
1574 1659
 
1575
-	if (empty($db_sessions))
1576
-		$_SESSION['admin_time'] = time();
1577
-	else
1660
+	if (empty($db_sessions)) {
1661
+			$_SESSION['admin_time'] = time();
1662
+	} else
1578 1663
 	{
1579 1664
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1580 1665
 
@@ -1598,8 +1683,9 @@  discard block
 block discarded – undo
1598 1683
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1599 1684
 		function($string){
1600 1685
 			global $sourcedir;
1601
-			if (function_exists('mb_strtolower'))
1602
-				return mb_strtolower($string, 'UTF-8');
1686
+			if (function_exists('mb_strtolower')) {
1687
+							return mb_strtolower($string, 'UTF-8');
1688
+			}
1603 1689
 			require_once($sourcedir . '/Subs-Charset.php');
1604 1690
 			return utf8_strtolower($string);
1605 1691
 		};
@@ -1615,8 +1701,9 @@  discard block
 block discarded – undo
1615 1701
 		)
1616 1702
 	);
1617 1703
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1618
-	if ($smcFunc['db_num_rows']($request) > 0)
1619
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1704
+	if ($smcFunc['db_num_rows']($request) > 0) {
1705
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1706
+	}
1620 1707
 	$smcFunc['db_free_result']($request);
1621 1708
 
1622 1709
 	// Now is the perfect time to fetch the SM files.
@@ -1635,8 +1722,9 @@  discard block
 block discarded – undo
1635 1722
 
1636 1723
 	// Check if we need some stupid MySQL fix.
1637 1724
 	$server_version = $smcFunc['db_server_info']();
1638
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1639
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1725
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1726
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1727
+	}
1640 1728
 
1641 1729
 	// Some final context for the template.
1642 1730
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1656,8 +1744,9 @@  discard block
 block discarded – undo
1656 1744
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1657 1745
 
1658 1746
 	// @todo Do we just want to read the file in clean, and split it this way always?
1659
-	if (count($settingsArray) == 1)
1660
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1747
+	if (count($settingsArray) == 1) {
1748
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1749
+	}
1661 1750
 
1662 1751
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1663 1752
 	{
@@ -1672,19 +1761,22 @@  discard block
 block discarded – undo
1672 1761
 			continue;
1673 1762
 		}
1674 1763
 
1675
-		if (trim($settingsArray[$i]) == '?' . '>')
1676
-			$settingsArray[$i] = '';
1764
+		if (trim($settingsArray[$i]) == '?' . '>') {
1765
+					$settingsArray[$i] = '';
1766
+		}
1677 1767
 
1678 1768
 		// Don't trim or bother with it if it's not a variable.
1679
-		if (substr($settingsArray[$i], 0, 1) != '$')
1680
-			continue;
1769
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1770
+					continue;
1771
+		}
1681 1772
 
1682 1773
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1683 1774
 
1684
-		foreach ($vars as $var => $val)
1685
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1775
+		foreach ($vars as $var => $val) {
1776
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1686 1777
 			{
1687 1778
 				$comment = strstr($settingsArray[$i], '#');
1779
+		}
1688 1780
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1689 1781
 				unset($vars[$var]);
1690 1782
 			}
@@ -1694,36 +1786,41 @@  discard block
 block discarded – undo
1694 1786
 	if (!empty($vars))
1695 1787
 	{
1696 1788
 		$settingsArray[$i++] = '';
1697
-		foreach ($vars as $var => $val)
1698
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1789
+		foreach ($vars as $var => $val) {
1790
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1791
+		}
1699 1792
 	}
1700 1793
 
1701 1794
 	// Blank out the file - done to fix a oddity with some servers.
1702 1795
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1703
-	if (!$fp)
1704
-		return false;
1796
+	if (!$fp) {
1797
+			return false;
1798
+	}
1705 1799
 	fclose($fp);
1706 1800
 
1707 1801
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1708 1802
 
1709 1803
 	// Gotta have one of these ;)
1710
-	if (trim($settingsArray[0]) != '<?php')
1711
-		fwrite($fp, "<?php\n");
1804
+	if (trim($settingsArray[0]) != '<?php') {
1805
+			fwrite($fp, "<?php\n");
1806
+	}
1712 1807
 
1713 1808
 	$lines = count($settingsArray);
1714 1809
 	for ($i = 0; $i < $lines - 1; $i++)
1715 1810
 	{
1716 1811
 		// Don't just write a bunch of blank lines.
1717
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1718
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1812
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1813
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1814
+		}
1719 1815
 	}
1720 1816
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1721 1817
 	fclose($fp);
1722 1818
 
1723 1819
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1724 1820
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1725
-	if (function_exists('opcache_invalidate'))
1726
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1821
+	if (function_exists('opcache_invalidate')) {
1822
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1823
+	}
1727 1824
 
1728 1825
 	return true;
1729 1826
 }
@@ -1748,9 +1845,9 @@  discard block
 block discarded – undo
1748 1845
 	SecFilterScanPOST Off
1749 1846
 </IfModule>';
1750 1847
 
1751
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1752
-		return true;
1753
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1848
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1849
+			return true;
1850
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1754 1851
 	{
1755 1852
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1756 1853
 
@@ -1762,29 +1859,28 @@  discard block
 block discarded – undo
1762 1859
 				fwrite($ht_handle, $htaccess_addition);
1763 1860
 				fclose($ht_handle);
1764 1861
 				return true;
1862
+			} else {
1863
+							return false;
1765 1864
 			}
1766
-			else
1767
-				return false;
1865
+		} else {
1866
+					return true;
1768 1867
 		}
1769
-		else
1770
-			return true;
1771
-	}
1772
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1773
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1774
-	elseif (is_writable(dirname(__FILE__)))
1868
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1869
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1870
+	} elseif (is_writable(dirname(__FILE__)))
1775 1871
 	{
1776 1872
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1777 1873
 		{
1778 1874
 			fwrite($ht_handle, $htaccess_addition);
1779 1875
 			fclose($ht_handle);
1780 1876
 			return true;
1877
+		} else {
1878
+					return false;
1781 1879
 		}
1782
-		else
1880
+	} else {
1783 1881
 			return false;
1784 1882
 	}
1785
-	else
1786
-		return false;
1787
-}
1883
+	}
1788 1884
 
1789 1885
 function template_install_above()
1790 1886
 {
@@ -1822,9 +1918,10 @@  discard block
 block discarded – undo
1822 1918
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1823 1919
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1824 1920
 
1825
-		foreach ($incontext['detected_languages'] as $lang => $name)
1826
-			echo '
1921
+		foreach ($incontext['detected_languages'] as $lang => $name) {
1922
+					echo '
1827 1923
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
1924
+		}
1828 1925
 
1829 1926
 		echo '
1830 1927
 								</select>
@@ -1844,9 +1941,10 @@  discard block
 block discarded – undo
1844 1941
 						<h2>', $txt['upgrade_progress'], '</h2>
1845 1942
 						<ul>';
1846 1943
 
1847
-	foreach ($incontext['steps'] as $num => $step)
1848
-		echo '
1944
+	foreach ($incontext['steps'] as $num => $step) {
1945
+			echo '
1849 1946
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
1947
+	}
1850 1948
 
1851 1949
 	echo '
1852 1950
 						</ul>
@@ -1871,20 +1969,23 @@  discard block
 block discarded – undo
1871 1969
 		echo '
1872 1970
 								<div>';
1873 1971
 
1874
-		if (!empty($incontext['continue']))
1875
-			echo '
1972
+		if (!empty($incontext['continue'])) {
1973
+					echo '
1876 1974
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1877
-		if (!empty($incontext['skip']))
1878
-			echo '
1975
+		}
1976
+		if (!empty($incontext['skip'])) {
1977
+					echo '
1879 1978
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1979
+		}
1880 1980
 		echo '
1881 1981
 								</div>';
1882 1982
 	}
1883 1983
 
1884 1984
 	// Show the closing form tag and other data only if not in the last step
1885
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1886
-		echo '
1985
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
1986
+			echo '
1887 1987
 							</form>';
1988
+	}
1888 1989
 
1889 1990
 	echo '
1890 1991
 						</div>
@@ -1919,13 +2020,15 @@  discard block
 block discarded – undo
1919 2020
 		</div>';
1920 2021
 
1921 2022
 	// Show the warnings, or not.
1922
-	if (template_warning_divs())
1923
-		echo '
2023
+	if (template_warning_divs()) {
2024
+			echo '
1924 2025
 		<h3>', $txt['install_all_lovely'], '</h3>';
2026
+	}
1925 2027
 
1926 2028
 	// Say we want the continue button!
1927
-	if (empty($incontext['error']))
1928
-		$incontext['continue'] = 1;
2029
+	if (empty($incontext['error'])) {
2030
+			$incontext['continue'] = 1;
2031
+	}
1929 2032
 
1930 2033
 	// For the latest version stuff.
1931 2034
 	echo '
@@ -1959,8 +2062,8 @@  discard block
 block discarded – undo
1959 2062
 	global $txt, $incontext;
1960 2063
 
1961 2064
 	// Errors are very serious..
1962
-	if (!empty($incontext['error']))
1963
-		echo '
2065
+	if (!empty($incontext['error'])) {
2066
+			echo '
1964 2067
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1965 2068
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1966 2069
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -1968,9 +2071,10 @@  discard block
 block discarded – undo
1968 2071
 				', $incontext['error'], '
1969 2072
 			</div>
1970 2073
 		</div>';
2074
+	}
1971 2075
 	// A warning message?
1972
-	elseif (!empty($incontext['warning']))
1973
-		echo '
2076
+	elseif (!empty($incontext['warning'])) {
2077
+			echo '
1974 2078
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1975 2079
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1976 2080
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -1978,6 +2082,7 @@  discard block
 block discarded – undo
1978 2082
 				', $incontext['warning'], '
1979 2083
 			</div>
1980 2084
 		</div>';
2085
+	}
1981 2086
 
1982 2087
 	return empty($incontext['error']) && empty($incontext['warning']);
1983 2088
 }
@@ -1993,27 +2098,30 @@  discard block
 block discarded – undo
1993 2098
 			<li>', $incontext['failed_files']), '</li>
1994 2099
 		</ul>';
1995 2100
 
1996
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
1997
-		echo '
2101
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2102
+			echo '
1998 2103
 		<hr>
1999 2104
 		<p>', $txt['chmod_linux_info'], '</p>
2000 2105
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2106
+	}
2001 2107
 
2002 2108
 	// This is serious!
2003
-	if (!template_warning_divs())
2004
-		return;
2109
+	if (!template_warning_divs()) {
2110
+			return;
2111
+	}
2005 2112
 
2006 2113
 	echo '
2007 2114
 		<hr>
2008 2115
 		<p>', $txt['ftp_setup_info'], '</p>';
2009 2116
 
2010
-	if (!empty($incontext['ftp_errors']))
2011
-		echo '
2117
+	if (!empty($incontext['ftp_errors'])) {
2118
+			echo '
2012 2119
 		<div class="error_message">
2013 2120
 			', $txt['error_ftp_no_connect'], '<br><br>
2014 2121
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2015 2122
 		</div>
2016 2123
 		<br>';
2124
+	}
2017 2125
 
2018 2126
 	echo '
2019 2127
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2073,17 +2181,17 @@  discard block
 block discarded – undo
2073 2181
 				<td>
2074 2182
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2075 2183
 
2076
-	foreach ($incontext['supported_databases'] as $key => $db)
2077
-			echo '
2184
+	foreach ($incontext['supported_databases'] as $key => $db) {
2185
+				echo '
2078 2186
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2187
+	}
2079 2188
 
2080 2189
 	echo '
2081 2190
 					</select>
2082 2191
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2083 2192
 				</td>
2084 2193
 			</tr>';
2085
-	}
2086
-	else
2194
+	} else
2087 2195
 	{
2088 2196
 		echo '
2089 2197
 			<tr style="display: none;">
@@ -2275,9 +2383,10 @@  discard block
 block discarded – undo
2275 2383
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2276 2384
 				<ul>';
2277 2385
 
2278
-		foreach ($incontext['failures'] as $line => $fail)
2279
-			echo '
2386
+		foreach ($incontext['failures'] as $line => $fail) {
2387
+					echo '
2280 2388
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2389
+		}
2281 2390
 
2282 2391
 		echo '
2283 2392
 				</ul>';
@@ -2338,15 +2447,16 @@  discard block
 block discarded – undo
2338 2447
 			</tr>
2339 2448
 		</table>';
2340 2449
 
2341
-	if ($incontext['require_db_confirm'])
2342
-		echo '
2450
+	if ($incontext['require_db_confirm']) {
2451
+			echo '
2343 2452
 		<h2>', $txt['user_settings_database'], '</h2>
2344 2453
 		<p>', $txt['user_settings_database_info'], '</p>
2345 2454
 
2346 2455
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2347 2456
 			<input type="password" name="password3" size="30" class="input_password" />
2348 2457
 		</div>';
2349
-}
2458
+	}
2459
+	}
2350 2460
 
2351 2461
 // Tell them it's done, and to delete.
2352 2462
 function template_delete_install()
@@ -2359,14 +2469,15 @@  discard block
 block discarded – undo
2359 2469
 	template_warning_divs();
2360 2470
 
2361 2471
 	// Install directory still writable?
2362
-	if ($incontext['dir_still_writable'])
2363
-		echo '
2472
+	if ($incontext['dir_still_writable']) {
2473
+			echo '
2364 2474
 		<em>', $txt['still_writable'], '</em><br>
2365 2475
 		<br>';
2476
+	}
2366 2477
 
2367 2478
 	// Don't show the box if it's like 99% sure it won't work :P.
2368
-	if ($incontext['probably_delete_install'])
2369
-		echo '
2479
+	if ($incontext['probably_delete_install']) {
2480
+			echo '
2370 2481
 		<div style="margin: 1ex; font-weight: bold;">
2371 2482
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" class="input_check" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
2372 2483
 		</div>
@@ -2382,6 +2493,7 @@  discard block
 block discarded – undo
2382 2493
 			}
2383 2494
 		</script>
2384 2495
 		<br>';
2496
+	}
2385 2497
 
2386 2498
 	echo '
2387 2499
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +870 added lines, -637 removed lines patch added patch discarded remove patch
@@ -75,8 +75,9 @@  discard block
 block discarded – undo
75 75
 $upcontext['inactive_timeout'] = 10;
76 76
 
77 77
 // The helper is crucial. Include it first thing.
78
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
78
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
79 79
     die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
80
+}
80 81
 
81 82
 require_once($upgrade_path . '/upgrade-helper.php');
82 83
 
@@ -100,11 +101,14 @@  discard block
 block discarded – undo
100 101
 	ini_set('default_socket_timeout', 900);
101 102
 }
102 103
 // Clean the upgrade path if this is from the client.
103
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
104
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
104
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
105
+	for ($i = 1;
106
+}
107
+$i < $_SERVER['argc']; $i++)
105 108
 	{
106
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
107
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
109
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
110
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
111
+		}
108 112
 	}
109 113
 
110 114
 // Are we from the client?
@@ -112,16 +116,17 @@  discard block
 block discarded – undo
112 116
 {
113 117
 	$command_line = true;
114 118
 	$disable_security = true;
115
-}
116
-else
119
+} else {
117 120
 	$command_line = false;
121
+}
118 122
 
119 123
 // Load this now just because we can.
120 124
 require_once($upgrade_path . '/Settings.php');
121 125
 
122 126
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
123
-if (isset($language))
127
+if (isset($language)) {
124 128
 	$language = str_ireplace('-utf8', '', $language);
129
+}
125 130
 
126 131
 // Are we logged in?
127 132
 if (isset($upgradeData))
@@ -129,10 +134,12 @@  discard block
 block discarded – undo
129 134
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
130 135
 
131 136
 	// Check for sensible values.
132
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
133
-		$upcontext['user']['started'] = time();
134
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
135
-		$upcontext['user']['updated'] = 0;
137
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
138
+			$upcontext['user']['started'] = time();
139
+	}
140
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
141
+			$upcontext['user']['updated'] = 0;
142
+	}
136 143
 
137 144
 	$upcontext['started'] = $upcontext['user']['started'];
138 145
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -190,8 +197,9 @@  discard block
 block discarded – undo
190 197
 			'db_error_skip' => true,
191 198
 		)
192 199
 	);
193
-	while ($row = $smcFunc['db_fetch_assoc']($request))
194
-		$modSettings[$row['variable']] = $row['value'];
200
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
201
+			$modSettings[$row['variable']] = $row['value'];
202
+	}
195 203
 	$smcFunc['db_free_result']($request);
196 204
 }
197 205
 
@@ -201,10 +209,12 @@  discard block
 block discarded – undo
201 209
 	$modSettings['theme_url'] = 'Themes/default';
202 210
 	$modSettings['images_url'] = 'Themes/default/images';
203 211
 }
204
-if (!isset($settings['default_theme_url']))
212
+if (!isset($settings['default_theme_url'])) {
205 213
 	$settings['default_theme_url'] = $modSettings['theme_url'];
206
-if (!isset($settings['default_theme_dir']))
214
+}
215
+if (!isset($settings['default_theme_dir'])) {
207 216
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
217
+}
208 218
 
209 219
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
210 220
 // Default title...
@@ -222,13 +232,15 @@  discard block
 block discarded – undo
222 232
 	$support_js = $upcontext['upgrade_status']['js'];
223 233
 
224 234
 	// Only set this if the upgrader status says so.
225
-	if (empty($is_debug))
226
-		$is_debug = $upcontext['upgrade_status']['debug'];
235
+	if (empty($is_debug)) {
236
+			$is_debug = $upcontext['upgrade_status']['debug'];
237
+	}
227 238
 
228 239
 	// Load the language.
229
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
230
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
231
-}
240
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
241
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
242
+	}
243
+	}
232 244
 // Set the defaults.
233 245
 else
234 246
 {
@@ -246,15 +258,18 @@  discard block
 block discarded – undo
246 258
 }
247 259
 
248 260
 // If this isn't the first stage see whether they are logging in and resuming.
249
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
261
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
250 262
 	checkLogin();
263
+}
251 264
 
252
-if ($command_line)
265
+if ($command_line) {
253 266
 	cmdStep0();
267
+}
254 268
 
255 269
 // Don't error if we're using xml.
256
-if (isset($_GET['xml']))
270
+if (isset($_GET['xml'])) {
257 271
 	$upcontext['return_error'] = true;
272
+}
258 273
 
259 274
 // Loop through all the steps doing each one as required.
260 275
 $upcontext['overall_percent'] = 0;
@@ -275,10 +290,11 @@  discard block
 block discarded – undo
275 290
 		}
276 291
 
277 292
 		// Call the step and if it returns false that means pause!
278
-		if (function_exists($step[2]) && $step[2]() === false)
279
-			break;
280
-		elseif (function_exists($step[2]))
281
-			$upcontext['current_step']++;
293
+		if (function_exists($step[2]) && $step[2]() === false) {
294
+					break;
295
+		} elseif (function_exists($step[2])) {
296
+					$upcontext['current_step']++;
297
+		}
282 298
 	}
283 299
 	$upcontext['overall_percent'] += $step[3];
284 300
 }
@@ -317,17 +333,18 @@  discard block
 block discarded – undo
317 333
 		// This should not happen my dear... HELP ME DEVELOPERS!!
318 334
 		if (!empty($command_line))
319 335
 		{
320
-			if (function_exists('debug_print_backtrace'))
321
-				debug_print_backtrace();
336
+			if (function_exists('debug_print_backtrace')) {
337
+							debug_print_backtrace();
338
+			}
322 339
 
323 340
 			echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
324 341
 			flush();
325 342
 			die();
326 343
 		}
327 344
 
328
-		if (!isset($_GET['xml']))
329
-			template_upgrade_above();
330
-		else
345
+		if (!isset($_GET['xml'])) {
346
+					template_upgrade_above();
347
+		} else
331 348
 		{
332 349
 			header('Content-Type: text/xml; charset=UTF-8');
333 350
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -349,21 +366,24 @@  discard block
 block discarded – undo
349 366
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
350 367
 
351 368
 			// Custom stuff to pass back?
352
-			if (!empty($upcontext['query_string']))
353
-				$upcontext['form_url'] .= $upcontext['query_string'];
369
+			if (!empty($upcontext['query_string'])) {
370
+							$upcontext['form_url'] .= $upcontext['query_string'];
371
+			}
354 372
 
355 373
 			call_user_func('template_' . $upcontext['sub_template']);
356 374
 		}
357 375
 
358 376
 		// Was there an error?
359
-		if (!empty($upcontext['forced_error_message']))
360
-			echo $upcontext['forced_error_message'];
377
+		if (!empty($upcontext['forced_error_message'])) {
378
+					echo $upcontext['forced_error_message'];
379
+		}
361 380
 
362 381
 		// Show the footer.
363
-		if (!isset($_GET['xml']))
364
-			template_upgrade_below();
365
-		else
366
-			template_xml_below();
382
+		if (!isset($_GET['xml'])) {
383
+					template_upgrade_below();
384
+		} else {
385
+					template_xml_below();
386
+		}
367 387
 	}
368 388
 
369 389
 
@@ -375,15 +395,19 @@  discard block
 block discarded – undo
375 395
 		$seconds = intval($active % 60);
376 396
 
377 397
 		$totalTime = '';
378
-		if ($hours > 0)
379
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
380
-		if ($minutes > 0)
381
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
382
-		if ($seconds > 0)
383
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
398
+		if ($hours > 0) {
399
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
400
+		}
401
+		if ($minutes > 0) {
402
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
403
+		}
404
+		if ($seconds > 0) {
405
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
406
+		}
384 407
 
385
-		if (!empty($totalTime))
386
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
408
+		if (!empty($totalTime)) {
409
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
410
+		}
387 411
 	}
388 412
 
389 413
 	// Bang - gone!
@@ -396,8 +420,9 @@  discard block
 block discarded – undo
396 420
 	global $upgradeurl, $upcontext, $command_line;
397 421
 
398 422
 	// Command line users can't be redirected.
399
-	if ($command_line)
400
-		upgradeExit(true);
423
+	if ($command_line) {
424
+			upgradeExit(true);
425
+	}
401 426
 
402 427
 	// Are we providing the core info?
403 428
 	if ($addForm)
@@ -420,19 +445,22 @@  discard block
 block discarded – undo
420 445
 	global $modSettings, $sourcedir, $smcFunc;
421 446
 
422 447
 	// Do the non-SSI stuff...
423
-	if (function_exists('set_magic_quotes_runtime'))
424
-		@set_magic_quotes_runtime(0);
448
+	if (function_exists('set_magic_quotes_runtime')) {
449
+			@set_magic_quotes_runtime(0);
450
+	}
425 451
 
426 452
 	error_reporting(E_ALL);
427 453
 	define('SMF', 1);
428 454
 
429 455
 	// Start the session.
430
-	if (@ini_get('session.save_handler') == 'user')
431
-		@ini_set('session.save_handler', 'files');
456
+	if (@ini_get('session.save_handler') == 'user') {
457
+			@ini_set('session.save_handler', 'files');
458
+	}
432 459
 	@session_start();
433 460
 
434
-	if (empty($smcFunc))
435
-		$smcFunc = array();
461
+	if (empty($smcFunc)) {
462
+			$smcFunc = array();
463
+	}
436 464
 
437 465
 	// We need this for authentication and some upgrade code
438 466
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -444,8 +472,9 @@  discard block
 block discarded – undo
444 472
 	initialize_inputs();
445 473
 
446 474
 	// Get the database going!
447
-	if (empty($db_type) || $db_type == 'mysqli')
448
-		$db_type = 'mysql';
475
+	if (empty($db_type) || $db_type == 'mysqli') {
476
+			$db_type = 'mysql';
477
+	}
449 478
 
450 479
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
451 480
 	{
@@ -455,17 +484,19 @@  discard block
 block discarded – undo
455 484
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
456 485
 
457 486
 		// Oh dear god!!
458
-		if ($db_connection === null)
459
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
487
+		if ($db_connection === null) {
488
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
489
+		}
460 490
 
461
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
462
-			$smcFunc['db_query']('', '
491
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
492
+					$smcFunc['db_query']('', '
463 493
 			SET NAMES {string:db_character_set}',
464 494
 			array(
465 495
 				'db_error_skip' => true,
466 496
 				'db_character_set' => $db_character_set,
467 497
 			)
468 498
 		);
499
+		}
469 500
 
470 501
 		// Load the modSettings data...
471 502
 		$request = $smcFunc['db_query']('', '
@@ -476,11 +507,11 @@  discard block
 block discarded – undo
476 507
 			)
477 508
 		);
478 509
 		$modSettings = array();
479
-		while ($row = $smcFunc['db_fetch_assoc']($request))
480
-			$modSettings[$row['variable']] = $row['value'];
510
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
511
+					$modSettings[$row['variable']] = $row['value'];
512
+		}
481 513
 		$smcFunc['db_free_result']($request);
482
-	}
483
-	else
514
+	} else
484 515
 	{
485 516
 		return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.');
486 517
 	}
@@ -494,9 +525,10 @@  discard block
 block discarded – undo
494 525
 		cleanRequest();
495 526
 	}
496 527
 
497
-	if (!isset($_GET['substep']))
498
-		$_GET['substep'] = 0;
499
-}
528
+	if (!isset($_GET['substep'])) {
529
+			$_GET['substep'] = 0;
530
+	}
531
+	}
500 532
 
501 533
 function initialize_inputs()
502 534
 {
@@ -526,8 +558,9 @@  discard block
 block discarded – undo
526 558
 		$dh = opendir(dirname(__FILE__));
527 559
 		while ($file = readdir($dh))
528 560
 		{
529
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
530
-				@unlink(dirname(__FILE__) . '/' . $file);
561
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
562
+							@unlink(dirname(__FILE__) . '/' . $file);
563
+			}
531 564
 		}
532 565
 		closedir($dh);
533 566
 
@@ -556,8 +589,9 @@  discard block
 block discarded – undo
556 589
 	$temp = 'upgrade_php?step';
557 590
 	while (strlen($temp) > 4)
558 591
 	{
559
-		if (isset($_GET[$temp]))
560
-			unset($_GET[$temp]);
592
+		if (isset($_GET[$temp])) {
593
+					unset($_GET[$temp]);
594
+		}
561 595
 		$temp = substr($temp, 1);
562 596
 	}
563 597
 
@@ -584,32 +618,39 @@  discard block
 block discarded – undo
584 618
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
585 619
 
586 620
 	// Need legacy scripts?
587
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
588
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
589
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
590
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
591
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
592
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
621
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
622
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
623
+	}
624
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
625
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
626
+	}
627
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
628
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
629
+	}
593 630
 
594 631
 	// We don't need "-utf8" files anymore...
595 632
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
596 633
 
597 634
 	// This needs to exist!
598
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
599
-		return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
600
-	else
601
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
635
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
636
+			return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
637
+	} else {
638
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
639
+	}
602 640
 
603
-	if (!$check)
604
-		// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
641
+	if (!$check) {
642
+			// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
605 643
 		return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.');
644
+	}
606 645
 
607 646
 	// Do they meet the install requirements?
608
-	if (!php_version_check())
609
-		return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
647
+	if (!php_version_check()) {
648
+			return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
649
+	}
610 650
 
611
-	if (!db_version_check())
612
-		return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
651
+	if (!db_version_check()) {
652
+			return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
653
+	}
613 654
 
614 655
 	// Do some checks to make sure they have proper privileges
615 656
 	db_extend('packages');
@@ -624,14 +665,16 @@  discard block
 block discarded – undo
624 665
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
625 666
 
626 667
 	// Sorry... we need CREATE, ALTER and DROP
627
-	if (!$create || !$alter || !$drop)
628
-		return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
668
+	if (!$create || !$alter || !$drop) {
669
+			return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
670
+	}
629 671
 
630 672
 	// Do a quick version spot check.
631 673
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
632 674
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
633
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
634
-		return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
675
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
676
+			return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
677
+	}
635 678
 
636 679
 	// What absolutely needs to be writable?
637 680
 	$writable_files = array(
@@ -653,12 +696,13 @@  discard block
 block discarded – undo
653 696
 	quickFileWritable($custom_av_dir);
654 697
 
655 698
 	// Are we good now?
656
-	if (!is_writable($custom_av_dir))
657
-		return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
658
-	elseif ($need_settings_update)
699
+	if (!is_writable($custom_av_dir)) {
700
+			return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
701
+	} elseif ($need_settings_update)
659 702
 	{
660
-		if (!function_exists('cache_put_data'))
661
-			require_once($sourcedir . '/Load.php');
703
+		if (!function_exists('cache_put_data')) {
704
+					require_once($sourcedir . '/Load.php');
705
+		}
662 706
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
663 707
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
664 708
 	}
@@ -667,28 +711,33 @@  discard block
 block discarded – undo
667 711
 
668 712
 	// Check the cache directory.
669 713
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
670
-	if (!file_exists($cachedir_temp))
671
-		@mkdir($cachedir_temp);
672
-	if (!file_exists($cachedir_temp))
673
-		return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
674
-
675
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
676
-		return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
677
-	elseif (!isset($_GET['skiplang']))
714
+	if (!file_exists($cachedir_temp)) {
715
+			@mkdir($cachedir_temp);
716
+	}
717
+	if (!file_exists($cachedir_temp)) {
718
+			return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
719
+	}
720
+
721
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
722
+			return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
723
+	} elseif (!isset($_GET['skiplang']))
678 724
 	{
679 725
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
680 726
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
681 727
 
682
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
683
-			return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
728
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
729
+					return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
730
+		}
684 731
 	}
685 732
 
686
-	if (!makeFilesWritable($writable_files))
687
-		return false;
733
+	if (!makeFilesWritable($writable_files)) {
734
+			return false;
735
+	}
688 736
 
689 737
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
690
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
691
-		return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
738
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
739
+			return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
740
+	}
692 741
 
693 742
 	// Upgrade the agreement.
694 743
 	elseif (isset($modSettings['agreement']))
@@ -699,8 +748,8 @@  discard block
 block discarded – undo
699 748
 	}
700 749
 
701 750
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
702
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
703
-		$upcontext['warning'] = '
751
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
752
+			$upcontext['warning'] = '
704 753
 			It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to &quot;' . $boarddir . '&quot; but should probably be &quot;' . dirname(__FILE__) . '&quot;. Settings.php currently lists your paths as:<br>
705 754
 			<ul>
706 755
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -708,10 +757,12 @@  discard block
 block discarded – undo
708 757
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
709 758
 			</ul>
710 759
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
760
+	}
711 761
 
712 762
 	// Either we're logged in or we're going to present the login.
713
-	if (checkLogin())
714
-		return true;
763
+	if (checkLogin()) {
764
+			return true;
765
+	}
715 766
 
716 767
 	$upcontext += createToken('login');
717 768
 
@@ -725,15 +776,17 @@  discard block
 block discarded – undo
725 776
 	global $smcFunc, $db_type, $support_js;
726 777
 
727 778
 	// Don't bother if the security is disabled.
728
-	if ($disable_security)
729
-		return true;
779
+	if ($disable_security) {
780
+			return true;
781
+	}
730 782
 
731 783
 	// Are we trying to login?
732 784
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
733 785
 	{
734 786
 		// If we've disabled security pick a suitable name!
735
-		if (empty($_POST['user']))
736
-			$_POST['user'] = 'Administrator';
787
+		if (empty($_POST['user'])) {
788
+					$_POST['user'] = 'Administrator';
789
+		}
737 790
 
738 791
 		// Before 2.0 these column names were different!
739 792
 		$oldDB = false;
@@ -748,16 +801,17 @@  discard block
 block discarded – undo
748 801
 					'db_error_skip' => true,
749 802
 				)
750 803
 			);
751
-			if ($smcFunc['db_num_rows']($request) != 0)
752
-				$oldDB = true;
804
+			if ($smcFunc['db_num_rows']($request) != 0) {
805
+							$oldDB = true;
806
+			}
753 807
 			$smcFunc['db_free_result']($request);
754 808
 		}
755 809
 
756 810
 		// Get what we believe to be their details.
757 811
 		if (!$disable_security)
758 812
 		{
759
-			if ($oldDB)
760
-				$request = $smcFunc['db_query']('', '
813
+			if ($oldDB) {
814
+							$request = $smcFunc['db_query']('', '
761 815
 					SELECT id_member, memberName AS member_name, passwd, id_group,
762 816
 					additionalGroups AS additional_groups, lngfile
763 817
 					FROM {db_prefix}members
@@ -767,8 +821,8 @@  discard block
 block discarded – undo
767 821
 						'db_error_skip' => true,
768 822
 					)
769 823
 				);
770
-			else
771
-				$request = $smcFunc['db_query']('', '
824
+			} else {
825
+							$request = $smcFunc['db_query']('', '
772 826
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
773 827
 					FROM {db_prefix}members
774 828
 					WHERE member_name = {string:member_name}',
@@ -777,6 +831,7 @@  discard block
 block discarded – undo
777 831
 						'db_error_skip' => true,
778 832
 					)
779 833
 				);
834
+			}
780 835
 			if ($smcFunc['db_num_rows']($request) != 0)
781 836
 			{
782 837
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -784,16 +839,17 @@  discard block
 block discarded – undo
784 839
 				$groups = explode(',', $addGroups);
785 840
 				$groups[] = $id_group;
786 841
 
787
-				foreach ($groups as $k => $v)
788
-					$groups[$k] = (int) $v;
842
+				foreach ($groups as $k => $v) {
843
+									$groups[$k] = (int) $v;
844
+				}
789 845
 
790 846
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
791 847
 
792 848
 				// We don't use "-utf8" anymore...
793 849
 				$user_language = str_ireplace('-utf8', '', $user_language);
850
+			} else {
851
+							$upcontext['username_incorrect'] = true;
794 852
 			}
795
-			else
796
-				$upcontext['username_incorrect'] = true;
797 853
 			$smcFunc['db_free_result']($request);
798 854
 		}
799 855
 		$upcontext['username'] = $_POST['user'];
@@ -803,13 +859,14 @@  discard block
 block discarded – undo
803 859
 		{
804 860
 			$upcontext['upgrade_status']['js'] = 1;
805 861
 			$support_js = 1;
862
+		} else {
863
+					$support_js = 0;
806 864
 		}
807
-		else
808
-			$support_js = 0;
809 865
 
810 866
 		// Note down the version we are coming from.
811
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
812
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
867
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
868
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
869
+		}
813 870
 
814 871
 		// Didn't get anywhere?
815 872
 		if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect']))
@@ -843,15 +900,15 @@  discard block
 block discarded – undo
843 900
 							'db_error_skip' => true,
844 901
 						)
845 902
 					);
846
-					if ($smcFunc['db_num_rows']($request) == 0)
847
-						return throw_error('You need to be an admin to perform an upgrade!');
903
+					if ($smcFunc['db_num_rows']($request) == 0) {
904
+											return throw_error('You need to be an admin to perform an upgrade!');
905
+					}
848 906
 					$smcFunc['db_free_result']($request);
849 907
 				}
850 908
 
851 909
 				$upcontext['user']['id'] = $id_member;
852 910
 				$upcontext['user']['name'] = $name;
853
-			}
854
-			else
911
+			} else
855 912
 			{
856 913
 				$upcontext['user']['id'] = 1;
857 914
 				$upcontext['user']['name'] = 'Administrator';
@@ -867,11 +924,11 @@  discard block
 block discarded – undo
867 924
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
868 925
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
869 926
 
870
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
871
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
872
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
873
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
874
-				else
927
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
928
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
929
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
930
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
931
+				} else
875 932
 				{
876 933
 					// Set this as the new language.
877 934
 					$upcontext['language'] = $user_language;
@@ -915,8 +972,9 @@  discard block
 block discarded – undo
915 972
 	unset($member_columns);
916 973
 
917 974
 	// If we've not submitted then we're done.
918
-	if (empty($_POST['upcont']))
919
-		return false;
975
+	if (empty($_POST['upcont'])) {
976
+			return false;
977
+	}
920 978
 
921 979
 	// Firstly, if they're enabling SM stat collection just do it.
922 980
 	if (!empty($_POST['stats']) && (substr($boardurl, 0, 16) != 'http://localhost' || substr($boardurl, 0, 16) != 'https://localhost') && empty($modSettings['allow_sm_stats']))
@@ -931,25 +989,26 @@  discard block
 block discarded – undo
931 989
 			fwrite($fp, $out);
932 990
 
933 991
 			$return_data = '';
934
-			while (!feof($fp))
935
-				$return_data .= fgets($fp, 128);
992
+			while (!feof($fp)) {
993
+							$return_data .= fgets($fp, 128);
994
+			}
936 995
 
937 996
 			fclose($fp);
938 997
 
939 998
 			// Get the unique site ID.
940 999
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
941 1000
 
942
-			if (!empty($ID[1]))
943
-				$smcFunc['db_insert']('replace',
1001
+			if (!empty($ID[1])) {
1002
+							$smcFunc['db_insert']('replace',
944 1003
 					$db_prefix . 'settings',
945 1004
 					array('variable' => 'string', 'value' => 'string'),
946 1005
 					array('allow_sm_stats', $ID[1]),
947 1006
 					array('variable')
948 1007
 				);
1008
+			}
949 1009
 		}
950
-	}
951
-	else
952
-		$smcFunc['db_query']('', '
1010
+	} else {
1011
+			$smcFunc['db_query']('', '
953 1012
 			DELETE FROM {db_prefix}settings
954 1013
 			WHERE variable = {string:allow_sm_stats}',
955 1014
 			array(
@@ -957,6 +1016,7 @@  discard block
 block discarded – undo
957 1016
 				'db_error_skip' => true,
958 1017
 			)
959 1018
 		);
1019
+	}
960 1020
 
961 1021
 	// Deleting old karma stuff?
962 1022
 	if (!empty($_POST['delete_karma']))
@@ -971,20 +1031,22 @@  discard block
 block discarded – undo
971 1031
 		);
972 1032
 
973 1033
 		// Cleaning up old karma member settings.
974
-		if ($upcontext['karma_installed']['good'])
975
-			$smcFunc['db_query']('', '
1034
+		if ($upcontext['karma_installed']['good']) {
1035
+					$smcFunc['db_query']('', '
976 1036
 				ALTER TABLE {db_prefix}members
977 1037
 				DROP karma_good',
978 1038
 				array()
979 1039
 			);
1040
+		}
980 1041
 
981 1042
 		// Does karma bad was enable?
982
-		if ($upcontext['karma_installed']['bad'])
983
-			$smcFunc['db_query']('', '
1043
+		if ($upcontext['karma_installed']['bad']) {
1044
+					$smcFunc['db_query']('', '
984 1045
 				ALTER TABLE {db_prefix}members
985 1046
 				DROP karma_bad',
986 1047
 				array()
987 1048
 			);
1049
+		}
988 1050
 
989 1051
 		// Cleaning up old karma permissions.
990 1052
 		$smcFunc['db_query']('', '
@@ -997,26 +1059,29 @@  discard block
 block discarded – undo
997 1059
 	}
998 1060
 
999 1061
 	// Emptying the error log?
1000
-	if (!empty($_POST['empty_error']))
1001
-		$smcFunc['db_query']('truncate_table', '
1062
+	if (!empty($_POST['empty_error'])) {
1063
+			$smcFunc['db_query']('truncate_table', '
1002 1064
 			TRUNCATE {db_prefix}log_errors',
1003 1065
 			array(
1004 1066
 			)
1005 1067
 		);
1068
+	}
1006 1069
 
1007 1070
 	$changes = array();
1008 1071
 
1009 1072
 	// Add proxy settings.
1010
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1011
-		$changes += array(
1073
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1074
+			$changes += array(
1012 1075
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1013 1076
 			'image_proxy_maxsize' => 5190,
1014 1077
 			'image_proxy_enabled' => 0,
1015 1078
 		);
1079
+	}
1016 1080
 
1017 1081
 	// If we're overriding the language follow it through.
1018
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1019
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1082
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1083
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1084
+	}
1020 1085
 
1021 1086
 	if (!empty($_POST['maint']))
1022 1087
 	{
@@ -1028,30 +1093,34 @@  discard block
 block discarded – undo
1028 1093
 		{
1029 1094
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1030 1095
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1031
-		}
1032
-		else
1096
+		} else
1033 1097
 		{
1034 1098
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1035 1099
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1036 1100
 		}
1037 1101
 	}
1038 1102
 
1039
-	if ($command_line)
1040
-		echo ' * Updating Settings.php...';
1103
+	if ($command_line) {
1104
+			echo ' * Updating Settings.php...';
1105
+	}
1041 1106
 
1042 1107
 	// Fix some old paths.
1043
-	if (substr($boarddir, 0, 1) == '.')
1044
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1108
+	if (substr($boarddir, 0, 1) == '.') {
1109
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1110
+	}
1045 1111
 
1046
-	if (substr($sourcedir, 0, 1) == '.')
1047
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1112
+	if (substr($sourcedir, 0, 1) == '.') {
1113
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1114
+	}
1048 1115
 
1049
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1050
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1116
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1117
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1118
+	}
1051 1119
 
1052 1120
 	// Not had the database type added before?
1053
-	if (empty($db_type))
1054
-		$changes['db_type'] = 'mysql';
1121
+	if (empty($db_type)) {
1122
+			$changes['db_type'] = 'mysql';
1123
+	}
1055 1124
 
1056 1125
 	// If they have a "host:port" setup for the host, split that into separate values
1057 1126
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1062,32 +1131,36 @@  discard block
 block discarded – undo
1062 1131
 		$changes['db_server'] = '\'' . $db_server . '\'';
1063 1132
 
1064 1133
 		// Only set this if we're not using the default port
1065
-		if ($db_port != ini_get('mysqli.default_port'))
1066
-			$changes['db_port'] = (int) $db_port;
1067
-	}
1068
-	elseif (!empty($db_port))
1134
+		if ($db_port != ini_get('mysqli.default_port')) {
1135
+					$changes['db_port'] = (int) $db_port;
1136
+		}
1137
+	} elseif (!empty($db_port))
1069 1138
 	{
1070 1139
 		// If db_port is set and is the same as the default, set it to ''
1071 1140
 		if ($db_type == 'mysql')
1072 1141
 		{
1073
-			if ($db_port == ini_get('mysqli.default_port'))
1074
-				$changes['db_port'] = '\'\'';
1075
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1076
-				$changes['db_port'] = '\'\'';
1142
+			if ($db_port == ini_get('mysqli.default_port')) {
1143
+							$changes['db_port'] = '\'\'';
1144
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1145
+							$changes['db_port'] = '\'\'';
1146
+			}
1077 1147
 		}
1078 1148
 	}
1079 1149
 
1080 1150
 	// Maybe we haven't had this option yet?
1081
-	if (empty($packagesdir))
1082
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1151
+	if (empty($packagesdir)) {
1152
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1153
+	}
1083 1154
 
1084 1155
 	// Add support for $tasksdir var.
1085
-	if (empty($tasksdir))
1086
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1156
+	if (empty($tasksdir)) {
1157
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1158
+	}
1087 1159
 
1088 1160
 	// Make sure we fix the language as well.
1089
-	if (stristr($language, '-utf8'))
1090
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1161
+	if (stristr($language, '-utf8')) {
1162
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1163
+	}
1091 1164
 
1092 1165
 	// @todo Maybe change the cookie name if going to 1.1, too?
1093 1166
 
@@ -1095,8 +1168,9 @@  discard block
 block discarded – undo
1095 1168
 	require_once($sourcedir . '/Subs-Admin.php');
1096 1169
 	updateSettingsFile($changes);
1097 1170
 
1098
-	if ($command_line)
1099
-		echo ' Successful.' . "\n";
1171
+	if ($command_line) {
1172
+			echo ' Successful.' . "\n";
1173
+	}
1100 1174
 
1101 1175
 	// Are we doing debug?
1102 1176
 	if (isset($_POST['debug']))
@@ -1106,8 +1180,9 @@  discard block
 block discarded – undo
1106 1180
 	}
1107 1181
 
1108 1182
 	// If we're not backing up then jump one.
1109
-	if (empty($_POST['backup']))
1110
-		$upcontext['current_step']++;
1183
+	if (empty($_POST['backup'])) {
1184
+			$upcontext['current_step']++;
1185
+	}
1111 1186
 
1112 1187
 	// If we've got here then let's proceed to the next step!
1113 1188
 	return true;
@@ -1122,8 +1197,9 @@  discard block
 block discarded – undo
1122 1197
 	$upcontext['page_title'] = 'Backup Database';
1123 1198
 
1124 1199
 	// Done it already - js wise?
1125
-	if (!empty($_POST['backup_done']))
1126
-		return true;
1200
+	if (!empty($_POST['backup_done'])) {
1201
+			return true;
1202
+	}
1127 1203
 
1128 1204
 	// Some useful stuff here.
1129 1205
 	db_extend();
@@ -1137,9 +1213,10 @@  discard block
 block discarded – undo
1137 1213
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1138 1214
 
1139 1215
 	$table_names = array();
1140
-	foreach ($tables as $table)
1141
-		if (substr($table, 0, 7) !== 'backup_')
1216
+	foreach ($tables as $table) {
1217
+			if (substr($table, 0, 7) !== 'backup_')
1142 1218
 			$table_names[] = $table;
1219
+	}
1143 1220
 
1144 1221
 	$upcontext['table_count'] = count($table_names);
1145 1222
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1149,12 +1226,14 @@  discard block
 block discarded – undo
1149 1226
 	$file_steps = $upcontext['table_count'];
1150 1227
 
1151 1228
 	// What ones have we already done?
1152
-	foreach ($table_names as $id => $table)
1153
-		if ($id < $_GET['substep'])
1229
+	foreach ($table_names as $id => $table) {
1230
+			if ($id < $_GET['substep'])
1154 1231
 			$upcontext['previous_tables'][] = $table;
1232
+	}
1155 1233
 
1156
-	if ($command_line)
1157
-		echo 'Backing Up Tables.';
1234
+	if ($command_line) {
1235
+			echo 'Backing Up Tables.';
1236
+	}
1158 1237
 
1159 1238
 	// If we don't support javascript we backup here.
1160 1239
 	if (!$support_js || isset($_GET['xml']))
@@ -1173,8 +1252,9 @@  discard block
 block discarded – undo
1173 1252
 			backupTable($table_names[$substep]);
1174 1253
 
1175 1254
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1176
-			if (isset($_GET['xml']))
1177
-				return upgradeExit();
1255
+			if (isset($_GET['xml'])) {
1256
+							return upgradeExit();
1257
+			}
1178 1258
 		}
1179 1259
 
1180 1260
 		if ($command_line)
@@ -1207,9 +1287,10 @@  discard block
 block discarded – undo
1207 1287
 
1208 1288
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1209 1289
 
1210
-	if ($command_line)
1211
-		echo ' done.';
1212
-}
1290
+	if ($command_line) {
1291
+			echo ' done.';
1292
+	}
1293
+	}
1213 1294
 
1214 1295
 // Step 2: Everything.
1215 1296
 function DatabaseChanges()
@@ -1218,8 +1299,9 @@  discard block
 block discarded – undo
1218 1299
 	global $upcontext, $support_js, $db_type;
1219 1300
 
1220 1301
 	// Have we just completed this?
1221
-	if (!empty($_POST['database_done']))
1222
-		return true;
1302
+	if (!empty($_POST['database_done'])) {
1303
+			return true;
1304
+	}
1223 1305
 
1224 1306
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1225 1307
 	$upcontext['page_title'] = 'Database Changes';
@@ -1234,15 +1316,16 @@  discard block
 block discarded – undo
1234 1316
 	);
1235 1317
 
1236 1318
 	// How many files are there in total?
1237
-	if (isset($_GET['filecount']))
1238
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1239
-	else
1319
+	if (isset($_GET['filecount'])) {
1320
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1321
+	} else
1240 1322
 	{
1241 1323
 		$upcontext['file_count'] = 0;
1242 1324
 		foreach ($files as $file)
1243 1325
 		{
1244
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1245
-				$upcontext['file_count']++;
1326
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1327
+							$upcontext['file_count']++;
1328
+			}
1246 1329
 		}
1247 1330
 	}
1248 1331
 
@@ -1252,9 +1335,9 @@  discard block
 block discarded – undo
1252 1335
 	$upcontext['cur_file_num'] = 0;
1253 1336
 	foreach ($files as $file)
1254 1337
 	{
1255
-		if ($did_not_do)
1256
-			$did_not_do--;
1257
-		else
1338
+		if ($did_not_do) {
1339
+					$did_not_do--;
1340
+		} else
1258 1341
 		{
1259 1342
 			$upcontext['cur_file_num']++;
1260 1343
 			$upcontext['cur_file_name'] = $file[0];
@@ -1281,12 +1364,13 @@  discard block
 block discarded – undo
1281 1364
 					// Flag to move on to the next.
1282 1365
 					$upcontext['completed_step'] = true;
1283 1366
 					// Did we complete the whole file?
1284
-					if ($nextFile)
1285
-						$upcontext['current_debug_item_num'] = -1;
1367
+					if ($nextFile) {
1368
+											$upcontext['current_debug_item_num'] = -1;
1369
+					}
1286 1370
 					return upgradeExit();
1371
+				} elseif ($support_js) {
1372
+									break;
1287 1373
 				}
1288
-				elseif ($support_js)
1289
-					break;
1290 1374
 			}
1291 1375
 			// Set the progress bar to be right as if we had - even if we hadn't...
1292 1376
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1311,8 +1395,9 @@  discard block
 block discarded – undo
1311 1395
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1312 1396
 
1313 1397
 	// Now it's nice to have some of the basic SMF source files.
1314
-	if (!isset($_GET['ssi']) && !$command_line)
1315
-		redirectLocation('&ssi=1');
1398
+	if (!isset($_GET['ssi']) && !$command_line) {
1399
+			redirectLocation('&ssi=1');
1400
+	}
1316 1401
 
1317 1402
 	$upcontext['sub_template'] = 'upgrade_complete';
1318 1403
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1328,14 +1413,16 @@  discard block
 block discarded – undo
1328 1413
 	// Are we in maintenance mode?
1329 1414
 	if (isset($upcontext['user']['main']))
1330 1415
 	{
1331
-		if ($command_line)
1332
-			echo ' * ';
1416
+		if ($command_line) {
1417
+					echo ' * ';
1418
+		}
1333 1419
 		$upcontext['removed_maintenance'] = true;
1334 1420
 		$changes['maintenance'] = $upcontext['user']['main'];
1335 1421
 	}
1336 1422
 	// Otherwise if somehow we are in 2 let's go to 1.
1337
-	elseif (!empty($maintenance) && $maintenance == 2)
1338
-		$changes['maintenance'] = 1;
1423
+	elseif (!empty($maintenance) && $maintenance == 2) {
1424
+			$changes['maintenance'] = 1;
1425
+	}
1339 1426
 
1340 1427
 	// Wipe this out...
1341 1428
 	$upcontext['user'] = array();
@@ -1350,9 +1437,9 @@  discard block
 block discarded – undo
1350 1437
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1351 1438
 
1352 1439
 	// Now is the perfect time to fetch the SM files.
1353
-	if ($command_line)
1354
-		cli_scheduled_fetchSMfiles();
1355
-	else
1440
+	if ($command_line) {
1441
+			cli_scheduled_fetchSMfiles();
1442
+	} else
1356 1443
 	{
1357 1444
 		require_once($sourcedir . '/ScheduledTasks.php');
1358 1445
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1360,8 +1447,9 @@  discard block
 block discarded – undo
1360 1447
 	}
1361 1448
 
1362 1449
 	// Log what we've done.
1363
-	if (empty($user_info['id']))
1364
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1450
+	if (empty($user_info['id'])) {
1451
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1452
+	}
1365 1453
 
1366 1454
 	// Log the action manually, so CLI still works.
1367 1455
 	$smcFunc['db_insert']('',
@@ -1380,8 +1468,9 @@  discard block
 block discarded – undo
1380 1468
 
1381 1469
 	// Save the current database version.
1382 1470
 	$server_version = $smcFunc['db_server_info']();
1383
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1384
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1471
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1472
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1473
+	}
1385 1474
 
1386 1475
 	if ($command_line)
1387 1476
 	{
@@ -1393,8 +1482,9 @@  discard block
 block discarded – undo
1393 1482
 
1394 1483
 	// Make sure it says we're done.
1395 1484
 	$upcontext['overall_percent'] = 100;
1396
-	if (isset($upcontext['step_progress']))
1397
-		unset($upcontext['step_progress']);
1485
+	if (isset($upcontext['step_progress'])) {
1486
+			unset($upcontext['step_progress']);
1487
+	}
1398 1488
 
1399 1489
 	$_GET['substep'] = 0;
1400 1490
 	return false;
@@ -1405,8 +1495,9 @@  discard block
 block discarded – undo
1405 1495
 {
1406 1496
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1407 1497
 
1408
-	if (empty($modSettings['time_format']))
1409
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1498
+	if (empty($modSettings['time_format'])) {
1499
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1500
+	}
1410 1501
 
1411 1502
 	// What files do we want to get
1412 1503
 	$request = $smcFunc['db_query']('', '
@@ -1440,12 +1531,14 @@  discard block
 block discarded – undo
1440 1531
 		$file_data = fetch_web_data($url);
1441 1532
 
1442 1533
 		// If we got an error - maybe https isn't working, try http?
1443
-		if ($file_data === false && substr($url, 0, 30) == 'https://www.simplemachines.org')
1444
-			$file_data = fetch_web_data(str_replace('https://www.simplemachines.org', 'http://www.simplemachines.org', $url));
1534
+		if ($file_data === false && substr($url, 0, 30) == 'https://www.simplemachines.org') {
1535
+					$file_data = fetch_web_data(str_replace('https://www.simplemachines.org', 'http://www.simplemachines.org', $url));
1536
+		}
1445 1537
 
1446 1538
 		// If we got an error - give up - the site might be down.
1447
-		if ($file_data === false)
1448
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1539
+		if ($file_data === false) {
1540
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1541
+		}
1449 1542
 
1450 1543
 		// Save the file to the database.
1451 1544
 		$smcFunc['db_query']('substring', '
@@ -1487,8 +1580,9 @@  discard block
 block discarded – undo
1487 1580
 	$themeData = array();
1488 1581
 	foreach ($values as $variable => $value)
1489 1582
 	{
1490
-		if (!isset($value) || $value === null)
1491
-			$value = 0;
1583
+		if (!isset($value) || $value === null) {
1584
+					$value = 0;
1585
+		}
1492 1586
 
1493 1587
 		$themeData[] = array(0, 1, $variable, $value);
1494 1588
 	}
@@ -1517,8 +1611,9 @@  discard block
 block discarded – undo
1517 1611
 
1518 1612
 	foreach ($values as $variable => $value)
1519 1613
 	{
1520
-		if (empty($modSettings[$value[0]]))
1521
-			continue;
1614
+		if (empty($modSettings[$value[0]])) {
1615
+					continue;
1616
+		}
1522 1617
 
1523 1618
 		$smcFunc['db_query']('', '
1524 1619
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1604,10 +1699,11 @@  discard block
 block discarded – undo
1604 1699
 	set_error_handler(
1605 1700
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1606 1701
 		{
1607
-			if ($support_js)
1608
-				return true;
1609
-			else
1610
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1702
+			if ($support_js) {
1703
+							return true;
1704
+			} else {
1705
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1706
+			}
1611 1707
 		}
1612 1708
 	);
1613 1709
 
@@ -1622,8 +1718,9 @@  discard block
 block discarded – undo
1622 1718
 				'db_error_skip' => true,
1623 1719
 			)
1624 1720
 		);
1625
-		if ($smcFunc['db_num_rows']($request) === 0)
1626
-			die('Unable to find members table!');
1721
+		if ($smcFunc['db_num_rows']($request) === 0) {
1722
+					die('Unable to find members table!');
1723
+		}
1627 1724
 		$table_status = $smcFunc['db_fetch_assoc']($request);
1628 1725
 		$smcFunc['db_free_result']($request);
1629 1726
 
@@ -1638,17 +1735,20 @@  discard block
 block discarded – undo
1638 1735
 				)
1639 1736
 			);
1640 1737
 			// Got something?
1641
-			if ($smcFunc['db_num_rows']($request) !== 0)
1642
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
1738
+			if ($smcFunc['db_num_rows']($request) !== 0) {
1739
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
1740
+			}
1643 1741
 			$smcFunc['db_free_result']($request);
1644 1742
 
1645 1743
 			// Excellent!
1646
-			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset']))
1647
-				$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1744
+			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) {
1745
+							$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1746
+			}
1648 1747
 		}
1649 1748
 	}
1650
-	if (empty($db_collation))
1651
-		$db_collation = '';
1749
+	if (empty($db_collation)) {
1750
+			$db_collation = '';
1751
+	}
1652 1752
 
1653 1753
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1654 1754
 
@@ -1660,8 +1760,9 @@  discard block
 block discarded – undo
1660 1760
 	$last_step = '';
1661 1761
 
1662 1762
 	// Make sure all newly created tables will have the proper characters set.
1663
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1664
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1763
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1764
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1765
+	}
1665 1766
 
1666 1767
 	// Count the total number of steps within this file - for progress.
1667 1768
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1681,15 +1782,18 @@  discard block
 block discarded – undo
1681 1782
 		$do_current = $substep >= $_GET['substep'];
1682 1783
 
1683 1784
 		// Get rid of any comments in the beginning of the line...
1684
-		if (substr(trim($line), 0, 2) === '/*')
1685
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1785
+		if (substr(trim($line), 0, 2) === '/*') {
1786
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1787
+		}
1686 1788
 
1687 1789
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1688
-		if ($is_debug && !$support_js && $command_line)
1689
-			flush();
1790
+		if ($is_debug && !$support_js && $command_line) {
1791
+					flush();
1792
+		}
1690 1793
 
1691
-		if (trim($line) === '')
1692
-			continue;
1794
+		if (trim($line) === '') {
1795
+					continue;
1796
+		}
1693 1797
 
1694 1798
 		if (trim(substr($line, 0, 3)) === '---')
1695 1799
 		{
@@ -1699,8 +1803,9 @@  discard block
 block discarded – undo
1699 1803
 			if (trim($current_data) != '' && $type !== '}')
1700 1804
 			{
1701 1805
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1702
-				if ($command_line)
1703
-					echo $upcontext['error_message'];
1806
+				if ($command_line) {
1807
+									echo $upcontext['error_message'];
1808
+				}
1704 1809
 			}
1705 1810
 
1706 1811
 			if ($type == ' ')
@@ -1718,17 +1823,18 @@  discard block
 block discarded – undo
1718 1823
 				if ($do_current)
1719 1824
 				{
1720 1825
 					$upcontext['actioned_items'][] = $last_step;
1721
-					if ($command_line)
1722
-						echo ' * ';
1826
+					if ($command_line) {
1827
+											echo ' * ';
1828
+					}
1723 1829
 				}
1724
-			}
1725
-			elseif ($type == '#')
1830
+			} elseif ($type == '#')
1726 1831
 			{
1727 1832
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1728 1833
 
1729 1834
 				$upcontext['current_debug_item_num']++;
1730
-				if (trim($line) != '---#')
1731
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1835
+				if (trim($line) != '---#') {
1836
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1837
+				}
1732 1838
 
1733 1839
 				// Have we already done something?
1734 1840
 				if (isset($_GET['xml']) && $done_something)
@@ -1739,34 +1845,36 @@  discard block
 block discarded – undo
1739 1845
 
1740 1846
 				if ($do_current)
1741 1847
 				{
1742
-					if (trim($line) == '---#' && $command_line)
1743
-						echo ' done.', $endl;
1744
-					elseif ($command_line)
1745
-						echo ' +++ ', rtrim(substr($line, 4));
1746
-					elseif (trim($line) != '---#')
1848
+					if (trim($line) == '---#' && $command_line) {
1849
+											echo ' done.', $endl;
1850
+					} elseif ($command_line) {
1851
+											echo ' +++ ', rtrim(substr($line, 4));
1852
+					} elseif (trim($line) != '---#')
1747 1853
 					{
1748
-						if ($is_debug)
1749
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1854
+						if ($is_debug) {
1855
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1856
+						}
1750 1857
 					}
1751 1858
 				}
1752 1859
 
1753 1860
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1754 1861
 				{
1755
-					if ($command_line)
1756
-						echo ' * ';
1757
-					else
1758
-						$upcontext['actioned_items'][] = $last_step;
1862
+					if ($command_line) {
1863
+											echo ' * ';
1864
+					} else {
1865
+											$upcontext['actioned_items'][] = $last_step;
1866
+					}
1759 1867
 				}
1760 1868
 
1761 1869
 				// Small step - only if we're actually doing stuff.
1762
-				if ($do_current)
1763
-					nextSubstep(++$substep);
1764
-				else
1765
-					$substep++;
1766
-			}
1767
-			elseif ($type == '{')
1768
-				$current_type = 'code';
1769
-			elseif ($type == '}')
1870
+				if ($do_current) {
1871
+									nextSubstep(++$substep);
1872
+				} else {
1873
+									$substep++;
1874
+				}
1875
+			} elseif ($type == '{') {
1876
+							$current_type = 'code';
1877
+			} elseif ($type == '}')
1770 1878
 			{
1771 1879
 				$current_type = 'sql';
1772 1880
 
@@ -1779,8 +1887,9 @@  discard block
 block discarded – undo
1779 1887
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1780 1888
 				{
1781 1889
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1782
-					if ($command_line)
1783
-						echo $upcontext['error_message'];
1890
+					if ($command_line) {
1891
+											echo $upcontext['error_message'];
1892
+					}
1784 1893
 				}
1785 1894
 
1786 1895
 				// Done with code!
@@ -1860,8 +1969,9 @@  discard block
 block discarded – undo
1860 1969
 	$db_unbuffered = false;
1861 1970
 
1862 1971
 	// Failure?!
1863
-	if ($result !== false)
1864
-		return $result;
1972
+	if ($result !== false) {
1973
+			return $result;
1974
+	}
1865 1975
 
1866 1976
 	$db_error_message = $smcFunc['db_error']($db_connection);
1867 1977
 	// If MySQL we do something more clever.
@@ -1889,54 +1999,61 @@  discard block
 block discarded – undo
1889 1999
 			{
1890 2000
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1891 2001
 				$result = mysqli_query($db_connection, $string);
1892
-				if ($result !== false)
1893
-					return $result;
2002
+				if ($result !== false) {
2003
+									return $result;
2004
+				}
1894 2005
 			}
1895
-		}
1896
-		elseif ($mysqli_errno == 2013)
2006
+		} elseif ($mysqli_errno == 2013)
1897 2007
 		{
1898 2008
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1899 2009
 			mysqli_select_db($db_connection, $db_name);
1900 2010
 			if ($db_connection)
1901 2011
 			{
1902 2012
 				$result = mysqli_query($db_connection, $string);
1903
-				if ($result !== false)
1904
-					return $result;
2013
+				if ($result !== false) {
2014
+									return $result;
2015
+				}
1905 2016
 			}
1906 2017
 		}
1907 2018
 		// Duplicate column name... should be okay ;).
1908
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1909
-			return false;
2019
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2020
+					return false;
2021
+		}
1910 2022
 		// Duplicate insert... make sure it's the proper type of query ;).
1911
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1912
-			return false;
2023
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2024
+					return false;
2025
+		}
1913 2026
 		// Creating an index on a non-existent column.
1914
-		elseif ($mysqli_errno == 1072)
1915
-			return false;
1916
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1917
-			return false;
2027
+		elseif ($mysqli_errno == 1072) {
2028
+					return false;
2029
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2030
+					return false;
2031
+		}
1918 2032
 	}
1919 2033
 	// If a table already exists don't go potty.
1920 2034
 	else
1921 2035
 	{
1922 2036
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1923 2037
 		{
1924
-			if (strpos($db_error_message, 'exist') !== false)
1925
-				return true;
1926
-		}
1927
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2038
+			if (strpos($db_error_message, 'exist') !== false) {
2039
+							return true;
2040
+			}
2041
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1928 2042
 		{
1929
-			if (strpos($db_error_message, 'duplicate') !== false)
1930
-				return true;
2043
+			if (strpos($db_error_message, 'duplicate') !== false) {
2044
+							return true;
2045
+			}
1931 2046
 		}
1932 2047
 	}
1933 2048
 
1934 2049
 	// Get the query string so we pass everything.
1935 2050
 	$query_string = '';
1936
-	foreach ($_GET as $k => $v)
1937
-		$query_string .= ';' . $k . '=' . $v;
1938
-	if (strlen($query_string) != 0)
1939
-		$query_string = '?' . substr($query_string, 1);
2051
+	foreach ($_GET as $k => $v) {
2052
+			$query_string .= ';' . $k . '=' . $v;
2053
+	}
2054
+	if (strlen($query_string) != 0) {
2055
+			$query_string = '?' . substr($query_string, 1);
2056
+	}
1940 2057
 
1941 2058
 	if ($command_line)
1942 2059
 	{
@@ -1991,16 +2108,18 @@  discard block
 block discarded – undo
1991 2108
 			{
1992 2109
 				$found |= 1;
1993 2110
 				// Do some checks on the data if we have it set.
1994
-				if (isset($change['col_type']))
1995
-					$found &= $change['col_type'] === $column['type'];
1996
-				if (isset($change['null_allowed']))
1997
-					$found &= $column['null'] == $change['null_allowed'];
1998
-				if (isset($change['default']))
1999
-					$found &= $change['default'] === $column['default'];
2111
+				if (isset($change['col_type'])) {
2112
+									$found &= $change['col_type'] === $column['type'];
2113
+				}
2114
+				if (isset($change['null_allowed'])) {
2115
+									$found &= $column['null'] == $change['null_allowed'];
2116
+				}
2117
+				if (isset($change['default'])) {
2118
+									$found &= $change['default'] === $column['default'];
2119
+				}
2000 2120
 			}
2001 2121
 		}
2002
-	}
2003
-	elseif ($change['type'] === 'index')
2122
+	} elseif ($change['type'] === 'index')
2004 2123
 	{
2005 2124
 		$request = upgrade_query('
2006 2125
 			SHOW INDEX
@@ -2009,9 +2128,10 @@  discard block
 block discarded – undo
2009 2128
 		{
2010 2129
 			$cur_index = array();
2011 2130
 
2012
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2013
-				if ($row['Key_name'] === $change['name'])
2131
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2132
+							if ($row['Key_name'] === $change['name'])
2014 2133
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2134
+			}
2015 2135
 
2016 2136
 			ksort($cur_index, SORT_NUMERIC);
2017 2137
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2021,14 +2141,17 @@  discard block
 block discarded – undo
2021 2141
 	}
2022 2142
 
2023 2143
 	// If we're trying to add and it's added, we're done.
2024
-	if ($found && in_array($change['method'], array('add', 'change')))
2025
-		return true;
2144
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2145
+			return true;
2146
+	}
2026 2147
 	// Otherwise if we're removing and it wasn't found we're also done.
2027
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2028
-		return true;
2148
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2149
+			return true;
2150
+	}
2029 2151
 	// Otherwise is it just a test?
2030
-	elseif ($is_test)
2031
-		return false;
2152
+	elseif ($is_test) {
2153
+			return false;
2154
+	}
2032 2155
 
2033 2156
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2034 2157
 	$running = false;
@@ -2039,8 +2162,9 @@  discard block
 block discarded – undo
2039 2162
 			SHOW FULL PROCESSLIST');
2040 2163
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2041 2164
 		{
2042
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2043
-				$found = true;
2165
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2166
+							$found = true;
2167
+			}
2044 2168
 		}
2045 2169
 
2046 2170
 		// Can't find it? Then we need to run it fools!
@@ -2052,8 +2176,9 @@  discard block
 block discarded – undo
2052 2176
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2053 2177
 				' . $change['text'], true) !== false;
2054 2178
 
2055
-			if (!$success)
2056
-				return false;
2179
+			if (!$success) {
2180
+							return false;
2181
+			}
2057 2182
 
2058 2183
 			// Return
2059 2184
 			$running = true;
@@ -2095,8 +2220,9 @@  discard block
 block discarded – undo
2095 2220
 			'db_error_skip' => true,
2096 2221
 		)
2097 2222
 	);
2098
-	if ($smcFunc['db_num_rows']($request) === 0)
2099
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2223
+	if ($smcFunc['db_num_rows']($request) === 0) {
2224
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2225
+	}
2100 2226
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2101 2227
 	$smcFunc['db_free_result']($request);
2102 2228
 
@@ -2118,18 +2244,19 @@  discard block
 block discarded – undo
2118 2244
 			)
2119 2245
 		);
2120 2246
 		// No results? Just forget it all together.
2121
-		if ($smcFunc['db_num_rows']($request) === 0)
2122
-			unset($table_row['Collation']);
2123
-		else
2124
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2247
+		if ($smcFunc['db_num_rows']($request) === 0) {
2248
+					unset($table_row['Collation']);
2249
+		} else {
2250
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2251
+		}
2125 2252
 		$smcFunc['db_free_result']($request);
2126 2253
 	}
2127 2254
 
2128 2255
 	if ($column_fix)
2129 2256
 	{
2130 2257
 		// Make sure there are no NULL's left.
2131
-		if ($null_fix)
2132
-			$smcFunc['db_query']('', '
2258
+		if ($null_fix) {
2259
+					$smcFunc['db_query']('', '
2133 2260
 				UPDATE {db_prefix}' . $change['table'] . '
2134 2261
 				SET ' . $change['column'] . ' = {string:default}
2135 2262
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2138,6 +2265,7 @@  discard block
 block discarded – undo
2138 2265
 					'db_error_skip' => true,
2139 2266
 				)
2140 2267
 			);
2268
+		}
2141 2269
 
2142 2270
 		// Do the actual alteration.
2143 2271
 		$smcFunc['db_query']('', '
@@ -2166,8 +2294,9 @@  discard block
 block discarded – undo
2166 2294
 	}
2167 2295
 
2168 2296
 	// Not a column we need to check on?
2169
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2170
-		return;
2297
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2298
+			return;
2299
+	}
2171 2300
 
2172 2301
 	// Break it up you (six|seven).
2173 2302
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2186,13 +2315,13 @@  discard block
 block discarded – undo
2186 2315
 				'new_name' => $temp[2],
2187 2316
 		));
2188 2317
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2189
-		if ($smcFunc['db_num_rows'] != 1)
2190
-			return;
2318
+		if ($smcFunc['db_num_rows'] != 1) {
2319
+					return;
2320
+		}
2191 2321
 
2192 2322
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2193 2323
 		$smcFunc['db_free_result']($request);
2194
-	}
2195
-	else
2324
+	} else
2196 2325
 	{
2197 2326
 		// Do this the old fashion, sure method way.
2198 2327
 		$request = $smcFunc['db_query']('', '
@@ -2203,21 +2332,24 @@  discard block
 block discarded – undo
2203 2332
 		));
2204 2333
 		// Mayday!
2205 2334
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2206
-		if ($smcFunc['db_num_rows'] == 0)
2207
-			return;
2335
+		if ($smcFunc['db_num_rows'] == 0) {
2336
+					return;
2337
+		}
2208 2338
 
2209 2339
 		// Oh where, oh where has my little field gone. Oh where can it be...
2210
-		while ($row = $smcFunc['db_query']($request))
2211
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2340
+		while ($row = $smcFunc['db_query']($request)) {
2341
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2212 2342
 			{
2213 2343
 				$current_type = $row['Type'];
2344
+		}
2214 2345
 				break;
2215 2346
 			}
2216 2347
 	}
2217 2348
 
2218 2349
 	// If this doesn't match, the column may of been altered for a reason.
2219
-	if (trim($current_type) != trim($temp[3]))
2220
-		$temp[3] = $current_type;
2350
+	if (trim($current_type) != trim($temp[3])) {
2351
+			$temp[3] = $current_type;
2352
+	}
2221 2353
 
2222 2354
 	// Piece this back together.
2223 2355
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2229,8 +2361,9 @@  discard block
 block discarded – undo
2229 2361
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2230 2362
 	global $step_progress, $is_debug, $upcontext;
2231 2363
 
2232
-	if ($_GET['substep'] < $substep)
2233
-		$_GET['substep'] = $substep;
2364
+	if ($_GET['substep'] < $substep) {
2365
+			$_GET['substep'] = $substep;
2366
+	}
2234 2367
 
2235 2368
 	if ($command_line)
2236 2369
 	{
@@ -2243,29 +2376,33 @@  discard block
 block discarded – undo
2243 2376
 	}
2244 2377
 
2245 2378
 	@set_time_limit(300);
2246
-	if (function_exists('apache_reset_timeout'))
2247
-		@apache_reset_timeout();
2379
+	if (function_exists('apache_reset_timeout')) {
2380
+			@apache_reset_timeout();
2381
+	}
2248 2382
 
2249
-	if (time() - $start_time <= $timeLimitThreshold)
2250
-		return;
2383
+	if (time() - $start_time <= $timeLimitThreshold) {
2384
+			return;
2385
+	}
2251 2386
 
2252 2387
 	// Do we have some custom step progress stuff?
2253 2388
 	if (!empty($step_progress))
2254 2389
 	{
2255 2390
 		$upcontext['substep_progress'] = 0;
2256 2391
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2257
-		if ($step_progress['current'] > $step_progress['total'])
2258
-			$upcontext['substep_progress'] = 99.9;
2259
-		else
2260
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2392
+		if ($step_progress['current'] > $step_progress['total']) {
2393
+					$upcontext['substep_progress'] = 99.9;
2394
+		} else {
2395
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2396
+		}
2261 2397
 
2262 2398
 		// Make it nicely rounded.
2263 2399
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2264 2400
 	}
2265 2401
 
2266 2402
 	// If this is XML we just exit right away!
2267
-	if (isset($_GET['xml']))
2268
-		return upgradeExit();
2403
+	if (isset($_GET['xml'])) {
2404
+			return upgradeExit();
2405
+	}
2269 2406
 
2270 2407
 	// We're going to pause after this!
2271 2408
 	$upcontext['pause'] = true;
@@ -2273,13 +2410,15 @@  discard block
 block discarded – undo
2273 2410
 	$upcontext['query_string'] = '';
2274 2411
 	foreach ($_GET as $k => $v)
2275 2412
 	{
2276
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2277
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2413
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2414
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2415
+		}
2278 2416
 	}
2279 2417
 
2280 2418
 	// Custom warning?
2281
-	if (!empty($custom_warning))
2282
-		$upcontext['custom_warning'] = $custom_warning;
2419
+	if (!empty($custom_warning)) {
2420
+			$upcontext['custom_warning'] = $custom_warning;
2421
+	}
2283 2422
 
2284 2423
 	upgradeExit();
2285 2424
 }
@@ -2294,25 +2433,26 @@  discard block
 block discarded – undo
2294 2433
 	ob_implicit_flush(true);
2295 2434
 	@set_time_limit(600);
2296 2435
 
2297
-	if (!isset($_SERVER['argv']))
2298
-		$_SERVER['argv'] = array();
2436
+	if (!isset($_SERVER['argv'])) {
2437
+			$_SERVER['argv'] = array();
2438
+	}
2299 2439
 	$_GET['maint'] = 1;
2300 2440
 
2301 2441
 	foreach ($_SERVER['argv'] as $i => $arg)
2302 2442
 	{
2303
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2304
-			$_GET['lang'] = $match[1];
2305
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2306
-			continue;
2307
-		elseif ($arg == '--no-maintenance')
2308
-			$_GET['maint'] = 0;
2309
-		elseif ($arg == '--debug')
2310
-			$is_debug = true;
2311
-		elseif ($arg == '--backup')
2312
-			$_POST['backup'] = 1;
2313
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2314
-			$_GET['conv'] = 1;
2315
-		elseif ($i != 0)
2443
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2444
+					$_GET['lang'] = $match[1];
2445
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2446
+					continue;
2447
+		} elseif ($arg == '--no-maintenance') {
2448
+					$_GET['maint'] = 0;
2449
+		} elseif ($arg == '--debug') {
2450
+					$is_debug = true;
2451
+		} elseif ($arg == '--backup') {
2452
+					$_POST['backup'] = 1;
2453
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2454
+					$_GET['conv'] = 1;
2455
+		} elseif ($i != 0)
2316 2456
 		{
2317 2457
 			echo 'SMF Command-line Upgrader
2318 2458
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2326,10 +2466,12 @@  discard block
 block discarded – undo
2326 2466
 		}
2327 2467
 	}
2328 2468
 
2329
-	if (!php_version_check())
2330
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2331
-	if (!db_version_check())
2332
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2469
+	if (!php_version_check()) {
2470
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2471
+	}
2472
+	if (!db_version_check()) {
2473
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2474
+	}
2333 2475
 
2334 2476
 	// Do some checks to make sure they have proper privileges
2335 2477
 	db_extend('packages');
@@ -2344,34 +2486,39 @@  discard block
 block discarded – undo
2344 2486
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2345 2487
 
2346 2488
 	// Sorry... we need CREATE, ALTER and DROP
2347
-	if (!$create || !$alter || !$drop)
2348
-		print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2489
+	if (!$create || !$alter || !$drop) {
2490
+			print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2491
+	}
2349 2492
 
2350 2493
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2351 2494
 		&& @file_exists($sourcedir . '/QueryString.php')
2352 2495
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2353
-	if (!$check && !isset($modSettings['smfVersion']))
2354
-		print_error('Error: Some files are missing or out-of-date.', true);
2496
+	if (!$check && !isset($modSettings['smfVersion'])) {
2497
+			print_error('Error: Some files are missing or out-of-date.', true);
2498
+	}
2355 2499
 
2356 2500
 	// Do a quick version spot check.
2357 2501
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2358 2502
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2359
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2360
-		print_error('Error: Some files have not yet been updated properly.');
2503
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2504
+			print_error('Error: Some files have not yet been updated properly.');
2505
+	}
2361 2506
 
2362 2507
 	// Make sure Settings.php is writable.
2363 2508
 		quickFileWritable($boarddir . '/Settings.php');
2364
-	if (!is_writable($boarddir . '/Settings.php'))
2365
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2509
+	if (!is_writable($boarddir . '/Settings.php')) {
2510
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2511
+	}
2366 2512
 
2367 2513
 	// Make sure Settings_bak.php is writable.
2368 2514
 		quickFileWritable($boarddir . '/Settings_bak.php');
2369
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2370
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2515
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2516
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2517
+	}
2371 2518
 
2372
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2373
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2374
-	elseif (isset($modSettings['agreement']))
2519
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2520
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2521
+	} elseif (isset($modSettings['agreement']))
2375 2522
 	{
2376 2523
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2377 2524
 		fwrite($fp, $modSettings['agreement']);
@@ -2381,31 +2528,36 @@  discard block
 block discarded – undo
2381 2528
 	// Make sure Themes is writable.
2382 2529
 	quickFileWritable($modSettings['theme_dir']);
2383 2530
 
2384
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2385
-		print_error('Error: Unable to obtain write access to "Themes".');
2531
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2532
+			print_error('Error: Unable to obtain write access to "Themes".');
2533
+	}
2386 2534
 
2387 2535
 	// Make sure cache directory exists and is writable!
2388 2536
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2389
-	if (!file_exists($cachedir_temp))
2390
-		@mkdir($cachedir_temp);
2537
+	if (!file_exists($cachedir_temp)) {
2538
+			@mkdir($cachedir_temp);
2539
+	}
2391 2540
 
2392 2541
 	// Make sure the cache temp dir is writable.
2393 2542
 	quickFileWritable($cachedir_temp);
2394 2543
 
2395
-	if (!is_writable($cachedir_temp))
2396
-		print_error('Error: Unable to obtain write access to "cache".', true);
2544
+	if (!is_writable($cachedir_temp)) {
2545
+			print_error('Error: Unable to obtain write access to "cache".', true);
2546
+	}
2397 2547
 
2398
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2399
-		print_error('Error: Unable to find language files!', true);
2400
-	else
2548
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2549
+			print_error('Error: Unable to find language files!', true);
2550
+	} else
2401 2551
 	{
2402 2552
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2403 2553
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2404 2554
 
2405
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2406
-			print_error('Error: Language files out of date.', true);
2407
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2408
-			print_error('Error: Install language is missing for selected language.', true);
2555
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2556
+					print_error('Error: Language files out of date.', true);
2557
+		}
2558
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2559
+					print_error('Error: Install language is missing for selected language.', true);
2560
+		}
2409 2561
 
2410 2562
 		// Otherwise include it!
2411 2563
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2434,8 +2586,7 @@  discard block
 block discarded – undo
2434 2586
 		);
2435 2587
 
2436 2588
 		return true;
2437
-	}
2438
-	else
2589
+	} else
2439 2590
 	{
2440 2591
 		$upcontext['page_title'] = 'Converting to UTF8';
2441 2592
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2479,8 +2630,9 @@  discard block
 block discarded – undo
2479 2630
 			)
2480 2631
 		);
2481 2632
 		$db_charsets = array();
2482
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2483
-			$db_charsets[] = $row['Charset'];
2633
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2634
+					$db_charsets[] = $row['Charset'];
2635
+		}
2484 2636
 
2485 2637
 		$smcFunc['db_free_result']($request);
2486 2638
 
@@ -2516,13 +2668,15 @@  discard block
 block discarded – undo
2516 2668
 		// If there's a fulltext index, we need to drop it first...
2517 2669
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2518 2670
 		{
2519
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2520
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2671
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2672
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2521 2673
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2674
+			}
2522 2675
 			$smcFunc['db_free_result']($request);
2523 2676
 
2524
-			if (isset($upcontext['fulltext_index']))
2525
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2677
+			if (isset($upcontext['fulltext_index'])) {
2678
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2679
+			}
2526 2680
 		}
2527 2681
 
2528 2682
 		// Drop it and make a note...
@@ -2712,8 +2866,9 @@  discard block
 block discarded – undo
2712 2866
 			$replace = '%field%';
2713 2867
 
2714 2868
 			// Build a huge REPLACE statement...
2715
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2716
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2869
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2870
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2871
+			}
2717 2872
 		}
2718 2873
 
2719 2874
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2747,8 +2902,9 @@  discard block
 block discarded – undo
2747 2902
 			$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2748 2903
 
2749 2904
 			// Just to make sure it doesn't time out.
2750
-			if (function_exists('apache_reset_timeout'))
2751
-				@apache_reset_timeout();
2905
+			if (function_exists('apache_reset_timeout')) {
2906
+							@apache_reset_timeout();
2907
+			}
2752 2908
 
2753 2909
 			$table_charsets = array();
2754 2910
 
@@ -2769,8 +2925,9 @@  discard block
 block discarded – undo
2769 2925
 					{
2770 2926
 						list($charset) = explode('_', $collation);
2771 2927
 
2772
-						if (!isset($table_charsets[$charset]))
2773
-							$table_charsets[$charset] = array();
2928
+						if (!isset($table_charsets[$charset])) {
2929
+													$table_charsets[$charset] = array();
2930
+						}
2774 2931
 
2775 2932
 						$table_charsets[$charset][] = $column_info;
2776 2933
 					}
@@ -2810,10 +2967,11 @@  discard block
 block discarded – undo
2810 2967
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2811 2968
 				{
2812 2969
 					$update = '';
2813
-					foreach ($table_charsets as $charset => $columns)
2814
-						foreach ($columns as $column)
2970
+					foreach ($table_charsets as $charset => $columns) {
2971
+											foreach ($columns as $column)
2815 2972
 							$update .= '
2816 2973
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2974
+					}
2817 2975
 
2818 2976
 					$smcFunc['db_query']('', '
2819 2977
 						UPDATE {raw:table_name}
@@ -2838,8 +2996,9 @@  discard block
 block discarded – undo
2838 2996
 			// Now do the actual conversion (if still needed).
2839 2997
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2840 2998
 			{
2841
-				if ($command_line)
2842
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
2999
+				if ($command_line) {
3000
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3001
+				}
2843 3002
 
2844 3003
 				$smcFunc['db_query']('', '
2845 3004
 					ALTER TABLE {raw:table_name}
@@ -2849,8 +3008,9 @@  discard block
 block discarded – undo
2849 3008
 					)
2850 3009
 				);
2851 3010
 
2852
-				if ($command_line)
2853
-					echo " done.\n";
3011
+				if ($command_line) {
3012
+									echo " done.\n";
3013
+				}
2854 3014
 			}
2855 3015
 		}
2856 3016
 
@@ -2880,8 +3040,8 @@  discard block
 block discarded – undo
2880 3040
 		);
2881 3041
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2882 3042
 		{
2883
-			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1)
2884
-				$smcFunc['db_query']('', '
3043
+			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) {
3044
+							$smcFunc['db_query']('', '
2885 3045
 					UPDATE {db_prefix}log_actions
2886 3046
 					SET extra = {string:extra}
2887 3047
 					WHERE id_action = {int:current_action}',
@@ -2890,6 +3050,7 @@  discard block
 block discarded – undo
2890 3050
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2891 3051
 					)
2892 3052
 				);
3053
+			}
2893 3054
 		}
2894 3055
 		$smcFunc['db_free_result']($request);
2895 3056
 
@@ -2911,15 +3072,17 @@  discard block
 block discarded – undo
2911 3072
 	// First thing's first - did we already do this?
2912 3073
 	if (!empty($modSettings['json_done']))
2913 3074
 	{
2914
-		if ($command_line)
2915
-			return DeleteUpgrade();
2916
-		else
2917
-			return true;
3075
+		if ($command_line) {
3076
+					return DeleteUpgrade();
3077
+		} else {
3078
+					return true;
3079
+		}
2918 3080
 	}
2919 3081
 
2920 3082
 	// Done it already - js wise?
2921
-	if (!empty($_POST['json_done']))
2922
-		return true;
3083
+	if (!empty($_POST['json_done'])) {
3084
+			return true;
3085
+	}
2923 3086
 
2924 3087
 	// List of tables affected by this function
2925 3088
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2951,12 +3114,14 @@  discard block
 block discarded – undo
2951 3114
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2952 3115
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2953 3116
 
2954
-	foreach ($keys as $id => $table)
2955
-		if ($id < $_GET['substep'])
3117
+	foreach ($keys as $id => $table) {
3118
+			if ($id < $_GET['substep'])
2956 3119
 			$upcontext['previous_tables'][] = $table;
3120
+	}
2957 3121
 
2958
-	if ($command_line)
2959
-		echo 'Converting data from serialize() to json_encode().';
3122
+	if ($command_line) {
3123
+			echo 'Converting data from serialize() to json_encode().';
3124
+	}
2960 3125
 
2961 3126
 	if (!$support_js || isset($_GET['xml']))
2962 3127
 	{
@@ -2996,8 +3161,9 @@  discard block
 block discarded – undo
2996 3161
 
2997 3162
 				// Loop through and fix these...
2998 3163
 				$new_settings = array();
2999
-				if ($command_line)
3000
-					echo "\n" . 'Fixing some settings...';
3164
+				if ($command_line) {
3165
+									echo "\n" . 'Fixing some settings...';
3166
+				}
3001 3167
 
3002 3168
 				foreach ($serialized_settings as $var)
3003 3169
 				{
@@ -3005,22 +3171,24 @@  discard block
 block discarded – undo
3005 3171
 					{
3006 3172
 						// Attempt to unserialize the setting
3007 3173
 						$temp = @safe_unserialize($modSettings[$var]);
3008
-						if (!$temp && $command_line)
3009
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3010
-						elseif ($temp !== false)
3011
-							$new_settings[$var] = json_encode($temp);
3174
+						if (!$temp && $command_line) {
3175
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3176
+						} elseif ($temp !== false) {
3177
+													$new_settings[$var] = json_encode($temp);
3178
+						}
3012 3179
 					}
3013 3180
 				}
3014 3181
 
3015 3182
 				// Update everything at once
3016
-				if (!function_exists('cache_put_data'))
3017
-					require_once($sourcedir . '/Load.php');
3183
+				if (!function_exists('cache_put_data')) {
3184
+									require_once($sourcedir . '/Load.php');
3185
+				}
3018 3186
 				updateSettings($new_settings, true);
3019 3187
 
3020
-				if ($command_line)
3021
-					echo ' done.';
3022
-			}
3023
-			elseif ($table == 'themes')
3188
+				if ($command_line) {
3189
+									echo ' done.';
3190
+				}
3191
+			} elseif ($table == 'themes')
3024 3192
 			{
3025 3193
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3026 3194
 				$query = $smcFunc['db_query']('', '
@@ -3039,10 +3207,11 @@  discard block
 block discarded – undo
3039 3207
 
3040 3208
 						if ($command_line)
3041 3209
 						{
3042
-							if ($temp === false)
3043
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3044
-							else
3045
-								echo "\n" . 'Fixing admin preferences...';
3210
+							if ($temp === false) {
3211
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3212
+							} else {
3213
+															echo "\n" . 'Fixing admin preferences...';
3214
+							}
3046 3215
 						}
3047 3216
 
3048 3217
 						if ($temp !== false)
@@ -3064,15 +3233,15 @@  discard block
 block discarded – undo
3064 3233
 								)
3065 3234
 							);
3066 3235
 
3067
-							if ($command_line)
3068
-								echo ' done.';
3236
+							if ($command_line) {
3237
+															echo ' done.';
3238
+							}
3069 3239
 						}
3070 3240
 					}
3071 3241
 
3072 3242
 					$smcFunc['db_free_result']($query);
3073 3243
 				}
3074
-			}
3075
-			else
3244
+			} else
3076 3245
 			{
3077 3246
 				// First item is always the key...
3078 3247
 				$key = $info[0];
@@ -3083,8 +3252,7 @@  discard block
 block discarded – undo
3083 3252
 				{
3084 3253
 					$col_select = $info[1];
3085 3254
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3086
-				}
3087
-				else
3255
+				} else
3088 3256
 				{
3089 3257
 					$col_select = implode(', ', $info);
3090 3258
 				}
@@ -3117,8 +3285,7 @@  discard block
 block discarded – undo
3117 3285
 								if ($temp === false && $command_line)
3118 3286
 								{
3119 3287
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3120
-								}
3121
-								else
3288
+								} else
3122 3289
 								{
3123 3290
 									$row[$col] = json_encode($temp);
3124 3291
 
@@ -3143,16 +3310,18 @@  discard block
 block discarded – undo
3143 3310
 						}
3144 3311
 					}
3145 3312
 
3146
-					if ($command_line)
3147
-						echo ' done.';
3313
+					if ($command_line) {
3314
+											echo ' done.';
3315
+					}
3148 3316
 
3149 3317
 					// Free up some memory...
3150 3318
 					$smcFunc['db_free_result']($query);
3151 3319
 				}
3152 3320
 			}
3153 3321
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3154
-			if (isset($_GET['xml']))
3155
-				return upgradeExit();
3322
+			if (isset($_GET['xml'])) {
3323
+							return upgradeExit();
3324
+			}
3156 3325
 		}
3157 3326
 
3158 3327
 		if ($command_line)
@@ -3167,8 +3336,9 @@  discard block
 block discarded – undo
3167 3336
 
3168 3337
 		$_GET['substep'] = 0;
3169 3338
 		// Make sure we move on!
3170
-		if ($command_line)
3171
-			return DeleteUpgrade();
3339
+		if ($command_line) {
3340
+					return DeleteUpgrade();
3341
+		}
3172 3342
 
3173 3343
 		return true;
3174 3344
 	}
@@ -3188,14 +3358,16 @@  discard block
 block discarded – undo
3188 3358
 	global $upcontext, $txt, $settings;
3189 3359
 
3190 3360
 	// Don't call me twice!
3191
-	if (!empty($upcontext['chmod_called']))
3192
-		return;
3361
+	if (!empty($upcontext['chmod_called'])) {
3362
+			return;
3363
+	}
3193 3364
 
3194 3365
 	$upcontext['chmod_called'] = true;
3195 3366
 
3196 3367
 	// Nothing?
3197
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3198
-		return;
3368
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3369
+			return;
3370
+	}
3199 3371
 
3200 3372
 	// Was it a problem with Windows?
3201 3373
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3227,11 +3399,12 @@  discard block
 block discarded – undo
3227 3399
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>The following files needs to be made writable to continue:</h4>\n\t\t\t\');
3228 3400
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3229 3401
 
3230
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3231
-		echo '
3402
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3403
+			echo '
3232 3404
 					content.write(\'<hr>\n\t\t\t\');
3233 3405
 					content.write(\'<p>If you have a shell account, the convenient below command can automatically correct permissions on these files</p>\n\t\t\t\');
3234 3406
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3407
+	}
3235 3408
 
3236 3409
 	echo '
3237 3410
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3239,17 +3412,19 @@  discard block
 block discarded – undo
3239 3412
 				}
3240 3413
 		</script>';
3241 3414
 
3242
-	if (!empty($upcontext['chmod']['ftp_error']))
3243
-		echo '
3415
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3416
+			echo '
3244 3417
 			<div class="error_message red">
3245 3418
 				The following error was encountered when trying to connect:<br><br>
3246 3419
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3247 3420
 			</div>
3248 3421
 			<br>';
3422
+	}
3249 3423
 
3250
-	if (empty($upcontext['chmod_in_form']))
3251
-		echo '
3424
+	if (empty($upcontext['chmod_in_form'])) {
3425
+			echo '
3252 3426
 	<form action="', $upcontext['form_url'], '" method="post">';
3427
+	}
3253 3428
 
3254 3429
 	echo '
3255 3430
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3284,10 +3459,11 @@  discard block
 block discarded – undo
3284 3459
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3285 3460
 	</div>';
3286 3461
 
3287
-	if (empty($upcontext['chmod_in_form']))
3288
-		echo '
3462
+	if (empty($upcontext['chmod_in_form'])) {
3463
+			echo '
3289 3464
 	</form>';
3290
-}
3465
+	}
3466
+	}
3291 3467
 
3292 3468
 function template_upgrade_above()
3293 3469
 {
@@ -3347,9 +3523,10 @@  discard block
 block discarded – undo
3347 3523
 				<h2>', $txt['upgrade_progress'], '</h2>
3348 3524
 				<ul>';
3349 3525
 
3350
-	foreach ($upcontext['steps'] as $num => $step)
3351
-		echo '
3526
+	foreach ($upcontext['steps'] as $num => $step) {
3527
+			echo '
3352 3528
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3529
+	}
3353 3530
 
3354 3531
 	echo '
3355 3532
 					</ul>
@@ -3362,8 +3539,8 @@  discard block
 block discarded – undo
3362 3539
 				</div>
3363 3540
 			</div>';
3364 3541
 
3365
-	if (isset($upcontext['step_progress']))
3366
-		echo '
3542
+	if (isset($upcontext['step_progress'])) {
3543
+			echo '
3367 3544
 				<br>
3368 3545
 				<br>
3369 3546
 				<div id="progress_bar_step">
@@ -3372,6 +3549,7 @@  discard block
 block discarded – undo
3372 3549
 						<span>', $txt['upgrade_step_progress'], '</span>
3373 3550
 					</div>
3374 3551
 				</div>';
3552
+	}
3375 3553
 
3376 3554
 	echo '
3377 3555
 				<div id="substep_bar_div" class="smalltext" style="float: left;width: 50%;margin-top: 0.6em;display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div>
@@ -3402,32 +3580,36 @@  discard block
 block discarded – undo
3402 3580
 {
3403 3581
 	global $upcontext, $txt;
3404 3582
 
3405
-	if (!empty($upcontext['pause']))
3406
-		echo '
3583
+	if (!empty($upcontext['pause'])) {
3584
+			echo '
3407 3585
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3408 3586
 
3409 3587
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3410 3588
 								<h3>
3411 3589
 									', $txt['upgrade_paused_overload'], '
3412 3590
 								</h3>';
3591
+	}
3413 3592
 
3414
-	if (!empty($upcontext['custom_warning']))
3415
-		echo '
3593
+	if (!empty($upcontext['custom_warning'])) {
3594
+			echo '
3416 3595
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3417 3596
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3418 3597
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3419 3598
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3420 3599
 								</div>';
3600
+	}
3421 3601
 
3422 3602
 	echo '
3423 3603
 								<div class="righttext" style="margin: 1ex;">';
3424 3604
 
3425
-	if (!empty($upcontext['continue']))
3426
-		echo '
3605
+	if (!empty($upcontext['continue'])) {
3606
+			echo '
3427 3607
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3428
-	if (!empty($upcontext['skip']))
3429
-		echo '
3608
+	}
3609
+	if (!empty($upcontext['skip'])) {
3610
+			echo '
3430 3611
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3612
+	}
3431 3613
 
3432 3614
 	echo '
3433 3615
 								</div>
@@ -3477,11 +3659,12 @@  discard block
 block discarded – undo
3477 3659
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3478 3660
 	<smf>';
3479 3661
 
3480
-	if (!empty($upcontext['get_data']))
3481
-		foreach ($upcontext['get_data'] as $k => $v)
3662
+	if (!empty($upcontext['get_data'])) {
3663
+			foreach ($upcontext['get_data'] as $k => $v)
3482 3664
 			echo '
3483 3665
 		<get key="', $k, '">', $v, '</get>';
3484
-}
3666
+	}
3667
+	}
3485 3668
 
3486 3669
 function template_xml_below()
3487 3670
 {
@@ -3522,8 +3705,8 @@  discard block
 block discarded – undo
3522 3705
 	template_chmod();
3523 3706
 
3524 3707
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3525
-	if ($upcontext['is_large_forum'])
3526
-		echo '
3708
+	if ($upcontext['is_large_forum']) {
3709
+			echo '
3527 3710
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3528 3711
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3529 3712
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3531,10 +3714,11 @@  discard block
 block discarded – undo
3531 3714
 				', $txt['upgrade_warning_lots_data'], '
3532 3715
 			</div>
3533 3716
 		</div>';
3717
+	}
3534 3718
 
3535 3719
 	// A warning message?
3536
-	if (!empty($upcontext['warning']))
3537
-		echo '
3720
+	if (!empty($upcontext['warning'])) {
3721
+			echo '
3538 3722
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3539 3723
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3540 3724
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3542,6 +3726,7 @@  discard block
 block discarded – undo
3542 3726
 				', $upcontext['warning'], '
3543 3727
 			</div>
3544 3728
 		</div>';
3729
+	}
3545 3730
 
3546 3731
 	// Paths are incorrect?
3547 3732
 	echo '
@@ -3557,20 +3742,22 @@  discard block
 block discarded – undo
3557 3742
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3558 3743
 	{
3559 3744
 		$ago = time() - $upcontext['started'];
3560
-		if ($ago < 60)
3561
-			$ago = $ago . ' seconds';
3562
-		elseif ($ago < 3600)
3563
-			$ago = (int) ($ago / 60) . ' minutes';
3564
-		else
3565
-			$ago = (int) ($ago / 3600) . ' hours';
3745
+		if ($ago < 60) {
3746
+					$ago = $ago . ' seconds';
3747
+		} elseif ($ago < 3600) {
3748
+					$ago = (int) ($ago / 60) . ' minutes';
3749
+		} else {
3750
+					$ago = (int) ($ago / 3600) . ' hours';
3751
+		}
3566 3752
 
3567 3753
 		$active = time() - $upcontext['updated'];
3568
-		if ($active < 60)
3569
-			$updated = $active . ' seconds';
3570
-		elseif ($active < 3600)
3571
-			$updated = (int) ($active / 60) . ' minutes';
3572
-		else
3573
-			$updated = (int) ($active / 3600) . ' hours';
3754
+		if ($active < 60) {
3755
+					$updated = $active . ' seconds';
3756
+		} elseif ($active < 3600) {
3757
+					$updated = (int) ($active / 60) . ' minutes';
3758
+		} else {
3759
+					$updated = (int) ($active / 3600) . ' hours';
3760
+		}
3574 3761
 
3575 3762
 		echo '
3576 3763
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3579,16 +3766,18 @@  discard block
 block discarded – undo
3579 3766
 			<div style="padding-left: 6ex;">
3580 3767
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3581 3768
 
3582
-		if ($active < 600)
3583
-			echo '
3769
+		if ($active < 600) {
3770
+					echo '
3584 3771
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3772
+		}
3585 3773
 
3586
-		if ($active > $upcontext['inactive_timeout'])
3587
-			echo '
3774
+		if ($active > $upcontext['inactive_timeout']) {
3775
+					echo '
3588 3776
 				<br><br>You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.';
3589
-		else
3590
-			echo '
3777
+		} else {
3778
+					echo '
3591 3779
 				<br><br>This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3780
+		}
3592 3781
 
3593 3782
 		echo '
3594 3783
 			</div>
@@ -3604,9 +3793,10 @@  discard block
 block discarded – undo
3604 3793
 					<td>
3605 3794
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3606 3795
 
3607
-	if (!empty($upcontext['username_incorrect']))
3608
-		echo '
3796
+	if (!empty($upcontext['username_incorrect'])) {
3797
+			echo '
3609 3798
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3799
+	}
3610 3800
 
3611 3801
 	echo '
3612 3802
 					</td>
@@ -3617,9 +3807,10 @@  discard block
 block discarded – undo
3617 3807
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3618 3808
 						<input type="hidden" name="hash_passwrd" value="">';
3619 3809
 
3620
-	if (!empty($upcontext['password_failed']))
3621
-		echo '
3810
+	if (!empty($upcontext['password_failed'])) {
3811
+			echo '
3622 3812
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3813
+	}
3623 3814
 
3624 3815
 	echo '
3625 3816
 					</td>
@@ -3690,8 +3881,8 @@  discard block
 block discarded – undo
3690 3881
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3691 3882
 
3692 3883
 	// Warning message?
3693
-	if (!empty($upcontext['upgrade_options_warning']))
3694
-		echo '
3884
+	if (!empty($upcontext['upgrade_options_warning'])) {
3885
+			echo '
3695 3886
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3696 3887
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3697 3888
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3699,6 +3890,7 @@  discard block
 block discarded – undo
3699 3890
 				', $upcontext['upgrade_options_warning'], '
3700 3891
 			</div>
3701 3892
 		</div>';
3893
+	}
3702 3894
 
3703 3895
 	echo '
3704 3896
 				<table>
@@ -3741,8 +3933,8 @@  discard block
 block discarded – undo
3741 3933
 						</td>
3742 3934
 					</tr>';
3743 3935
 
3744
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3745
-		echo '
3936
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3937
+			echo '
3746 3938
 					<tr valign="top">
3747 3939
 						<td width="2%">
3748 3940
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3751,6 +3943,7 @@  discard block
 block discarded – undo
3751 3943
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3752 3944
 						</td>
3753 3945
 					</tr>';
3946
+	}
3754 3947
 
3755 3948
 	echo '
3756 3949
 					<tr valign="top">
@@ -3788,10 +3981,11 @@  discard block
 block discarded – undo
3788 3981
 			</div>';
3789 3982
 
3790 3983
 	// Dont any tables so far?
3791
-	if (!empty($upcontext['previous_tables']))
3792
-		foreach ($upcontext['previous_tables'] as $table)
3984
+	if (!empty($upcontext['previous_tables'])) {
3985
+			foreach ($upcontext['previous_tables'] as $table)
3793 3986
 			echo '
3794 3987
 			<br>Completed Table: &quot;', $table, '&quot;.';
3988
+	}
3795 3989
 
3796 3990
 	echo '
3797 3991
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3828,12 +4022,13 @@  discard block
 block discarded – undo
3828 4022
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3829 4023
 
3830 4024
 		// If debug flood the screen.
3831
-		if ($is_debug)
3832
-			echo '
4025
+		if ($is_debug) {
4026
+					echo '
3833 4027
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3834 4028
 
3835 4029
 				if (document.getElementById(\'debug_section\').scrollHeight)
3836 4030
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4031
+		}
3837 4032
 
3838 4033
 		echo '
3839 4034
 				// Get the next update...
@@ -3865,8 +4060,9 @@  discard block
 block discarded – undo
3865 4060
 {
3866 4061
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3867 4062
 
3868
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3869
-		$is_debug = true;
4063
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4064
+			$is_debug = true;
4065
+	}
3870 4066
 
3871 4067
 	echo '
3872 4068
 		<h3>Executing database changes</h3>
@@ -3881,8 +4077,9 @@  discard block
 block discarded – undo
3881 4077
 	{
3882 4078
 		foreach ($upcontext['actioned_items'] as $num => $item)
3883 4079
 		{
3884
-			if ($num != 0)
3885
-				echo ' Successful!';
4080
+			if ($num != 0) {
4081
+							echo ' Successful!';
4082
+			}
3886 4083
 			echo '<br>' . $item;
3887 4084
 		}
3888 4085
 		if (!empty($upcontext['changes_complete']))
@@ -3895,28 +4092,32 @@  discard block
 block discarded – undo
3895 4092
 				$seconds = intval($active % 60);
3896 4093
 
3897 4094
 				$totalTime = '';
3898
-				if ($hours > 0)
3899
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3900
-				if ($minutes > 0)
3901
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3902
-				if ($seconds > 0)
3903
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4095
+				if ($hours > 0) {
4096
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4097
+				}
4098
+				if ($minutes > 0) {
4099
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4100
+				}
4101
+				if ($seconds > 0) {
4102
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4103
+				}
3904 4104
 			}
3905 4105
 
3906
-			if ($is_debug && !empty($totalTime))
3907
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3908
-			else
3909
-				echo ' Successful!<br><br>';
4106
+			if ($is_debug && !empty($totalTime)) {
4107
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4108
+			} else {
4109
+							echo ' Successful!<br><br>';
4110
+			}
3910 4111
 
3911 4112
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3912 4113
 		}
3913
-	}
3914
-	else
4114
+	} else
3915 4115
 	{
3916 4116
 		// Tell them how many files we have in total.
3917
-		if ($upcontext['file_count'] > 1)
3918
-			echo '
4117
+		if ($upcontext['file_count'] > 1) {
4118
+					echo '
3919 4119
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4120
+		}
3920 4121
 
3921 4122
 		echo '
3922 4123
 		<h3 id="info2"><strong>Executing:</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> of <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -3932,19 +4133,23 @@  discard block
 block discarded – undo
3932 4133
 				$seconds = intval($active % 60);
3933 4134
 
3934 4135
 				$totalTime = '';
3935
-				if ($hours > 0)
3936
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3937
-				if ($minutes > 0)
3938
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3939
-				if ($seconds > 0)
3940
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4136
+				if ($hours > 0) {
4137
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4138
+				}
4139
+				if ($minutes > 0) {
4140
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4141
+				}
4142
+				if ($seconds > 0) {
4143
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4144
+				}
3941 4145
 			}
3942 4146
 
3943 4147
 			echo '
3944 4148
 			<br><span id="upgradeCompleted">';
3945 4149
 
3946
-			if (!empty($totalTime))
3947
-				echo 'Completed in ', $totalTime, '<br>';
4150
+			if (!empty($totalTime)) {
4151
+							echo 'Completed in ', $totalTime, '<br>';
4152
+			}
3948 4153
 
3949 4154
 			echo '</span>
3950 4155
 			<div id="debug_section" style="height: 200px; overflow: auto;">
@@ -3981,9 +4186,10 @@  discard block
 block discarded – undo
3981 4186
 			var getData = "";
3982 4187
 			var debugItems = ', $upcontext['debug_items'], ';';
3983 4188
 
3984
-		if ($is_debug)
3985
-			echo '
4189
+		if ($is_debug) {
4190
+					echo '
3986 4191
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4192
+		}
3987 4193
 
3988 4194
 		echo '
3989 4195
 			function getNextItem()
@@ -4023,9 +4229,10 @@  discard block
 block discarded – undo
4023 4229
 						document.getElementById("error_block").style.display = "";
4024 4230
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4025 4231
 
4026
-	if ($is_debug)
4027
-		echo '
4232
+	if ($is_debug) {
4233
+			echo '
4028 4234
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4235
+	}
4029 4236
 
4030 4237
 	echo '
4031 4238
 					}
@@ -4046,9 +4253,10 @@  discard block
 block discarded – undo
4046 4253
 						document.getElementById("error_block").style.display = "";
4047 4254
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4048 4255
 
4049
-	if ($is_debug)
4050
-		echo '
4256
+	if ($is_debug) {
4257
+			echo '
4051 4258
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4259
+	}
4052 4260
 
4053 4261
 	echo '
4054 4262
 					}
@@ -4107,8 +4315,8 @@  discard block
 block discarded – undo
4107 4315
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4108 4316
 				{';
4109 4317
 
4110
-		if ($is_debug)
4111
-			echo '
4318
+		if ($is_debug) {
4319
+					echo '
4112 4320
 					document.getElementById(\'debug_section\').style.display = "none";
4113 4321
 
4114 4322
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4126,6 +4334,7 @@  discard block
 block discarded – undo
4126 4334
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4127 4335
 
4128 4336
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4337
+		}
4129 4338
 
4130 4339
 		echo '
4131 4340
 
@@ -4133,9 +4342,10 @@  discard block
 block discarded – undo
4133 4342
 					document.getElementById(\'contbutt\').disabled = 0;
4134 4343
 					document.getElementById(\'database_done\').value = 1;';
4135 4344
 
4136
-		if ($upcontext['file_count'] > 1)
4137
-			echo '
4345
+		if ($upcontext['file_count'] > 1) {
4346
+					echo '
4138 4347
 					document.getElementById(\'info1\').style.display = "none";';
4348
+		}
4139 4349
 
4140 4350
 		echo '
4141 4351
 					document.getElementById(\'info2\').style.display = "none";
@@ -4148,9 +4358,10 @@  discard block
 block discarded – undo
4148 4358
 					lastItem = 0;
4149 4359
 					prevFile = curFile;';
4150 4360
 
4151
-		if ($is_debug)
4152
-			echo '
4361
+		if ($is_debug) {
4362
+					echo '
4153 4363
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4364
+		}
4154 4365
 
4155 4366
 		echo '
4156 4367
 					getNextItem();
@@ -4158,8 +4369,8 @@  discard block
 block discarded – undo
4158 4369
 				}';
4159 4370
 
4160 4371
 		// If debug scroll the screen.
4161
-		if ($is_debug)
4162
-			echo '
4372
+		if ($is_debug) {
4373
+					echo '
4163 4374
 				if (iLastSubStepProgress == -1)
4164 4375
 				{
4165 4376
 					// Give it consistent dots.
@@ -4178,6 +4389,7 @@  discard block
 block discarded – undo
4178 4389
 
4179 4390
 				if (document.getElementById(\'debug_section\').scrollHeight)
4180 4391
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4392
+		}
4181 4393
 
4182 4394
 		echo '
4183 4395
 				// Update the page.
@@ -4238,9 +4450,10 @@  discard block
 block discarded – undo
4238 4450
 			}';
4239 4451
 
4240 4452
 		// Start things off assuming we've not errored.
4241
-		if (empty($upcontext['error_message']))
4242
-			echo '
4453
+		if (empty($upcontext['error_message'])) {
4454
+					echo '
4243 4455
 			getNextItem();';
4456
+		}
4244 4457
 
4245 4458
 		echo '
4246 4459
 		</script>';
@@ -4257,18 +4470,21 @@  discard block
 block discarded – undo
4257 4470
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4258 4471
 	<debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>';
4259 4472
 
4260
-	if (!empty($upcontext['error_message']))
4261
-		echo '
4473
+	if (!empty($upcontext['error_message'])) {
4474
+			echo '
4262 4475
 	<error>', $upcontext['error_message'], '</error>';
4476
+	}
4263 4477
 
4264
-	if (!empty($upcontext['error_string']))
4265
-		echo '
4478
+	if (!empty($upcontext['error_string'])) {
4479
+			echo '
4266 4480
 	<sql>', $upcontext['error_string'], '</sql>';
4481
+	}
4267 4482
 
4268
-	if ($is_debug)
4269
-		echo '
4483
+	if ($is_debug) {
4484
+			echo '
4270 4485
 	<curtime>', time(), '</curtime>';
4271
-}
4486
+	}
4487
+	}
4272 4488
 
4273 4489
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4274 4490
 function template_convert_utf8()
@@ -4285,18 +4501,20 @@  discard block
 block discarded – undo
4285 4501
 			<span id="debuginfo"></span>';
4286 4502
 
4287 4503
 	// Done any tables so far?
4288
-	if (!empty($upcontext['previous_tables']))
4289
-		foreach ($upcontext['previous_tables'] as $table)
4504
+	if (!empty($upcontext['previous_tables'])) {
4505
+			foreach ($upcontext['previous_tables'] as $table)
4290 4506
 			echo '
4291 4507
 			<br>Completed Table: &quot;', $table, '&quot;.';
4508
+	}
4292 4509
 
4293 4510
 	echo '
4294 4511
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4295 4512
 
4296 4513
 	// If we dropped their index, let's let them know
4297
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
4298
-		echo '
4514
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
4515
+			echo '
4299 4516
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
4517
+	}
4300 4518
 
4301 4519
 	echo '
4302 4520
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Conversion Complete! Click Continue to Proceed.</span>';
@@ -4332,9 +4550,10 @@  discard block
 block discarded – undo
4332 4550
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4333 4551
 
4334 4552
 		// If debug flood the screen.
4335
-		if ($is_debug)
4336
-			echo '
4553
+		if ($is_debug) {
4554
+					echo '
4337 4555
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4556
+		}
4338 4557
 
4339 4558
 		echo '
4340 4559
 				// Get the next update...
@@ -4376,19 +4595,21 @@  discard block
 block discarded – undo
4376 4595
 			<span id="debuginfo"></span>';
4377 4596
 
4378 4597
 	// Dont any tables so far?
4379
-	if (!empty($upcontext['previous_tables']))
4380
-		foreach ($upcontext['previous_tables'] as $table)
4598
+	if (!empty($upcontext['previous_tables'])) {
4599
+			foreach ($upcontext['previous_tables'] as $table)
4381 4600
 			echo '
4382 4601
 			<br>Completed Table: &quot;', $table, '&quot;.';
4602
+	}
4383 4603
 
4384 4604
 	echo '
4385 4605
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4386 4606
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Convert to JSON Complete! Click Continue to Proceed.</span>';
4387 4607
 
4388 4608
 	// Try to make sure substep was reset.
4389
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4390
-		echo '
4609
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4610
+			echo '
4391 4611
 			<input type="hidden" name="substep" id="substep" value="0">';
4612
+	}
4392 4613
 
4393 4614
 	// Continue please!
4394 4615
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4421,9 +4642,10 @@  discard block
 block discarded – undo
4421 4642
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4422 4643
 
4423 4644
 		// If debug flood the screen.
4424
-		if ($is_debug)
4425
-			echo '
4645
+		if ($is_debug) {
4646
+					echo '
4426 4647
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4648
+		}
4427 4649
 
4428 4650
 		echo '
4429 4651
 				// Get the next update...
@@ -4458,8 +4680,8 @@  discard block
 block discarded – undo
4458 4680
 	<h3>That wasn\'t so hard, was it?  Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>.  Hope you like it!</h3>
4459 4681
 	<form action="', $boardurl, '/index.php">';
4460 4682
 
4461
-	if (!empty($upcontext['can_delete_script']))
4462
-		echo '
4683
+	if (!empty($upcontext['can_delete_script'])) {
4684
+			echo '
4463 4685
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em>
4464 4686
 			<script>
4465 4687
 				function doTheDelete(theCheck)
@@ -4471,6 +4693,7 @@  discard block
 block discarded – undo
4471 4693
 				}
4472 4694
 			</script>
4473 4695
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4696
+	}
4474 4697
 
4475 4698
 	$active = time() - $upcontext['started'];
4476 4699
 	$hours = floor($active / 3600);
@@ -4480,16 +4703,20 @@  discard block
 block discarded – undo
4480 4703
 	if ($is_debug)
4481 4704
 	{
4482 4705
 		$totalTime = '';
4483
-		if ($hours > 0)
4484
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4485
-		if ($minutes > 0)
4486
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4487
-		if ($seconds > 0)
4488
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4706
+		if ($hours > 0) {
4707
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4708
+		}
4709
+		if ($minutes > 0) {
4710
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4711
+		}
4712
+		if ($seconds > 0) {
4713
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4714
+		}
4489 4715
 	}
4490 4716
 
4491
-	if ($is_debug && !empty($totalTime))
4492
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4717
+	if ($is_debug && !empty($totalTime)) {
4718
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4719
+	}
4493 4720
 
4494 4721
 	echo '<br>
4495 4722
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="https://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -4516,8 +4743,9 @@  discard block
 block discarded – undo
4516 4743
 
4517 4744
 	$current_substep = $_GET['substep'];
4518 4745
 
4519
-	if (empty($_GET['a']))
4520
-		$_GET['a'] = 0;
4746
+	if (empty($_GET['a'])) {
4747
+			$_GET['a'] = 0;
4748
+	}
4521 4749
 	$step_progress['name'] = 'Converting ips';
4522 4750
 	$step_progress['current'] = $_GET['a'];
4523 4751
 
@@ -4560,16 +4788,19 @@  discard block
 block discarded – undo
4560 4788
 				'empty' => '',
4561 4789
 				'limit' => $limit,
4562 4790
 		));
4563
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4564
-			$arIp[] = $row[$oldCol];
4791
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4792
+					$arIp[] = $row[$oldCol];
4793
+		}
4565 4794
 		$smcFunc['db_free_result']($request);
4566 4795
 
4567 4796
 		// Special case, null ip could keep us in a loop.
4568
-		if (is_null($arIp[0]))
4569
-			unset($arIp[0]);
4797
+		if (is_null($arIp[0])) {
4798
+					unset($arIp[0]);
4799
+		}
4570 4800
 
4571
-		if (empty($arIp))
4572
-			$is_done = true;
4801
+		if (empty($arIp)) {
4802
+					$is_done = true;
4803
+		}
4573 4804
 
4574 4805
 		$updates = array();
4575 4806
 		$cases = array();
@@ -4578,16 +4809,18 @@  discard block
 block discarded – undo
4578 4809
 		{
4579 4810
 			$arIp[$i] = trim($arIp[$i]);
4580 4811
 
4581
-			if (empty($arIp[$i]))
4582
-				continue;
4812
+			if (empty($arIp[$i])) {
4813
+							continue;
4814
+			}
4583 4815
 
4584 4816
 			$updates['ip' . $i] = $arIp[$i];
4585 4817
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4586 4818
 
4587 4819
 			if ($setSize > 0 && $i % $setSize === 0)
4588 4820
 			{
4589
-				if (count($updates) == 1)
4590
-					continue;
4821
+				if (count($updates) == 1) {
4822
+									continue;
4823
+				}
4591 4824
 
4592 4825
 				$updates['whereSet'] = array_values($updates);
4593 4826
 				$smcFunc['db_query']('', '
@@ -4621,8 +4854,7 @@  discard block
 block discarded – undo
4621 4854
 							'ip' => $ip
4622 4855
 					));
4623 4856
 				}
4624
-			}
4625
-			else
4857
+			} else
4626 4858
 			{
4627 4859
 				$updates['whereSet'] = array_values($updates);
4628 4860
 				$smcFunc['db_query']('', '
@@ -4636,9 +4868,9 @@  discard block
 block discarded – undo
4636 4868
 					$updates
4637 4869
 				);
4638 4870
 			}
4871
+		} else {
4872
+					$is_done = true;
4639 4873
 		}
4640
-		else
4641
-			$is_done = true;
4642 4874
 
4643 4875
 		$_GET['a'] += $limit;
4644 4876
 		$step_progress['current'] = $_GET['a'];
@@ -4664,10 +4896,11 @@  discard block
 block discarded – undo
4664 4896
  
4665 4897
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4666 4898
 
4667
-	if (isset($columns[$column]))
4668
-		return $columns[$column];
4669
-	else
4670
-		return null;
4671
-}
4899
+	if (isset($columns[$column])) {
4900
+			return $columns[$column];
4901
+	} else {
4902
+			return null;
4903
+	}
4904
+	}
4672 4905
 
4673 4906
 ?>
4674 4907
\ No newline at end of file
Please login to merge, or discard this patch.