Completed
Push — release-2.1 ( e55abf...f15ab1 )
by
unknown
08:31
created
Sources/ScheduledTasks.php 1 patch
Braces   +277 added lines, -201 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * This function works out what to do!
@@ -24,9 +25,9 @@  discard block
 block discarded – undo
24 25
 	global $time_start, $smcFunc;
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
 
@@ -506,15 +531,17 @@  discard block
 block discarded – undo
506 531
 
507 532
 		// Store this useful data!
508 533
 		$boards[$row['id_board']] = $row['id_board'];
509
-		if ($row['id_topic'])
510
-			$notify['topics'][$row['id_topic']][] = $row['id_member'];
511
-		else
512
-			$notify['boards'][$row['id_board']][] = $row['id_member'];
534
+		if ($row['id_topic']) {
535
+					$notify['topics'][$row['id_topic']][] = $row['id_member'];
536
+		} else {
537
+					$notify['boards'][$row['id_board']][] = $row['id_member'];
538
+		}
513 539
 	}
514 540
 	$smcFunc['db_free_result']($request);
515 541
 
516
-	if (empty($boards))
517
-		return true;
542
+	if (empty($boards)) {
543
+			return true;
544
+	}
518 545
 
519 546
 	// Just get the board names.
520 547
 	$request = $smcFunc['db_query']('', '
@@ -526,12 +553,14 @@  discard block
 block discarded – undo
526 553
 		)
527 554
 	);
528 555
 	$boards = array();
529
-	while ($row = $smcFunc['db_fetch_assoc']($request))
530
-		$boards[$row['id_board']] = $row['name'];
556
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
557
+			$boards[$row['id_board']] = $row['name'];
558
+	}
531 559
 	$smcFunc['db_free_result']($request);
532 560
 
533
-	if (empty($boards))
534
-		return true;
561
+	if (empty($boards)) {
562
+			return true;
563
+	}
535 564
 
536 565
 	// Get the actual topics...
537 566
 	$request = $smcFunc['db_query']('', '
@@ -551,52 +580,57 @@  discard block
 block discarded – undo
551 580
 	$types = array();
552 581
 	while ($row = $smcFunc['db_fetch_assoc']($request))
553 582
 	{
554
-		if (!isset($types[$row['note_type']][$row['id_board']]))
555
-			$types[$row['note_type']][$row['id_board']] = array(
583
+		if (!isset($types[$row['note_type']][$row['id_board']])) {
584
+					$types[$row['note_type']][$row['id_board']] = array(
556 585
 				'lines' => array(),
557 586
 				'name' => $row['board_name'],
558 587
 				'id' => $row['id_board'],
559 588
 			);
589
+		}
560 590
 
561 591
 		if ($row['note_type'] == 'reply')
562 592
 		{
563
-			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
564
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
565
-			else
566
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
593
+			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
594
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
595
+			} else {
596
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
567 597
 					'id' => $row['id_topic'],
568 598
 					'subject' => un_htmlspecialchars($row['subject']),
569 599
 					'count' => 1,
570 600
 				);
571
-		}
572
-		elseif ($row['note_type'] == 'topic')
601
+			}
602
+		} elseif ($row['note_type'] == 'topic')
573 603
 		{
574
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
575
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
604
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
605
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
576 606
 					'id' => $row['id_topic'],
577 607
 					'subject' => un_htmlspecialchars($row['subject']),
578 608
 				);
579
-		}
580
-		else
609
+			}
610
+		} else
581 611
 		{
582
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
583
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
612
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
613
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
584 614
 					'id' => $row['id_topic'],
585 615
 					'subject' => un_htmlspecialchars($row['subject']),
586 616
 					'starter' => $row['id_member_started'],
587 617
 				);
618
+			}
588 619
 		}
589 620
 
590 621
 		$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
591
-		if (!empty($notify['topics'][$row['id_topic']]))
592
-			$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']]);
593
-		if (!empty($notify['boards'][$row['id_board']]))
594
-			$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']]);
622
+		if (!empty($notify['topics'][$row['id_topic']])) {
623
+					$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']]);
624
+		}
625
+		if (!empty($notify['boards'][$row['id_board']])) {
626
+					$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']]);
627
+		}
595 628
 	}
596 629
 	$smcFunc['db_free_result']($request);
597 630
 
598
-	if (empty($types))
599
-		return true;
631
+	if (empty($types)) {
632
+			return true;
633
+	}
600 634
 
601 635
 	// Let's load all the languages into a cache thingy.
602 636
 	$langtxt = array();
@@ -637,8 +671,9 @@  discard block
 block discarded – undo
637 671
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
638 672
 
639 673
 		// Did they not elect to choose this?
640
-		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
641
-			continue;
674
+		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
675
+					continue;
676
+		}
642 677
 
643 678
 		// Right character set!
644 679
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -654,39 +689,43 @@  discard block
 block discarded – undo
654 689
 		if (isset($types['topic']))
655 690
 		{
656 691
 			$titled = false;
657
-			foreach ($types['topic'] as $id => $board)
658
-				foreach ($board['lines'] as $topic)
692
+			foreach ($types['topic'] as $id => $board) {
693
+							foreach ($board['lines'] as $topic)
659 694
 					if (in_array($mid, $topic['members']))
660 695
 					{
661 696
 						if (!$titled)
662 697
 						{
663 698
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
699
+			}
664 700
 							$titled = true;
665 701
 						}
666 702
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
667 703
 					}
668
-			if ($titled)
669
-				$email['body'] .= "\n";
704
+			if ($titled) {
705
+							$email['body'] .= "\n";
706
+			}
670 707
 		}
671 708
 
672 709
 		// What about replies?
673 710
 		if (isset($types['reply']))
674 711
 		{
675 712
 			$titled = false;
676
-			foreach ($types['reply'] as $id => $board)
677
-				foreach ($board['lines'] as $topic)
713
+			foreach ($types['reply'] as $id => $board) {
714
+							foreach ($board['lines'] as $topic)
678 715
 					if (in_array($mid, $topic['members']))
679 716
 					{
680 717
 						if (!$titled)
681 718
 						{
682 719
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
720
+			}
683 721
 							$titled = true;
684 722
 						}
685 723
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
686 724
 					}
687 725
 
688
-			if ($titled)
689
-				$email['body'] .= "\n";
726
+			if ($titled) {
727
+							$email['body'] .= "\n";
728
+			}
690 729
 		}
691 730
 
692 731
 		// Finally, moderation actions!
@@ -695,24 +734,27 @@  discard block
 block discarded – undo
695 734
 			$titled = false;
696 735
 			foreach ($types as $note_type => $type)
697 736
 			{
698
-				if ($note_type == 'topic' || $note_type == 'reply')
699
-					continue;
737
+				if ($note_type == 'topic' || $note_type == 'reply') {
738
+									continue;
739
+				}
700 740
 
701
-				foreach ($type as $id => $board)
702
-					foreach ($board['lines'] as $topic)
741
+				foreach ($type as $id => $board) {
742
+									foreach ($board['lines'] as $topic)
703 743
 						if (in_array($mid, $topic['members']))
704 744
 						{
705 745
 							if (!$titled)
706 746
 							{
707 747
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
748
+				}
708 749
 								$titled = true;
709 750
 							}
710 751
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
711 752
 						}
712 753
 			}
713 754
 		}
714
-		if ($titled)
715
-			$email['body'] .= "\n";
755
+		if ($titled) {
756
+					$email['body'] .= "\n";
757
+		}
716 758
 
717 759
 		// Then just say our goodbyes!
718 760
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -740,8 +782,7 @@  discard block
 block discarded – undo
740 782
 				'not_daily' => 0,
741 783
 			)
742 784
 		);
743
-	}
744
-	else
785
+	} else
745 786
 	{
746 787
 		// Clear any only weekly ones, and stop us from sending daily again.
747 788
 		$smcFunc['db_query']('', '
@@ -803,16 +844,19 @@  discard block
 block discarded – undo
803 844
 	global $modSettings, $smcFunc, $sourcedir;
804 845
 
805 846
 	// Are we intending another script to be sending out the queue?
806
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
807
-		return false;
847
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
848
+			return false;
849
+	}
808 850
 
809 851
 	// By default send 5 at once.
810
-	if (!$number)
811
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
852
+	if (!$number) {
853
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
854
+	}
812 855
 
813 856
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
814
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
815
-		return false;
857
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
858
+			return false;
859
+	}
816 860
 
817 861
 	// By default move the next sending on by 10 seconds, and require an affected row.
818 862
 	if (!$override_limit)
@@ -829,8 +873,9 @@  discard block
 block discarded – undo
829 873
 				'last_send' => $modSettings['mail_next_send'],
830 874
 			)
831 875
 		);
832
-		if ($smcFunc['db_affected_rows']() == 0)
833
-			return false;
876
+		if ($smcFunc['db_affected_rows']() == 0) {
877
+					return false;
878
+		}
834 879
 		$modSettings['mail_next_send'] = time() + $delay;
835 880
 	}
836 881
 
@@ -851,8 +896,9 @@  discard block
 block discarded – undo
851 896
 			$mn += $number;
852 897
 		}
853 898
 		// No more I'm afraid, return!
854
-		else
855
-			return false;
899
+		else {
900
+					return false;
901
+		}
856 902
 
857 903
 		// Reflect that we're about to send some, do it now to be safe.
858 904
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -887,14 +933,15 @@  discard block
 block discarded – undo
887 933
 	$smcFunc['db_free_result']($request);
888 934
 
889 935
 	// Delete, delete, delete!!!
890
-	if (!empty($ids))
891
-		$smcFunc['db_query']('', '
936
+	if (!empty($ids)) {
937
+			$smcFunc['db_query']('', '
892 938
 			DELETE FROM {db_prefix}mail_queue
893 939
 			WHERE id_mail IN ({array_int:mail_list})',
894 940
 			array(
895 941
 				'mail_list' => $ids,
896 942
 			)
897 943
 		);
944
+	}
898 945
 
899 946
 	// Don't believe we have any left?
900 947
 	if (count($ids) < $number)
@@ -912,11 +959,13 @@  discard block
 block discarded – undo
912 959
 		);
913 960
 	}
914 961
 
915
-	if (empty($ids))
916
-		return false;
962
+	if (empty($ids)) {
963
+			return false;
964
+	}
917 965
 
918
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
919
-		require_once($sourcedir . '/Subs-Post.php');
966
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
967
+			require_once($sourcedir . '/Subs-Post.php');
968
+	}
920 969
 
921 970
 	// Send each email, yea!
922 971
 	$failed_emails = array();
@@ -936,15 +985,17 @@  discard block
 block discarded – undo
936 985
 
937 986
 			// Try to stop a timeout, this would be bad...
938 987
 			@set_time_limit(300);
939
-			if (function_exists('apache_reset_timeout'))
940
-				@apache_reset_timeout();
988
+			if (function_exists('apache_reset_timeout')) {
989
+							@apache_reset_timeout();
990
+			}
991
+		} else {
992
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
941 993
 		}
942
-		else
943
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
944 994
 
945 995
 		// Hopefully it sent?
946
-		if (!$result)
947
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
996
+		if (!$result) {
997
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
998
+		}
948 999
 	}
949 1000
 
950 1001
 	// Any emails that didn't send?
@@ -959,8 +1010,8 @@  discard block
 block discarded – undo
959 1010
 		);
960 1011
 
961 1012
 		// If we have failed to many times, tell mail to wait a bit and try again.
962
-		if ($modSettings['mail_failed_attempts'] > 5)
963
-			$smcFunc['db_query']('', '
1013
+		if ($modSettings['mail_failed_attempts'] > 5) {
1014
+					$smcFunc['db_query']('', '
964 1015
 				UPDATE {db_prefix}settings
965 1016
 				SET value = {string:next_mail_send}
966 1017
 				WHERE variable = {literal:mail_next_send}
@@ -969,6 +1020,7 @@  discard block
 block discarded – undo
969 1020
 					'next_mail_send' => time() + 60,
970 1021
 					'last_send' => $modSettings['mail_next_send'],
971 1022
 			));
1023
+		}
972 1024
 
973 1025
 		// Add our email back to the queue, manually.
974 1026
 		$smcFunc['db_insert']('insert',
@@ -981,8 +1033,8 @@  discard block
 block discarded – undo
981 1033
 		return false;
982 1034
 	}
983 1035
 	// We where unable to send the email, clear our failed attempts.
984
-	elseif (!empty($modSettings['mail_failed_attempts']))
985
-		$smcFunc['db_query']('', '
1036
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1037
+			$smcFunc['db_query']('', '
986 1038
 			UPDATE {db_prefix}settings
987 1039
 			SET value = {string:zero}
988 1040
 			WHERE variable = {string:mail_failed_attempts}',
@@ -990,6 +1042,7 @@  discard block
 block discarded – undo
990 1042
 				'zero' => '0',
991 1043
 				'mail_failed_attempts' => 'mail_failed_attempts',
992 1044
 		));
1045
+	}
993 1046
 
994 1047
 	// Had something to send...
995 1048
 	return true;
@@ -1006,16 +1059,18 @@  discard block
 block discarded – undo
1006 1059
 	global $modSettings, $smcFunc;
1007 1060
 
1008 1061
 	$task_query = '';
1009
-	if (!is_array($tasks))
1010
-		$tasks = array($tasks);
1062
+	if (!is_array($tasks)) {
1063
+			$tasks = array($tasks);
1064
+	}
1011 1065
 
1012 1066
 	// Actually have something passed?
1013 1067
 	if (!empty($tasks))
1014 1068
 	{
1015
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1016
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1017
-		else
1018
-			$task_query = ' AND task IN ({array_string:tasks})';
1069
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1070
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1071
+		} else {
1072
+					$task_query = ' AND task IN ({array_string:tasks})';
1073
+		}
1019 1074
 	}
1020 1075
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1021 1076
 
@@ -1036,20 +1091,22 @@  discard block
 block discarded – undo
1036 1091
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1037 1092
 
1038 1093
 		// Only bother moving the task if it's out of place or we're forcing it!
1039
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1040
-			$tasks[$row['id_task']] = $next_time;
1041
-		else
1042
-			$next_time = $row['next_time'];
1094
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1095
+					$tasks[$row['id_task']] = $next_time;
1096
+		} else {
1097
+					$next_time = $row['next_time'];
1098
+		}
1043 1099
 
1044 1100
 		// If this is sooner than the current next task, make this the next task.
1045
-		if ($next_time < $nextTaskTime)
1046
-			$nextTaskTime = $next_time;
1101
+		if ($next_time < $nextTaskTime) {
1102
+					$nextTaskTime = $next_time;
1103
+		}
1047 1104
 	}
1048 1105
 	$smcFunc['db_free_result']($request);
1049 1106
 
1050 1107
 	// Now make the changes!
1051
-	foreach ($tasks as $id => $time)
1052
-		$smcFunc['db_query']('', '
1108
+	foreach ($tasks as $id => $time) {
1109
+			$smcFunc['db_query']('', '
1053 1110
 			UPDATE {db_prefix}scheduled_tasks
1054 1111
 			SET next_time = {int:next_time}
1055 1112
 			WHERE id_task = {int:id_task}',
@@ -1058,11 +1115,13 @@  discard block
 block discarded – undo
1058 1115
 				'id_task' => $id,
1059 1116
 			)
1060 1117
 		);
1118
+	}
1061 1119
 
1062 1120
 	// If the next task is now different update.
1063
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1064
-		updateSettings(array('next_task_time' => $nextTaskTime));
1065
-}
1121
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1122
+			updateSettings(array('next_task_time' => $nextTaskTime));
1123
+	}
1124
+	}
1066 1125
 
1067 1126
 /**
1068 1127
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1075,8 +1134,9 @@  discard block
 block discarded – undo
1075 1134
 function next_time($regularity, $unit, $offset)
1076 1135
 {
1077 1136
 	// Just in case!
1078
-	if ($regularity == 0)
1079
-		$regularity = 2;
1137
+	if ($regularity == 0) {
1138
+			$regularity = 2;
1139
+	}
1080 1140
 
1081 1141
 	$curMin = date('i', time());
1082 1142
 
@@ -1086,15 +1146,16 @@  discard block
 block discarded – undo
1086 1146
 		$off = date('i', $offset);
1087 1147
 
1088 1148
 		// If it's now just pretend it ain't,
1089
-		if ($off == $curMin)
1090
-			$next_time = time() + $regularity;
1091
-		else
1149
+		if ($off == $curMin) {
1150
+					$next_time = time() + $regularity;
1151
+		} else
1092 1152
 		{
1093 1153
 			// Make sure that the offset is always in the past.
1094 1154
 			$off = $off > $curMin ? $off - 60 : $off;
1095 1155
 
1096
-			while ($off <= $curMin)
1097
-				$off += $regularity;
1156
+			while ($off <= $curMin) {
1157
+							$off += $regularity;
1158
+			}
1098 1159
 
1099 1160
 			// Now we know when the time should be!
1100 1161
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1114,11 +1175,13 @@  discard block
 block discarded – undo
1114 1175
 		// Default we'll jump in hours.
1115 1176
 		$applyOffset = 3600;
1116 1177
 		// 24 hours = 1 day.
1117
-		if ($unit == 'd')
1118
-			$applyOffset = 86400;
1178
+		if ($unit == 'd') {
1179
+					$applyOffset = 86400;
1180
+		}
1119 1181
 		// Otherwise a week.
1120
-		if ($unit == 'w')
1121
-			$applyOffset = 604800;
1182
+		if ($unit == 'w') {
1183
+					$applyOffset = 604800;
1184
+		}
1122 1185
 
1123 1186
 		$applyOffset *= $regularity;
1124 1187
 
@@ -1155,8 +1218,9 @@  discard block
 block discarded – undo
1155 1218
 		$settings[$row['variable']] = $row['value'];
1156 1219
 
1157 1220
 		// Is this the default theme?
1158
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1159
-			$settings['default_' . $row['variable']] = $row['value'];
1221
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1222
+					$settings['default_' . $row['variable']] = $row['value'];
1223
+		}
1160 1224
 	}
1161 1225
 	$smcFunc['db_free_result']($result);
1162 1226
 
@@ -1166,12 +1230,14 @@  discard block
 block discarded – undo
1166 1230
 		$settings['template_dirs'] = array($settings['theme_dir']);
1167 1231
 
1168 1232
 		// Based on theme (if there is one).
1169
-		if (!empty($settings['base_theme_dir']))
1170
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1233
+		if (!empty($settings['base_theme_dir'])) {
1234
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1235
+		}
1171 1236
 
1172 1237
 		// Lastly the default theme.
1173
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1174
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1238
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1239
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1240
+		}
1175 1241
 	}
1176 1242
 
1177 1243
 	// Assume we want this.
@@ -1318,8 +1384,9 @@  discard block
 block discarded – undo
1318 1384
 	// Ok should we prune the logs?
1319 1385
 	if (!empty($modSettings['pruningOptions']))
1320 1386
 	{
1321
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1322
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1387
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1388
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1389
+		}
1323 1390
 
1324 1391
 		if (!empty($modSettings['pruneErrorLog']))
1325 1392
 		{
@@ -1385,8 +1452,9 @@  discard block
 block discarded – undo
1385 1452
 				)
1386 1453
 			);
1387 1454
 
1388
-			while ($row = $smcFunc['db_fetch_row']($result))
1389
-				$reports[] = $row[0];
1455
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1456
+							$reports[] = $row[0];
1457
+			}
1390 1458
 
1391 1459
 			$smcFunc['db_free_result']($result);
1392 1460
 
@@ -1554,8 +1622,9 @@  discard block
 block discarded – undo
1554 1622
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1555 1623
 
1556 1624
 		// Send the actual email.
1557
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1558
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1625
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1626
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1627
+		}
1559 1628
 
1560 1629
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1561 1630
 		{
@@ -1578,18 +1647,19 @@  discard block
 block discarded – undo
1578 1647
 	}
1579 1648
 
1580 1649
 	// Insert the alerts if any
1581
-	if (!empty($alert_rows))
1582
-		$smcFunc['db_insert']('',
1650
+	if (!empty($alert_rows)) {
1651
+			$smcFunc['db_insert']('',
1583 1652
 			'{db_prefix}user_alerts',
1584 1653
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1585 1654
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1586 1655
 			$alert_rows,
1587 1656
 			array()
1588 1657
 		);
1658
+	}
1589 1659
 
1590 1660
 	// Mark the reminder as sent.
1591
-	if (!empty($subs_reminded))
1592
-		$smcFunc['db_query']('', '
1661
+	if (!empty($subs_reminded)) {
1662
+			$smcFunc['db_query']('', '
1593 1663
 			UPDATE {db_prefix}log_subscribed
1594 1664
 			SET reminder_sent = {int:reminder_sent}
1595 1665
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1598,6 +1668,7 @@  discard block
 block discarded – undo
1598 1668
 				'reminder_sent' => 1,
1599 1669
 			)
1600 1670
 		);
1671
+	}
1601 1672
 
1602 1673
 	return true;
1603 1674
 }
@@ -1613,13 +1684,13 @@  discard block
 block discarded – undo
1613 1684
 	// We need to know where this thing is going.
1614 1685
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1615 1686
 	{
1616
-		if (!is_array($modSettings['attachmentUploadDir']))
1617
-			$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1687
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1688
+					$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1689
+		}
1618 1690
 
1619 1691
 		// Just use the current path for temp files.
1620 1692
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1621
-	}
1622
-	else
1693
+	} else
1623 1694
 	{
1624 1695
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1625 1696
 	}
@@ -1638,14 +1709,16 @@  discard block
 block discarded – undo
1638 1709
 
1639 1710
 		while ($file = readdir($dir))
1640 1711
 		{
1641
-			if ($file == '.' || $file == '..')
1642
-				continue;
1712
+			if ($file == '.' || $file == '..') {
1713
+							continue;
1714
+			}
1643 1715
 
1644 1716
 			if (strpos($file, 'post_tmp_') !== false)
1645 1717
 			{
1646 1718
 				// Temp file is more than 5 hours old!
1647
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1648
-					@unlink($attach_dir . '/' . $file);
1719
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1720
+									@unlink($attach_dir . '/' . $file);
1721
+				}
1649 1722
 			}
1650 1723
 		}
1651 1724
 		closedir($dir);
@@ -1678,8 +1751,9 @@  discard block
 block discarded – undo
1678 1751
 		)
1679 1752
 	);
1680 1753
 
1681
-	while ($row = $smcFunc['db_fetch_row']($request))
1682
-		$topics[] = $row[0];
1754
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1755
+			$topics[] = $row[0];
1756
+	}
1683 1757
 	$smcFunc['db_free_result']($request);
1684 1758
 
1685 1759
 	// Zap, your gone
@@ -1699,8 +1773,9 @@  discard block
 block discarded – undo
1699 1773
 {
1700 1774
 	global $smcFunc, $sourcedir, $modSettings;
1701 1775
 
1702
-	if (empty($modSettings['drafts_keep_days']))
1703
-		return true;
1776
+	if (empty($modSettings['drafts_keep_days'])) {
1777
+			return true;
1778
+	}
1704 1779
 
1705 1780
 	// init
1706 1781
 	$drafts = array();
@@ -1718,8 +1793,9 @@  discard block
 block discarded – undo
1718 1793
 		)
1719 1794
 	);
1720 1795
 
1721
-	while ($row = $smcFunc['db_fetch_row']($request))
1722
-		$drafts[] = (int) $row[0];
1796
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1797
+			$drafts[] = (int) $row[0];
1798
+	}
1723 1799
 	$smcFunc['db_free_result']($request);
1724 1800
 
1725 1801
 	// If we have old one, remove them
Please login to merge, or discard this patch.
Sources/Attachments.php 1 patch
Braces   +102 added lines, -75 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 class Attachments
20 21
 {
@@ -70,16 +71,18 @@  discard block
 block discarded – undo
70 71
 
71 72
 		$this->_sa = !empty($_REQUEST['sa']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_REQUEST['sa'])) : false;
72 73
 
73
-		if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions))
74
-			$this->{$this->_sa}();
74
+		if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) {
75
+					$this->{$this->_sa}();
76
+		}
75 77
 
76 78
 		// Just send a generic message.
77
-		else
78
-			$this->setResponse(array(
79
+		else {
80
+					$this->setResponse(array(
79 81
 				'text' => $this->_sa == 'add' ? 'attach_error_title' :   'attached_file_deleted_error',
80 82
 				'type' => 'error',
81 83
 				'data' => false,
82 84
 			));
85
+		}
83 86
 
84 87
 		// Back to the future, oh, to the browser!
85 88
 		$this->sendResponse();
@@ -95,12 +98,13 @@  discard block
 block discarded – undo
95 98
 		$attachID = !empty($_REQUEST['attach']) && is_numeric($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : 0;
96 99
 
97 100
 		// Need something to work with.
98
-		if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID])))
99
-			return $this->setResponse(array(
101
+		if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) {
102
+					return $this->setResponse(array(
100 103
 				'text' => 'attached_file_deleted_error',
101 104
 				'type' => 'error',
102 105
 				'data' => false,
103 106
 			));
107
+		}
104 108
 
105 109
 		// Lets pass some params and see what happens :P
106 110
 		$affectedMessage = removeAttachments(array('id_attach' => $attachID), '', true, true);
@@ -119,19 +123,21 @@  discard block
 block discarded – undo
119 123
 	public function add()
120 124
 	{
121 125
 		// You gotta be able to post attachments.
122
-		if (!$this->_canPostAttachment)
123
-			return $this->setResponse(array(
126
+		if (!$this->_canPostAttachment) {
127
+					return $this->setResponse(array(
124 128
 				'text' => 'attached_file_cannot',
125 129
 				'type' => 'error',
126 130
 				'data' => false,
127 131
 			));
132
+		}
128 133
 
129 134
 		// Process them at once!
130 135
 		$this->processAttachments();
131 136
 
132 137
 		// The attachments was created and moved the the right folder, time to update the DB.
133
-		if (!empty($_SESSION['temp_attachments']))
134
-			$this->createAtttach();
138
+		if (!empty($_SESSION['temp_attachments'])) {
139
+					$this->createAtttach();
140
+		}
135 141
 
136 142
 		// Set the response.
137 143
 		$this->setResponse();
@@ -144,8 +150,9 @@  discard block
 block discarded – undo
144 150
 	{
145 151
 		global $context, $modSettings, $smcFunc, $user_info, $txt;
146 152
 
147
-		if (!isset($_FILES['attachment']['name']))
148
-			$_FILES['attachment']['tmp_name'] = array();
153
+		if (!isset($_FILES['attachment']['name'])) {
154
+					$_FILES['attachment']['tmp_name'] = array();
155
+		}
149 156
 
150 157
 		// If there are attachments, calculate the total size and how many.
151 158
 		$context['attachments']['total_size'] = 0;
@@ -155,25 +162,30 @@  discard block
 block discarded – undo
155 162
 		if (isset($_REQUEST['msg']))
156 163
 		{
157 164
 			$context['attachments']['quantity'] = count($context['current_attachments']);
158
-			foreach ($context['current_attachments'] as $attachment)
159
-				$context['attachments']['total_size'] += $attachment['size'];
165
+			foreach ($context['current_attachments'] as $attachment) {
166
+							$context['attachments']['total_size'] += $attachment['size'];
167
+			}
160 168
 		}
161 169
 
162 170
 		// A bit of house keeping first.
163
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
164
-			unset($_SESSION['temp_attachments']);
171
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
172
+					unset($_SESSION['temp_attachments']);
173
+		}
165 174
 
166 175
 		// Our infamous SESSION var, we are gonna have soo much fun with it!
167
-		if (!isset($_SESSION['temp_attachments']))
168
-			$_SESSION['temp_attachments'] = array();
176
+		if (!isset($_SESSION['temp_attachments'])) {
177
+					$_SESSION['temp_attachments'] = array();
178
+		}
169 179
 
170 180
 		// Make sure we're uploading to the right place.
171
-		if (!empty($modSettings['automanage_attachments']))
172
-			automanage_attachments_check_directory();
181
+		if (!empty($modSettings['automanage_attachments'])) {
182
+					automanage_attachments_check_directory();
183
+		}
173 184
 
174 185
 		// Is the attachments folder actually there?
175
-		if (!empty($context['dir_creation_error']))
176
-			$this->_generalErrors[] = $context['dir_creation_error'];
186
+		if (!empty($context['dir_creation_error'])) {
187
+					$this->_generalErrors[] = $context['dir_creation_error'];
188
+		}
177 189
 
178 190
 		// The current attach folder ha some issues...
179 191
 		elseif (!is_dir($this->_attchDir))
@@ -198,13 +210,12 @@  discard block
 block discarded – undo
198 210
 			);
199 211
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
200 212
 			$smcFunc['db_free_result']($request);
201
-		}
202
-
203
-		else
204
-			$context['attachments'] = array(
213
+		} else {
214
+					$context['attachments'] = array(
205 215
 				'quantity' => 0,
206 216
 				'total_size' => 0,
207 217
 			);
218
+		}
208 219
 
209 220
 		// Check for other general errors here.
210 221
 
@@ -212,9 +223,10 @@  discard block
 block discarded – undo
212 223
 		if (!empty($this->_generalErrors))
213 224
 		{
214 225
 			// And delete the files 'cos they ain't going nowhere.
215
-			foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
216
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
226
+			foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
227
+							if (file_exists($_FILES['attachment']['tmp_name'][$n]))
217 228
 					unlink($_FILES['attachment']['tmp_name'][$n]);
229
+			}
218 230
 
219 231
 			$_FILES['attachment']['tmp_name'] = array();
220 232
 
@@ -225,26 +237,29 @@  discard block
 block discarded – undo
225 237
 		// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
226 238
 		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
227 239
 		{
228
-			if ($_FILES['attachment']['name'][$n] == '')
229
-				continue;
240
+			if ($_FILES['attachment']['name'][$n] == '') {
241
+							continue;
242
+			}
230 243
 
231 244
 			// First, let's first check for PHP upload errors.
232 245
 			$errors = array();
233 246
 			if (!empty($_FILES['attachment']['error'][$n]))
234 247
 			{
235
-				if ($_FILES['attachment']['error'][$n] == 2)
236
-					$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
237
-
238
-				else
239
-					log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
248
+				if ($_FILES['attachment']['error'][$n] == 2) {
249
+									$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
250
+				} else {
251
+									log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
252
+				}
240 253
 
241 254
 				// Log this one, because...
242
-				if ($_FILES['attachment']['error'][$n] == 6)
243
-					log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
255
+				if ($_FILES['attachment']['error'][$n] == 6) {
256
+									log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
257
+				}
244 258
 
245 259
 				// Weird, no errors were cached, still fill out a generic one.
246
-				if (empty($errors))
247
-					$errors[] = 'attach_php_error';
260
+				if (empty($errors)) {
261
+									$errors[] = 'attach_php_error';
262
+				}
248 263
 			}
249 264
 
250 265
 			// Try to move and rename the file before doing any more checks on it.
@@ -256,8 +271,9 @@  discard block
 block discarded – undo
256 271
 			{
257 272
 				// The reported MIME type of the attachment might not be reliable.
258 273
 				// Fortunately, PHP 5.3+ lets us easily verify the real MIME type.
259
-				if (function_exists('mime_content_type'))
260
-					$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
274
+				if (function_exists('mime_content_type')) {
275
+									$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
276
+				}
261 277
 
262 278
 				$_SESSION['temp_attachments'][$attachID] = array(
263 279
 					'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -269,16 +285,18 @@  discard block
 block discarded – undo
269 285
 				);
270 286
 
271 287
 				// Move the file to the attachments folder with a temp name for now.
272
-				if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
273
-					smf_chmod($destName, 0644);
288
+				if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
289
+									smf_chmod($destName, 0644);
290
+				}
274 291
 
275 292
 				// This is madness!!
276 293
 				else
277 294
 				{
278 295
 					// File couldn't be moved.
279 296
 					$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
280
-					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
281
-						unlink($_FILES['attachment']['tmp_name'][$n]);
297
+					if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
298
+											unlink($_FILES['attachment']['tmp_name'][$n]);
299
+					}
282 300
 				}
283 301
 			}
284 302
 
@@ -291,13 +309,15 @@  discard block
 block discarded – undo
291 309
 					'errors' => $errors,
292 310
 				);
293 311
 
294
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
295
-					unlink($_FILES['attachment']['tmp_name'][$n]);
312
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
313
+									unlink($_FILES['attachment']['tmp_name'][$n]);
314
+				}
296 315
 			}
297 316
 
298 317
 			// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
299
-			if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
300
-				attachmentChecks($attachID);
318
+			if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
319
+							attachmentChecks($attachID);
320
+			}
301 321
 		}
302 322
 
303 323
 		// Mod authors, finally a hook to hang an alternate attachment upload system upon
@@ -344,14 +364,15 @@  discard block
 block discarded – undo
344 364
 
345 365
 					$_SESSION['already_attached'][$attachmentOptions['attachID']] = $attachmentOptions['attachID'];
346 366
 
347
-					if (!empty($attachmentOptions['thumb']))
348
-						$_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb'];
367
+					if (!empty($attachmentOptions['thumb'])) {
368
+											$_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb'];
369
+					}
349 370
 
350
-					if ($this->_msg)
351
-						assignAttachments($_SESSION['already_attached'], $this->_msg);
371
+					if ($this->_msg) {
372
+											assignAttachments($_SESSION['already_attached'], $this->_msg);
373
+					}
352 374
 				}
353
-			}
354
-			else
375
+			} else
355 376
 			{
356 377
 				// Sort out the errors for display and delete any associated files.
357 378
 				$log_these = array('attachments_no_create', 'attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file');
@@ -363,14 +384,16 @@  discard block
 block discarded – undo
363 384
 					if (!is_array($error))
364 385
 					{
365 386
 						$attachmentOptions['errors'][] = $txt[$error];
366
-						if (in_array($error, $log_these))
367
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
387
+						if (in_array($error, $log_these)) {
388
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
389
+						}
390
+					} else {
391
+											$attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]);
368 392
 					}
369
-					else
370
-						$attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]);
371 393
 				}
372
-				if (file_exists($attachment['tmp_name']))
373
-					unlink($attachment['tmp_name']);
394
+				if (file_exists($attachment['tmp_name'])) {
395
+									unlink($attachment['tmp_name']);
396
+				}
374 397
 			}
375 398
 
376 399
 			// You don't need to know.
@@ -382,8 +405,9 @@  discard block
 block discarded – undo
382 405
 		}
383 406
 
384 407
 		// Temp save this on the db.
385
-		if (!empty($_SESSION['already_attached']))
386
-			$this->_attachSuccess = $_SESSION['already_attached'];
408
+		if (!empty($_SESSION['already_attached'])) {
409
+					$this->_attachSuccess = $_SESSION['already_attached'];
410
+		}
387 411
 
388 412
 		unset($_SESSION['temp_attachments']);
389 413
 	}
@@ -403,14 +427,16 @@  discard block
 block discarded – undo
403 427
 		if ($this->_sa == 'add')
404 428
 		{
405 429
 			// Is there any generic errors? made some sense out of them!
406
-			if ($this->_generalErrors)
407
-				foreach ($this->_generalErrors as $k => $v)
430
+			if ($this->_generalErrors) {
431
+							foreach ($this->_generalErrors as $k => $v)
408 432
 					$this->_generalErrors[$k] = (is_array($v) ? vsprintf($txt[$v[0]], $v[1]) : $txt[$v]);
433
+			}
409 434
 
410 435
 			// Gotta urlencode the filename.
411
-			if ($this->_attachResults)
412
-				foreach ($this->_attachResults as $k => $v)
436
+			if ($this->_attachResults) {
437
+							foreach ($this->_attachResults as $k => $v)
413 438
 					$this->_attachResults[$k]['name'] =  urlencode($this->_attachResults[$k]['name']);
439
+			}
414 440
 
415 441
 			$this->_response = array(
416 442
 				'files' => $this->_attachResults ? $this->_attachResults : false,
@@ -419,9 +445,10 @@  discard block
 block discarded – undo
419 445
 		}
420 446
 
421 447
 		// Rest of us mere mortals gets no special treatment...
422
-		elseif (!empty($data))
423
-			if (!empty($data['text']) && !empty($txt[$data['text']]))
448
+		elseif (!empty($data)) {
449
+					if (!empty($data['text']) && !empty($txt[$data['text']]))
424 450
 				$this->_response['text'] = $txt[$data['text']];
451
+		}
425 452
 	}
426 453
 
427 454
 	protected function sendResponse()
@@ -430,11 +457,11 @@  discard block
 block discarded – undo
430 457
 
431 458
 		ob_end_clean();
432 459
 
433
-		if (!empty($modSettings['CompressedOutput']))
434
-			@ob_start('ob_gzhandler');
435
-
436
-		else
437
-			ob_start();
460
+		if (!empty($modSettings['CompressedOutput'])) {
461
+					@ob_start('ob_gzhandler');
462
+		} else {
463
+					ob_start();
464
+		}
438 465
 
439 466
 		// Set the header.
440 467
 		header('content-type: application/json; charset='. $context['character_set'] .'');
Please login to merge, or discard this patch.
Sources/Register.php 1 patch
Braces   +177 added lines, -128 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Begin the registration process.
@@ -29,19 +30,23 @@  discard block
 block discarded – undo
29 30
 	global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile;
30 31
 
31 32
 	// Is this an incoming AJAX check?
32
-	if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck')
33
-		return RegisterCheckUsername();
33
+	if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') {
34
+			return RegisterCheckUsername();
35
+	}
34 36
 
35 37
 	// Check if the administrator has it disabled.
36
-	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3')
37
-		fatal_lang_error('registration_disabled', false);
38
+	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') {
39
+			fatal_lang_error('registration_disabled', false);
40
+	}
38 41
 
39 42
 	// If this user is an admin - redirect them to the admin registration page.
40
-	if (allowedTo('moderate_forum') && !$user_info['is_guest'])
41
-		redirectexit('action=admin;area=regcenter;sa=register');
43
+	if (allowedTo('moderate_forum') && !$user_info['is_guest']) {
44
+			redirectexit('action=admin;area=regcenter;sa=register');
45
+	}
42 46
 	// You are not a guest, so you are a member - and members don't get to register twice!
43
-	elseif (empty($user_info['is_guest']))
44
-		redirectexit();
47
+	elseif (empty($user_info['is_guest'])) {
48
+			redirectexit();
49
+	}
45 50
 
46 51
 	loadLanguage('Login');
47 52
 	loadTemplate('Register');
@@ -82,16 +87,18 @@  discard block
 block discarded – undo
82 87
 		}
83 88
 	}
84 89
 	// Make sure they don't squeeze through without agreeing.
85
-	elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement'])
86
-		$current_step = 1;
90
+	elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) {
91
+			$current_step = 1;
92
+	}
87 93
 
88 94
 	// Show the user the right form.
89 95
 	$context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form';
90 96
 	$context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form'];
91 97
 
92 98
 	// Kinda need this.
93
-	if ($context['sub_template'] == 'registration_form')
94
-		loadJavaScriptFile('register.js', array('defer' => false), 'smf_register');
99
+	if ($context['sub_template'] == 'registration_form') {
100
+			loadJavaScriptFile('register.js', array('defer' => false), 'smf_register');
101
+	}
95 102
 
96 103
 	// Add the register chain to the link tree.
97 104
 	$context['linktree'][] = array(
@@ -100,24 +107,26 @@  discard block
 block discarded – undo
100 107
 	);
101 108
 
102 109
 	// Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one.
103
-	if (!isset($_SESSION['register']))
104
-		$_SESSION['register'] = array(
110
+	if (!isset($_SESSION['register'])) {
111
+			$_SESSION['register'] = array(
105 112
 			'timenow' => time(),
106 113
 			'limit' => 10, // minimum number of seconds required on this page for registration
107 114
 		);
108
-	else
109
-		$_SESSION['register']['timenow'] = time();
115
+	} else {
116
+			$_SESSION['register']['timenow'] = time();
117
+	}
110 118
 
111 119
 	// If you have to agree to the agreement, it needs to be fetched from the file.
112 120
 	if ($context['require_agreement'])
113 121
 	{
114 122
 		// Have we got a localized one?
115
-		if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt'))
116
-			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
117
-		elseif (file_exists($boarddir . '/agreement.txt'))
118
-			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
119
-		else
120
-			$context['agreement'] = '';
123
+		if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) {
124
+					$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
125
+		} elseif (file_exists($boarddir . '/agreement.txt')) {
126
+					$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
127
+		} else {
128
+					$context['agreement'] = '';
129
+		}
121 130
 
122 131
 		// Nothing to show, lets disable registration and inform the admin of this error
123 132
 		if (empty($context['agreement']))
@@ -133,8 +142,9 @@  discard block
 block discarded – undo
133 142
 		$selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language'];
134 143
 
135 144
 		// Do we have any languages?
136
-		if (empty($context['languages']))
137
-			getLanguages();
145
+		if (empty($context['languages'])) {
146
+					getLanguages();
147
+		}
138 148
 
139 149
 		// Try to find our selected language.
140 150
 		foreach ($context['languages'] as $key => $lang)
@@ -142,8 +152,9 @@  discard block
 block discarded – undo
142 152
 			$context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => ''));
143 153
 
144 154
 			// Found it!
145
-			if ($selectedLanguage == $lang['filename'])
146
-				$context['languages'][$key]['selected'] = true;
155
+			if ($selectedLanguage == $lang['filename']) {
156
+							$context['languages'][$key]['selected'] = true;
157
+			}
147 158
 		}
148 159
 	}
149 160
 
@@ -170,16 +181,19 @@  discard block
 block discarded – undo
170 181
 		if (in_array('website', $reg_fields))
171 182
 		{
172 183
 			unset($reg_fields['website']);
173
-			if (isset($_POST['website_title']))
174
-				$cur_profile['website_title'] = $smcFunc['htmlspecialchars']($_POST['website_title']);
175
-			if (isset($_POST['website_url']))
176
-				$cur_profile['website_url'] = $smcFunc['htmlspecialchars']($_POST['website_url']);
184
+			if (isset($_POST['website_title'])) {
185
+							$cur_profile['website_title'] = $smcFunc['htmlspecialchars']($_POST['website_title']);
186
+			}
187
+			if (isset($_POST['website_url'])) {
188
+							$cur_profile['website_url'] = $smcFunc['htmlspecialchars']($_POST['website_url']);
189
+			}
177 190
 		}
178 191
 				
179 192
 		// We might have had some submissions on this front - go check.
180
-		foreach ($reg_fields as $field)
181
-			if (isset($_POST[$field]))
193
+		foreach ($reg_fields as $field) {
194
+					if (isset($_POST[$field]))
182 195
 				$cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]);
196
+		}
183 197
 
184 198
 		// Load all the fields in question.
185 199
 		setupProfileContext($reg_fields);
@@ -196,8 +210,9 @@  discard block
 block discarded – undo
196 210
 		$context['visual_verification_id'] = $verificationOptions['id'];
197 211
 	}
198 212
 	// Otherwise we have nothing to show.
199
-	else
200
-		$context['visual_verification'] = false;
213
+	else {
214
+			$context['visual_verification'] = false;
215
+	}
201 216
 
202 217
 
203 218
 	$context += array(
@@ -208,8 +223,9 @@  discard block
 block discarded – undo
208 223
 
209 224
 	// Were there any errors?
210 225
 	$context['registration_errors'] = array();
211
-	if (!empty($reg_errors))
212
-		$context['registration_errors'] = $reg_errors;
226
+	if (!empty($reg_errors)) {
227
+			$context['registration_errors'] = $reg_errors;
228
+	}
213 229
 
214 230
 	createToken('register');
215 231
 }
@@ -226,27 +242,32 @@  discard block
 block discarded – undo
226 242
 	validateToken('register');
227 243
 
228 244
 	// Check to ensure we're forcing SSL for authentication
229
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
230
-		fatal_lang_error('register_ssl_required');
245
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
246
+			fatal_lang_error('register_ssl_required');
247
+	}
231 248
 
232 249
 	// Start collecting together any errors.
233 250
 	$reg_errors = array();
234 251
 
235 252
 	// You can't register if it's disabled.
236
-	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3)
237
-		fatal_lang_error('registration_disabled', false);
253
+	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) {
254
+			fatal_lang_error('registration_disabled', false);
255
+	}
238 256
 
239 257
 	// Well, if you don't agree, you can't register.
240
-	if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed']))
241
-		redirectexit();
258
+	if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) {
259
+			redirectexit();
260
+	}
242 261
 
243 262
 	// Make sure they came from *somewhere*, have a session.
244
-	if (!isset($_SESSION['old_url']))
245
-		redirectexit('action=signup');
263
+	if (!isset($_SESSION['old_url'])) {
264
+			redirectexit('action=signup');
265
+	}
246 266
 
247 267
 	// If we don't require an agreement, we need a extra check for coppa.
248
-	if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge']))
249
-		$_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']);
268
+	if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) {
269
+			$_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']);
270
+	}
250 271
 	// Are they under age, and under age users are banned?
251 272
 	if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa']))
252 273
 	{
@@ -255,8 +276,9 @@  discard block
 block discarded – undo
255 276
 	}
256 277
 
257 278
 	// Check the time gate for miscreants. First make sure they came from somewhere that actually set it up.
258
-	if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit']))
259
-		redirectexit('action=signup');
279
+	if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) {
280
+			redirectexit('action=signup');
281
+	}
260 282
 	// Failing that, check the time on it.
261 283
 	if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit'])
262 284
 	{
@@ -276,15 +298,17 @@  discard block
 block discarded – undo
276 298
 		if (is_array($context['visual_verification']))
277 299
 		{
278 300
 			loadLanguage('Errors');
279
-			foreach ($context['visual_verification'] as $error)
280
-				$reg_errors[] = $txt['error_' . $error];
301
+			foreach ($context['visual_verification'] as $error) {
302
+							$reg_errors[] = $txt['error_' . $error];
303
+			}
281 304
 		}
282 305
 	}
283 306
 
284 307
 	foreach ($_POST as $key => $value)
285 308
 	{
286
-		if (!is_array($_POST[$key]))
287
-			$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
309
+		if (!is_array($_POST[$key])) {
310
+					$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
311
+		}
288 312
 	}
289 313
 
290 314
 	// Collect all extra registration fields someone might have filled in.
@@ -314,12 +338,14 @@  discard block
 block discarded – undo
314 338
 		$reg_fields = explode(',', $modSettings['registration_fields']);
315 339
 
316 340
 		// Website is a little different
317
-		if (in_array('website', $reg_fields))
318
-			$possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings);
341
+		if (in_array('website', $reg_fields)) {
342
+					$possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings);
343
+		}
319 344
 	}
320 345
 
321
-	if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '')
322
-		$_POST['secret_answer'] = md5($_POST['secret_answer']);
346
+	if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') {
347
+			$_POST['secret_answer'] = md5($_POST['secret_answer']);
348
+	}
323 349
 
324 350
 	// Needed for isReservedName() and registerMember().
325 351
 	require_once($sourcedir . '/Subs-Members.php');
@@ -328,8 +354,9 @@  discard block
 block discarded – undo
328 354
 	if (isset($_POST['real_name']))
329 355
 	{
330 356
 		// Are you already allowed to edit the displayed name?
331
-		if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum'))
332
-			$canEditDisplayName = true;
357
+		if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) {
358
+					$canEditDisplayName = true;
359
+		}
333 360
 
334 361
 		// If you are a guest, will you be allowed to once you register?
335 362
 		else
@@ -353,33 +380,38 @@  discard block
 block discarded – undo
353 380
 			$_POST['real_name'] = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $_POST['real_name']));
354 381
 
355 382
 			// Only set it if we are sure it is good
356
-			if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60)
357
-				$possible_strings[] = 'real_name';
383
+			if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) {
384
+							$possible_strings[] = 'real_name';
385
+			}
358 386
 		}
359 387
 	}
360 388
 
361 389
 	// Handle a string as a birthdate...
362
-	if (isset($_POST['birthdate']) && $_POST['birthdate'] != '')
363
-		$_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate']));
390
+	if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') {
391
+			$_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate']));
392
+	}
364 393
 	// Or birthdate parts...
365
-	elseif (!empty($_POST['bday1']) && !empty($_POST['bday2']))
366
-		$_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']);
394
+	elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) {
395
+			$_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']);
396
+	}
367 397
 
368 398
 	// Validate the passed language file.
369 399
 	if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage']))
370 400
 	{
371 401
 		// Do we have any languages?
372
-		if (empty($context['languages']))
373
-			getLanguages();
402
+		if (empty($context['languages'])) {
403
+					getLanguages();
404
+		}
374 405
 
375 406
 		// Did we find it?
376
-		if (isset($context['languages'][$_POST['lngfile']]))
377
-			$_SESSION['language'] = $_POST['lngfile'];
378
-		else
407
+		if (isset($context['languages'][$_POST['lngfile']])) {
408
+					$_SESSION['language'] = $_POST['lngfile'];
409
+		} else {
410
+					unset($_POST['lngfile']);
411
+		}
412
+	} else {
379 413
 			unset($_POST['lngfile']);
380 414
 	}
381
-	else
382
-		unset($_POST['lngfile']);
383 415
 
384 416
 	// Set the options needed for registration.
385 417
 	$regOptions = array(
@@ -399,22 +431,27 @@  discard block
 block discarded – undo
399 431
 	);
400 432
 
401 433
 	// Include the additional options that might have been filled in.
402
-	foreach ($possible_strings as $var)
403
-		if (isset($_POST[$var]))
434
+	foreach ($possible_strings as $var) {
435
+			if (isset($_POST[$var]))
404 436
 			$regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES);
405
-	foreach ($possible_ints as $var)
406
-		if (isset($_POST[$var]))
437
+	}
438
+	foreach ($possible_ints as $var) {
439
+			if (isset($_POST[$var]))
407 440
 			$regOptions['extra_register_vars'][$var] = (int) $_POST[$var];
408
-	foreach ($possible_floats as $var)
409
-		if (isset($_POST[$var]))
441
+	}
442
+	foreach ($possible_floats as $var) {
443
+			if (isset($_POST[$var]))
410 444
 			$regOptions['extra_register_vars'][$var] = (float) $_POST[$var];
411
-	foreach ($possible_bools as $var)
412
-		if (isset($_POST[$var]))
445
+	}
446
+	foreach ($possible_bools as $var) {
447
+			if (isset($_POST[$var]))
413 448
 			$regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1;
449
+	}
414 450
 
415 451
 	// Registration options are always default options...
416
-	if (isset($_POST['default_options']))
417
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
452
+	if (isset($_POST['default_options'])) {
453
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
454
+	}
418 455
 	$regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array();
419 456
 
420 457
 	// Make sure they are clean, dammit!
@@ -434,12 +471,14 @@  discard block
 block discarded – undo
434 471
 	while ($row = $smcFunc['db_fetch_assoc']($request))
435 472
 	{
436 473
 		// Don't allow overriding of the theme variables.
437
-		if (isset($regOptions['theme_vars'][$row['col_name']]))
438
-			unset($regOptions['theme_vars'][$row['col_name']]);
474
+		if (isset($regOptions['theme_vars'][$row['col_name']])) {
475
+					unset($regOptions['theme_vars'][$row['col_name']]);
476
+		}
439 477
 
440 478
 		// Not actually showing it then?
441
-		if (!$row['show_reg'])
442
-			continue;
479
+		if (!$row['show_reg']) {
480
+					continue;
481
+		}
443 482
 
444 483
 		// Prepare the value!
445 484
 		$value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : '';
@@ -448,24 +487,27 @@  discard block
 block discarded – undo
448 487
 		if (!in_array($row['field_type'], array('check', 'select', 'radio')))
449 488
 		{
450 489
 			// Is it too long?
451
-			if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value))
452
-				$custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length']));
490
+			if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) {
491
+							$custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length']));
492
+			}
453 493
 
454 494
 			// Any masks to apply?
455 495
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
456 496
 			{
457
-				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
458
-					$custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name']));
459
-				elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value))
460
-					$custom_field_errors[] = array('custom_field_not_number', array($row['field_name']));
461
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
462
-					$custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name']));
497
+				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) {
498
+									$custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name']));
499
+				} elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) {
500
+									$custom_field_errors[] = array('custom_field_not_number', array($row['field_name']));
501
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) {
502
+									$custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name']));
503
+				}
463 504
 			}
464 505
 		}
465 506
 
466 507
 		// Is this required but not there?
467
-		if (trim($value) == '' && $row['show_reg'] > 1)
468
-			$custom_field_errors[] = array('custom_field_empty', array($row['field_name']));
508
+		if (trim($value) == '' && $row['show_reg'] > 1) {
509
+					$custom_field_errors[] = array('custom_field_empty', array($row['field_name']));
510
+		}
469 511
 	}
470 512
 	$smcFunc['db_free_result']($request);
471 513
 
@@ -473,8 +515,9 @@  discard block
 block discarded – undo
473 515
 	if (!empty($custom_field_errors))
474 516
 	{
475 517
 		loadLanguage('Errors');
476
-		foreach ($custom_field_errors as $error)
477
-			$reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]);
518
+		foreach ($custom_field_errors as $error) {
519
+					$reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]);
520
+		}
478 521
 	}
479 522
 
480 523
 	// Lets check for other errors before trying to register the member.
@@ -519,8 +562,9 @@  discard block
 block discarded – undo
519 562
 	}
520 563
 
521 564
 	// If COPPA has been selected then things get complicated, setup the template.
522
-	if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa']))
523
-		redirectexit('action=coppa;member=' . $memberID);
565
+	if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) {
566
+			redirectexit('action=coppa;member=' . $memberID);
567
+	}
524 568
 	// Basic template variable setup.
525 569
 	elseif (!empty($modSettings['registration_method']))
526 570
 	{
@@ -532,8 +576,7 @@  discard block
 block discarded – undo
532 576
 			'sub_template' => 'after',
533 577
 			'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration']
534 578
 		);
535
-	}
536
-	else
579
+	} else
537 580
 	{
538 581
 		call_integration_hook('integrate_activate', array($regOptions['username']));
539 582
 
@@ -553,16 +596,18 @@  discard block
 block discarded – undo
553 596
 	global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info;
554 597
 
555 598
 	// Logged in users should not bother to activate their accounts
556
-	if (!empty($user_info['id']))
557
-		redirectexit();
599
+	if (!empty($user_info['id'])) {
600
+			redirectexit();
601
+	}
558 602
 
559 603
 	loadLanguage('Login');
560 604
 	loadTemplate('Login');
561 605
 
562 606
 	if (empty($_REQUEST['u']) && empty($_POST['user']))
563 607
 	{
564
-		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3')
565
-			fatal_lang_error('no_access', false);
608
+		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') {
609
+					fatal_lang_error('no_access', false);
610
+		}
566 611
 
567 612
 		$context['member_id'] = 0;
568 613
 		$context['sub_template'] = 'resend';
@@ -602,11 +647,13 @@  discard block
 block discarded – undo
602 647
 	// Change their email address? (they probably tried a fake one first :P.)
603 648
 	if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2))
604 649
 	{
605
-		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3)
606
-			fatal_lang_error('no_access', false);
650
+		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) {
651
+					fatal_lang_error('no_access', false);
652
+		}
607 653
 
608
-		if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL))
609
-			fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false);
654
+		if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) {
655
+					fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false);
656
+		}
610 657
 
611 658
 		// Make sure their email isn't banned.
612 659
 		isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']);
@@ -622,8 +669,9 @@  discard block
 block discarded – undo
622 669
 			)
623 670
 		);
624 671
 
625
-		if ($smcFunc['db_num_rows']($request) != 0)
626
-			fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email'])));
672
+		if ($smcFunc['db_num_rows']($request) != 0) {
673
+					fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email'])));
674
+		}
627 675
 		$smcFunc['db_free_result']($request);
628 676
 
629 677
 		updateMemberData($row['id_member'], array('email_address' => $_POST['new_email']));
@@ -661,9 +709,9 @@  discard block
 block discarded – undo
661 709
 	// Quit if this code is not right.
662 710
 	if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code'])
663 711
 	{
664
-		if (!empty($row['is_activated']))
665
-			fatal_lang_error('already_activated', false);
666
-		elseif ($row['validation_code'] == '')
712
+		if (!empty($row['is_activated'])) {
713
+					fatal_lang_error('already_activated', false);
714
+		} elseif ($row['validation_code'] == '')
667 715
 		{
668 716
 			loadLanguage('Profile');
669 717
 			fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false);
@@ -713,8 +761,9 @@  discard block
 block discarded – undo
713 761
 	loadTemplate('Register');
714 762
 
715 763
 	// No User ID??
716
-	if (!isset($_GET['member']))
717
-		fatal_lang_error('no_access', false);
764
+	if (!isset($_GET['member'])) {
765
+			fatal_lang_error('no_access', false);
766
+	}
718 767
 
719 768
 	// Get the user details...
720 769
 	$request = $smcFunc['db_query']('', '
@@ -727,8 +776,9 @@  discard block
 block discarded – undo
727 776
 			'is_coppa' => 5,
728 777
 		)
729 778
 	);
730
-	if ($smcFunc['db_num_rows']($request) == 0)
731
-		fatal_lang_error('no_access', false);
779
+	if ($smcFunc['db_num_rows']($request) == 0) {
780
+			fatal_lang_error('no_access', false);
781
+	}
732 782
 	list ($username) = $smcFunc['db_fetch_row']($request);
733 783
 	$smcFunc['db_free_result']($request);
734 784
 
@@ -766,8 +816,7 @@  discard block
 block discarded – undo
766 816
 			echo $data;
767 817
 			obExit(false);
768 818
 		}
769
-	}
770
-	else
819
+	} else
771 820
 	{
772 821
 		$context += array(
773 822
 			'page_title' => $txt['coppa_title'],
@@ -820,8 +869,9 @@  discard block
 block discarded – undo
820 869
 	{
821 870
 		require_once($sourcedir . '/Subs-Graphics.php');
822 871
 
823
-		if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code))
824
-			header('HTTP/1.1 400 Bad Request');
872
+		if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) {
873
+					header('HTTP/1.1 400 Bad Request');
874
+		}
825 875
 
826 876
 		// Otherwise just show a pre-defined letter.
827 877
 		elseif (isset($_REQUEST['letter']))
@@ -839,14 +889,13 @@  discard block
 block discarded – undo
839 889
 			header('content-type: image/gif');
840 890
 			die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
841 891
 		}
842
-	}
843
-
844
-	elseif ($_REQUEST['format'] === '.wav')
892
+	} elseif ($_REQUEST['format'] === '.wav')
845 893
 	{
846 894
 		require_once($sourcedir . '/Subs-Sound.php');
847 895
 
848
-		if (!createWaveFile($code))
849
-			header('HTTP/1.1 400 Bad Request');
896
+		if (!createWaveFile($code)) {
897
+					header('HTTP/1.1 400 Bad Request');
898
+		}
850 899
 	}
851 900
 
852 901
 	// We all die one day...
Please login to merge, or discard this patch.
Sources/Security.php 1 patch
Braces   +258 added lines, -199 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Check if the user is who he/she says he is
@@ -42,12 +43,14 @@  discard block
 block discarded – undo
42 43
 	$refreshTime = isset($_GET['xml']) ? 4200 : 3600;
43 44
 
44 45
 	// Is the security option off?
45
-	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')]))
46
-		return;
46
+	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) {
47
+			return;
48
+	}
47 49
 
48 50
 	// Or are they already logged in?, Moderator or admin session is need for this area
49
-	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time()))
50
-		return;
51
+	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) {
52
+			return;
53
+	}
51 54
 
52 55
 	require_once($sourcedir . '/Subs-Auth.php');
53 56
 
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 	if (isset($_POST[$type . '_pass']))
56 59
 	{
57 60
 		// Check to ensure we're forcing SSL for authentication
58
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
59
-			fatal_lang_error('login_ssl_required');
61
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
62
+					fatal_lang_error('login_ssl_required');
63
+		}
60 64
 
61 65
 		checkSession();
62 66
 
@@ -72,17 +76,19 @@  discard block
 block discarded – undo
72 76
 	}
73 77
 
74 78
 	// Better be sure to remember the real referer
75
-	if (empty($_SESSION['request_referer']))
76
-		$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
77
-	elseif (empty($_POST))
78
-		unset($_SESSION['request_referer']);
79
+	if (empty($_SESSION['request_referer'])) {
80
+			$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
81
+	} elseif (empty($_POST)) {
82
+			unset($_SESSION['request_referer']);
83
+	}
79 84
 
80 85
 	// Need to type in a password for that, man.
81
-	if (!isset($_GET['xml']))
82
-		adminLogin($type);
83
-	else
84
-		return 'session_verify_fail';
85
-}
86
+	if (!isset($_GET['xml'])) {
87
+			adminLogin($type);
88
+	} else {
89
+			return 'session_verify_fail';
90
+	}
91
+	}
86 92
 
87 93
 /**
88 94
  * Require a user who is logged in. (not a guest.)
@@ -96,25 +102,30 @@  discard block
 block discarded – undo
96 102
 	global $user_info, $txt, $context, $scripturl, $modSettings;
97 103
 
98 104
 	// Luckily, this person isn't a guest.
99
-	if (!$user_info['is_guest'])
100
-		return;
105
+	if (!$user_info['is_guest']) {
106
+			return;
107
+	}
101 108
 
102 109
 	// Log what they were trying to do didn't work)
103
-	if (!empty($modSettings['who_enabled']))
104
-		$_GET['error'] = 'guest_login';
110
+	if (!empty($modSettings['who_enabled'])) {
111
+			$_GET['error'] = 'guest_login';
112
+	}
105 113
 	writeLog(true);
106 114
 
107 115
 	// Just die.
108
-	if (isset($_REQUEST['xml']))
109
-		obExit(false);
116
+	if (isset($_REQUEST['xml'])) {
117
+			obExit(false);
118
+	}
110 119
 
111 120
 	// Attempt to detect if they came from dlattach.
112
-	if (SMF != 'SSI' && empty($context['theme_loaded']))
113
-		loadTheme();
121
+	if (SMF != 'SSI' && empty($context['theme_loaded'])) {
122
+			loadTheme();
123
+	}
114 124
 
115 125
 	// Never redirect to an attachment
116
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
117
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
126
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
127
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
128
+	}
118 129
 
119 130
 	// Load the Login template and language file.
120 131
 	loadLanguage('Login');
@@ -124,8 +135,7 @@  discard block
 block discarded – undo
124 135
 	{
125 136
 		$_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING'];
126 137
 		redirectexit('action=login');
127
-	}
128
-	else
138
+	} else
129 139
 	{
130 140
 		loadTemplate('Login');
131 141
 		$context['sub_template'] = 'kick_guest';
@@ -155,8 +165,9 @@  discard block
 block discarded – undo
155 165
 	global $sourcedir, $cookiename, $user_settings, $smcFunc;
156 166
 
157 167
 	// You cannot be banned if you are an admin - doesn't help if you log out.
158
-	if ($user_info['is_admin'])
159
-		return;
168
+	if ($user_info['is_admin']) {
169
+			return;
170
+	}
160 171
 
161 172
 	// Only check the ban every so often. (to reduce load.)
162 173
 	if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email']))
@@ -177,8 +188,9 @@  discard block
 block discarded – undo
177 188
 		// Check both IP addresses.
178 189
 		foreach (array('ip', 'ip2') as $ip_number)
179 190
 		{
180
-			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip'])
181
-				continue;
191
+			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) {
192
+							continue;
193
+			}
182 194
 			$ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high';
183 195
 			$ban_query_vars[$ip_number] = $user_info[$ip_number];
184 196
 			// IP was valid, maybe there's also a hostname...
@@ -228,24 +240,28 @@  discard block
 block discarded – undo
228 240
 			// Store every type of ban that applies to you in your session.
229 241
 			while ($row = $smcFunc['db_fetch_assoc']($request))
230 242
 			{
231
-				foreach ($restrictions as $restriction)
232
-					if (!empty($row[$restriction]))
243
+				foreach ($restrictions as $restriction) {
244
+									if (!empty($row[$restriction]))
233 245
 					{
234 246
 						$_SESSION['ban'][$restriction]['reason'] = $row['reason'];
247
+				}
235 248
 						$_SESSION['ban'][$restriction]['ids'][] = $row['id_ban'];
236
-						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time'])))
237
-							$_SESSION['ban']['expire_time'] = $row['expire_time'];
249
+						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) {
250
+													$_SESSION['ban']['expire_time'] = $row['expire_time'];
251
+						}
238 252
 
239
-						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email']))
240
-							$flag_is_activated = true;
253
+						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) {
254
+													$flag_is_activated = true;
255
+						}
241 256
 					}
242 257
 			}
243 258
 			$smcFunc['db_free_result']($request);
244 259
 		}
245 260
 
246 261
 		// Mark the cannot_access and cannot_post bans as being 'hit'.
247
-		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login']))
248
-			log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
262
+		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) {
263
+					log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
264
+		}
249 265
 
250 266
 		// If for whatever reason the is_activated flag seems wrong, do a little work to clear it up.
251 267
 		if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated)
@@ -260,8 +276,9 @@  discard block
 block discarded – undo
260 276
 	if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_']))
261 277
 	{
262 278
 		$bans = explode(',', $_COOKIE[$cookiename . '_']);
263
-		foreach ($bans as $key => $value)
264
-			$bans[$key] = (int) $value;
279
+		foreach ($bans as $key => $value) {
280
+					$bans[$key] = (int) $value;
281
+		}
265 282
 		$request = $smcFunc['db_query']('', '
266 283
 			SELECT bi.id_ban, bg.reason
267 284
 			FROM {db_prefix}ban_items AS bi
@@ -297,14 +314,15 @@  discard block
 block discarded – undo
297 314
 	if (isset($_SESSION['ban']['cannot_access']))
298 315
 	{
299 316
 		// We don't wanna see you!
300
-		if (!$user_info['is_guest'])
301
-			$smcFunc['db_query']('', '
317
+		if (!$user_info['is_guest']) {
318
+					$smcFunc['db_query']('', '
302 319
 				DELETE FROM {db_prefix}log_online
303 320
 				WHERE id_member = {int:current_member}',
304 321
 				array(
305 322
 					'current_member' => $user_info['id'],
306 323
 				)
307 324
 			);
325
+		}
308 326
 
309 327
 		// 'Log' the user out.  Can't have any funny business... (save the name!)
310 328
 		$old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
@@ -390,9 +408,10 @@  discard block
 block discarded – undo
390 408
 	}
391 409
 
392 410
 	// Fix up the banning permissions.
393
-	if (isset($user_info['permissions']))
394
-		banPermissions();
395
-}
411
+	if (isset($user_info['permissions'])) {
412
+			banPermissions();
413
+	}
414
+	}
396 415
 
397 416
 /**
398 417
  * Fix permissions according to ban status.
@@ -403,8 +422,9 @@  discard block
 block discarded – undo
403 422
 	global $user_info, $sourcedir, $modSettings, $context;
404 423
 
405 424
 	// Somehow they got here, at least take away all permissions...
406
-	if (isset($_SESSION['ban']['cannot_access']))
407
-		$user_info['permissions'] = array();
425
+	if (isset($_SESSION['ban']['cannot_access'])) {
426
+			$user_info['permissions'] = array();
427
+	}
408 428
 	// Okay, well, you can watch, but don't touch a thing.
409 429
 	elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning']))
410 430
 	{
@@ -446,19 +466,20 @@  discard block
 block discarded – undo
446 466
 		call_integration_hook('integrate_warn_permissions', array(&$permission_change));
447 467
 		foreach ($permission_change as $old => $new)
448 468
 		{
449
-			if (!in_array($old, $user_info['permissions']))
450
-				unset($permission_change[$old]);
451
-			else
452
-				$user_info['permissions'][] = $new;
469
+			if (!in_array($old, $user_info['permissions'])) {
470
+							unset($permission_change[$old]);
471
+			} else {
472
+							$user_info['permissions'][] = $new;
473
+			}
453 474
 		}
454 475
 		$user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change));
455 476
 	}
456 477
 
457 478
 	// @todo Find a better place to call this? Needs to be after permissions loaded!
458 479
 	// Finally, some bits we cache in the session because it saves queries.
459
-	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id'])
460
-		$user_info['mod_cache'] = $_SESSION['mc'];
461
-	else
480
+	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) {
481
+			$user_info['mod_cache'] = $_SESSION['mc'];
482
+	} else
462 483
 	{
463 484
 		require_once($sourcedir . '/Subs-Auth.php');
464 485
 		rebuildModCache();
@@ -469,14 +490,12 @@  discard block
 block discarded – undo
469 490
 	{
470 491
 		$context['open_mod_reports'] = $_SESSION['rc']['reports'];
471 492
 		$context['open_member_reports'] = $_SESSION['rc']['member_reports'];
472
-	}
473
-	elseif ($_SESSION['mc']['bq'] != '0=1')
493
+	} elseif ($_SESSION['mc']['bq'] != '0=1')
474 494
 	{
475 495
 		require_once($sourcedir . '/Subs-ReportedContent.php');
476 496
 		$context['open_mod_reports'] = recountOpenReports('posts');
477 497
 		$context['open_member_reports'] = recountOpenReports('members');
478
-	}
479
-	else
498
+	} else
480 499
 	{
481 500
 		$context['open_mod_reports'] = 0;
482 501
 		$context['open_member_reports'] = 0;
@@ -496,8 +515,9 @@  discard block
 block discarded – undo
496 515
 	global $user_info, $smcFunc;
497 516
 
498 517
 	// Don't log web accelerators, it's very confusing...
499
-	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
500
-		return;
518
+	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
519
+			return;
520
+	}
501 521
 
502 522
 	$smcFunc['db_insert']('',
503 523
 		'{db_prefix}log_banned',
@@ -507,8 +527,8 @@  discard block
 block discarded – undo
507 527
 	);
508 528
 
509 529
 	// One extra point for these bans.
510
-	if (!empty($ban_ids))
511
-		$smcFunc['db_query']('', '
530
+	if (!empty($ban_ids)) {
531
+			$smcFunc['db_query']('', '
512 532
 			UPDATE {db_prefix}ban_items
513 533
 			SET hits = hits + 1
514 534
 			WHERE id_ban IN ({array_int:ban_ids})',
@@ -516,7 +536,8 @@  discard block
 block discarded – undo
516 536
 				'ban_ids' => $ban_ids,
517 537
 			)
518 538
 		);
519
-}
539
+	}
540
+	}
520 541
 
521 542
 /**
522 543
  * Checks if a given email address might be banned.
@@ -532,8 +553,9 @@  discard block
 block discarded – undo
532 553
 	global $txt, $smcFunc;
533 554
 
534 555
 	// Can't ban an empty email
535
-	if (empty($email) || trim($email) == '')
536
-		return;
556
+	if (empty($email) || trim($email) == '') {
557
+			return;
558
+	}
537 559
 
538 560
 	// Let's start with the bans based on your IP/hostname/memberID...
539 561
 	$ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array();
@@ -606,16 +628,18 @@  discard block
 block discarded – undo
606 628
 	if ($type == 'post')
607 629
 	{
608 630
 		$check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null);
609
-		if ($check !== $sc)
610
-			$error = 'session_timeout';
631
+		if ($check !== $sc) {
632
+					$error = 'session_timeout';
633
+		}
611 634
 	}
612 635
 
613 636
 	// How about $_GET['sesc']?
614 637
 	elseif ($type == 'get')
615 638
 	{
616 639
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null);
617
-		if ($check !== $sc)
618
-			$error = 'session_verify_fail';
640
+		if ($check !== $sc) {
641
+					$error = 'session_verify_fail';
642
+		}
619 643
 	}
620 644
 
621 645
 	// Or can it be in either?
@@ -623,13 +647,15 @@  discard block
 block discarded – undo
623 647
 	{
624 648
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null)));
625 649
 
626
-		if ($check !== $sc)
627
-			$error = 'session_verify_fail';
650
+		if ($check !== $sc) {
651
+					$error = 'session_verify_fail';
652
+		}
628 653
 	}
629 654
 
630 655
 	// Verify that they aren't changing user agents on us - that could be bad.
631
-	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA']))
632
-		$error = 'session_verify_fail';
656
+	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) {
657
+			$error = 'session_verify_fail';
658
+	}
633 659
 
634 660
 	// Make sure a page with session check requirement is not being prefetched.
635 661
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -640,30 +666,35 @@  discard block
 block discarded – undo
640 666
 	}
641 667
 
642 668
 	// Check the referring site - it should be the same server at least!
643
-	if (isset($_SESSION['request_referer']))
644
-		$referrer = $_SESSION['request_referer'];
645
-	else
646
-		$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
669
+	if (isset($_SESSION['request_referer'])) {
670
+			$referrer = $_SESSION['request_referer'];
671
+	} else {
672
+			$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
673
+	}
647 674
 	if (!empty($referrer['host']))
648 675
 	{
649
-		if (strpos($_SERVER['HTTP_HOST'], ':') !== false)
650
-			$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
651
-		else
652
-			$real_host = $_SERVER['HTTP_HOST'];
676
+		if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
677
+					$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
678
+		} else {
679
+					$real_host = $_SERVER['HTTP_HOST'];
680
+		}
653 681
 
654 682
 		$parsed_url = parse_url($boardurl);
655 683
 
656 684
 		// Are global cookies on?  If so, let's check them ;).
657 685
 		if (!empty($modSettings['globalCookies']))
658 686
 		{
659
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
660
-				$parsed_url['host'] = $parts[1];
687
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
688
+							$parsed_url['host'] = $parts[1];
689
+			}
661 690
 
662
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1)
663
-				$referrer['host'] = $parts[1];
691
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) {
692
+							$referrer['host'] = $parts[1];
693
+			}
664 694
 
665
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1)
666
-				$real_host = $parts[1];
695
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) {
696
+							$real_host = $parts[1];
697
+			}
667 698
 		}
668 699
 
669 700
 		// Okay: referrer must either match parsed_url or real_host.
@@ -681,12 +712,14 @@  discard block
 block discarded – undo
681 712
 		$log_error = true;
682 713
 	}
683 714
 
684
-	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker')
685
-		fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
715
+	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') {
716
+			fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
717
+	}
686 718
 
687 719
 	// Everything is ok, return an empty string.
688
-	if (!isset($error))
689
-		return '';
720
+	if (!isset($error)) {
721
+			return '';
722
+	}
690 723
 	// A session error occurred, show the error.
691 724
 	elseif ($is_fatal)
692 725
 	{
@@ -695,13 +728,14 @@  discard block
 block discarded – undo
695 728
 			ob_end_clean();
696 729
 			header('HTTP/1.1 403 Forbidden - Session timeout');
697 730
 			die;
731
+		} else {
732
+					fatal_lang_error($error, isset($log_error) ? 'user' : false);
698 733
 		}
699
-		else
700
-			fatal_lang_error($error, isset($log_error) ? 'user' : false);
701 734
 	}
702 735
 	// A session error occurred, return the error to the calling function.
703
-	else
704
-		return $error;
736
+	else {
737
+			return $error;
738
+	}
705 739
 
706 740
 	// We really should never fall through here, for very important reasons.  Let's make sure.
707 741
 	trigger_error('Hacking attempt...', E_USER_ERROR);
@@ -717,10 +751,9 @@  discard block
 block discarded – undo
717 751
 {
718 752
 	global $modSettings;
719 753
 
720
-	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action])
721
-		return true;
722
-
723
-	else
754
+	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) {
755
+			return true;
756
+	} else
724 757
 	{
725 758
 		$token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']);
726 759
 		$_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']);
@@ -771,9 +804,9 @@  discard block
 block discarded – undo
771 804
 			$return = $_SESSION['token'][$type . '-' . $action][3];
772 805
 			unset($_SESSION['token'][$type . '-' . $action]);
773 806
 			return $return;
807
+		} else {
808
+					return '';
774 809
 		}
775
-		else
776
-			return '';
777 810
 	}
778 811
 
779 812
 	// This nasty piece of code validates a token.
@@ -804,12 +837,14 @@  discard block
 block discarded – undo
804 837
 		fatal_lang_error('token_verify_fail', false);
805 838
 	}
806 839
 	// Remove this token as its useless
807
-	else
808
-		unset($_SESSION['token'][$type . '-' . $action]);
840
+	else {
841
+			unset($_SESSION['token'][$type . '-' . $action]);
842
+	}
809 843
 
810 844
 	// Randomly check if we should remove some older tokens.
811
-	if (mt_rand(0, 138) == 23)
812
-		cleanTokens();
845
+	if (mt_rand(0, 138) == 23) {
846
+			cleanTokens();
847
+	}
813 848
 
814 849
 	return false;
815 850
 }
@@ -824,14 +859,16 @@  discard block
 block discarded – undo
824 859
 function cleanTokens($complete = false)
825 860
 {
826 861
 	// We appreciate cleaning up after yourselves.
827
-	if (!isset($_SESSION['token']))
828
-		return;
862
+	if (!isset($_SESSION['token'])) {
863
+			return;
864
+	}
829 865
 
830 866
 	// Clean up tokens, trying to give enough time still.
831
-	foreach ($_SESSION['token'] as $key => $data)
832
-		if ($data[2] + 10800 < time() || $complete)
867
+	foreach ($_SESSION['token'] as $key => $data) {
868
+			if ($data[2] + 10800 < time() || $complete)
833 869
 			unset($_SESSION['token'][$key]);
834
-}
870
+	}
871
+	}
835 872
 
836 873
 /**
837 874
  * Check whether a form has been submitted twice.
@@ -849,37 +886,40 @@  discard block
 block discarded – undo
849 886
 {
850 887
 	global $context;
851 888
 
852
-	if (!isset($_SESSION['forms']))
853
-		$_SESSION['forms'] = array();
889
+	if (!isset($_SESSION['forms'])) {
890
+			$_SESSION['forms'] = array();
891
+	}
854 892
 
855 893
 	// Register a form number and store it in the session stack. (use this on the page that has the form.)
856 894
 	if ($action == 'register')
857 895
 	{
858 896
 		$context['form_sequence_number'] = 0;
859
-		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms']))
860
-			$context['form_sequence_number'] = mt_rand(1, 16000000);
897
+		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) {
898
+					$context['form_sequence_number'] = mt_rand(1, 16000000);
899
+		}
861 900
 	}
862 901
 	// Check whether the submitted number can be found in the session.
863 902
 	elseif ($action == 'check')
864 903
 	{
865
-		if (!isset($_REQUEST['seqnum']))
866
-			return true;
867
-		elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
904
+		if (!isset($_REQUEST['seqnum'])) {
905
+					return true;
906
+		} elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
868 907
 		{
869 908
 			$_SESSION['forms'][] = (int) $_REQUEST['seqnum'];
870 909
 			return true;
910
+		} elseif ($is_fatal) {
911
+					fatal_lang_error('error_form_already_submitted', false);
912
+		} else {
913
+					return false;
871 914
 		}
872
-		elseif ($is_fatal)
873
-			fatal_lang_error('error_form_already_submitted', false);
874
-		else
875
-			return false;
876 915
 	}
877 916
 	// Don't check, just free the stack number.
878
-	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms']))
879
-		$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
880
-	elseif ($action != 'free')
881
-		trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
882
-}
917
+	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) {
918
+			$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
919
+	} elseif ($action != 'free') {
920
+			trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
921
+	}
922
+	}
883 923
 
884 924
 /**
885 925
  * Check the user's permissions.
@@ -898,16 +938,19 @@  discard block
 block discarded – undo
898 938
 	global $user_info, $smcFunc;
899 939
 
900 940
 	// You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!)
901
-	if (empty($permission))
902
-		return true;
941
+	if (empty($permission)) {
942
+			return true;
943
+	}
903 944
 
904 945
 	// You're never allowed to do something if your data hasn't been loaded yet!
905
-	if (empty($user_info))
906
-		return false;
946
+	if (empty($user_info)) {
947
+			return false;
948
+	}
907 949
 
908 950
 	// Administrators are supermen :P.
909
-	if ($user_info['is_admin'])
910
-		return true;
951
+	if ($user_info['is_admin']) {
952
+			return true;
953
+	}
911 954
 
912 955
 	// Let's ensure this is an array.
913 956
 	$permission = (array) $permission;
@@ -915,14 +958,16 @@  discard block
 block discarded – undo
915 958
 	// Are we checking the _current_ board, or some other boards?
916 959
 	if ($boards === null)
917 960
 	{
918
-		if (count(array_intersect($permission, $user_info['permissions'])) != 0)
919
-			return true;
961
+		if (count(array_intersect($permission, $user_info['permissions'])) != 0) {
962
+					return true;
963
+		}
920 964
 		// You aren't allowed, by default.
921
-		else
922
-			return false;
965
+		else {
966
+					return false;
967
+		}
968
+	} elseif (!is_array($boards)) {
969
+			$boards = array($boards);
923 970
 	}
924
-	elseif (!is_array($boards))
925
-		$boards = array($boards);
926 971
 
927 972
 	$request = $smcFunc['db_query']('', '
928 973
 		SELECT MIN(bp.add_deny) AS add_deny
@@ -950,20 +995,23 @@  discard block
 block discarded – undo
950 995
 		while ($row = $smcFunc['db_fetch_assoc']($request))
951 996
 		{
952 997
 			$result = !empty($row['add_deny']);
953
-			if ($result == true)
954
-				break;
998
+			if ($result == true) {
999
+							break;
1000
+			}
955 1001
 		}
956 1002
 		$smcFunc['db_free_result']($request);
957 1003
 		return $result;
958 1004
 	}
959 1005
 
960 1006
 	// Make sure they can do it on all of the boards.
961
-	if ($smcFunc['db_num_rows']($request) != count($boards))
962
-		return false;
1007
+	if ($smcFunc['db_num_rows']($request) != count($boards)) {
1008
+			return false;
1009
+	}
963 1010
 
964 1011
 	$result = true;
965
-	while ($row = $smcFunc['db_fetch_assoc']($request))
966
-		$result &= !empty($row['add_deny']);
1012
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1013
+			$result &= !empty($row['add_deny']);
1014
+	}
967 1015
 	$smcFunc['db_free_result']($request);
968 1016
 
969 1017
 	// If the query returned 1, they can do it... otherwise, they can't.
@@ -1030,9 +1078,10 @@  discard block
 block discarded – undo
1030 1078
 
1031 1079
 	// If you're doing something on behalf of some "heavy" permissions, validate your session.
1032 1080
 	// (take out the heavy permissions, and if you can't do anything but those, you need a validated session.)
1033
-	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards))
1034
-		validateSession();
1035
-}
1081
+	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) {
1082
+			validateSession();
1083
+	}
1084
+	}
1036 1085
 
1037 1086
 /**
1038 1087
  * Return the boards a user has a certain (board) permission on. (array(0) if all.)
@@ -1051,8 +1100,9 @@  discard block
 block discarded – undo
1051 1100
 	global $user_info, $smcFunc;
1052 1101
 
1053 1102
 	// Arrays are nice, most of the time.
1054
-	if (!is_array($permissions))
1055
-		$permissions = array($permissions);
1103
+	if (!is_array($permissions)) {
1104
+			$permissions = array($permissions);
1105
+	}
1056 1106
 
1057 1107
 	/*
1058 1108
 	 * Set $simple to true to use this function as it were in SMF 2.0.x.
@@ -1064,13 +1114,14 @@  discard block
 block discarded – undo
1064 1114
 	// Administrators are all powerful, sorry.
1065 1115
 	if ($user_info['is_admin'])
1066 1116
 	{
1067
-		if ($simple)
1068
-			return array(0);
1069
-		else
1117
+		if ($simple) {
1118
+					return array(0);
1119
+		} else
1070 1120
 		{
1071 1121
 			$boards = array();
1072
-			foreach ($permissions as $permission)
1073
-				$boards[$permission] = array(0);
1122
+			foreach ($permissions as $permission) {
1123
+							$boards[$permission] = array(0);
1124
+			}
1074 1125
 
1075 1126
 			return $boards;
1076 1127
 		}
@@ -1102,31 +1153,32 @@  discard block
 block discarded – undo
1102 1153
 	{
1103 1154
 		if ($simple)
1104 1155
 		{
1105
-			if (empty($row['add_deny']))
1106
-				$deny_boards[] = $row['id_board'];
1107
-			else
1108
-				$boards[] = $row['id_board'];
1109
-		}
1110
-		else
1156
+			if (empty($row['add_deny'])) {
1157
+							$deny_boards[] = $row['id_board'];
1158
+			} else {
1159
+							$boards[] = $row['id_board'];
1160
+			}
1161
+		} else
1111 1162
 		{
1112
-			if (empty($row['add_deny']))
1113
-				$deny_boards[$row['permission']][] = $row['id_board'];
1114
-			else
1115
-				$boards[$row['permission']][] = $row['id_board'];
1163
+			if (empty($row['add_deny'])) {
1164
+							$deny_boards[$row['permission']][] = $row['id_board'];
1165
+			} else {
1166
+							$boards[$row['permission']][] = $row['id_board'];
1167
+			}
1116 1168
 		}
1117 1169
 	}
1118 1170
 	$smcFunc['db_free_result']($request);
1119 1171
 
1120
-	if ($simple)
1121
-		$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1122
-	else
1172
+	if ($simple) {
1173
+			$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1174
+	} else
1123 1175
 	{
1124 1176
 		foreach ($permissions as $permission)
1125 1177
 		{
1126 1178
 			// never had it to start with
1127
-			if (empty($boards[$permission]))
1128
-				$boards[$permission] = array();
1129
-			else
1179
+			if (empty($boards[$permission])) {
1180
+							$boards[$permission] = array();
1181
+			} else
1130 1182
 			{
1131 1183
 				// Or it may have been removed
1132 1184
 				$deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array();
@@ -1162,10 +1214,11 @@  discard block
 block discarded – undo
1162 1214
 
1163 1215
 
1164 1216
 	// Moderators are free...
1165
-	if (!allowedTo('moderate_board'))
1166
-		$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1167
-	else
1168
-		$timeLimit = 2;
1217
+	if (!allowedTo('moderate_board')) {
1218
+			$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1219
+	} else {
1220
+			$timeLimit = 2;
1221
+	}
1169 1222
 
1170 1223
 	call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit));
1171 1224
 
@@ -1192,8 +1245,9 @@  discard block
 block discarded – undo
1192 1245
 	if ($smcFunc['db_affected_rows']() != 1)
1193 1246
 	{
1194 1247
 		// Spammer!  You only have to wait a *few* seconds!
1195
-		if (!$only_return_result)
1196
-			fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1248
+		if (!$only_return_result) {
1249
+					fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1250
+		}
1197 1251
 
1198 1252
 		return true;
1199 1253
 	}
@@ -1211,11 +1265,13 @@  discard block
 block discarded – undo
1211 1265
  */
1212 1266
 function secureDirectory($path, $attachments = false)
1213 1267
 {
1214
-	if (empty($path))
1215
-		return 'empty_path';
1268
+	if (empty($path)) {
1269
+			return 'empty_path';
1270
+	}
1216 1271
 
1217
-	if (!is_writable($path))
1218
-		return 'path_not_writable';
1272
+	if (!is_writable($path)) {
1273
+			return 'path_not_writable';
1274
+	}
1219 1275
 
1220 1276
 	$directoryname = basename($path);
1221 1277
 
@@ -1227,9 +1283,9 @@  discard block
 block discarded – undo
1227 1283
 
1228 1284
 RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml';
1229 1285
 
1230
-	if (file_exists($path . '/.htaccess'))
1231
-		$errors[] = 'htaccess_exists';
1232
-	else
1286
+	if (file_exists($path . '/.htaccess')) {
1287
+			$errors[] = 'htaccess_exists';
1288
+	} else
1233 1289
 	{
1234 1290
 		$fh = @fopen($path . '/.htaccess', 'w');
1235 1291
 		if ($fh) {
@@ -1241,9 +1297,9 @@  discard block
 block discarded – undo
1241 1297
 		$errors[] = 'htaccess_cannot_create_file';
1242 1298
 	}
1243 1299
 
1244
-	if (file_exists($path . '/index.php'))
1245
-		$errors[] = 'index-php_exists';
1246
-	else
1300
+	if (file_exists($path . '/index.php')) {
1301
+			$errors[] = 'index-php_exists';
1302
+	} else
1247 1303
 	{
1248 1304
 		$fh = @fopen($path . '/index.php', 'w');
1249 1305
 		if ($fh) {
@@ -1270,11 +1326,12 @@  discard block
 block discarded – undo
1270 1326
 		$errors[] = 'index-php_cannot_create_file';
1271 1327
 	}
1272 1328
 
1273
-	if (!empty($errors))
1274
-		return $errors;
1275
-	else
1276
-		return true;
1277
-}
1329
+	if (!empty($errors)) {
1330
+			return $errors;
1331
+	} else {
1332
+			return true;
1333
+	}
1334
+	}
1278 1335
 
1279 1336
 /**
1280 1337
 * This sets the X-Frame-Options header.
@@ -1287,14 +1344,16 @@  discard block
 block discarded – undo
1287 1344
 	global $modSettings;
1288 1345
 
1289 1346
 	$option = 'SAMEORIGIN';
1290
-	if (is_null($override) && !empty($modSettings['frame_security']))
1291
-		$option = $modSettings['frame_security'];
1292
-	elseif (in_array($override, array('SAMEORIGIN', 'DENY')))
1293
-		$option = $override;
1347
+	if (is_null($override) && !empty($modSettings['frame_security'])) {
1348
+			$option = $modSettings['frame_security'];
1349
+	} elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) {
1350
+			$option = $override;
1351
+	}
1294 1352
 
1295 1353
 	// Don't bother setting the header if we have disabled it.
1296
-	if ($option == 'DISABLE')
1297
-		return;
1354
+	if ($option == 'DISABLE') {
1355
+			return;
1356
+	}
1298 1357
 
1299 1358
 	// Finally set it.
1300 1359
 	header('x-frame-options: ' . $option);
Please login to merge, or discard this patch.
Sources/Subs-Auth.php 1 patch
Braces   +168 added lines, -121 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Sets the SMF-style login cookie and session based on the id_member and password passed.
@@ -47,8 +48,9 @@  discard block
 block discarded – undo
47 48
 	if (isset($_COOKIE[$cookiename]))
48 49
 	{
49 50
 		// First check for 2.1 json-format cookie
50
-		if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1)
51
-			list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
51
+		if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1) {
52
+					list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
53
+		}
52 54
 
53 55
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
54 56
 		elseif (preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;(i:3;i:\d;)?~', $_COOKIE[$cookiename]) === 1)
@@ -58,15 +60,17 @@  discard block
 block discarded – undo
58 60
 			$cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2);
59 61
 
60 62
 			// Maybe we need to temporarily pretend to be using local cookies
61
-			if ($cookie_state == 0 && $old_state == 1)
62
-				list($old_domain, $old_path) = url_parts(true, false);
63
-			else
64
-				list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0);
63
+			if ($cookie_state == 0 && $old_state == 1) {
64
+							list($old_domain, $old_path) = url_parts(true, false);
65
+			} else {
66
+							list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0);
67
+			}
65 68
 		}
66 69
 
67 70
 		// Out with the old, in with the new!
68
-		if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1])
69
-			smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain);
71
+		if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1]) {
72
+					smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain);
73
+		}
70 74
 	}
71 75
 
72 76
 	// Get the data and path to set it on.
@@ -82,8 +86,9 @@  discard block
 block discarded – undo
82 86
 	smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], $cookie_url[0]);
83 87
 
84 88
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
85
-	if (empty($id) && !empty($modSettings['globalCookies']))
86
-		smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], '');
89
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
90
+			smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], '');
91
+	}
87 92
 
88 93
 	// Any alias URLs?  This is mainly for use with frames, etc.
89 94
 	if (!empty($modSettings['forum_alias_urls']))
@@ -99,8 +104,9 @@  discard block
 block discarded – undo
99 104
 
100 105
 			$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
101 106
 
102
-			if ($cookie_url[0] == '')
103
-				$cookie_url[0] = strtok($alias, '/');
107
+			if ($cookie_url[0] == '') {
108
+							$cookie_url[0] = strtok($alias, '/');
109
+			}
104 110
 
105 111
 			$alias_data = $smcFunc['json_decode']($data, true);
106 112
 			$alias_data[3] = $cookie_url[0];
@@ -151,8 +157,9 @@  discard block
 block discarded – undo
151 157
 	$identifier = $cookiename . '_tfa';
152 158
 	$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
153 159
 
154
-	if ($preserve)
155
-		$cookie_length = 81600 * 30;
160
+	if ($preserve) {
161
+			$cookie_length = 81600 * 30;
162
+	}
156 163
 
157 164
 	// Get the data and path to set it on.
158 165
 	$data = $smcFunc['json_encode'](empty($id) ? array(0, '', 0, $cookie_url[0], $cookie_url[1], false) : array($id, $secret, time() + $cookie_length, $cookie_url[0], $cookie_url[1], $preserve), JSON_FORCE_OBJECT);
@@ -161,8 +168,9 @@  discard block
 block discarded – undo
161 168
 	smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
162 169
 
163 170
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
164
-	if (empty($id) && !empty($modSettings['globalCookies']))
165
-		smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
171
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
172
+			smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
173
+	}
166 174
 
167 175
 	$_COOKIE[$identifier] = $data;
168 176
 }
@@ -184,23 +192,28 @@  discard block
 block discarded – undo
184 192
 	$parsed_url = parse_url($boardurl);
185 193
 
186 194
 	// Is local cookies off?
187
-	if (empty($parsed_url['path']) || !$local)
188
-		$parsed_url['path'] = '';
195
+	if (empty($parsed_url['path']) || !$local) {
196
+			$parsed_url['path'] = '';
197
+	}
189 198
 
190
-	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false)
191
-		$parsed_url['host'] = $modSettings['globalCookiesDomain'];
199
+	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) {
200
+			$parsed_url['host'] = $modSettings['globalCookiesDomain'];
201
+	}
192 202
 
193 203
 	// Globalize cookies across domains (filter out IP-addresses)?
194
-	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
195
-		$parsed_url['host'] = '.' . $parts[1];
204
+	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
205
+			$parsed_url['host'] = '.' . $parts[1];
206
+	}
196 207
 
197 208
 	// We shouldn't use a host at all if both options are off.
198
-	elseif (!$local && !$global)
199
-		$parsed_url['host'] = '';
209
+	elseif (!$local && !$global) {
210
+			$parsed_url['host'] = '';
211
+	}
200 212
 
201 213
 	// The host also shouldn't be set if there aren't any dots in it.
202
-	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false)
203
-		$parsed_url['host'] = '';
214
+	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) {
215
+			$parsed_url['host'] = '';
216
+	}
204 217
 
205 218
 	return array($parsed_url['host'], $parsed_url['path'] . '/');
206 219
 }
@@ -219,8 +232,9 @@  discard block
 block discarded – undo
219 232
 	createToken('login');
220 233
 
221 234
 	// Never redirect to an attachment
222
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
223
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
235
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
236
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
237
+	}
224 238
 
225 239
 	$context['sub_template'] = 'kick_guest';
226 240
 	$context['page_title'] = $txt['login'];
@@ -275,10 +289,12 @@  discard block
 block discarded – undo
275 289
 		$txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']);
276 290
 		log_error($txt['security_wrong'], 'critical');
277 291
 
278
-		if (isset($_POST[$type . '_hash_pass']))
279
-			unset($_POST[$type . '_hash_pass']);
280
-		if (isset($_POST[$type . '_pass']))
281
-			unset($_POST[$type . '_pass']);
292
+		if (isset($_POST[$type . '_hash_pass'])) {
293
+					unset($_POST[$type . '_hash_pass']);
294
+		}
295
+		if (isset($_POST[$type . '_pass'])) {
296
+					unset($_POST[$type . '_pass']);
297
+		}
282 298
 
283 299
 		$context['incorrect_password'] = true;
284 300
 	}
@@ -291,15 +307,17 @@  discard block
 block discarded – undo
291 307
 
292 308
 	// Now go through $_POST.  Make sure the session hash is sent.
293 309
 	$_POST[$context['session_var']] = $context['session_id'];
294
-	foreach ($_POST as $k => $v)
295
-		$context['post_data'] .= adminLogin_outputPostVars($k, $v);
310
+	foreach ($_POST as $k => $v) {
311
+			$context['post_data'] .= adminLogin_outputPostVars($k, $v);
312
+	}
296 313
 
297 314
 	// Now we'll use the admin_login sub template of the Login template.
298 315
 	$context['sub_template'] = 'admin_login';
299 316
 
300 317
 	// And title the page something like "Login".
301
-	if (!isset($context['page_title']))
302
-		$context['page_title'] = $txt['login'];
318
+	if (!isset($context['page_title'])) {
319
+			$context['page_title'] = $txt['login'];
320
+	}
303 321
 
304 322
 	// The type of action.
305 323
 	$context['sessionCheckType'] = $type;
@@ -322,14 +340,15 @@  discard block
 block discarded – undo
322 340
 {
323 341
 	global $smcFunc;
324 342
 
325
-	if (!is_array($v))
326
-		return '
343
+	if (!is_array($v)) {
344
+			return '
327 345
 <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '&quot;', '<' => '&lt;', '>' => '&gt;')) . '">';
328
-	else
346
+	} else
329 347
 	{
330 348
 		$ret = '';
331
-		foreach ($v as $k2 => $v2)
332
-			$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
349
+		foreach ($v as $k2 => $v2) {
350
+					$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
351
+		}
333 352
 
334 353
 		return $ret;
335 354
 	}
@@ -356,18 +375,20 @@  discard block
 block discarded – undo
356 375
 		foreach ($get as $k => $v)
357 376
 		{
358 377
 			// Only if it's not already in the $scripturl!
359
-			if (!isset($temp[$k]))
360
-				$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
378
+			if (!isset($temp[$k])) {
379
+							$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
380
+			}
361 381
 			// If it changed, put it out there, but with an ampersand.
362
-			elseif ($temp[$k] != $get[$k])
363
-				$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
382
+			elseif ($temp[$k] != $get[$k]) {
383
+							$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
384
+			}
364 385
 		}
365
-	}
366
-	else
386
+	} else
367 387
 	{
368 388
 		// Add up all the data from $_GET into get_data.
369
-		foreach ($get as $k => $v)
370
-			$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
389
+		foreach ($get as $k => $v) {
390
+					$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
391
+		}
371 392
 	}
372 393
 
373 394
 	$query_string = substr($query_string, 0, -1);
@@ -390,8 +411,9 @@  discard block
 block discarded – undo
390 411
 	global $scripturl, $user_info, $smcFunc;
391 412
 
392 413
 	// If it's not already an array, make it one.
393
-	if (!is_array($names))
394
-		$names = explode(',', $names);
414
+	if (!is_array($names)) {
415
+			$names = explode(',', $names);
416
+	}
395 417
 
396 418
 	$maybe_email = false;
397 419
 	$names_list = array();
@@ -403,10 +425,11 @@  discard block
 block discarded – undo
403 425
 		$maybe_email |= strpos($name, '@') !== false;
404 426
 
405 427
 		// Make it so standard wildcards will work. (* and ?)
406
-		if ($use_wildcards)
407
-			$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
408
-		else
409
-			$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
428
+		if ($use_wildcards) {
429
+					$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
430
+		} else {
431
+					$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
432
+		}
410 433
 
411 434
 		$names_list[] = '{string:lookup_name_' . $i . '}';
412 435
 		$where_params['lookup_name_' . $i] = $names[$i];
@@ -419,11 +442,12 @@  discard block
 block discarded – undo
419 442
 	$results = array();
420 443
 
421 444
 	// This ensures you can't search someones email address if you can't see it.
422
-	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum'))
423
-		$email_condition = '
445
+	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) {
446
+			$email_condition = '
424 447
 			OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
425
-	else
426
-		$email_condition = '';
448
+	} else {
449
+			$email_condition = '';
450
+	}
427 451
 
428 452
 	// Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise.
429 453
 	$member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name';
@@ -482,10 +506,11 @@  discard block
 block discarded – undo
482 506
 	$context['template_layers'] = array();
483 507
 	$context['sub_template'] = 'find_members';
484 508
 
485
-	if (isset($_REQUEST['search']))
486
-		$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
487
-	else
488
-		$_REQUEST['start'] = 0;
509
+	if (isset($_REQUEST['search'])) {
510
+			$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
511
+	} else {
512
+			$_REQUEST['start'] = 0;
513
+	}
489 514
 
490 515
 	// Allow the user to pass the input to be added to to the box.
491 516
 	$context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to';
@@ -526,10 +551,10 @@  discard block
 block discarded – undo
526 551
 		);
527 552
 
528 553
 		$context['results'] = array_slice($context['results'], $_REQUEST['start'], 7);
554
+	} else {
555
+			$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
556
+	}
529 557
 	}
530
-	else
531
-		$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
532
-}
533 558
 
534 559
 /**
535 560
  * Outputs each member name on its own line.
@@ -545,8 +570,9 @@  discard block
 block discarded – undo
545 570
 	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search']));
546 571
 	$_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;'));
547 572
 
548
-	if (function_exists('iconv'))
549
-		header('content-type: text/plain; charset=UTF-8');
573
+	if (function_exists('iconv')) {
574
+			header('content-type: text/plain; charset=UTF-8');
575
+	}
550 576
 
551 577
 	$request = $smcFunc['db_query']('', '
552 578
 		SELECT real_name
@@ -566,14 +592,16 @@  discard block
 block discarded – undo
566 592
 		if (function_exists('iconv'))
567 593
 		{
568 594
 			$utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']);
569
-			if ($utf8)
570
-				$row['real_name'] = $utf8;
595
+			if ($utf8) {
596
+							$row['real_name'] = $utf8;
597
+			}
571 598
 		}
572 599
 
573 600
 		$row['real_name'] = strtr($row['real_name'], array('&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;'));
574 601
 
575
-		if (preg_match('~&#\d+;~', $row['real_name']) != 0)
576
-			$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
602
+		if (preg_match('~&#\d+;~', $row['real_name']) != 0) {
603
+					$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
604
+		}
577 605
 
578 606
 		echo $row['real_name'], "\n";
579 607
 	}
@@ -630,9 +658,9 @@  discard block
 block discarded – undo
630 658
 
631 659
 		// Update the database...
632 660
 		updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1));
661
+	} else {
662
+			updateMemberData($memID, array('passwd' => $newPassword_sha1));
633 663
 	}
634
-	else
635
-		updateMemberData($memID, array('passwd' => $newPassword_sha1));
636 664
 
637 665
 	call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword));
638 666
 
@@ -663,31 +691,37 @@  discard block
 block discarded – undo
663 691
 	$errors = array();
664 692
 
665 693
 	// Don't use too long a name.
666
-	if ($smcFunc['strlen']($username) > 25)
667
-		$errors[] = array('lang', 'error_long_name');
694
+	if ($smcFunc['strlen']($username) > 25) {
695
+			$errors[] = array('lang', 'error_long_name');
696
+	}
668 697
 
669 698
 	// No name?!  How can you register with no name?
670
-	if ($username == '')
671
-		$errors[] = array('lang', 'need_username');
699
+	if ($username == '') {
700
+			$errors[] = array('lang', 'need_username');
701
+	}
672 702
 
673 703
 	// Only these characters are permitted.
674
-	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false)
675
-		$errors[] = array('lang', 'error_invalid_characters_username');
704
+	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) {
705
+			$errors[] = array('lang', 'error_invalid_characters_username');
706
+	}
676 707
 
677
-	if (stristr($username, $txt['guest_title']) !== false)
678
-		$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
708
+	if (stristr($username, $txt['guest_title']) !== false) {
709
+			$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
710
+	}
679 711
 
680 712
 	if ($check_reserved_name)
681 713
 	{
682 714
 		require_once($sourcedir . '/Subs-Members.php');
683
-		if (isReservedName($username, $memID, false))
684
-			$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
715
+		if (isReservedName($username, $memID, false)) {
716
+					$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
717
+		}
685 718
 	}
686 719
 
687
-	if ($return_error)
688
-		return $errors;
689
-	elseif (empty($errors))
690
-		return null;
720
+	if ($return_error) {
721
+			return $errors;
722
+	} elseif (empty($errors)) {
723
+			return null;
724
+	}
691 725
 
692 726
 	loadLanguage('Errors');
693 727
 	$error = $errors[0];
@@ -713,22 +747,26 @@  discard block
 block discarded – undo
713 747
 	global $modSettings, $smcFunc;
714 748
 
715 749
 	// Perform basic requirements first.
716
-	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8))
717
-		return 'short';
750
+	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) {
751
+			return 'short';
752
+	}
718 753
 
719 754
 	// Is this enough?
720
-	if (empty($modSettings['password_strength']))
721
-		return null;
755
+	if (empty($modSettings['password_strength'])) {
756
+			return null;
757
+	}
722 758
 
723 759
 	// Otherwise, perform the medium strength test - checking if password appears in the restricted string.
724
-	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0)
725
-		return 'restricted_words';
726
-	elseif ($smcFunc['strpos']($password, $username) !== false)
727
-		return 'restricted_words';
760
+	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) {
761
+			return 'restricted_words';
762
+	} elseif ($smcFunc['strpos']($password, $username) !== false) {
763
+			return 'restricted_words';
764
+	}
728 765
 
729 766
 	// If just medium, we're done.
730
-	if ($modSettings['password_strength'] == 1)
731
-		return null;
767
+	if ($modSettings['password_strength'] == 1) {
768
+			return null;
769
+	}
732 770
 
733 771
 	// Otherwise, hard test next, check for numbers and letters, uppercase too.
734 772
 	$good = preg_match('~(\D\d|\d\D)~', $password) != 0;
@@ -760,14 +798,16 @@  discard block
 block discarded – undo
760 798
 			)
761 799
 		);
762 800
 		$groups = array();
763
-		while ($row = $smcFunc['db_fetch_assoc']($request))
764
-			$groups[] = $row['id_group'];
801
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
802
+					$groups[] = $row['id_group'];
803
+		}
765 804
 		$smcFunc['db_free_result']($request);
766 805
 
767
-		if (empty($groups))
768
-			$group_query = '0=1';
769
-		else
770
-			$group_query = 'id_group IN (' . implode(',', $groups) . ')';
806
+		if (empty($groups)) {
807
+					$group_query = '0=1';
808
+		} else {
809
+					$group_query = 'id_group IN (' . implode(',', $groups) . ')';
810
+		}
771 811
 	}
772 812
 
773 813
 	// Then, same again, just the boards this time!
@@ -777,10 +817,11 @@  discard block
 block discarded – undo
777 817
 	{
778 818
 		$boards = boardsAllowedTo('moderate_board', true);
779 819
 
780
-		if (empty($boards))
781
-			$board_query = '0=1';
782
-		else
783
-			$board_query = 'id_board IN (' . implode(',', $boards) . ')';
820
+		if (empty($boards)) {
821
+					$board_query = '0=1';
822
+		} else {
823
+					$board_query = 'id_board IN (' . implode(',', $boards) . ')';
824
+		}
784 825
 	}
785 826
 
786 827
 	// What boards are they the moderator of?
@@ -795,8 +836,9 @@  discard block
 block discarded – undo
795 836
 				'current_member' => $user_info['id'],
796 837
 			)
797 838
 		);
798
-		while ($row = $smcFunc['db_fetch_assoc']($request))
799
-			$boards_mod[] = $row['id_board'];
839
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
840
+					$boards_mod[] = $row['id_board'];
841
+		}
800 842
 		$smcFunc['db_free_result']($request);
801 843
 
802 844
 		// Can any of the groups they're in moderate any of the boards?
@@ -808,8 +850,9 @@  discard block
 block discarded – undo
808 850
 				'groups' => $user_info['groups'],
809 851
 			)
810 852
 		);
811
-		while ($row = $smcFunc['db_fetch_assoc']($request))
812
-			$boards_mod[] = $row['id_board'];
853
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
854
+					$boards_mod[] = $row['id_board'];
855
+		}
813 856
 		$smcFunc['db_free_result']($request);
814 857
 
815 858
 		// Just in case we've got duplicates here...
@@ -854,10 +897,12 @@  discard block
 block discarded – undo
854 897
 	global $modSettings;
855 898
 
856 899
 	// In case a customization wants to override the default settings
857
-	if ($httponly === null)
858
-		$httponly = !empty($modSettings['httponlyCookies']);
859
-	if ($secure === null)
860
-		$secure = !empty($modSettings['secureCookies']);
900
+	if ($httponly === null) {
901
+			$httponly = !empty($modSettings['httponlyCookies']);
902
+	}
903
+	if ($secure === null) {
904
+			$secure = !empty($modSettings['secureCookies']);
905
+	}
861 906
 
862 907
 	// Intercept cookie?
863 908
 	call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly));
@@ -877,8 +922,9 @@  discard block
 block discarded – undo
877 922
 function hash_password($username, $password, $cost = null)
878 923
 {
879 924
 	global $sourcedir, $smcFunc, $modSettings;
880
-	if (!function_exists('password_hash'))
881
-		require_once($sourcedir . '/Subs-Password.php');
925
+	if (!function_exists('password_hash')) {
926
+			require_once($sourcedir . '/Subs-Password.php');
927
+	}
882 928
 
883 929
 	$cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost;
884 930
 
@@ -910,8 +956,9 @@  discard block
 block discarded – undo
910 956
 function hash_verify_password($username, $password, $hash)
911 957
 {
912 958
 	global $sourcedir, $smcFunc;
913
-	if (!function_exists('password_verify'))
914
-		require_once($sourcedir . '/Subs-Password.php');
959
+	if (!function_exists('password_verify')) {
960
+			require_once($sourcedir . '/Subs-Password.php');
961
+	}
915 962
 
916 963
 	return password_verify($smcFunc['strtolower']($username) . $password, $hash);
917 964
 }
Please login to merge, or discard this patch.
Sources/Admin.php 1 patch
Braces   +75 added lines, -52 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main admin handling function.<br>
@@ -444,8 +445,9 @@  discard block
 block discarded – undo
444 445
 		foreach ($admin_includes as $include)
445 446
 		{
446 447
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
447
-			if (file_exists($include))
448
-				require_once($include);
448
+			if (file_exists($include)) {
449
+							require_once($include);
450
+			}
449 451
 		}
450 452
 	}
451 453
 
@@ -457,24 +459,27 @@  discard block
 block discarded – undo
457 459
 	unset($admin_areas);
458 460
 
459 461
 	// Nothing valid?
460
-	if ($admin_include_data == false)
461
-		fatal_lang_error('no_access', false);
462
+	if ($admin_include_data == false) {
463
+			fatal_lang_error('no_access', false);
464
+	}
462 465
 
463 466
 	// Build the link tree.
464 467
 	$context['linktree'][] = array(
465 468
 		'url' => $scripturl . '?action=admin',
466 469
 		'name' => $txt['admin_center'],
467 470
 	);
468
-	if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index')
469
-		$context['linktree'][] = array(
471
+	if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index') {
472
+			$context['linktree'][] = array(
470 473
 			'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'],
471 474
 			'name' => $admin_include_data['label'],
472 475
 		);
473
-	if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label'])
474
-		$context['linktree'][] = array(
476
+	}
477
+	if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label']) {
478
+			$context['linktree'][] = array(
475 479
 			'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'],
476 480
 			'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0],
477 481
 		);
482
+	}
478 483
 
479 484
 	// Make a note of the Unique ID for this menu.
480 485
 	$context['admin_menu_id'] = $context['max_menu_id'];
@@ -484,16 +489,18 @@  discard block
 block discarded – undo
484 489
 	$context['admin_area'] = $admin_include_data['current_area'];
485 490
 
486 491
 	// Now - finally - call the right place!
487
-	if (isset($admin_include_data['file']))
488
-		require_once($sourcedir . '/' . $admin_include_data['file']);
492
+	if (isset($admin_include_data['file'])) {
493
+			require_once($sourcedir . '/' . $admin_include_data['file']);
494
+	}
489 495
 
490 496
 	// Get the right callable.
491 497
 	$call = call_helper($admin_include_data['function'], true);
492 498
 
493 499
 	// Is it valid?
494
-	if (!empty($call))
495
-		call_user_func($call);
496
-}
500
+	if (!empty($call)) {
501
+			call_user_func($call);
502
+	}
503
+	}
497 504
 
498 505
 /**
499 506
  * The main administration section.
@@ -547,13 +554,14 @@  discard block
 block discarded – undo
547 554
 
548 555
 	$context['sub_template'] = $context['admin_area'] == 'credits' ? 'credits' : 'admin';
549 556
 	$context['page_title'] = $context['admin_area'] == 'credits' ? $txt['support_credits_title'] : $txt['admin_center'];
550
-	if ($context['admin_area'] != 'credits')
551
-		$context[$context['admin_menu_name']]['tab_data'] = array(
557
+	if ($context['admin_area'] != 'credits') {
558
+			$context[$context['admin_menu_name']]['tab_data'] = array(
552 559
 			'title' => $txt['admin_center'],
553 560
 			'help' => '',
554 561
 			'description' => '<strong>' . $txt['hello_guest'] . ' ' . $context['user']['name'] . '!</strong>
555 562
 						' . sprintf($txt['admin_main_welcome'], $txt['admin_center'], $txt['help'], $txt['help']),
556 563
 		);
564
+	}
557 565
 
558 566
 	// Lastly, fill in the blanks in the support resources paragraphs.
559 567
 	$txt['support_resources_p1'] = sprintf($txt['support_resources_p1'],
@@ -571,9 +579,10 @@  discard block
 block discarded – undo
571 579
 		'https://www.simplemachines.org/redirect/customize_support'
572 580
 	);
573 581
 
574
-	if ($context['admin_area'] == 'admin')
575
-		loadJavaScriptFile('admin.js', array('defer' => false), 'smf_admin');
576
-}
582
+	if ($context['admin_area'] == 'admin') {
583
+			loadJavaScriptFile('admin.js', array('defer' => false), 'smf_admin');
584
+	}
585
+	}
577 586
 
578 587
 /**
579 588
  * Get one of the admin information files from Simple Machines.
@@ -584,8 +593,9 @@  discard block
 block discarded – undo
584 593
 
585 594
 	setMemoryLimit('32M');
586 595
 
587
-	if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename']))
588
-		fatal_lang_error('no_access', false);
596
+	if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename'])) {
597
+			fatal_lang_error('no_access', false);
598
+	}
589 599
 
590 600
 	// Strip off the forum cache part or we won't find it...
591 601
 	$_REQUEST['filename'] = str_replace($modSettings['browser_cache'], '', $_REQUEST['filename']);
@@ -600,27 +610,30 @@  discard block
 block discarded – undo
600 610
 		)
601 611
 	);
602 612
 
603
-	if ($smcFunc['db_num_rows']($request) == 0)
604
-		fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404);
613
+	if ($smcFunc['db_num_rows']($request) == 0) {
614
+			fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404);
615
+	}
605 616
 
606 617
 	list ($file_data, $filetype) = $smcFunc['db_fetch_row']($request);
607 618
 	$smcFunc['db_free_result']($request);
608 619
 
609 620
 	// @todo Temp
610 621
 	// Figure out if sesc is still being used.
611
-	if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript')
612
-		$file_data = '
622
+	if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript') {
623
+			$file_data = '
613 624
 if (!(\'smfForum_sessionvar\' in window))
614 625
 	window.smfForum_sessionvar = \'sesc\';
615 626
 ' . strtr($file_data, array(';sesc=' => ';\' + window.smfForum_sessionvar + \'='));
627
+	}
616 628
 
617 629
 	$context['template_layers'] = array();
618 630
 	// Lets make sure we aren't going to output anything nasty.
619 631
 	@ob_end_clean();
620
-	if (!empty($modSettings['enableCompressedOutput']))
621
-		@ob_start('ob_gzhandler');
622
-	else
623
-		@ob_start();
632
+	if (!empty($modSettings['enableCompressedOutput'])) {
633
+			@ob_start('ob_gzhandler');
634
+	} else {
635
+			@ob_start();
636
+	}
624 637
 
625 638
 	// Make sure they know what type of file we are.
626 639
 	header('content-type: ' . $filetype);
@@ -660,11 +673,12 @@  discard block
 block discarded – undo
660 673
 		updateAdminPreferences();
661 674
 	}
662 675
 
663
-	if (trim($context['search_term']) == '')
664
-		$context['search_results'] = array();
665
-	else
666
-		call_helper($subActions[$context['search_type']]);
667
-}
676
+	if (trim($context['search_term']) == '') {
677
+			$context['search_results'] = array();
678
+	} else {
679
+			call_helper($subActions[$context['search_type']]);
680
+	}
681
+	}
668 682
 
669 683
 /**
670 684
  * A complicated but relatively quick internal search.
@@ -728,8 +742,9 @@  discard block
 block discarded – undo
728 742
 
729 743
 	loadLanguage(implode('+', $language_files));
730 744
 
731
-	foreach ($include_files as $file)
732
-		require_once($sourcedir . '/' . $file . '.php');
745
+	foreach ($include_files as $file) {
746
+			require_once($sourcedir . '/' . $file . '.php');
747
+	}
733 748
 
734 749
 	/* This is the huge array that defines everything... it's a huge array of items formatted as follows:
735 750
 		0 = Language index (Can be array of indexes) to search through for this setting.
@@ -753,11 +768,12 @@  discard block
 block discarded – undo
753 768
 		foreach ($section['areas'] as $menu_key => $menu_item)
754 769
 		{
755 770
 			$search_data['sections'][] = array($menu_item['label'], 'area=' . $menu_key);
756
-			if (!empty($menu_item['subsections']))
757
-				foreach ($menu_item['subsections'] as $key => $sublabel)
771
+			if (!empty($menu_item['subsections'])) {
772
+							foreach ($menu_item['subsections'] as $key => $sublabel)
758 773
 				{
759 774
 					if (isset($sublabel['label']))
760 775
 						$search_data['sections'][] = array($sublabel['label'], 'area=' . $menu_key . ';sa=' . $key);
776
+			}
761 777
 				}
762 778
 		}
763 779
 	}
@@ -767,9 +783,10 @@  discard block
 block discarded – undo
767 783
 		// Get a list of their variables.
768 784
 		$config_vars = $setting_area[0](true);
769 785
 
770
-		foreach ($config_vars as $var)
771
-			if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc')))
786
+		foreach ($config_vars as $var) {
787
+					if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc')))
772 788
 				$search_data['settings'][] = array($var[(isset($var[2]) && in_array($var[2], array('file', 'db'))) ? 0 : 1], $setting_area[1], 'alttxt' => (isset($var[2]) && in_array($var[2], array('file', 'db'))) || isset($var[3]) ? (in_array($var[2], array('file', 'db')) ? $var[1] : $var[3]) : '');
789
+		}
773 790
 	}
774 791
 
775 792
 	$context['page_title'] = $txt['admin_search_results'];
@@ -782,8 +799,9 @@  discard block
 block discarded – undo
782 799
 		foreach ($data as $item)
783 800
 		{
784 801
 			$found = false;
785
-			if (!is_array($item[0]))
786
-				$item[0] = array($item[0]);
802
+			if (!is_array($item[0])) {
803
+							$item[0] = array($item[0]);
804
+			}
787 805
 			foreach ($item[0] as $term)
788 806
 			{
789 807
 				if (stripos($term, $search_term) !== false || (isset($txt[$term]) && stripos($txt[$term], $search_term) !== false) || (isset($txt['setting_' . $term]) && stripos($txt['setting_' . $term], $search_term) !== false))
@@ -841,8 +859,9 @@  discard block
 block discarded – undo
841 859
 	$postVars = explode(' ', $context['search_term']);
842 860
 
843 861
 	// Encode the search data.
844
-	foreach ($postVars as $k => $v)
845
-		$postVars[$k] = urlencode($v);
862
+	foreach ($postVars as $k => $v) {
863
+			$postVars[$k] = urlencode($v);
864
+	}
846 865
 
847 866
 	// This is what we will send.
848 867
 	$postVars = implode('+', $postVars);
@@ -854,8 +873,9 @@  discard block
 block discarded – undo
854 873
 	$search_results = fetch_web_data($context['doc_apiurl'] . '?action=query&list=search&srprop=timestamp|snippet&format=xml&srwhat=text&srsearch=' . $postVars);
855 874
 
856 875
 	// If we didn't get any xml back we are in trouble - perhaps the doc site is overloaded?
857
-	if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api>.+?</api>)~is', $search_results, $matches) != true)
858
-		fatal_lang_error('cannot_connect_doc_site');
876
+	if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api>.+?</api>)~is', $search_results, $matches) != true) {
877
+			fatal_lang_error('cannot_connect_doc_site');
878
+	}
859 879
 
860 880
 	$search_results = $matches[1];
861 881
 
@@ -867,8 +887,9 @@  discard block
 block discarded – undo
867 887
 	$results = new xmlArray($search_results, false);
868 888
 
869 889
 	// Move through the api layer.
870
-	if (!$results->exists('api'))
871
-		fatal_lang_error('cannot_connect_doc_site');
890
+	if (!$results->exists('api')) {
891
+			fatal_lang_error('cannot_connect_doc_site');
892
+	}
872 893
 
873 894
 	// Are there actually some results?
874 895
 	if ($results->exists('api/query/search/p'))
@@ -904,8 +925,9 @@  discard block
 block discarded – undo
904 925
 	);
905 926
 
906 927
 	// If it's not got a sa set it must have come here for first time, pretend error log should be reversed.
907
-	if (!isset($_REQUEST['sa']))
908
-		$_REQUEST['desc'] = true;
928
+	if (!isset($_REQUEST['sa'])) {
929
+			$_REQUEST['desc'] = true;
930
+	}
909 931
 
910 932
 	// Setup some tab stuff.
911 933
 	$context[$context['admin_menu_name']]['tab_data'] = array(
@@ -955,9 +977,10 @@  discard block
 block discarded – undo
955 977
 	unset($_SESSION['admin_time']);
956 978
 
957 979
 	// Clean any admin tokens as well.
958
-	foreach ($_SESSION['token'] as $key => $token)
959
-		if (strpos($key, '-admin') !== false)
980
+	foreach ($_SESSION['token'] as $key => $token) {
981
+			if (strpos($key, '-admin') !== false)
960 982
 			unset($_SESSION['token'][$key]);
983
+	}
961 984
 
962 985
 	redirectexit();
963 986
 }
Please login to merge, or discard this patch.
SSI.php 1 patch
Braces   +426 added lines, -304 removed lines patch added patch discarded remove patch
@@ -12,8 +12,9 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Don't do anything if SMF is already loaded.
15
-if (defined('SMF'))
15
+if (defined('SMF')) {
16 16
 	return true;
17
+}
17 18
 
18 19
 define('SMF', 'SSI');
19 20
 
@@ -28,16 +29,18 @@  discard block
 block discarded – undo
28 29
 $time_start = microtime(true);
29 30
 
30 31
 // Just being safe...
31
-foreach (array('db_character_set', 'cachedir') as $variable)
32
+foreach (array('db_character_set', 'cachedir') as $variable) {
32 33
 	if (isset($GLOBALS[$variable]))
33 34
 		unset($GLOBALS[$variable]);
35
+}
34 36
 
35 37
 // Get the forum's settings for database and file paths.
36 38
 require_once(dirname(__FILE__) . '/Settings.php');
37 39
 
38 40
 // Make absolutely sure the cache directory is defined.
39
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
41
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
40 42
 	$cachedir = $boarddir . '/cache';
43
+}
41 44
 
42 45
 $ssi_error_reporting = error_reporting(E_ALL);
43 46
 /* Set this to one of three values depending on what you want to happen in the case of a fatal error.
@@ -48,12 +51,14 @@  discard block
 block discarded – undo
48 51
 $ssi_on_error_method = false;
49 52
 
50 53
 // Don't do john didley if the forum's been shut down completely.
51
-if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true))
54
+if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true)) {
52 55
 	die($mmessage);
56
+}
53 57
 
54 58
 // Fix for using the current directory as a path.
55
-if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.')
59
+if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') {
56 60
 	$sourcedir = dirname(__FILE__) . substr($sourcedir, 1);
61
+}
57 62
 
58 63
 // Load the important includes.
59 64
 require_once($sourcedir . '/QueryString.php');
@@ -78,26 +83,30 @@  discard block
 block discarded – undo
78 83
 cleanRequest();
79 84
 
80 85
 // Seed the random generator?
81
-if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69)
86
+if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) {
82 87
 	smf_seed_generator();
88
+}
83 89
 
84 90
 // Check on any hacking attempts.
85
-if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
91
+if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
86 92
 	die('No direct access...');
87
-elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme)
93
+} elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme) {
88 94
 	die('No direct access...');
89
-elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme)
95
+} elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme) {
90 96
 	die('No direct access...');
91
-elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers)
97
+} elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers) {
92 98
 	die('No direct access...');
93
-if (isset($_REQUEST['context']))
99
+}
100
+if (isset($_REQUEST['context'])) {
94 101
 	die('No direct access...');
102
+}
95 103
 
96 104
 // Gzip output? (because it must be boolean and true, this can't be hacked.)
97
-if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>='))
105
+if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>=')) {
98 106
 	ob_start('ob_gzhandler');
99
-else
107
+} else {
100 108
 	$modSettings['enableCompressedOutput'] = '0';
109
+}
101 110
 
102 111
 /**
103 112
  * An autoloader for certain classes.
@@ -146,9 +155,9 @@  discard block
 block discarded – undo
146 155
 ob_start('ob_sessrewrite');
147 156
 
148 157
 // Start the session... known to scramble SSI includes in cases...
149
-if (!headers_sent())
158
+if (!headers_sent()) {
150 159
 	loadSession();
151
-else
160
+} else
152 161
 {
153 162
 	if (isset($_COOKIE[session_name()]) || isset($_REQUEST[session_name()]))
154 163
 	{
@@ -182,12 +191,14 @@  discard block
 block discarded – undo
182 191
 loadTheme(isset($ssi_theme) ? (int) $ssi_theme : 0);
183 192
 
184 193
 // @todo: probably not the best place, but somewhere it should be set...
185
-if (!headers_sent())
194
+if (!headers_sent()) {
186 195
 	header('content-type: text/html; charset=' . (empty($modSettings['global_character_set']) ? (empty($txt['lang_character_set']) ? 'ISO-8859-1' : $txt['lang_character_set']) : $modSettings['global_character_set']));
196
+}
187 197
 
188 198
 // Take care of any banning that needs to be done.
189
-if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true))
199
+if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true)) {
190 200
 	is_not_banned();
201
+}
191 202
 
192 203
 // Do we allow guests in here?
193 204
 if (empty($ssi_guest_access) && empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && basename($_SERVER['PHP_SELF']) != 'SSI.php')
@@ -202,17 +213,19 @@  discard block
 block discarded – undo
202 213
 {
203 214
 	$context['template_layers'] = $ssi_layers;
204 215
 	template_header();
205
-}
206
-else
216
+} else {
207 217
 	setupThemeContext();
218
+}
208 219
 
209 220
 // Make sure they didn't muss around with the settings... but only if it's not cli.
210
-if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '')
221
+if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '') {
211 222
 	trigger_error($txt['ssi_session_broken'], E_USER_NOTICE);
223
+}
212 224
 
213 225
 // Without visiting the forum this session variable might not be set on submit.
214
-if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote'))
226
+if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote')) {
215 227
 	$_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT'];
228
+}
216 229
 
217 230
 // Have the ability to easily add functions to SSI.
218 231
 call_integration_hook('integrate_SSI');
@@ -221,11 +234,13 @@  discard block
 block discarded – undo
221 234
 if (basename($_SERVER['PHP_SELF']) == 'SSI.php')
222 235
 {
223 236
 	// You shouldn't just access SSI.php directly by URL!!
224
-	if (!isset($_GET['ssi_function']))
225
-		die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\''));
237
+	if (!isset($_GET['ssi_function'])) {
238
+			die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\''));
239
+	}
226 240
 	// Call a function passed by GET.
227
-	if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest']))
228
-		call_user_func('ssi_' . $_GET['ssi_function']);
241
+	if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest'])) {
242
+			call_user_func('ssi_' . $_GET['ssi_function']);
243
+	}
229 244
 	exit;
230 245
 }
231 246
 
@@ -242,9 +257,10 @@  discard block
 block discarded – undo
242 257
  */
243 258
 function ssi_shutdown()
244 259
 {
245
-	if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown')
246
-		template_footer();
247
-}
260
+	if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown') {
261
+			template_footer();
262
+	}
263
+	}
248 264
 
249 265
 /**
250 266
  * Display a welcome message, like: Hey, User, you have 0 messages, 0 are new.
@@ -257,15 +273,17 @@  discard block
 block discarded – undo
257 273
 
258 274
 	if ($output_method == 'echo')
259 275
 	{
260
-		if ($context['user']['is_guest'])
261
-			echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup');
262
-		else
263
-			echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : '';
276
+		if ($context['user']['is_guest']) {
277
+					echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup');
278
+		} else {
279
+					echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : '';
280
+		}
264 281
 	}
265 282
 	// Don't echo... then do what?!
266
-	else
267
-		return $context['user'];
268
-}
283
+	else {
284
+			return $context['user'];
285
+	}
286
+	}
269 287
 
270 288
 /**
271 289
  * Display a menu bar, like is displayed at the top of the forum.
@@ -276,12 +294,14 @@  discard block
 block discarded – undo
276 294
 {
277 295
 	global $context;
278 296
 
279
-	if ($output_method == 'echo')
280
-		template_menu();
297
+	if ($output_method == 'echo') {
298
+			template_menu();
299
+	}
281 300
 	// What else could this do?
282
-	else
283
-		return $context['menu_buttons'];
284
-}
301
+	else {
302
+			return $context['menu_buttons'];
303
+	}
304
+	}
285 305
 
286 306
 /**
287 307
  * Show a logout link.
@@ -293,20 +313,23 @@  discard block
 block discarded – undo
293 313
 {
294 314
 	global $context, $txt, $scripturl;
295 315
 
296
-	if ($redirect_to != '')
297
-		$_SESSION['logout_url'] = $redirect_to;
316
+	if ($redirect_to != '') {
317
+			$_SESSION['logout_url'] = $redirect_to;
318
+	}
298 319
 
299 320
 	// Guests can't log out.
300
-	if ($context['user']['is_guest'])
301
-		return false;
321
+	if ($context['user']['is_guest']) {
322
+			return false;
323
+	}
302 324
 
303 325
 	$link = '<a href="' . $scripturl . '?action=logout;' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['logout'] . '</a>';
304 326
 
305
-	if ($output_method == 'echo')
306
-		echo $link;
307
-	else
308
-		return $link;
309
-}
327
+	if ($output_method == 'echo') {
328
+			echo $link;
329
+	} else {
330
+			return $link;
331
+	}
332
+	}
310 333
 
311 334
 /**
312 335
  * Recent post list:   [board] Subject by Poster    Date
@@ -322,17 +345,17 @@  discard block
 block discarded – undo
322 345
 	global $modSettings, $context;
323 346
 
324 347
 	// Excluding certain boards...
325
-	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
326
-		$exclude_boards = array($modSettings['recycle_board']);
327
-	else
328
-		$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
348
+	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) {
349
+			$exclude_boards = array($modSettings['recycle_board']);
350
+	} else {
351
+			$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
352
+	}
329 353
 
330 354
 	// What about including certain boards - note we do some protection here as pre-2.0 didn't have this parameter.
331 355
 	if (is_array($include_boards) || (int) $include_boards === $include_boards)
332 356
 	{
333 357
 		$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
334
-	}
335
-	elseif ($include_boards != null)
358
+	} elseif ($include_boards != null)
336 359
 	{
337 360
 		$include_boards = array();
338 361
 	}
@@ -369,8 +392,9 @@  discard block
 block discarded – undo
369 392
 {
370 393
 	global $modSettings;
371 394
 
372
-	if (empty($post_ids))
373
-		return;
395
+	if (empty($post_ids)) {
396
+			return;
397
+	}
374 398
 
375 399
 	// Allow the user to request more than one - why not?
376 400
 	$post_ids = is_array($post_ids) ? $post_ids : array($post_ids);
@@ -405,8 +429,9 @@  discard block
 block discarded – undo
405 429
 	global $scripturl, $txt, $user_info;
406 430
 	global $modSettings, $smcFunc, $context;
407 431
 
408
-	if (!empty($modSettings['enable_likes']))
409
-		$context['can_like'] = allowedTo('likes_like');
432
+	if (!empty($modSettings['enable_likes'])) {
433
+			$context['can_like'] = allowedTo('likes_like');
434
+	}
410 435
 
411 436
 	// Find all the posts. Newer ones will have higher IDs.
412 437
 	$request = $smcFunc['db_query']('substring', '
@@ -472,12 +497,13 @@  discard block
 block discarded – undo
472 497
 		);
473 498
 
474 499
 		// Get the likes for each message.
475
-		if (!empty($modSettings['enable_likes']))
476
-			$posts[$row['id_msg']]['likes'] = array(
500
+		if (!empty($modSettings['enable_likes'])) {
501
+					$posts[$row['id_msg']]['likes'] = array(
477 502
 				'count' => $row['likes'],
478 503
 				'you' => in_array($row['id_msg'], prepareLikesContext($row['id_topic'])),
479 504
 				'can_like' => !$context['user']['is_guest'] && $row['id_member'] != $context['user']['id'] && !empty($context['can_like']),
480 505
 			);
506
+		}
481 507
 	}
482 508
 	$smcFunc['db_free_result']($request);
483 509
 
@@ -485,13 +511,14 @@  discard block
 block discarded – undo
485 511
 	call_integration_hook('integrate_ssi_queryPosts', array(&$posts));
486 512
 
487 513
 	// Just return it.
488
-	if ($output_method != 'echo' || empty($posts))
489
-		return $posts;
514
+	if ($output_method != 'echo' || empty($posts)) {
515
+			return $posts;
516
+	}
490 517
 
491 518
 	echo '
492 519
 		<table style="border: none" class="ssi_table">';
493
-	foreach ($posts as $post)
494
-		echo '
520
+	foreach ($posts as $post) {
521
+			echo '
495 522
 			<tr>
496 523
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
497 524
 					[', $post['board']['link'], ']
@@ -505,6 +532,7 @@  discard block
 block discarded – undo
505 532
 					', $post['time'], '
506 533
 				</td>
507 534
 			</tr>';
535
+	}
508 536
 	echo '
509 537
 		</table>';
510 538
 }
@@ -522,25 +550,26 @@  discard block
 block discarded – undo
522 550
 	global $settings, $scripturl, $txt, $user_info;
523 551
 	global $modSettings, $smcFunc, $context;
524 552
 
525
-	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
526
-		$exclude_boards = array($modSettings['recycle_board']);
527
-	else
528
-		$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
553
+	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) {
554
+			$exclude_boards = array($modSettings['recycle_board']);
555
+	} else {
556
+			$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
557
+	}
529 558
 
530 559
 	// Only some boards?.
531 560
 	if (is_array($include_boards) || (int) $include_boards === $include_boards)
532 561
 	{
533 562
 		$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
534
-	}
535
-	elseif ($include_boards != null)
563
+	} elseif ($include_boards != null)
536 564
 	{
537 565
 		$output_method = $include_boards;
538 566
 		$include_boards = array();
539 567
 	}
540 568
 
541 569
 	$icon_sources = array();
542
-	foreach ($context['stable_icons'] as $icon)
543
-		$icon_sources[$icon] = 'images_url';
570
+	foreach ($context['stable_icons'] as $icon) {
571
+			$icon_sources[$icon] = 'images_url';
572
+	}
544 573
 
545 574
 	// Find all the posts in distinct topics.  Newer ones will have higher IDs.
546 575
 	$request = $smcFunc['db_query']('substring', '
@@ -565,13 +594,15 @@  discard block
 block discarded – undo
565 594
 		)
566 595
 	);
567 596
 	$topics = array();
568
-	while ($row = $smcFunc['db_fetch_assoc']($request))
569
-		$topics[$row['id_topic']] = $row;
597
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
598
+			$topics[$row['id_topic']] = $row;
599
+	}
570 600
 	$smcFunc['db_free_result']($request);
571 601
 
572 602
 	// Did we find anything? If not, bail.
573
-	if (empty($topics))
574
-		return array();
603
+	if (empty($topics)) {
604
+			return array();
605
+	}
575 606
 
576 607
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
577 608
 
@@ -599,19 +630,22 @@  discard block
 block discarded – undo
599 630
 	while ($row = $smcFunc['db_fetch_assoc']($request))
600 631
 	{
601 632
 		$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br>' => '&#10;')));
602
-		if ($smcFunc['strlen']($row['body']) > 128)
603
-			$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
633
+		if ($smcFunc['strlen']($row['body']) > 128) {
634
+					$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
635
+		}
604 636
 
605 637
 		// Censor the subject.
606 638
 		censorText($row['subject']);
607 639
 		censorText($row['body']);
608 640
 
609 641
 		// Recycled icon
610
-		if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board'])
611
-			$row['icon'] = 'recycled';
642
+		if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board']) {
643
+					$row['icon'] = 'recycled';
644
+		}
612 645
 
613
-		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
614
-			$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
646
+		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) {
647
+					$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
648
+		}
615 649
 
616 650
 		// Build the array.
617 651
 		$posts[] = array(
@@ -650,13 +684,14 @@  discard block
 block discarded – undo
650 684
 	call_integration_hook('integrate_ssi_recentTopics', array(&$posts));
651 685
 
652 686
 	// Just return it.
653
-	if ($output_method != 'echo' || empty($posts))
654
-		return $posts;
687
+	if ($output_method != 'echo' || empty($posts)) {
688
+			return $posts;
689
+	}
655 690
 
656 691
 	echo '
657 692
 		<table style="border: none" class="ssi_table">';
658
-	foreach ($posts as $post)
659
-		echo '
693
+	foreach ($posts as $post) {
694
+			echo '
660 695
 			<tr>
661 696
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
662 697
 					[', $post['board']['link'], ']
@@ -670,6 +705,7 @@  discard block
 block discarded – undo
670 705
 					', $post['time'], '
671 706
 				</td>
672 707
 			</tr>';
708
+	}
673 709
 	echo '
674 710
 		</table>';
675 711
 }
@@ -694,27 +730,30 @@  discard block
 block discarded – undo
694 730
 		)
695 731
 	);
696 732
 	$return = array();
697
-	while ($row = $smcFunc['db_fetch_assoc']($request))
698
-		$return[] = array(
733
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
734
+			$return[] = array(
699 735
 			'id' => $row['id_member'],
700 736
 			'name' => $row['real_name'],
701 737
 			'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
702 738
 			'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
703 739
 			'posts' => $row['posts']
704 740
 		);
741
+	}
705 742
 	$smcFunc['db_free_result']($request);
706 743
 
707 744
 	// If mods want to do somthing with this list of members, let them do that now.
708 745
 	call_integration_hook('integrate_ssi_topPoster', array(&$return));
709 746
 
710 747
 	// Just return all the top posters.
711
-	if ($output_method != 'echo')
712
-		return $return;
748
+	if ($output_method != 'echo') {
749
+			return $return;
750
+	}
713 751
 
714 752
 	// Make a quick array to list the links in.
715 753
 	$temp_array = array();
716
-	foreach ($return as $member)
717
-		$temp_array[] = $member['link'];
754
+	foreach ($return as $member) {
755
+			$temp_array[] = $member['link'];
756
+	}
718 757
 
719 758
 	echo implode(', ', $temp_array);
720 759
 }
@@ -746,8 +785,8 @@  discard block
 block discarded – undo
746 785
 		)
747 786
 	);
748 787
 	$boards = array();
749
-	while ($row = $smcFunc['db_fetch_assoc']($request))
750
-		$boards[] = array(
788
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
789
+			$boards[] = array(
751 790
 			'id' => $row['id_board'],
752 791
 			'num_posts' => $row['num_posts'],
753 792
 			'num_topics' => $row['num_topics'],
@@ -756,14 +795,16 @@  discard block
 block discarded – undo
756 795
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
757 796
 			'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'
758 797
 		);
798
+	}
759 799
 	$smcFunc['db_free_result']($request);
760 800
 
761 801
 	// If mods want to do somthing with this list of boards, let them do that now.
762 802
 	call_integration_hook('integrate_ssi_topBoards', array(&$boards));
763 803
 
764 804
 	// If we shouldn't output or have nothing to output, just jump out.
765
-	if ($output_method != 'echo' || empty($boards))
766
-		return $boards;
805
+	if ($output_method != 'echo' || empty($boards)) {
806
+			return $boards;
807
+	}
767 808
 
768 809
 	echo '
769 810
 		<table class="ssi_table">
@@ -772,13 +813,14 @@  discard block
 block discarded – undo
772 813
 				<th style="text-align: left">', $txt['board_topics'], '</th>
773 814
 				<th style="text-align: left">', $txt['posts'], '</th>
774 815
 			</tr>';
775
-	foreach ($boards as $sBoard)
776
-		echo '
816
+	foreach ($boards as $sBoard) {
817
+			echo '
777 818
 			<tr>
778 819
 				<td>', $sBoard['link'], $sBoard['new'] ? ' <a href="' . $sBoard['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>' : '', '</td>
779 820
 				<td style="text-align: right">', comma_format($sBoard['num_topics']), '</td>
780 821
 				<td style="text-align: right">', comma_format($sBoard['num_posts']), '</td>
781 822
 			</tr>';
823
+	}
782 824
 	echo '
783 825
 		</table>';
784 826
 }
@@ -811,12 +853,13 @@  discard block
 block discarded – undo
811 853
 			)
812 854
 		);
813 855
 		$topic_ids = array();
814
-		while ($row = $smcFunc['db_fetch_assoc']($request))
815
-			$topic_ids[] = $row['id_topic'];
856
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
857
+					$topic_ids[] = $row['id_topic'];
858
+		}
816 859
 		$smcFunc['db_free_result']($request);
860
+	} else {
861
+			$topic_ids = array();
817 862
 	}
818
-	else
819
-		$topic_ids = array();
820 863
 
821 864
 	$request = $smcFunc['db_query']('', '
822 865
 		SELECT m.subject, m.id_topic, t.num_views, t.num_replies
@@ -855,8 +898,9 @@  discard block
 block discarded – undo
855 898
 	// If mods want to do somthing with this list of topics, let them do that now.
856 899
 	call_integration_hook('integrate_ssi_topTopics', array(&$topics, $type));
857 900
 
858
-	if ($output_method != 'echo' || empty($topics))
859
-		return $topics;
901
+	if ($output_method != 'echo' || empty($topics)) {
902
+			return $topics;
903
+	}
860 904
 
861 905
 	echo '
862 906
 		<table class="ssi_table">
@@ -865,8 +909,8 @@  discard block
 block discarded – undo
865 909
 				<th style="text-align: left">', $txt['views'], '</th>
866 910
 				<th style="text-align: left">', $txt['replies'], '</th>
867 911
 			</tr>';
868
-	foreach ($topics as $sTopic)
869
-		echo '
912
+	foreach ($topics as $sTopic) {
913
+			echo '
870 914
 			<tr>
871 915
 				<td style="text-align: left">
872 916
 					', $sTopic['link'], '
@@ -874,6 +918,7 @@  discard block
 block discarded – undo
874 918
 				<td style="text-align: right">', comma_format($sTopic['num_views']), '</td>
875 919
 				<td style="text-align: right">', comma_format($sTopic['num_replies']), '</td>
876 920
 			</tr>';
921
+	}
877 922
 	echo '
878 923
 		</table>';
879 924
 }
@@ -909,12 +954,13 @@  discard block
 block discarded – undo
909 954
 {
910 955
 	global $txt, $context;
911 956
 
912
-	if ($output_method == 'echo')
913
-		echo '
957
+	if ($output_method == 'echo') {
958
+			echo '
914 959
 	', sprintf($txt['welcome_newest_member'], $context['common_stats']['latest_member']['link']), '<br>';
915
-	else
916
-		return $context['common_stats']['latest_member'];
917
-}
960
+	} else {
961
+			return $context['common_stats']['latest_member'];
962
+	}
963
+	}
918 964
 
919 965
 /**
920 966
  * Fetches a random member.
@@ -963,8 +1009,9 @@  discard block
 block discarded – undo
963 1009
 	}
964 1010
 
965 1011
 	// Just to be sure put the random generator back to something... random.
966
-	if ($random_type != '')
967
-		mt_srand(time());
1012
+	if ($random_type != '') {
1013
+			mt_srand(time());
1014
+	}
968 1015
 
969 1016
 	return $result;
970 1017
 }
@@ -977,8 +1024,9 @@  discard block
 block discarded – undo
977 1024
  */
978 1025
 function ssi_fetchMember($member_ids = array(), $output_method = 'echo')
979 1026
 {
980
-	if (empty($member_ids))
981
-		return;
1027
+	if (empty($member_ids)) {
1028
+			return;
1029
+	}
982 1030
 
983 1031
 	// Can have more than one member if you really want...
984 1032
 	$member_ids = is_array($member_ids) ? $member_ids : array($member_ids);
@@ -1003,8 +1051,9 @@  discard block
 block discarded – undo
1003 1051
  */
1004 1052
 function ssi_fetchGroupMembers($group_id = null, $output_method = 'echo')
1005 1053
 {
1006
-	if ($group_id === null)
1007
-		return;
1054
+	if ($group_id === null) {
1055
+			return;
1056
+	}
1008 1057
 
1009 1058
 	$query_where = '
1010 1059
 		id_group = {int:id_group}
@@ -1031,8 +1080,9 @@  discard block
 block discarded – undo
1031 1080
 {
1032 1081
 	global $smcFunc, $memberContext;
1033 1082
 
1034
-	if ($query_where === null)
1035
-		return;
1083
+	if ($query_where === null) {
1084
+			return;
1085
+	}
1036 1086
 
1037 1087
 	// Fetch the members in question.
1038 1088
 	$request = $smcFunc['db_query']('', '
@@ -1045,12 +1095,14 @@  discard block
 block discarded – undo
1045 1095
 		))
1046 1096
 	);
1047 1097
 	$members = array();
1048
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1049
-		$members[] = $row['id_member'];
1098
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1099
+			$members[] = $row['id_member'];
1100
+	}
1050 1101
 	$smcFunc['db_free_result']($request);
1051 1102
 
1052
-	if (empty($members))
1053
-		return array();
1103
+	if (empty($members)) {
1104
+			return array();
1105
+	}
1054 1106
 
1055 1107
 	// If mods want to do somthing with this list of members, let them do that now.
1056 1108
 	call_integration_hook('integrate_ssi_queryMembers', array(&$members));
@@ -1059,23 +1111,25 @@  discard block
 block discarded – undo
1059 1111
 	loadMemberData($members);
1060 1112
 
1061 1113
 	// Draw the table!
1062
-	if ($output_method == 'echo')
1063
-		echo '
1114
+	if ($output_method == 'echo') {
1115
+			echo '
1064 1116
 		<table style="border: none" class="ssi_table">';
1117
+	}
1065 1118
 
1066 1119
 	$query_members = array();
1067 1120
 	foreach ($members as $member)
1068 1121
 	{
1069 1122
 		// Load their context data.
1070
-		if (!loadMemberContext($member))
1071
-			continue;
1123
+		if (!loadMemberContext($member)) {
1124
+					continue;
1125
+		}
1072 1126
 
1073 1127
 		// Store this member's information.
1074 1128
 		$query_members[$member] = $memberContext[$member];
1075 1129
 
1076 1130
 		// Only do something if we're echo'ing.
1077
-		if ($output_method == 'echo')
1078
-			echo '
1131
+		if ($output_method == 'echo') {
1132
+					echo '
1079 1133
 			<tr>
1080 1134
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
1081 1135
 					', $query_members[$member]['link'], '
@@ -1083,12 +1137,14 @@  discard block
 block discarded – undo
1083 1137
 					<br>', $query_members[$member]['avatar']['image'], '
1084 1138
 				</td>
1085 1139
 			</tr>';
1140
+		}
1086 1141
 	}
1087 1142
 
1088 1143
 	// End the table if appropriate.
1089
-	if ($output_method == 'echo')
1090
-		echo '
1144
+	if ($output_method == 'echo') {
1145
+			echo '
1091 1146
 		</table>';
1147
+	}
1092 1148
 
1093 1149
 	// Send back the data.
1094 1150
 	return $query_members;
@@ -1103,8 +1159,9 @@  discard block
 block discarded – undo
1103 1159
 {
1104 1160
 	global $txt, $scripturl, $modSettings, $smcFunc;
1105 1161
 
1106
-	if (!allowedTo('view_stats'))
1107
-		return;
1162
+	if (!allowedTo('view_stats')) {
1163
+			return;
1164
+	}
1108 1165
 
1109 1166
 	$totals = array(
1110 1167
 		'members' => $modSettings['totalMembers'],
@@ -1133,8 +1190,9 @@  discard block
 block discarded – undo
1133 1190
 	// If mods want to do somthing with the board stats, let them do that now.
1134 1191
 	call_integration_hook('integrate_ssi_boardStats', array(&$totals));
1135 1192
 
1136
-	if ($output_method != 'echo')
1137
-		return $totals;
1193
+	if ($output_method != 'echo') {
1194
+			return $totals;
1195
+	}
1138 1196
 
1139 1197
 	echo '
1140 1198
 		', $txt['total_members'], ': <a href="', $scripturl . '?action=mlist">', comma_format($totals['members']), '</a><br>
@@ -1163,8 +1221,8 @@  discard block
 block discarded – undo
1163 1221
 	call_integration_hook('integrate_ssi_whosOnline', array(&$return));
1164 1222
 
1165 1223
 	// Add some redundancy for backwards compatibility reasons.
1166
-	if ($output_method != 'echo')
1167
-		return $return + array(
1224
+	if ($output_method != 'echo') {
1225
+			return $return + array(
1168 1226
 			'users' => $return['users_online'],
1169 1227
 			'guests' => $return['num_guests'],
1170 1228
 			'hidden' => $return['num_users_hidden'],
@@ -1172,29 +1230,35 @@  discard block
 block discarded – undo
1172 1230
 			'num_users' => $return['num_users_online'],
1173 1231
 			'total_users' => $return['num_users_online'] + $return['num_guests'],
1174 1232
 		);
1233
+	}
1175 1234
 
1176 1235
 	echo '
1177 1236
 		', comma_format($return['num_guests']), ' ', $return['num_guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', comma_format($return['num_users_online']), ' ', $return['num_users_online'] == 1 ? $txt['user'] : $txt['users'];
1178 1237
 
1179 1238
 	$bracketList = array();
1180
-	if (!empty($user_info['buddies']))
1181
-		$bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
1182
-	if (!empty($return['num_spiders']))
1183
-		$bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
1184
-	if (!empty($return['num_users_hidden']))
1185
-		$bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden'];
1239
+	if (!empty($user_info['buddies'])) {
1240
+			$bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
1241
+	}
1242
+	if (!empty($return['num_spiders'])) {
1243
+			$bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
1244
+	}
1245
+	if (!empty($return['num_users_hidden'])) {
1246
+			$bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden'];
1247
+	}
1186 1248
 
1187
-	if (!empty($bracketList))
1188
-		echo ' (' . implode(', ', $bracketList) . ')';
1249
+	if (!empty($bracketList)) {
1250
+			echo ' (' . implode(', ', $bracketList) . ')';
1251
+	}
1189 1252
 
1190 1253
 	echo '<br>
1191 1254
 			', implode(', ', $return['list_users_online']);
1192 1255
 
1193 1256
 	// Showing membergroups?
1194
-	if (!empty($settings['show_group_key']) && !empty($return['membergroups']))
1195
-		echo '<br>
1257
+	if (!empty($settings['show_group_key']) && !empty($return['membergroups'])) {
1258
+			echo '<br>
1196 1259
 			[' . implode(']&nbsp;&nbsp;[', $return['membergroups']) . ']';
1197
-}
1260
+	}
1261
+	}
1198 1262
 
1199 1263
 /**
1200 1264
  * Just like whosOnline except it also logs the online presence.
@@ -1205,11 +1269,12 @@  discard block
 block discarded – undo
1205 1269
 {
1206 1270
 	writeLog();
1207 1271
 
1208
-	if ($output_method != 'echo')
1209
-		return ssi_whosOnline($output_method);
1210
-	else
1211
-		ssi_whosOnline($output_method);
1212
-}
1272
+	if ($output_method != 'echo') {
1273
+			return ssi_whosOnline($output_method);
1274
+	} else {
1275
+			ssi_whosOnline($output_method);
1276
+	}
1277
+	}
1213 1278
 
1214 1279
 // Shows a login box.
1215 1280
 /**
@@ -1222,11 +1287,13 @@  discard block
 block discarded – undo
1222 1287
 {
1223 1288
 	global $scripturl, $txt, $user_info, $context;
1224 1289
 
1225
-	if ($redirect_to != '')
1226
-		$_SESSION['login_url'] = $redirect_to;
1290
+	if ($redirect_to != '') {
1291
+			$_SESSION['login_url'] = $redirect_to;
1292
+	}
1227 1293
 
1228
-	if ($output_method != 'echo' || !$user_info['is_guest'])
1229
-		return $user_info['is_guest'];
1294
+	if ($output_method != 'echo' || !$user_info['is_guest']) {
1295
+			return $user_info['is_guest'];
1296
+	}
1230 1297
 
1231 1298
 	// Create a login token
1232 1299
 	createToken('login');
@@ -1278,8 +1345,9 @@  discard block
 block discarded – undo
1278 1345
 
1279 1346
 	$boardsAllowed = array_intersect(boardsAllowedTo('poll_view'), boardsAllowedTo('poll_vote'));
1280 1347
 
1281
-	if (empty($boardsAllowed))
1282
-		return array();
1348
+	if (empty($boardsAllowed)) {
1349
+			return array();
1350
+	}
1283 1351
 
1284 1352
 	$request = $smcFunc['db_query']('', '
1285 1353
 		SELECT p.id_poll, p.question, t.id_topic, p.max_votes, p.guest_vote, p.hide_results, p.expire_time
@@ -1312,12 +1380,14 @@  discard block
 block discarded – undo
1312 1380
 	$smcFunc['db_free_result']($request);
1313 1381
 
1314 1382
 	// This user has voted on all the polls.
1315
-	if (empty($row) || !is_array($row))
1316
-		return array();
1383
+	if (empty($row) || !is_array($row)) {
1384
+			return array();
1385
+	}
1317 1386
 
1318 1387
 	// If this is a guest who's voted we'll through ourselves to show poll to show the results.
1319
-	if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote'])))))
1320
-		return ssi_showPoll($row['id_topic'], $output_method);
1388
+	if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))))) {
1389
+			return ssi_showPoll($row['id_topic'], $output_method);
1390
+	}
1321 1391
 
1322 1392
 	$request = $smcFunc['db_query']('', '
1323 1393
 		SELECT COUNT(DISTINCT id_member)
@@ -1381,8 +1451,9 @@  discard block
 block discarded – undo
1381 1451
 	// If mods want to do somthing with this list of polls, let them do that now.
1382 1452
 	call_integration_hook('integrate_ssi_recentPoll', array(&$return, $topPollInstead));
1383 1453
 
1384
-	if ($output_method != 'echo')
1385
-		return $return;
1454
+	if ($output_method != 'echo') {
1455
+			return $return;
1456
+	}
1386 1457
 
1387 1458
 	if ($allow_view_results)
1388 1459
 	{
@@ -1391,19 +1462,20 @@  discard block
 block discarded – undo
1391 1462
 			<strong>', $return['question'], '</strong><br>
1392 1463
 			', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : '';
1393 1464
 
1394
-		foreach ($return['options'] as $option)
1395
-			echo '
1465
+		foreach ($return['options'] as $option) {
1466
+					echo '
1396 1467
 			<label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>';
1468
+		}
1397 1469
 
1398 1470
 		echo '
1399 1471
 			<input type="submit" value="', $txt['poll_vote'], '" class="button">
1400 1472
 			<input type="hidden" name="poll" value="', $return['id'], '">
1401 1473
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1402 1474
 		</form>';
1475
+	} else {
1476
+			echo $txt['poll_cannot_see'];
1477
+	}
1403 1478
 	}
1404
-	else
1405
-		echo $txt['poll_cannot_see'];
1406
-}
1407 1479
 
1408 1480
 /**
1409 1481
  * Shows the poll from the specified topic
@@ -1417,13 +1489,15 @@  discard block
 block discarded – undo
1417 1489
 
1418 1490
 	$boardsAllowed = boardsAllowedTo('poll_view');
1419 1491
 
1420
-	if (empty($boardsAllowed))
1421
-		return array();
1492
+	if (empty($boardsAllowed)) {
1493
+			return array();
1494
+	}
1422 1495
 
1423
-	if ($topic === null && isset($_REQUEST['ssi_topic']))
1424
-		$topic = (int) $_REQUEST['ssi_topic'];
1425
-	else
1426
-		$topic = (int) $topic;
1496
+	if ($topic === null && isset($_REQUEST['ssi_topic'])) {
1497
+			$topic = (int) $_REQUEST['ssi_topic'];
1498
+	} else {
1499
+			$topic = (int) $topic;
1500
+	}
1427 1501
 
1428 1502
 	$request = $smcFunc['db_query']('', '
1429 1503
 		SELECT
@@ -1444,17 +1518,18 @@  discard block
 block discarded – undo
1444 1518
 	);
1445 1519
 
1446 1520
 	// Either this topic has no poll, or the user cannot view it.
1447
-	if ($smcFunc['db_num_rows']($request) == 0)
1448
-		return array();
1521
+	if ($smcFunc['db_num_rows']($request) == 0) {
1522
+			return array();
1523
+	}
1449 1524
 
1450 1525
 	$row = $smcFunc['db_fetch_assoc']($request);
1451 1526
 	$smcFunc['db_free_result']($request);
1452 1527
 
1453 1528
 	// Check if they can vote.
1454 1529
 	$already_voted = false;
1455
-	if (!empty($row['expire_time']) && $row['expire_time'] < time())
1456
-		$allow_vote = false;
1457
-	elseif ($user_info['is_guest'])
1530
+	if (!empty($row['expire_time']) && $row['expire_time'] < time()) {
1531
+			$allow_vote = false;
1532
+	} elseif ($user_info['is_guest'])
1458 1533
 	{
1459 1534
 		// There's a difference between "allowed to vote" and "already voted"...
1460 1535
 		$allow_vote = $row['guest_vote'];
@@ -1464,10 +1539,9 @@  discard block
 block discarded – undo
1464 1539
 		{
1465 1540
 			$already_voted = true;
1466 1541
 		}
1467
-	}
1468
-	elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board']))
1469
-		$allow_vote = false;
1470
-	else
1542
+	} elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board'])) {
1543
+			$allow_vote = false;
1544
+	} else
1471 1545
 	{
1472 1546
 		$request = $smcFunc['db_query']('', '
1473 1547
 			SELECT id_member
@@ -1549,8 +1623,9 @@  discard block
 block discarded – undo
1549 1623
 	// If mods want to do somthing with this poll, let them do that now.
1550 1624
 	call_integration_hook('integrate_ssi_showPoll', array(&$return));
1551 1625
 
1552
-	if ($output_method != 'echo')
1553
-		return $return;
1626
+	if ($output_method != 'echo') {
1627
+			return $return;
1628
+	}
1554 1629
 
1555 1630
 	if ($return['allow_vote'])
1556 1631
 	{
@@ -1559,17 +1634,17 @@  discard block
 block discarded – undo
1559 1634
 				<strong>', $return['question'], '</strong><br>
1560 1635
 				', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : '';
1561 1636
 
1562
-		foreach ($return['options'] as $option)
1563
-			echo '
1637
+		foreach ($return['options'] as $option) {
1638
+					echo '
1564 1639
 				<label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>';
1640
+		}
1565 1641
 
1566 1642
 		echo '
1567 1643
 				<input type="submit" value="', $txt['poll_vote'], '" class="button">
1568 1644
 				<input type="hidden" name="poll" value="', $return['id'], '">
1569 1645
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1570 1646
 			</form>';
1571
-	}
1572
-	else
1647
+	} else
1573 1648
 	{
1574 1649
 		echo '
1575 1650
 			<div class="ssi_poll">
@@ -1649,27 +1724,32 @@  discard block
 block discarded – undo
1649 1724
 			'is_approved' => 1,
1650 1725
 		)
1651 1726
 	);
1652
-	if ($smcFunc['db_num_rows']($request) == 0)
1653
-		die;
1727
+	if ($smcFunc['db_num_rows']($request) == 0) {
1728
+			die;
1729
+	}
1654 1730
 	$row = $smcFunc['db_fetch_assoc']($request);
1655 1731
 	$smcFunc['db_free_result']($request);
1656 1732
 
1657
-	if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time']))
1658
-		redirectexit('topic=' . $row['id_topic'] . '.0');
1733
+	if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) {
1734
+			redirectexit('topic=' . $row['id_topic'] . '.0');
1735
+	}
1659 1736
 
1660 1737
 	// Too many options checked?
1661
-	if (count($_REQUEST['options']) > $row['max_votes'])
1662
-		redirectexit('topic=' . $row['id_topic'] . '.0');
1738
+	if (count($_REQUEST['options']) > $row['max_votes']) {
1739
+			redirectexit('topic=' . $row['id_topic'] . '.0');
1740
+	}
1663 1741
 
1664 1742
 	// It's a guest who has already voted?
1665 1743
 	if ($user_info['is_guest'])
1666 1744
 	{
1667 1745
 		// Guest voting disabled?
1668
-		if (!$row['guest_vote'])
1669
-			redirectexit('topic=' . $row['id_topic'] . '.0');
1746
+		if (!$row['guest_vote']) {
1747
+					redirectexit('topic=' . $row['id_topic'] . '.0');
1748
+		}
1670 1749
 		// Already voted?
1671
-		elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote'])))
1672
-			redirectexit('topic=' . $row['id_topic'] . '.0');
1750
+		elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))) {
1751
+					redirectexit('topic=' . $row['id_topic'] . '.0');
1752
+		}
1673 1753
 	}
1674 1754
 
1675 1755
 	$sOptions = array();
@@ -1723,11 +1803,13 @@  discard block
 block discarded – undo
1723 1803
 {
1724 1804
 	global $scripturl, $txt, $context;
1725 1805
 
1726
-	if (!allowedTo('search_posts'))
1727
-		return;
1806
+	if (!allowedTo('search_posts')) {
1807
+			return;
1808
+	}
1728 1809
 
1729
-	if ($output_method != 'echo')
1730
-		return $scripturl . '?action=search';
1810
+	if ($output_method != 'echo') {
1811
+			return $scripturl . '?action=search';
1812
+	}
1731 1813
 
1732 1814
 	echo '
1733 1815
 		<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
@@ -1749,8 +1831,9 @@  discard block
 block discarded – undo
1749 1831
 	// If mods want to do somthing with the news, let them do that now. Don't need to pass the news line itself, since it is already in $context.
1750 1832
 	call_integration_hook('integrate_ssi_news');
1751 1833
 
1752
-	if ($output_method != 'echo')
1753
-		return $context['random_news_line'];
1834
+	if ($output_method != 'echo') {
1835
+			return $context['random_news_line'];
1836
+	}
1754 1837
 
1755 1838
 	echo $context['random_news_line'];
1756 1839
 }
@@ -1764,8 +1847,9 @@  discard block
 block discarded – undo
1764 1847
 {
1765 1848
 	global $scripturl, $modSettings, $user_info;
1766 1849
 
1767
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view'))
1768
-		return;
1850
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view')) {
1851
+			return;
1852
+	}
1769 1853
 
1770 1854
 	$eventOptions = array(
1771 1855
 		'include_birthdays' => true,
@@ -1776,13 +1860,15 @@  discard block
 block discarded – undo
1776 1860
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1777 1861
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1778 1862
 
1779
-	if ($output_method != 'echo')
1780
-		return $return['calendar_birthdays'];
1863
+	if ($output_method != 'echo') {
1864
+			return $return['calendar_birthdays'];
1865
+	}
1781 1866
 
1782
-	foreach ($return['calendar_birthdays'] as $member)
1783
-		echo '
1867
+	foreach ($return['calendar_birthdays'] as $member) {
1868
+			echo '
1784 1869
 			<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">' . $member['name'] . '</span>' . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>' . (!$member['is_last'] ? ', ' : '');
1785
-}
1870
+	}
1871
+	}
1786 1872
 
1787 1873
 /**
1788 1874
  * Shows today's holidays.
@@ -1793,8 +1879,9 @@  discard block
 block discarded – undo
1793 1879
 {
1794 1880
 	global $modSettings, $user_info;
1795 1881
 
1796
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1797
-		return;
1882
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1883
+			return;
1884
+	}
1798 1885
 
1799 1886
 	$eventOptions = array(
1800 1887
 		'include_holidays' => true,
@@ -1805,8 +1892,9 @@  discard block
 block discarded – undo
1805 1892
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1806 1893
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1807 1894
 
1808
-	if ($output_method != 'echo')
1809
-		return $return['calendar_holidays'];
1895
+	if ($output_method != 'echo') {
1896
+			return $return['calendar_holidays'];
1897
+	}
1810 1898
 
1811 1899
 	echo '
1812 1900
 		', implode(', ', $return['calendar_holidays']);
@@ -1820,8 +1908,9 @@  discard block
 block discarded – undo
1820 1908
 {
1821 1909
 	global $modSettings, $user_info;
1822 1910
 
1823
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1824
-		return;
1911
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1912
+			return;
1913
+	}
1825 1914
 
1826 1915
 	$eventOptions = array(
1827 1916
 		'include_events' => true,
@@ -1832,14 +1921,16 @@  discard block
 block discarded – undo
1832 1921
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1833 1922
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1834 1923
 
1835
-	if ($output_method != 'echo')
1836
-		return $return['calendar_events'];
1924
+	if ($output_method != 'echo') {
1925
+			return $return['calendar_events'];
1926
+	}
1837 1927
 
1838 1928
 	foreach ($return['calendar_events'] as $event)
1839 1929
 	{
1840
-		if ($event['can_edit'])
1841
-			echo '
1930
+		if ($event['can_edit']) {
1931
+					echo '
1842 1932
 	<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
1933
+		}
1843 1934
 		echo '
1844 1935
 	' . $event['link'] . (!$event['is_last'] ? ', ' : '');
1845 1936
 	}
@@ -1854,8 +1945,9 @@  discard block
 block discarded – undo
1854 1945
 {
1855 1946
 	global $modSettings, $txt, $scripturl, $user_info;
1856 1947
 
1857
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1858
-		return;
1948
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1949
+			return;
1950
+	}
1859 1951
 
1860 1952
 	$eventOptions = array(
1861 1953
 		'include_birthdays' => allowedTo('profile_view'),
@@ -1868,19 +1960,22 @@  discard block
 block discarded – undo
1868 1960
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1869 1961
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1870 1962
 
1871
-	if ($output_method != 'echo')
1872
-		return $return;
1963
+	if ($output_method != 'echo') {
1964
+			return $return;
1965
+	}
1873 1966
 
1874
-	if (!empty($return['calendar_holidays']))
1875
-		echo '
1967
+	if (!empty($return['calendar_holidays'])) {
1968
+			echo '
1876 1969
 			<span class="holiday">' . $txt['calendar_prompt'] . ' ' . implode(', ', $return['calendar_holidays']) . '<br></span>';
1970
+	}
1877 1971
 	if (!empty($return['calendar_birthdays']))
1878 1972
 	{
1879 1973
 		echo '
1880 1974
 			<span class="birthday">' . $txt['birthdays_upcoming'] . '</span> ';
1881
-		foreach ($return['calendar_birthdays'] as $member)
1882
-			echo '
1975
+		foreach ($return['calendar_birthdays'] as $member) {
1976
+					echo '
1883 1977
 			<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', !$member['is_last'] ? ', ' : '';
1978
+		}
1884 1979
 		echo '
1885 1980
 			<br>';
1886 1981
 	}
@@ -1890,9 +1985,10 @@  discard block
 block discarded – undo
1890 1985
 			<span class="event">' . $txt['events_upcoming'] . '</span> ';
1891 1986
 		foreach ($return['calendar_events'] as $event)
1892 1987
 		{
1893
-			if ($event['can_edit'])
1894
-				echo '
1988
+			if ($event['can_edit']) {
1989
+							echo '
1895 1990
 			<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
1991
+			}
1896 1992
 			echo '
1897 1993
 			' . $event['link'] . (!$event['is_last'] ? ', ' : '');
1898 1994
 		}
@@ -1916,25 +2012,29 @@  discard block
 block discarded – undo
1916 2012
 	loadLanguage('Stats');
1917 2013
 
1918 2014
 	// Must be integers....
1919
-	if ($limit === null)
1920
-		$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
1921
-	else
1922
-		$limit = (int) $limit;
1923
-
1924
-	if ($start === null)
1925
-		$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1926
-	else
1927
-		$start = (int) $start;
1928
-
1929
-	if ($board !== null)
1930
-		$board = (int) $board;
1931
-	elseif (isset($_GET['board']))
1932
-		$board = (int) $_GET['board'];
1933
-
1934
-	if ($length === null)
1935
-		$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
1936
-	else
1937
-		$length = (int) $length;
2015
+	if ($limit === null) {
2016
+			$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
2017
+	} else {
2018
+			$limit = (int) $limit;
2019
+	}
2020
+
2021
+	if ($start === null) {
2022
+			$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
2023
+	} else {
2024
+			$start = (int) $start;
2025
+	}
2026
+
2027
+	if ($board !== null) {
2028
+			$board = (int) $board;
2029
+	} elseif (isset($_GET['board'])) {
2030
+			$board = (int) $_GET['board'];
2031
+	}
2032
+
2033
+	if ($length === null) {
2034
+			$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
2035
+	} else {
2036
+			$length = (int) $length;
2037
+	}
1938 2038
 
1939 2039
 	$limit = max(0, $limit);
1940 2040
 	$start = max(0, $start);
@@ -1952,17 +2052,19 @@  discard block
 block discarded – undo
1952 2052
 	);
1953 2053
 	if ($smcFunc['db_num_rows']($request) == 0)
1954 2054
 	{
1955
-		if ($output_method == 'echo')
1956
-			die($txt['ssi_no_guests']);
1957
-		else
1958
-			return array();
2055
+		if ($output_method == 'echo') {
2056
+					die($txt['ssi_no_guests']);
2057
+		} else {
2058
+					return array();
2059
+		}
1959 2060
 	}
1960 2061
 	list ($board) = $smcFunc['db_fetch_row']($request);
1961 2062
 	$smcFunc['db_free_result']($request);
1962 2063
 
1963 2064
 	$icon_sources = array();
1964
-	foreach ($context['stable_icons'] as $icon)
1965
-		$icon_sources[$icon] = 'images_url';
2065
+	foreach ($context['stable_icons'] as $icon) {
2066
+			$icon_sources[$icon] = 'images_url';
2067
+	}
1966 2068
 
1967 2069
 	if (!empty($modSettings['enable_likes']))
1968 2070
 	{
@@ -1985,12 +2087,14 @@  discard block
 block discarded – undo
1985 2087
 		)
1986 2088
 	);
1987 2089
 	$posts = array();
1988
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1989
-		$posts[] = $row['id_first_msg'];
2090
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2091
+			$posts[] = $row['id_first_msg'];
2092
+	}
1990 2093
 	$smcFunc['db_free_result']($request);
1991 2094
 
1992
-	if (empty($posts))
1993
-		return array();
2095
+	if (empty($posts)) {
2096
+			return array();
2097
+	}
1994 2098
 
1995 2099
 	// Find the posts.
1996 2100
 	$request = $smcFunc['db_query']('', '
@@ -2020,24 +2124,28 @@  discard block
 block discarded – undo
2020 2124
 			$last_space = strrpos($row['body'], ' ');
2021 2125
 			$last_open = strrpos($row['body'], '<');
2022 2126
 			$last_close = strrpos($row['body'], '>');
2023
-			if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6)
2024
-				$cutoff = $last_open;
2025
-			elseif (empty($last_close) || $last_close < $last_open)
2026
-				$cutoff = $last_space;
2127
+			if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6) {
2128
+							$cutoff = $last_open;
2129
+			} elseif (empty($last_close) || $last_close < $last_open) {
2130
+							$cutoff = $last_space;
2131
+			}
2027 2132
 
2028
-			if ($cutoff !== false)
2029
-				$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
2133
+			if ($cutoff !== false) {
2134
+							$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
2135
+			}
2030 2136
 			$row['body'] .= '...';
2031 2137
 		}
2032 2138
 
2033 2139
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
2034 2140
 
2035
-		if (!empty($recycle_board) && $row['id_board'] == $recycle_board)
2036
-			$row['icon'] = 'recycled';
2141
+		if (!empty($recycle_board) && $row['id_board'] == $recycle_board) {
2142
+					$row['icon'] = 'recycled';
2143
+		}
2037 2144
 
2038 2145
 		// Check that this message icon is there...
2039
-		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
2040
-			$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
2146
+		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) {
2147
+					$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
2148
+		}
2041 2149
 
2042 2150
 		censorText($row['subject']);
2043 2151
 		censorText($row['body']);
@@ -2074,16 +2182,18 @@  discard block
 block discarded – undo
2074 2182
 	}
2075 2183
 	$smcFunc['db_free_result']($request);
2076 2184
 
2077
-	if (empty($return))
2078
-		return $return;
2185
+	if (empty($return)) {
2186
+			return $return;
2187
+	}
2079 2188
 
2080 2189
 	$return[count($return) - 1]['is_last'] = true;
2081 2190
 
2082 2191
 	// If mods want to do somthing with this list of posts, let them do that now.
2083 2192
 	call_integration_hook('integrate_ssi_boardNews', array(&$return));
2084 2193
 
2085
-	if ($output_method != 'echo')
2086
-		return $return;
2194
+	if ($output_method != 'echo') {
2195
+			return $return;
2196
+	}
2087 2197
 
2088 2198
 	foreach ($return as $news)
2089 2199
 	{
@@ -2135,9 +2245,10 @@  discard block
 block discarded – undo
2135 2245
 		echo '
2136 2246
 			</div>';
2137 2247
 
2138
-		if (!$news['is_last'])
2139
-			echo '
2248
+		if (!$news['is_last']) {
2249
+					echo '
2140 2250
 			<hr>';
2251
+		}
2141 2252
 	}
2142 2253
 }
2143 2254
 
@@ -2151,8 +2262,9 @@  discard block
 block discarded – undo
2151 2262
 {
2152 2263
 	global $user_info, $scripturl, $modSettings, $txt, $context, $smcFunc;
2153 2264
 
2154
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
2155
-		return;
2265
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
2266
+			return;
2267
+	}
2156 2268
 
2157 2269
 	// Find all events which are happening in the near future that the member can see.
2158 2270
 	$request = $smcFunc['db_query']('', '
@@ -2178,20 +2290,23 @@  discard block
 block discarded – undo
2178 2290
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2179 2291
 	{
2180 2292
 		// Check if we've already come by an event linked to this same topic with the same title... and don't display it if we have.
2181
-		if (!empty($duplicates[$row['title'] . $row['id_topic']]))
2182
-			continue;
2293
+		if (!empty($duplicates[$row['title'] . $row['id_topic']])) {
2294
+					continue;
2295
+		}
2183 2296
 
2184 2297
 		// Censor the title.
2185 2298
 		censorText($row['title']);
2186 2299
 
2187
-		if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false)))
2188
-			$date = strftime('%Y-%m-%d', forum_time(false));
2189
-		else
2190
-			$date = $row['start_date'];
2300
+		if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false))) {
2301
+					$date = strftime('%Y-%m-%d', forum_time(false));
2302
+		} else {
2303
+					$date = $row['start_date'];
2304
+		}
2191 2305
 
2192 2306
 		// If the topic it is attached to is not approved then don't link it.
2193
-		if (!empty($row['id_first_msg']) && !$row['approved'])
2194
-			$row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0;
2307
+		if (!empty($row['id_first_msg']) && !$row['approved']) {
2308
+					$row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0;
2309
+		}
2195 2310
 
2196 2311
 		$allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false;
2197 2312
 
@@ -2217,24 +2332,27 @@  discard block
 block discarded – undo
2217 2332
 	}
2218 2333
 	$smcFunc['db_free_result']($request);
2219 2334
 
2220
-	foreach ($return as $mday => $array)
2221
-		$return[$mday][count($array) - 1]['is_last'] = true;
2335
+	foreach ($return as $mday => $array) {
2336
+			$return[$mday][count($array) - 1]['is_last'] = true;
2337
+	}
2222 2338
 
2223 2339
 	// If mods want to do somthing with this list of events, let them do that now.
2224 2340
 	call_integration_hook('integrate_ssi_recentEvents', array(&$return));
2225 2341
 
2226
-	if ($output_method != 'echo' || empty($return))
2227
-		return $return;
2342
+	if ($output_method != 'echo' || empty($return)) {
2343
+			return $return;
2344
+	}
2228 2345
 
2229 2346
 	// Well the output method is echo.
2230 2347
 	echo '
2231 2348
 			<span class="event">' . $txt['events'] . '</span> ';
2232
-	foreach ($return as $mday => $array)
2233
-		foreach ($array as $event)
2349
+	foreach ($return as $mday => $array) {
2350
+			foreach ($array as $event)
2234 2351
 		{
2235 2352
 			if ($event['can_edit'])
2236 2353
 				echo '
2237 2354
 				<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
2355
+	}
2238 2356
 
2239 2357
 			echo '
2240 2358
 				' . $event['link'] . (!$event['is_last'] ? ', ' : '');
@@ -2253,8 +2371,9 @@  discard block
 block discarded – undo
2253 2371
 	global $smcFunc;
2254 2372
 
2255 2373
 	// If $id is null, this was most likely called from a query string and should do nothing.
2256
-	if ($id === null)
2257
-		return;
2374
+	if ($id === null) {
2375
+			return;
2376
+	}
2258 2377
 
2259 2378
 	$request = $smcFunc['db_query']('', '
2260 2379
 		SELECT passwd, member_name, is_activated
@@ -2286,8 +2405,9 @@  discard block
 block discarded – undo
2286 2405
 	$attachments_boards = boardsAllowedTo('view_attachments');
2287 2406
 
2288 2407
 	// No boards?  Adios amigo.
2289
-	if (empty($attachments_boards))
2290
-		return array();
2408
+	if (empty($attachments_boards)) {
2409
+			return array();
2410
+	}
2291 2411
 
2292 2412
 	// Is it an array?
2293 2413
 	$attachment_ext = (array) $attachment_ext;
@@ -2371,8 +2491,9 @@  discard block
 block discarded – undo
2371 2491
 	call_integration_hook('integrate_ssi_recentAttachments', array(&$attachments));
2372 2492
 
2373 2493
 	// So you just want an array?  Here you can have it.
2374
-	if ($output_method == 'array' || empty($attachments))
2375
-		return $attachments;
2494
+	if ($output_method == 'array' || empty($attachments)) {
2495
+			return $attachments;
2496
+	}
2376 2497
 
2377 2498
 	// Give them the default.
2378 2499
 	echo '
@@ -2383,14 +2504,15 @@  discard block
 block discarded – undo
2383 2504
 				<th style="text-align: left; padding: 2">', $txt['downloads'], '</th>
2384 2505
 				<th style="text-align: left; padding: 2">', $txt['filesize'], '</th>
2385 2506
 			</tr>';
2386
-	foreach ($attachments as $attach)
2387
-		echo '
2507
+	foreach ($attachments as $attach) {
2508
+			echo '
2388 2509
 			<tr>
2389 2510
 				<td>', $attach['file']['link'], '</td>
2390 2511
 				<td>', $attach['member']['link'], '</td>
2391 2512
 				<td style="text-align: center">', $attach['file']['downloads'], '</td>
2392 2513
 				<td>', $attach['file']['filesize'], '</td>
2393 2514
 			</tr>';
2515
+	}
2394 2516
 	echo '
2395 2517
 		</table>';
2396 2518
 }
Please login to merge, or discard this patch.
other/install.php 1 patch
Braces   +470 added lines, -350 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;',
@@ -76,12 +78,14 @@  discard block
 block discarded – undo
76 78
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
77 79
 
78 80
 			// Is it reserved?
79
-			if ($value == 'pg_')
80
-				return $txt['error_db_prefix_reserved'];
81
+			if ($value == 'pg_') {
82
+							return $txt['error_db_prefix_reserved'];
83
+			}
81 84
 
82 85
 			// Is the prefix numeric?
83
-			if (preg_match('~^\d~', $value))
84
-				return $txt['error_db_prefix_numeric'];
86
+			if (preg_match('~^\d~', $value)) {
87
+							return $txt['error_db_prefix_numeric'];
88
+			}
85 89
 
86 90
 			return true;
87 91
 		},
@@ -128,10 +132,11 @@  discard block
 block discarded – undo
128 132
 		$incontext['skip'] = false;
129 133
 
130 134
 		// Call the step and if it returns false that means pause!
131
-		if (function_exists($step[2]) && $step[2]() === false)
132
-			break;
133
-		elseif (function_exists($step[2]))
134
-			$incontext['current_step']++;
135
+		if (function_exists($step[2]) && $step[2]() === false) {
136
+					break;
137
+		} elseif (function_exists($step[2])) {
138
+					$incontext['current_step']++;
139
+		}
135 140
 
136 141
 		// No warnings pass on.
137 142
 		$incontext['warning'] = '';
@@ -147,8 +152,9 @@  discard block
 block discarded – undo
147 152
 	global $databases;
148 153
 
149 154
 	// Just so people using older versions of PHP aren't left in the cold.
150
-	if (!isset($_SERVER['PHP_SELF']))
151
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
155
+	if (!isset($_SERVER['PHP_SELF'])) {
156
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
157
+	}
152 158
 
153 159
 	// Enable error reporting for fatal errors.
154 160
 	error_reporting(E_ERROR | E_PARSE);
@@ -164,21 +170,23 @@  discard block
 block discarded – undo
164 170
 	{
165 171
 		ob_start();
166 172
 
167
-		if (ini_get('session.save_handler') == 'user')
168
-			@ini_set('session.save_handler', 'files');
169
-		if (function_exists('session_start'))
170
-			@session_start();
171
-	}
172
-	else
173
+		if (ini_get('session.save_handler') == 'user') {
174
+					@ini_set('session.save_handler', 'files');
175
+		}
176
+		if (function_exists('session_start')) {
177
+					@session_start();
178
+		}
179
+	} else
173 180
 	{
174 181
 		ob_start('ob_gzhandler');
175 182
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
183
+		if (ini_get('session.save_handler') == 'user') {
184
+					@ini_set('session.save_handler', 'files');
185
+		}
178 186
 		session_start();
179 187
 
180
-		if (!headers_sent())
181
-			echo '<!DOCTYPE html>
188
+		if (!headers_sent()) {
189
+					echo '<!DOCTYPE html>
182 190
 <html>
183 191
 	<head>
184 192
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -187,14 +195,16 @@  discard block
 block discarded – undo
187 195
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
188 196
 	</body>
189 197
 </html>';
198
+		}
190 199
 		exit;
191 200
 	}
192 201
 
193 202
 	// Add slashes, as long as they aren't already being added.
194
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
195
-		foreach ($_POST as $k => $v)
203
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
204
+			foreach ($_POST as $k => $v)
196 205
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
197 206
 				$_POST[$k] = addslashes($v);
207
+	}
198 208
 
199 209
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
200 210
 	if (isset($_GET['delete']))
@@ -215,8 +225,7 @@  discard block
 block discarded – undo
215 225
 			$ftp->close();
216 226
 
217 227
 			unset($_SESSION['installer_temp_ftp']);
218
-		}
219
-		else
228
+		} else
220 229
 		{
221 230
 			@unlink(__FILE__);
222 231
 
@@ -230,10 +239,11 @@  discard block
 block discarded – undo
230 239
 		// Now just redirect to a blank.png...
231 240
 		$secure = false;
232 241
 
233
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
234
-			$secure = true;
235
-		elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
236
-			$secure = true;
242
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
243
+					$secure = true;
244
+		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
245
+					$secure = true;
246
+		}
237 247
 
238 248
 		header('location: http' . ($secure ? 's' : '') . '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png');
239 249
 		exit;
@@ -244,10 +254,11 @@  discard block
 block discarded – undo
244 254
 	{
245 255
 		// Get PHP's default timezone, if set
246 256
 		$ini_tz = ini_get('date.timezone');
247
-		if (!empty($ini_tz))
248
-			$timezone_id = $ini_tz;
249
-		else
250
-			$timezone_id = '';
257
+		if (!empty($ini_tz)) {
258
+					$timezone_id = $ini_tz;
259
+		} else {
260
+					$timezone_id = '';
261
+		}
251 262
 
252 263
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
253 264
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -277,8 +288,9 @@  discard block
 block discarded – undo
277 288
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
278 289
 		while ($entry = $dir->read())
279 290
 		{
280
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
281
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
291
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
292
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
293
+			}
282 294
 		}
283 295
 		$dir->close();
284 296
 	}
@@ -313,10 +325,11 @@  discard block
 block discarded – undo
313 325
 	}
314 326
 
315 327
 	// Override the language file?
316
-	if (isset($_GET['lang_file']))
317
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
318
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
319
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
328
+	if (isset($_GET['lang_file'])) {
329
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
330
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
331
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
332
+	}
320 333
 
321 334
 	// Make sure it exists, if it doesn't reset it.
322 335
 	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']))
@@ -325,8 +338,9 @@  discard block
 block discarded – undo
325 338
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
326 339
 
327 340
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
328
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
329
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
341
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
342
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
343
+		}
330 344
 	}
331 345
 
332 346
 	// And now include the actual language file itself.
@@ -343,15 +357,18 @@  discard block
 block discarded – undo
343 357
 	global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings;
344 358
 	global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist;
345 359
 
346
-	if (empty($sourcedir))
347
-		$sourcedir = dirname(__FILE__) . '/Sources';
360
+	if (empty($sourcedir)) {
361
+			$sourcedir = dirname(__FILE__) . '/Sources';
362
+	}
348 363
 
349 364
 	// Need this to check whether we need the database password.
350 365
 	require(dirname(__FILE__) . '/Settings.php');
351
-	if (!defined('SMF'))
352
-		define('SMF', 1);
353
-	if (empty($smcFunc))
354
-		$smcFunc = array();
366
+	if (!defined('SMF')) {
367
+			define('SMF', 1);
368
+	}
369
+	if (empty($smcFunc)) {
370
+			$smcFunc = array();
371
+	}
355 372
 
356 373
 	$modSettings['disableQueryCheck'] = true;
357 374
 
@@ -359,8 +376,9 @@  discard block
 block discarded – undo
359 376
 	if (!$db_connection)
360 377
 	{
361 378
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
362
-		if (version_compare(PHP_VERSION, '5', '<'))
363
-			require_once($sourcedir . '/Subs-Compat.php');
379
+		if (version_compare(PHP_VERSION, '5', '<')) {
380
+					require_once($sourcedir . '/Subs-Compat.php');
381
+		}
364 382
 
365 383
 		$db_options = array('persist' => $db_persist);
366 384
 		$port = '';
@@ -371,19 +389,20 @@  discard block
 block discarded – undo
371 389
 			if ($db_type == 'mysql')
372 390
 			{
373 391
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
374
-			}
375
-			elseif ($db_type == 'postgresql')
392
+			} elseif ($db_type == 'postgresql')
376 393
 			{
377 394
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
378 395
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
379 396
 			}
380 397
 		}
381 398
 
382
-		if (!empty($port))
383
-			$db_options['port'] = $port;
399
+		if (!empty($port)) {
400
+					$db_options['port'] = $port;
401
+		}
384 402
 
385
-		if (!$db_connection)
386
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
403
+		if (!$db_connection) {
404
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
405
+		}
387 406
 	}
388 407
 }
389 408
 
@@ -411,8 +430,9 @@  discard block
 block discarded – undo
411 430
 		// @todo REMOVE THIS!!
412 431
 		else
413 432
 		{
414
-			if (function_exists('doStep' . $_GET['step']))
415
-				call_user_func('doStep' . $_GET['step']);
433
+			if (function_exists('doStep' . $_GET['step'])) {
434
+							call_user_func('doStep' . $_GET['step']);
435
+			}
416 436
 		}
417 437
 		// Show the footer.
418 438
 		template_install_below();
@@ -430,8 +450,9 @@  discard block
 block discarded – undo
430 450
 	$incontext['sub_template'] = 'welcome_message';
431 451
 
432 452
 	// Done the submission?
433
-	if (isset($_POST['contbutt']))
434
-		return true;
453
+	if (isset($_POST['contbutt'])) {
454
+			return true;
455
+	}
435 456
 
436 457
 	// See if we think they have already installed it?
437 458
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -439,14 +460,17 @@  discard block
 block discarded – undo
439 460
 		$probably_installed = 0;
440 461
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
441 462
 		{
442
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
443
-				$probably_installed++;
444
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
445
-				$probably_installed++;
463
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
464
+							$probably_installed++;
465
+			}
466
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
467
+							$probably_installed++;
468
+			}
446 469
 		}
447 470
 
448
-		if ($probably_installed == 2)
449
-			$incontext['warning'] = $txt['error_already_installed'];
471
+		if ($probably_installed == 2) {
472
+					$incontext['warning'] = $txt['error_already_installed'];
473
+		}
450 474
 	}
451 475
 
452 476
 	// Is some database support even compiled in?
@@ -461,45 +485,54 @@  discard block
 block discarded – undo
461 485
 				$databases[$key]['supported'] = false;
462 486
 				$notFoundSQLFile = true;
463 487
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
488
+			} else {
489
+							$incontext['supported_databases'][] = $db;
464 490
 			}
465
-			else
466
-				$incontext['supported_databases'][] = $db;
467 491
 		}
468 492
 	}
469 493
 
470 494
 	// Check the PHP version.
471
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>=')))
472
-		$error = 'error_php_too_low';
495
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) {
496
+			$error = 'error_php_too_low';
497
+	}
473 498
 	// Make sure we have a supported database
474
-	elseif (empty($incontext['supported_databases']))
475
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
499
+	elseif (empty($incontext['supported_databases'])) {
500
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
501
+	}
476 502
 	// How about session support?  Some crazy sysadmin remove it?
477
-	elseif (!function_exists('session_start'))
478
-		$error = 'error_session_missing';
503
+	elseif (!function_exists('session_start')) {
504
+			$error = 'error_session_missing';
505
+	}
479 506
 	// Make sure they uploaded all the files.
480
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
481
-		$error = 'error_missing_files';
507
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
508
+			$error = 'error_missing_files';
509
+	}
482 510
 	// Very simple check on the session.save_path for Windows.
483 511
 	// @todo Move this down later if they don't use database-driven sessions?
484
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
485
-		$error = 'error_session_save_path';
512
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
513
+			$error = 'error_session_save_path';
514
+	}
486 515
 
487 516
 	// Since each of the three messages would look the same, anyway...
488
-	if (isset($error))
489
-		$incontext['error'] = $txt[$error];
517
+	if (isset($error)) {
518
+			$incontext['error'] = $txt[$error];
519
+	}
490 520
 
491 521
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
492
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
493
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
522
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
523
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
524
+	}
494 525
 
495 526
 	// Confirm mbstring is loaded...
496
-	if (!extension_loaded('mbstring'))
497
-		$incontext['error'] = $txt['install_no_mbstring'];
527
+	if (!extension_loaded('mbstring')) {
528
+			$incontext['error'] = $txt['install_no_mbstring'];
529
+	}
498 530
 
499 531
 	// Check for https stream support.
500 532
 	$supported_streams = stream_get_wrappers();
501
-	if (!in_array('https', $supported_streams))
502
-		$incontext['warning'] = $txt['install_no_https'];
533
+	if (!in_array('https', $supported_streams)) {
534
+			$incontext['warning'] = $txt['install_no_https'];
535
+	}
503 536
 
504 537
 	return false;
505 538
 }
@@ -524,12 +557,14 @@  discard block
 block discarded – undo
524 557
 		'Settings_bak.php',
525 558
 	);
526 559
 
527
-	foreach ($incontext['detected_languages'] as $lang => $temp)
528
-		$extra_files[] = 'Themes/default/languages/' . $lang;
560
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
561
+			$extra_files[] = 'Themes/default/languages/' . $lang;
562
+	}
529 563
 
530 564
 	// With mod_security installed, we could attempt to fix it with .htaccess.
531
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
532
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
565
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
566
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
567
+	}
533 568
 
534 569
 	$failed_files = array();
535 570
 
@@ -541,20 +576,23 @@  discard block
 block discarded – undo
541 576
 		foreach ($writable_files as $file)
542 577
 		{
543 578
 			// Some files won't exist, try to address up front
544
-			if (!file_exists(dirname(__FILE__) . '/' . $file))
545
-				@touch(dirname(__FILE__) . '/' . $file);
579
+			if (!file_exists(dirname(__FILE__) . '/' . $file)) {
580
+							@touch(dirname(__FILE__) . '/' . $file);
581
+			}
546 582
 			// NOW do the writable check...
547 583
 			if (!is_writable(dirname(__FILE__) . '/' . $file))
548 584
 			{
549 585
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
550 586
 
551 587
 				// Well, 755 hopefully worked... if not, try 777.
552
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
553
-					$failed_files[] = $file;
588
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
589
+									$failed_files[] = $file;
590
+				}
554 591
 			}
555 592
 		}
556
-		foreach ($extra_files as $file)
557
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
593
+		foreach ($extra_files as $file) {
594
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
595
+		}
558 596
 	}
559 597
 	// Windows is trickier.  Let's try opening for r+...
560 598
 	else
@@ -564,30 +602,35 @@  discard block
 block discarded – undo
564 602
 		foreach ($writable_files as $file)
565 603
 		{
566 604
 			// Folders can't be opened for write... but the index.php in them can ;)
567
-			if (is_dir(dirname(__FILE__) . '/' . $file))
568
-				$file .= '/index.php';
605
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
606
+							$file .= '/index.php';
607
+			}
569 608
 
570 609
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
571 610
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
572 611
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
573 612
 
574 613
 			// Hmm, okay, try just for write in that case...
575
-			if (!is_resource($fp))
576
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
614
+			if (!is_resource($fp)) {
615
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
616
+			}
577 617
 
578
-			if (!is_resource($fp))
579
-				$failed_files[] = $file;
618
+			if (!is_resource($fp)) {
619
+							$failed_files[] = $file;
620
+			}
580 621
 
581 622
 			@fclose($fp);
582 623
 		}
583
-		foreach ($extra_files as $file)
584
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
624
+		foreach ($extra_files as $file) {
625
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
626
+		}
585 627
 	}
586 628
 
587 629
 	$failure = count($failed_files) >= 1;
588 630
 
589
-	if (!isset($_SERVER))
590
-		return !$failure;
631
+	if (!isset($_SERVER)) {
632
+			return !$failure;
633
+	}
591 634
 
592 635
 	// Put the list into context.
593 636
 	$incontext['failed_files'] = $failed_files;
@@ -635,19 +678,23 @@  discard block
 block discarded – undo
635 678
 
636 679
 		if (!isset($ftp) || $ftp->error !== false)
637 680
 		{
638
-			if (!isset($ftp))
639
-				$ftp = new ftp_connection(null);
681
+			if (!isset($ftp)) {
682
+							$ftp = new ftp_connection(null);
683
+			}
640 684
 			// Save the error so we can mess with listing...
641
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
642
-				$incontext['ftp_errors'][] = $ftp->last_message;
685
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
686
+							$incontext['ftp_errors'][] = $ftp->last_message;
687
+			}
643 688
 
644 689
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
645 690
 
646
-			if (empty($_POST['ftp_path']) && $found_path)
647
-				$_POST['ftp_path'] = $detect_path;
691
+			if (empty($_POST['ftp_path']) && $found_path) {
692
+							$_POST['ftp_path'] = $detect_path;
693
+			}
648 694
 
649
-			if (!isset($_POST['ftp_username']))
650
-				$_POST['ftp_username'] = $username;
695
+			if (!isset($_POST['ftp_username'])) {
696
+							$_POST['ftp_username'] = $username;
697
+			}
651 698
 
652 699
 			// Set the username etc, into context.
653 700
 			$incontext['ftp'] = array(
@@ -659,8 +706,7 @@  discard block
 block discarded – undo
659 706
 			);
660 707
 
661 708
 			return false;
662
-		}
663
-		else
709
+		} else
664 710
 		{
665 711
 			$_SESSION['installer_temp_ftp'] = array(
666 712
 				'server' => $_POST['ftp_server'],
@@ -674,10 +720,12 @@  discard block
 block discarded – undo
674 720
 
675 721
 			foreach ($failed_files as $file)
676 722
 			{
677
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
678
-					$ftp->chmod($file, 0755);
679
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
680
-					$ftp->chmod($file, 0777);
723
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
724
+									$ftp->chmod($file, 0755);
725
+				}
726
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
727
+									$ftp->chmod($file, 0777);
728
+				}
681 729
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
682 730
 				{
683 731
 					$failed_files_updated[] = $file;
@@ -733,15 +781,17 @@  discard block
 block discarded – undo
733 781
 
734 782
 			if (!$foundOne)
735 783
 			{
736
-				if (isset($db['default_host']))
737
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
784
+				if (isset($db['default_host'])) {
785
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
786
+				}
738 787
 				if (isset($db['default_user']))
739 788
 				{
740 789
 					$incontext['db']['user'] = ini_get($db['default_user']);
741 790
 					$incontext['db']['name'] = ini_get($db['default_user']);
742 791
 				}
743
-				if (isset($db['default_password']))
744
-					$incontext['db']['pass'] = ini_get($db['default_password']);
792
+				if (isset($db['default_password'])) {
793
+									$incontext['db']['pass'] = ini_get($db['default_password']);
794
+				}
745 795
 
746 796
 				// For simplicity and less confusion, leave the port blank by default
747 797
 				$incontext['db']['port'] = '';
@@ -760,10 +810,10 @@  discard block
 block discarded – undo
760 810
 		$incontext['db']['server'] = $_POST['db_server'];
761 811
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
762 812
 
763
-		if (!empty($_POST['db_port']))
764
-			$incontext['db']['port'] = $_POST['db_port'];
765
-	}
766
-	else
813
+		if (!empty($_POST['db_port'])) {
814
+					$incontext['db']['port'] = $_POST['db_port'];
815
+		}
816
+	} else
767 817
 	{
768 818
 		$incontext['db']['prefix'] = 'smf_';
769 819
 	}
@@ -799,10 +849,11 @@  discard block
 block discarded – undo
799 849
 		if (!empty($_POST['db_port']))
800 850
 		{
801 851
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
802
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
803
-				$vars['db_port'] = (int) $_POST['db_port'];
804
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
805
-				$vars['db_port'] = (int) $_POST['db_port'];
852
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
853
+							$vars['db_port'] = (int) $_POST['db_port'];
854
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
855
+							$vars['db_port'] = (int) $_POST['db_port'];
856
+			}
806 857
 		}
807 858
 
808 859
 		// God I hope it saved!
@@ -815,8 +866,9 @@  discard block
 block discarded – undo
815 866
 		// Make sure it works.
816 867
 		require(dirname(__FILE__) . '/Settings.php');
817 868
 
818
-		if (empty($sourcedir))
819
-			$sourcedir = dirname(__FILE__) . '/Sources';
869
+		if (empty($sourcedir)) {
870
+					$sourcedir = dirname(__FILE__) . '/Sources';
871
+		}
820 872
 
821 873
 		// Better find the database file!
822 874
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -826,18 +878,21 @@  discard block
 block discarded – undo
826 878
 		}
827 879
 
828 880
 		// Now include it for database functions!
829
-		if (!defined('SMF'))
830
-			define('SMF', 1);
881
+		if (!defined('SMF')) {
882
+					define('SMF', 1);
883
+		}
831 884
 
832 885
 		$modSettings['disableQueryCheck'] = true;
833
-		if (empty($smcFunc))
834
-			$smcFunc = array();
886
+		if (empty($smcFunc)) {
887
+					$smcFunc = array();
888
+		}
835 889
 
836 890
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
837 891
 
838 892
 		// What - running PHP4? The shame!
839
-		if (version_compare(PHP_VERSION, '5', '<'))
840
-			require_once($sourcedir . '/Subs-Compat.php');
893
+		if (version_compare(PHP_VERSION, '5', '<')) {
894
+					require_once($sourcedir . '/Subs-Compat.php');
895
+		}
841 896
 
842 897
 		// Attempt a connection.
843 898
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -925,12 +980,14 @@  discard block
 block discarded – undo
925 980
 	$incontext['page_title'] = $txt['install_settings'];
926 981
 
927 982
 	// Let's see if we got the database type correct.
928
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
929
-		$db_type = $_POST['db_type'];
983
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
984
+			$db_type = $_POST['db_type'];
985
+	}
930 986
 
931 987
 	// Else we'd better be able to get the connection.
932
-	else
933
-		load_database();
988
+	else {
989
+			load_database();
990
+	}
934 991
 
935 992
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
936 993
 
@@ -939,10 +996,11 @@  discard block
 block discarded – undo
939 996
 
940 997
 		$secure = false;
941 998
 
942
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
943
-			$secure = true;
944
-		elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
945
-			$secure = true;
999
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
1000
+					$secure = true;
1001
+		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
1002
+					$secure = true;
1003
+		}
946 1004
 
947 1005
 	// Now, to put what we've learned together... and add a path.
948 1006
 	$incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
@@ -974,18 +1032,21 @@  discard block
 block discarded – undo
974 1032
 	// Submitting?
975 1033
 	if (isset($_POST['boardurl']))
976 1034
 	{
977
-		if (substr($_POST['boardurl'], -10) == '/index.php')
978
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
979
-		elseif (substr($_POST['boardurl'], -1) == '/')
980
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
981
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
982
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1035
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1036
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1037
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1038
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1039
+		}
1040
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1041
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1042
+		}
983 1043
 
984 1044
 		//Make sure boardurl is aligned with ssl setting
985
-		if (empty($_POST['force_ssl']))
986
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
987
-		else
988
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1045
+		if (empty($_POST['force_ssl'])) {
1046
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
1047
+		} else {
1048
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1049
+		}
989 1050
 
990 1051
 		// Save these variables.
991 1052
 		$vars = array(
@@ -1024,10 +1085,10 @@  discard block
 block discarded – undo
1024 1085
 			{
1025 1086
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
1026 1087
 				return false;
1027
-			}
1028
-			else
1029
-				// Set the character set here.
1088
+			} else {
1089
+							// Set the character set here.
1030 1090
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1091
+			}
1031 1092
 		}
1032 1093
 
1033 1094
 		// Good, skip on.
@@ -1047,8 +1108,9 @@  discard block
 block discarded – undo
1047 1108
 	$incontext['continue'] = 1;
1048 1109
 
1049 1110
 	// Already done?
1050
-	if (isset($_POST['pop_done']))
1051
-		return true;
1111
+	if (isset($_POST['pop_done'])) {
1112
+			return true;
1113
+	}
1052 1114
 
1053 1115
 	// Reload settings.
1054 1116
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1066,8 +1128,9 @@  discard block
 block discarded – undo
1066 1128
 	$modSettings = array();
1067 1129
 	if ($result !== false)
1068 1130
 	{
1069
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1070
-			$modSettings[$row['variable']] = $row['value'];
1131
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1132
+					$modSettings[$row['variable']] = $row['value'];
1133
+		}
1071 1134
 		$smcFunc['db_free_result']($result);
1072 1135
 
1073 1136
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1080,20 +1143,22 @@  discard block
 block discarded – undo
1080 1143
 	$modSettings['disableQueryCheck'] = true;
1081 1144
 
1082 1145
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1083
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1084
-		$smcFunc['db_query']('', '
1146
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1147
+			$smcFunc['db_query']('', '
1085 1148
 			SET NAMES {string:utf8}',
1086 1149
 			array(
1087 1150
 				'db_error_skip' => true,
1088 1151
 				'utf8' => 'utf8',
1089 1152
 			)
1090 1153
 		);
1154
+	}
1091 1155
 
1092 1156
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1093
-	if (substr(__DIR__, -1) == '\\')
1094
-		$attachdir = __DIR__ . 'attachments';
1095
-	else
1096
-		$attachdir = __DIR__ . '/attachments';
1157
+	if (substr(__DIR__, -1) == '\\') {
1158
+			$attachdir = __DIR__ . 'attachments';
1159
+	} else {
1160
+			$attachdir = __DIR__ . '/attachments';
1161
+	}
1097 1162
 
1098 1163
 	$replaces = array(
1099 1164
 		'{$db_prefix}' => $db_prefix,
@@ -1110,8 +1175,9 @@  discard block
 block discarded – undo
1110 1175
 
1111 1176
 	foreach ($txt as $key => $value)
1112 1177
 	{
1113
-		if (substr($key, 0, 8) == 'default_')
1114
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1178
+		if (substr($key, 0, 8) == 'default_') {
1179
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1180
+		}
1115 1181
 	}
1116 1182
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1117 1183
 
@@ -1126,8 +1192,9 @@  discard block
 block discarded – undo
1126 1192
 
1127 1193
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1128 1194
 		{
1129
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1130
-				$engines[] = $row['Engine'];
1195
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1196
+							$engines[] = $row['Engine'];
1197
+			}
1131 1198
 		}
1132 1199
 
1133 1200
 		// Done with this now
@@ -1151,8 +1218,7 @@  discard block
 block discarded – undo
1151 1218
 			$replaces['START TRANSACTION;'] = '';
1152 1219
 			$replaces['COMMIT;'] = '';
1153 1220
 		}
1154
-	}
1155
-	else
1221
+	} else
1156 1222
 	{
1157 1223
 		$has_innodb = false;
1158 1224
 	}
@@ -1174,21 +1240,24 @@  discard block
 block discarded – undo
1174 1240
 	foreach ($sql_lines as $count => $line)
1175 1241
 	{
1176 1242
 		// No comments allowed!
1177
-		if (substr(trim($line), 0, 1) != '#')
1178
-			$current_statement .= "\n" . rtrim($line);
1243
+		if (substr(trim($line), 0, 1) != '#') {
1244
+					$current_statement .= "\n" . rtrim($line);
1245
+		}
1179 1246
 
1180 1247
 		// Is this the end of the query string?
1181
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1182
-			continue;
1248
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1249
+					continue;
1250
+		}
1183 1251
 
1184 1252
 		// Does this table already exist?  If so, don't insert more data into it!
1185 1253
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1186 1254
 		{
1187 1255
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1188
-			if (!empty($matches[0]))
1189
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1190
-			else
1191
-				$incontext['sql_results']['insert_dups']++;
1256
+			if (!empty($matches[0])) {
1257
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1258
+			} else {
1259
+							$incontext['sql_results']['insert_dups']++;
1260
+			}
1192 1261
 
1193 1262
 			$current_statement = '';
1194 1263
 			continue;
@@ -1197,8 +1266,9 @@  discard block
 block discarded – undo
1197 1266
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1198 1267
 		{
1199 1268
 			// Use the appropriate function based on the DB type
1200
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1201
-				$db_errorno = $db_type . '_errno';
1269
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1270
+							$db_errorno = $db_type . '_errno';
1271
+			}
1202 1272
 
1203 1273
 			// Error 1050: Table already exists!
1204 1274
 			// @todo Needs to be made better!
@@ -1213,18 +1283,18 @@  discard block
 block discarded – undo
1213 1283
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1214 1284
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1215 1285
 			}
1216
-		}
1217
-		else
1286
+		} else
1218 1287
 		{
1219
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1220
-				$incontext['sql_results']['tables']++;
1221
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1288
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1289
+							$incontext['sql_results']['tables']++;
1290
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1222 1291
 			{
1223 1292
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1224
-				if (!empty($matches[0]))
1225
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1226
-				else
1227
-					$incontext['sql_results']['inserts']++;
1293
+				if (!empty($matches[0])) {
1294
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1295
+				} else {
1296
+									$incontext['sql_results']['inserts']++;
1297
+				}
1228 1298
 			}
1229 1299
 		}
1230 1300
 
@@ -1237,15 +1307,17 @@  discard block
 block discarded – undo
1237 1307
 	// Sort out the context for the SQL.
1238 1308
 	foreach ($incontext['sql_results'] as $key => $number)
1239 1309
 	{
1240
-		if ($number == 0)
1241
-			unset($incontext['sql_results'][$key]);
1242
-		else
1243
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1310
+		if ($number == 0) {
1311
+					unset($incontext['sql_results'][$key]);
1312
+		} else {
1313
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1314
+		}
1244 1315
 	}
1245 1316
 
1246 1317
 	// Make sure UTF will be used globally.
1247
-	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'])))
1248
-		$newSettings[] = array('global_character_set', 'UTF-8');
1318
+	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']))) {
1319
+			$newSettings[] = array('global_character_set', 'UTF-8');
1320
+	}
1249 1321
 
1250 1322
 	// Auto-detect local & global cookie settings
1251 1323
 	$url_parts = parse_url($boardurl);
@@ -1274,15 +1346,19 @@  discard block
 block discarded – undo
1274 1346
 
1275 1347
 		// Look for subfolder, if found, set localCookie
1276 1348
 		// Checking for len > 1 ensures you don't have just a slash...
1277
-		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1)
1278
-			$localCookies = '1';
1349
+		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) {
1350
+					$localCookies = '1';
1351
+		}
1279 1352
 
1280
-		if (isset($globalCookies))
1281
-			$newSettings[] = array('globalCookies', $globalCookies);
1282
-		if (isset($globalCookiesDomain))
1283
-			$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1284
-		if (isset($localCookies))
1285
-			$newSettings[] = array('localCookies', $localCookies);
1353
+		if (isset($globalCookies)) {
1354
+					$newSettings[] = array('globalCookies', $globalCookies);
1355
+		}
1356
+		if (isset($globalCookiesDomain)) {
1357
+					$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1358
+		}
1359
+		if (isset($localCookies)) {
1360
+					$newSettings[] = array('localCookies', $localCookies);
1361
+		}
1286 1362
 	}
1287 1363
 
1288 1364
 	// Are we allowing stat collection?
@@ -1300,16 +1376,17 @@  discard block
 block discarded – undo
1300 1376
 			fwrite($fp, $out);
1301 1377
 
1302 1378
 			$return_data = '';
1303
-			while (!feof($fp))
1304
-				$return_data .= fgets($fp, 128);
1379
+			while (!feof($fp)) {
1380
+							$return_data .= fgets($fp, 128);
1381
+			}
1305 1382
 
1306 1383
 			fclose($fp);
1307 1384
 
1308 1385
 			// Get the unique site ID.
1309 1386
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1310 1387
 
1311
-			if (!empty($ID[1]))
1312
-				$smcFunc['db_insert']('replace',
1388
+			if (!empty($ID[1])) {
1389
+							$smcFunc['db_insert']('replace',
1313 1390
 					$db_prefix . 'settings',
1314 1391
 					array('variable' => 'string', 'value' => 'string'),
1315 1392
 					array(
@@ -1318,11 +1395,12 @@  discard block
 block discarded – undo
1318 1395
 					),
1319 1396
 					array('variable')
1320 1397
 				);
1398
+			}
1321 1399
 		}
1322 1400
 	}
1323 1401
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1324
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1325
-		$smcFunc['db_query']('', '
1402
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1403
+			$smcFunc['db_query']('', '
1326 1404
 			DELETE FROM {db_prefix}settings
1327 1405
 			WHERE variable = {string:enable_sm_stats}',
1328 1406
 			array(
@@ -1330,20 +1408,23 @@  discard block
 block discarded – undo
1330 1408
 				'db_error_skip' => true,
1331 1409
 			)
1332 1410
 		);
1411
+	}
1333 1412
 
1334 1413
 	// Are we enabling SSL?
1335
-	if (!empty($_POST['force_ssl']))
1336
-		$newSettings[] = array('force_ssl', 1);
1414
+	if (!empty($_POST['force_ssl'])) {
1415
+			$newSettings[] = array('force_ssl', 1);
1416
+	}
1337 1417
 
1338 1418
 	// Setting a timezone is required.
1339 1419
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1340 1420
 	{
1341 1421
 		// Get PHP's default timezone, if set
1342 1422
 		$ini_tz = ini_get('date.timezone');
1343
-		if (!empty($ini_tz))
1344
-			$timezone_id = $ini_tz;
1345
-		else
1346
-			$timezone_id = '';
1423
+		if (!empty($ini_tz)) {
1424
+					$timezone_id = $ini_tz;
1425
+		} else {
1426
+					$timezone_id = '';
1427
+		}
1347 1428
 
1348 1429
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1349 1430
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1352,8 +1433,9 @@  discard block
 block discarded – undo
1352 1433
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1353 1434
 		}
1354 1435
 
1355
-		if (date_default_timezone_set($timezone_id))
1356
-			$newSettings[] = array('default_timezone', $timezone_id);
1436
+		if (date_default_timezone_set($timezone_id)) {
1437
+					$newSettings[] = array('default_timezone', $timezone_id);
1438
+		}
1357 1439
 	}
1358 1440
 
1359 1441
 	if (!empty($newSettings))
@@ -1384,16 +1466,18 @@  discard block
 block discarded – undo
1384 1466
 	}
1385 1467
 
1386 1468
 	// MySQL specific stuff
1387
-	if (substr($db_type, 0, 5) != 'mysql')
1388
-		return false;
1469
+	if (substr($db_type, 0, 5) != 'mysql') {
1470
+			return false;
1471
+	}
1389 1472
 
1390 1473
 	// Find database user privileges.
1391 1474
 	$privs = array();
1392 1475
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1393 1476
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1394 1477
 	{
1395
-		if ($row['Privilege'] == 'Alter')
1396
-			$privs[] = $row['Privilege'];
1478
+		if ($row['Privilege'] == 'Alter') {
1479
+					$privs[] = $row['Privilege'];
1480
+		}
1397 1481
 	}
1398 1482
 	$smcFunc['db_free_result']($get_privs);
1399 1483
 
@@ -1423,8 +1507,9 @@  discard block
 block discarded – undo
1423 1507
 	$incontext['continue'] = 1;
1424 1508
 
1425 1509
 	// Skipping?
1426
-	if (!empty($_POST['skip']))
1427
-		return true;
1510
+	if (!empty($_POST['skip'])) {
1511
+			return true;
1512
+	}
1428 1513
 
1429 1514
 	// Need this to check whether we need the database password.
1430 1515
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1441,18 +1526,22 @@  discard block
 block discarded – undo
1441 1526
 	// We need this to properly hash the password for Admin
1442 1527
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1443 1528
 			global $sourcedir;
1444
-			if (function_exists('mb_strtolower'))
1445
-				return mb_strtolower($string, 'UTF-8');
1529
+			if (function_exists('mb_strtolower')) {
1530
+							return mb_strtolower($string, 'UTF-8');
1531
+			}
1446 1532
 			require_once($sourcedir . '/Subs-Charset.php');
1447 1533
 			return utf8_strtolower($string);
1448 1534
 		};
1449 1535
 
1450
-	if (!isset($_POST['username']))
1451
-		$_POST['username'] = '';
1452
-	if (!isset($_POST['email']))
1453
-		$_POST['email'] = '';
1454
-	if (!isset($_POST['server_email']))
1455
-		$_POST['server_email'] = '';
1536
+	if (!isset($_POST['username'])) {
1537
+			$_POST['username'] = '';
1538
+	}
1539
+	if (!isset($_POST['email'])) {
1540
+			$_POST['email'] = '';
1541
+	}
1542
+	if (!isset($_POST['server_email'])) {
1543
+			$_POST['server_email'] = '';
1544
+	}
1456 1545
 
1457 1546
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1458 1547
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1471,8 +1560,9 @@  discard block
 block discarded – undo
1471 1560
 			'admin_group' => 1,
1472 1561
 		)
1473 1562
 	);
1474
-	if ($smcFunc['db_num_rows']($request) != 0)
1475
-		$incontext['skip'] = 1;
1563
+	if ($smcFunc['db_num_rows']($request) != 0) {
1564
+			$incontext['skip'] = 1;
1565
+	}
1476 1566
 	$smcFunc['db_free_result']($request);
1477 1567
 
1478 1568
 	// Trying to create an account?
@@ -1503,8 +1593,9 @@  discard block
 block discarded – undo
1503 1593
 		}
1504 1594
 
1505 1595
 		// Update the webmaster's email?
1506
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1507
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1596
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1597
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1598
+		}
1508 1599
 
1509 1600
 		// Work out whether we're going to have dodgy characters and remove them.
1510 1601
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1527,32 +1618,27 @@  discard block
 block discarded – undo
1527 1618
 			$smcFunc['db_free_result']($result);
1528 1619
 
1529 1620
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1530
-		}
1531
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1621
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1532 1622
 		{
1533 1623
 			// Try the previous step again.
1534 1624
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1535 1625
 			return false;
1536
-		}
1537
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1626
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1538 1627
 		{
1539 1628
 			// Try the previous step again.
1540 1629
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1541 1630
 			return false;
1542
-		}
1543
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1631
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1544 1632
 		{
1545 1633
 			// One step back, this time fill out a proper admin email address.
1546 1634
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1547 1635
 			return false;
1548
-		}
1549
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1636
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1550 1637
 		{
1551 1638
 			// One step back, this time fill out a proper admin email address.
1552 1639
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1553 1640
 			return false;
1554
-		}
1555
-		elseif ($_POST['username'] != '')
1641
+		} elseif ($_POST['username'] != '')
1556 1642
 		{
1557 1643
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1558 1644
 
@@ -1620,17 +1706,19 @@  discard block
 block discarded – undo
1620 1706
 	reloadSettings();
1621 1707
 
1622 1708
 	// Bring a warning over.
1623
-	if (!empty($incontext['account_existed']))
1624
-		$incontext['warning'] = $incontext['account_existed'];
1709
+	if (!empty($incontext['account_existed'])) {
1710
+			$incontext['warning'] = $incontext['account_existed'];
1711
+	}
1625 1712
 
1626
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1627
-		$smcFunc['db_query']('', '
1713
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1714
+			$smcFunc['db_query']('', '
1628 1715
 			SET NAMES {string:db_character_set}',
1629 1716
 			array(
1630 1717
 				'db_character_set' => $db_character_set,
1631 1718
 				'db_error_skip' => true,
1632 1719
 			)
1633 1720
 		);
1721
+	}
1634 1722
 
1635 1723
 	// As track stats is by default enabled let's add some activity.
1636 1724
 	$smcFunc['db_insert']('ignore',
@@ -1651,14 +1739,16 @@  discard block
 block discarded – undo
1651 1739
 	// Only proceed if we can load the data.
1652 1740
 	if ($request)
1653 1741
 	{
1654
-		while ($row = $smcFunc['db_fetch_row']($request))
1655
-			$modSettings[$row[0]] = $row[1];
1742
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1743
+					$modSettings[$row[0]] = $row[1];
1744
+		}
1656 1745
 		$smcFunc['db_free_result']($request);
1657 1746
 	}
1658 1747
 
1659 1748
 	// Automatically log them in ;)
1660
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1661
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1749
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1750
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1751
+	}
1662 1752
 
1663 1753
 	$result = $smcFunc['db_query']('', '
1664 1754
 		SELECT value
@@ -1669,13 +1759,14 @@  discard block
 block discarded – undo
1669 1759
 			'db_error_skip' => true,
1670 1760
 		)
1671 1761
 	);
1672
-	if ($smcFunc['db_num_rows']($result) != 0)
1673
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1762
+	if ($smcFunc['db_num_rows']($result) != 0) {
1763
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1764
+	}
1674 1765
 	$smcFunc['db_free_result']($result);
1675 1766
 
1676
-	if (empty($db_sessions))
1677
-		$_SESSION['admin_time'] = time();
1678
-	else
1767
+	if (empty($db_sessions)) {
1768
+			$_SESSION['admin_time'] = time();
1769
+	} else
1679 1770
 	{
1680 1771
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1681 1772
 
@@ -1699,8 +1790,9 @@  discard block
 block discarded – undo
1699 1790
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1700 1791
 		function($string){
1701 1792
 			global $sourcedir;
1702
-			if (function_exists('mb_strtolower'))
1703
-				return mb_strtolower($string, 'UTF-8');
1793
+			if (function_exists('mb_strtolower')) {
1794
+							return mb_strtolower($string, 'UTF-8');
1795
+			}
1704 1796
 			require_once($sourcedir . '/Subs-Charset.php');
1705 1797
 			return utf8_strtolower($string);
1706 1798
 		};
@@ -1716,8 +1808,9 @@  discard block
 block discarded – undo
1716 1808
 		)
1717 1809
 	);
1718 1810
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1719
-	if ($smcFunc['db_num_rows']($request) > 0)
1720
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1811
+	if ($smcFunc['db_num_rows']($request) > 0) {
1812
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1813
+	}
1721 1814
 	$smcFunc['db_free_result']($request);
1722 1815
 
1723 1816
 	// Now is the perfect time to fetch the SM files.
@@ -1736,8 +1829,9 @@  discard block
 block discarded – undo
1736 1829
 
1737 1830
 	// Check if we need some stupid MySQL fix.
1738 1831
 	$server_version = $smcFunc['db_server_info']();
1739
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1740
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1832
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1833
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1834
+	}
1741 1835
 
1742 1836
 	// Some final context for the template.
1743 1837
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1757,8 +1851,9 @@  discard block
 block discarded – undo
1757 1851
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1758 1852
 
1759 1853
 	// @todo Do we just want to read the file in clean, and split it this way always?
1760
-	if (count($settingsArray) == 1)
1761
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1854
+	if (count($settingsArray) == 1) {
1855
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1856
+	}
1762 1857
 
1763 1858
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1764 1859
 	{
@@ -1766,25 +1861,29 @@  discard block
 block discarded – undo
1766 1861
 		if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}')
1767 1862
 		{
1768 1863
 			// Set the ten lines to nothing.
1769
-			for ($j=0; $j < 10; $j++)
1770
-				$settingsArray[$i++] = '';
1864
+			for ($j=0; $j < 10; $j++) {
1865
+							$settingsArray[$i++] = '';
1866
+			}
1771 1867
 
1772 1868
 			continue;
1773 1869
 		}
1774 1870
 
1775
-		if (trim($settingsArray[$i]) == '?' . '>')
1776
-			$settingsArray[$i] = '';
1871
+		if (trim($settingsArray[$i]) == '?' . '>') {
1872
+					$settingsArray[$i] = '';
1873
+		}
1777 1874
 
1778 1875
 		// Don't trim or bother with it if it's not a variable.
1779
-		if (substr($settingsArray[$i], 0, 1) != '$')
1780
-			continue;
1876
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1877
+					continue;
1878
+		}
1781 1879
 
1782 1880
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1783 1881
 
1784
-		foreach ($vars as $var => $val)
1785
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1882
+		foreach ($vars as $var => $val) {
1883
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1786 1884
 			{
1787 1885
 				$comment = strstr($settingsArray[$i], '#');
1886
+		}
1788 1887
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1789 1888
 				unset($vars[$var]);
1790 1889
 			}
@@ -1794,36 +1893,41 @@  discard block
 block discarded – undo
1794 1893
 	if (!empty($vars))
1795 1894
 	{
1796 1895
 		$settingsArray[$i++] = '';
1797
-		foreach ($vars as $var => $val)
1798
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1896
+		foreach ($vars as $var => $val) {
1897
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1898
+		}
1799 1899
 	}
1800 1900
 
1801 1901
 	// Blank out the file - done to fix a oddity with some servers.
1802 1902
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1803
-	if (!$fp)
1804
-		return false;
1903
+	if (!$fp) {
1904
+			return false;
1905
+	}
1805 1906
 	fclose($fp);
1806 1907
 
1807 1908
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1808 1909
 
1809 1910
 	// Gotta have one of these ;)
1810
-	if (trim($settingsArray[0]) != '<?php')
1811
-		fwrite($fp, "<?php\n");
1911
+	if (trim($settingsArray[0]) != '<?php') {
1912
+			fwrite($fp, "<?php\n");
1913
+	}
1812 1914
 
1813 1915
 	$lines = count($settingsArray);
1814 1916
 	for ($i = 0; $i < $lines - 1; $i++)
1815 1917
 	{
1816 1918
 		// Don't just write a bunch of blank lines.
1817
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1818
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1919
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1920
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1921
+		}
1819 1922
 	}
1820 1923
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1821 1924
 	fclose($fp);
1822 1925
 
1823 1926
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1824 1927
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1825
-	if (function_exists('opcache_invalidate'))
1826
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1928
+	if (function_exists('opcache_invalidate')) {
1929
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1930
+	}
1827 1931
 
1828 1932
 	return true;
1829 1933
 }
@@ -1833,10 +1937,11 @@  discard block
 block discarded – undo
1833 1937
 	global $cachedir;
1834 1938
 
1835 1939
 	// Write out the db_last_error file with the error timestamp
1836
-	if (!empty($cachedir) && is_writable($cachedir))
1837
-		file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1838
-	else
1839
-		file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1940
+	if (!empty($cachedir) && is_writable($cachedir)) {
1941
+			file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1942
+	} else {
1943
+			file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1944
+	}
1840 1945
 
1841 1946
 	return true;
1842 1947
 }
@@ -1853,9 +1958,9 @@  discard block
 block discarded – undo
1853 1958
 	SecFilterScanPOST Off
1854 1959
 </IfModule>';
1855 1960
 
1856
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1857
-		return true;
1858
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1961
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1962
+			return true;
1963
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1859 1964
 	{
1860 1965
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1861 1966
 
@@ -1867,29 +1972,28 @@  discard block
 block discarded – undo
1867 1972
 				fwrite($ht_handle, $htaccess_addition);
1868 1973
 				fclose($ht_handle);
1869 1974
 				return true;
1975
+			} else {
1976
+							return false;
1870 1977
 			}
1871
-			else
1872
-				return false;
1978
+		} else {
1979
+					return true;
1873 1980
 		}
1874
-		else
1875
-			return true;
1876
-	}
1877
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1878
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1879
-	elseif (is_writable(dirname(__FILE__)))
1981
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1982
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1983
+	} elseif (is_writable(dirname(__FILE__)))
1880 1984
 	{
1881 1985
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1882 1986
 		{
1883 1987
 			fwrite($ht_handle, $htaccess_addition);
1884 1988
 			fclose($ht_handle);
1885 1989
 			return true;
1990
+		} else {
1991
+					return false;
1886 1992
 		}
1887
-		else
1993
+	} else {
1888 1994
 			return false;
1889 1995
 	}
1890
-	else
1891
-		return false;
1892
-}
1996
+	}
1893 1997
 
1894 1998
 function template_install_above()
1895 1999
 {
@@ -1927,9 +2031,10 @@  discard block
 block discarded – undo
1927 2031
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1928 2032
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1929 2033
 
1930
-		foreach ($incontext['detected_languages'] as $lang => $name)
1931
-			echo '
2034
+		foreach ($incontext['detected_languages'] as $lang => $name) {
2035
+					echo '
1932 2036
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
2037
+		}
1933 2038
 
1934 2039
 		echo '
1935 2040
 								</select>
@@ -1949,9 +2054,10 @@  discard block
 block discarded – undo
1949 2054
 						<h2>', $txt['upgrade_progress'], '</h2>
1950 2055
 						<ul>';
1951 2056
 
1952
-	foreach ($incontext['steps'] as $num => $step)
1953
-		echo '
2057
+	foreach ($incontext['steps'] as $num => $step) {
2058
+			echo '
1954 2059
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
2060
+	}
1955 2061
 
1956 2062
 	echo '
1957 2063
 						</ul>
@@ -1976,20 +2082,23 @@  discard block
 block discarded – undo
1976 2082
 		echo '
1977 2083
 								<div class="floatright">';
1978 2084
 
1979
-		if (!empty($incontext['continue']))
1980
-			echo '
2085
+		if (!empty($incontext['continue'])) {
2086
+					echo '
1981 2087
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button" />';
1982
-		if (!empty($incontext['skip']))
1983
-			echo '
2088
+		}
2089
+		if (!empty($incontext['skip'])) {
2090
+					echo '
1984 2091
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button" />';
2092
+		}
1985 2093
 		echo '
1986 2094
 								</div>';
1987 2095
 	}
1988 2096
 
1989 2097
 	// Show the closing form tag and other data only if not in the last step
1990
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1991
-		echo '
2098
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2099
+			echo '
1992 2100
 							</form>';
2101
+	}
1993 2102
 
1994 2103
 	echo '
1995 2104
 						</div>
@@ -2024,13 +2133,15 @@  discard block
 block discarded – undo
2024 2133
 		</div>';
2025 2134
 
2026 2135
 	// Show the warnings, or not.
2027
-	if (template_warning_divs())
2028
-		echo '
2136
+	if (template_warning_divs()) {
2137
+			echo '
2029 2138
 		<h3>', $txt['install_all_lovely'], '</h3>';
2139
+	}
2030 2140
 
2031 2141
 	// Say we want the continue button!
2032
-	if (empty($incontext['error']))
2033
-		$incontext['continue'] = 1;
2142
+	if (empty($incontext['error'])) {
2143
+			$incontext['continue'] = 1;
2144
+	}
2034 2145
 
2035 2146
 	// For the latest version stuff.
2036 2147
 	echo '
@@ -2064,8 +2175,8 @@  discard block
 block discarded – undo
2064 2175
 	global $txt, $incontext;
2065 2176
 
2066 2177
 	// Errors are very serious..
2067
-	if (!empty($incontext['error']))
2068
-		echo '
2178
+	if (!empty($incontext['error'])) {
2179
+			echo '
2069 2180
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
2070 2181
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2071 2182
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -2073,9 +2184,10 @@  discard block
 block discarded – undo
2073 2184
 				', $incontext['error'], '
2074 2185
 			</div>
2075 2186
 		</div>';
2187
+	}
2076 2188
 	// A warning message?
2077
-	elseif (!empty($incontext['warning']))
2078
-		echo '
2189
+	elseif (!empty($incontext['warning'])) {
2190
+			echo '
2079 2191
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
2080 2192
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2081 2193
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -2083,6 +2195,7 @@  discard block
 block discarded – undo
2083 2195
 				', $incontext['warning'], '
2084 2196
 			</div>
2085 2197
 		</div>';
2198
+	}
2086 2199
 
2087 2200
 	return empty($incontext['error']) && empty($incontext['warning']);
2088 2201
 }
@@ -2098,27 +2211,30 @@  discard block
 block discarded – undo
2098 2211
 			<li>', $incontext['failed_files']), '</li>
2099 2212
 		</ul>';
2100 2213
 
2101
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2102
-		echo '
2214
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2215
+			echo '
2103 2216
 		<hr>
2104 2217
 		<p>', $txt['chmod_linux_info'], '</p>
2105 2218
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2219
+	}
2106 2220
 
2107 2221
 	// This is serious!
2108
-	if (!template_warning_divs())
2109
-		return;
2222
+	if (!template_warning_divs()) {
2223
+			return;
2224
+	}
2110 2225
 
2111 2226
 	echo '
2112 2227
 		<hr>
2113 2228
 		<p>', $txt['ftp_setup_info'], '</p>';
2114 2229
 
2115
-	if (!empty($incontext['ftp_errors']))
2116
-		echo '
2230
+	if (!empty($incontext['ftp_errors'])) {
2231
+			echo '
2117 2232
 		<div class="error_message">
2118 2233
 			', $txt['error_ftp_no_connect'], '<br><br>
2119 2234
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2120 2235
 		</div>
2121 2236
 		<br>';
2237
+	}
2122 2238
 
2123 2239
 	echo '
2124 2240
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2178,17 +2294,17 @@  discard block
 block discarded – undo
2178 2294
 				<td>
2179 2295
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2180 2296
 
2181
-	foreach ($incontext['supported_databases'] as $key => $db)
2182
-			echo '
2297
+	foreach ($incontext['supported_databases'] as $key => $db) {
2298
+				echo '
2183 2299
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2300
+	}
2184 2301
 
2185 2302
 	echo '
2186 2303
 					</select>
2187 2304
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2188 2305
 				</td>
2189 2306
 			</tr>';
2190
-	}
2191
-	else
2307
+	} else
2192 2308
 	{
2193 2309
 		echo '
2194 2310
 			<tr style="display: none;">
@@ -2381,9 +2497,10 @@  discard block
 block discarded – undo
2381 2497
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2382 2498
 				<ul>';
2383 2499
 
2384
-		foreach ($incontext['failures'] as $line => $fail)
2385
-			echo '
2500
+		foreach ($incontext['failures'] as $line => $fail) {
2501
+					echo '
2386 2502
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2503
+		}
2387 2504
 
2388 2505
 		echo '
2389 2506
 				</ul>';
@@ -2444,15 +2561,16 @@  discard block
 block discarded – undo
2444 2561
 			</tr>
2445 2562
 		</table>';
2446 2563
 
2447
-	if ($incontext['require_db_confirm'])
2448
-		echo '
2564
+	if ($incontext['require_db_confirm']) {
2565
+			echo '
2449 2566
 		<h2>', $txt['user_settings_database'], '</h2>
2450 2567
 		<p>', $txt['user_settings_database_info'], '</p>
2451 2568
 
2452 2569
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2453 2570
 			<input type="password" name="password3" size="30" />
2454 2571
 		</div>';
2455
-}
2572
+	}
2573
+	}
2456 2574
 
2457 2575
 // Tell them it's done, and to delete.
2458 2576
 function template_delete_install()
@@ -2465,14 +2583,15 @@  discard block
 block discarded – undo
2465 2583
 	template_warning_divs();
2466 2584
 
2467 2585
 	// Install directory still writable?
2468
-	if ($incontext['dir_still_writable'])
2469
-		echo '
2586
+	if ($incontext['dir_still_writable']) {
2587
+			echo '
2470 2588
 		<em>', $txt['still_writable'], '</em><br>
2471 2589
 		<br>';
2590
+	}
2472 2591
 
2473 2592
 	// Don't show the box if it's like 99% sure it won't work :P.
2474
-	if ($incontext['probably_delete_install'])
2475
-		echo '
2593
+	if ($incontext['probably_delete_install']) {
2594
+			echo '
2476 2595
 		<div style="margin: 1ex; font-weight: bold;">
2477 2596
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
2478 2597
 		</div>
@@ -2488,6 +2607,7 @@  discard block
 block discarded – undo
2488 2607
 			}
2489 2608
 		</script>
2490 2609
 		<br>';
2610
+	}
2491 2611
 
2492 2612
 	echo '
2493 2613
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +887 added lines, -651 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'];
@@ -197,8 +204,9 @@  discard block
 block discarded – undo
197 204
 			'db_error_skip' => true,
198 205
 		)
199 206
 	);
200
-	while ($row = $smcFunc['db_fetch_assoc']($request))
201
-		$modSettings[$row['variable']] = $row['value'];
207
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
208
+			$modSettings[$row['variable']] = $row['value'];
209
+	}
202 210
 	$smcFunc['db_free_result']($request);
203 211
 }
204 212
 
@@ -208,10 +216,12 @@  discard block
 block discarded – undo
208 216
 	$modSettings['theme_url'] = 'Themes/default';
209 217
 	$modSettings['images_url'] = 'Themes/default/images';
210 218
 }
211
-if (!isset($settings['default_theme_url']))
219
+if (!isset($settings['default_theme_url'])) {
212 220
 	$settings['default_theme_url'] = $modSettings['theme_url'];
213
-if (!isset($settings['default_theme_dir']))
221
+}
222
+if (!isset($settings['default_theme_dir'])) {
214 223
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
224
+}
215 225
 
216 226
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
217 227
 // Default title...
@@ -229,13 +239,15 @@  discard block
 block discarded – undo
229 239
 	$support_js = $upcontext['upgrade_status']['js'];
230 240
 
231 241
 	// Only set this if the upgrader status says so.
232
-	if (empty($is_debug))
233
-		$is_debug = $upcontext['upgrade_status']['debug'];
242
+	if (empty($is_debug)) {
243
+			$is_debug = $upcontext['upgrade_status']['debug'];
244
+	}
234 245
 
235 246
 	// Load the language.
236
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
237
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
238
-}
247
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
248
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
249
+	}
250
+	}
239 251
 // Set the defaults.
240 252
 else
241 253
 {
@@ -253,15 +265,18 @@  discard block
 block discarded – undo
253 265
 }
254 266
 
255 267
 // If this isn't the first stage see whether they are logging in and resuming.
256
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
268
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
257 269
 	checkLogin();
270
+}
258 271
 
259
-if ($command_line)
272
+if ($command_line) {
260 273
 	cmdStep0();
274
+}
261 275
 
262 276
 // Don't error if we're using xml.
263
-if (isset($_GET['xml']))
277
+if (isset($_GET['xml'])) {
264 278
 	$upcontext['return_error'] = true;
279
+}
265 280
 
266 281
 // Loop through all the steps doing each one as required.
267 282
 $upcontext['overall_percent'] = 0;
@@ -282,9 +297,9 @@  discard block
 block discarded – undo
282 297
 		}
283 298
 
284 299
 		// Call the step and if it returns false that means pause!
285
-		if (function_exists($step[2]) && $step[2]() === false)
286
-			break;
287
-		elseif (function_exists($step[2])) {
300
+		if (function_exists($step[2]) && $step[2]() === false) {
301
+					break;
302
+		} elseif (function_exists($step[2])) {
288 303
 			//Start each new step with this unset, so the 'normal' template is called first
289 304
 			unset($_GET['xml']);
290 305
 			//Clear out warnings at the start of each step
@@ -330,17 +345,18 @@  discard block
 block discarded – undo
330 345
 		// This should not happen my dear... HELP ME DEVELOPERS!!
331 346
 		if (!empty($command_line))
332 347
 		{
333
-			if (function_exists('debug_print_backtrace'))
334
-				debug_print_backtrace();
348
+			if (function_exists('debug_print_backtrace')) {
349
+							debug_print_backtrace();
350
+			}
335 351
 
336 352
 			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.';
337 353
 			flush();
338 354
 			die();
339 355
 		}
340 356
 
341
-		if (!isset($_GET['xml']))
342
-			template_upgrade_above();
343
-		else
357
+		if (!isset($_GET['xml'])) {
358
+					template_upgrade_above();
359
+		} else
344 360
 		{
345 361
 			header('content-type: text/xml; charset=UTF-8');
346 362
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -362,25 +378,29 @@  discard block
 block discarded – undo
362 378
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
363 379
 
364 380
 			// Custom stuff to pass back?
365
-			if (!empty($upcontext['query_string']))
366
-				$upcontext['form_url'] .= $upcontext['query_string'];
381
+			if (!empty($upcontext['query_string'])) {
382
+							$upcontext['form_url'] .= $upcontext['query_string'];
383
+			}
367 384
 
368 385
 			// Call the appropriate subtemplate
369
-			if (is_callable('template_' . $upcontext['sub_template']))
370
-				call_user_func('template_' . $upcontext['sub_template']);
371
-			else
372
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
386
+			if (is_callable('template_' . $upcontext['sub_template'])) {
387
+							call_user_func('template_' . $upcontext['sub_template']);
388
+			} else {
389
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
390
+			}
373 391
 		}
374 392
 
375 393
 		// Was there an error?
376
-		if (!empty($upcontext['forced_error_message']))
377
-			echo $upcontext['forced_error_message'];
394
+		if (!empty($upcontext['forced_error_message'])) {
395
+					echo $upcontext['forced_error_message'];
396
+		}
378 397
 
379 398
 		// Show the footer.
380
-		if (!isset($_GET['xml']))
381
-			template_upgrade_below();
382
-		else
383
-			template_xml_below();
399
+		if (!isset($_GET['xml'])) {
400
+					template_upgrade_below();
401
+		} else {
402
+					template_xml_below();
403
+		}
384 404
 	}
385 405
 
386 406
 
@@ -392,15 +412,19 @@  discard block
 block discarded – undo
392 412
 		$seconds = intval($active % 60);
393 413
 
394 414
 		$totalTime = '';
395
-		if ($hours > 0)
396
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
397
-		if ($minutes > 0)
398
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
399
-		if ($seconds > 0)
400
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
415
+		if ($hours > 0) {
416
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
417
+		}
418
+		if ($minutes > 0) {
419
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
420
+		}
421
+		if ($seconds > 0) {
422
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
423
+		}
401 424
 
402
-		if (!empty($totalTime))
403
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
425
+		if (!empty($totalTime)) {
426
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
427
+		}
404 428
 	}
405 429
 
406 430
 	// Bang - gone!
@@ -413,8 +437,9 @@  discard block
 block discarded – undo
413 437
 	global $upgradeurl, $upcontext, $command_line;
414 438
 
415 439
 	// Command line users can't be redirected.
416
-	if ($command_line)
417
-		upgradeExit(true);
440
+	if ($command_line) {
441
+			upgradeExit(true);
442
+	}
418 443
 
419 444
 	// Are we providing the core info?
420 445
 	if ($addForm)
@@ -440,12 +465,14 @@  discard block
 block discarded – undo
440 465
 	define('SMF', 1);
441 466
 
442 467
 	// Start the session.
443
-	if (@ini_get('session.save_handler') == 'user')
444
-		@ini_set('session.save_handler', 'files');
468
+	if (@ini_get('session.save_handler') == 'user') {
469
+			@ini_set('session.save_handler', 'files');
470
+	}
445 471
 	@session_start();
446 472
 
447
-	if (empty($smcFunc))
448
-		$smcFunc = array();
473
+	if (empty($smcFunc)) {
474
+			$smcFunc = array();
475
+	}
449 476
 
450 477
 	// We need this for authentication and some upgrade code
451 478
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -472,24 +499,27 @@  discard block
 block discarded – undo
472 499
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
473 500
 
474 501
 		// Make the connection...
475
-		if (empty($db_connection))
476
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
477
-		else
478
-			// If we've returned here, ping/reconnect to be safe
502
+		if (empty($db_connection)) {
503
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
504
+		} else {
505
+					// If we've returned here, ping/reconnect to be safe
479 506
 			$smcFunc['db_ping']($db_connection);
507
+		}
480 508
 
481 509
 		// Oh dear god!!
482
-		if ($db_connection === null)
483
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
510
+		if ($db_connection === null) {
511
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
512
+		}
484 513
 
485
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
486
-			$smcFunc['db_query']('', '
514
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
515
+					$smcFunc['db_query']('', '
487 516
 			SET NAMES {string:db_character_set}',
488 517
 			array(
489 518
 				'db_error_skip' => true,
490 519
 				'db_character_set' => $db_character_set,
491 520
 			)
492 521
 		);
522
+		}
493 523
 
494 524
 		// Load the modSettings data...
495 525
 		$request = $smcFunc['db_query']('', '
@@ -500,11 +530,11 @@  discard block
 block discarded – undo
500 530
 			)
501 531
 		);
502 532
 		$modSettings = array();
503
-		while ($row = $smcFunc['db_fetch_assoc']($request))
504
-			$modSettings[$row['variable']] = $row['value'];
533
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
534
+					$modSettings[$row['variable']] = $row['value'];
535
+		}
505 536
 		$smcFunc['db_free_result']($request);
506
-	}
507
-	else
537
+	} else
508 538
 	{
509 539
 		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.');
510 540
 	}
@@ -518,9 +548,10 @@  discard block
 block discarded – undo
518 548
 		cleanRequest();
519 549
 	}
520 550
 
521
-	if (!isset($_GET['substep']))
522
-		$_GET['substep'] = 0;
523
-}
551
+	if (!isset($_GET['substep'])) {
552
+			$_GET['substep'] = 0;
553
+	}
554
+	}
524 555
 
525 556
 function initialize_inputs()
526 557
 {
@@ -550,8 +581,9 @@  discard block
 block discarded – undo
550 581
 		$dh = opendir(dirname(__FILE__));
551 582
 		while ($file = readdir($dh))
552 583
 		{
553
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
554
-				@unlink(dirname(__FILE__) . '/' . $file);
584
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
585
+							@unlink(dirname(__FILE__) . '/' . $file);
586
+			}
555 587
 		}
556 588
 		closedir($dh);
557 589
 
@@ -580,8 +612,9 @@  discard block
 block discarded – undo
580 612
 	$temp = 'upgrade_php?step';
581 613
 	while (strlen($temp) > 4)
582 614
 	{
583
-		if (isset($_GET[$temp]))
584
-			unset($_GET[$temp]);
615
+		if (isset($_GET[$temp])) {
616
+					unset($_GET[$temp]);
617
+		}
585 618
 		$temp = substr($temp, 1);
586 619
 	}
587 620
 
@@ -608,32 +641,39 @@  discard block
 block discarded – undo
608 641
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
609 642
 
610 643
 	// Need legacy scripts?
611
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
612
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
613
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
614
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
615
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
616
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
644
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
645
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
646
+	}
647
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
648
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
649
+	}
650
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
651
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
652
+	}
617 653
 
618 654
 	// We don't need "-utf8" files anymore...
619 655
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
620 656
 
621 657
 	// This needs to exist!
622
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
623
-		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>]');
624
-	else
625
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
658
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
659
+			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>]');
660
+	} else {
661
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
662
+	}
626 663
 
627
-	if (!$check)
628
-		// 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.
664
+	if (!$check) {
665
+			// 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.
629 666
 		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.');
667
+	}
630 668
 
631 669
 	// Do they meet the install requirements?
632
-	if (!php_version_check())
633
-		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.');
670
+	if (!php_version_check()) {
671
+			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.');
672
+	}
634 673
 
635
-	if (!db_version_check())
636
-		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.');
674
+	if (!db_version_check()) {
675
+			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.');
676
+	}
637 677
 
638 678
 	// Do some checks to make sure they have proper privileges
639 679
 	db_extend('packages');
@@ -648,14 +688,16 @@  discard block
 block discarded – undo
648 688
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
649 689
 
650 690
 	// Sorry... we need CREATE, ALTER and DROP
651
-	if (!$create || !$alter || !$drop)
652
-		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.');
691
+	if (!$create || !$alter || !$drop) {
692
+			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.');
693
+	}
653 694
 
654 695
 	// Do a quick version spot check.
655 696
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
656 697
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
657
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
658
-		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.');
698
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
699
+			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.');
700
+	}
659 701
 
660 702
 	// What absolutely needs to be writable?
661 703
 	$writable_files = array(
@@ -664,12 +706,13 @@  discard block
 block discarded – undo
664 706
 	);
665 707
 
666 708
 	// Only check for minified writable files if we have it enabled or not set.
667
-	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files']))
668
-		$writable_files += array(
709
+	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) {
710
+			$writable_files += array(
669 711
 			$modSettings['theme_dir'] . '/css/minified.css',
670 712
 			$modSettings['theme_dir'] . '/scripts/minified.js',
671 713
 			$modSettings['theme_dir'] . '/scripts/minified_deferred.js',
672 714
 		);
715
+	}
673 716
 
674 717
 	// Do we need to add this setting?
675 718
 	$need_settings_update = empty($modSettings['custom_avatar_dir']);
@@ -681,12 +724,13 @@  discard block
 block discarded – undo
681 724
 	quickFileWritable($custom_av_dir);
682 725
 
683 726
 	// Are we good now?
684
-	if (!is_writable($custom_av_dir))
685
-		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));
686
-	elseif ($need_settings_update)
727
+	if (!is_writable($custom_av_dir)) {
728
+			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));
729
+	} elseif ($need_settings_update)
687 730
 	{
688
-		if (!function_exists('cache_put_data'))
689
-			require_once($sourcedir . '/Load.php');
731
+		if (!function_exists('cache_put_data')) {
732
+					require_once($sourcedir . '/Load.php');
733
+		}
690 734
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
691 735
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
692 736
 	}
@@ -695,28 +739,33 @@  discard block
 block discarded – undo
695 739
 
696 740
 	// Check the cache directory.
697 741
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
698
-	if (!file_exists($cachedir_temp))
699
-		@mkdir($cachedir_temp);
700
-	if (!file_exists($cachedir_temp))
701
-		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.');
702
-
703
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
704
-		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>.');
705
-	elseif (!isset($_GET['skiplang']))
742
+	if (!file_exists($cachedir_temp)) {
743
+			@mkdir($cachedir_temp);
744
+	}
745
+	if (!file_exists($cachedir_temp)) {
746
+			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.');
747
+	}
748
+
749
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
750
+			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>.');
751
+	} elseif (!isset($_GET['skiplang']))
706 752
 	{
707 753
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
708 754
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
709 755
 
710
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
711
-			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>]');
756
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
757
+					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>]');
758
+		}
712 759
 	}
713 760
 
714
-	if (!makeFilesWritable($writable_files))
715
-		return false;
761
+	if (!makeFilesWritable($writable_files)) {
762
+			return false;
763
+	}
716 764
 
717 765
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
718
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
719
-		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.');
766
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
767
+			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.');
768
+	}
720 769
 
721 770
 	// Upgrade the agreement.
722 771
 	elseif (isset($modSettings['agreement']))
@@ -727,8 +776,8 @@  discard block
 block discarded – undo
727 776
 	}
728 777
 
729 778
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
730
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
731
-		$upcontext['warning'] = '
779
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
780
+			$upcontext['warning'] = '
732 781
 			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>
733 782
 			<ul>
734 783
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -736,19 +785,23 @@  discard block
 block discarded – undo
736 785
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
737 786
 			</ul>
738 787
 			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.';
788
+	}
739 789
 
740 790
 	// Confirm mbstring is loaded...
741
-	if (!extension_loaded('mbstring'))
742
-		return throw_error($txt['install_no_mbstring']);
791
+	if (!extension_loaded('mbstring')) {
792
+			return throw_error($txt['install_no_mbstring']);
793
+	}
743 794
 
744 795
 	// Check for https stream support.
745 796
 	$supported_streams = stream_get_wrappers();
746
-	if (!in_array('https', $supported_streams))
747
-		$upcontext['custom_warning'] = $txt['install_no_https'];
797
+	if (!in_array('https', $supported_streams)) {
798
+			$upcontext['custom_warning'] = $txt['install_no_https'];
799
+	}
748 800
 
749 801
 	// Either we're logged in or we're going to present the login.
750
-	if (checkLogin())
751
-		return true;
802
+	if (checkLogin()) {
803
+			return true;
804
+	}
752 805
 
753 806
 	$upcontext += createToken('login');
754 807
 
@@ -762,15 +815,17 @@  discard block
 block discarded – undo
762 815
 	global $smcFunc, $db_type, $support_js;
763 816
 
764 817
 	// Don't bother if the security is disabled.
765
-	if ($disable_security)
766
-		return true;
818
+	if ($disable_security) {
819
+			return true;
820
+	}
767 821
 
768 822
 	// Are we trying to login?
769 823
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
770 824
 	{
771 825
 		// If we've disabled security pick a suitable name!
772
-		if (empty($_POST['user']))
773
-			$_POST['user'] = 'Administrator';
826
+		if (empty($_POST['user'])) {
827
+					$_POST['user'] = 'Administrator';
828
+		}
774 829
 
775 830
 		// Before 2.0 these column names were different!
776 831
 		$oldDB = false;
@@ -785,16 +840,17 @@  discard block
 block discarded – undo
785 840
 					'db_error_skip' => true,
786 841
 				)
787 842
 			);
788
-			if ($smcFunc['db_num_rows']($request) != 0)
789
-				$oldDB = true;
843
+			if ($smcFunc['db_num_rows']($request) != 0) {
844
+							$oldDB = true;
845
+			}
790 846
 			$smcFunc['db_free_result']($request);
791 847
 		}
792 848
 
793 849
 		// Get what we believe to be their details.
794 850
 		if (!$disable_security)
795 851
 		{
796
-			if ($oldDB)
797
-				$request = $smcFunc['db_query']('', '
852
+			if ($oldDB) {
853
+							$request = $smcFunc['db_query']('', '
798 854
 					SELECT id_member, memberName AS member_name, passwd, id_group,
799 855
 					additionalGroups AS additional_groups, lngfile
800 856
 					FROM {db_prefix}members
@@ -804,8 +860,8 @@  discard block
 block discarded – undo
804 860
 						'db_error_skip' => true,
805 861
 					)
806 862
 				);
807
-			else
808
-				$request = $smcFunc['db_query']('', '
863
+			} else {
864
+							$request = $smcFunc['db_query']('', '
809 865
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
810 866
 					FROM {db_prefix}members
811 867
 					WHERE member_name = {string:member_name}',
@@ -814,6 +870,7 @@  discard block
 block discarded – undo
814 870
 						'db_error_skip' => true,
815 871
 					)
816 872
 				);
873
+			}
817 874
 			if ($smcFunc['db_num_rows']($request) != 0)
818 875
 			{
819 876
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -821,16 +878,17 @@  discard block
 block discarded – undo
821 878
 				$groups = explode(',', $addGroups);
822 879
 				$groups[] = $id_group;
823 880
 
824
-				foreach ($groups as $k => $v)
825
-					$groups[$k] = (int) $v;
881
+				foreach ($groups as $k => $v) {
882
+									$groups[$k] = (int) $v;
883
+				}
826 884
 
827 885
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
828 886
 
829 887
 				// We don't use "-utf8" anymore...
830 888
 				$user_language = str_ireplace('-utf8', '', $user_language);
889
+			} else {
890
+							$upcontext['username_incorrect'] = true;
831 891
 			}
832
-			else
833
-				$upcontext['username_incorrect'] = true;
834 892
 			$smcFunc['db_free_result']($request);
835 893
 		}
836 894
 		$upcontext['username'] = $_POST['user'];
@@ -840,13 +898,14 @@  discard block
 block discarded – undo
840 898
 		{
841 899
 			$upcontext['upgrade_status']['js'] = 1;
842 900
 			$support_js = 1;
901
+		} else {
902
+					$support_js = 0;
843 903
 		}
844
-		else
845
-			$support_js = 0;
846 904
 
847 905
 		// Note down the version we are coming from.
848
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
849
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
906
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
907
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
908
+		}
850 909
 
851 910
 		// Didn't get anywhere?
852 911
 		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']))
@@ -880,15 +939,15 @@  discard block
 block discarded – undo
880 939
 							'db_error_skip' => true,
881 940
 						)
882 941
 					);
883
-					if ($smcFunc['db_num_rows']($request) == 0)
884
-						return throw_error('You need to be an admin to perform an upgrade!');
942
+					if ($smcFunc['db_num_rows']($request) == 0) {
943
+											return throw_error('You need to be an admin to perform an upgrade!');
944
+					}
885 945
 					$smcFunc['db_free_result']($request);
886 946
 				}
887 947
 
888 948
 				$upcontext['user']['id'] = $id_member;
889 949
 				$upcontext['user']['name'] = $name;
890
-			}
891
-			else
950
+			} else
892 951
 			{
893 952
 				$upcontext['user']['id'] = 1;
894 953
 				$upcontext['user']['name'] = 'Administrator';
@@ -904,11 +963,11 @@  discard block
 block discarded – undo
904 963
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
905 964
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
906 965
 
907
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
908
-					$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'] . '.';
909
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
910
-					$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'] . '.';
911
-				else
966
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
967
+									$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'] . '.';
968
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
969
+									$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'] . '.';
970
+				} else
912 971
 				{
913 972
 					// Set this as the new language.
914 973
 					$upcontext['language'] = $user_language;
@@ -952,8 +1011,9 @@  discard block
 block discarded – undo
952 1011
 	unset($member_columns);
953 1012
 
954 1013
 	// If we've not submitted then we're done.
955
-	if (empty($_POST['upcont']))
956
-		return false;
1014
+	if (empty($_POST['upcont'])) {
1015
+			return false;
1016
+	}
957 1017
 
958 1018
 	// Firstly, if they're enabling SM stat collection just do it.
959 1019
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -973,16 +1033,17 @@  discard block
 block discarded – undo
973 1033
 				fwrite($fp, $out);
974 1034
 
975 1035
 				$return_data = '';
976
-				while (!feof($fp))
977
-					$return_data .= fgets($fp, 128);
1036
+				while (!feof($fp)) {
1037
+									$return_data .= fgets($fp, 128);
1038
+				}
978 1039
 
979 1040
 				fclose($fp);
980 1041
 
981 1042
 				// Get the unique site ID.
982 1043
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
983 1044
 
984
-				if (!empty($ID[1]))
985
-					$smcFunc['db_insert']('replace',
1045
+				if (!empty($ID[1])) {
1046
+									$smcFunc['db_insert']('replace',
986 1047
 						$db_prefix . 'settings',
987 1048
 						array('variable' => 'string', 'value' => 'string'),
988 1049
 						array(
@@ -991,9 +1052,9 @@  discard block
 block discarded – undo
991 1052
 						),
992 1053
 						array('variable')
993 1054
 					);
1055
+				}
994 1056
 			}
995
-		}
996
-		else
1057
+		} else
997 1058
 		{
998 1059
 			$smcFunc['db_insert']('replace',
999 1060
 				$db_prefix . 'settings',
@@ -1004,8 +1065,8 @@  discard block
 block discarded – undo
1004 1065
 		}
1005 1066
 	}
1006 1067
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1007
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1008
-		$smcFunc['db_query']('', '
1068
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1069
+			$smcFunc['db_query']('', '
1009 1070
 			DELETE FROM {db_prefix}settings
1010 1071
 			WHERE variable = {string:enable_sm_stats}',
1011 1072
 			array(
@@ -1013,6 +1074,7 @@  discard block
 block discarded – undo
1013 1074
 				'db_error_skip' => true,
1014 1075
 			)
1015 1076
 		);
1077
+	}
1016 1078
 
1017 1079
 	// Deleting old karma stuff?
1018 1080
 	if (!empty($_POST['delete_karma']))
@@ -1027,20 +1089,22 @@  discard block
 block discarded – undo
1027 1089
 		);
1028 1090
 
1029 1091
 		// Cleaning up old karma member settings.
1030
-		if ($upcontext['karma_installed']['good'])
1031
-			$smcFunc['db_query']('', '
1092
+		if ($upcontext['karma_installed']['good']) {
1093
+					$smcFunc['db_query']('', '
1032 1094
 				ALTER TABLE {db_prefix}members
1033 1095
 				DROP karma_good',
1034 1096
 				array()
1035 1097
 			);
1098
+		}
1036 1099
 
1037 1100
 		// Does karma bad was enable?
1038
-		if ($upcontext['karma_installed']['bad'])
1039
-			$smcFunc['db_query']('', '
1101
+		if ($upcontext['karma_installed']['bad']) {
1102
+					$smcFunc['db_query']('', '
1040 1103
 				ALTER TABLE {db_prefix}members
1041 1104
 				DROP karma_bad',
1042 1105
 				array()
1043 1106
 			);
1107
+		}
1044 1108
 
1045 1109
 		// Cleaning up old karma permissions.
1046 1110
 		$smcFunc['db_query']('', '
@@ -1058,32 +1122,37 @@  discard block
 block discarded – undo
1058 1122
 	}
1059 1123
 
1060 1124
 	// Emptying the error log?
1061
-	if (!empty($_POST['empty_error']))
1062
-		$smcFunc['db_query']('truncate_table', '
1125
+	if (!empty($_POST['empty_error'])) {
1126
+			$smcFunc['db_query']('truncate_table', '
1063 1127
 			TRUNCATE {db_prefix}log_errors',
1064 1128
 			array(
1065 1129
 			)
1066 1130
 		);
1131
+	}
1067 1132
 
1068 1133
 	$changes = array();
1069 1134
 
1070 1135
 	// Add proxy settings.
1071
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1072
-		$changes += array(
1136
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1137
+			$changes += array(
1073 1138
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1074 1139
 			'image_proxy_maxsize' => 5190,
1075 1140
 			'image_proxy_enabled' => 0,
1076 1141
 		);
1142
+	}
1077 1143
 
1078 1144
 	// If $boardurl reflects https, set force_ssl
1079
-	if (!function_exists('cache_put_data'))
1080
-		require_once($sourcedir . '/Load.php');
1081
-	if (stripos($boardurl, 'https://') !== false)
1082
-		updateSettings(array('force_ssl' => '1'));
1145
+	if (!function_exists('cache_put_data')) {
1146
+			require_once($sourcedir . '/Load.php');
1147
+	}
1148
+	if (stripos($boardurl, 'https://') !== false) {
1149
+			updateSettings(array('force_ssl' => '1'));
1150
+	}
1083 1151
 
1084 1152
 	// If we're overriding the language follow it through.
1085
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1086
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1153
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1154
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1155
+	}
1087 1156
 
1088 1157
 	if (!empty($_POST['maint']))
1089 1158
 	{
@@ -1095,26 +1164,29 @@  discard block
 block discarded – undo
1095 1164
 		{
1096 1165
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1097 1166
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1098
-		}
1099
-		else
1167
+		} else
1100 1168
 		{
1101 1169
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1102 1170
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1103 1171
 		}
1104 1172
 	}
1105 1173
 
1106
-	if ($command_line)
1107
-		echo ' * Updating Settings.php...';
1174
+	if ($command_line) {
1175
+			echo ' * Updating Settings.php...';
1176
+	}
1108 1177
 
1109 1178
 	// Fix some old paths.
1110
-	if (substr($boarddir, 0, 1) == '.')
1111
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1179
+	if (substr($boarddir, 0, 1) == '.') {
1180
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1181
+	}
1112 1182
 
1113
-	if (substr($sourcedir, 0, 1) == '.')
1114
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1183
+	if (substr($sourcedir, 0, 1) == '.') {
1184
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1185
+	}
1115 1186
 
1116
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1117
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1187
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1188
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1189
+	}
1118 1190
 
1119 1191
 	// If they have a "host:port" setup for the host, split that into separate values
1120 1192
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1125,32 +1197,36 @@  discard block
 block discarded – undo
1125 1197
 		$changes['db_server'] = '\'' . $db_server . '\'';
1126 1198
 
1127 1199
 		// Only set this if we're not using the default port
1128
-		if ($db_port != ini_get('mysqli.default_port'))
1129
-			$changes['db_port'] = (int) $db_port;
1130
-	}
1131
-	elseif (!empty($db_port))
1200
+		if ($db_port != ini_get('mysqli.default_port')) {
1201
+					$changes['db_port'] = (int) $db_port;
1202
+		}
1203
+	} elseif (!empty($db_port))
1132 1204
 	{
1133 1205
 		// If db_port is set and is the same as the default, set it to ''
1134 1206
 		if ($db_type == 'mysql')
1135 1207
 		{
1136
-			if ($db_port == ini_get('mysqli.default_port'))
1137
-				$changes['db_port'] = '\'\'';
1138
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1139
-				$changes['db_port'] = '\'\'';
1208
+			if ($db_port == ini_get('mysqli.default_port')) {
1209
+							$changes['db_port'] = '\'\'';
1210
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1211
+							$changes['db_port'] = '\'\'';
1212
+			}
1140 1213
 		}
1141 1214
 	}
1142 1215
 
1143 1216
 	// Maybe we haven't had this option yet?
1144
-	if (empty($packagesdir))
1145
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1217
+	if (empty($packagesdir)) {
1218
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1219
+	}
1146 1220
 
1147 1221
 	// Add support for $tasksdir var.
1148
-	if (empty($tasksdir))
1149
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1222
+	if (empty($tasksdir)) {
1223
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1224
+	}
1150 1225
 
1151 1226
 	// Make sure we fix the language as well.
1152
-	if (stristr($language, '-utf8'))
1153
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1227
+	if (stristr($language, '-utf8')) {
1228
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1229
+	}
1154 1230
 
1155 1231
 	// @todo Maybe change the cookie name if going to 1.1, too?
1156 1232
 
@@ -1161,8 +1237,9 @@  discard block
 block discarded – undo
1161 1237
 	// Tell Settings.php to store db_last_error.php in the cache
1162 1238
 	move_db_last_error_to_cachedir();
1163 1239
 
1164
-	if ($command_line)
1165
-		echo ' Successful.' . "\n";
1240
+	if ($command_line) {
1241
+			echo ' Successful.' . "\n";
1242
+	}
1166 1243
 
1167 1244
 	// Are we doing debug?
1168 1245
 	if (isset($_POST['debug']))
@@ -1172,8 +1249,9 @@  discard block
 block discarded – undo
1172 1249
 	}
1173 1250
 
1174 1251
 	// If we're not backing up then jump one.
1175
-	if (empty($_POST['backup']))
1176
-		$upcontext['current_step']++;
1252
+	if (empty($_POST['backup'])) {
1253
+			$upcontext['current_step']++;
1254
+	}
1177 1255
 
1178 1256
 	// If we've got here then let's proceed to the next step!
1179 1257
 	return true;
@@ -1188,8 +1266,9 @@  discard block
 block discarded – undo
1188 1266
 	$upcontext['page_title'] = 'Backup Database';
1189 1267
 
1190 1268
 	// Done it already - js wise?
1191
-	if (!empty($_POST['backup_done']))
1192
-		return true;
1269
+	if (!empty($_POST['backup_done'])) {
1270
+			return true;
1271
+	}
1193 1272
 
1194 1273
 	// Some useful stuff here.
1195 1274
 	db_extend();
@@ -1203,9 +1282,10 @@  discard block
 block discarded – undo
1203 1282
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1204 1283
 
1205 1284
 	$table_names = array();
1206
-	foreach ($tables as $table)
1207
-		if (substr($table, 0, 7) !== 'backup_')
1285
+	foreach ($tables as $table) {
1286
+			if (substr($table, 0, 7) !== 'backup_')
1208 1287
 			$table_names[] = $table;
1288
+	}
1209 1289
 
1210 1290
 	$upcontext['table_count'] = count($table_names);
1211 1291
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1215,12 +1295,14 @@  discard block
 block discarded – undo
1215 1295
 	$file_steps = $upcontext['table_count'];
1216 1296
 
1217 1297
 	// What ones have we already done?
1218
-	foreach ($table_names as $id => $table)
1219
-		if ($id < $_GET['substep'])
1298
+	foreach ($table_names as $id => $table) {
1299
+			if ($id < $_GET['substep'])
1220 1300
 			$upcontext['previous_tables'][] = $table;
1301
+	}
1221 1302
 
1222
-	if ($command_line)
1223
-		echo 'Backing Up Tables.';
1303
+	if ($command_line) {
1304
+			echo 'Backing Up Tables.';
1305
+	}
1224 1306
 
1225 1307
 	// If we don't support javascript we backup here.
1226 1308
 	if (!$support_js || isset($_GET['xml']))
@@ -1239,8 +1321,9 @@  discard block
 block discarded – undo
1239 1321
 			backupTable($table_names[$substep]);
1240 1322
 
1241 1323
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1242
-			if (isset($_GET['xml']))
1243
-				return upgradeExit();
1324
+			if (isset($_GET['xml'])) {
1325
+							return upgradeExit();
1326
+			}
1244 1327
 		}
1245 1328
 
1246 1329
 		if ($command_line)
@@ -1273,9 +1356,10 @@  discard block
 block discarded – undo
1273 1356
 
1274 1357
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1275 1358
 
1276
-	if ($command_line)
1277
-		echo ' done.';
1278
-}
1359
+	if ($command_line) {
1360
+			echo ' done.';
1361
+	}
1362
+	}
1279 1363
 
1280 1364
 // Step 2: Everything.
1281 1365
 function DatabaseChanges()
@@ -1284,8 +1368,9 @@  discard block
 block discarded – undo
1284 1368
 	global $upcontext, $support_js, $db_type;
1285 1369
 
1286 1370
 	// Have we just completed this?
1287
-	if (!empty($_POST['database_done']))
1288
-		return true;
1371
+	if (!empty($_POST['database_done'])) {
1372
+			return true;
1373
+	}
1289 1374
 
1290 1375
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1291 1376
 	$upcontext['page_title'] = 'Database Changes';
@@ -1300,15 +1385,16 @@  discard block
 block discarded – undo
1300 1385
 	);
1301 1386
 
1302 1387
 	// How many files are there in total?
1303
-	if (isset($_GET['filecount']))
1304
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1305
-	else
1388
+	if (isset($_GET['filecount'])) {
1389
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1390
+	} else
1306 1391
 	{
1307 1392
 		$upcontext['file_count'] = 0;
1308 1393
 		foreach ($files as $file)
1309 1394
 		{
1310
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1311
-				$upcontext['file_count']++;
1395
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1396
+							$upcontext['file_count']++;
1397
+			}
1312 1398
 		}
1313 1399
 	}
1314 1400
 
@@ -1318,9 +1404,9 @@  discard block
 block discarded – undo
1318 1404
 	$upcontext['cur_file_num'] = 0;
1319 1405
 	foreach ($files as $file)
1320 1406
 	{
1321
-		if ($did_not_do)
1322
-			$did_not_do--;
1323
-		else
1407
+		if ($did_not_do) {
1408
+					$did_not_do--;
1409
+		} else
1324 1410
 		{
1325 1411
 			$upcontext['cur_file_num']++;
1326 1412
 			$upcontext['cur_file_name'] = $file[0];
@@ -1347,12 +1433,13 @@  discard block
 block discarded – undo
1347 1433
 					// Flag to move on to the next.
1348 1434
 					$upcontext['completed_step'] = true;
1349 1435
 					// Did we complete the whole file?
1350
-					if ($nextFile)
1351
-						$upcontext['current_debug_item_num'] = -1;
1436
+					if ($nextFile) {
1437
+											$upcontext['current_debug_item_num'] = -1;
1438
+					}
1352 1439
 					return upgradeExit();
1440
+				} elseif ($support_js) {
1441
+									break;
1353 1442
 				}
1354
-				elseif ($support_js)
1355
-					break;
1356 1443
 			}
1357 1444
 			// Set the progress bar to be right as if we had - even if we hadn't...
1358 1445
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1377,8 +1464,9 @@  discard block
 block discarded – undo
1377 1464
 	global $command_line, $language, $upcontext, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1378 1465
 
1379 1466
 	// Now it's nice to have some of the basic SMF source files.
1380
-	if (!isset($_GET['ssi']) && !$command_line)
1381
-		redirectLocation('&ssi=1');
1467
+	if (!isset($_GET['ssi']) && !$command_line) {
1468
+			redirectLocation('&ssi=1');
1469
+	}
1382 1470
 
1383 1471
 	$upcontext['sub_template'] = 'upgrade_complete';
1384 1472
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1394,14 +1482,16 @@  discard block
 block discarded – undo
1394 1482
 	// Are we in maintenance mode?
1395 1483
 	if (isset($upcontext['user']['main']))
1396 1484
 	{
1397
-		if ($command_line)
1398
-			echo ' * ';
1485
+		if ($command_line) {
1486
+					echo ' * ';
1487
+		}
1399 1488
 		$upcontext['removed_maintenance'] = true;
1400 1489
 		$changes['maintenance'] = $upcontext['user']['main'];
1401 1490
 	}
1402 1491
 	// Otherwise if somehow we are in 2 let's go to 1.
1403
-	elseif (!empty($maintenance) && $maintenance == 2)
1404
-		$changes['maintenance'] = 1;
1492
+	elseif (!empty($maintenance) && $maintenance == 2) {
1493
+			$changes['maintenance'] = 1;
1494
+	}
1405 1495
 
1406 1496
 	// Wipe this out...
1407 1497
 	$upcontext['user'] = array();
@@ -1416,9 +1506,9 @@  discard block
 block discarded – undo
1416 1506
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1417 1507
 
1418 1508
 	// Now is the perfect time to fetch the SM files.
1419
-	if ($command_line)
1420
-		cli_scheduled_fetchSMfiles();
1421
-	else
1509
+	if ($command_line) {
1510
+			cli_scheduled_fetchSMfiles();
1511
+	} else
1422 1512
 	{
1423 1513
 		require_once($sourcedir . '/ScheduledTasks.php');
1424 1514
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1426,8 +1516,9 @@  discard block
 block discarded – undo
1426 1516
 	}
1427 1517
 
1428 1518
 	// Log what we've done.
1429
-	if (empty($user_info['id']))
1430
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1519
+	if (empty($user_info['id'])) {
1520
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1521
+	}
1431 1522
 
1432 1523
 	// Log the action manually, so CLI still works.
1433 1524
 	$smcFunc['db_insert']('',
@@ -1446,8 +1537,9 @@  discard block
 block discarded – undo
1446 1537
 
1447 1538
 	// Save the current database version.
1448 1539
 	$server_version = $smcFunc['db_server_info']();
1449
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1450
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1540
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1541
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1542
+	}
1451 1543
 
1452 1544
 	if ($command_line)
1453 1545
 	{
@@ -1459,8 +1551,9 @@  discard block
 block discarded – undo
1459 1551
 
1460 1552
 	// Make sure it says we're done.
1461 1553
 	$upcontext['overall_percent'] = 100;
1462
-	if (isset($upcontext['step_progress']))
1463
-		unset($upcontext['step_progress']);
1554
+	if (isset($upcontext['step_progress'])) {
1555
+			unset($upcontext['step_progress']);
1556
+	}
1464 1557
 
1465 1558
 	$_GET['substep'] = 0;
1466 1559
 	return false;
@@ -1471,8 +1564,9 @@  discard block
 block discarded – undo
1471 1564
 {
1472 1565
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1473 1566
 
1474
-	if (empty($modSettings['time_format']))
1475
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1567
+	if (empty($modSettings['time_format'])) {
1568
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1569
+	}
1476 1570
 
1477 1571
 	// What files do we want to get
1478 1572
 	$request = $smcFunc['db_query']('', '
@@ -1506,8 +1600,9 @@  discard block
 block discarded – undo
1506 1600
 		$file_data = fetch_web_data($url);
1507 1601
 
1508 1602
 		// If we got an error - give up - the site might be down.
1509
-		if ($file_data === false)
1510
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1603
+		if ($file_data === false) {
1604
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1605
+		}
1511 1606
 
1512 1607
 		// Save the file to the database.
1513 1608
 		$smcFunc['db_query']('substring', '
@@ -1549,8 +1644,9 @@  discard block
 block discarded – undo
1549 1644
 	$themeData = array();
1550 1645
 	foreach ($values as $variable => $value)
1551 1646
 	{
1552
-		if (!isset($value) || $value === null)
1553
-			$value = 0;
1647
+		if (!isset($value) || $value === null) {
1648
+					$value = 0;
1649
+		}
1554 1650
 
1555 1651
 		$themeData[] = array(0, 1, $variable, $value);
1556 1652
 	}
@@ -1579,8 +1675,9 @@  discard block
 block discarded – undo
1579 1675
 
1580 1676
 	foreach ($values as $variable => $value)
1581 1677
 	{
1582
-		if (empty($modSettings[$value[0]]))
1583
-			continue;
1678
+		if (empty($modSettings[$value[0]])) {
1679
+					continue;
1680
+		}
1584 1681
 
1585 1682
 		$smcFunc['db_query']('', '
1586 1683
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1666,19 +1763,21 @@  discard block
 block discarded – undo
1666 1763
 	set_error_handler(
1667 1764
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1668 1765
 		{
1669
-			if ($support_js)
1670
-				return true;
1671
-			else
1672
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1766
+			if ($support_js) {
1767
+							return true;
1768
+			} else {
1769
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1770
+			}
1673 1771
 		}
1674 1772
 	);
1675 1773
 
1676 1774
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1677 1775
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1678
-	if ($db_type == 'mysql')
1679
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1680
-	else
1681
-		$db_collation = '';
1776
+	if ($db_type == 'mysql') {
1777
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1778
+	} else {
1779
+			$db_collation = '';
1780
+	}
1682 1781
 
1683 1782
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1684 1783
 
@@ -1690,8 +1789,9 @@  discard block
 block discarded – undo
1690 1789
 	$last_step = '';
1691 1790
 
1692 1791
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1693
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1694
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1792
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1793
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1794
+	}
1695 1795
 
1696 1796
 	// Count the total number of steps within this file - for progress.
1697 1797
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1711,15 +1811,18 @@  discard block
 block discarded – undo
1711 1811
 		$do_current = $substep >= $_GET['substep'];
1712 1812
 
1713 1813
 		// Get rid of any comments in the beginning of the line...
1714
-		if (substr(trim($line), 0, 2) === '/*')
1715
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1814
+		if (substr(trim($line), 0, 2) === '/*') {
1815
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1816
+		}
1716 1817
 
1717 1818
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1718
-		if ($is_debug && !$support_js && $command_line)
1719
-			flush();
1819
+		if ($is_debug && !$support_js && $command_line) {
1820
+					flush();
1821
+		}
1720 1822
 
1721
-		if (trim($line) === '')
1722
-			continue;
1823
+		if (trim($line) === '') {
1824
+					continue;
1825
+		}
1723 1826
 
1724 1827
 		if (trim(substr($line, 0, 3)) === '---')
1725 1828
 		{
@@ -1729,8 +1832,9 @@  discard block
 block discarded – undo
1729 1832
 			if (trim($current_data) != '' && $type !== '}')
1730 1833
 			{
1731 1834
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1732
-				if ($command_line)
1733
-					echo $upcontext['error_message'];
1835
+				if ($command_line) {
1836
+									echo $upcontext['error_message'];
1837
+				}
1734 1838
 			}
1735 1839
 
1736 1840
 			if ($type == ' ')
@@ -1748,17 +1852,18 @@  discard block
 block discarded – undo
1748 1852
 				if ($do_current)
1749 1853
 				{
1750 1854
 					$upcontext['actioned_items'][] = $last_step;
1751
-					if ($command_line)
1752
-						echo ' * ';
1855
+					if ($command_line) {
1856
+											echo ' * ';
1857
+					}
1753 1858
 				}
1754
-			}
1755
-			elseif ($type == '#')
1859
+			} elseif ($type == '#')
1756 1860
 			{
1757 1861
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1758 1862
 
1759 1863
 				$upcontext['current_debug_item_num']++;
1760
-				if (trim($line) != '---#')
1761
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1864
+				if (trim($line) != '---#') {
1865
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1866
+				}
1762 1867
 
1763 1868
 				// Have we already done something?
1764 1869
 				if (isset($_GET['xml']) && $done_something)
@@ -1769,34 +1874,36 @@  discard block
 block discarded – undo
1769 1874
 
1770 1875
 				if ($do_current)
1771 1876
 				{
1772
-					if (trim($line) == '---#' && $command_line)
1773
-						echo ' done.', $endl;
1774
-					elseif ($command_line)
1775
-						echo ' +++ ', rtrim(substr($line, 4));
1776
-					elseif (trim($line) != '---#')
1877
+					if (trim($line) == '---#' && $command_line) {
1878
+											echo ' done.', $endl;
1879
+					} elseif ($command_line) {
1880
+											echo ' +++ ', rtrim(substr($line, 4));
1881
+					} elseif (trim($line) != '---#')
1777 1882
 					{
1778
-						if ($is_debug)
1779
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1883
+						if ($is_debug) {
1884
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1885
+						}
1780 1886
 					}
1781 1887
 				}
1782 1888
 
1783 1889
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1784 1890
 				{
1785
-					if ($command_line)
1786
-						echo ' * ';
1787
-					else
1788
-						$upcontext['actioned_items'][] = $last_step;
1891
+					if ($command_line) {
1892
+											echo ' * ';
1893
+					} else {
1894
+											$upcontext['actioned_items'][] = $last_step;
1895
+					}
1789 1896
 				}
1790 1897
 
1791 1898
 				// Small step - only if we're actually doing stuff.
1792
-				if ($do_current)
1793
-					nextSubstep(++$substep);
1794
-				else
1795
-					$substep++;
1796
-			}
1797
-			elseif ($type == '{')
1798
-				$current_type = 'code';
1799
-			elseif ($type == '}')
1899
+				if ($do_current) {
1900
+									nextSubstep(++$substep);
1901
+				} else {
1902
+									$substep++;
1903
+				}
1904
+			} elseif ($type == '{') {
1905
+							$current_type = 'code';
1906
+			} elseif ($type == '}')
1800 1907
 			{
1801 1908
 				$current_type = 'sql';
1802 1909
 
@@ -1809,8 +1916,9 @@  discard block
 block discarded – undo
1809 1916
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1810 1917
 				{
1811 1918
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1812
-					if ($command_line)
1813
-						echo $upcontext['error_message'];
1919
+					if ($command_line) {
1920
+											echo $upcontext['error_message'];
1921
+					}
1814 1922
 				}
1815 1923
 
1816 1924
 				// Done with code!
@@ -1890,8 +1998,9 @@  discard block
 block discarded – undo
1890 1998
 	$db_unbuffered = false;
1891 1999
 
1892 2000
 	// Failure?!
1893
-	if ($result !== false)
1894
-		return $result;
2001
+	if ($result !== false) {
2002
+			return $result;
2003
+	}
1895 2004
 
1896 2005
 	$db_error_message = $smcFunc['db_error']($db_connection);
1897 2006
 	// If MySQL we do something more clever.
@@ -1919,54 +2028,61 @@  discard block
 block discarded – undo
1919 2028
 			{
1920 2029
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1921 2030
 				$result = mysqli_query($db_connection, $string);
1922
-				if ($result !== false)
1923
-					return $result;
2031
+				if ($result !== false) {
2032
+									return $result;
2033
+				}
1924 2034
 			}
1925
-		}
1926
-		elseif ($mysqli_errno == 2013)
2035
+		} elseif ($mysqli_errno == 2013)
1927 2036
 		{
1928 2037
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1929 2038
 			mysqli_select_db($db_connection, $db_name);
1930 2039
 			if ($db_connection)
1931 2040
 			{
1932 2041
 				$result = mysqli_query($db_connection, $string);
1933
-				if ($result !== false)
1934
-					return $result;
2042
+				if ($result !== false) {
2043
+									return $result;
2044
+				}
1935 2045
 			}
1936 2046
 		}
1937 2047
 		// Duplicate column name... should be okay ;).
1938
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1939
-			return false;
2048
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2049
+					return false;
2050
+		}
1940 2051
 		// Duplicate insert... make sure it's the proper type of query ;).
1941
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1942
-			return false;
2052
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2053
+					return false;
2054
+		}
1943 2055
 		// Creating an index on a non-existent column.
1944
-		elseif ($mysqli_errno == 1072)
1945
-			return false;
1946
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1947
-			return false;
2056
+		elseif ($mysqli_errno == 1072) {
2057
+					return false;
2058
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2059
+					return false;
2060
+		}
1948 2061
 	}
1949 2062
 	// If a table already exists don't go potty.
1950 2063
 	else
1951 2064
 	{
1952 2065
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1953 2066
 		{
1954
-			if (strpos($db_error_message, 'exist') !== false)
1955
-				return true;
1956
-		}
1957
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2067
+			if (strpos($db_error_message, 'exist') !== false) {
2068
+							return true;
2069
+			}
2070
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1958 2071
 		{
1959
-			if (strpos($db_error_message, 'duplicate') !== false)
1960
-				return true;
2072
+			if (strpos($db_error_message, 'duplicate') !== false) {
2073
+							return true;
2074
+			}
1961 2075
 		}
1962 2076
 	}
1963 2077
 
1964 2078
 	// Get the query string so we pass everything.
1965 2079
 	$query_string = '';
1966
-	foreach ($_GET as $k => $v)
1967
-		$query_string .= ';' . $k . '=' . $v;
1968
-	if (strlen($query_string) != 0)
1969
-		$query_string = '?' . substr($query_string, 1);
2080
+	foreach ($_GET as $k => $v) {
2081
+			$query_string .= ';' . $k . '=' . $v;
2082
+	}
2083
+	if (strlen($query_string) != 0) {
2084
+			$query_string = '?' . substr($query_string, 1);
2085
+	}
1970 2086
 
1971 2087
 	if ($command_line)
1972 2088
 	{
@@ -2021,16 +2137,18 @@  discard block
 block discarded – undo
2021 2137
 			{
2022 2138
 				$found |= 1;
2023 2139
 				// Do some checks on the data if we have it set.
2024
-				if (isset($change['col_type']))
2025
-					$found &= $change['col_type'] === $column['type'];
2026
-				if (isset($change['null_allowed']))
2027
-					$found &= $column['null'] == $change['null_allowed'];
2028
-				if (isset($change['default']))
2029
-					$found &= $change['default'] === $column['default'];
2140
+				if (isset($change['col_type'])) {
2141
+									$found &= $change['col_type'] === $column['type'];
2142
+				}
2143
+				if (isset($change['null_allowed'])) {
2144
+									$found &= $column['null'] == $change['null_allowed'];
2145
+				}
2146
+				if (isset($change['default'])) {
2147
+									$found &= $change['default'] === $column['default'];
2148
+				}
2030 2149
 			}
2031 2150
 		}
2032
-	}
2033
-	elseif ($change['type'] === 'index')
2151
+	} elseif ($change['type'] === 'index')
2034 2152
 	{
2035 2153
 		$request = upgrade_query('
2036 2154
 			SHOW INDEX
@@ -2039,9 +2157,10 @@  discard block
 block discarded – undo
2039 2157
 		{
2040 2158
 			$cur_index = array();
2041 2159
 
2042
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2043
-				if ($row['Key_name'] === $change['name'])
2160
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2161
+							if ($row['Key_name'] === $change['name'])
2044 2162
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2163
+			}
2045 2164
 
2046 2165
 			ksort($cur_index, SORT_NUMERIC);
2047 2166
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2051,14 +2170,17 @@  discard block
 block discarded – undo
2051 2170
 	}
2052 2171
 
2053 2172
 	// If we're trying to add and it's added, we're done.
2054
-	if ($found && in_array($change['method'], array('add', 'change')))
2055
-		return true;
2173
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2174
+			return true;
2175
+	}
2056 2176
 	// Otherwise if we're removing and it wasn't found we're also done.
2057
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2058
-		return true;
2177
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2178
+			return true;
2179
+	}
2059 2180
 	// Otherwise is it just a test?
2060
-	elseif ($is_test)
2061
-		return false;
2181
+	elseif ($is_test) {
2182
+			return false;
2183
+	}
2062 2184
 
2063 2185
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2064 2186
 	$running = false;
@@ -2069,8 +2191,9 @@  discard block
 block discarded – undo
2069 2191
 			SHOW FULL PROCESSLIST');
2070 2192
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2071 2193
 		{
2072
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2073
-				$found = true;
2194
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2195
+							$found = true;
2196
+			}
2074 2197
 		}
2075 2198
 
2076 2199
 		// Can't find it? Then we need to run it fools!
@@ -2082,8 +2205,9 @@  discard block
 block discarded – undo
2082 2205
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2083 2206
 				' . $change['text'], true) !== false;
2084 2207
 
2085
-			if (!$success)
2086
-				return false;
2208
+			if (!$success) {
2209
+							return false;
2210
+			}
2087 2211
 
2088 2212
 			// Return
2089 2213
 			$running = true;
@@ -2125,8 +2249,9 @@  discard block
 block discarded – undo
2125 2249
 			'db_error_skip' => true,
2126 2250
 		)
2127 2251
 	);
2128
-	if ($smcFunc['db_num_rows']($request) === 0)
2129
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2252
+	if ($smcFunc['db_num_rows']($request) === 0) {
2253
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2254
+	}
2130 2255
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2131 2256
 	$smcFunc['db_free_result']($request);
2132 2257
 
@@ -2148,18 +2273,19 @@  discard block
 block discarded – undo
2148 2273
 			)
2149 2274
 		);
2150 2275
 		// No results? Just forget it all together.
2151
-		if ($smcFunc['db_num_rows']($request) === 0)
2152
-			unset($table_row['Collation']);
2153
-		else
2154
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2276
+		if ($smcFunc['db_num_rows']($request) === 0) {
2277
+					unset($table_row['Collation']);
2278
+		} else {
2279
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2280
+		}
2155 2281
 		$smcFunc['db_free_result']($request);
2156 2282
 	}
2157 2283
 
2158 2284
 	if ($column_fix)
2159 2285
 	{
2160 2286
 		// Make sure there are no NULL's left.
2161
-		if ($null_fix)
2162
-			$smcFunc['db_query']('', '
2287
+		if ($null_fix) {
2288
+					$smcFunc['db_query']('', '
2163 2289
 				UPDATE {db_prefix}' . $change['table'] . '
2164 2290
 				SET ' . $change['column'] . ' = {string:default}
2165 2291
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2168,6 +2294,7 @@  discard block
 block discarded – undo
2168 2294
 					'db_error_skip' => true,
2169 2295
 				)
2170 2296
 			);
2297
+		}
2171 2298
 
2172 2299
 		// Do the actual alteration.
2173 2300
 		$smcFunc['db_query']('', '
@@ -2196,8 +2323,9 @@  discard block
 block discarded – undo
2196 2323
 	}
2197 2324
 
2198 2325
 	// Not a column we need to check on?
2199
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2200
-		return;
2326
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2327
+			return;
2328
+	}
2201 2329
 
2202 2330
 	// Break it up you (six|seven).
2203 2331
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2216,13 +2344,13 @@  discard block
 block discarded – undo
2216 2344
 				'new_name' => $temp[2],
2217 2345
 		));
2218 2346
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2219
-		if ($smcFunc['db_num_rows'] != 1)
2220
-			return;
2347
+		if ($smcFunc['db_num_rows'] != 1) {
2348
+					return;
2349
+		}
2221 2350
 
2222 2351
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2223 2352
 		$smcFunc['db_free_result']($request);
2224
-	}
2225
-	else
2353
+	} else
2226 2354
 	{
2227 2355
 		// Do this the old fashion, sure method way.
2228 2356
 		$request = $smcFunc['db_query']('', '
@@ -2233,21 +2361,24 @@  discard block
 block discarded – undo
2233 2361
 		));
2234 2362
 		// Mayday!
2235 2363
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2236
-		if ($smcFunc['db_num_rows'] == 0)
2237
-			return;
2364
+		if ($smcFunc['db_num_rows'] == 0) {
2365
+					return;
2366
+		}
2238 2367
 
2239 2368
 		// Oh where, oh where has my little field gone. Oh where can it be...
2240
-		while ($row = $smcFunc['db_query']($request))
2241
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2369
+		while ($row = $smcFunc['db_query']($request)) {
2370
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2242 2371
 			{
2243 2372
 				$current_type = $row['Type'];
2373
+		}
2244 2374
 				break;
2245 2375
 			}
2246 2376
 	}
2247 2377
 
2248 2378
 	// If this doesn't match, the column may of been altered for a reason.
2249
-	if (trim($current_type) != trim($temp[3]))
2250
-		$temp[3] = $current_type;
2379
+	if (trim($current_type) != trim($temp[3])) {
2380
+			$temp[3] = $current_type;
2381
+	}
2251 2382
 
2252 2383
 	// Piece this back together.
2253 2384
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2259,8 +2390,9 @@  discard block
 block discarded – undo
2259 2390
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2260 2391
 	global $step_progress, $is_debug, $upcontext;
2261 2392
 
2262
-	if ($_GET['substep'] < $substep)
2263
-		$_GET['substep'] = $substep;
2393
+	if ($_GET['substep'] < $substep) {
2394
+			$_GET['substep'] = $substep;
2395
+	}
2264 2396
 
2265 2397
 	if ($command_line)
2266 2398
 	{
@@ -2273,29 +2405,33 @@  discard block
 block discarded – undo
2273 2405
 	}
2274 2406
 
2275 2407
 	@set_time_limit(300);
2276
-	if (function_exists('apache_reset_timeout'))
2277
-		@apache_reset_timeout();
2408
+	if (function_exists('apache_reset_timeout')) {
2409
+			@apache_reset_timeout();
2410
+	}
2278 2411
 
2279
-	if (time() - $start_time <= $timeLimitThreshold)
2280
-		return;
2412
+	if (time() - $start_time <= $timeLimitThreshold) {
2413
+			return;
2414
+	}
2281 2415
 
2282 2416
 	// Do we have some custom step progress stuff?
2283 2417
 	if (!empty($step_progress))
2284 2418
 	{
2285 2419
 		$upcontext['substep_progress'] = 0;
2286 2420
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2287
-		if ($step_progress['current'] > $step_progress['total'])
2288
-			$upcontext['substep_progress'] = 99.9;
2289
-		else
2290
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2421
+		if ($step_progress['current'] > $step_progress['total']) {
2422
+					$upcontext['substep_progress'] = 99.9;
2423
+		} else {
2424
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2425
+		}
2291 2426
 
2292 2427
 		// Make it nicely rounded.
2293 2428
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2294 2429
 	}
2295 2430
 
2296 2431
 	// If this is XML we just exit right away!
2297
-	if (isset($_GET['xml']))
2298
-		return upgradeExit();
2432
+	if (isset($_GET['xml'])) {
2433
+			return upgradeExit();
2434
+	}
2299 2435
 
2300 2436
 	// We're going to pause after this!
2301 2437
 	$upcontext['pause'] = true;
@@ -2303,13 +2439,15 @@  discard block
 block discarded – undo
2303 2439
 	$upcontext['query_string'] = '';
2304 2440
 	foreach ($_GET as $k => $v)
2305 2441
 	{
2306
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2307
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2442
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2443
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2444
+		}
2308 2445
 	}
2309 2446
 
2310 2447
 	// Custom warning?
2311
-	if (!empty($custom_warning))
2312
-		$upcontext['custom_warning'] = $custom_warning;
2448
+	if (!empty($custom_warning)) {
2449
+			$upcontext['custom_warning'] = $custom_warning;
2450
+	}
2313 2451
 
2314 2452
 	upgradeExit();
2315 2453
 }
@@ -2324,25 +2462,26 @@  discard block
 block discarded – undo
2324 2462
 	ob_implicit_flush(true);
2325 2463
 	@set_time_limit(600);
2326 2464
 
2327
-	if (!isset($_SERVER['argv']))
2328
-		$_SERVER['argv'] = array();
2465
+	if (!isset($_SERVER['argv'])) {
2466
+			$_SERVER['argv'] = array();
2467
+	}
2329 2468
 	$_GET['maint'] = 1;
2330 2469
 
2331 2470
 	foreach ($_SERVER['argv'] as $i => $arg)
2332 2471
 	{
2333
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2334
-			$_GET['lang'] = $match[1];
2335
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2336
-			continue;
2337
-		elseif ($arg == '--no-maintenance')
2338
-			$_GET['maint'] = 0;
2339
-		elseif ($arg == '--debug')
2340
-			$is_debug = true;
2341
-		elseif ($arg == '--backup')
2342
-			$_POST['backup'] = 1;
2343
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2344
-			$_GET['conv'] = 1;
2345
-		elseif ($i != 0)
2472
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2473
+					$_GET['lang'] = $match[1];
2474
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2475
+					continue;
2476
+		} elseif ($arg == '--no-maintenance') {
2477
+					$_GET['maint'] = 0;
2478
+		} elseif ($arg == '--debug') {
2479
+					$is_debug = true;
2480
+		} elseif ($arg == '--backup') {
2481
+					$_POST['backup'] = 1;
2482
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2483
+					$_GET['conv'] = 1;
2484
+		} elseif ($i != 0)
2346 2485
 		{
2347 2486
 			echo 'SMF Command-line Upgrader
2348 2487
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2356,10 +2495,12 @@  discard block
 block discarded – undo
2356 2495
 		}
2357 2496
 	}
2358 2497
 
2359
-	if (!php_version_check())
2360
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2361
-	if (!db_version_check())
2362
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2498
+	if (!php_version_check()) {
2499
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2500
+	}
2501
+	if (!db_version_check()) {
2502
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2503
+	}
2363 2504
 
2364 2505
 	// Do some checks to make sure they have proper privileges
2365 2506
 	db_extend('packages');
@@ -2374,34 +2515,39 @@  discard block
 block discarded – undo
2374 2515
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2375 2516
 
2376 2517
 	// Sorry... we need CREATE, ALTER and DROP
2377
-	if (!$create || !$alter || !$drop)
2378
-		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);
2518
+	if (!$create || !$alter || !$drop) {
2519
+			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);
2520
+	}
2379 2521
 
2380 2522
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2381 2523
 		&& @file_exists($sourcedir . '/QueryString.php')
2382 2524
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2383
-	if (!$check && !isset($modSettings['smfVersion']))
2384
-		print_error('Error: Some files are missing or out-of-date.', true);
2525
+	if (!$check && !isset($modSettings['smfVersion'])) {
2526
+			print_error('Error: Some files are missing or out-of-date.', true);
2527
+	}
2385 2528
 
2386 2529
 	// Do a quick version spot check.
2387 2530
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2388 2531
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2389
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2390
-		print_error('Error: Some files have not yet been updated properly.');
2532
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2533
+			print_error('Error: Some files have not yet been updated properly.');
2534
+	}
2391 2535
 
2392 2536
 	// Make sure Settings.php is writable.
2393 2537
 	quickFileWritable($boarddir . '/Settings.php');
2394
-	if (!is_writable($boarddir . '/Settings.php'))
2395
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2538
+	if (!is_writable($boarddir . '/Settings.php')) {
2539
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2540
+	}
2396 2541
 
2397 2542
 	// Make sure Settings_bak.php is writable.
2398 2543
 	quickFileWritable($boarddir . '/Settings_bak.php');
2399
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2400
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2544
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2545
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2546
+	}
2401 2547
 
2402
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2403
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2404
-	elseif (isset($modSettings['agreement']))
2548
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2549
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2550
+	} elseif (isset($modSettings['agreement']))
2405 2551
 	{
2406 2552
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2407 2553
 		fwrite($fp, $modSettings['agreement']);
@@ -2411,36 +2557,42 @@  discard block
 block discarded – undo
2411 2557
 	// Make sure Themes is writable.
2412 2558
 	quickFileWritable($modSettings['theme_dir']);
2413 2559
 
2414
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2415
-		print_error('Error: Unable to obtain write access to "Themes".');
2560
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2561
+			print_error('Error: Unable to obtain write access to "Themes".');
2562
+	}
2416 2563
 
2417 2564
 	// Make sure cache directory exists and is writable!
2418 2565
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2419
-	if (!file_exists($cachedir_temp))
2420
-		@mkdir($cachedir_temp);
2566
+	if (!file_exists($cachedir_temp)) {
2567
+			@mkdir($cachedir_temp);
2568
+	}
2421 2569
 
2422 2570
 	// Make sure the cache temp dir is writable.
2423 2571
 	quickFileWritable($cachedir_temp);
2424 2572
 
2425
-	if (!is_writable($cachedir_temp))
2426
-		print_error('Error: Unable to obtain write access to "cache".', true);
2573
+	if (!is_writable($cachedir_temp)) {
2574
+			print_error('Error: Unable to obtain write access to "cache".', true);
2575
+	}
2427 2576
 
2428 2577
 	// Make sure db_last_error.php is writable.
2429 2578
 	quickFileWritable($cachedir_temp . '/db_last_error.php');
2430
-	if (!is_writable($cachedir_temp . '/db_last_error.php'))
2431
-		print_error('Error: Unable to obtain write access to "db_last_error.php".');
2579
+	if (!is_writable($cachedir_temp . '/db_last_error.php')) {
2580
+			print_error('Error: Unable to obtain write access to "db_last_error.php".');
2581
+	}
2432 2582
 
2433
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2434
-		print_error('Error: Unable to find language files!', true);
2435
-	else
2583
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2584
+			print_error('Error: Unable to find language files!', true);
2585
+	} else
2436 2586
 	{
2437 2587
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2438 2588
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2439 2589
 
2440
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2441
-			print_error('Error: Language files out of date.', true);
2442
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2443
-			print_error('Error: Install language is missing for selected language.', true);
2590
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2591
+					print_error('Error: Language files out of date.', true);
2592
+		}
2593
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2594
+					print_error('Error: Install language is missing for selected language.', true);
2595
+		}
2444 2596
 
2445 2597
 		// Otherwise include it!
2446 2598
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2459,8 +2611,9 @@  discard block
 block discarded – undo
2459 2611
 	global $upcontext, $db_character_set, $sourcedir, $smcFunc, $modSettings, $language, $db_prefix, $db_type, $command_line, $support_js;
2460 2612
 
2461 2613
 	// Done it already?
2462
-	if (!empty($_POST['utf8_done']))
2463
-		return true;
2614
+	if (!empty($_POST['utf8_done'])) {
2615
+			return true;
2616
+	}
2464 2617
 
2465 2618
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2466 2619
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2473,8 +2626,7 @@  discard block
 block discarded – undo
2473 2626
 		);
2474 2627
 
2475 2628
 		return true;
2476
-	}
2477
-	else
2629
+	} else
2478 2630
 	{
2479 2631
 		$upcontext['page_title'] = 'Converting to UTF8';
2480 2632
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2518,8 +2670,9 @@  discard block
 block discarded – undo
2518 2670
 			)
2519 2671
 		);
2520 2672
 		$db_charsets = array();
2521
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2522
-			$db_charsets[] = $row['Charset'];
2673
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2674
+					$db_charsets[] = $row['Charset'];
2675
+		}
2523 2676
 
2524 2677
 		$smcFunc['db_free_result']($request);
2525 2678
 
@@ -2555,13 +2708,15 @@  discard block
 block discarded – undo
2555 2708
 		// If there's a fulltext index, we need to drop it first...
2556 2709
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2557 2710
 		{
2558
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2559
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2711
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2712
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2560 2713
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2714
+			}
2561 2715
 			$smcFunc['db_free_result']($request);
2562 2716
 
2563
-			if (isset($upcontext['fulltext_index']))
2564
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2717
+			if (isset($upcontext['fulltext_index'])) {
2718
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2719
+			}
2565 2720
 		}
2566 2721
 
2567 2722
 		// Drop it and make a note...
@@ -2751,8 +2906,9 @@  discard block
 block discarded – undo
2751 2906
 			$replace = '%field%';
2752 2907
 
2753 2908
 			// Build a huge REPLACE statement...
2754
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2755
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2909
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2910
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2911
+			}
2756 2912
 		}
2757 2913
 
2758 2914
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2762,9 +2918,10 @@  discard block
 block discarded – undo
2762 2918
 		$upcontext['table_count'] = count($queryTables);
2763 2919
 
2764 2920
 		// What ones have we already done?
2765
-		foreach ($queryTables as $id => $table)
2766
-			if ($id < $_GET['substep'])
2921
+		foreach ($queryTables as $id => $table) {
2922
+					if ($id < $_GET['substep'])
2767 2923
 				$upcontext['previous_tables'][] = $table;
2924
+		}
2768 2925
 
2769 2926
 		$upcontext['cur_table_num'] = $_GET['substep'];
2770 2927
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2801,8 +2958,9 @@  discard block
 block discarded – undo
2801 2958
 			nextSubstep($substep);
2802 2959
 
2803 2960
 			// Just to make sure it doesn't time out.
2804
-			if (function_exists('apache_reset_timeout'))
2805
-				@apache_reset_timeout();
2961
+			if (function_exists('apache_reset_timeout')) {
2962
+							@apache_reset_timeout();
2963
+			}
2806 2964
 
2807 2965
 			$table_charsets = array();
2808 2966
 
@@ -2825,8 +2983,9 @@  discard block
 block discarded – undo
2825 2983
 
2826 2984
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2827 2985
 						if ($charset != 'utf8') {
2828
-							if (!isset($table_charsets[$charset]))
2829
-								$table_charsets[$charset] = array();
2986
+							if (!isset($table_charsets[$charset])) {
2987
+															$table_charsets[$charset] = array();
2988
+							}
2830 2989
 
2831 2990
 							$table_charsets[$charset][] = $column_info;
2832 2991
 						}
@@ -2867,10 +3026,11 @@  discard block
 block discarded – undo
2867 3026
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2868 3027
 				{
2869 3028
 					$update = '';
2870
-					foreach ($table_charsets as $charset => $columns)
2871
-						foreach ($columns as $column)
3029
+					foreach ($table_charsets as $charset => $columns) {
3030
+											foreach ($columns as $column)
2872 3031
 							$update .= '
2873 3032
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3033
+					}
2874 3034
 
2875 3035
 					$smcFunc['db_query']('', '
2876 3036
 						UPDATE {raw:table_name}
@@ -2895,8 +3055,9 @@  discard block
 block discarded – undo
2895 3055
 			// Now do the actual conversion (if still needed).
2896 3056
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2897 3057
 			{
2898
-				if ($command_line)
2899
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3058
+				if ($command_line) {
3059
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3060
+				}
2900 3061
 
2901 3062
 				$smcFunc['db_query']('', '
2902 3063
 					ALTER TABLE {raw:table_name}
@@ -2906,12 +3067,14 @@  discard block
 block discarded – undo
2906 3067
 					)
2907 3068
 				);
2908 3069
 
2909
-				if ($command_line)
2910
-					echo " done.\n";
3070
+				if ($command_line) {
3071
+									echo " done.\n";
3072
+				}
2911 3073
 			}
2912 3074
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2913
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
2914
-				return upgradeExit();
3075
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3076
+							return upgradeExit();
3077
+			}
2915 3078
 		}
2916 3079
 
2917 3080
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -2940,8 +3103,8 @@  discard block
 block discarded – undo
2940 3103
 		);
2941 3104
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2942 3105
 		{
2943
-			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)
2944
-				$smcFunc['db_query']('', '
3106
+			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) {
3107
+							$smcFunc['db_query']('', '
2945 3108
 					UPDATE {db_prefix}log_actions
2946 3109
 					SET extra = {string:extra}
2947 3110
 					WHERE id_action = {int:current_action}',
@@ -2950,6 +3113,7 @@  discard block
 block discarded – undo
2950 3113
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2951 3114
 					)
2952 3115
 				);
3116
+			}
2953 3117
 		}
2954 3118
 		$smcFunc['db_free_result']($request);
2955 3119
 
@@ -2971,15 +3135,17 @@  discard block
 block discarded – undo
2971 3135
 	// First thing's first - did we already do this?
2972 3136
 	if (!empty($modSettings['json_done']))
2973 3137
 	{
2974
-		if ($command_line)
2975
-			return DeleteUpgrade();
2976
-		else
2977
-			return true;
3138
+		if ($command_line) {
3139
+					return DeleteUpgrade();
3140
+		} else {
3141
+					return true;
3142
+		}
2978 3143
 	}
2979 3144
 
2980 3145
 	// Done it already - js wise?
2981
-	if (!empty($_POST['json_done']))
2982
-		return true;
3146
+	if (!empty($_POST['json_done'])) {
3147
+			return true;
3148
+	}
2983 3149
 
2984 3150
 	// List of tables affected by this function
2985 3151
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3011,12 +3177,14 @@  discard block
 block discarded – undo
3011 3177
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3012 3178
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3013 3179
 
3014
-	foreach ($keys as $id => $table)
3015
-		if ($id < $_GET['substep'])
3180
+	foreach ($keys as $id => $table) {
3181
+			if ($id < $_GET['substep'])
3016 3182
 			$upcontext['previous_tables'][] = $table;
3183
+	}
3017 3184
 
3018
-	if ($command_line)
3019
-		echo 'Converting data from serialize() to json_encode().';
3185
+	if ($command_line) {
3186
+			echo 'Converting data from serialize() to json_encode().';
3187
+	}
3020 3188
 
3021 3189
 	if (!$support_js || isset($_GET['xml']))
3022 3190
 	{
@@ -3056,8 +3224,9 @@  discard block
 block discarded – undo
3056 3224
 
3057 3225
 				// Loop through and fix these...
3058 3226
 				$new_settings = array();
3059
-				if ($command_line)
3060
-					echo "\n" . 'Fixing some settings...';
3227
+				if ($command_line) {
3228
+									echo "\n" . 'Fixing some settings...';
3229
+				}
3061 3230
 
3062 3231
 				foreach ($serialized_settings as $var)
3063 3232
 				{
@@ -3065,22 +3234,24 @@  discard block
 block discarded – undo
3065 3234
 					{
3066 3235
 						// Attempt to unserialize the setting
3067 3236
 						$temp = @safe_unserialize($modSettings[$var]);
3068
-						if (!$temp && $command_line)
3069
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3070
-						elseif ($temp !== false)
3071
-							$new_settings[$var] = json_encode($temp);
3237
+						if (!$temp && $command_line) {
3238
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3239
+						} elseif ($temp !== false) {
3240
+													$new_settings[$var] = json_encode($temp);
3241
+						}
3072 3242
 					}
3073 3243
 				}
3074 3244
 
3075 3245
 				// Update everything at once
3076
-				if (!function_exists('cache_put_data'))
3077
-					require_once($sourcedir . '/Load.php');
3246
+				if (!function_exists('cache_put_data')) {
3247
+									require_once($sourcedir . '/Load.php');
3248
+				}
3078 3249
 				updateSettings($new_settings, true);
3079 3250
 
3080
-				if ($command_line)
3081
-					echo ' done.';
3082
-			}
3083
-			elseif ($table == 'themes')
3251
+				if ($command_line) {
3252
+									echo ' done.';
3253
+				}
3254
+			} elseif ($table == 'themes')
3084 3255
 			{
3085 3256
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3086 3257
 				$query = $smcFunc['db_query']('', '
@@ -3099,10 +3270,11 @@  discard block
 block discarded – undo
3099 3270
 
3100 3271
 						if ($command_line)
3101 3272
 						{
3102
-							if ($temp === false)
3103
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3104
-							else
3105
-								echo "\n" . 'Fixing admin preferences...';
3273
+							if ($temp === false) {
3274
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3275
+							} else {
3276
+															echo "\n" . 'Fixing admin preferences...';
3277
+							}
3106 3278
 						}
3107 3279
 
3108 3280
 						if ($temp !== false)
@@ -3124,15 +3296,15 @@  discard block
 block discarded – undo
3124 3296
 								)
3125 3297
 							);
3126 3298
 
3127
-							if ($command_line)
3128
-								echo ' done.';
3299
+							if ($command_line) {
3300
+															echo ' done.';
3301
+							}
3129 3302
 						}
3130 3303
 					}
3131 3304
 
3132 3305
 					$smcFunc['db_free_result']($query);
3133 3306
 				}
3134
-			}
3135
-			else
3307
+			} else
3136 3308
 			{
3137 3309
 				// First item is always the key...
3138 3310
 				$key = $info[0];
@@ -3143,8 +3315,7 @@  discard block
 block discarded – undo
3143 3315
 				{
3144 3316
 					$col_select = $info[1];
3145 3317
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3146
-				}
3147
-				else
3318
+				} else
3148 3319
 				{
3149 3320
 					$col_select = implode(', ', $info);
3150 3321
 				}
@@ -3177,8 +3348,7 @@  discard block
 block discarded – undo
3177 3348
 								if ($temp === false && $command_line)
3178 3349
 								{
3179 3350
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3180
-								}
3181
-								else
3351
+								} else
3182 3352
 								{
3183 3353
 									$row[$col] = json_encode($temp);
3184 3354
 
@@ -3203,16 +3373,18 @@  discard block
 block discarded – undo
3203 3373
 						}
3204 3374
 					}
3205 3375
 
3206
-					if ($command_line)
3207
-						echo ' done.';
3376
+					if ($command_line) {
3377
+											echo ' done.';
3378
+					}
3208 3379
 
3209 3380
 					// Free up some memory...
3210 3381
 					$smcFunc['db_free_result']($query);
3211 3382
 				}
3212 3383
 			}
3213 3384
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3214
-			if (isset($_GET['xml']))
3215
-				return upgradeExit();
3385
+			if (isset($_GET['xml'])) {
3386
+							return upgradeExit();
3387
+			}
3216 3388
 		}
3217 3389
 
3218 3390
 		if ($command_line)
@@ -3227,8 +3399,9 @@  discard block
 block discarded – undo
3227 3399
 
3228 3400
 		$_GET['substep'] = 0;
3229 3401
 		// Make sure we move on!
3230
-		if ($command_line)
3231
-			return DeleteUpgrade();
3402
+		if ($command_line) {
3403
+					return DeleteUpgrade();
3404
+		}
3232 3405
 
3233 3406
 		return true;
3234 3407
 	}
@@ -3285,14 +3458,16 @@  discard block
 block discarded – undo
3285 3458
 	global $upcontext, $txt, $settings;
3286 3459
 
3287 3460
 	// Don't call me twice!
3288
-	if (!empty($upcontext['chmod_called']))
3289
-		return;
3461
+	if (!empty($upcontext['chmod_called'])) {
3462
+			return;
3463
+	}
3290 3464
 
3291 3465
 	$upcontext['chmod_called'] = true;
3292 3466
 
3293 3467
 	// Nothing?
3294
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3295
-		return;
3468
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3469
+			return;
3470
+	}
3296 3471
 
3297 3472
 	// Was it a problem with Windows?
3298 3473
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3324,11 +3499,12 @@  discard block
 block discarded – undo
3324 3499
 					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\');
3325 3500
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3326 3501
 
3327
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3328
-		echo '
3502
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3503
+			echo '
3329 3504
 					content.write(\'<hr>\n\t\t\t\');
3330 3505
 					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\');
3331 3506
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3507
+	}
3332 3508
 
3333 3509
 	echo '
3334 3510
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3336,17 +3512,19 @@  discard block
 block discarded – undo
3336 3512
 				}
3337 3513
 			</script>';
3338 3514
 
3339
-	if (!empty($upcontext['chmod']['ftp_error']))
3340
-		echo '
3515
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3516
+			echo '
3341 3517
 			<div class="error_message red">
3342 3518
 				The following error was encountered when trying to connect:<br><br>
3343 3519
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3344 3520
 			</div>
3345 3521
 			<br>';
3522
+	}
3346 3523
 
3347
-	if (empty($upcontext['chmod_in_form']))
3348
-		echo '
3524
+	if (empty($upcontext['chmod_in_form'])) {
3525
+			echo '
3349 3526
 	<form action="', $upcontext['form_url'], '" method="post">';
3527
+	}
3350 3528
 
3351 3529
 	echo '
3352 3530
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3381,10 +3559,11 @@  discard block
 block discarded – undo
3381 3559
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button"></div>
3382 3560
 	</div>';
3383 3561
 
3384
-	if (empty($upcontext['chmod_in_form']))
3385
-		echo '
3562
+	if (empty($upcontext['chmod_in_form'])) {
3563
+			echo '
3386 3564
 	</form>';
3387
-}
3565
+	}
3566
+	}
3388 3567
 
3389 3568
 function template_upgrade_above()
3390 3569
 {
@@ -3444,9 +3623,10 @@  discard block
 block discarded – undo
3444 3623
 				<h2>', $txt['upgrade_progress'], '</h2>
3445 3624
 				<ul>';
3446 3625
 
3447
-	foreach ($upcontext['steps'] as $num => $step)
3448
-		echo '
3626
+	foreach ($upcontext['steps'] as $num => $step) {
3627
+			echo '
3449 3628
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3629
+	}
3450 3630
 
3451 3631
 	echo '
3452 3632
 					</ul>
@@ -3459,8 +3639,8 @@  discard block
 block discarded – undo
3459 3639
 				</div>
3460 3640
 			</div>';
3461 3641
 
3462
-	if (isset($upcontext['step_progress']))
3463
-		echo '
3642
+	if (isset($upcontext['step_progress'])) {
3643
+			echo '
3464 3644
 				<br>
3465 3645
 				<br>
3466 3646
 				<div id="progress_bar_step">
@@ -3469,6 +3649,7 @@  discard block
 block discarded – undo
3469 3649
 						<span>', $txt['upgrade_step_progress'], '</span>
3470 3650
 					</div>
3471 3651
 				</div>';
3652
+	}
3472 3653
 
3473 3654
 	echo '
3474 3655
 				<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>
@@ -3499,32 +3680,36 @@  discard block
 block discarded – undo
3499 3680
 {
3500 3681
 	global $upcontext, $txt;
3501 3682
 
3502
-	if (!empty($upcontext['pause']))
3503
-		echo '
3683
+	if (!empty($upcontext['pause'])) {
3684
+			echo '
3504 3685
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3505 3686
 
3506 3687
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3507 3688
 								<h3>
3508 3689
 									', $txt['upgrade_paused_overload'], '
3509 3690
 								</h3>';
3691
+	}
3510 3692
 
3511
-	if (!empty($upcontext['custom_warning']))
3512
-		echo '
3693
+	if (!empty($upcontext['custom_warning'])) {
3694
+			echo '
3513 3695
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3514 3696
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3515 3697
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3516 3698
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3517 3699
 								</div>';
3700
+	}
3518 3701
 
3519 3702
 	echo '
3520 3703
 								<div class="righttext" style="margin: 1ex;">';
3521 3704
 
3522
-	if (!empty($upcontext['continue']))
3523
-		echo '
3705
+	if (!empty($upcontext['continue'])) {
3706
+			echo '
3524 3707
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">';
3525
-	if (!empty($upcontext['skip']))
3526
-		echo '
3708
+	}
3709
+	if (!empty($upcontext['skip'])) {
3710
+			echo '
3527 3711
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">';
3712
+	}
3528 3713
 
3529 3714
 	echo '
3530 3715
 								</div>
@@ -3574,11 +3759,12 @@  discard block
 block discarded – undo
3574 3759
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3575 3760
 	<smf>';
3576 3761
 
3577
-	if (!empty($upcontext['get_data']))
3578
-		foreach ($upcontext['get_data'] as $k => $v)
3762
+	if (!empty($upcontext['get_data'])) {
3763
+			foreach ($upcontext['get_data'] as $k => $v)
3579 3764
 			echo '
3580 3765
 		<get key="', $k, '">', $v, '</get>';
3581
-}
3766
+	}
3767
+	}
3582 3768
 
3583 3769
 function template_xml_below()
3584 3770
 {
@@ -3619,8 +3805,8 @@  discard block
 block discarded – undo
3619 3805
 	template_chmod();
3620 3806
 
3621 3807
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3622
-	if ($upcontext['is_large_forum'])
3623
-		echo '
3808
+	if ($upcontext['is_large_forum']) {
3809
+			echo '
3624 3810
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3625 3811
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3626 3812
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3628,10 +3814,11 @@  discard block
 block discarded – undo
3628 3814
 				', $txt['upgrade_warning_lots_data'], '
3629 3815
 			</div>
3630 3816
 		</div>';
3817
+	}
3631 3818
 
3632 3819
 	// A warning message?
3633
-	if (!empty($upcontext['warning']))
3634
-		echo '
3820
+	if (!empty($upcontext['warning'])) {
3821
+			echo '
3635 3822
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3636 3823
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3637 3824
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3639,6 +3826,7 @@  discard block
 block discarded – undo
3639 3826
 				', $upcontext['warning'], '
3640 3827
 			</div>
3641 3828
 		</div>';
3829
+	}
3642 3830
 
3643 3831
 	// Paths are incorrect?
3644 3832
 	echo '
@@ -3654,20 +3842,22 @@  discard block
 block discarded – undo
3654 3842
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3655 3843
 	{
3656 3844
 		$ago = time() - $upcontext['started'];
3657
-		if ($ago < 60)
3658
-			$ago = $ago . ' seconds';
3659
-		elseif ($ago < 3600)
3660
-			$ago = (int) ($ago / 60) . ' minutes';
3661
-		else
3662
-			$ago = (int) ($ago / 3600) . ' hours';
3845
+		if ($ago < 60) {
3846
+					$ago = $ago . ' seconds';
3847
+		} elseif ($ago < 3600) {
3848
+					$ago = (int) ($ago / 60) . ' minutes';
3849
+		} else {
3850
+					$ago = (int) ($ago / 3600) . ' hours';
3851
+		}
3663 3852
 
3664 3853
 		$active = time() - $upcontext['updated'];
3665
-		if ($active < 60)
3666
-			$updated = $active . ' seconds';
3667
-		elseif ($active < 3600)
3668
-			$updated = (int) ($active / 60) . ' minutes';
3669
-		else
3670
-			$updated = (int) ($active / 3600) . ' hours';
3854
+		if ($active < 60) {
3855
+					$updated = $active . ' seconds';
3856
+		} elseif ($active < 3600) {
3857
+					$updated = (int) ($active / 60) . ' minutes';
3858
+		} else {
3859
+					$updated = (int) ($active / 3600) . ' hours';
3860
+		}
3671 3861
 
3672 3862
 		echo '
3673 3863
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3676,16 +3866,18 @@  discard block
 block discarded – undo
3676 3866
 			<div style="padding-left: 6ex;">
3677 3867
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3678 3868
 
3679
-		if ($active < 600)
3680
-			echo '
3869
+		if ($active < 600) {
3870
+					echo '
3681 3871
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3872
+		}
3682 3873
 
3683
-		if ($active > $upcontext['inactive_timeout'])
3684
-			echo '
3874
+		if ($active > $upcontext['inactive_timeout']) {
3875
+					echo '
3685 3876
 				<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.';
3686
-		else
3687
-			echo '
3877
+		} else {
3878
+					echo '
3688 3879
 				<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!');
3880
+		}
3689 3881
 
3690 3882
 		echo '
3691 3883
 			</div>
@@ -3701,9 +3893,10 @@  discard block
 block discarded – undo
3701 3893
 					<td>
3702 3894
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>';
3703 3895
 
3704
-	if (!empty($upcontext['username_incorrect']))
3705
-		echo '
3896
+	if (!empty($upcontext['username_incorrect'])) {
3897
+			echo '
3706 3898
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3899
+	}
3707 3900
 
3708 3901
 	echo '
3709 3902
 					</td>
@@ -3714,9 +3907,10 @@  discard block
 block discarded – undo
3714 3907
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '>
3715 3908
 						<input type="hidden" name="hash_passwrd" value="">';
3716 3909
 
3717
-	if (!empty($upcontext['password_failed']))
3718
-		echo '
3910
+	if (!empty($upcontext['password_failed'])) {
3911
+			echo '
3719 3912
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3913
+	}
3720 3914
 
3721 3915
 	echo '
3722 3916
 					</td>
@@ -3787,8 +3981,8 @@  discard block
 block discarded – undo
3787 3981
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3788 3982
 
3789 3983
 	// Warning message?
3790
-	if (!empty($upcontext['upgrade_options_warning']))
3791
-		echo '
3984
+	if (!empty($upcontext['upgrade_options_warning'])) {
3985
+			echo '
3792 3986
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3793 3987
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3794 3988
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3796,6 +3990,7 @@  discard block
 block discarded – undo
3796 3990
 				', $upcontext['upgrade_options_warning'], '
3797 3991
 			</div>
3798 3992
 		</div>';
3993
+	}
3799 3994
 
3800 3995
 	echo '
3801 3996
 				<table>
@@ -3838,8 +4033,8 @@  discard block
 block discarded – undo
3838 4033
 						</td>
3839 4034
 					</tr>';
3840 4035
 
3841
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3842
-		echo '
4036
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4037
+			echo '
3843 4038
 					<tr valign="top">
3844 4039
 						<td width="2%">
3845 4040
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1">
@@ -3848,6 +4043,7 @@  discard block
 block discarded – undo
3848 4043
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3849 4044
 						</td>
3850 4045
 					</tr>';
4046
+	}
3851 4047
 
3852 4048
 	echo '
3853 4049
 					<tr valign="top">
@@ -3885,10 +4081,11 @@  discard block
 block discarded – undo
3885 4081
 			</div>';
3886 4082
 
3887 4083
 	// Dont any tables so far?
3888
-	if (!empty($upcontext['previous_tables']))
3889
-		foreach ($upcontext['previous_tables'] as $table)
4084
+	if (!empty($upcontext['previous_tables'])) {
4085
+			foreach ($upcontext['previous_tables'] as $table)
3890 4086
 			echo '
3891 4087
 			<br>Completed Table: &quot;', $table, '&quot;.';
4088
+	}
3892 4089
 
3893 4090
 	echo '
3894 4091
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3925,12 +4122,13 @@  discard block
 block discarded – undo
3925 4122
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3926 4123
 
3927 4124
 		// If debug flood the screen.
3928
-		if ($is_debug)
3929
-			echo '
4125
+		if ($is_debug) {
4126
+					echo '
3930 4127
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3931 4128
 
3932 4129
 				if (document.getElementById(\'debug_section\').scrollHeight)
3933 4130
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4131
+		}
3934 4132
 
3935 4133
 		echo '
3936 4134
 				// Get the next update...
@@ -3963,8 +4161,9 @@  discard block
 block discarded – undo
3963 4161
 {
3964 4162
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3965 4163
 
3966
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3967
-		$is_debug = true;
4164
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4165
+			$is_debug = true;
4166
+	}
3968 4167
 
3969 4168
 	echo '
3970 4169
 		<h3>Executing database changes</h3>
@@ -3979,8 +4178,9 @@  discard block
 block discarded – undo
3979 4178
 	{
3980 4179
 		foreach ($upcontext['actioned_items'] as $num => $item)
3981 4180
 		{
3982
-			if ($num != 0)
3983
-				echo ' Successful!';
4181
+			if ($num != 0) {
4182
+							echo ' Successful!';
4183
+			}
3984 4184
 			echo '<br>' . $item;
3985 4185
 		}
3986 4186
 		if (!empty($upcontext['changes_complete']))
@@ -3993,28 +4193,32 @@  discard block
 block discarded – undo
3993 4193
 				$seconds = intval($active % 60);
3994 4194
 
3995 4195
 				$totalTime = '';
3996
-				if ($hours > 0)
3997
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3998
-				if ($minutes > 0)
3999
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4000
-				if ($seconds > 0)
4001
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4196
+				if ($hours > 0) {
4197
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4198
+				}
4199
+				if ($minutes > 0) {
4200
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4201
+				}
4202
+				if ($seconds > 0) {
4203
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4204
+				}
4002 4205
 			}
4003 4206
 
4004
-			if ($is_debug && !empty($totalTime))
4005
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
4006
-			else
4007
-				echo ' Successful!<br><br>';
4207
+			if ($is_debug && !empty($totalTime)) {
4208
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4209
+			} else {
4210
+							echo ' Successful!<br><br>';
4211
+			}
4008 4212
 
4009 4213
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
4010 4214
 		}
4011
-	}
4012
-	else
4215
+	} else
4013 4216
 	{
4014 4217
 		// Tell them how many files we have in total.
4015
-		if ($upcontext['file_count'] > 1)
4016
-			echo '
4218
+		if ($upcontext['file_count'] > 1) {
4219
+					echo '
4017 4220
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4221
+		}
4018 4222
 
4019 4223
 		echo '
4020 4224
 		<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>
@@ -4030,19 +4234,23 @@  discard block
 block discarded – undo
4030 4234
 				$seconds = intval($active % 60);
4031 4235
 
4032 4236
 				$totalTime = '';
4033
-				if ($hours > 0)
4034
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4035
-				if ($minutes > 0)
4036
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4037
-				if ($seconds > 0)
4038
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4237
+				if ($hours > 0) {
4238
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4239
+				}
4240
+				if ($minutes > 0) {
4241
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4242
+				}
4243
+				if ($seconds > 0) {
4244
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4245
+				}
4039 4246
 			}
4040 4247
 
4041 4248
 			echo '
4042 4249
 			<br><span id="upgradeCompleted">';
4043 4250
 
4044
-			if (!empty($totalTime))
4045
-				echo 'Completed in ', $totalTime, '<br>';
4251
+			if (!empty($totalTime)) {
4252
+							echo 'Completed in ', $totalTime, '<br>';
4253
+			}
4046 4254
 
4047 4255
 			echo '</span>
4048 4256
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -4079,9 +4287,10 @@  discard block
 block discarded – undo
4079 4287
 			var getData = "";
4080 4288
 			var debugItems = ', $upcontext['debug_items'], ';';
4081 4289
 
4082
-		if ($is_debug)
4083
-			echo '
4290
+		if ($is_debug) {
4291
+					echo '
4084 4292
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4293
+		}
4085 4294
 
4086 4295
 		echo '
4087 4296
 			function getNextItem()
@@ -4121,9 +4330,10 @@  discard block
 block discarded – undo
4121 4330
 						document.getElementById("error_block").style.display = "";
4122 4331
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4123 4332
 
4124
-	if ($is_debug)
4125
-		echo '
4333
+	if ($is_debug) {
4334
+			echo '
4126 4335
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4336
+	}
4127 4337
 
4128 4338
 	echo '
4129 4339
 					}
@@ -4144,9 +4354,10 @@  discard block
 block discarded – undo
4144 4354
 						document.getElementById("error_block").style.display = "";
4145 4355
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4146 4356
 
4147
-	if ($is_debug)
4148
-		echo '
4357
+	if ($is_debug) {
4358
+			echo '
4149 4359
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4360
+	}
4150 4361
 
4151 4362
 	echo '
4152 4363
 					}
@@ -4205,8 +4416,8 @@  discard block
 block discarded – undo
4205 4416
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4206 4417
 				{';
4207 4418
 
4208
-		if ($is_debug)
4209
-			echo '
4419
+		if ($is_debug) {
4420
+					echo '
4210 4421
 					document.getElementById(\'debug_section\').style.display = "none";
4211 4422
 
4212 4423
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4224,6 +4435,7 @@  discard block
 block discarded – undo
4224 4435
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4225 4436
 
4226 4437
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4438
+		}
4227 4439
 
4228 4440
 		echo '
4229 4441
 
@@ -4231,9 +4443,10 @@  discard block
 block discarded – undo
4231 4443
 					document.getElementById(\'contbutt\').disabled = 0;
4232 4444
 					document.getElementById(\'database_done\').value = 1;';
4233 4445
 
4234
-		if ($upcontext['file_count'] > 1)
4235
-			echo '
4446
+		if ($upcontext['file_count'] > 1) {
4447
+					echo '
4236 4448
 					document.getElementById(\'info1\').style.display = "none";';
4449
+		}
4237 4450
 
4238 4451
 		echo '
4239 4452
 					document.getElementById(\'info2\').style.display = "none";
@@ -4246,9 +4459,10 @@  discard block
 block discarded – undo
4246 4459
 					lastItem = 0;
4247 4460
 					prevFile = curFile;';
4248 4461
 
4249
-		if ($is_debug)
4250
-			echo '
4462
+		if ($is_debug) {
4463
+					echo '
4251 4464
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4465
+		}
4252 4466
 
4253 4467
 		echo '
4254 4468
 					getNextItem();
@@ -4256,8 +4470,8 @@  discard block
 block discarded – undo
4256 4470
 				}';
4257 4471
 
4258 4472
 		// If debug scroll the screen.
4259
-		if ($is_debug)
4260
-			echo '
4473
+		if ($is_debug) {
4474
+					echo '
4261 4475
 				if (iLastSubStepProgress == -1)
4262 4476
 				{
4263 4477
 					// Give it consistent dots.
@@ -4276,6 +4490,7 @@  discard block
 block discarded – undo
4276 4490
 
4277 4491
 				if (document.getElementById(\'debug_section\').scrollHeight)
4278 4492
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4493
+		}
4279 4494
 
4280 4495
 		echo '
4281 4496
 				// Update the page.
@@ -4336,9 +4551,10 @@  discard block
 block discarded – undo
4336 4551
 			}';
4337 4552
 
4338 4553
 		// Start things off assuming we've not errored.
4339
-		if (empty($upcontext['error_message']))
4340
-			echo '
4554
+		if (empty($upcontext['error_message'])) {
4555
+					echo '
4341 4556
 			getNextItem();';
4557
+		}
4342 4558
 
4343 4559
 		echo '
4344 4560
 		//# sourceURL=dynamicScript-dbch.js
@@ -4356,18 +4572,21 @@  discard block
 block discarded – undo
4356 4572
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4357 4573
 	<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>';
4358 4574
 
4359
-	if (!empty($upcontext['error_message']))
4360
-		echo '
4575
+	if (!empty($upcontext['error_message'])) {
4576
+			echo '
4361 4577
 	<error>', $upcontext['error_message'], '</error>';
4578
+	}
4362 4579
 
4363
-	if (!empty($upcontext['error_string']))
4364
-		echo '
4580
+	if (!empty($upcontext['error_string'])) {
4581
+			echo '
4365 4582
 	<sql>', $upcontext['error_string'], '</sql>';
4583
+	}
4366 4584
 
4367
-	if ($is_debug)
4368
-		echo '
4585
+	if ($is_debug) {
4586
+			echo '
4369 4587
 	<curtime>', time(), '</curtime>';
4370
-}
4588
+	}
4589
+	}
4371 4590
 
4372 4591
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4373 4592
 function template_convert_utf8()
@@ -4386,18 +4605,20 @@  discard block
 block discarded – undo
4386 4605
 			</div>';
4387 4606
 
4388 4607
 	// Done any tables so far?
4389
-	if (!empty($upcontext['previous_tables']))
4390
-		foreach ($upcontext['previous_tables'] as $table)
4608
+	if (!empty($upcontext['previous_tables'])) {
4609
+			foreach ($upcontext['previous_tables'] as $table)
4391 4610
 			echo '
4392 4611
 			<br>Completed Table: &quot;', $table, '&quot;.';
4612
+	}
4393 4613
 
4394 4614
 	echo '
4395 4615
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4396 4616
 
4397 4617
 	// If we dropped their index, let's let them know
4398
-	if ($upcontext['dropping_index'])
4399
-		echo '
4618
+	if ($upcontext['dropping_index']) {
4619
+			echo '
4400 4620
 				<br><span id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated in the admin area after the upgrade is complete.</span>';
4621
+	}
4401 4622
 
4402 4623
 	// Completion notification
4403 4624
 	echo '
@@ -4434,12 +4655,13 @@  discard block
 block discarded – undo
4434 4655
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4435 4656
 
4436 4657
 		// If debug flood the screen.
4437
-		if ($is_debug)
4438
-			echo '
4658
+		if ($is_debug) {
4659
+					echo '
4439 4660
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4440 4661
 
4441 4662
 				if (document.getElementById(\'debug_section\').scrollHeight)
4442 4663
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4664
+		}
4443 4665
 
4444 4666
 		echo '
4445 4667
 				// Get the next update...
@@ -4487,19 +4709,21 @@  discard block
 block discarded – undo
4487 4709
 			</div>';
4488 4710
 
4489 4711
 	// Dont any tables so far?
4490
-	if (!empty($upcontext['previous_tables']))
4491
-		foreach ($upcontext['previous_tables'] as $table)
4712
+	if (!empty($upcontext['previous_tables'])) {
4713
+			foreach ($upcontext['previous_tables'] as $table)
4492 4714
 			echo '
4493 4715
 			<br>Completed Table: &quot;', $table, '&quot;.';
4716
+	}
4494 4717
 
4495 4718
 	echo '
4496 4719
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4497 4720
 			<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>';
4498 4721
 
4499 4722
 	// Try to make sure substep was reset.
4500
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4501
-		echo '
4723
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4724
+			echo '
4502 4725
 			<input type="hidden" name="substep" id="substep" value="0">';
4726
+	}
4503 4727
 
4504 4728
 	// Continue please!
4505 4729
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4532,12 +4756,13 @@  discard block
 block discarded – undo
4532 4756
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4533 4757
 
4534 4758
 		// If debug flood the screen.
4535
-		if ($is_debug)
4536
-			echo '
4759
+		if ($is_debug) {
4760
+					echo '
4537 4761
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4538 4762
 
4539 4763
 				if (document.getElementById(\'debug_section\').scrollHeight)
4540 4764
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4765
+		}
4541 4766
 
4542 4767
 		echo '
4543 4768
 				// Get the next update...
@@ -4573,8 +4798,8 @@  discard block
 block discarded – undo
4573 4798
 	<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>
4574 4799
 	<form action="', $boardurl, '/index.php">';
4575 4800
 
4576
-	if (!empty($upcontext['can_delete_script']))
4577
-		echo '
4801
+	if (!empty($upcontext['can_delete_script'])) {
4802
+			echo '
4578 4803
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em>
4579 4804
 			<script>
4580 4805
 				function doTheDelete(theCheck)
@@ -4586,6 +4811,7 @@  discard block
 block discarded – undo
4586 4811
 				}
4587 4812
 			</script>
4588 4813
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4814
+	}
4589 4815
 
4590 4816
 	$active = time() - $upcontext['started'];
4591 4817
 	$hours = floor($active / 3600);
@@ -4595,16 +4821,20 @@  discard block
 block discarded – undo
4595 4821
 	if ($is_debug)
4596 4822
 	{
4597 4823
 		$totalTime = '';
4598
-		if ($hours > 0)
4599
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4600
-		if ($minutes > 0)
4601
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4602
-		if ($seconds > 0)
4603
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4824
+		if ($hours > 0) {
4825
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4826
+		}
4827
+		if ($minutes > 0) {
4828
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4829
+		}
4830
+		if ($seconds > 0) {
4831
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4832
+		}
4604 4833
 	}
4605 4834
 
4606
-	if ($is_debug && !empty($totalTime))
4607
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4835
+	if ($is_debug && !empty($totalTime)) {
4836
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4837
+	}
4608 4838
 
4609 4839
 	echo '<br>
4610 4840
 			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>
@@ -4631,8 +4861,9 @@  discard block
 block discarded – undo
4631 4861
 
4632 4862
 	$current_substep = $_GET['substep'];
4633 4863
 
4634
-	if (empty($_GET['a']))
4635
-		$_GET['a'] = 0;
4864
+	if (empty($_GET['a'])) {
4865
+			$_GET['a'] = 0;
4866
+	}
4636 4867
 	$step_progress['name'] = 'Converting ips';
4637 4868
 	$step_progress['current'] = $_GET['a'];
4638 4869
 
@@ -4675,16 +4906,19 @@  discard block
 block discarded – undo
4675 4906
 				'empty' => '',
4676 4907
 				'limit' => $limit,
4677 4908
 		));
4678
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4679
-			$arIp[] = $row[$oldCol];
4909
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4910
+					$arIp[] = $row[$oldCol];
4911
+		}
4680 4912
 		$smcFunc['db_free_result']($request);
4681 4913
 
4682 4914
 		// Special case, null ip could keep us in a loop.
4683
-		if (is_null($arIp[0]))
4684
-			unset($arIp[0]);
4915
+		if (is_null($arIp[0])) {
4916
+					unset($arIp[0]);
4917
+		}
4685 4918
 
4686
-		if (empty($arIp))
4687
-			$is_done = true;
4919
+		if (empty($arIp)) {
4920
+					$is_done = true;
4921
+		}
4688 4922
 
4689 4923
 		$updates = array();
4690 4924
 		$cases = array();
@@ -4693,16 +4927,18 @@  discard block
 block discarded – undo
4693 4927
 		{
4694 4928
 			$arIp[$i] = trim($arIp[$i]);
4695 4929
 
4696
-			if (empty($arIp[$i]))
4697
-				continue;
4930
+			if (empty($arIp[$i])) {
4931
+							continue;
4932
+			}
4698 4933
 
4699 4934
 			$updates['ip' . $i] = $arIp[$i];
4700 4935
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4701 4936
 
4702 4937
 			if ($setSize > 0 && $i % $setSize === 0)
4703 4938
 			{
4704
-				if (count($updates) == 1)
4705
-					continue;
4939
+				if (count($updates) == 1) {
4940
+									continue;
4941
+				}
4706 4942
 
4707 4943
 				$updates['whereSet'] = array_values($updates);
4708 4944
 				$smcFunc['db_query']('', '
@@ -4736,8 +4972,7 @@  discard block
 block discarded – undo
4736 4972
 							'ip' => $ip
4737 4973
 					));
4738 4974
 				}
4739
-			}
4740
-			else
4975
+			} else
4741 4976
 			{
4742 4977
 				$updates['whereSet'] = array_values($updates);
4743 4978
 				$smcFunc['db_query']('', '
@@ -4751,9 +4986,9 @@  discard block
 block discarded – undo
4751 4986
 					$updates
4752 4987
 				);
4753 4988
 			}
4989
+		} else {
4990
+					$is_done = true;
4754 4991
 		}
4755
-		else
4756
-			$is_done = true;
4757 4992
 
4758 4993
 		$_GET['a'] += $limit;
4759 4994
 		$step_progress['current'] = $_GET['a'];
@@ -4779,10 +5014,11 @@  discard block
 block discarded – undo
4779 5014
 
4780 5015
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4781 5016
 
4782
-	if (isset($columns[$column]))
4783
-		return $columns[$column];
4784
-	else
4785
-		return null;
4786
-}
5017
+	if (isset($columns[$column])) {
5018
+			return $columns[$column];
5019
+	} else {
5020
+			return null;
5021
+	}
5022
+	}
4787 5023
 
4788 5024
 ?>
4789 5025
\ No newline at end of file
Please login to merge, or discard this patch.