Completed
Pull Request — release-2.1 (#3761)
by Rick
06:56
created
other/upgrade.php 3 patches
Doc Comments   +22 added lines, -1 removed lines patch added patch discarded remove patch
@@ -187,6 +187,9 @@  discard block
 block discarded – undo
187 187
 // MD5 Encryption.
188 188
 if (!function_exists('md5_hmac'))
189 189
 {
190
+	/**
191
+	 * @param string $key
192
+	 */
190 193
 	function md5_hmac($data, $key)
191 194
 	{
192 195
 		if (strlen($key) > 64)
@@ -421,6 +424,9 @@  discard block
 block discarded – undo
421 424
 }
422 425
 
423 426
 // Used to direct the user to another location.
427
+/**
428
+ * @param string $location
429
+ */
424 430
 function redirectLocation($location, $addForm = true)
425 431
 {
426 432
 	global $upgradeurl, $upcontext, $command_line;
@@ -1787,6 +1793,9 @@  discard block
 block discarded – undo
1787 1793
 	return addslashes(preg_replace(array('~^\.([/\\\]|$)~', '~[/]+~', '~[\\\]+~', '~[/\\\]$~'), array($install_path . '$1', '/', '\\', ''), $path));
1788 1794
 }
1789 1795
 
1796
+/**
1797
+ * @param string $filename
1798
+ */
1790 1799
 function parse_sql($filename)
1791 1800
 {
1792 1801
 	global $db_prefix, $db_collation, $boarddir, $boardurl, $command_line, $file_steps, $step_progress, $custom_warning;
@@ -2073,6 +2082,9 @@  discard block
 block discarded – undo
2073 2082
 	return true;
2074 2083
 }
2075 2084
 
2085
+/**
2086
+ * @param string $string
2087
+ */
2076 2088
 function upgrade_query($string, $unbuffered = false)
2077 2089
 {
2078 2090
 	global $db_connection, $db_server, $db_user, $db_passwd, $db_type, $command_line, $upcontext, $upgradeurl, $modSettings;
@@ -2676,6 +2688,9 @@  discard block
 block discarded – undo
2676 2688
 	$upcontext['current_step'] = 1;
2677 2689
 }
2678 2690
 
2691
+/**
2692
+ * @param string $message
2693
+ */
2679 2694
 function print_error($message, $fatal = false)
2680 2695
 {
2681 2696
 	static $fp = null;
@@ -2689,6 +2704,9 @@  discard block
 block discarded – undo
2689 2704
 		exit;
2690 2705
 }
2691 2706
 
2707
+/**
2708
+ * @param string $message
2709
+ */
2692 2710
 function throw_error($message)
2693 2711
 {
2694 2712
 	global $upcontext;
@@ -2700,6 +2718,9 @@  discard block
 block discarded – undo
2700 2718
 }
2701 2719
 
2702 2720
 // Check files are writable - make them writable if necessary...
2721
+/**
2722
+ * @param string[] $files
2723
+ */
2703 2724
 function makeFilesWritable(&$files)
2704 2725
 {
2705 2726
 	global $upcontext, $boarddir;
@@ -5024,7 +5045,7 @@  discard block
 block discarded – undo
5024 5045
  * @param int $setSize The amount of entries after which to update the database.
5025 5046
  *
5026 5047
  * newCol needs to be a varbinary(16) null able field
5027
- * @return bool
5048
+ * @return boolean|null
5028 5049
  */
5029 5050
 function MySQLConvertOldIp($targetTable, $oldCol, $newCol, $limit = 50000, $setSize = 100)
5030 5051
 {
Please login to merge, or discard this patch.
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -3122,94 +3122,94 @@
 block discarded – undo
3122 3122
 		// Translation table for the character sets not native for MySQL.
3123 3123
 		$translation_tables = array(
3124 3124
 			'windows-1255' => array(
3125
-				'0x81' => '\'\'',		'0x8A' => '\'\'',		'0x8C' => '\'\'',
3126
-				'0x8D' => '\'\'',		'0x8E' => '\'\'',		'0x8F' => '\'\'',
3127
-				'0x90' => '\'\'',		'0x9A' => '\'\'',		'0x9C' => '\'\'',
3128
-				'0x9D' => '\'\'',		'0x9E' => '\'\'',		'0x9F' => '\'\'',
3129
-				'0xCA' => '\'\'',		'0xD9' => '\'\'',		'0xDA' => '\'\'',
3130
-				'0xDB' => '\'\'',		'0xDC' => '\'\'',		'0xDD' => '\'\'',
3131
-				'0xDE' => '\'\'',		'0xDF' => '\'\'',		'0xFB' => '0xD792',
3132
-				'0xFC' => '0xE282AC',		'0xFF' => '0xD6B2',		'0xC2' => '0xFF',
3133
-				'0x80' => '0xFC',		'0xE2' => '0xFB',		'0xA0' => '0xC2A0',
3134
-				'0xA1' => '0xC2A1',		'0xA2' => '0xC2A2',		'0xA3' => '0xC2A3',
3135
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
3136
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
3137
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
3138
-				'0xAF' => '0xC2AF',		'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',
3139
-				'0xB2' => '0xC2B2',		'0xB3' => '0xC2B3',		'0xB4' => '0xC2B4',
3140
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
3141
-				'0xB8' => '0xC2B8',		'0xB9' => '0xC2B9',		'0xBB' => '0xC2BB',
3142
-				'0xBC' => '0xC2BC',		'0xBD' => '0xC2BD',		'0xBE' => '0xC2BE',
3143
-				'0xBF' => '0xC2BF',		'0xD7' => '0xD7B3',		'0xD1' => '0xD781',
3144
-				'0xD4' => '0xD7B0',		'0xD5' => '0xD7B1',		'0xD6' => '0xD7B2',
3145
-				'0xE0' => '0xD790',		'0xEA' => '0xD79A',		'0xEC' => '0xD79C',
3146
-				'0xED' => '0xD79D',		'0xEE' => '0xD79E',		'0xEF' => '0xD79F',
3147
-				'0xF0' => '0xD7A0',		'0xF1' => '0xD7A1',		'0xF2' => '0xD7A2',
3148
-				'0xF3' => '0xD7A3',		'0xF5' => '0xD7A5',		'0xF6' => '0xD7A6',
3149
-				'0xF7' => '0xD7A7',		'0xF8' => '0xD7A8',		'0xF9' => '0xD7A9',
3150
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
3151
-				'0x86' => '0xE280A0',	'0x87' => '0xE280A1',	'0x89' => '0xE280B0',
3152
-				'0x8B' => '0xE280B9',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
3153
-				'0x95' => '0xE280A2',	'0x97' => '0xE28094',	'0x99' => '0xE284A2',
3154
-				'0xC0' => '0xD6B0',		'0xC1' => '0xD6B1',		'0xC3' => '0xD6B3',
3155
-				'0xC4' => '0xD6B4',		'0xC5' => '0xD6B5',		'0xC6' => '0xD6B6',
3156
-				'0xC7' => '0xD6B7',		'0xC8' => '0xD6B8',		'0xC9' => '0xD6B9',
3157
-				'0xCB' => '0xD6BB',		'0xCC' => '0xD6BC',		'0xCD' => '0xD6BD',
3158
-				'0xCE' => '0xD6BE',		'0xCF' => '0xD6BF',		'0xD0' => '0xD780',
3159
-				'0xD2' => '0xD782',		'0xE3' => '0xD793',		'0xE4' => '0xD794',
3160
-				'0xE5' => '0xD795',		'0xE7' => '0xD797',		'0xE9' => '0xD799',
3161
-				'0xFD' => '0xE2808E',	'0xFE' => '0xE2808F',	'0x92' => '0xE28099',
3162
-				'0x83' => '0xC692',		'0xD3' => '0xD783',		'0x88' => '0xCB86',
3163
-				'0x98' => '0xCB9C',		'0x91' => '0xE28098',	'0x96' => '0xE28093',
3164
-				'0xBA' => '0xC3B7',		'0x9B' => '0xE280BA',	'0xAA' => '0xC397',
3165
-				'0xA4' => '0xE282AA',	'0xE1' => '0xD791',		'0xE6' => '0xD796',
3166
-				'0xE8' => '0xD798',		'0xEB' => '0xD79B',		'0xF4' => '0xD7A4',
3125
+				'0x81' => '\'\'', '0x8A' => '\'\'', '0x8C' => '\'\'',
3126
+				'0x8D' => '\'\'', '0x8E' => '\'\'', '0x8F' => '\'\'',
3127
+				'0x90' => '\'\'', '0x9A' => '\'\'', '0x9C' => '\'\'',
3128
+				'0x9D' => '\'\'', '0x9E' => '\'\'', '0x9F' => '\'\'',
3129
+				'0xCA' => '\'\'', '0xD9' => '\'\'', '0xDA' => '\'\'',
3130
+				'0xDB' => '\'\'', '0xDC' => '\'\'', '0xDD' => '\'\'',
3131
+				'0xDE' => '\'\'', '0xDF' => '\'\'', '0xFB' => '0xD792',
3132
+				'0xFC' => '0xE282AC', '0xFF' => '0xD6B2', '0xC2' => '0xFF',
3133
+				'0x80' => '0xFC', '0xE2' => '0xFB', '0xA0' => '0xC2A0',
3134
+				'0xA1' => '0xC2A1', '0xA2' => '0xC2A2', '0xA3' => '0xC2A3',
3135
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
3136
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
3137
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
3138
+				'0xAF' => '0xC2AF', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1',
3139
+				'0xB2' => '0xC2B2', '0xB3' => '0xC2B3', '0xB4' => '0xC2B4',
3140
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
3141
+				'0xB8' => '0xC2B8', '0xB9' => '0xC2B9', '0xBB' => '0xC2BB',
3142
+				'0xBC' => '0xC2BC', '0xBD' => '0xC2BD', '0xBE' => '0xC2BE',
3143
+				'0xBF' => '0xC2BF', '0xD7' => '0xD7B3', '0xD1' => '0xD781',
3144
+				'0xD4' => '0xD7B0', '0xD5' => '0xD7B1', '0xD6' => '0xD7B2',
3145
+				'0xE0' => '0xD790', '0xEA' => '0xD79A', '0xEC' => '0xD79C',
3146
+				'0xED' => '0xD79D', '0xEE' => '0xD79E', '0xEF' => '0xD79F',
3147
+				'0xF0' => '0xD7A0', '0xF1' => '0xD7A1', '0xF2' => '0xD7A2',
3148
+				'0xF3' => '0xD7A3', '0xF5' => '0xD7A5', '0xF6' => '0xD7A6',
3149
+				'0xF7' => '0xD7A7', '0xF8' => '0xD7A8', '0xF9' => '0xD7A9',
3150
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
3151
+				'0x86' => '0xE280A0', '0x87' => '0xE280A1', '0x89' => '0xE280B0',
3152
+				'0x8B' => '0xE280B9', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
3153
+				'0x95' => '0xE280A2', '0x97' => '0xE28094', '0x99' => '0xE284A2',
3154
+				'0xC0' => '0xD6B0', '0xC1' => '0xD6B1', '0xC3' => '0xD6B3',
3155
+				'0xC4' => '0xD6B4', '0xC5' => '0xD6B5', '0xC6' => '0xD6B6',
3156
+				'0xC7' => '0xD6B7', '0xC8' => '0xD6B8', '0xC9' => '0xD6B9',
3157
+				'0xCB' => '0xD6BB', '0xCC' => '0xD6BC', '0xCD' => '0xD6BD',
3158
+				'0xCE' => '0xD6BE', '0xCF' => '0xD6BF', '0xD0' => '0xD780',
3159
+				'0xD2' => '0xD782', '0xE3' => '0xD793', '0xE4' => '0xD794',
3160
+				'0xE5' => '0xD795', '0xE7' => '0xD797', '0xE9' => '0xD799',
3161
+				'0xFD' => '0xE2808E', '0xFE' => '0xE2808F', '0x92' => '0xE28099',
3162
+				'0x83' => '0xC692', '0xD3' => '0xD783', '0x88' => '0xCB86',
3163
+				'0x98' => '0xCB9C', '0x91' => '0xE28098', '0x96' => '0xE28093',
3164
+				'0xBA' => '0xC3B7', '0x9B' => '0xE280BA', '0xAA' => '0xC397',
3165
+				'0xA4' => '0xE282AA', '0xE1' => '0xD791', '0xE6' => '0xD796',
3166
+				'0xE8' => '0xD798', '0xEB' => '0xD79B', '0xF4' => '0xD7A4',
3167 3167
 				'0xFA' => '0xD7AA',
3168 3168
 			),
3169 3169
 			'windows-1253' => array(
3170
-				'0x81' => '\'\'',			'0x88' => '\'\'',			'0x8A' => '\'\'',
3171
-				'0x8C' => '\'\'',			'0x8D' => '\'\'',			'0x8E' => '\'\'',
3172
-				'0x8F' => '\'\'',			'0x90' => '\'\'',			'0x98' => '\'\'',
3173
-				'0x9A' => '\'\'',			'0x9C' => '\'\'',			'0x9D' => '\'\'',
3174
-				'0x9E' => '\'\'',			'0x9F' => '\'\'',			'0xAA' => '\'\'',
3175
-				'0xD2' => '0xE282AC',			'0xFF' => '0xCE92',			'0xCE' => '0xCE9E',
3176
-				'0xB8' => '0xCE88',		'0xBA' => '0xCE8A',		'0xBC' => '0xCE8C',
3177
-				'0xBE' => '0xCE8E',		'0xBF' => '0xCE8F',		'0xC0' => '0xCE90',
3178
-				'0xC8' => '0xCE98',		'0xCA' => '0xCE9A',		'0xCC' => '0xCE9C',
3179
-				'0xCD' => '0xCE9D',		'0xCF' => '0xCE9F',		'0xDA' => '0xCEAA',
3180
-				'0xE8' => '0xCEB8',		'0xEA' => '0xCEBA',		'0xEC' => '0xCEBC',
3181
-				'0xEE' => '0xCEBE',		'0xEF' => '0xCEBF',		'0xC2' => '0xFF',
3182
-				'0xBD' => '0xC2BD',		'0xED' => '0xCEBD',		'0xB2' => '0xC2B2',
3183
-				'0xA0' => '0xC2A0',		'0xA3' => '0xC2A3',		'0xA4' => '0xC2A4',
3184
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
3185
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
3186
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
3187
-				'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',		'0xB3' => '0xC2B3',
3188
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
3189
-				'0xBB' => '0xC2BB',		'0xE2' => '0xCEB2',		'0x80' => '0xD2',
3190
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
3191
-				'0x86' => '0xE280A0',	'0xA1' => '0xCE85',		'0xA2' => '0xCE86',
3192
-				'0x87' => '0xE280A1',	'0x89' => '0xE280B0',	'0xB9' => '0xCE89',
3193
-				'0x8B' => '0xE280B9',	'0x91' => '0xE28098',	'0x99' => '0xE284A2',
3194
-				'0x92' => '0xE28099',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
3195
-				'0x95' => '0xE280A2',	'0x96' => '0xE28093',	'0x97' => '0xE28094',
3196
-				'0x9B' => '0xE280BA',	'0xAF' => '0xE28095',	'0xB4' => '0xCE84',
3197
-				'0xC1' => '0xCE91',		'0xC3' => '0xCE93',		'0xC4' => '0xCE94',
3198
-				'0xC5' => '0xCE95',		'0xC6' => '0xCE96',		'0x83' => '0xC692',
3199
-				'0xC7' => '0xCE97',		'0xC9' => '0xCE99',		'0xCB' => '0xCE9B',
3200
-				'0xD0' => '0xCEA0',		'0xD1' => '0xCEA1',		'0xD3' => '0xCEA3',
3201
-				'0xD4' => '0xCEA4',		'0xD5' => '0xCEA5',		'0xD6' => '0xCEA6',
3202
-				'0xD7' => '0xCEA7',		'0xD8' => '0xCEA8',		'0xD9' => '0xCEA9',
3203
-				'0xDB' => '0xCEAB',		'0xDC' => '0xCEAC',		'0xDD' => '0xCEAD',
3204
-				'0xDE' => '0xCEAE',		'0xDF' => '0xCEAF',		'0xE0' => '0xCEB0',
3205
-				'0xE1' => '0xCEB1',		'0xE3' => '0xCEB3',		'0xE4' => '0xCEB4',
3206
-				'0xE5' => '0xCEB5',		'0xE6' => '0xCEB6',		'0xE7' => '0xCEB7',
3207
-				'0xE9' => '0xCEB9',		'0xEB' => '0xCEBB',		'0xF0' => '0xCF80',
3208
-				'0xF1' => '0xCF81',		'0xF2' => '0xCF82',		'0xF3' => '0xCF83',
3209
-				'0xF4' => '0xCF84',		'0xF5' => '0xCF85',		'0xF6' => '0xCF86',
3210
-				'0xF7' => '0xCF87',		'0xF8' => '0xCF88',		'0xF9' => '0xCF89',
3211
-				'0xFA' => '0xCF8A',		'0xFB' => '0xCF8B',		'0xFC' => '0xCF8C',
3212
-				'0xFD' => '0xCF8D',		'0xFE' => '0xCF8E',
3170
+				'0x81' => '\'\'', '0x88' => '\'\'', '0x8A' => '\'\'',
3171
+				'0x8C' => '\'\'', '0x8D' => '\'\'', '0x8E' => '\'\'',
3172
+				'0x8F' => '\'\'', '0x90' => '\'\'', '0x98' => '\'\'',
3173
+				'0x9A' => '\'\'', '0x9C' => '\'\'', '0x9D' => '\'\'',
3174
+				'0x9E' => '\'\'', '0x9F' => '\'\'', '0xAA' => '\'\'',
3175
+				'0xD2' => '0xE282AC', '0xFF' => '0xCE92', '0xCE' => '0xCE9E',
3176
+				'0xB8' => '0xCE88', '0xBA' => '0xCE8A', '0xBC' => '0xCE8C',
3177
+				'0xBE' => '0xCE8E', '0xBF' => '0xCE8F', '0xC0' => '0xCE90',
3178
+				'0xC8' => '0xCE98', '0xCA' => '0xCE9A', '0xCC' => '0xCE9C',
3179
+				'0xCD' => '0xCE9D', '0xCF' => '0xCE9F', '0xDA' => '0xCEAA',
3180
+				'0xE8' => '0xCEB8', '0xEA' => '0xCEBA', '0xEC' => '0xCEBC',
3181
+				'0xEE' => '0xCEBE', '0xEF' => '0xCEBF', '0xC2' => '0xFF',
3182
+				'0xBD' => '0xC2BD', '0xED' => '0xCEBD', '0xB2' => '0xC2B2',
3183
+				'0xA0' => '0xC2A0', '0xA3' => '0xC2A3', '0xA4' => '0xC2A4',
3184
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
3185
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
3186
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
3187
+				'0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB3' => '0xC2B3',
3188
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
3189
+				'0xBB' => '0xC2BB', '0xE2' => '0xCEB2', '0x80' => '0xD2',
3190
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
3191
+				'0x86' => '0xE280A0', '0xA1' => '0xCE85', '0xA2' => '0xCE86',
3192
+				'0x87' => '0xE280A1', '0x89' => '0xE280B0', '0xB9' => '0xCE89',
3193
+				'0x8B' => '0xE280B9', '0x91' => '0xE28098', '0x99' => '0xE284A2',
3194
+				'0x92' => '0xE28099', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
3195
+				'0x95' => '0xE280A2', '0x96' => '0xE28093', '0x97' => '0xE28094',
3196
+				'0x9B' => '0xE280BA', '0xAF' => '0xE28095', '0xB4' => '0xCE84',
3197
+				'0xC1' => '0xCE91', '0xC3' => '0xCE93', '0xC4' => '0xCE94',
3198
+				'0xC5' => '0xCE95', '0xC6' => '0xCE96', '0x83' => '0xC692',
3199
+				'0xC7' => '0xCE97', '0xC9' => '0xCE99', '0xCB' => '0xCE9B',
3200
+				'0xD0' => '0xCEA0', '0xD1' => '0xCEA1', '0xD3' => '0xCEA3',
3201
+				'0xD4' => '0xCEA4', '0xD5' => '0xCEA5', '0xD6' => '0xCEA6',
3202
+				'0xD7' => '0xCEA7', '0xD8' => '0xCEA8', '0xD9' => '0xCEA9',
3203
+				'0xDB' => '0xCEAB', '0xDC' => '0xCEAC', '0xDD' => '0xCEAD',
3204
+				'0xDE' => '0xCEAE', '0xDF' => '0xCEAF', '0xE0' => '0xCEB0',
3205
+				'0xE1' => '0xCEB1', '0xE3' => '0xCEB3', '0xE4' => '0xCEB4',
3206
+				'0xE5' => '0xCEB5', '0xE6' => '0xCEB6', '0xE7' => '0xCEB7',
3207
+				'0xE9' => '0xCEB9', '0xEB' => '0xCEBB', '0xF0' => '0xCF80',
3208
+				'0xF1' => '0xCF81', '0xF2' => '0xCF82', '0xF3' => '0xCF83',
3209
+				'0xF4' => '0xCF84', '0xF5' => '0xCF85', '0xF6' => '0xCF86',
3210
+				'0xF7' => '0xCF87', '0xF8' => '0xCF88', '0xF9' => '0xCF89',
3211
+				'0xFA' => '0xCF8A', '0xFB' => '0xCF8B', '0xFC' => '0xCF8C',
3212
+				'0xFD' => '0xCF8D', '0xFE' => '0xCF8E',
3213 3213
 			),
3214 3214
 		);
3215 3215
 
Please login to merge, or discard this patch.
Braces   +976 added lines, -715 removed lines patch added patch discarded remove patch
@@ -66,11 +66,14 @@  discard block
 block discarded – undo
66 66
 	ini_set('default_socket_timeout', 900);
67 67
 }
68 68
 // Clean the upgrade path if this is from the client.
69
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
70
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
69
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
70
+	for ($i = 1;
71
+}
72
+$i < $_SERVER['argc']; $i++)
71 73
 	{
72
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
73
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
74
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
75
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
76
+		}
74 77
 	}
75 78
 
76 79
 // Are we from the client?
@@ -78,9 +81,9 @@  discard block
 block discarded – undo
78 81
 {
79 82
 	$command_line = true;
80 83
 	$disable_security = 1;
81
-}
82
-else
84
+} else {
83 85
 	$command_line = false;
86
+}
84 87
 
85 88
 // Load this now just because we can.
86 89
 require_once($upgrade_path . '/Settings.php');
@@ -95,10 +98,12 @@  discard block
 block discarded – undo
95 98
 	$upcontext['user'] = unserialize(base64_decode($upgradeData));
96 99
 
97 100
 	// Check for sensible values.
98
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
99
-		$upcontext['user']['started'] = time();
100
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
101
-		$upcontext['user']['updated'] = 0;
101
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
102
+			$upcontext['user']['started'] = time();
103
+	}
104
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
105
+			$upcontext['user']['updated'] = 0;
106
+	}
102 107
 
103 108
 	$upcontext['started'] = $upcontext['user']['started'];
104 109
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -161,8 +166,9 @@  discard block
 block discarded – undo
161 166
 		{
162 167
 			$word = trim($word, '-_\'');
163 168
 
164
-			if ($word != '')
165
-				$returned_words[] = substr($word, 0, 20);
169
+			if ($word != '') {
170
+							$returned_words[] = substr($word, 0, 20);
171
+			}
166 172
 		}
167 173
 
168 174
 		return array_unique($returned_words);
@@ -189,8 +195,9 @@  discard block
 block discarded – undo
189 195
 {
190 196
 	function md5_hmac($data, $key)
191 197
 	{
192
-		if (strlen($key) > 64)
193
-			$key = pack('H*', md5($key));
198
+		if (strlen($key) > 64) {
199
+					$key = pack('H*', md5($key));
200
+		}
194 201
 		$key = str_pad($key, 64, chr(0x00));
195 202
 
196 203
 		$k_ipad = $key ^ str_repeat(chr(0x36), 64);
@@ -201,8 +208,9 @@  discard block
 block discarded – undo
201 208
 }
202 209
 
203 210
 // Don't do security check if on Yabbse
204
-if (!isset($modSettings['smfVersion']))
211
+if (!isset($modSettings['smfVersion'])) {
205 212
 	$disable_security = true;
213
+}
206 214
 
207 215
 // This only exists if we're on SMF ;)
208 216
 if (isset($modSettings['smfVersion']))
@@ -220,8 +228,9 @@  discard block
 block discarded – undo
220 228
 			'db_error_skip' => true,
221 229
 		)
222 230
 	);
223
-	while ($row = $smcFunc['db_fetch_assoc']($request))
224
-		$modSettings[$row['variable']] = $row['value'];
231
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
232
+			$modSettings[$row['variable']] = $row['value'];
233
+	}
225 234
 	$smcFunc['db_free_result']($request);
226 235
 }
227 236
 
@@ -231,10 +240,12 @@  discard block
 block discarded – undo
231 240
 	$modSettings['theme_url'] = 'Themes/default';
232 241
 	$modSettings['images_url'] = 'Themes/default/images';
233 242
 }
234
-if (!isset($settings['default_theme_url']))
243
+if (!isset($settings['default_theme_url'])) {
235 244
 	$settings['default_theme_url'] = $modSettings['theme_url'];
236
-if (!isset($settings['default_theme_dir']))
245
+}
246
+if (!isset($settings['default_theme_dir'])) {
237 247
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
248
+}
238 249
 
239 250
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
240 251
 // Default title...
@@ -252,13 +263,15 @@  discard block
 block discarded – undo
252 263
 	$support_js = $upcontext['upgrade_status']['js'];
253 264
 
254 265
 	// Only set this if the upgrader status says so.
255
-	if (empty($is_debug))
256
-		$is_debug = $upcontext['upgrade_status']['debug'];
266
+	if (empty($is_debug)) {
267
+			$is_debug = $upcontext['upgrade_status']['debug'];
268
+	}
257 269
 
258 270
 	// Load the language.
259
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
260
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
261
-}
271
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
272
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
273
+	}
274
+	}
262 275
 // Set the defaults.
263 276
 else
264 277
 {
@@ -276,15 +289,18 @@  discard block
 block discarded – undo
276 289
 }
277 290
 
278 291
 // If this isn't the first stage see whether they are logging in and resuming.
279
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
292
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
280 293
 	checkLogin();
294
+}
281 295
 
282
-if ($command_line)
296
+if ($command_line) {
283 297
 	cmdStep0();
298
+}
284 299
 
285 300
 // Don't error if we're using xml.
286
-if (isset($_GET['xml']))
301
+if (isset($_GET['xml'])) {
287 302
 	$upcontext['return_error'] = true;
303
+}
288 304
 
289 305
 // Loop through all the steps doing each one as required.
290 306
 $upcontext['overall_percent'] = 0;
@@ -305,10 +321,11 @@  discard block
 block discarded – undo
305 321
 		}
306 322
 
307 323
 		// Call the step and if it returns false that means pause!
308
-		if (function_exists($step[2]) && $step[2]() === false)
309
-			break;
310
-		elseif (function_exists($step[2]))
311
-			$upcontext['current_step']++;
324
+		if (function_exists($step[2]) && $step[2]() === false) {
325
+					break;
326
+		} elseif (function_exists($step[2])) {
327
+					$upcontext['current_step']++;
328
+		}
312 329
 	}
313 330
 	$upcontext['overall_percent'] += $step[3];
314 331
 }
@@ -347,17 +364,18 @@  discard block
 block discarded – undo
347 364
 		// This should not happen my dear... HELP ME DEVELOPERS!!
348 365
 		if (!empty($command_line))
349 366
 		{
350
-			if (function_exists('debug_print_backtrace'))
351
-				debug_print_backtrace();
367
+			if (function_exists('debug_print_backtrace')) {
368
+							debug_print_backtrace();
369
+			}
352 370
 
353 371
 			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.';
354 372
 			flush();
355 373
 			die();
356 374
 		}
357 375
 
358
-		if (!isset($_GET['xml']))
359
-			template_upgrade_above();
360
-		else
376
+		if (!isset($_GET['xml'])) {
377
+					template_upgrade_above();
378
+		} else
361 379
 		{
362 380
 			header('Content-Type: text/xml; charset=UTF-8');
363 381
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -379,21 +397,24 @@  discard block
 block discarded – undo
379 397
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(safe_serialize($upcontext['upgrade_status']));
380 398
 
381 399
 			// Custom stuff to pass back?
382
-			if (!empty($upcontext['query_string']))
383
-				$upcontext['form_url'] .= $upcontext['query_string'];
400
+			if (!empty($upcontext['query_string'])) {
401
+							$upcontext['form_url'] .= $upcontext['query_string'];
402
+			}
384 403
 
385 404
 			call_user_func('template_' . $upcontext['sub_template']);
386 405
 		}
387 406
 
388 407
 		// Was there an error?
389
-		if (!empty($upcontext['forced_error_message']))
390
-			echo $upcontext['forced_error_message'];
408
+		if (!empty($upcontext['forced_error_message'])) {
409
+					echo $upcontext['forced_error_message'];
410
+		}
391 411
 
392 412
 		// Show the footer.
393
-		if (!isset($_GET['xml']))
394
-			template_upgrade_below();
395
-		else
396
-			template_xml_below();
413
+		if (!isset($_GET['xml'])) {
414
+					template_upgrade_below();
415
+		} else {
416
+					template_xml_below();
417
+		}
397 418
 	}
398 419
 
399 420
 
@@ -405,15 +426,19 @@  discard block
 block discarded – undo
405 426
 		$seconds = intval($active % 60);
406 427
 
407 428
 		$totalTime = '';
408
-		if ($hours > 0)
409
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
410
-		if ($minutes > 0)
411
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
412
-		if ($seconds > 0)
413
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
429
+		if ($hours > 0) {
430
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
431
+		}
432
+		if ($minutes > 0) {
433
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
434
+		}
435
+		if ($seconds > 0) {
436
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
437
+		}
414 438
 
415
-		if (!empty($totalTime))
416
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
439
+		if (!empty($totalTime)) {
440
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
441
+		}
417 442
 	}
418 443
 
419 444
 	// Bang - gone!
@@ -426,8 +451,9 @@  discard block
 block discarded – undo
426 451
 	global $upgradeurl, $upcontext, $command_line;
427 452
 
428 453
 	// Command line users can't be redirected.
429
-	if ($command_line)
430
-		upgradeExit(true);
454
+	if ($command_line) {
455
+			upgradeExit(true);
456
+	}
431 457
 
432 458
 	// Are we providing the core info?
433 459
 	if ($addForm)
@@ -450,19 +476,22 @@  discard block
 block discarded – undo
450 476
 	global $modSettings, $sourcedir, $smcFunc;
451 477
 
452 478
 	// Do the non-SSI stuff...
453
-	if (function_exists('set_magic_quotes_runtime'))
454
-		@set_magic_quotes_runtime(0);
479
+	if (function_exists('set_magic_quotes_runtime')) {
480
+			@set_magic_quotes_runtime(0);
481
+	}
455 482
 
456 483
 	error_reporting(E_ALL);
457 484
 	define('SMF', 1);
458 485
 
459 486
 	// Start the session.
460
-	if (@ini_get('session.save_handler') == 'user')
461
-		@ini_set('session.save_handler', 'files');
487
+	if (@ini_get('session.save_handler') == 'user') {
488
+			@ini_set('session.save_handler', 'files');
489
+	}
462 490
 	@session_start();
463 491
 
464
-	if (empty($smcFunc))
465
-		$smcFunc = array();
492
+	if (empty($smcFunc)) {
493
+			$smcFunc = array();
494
+	}
466 495
 
467 496
 	// We need this for authentication and some upgrade code
468 497
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -475,8 +504,9 @@  discard block
 block discarded – undo
475 504
 	initialize_inputs();
476 505
 
477 506
 	// Get the database going!
478
-	if (empty($db_type))
479
-		$db_type = 'mysql';
507
+	if (empty($db_type)) {
508
+			$db_type = 'mysql';
509
+	}
480 510
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
481 511
 	{
482 512
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -485,17 +515,19 @@  discard block
 block discarded – undo
485 515
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
486 516
 
487 517
 		// Oh dear god!!
488
-		if ($db_connection === null)
489
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
518
+		if ($db_connection === null) {
519
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
520
+		}
490 521
 
491
-		if (($db_type == 'mysql' || $db_type == 'mysqli') && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
492
-			$smcFunc['db_query']('', '
522
+		if (($db_type == 'mysql' || $db_type == 'mysqli') && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
523
+					$smcFunc['db_query']('', '
493 524
 			SET NAMES {string:db_character_set}',
494 525
 			array(
495 526
 				'db_error_skip' => true,
496 527
 				'db_character_set' => $db_character_set,
497 528
 			)
498 529
 		);
530
+		}
499 531
 
500 532
 		// Load the modSettings data...
501 533
 		$request = $smcFunc['db_query']('', '
@@ -506,11 +538,11 @@  discard block
 block discarded – undo
506 538
 			)
507 539
 		);
508 540
 		$modSettings = array();
509
-		while ($row = $smcFunc['db_fetch_assoc']($request))
510
-			$modSettings[$row['variable']] = $row['value'];
541
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
542
+					$modSettings[$row['variable']] = $row['value'];
543
+		}
511 544
 		$smcFunc['db_free_result']($request);
512
-	}
513
-	else
545
+	} else
514 546
 	{
515 547
 		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.');
516 548
 	}
@@ -524,9 +556,10 @@  discard block
 block discarded – undo
524 556
 		cleanRequest();
525 557
 	}
526 558
 
527
-	if (!isset($_GET['substep']))
528
-		$_GET['substep'] = 0;
529
-}
559
+	if (!isset($_GET['substep'])) {
560
+			$_GET['substep'] = 0;
561
+	}
562
+	}
530 563
 
531 564
 function initialize_inputs()
532 565
 {
@@ -564,8 +597,9 @@  discard block
 block discarded – undo
564 597
 		$dh = opendir(dirname(__FILE__));
565 598
 		while ($file = readdir($dh))
566 599
 		{
567
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
568
-				@unlink(dirname(__FILE__) . '/' . $file);
600
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
601
+							@unlink(dirname(__FILE__) . '/' . $file);
602
+			}
569 603
 		}
570 604
 		closedir($dh);
571 605
 
@@ -595,8 +629,9 @@  discard block
 block discarded – undo
595 629
 	{
596 630
 		$upcontext['remote_files_available'] = false;
597 631
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
598
-		if ($test)
599
-			$upcontext['remote_files_available'] = true;
632
+		if ($test) {
633
+					$upcontext['remote_files_available'] = true;
634
+		}
600 635
 		@fclose($test);
601 636
 	}
602 637
 
@@ -604,8 +639,9 @@  discard block
 block discarded – undo
604 639
 	$temp = 'upgrade_php?step';
605 640
 	while (strlen($temp) > 4)
606 641
 	{
607
-		if (isset($_GET[$temp]))
608
-			unset($_GET[$temp]);
642
+		if (isset($_GET[$temp])) {
643
+					unset($_GET[$temp]);
644
+		}
609 645
 		$temp = substr($temp, 1);
610 646
 	}
611 647
 
@@ -631,29 +667,36 @@  discard block
 block discarded – undo
631 667
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $type . '.sql');
632 668
 
633 669
 	// Need legacy scripts?
634
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
635
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $type . '.sql');
636
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
637
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
638
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
639
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
670
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
671
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $type . '.sql');
672
+	}
673
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
674
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
675
+	}
676
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
677
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
678
+	}
640 679
 
641 680
 	// This needs to exist!
642
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
643
-		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>]');
644
-	else
645
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
681
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
682
+			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>]');
683
+	} else {
684
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
685
+	}
646 686
 
647
-	if (!$check)
648
-		// 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.
687
+	if (!$check) {
688
+			// 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.
649 689
 		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.');
690
+	}
650 691
 
651 692
 	// Do they meet the install requirements?
652
-	if (!php_version_check())
653
-		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.');
693
+	if (!php_version_check()) {
694
+			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.');
695
+	}
654 696
 
655
-	if (!db_version_check())
656
-		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.');
697
+	if (!db_version_check()) {
698
+			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.');
699
+	}
657 700
 
658 701
 	// Do some checks to make sure they have proper privileges
659 702
 	db_extend('packages');
@@ -668,14 +711,16 @@  discard block
 block discarded – undo
668 711
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
669 712
 
670 713
 	// Sorry... we need CREATE, ALTER and DROP
671
-	if (!$create || !$alter || !$drop)
672
-		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.');
714
+	if (!$create || !$alter || !$drop) {
715
+			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.');
716
+	}
673 717
 
674 718
 	// Do a quick version spot check.
675 719
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
676 720
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
677
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
678
-		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.');
721
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
722
+			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.');
723
+	}
679 724
 
680 725
 	// What absolutely needs to be writable?
681 726
 	$writable_files = array(
@@ -697,12 +742,13 @@  discard block
 block discarded – undo
697 742
 	quickFileWritable($custom_av_dir);
698 743
 
699 744
 	// Are we good now?
700
-	if (!is_writable($custom_av_dir))
701
-		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));
702
-	elseif ($need_settings_update)
745
+	if (!is_writable($custom_av_dir)) {
746
+			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));
747
+	} elseif ($need_settings_update)
703 748
 	{
704
-		if (!function_exists('cache_put_data'))
705
-			require_once($sourcedir . '/Load.php');
749
+		if (!function_exists('cache_put_data')) {
750
+					require_once($sourcedir . '/Load.php');
751
+		}
706 752
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
707 753
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
708 754
 	}
@@ -711,28 +757,33 @@  discard block
 block discarded – undo
711 757
 
712 758
 	// Check the cache directory.
713 759
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
714
-	if (!file_exists($cachedir_temp))
715
-		@mkdir($cachedir_temp);
716
-	if (!file_exists($cachedir_temp))
717
-		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.');
718
-
719
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
720
-		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>.');
721
-	elseif (!isset($_GET['skiplang']))
760
+	if (!file_exists($cachedir_temp)) {
761
+			@mkdir($cachedir_temp);
762
+	}
763
+	if (!file_exists($cachedir_temp)) {
764
+			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.');
765
+	}
766
+
767
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
768
+			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>.');
769
+	} elseif (!isset($_GET['skiplang']))
722 770
 	{
723 771
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
724 772
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
725 773
 
726
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
727
-			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>]');
774
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
775
+					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>]');
776
+		}
728 777
 	}
729 778
 
730
-	if (!makeFilesWritable($writable_files))
731
-		return false;
779
+	if (!makeFilesWritable($writable_files)) {
780
+			return false;
781
+	}
732 782
 
733 783
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
734
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
735
-		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.');
784
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
785
+			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.');
786
+	}
736 787
 
737 788
 	// Upgrade the agreement.
738 789
 	elseif (isset($modSettings['agreement']))
@@ -743,8 +794,8 @@  discard block
 block discarded – undo
743 794
 	}
744 795
 
745 796
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
746
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
747
-		$upcontext['warning'] = '
797
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
798
+			$upcontext['warning'] = '
748 799
 			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>
749 800
 			<ul>
750 801
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -752,10 +803,12 @@  discard block
 block discarded – undo
752 803
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
753 804
 			</ul>
754 805
 			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="http://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
806
+	}
755 807
 
756 808
 	// Either we're logged in or we're going to present the login.
757
-	if (checkLogin())
758
-		return true;
809
+	if (checkLogin()) {
810
+			return true;
811
+	}
759 812
 
760 813
 	$upcontext += createToken('login');
761 814
 
@@ -772,8 +825,9 @@  discard block
 block discarded – undo
772 825
 	if (isset($_POST['contbutt']) && (!empty($_POST['user']) || $disable_security))
773 826
 	{
774 827
 		// If we've disabled security pick a suitable name!
775
-		if (empty($_POST['user']))
776
-			$_POST['user'] = 'Administrator';
828
+		if (empty($_POST['user'])) {
829
+					$_POST['user'] = 'Administrator';
830
+		}
777 831
 
778 832
 		// Before 2.0 these column names were different!
779 833
 		$oldDB = false;
@@ -788,16 +842,17 @@  discard block
 block discarded – undo
788 842
 					'db_error_skip' => true,
789 843
 				)
790 844
 			);
791
-			if ($smcFunc['db_num_rows']($request) != 0)
792
-				$oldDB = true;
845
+			if ($smcFunc['db_num_rows']($request) != 0) {
846
+							$oldDB = true;
847
+			}
793 848
 			$smcFunc['db_free_result']($request);
794 849
 		}
795 850
 
796 851
 		// Get what we believe to be their details.
797 852
 		if (!$disable_security)
798 853
 		{
799
-			if ($oldDB)
800
-				$request = $smcFunc['db_query']('', '
854
+			if ($oldDB) {
855
+							$request = $smcFunc['db_query']('', '
801 856
 					SELECT id_member, memberName AS member_name, passwd, id_group,
802 857
 					additionalGroups AS additional_groups, lngfile
803 858
 					FROM {db_prefix}members
@@ -807,8 +862,8 @@  discard block
 block discarded – undo
807 862
 						'db_error_skip' => true,
808 863
 					)
809 864
 				);
810
-			else
811
-				$request = $smcFunc['db_query']('', '
865
+			} else {
866
+							$request = $smcFunc['db_query']('', '
812 867
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
813 868
 					FROM {db_prefix}members
814 869
 					WHERE member_name = {string:member_name}',
@@ -817,6 +872,7 @@  discard block
 block discarded – undo
817 872
 						'db_error_skip' => true,
818 873
 					)
819 874
 				);
875
+			}
820 876
 			if ($smcFunc['db_num_rows']($request) != 0)
821 877
 			{
822 878
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -824,13 +880,14 @@  discard block
 block discarded – undo
824 880
 				$groups = explode(',', $addGroups);
825 881
 				$groups[] = $id_group;
826 882
 
827
-				foreach ($groups as $k => $v)
828
-					$groups[$k] = (int) $v;
883
+				foreach ($groups as $k => $v) {
884
+									$groups[$k] = (int) $v;
885
+				}
829 886
 
830 887
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
888
+			} else {
889
+							$upcontext['username_incorrect'] = true;
831 890
 			}
832
-			else
833
-				$upcontext['username_incorrect'] = true;
834 891
 			$smcFunc['db_free_result']($request);
835 892
 		}
836 893
 		$upcontext['username'] = $_POST['user'];
@@ -840,13 +897,14 @@  discard block
 block discarded – undo
840 897
 		{
841 898
 			$upcontext['upgrade_status']['js'] = 1;
842 899
 			$support_js = 1;
900
+		} else {
901
+					$support_js = 0;
843 902
 		}
844
-		else
845
-			$support_js = 0;
846 903
 
847 904
 		// Note down the version we are coming from.
848
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
849
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
905
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
906
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
907
+		}
850 908
 
851 909
 		// Didn't get anywhere?
852 910
 		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 +938,15 @@  discard block
 block discarded – undo
880 938
 							'db_error_skip' => true,
881 939
 						)
882 940
 					);
883
-					if ($smcFunc['db_num_rows']($request) == 0)
884
-						return throw_error('You need to be an admin to perform an upgrade!');
941
+					if ($smcFunc['db_num_rows']($request) == 0) {
942
+											return throw_error('You need to be an admin to perform an upgrade!');
943
+					}
885 944
 					$smcFunc['db_free_result']($request);
886 945
 				}
887 946
 
888 947
 				$upcontext['user']['id'] = $id_member;
889 948
 				$upcontext['user']['name'] = $name;
890
-			}
891
-			else
949
+			} else
892 950
 			{
893 951
 				$upcontext['user']['id'] = 1;
894 952
 				$upcontext['user']['name'] = 'Administrator';
@@ -904,11 +962,11 @@  discard block
 block discarded – undo
904 962
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
905 963
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
906 964
 
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
965
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
966
+									$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'] . '.';
967
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
968
+									$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'] . '.';
969
+				} else
912 970
 				{
913 971
 					// Set this as the new language.
914 972
 					$upcontext['language'] = $user_language;
@@ -952,15 +1010,17 @@  discard block
 block discarded – undo
952 1010
 	unset($member_columns);
953 1011
 
954 1012
 	// If we've not submitted then we're done.
955
-	if (empty($_POST['upcont']))
956
-		return false;
1013
+	if (empty($_POST['upcont'])) {
1014
+			return false;
1015
+	}
957 1016
 
958 1017
 	require_once($sourcedir . '/Subs-Admin.php');
959 1018
 	updateSettingsFile(array('image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\''));
960 1019
 
961 1020
 	// Should we update the $db_type value?
962
-	if ($upcontext['update_db_type_to_mysqli'])
963
-		updateSettingsFile(array('db_type' => '\'mysqli\''));
1021
+	if ($upcontext['update_db_type_to_mysqli']) {
1022
+			updateSettingsFile(array('db_type' => '\'mysqli\''));
1023
+	}
964 1024
 
965 1025
 	// Firstly, if they're enabling SM stat collection just do it.
966 1026
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']))
@@ -975,25 +1035,26 @@  discard block
 block discarded – undo
975 1035
 			fwrite($fp, $out);
976 1036
 
977 1037
 			$return_data = '';
978
-			while (!feof($fp))
979
-				$return_data .= fgets($fp, 128);
1038
+			while (!feof($fp)) {
1039
+							$return_data .= fgets($fp, 128);
1040
+			}
980 1041
 
981 1042
 			fclose($fp);
982 1043
 
983 1044
 			// Get the unique site ID.
984 1045
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
985 1046
 
986
-			if (!empty($ID[1]))
987
-				$smcFunc['db_insert']('replace',
1047
+			if (!empty($ID[1])) {
1048
+							$smcFunc['db_insert']('replace',
988 1049
 					$db_prefix . 'settings',
989 1050
 					array('variable' => 'string', 'value' => 'string'),
990 1051
 					array('allow_sm_stats', $ID[1]),
991 1052
 					array('variable')
992 1053
 				);
1054
+			}
993 1055
 		}
994
-	}
995
-	else
996
-		$smcFunc['db_query']('', '
1056
+	} else {
1057
+			$smcFunc['db_query']('', '
997 1058
 			DELETE FROM {db_prefix}settings
998 1059
 			WHERE variable = {string:allow_sm_stats}',
999 1060
 			array(
@@ -1001,6 +1062,7 @@  discard block
 block discarded – undo
1001 1062
 				'db_error_skip' => true,
1002 1063
 			)
1003 1064
 		);
1065
+	}
1004 1066
 
1005 1067
 	// Deleting old karma stuff?
1006 1068
 	if (!empty($_POST['delete_karma']))
@@ -1015,20 +1077,22 @@  discard block
 block discarded – undo
1015 1077
 		);
1016 1078
 
1017 1079
 		// Cleaning up old karma member settings.
1018
-		if ($upcontext['karma_installed']['good'])
1019
-			$smcFunc['db_query']('', '
1080
+		if ($upcontext['karma_installed']['good']) {
1081
+					$smcFunc['db_query']('', '
1020 1082
 				ALTER TABLE {db_prefix}members
1021 1083
 				DROP karma_good',
1022 1084
 				array()
1023 1085
 			);
1086
+		}
1024 1087
 
1025 1088
 		// Does karma bad was enable?
1026
-		if ($upcontext['karma_installed']['bad'])
1027
-			$smcFunc['db_query']('', '
1089
+		if ($upcontext['karma_installed']['bad']) {
1090
+					$smcFunc['db_query']('', '
1028 1091
 				ALTER TABLE {db_prefix}members
1029 1092
 				DROP karma_bad',
1030 1093
 				array()
1031 1094
 			);
1095
+		}
1032 1096
 
1033 1097
 		// Cleaning up old karma permissions.
1034 1098
 		$smcFunc['db_query']('', '
@@ -1041,18 +1105,20 @@  discard block
 block discarded – undo
1041 1105
 	}
1042 1106
 
1043 1107
 	// Emptying the error log?
1044
-	if (!empty($_POST['empty_error']))
1045
-		$smcFunc['db_query']('truncate_table', '
1108
+	if (!empty($_POST['empty_error'])) {
1109
+			$smcFunc['db_query']('truncate_table', '
1046 1110
 			TRUNCATE {db_prefix}log_errors',
1047 1111
 			array(
1048 1112
 			)
1049 1113
 		);
1114
+	}
1050 1115
 
1051 1116
 	$changes = array();
1052 1117
 
1053 1118
 	// If we're overriding the language follow it through.
1054
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1055
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1119
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1120
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1121
+	}
1056 1122
 
1057 1123
 	if (!empty($_POST['maint']))
1058 1124
 	{
@@ -1064,37 +1130,42 @@  discard block
 block discarded – undo
1064 1130
 		{
1065 1131
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1066 1132
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1067
-		}
1068
-		else
1133
+		} else
1069 1134
 		{
1070 1135
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1071 1136
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1072 1137
 		}
1073 1138
 	}
1074 1139
 
1075
-	if ($command_line)
1076
-		echo ' * Updating Settings.php...';
1140
+	if ($command_line) {
1141
+			echo ' * Updating Settings.php...';
1142
+	}
1077 1143
 
1078 1144
 	// Backup the current one first.
1079 1145
 	copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
1080 1146
 
1081 1147
 	// Fix some old paths.
1082
-	if (substr($boarddir, 0, 1) == '.')
1083
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1148
+	if (substr($boarddir, 0, 1) == '.') {
1149
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1150
+	}
1084 1151
 
1085
-	if (substr($sourcedir, 0, 1) == '.')
1086
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1152
+	if (substr($sourcedir, 0, 1) == '.') {
1153
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1154
+	}
1087 1155
 
1088
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1089
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1156
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1157
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1158
+	}
1090 1159
 
1091 1160
 	// Not had the database type added before?
1092
-	if (empty($db_type))
1093
-		$changes['db_type'] = 'mysql';
1161
+	if (empty($db_type)) {
1162
+			$changes['db_type'] = 'mysql';
1163
+	}
1094 1164
 
1095 1165
 	// For now we offer a option, this may change in future versions when mysql is completely removed.
1096
-	if (!empty($_POST['convertMysql']) && $db_type == 'mysql')
1097
-		$changes['db_type'] = '\'mysqli\'';
1166
+	if (!empty($_POST['convertMysql']) && $db_type == 'mysql') {
1167
+			$changes['db_type'] = '\'mysqli\'';
1168
+	}
1098 1169
 
1099 1170
 	// If they have a "host:port" setup for the host, split that into separate values
1100 1171
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1105,28 +1176,31 @@  discard block
 block discarded – undo
1105 1176
 		$changes['db_server'] = '\'' . $db_server . '\'';
1106 1177
 
1107 1178
 		// Only set this if we're not using the default port
1108
-		if ($db_port != ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port'))
1109
-			$changes['db_port'] = (int) $db_port;
1110
-	}
1111
-	elseif (!empty($db_port))
1179
+		if ($db_port != ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port')) {
1180
+					$changes['db_port'] = (int) $db_port;
1181
+		}
1182
+	} elseif (!empty($db_port))
1112 1183
 	{
1113 1184
 		// If db_port is set and is the same as the default, set it to ''
1114 1185
 		if ($db_type == 'mysql' || $db_type == 'mysqli')
1115 1186
 		{
1116
-			if ($db_port == ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port'))
1117
-				$changes['db_port'] = '\'\'';
1118
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1119
-				$changes['db_port'] = '\'\'';
1187
+			if ($db_port == ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port')) {
1188
+							$changes['db_port'] = '\'\'';
1189
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1190
+							$changes['db_port'] = '\'\'';
1191
+			}
1120 1192
 		}
1121 1193
 	}
1122 1194
 
1123 1195
 	// Maybe we haven't had this option yet?
1124
-	if (empty($packagesdir))
1125
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1196
+	if (empty($packagesdir)) {
1197
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1198
+	}
1126 1199
 
1127 1200
 	// Add support for $tasksdir var.
1128
-	if (empty($tasksdir))
1129
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1201
+	if (empty($tasksdir)) {
1202
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1203
+	}
1130 1204
 
1131 1205
 	// @todo Maybe change the cookie name if going to 1.1, too?
1132 1206
 
@@ -1171,8 +1245,7 @@  discard block
 block discarded – undo
1171 1245
 			$found_old = true;
1172 1246
 			// Replace the old line with the new code
1173 1247
 			$settings_file = str_replace('$db_last_error = ' . $db_last_error . ';', $error_catching_header . $error_catching, $settings_file);
1174
-		}
1175
-		else
1248
+		} else
1176 1249
 		{
1177 1250
 			$found_old = false;
1178 1251
 			// We want the comments as well as the code...
@@ -1203,8 +1276,9 @@  discard block
 block discarded – undo
1203 1276
 		fclose($file);
1204 1277
 	}
1205 1278
 
1206
-	if ($command_line)
1207
-		echo ' Successful.' . "\n";
1279
+	if ($command_line) {
1280
+			echo ' Successful.' . "\n";
1281
+	}
1208 1282
 
1209 1283
 	// Are we doing debug?
1210 1284
 	if (isset($_POST['debug']))
@@ -1214,8 +1288,9 @@  discard block
 block discarded – undo
1214 1288
 	}
1215 1289
 
1216 1290
 	// If we're not backing up then jump one.
1217
-	if (empty($_POST['backup']))
1218
-		$upcontext['current_step']++;
1291
+	if (empty($_POST['backup'])) {
1292
+			$upcontext['current_step']++;
1293
+	}
1219 1294
 
1220 1295
 	// If we've got here then let's proceed to the next step!
1221 1296
 	return true;
@@ -1230,8 +1305,9 @@  discard block
 block discarded – undo
1230 1305
 	$upcontext['page_title'] = 'Backup Database';
1231 1306
 
1232 1307
 	// Done it already - js wise?
1233
-	if (!empty($_POST['backup_done']))
1234
-		return true;
1308
+	if (!empty($_POST['backup_done'])) {
1309
+			return true;
1310
+	}
1235 1311
 
1236 1312
 	// Some useful stuff here.
1237 1313
 	db_extend();
@@ -1245,9 +1321,10 @@  discard block
 block discarded – undo
1245 1321
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1246 1322
 
1247 1323
 	$table_names = array();
1248
-	foreach ($tables as $table)
1249
-		if (substr($table, 0, 7) !== 'backup_')
1324
+	foreach ($tables as $table) {
1325
+			if (substr($table, 0, 7) !== 'backup_')
1250 1326
 			$table_names[] = $table;
1327
+	}
1251 1328
 
1252 1329
 	$upcontext['table_count'] = count($table_names);
1253 1330
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1257,12 +1334,14 @@  discard block
 block discarded – undo
1257 1334
 	$file_steps = $upcontext['table_count'];
1258 1335
 
1259 1336
 	// What ones have we already done?
1260
-	foreach ($table_names as $id => $table)
1261
-		if ($id < $_GET['substep'])
1337
+	foreach ($table_names as $id => $table) {
1338
+			if ($id < $_GET['substep'])
1262 1339
 			$upcontext['previous_tables'][] = $table;
1340
+	}
1263 1341
 
1264
-	if ($command_line)
1265
-		echo 'Backing Up Tables.';
1342
+	if ($command_line) {
1343
+			echo 'Backing Up Tables.';
1344
+	}
1266 1345
 
1267 1346
 	// If we don't support javascript we backup here.
1268 1347
 	if (!$support_js || isset($_GET['xml']))
@@ -1281,8 +1360,9 @@  discard block
 block discarded – undo
1281 1360
 			backupTable($table_names[$substep]);
1282 1361
 
1283 1362
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1284
-			if (isset($_GET['xml']))
1285
-				return upgradeExit();
1363
+			if (isset($_GET['xml'])) {
1364
+							return upgradeExit();
1365
+			}
1286 1366
 		}
1287 1367
 
1288 1368
 		if ($command_line)
@@ -1315,9 +1395,10 @@  discard block
 block discarded – undo
1315 1395
 
1316 1396
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1317 1397
 
1318
-	if ($command_line)
1319
-		echo ' done.';
1320
-}
1398
+	if ($command_line) {
1399
+			echo ' done.';
1400
+	}
1401
+	}
1321 1402
 
1322 1403
 // Step 2: Everything.
1323 1404
 function DatabaseChanges()
@@ -1326,8 +1407,9 @@  discard block
 block discarded – undo
1326 1407
 	global $upcontext, $support_js, $db_type;
1327 1408
 
1328 1409
 	// Have we just completed this?
1329
-	if (!empty($_POST['database_done']))
1330
-		return true;
1410
+	if (!empty($_POST['database_done'])) {
1411
+			return true;
1412
+	}
1331 1413
 
1332 1414
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1333 1415
 	$upcontext['page_title'] = 'Database Changes';
@@ -1344,15 +1426,16 @@  discard block
 block discarded – undo
1344 1426
 	);
1345 1427
 
1346 1428
 	// How many files are there in total?
1347
-	if (isset($_GET['filecount']))
1348
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1349
-	else
1429
+	if (isset($_GET['filecount'])) {
1430
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1431
+	} else
1350 1432
 	{
1351 1433
 		$upcontext['file_count'] = 0;
1352 1434
 		foreach ($files as $file)
1353 1435
 		{
1354
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1355
-				$upcontext['file_count']++;
1436
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1437
+							$upcontext['file_count']++;
1438
+			}
1356 1439
 		}
1357 1440
 	}
1358 1441
 
@@ -1362,9 +1445,9 @@  discard block
 block discarded – undo
1362 1445
 	$upcontext['cur_file_num'] = 0;
1363 1446
 	foreach ($files as $file)
1364 1447
 	{
1365
-		if ($did_not_do)
1366
-			$did_not_do--;
1367
-		else
1448
+		if ($did_not_do) {
1449
+					$did_not_do--;
1450
+		} else
1368 1451
 		{
1369 1452
 			$upcontext['cur_file_num']++;
1370 1453
 			$upcontext['cur_file_name'] = $file[0];
@@ -1391,12 +1474,13 @@  discard block
 block discarded – undo
1391 1474
 					// Flag to move on to the next.
1392 1475
 					$upcontext['completed_step'] = true;
1393 1476
 					// Did we complete the whole file?
1394
-					if ($nextFile)
1395
-						$upcontext['current_debug_item_num'] = -1;
1477
+					if ($nextFile) {
1478
+											$upcontext['current_debug_item_num'] = -1;
1479
+					}
1396 1480
 					return upgradeExit();
1481
+				} elseif ($support_js) {
1482
+									break;
1397 1483
 				}
1398
-				elseif ($support_js)
1399
-					break;
1400 1484
 			}
1401 1485
 			// Set the progress bar to be right as if we had - even if we hadn't...
1402 1486
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1421,8 +1505,9 @@  discard block
 block discarded – undo
1421 1505
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1422 1506
 
1423 1507
 	// Now it's nice to have some of the basic SMF source files.
1424
-	if (!isset($_GET['ssi']) && !$command_line)
1425
-		redirectLocation('&ssi=1');
1508
+	if (!isset($_GET['ssi']) && !$command_line) {
1509
+			redirectLocation('&ssi=1');
1510
+	}
1426 1511
 
1427 1512
 	$upcontext['sub_template'] = 'upgrade_complete';
1428 1513
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1438,14 +1523,16 @@  discard block
 block discarded – undo
1438 1523
 	// Are we in maintenance mode?
1439 1524
 	if (isset($upcontext['user']['main']))
1440 1525
 	{
1441
-		if ($command_line)
1442
-			echo ' * ';
1526
+		if ($command_line) {
1527
+					echo ' * ';
1528
+		}
1443 1529
 		$upcontext['removed_maintenance'] = true;
1444 1530
 		$changes['maintenance'] = $upcontext['user']['main'];
1445 1531
 	}
1446 1532
 	// Otherwise if somehow we are in 2 let's go to 1.
1447
-	elseif (!empty($maintenance) && $maintenance == 2)
1448
-		$changes['maintenance'] = 1;
1533
+	elseif (!empty($maintenance) && $maintenance == 2) {
1534
+			$changes['maintenance'] = 1;
1535
+	}
1449 1536
 
1450 1537
 	// Wipe this out...
1451 1538
 	$upcontext['user'] = array();
@@ -1461,9 +1548,9 @@  discard block
 block discarded – undo
1461 1548
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1462 1549
 
1463 1550
 	// Now is the perfect time to fetch the SM files.
1464
-	if ($command_line)
1465
-		cli_scheduled_fetchSMfiles();
1466
-	else
1551
+	if ($command_line) {
1552
+			cli_scheduled_fetchSMfiles();
1553
+	} else
1467 1554
 	{
1468 1555
 		require_once($sourcedir . '/ScheduledTasks.php');
1469 1556
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1471,8 +1558,9 @@  discard block
 block discarded – undo
1471 1558
 	}
1472 1559
 
1473 1560
 	// Log what we've done.
1474
-	if (empty($user_info['id']))
1475
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1561
+	if (empty($user_info['id'])) {
1562
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1563
+	}
1476 1564
 
1477 1565
 	// Log the action manually, so CLI still works.
1478 1566
 	$smcFunc['db_insert']('',
@@ -1491,8 +1579,9 @@  discard block
 block discarded – undo
1491 1579
 
1492 1580
 	// Save the current database version.
1493 1581
 	$server_version = $smcFunc['db_server_info']();
1494
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1495
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1582
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1583
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1584
+	}
1496 1585
 
1497 1586
 	if ($command_line)
1498 1587
 	{
@@ -1504,8 +1593,9 @@  discard block
 block discarded – undo
1504 1593
 
1505 1594
 	// Make sure it says we're done.
1506 1595
 	$upcontext['overall_percent'] = 100;
1507
-	if (isset($upcontext['step_progress']))
1508
-		unset($upcontext['step_progress']);
1596
+	if (isset($upcontext['step_progress'])) {
1597
+			unset($upcontext['step_progress']);
1598
+	}
1509 1599
 
1510 1600
 	$_GET['substep'] = 0;
1511 1601
 	return false;
@@ -1516,8 +1606,9 @@  discard block
 block discarded – undo
1516 1606
 {
1517 1607
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1518 1608
 
1519
-	if (empty($modSettings['time_format']))
1520
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1609
+	if (empty($modSettings['time_format'])) {
1610
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1611
+	}
1521 1612
 
1522 1613
 	// What files do we want to get
1523 1614
 	$request = $smcFunc['db_query']('', '
@@ -1551,8 +1642,9 @@  discard block
 block discarded – undo
1551 1642
 		$file_data = fetch_web_data($url);
1552 1643
 
1553 1644
 		// If we got an error - give up - the site might be down.
1554
-		if ($file_data === false)
1555
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1645
+		if ($file_data === false) {
1646
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1647
+		}
1556 1648
 
1557 1649
 		// Save the file to the database.
1558 1650
 		$smcFunc['db_query']('substring', '
@@ -1594,8 +1686,9 @@  discard block
 block discarded – undo
1594 1686
 	$themeData = array();
1595 1687
 	foreach ($values as $variable => $value)
1596 1688
 	{
1597
-		if (!isset($value) || $value === null)
1598
-			$value = 0;
1689
+		if (!isset($value) || $value === null) {
1690
+					$value = 0;
1691
+		}
1599 1692
 
1600 1693
 		$themeData[] = array(0, 1, $variable, $value);
1601 1694
 	}
@@ -1624,8 +1717,9 @@  discard block
 block discarded – undo
1624 1717
 
1625 1718
 	foreach ($values as $variable => $value)
1626 1719
 	{
1627
-		if (empty($modSettings[$value[0]]))
1628
-			continue;
1720
+		if (empty($modSettings[$value[0]])) {
1721
+					continue;
1722
+		}
1629 1723
 
1630 1724
 		$smcFunc['db_query']('', '
1631 1725
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1658,8 +1752,9 @@  discard block
 block discarded – undo
1658 1752
 
1659 1753
 	$settingsArray = file($boarddir . '/Settings_bak.php');
1660 1754
 
1661
-	if (count($settingsArray) == 1)
1662
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1755
+	if (count($settingsArray) == 1) {
1756
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1757
+	}
1663 1758
 
1664 1759
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1665 1760
 	{
@@ -1672,9 +1767,9 @@  discard block
 block discarded – undo
1672 1767
 			{
1673 1768
 				if (isset($settingsArray[$i]) && strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1674 1769
 				{
1675
-					if ($val == '#remove#')
1676
-						unset($settingsArray[$i]);
1677
-					else
1770
+					if ($val == '#remove#') {
1771
+											unset($settingsArray[$i]);
1772
+					} else
1678 1773
 					{
1679 1774
 						$comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#');
1680 1775
 						$settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment != '' ? "\t\t" . $comment : "\n");
@@ -1686,22 +1781,25 @@  discard block
 block discarded – undo
1686 1781
 		}
1687 1782
 		if (isset($settingsArray[$i]))
1688 1783
 		{
1689
-			if (trim(substr($settingsArray[$i], 0, 2)) == '?' . '>')
1690
-				$end = $i;
1784
+			if (trim(substr($settingsArray[$i], 0, 2)) == '?' . '>') {
1785
+							$end = $i;
1786
+			}
1691 1787
 		}
1692 1788
 	}
1693 1789
 
1694 1790
 	// Assume end-of-file if the end wasn't found.
1695
-	if (empty($end) || $end < 10)
1696
-		$end = count($settingsArray);
1791
+	if (empty($end) || $end < 10) {
1792
+			$end = count($settingsArray);
1793
+	}
1697 1794
 
1698 1795
 	if (!empty($config_vars))
1699 1796
 	{
1700 1797
 		$settingsArray[$end++] = '';
1701 1798
 		foreach ($config_vars as $var => $val)
1702 1799
 		{
1703
-			if ($val != '#remove#')
1704
-				$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
1800
+			if ($val != '#remove#') {
1801
+							$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
1802
+			}
1705 1803
 		}
1706 1804
 	}
1707 1805
 	// This should be the last line and even last bytes of the file.
@@ -1714,8 +1812,9 @@  discard block
 block discarded – undo
1714 1812
 	$fp = fopen($boarddir . '/Settings.php', 'r+');
1715 1813
 	for ($i = 0; $i < $end; $i++)
1716 1814
 	{
1717
-		if (isset($settingsArray[$i]))
1718
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1815
+		if (isset($settingsArray[$i])) {
1816
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1817
+		}
1719 1818
 	}
1720 1819
 	fwrite($fp, rtrim($settingsArray[$i]));
1721 1820
 	fclose($fp);
@@ -1746,8 +1845,9 @@  discard block
 block discarded – undo
1746 1845
 	global $smcFunc;
1747 1846
 	static $member_groups = array();
1748 1847
 
1749
-	if (!empty($member_groups))
1750
-		return $member_groups;
1848
+	if (!empty($member_groups)) {
1849
+			return $member_groups;
1850
+	}
1751 1851
 
1752 1852
 	$request = $smcFunc['db_query']('', '
1753 1853
 		SELECT group_name, id_group
@@ -1772,8 +1872,9 @@  discard block
 block discarded – undo
1772 1872
 			)
1773 1873
 		);
1774 1874
 	}
1775
-	while ($row = $smcFunc['db_fetch_row']($request))
1776
-		$member_groups[trim($row[0])] = $row[1];
1875
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1876
+			$member_groups[trim($row[0])] = $row[1];
1877
+	}
1777 1878
 	$smcFunc['db_free_result']($request);
1778 1879
 
1779 1880
 	return $member_groups;
@@ -1826,10 +1927,11 @@  discard block
 block discarded – undo
1826 1927
 		{
1827 1928
 			global $support_js;
1828 1929
 
1829
-			if ($support_js)
1830
-				return true;
1831
-			else
1832
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1930
+			if ($support_js) {
1931
+							return true;
1932
+			} else {
1933
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1934
+			}
1833 1935
 		}
1834 1936
 	}
1835 1937
 
@@ -1847,8 +1949,9 @@  discard block
 block discarded – undo
1847 1949
 				'db_error_skip' => true,
1848 1950
 			)
1849 1951
 		);
1850
-		if ($smcFunc['db_num_rows']($request) === 0)
1851
-			die('Unable to find members table!');
1952
+		if ($smcFunc['db_num_rows']($request) === 0) {
1953
+					die('Unable to find members table!');
1954
+		}
1852 1955
 		$table_status = $smcFunc['db_fetch_assoc']($request);
1853 1956
 		$smcFunc['db_free_result']($request);
1854 1957
 
@@ -1863,17 +1966,20 @@  discard block
 block discarded – undo
1863 1966
 				)
1864 1967
 			);
1865 1968
 			// Got something?
1866
-			if ($smcFunc['db_num_rows']($request) !== 0)
1867
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
1969
+			if ($smcFunc['db_num_rows']($request) !== 0) {
1970
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
1971
+			}
1868 1972
 			$smcFunc['db_free_result']($request);
1869 1973
 
1870 1974
 			// Excellent!
1871
-			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset']))
1872
-				$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1975
+			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) {
1976
+							$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1977
+			}
1873 1978
 		}
1874 1979
 	}
1875
-	if (empty($db_collation))
1876
-		$db_collation = '';
1980
+	if (empty($db_collation)) {
1981
+			$db_collation = '';
1982
+	}
1877 1983
 
1878 1984
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1879 1985
 
@@ -1885,8 +1991,9 @@  discard block
 block discarded – undo
1885 1991
 	$last_step = '';
1886 1992
 
1887 1993
 	// Make sure all newly created tables will have the proper characters set.
1888
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1889
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1994
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1995
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1996
+	}
1890 1997
 
1891 1998
 	// Count the total number of steps within this file - for progress.
1892 1999
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1906,15 +2013,18 @@  discard block
 block discarded – undo
1906 2013
 		$do_current = $substep >= $_GET['substep'];
1907 2014
 
1908 2015
 		// Get rid of any comments in the beginning of the line...
1909
-		if (substr(trim($line), 0, 2) === '/*')
1910
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
2016
+		if (substr(trim($line), 0, 2) === '/*') {
2017
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
2018
+		}
1911 2019
 
1912 2020
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1913
-		if ($is_debug && !$support_js && $command_line)
1914
-			flush();
2021
+		if ($is_debug && !$support_js && $command_line) {
2022
+					flush();
2023
+		}
1915 2024
 
1916
-		if (trim($line) === '')
1917
-			continue;
2025
+		if (trim($line) === '') {
2026
+					continue;
2027
+		}
1918 2028
 
1919 2029
 		if (trim(substr($line, 0, 3)) === '---')
1920 2030
 		{
@@ -1924,8 +2034,9 @@  discard block
 block discarded – undo
1924 2034
 			if (trim($current_data) != '' && $type !== '}')
1925 2035
 			{
1926 2036
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1927
-				if ($command_line)
1928
-					echo $upcontext['error_message'];
2037
+				if ($command_line) {
2038
+									echo $upcontext['error_message'];
2039
+				}
1929 2040
 			}
1930 2041
 
1931 2042
 			if ($type == ' ')
@@ -1943,17 +2054,18 @@  discard block
 block discarded – undo
1943 2054
 				if ($do_current)
1944 2055
 				{
1945 2056
 					$upcontext['actioned_items'][] = $last_step;
1946
-					if ($command_line)
1947
-						echo ' * ';
2057
+					if ($command_line) {
2058
+											echo ' * ';
2059
+					}
1948 2060
 				}
1949
-			}
1950
-			elseif ($type == '#')
2061
+			} elseif ($type == '#')
1951 2062
 			{
1952 2063
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1953 2064
 
1954 2065
 				$upcontext['current_debug_item_num']++;
1955
-				if (trim($line) != '---#')
1956
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
2066
+				if (trim($line) != '---#') {
2067
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
2068
+				}
1957 2069
 
1958 2070
 				// Have we already done something?
1959 2071
 				if (isset($_GET['xml']) && $done_something)
@@ -1964,34 +2076,36 @@  discard block
 block discarded – undo
1964 2076
 
1965 2077
 				if ($do_current)
1966 2078
 				{
1967
-					if (trim($line) == '---#' && $command_line)
1968
-						echo ' done.', $endl;
1969
-					elseif ($command_line)
1970
-						echo ' +++ ', rtrim(substr($line, 4));
1971
-					elseif (trim($line) != '---#')
2079
+					if (trim($line) == '---#' && $command_line) {
2080
+											echo ' done.', $endl;
2081
+					} elseif ($command_line) {
2082
+											echo ' +++ ', rtrim(substr($line, 4));
2083
+					} elseif (trim($line) != '---#')
1972 2084
 					{
1973
-						if ($is_debug)
1974
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
2085
+						if ($is_debug) {
2086
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
2087
+						}
1975 2088
 					}
1976 2089
 				}
1977 2090
 
1978 2091
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1979 2092
 				{
1980
-					if ($command_line)
1981
-						echo ' * ';
1982
-					else
1983
-						$upcontext['actioned_items'][] = $last_step;
2093
+					if ($command_line) {
2094
+											echo ' * ';
2095
+					} else {
2096
+											$upcontext['actioned_items'][] = $last_step;
2097
+					}
1984 2098
 				}
1985 2099
 
1986 2100
 				// Small step - only if we're actually doing stuff.
1987
-				if ($do_current)
1988
-					nextSubstep(++$substep);
1989
-				else
1990
-					$substep++;
1991
-			}
1992
-			elseif ($type == '{')
1993
-				$current_type = 'code';
1994
-			elseif ($type == '}')
2101
+				if ($do_current) {
2102
+									nextSubstep(++$substep);
2103
+				} else {
2104
+									$substep++;
2105
+				}
2106
+			} elseif ($type == '{') {
2107
+							$current_type = 'code';
2108
+			} elseif ($type == '}')
1995 2109
 			{
1996 2110
 				$current_type = 'sql';
1997 2111
 
@@ -2004,8 +2118,9 @@  discard block
 block discarded – undo
2004 2118
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
2005 2119
 				{
2006 2120
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
2007
-					if ($command_line)
2008
-						echo $upcontext['error_message'];
2121
+					if ($command_line) {
2122
+											echo $upcontext['error_message'];
2123
+					}
2009 2124
 				}
2010 2125
 
2011 2126
 				// Done with code!
@@ -2085,8 +2200,9 @@  discard block
 block discarded – undo
2085 2200
 	$db_unbuffered = false;
2086 2201
 
2087 2202
 	// Failure?!
2088
-	if ($result !== false)
2089
-		return $result;
2203
+	if ($result !== false) {
2204
+			return $result;
2205
+	}
2090 2206
 
2091 2207
 	$db_error_message = $smcFunc['db_error']($db_connection);
2092 2208
 	// If MySQL we do something more clever.
@@ -2114,54 +2230,61 @@  discard block
 block discarded – undo
2114 2230
 			{
2115 2231
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
2116 2232
 				$result = mysqli_query($db_connection, $string);
2117
-				if ($result !== false)
2118
-					return $result;
2233
+				if ($result !== false) {
2234
+									return $result;
2235
+				}
2119 2236
 			}
2120
-		}
2121
-		elseif ($mysqli_errno == 2013)
2237
+		} elseif ($mysqli_errno == 2013)
2122 2238
 		{
2123 2239
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
2124 2240
 			mysqli_select_db($db_connection, $db_name);
2125 2241
 			if ($db_connection)
2126 2242
 			{
2127 2243
 				$result = mysqli_query($db_connection, $string);
2128
-				if ($result !== false)
2129
-					return $result;
2244
+				if ($result !== false) {
2245
+									return $result;
2246
+				}
2130 2247
 			}
2131 2248
 		}
2132 2249
 		// Duplicate column name... should be okay ;).
2133
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
2134
-			return false;
2250
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2251
+					return false;
2252
+		}
2135 2253
 		// Duplicate insert... make sure it's the proper type of query ;).
2136
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
2137
-			return false;
2254
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2255
+					return false;
2256
+		}
2138 2257
 		// Creating an index on a non-existent column.
2139
-		elseif ($mysqli_errno == 1072)
2140
-			return false;
2141
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
2142
-			return false;
2258
+		elseif ($mysqli_errno == 1072) {
2259
+					return false;
2260
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2261
+					return false;
2262
+		}
2143 2263
 	}
2144 2264
 	// If a table already exists don't go potty.
2145 2265
 	else
2146 2266
 	{
2147 2267
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
2148 2268
 		{
2149
-			if (strpos($db_error_message, 'exist') !== false)
2150
-				return true;
2151
-		}
2152
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2269
+			if (strpos($db_error_message, 'exist') !== false) {
2270
+							return true;
2271
+			}
2272
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
2153 2273
 		{
2154
-			if (strpos($db_error_message, 'duplicate') !== false)
2155
-				return true;
2274
+			if (strpos($db_error_message, 'duplicate') !== false) {
2275
+							return true;
2276
+			}
2156 2277
 		}
2157 2278
 	}
2158 2279
 
2159 2280
 	// Get the query string so we pass everything.
2160 2281
 	$query_string = '';
2161
-	foreach ($_GET as $k => $v)
2162
-		$query_string .= ';' . $k . '=' . $v;
2163
-	if (strlen($query_string) != 0)
2164
-		$query_string = '?' . substr($query_string, 1);
2282
+	foreach ($_GET as $k => $v) {
2283
+			$query_string .= ';' . $k . '=' . $v;
2284
+	}
2285
+	if (strlen($query_string) != 0) {
2286
+			$query_string = '?' . substr($query_string, 1);
2287
+	}
2165 2288
 
2166 2289
 	if ($command_line)
2167 2290
 	{
@@ -2247,16 +2370,18 @@  discard block
 block discarded – undo
2247 2370
 			{
2248 2371
 				$found |= 1;
2249 2372
 				// Do some checks on the data if we have it set.
2250
-				if (isset($change['col_type']))
2251
-					$found &= $change['col_type'] === $column['type'];
2252
-				if (isset($change['null_allowed']))
2253
-					$found &= $column['null'] == $change['null_allowed'];
2254
-				if (isset($change['default']))
2255
-					$found &= $change['default'] === $column['default'];
2373
+				if (isset($change['col_type'])) {
2374
+									$found &= $change['col_type'] === $column['type'];
2375
+				}
2376
+				if (isset($change['null_allowed'])) {
2377
+									$found &= $column['null'] == $change['null_allowed'];
2378
+				}
2379
+				if (isset($change['default'])) {
2380
+									$found &= $change['default'] === $column['default'];
2381
+				}
2256 2382
 			}
2257 2383
 		}
2258
-	}
2259
-	elseif ($change['type'] === 'index')
2384
+	} elseif ($change['type'] === 'index')
2260 2385
 	{
2261 2386
 		$request = upgrade_query('
2262 2387
 			SHOW INDEX
@@ -2265,9 +2390,10 @@  discard block
 block discarded – undo
2265 2390
 		{
2266 2391
 			$cur_index = array();
2267 2392
 
2268
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2269
-				if ($row['Key_name'] === $change['name'])
2393
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2394
+							if ($row['Key_name'] === $change['name'])
2270 2395
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2396
+			}
2271 2397
 
2272 2398
 			ksort($cur_index, SORT_NUMERIC);
2273 2399
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2277,14 +2403,17 @@  discard block
 block discarded – undo
2277 2403
 	}
2278 2404
 
2279 2405
 	// If we're trying to add and it's added, we're done.
2280
-	if ($found && in_array($change['method'], array('add', 'change')))
2281
-		return true;
2406
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2407
+			return true;
2408
+	}
2282 2409
 	// Otherwise if we're removing and it wasn't found we're also done.
2283
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2284
-		return true;
2410
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2411
+			return true;
2412
+	}
2285 2413
 	// Otherwise is it just a test?
2286
-	elseif ($is_test)
2287
-		return false;
2414
+	elseif ($is_test) {
2415
+			return false;
2416
+	}
2288 2417
 
2289 2418
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2290 2419
 	$running = false;
@@ -2295,8 +2424,9 @@  discard block
 block discarded – undo
2295 2424
 			SHOW FULL PROCESSLIST');
2296 2425
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2297 2426
 		{
2298
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2299
-				$found = true;
2427
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2428
+							$found = true;
2429
+			}
2300 2430
 		}
2301 2431
 
2302 2432
 		// Can't find it? Then we need to run it fools!
@@ -2308,8 +2438,9 @@  discard block
 block discarded – undo
2308 2438
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2309 2439
 				' . $change['text'], true) !== false;
2310 2440
 
2311
-			if (!$success)
2312
-				return false;
2441
+			if (!$success) {
2442
+							return false;
2443
+			}
2313 2444
 
2314 2445
 			// Return
2315 2446
 			$running = true;
@@ -2342,8 +2473,7 @@  discard block
 block discarded – undo
2342 2473
 	{
2343 2474
 		$column_fix = true;
2344 2475
 		$null_fix = !$change['null_allowed'];
2345
-	}
2346
-	else
2476
+	} else
2347 2477
 	{
2348 2478
 		$request = $smcFunc['db_query']('', '
2349 2479
 			SHOW FULL COLUMNS
@@ -2354,8 +2484,9 @@  discard block
 block discarded – undo
2354 2484
 				'db_error_skip' => true,
2355 2485
 			)
2356 2486
 		);
2357
-		if ($smcFunc['db_num_rows']($request) === 0)
2358
-			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2487
+		if ($smcFunc['db_num_rows']($request) === 0) {
2488
+					die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2489
+		}
2359 2490
 		$table_row = $smcFunc['db_fetch_assoc']($request);
2360 2491
 		$smcFunc['db_free_result']($request);
2361 2492
 
@@ -2377,10 +2508,11 @@  discard block
 block discarded – undo
2377 2508
 				)
2378 2509
 			);
2379 2510
 			// No results? Just forget it all together.
2380
-			if ($smcFunc['db_num_rows']($request) === 0)
2381
-				unset($table_row['Collation']);
2382
-			else
2383
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
2511
+			if ($smcFunc['db_num_rows']($request) === 0) {
2512
+							unset($table_row['Collation']);
2513
+			} else {
2514
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
2515
+			}
2384 2516
 			$smcFunc['db_free_result']($request);
2385 2517
 		}
2386 2518
 	}
@@ -2388,8 +2520,8 @@  discard block
 block discarded – undo
2388 2520
 	if ($column_fix)
2389 2521
 	{
2390 2522
 		// Make sure there are no NULL's left.
2391
-		if ($null_fix)
2392
-			$smcFunc['db_query']('', '
2523
+		if ($null_fix) {
2524
+					$smcFunc['db_query']('', '
2393 2525
 				UPDATE {db_prefix}' . $change['table'] . '
2394 2526
 				SET ' . $change['column'] . ' = {string:default}
2395 2527
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2398,6 +2530,7 @@  discard block
 block discarded – undo
2398 2530
 					'db_error_skip' => true,
2399 2531
 				)
2400 2532
 			);
2533
+		}
2401 2534
 
2402 2535
 		// Do the actual alteration.
2403 2536
 		$smcFunc['db_query']('', '
@@ -2426,8 +2559,9 @@  discard block
 block discarded – undo
2426 2559
 	}
2427 2560
 
2428 2561
 	// Not a column we need to check on?
2429
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2430
-		return;
2562
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2563
+			return;
2564
+	}
2431 2565
 
2432 2566
 	// Break it up you (six|seven).
2433 2567
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2446,13 +2580,13 @@  discard block
 block discarded – undo
2446 2580
 				'new_name' => $temp[2],
2447 2581
 		));
2448 2582
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2449
-		if ($smcFunc['db_num_rows'] != 1)
2450
-			return;
2583
+		if ($smcFunc['db_num_rows'] != 1) {
2584
+					return;
2585
+		}
2451 2586
 
2452 2587
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2453 2588
 		$smcFunc['db_free_result']($request);
2454
-	}
2455
-	else
2589
+	} else
2456 2590
 	{
2457 2591
 		// Do this the old fashion, sure method way.
2458 2592
 		$request = $smcFunc['db_query']('', '
@@ -2463,21 +2597,24 @@  discard block
 block discarded – undo
2463 2597
 		));
2464 2598
 		// Mayday!
2465 2599
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2466
-		if ($smcFunc['db_num_rows'] == 0)
2467
-			return;
2600
+		if ($smcFunc['db_num_rows'] == 0) {
2601
+					return;
2602
+		}
2468 2603
 
2469 2604
 		// Oh where, oh where has my little field gone. Oh where can it be...
2470
-		while ($row = $smcFunc['db_query']($request))
2471
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2605
+		while ($row = $smcFunc['db_query']($request)) {
2606
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2472 2607
 			{
2473 2608
 				$current_type = $row['Type'];
2609
+		}
2474 2610
 				break;
2475 2611
 			}
2476 2612
 	}
2477 2613
 
2478 2614
 	// If this doesn't match, the column may of been altered for a reason.
2479
-	if (trim($current_type) != trim($temp[3]))
2480
-		$temp[3] = $current_type;
2615
+	if (trim($current_type) != trim($temp[3])) {
2616
+			$temp[3] = $current_type;
2617
+	}
2481 2618
 
2482 2619
 	// Piece this back together.
2483 2620
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2489,8 +2626,9 @@  discard block
 block discarded – undo
2489 2626
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2490 2627
 	global $step_progress, $is_debug, $upcontext;
2491 2628
 
2492
-	if ($_GET['substep'] < $substep)
2493
-		$_GET['substep'] = $substep;
2629
+	if ($_GET['substep'] < $substep) {
2630
+			$_GET['substep'] = $substep;
2631
+	}
2494 2632
 
2495 2633
 	if ($command_line)
2496 2634
 	{
@@ -2503,29 +2641,33 @@  discard block
 block discarded – undo
2503 2641
 	}
2504 2642
 
2505 2643
 	@set_time_limit(300);
2506
-	if (function_exists('apache_reset_timeout'))
2507
-		@apache_reset_timeout();
2644
+	if (function_exists('apache_reset_timeout')) {
2645
+			@apache_reset_timeout();
2646
+	}
2508 2647
 
2509
-	if (time() - $start_time <= $timeLimitThreshold)
2510
-		return;
2648
+	if (time() - $start_time <= $timeLimitThreshold) {
2649
+			return;
2650
+	}
2511 2651
 
2512 2652
 	// Do we have some custom step progress stuff?
2513 2653
 	if (!empty($step_progress))
2514 2654
 	{
2515 2655
 		$upcontext['substep_progress'] = 0;
2516 2656
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2517
-		if ($step_progress['current'] > $step_progress['total'])
2518
-			$upcontext['substep_progress'] = 99.9;
2519
-		else
2520
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2657
+		if ($step_progress['current'] > $step_progress['total']) {
2658
+					$upcontext['substep_progress'] = 99.9;
2659
+		} else {
2660
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2661
+		}
2521 2662
 
2522 2663
 		// Make it nicely rounded.
2523 2664
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2524 2665
 	}
2525 2666
 
2526 2667
 	// If this is XML we just exit right away!
2527
-	if (isset($_GET['xml']))
2528
-		return upgradeExit();
2668
+	if (isset($_GET['xml'])) {
2669
+			return upgradeExit();
2670
+	}
2529 2671
 
2530 2672
 	// We're going to pause after this!
2531 2673
 	$upcontext['pause'] = true;
@@ -2533,13 +2675,15 @@  discard block
 block discarded – undo
2533 2675
 	$upcontext['query_string'] = '';
2534 2676
 	foreach ($_GET as $k => $v)
2535 2677
 	{
2536
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2537
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2678
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2679
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2680
+		}
2538 2681
 	}
2539 2682
 
2540 2683
 	// Custom warning?
2541
-	if (!empty($custom_warning))
2542
-		$upcontext['custom_warning'] = $custom_warning;
2684
+	if (!empty($custom_warning)) {
2685
+			$upcontext['custom_warning'] = $custom_warning;
2686
+	}
2543 2687
 
2544 2688
 	upgradeExit();
2545 2689
 }
@@ -2554,25 +2698,26 @@  discard block
 block discarded – undo
2554 2698
 	ob_implicit_flush(true);
2555 2699
 	@set_time_limit(600);
2556 2700
 
2557
-	if (!isset($_SERVER['argv']))
2558
-		$_SERVER['argv'] = array();
2701
+	if (!isset($_SERVER['argv'])) {
2702
+			$_SERVER['argv'] = array();
2703
+	}
2559 2704
 	$_GET['maint'] = 1;
2560 2705
 
2561 2706
 	foreach ($_SERVER['argv'] as $i => $arg)
2562 2707
 	{
2563
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2564
-			$_GET['lang'] = $match[1];
2565
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2566
-			continue;
2567
-		elseif ($arg == '--no-maintenance')
2568
-			$_GET['maint'] = 0;
2569
-		elseif ($arg == '--debug')
2570
-			$is_debug = true;
2571
-		elseif ($arg == '--backup')
2572
-			$_POST['backup'] = 1;
2573
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2574
-			$_GET['conv'] = 1;
2575
-		elseif ($i != 0)
2708
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2709
+					$_GET['lang'] = $match[1];
2710
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2711
+					continue;
2712
+		} elseif ($arg == '--no-maintenance') {
2713
+					$_GET['maint'] = 0;
2714
+		} elseif ($arg == '--debug') {
2715
+					$is_debug = true;
2716
+		} elseif ($arg == '--backup') {
2717
+					$_POST['backup'] = 1;
2718
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2719
+					$_GET['conv'] = 1;
2720
+		} elseif ($i != 0)
2576 2721
 		{
2577 2722
 			echo 'SMF Command-line Upgrader
2578 2723
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2586,10 +2731,12 @@  discard block
 block discarded – undo
2586 2731
 		}
2587 2732
 	}
2588 2733
 
2589
-	if (!php_version_check())
2590
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2591
-	if (!db_version_check())
2592
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2734
+	if (!php_version_check()) {
2735
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2736
+	}
2737
+	if (!db_version_check()) {
2738
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2739
+	}
2593 2740
 
2594 2741
 	// Do some checks to make sure they have proper privileges
2595 2742
 	db_extend('packages');
@@ -2604,34 +2751,39 @@  discard block
 block discarded – undo
2604 2751
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2605 2752
 
2606 2753
 	// Sorry... we need CREATE, ALTER and DROP
2607
-	if (!$create || !$alter || !$drop)
2608
-		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);
2754
+	if (!$create || !$alter || !$drop) {
2755
+			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);
2756
+	}
2609 2757
 
2610 2758
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2611 2759
 		&& @file_exists($sourcedir . '/QueryString.php')
2612 2760
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2613
-	if (!$check && !isset($modSettings['smfVersion']))
2614
-		print_error('Error: Some files are missing or out-of-date.', true);
2761
+	if (!$check && !isset($modSettings['smfVersion'])) {
2762
+			print_error('Error: Some files are missing or out-of-date.', true);
2763
+	}
2615 2764
 
2616 2765
 	// Do a quick version spot check.
2617 2766
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2618 2767
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2619
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2620
-		print_error('Error: Some files have not yet been updated properly.');
2768
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2769
+			print_error('Error: Some files have not yet been updated properly.');
2770
+	}
2621 2771
 
2622 2772
 	// Make sure Settings.php is writable.
2623 2773
 		quickFileWritable($boarddir . '/Settings.php');
2624
-	if (!is_writable($boarddir . '/Settings.php'))
2625
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2774
+	if (!is_writable($boarddir . '/Settings.php')) {
2775
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2776
+	}
2626 2777
 
2627 2778
 	// Make sure Settings_bak.php is writable.
2628 2779
 		quickFileWritable($boarddir . '/Settings_bak.php');
2629
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2630
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2780
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2781
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2782
+	}
2631 2783
 
2632
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2633
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2634
-	elseif (isset($modSettings['agreement']))
2784
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2785
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2786
+	} elseif (isset($modSettings['agreement']))
2635 2787
 	{
2636 2788
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2637 2789
 		fwrite($fp, $modSettings['agreement']);
@@ -2641,31 +2793,36 @@  discard block
 block discarded – undo
2641 2793
 	// Make sure Themes is writable.
2642 2794
 	quickFileWritable($modSettings['theme_dir']);
2643 2795
 
2644
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2645
-		print_error('Error: Unable to obtain write access to "Themes".');
2796
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2797
+			print_error('Error: Unable to obtain write access to "Themes".');
2798
+	}
2646 2799
 
2647 2800
 	// Make sure cache directory exists and is writable!
2648 2801
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2649
-	if (!file_exists($cachedir_temp))
2650
-		@mkdir($cachedir_temp);
2802
+	if (!file_exists($cachedir_temp)) {
2803
+			@mkdir($cachedir_temp);
2804
+	}
2651 2805
 
2652 2806
 	// Make sure the cache temp dir is writable.
2653 2807
 	quickFileWritable($cachedir_temp);
2654 2808
 
2655
-	if (!is_writable($cachedir_temp))
2656
-		print_error('Error: Unable to obtain write access to "cache".', true);
2809
+	if (!is_writable($cachedir_temp)) {
2810
+			print_error('Error: Unable to obtain write access to "cache".', true);
2811
+	}
2657 2812
 
2658
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2659
-		print_error('Error: Unable to find language files!', true);
2660
-	else
2813
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2814
+			print_error('Error: Unable to find language files!', true);
2815
+	} else
2661 2816
 	{
2662 2817
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2663 2818
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2664 2819
 
2665
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2666
-			print_error('Error: Language files out of date.', true);
2667
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2668
-			print_error('Error: Install language is missing for selected language.', true);
2820
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2821
+					print_error('Error: Language files out of date.', true);
2822
+		}
2823
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2824
+					print_error('Error: Install language is missing for selected language.', true);
2825
+		}
2669 2826
 
2670 2827
 		// Otherwise include it!
2671 2828
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2680,14 +2837,16 @@  discard block
 block discarded – undo
2680 2837
 {
2681 2838
 	static $fp = null;
2682 2839
 
2683
-	if ($fp === null)
2684
-		$fp = fopen('php://stderr', 'wb');
2840
+	if ($fp === null) {
2841
+			$fp = fopen('php://stderr', 'wb');
2842
+	}
2685 2843
 
2686 2844
 	fwrite($fp, $message . "\n");
2687 2845
 
2688
-	if ($fatal)
2689
-		exit;
2690
-}
2846
+	if ($fatal) {
2847
+			exit;
2848
+	}
2849
+	}
2691 2850
 
2692 2851
 function throw_error($message)
2693 2852
 {
@@ -2704,8 +2863,9 @@  discard block
 block discarded – undo
2704 2863
 {
2705 2864
 	global $upcontext, $boarddir;
2706 2865
 
2707
-	if (empty($files))
2708
-		return true;
2866
+	if (empty($files)) {
2867
+			return true;
2868
+	}
2709 2869
 
2710 2870
 	$failure = false;
2711 2871
 	// On linux, it's easy - just use is_writable!
@@ -2720,14 +2880,16 @@  discard block
 block discarded – undo
2720 2880
 				@chmod($file, 0755);
2721 2881
 
2722 2882
 				// Well, 755 hopefully worked... if not, try 777.
2723
-				if (!is_writable($file) && !@chmod($file, 0777))
2724
-					$failure = true;
2883
+				if (!is_writable($file) && !@chmod($file, 0777)) {
2884
+									$failure = true;
2885
+				}
2725 2886
 				// Otherwise remove it as it's good!
2726
-				else
2727
-					unset($files[$k]);
2887
+				else {
2888
+									unset($files[$k]);
2889
+				}
2890
+			} else {
2891
+							unset($files[$k]);
2728 2892
 			}
2729
-			else
2730
-				unset($files[$k]);
2731 2893
 		}
2732 2894
 	}
2733 2895
 	// Windows is trickier.  Let's try opening for r+...
@@ -2738,30 +2900,35 @@  discard block
 block discarded – undo
2738 2900
 		foreach ($files as $k => $file)
2739 2901
 		{
2740 2902
 			// Folders can't be opened for write... but the index.php in them can ;).
2741
-			if (is_dir($file))
2742
-				$file .= '/index.php';
2903
+			if (is_dir($file)) {
2904
+							$file .= '/index.php';
2905
+			}
2743 2906
 
2744 2907
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
2745 2908
 			@chmod($file, 0777);
2746 2909
 			$fp = @fopen($file, 'r+');
2747 2910
 
2748 2911
 			// Hmm, okay, try just for write in that case...
2749
-			if (!$fp)
2750
-				$fp = @fopen($file, 'w');
2912
+			if (!$fp) {
2913
+							$fp = @fopen($file, 'w');
2914
+			}
2751 2915
 
2752
-			if (!$fp)
2753
-				$failure = true;
2754
-			else
2755
-				unset($files[$k]);
2916
+			if (!$fp) {
2917
+							$failure = true;
2918
+			} else {
2919
+							unset($files[$k]);
2920
+			}
2756 2921
 			@fclose($fp);
2757 2922
 		}
2758 2923
 	}
2759 2924
 
2760
-	if (empty($files))
2761
-		return true;
2925
+	if (empty($files)) {
2926
+			return true;
2927
+	}
2762 2928
 
2763
-	if (!isset($_SERVER))
2764
-		return !$failure;
2929
+	if (!isset($_SERVER)) {
2930
+			return !$failure;
2931
+	}
2765 2932
 
2766 2933
 	// What still needs to be done?
2767 2934
 	$upcontext['chmod']['files'] = $files;
@@ -2812,36 +2979,40 @@  discard block
 block discarded – undo
2812 2979
 
2813 2980
 		if (!isset($ftp) || $ftp->error !== false)
2814 2981
 		{
2815
-			if (!isset($ftp))
2816
-				$ftp = new ftp_connection(null);
2982
+			if (!isset($ftp)) {
2983
+							$ftp = new ftp_connection(null);
2984
+			}
2817 2985
 			// Save the error so we can mess with listing...
2818
-			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error']))
2819
-				$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
2986
+			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) {
2987
+							$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
2988
+			}
2820 2989
 
2821 2990
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
2822 2991
 
2823
-			if ($found_path || !isset($upcontext['chmod']['path']))
2824
-				$upcontext['chmod']['path'] = $detect_path;
2992
+			if ($found_path || !isset($upcontext['chmod']['path'])) {
2993
+							$upcontext['chmod']['path'] = $detect_path;
2994
+			}
2825 2995
 
2826
-			if (!isset($upcontext['chmod']['username']))
2827
-				$upcontext['chmod']['username'] = $username;
2996
+			if (!isset($upcontext['chmod']['username'])) {
2997
+							$upcontext['chmod']['username'] = $username;
2998
+			}
2828 2999
 
2829 3000
 			// Don't forget the login token.
2830 3001
 			$upcontext += createToken('login');
2831 3002
 
2832 3003
 			return false;
2833
-		}
2834
-		else
3004
+		} else
2835 3005
 		{
2836 3006
 			// We want to do a relative path for FTP.
2837 3007
 			if (!in_array($upcontext['chmod']['path'], array('', '/')))
2838 3008
 			{
2839 3009
 				$ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => ''));
2840
-				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/'))
2841
-				$ftp_root = substr($ftp_root, 0, -1);
3010
+				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) {
3011
+								$ftp_root = substr($ftp_root, 0, -1);
3012
+				}
3013
+			} else {
3014
+							$ftp_root = $boarddir;
2842 3015
 			}
2843
-			else
2844
-				$ftp_root = $boarddir;
2845 3016
 
2846 3017
 			// Save the info for next time!
2847 3018
 			$_SESSION['installer_temp_ftp'] = array(
@@ -2855,10 +3026,12 @@  discard block
 block discarded – undo
2855 3026
 
2856 3027
 			foreach ($files as $k => $file)
2857 3028
 			{
2858
-				if (!is_writable($file))
2859
-					$ftp->chmod($file, 0755);
2860
-				if (!is_writable($file))
2861
-					$ftp->chmod($file, 0777);
3029
+				if (!is_writable($file)) {
3030
+									$ftp->chmod($file, 0755);
3031
+				}
3032
+				if (!is_writable($file)) {
3033
+									$ftp->chmod($file, 0777);
3034
+				}
2862 3035
 
2863 3036
 				// Assuming that didn't work calculate the path without the boarddir.
2864 3037
 				if (!is_writable($file))
@@ -2867,19 +3040,23 @@  discard block
 block discarded – undo
2867 3040
 					{
2868 3041
 						$ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => ''));
2869 3042
 						$ftp->chmod($ftp_file, 0755);
2870
-						if (!is_writable($file))
2871
-							$ftp->chmod($ftp_file, 0777);
3043
+						if (!is_writable($file)) {
3044
+													$ftp->chmod($ftp_file, 0777);
3045
+						}
2872 3046
 						// Sometimes an extra slash can help...
2873 3047
 						$ftp_file = '/' . $ftp_file;
2874
-						if (!is_writable($file))
2875
-							$ftp->chmod($ftp_file, 0755);
2876
-						if (!is_writable($file))
2877
-							$ftp->chmod($ftp_file, 0777);
3048
+						if (!is_writable($file)) {
3049
+													$ftp->chmod($ftp_file, 0755);
3050
+						}
3051
+						if (!is_writable($file)) {
3052
+													$ftp->chmod($ftp_file, 0777);
3053
+						}
2878 3054
 					}
2879 3055
 				}
2880 3056
 
2881
-				if (is_writable($file))
2882
-					unset($files[$k]);
3057
+				if (is_writable($file)) {
3058
+									unset($files[$k]);
3059
+				}
2883 3060
 			}
2884 3061
 
2885 3062
 			$ftp->close();
@@ -2889,16 +3066,18 @@  discard block
 block discarded – undo
2889 3066
 	// What remains?
2890 3067
 	$upcontext['chmod']['files'] = $files;
2891 3068
 
2892
-	if (empty($files))
2893
-		return true;
3069
+	if (empty($files)) {
3070
+			return true;
3071
+	}
2894 3072
 
2895 3073
 	return false;
2896 3074
 }
2897 3075
 
2898 3076
 function quickFileWritable($file)
2899 3077
 {
2900
-	if (is_writable($file))
2901
-		return true;
3078
+	if (is_writable($file)) {
3079
+			return true;
3080
+	}
2902 3081
 
2903 3082
 	@chmod($file, 0755);
2904 3083
 
@@ -2908,17 +3087,19 @@  discard block
 block discarded – undo
2908 3087
 	foreach ($chmod_values as $val)
2909 3088
 	{
2910 3089
 		// If it's writable, break out of the loop
2911
-		if (is_writable($file))
2912
-			break;
2913
-		else
2914
-			@chmod($file, $val);
3090
+		if (is_writable($file)) {
3091
+					break;
3092
+		} else {
3093
+					@chmod($file, $val);
3094
+		}
2915 3095
 	}
2916 3096
 }
2917 3097
 function smf_strtolower($string)
2918 3098
 {
2919 3099
 	global $sourcedir;
2920
-	if (function_exists('mb_strtolower'))
2921
-		return mb_strtolower($string, 'UTF-8');
3100
+	if (function_exists('mb_strtolower')) {
3101
+			return mb_strtolower($string, 'UTF-8');
3102
+	}
2922 3103
 	require_once($sourcedir . '/Subs-Charset.php');
2923 3104
 	return utf8_strtolower($string);
2924 3105
 }
@@ -2941,8 +3122,7 @@  discard block
 block discarded – undo
2941 3122
 		);
2942 3123
 		
2943 3124
 		return true;
2944
-	}
2945
-	else
3125
+	} else
2946 3126
 	{
2947 3127
 		$upcontext['page_title'] = 'Converting to UTF8';
2948 3128
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2986,8 +3166,9 @@  discard block
 block discarded – undo
2986 3166
 			)
2987 3167
 		);
2988 3168
 		$db_charsets = array();
2989
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2990
-			$db_charsets[] = $row['Charset'];
3169
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3170
+					$db_charsets[] = $row['Charset'];
3171
+		}
2991 3172
 
2992 3173
 		$smcFunc['db_free_result']($request);
2993 3174
 
@@ -3023,13 +3204,15 @@  discard block
 block discarded – undo
3023 3204
 		// If there's a fulltext index, we need to drop it first...
3024 3205
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
3025 3206
 		{
3026
-			while ($row = $smcFunc['db_fetch_assoc']($request))
3027
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
3207
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
3208
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
3028 3209
 					$upcontext['fulltext_index'][] = $row['Key_name'];
3210
+			}
3029 3211
 			$smcFunc['db_free_result']($request);
3030 3212
 
3031
-			if (isset($upcontext['fulltext_index']))
3032
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
3213
+			if (isset($upcontext['fulltext_index'])) {
3214
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
3215
+			}
3033 3216
 		}
3034 3217
 
3035 3218
 		// Drop it and make a note...
@@ -3219,8 +3402,9 @@  discard block
 block discarded – undo
3219 3402
 			$replace = '%field%';
3220 3403
 
3221 3404
 			// Build a huge REPLACE statement...
3222
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
3223
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3405
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
3406
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3407
+			}
3224 3408
 		}
3225 3409
 
3226 3410
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -3253,8 +3437,9 @@  discard block
 block discarded – undo
3253 3437
 			$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3254 3438
 
3255 3439
 			// Just to make sure it doesn't time out.
3256
-			if (function_exists('apache_reset_timeout'))
3257
-				@apache_reset_timeout();
3440
+			if (function_exists('apache_reset_timeout')) {
3441
+							@apache_reset_timeout();
3442
+			}
3258 3443
 
3259 3444
 			$table_charsets = array();
3260 3445
 
@@ -3275,8 +3460,9 @@  discard block
 block discarded – undo
3275 3460
 					{
3276 3461
 						list($charset) = explode('_', $collation);
3277 3462
 
3278
-						if (!isset($table_charsets[$charset]))
3279
-							$table_charsets[$charset] = array();
3463
+						if (!isset($table_charsets[$charset])) {
3464
+													$table_charsets[$charset] = array();
3465
+						}
3280 3466
 
3281 3467
 						$table_charsets[$charset][] = $column_info;
3282 3468
 					}
@@ -3316,10 +3502,11 @@  discard block
 block discarded – undo
3316 3502
 				if (isset($translation_tables[$upcontext['charset_detected']]))
3317 3503
 				{
3318 3504
 					$update = '';
3319
-					foreach ($table_charsets as $charset => $columns)
3320
-						foreach ($columns as $column)
3505
+					foreach ($table_charsets as $charset => $columns) {
3506
+											foreach ($columns as $column)
3321 3507
 							$update .= '
3322 3508
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3509
+					}
3323 3510
 
3324 3511
 					$smcFunc['db_query']('', '
3325 3512
 						UPDATE {raw:table_name}
@@ -3344,8 +3531,9 @@  discard block
 block discarded – undo
3344 3531
 			// Now do the actual conversion (if still needed).
3345 3532
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
3346 3533
 			{
3347
-				if ($command_line)
3348
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3534
+				if ($command_line) {
3535
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3536
+				}
3349 3537
 
3350 3538
 				$smcFunc['db_query']('', '
3351 3539
 					ALTER TABLE {raw:table_name}
@@ -3355,8 +3543,9 @@  discard block
 block discarded – undo
3355 3543
 						)
3356 3544
 				);
3357 3545
 
3358
-				if ($command_line)
3359
-					echo " done.\n";
3546
+				if ($command_line) {
3547
+									echo " done.\n";
3548
+				}
3360 3549
 			}
3361 3550
 		}
3362 3551
 
@@ -3386,8 +3575,8 @@  discard block
 block discarded – undo
3386 3575
 		);
3387 3576
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3388 3577
 		{
3389
-			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)
3390
-				$smcFunc['db_query']('', '
3578
+			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) {
3579
+							$smcFunc['db_query']('', '
3391 3580
 					UPDATE {db_prefix}log_actions
3392 3581
 					SET extra = {string:extra}
3393 3582
 					WHERE id_action = {int:current_action}',
@@ -3396,6 +3585,7 @@  discard block
 block discarded – undo
3396 3585
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
3397 3586
 					)
3398 3587
 				);
3588
+			}
3399 3589
 		}
3400 3590
 		$smcFunc['db_free_result']($request);
3401 3591
 
@@ -3417,15 +3607,17 @@  discard block
 block discarded – undo
3417 3607
 	// First thing's first - did we already do this?
3418 3608
 	if (!empty($modSettings['json_done']))
3419 3609
 	{
3420
-		if ($command_line)
3421
-			return DeleteUpgrade();
3422
-		else
3423
-			return true;
3610
+		if ($command_line) {
3611
+					return DeleteUpgrade();
3612
+		} else {
3613
+					return true;
3614
+		}
3424 3615
 	}
3425 3616
 
3426 3617
 	// Done it already - js wise?
3427
-	if (!empty($_POST['json_done']))
3428
-		return true;
3618
+	if (!empty($_POST['json_done'])) {
3619
+			return true;
3620
+	}
3429 3621
 
3430 3622
 	// List of tables affected by this function
3431 3623
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3456,12 +3648,14 @@  discard block
 block discarded – undo
3456 3648
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3457 3649
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3458 3650
 
3459
-	foreach ($keys as $id => $table)
3460
-		if ($id < $_GET['substep'])
3651
+	foreach ($keys as $id => $table) {
3652
+			if ($id < $_GET['substep'])
3461 3653
 			$upcontext['previous_tables'][] = $table;
3654
+	}
3462 3655
 
3463
-	if ($command_line)
3464
-		echo 'Converting data from serialize() to json_encode().';
3656
+	if ($command_line) {
3657
+			echo 'Converting data from serialize() to json_encode().';
3658
+	}
3465 3659
 
3466 3660
 	if (!$support_js || isset($_GET['xml']))
3467 3661
 	{
@@ -3501,8 +3695,9 @@  discard block
 block discarded – undo
3501 3695
 
3502 3696
 				// Loop through and fix these...
3503 3697
 				$new_settings = array();
3504
-				if ($command_line)
3505
-					echo "\n" . 'Fixing some settings...';
3698
+				if ($command_line) {
3699
+									echo "\n" . 'Fixing some settings...';
3700
+				}
3506 3701
 
3507 3702
 				foreach ($serialized_settings as $var)
3508 3703
 				{
@@ -3510,22 +3705,24 @@  discard block
 block discarded – undo
3510 3705
 					{
3511 3706
 						// Attempt to unserialize the setting
3512 3707
 						$temp = @safe_unserialize($modSettings[$var]);
3513
-						if (!$temp && $command_line)
3514
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3515
-						elseif ($temp !== false)
3516
-							$new_settings[$var] = json_encode($temp);
3708
+						if (!$temp && $command_line) {
3709
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3710
+						} elseif ($temp !== false) {
3711
+													$new_settings[$var] = json_encode($temp);
3712
+						}
3517 3713
 					}
3518 3714
 				}
3519 3715
 
3520 3716
 				// Update everything at once
3521
-				if (!function_exists('cache_put_data'))
3522
-					require_once($sourcedir . '/Load.php');
3717
+				if (!function_exists('cache_put_data')) {
3718
+									require_once($sourcedir . '/Load.php');
3719
+				}
3523 3720
 				updateSettings($new_settings, true);
3524 3721
 
3525
-				if ($command_line)
3526
-					echo ' done.';
3527
-			}
3528
-			elseif ($table == 'themes')
3722
+				if ($command_line) {
3723
+									echo ' done.';
3724
+				}
3725
+			} elseif ($table == 'themes')
3529 3726
 			{
3530 3727
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3531 3728
 				$query = $smcFunc['db_query']('', '
@@ -3544,10 +3741,11 @@  discard block
 block discarded – undo
3544 3741
 
3545 3742
 						if ($command_line)
3546 3743
 						{
3547
-							if ($temp === false)
3548
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3549
-							else
3550
-								echo "\n" . 'Fixing admin preferences...';
3744
+							if ($temp === false) {
3745
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3746
+							} else {
3747
+															echo "\n" . 'Fixing admin preferences...';
3748
+							}
3551 3749
 						}
3552 3750
 
3553 3751
 						if ($temp !== false)
@@ -3567,15 +3765,15 @@  discard block
 block discarded – undo
3567 3765
 								)
3568 3766
 							);
3569 3767
 
3570
-							if ($command_line)
3571
-								echo ' done.';
3768
+							if ($command_line) {
3769
+															echo ' done.';
3770
+							}
3572 3771
 						}
3573 3772
 					}
3574 3773
 
3575 3774
 					$smcFunc['db_free_result']($query);
3576 3775
 				}
3577
-			}
3578
-			else
3776
+			} else
3579 3777
 			{
3580 3778
 				// First item is always the key...
3581 3779
 				$key = $info[0];
@@ -3586,8 +3784,7 @@  discard block
 block discarded – undo
3586 3784
 				{
3587 3785
 					$col_select = $info[1];
3588 3786
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3589
-				}
3590
-				else
3787
+				} else
3591 3788
 				{
3592 3789
 					$col_select = implode(', ', $info);
3593 3790
 				}
@@ -3620,8 +3817,7 @@  discard block
 block discarded – undo
3620 3817
 								if ($temp === false && $command_line)
3621 3818
 								{
3622 3819
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3623
-								}
3624
-								else
3820
+								} else
3625 3821
 								{
3626 3822
 									$row[$col] = json_encode($temp);
3627 3823
 
@@ -3646,16 +3842,18 @@  discard block
 block discarded – undo
3646 3842
 						}
3647 3843
 					}
3648 3844
 
3649
-					if ($command_line)
3650
-						echo ' done.';
3845
+					if ($command_line) {
3846
+											echo ' done.';
3847
+					}
3651 3848
 
3652 3849
 					// Free up some memory...
3653 3850
 					$smcFunc['db_free_result']($query);
3654 3851
 				}
3655 3852
 			}
3656 3853
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3657
-			if (isset($_GET['xml']))
3658
-				return upgradeExit();
3854
+			if (isset($_GET['xml'])) {
3855
+							return upgradeExit();
3856
+			}
3659 3857
 		}
3660 3858
 
3661 3859
 		if ($command_line)
@@ -3670,8 +3868,9 @@  discard block
 block discarded – undo
3670 3868
 
3671 3869
 		$_GET['substep'] = 0;
3672 3870
 		// Make sure we move on!
3673
-		if ($command_line)
3674
-			return DeleteUpgrade();
3871
+		if ($command_line) {
3872
+					return DeleteUpgrade();
3873
+		}
3675 3874
 
3676 3875
 		return true;
3677 3876
 	}
@@ -3691,14 +3890,16 @@  discard block
 block discarded – undo
3691 3890
 	global $upcontext, $txt, $settings;
3692 3891
 
3693 3892
 	// Don't call me twice!
3694
-	if (!empty($upcontext['chmod_called']))
3695
-		return;
3893
+	if (!empty($upcontext['chmod_called'])) {
3894
+			return;
3895
+	}
3696 3896
 
3697 3897
 	$upcontext['chmod_called'] = true;
3698 3898
 
3699 3899
 	// Nothing?
3700
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3701
-		return;
3900
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3901
+			return;
3902
+	}
3702 3903
 
3703 3904
 	// Was it a problem with Windows?
3704 3905
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3730,11 +3931,12 @@  discard block
 block discarded – undo
3730 3931
 					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\');
3731 3932
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3732 3933
 
3733
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3734
-		echo '
3934
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3935
+			echo '
3735 3936
 					content.write(\'<hr>\n\t\t\t\');
3736 3937
 					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\');
3737 3938
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3939
+	}
3738 3940
 
3739 3941
 	echo '
3740 3942
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3742,17 +3944,19 @@  discard block
 block discarded – undo
3742 3944
 				}
3743 3945
 		</script>';
3744 3946
 
3745
-	if (!empty($upcontext['chmod']['ftp_error']))
3746
-		echo '
3947
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3948
+			echo '
3747 3949
 			<div class="error_message red">
3748 3950
 				The following error was encountered when trying to connect:<br><br>
3749 3951
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3750 3952
 			</div>
3751 3953
 			<br>';
3954
+	}
3752 3955
 
3753
-	if (empty($upcontext['chmod_in_form']))
3754
-		echo '
3956
+	if (empty($upcontext['chmod_in_form'])) {
3957
+			echo '
3755 3958
 	<form action="', $upcontext['form_url'], '" method="post">';
3959
+	}
3756 3960
 
3757 3961
 	echo '
3758 3962
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3787,10 +3991,11 @@  discard block
 block discarded – undo
3787 3991
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3788 3992
 	</div>';
3789 3993
 
3790
-	if (empty($upcontext['chmod_in_form']))
3791
-		echo '
3994
+	if (empty($upcontext['chmod_in_form'])) {
3995
+			echo '
3792 3996
 	</form>';
3793
-}
3997
+	}
3998
+	}
3794 3999
 
3795 4000
 function template_upgrade_above()
3796 4001
 {
@@ -3850,9 +4055,10 @@  discard block
 block discarded – undo
3850 4055
 				<h2>', $txt['upgrade_progress'], '</h2>
3851 4056
 				<ul>';
3852 4057
 
3853
-	foreach ($upcontext['steps'] as $num => $step)
3854
-		echo '
4058
+	foreach ($upcontext['steps'] as $num => $step) {
4059
+			echo '
3855 4060
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
4061
+	}
3856 4062
 
3857 4063
 	echo '
3858 4064
 					</ul>
@@ -3865,8 +4071,8 @@  discard block
 block discarded – undo
3865 4071
 				</div>
3866 4072
 			</div>';
3867 4073
 
3868
-	if (isset($upcontext['step_progress']))
3869
-		echo '
4074
+	if (isset($upcontext['step_progress'])) {
4075
+			echo '
3870 4076
 				<br>
3871 4077
 				<br>
3872 4078
 				<div id="progress_bar_step">
@@ -3875,6 +4081,7 @@  discard block
 block discarded – undo
3875 4081
 						<span>', $txt['upgrade_step_progress'], '</span>
3876 4082
 					</div>
3877 4083
 				</div>';
4084
+	}
3878 4085
 
3879 4086
 	echo '
3880 4087
 				<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>
@@ -3905,32 +4112,36 @@  discard block
 block discarded – undo
3905 4112
 {
3906 4113
 	global $upcontext, $txt;
3907 4114
 
3908
-	if (!empty($upcontext['pause']))
3909
-		echo '
4115
+	if (!empty($upcontext['pause'])) {
4116
+			echo '
3910 4117
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3911 4118
 
3912 4119
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3913 4120
 								<h3>
3914 4121
 									', $txt['upgrade_paused_overload'], '
3915 4122
 								</h3>';
4123
+	}
3916 4124
 
3917
-	if (!empty($upcontext['custom_warning']))
3918
-		echo '
4125
+	if (!empty($upcontext['custom_warning'])) {
4126
+			echo '
3919 4127
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3920 4128
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3921 4129
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3922 4130
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3923 4131
 								</div>';
4132
+	}
3924 4133
 
3925 4134
 	echo '
3926 4135
 								<div class="righttext" style="margin: 1ex;">';
3927 4136
 
3928
-	if (!empty($upcontext['continue']))
3929
-		echo '
4137
+	if (!empty($upcontext['continue'])) {
4138
+			echo '
3930 4139
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3931
-	if (!empty($upcontext['skip']))
3932
-		echo '
4140
+	}
4141
+	if (!empty($upcontext['skip'])) {
4142
+			echo '
3933 4143
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
4144
+	}
3934 4145
 
3935 4146
 	echo '
3936 4147
 								</div>
@@ -3980,11 +4191,12 @@  discard block
 block discarded – undo
3980 4191
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3981 4192
 	<smf>';
3982 4193
 
3983
-	if (!empty($upcontext['get_data']))
3984
-		foreach ($upcontext['get_data'] as $k => $v)
4194
+	if (!empty($upcontext['get_data'])) {
4195
+			foreach ($upcontext['get_data'] as $k => $v)
3985 4196
 			echo '
3986 4197
 		<get key="', $k, '">', $v, '</get>';
3987
-}
4198
+	}
4199
+	}
3988 4200
 
3989 4201
 function template_xml_below()
3990 4202
 {
@@ -4025,8 +4237,8 @@  discard block
 block discarded – undo
4025 4237
 	template_chmod();
4026 4238
 
4027 4239
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
4028
-	if ($upcontext['is_large_forum'])
4029
-		echo '
4240
+	if ($upcontext['is_large_forum']) {
4241
+			echo '
4030 4242
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
4031 4243
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
4032 4244
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -4034,10 +4246,11 @@  discard block
 block discarded – undo
4034 4246
 				', $txt['upgrade_warning_lots_data'], '
4035 4247
 			</div>
4036 4248
 		</div>';
4249
+	}
4037 4250
 
4038 4251
 	// A warning message?
4039
-	if (!empty($upcontext['warning']))
4040
-		echo '
4252
+	if (!empty($upcontext['warning'])) {
4253
+			echo '
4041 4254
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
4042 4255
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
4043 4256
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -4045,6 +4258,7 @@  discard block
 block discarded – undo
4045 4258
 				', $upcontext['warning'], '
4046 4259
 			</div>
4047 4260
 		</div>';
4261
+	}
4048 4262
 
4049 4263
 	// Paths are incorrect?
4050 4264
 	echo '
@@ -4060,20 +4274,22 @@  discard block
 block discarded – undo
4060 4274
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
4061 4275
 	{
4062 4276
 		$ago = time() - $upcontext['started'];
4063
-		if ($ago < 60)
4064
-			$ago = $ago . ' seconds';
4065
-		elseif ($ago < 3600)
4066
-			$ago = (int) ($ago / 60) . ' minutes';
4067
-		else
4068
-			$ago = (int) ($ago / 3600) . ' hours';
4277
+		if ($ago < 60) {
4278
+					$ago = $ago . ' seconds';
4279
+		} elseif ($ago < 3600) {
4280
+					$ago = (int) ($ago / 60) . ' minutes';
4281
+		} else {
4282
+					$ago = (int) ($ago / 3600) . ' hours';
4283
+		}
4069 4284
 
4070 4285
 		$active = time() - $upcontext['updated'];
4071
-		if ($active < 60)
4072
-			$updated = $active . ' seconds';
4073
-		elseif ($active < 3600)
4074
-			$updated = (int) ($active / 60) . ' minutes';
4075
-		else
4076
-			$updated = (int) ($active / 3600) . ' hours';
4286
+		if ($active < 60) {
4287
+					$updated = $active . ' seconds';
4288
+		} elseif ($active < 3600) {
4289
+					$updated = (int) ($active / 60) . ' minutes';
4290
+		} else {
4291
+					$updated = (int) ($active / 3600) . ' hours';
4292
+		}
4077 4293
 
4078 4294
 		echo '
4079 4295
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -4082,16 +4298,18 @@  discard block
 block discarded – undo
4082 4298
 			<div style="padding-left: 6ex;">
4083 4299
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
4084 4300
 
4085
-		if ($active < 600)
4086
-			echo '
4301
+		if ($active < 600) {
4302
+					echo '
4087 4303
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
4304
+		}
4088 4305
 
4089
-		if ($active > $upcontext['inactive_timeout'])
4090
-			echo '
4306
+		if ($active > $upcontext['inactive_timeout']) {
4307
+					echo '
4091 4308
 				<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.';
4092
-		else
4093
-			echo '
4309
+		} else {
4310
+					echo '
4094 4311
 				<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!');
4312
+		}
4095 4313
 
4096 4314
 		echo '
4097 4315
 			</div>
@@ -4107,9 +4325,10 @@  discard block
 block discarded – undo
4107 4325
 					<td>
4108 4326
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
4109 4327
 
4110
-	if (!empty($upcontext['username_incorrect']))
4111
-		echo '
4328
+	if (!empty($upcontext['username_incorrect'])) {
4329
+			echo '
4112 4330
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
4331
+	}
4113 4332
 
4114 4333
 	echo '
4115 4334
 					</td>
@@ -4120,9 +4339,10 @@  discard block
 block discarded – undo
4120 4339
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
4121 4340
 						<input type="hidden" name="hash_passwrd" value="">';
4122 4341
 
4123
-	if (!empty($upcontext['password_failed']))
4124
-		echo '
4342
+	if (!empty($upcontext['password_failed'])) {
4343
+			echo '
4125 4344
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
4345
+	}
4126 4346
 
4127 4347
 	echo '
4128 4348
 					</td>
@@ -4193,8 +4413,8 @@  discard block
 block discarded – undo
4193 4413
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
4194 4414
 
4195 4415
 	// Warning message?
4196
-	if (!empty($upcontext['upgrade_options_warning']))
4197
-		echo '
4416
+	if (!empty($upcontext['upgrade_options_warning'])) {
4417
+			echo '
4198 4418
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
4199 4419
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
4200 4420
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -4202,6 +4422,7 @@  discard block
 block discarded – undo
4202 4422
 				', $upcontext['upgrade_options_warning'], '
4203 4423
 			</div>
4204 4424
 		</div>';
4425
+	}
4205 4426
 
4206 4427
 	echo '
4207 4428
 				<table>
@@ -4229,8 +4450,8 @@  discard block
 block discarded – undo
4229 4450
 					</tr>';
4230 4451
 
4231 4452
 	// Offer mysql users to switch to mysqli
4232
-	if ($db_type == 'mysql' && function_exists('mysqli_query'))
4233
-		echo '
4453
+	if ($db_type == 'mysql' && function_exists('mysqli_query')) {
4454
+			echo '
4234 4455
 					<tr valign="top">
4235 4456
 						<td width="2%">
4236 4457
 							<input type="checkbox" name="convertMysql" id="convertMysql" value="1" checked class="input_check">
@@ -4240,6 +4461,7 @@  discard block
 block discarded – undo
4240 4461
 							<strong class="smalltext"><a href="http://wiki.simplemachines.org/smf/Upgrading-MySQLi-Functionality" target="_blank">More information about MySQLi</a></strong><br>
4241 4462
 						</td>
4242 4463
 					</tr>';
4464
+	}
4243 4465
 
4244 4466
 	echo '
4245 4467
 					<tr valign="top">
@@ -4259,8 +4481,8 @@  discard block
 block discarded – undo
4259 4481
 						</td>
4260 4482
 					</tr>';
4261 4483
 
4262
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
4263
-		echo '
4484
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4485
+			echo '
4264 4486
 					<tr valign="top">
4265 4487
 						<td width="2%">
4266 4488
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -4269,6 +4491,7 @@  discard block
 block discarded – undo
4269 4491
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
4270 4492
 						</td>
4271 4493
 					</tr>';
4494
+	}
4272 4495
 
4273 4496
 	echo '
4274 4497
 					<tr valign="top">
@@ -4304,10 +4527,11 @@  discard block
 block discarded – undo
4304 4527
 			<span id="debuginfo"></span>';
4305 4528
 
4306 4529
 	// Dont any tables so far?
4307
-	if (!empty($upcontext['previous_tables']))
4308
-		foreach ($upcontext['previous_tables'] as $table)
4530
+	if (!empty($upcontext['previous_tables'])) {
4531
+			foreach ($upcontext['previous_tables'] as $table)
4309 4532
 			echo '
4310 4533
 			<br>Completed Table: &quot;', $table, '&quot;.';
4534
+	}
4311 4535
 
4312 4536
 	echo '
4313 4537
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -4344,12 +4568,13 @@  discard block
 block discarded – undo
4344 4568
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4345 4569
 
4346 4570
 		// If debug flood the screen.
4347
-		if ($is_debug)
4348
-			echo '
4571
+		if ($is_debug) {
4572
+					echo '
4349 4573
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4350 4574
 
4351 4575
 				if (document.getElementById(\'debuginfo\').scrollHeight)
4352 4576
 					document.getElementById(\'debuginfo\').scrollTop = document.getElementById(\'debuginfo\').scrollHeight;';
4577
+		}
4353 4578
 
4354 4579
 		echo '
4355 4580
 				// Get the next update...
@@ -4381,8 +4606,9 @@  discard block
 block discarded – undo
4381 4606
 {
4382 4607
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
4383 4608
 
4384
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
4385
-		$is_debug = true;
4609
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4610
+			$is_debug = true;
4611
+	}
4386 4612
 
4387 4613
 	echo '
4388 4614
 		<h3>Executing database changes</h3>
@@ -4397,8 +4623,9 @@  discard block
 block discarded – undo
4397 4623
 	{
4398 4624
 		foreach ($upcontext['actioned_items'] as $num => $item)
4399 4625
 		{
4400
-			if ($num != 0)
4401
-				echo ' Successful!';
4626
+			if ($num != 0) {
4627
+							echo ' Successful!';
4628
+			}
4402 4629
 			echo '<br>' . $item;
4403 4630
 		}
4404 4631
 		if (!empty($upcontext['changes_complete']))
@@ -4411,28 +4638,32 @@  discard block
 block discarded – undo
4411 4638
 				$seconds = intval($active % 60);
4412 4639
 
4413 4640
 				$totalTime = '';
4414
-				if ($hours > 0)
4415
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4416
-				if ($minutes > 0)
4417
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4418
-				if ($seconds > 0)
4419
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4641
+				if ($hours > 0) {
4642
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4643
+				}
4644
+				if ($minutes > 0) {
4645
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4646
+				}
4647
+				if ($seconds > 0) {
4648
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4649
+				}
4420 4650
 			}
4421 4651
 
4422
-			if ($is_debug && !empty($totalTime))
4423
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
4424
-			else
4425
-				echo ' Successful!<br><br>';
4652
+			if ($is_debug && !empty($totalTime)) {
4653
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4654
+			} else {
4655
+							echo ' Successful!<br><br>';
4656
+			}
4426 4657
 
4427 4658
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
4428 4659
 		}
4429
-	}
4430
-	else
4660
+	} else
4431 4661
 	{
4432 4662
 		// Tell them how many files we have in total.
4433
-		if ($upcontext['file_count'] > 1)
4434
-			echo '
4663
+		if ($upcontext['file_count'] > 1) {
4664
+					echo '
4435 4665
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4666
+		}
4436 4667
 
4437 4668
 		echo '
4438 4669
 		<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>
@@ -4448,19 +4679,23 @@  discard block
 block discarded – undo
4448 4679
 				$seconds = intval($active % 60);
4449 4680
 
4450 4681
 				$totalTime = '';
4451
-				if ($hours > 0)
4452
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4453
-				if ($minutes > 0)
4454
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4455
-				if ($seconds > 0)
4456
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4682
+				if ($hours > 0) {
4683
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4684
+				}
4685
+				if ($minutes > 0) {
4686
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4687
+				}
4688
+				if ($seconds > 0) {
4689
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4690
+				}
4457 4691
 			}
4458 4692
 
4459 4693
 			echo '
4460 4694
 			<br><span id="upgradeCompleted">';
4461 4695
 
4462
-			if (!empty($totalTime))
4463
-				echo 'Completed in ', $totalTime, '<br>';
4696
+			if (!empty($totalTime)) {
4697
+							echo 'Completed in ', $totalTime, '<br>';
4698
+			}
4464 4699
 
4465 4700
 			echo '</span>
4466 4701
 			<div id="debug_section" style="height: 200px; overflow: auto;">
@@ -4497,9 +4732,10 @@  discard block
 block discarded – undo
4497 4732
 			var getData = "";
4498 4733
 			var debugItems = ', $upcontext['debug_items'], ';';
4499 4734
 
4500
-		if ($is_debug)
4501
-			echo '
4735
+		if ($is_debug) {
4736
+					echo '
4502 4737
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4738
+		}
4503 4739
 
4504 4740
 		echo '
4505 4741
 			function getNextItem()
@@ -4539,9 +4775,10 @@  discard block
 block discarded – undo
4539 4775
 						document.getElementById("error_block").style.display = "";
4540 4776
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4541 4777
 
4542
-	if ($is_debug)
4543
-		echo '
4778
+	if ($is_debug) {
4779
+			echo '
4544 4780
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4781
+	}
4545 4782
 
4546 4783
 	echo '
4547 4784
 					}
@@ -4562,9 +4799,10 @@  discard block
 block discarded – undo
4562 4799
 						document.getElementById("error_block").style.display = "";
4563 4800
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4564 4801
 
4565
-	if ($is_debug)
4566
-		echo '
4802
+	if ($is_debug) {
4803
+			echo '
4567 4804
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4805
+	}
4568 4806
 
4569 4807
 	echo '
4570 4808
 					}
@@ -4623,8 +4861,8 @@  discard block
 block discarded – undo
4623 4861
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4624 4862
 				{';
4625 4863
 
4626
-		if ($is_debug)
4627
-			echo '
4864
+		if ($is_debug) {
4865
+					echo '
4628 4866
 					document.getElementById(\'debug_section\').style.display = "none";
4629 4867
 
4630 4868
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4642,6 +4880,7 @@  discard block
 block discarded – undo
4642 4880
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4643 4881
 
4644 4882
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4883
+		}
4645 4884
 
4646 4885
 		echo '
4647 4886
 
@@ -4649,9 +4888,10 @@  discard block
 block discarded – undo
4649 4888
 					document.getElementById(\'contbutt\').disabled = 0;
4650 4889
 					document.getElementById(\'database_done\').value = 1;';
4651 4890
 
4652
-		if ($upcontext['file_count'] > 1)
4653
-			echo '
4891
+		if ($upcontext['file_count'] > 1) {
4892
+					echo '
4654 4893
 					document.getElementById(\'info1\').style.display = "none";';
4894
+		}
4655 4895
 
4656 4896
 		echo '
4657 4897
 					document.getElementById(\'info2\').style.display = "none";
@@ -4664,9 +4904,10 @@  discard block
 block discarded – undo
4664 4904
 					lastItem = 0;
4665 4905
 					prevFile = curFile;';
4666 4906
 
4667
-		if ($is_debug)
4668
-			echo '
4907
+		if ($is_debug) {
4908
+					echo '
4669 4909
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4910
+		}
4670 4911
 
4671 4912
 		echo '
4672 4913
 					getNextItem();
@@ -4674,8 +4915,8 @@  discard block
 block discarded – undo
4674 4915
 				}';
4675 4916
 
4676 4917
 		// If debug scroll the screen.
4677
-		if ($is_debug)
4678
-			echo '
4918
+		if ($is_debug) {
4919
+					echo '
4679 4920
 				if (iLastSubStepProgress == -1)
4680 4921
 				{
4681 4922
 					// Give it consistent dots.
@@ -4694,6 +4935,7 @@  discard block
 block discarded – undo
4694 4935
 
4695 4936
 				if (document.getElementById(\'debug_section\').scrollHeight)
4696 4937
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4938
+		}
4697 4939
 
4698 4940
 		echo '
4699 4941
 				// Update the page.
@@ -4754,9 +4996,10 @@  discard block
 block discarded – undo
4754 4996
 			}';
4755 4997
 
4756 4998
 		// Start things off assuming we've not errored.
4757
-		if (empty($upcontext['error_message']))
4758
-			echo '
4999
+		if (empty($upcontext['error_message'])) {
5000
+					echo '
4759 5001
 			getNextItem();';
5002
+		}
4760 5003
 
4761 5004
 		echo '
4762 5005
 		</script>';
@@ -4773,18 +5016,21 @@  discard block
 block discarded – undo
4773 5016
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4774 5017
 	<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>';
4775 5018
 
4776
-	if (!empty($upcontext['error_message']))
4777
-		echo '
5019
+	if (!empty($upcontext['error_message'])) {
5020
+			echo '
4778 5021
 	<error>', $upcontext['error_message'], '</error>';
5022
+	}
4779 5023
 
4780
-	if (!empty($upcontext['error_string']))
4781
-		echo '
5024
+	if (!empty($upcontext['error_string'])) {
5025
+			echo '
4782 5026
 	<sql>', $upcontext['error_string'], '</sql>';
5027
+	}
4783 5028
 
4784
-	if ($is_debug)
4785
-		echo '
5029
+	if ($is_debug) {
5030
+			echo '
4786 5031
 	<curtime>', time(), '</curtime>';
4787
-}
5032
+	}
5033
+	}
4788 5034
 
4789 5035
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4790 5036
 function template_convert_utf8()
@@ -4801,18 +5047,20 @@  discard block
 block discarded – undo
4801 5047
 			<span id="debuginfo"></span>';
4802 5048
 
4803 5049
 	// Done any tables so far?
4804
-	if (!empty($upcontext['previous_tables']))
4805
-		foreach ($upcontext['previous_tables'] as $table)
5050
+	if (!empty($upcontext['previous_tables'])) {
5051
+			foreach ($upcontext['previous_tables'] as $table)
4806 5052
 			echo '
4807 5053
 			<br>Completed Table: &quot;', $table, '&quot;.';
5054
+	}
4808 5055
 
4809 5056
 	echo '
4810 5057
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4811 5058
 
4812 5059
 	// If we dropped their index, let's let them know
4813
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
4814
-		echo '
5060
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
5061
+			echo '
4815 5062
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
5063
+	}
4816 5064
 
4817 5065
 	echo '
4818 5066
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Conversion Complete! Click Continue to Proceed.</span>';
@@ -4848,9 +5096,10 @@  discard block
 block discarded – undo
4848 5096
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4849 5097
 
4850 5098
 		// If debug flood the screen.
4851
-		if ($is_debug)
4852
-			echo '
5099
+		if ($is_debug) {
5100
+					echo '
4853 5101
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
5102
+		}
4854 5103
 
4855 5104
 		echo '
4856 5105
 				// Get the next update...
@@ -4892,19 +5141,21 @@  discard block
 block discarded – undo
4892 5141
 			<span id="debuginfo"></span>';
4893 5142
 
4894 5143
 	// Dont any tables so far?
4895
-	if (!empty($upcontext['previous_tables']))
4896
-		foreach ($upcontext['previous_tables'] as $table)
5144
+	if (!empty($upcontext['previous_tables'])) {
5145
+			foreach ($upcontext['previous_tables'] as $table)
4897 5146
 			echo '
4898 5147
 			<br>Completed Table: &quot;', $table, '&quot;.';
5148
+	}
4899 5149
 
4900 5150
 	echo '
4901 5151
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4902 5152
 			<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>';
4903 5153
 
4904 5154
 	// Try to make sure substep was reset.
4905
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4906
-		echo '
5155
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
5156
+			echo '
4907 5157
 			<input type="hidden" name="substep" id="substep" value="0">';
5158
+	}
4908 5159
 
4909 5160
 	// Continue please!
4910 5161
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4937,9 +5188,10 @@  discard block
 block discarded – undo
4937 5188
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4938 5189
 
4939 5190
 		// If debug flood the screen.
4940
-		if ($is_debug)
4941
-			echo '
5191
+		if ($is_debug) {
5192
+					echo '
4942 5193
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
5194
+		}
4943 5195
 
4944 5196
 		echo '
4945 5197
 				// Get the next update...
@@ -4974,8 +5226,8 @@  discard block
 block discarded – undo
4974 5226
 	<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>
4975 5227
 	<form action="', $boardurl, '/index.php">';
4976 5228
 
4977
-	if (!empty($upcontext['can_delete_script']))
4978
-		echo '
5229
+	if (!empty($upcontext['can_delete_script'])) {
5230
+			echo '
4979 5231
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em>
4980 5232
 			<script>
4981 5233
 				function doTheDelete(theCheck)
@@ -4987,6 +5239,7 @@  discard block
 block discarded – undo
4987 5239
 				}
4988 5240
 			</script>
4989 5241
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
5242
+	}
4990 5243
 
4991 5244
 	$active = time() - $upcontext['started'];
4992 5245
 	$hours = floor($active / 3600);
@@ -4996,16 +5249,20 @@  discard block
 block discarded – undo
4996 5249
 	if ($is_debug)
4997 5250
 	{
4998 5251
 		$totalTime = '';
4999
-		if ($hours > 0)
5000
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
5001
-		if ($minutes > 0)
5002
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
5003
-		if ($seconds > 0)
5004
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
5252
+		if ($hours > 0) {
5253
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
5254
+		}
5255
+		if ($minutes > 0) {
5256
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
5257
+		}
5258
+		if ($seconds > 0) {
5259
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
5260
+		}
5005 5261
 	}
5006 5262
 
5007
-	if ($is_debug && !empty($totalTime))
5008
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
5263
+	if ($is_debug && !empty($totalTime)) {
5264
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
5265
+	}
5009 5266
 
5010 5267
 	echo '<br>
5011 5268
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="http://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -5072,16 +5329,19 @@  discard block
 block discarded – undo
5072 5329
 				'empty' => '',
5073 5330
 				'limit' => $limit,
5074 5331
 		));
5075
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5076
-			$arIp[] = $row[$oldCol];
5332
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5333
+					$arIp[] = $row[$oldCol];
5334
+		}
5077 5335
 		$smcFunc['db_free_result']($request);
5078 5336
 
5079 5337
 		// Special case, null ip could keep us in a loop.
5080
-		if (is_null($arIp[0]))
5081
-			unset($arIp[0]);
5338
+		if (is_null($arIp[0])) {
5339
+					unset($arIp[0]);
5340
+		}
5082 5341
 
5083
-		if (empty($arIp))
5084
-			$is_done = true;
5342
+		if (empty($arIp)) {
5343
+					$is_done = true;
5344
+		}
5085 5345
 
5086 5346
 		$updates = array();
5087 5347
 		$cases = array();
@@ -5090,16 +5350,18 @@  discard block
 block discarded – undo
5090 5350
 		{
5091 5351
 			$arIp[$i] = trim($arIp[$i]);
5092 5352
 
5093
-			if (empty($arIp[$i]))
5094
-				continue;
5353
+			if (empty($arIp[$i])) {
5354
+							continue;
5355
+			}
5095 5356
 
5096 5357
 			$updates['ip' . $i] = $arIp[$i];
5097 5358
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
5098 5359
 
5099 5360
 			if ($setSize > 0 && $i % $setSize === 0)
5100 5361
 			{
5101
-				if (count($updates) == 1)
5102
-					continue;
5362
+				if (count($updates) == 1) {
5363
+									continue;
5364
+				}
5103 5365
 
5104 5366
 				$updates['whereSet'] = array_values($updates);
5105 5367
 				$smcFunc['db_query']('', '
@@ -5133,8 +5395,7 @@  discard block
 block discarded – undo
5133 5395
 							'ip' => $ip
5134 5396
 					));
5135 5397
 				}
5136
-			}
5137
-			else
5398
+			} else
5138 5399
 			{
5139 5400
 				$updates['whereSet'] = array_values($updates);
5140 5401
 				$smcFunc['db_query']('', '
@@ -5148,9 +5409,9 @@  discard block
 block discarded – undo
5148 5409
 					$updates
5149 5410
 				);
5150 5411
 			}
5412
+		} else {
5413
+					$is_done = true;
5151 5414
 		}
5152
-		else
5153
-			$is_done = true;
5154 5415
 
5155 5416
 		$_GET['a'] += $limit;
5156 5417
 		$step_progress['current'] = $_GET['a'];
Please login to merge, or discard this patch.