Completed
Pull Request — release-2.1 (#3761)
by Rick
07:11
created
other/upgrade.php 3 patches
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.
Doc Comments   +10 added lines, -1 removed lines patch added patch discarded remove patch
@@ -390,6 +390,9 @@  discard block
 block discarded – undo
390 390
 }
391 391
 
392 392
 // Used to direct the user to another location.
393
+/**
394
+ * @param string $location
395
+ */
393 396
 function redirectLocation($location, $addForm = true)
394 397
 {
395 398
 	global $upgradeurl, $upcontext, $command_line;
@@ -1719,6 +1722,9 @@  discard block
 block discarded – undo
1719 1722
 	return addslashes(preg_replace(array('~^\.([/\\\]|$)~', '~[/]+~', '~[\\\]+~', '~[/\\\]$~'), array($install_path . '$1', '/', '\\', ''), $path));
1720 1723
 }
1721 1724
 
1725
+/**
1726
+ * @param string $filename
1727
+ */
1722 1728
 function parse_sql($filename)
1723 1729
 {
1724 1730
 	global $db_prefix, $db_collation, $boarddir, $boardurl, $command_line, $file_steps, $step_progress, $custom_warning;
@@ -2005,6 +2011,9 @@  discard block
 block discarded – undo
2005 2011
 	return true;
2006 2012
 }
2007 2013
 
2014
+/**
2015
+ * @param string $string
2016
+ */
2008 2017
 function upgrade_query($string, $unbuffered = false)
2009 2018
 {
2010 2019
 	global $db_connection, $db_server, $db_user, $db_passwd, $db_type, $command_line, $upcontext, $upgradeurl, $modSettings;
@@ -4675,7 +4684,7 @@  discard block
 block discarded – undo
4675 4684
  * @param int $setSize The amount of entries after which to update the database.
4676 4685
  *
4677 4686
  * newCol needs to be a varbinary(16) null able field
4678
- * @return bool
4687
+ * @return boolean|null
4679 4688
  */
4680 4689
 function MySQLConvertOldIp($targetTable, $oldCol, $newCol, $limit = 50000, $setSize = 100)
4681 4690
 {
Please login to merge, or discard this patch.
Braces   +879 added lines, -645 removed lines patch added patch discarded remove patch
@@ -100,11 +100,14 @@  discard block
 block discarded – undo
100 100
 	ini_set('default_socket_timeout', 900);
101 101
 }
102 102
 // Clean the upgrade path if this is from the client.
103
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
104
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
103
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
104
+	for ($i = 1;
105
+}
106
+$i < $_SERVER['argc']; $i++)
105 107
 	{
106
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
107
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
108
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
109
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
110
+		}
108 111
 	}
109 112
 
110 113
 // Are we from the client?
@@ -112,9 +115,9 @@  discard block
 block discarded – undo
112 115
 {
113 116
 	$command_line = true;
114 117
 	$disable_security = 1;
115
-}
116
-else
118
+} else {
117 119
 	$command_line = false;
120
+}
118 121
 
119 122
 // Load this now just because we can.
120 123
 require_once($upgrade_path . '/Settings.php');
@@ -129,10 +132,12 @@  discard block
 block discarded – undo
129 132
 	$upcontext['user'] = unserialize(base64_decode($upgradeData));
130 133
 
131 134
 	// Check for sensible values.
132
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
133
-		$upcontext['user']['started'] = time();
134
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
135
-		$upcontext['user']['updated'] = 0;
135
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
136
+			$upcontext['user']['started'] = time();
137
+	}
138
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
139
+			$upcontext['user']['updated'] = 0;
140
+	}
136 141
 
137 142
 	$upcontext['started'] = $upcontext['user']['started'];
138 143
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -189,8 +194,9 @@  discard block
 block discarded – undo
189 194
 			'db_error_skip' => true,
190 195
 		)
191 196
 	);
192
-	while ($row = $smcFunc['db_fetch_assoc']($request))
193
-		$modSettings[$row['variable']] = $row['value'];
197
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
198
+			$modSettings[$row['variable']] = $row['value'];
199
+	}
194 200
 	$smcFunc['db_free_result']($request);
195 201
 }
196 202
 
@@ -200,10 +206,12 @@  discard block
 block discarded – undo
200 206
 	$modSettings['theme_url'] = 'Themes/default';
201 207
 	$modSettings['images_url'] = 'Themes/default/images';
202 208
 }
203
-if (!isset($settings['default_theme_url']))
209
+if (!isset($settings['default_theme_url'])) {
204 210
 	$settings['default_theme_url'] = $modSettings['theme_url'];
205
-if (!isset($settings['default_theme_dir']))
211
+}
212
+if (!isset($settings['default_theme_dir'])) {
206 213
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
214
+}
207 215
 
208 216
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
209 217
 // Default title...
@@ -221,13 +229,15 @@  discard block
 block discarded – undo
221 229
 	$support_js = $upcontext['upgrade_status']['js'];
222 230
 
223 231
 	// Only set this if the upgrader status says so.
224
-	if (empty($is_debug))
225
-		$is_debug = $upcontext['upgrade_status']['debug'];
232
+	if (empty($is_debug)) {
233
+			$is_debug = $upcontext['upgrade_status']['debug'];
234
+	}
226 235
 
227 236
 	// Load the language.
228
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
229
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
230
-}
237
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
238
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
239
+	}
240
+	}
231 241
 // Set the defaults.
232 242
 else
233 243
 {
@@ -245,15 +255,18 @@  discard block
 block discarded – undo
245 255
 }
246 256
 
247 257
 // If this isn't the first stage see whether they are logging in and resuming.
248
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
258
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
249 259
 	checkLogin();
260
+}
250 261
 
251
-if ($command_line)
262
+if ($command_line) {
252 263
 	cmdStep0();
264
+}
253 265
 
254 266
 // Don't error if we're using xml.
255
-if (isset($_GET['xml']))
267
+if (isset($_GET['xml'])) {
256 268
 	$upcontext['return_error'] = true;
269
+}
257 270
 
258 271
 // Loop through all the steps doing each one as required.
259 272
 $upcontext['overall_percent'] = 0;
@@ -274,10 +287,11 @@  discard block
 block discarded – undo
274 287
 		}
275 288
 
276 289
 		// Call the step and if it returns false that means pause!
277
-		if (function_exists($step[2]) && $step[2]() === false)
278
-			break;
279
-		elseif (function_exists($step[2]))
280
-			$upcontext['current_step']++;
290
+		if (function_exists($step[2]) && $step[2]() === false) {
291
+					break;
292
+		} elseif (function_exists($step[2])) {
293
+					$upcontext['current_step']++;
294
+		}
281 295
 	}
282 296
 	$upcontext['overall_percent'] += $step[3];
283 297
 }
@@ -316,17 +330,18 @@  discard block
 block discarded – undo
316 330
 		// This should not happen my dear... HELP ME DEVELOPERS!!
317 331
 		if (!empty($command_line))
318 332
 		{
319
-			if (function_exists('debug_print_backtrace'))
320
-				debug_print_backtrace();
333
+			if (function_exists('debug_print_backtrace')) {
334
+							debug_print_backtrace();
335
+			}
321 336
 
322 337
 			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.';
323 338
 			flush();
324 339
 			die();
325 340
 		}
326 341
 
327
-		if (!isset($_GET['xml']))
328
-			template_upgrade_above();
329
-		else
342
+		if (!isset($_GET['xml'])) {
343
+					template_upgrade_above();
344
+		} else
330 345
 		{
331 346
 			header('Content-Type: text/xml; charset=UTF-8');
332 347
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -348,21 +363,24 @@  discard block
 block discarded – undo
348 363
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(safe_serialize($upcontext['upgrade_status']));
349 364
 
350 365
 			// Custom stuff to pass back?
351
-			if (!empty($upcontext['query_string']))
352
-				$upcontext['form_url'] .= $upcontext['query_string'];
366
+			if (!empty($upcontext['query_string'])) {
367
+							$upcontext['form_url'] .= $upcontext['query_string'];
368
+			}
353 369
 
354 370
 			call_user_func('template_' . $upcontext['sub_template']);
355 371
 		}
356 372
 
357 373
 		// Was there an error?
358
-		if (!empty($upcontext['forced_error_message']))
359
-			echo $upcontext['forced_error_message'];
374
+		if (!empty($upcontext['forced_error_message'])) {
375
+					echo $upcontext['forced_error_message'];
376
+		}
360 377
 
361 378
 		// Show the footer.
362
-		if (!isset($_GET['xml']))
363
-			template_upgrade_below();
364
-		else
365
-			template_xml_below();
379
+		if (!isset($_GET['xml'])) {
380
+					template_upgrade_below();
381
+		} else {
382
+					template_xml_below();
383
+		}
366 384
 	}
367 385
 
368 386
 
@@ -374,15 +392,19 @@  discard block
 block discarded – undo
374 392
 		$seconds = intval($active % 60);
375 393
 
376 394
 		$totalTime = '';
377
-		if ($hours > 0)
378
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
379
-		if ($minutes > 0)
380
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
381
-		if ($seconds > 0)
382
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
395
+		if ($hours > 0) {
396
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
397
+		}
398
+		if ($minutes > 0) {
399
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
400
+		}
401
+		if ($seconds > 0) {
402
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
403
+		}
383 404
 
384
-		if (!empty($totalTime))
385
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
405
+		if (!empty($totalTime)) {
406
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
407
+		}
386 408
 	}
387 409
 
388 410
 	// Bang - gone!
@@ -395,8 +417,9 @@  discard block
 block discarded – undo
395 417
 	global $upgradeurl, $upcontext, $command_line;
396 418
 
397 419
 	// Command line users can't be redirected.
398
-	if ($command_line)
399
-		upgradeExit(true);
420
+	if ($command_line) {
421
+			upgradeExit(true);
422
+	}
400 423
 
401 424
 	// Are we providing the core info?
402 425
 	if ($addForm)
@@ -419,19 +442,22 @@  discard block
 block discarded – undo
419 442
 	global $modSettings, $sourcedir, $smcFunc;
420 443
 
421 444
 	// Do the non-SSI stuff...
422
-	if (function_exists('set_magic_quotes_runtime'))
423
-		@set_magic_quotes_runtime(0);
445
+	if (function_exists('set_magic_quotes_runtime')) {
446
+			@set_magic_quotes_runtime(0);
447
+	}
424 448
 
425 449
 	error_reporting(E_ALL);
426 450
 	define('SMF', 1);
427 451
 
428 452
 	// Start the session.
429
-	if (@ini_get('session.save_handler') == 'user')
430
-		@ini_set('session.save_handler', 'files');
453
+	if (@ini_get('session.save_handler') == 'user') {
454
+			@ini_set('session.save_handler', 'files');
455
+	}
431 456
 	@session_start();
432 457
 
433
-	if (empty($smcFunc))
434
-		$smcFunc = array();
458
+	if (empty($smcFunc)) {
459
+			$smcFunc = array();
460
+	}
435 461
 
436 462
 	// We need this for authentication and some upgrade code
437 463
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -444,8 +470,9 @@  discard block
 block discarded – undo
444 470
 	initialize_inputs();
445 471
 
446 472
 	// Get the database going!
447
-	if (empty($db_type))
448
-		$db_type = 'mysqli';
473
+	if (empty($db_type)) {
474
+			$db_type = 'mysqli';
475
+	}
449 476
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
450 477
 	{
451 478
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -454,17 +481,19 @@  discard block
 block discarded – undo
454 481
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
455 482
 
456 483
 		// Oh dear god!!
457
-		if ($db_connection === null)
458
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
484
+		if ($db_connection === null) {
485
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
486
+		}
459 487
 
460
-		if (($db_type == 'mysql' || $db_type == 'mysqli') && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
461
-			$smcFunc['db_query']('', '
488
+		if (($db_type == 'mysql' || $db_type == 'mysqli') && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
489
+					$smcFunc['db_query']('', '
462 490
 			SET NAMES {string:db_character_set}',
463 491
 			array(
464 492
 				'db_error_skip' => true,
465 493
 				'db_character_set' => $db_character_set,
466 494
 			)
467 495
 		);
496
+		}
468 497
 
469 498
 		// Load the modSettings data...
470 499
 		$request = $smcFunc['db_query']('', '
@@ -475,11 +504,11 @@  discard block
 block discarded – undo
475 504
 			)
476 505
 		);
477 506
 		$modSettings = array();
478
-		while ($row = $smcFunc['db_fetch_assoc']($request))
479
-			$modSettings[$row['variable']] = $row['value'];
507
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
508
+					$modSettings[$row['variable']] = $row['value'];
509
+		}
480 510
 		$smcFunc['db_free_result']($request);
481
-	}
482
-	else
511
+	} else
483 512
 	{
484 513
 		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.');
485 514
 	}
@@ -493,9 +522,10 @@  discard block
 block discarded – undo
493 522
 		cleanRequest();
494 523
 	}
495 524
 
496
-	if (!isset($_GET['substep']))
497
-		$_GET['substep'] = 0;
498
-}
525
+	if (!isset($_GET['substep'])) {
526
+			$_GET['substep'] = 0;
527
+	}
528
+	}
499 529
 
500 530
 function initialize_inputs()
501 531
 {
@@ -527,8 +557,9 @@  discard block
 block discarded – undo
527 557
 		$dh = opendir(dirname(__FILE__));
528 558
 		while ($file = readdir($dh))
529 559
 		{
530
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
531
-				@unlink(dirname(__FILE__) . '/' . $file);
560
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
561
+							@unlink(dirname(__FILE__) . '/' . $file);
562
+			}
532 563
 		}
533 564
 		closedir($dh);
534 565
 
@@ -558,8 +589,9 @@  discard block
 block discarded – undo
558 589
 	{
559 590
 		$upcontext['remote_files_available'] = false;
560 591
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
561
-		if ($test)
562
-			$upcontext['remote_files_available'] = true;
592
+		if ($test) {
593
+					$upcontext['remote_files_available'] = true;
594
+		}
563 595
 		@fclose($test);
564 596
 	}
565 597
 
@@ -567,8 +599,9 @@  discard block
 block discarded – undo
567 599
 	$temp = 'upgrade_php?step';
568 600
 	while (strlen($temp) > 4)
569 601
 	{
570
-		if (isset($_GET[$temp]))
571
-			unset($_GET[$temp]);
602
+		if (isset($_GET[$temp])) {
603
+					unset($_GET[$temp]);
604
+		}
572 605
 		$temp = substr($temp, 1);
573 606
 	}
574 607
 
@@ -597,29 +630,36 @@  discard block
 block discarded – undo
597 630
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $type . '.sql');
598 631
 
599 632
 	// Need legacy scripts?
600
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
601
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $type . '.sql');
602
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
603
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
604
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
605
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
633
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
634
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $type . '.sql');
635
+	}
636
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
637
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
638
+	}
639
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
640
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
641
+	}
606 642
 
607 643
 	// This needs to exist!
608
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
609
-		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>]');
610
-	else
611
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
644
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
645
+			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>]');
646
+	} else {
647
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
648
+	}
612 649
 
613
-	if (!$check)
614
-		// 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.
650
+	if (!$check) {
651
+			// 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.
615 652
 		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.');
653
+	}
616 654
 
617 655
 	// Do they meet the install requirements?
618
-	if (!php_version_check())
619
-		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.');
656
+	if (!php_version_check()) {
657
+			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.');
658
+	}
620 659
 
621
-	if (!db_version_check())
622
-		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.');
660
+	if (!db_version_check()) {
661
+			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.');
662
+	}
623 663
 
624 664
 	// Do some checks to make sure they have proper privileges
625 665
 	db_extend('packages');
@@ -634,14 +674,16 @@  discard block
 block discarded – undo
634 674
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
635 675
 
636 676
 	// Sorry... we need CREATE, ALTER and DROP
637
-	if (!$create || !$alter || !$drop)
638
-		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.');
677
+	if (!$create || !$alter || !$drop) {
678
+			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.');
679
+	}
639 680
 
640 681
 	// Do a quick version spot check.
641 682
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
642 683
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
643
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
644
-		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.');
684
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
685
+			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.');
686
+	}
645 687
 
646 688
 	// What absolutely needs to be writable?
647 689
 	$writable_files = array(
@@ -663,12 +705,13 @@  discard block
 block discarded – undo
663 705
 	quickFileWritable($custom_av_dir);
664 706
 
665 707
 	// Are we good now?
666
-	if (!is_writable($custom_av_dir))
667
-		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));
668
-	elseif ($need_settings_update)
708
+	if (!is_writable($custom_av_dir)) {
709
+			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));
710
+	} elseif ($need_settings_update)
669 711
 	{
670
-		if (!function_exists('cache_put_data'))
671
-			require_once($sourcedir . '/Load.php');
712
+		if (!function_exists('cache_put_data')) {
713
+					require_once($sourcedir . '/Load.php');
714
+		}
672 715
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
673 716
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
674 717
 	}
@@ -677,28 +720,33 @@  discard block
 block discarded – undo
677 720
 
678 721
 	// Check the cache directory.
679 722
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
680
-	if (!file_exists($cachedir_temp))
681
-		@mkdir($cachedir_temp);
682
-	if (!file_exists($cachedir_temp))
683
-		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.');
684
-
685
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
686
-		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>.');
687
-	elseif (!isset($_GET['skiplang']))
723
+	if (!file_exists($cachedir_temp)) {
724
+			@mkdir($cachedir_temp);
725
+	}
726
+	if (!file_exists($cachedir_temp)) {
727
+			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.');
728
+	}
729
+
730
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
731
+			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>.');
732
+	} elseif (!isset($_GET['skiplang']))
688 733
 	{
689 734
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
690 735
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
691 736
 
692
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
693
-			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>]');
737
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
738
+					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>]');
739
+		}
694 740
 	}
695 741
 
696
-	if (!makeFilesWritable($writable_files))
697
-		return false;
742
+	if (!makeFilesWritable($writable_files)) {
743
+			return false;
744
+	}
698 745
 
699 746
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
700
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
701
-		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.');
747
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
748
+			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.');
749
+	}
702 750
 
703 751
 	// Upgrade the agreement.
704 752
 	elseif (isset($modSettings['agreement']))
@@ -709,8 +757,8 @@  discard block
 block discarded – undo
709 757
 	}
710 758
 
711 759
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
712
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
713
-		$upcontext['warning'] = '
760
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
761
+			$upcontext['warning'] = '
714 762
 			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>
715 763
 			<ul>
716 764
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -718,10 +766,12 @@  discard block
 block discarded – undo
718 766
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
719 767
 			</ul>
720 768
 			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.';
769
+	}
721 770
 
722 771
 	// Either we're logged in or we're going to present the login.
723
-	if (checkLogin())
724
-		return true;
772
+	if (checkLogin()) {
773
+			return true;
774
+	}
725 775
 
726 776
 	$upcontext += createToken('login');
727 777
 
@@ -735,15 +785,17 @@  discard block
 block discarded – undo
735 785
 	global $smcFunc, $db_type, $support_js;
736 786
 
737 787
 	// Don't bother if the security is disabled.
738
-	if ($disable_security)
739
-		return true;
788
+	if ($disable_security) {
789
+			return true;
790
+	}
740 791
 
741 792
 	// Are we trying to login?
742 793
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
743 794
 	{
744 795
 		// If we've disabled security pick a suitable name!
745
-		if (empty($_POST['user']))
746
-			$_POST['user'] = 'Administrator';
796
+		if (empty($_POST['user'])) {
797
+					$_POST['user'] = 'Administrator';
798
+		}
747 799
 
748 800
 		// Before 2.0 these column names were different!
749 801
 		$oldDB = false;
@@ -758,16 +810,17 @@  discard block
 block discarded – undo
758 810
 					'db_error_skip' => true,
759 811
 				)
760 812
 			);
761
-			if ($smcFunc['db_num_rows']($request) != 0)
762
-				$oldDB = true;
813
+			if ($smcFunc['db_num_rows']($request) != 0) {
814
+							$oldDB = true;
815
+			}
763 816
 			$smcFunc['db_free_result']($request);
764 817
 		}
765 818
 
766 819
 		// Get what we believe to be their details.
767 820
 		if (!$disable_security)
768 821
 		{
769
-			if ($oldDB)
770
-				$request = $smcFunc['db_query']('', '
822
+			if ($oldDB) {
823
+							$request = $smcFunc['db_query']('', '
771 824
 					SELECT id_member, memberName AS member_name, passwd, id_group,
772 825
 					additionalGroups AS additional_groups, lngfile
773 826
 					FROM {db_prefix}members
@@ -777,8 +830,8 @@  discard block
 block discarded – undo
777 830
 						'db_error_skip' => true,
778 831
 					)
779 832
 				);
780
-			else
781
-				$request = $smcFunc['db_query']('', '
833
+			} else {
834
+							$request = $smcFunc['db_query']('', '
782 835
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
783 836
 					FROM {db_prefix}members
784 837
 					WHERE member_name = {string:member_name}',
@@ -787,6 +840,7 @@  discard block
 block discarded – undo
787 840
 						'db_error_skip' => true,
788 841
 					)
789 842
 				);
843
+			}
790 844
 			if ($smcFunc['db_num_rows']($request) != 0)
791 845
 			{
792 846
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -794,13 +848,14 @@  discard block
 block discarded – undo
794 848
 				$groups = explode(',', $addGroups);
795 849
 				$groups[] = $id_group;
796 850
 
797
-				foreach ($groups as $k => $v)
798
-					$groups[$k] = (int) $v;
851
+				foreach ($groups as $k => $v) {
852
+									$groups[$k] = (int) $v;
853
+				}
799 854
 
800 855
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
856
+			} else {
857
+							$upcontext['username_incorrect'] = true;
801 858
 			}
802
-			else
803
-				$upcontext['username_incorrect'] = true;
804 859
 			$smcFunc['db_free_result']($request);
805 860
 		}
806 861
 		$upcontext['username'] = $_POST['user'];
@@ -810,13 +865,14 @@  discard block
 block discarded – undo
810 865
 		{
811 866
 			$upcontext['upgrade_status']['js'] = 1;
812 867
 			$support_js = 1;
868
+		} else {
869
+					$support_js = 0;
813 870
 		}
814
-		else
815
-			$support_js = 0;
816 871
 
817 872
 		// Note down the version we are coming from.
818
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
819
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
873
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
874
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
875
+		}
820 876
 
821 877
 		// Didn't get anywhere?
822 878
 		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']))
@@ -850,15 +906,15 @@  discard block
 block discarded – undo
850 906
 							'db_error_skip' => true,
851 907
 						)
852 908
 					);
853
-					if ($smcFunc['db_num_rows']($request) == 0)
854
-						return throw_error('You need to be an admin to perform an upgrade!');
909
+					if ($smcFunc['db_num_rows']($request) == 0) {
910
+											return throw_error('You need to be an admin to perform an upgrade!');
911
+					}
855 912
 					$smcFunc['db_free_result']($request);
856 913
 				}
857 914
 
858 915
 				$upcontext['user']['id'] = $id_member;
859 916
 				$upcontext['user']['name'] = $name;
860
-			}
861
-			else
917
+			} else
862 918
 			{
863 919
 				$upcontext['user']['id'] = 1;
864 920
 				$upcontext['user']['name'] = 'Administrator';
@@ -874,11 +930,11 @@  discard block
 block discarded – undo
874 930
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
875 931
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
876 932
 
877
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
878
-					$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'] . '.';
879
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
880
-					$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'] . '.';
881
-				else
933
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
934
+									$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'] . '.';
935
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
936
+									$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'] . '.';
937
+				} else
882 938
 				{
883 939
 					// Set this as the new language.
884 940
 					$upcontext['language'] = $user_language;
@@ -922,15 +978,17 @@  discard block
 block discarded – undo
922 978
 	unset($member_columns);
923 979
 
924 980
 	// If we've not submitted then we're done.
925
-	if (empty($_POST['upcont']))
926
-		return false;
981
+	if (empty($_POST['upcont'])) {
982
+			return false;
983
+	}
927 984
 
928 985
 	require_once($sourcedir . '/Subs-Admin.php');
929 986
 	updateSettingsFile(array('image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\''));
930 987
 
931 988
 	// Should we update the $db_type value?
932
-	if ($upcontext['update_db_type_to_mysqli'])
933
-		updateSettingsFile(array('db_type' => '\'mysqli\''));
989
+	if ($upcontext['update_db_type_to_mysqli']) {
990
+			updateSettingsFile(array('db_type' => '\'mysqli\''));
991
+	}
934 992
 
935 993
 	// Firstly, if they're enabling SM stat collection just do it.
936 994
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']))
@@ -945,25 +1003,26 @@  discard block
 block discarded – undo
945 1003
 			fwrite($fp, $out);
946 1004
 
947 1005
 			$return_data = '';
948
-			while (!feof($fp))
949
-				$return_data .= fgets($fp, 128);
1006
+			while (!feof($fp)) {
1007
+							$return_data .= fgets($fp, 128);
1008
+			}
950 1009
 
951 1010
 			fclose($fp);
952 1011
 
953 1012
 			// Get the unique site ID.
954 1013
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
955 1014
 
956
-			if (!empty($ID[1]))
957
-				$smcFunc['db_insert']('replace',
1015
+			if (!empty($ID[1])) {
1016
+							$smcFunc['db_insert']('replace',
958 1017
 					$db_prefix . 'settings',
959 1018
 					array('variable' => 'string', 'value' => 'string'),
960 1019
 					array('allow_sm_stats', $ID[1]),
961 1020
 					array('variable')
962 1021
 				);
1022
+			}
963 1023
 		}
964
-	}
965
-	else
966
-		$smcFunc['db_query']('', '
1024
+	} else {
1025
+			$smcFunc['db_query']('', '
967 1026
 			DELETE FROM {db_prefix}settings
968 1027
 			WHERE variable = {string:allow_sm_stats}',
969 1028
 			array(
@@ -971,6 +1030,7 @@  discard block
 block discarded – undo
971 1030
 				'db_error_skip' => true,
972 1031
 			)
973 1032
 		);
1033
+	}
974 1034
 
975 1035
 	// Deleting old karma stuff?
976 1036
 	if (!empty($_POST['delete_karma']))
@@ -985,20 +1045,22 @@  discard block
 block discarded – undo
985 1045
 		);
986 1046
 
987 1047
 		// Cleaning up old karma member settings.
988
-		if ($upcontext['karma_installed']['good'])
989
-			$smcFunc['db_query']('', '
1048
+		if ($upcontext['karma_installed']['good']) {
1049
+					$smcFunc['db_query']('', '
990 1050
 				ALTER TABLE {db_prefix}members
991 1051
 				DROP karma_good',
992 1052
 				array()
993 1053
 			);
1054
+		}
994 1055
 
995 1056
 		// Does karma bad was enable?
996
-		if ($upcontext['karma_installed']['bad'])
997
-			$smcFunc['db_query']('', '
1057
+		if ($upcontext['karma_installed']['bad']) {
1058
+					$smcFunc['db_query']('', '
998 1059
 				ALTER TABLE {db_prefix}members
999 1060
 				DROP karma_bad',
1000 1061
 				array()
1001 1062
 			);
1063
+		}
1002 1064
 
1003 1065
 		// Cleaning up old karma permissions.
1004 1066
 		$smcFunc['db_query']('', '
@@ -1011,18 +1073,20 @@  discard block
 block discarded – undo
1011 1073
 	}
1012 1074
 
1013 1075
 	// Emptying the error log?
1014
-	if (!empty($_POST['empty_error']))
1015
-		$smcFunc['db_query']('truncate_table', '
1076
+	if (!empty($_POST['empty_error'])) {
1077
+			$smcFunc['db_query']('truncate_table', '
1016 1078
 			TRUNCATE {db_prefix}log_errors',
1017 1079
 			array(
1018 1080
 			)
1019 1081
 		);
1082
+	}
1020 1083
 
1021 1084
 	$changes = array();
1022 1085
 
1023 1086
 	// If we're overriding the language follow it through.
1024
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1025
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1087
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1088
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1089
+	}
1026 1090
 
1027 1091
 	if (!empty($_POST['maint']))
1028 1092
 	{
@@ -1034,37 +1098,42 @@  discard block
 block discarded – undo
1034 1098
 		{
1035 1099
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1036 1100
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1037
-		}
1038
-		else
1101
+		} else
1039 1102
 		{
1040 1103
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1041 1104
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1042 1105
 		}
1043 1106
 	}
1044 1107
 
1045
-	if ($command_line)
1046
-		echo ' * Updating Settings.php...';
1108
+	if ($command_line) {
1109
+			echo ' * Updating Settings.php...';
1110
+	}
1047 1111
 
1048 1112
 	// Backup the current one first.
1049 1113
 	copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
1050 1114
 
1051 1115
 	// Fix some old paths.
1052
-	if (substr($boarddir, 0, 1) == '.')
1053
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1116
+	if (substr($boarddir, 0, 1) == '.') {
1117
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1118
+	}
1054 1119
 
1055
-	if (substr($sourcedir, 0, 1) == '.')
1056
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1120
+	if (substr($sourcedir, 0, 1) == '.') {
1121
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1122
+	}
1057 1123
 
1058
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1059
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1124
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1125
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1126
+	}
1060 1127
 
1061 1128
 	// Not had the database type added before?
1062
-	if (empty($db_type))
1063
-		$changes['db_type'] = 'mysql';
1129
+	if (empty($db_type)) {
1130
+			$changes['db_type'] = 'mysql';
1131
+	}
1064 1132
 
1065 1133
 	// For now we offer a option, this may change in future versions when mysql is completely removed.
1066
-	if (!empty($_POST['convertMysql']) && $db_type == 'mysql')
1067
-		$changes['db_type'] = '\'mysqli\'';
1134
+	if (!empty($_POST['convertMysql']) && $db_type == 'mysql') {
1135
+			$changes['db_type'] = '\'mysqli\'';
1136
+	}
1068 1137
 
1069 1138
 	// If they have a "host:port" setup for the host, split that into separate values
1070 1139
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1075,28 +1144,31 @@  discard block
 block discarded – undo
1075 1144
 		$changes['db_server'] = '\'' . $db_server . '\'';
1076 1145
 
1077 1146
 		// Only set this if we're not using the default port
1078
-		if ($db_port != ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port'))
1079
-			$changes['db_port'] = (int) $db_port;
1080
-	}
1081
-	elseif (!empty($db_port))
1147
+		if ($db_port != ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port')) {
1148
+					$changes['db_port'] = (int) $db_port;
1149
+		}
1150
+	} elseif (!empty($db_port))
1082 1151
 	{
1083 1152
 		// If db_port is set and is the same as the default, set it to ''
1084 1153
 		if ($db_type == 'mysql' || $db_type == 'mysqli')
1085 1154
 		{
1086
-			if ($db_port == ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port'))
1087
-				$changes['db_port'] = '\'\'';
1088
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1089
-				$changes['db_port'] = '\'\'';
1155
+			if ($db_port == ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port')) {
1156
+							$changes['db_port'] = '\'\'';
1157
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1158
+							$changes['db_port'] = '\'\'';
1159
+			}
1090 1160
 		}
1091 1161
 	}
1092 1162
 
1093 1163
 	// Maybe we haven't had this option yet?
1094
-	if (empty($packagesdir))
1095
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1164
+	if (empty($packagesdir)) {
1165
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1166
+	}
1096 1167
 
1097 1168
 	// Add support for $tasksdir var.
1098
-	if (empty($tasksdir))
1099
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1169
+	if (empty($tasksdir)) {
1170
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1171
+	}
1100 1172
 
1101 1173
 	// @todo Maybe change the cookie name if going to 1.1, too?
1102 1174
 
@@ -1141,8 +1213,7 @@  discard block
 block discarded – undo
1141 1213
 			$found_old = true;
1142 1214
 			// Replace the old line with the new code
1143 1215
 			$settings_file = str_replace('$db_last_error = ' . $db_last_error . ';', $error_catching_header . $error_catching, $settings_file);
1144
-		}
1145
-		else
1216
+		} else
1146 1217
 		{
1147 1218
 			$found_old = false;
1148 1219
 			// We want the comments as well as the code...
@@ -1173,8 +1244,9 @@  discard block
 block discarded – undo
1173 1244
 		fclose($file);
1174 1245
 	}
1175 1246
 
1176
-	if ($command_line)
1177
-		echo ' Successful.' . "\n";
1247
+	if ($command_line) {
1248
+			echo ' Successful.' . "\n";
1249
+	}
1178 1250
 
1179 1251
 	// Are we doing debug?
1180 1252
 	if (isset($_POST['debug']))
@@ -1184,8 +1256,9 @@  discard block
 block discarded – undo
1184 1256
 	}
1185 1257
 
1186 1258
 	// If we're not backing up then jump one.
1187
-	if (empty($_POST['backup']))
1188
-		$upcontext['current_step']++;
1259
+	if (empty($_POST['backup'])) {
1260
+			$upcontext['current_step']++;
1261
+	}
1189 1262
 
1190 1263
 	// If we've got here then let's proceed to the next step!
1191 1264
 	return true;
@@ -1200,8 +1273,9 @@  discard block
 block discarded – undo
1200 1273
 	$upcontext['page_title'] = 'Backup Database';
1201 1274
 
1202 1275
 	// Done it already - js wise?
1203
-	if (!empty($_POST['backup_done']))
1204
-		return true;
1276
+	if (!empty($_POST['backup_done'])) {
1277
+			return true;
1278
+	}
1205 1279
 
1206 1280
 	// Some useful stuff here.
1207 1281
 	db_extend();
@@ -1215,9 +1289,10 @@  discard block
 block discarded – undo
1215 1289
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1216 1290
 
1217 1291
 	$table_names = array();
1218
-	foreach ($tables as $table)
1219
-		if (substr($table, 0, 7) !== 'backup_')
1292
+	foreach ($tables as $table) {
1293
+			if (substr($table, 0, 7) !== 'backup_')
1220 1294
 			$table_names[] = $table;
1295
+	}
1221 1296
 
1222 1297
 	$upcontext['table_count'] = count($table_names);
1223 1298
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1227,12 +1302,14 @@  discard block
 block discarded – undo
1227 1302
 	$file_steps = $upcontext['table_count'];
1228 1303
 
1229 1304
 	// What ones have we already done?
1230
-	foreach ($table_names as $id => $table)
1231
-		if ($id < $_GET['substep'])
1305
+	foreach ($table_names as $id => $table) {
1306
+			if ($id < $_GET['substep'])
1232 1307
 			$upcontext['previous_tables'][] = $table;
1308
+	}
1233 1309
 
1234
-	if ($command_line)
1235
-		echo 'Backing Up Tables.';
1310
+	if ($command_line) {
1311
+			echo 'Backing Up Tables.';
1312
+	}
1236 1313
 
1237 1314
 	// If we don't support javascript we backup here.
1238 1315
 	if (!$support_js || isset($_GET['xml']))
@@ -1251,8 +1328,9 @@  discard block
 block discarded – undo
1251 1328
 			backupTable($table_names[$substep]);
1252 1329
 
1253 1330
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1254
-			if (isset($_GET['xml']))
1255
-				return upgradeExit();
1331
+			if (isset($_GET['xml'])) {
1332
+							return upgradeExit();
1333
+			}
1256 1334
 		}
1257 1335
 
1258 1336
 		if ($command_line)
@@ -1285,9 +1363,10 @@  discard block
 block discarded – undo
1285 1363
 
1286 1364
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1287 1365
 
1288
-	if ($command_line)
1289
-		echo ' done.';
1290
-}
1366
+	if ($command_line) {
1367
+			echo ' done.';
1368
+	}
1369
+	}
1291 1370
 
1292 1371
 // Step 2: Everything.
1293 1372
 function DatabaseChanges()
@@ -1296,8 +1375,9 @@  discard block
 block discarded – undo
1296 1375
 	global $upcontext, $support_js, $db_type;
1297 1376
 
1298 1377
 	// Have we just completed this?
1299
-	if (!empty($_POST['database_done']))
1300
-		return true;
1378
+	if (!empty($_POST['database_done'])) {
1379
+			return true;
1380
+	}
1301 1381
 
1302 1382
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1303 1383
 	$upcontext['page_title'] = 'Database Changes';
@@ -1314,15 +1394,16 @@  discard block
 block discarded – undo
1314 1394
 	);
1315 1395
 
1316 1396
 	// How many files are there in total?
1317
-	if (isset($_GET['filecount']))
1318
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1319
-	else
1397
+	if (isset($_GET['filecount'])) {
1398
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1399
+	} else
1320 1400
 	{
1321 1401
 		$upcontext['file_count'] = 0;
1322 1402
 		foreach ($files as $file)
1323 1403
 		{
1324
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1325
-				$upcontext['file_count']++;
1404
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1405
+							$upcontext['file_count']++;
1406
+			}
1326 1407
 		}
1327 1408
 	}
1328 1409
 
@@ -1332,9 +1413,9 @@  discard block
 block discarded – undo
1332 1413
 	$upcontext['cur_file_num'] = 0;
1333 1414
 	foreach ($files as $file)
1334 1415
 	{
1335
-		if ($did_not_do)
1336
-			$did_not_do--;
1337
-		else
1416
+		if ($did_not_do) {
1417
+					$did_not_do--;
1418
+		} else
1338 1419
 		{
1339 1420
 			$upcontext['cur_file_num']++;
1340 1421
 			$upcontext['cur_file_name'] = $file[0];
@@ -1361,12 +1442,13 @@  discard block
 block discarded – undo
1361 1442
 					// Flag to move on to the next.
1362 1443
 					$upcontext['completed_step'] = true;
1363 1444
 					// Did we complete the whole file?
1364
-					if ($nextFile)
1365
-						$upcontext['current_debug_item_num'] = -1;
1445
+					if ($nextFile) {
1446
+											$upcontext['current_debug_item_num'] = -1;
1447
+					}
1366 1448
 					return upgradeExit();
1449
+				} elseif ($support_js) {
1450
+									break;
1367 1451
 				}
1368
-				elseif ($support_js)
1369
-					break;
1370 1452
 			}
1371 1453
 			// Set the progress bar to be right as if we had - even if we hadn't...
1372 1454
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1391,8 +1473,9 @@  discard block
 block discarded – undo
1391 1473
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1392 1474
 
1393 1475
 	// Now it's nice to have some of the basic SMF source files.
1394
-	if (!isset($_GET['ssi']) && !$command_line)
1395
-		redirectLocation('&ssi=1');
1476
+	if (!isset($_GET['ssi']) && !$command_line) {
1477
+			redirectLocation('&ssi=1');
1478
+	}
1396 1479
 
1397 1480
 	$upcontext['sub_template'] = 'upgrade_complete';
1398 1481
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1408,14 +1491,16 @@  discard block
 block discarded – undo
1408 1491
 	// Are we in maintenance mode?
1409 1492
 	if (isset($upcontext['user']['main']))
1410 1493
 	{
1411
-		if ($command_line)
1412
-			echo ' * ';
1494
+		if ($command_line) {
1495
+					echo ' * ';
1496
+		}
1413 1497
 		$upcontext['removed_maintenance'] = true;
1414 1498
 		$changes['maintenance'] = $upcontext['user']['main'];
1415 1499
 	}
1416 1500
 	// Otherwise if somehow we are in 2 let's go to 1.
1417
-	elseif (!empty($maintenance) && $maintenance == 2)
1418
-		$changes['maintenance'] = 1;
1501
+	elseif (!empty($maintenance) && $maintenance == 2) {
1502
+			$changes['maintenance'] = 1;
1503
+	}
1419 1504
 
1420 1505
 	// Wipe this out...
1421 1506
 	$upcontext['user'] = array();
@@ -1431,9 +1516,9 @@  discard block
 block discarded – undo
1431 1516
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1432 1517
 
1433 1518
 	// Now is the perfect time to fetch the SM files.
1434
-	if ($command_line)
1435
-		cli_scheduled_fetchSMfiles();
1436
-	else
1519
+	if ($command_line) {
1520
+			cli_scheduled_fetchSMfiles();
1521
+	} else
1437 1522
 	{
1438 1523
 		require_once($sourcedir . '/ScheduledTasks.php');
1439 1524
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1441,8 +1526,9 @@  discard block
 block discarded – undo
1441 1526
 	}
1442 1527
 
1443 1528
 	// Log what we've done.
1444
-	if (empty($user_info['id']))
1445
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1529
+	if (empty($user_info['id'])) {
1530
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1531
+	}
1446 1532
 
1447 1533
 	// Log the action manually, so CLI still works.
1448 1534
 	$smcFunc['db_insert']('',
@@ -1461,8 +1547,9 @@  discard block
 block discarded – undo
1461 1547
 
1462 1548
 	// Save the current database version.
1463 1549
 	$server_version = $smcFunc['db_server_info']();
1464
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1465
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1550
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1551
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1552
+	}
1466 1553
 
1467 1554
 	if ($command_line)
1468 1555
 	{
@@ -1474,8 +1561,9 @@  discard block
 block discarded – undo
1474 1561
 
1475 1562
 	// Make sure it says we're done.
1476 1563
 	$upcontext['overall_percent'] = 100;
1477
-	if (isset($upcontext['step_progress']))
1478
-		unset($upcontext['step_progress']);
1564
+	if (isset($upcontext['step_progress'])) {
1565
+			unset($upcontext['step_progress']);
1566
+	}
1479 1567
 
1480 1568
 	$_GET['substep'] = 0;
1481 1569
 	return false;
@@ -1486,8 +1574,9 @@  discard block
 block discarded – undo
1486 1574
 {
1487 1575
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1488 1576
 
1489
-	if (empty($modSettings['time_format']))
1490
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1577
+	if (empty($modSettings['time_format'])) {
1578
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1579
+	}
1491 1580
 
1492 1581
 	// What files do we want to get
1493 1582
 	$request = $smcFunc['db_query']('', '
@@ -1521,8 +1610,9 @@  discard block
 block discarded – undo
1521 1610
 		$file_data = fetch_web_data($url);
1522 1611
 
1523 1612
 		// If we got an error - give up - the site might be down.
1524
-		if ($file_data === false)
1525
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1613
+		if ($file_data === false) {
1614
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1615
+		}
1526 1616
 
1527 1617
 		// Save the file to the database.
1528 1618
 		$smcFunc['db_query']('substring', '
@@ -1564,8 +1654,9 @@  discard block
 block discarded – undo
1564 1654
 	$themeData = array();
1565 1655
 	foreach ($values as $variable => $value)
1566 1656
 	{
1567
-		if (!isset($value) || $value === null)
1568
-			$value = 0;
1657
+		if (!isset($value) || $value === null) {
1658
+					$value = 0;
1659
+		}
1569 1660
 
1570 1661
 		$themeData[] = array(0, 1, $variable, $value);
1571 1662
 	}
@@ -1594,8 +1685,9 @@  discard block
 block discarded – undo
1594 1685
 
1595 1686
 	foreach ($values as $variable => $value)
1596 1687
 	{
1597
-		if (empty($modSettings[$value[0]]))
1598
-			continue;
1688
+		if (empty($modSettings[$value[0]])) {
1689
+					continue;
1690
+		}
1599 1691
 
1600 1692
 		$smcFunc['db_query']('', '
1601 1693
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1628,8 +1720,9 @@  discard block
 block discarded – undo
1628 1720
 
1629 1721
 	$settingsArray = file($boarddir . '/Settings_bak.php');
1630 1722
 
1631
-	if (count($settingsArray) == 1)
1632
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1723
+	if (count($settingsArray) == 1) {
1724
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1725
+	}
1633 1726
 
1634 1727
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1635 1728
 	{
@@ -1642,9 +1735,9 @@  discard block
 block discarded – undo
1642 1735
 			{
1643 1736
 				if (isset($settingsArray[$i]) && strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1644 1737
 				{
1645
-					if ($val == '#remove#')
1646
-						unset($settingsArray[$i]);
1647
-					else
1738
+					if ($val == '#remove#') {
1739
+											unset($settingsArray[$i]);
1740
+					} else
1648 1741
 					{
1649 1742
 						$comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#');
1650 1743
 						$settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment != '' ? "\t\t" . $comment : "\n");
@@ -1656,22 +1749,25 @@  discard block
 block discarded – undo
1656 1749
 		}
1657 1750
 		if (isset($settingsArray[$i]))
1658 1751
 		{
1659
-			if (trim(substr($settingsArray[$i], 0, 2)) == '?' . '>')
1660
-				$end = $i;
1752
+			if (trim(substr($settingsArray[$i], 0, 2)) == '?' . '>') {
1753
+							$end = $i;
1754
+			}
1661 1755
 		}
1662 1756
 	}
1663 1757
 
1664 1758
 	// Assume end-of-file if the end wasn't found.
1665
-	if (empty($end) || $end < 10)
1666
-		$end = count($settingsArray);
1759
+	if (empty($end) || $end < 10) {
1760
+			$end = count($settingsArray);
1761
+	}
1667 1762
 
1668 1763
 	if (!empty($config_vars))
1669 1764
 	{
1670 1765
 		$settingsArray[$end++] = '';
1671 1766
 		foreach ($config_vars as $var => $val)
1672 1767
 		{
1673
-			if ($val != '#remove#')
1674
-				$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
1768
+			if ($val != '#remove#') {
1769
+							$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
1770
+			}
1675 1771
 		}
1676 1772
 	}
1677 1773
 	// This should be the last line and even last bytes of the file.
@@ -1684,8 +1780,9 @@  discard block
 block discarded – undo
1684 1780
 	$fp = fopen($boarddir . '/Settings.php', 'r+');
1685 1781
 	for ($i = 0; $i < $end; $i++)
1686 1782
 	{
1687
-		if (isset($settingsArray[$i]))
1688
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1783
+		if (isset($settingsArray[$i])) {
1784
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1785
+		}
1689 1786
 	}
1690 1787
 	fwrite($fp, rtrim($settingsArray[$i]));
1691 1788
 	fclose($fp);
@@ -1758,10 +1855,11 @@  discard block
 block discarded – undo
1758 1855
 		{
1759 1856
 			global $support_js;
1760 1857
 
1761
-			if ($support_js)
1762
-				return true;
1763
-			else
1764
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1858
+			if ($support_js) {
1859
+							return true;
1860
+			} else {
1861
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1862
+			}
1765 1863
 		}
1766 1864
 	}
1767 1865
 
@@ -1779,8 +1877,9 @@  discard block
 block discarded – undo
1779 1877
 				'db_error_skip' => true,
1780 1878
 			)
1781 1879
 		);
1782
-		if ($smcFunc['db_num_rows']($request) === 0)
1783
-			die('Unable to find members table!');
1880
+		if ($smcFunc['db_num_rows']($request) === 0) {
1881
+					die('Unable to find members table!');
1882
+		}
1784 1883
 		$table_status = $smcFunc['db_fetch_assoc']($request);
1785 1884
 		$smcFunc['db_free_result']($request);
1786 1885
 
@@ -1795,17 +1894,20 @@  discard block
 block discarded – undo
1795 1894
 				)
1796 1895
 			);
1797 1896
 			// Got something?
1798
-			if ($smcFunc['db_num_rows']($request) !== 0)
1799
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
1897
+			if ($smcFunc['db_num_rows']($request) !== 0) {
1898
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
1899
+			}
1800 1900
 			$smcFunc['db_free_result']($request);
1801 1901
 
1802 1902
 			// Excellent!
1803
-			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset']))
1804
-				$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1903
+			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) {
1904
+							$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1905
+			}
1805 1906
 		}
1806 1907
 	}
1807
-	if (empty($db_collation))
1808
-		$db_collation = '';
1908
+	if (empty($db_collation)) {
1909
+			$db_collation = '';
1910
+	}
1809 1911
 
1810 1912
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1811 1913
 
@@ -1817,8 +1919,9 @@  discard block
 block discarded – undo
1817 1919
 	$last_step = '';
1818 1920
 
1819 1921
 	// Make sure all newly created tables will have the proper characters set.
1820
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1821
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1922
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1923
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1924
+	}
1822 1925
 
1823 1926
 	// Count the total number of steps within this file - for progress.
1824 1927
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1838,15 +1941,18 @@  discard block
 block discarded – undo
1838 1941
 		$do_current = $substep >= $_GET['substep'];
1839 1942
 
1840 1943
 		// Get rid of any comments in the beginning of the line...
1841
-		if (substr(trim($line), 0, 2) === '/*')
1842
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1944
+		if (substr(trim($line), 0, 2) === '/*') {
1945
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1946
+		}
1843 1947
 
1844 1948
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1845
-		if ($is_debug && !$support_js && $command_line)
1846
-			flush();
1949
+		if ($is_debug && !$support_js && $command_line) {
1950
+					flush();
1951
+		}
1847 1952
 
1848
-		if (trim($line) === '')
1849
-			continue;
1953
+		if (trim($line) === '') {
1954
+					continue;
1955
+		}
1850 1956
 
1851 1957
 		if (trim(substr($line, 0, 3)) === '---')
1852 1958
 		{
@@ -1856,8 +1962,9 @@  discard block
 block discarded – undo
1856 1962
 			if (trim($current_data) != '' && $type !== '}')
1857 1963
 			{
1858 1964
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1859
-				if ($command_line)
1860
-					echo $upcontext['error_message'];
1965
+				if ($command_line) {
1966
+									echo $upcontext['error_message'];
1967
+				}
1861 1968
 			}
1862 1969
 
1863 1970
 			if ($type == ' ')
@@ -1875,17 +1982,18 @@  discard block
 block discarded – undo
1875 1982
 				if ($do_current)
1876 1983
 				{
1877 1984
 					$upcontext['actioned_items'][] = $last_step;
1878
-					if ($command_line)
1879
-						echo ' * ';
1985
+					if ($command_line) {
1986
+											echo ' * ';
1987
+					}
1880 1988
 				}
1881
-			}
1882
-			elseif ($type == '#')
1989
+			} elseif ($type == '#')
1883 1990
 			{
1884 1991
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1885 1992
 
1886 1993
 				$upcontext['current_debug_item_num']++;
1887
-				if (trim($line) != '---#')
1888
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1994
+				if (trim($line) != '---#') {
1995
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1996
+				}
1889 1997
 
1890 1998
 				// Have we already done something?
1891 1999
 				if (isset($_GET['xml']) && $done_something)
@@ -1896,34 +2004,36 @@  discard block
 block discarded – undo
1896 2004
 
1897 2005
 				if ($do_current)
1898 2006
 				{
1899
-					if (trim($line) == '---#' && $command_line)
1900
-						echo ' done.', $endl;
1901
-					elseif ($command_line)
1902
-						echo ' +++ ', rtrim(substr($line, 4));
1903
-					elseif (trim($line) != '---#')
2007
+					if (trim($line) == '---#' && $command_line) {
2008
+											echo ' done.', $endl;
2009
+					} elseif ($command_line) {
2010
+											echo ' +++ ', rtrim(substr($line, 4));
2011
+					} elseif (trim($line) != '---#')
1904 2012
 					{
1905
-						if ($is_debug)
1906
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
2013
+						if ($is_debug) {
2014
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
2015
+						}
1907 2016
 					}
1908 2017
 				}
1909 2018
 
1910 2019
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1911 2020
 				{
1912
-					if ($command_line)
1913
-						echo ' * ';
1914
-					else
1915
-						$upcontext['actioned_items'][] = $last_step;
2021
+					if ($command_line) {
2022
+											echo ' * ';
2023
+					} else {
2024
+											$upcontext['actioned_items'][] = $last_step;
2025
+					}
1916 2026
 				}
1917 2027
 
1918 2028
 				// Small step - only if we're actually doing stuff.
1919
-				if ($do_current)
1920
-					nextSubstep(++$substep);
1921
-				else
1922
-					$substep++;
1923
-			}
1924
-			elseif ($type == '{')
1925
-				$current_type = 'code';
1926
-			elseif ($type == '}')
2029
+				if ($do_current) {
2030
+									nextSubstep(++$substep);
2031
+				} else {
2032
+									$substep++;
2033
+				}
2034
+			} elseif ($type == '{') {
2035
+							$current_type = 'code';
2036
+			} elseif ($type == '}')
1927 2037
 			{
1928 2038
 				$current_type = 'sql';
1929 2039
 
@@ -1936,8 +2046,9 @@  discard block
 block discarded – undo
1936 2046
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1937 2047
 				{
1938 2048
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1939
-					if ($command_line)
1940
-						echo $upcontext['error_message'];
2049
+					if ($command_line) {
2050
+											echo $upcontext['error_message'];
2051
+					}
1941 2052
 				}
1942 2053
 
1943 2054
 				// Done with code!
@@ -2017,8 +2128,9 @@  discard block
 block discarded – undo
2017 2128
 	$db_unbuffered = false;
2018 2129
 
2019 2130
 	// Failure?!
2020
-	if ($result !== false)
2021
-		return $result;
2131
+	if ($result !== false) {
2132
+			return $result;
2133
+	}
2022 2134
 
2023 2135
 	$db_error_message = $smcFunc['db_error']($db_connection);
2024 2136
 	// If MySQL we do something more clever.
@@ -2046,54 +2158,61 @@  discard block
 block discarded – undo
2046 2158
 			{
2047 2159
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
2048 2160
 				$result = mysqli_query($db_connection, $string);
2049
-				if ($result !== false)
2050
-					return $result;
2161
+				if ($result !== false) {
2162
+									return $result;
2163
+				}
2051 2164
 			}
2052
-		}
2053
-		elseif ($mysqli_errno == 2013)
2165
+		} elseif ($mysqli_errno == 2013)
2054 2166
 		{
2055 2167
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
2056 2168
 			mysqli_select_db($db_connection, $db_name);
2057 2169
 			if ($db_connection)
2058 2170
 			{
2059 2171
 				$result = mysqli_query($db_connection, $string);
2060
-				if ($result !== false)
2061
-					return $result;
2172
+				if ($result !== false) {
2173
+									return $result;
2174
+				}
2062 2175
 			}
2063 2176
 		}
2064 2177
 		// Duplicate column name... should be okay ;).
2065
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
2066
-			return false;
2178
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2179
+					return false;
2180
+		}
2067 2181
 		// Duplicate insert... make sure it's the proper type of query ;).
2068
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
2069
-			return false;
2182
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2183
+					return false;
2184
+		}
2070 2185
 		// Creating an index on a non-existent column.
2071
-		elseif ($mysqli_errno == 1072)
2072
-			return false;
2073
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
2074
-			return false;
2186
+		elseif ($mysqli_errno == 1072) {
2187
+					return false;
2188
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2189
+					return false;
2190
+		}
2075 2191
 	}
2076 2192
 	// If a table already exists don't go potty.
2077 2193
 	else
2078 2194
 	{
2079 2195
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
2080 2196
 		{
2081
-			if (strpos($db_error_message, 'exist') !== false)
2082
-				return true;
2083
-		}
2084
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2197
+			if (strpos($db_error_message, 'exist') !== false) {
2198
+							return true;
2199
+			}
2200
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
2085 2201
 		{
2086
-			if (strpos($db_error_message, 'duplicate') !== false)
2087
-				return true;
2202
+			if (strpos($db_error_message, 'duplicate') !== false) {
2203
+							return true;
2204
+			}
2088 2205
 		}
2089 2206
 	}
2090 2207
 
2091 2208
 	// Get the query string so we pass everything.
2092 2209
 	$query_string = '';
2093
-	foreach ($_GET as $k => $v)
2094
-		$query_string .= ';' . $k . '=' . $v;
2095
-	if (strlen($query_string) != 0)
2096
-		$query_string = '?' . substr($query_string, 1);
2210
+	foreach ($_GET as $k => $v) {
2211
+			$query_string .= ';' . $k . '=' . $v;
2212
+	}
2213
+	if (strlen($query_string) != 0) {
2214
+			$query_string = '?' . substr($query_string, 1);
2215
+	}
2097 2216
 
2098 2217
 	if ($command_line)
2099 2218
 	{
@@ -2148,16 +2267,18 @@  discard block
 block discarded – undo
2148 2267
 			{
2149 2268
 				$found |= 1;
2150 2269
 				// Do some checks on the data if we have it set.
2151
-				if (isset($change['col_type']))
2152
-					$found &= $change['col_type'] === $column['type'];
2153
-				if (isset($change['null_allowed']))
2154
-					$found &= $column['null'] == $change['null_allowed'];
2155
-				if (isset($change['default']))
2156
-					$found &= $change['default'] === $column['default'];
2270
+				if (isset($change['col_type'])) {
2271
+									$found &= $change['col_type'] === $column['type'];
2272
+				}
2273
+				if (isset($change['null_allowed'])) {
2274
+									$found &= $column['null'] == $change['null_allowed'];
2275
+				}
2276
+				if (isset($change['default'])) {
2277
+									$found &= $change['default'] === $column['default'];
2278
+				}
2157 2279
 			}
2158 2280
 		}
2159
-	}
2160
-	elseif ($change['type'] === 'index')
2281
+	} elseif ($change['type'] === 'index')
2161 2282
 	{
2162 2283
 		$request = upgrade_query('
2163 2284
 			SHOW INDEX
@@ -2166,9 +2287,10 @@  discard block
 block discarded – undo
2166 2287
 		{
2167 2288
 			$cur_index = array();
2168 2289
 
2169
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2170
-				if ($row['Key_name'] === $change['name'])
2290
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2291
+							if ($row['Key_name'] === $change['name'])
2171 2292
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2293
+			}
2172 2294
 
2173 2295
 			ksort($cur_index, SORT_NUMERIC);
2174 2296
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2178,14 +2300,17 @@  discard block
 block discarded – undo
2178 2300
 	}
2179 2301
 
2180 2302
 	// If we're trying to add and it's added, we're done.
2181
-	if ($found && in_array($change['method'], array('add', 'change')))
2182
-		return true;
2303
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2304
+			return true;
2305
+	}
2183 2306
 	// Otherwise if we're removing and it wasn't found we're also done.
2184
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2185
-		return true;
2307
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2308
+			return true;
2309
+	}
2186 2310
 	// Otherwise is it just a test?
2187
-	elseif ($is_test)
2188
-		return false;
2311
+	elseif ($is_test) {
2312
+			return false;
2313
+	}
2189 2314
 
2190 2315
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2191 2316
 	$running = false;
@@ -2196,8 +2321,9 @@  discard block
 block discarded – undo
2196 2321
 			SHOW FULL PROCESSLIST');
2197 2322
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2198 2323
 		{
2199
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2200
-				$found = true;
2324
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2325
+							$found = true;
2326
+			}
2201 2327
 		}
2202 2328
 
2203 2329
 		// Can't find it? Then we need to run it fools!
@@ -2209,8 +2335,9 @@  discard block
 block discarded – undo
2209 2335
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2210 2336
 				' . $change['text'], true) !== false;
2211 2337
 
2212
-			if (!$success)
2213
-				return false;
2338
+			if (!$success) {
2339
+							return false;
2340
+			}
2214 2341
 
2215 2342
 			// Return
2216 2343
 			$running = true;
@@ -2252,8 +2379,9 @@  discard block
 block discarded – undo
2252 2379
 			'db_error_skip' => true,
2253 2380
 		)
2254 2381
 	);
2255
-	if ($smcFunc['db_num_rows']($request) === 0)
2256
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2382
+	if ($smcFunc['db_num_rows']($request) === 0) {
2383
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2384
+	}
2257 2385
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2258 2386
 	$smcFunc['db_free_result']($request);
2259 2387
 
@@ -2275,18 +2403,19 @@  discard block
 block discarded – undo
2275 2403
 			)
2276 2404
 		);
2277 2405
 		// No results? Just forget it all together.
2278
-		if ($smcFunc['db_num_rows']($request) === 0)
2279
-			unset($table_row['Collation']);
2280
-		else
2281
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2406
+		if ($smcFunc['db_num_rows']($request) === 0) {
2407
+					unset($table_row['Collation']);
2408
+		} else {
2409
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2410
+		}
2282 2411
 		$smcFunc['db_free_result']($request);
2283 2412
 	}
2284 2413
 
2285 2414
 	if ($column_fix)
2286 2415
 	{
2287 2416
 		// Make sure there are no NULL's left.
2288
-		if ($null_fix)
2289
-			$smcFunc['db_query']('', '
2417
+		if ($null_fix) {
2418
+					$smcFunc['db_query']('', '
2290 2419
 				UPDATE {db_prefix}' . $change['table'] . '
2291 2420
 				SET ' . $change['column'] . ' = {string:default}
2292 2421
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2295,6 +2424,7 @@  discard block
 block discarded – undo
2295 2424
 					'db_error_skip' => true,
2296 2425
 				)
2297 2426
 			);
2427
+		}
2298 2428
 
2299 2429
 		// Do the actual alteration.
2300 2430
 		$smcFunc['db_query']('', '
@@ -2323,8 +2453,9 @@  discard block
 block discarded – undo
2323 2453
 	}
2324 2454
 
2325 2455
 	// Not a column we need to check on?
2326
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2327
-		return;
2456
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2457
+			return;
2458
+	}
2328 2459
 
2329 2460
 	// Break it up you (six|seven).
2330 2461
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2343,13 +2474,13 @@  discard block
 block discarded – undo
2343 2474
 				'new_name' => $temp[2],
2344 2475
 		));
2345 2476
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2346
-		if ($smcFunc['db_num_rows'] != 1)
2347
-			return;
2477
+		if ($smcFunc['db_num_rows'] != 1) {
2478
+					return;
2479
+		}
2348 2480
 
2349 2481
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2350 2482
 		$smcFunc['db_free_result']($request);
2351
-	}
2352
-	else
2483
+	} else
2353 2484
 	{
2354 2485
 		// Do this the old fashion, sure method way.
2355 2486
 		$request = $smcFunc['db_query']('', '
@@ -2360,21 +2491,24 @@  discard block
 block discarded – undo
2360 2491
 		));
2361 2492
 		// Mayday!
2362 2493
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2363
-		if ($smcFunc['db_num_rows'] == 0)
2364
-			return;
2494
+		if ($smcFunc['db_num_rows'] == 0) {
2495
+					return;
2496
+		}
2365 2497
 
2366 2498
 		// Oh where, oh where has my little field gone. Oh where can it be...
2367
-		while ($row = $smcFunc['db_query']($request))
2368
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2499
+		while ($row = $smcFunc['db_query']($request)) {
2500
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2369 2501
 			{
2370 2502
 				$current_type = $row['Type'];
2503
+		}
2371 2504
 				break;
2372 2505
 			}
2373 2506
 	}
2374 2507
 
2375 2508
 	// If this doesn't match, the column may of been altered for a reason.
2376
-	if (trim($current_type) != trim($temp[3]))
2377
-		$temp[3] = $current_type;
2509
+	if (trim($current_type) != trim($temp[3])) {
2510
+			$temp[3] = $current_type;
2511
+	}
2378 2512
 
2379 2513
 	// Piece this back together.
2380 2514
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2386,8 +2520,9 @@  discard block
 block discarded – undo
2386 2520
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2387 2521
 	global $step_progress, $is_debug, $upcontext;
2388 2522
 
2389
-	if ($_GET['substep'] < $substep)
2390
-		$_GET['substep'] = $substep;
2523
+	if ($_GET['substep'] < $substep) {
2524
+			$_GET['substep'] = $substep;
2525
+	}
2391 2526
 
2392 2527
 	if ($command_line)
2393 2528
 	{
@@ -2400,29 +2535,33 @@  discard block
 block discarded – undo
2400 2535
 	}
2401 2536
 
2402 2537
 	@set_time_limit(300);
2403
-	if (function_exists('apache_reset_timeout'))
2404
-		@apache_reset_timeout();
2538
+	if (function_exists('apache_reset_timeout')) {
2539
+			@apache_reset_timeout();
2540
+	}
2405 2541
 
2406
-	if (time() - $start_time <= $timeLimitThreshold)
2407
-		return;
2542
+	if (time() - $start_time <= $timeLimitThreshold) {
2543
+			return;
2544
+	}
2408 2545
 
2409 2546
 	// Do we have some custom step progress stuff?
2410 2547
 	if (!empty($step_progress))
2411 2548
 	{
2412 2549
 		$upcontext['substep_progress'] = 0;
2413 2550
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2414
-		if ($step_progress['current'] > $step_progress['total'])
2415
-			$upcontext['substep_progress'] = 99.9;
2416
-		else
2417
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2551
+		if ($step_progress['current'] > $step_progress['total']) {
2552
+					$upcontext['substep_progress'] = 99.9;
2553
+		} else {
2554
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2555
+		}
2418 2556
 
2419 2557
 		// Make it nicely rounded.
2420 2558
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2421 2559
 	}
2422 2560
 
2423 2561
 	// If this is XML we just exit right away!
2424
-	if (isset($_GET['xml']))
2425
-		return upgradeExit();
2562
+	if (isset($_GET['xml'])) {
2563
+			return upgradeExit();
2564
+	}
2426 2565
 
2427 2566
 	// We're going to pause after this!
2428 2567
 	$upcontext['pause'] = true;
@@ -2430,13 +2569,15 @@  discard block
 block discarded – undo
2430 2569
 	$upcontext['query_string'] = '';
2431 2570
 	foreach ($_GET as $k => $v)
2432 2571
 	{
2433
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2434
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2572
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2573
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2574
+		}
2435 2575
 	}
2436 2576
 
2437 2577
 	// Custom warning?
2438
-	if (!empty($custom_warning))
2439
-		$upcontext['custom_warning'] = $custom_warning;
2578
+	if (!empty($custom_warning)) {
2579
+			$upcontext['custom_warning'] = $custom_warning;
2580
+	}
2440 2581
 
2441 2582
 	upgradeExit();
2442 2583
 }
@@ -2451,25 +2592,26 @@  discard block
 block discarded – undo
2451 2592
 	ob_implicit_flush(true);
2452 2593
 	@set_time_limit(600);
2453 2594
 
2454
-	if (!isset($_SERVER['argv']))
2455
-		$_SERVER['argv'] = array();
2595
+	if (!isset($_SERVER['argv'])) {
2596
+			$_SERVER['argv'] = array();
2597
+	}
2456 2598
 	$_GET['maint'] = 1;
2457 2599
 
2458 2600
 	foreach ($_SERVER['argv'] as $i => $arg)
2459 2601
 	{
2460
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2461
-			$_GET['lang'] = $match[1];
2462
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2463
-			continue;
2464
-		elseif ($arg == '--no-maintenance')
2465
-			$_GET['maint'] = 0;
2466
-		elseif ($arg == '--debug')
2467
-			$is_debug = true;
2468
-		elseif ($arg == '--backup')
2469
-			$_POST['backup'] = 1;
2470
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2471
-			$_GET['conv'] = 1;
2472
-		elseif ($i != 0)
2602
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2603
+					$_GET['lang'] = $match[1];
2604
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2605
+					continue;
2606
+		} elseif ($arg == '--no-maintenance') {
2607
+					$_GET['maint'] = 0;
2608
+		} elseif ($arg == '--debug') {
2609
+					$is_debug = true;
2610
+		} elseif ($arg == '--backup') {
2611
+					$_POST['backup'] = 1;
2612
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2613
+					$_GET['conv'] = 1;
2614
+		} elseif ($i != 0)
2473 2615
 		{
2474 2616
 			echo 'SMF Command-line Upgrader
2475 2617
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2483,10 +2625,12 @@  discard block
 block discarded – undo
2483 2625
 		}
2484 2626
 	}
2485 2627
 
2486
-	if (!php_version_check())
2487
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2488
-	if (!db_version_check())
2489
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2628
+	if (!php_version_check()) {
2629
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2630
+	}
2631
+	if (!db_version_check()) {
2632
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2633
+	}
2490 2634
 
2491 2635
 	// Do some checks to make sure they have proper privileges
2492 2636
 	db_extend('packages');
@@ -2501,34 +2645,39 @@  discard block
 block discarded – undo
2501 2645
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2502 2646
 
2503 2647
 	// Sorry... we need CREATE, ALTER and DROP
2504
-	if (!$create || !$alter || !$drop)
2505
-		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);
2648
+	if (!$create || !$alter || !$drop) {
2649
+			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);
2650
+	}
2506 2651
 
2507 2652
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2508 2653
 		&& @file_exists($sourcedir . '/QueryString.php')
2509 2654
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2510
-	if (!$check && !isset($modSettings['smfVersion']))
2511
-		print_error('Error: Some files are missing or out-of-date.', true);
2655
+	if (!$check && !isset($modSettings['smfVersion'])) {
2656
+			print_error('Error: Some files are missing or out-of-date.', true);
2657
+	}
2512 2658
 
2513 2659
 	// Do a quick version spot check.
2514 2660
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2515 2661
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2516
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2517
-		print_error('Error: Some files have not yet been updated properly.');
2662
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2663
+			print_error('Error: Some files have not yet been updated properly.');
2664
+	}
2518 2665
 
2519 2666
 	// Make sure Settings.php is writable.
2520 2667
 		quickFileWritable($boarddir . '/Settings.php');
2521
-	if (!is_writable($boarddir . '/Settings.php'))
2522
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2668
+	if (!is_writable($boarddir . '/Settings.php')) {
2669
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2670
+	}
2523 2671
 
2524 2672
 	// Make sure Settings_bak.php is writable.
2525 2673
 		quickFileWritable($boarddir . '/Settings_bak.php');
2526
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2527
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2674
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2675
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2676
+	}
2528 2677
 
2529
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2530
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2531
-	elseif (isset($modSettings['agreement']))
2678
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2679
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2680
+	} elseif (isset($modSettings['agreement']))
2532 2681
 	{
2533 2682
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2534 2683
 		fwrite($fp, $modSettings['agreement']);
@@ -2538,31 +2687,36 @@  discard block
 block discarded – undo
2538 2687
 	// Make sure Themes is writable.
2539 2688
 	quickFileWritable($modSettings['theme_dir']);
2540 2689
 
2541
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2542
-		print_error('Error: Unable to obtain write access to "Themes".');
2690
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2691
+			print_error('Error: Unable to obtain write access to "Themes".');
2692
+	}
2543 2693
 
2544 2694
 	// Make sure cache directory exists and is writable!
2545 2695
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2546
-	if (!file_exists($cachedir_temp))
2547
-		@mkdir($cachedir_temp);
2696
+	if (!file_exists($cachedir_temp)) {
2697
+			@mkdir($cachedir_temp);
2698
+	}
2548 2699
 
2549 2700
 	// Make sure the cache temp dir is writable.
2550 2701
 	quickFileWritable($cachedir_temp);
2551 2702
 
2552
-	if (!is_writable($cachedir_temp))
2553
-		print_error('Error: Unable to obtain write access to "cache".', true);
2703
+	if (!is_writable($cachedir_temp)) {
2704
+			print_error('Error: Unable to obtain write access to "cache".', true);
2705
+	}
2554 2706
 
2555
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2556
-		print_error('Error: Unable to find language files!', true);
2557
-	else
2707
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2708
+			print_error('Error: Unable to find language files!', true);
2709
+	} else
2558 2710
 	{
2559 2711
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2560 2712
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2561 2713
 
2562
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2563
-			print_error('Error: Language files out of date.', true);
2564
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2565
-			print_error('Error: Install language is missing for selected language.', true);
2714
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2715
+					print_error('Error: Language files out of date.', true);
2716
+		}
2717
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2718
+					print_error('Error: Install language is missing for selected language.', true);
2719
+		}
2566 2720
 
2567 2721
 		// Otherwise include it!
2568 2722
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2591,8 +2745,7 @@  discard block
 block discarded – undo
2591 2745
 		);
2592 2746
 		
2593 2747
 		return true;
2594
-	}
2595
-	else
2748
+	} else
2596 2749
 	{
2597 2750
 		$upcontext['page_title'] = 'Converting to UTF8';
2598 2751
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2636,8 +2789,9 @@  discard block
 block discarded – undo
2636 2789
 			)
2637 2790
 		);
2638 2791
 		$db_charsets = array();
2639
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2640
-			$db_charsets[] = $row['Charset'];
2792
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2793
+					$db_charsets[] = $row['Charset'];
2794
+		}
2641 2795
 
2642 2796
 		$smcFunc['db_free_result']($request);
2643 2797
 
@@ -2673,13 +2827,15 @@  discard block
 block discarded – undo
2673 2827
 		// If there's a fulltext index, we need to drop it first...
2674 2828
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2675 2829
 		{
2676
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2677
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2830
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2831
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2678 2832
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2833
+			}
2679 2834
 			$smcFunc['db_free_result']($request);
2680 2835
 
2681
-			if (isset($upcontext['fulltext_index']))
2682
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2836
+			if (isset($upcontext['fulltext_index'])) {
2837
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2838
+			}
2683 2839
 		}
2684 2840
 
2685 2841
 		// Drop it and make a note...
@@ -2869,8 +3025,9 @@  discard block
 block discarded – undo
2869 3025
 			$replace = '%field%';
2870 3026
 
2871 3027
 			// Build a huge REPLACE statement...
2872
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2873
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3028
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
3029
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3030
+			}
2874 3031
 		}
2875 3032
 
2876 3033
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2904,8 +3061,9 @@  discard block
 block discarded – undo
2904 3061
 			$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2905 3062
 
2906 3063
 			// Just to make sure it doesn't time out.
2907
-			if (function_exists('apache_reset_timeout'))
2908
-				@apache_reset_timeout();
3064
+			if (function_exists('apache_reset_timeout')) {
3065
+							@apache_reset_timeout();
3066
+			}
2909 3067
 
2910 3068
 			$table_charsets = array();
2911 3069
 
@@ -2926,8 +3084,9 @@  discard block
 block discarded – undo
2926 3084
 					{
2927 3085
 						list($charset) = explode('_', $collation);
2928 3086
 
2929
-						if (!isset($table_charsets[$charset]))
2930
-							$table_charsets[$charset] = array();
3087
+						if (!isset($table_charsets[$charset])) {
3088
+													$table_charsets[$charset] = array();
3089
+						}
2931 3090
 
2932 3091
 						$table_charsets[$charset][] = $column_info;
2933 3092
 					}
@@ -2967,10 +3126,11 @@  discard block
 block discarded – undo
2967 3126
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2968 3127
 				{
2969 3128
 					$update = '';
2970
-					foreach ($table_charsets as $charset => $columns)
2971
-						foreach ($columns as $column)
3129
+					foreach ($table_charsets as $charset => $columns) {
3130
+											foreach ($columns as $column)
2972 3131
 							$update .= '
2973 3132
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3133
+					}
2974 3134
 
2975 3135
 					$smcFunc['db_query']('', '
2976 3136
 						UPDATE {raw:table_name}
@@ -2995,8 +3155,9 @@  discard block
 block discarded – undo
2995 3155
 			// Now do the actual conversion (if still needed).
2996 3156
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2997 3157
 			{
2998
-				if ($command_line)
2999
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3158
+				if ($command_line) {
3159
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3160
+				}
3000 3161
 
3001 3162
 				$smcFunc['db_query']('', '
3002 3163
 					ALTER TABLE {raw:table_name}
@@ -3006,8 +3167,9 @@  discard block
 block discarded – undo
3006 3167
 						)
3007 3168
 				);
3008 3169
 
3009
-				if ($command_line)
3010
-					echo " done.\n";
3170
+				if ($command_line) {
3171
+									echo " done.\n";
3172
+				}
3011 3173
 			}
3012 3174
 		}
3013 3175
 
@@ -3037,8 +3199,8 @@  discard block
 block discarded – undo
3037 3199
 		);
3038 3200
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3039 3201
 		{
3040
-			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)
3041
-				$smcFunc['db_query']('', '
3202
+			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) {
3203
+							$smcFunc['db_query']('', '
3042 3204
 					UPDATE {db_prefix}log_actions
3043 3205
 					SET extra = {string:extra}
3044 3206
 					WHERE id_action = {int:current_action}',
@@ -3047,6 +3209,7 @@  discard block
 block discarded – undo
3047 3209
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
3048 3210
 					)
3049 3211
 				);
3212
+			}
3050 3213
 		}
3051 3214
 		$smcFunc['db_free_result']($request);
3052 3215
 
@@ -3068,15 +3231,17 @@  discard block
 block discarded – undo
3068 3231
 	// First thing's first - did we already do this?
3069 3232
 	if (!empty($modSettings['json_done']))
3070 3233
 	{
3071
-		if ($command_line)
3072
-			return DeleteUpgrade();
3073
-		else
3074
-			return true;
3234
+		if ($command_line) {
3235
+					return DeleteUpgrade();
3236
+		} else {
3237
+					return true;
3238
+		}
3075 3239
 	}
3076 3240
 
3077 3241
 	// Done it already - js wise?
3078
-	if (!empty($_POST['json_done']))
3079
-		return true;
3242
+	if (!empty($_POST['json_done'])) {
3243
+			return true;
3244
+	}
3080 3245
 
3081 3246
 	// List of tables affected by this function
3082 3247
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3107,12 +3272,14 @@  discard block
 block discarded – undo
3107 3272
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3108 3273
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3109 3274
 
3110
-	foreach ($keys as $id => $table)
3111
-		if ($id < $_GET['substep'])
3275
+	foreach ($keys as $id => $table) {
3276
+			if ($id < $_GET['substep'])
3112 3277
 			$upcontext['previous_tables'][] = $table;
3278
+	}
3113 3279
 
3114
-	if ($command_line)
3115
-		echo 'Converting data from serialize() to json_encode().';
3280
+	if ($command_line) {
3281
+			echo 'Converting data from serialize() to json_encode().';
3282
+	}
3116 3283
 
3117 3284
 	if (!$support_js || isset($_GET['xml']))
3118 3285
 	{
@@ -3152,8 +3319,9 @@  discard block
 block discarded – undo
3152 3319
 
3153 3320
 				// Loop through and fix these...
3154 3321
 				$new_settings = array();
3155
-				if ($command_line)
3156
-					echo "\n" . 'Fixing some settings...';
3322
+				if ($command_line) {
3323
+									echo "\n" . 'Fixing some settings...';
3324
+				}
3157 3325
 
3158 3326
 				foreach ($serialized_settings as $var)
3159 3327
 				{
@@ -3161,22 +3329,24 @@  discard block
 block discarded – undo
3161 3329
 					{
3162 3330
 						// Attempt to unserialize the setting
3163 3331
 						$temp = @safe_unserialize($modSettings[$var]);
3164
-						if (!$temp && $command_line)
3165
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3166
-						elseif ($temp !== false)
3167
-							$new_settings[$var] = json_encode($temp);
3332
+						if (!$temp && $command_line) {
3333
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3334
+						} elseif ($temp !== false) {
3335
+													$new_settings[$var] = json_encode($temp);
3336
+						}
3168 3337
 					}
3169 3338
 				}
3170 3339
 
3171 3340
 				// Update everything at once
3172
-				if (!function_exists('cache_put_data'))
3173
-					require_once($sourcedir . '/Load.php');
3341
+				if (!function_exists('cache_put_data')) {
3342
+									require_once($sourcedir . '/Load.php');
3343
+				}
3174 3344
 				updateSettings($new_settings, true);
3175 3345
 
3176
-				if ($command_line)
3177
-					echo ' done.';
3178
-			}
3179
-			elseif ($table == 'themes')
3346
+				if ($command_line) {
3347
+									echo ' done.';
3348
+				}
3349
+			} elseif ($table == 'themes')
3180 3350
 			{
3181 3351
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3182 3352
 				$query = $smcFunc['db_query']('', '
@@ -3195,10 +3365,11 @@  discard block
 block discarded – undo
3195 3365
 
3196 3366
 						if ($command_line)
3197 3367
 						{
3198
-							if ($temp === false)
3199
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3200
-							else
3201
-								echo "\n" . 'Fixing admin preferences...';
3368
+							if ($temp === false) {
3369
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3370
+							} else {
3371
+															echo "\n" . 'Fixing admin preferences...';
3372
+							}
3202 3373
 						}
3203 3374
 
3204 3375
 						if ($temp !== false)
@@ -3218,15 +3389,15 @@  discard block
 block discarded – undo
3218 3389
 								)
3219 3390
 							);
3220 3391
 
3221
-							if ($command_line)
3222
-								echo ' done.';
3392
+							if ($command_line) {
3393
+															echo ' done.';
3394
+							}
3223 3395
 						}
3224 3396
 					}
3225 3397
 
3226 3398
 					$smcFunc['db_free_result']($query);
3227 3399
 				}
3228
-			}
3229
-			else
3400
+			} else
3230 3401
 			{
3231 3402
 				// First item is always the key...
3232 3403
 				$key = $info[0];
@@ -3237,8 +3408,7 @@  discard block
 block discarded – undo
3237 3408
 				{
3238 3409
 					$col_select = $info[1];
3239 3410
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3240
-				}
3241
-				else
3411
+				} else
3242 3412
 				{
3243 3413
 					$col_select = implode(', ', $info);
3244 3414
 				}
@@ -3271,8 +3441,7 @@  discard block
 block discarded – undo
3271 3441
 								if ($temp === false && $command_line)
3272 3442
 								{
3273 3443
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3274
-								}
3275
-								else
3444
+								} else
3276 3445
 								{
3277 3446
 									$row[$col] = json_encode($temp);
3278 3447
 
@@ -3297,16 +3466,18 @@  discard block
 block discarded – undo
3297 3466
 						}
3298 3467
 					}
3299 3468
 
3300
-					if ($command_line)
3301
-						echo ' done.';
3469
+					if ($command_line) {
3470
+											echo ' done.';
3471
+					}
3302 3472
 
3303 3473
 					// Free up some memory...
3304 3474
 					$smcFunc['db_free_result']($query);
3305 3475
 				}
3306 3476
 			}
3307 3477
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3308
-			if (isset($_GET['xml']))
3309
-				return upgradeExit();
3478
+			if (isset($_GET['xml'])) {
3479
+							return upgradeExit();
3480
+			}
3310 3481
 		}
3311 3482
 
3312 3483
 		if ($command_line)
@@ -3321,8 +3492,9 @@  discard block
 block discarded – undo
3321 3492
 
3322 3493
 		$_GET['substep'] = 0;
3323 3494
 		// Make sure we move on!
3324
-		if ($command_line)
3325
-			return DeleteUpgrade();
3495
+		if ($command_line) {
3496
+					return DeleteUpgrade();
3497
+		}
3326 3498
 
3327 3499
 		return true;
3328 3500
 	}
@@ -3342,14 +3514,16 @@  discard block
 block discarded – undo
3342 3514
 	global $upcontext, $txt, $settings;
3343 3515
 
3344 3516
 	// Don't call me twice!
3345
-	if (!empty($upcontext['chmod_called']))
3346
-		return;
3517
+	if (!empty($upcontext['chmod_called'])) {
3518
+			return;
3519
+	}
3347 3520
 
3348 3521
 	$upcontext['chmod_called'] = true;
3349 3522
 
3350 3523
 	// Nothing?
3351
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3352
-		return;
3524
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3525
+			return;
3526
+	}
3353 3527
 
3354 3528
 	// Was it a problem with Windows?
3355 3529
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3381,11 +3555,12 @@  discard block
 block discarded – undo
3381 3555
 					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\');
3382 3556
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3383 3557
 
3384
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3385
-		echo '
3558
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3559
+			echo '
3386 3560
 					content.write(\'<hr>\n\t\t\t\');
3387 3561
 					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\');
3388 3562
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3563
+	}
3389 3564
 
3390 3565
 	echo '
3391 3566
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3393,17 +3568,19 @@  discard block
 block discarded – undo
3393 3568
 				}
3394 3569
 		</script>';
3395 3570
 
3396
-	if (!empty($upcontext['chmod']['ftp_error']))
3397
-		echo '
3571
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3572
+			echo '
3398 3573
 			<div class="error_message red">
3399 3574
 				The following error was encountered when trying to connect:<br><br>
3400 3575
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3401 3576
 			</div>
3402 3577
 			<br>';
3578
+	}
3403 3579
 
3404
-	if (empty($upcontext['chmod_in_form']))
3405
-		echo '
3580
+	if (empty($upcontext['chmod_in_form'])) {
3581
+			echo '
3406 3582
 	<form action="', $upcontext['form_url'], '" method="post">';
3583
+	}
3407 3584
 
3408 3585
 	echo '
3409 3586
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3438,10 +3615,11 @@  discard block
 block discarded – undo
3438 3615
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3439 3616
 	</div>';
3440 3617
 
3441
-	if (empty($upcontext['chmod_in_form']))
3442
-		echo '
3618
+	if (empty($upcontext['chmod_in_form'])) {
3619
+			echo '
3443 3620
 	</form>';
3444
-}
3621
+	}
3622
+	}
3445 3623
 
3446 3624
 function template_upgrade_above()
3447 3625
 {
@@ -3501,9 +3679,10 @@  discard block
 block discarded – undo
3501 3679
 				<h2>', $txt['upgrade_progress'], '</h2>
3502 3680
 				<ul>';
3503 3681
 
3504
-	foreach ($upcontext['steps'] as $num => $step)
3505
-		echo '
3682
+	foreach ($upcontext['steps'] as $num => $step) {
3683
+			echo '
3506 3684
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3685
+	}
3507 3686
 
3508 3687
 	echo '
3509 3688
 					</ul>
@@ -3516,8 +3695,8 @@  discard block
 block discarded – undo
3516 3695
 				</div>
3517 3696
 			</div>';
3518 3697
 
3519
-	if (isset($upcontext['step_progress']))
3520
-		echo '
3698
+	if (isset($upcontext['step_progress'])) {
3699
+			echo '
3521 3700
 				<br>
3522 3701
 				<br>
3523 3702
 				<div id="progress_bar_step">
@@ -3526,6 +3705,7 @@  discard block
 block discarded – undo
3526 3705
 						<span>', $txt['upgrade_step_progress'], '</span>
3527 3706
 					</div>
3528 3707
 				</div>';
3708
+	}
3529 3709
 
3530 3710
 	echo '
3531 3711
 				<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>
@@ -3556,32 +3736,36 @@  discard block
 block discarded – undo
3556 3736
 {
3557 3737
 	global $upcontext, $txt;
3558 3738
 
3559
-	if (!empty($upcontext['pause']))
3560
-		echo '
3739
+	if (!empty($upcontext['pause'])) {
3740
+			echo '
3561 3741
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3562 3742
 
3563 3743
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3564 3744
 								<h3>
3565 3745
 									', $txt['upgrade_paused_overload'], '
3566 3746
 								</h3>';
3747
+	}
3567 3748
 
3568
-	if (!empty($upcontext['custom_warning']))
3569
-		echo '
3749
+	if (!empty($upcontext['custom_warning'])) {
3750
+			echo '
3570 3751
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3571 3752
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3572 3753
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3573 3754
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3574 3755
 								</div>';
3756
+	}
3575 3757
 
3576 3758
 	echo '
3577 3759
 								<div class="righttext" style="margin: 1ex;">';
3578 3760
 
3579
-	if (!empty($upcontext['continue']))
3580
-		echo '
3761
+	if (!empty($upcontext['continue'])) {
3762
+			echo '
3581 3763
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3582
-	if (!empty($upcontext['skip']))
3583
-		echo '
3764
+	}
3765
+	if (!empty($upcontext['skip'])) {
3766
+			echo '
3584 3767
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3768
+	}
3585 3769
 
3586 3770
 	echo '
3587 3771
 								</div>
@@ -3631,11 +3815,12 @@  discard block
 block discarded – undo
3631 3815
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3632 3816
 	<smf>';
3633 3817
 
3634
-	if (!empty($upcontext['get_data']))
3635
-		foreach ($upcontext['get_data'] as $k => $v)
3818
+	if (!empty($upcontext['get_data'])) {
3819
+			foreach ($upcontext['get_data'] as $k => $v)
3636 3820
 			echo '
3637 3821
 		<get key="', $k, '">', $v, '</get>';
3638
-}
3822
+	}
3823
+	}
3639 3824
 
3640 3825
 function template_xml_below()
3641 3826
 {
@@ -3676,8 +3861,8 @@  discard block
 block discarded – undo
3676 3861
 	template_chmod();
3677 3862
 
3678 3863
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3679
-	if ($upcontext['is_large_forum'])
3680
-		echo '
3864
+	if ($upcontext['is_large_forum']) {
3865
+			echo '
3681 3866
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3682 3867
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3683 3868
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3685,10 +3870,11 @@  discard block
 block discarded – undo
3685 3870
 				', $txt['upgrade_warning_lots_data'], '
3686 3871
 			</div>
3687 3872
 		</div>';
3873
+	}
3688 3874
 
3689 3875
 	// A warning message?
3690
-	if (!empty($upcontext['warning']))
3691
-		echo '
3876
+	if (!empty($upcontext['warning'])) {
3877
+			echo '
3692 3878
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3693 3879
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3694 3880
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3696,6 +3882,7 @@  discard block
 block discarded – undo
3696 3882
 				', $upcontext['warning'], '
3697 3883
 			</div>
3698 3884
 		</div>';
3885
+	}
3699 3886
 
3700 3887
 	// Paths are incorrect?
3701 3888
 	echo '
@@ -3711,20 +3898,22 @@  discard block
 block discarded – undo
3711 3898
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3712 3899
 	{
3713 3900
 		$ago = time() - $upcontext['started'];
3714
-		if ($ago < 60)
3715
-			$ago = $ago . ' seconds';
3716
-		elseif ($ago < 3600)
3717
-			$ago = (int) ($ago / 60) . ' minutes';
3718
-		else
3719
-			$ago = (int) ($ago / 3600) . ' hours';
3901
+		if ($ago < 60) {
3902
+					$ago = $ago . ' seconds';
3903
+		} elseif ($ago < 3600) {
3904
+					$ago = (int) ($ago / 60) . ' minutes';
3905
+		} else {
3906
+					$ago = (int) ($ago / 3600) . ' hours';
3907
+		}
3720 3908
 
3721 3909
 		$active = time() - $upcontext['updated'];
3722
-		if ($active < 60)
3723
-			$updated = $active . ' seconds';
3724
-		elseif ($active < 3600)
3725
-			$updated = (int) ($active / 60) . ' minutes';
3726
-		else
3727
-			$updated = (int) ($active / 3600) . ' hours';
3910
+		if ($active < 60) {
3911
+					$updated = $active . ' seconds';
3912
+		} elseif ($active < 3600) {
3913
+					$updated = (int) ($active / 60) . ' minutes';
3914
+		} else {
3915
+					$updated = (int) ($active / 3600) . ' hours';
3916
+		}
3728 3917
 
3729 3918
 		echo '
3730 3919
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3733,16 +3922,18 @@  discard block
 block discarded – undo
3733 3922
 			<div style="padding-left: 6ex;">
3734 3923
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3735 3924
 
3736
-		if ($active < 600)
3737
-			echo '
3925
+		if ($active < 600) {
3926
+					echo '
3738 3927
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3928
+		}
3739 3929
 
3740
-		if ($active > $upcontext['inactive_timeout'])
3741
-			echo '
3930
+		if ($active > $upcontext['inactive_timeout']) {
3931
+					echo '
3742 3932
 				<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.';
3743
-		else
3744
-			echo '
3933
+		} else {
3934
+					echo '
3745 3935
 				<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!');
3936
+		}
3746 3937
 
3747 3938
 		echo '
3748 3939
 			</div>
@@ -3758,9 +3949,10 @@  discard block
 block discarded – undo
3758 3949
 					<td>
3759 3950
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3760 3951
 
3761
-	if (!empty($upcontext['username_incorrect']))
3762
-		echo '
3952
+	if (!empty($upcontext['username_incorrect'])) {
3953
+			echo '
3763 3954
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3955
+	}
3764 3956
 
3765 3957
 	echo '
3766 3958
 					</td>
@@ -3771,9 +3963,10 @@  discard block
 block discarded – undo
3771 3963
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3772 3964
 						<input type="hidden" name="hash_passwrd" value="">';
3773 3965
 
3774
-	if (!empty($upcontext['password_failed']))
3775
-		echo '
3966
+	if (!empty($upcontext['password_failed'])) {
3967
+			echo '
3776 3968
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3969
+	}
3777 3970
 
3778 3971
 	echo '
3779 3972
 					</td>
@@ -3844,8 +4037,8 @@  discard block
 block discarded – undo
3844 4037
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3845 4038
 
3846 4039
 	// Warning message?
3847
-	if (!empty($upcontext['upgrade_options_warning']))
3848
-		echo '
4040
+	if (!empty($upcontext['upgrade_options_warning'])) {
4041
+			echo '
3849 4042
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3850 4043
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3851 4044
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3853,6 +4046,7 @@  discard block
 block discarded – undo
3853 4046
 				', $upcontext['upgrade_options_warning'], '
3854 4047
 			</div>
3855 4048
 		</div>';
4049
+	}
3856 4050
 
3857 4051
 	echo '
3858 4052
 				<table>
@@ -3880,8 +4074,8 @@  discard block
 block discarded – undo
3880 4074
 					</tr>';
3881 4075
 
3882 4076
 	// Offer mysql users to switch to mysqli
3883
-	if ($db_type == 'mysql' && function_exists('mysqli_query'))
3884
-		echo '
4077
+	if ($db_type == 'mysql' && function_exists('mysqli_query')) {
4078
+			echo '
3885 4079
 					<tr valign="top">
3886 4080
 						<td width="2%">
3887 4081
 							<input type="checkbox" name="convertMysql" id="convertMysql" value="1" checked class="input_check">
@@ -3891,6 +4085,7 @@  discard block
 block discarded – undo
3891 4085
 							<strong class="smalltext"><a href="http://wiki.simplemachines.org/smf/Upgrading-MySQLi-Functionality" target="_blank">More information about MySQLi</a></strong><br>
3892 4086
 						</td>
3893 4087
 					</tr>';
4088
+	}
3894 4089
 
3895 4090
 	echo '
3896 4091
 					<tr valign="top">
@@ -3910,8 +4105,8 @@  discard block
 block discarded – undo
3910 4105
 						</td>
3911 4106
 					</tr>';
3912 4107
 
3913
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3914
-		echo '
4108
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4109
+			echo '
3915 4110
 					<tr valign="top">
3916 4111
 						<td width="2%">
3917 4112
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3920,6 +4115,7 @@  discard block
 block discarded – undo
3920 4115
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3921 4116
 						</td>
3922 4117
 					</tr>';
4118
+	}
3923 4119
 
3924 4120
 	echo '
3925 4121
 					<tr valign="top">
@@ -3955,10 +4151,11 @@  discard block
 block discarded – undo
3955 4151
 			<span id="debuginfo"></span>';
3956 4152
 
3957 4153
 	// Dont any tables so far?
3958
-	if (!empty($upcontext['previous_tables']))
3959
-		foreach ($upcontext['previous_tables'] as $table)
4154
+	if (!empty($upcontext['previous_tables'])) {
4155
+			foreach ($upcontext['previous_tables'] as $table)
3960 4156
 			echo '
3961 4157
 			<br>Completed Table: &quot;', $table, '&quot;.';
4158
+	}
3962 4159
 
3963 4160
 	echo '
3964 4161
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3995,12 +4192,13 @@  discard block
 block discarded – undo
3995 4192
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3996 4193
 
3997 4194
 		// If debug flood the screen.
3998
-		if ($is_debug)
3999
-			echo '
4195
+		if ($is_debug) {
4196
+					echo '
4000 4197
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4001 4198
 
4002 4199
 				if (document.getElementById(\'debuginfo\').scrollHeight)
4003 4200
 					document.getElementById(\'debuginfo\').scrollTop = document.getElementById(\'debuginfo\').scrollHeight;';
4201
+		}
4004 4202
 
4005 4203
 		echo '
4006 4204
 				// Get the next update...
@@ -4032,8 +4230,9 @@  discard block
 block discarded – undo
4032 4230
 {
4033 4231
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
4034 4232
 
4035
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
4036
-		$is_debug = true;
4233
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4234
+			$is_debug = true;
4235
+	}
4037 4236
 
4038 4237
 	echo '
4039 4238
 		<h3>Executing database changes</h3>
@@ -4048,8 +4247,9 @@  discard block
 block discarded – undo
4048 4247
 	{
4049 4248
 		foreach ($upcontext['actioned_items'] as $num => $item)
4050 4249
 		{
4051
-			if ($num != 0)
4052
-				echo ' Successful!';
4250
+			if ($num != 0) {
4251
+							echo ' Successful!';
4252
+			}
4053 4253
 			echo '<br>' . $item;
4054 4254
 		}
4055 4255
 		if (!empty($upcontext['changes_complete']))
@@ -4062,28 +4262,32 @@  discard block
 block discarded – undo
4062 4262
 				$seconds = intval($active % 60);
4063 4263
 
4064 4264
 				$totalTime = '';
4065
-				if ($hours > 0)
4066
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4067
-				if ($minutes > 0)
4068
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4069
-				if ($seconds > 0)
4070
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4265
+				if ($hours > 0) {
4266
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4267
+				}
4268
+				if ($minutes > 0) {
4269
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4270
+				}
4271
+				if ($seconds > 0) {
4272
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4273
+				}
4071 4274
 			}
4072 4275
 
4073
-			if ($is_debug && !empty($totalTime))
4074
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
4075
-			else
4076
-				echo ' Successful!<br><br>';
4276
+			if ($is_debug && !empty($totalTime)) {
4277
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4278
+			} else {
4279
+							echo ' Successful!<br><br>';
4280
+			}
4077 4281
 
4078 4282
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
4079 4283
 		}
4080
-	}
4081
-	else
4284
+	} else
4082 4285
 	{
4083 4286
 		// Tell them how many files we have in total.
4084
-		if ($upcontext['file_count'] > 1)
4085
-			echo '
4287
+		if ($upcontext['file_count'] > 1) {
4288
+					echo '
4086 4289
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4290
+		}
4087 4291
 
4088 4292
 		echo '
4089 4293
 		<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>
@@ -4099,19 +4303,23 @@  discard block
 block discarded – undo
4099 4303
 				$seconds = intval($active % 60);
4100 4304
 
4101 4305
 				$totalTime = '';
4102
-				if ($hours > 0)
4103
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4104
-				if ($minutes > 0)
4105
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4106
-				if ($seconds > 0)
4107
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4306
+				if ($hours > 0) {
4307
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4308
+				}
4309
+				if ($minutes > 0) {
4310
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4311
+				}
4312
+				if ($seconds > 0) {
4313
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4314
+				}
4108 4315
 			}
4109 4316
 
4110 4317
 			echo '
4111 4318
 			<br><span id="upgradeCompleted">';
4112 4319
 
4113
-			if (!empty($totalTime))
4114
-				echo 'Completed in ', $totalTime, '<br>';
4320
+			if (!empty($totalTime)) {
4321
+							echo 'Completed in ', $totalTime, '<br>';
4322
+			}
4115 4323
 
4116 4324
 			echo '</span>
4117 4325
 			<div id="debug_section" style="height: 200px; overflow: auto;">
@@ -4148,9 +4356,10 @@  discard block
 block discarded – undo
4148 4356
 			var getData = "";
4149 4357
 			var debugItems = ', $upcontext['debug_items'], ';';
4150 4358
 
4151
-		if ($is_debug)
4152
-			echo '
4359
+		if ($is_debug) {
4360
+					echo '
4153 4361
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4362
+		}
4154 4363
 
4155 4364
 		echo '
4156 4365
 			function getNextItem()
@@ -4190,9 +4399,10 @@  discard block
 block discarded – undo
4190 4399
 						document.getElementById("error_block").style.display = "";
4191 4400
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4192 4401
 
4193
-	if ($is_debug)
4194
-		echo '
4402
+	if ($is_debug) {
4403
+			echo '
4195 4404
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4405
+	}
4196 4406
 
4197 4407
 	echo '
4198 4408
 					}
@@ -4213,9 +4423,10 @@  discard block
 block discarded – undo
4213 4423
 						document.getElementById("error_block").style.display = "";
4214 4424
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4215 4425
 
4216
-	if ($is_debug)
4217
-		echo '
4426
+	if ($is_debug) {
4427
+			echo '
4218 4428
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4429
+	}
4219 4430
 
4220 4431
 	echo '
4221 4432
 					}
@@ -4274,8 +4485,8 @@  discard block
 block discarded – undo
4274 4485
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4275 4486
 				{';
4276 4487
 
4277
-		if ($is_debug)
4278
-			echo '
4488
+		if ($is_debug) {
4489
+					echo '
4279 4490
 					document.getElementById(\'debug_section\').style.display = "none";
4280 4491
 
4281 4492
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4293,6 +4504,7 @@  discard block
 block discarded – undo
4293 4504
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4294 4505
 
4295 4506
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4507
+		}
4296 4508
 
4297 4509
 		echo '
4298 4510
 
@@ -4300,9 +4512,10 @@  discard block
 block discarded – undo
4300 4512
 					document.getElementById(\'contbutt\').disabled = 0;
4301 4513
 					document.getElementById(\'database_done\').value = 1;';
4302 4514
 
4303
-		if ($upcontext['file_count'] > 1)
4304
-			echo '
4515
+		if ($upcontext['file_count'] > 1) {
4516
+					echo '
4305 4517
 					document.getElementById(\'info1\').style.display = "none";';
4518
+		}
4306 4519
 
4307 4520
 		echo '
4308 4521
 					document.getElementById(\'info2\').style.display = "none";
@@ -4315,9 +4528,10 @@  discard block
 block discarded – undo
4315 4528
 					lastItem = 0;
4316 4529
 					prevFile = curFile;';
4317 4530
 
4318
-		if ($is_debug)
4319
-			echo '
4531
+		if ($is_debug) {
4532
+					echo '
4320 4533
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4534
+		}
4321 4535
 
4322 4536
 		echo '
4323 4537
 					getNextItem();
@@ -4325,8 +4539,8 @@  discard block
 block discarded – undo
4325 4539
 				}';
4326 4540
 
4327 4541
 		// If debug scroll the screen.
4328
-		if ($is_debug)
4329
-			echo '
4542
+		if ($is_debug) {
4543
+					echo '
4330 4544
 				if (iLastSubStepProgress == -1)
4331 4545
 				{
4332 4546
 					// Give it consistent dots.
@@ -4345,6 +4559,7 @@  discard block
 block discarded – undo
4345 4559
 
4346 4560
 				if (document.getElementById(\'debug_section\').scrollHeight)
4347 4561
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4562
+		}
4348 4563
 
4349 4564
 		echo '
4350 4565
 				// Update the page.
@@ -4405,9 +4620,10 @@  discard block
 block discarded – undo
4405 4620
 			}';
4406 4621
 
4407 4622
 		// Start things off assuming we've not errored.
4408
-		if (empty($upcontext['error_message']))
4409
-			echo '
4623
+		if (empty($upcontext['error_message'])) {
4624
+					echo '
4410 4625
 			getNextItem();';
4626
+		}
4411 4627
 
4412 4628
 		echo '
4413 4629
 		</script>';
@@ -4424,18 +4640,21 @@  discard block
 block discarded – undo
4424 4640
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4425 4641
 	<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>';
4426 4642
 
4427
-	if (!empty($upcontext['error_message']))
4428
-		echo '
4643
+	if (!empty($upcontext['error_message'])) {
4644
+			echo '
4429 4645
 	<error>', $upcontext['error_message'], '</error>';
4646
+	}
4430 4647
 
4431
-	if (!empty($upcontext['error_string']))
4432
-		echo '
4648
+	if (!empty($upcontext['error_string'])) {
4649
+			echo '
4433 4650
 	<sql>', $upcontext['error_string'], '</sql>';
4651
+	}
4434 4652
 
4435
-	if ($is_debug)
4436
-		echo '
4653
+	if ($is_debug) {
4654
+			echo '
4437 4655
 	<curtime>', time(), '</curtime>';
4438
-}
4656
+	}
4657
+	}
4439 4658
 
4440 4659
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4441 4660
 function template_convert_utf8()
@@ -4452,18 +4671,20 @@  discard block
 block discarded – undo
4452 4671
 			<span id="debuginfo"></span>';
4453 4672
 
4454 4673
 	// Done any tables so far?
4455
-	if (!empty($upcontext['previous_tables']))
4456
-		foreach ($upcontext['previous_tables'] as $table)
4674
+	if (!empty($upcontext['previous_tables'])) {
4675
+			foreach ($upcontext['previous_tables'] as $table)
4457 4676
 			echo '
4458 4677
 			<br>Completed Table: &quot;', $table, '&quot;.';
4678
+	}
4459 4679
 
4460 4680
 	echo '
4461 4681
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4462 4682
 
4463 4683
 	// If we dropped their index, let's let them know
4464
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
4465
-		echo '
4684
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
4685
+			echo '
4466 4686
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
4687
+	}
4467 4688
 
4468 4689
 	echo '
4469 4690
 			<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>';
@@ -4499,9 +4720,10 @@  discard block
 block discarded – undo
4499 4720
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4500 4721
 
4501 4722
 		// If debug flood the screen.
4502
-		if ($is_debug)
4503
-			echo '
4723
+		if ($is_debug) {
4724
+					echo '
4504 4725
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4726
+		}
4505 4727
 
4506 4728
 		echo '
4507 4729
 				// Get the next update...
@@ -4543,19 +4765,21 @@  discard block
 block discarded – undo
4543 4765
 			<span id="debuginfo"></span>';
4544 4766
 
4545 4767
 	// Dont any tables so far?
4546
-	if (!empty($upcontext['previous_tables']))
4547
-		foreach ($upcontext['previous_tables'] as $table)
4768
+	if (!empty($upcontext['previous_tables'])) {
4769
+			foreach ($upcontext['previous_tables'] as $table)
4548 4770
 			echo '
4549 4771
 			<br>Completed Table: &quot;', $table, '&quot;.';
4772
+	}
4550 4773
 
4551 4774
 	echo '
4552 4775
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4553 4776
 			<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>';
4554 4777
 
4555 4778
 	// Try to make sure substep was reset.
4556
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4557
-		echo '
4779
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4780
+			echo '
4558 4781
 			<input type="hidden" name="substep" id="substep" value="0">';
4782
+	}
4559 4783
 
4560 4784
 	// Continue please!
4561 4785
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4588,9 +4812,10 @@  discard block
 block discarded – undo
4588 4812
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4589 4813
 
4590 4814
 		// If debug flood the screen.
4591
-		if ($is_debug)
4592
-			echo '
4815
+		if ($is_debug) {
4816
+					echo '
4593 4817
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4818
+		}
4594 4819
 
4595 4820
 		echo '
4596 4821
 				// Get the next update...
@@ -4625,8 +4850,8 @@  discard block
 block discarded – undo
4625 4850
 	<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>
4626 4851
 	<form action="', $boardurl, '/index.php">';
4627 4852
 
4628
-	if (!empty($upcontext['can_delete_script']))
4629
-		echo '
4853
+	if (!empty($upcontext['can_delete_script'])) {
4854
+			echo '
4630 4855
 			<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>
4631 4856
 			<script>
4632 4857
 				function doTheDelete(theCheck)
@@ -4638,6 +4863,7 @@  discard block
 block discarded – undo
4638 4863
 				}
4639 4864
 			</script>
4640 4865
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4866
+	}
4641 4867
 
4642 4868
 	$active = time() - $upcontext['started'];
4643 4869
 	$hours = floor($active / 3600);
@@ -4647,16 +4873,20 @@  discard block
 block discarded – undo
4647 4873
 	if ($is_debug)
4648 4874
 	{
4649 4875
 		$totalTime = '';
4650
-		if ($hours > 0)
4651
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4652
-		if ($minutes > 0)
4653
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4654
-		if ($seconds > 0)
4655
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4876
+		if ($hours > 0) {
4877
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4878
+		}
4879
+		if ($minutes > 0) {
4880
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4881
+		}
4882
+		if ($seconds > 0) {
4883
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4884
+		}
4656 4885
 	}
4657 4886
 
4658
-	if ($is_debug && !empty($totalTime))
4659
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4887
+	if ($is_debug && !empty($totalTime)) {
4888
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4889
+	}
4660 4890
 
4661 4891
 	echo '<br>
4662 4892
 			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>
@@ -4723,16 +4953,19 @@  discard block
 block discarded – undo
4723 4953
 				'empty' => '',
4724 4954
 				'limit' => $limit,
4725 4955
 		));
4726
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4727
-			$arIp[] = $row[$oldCol];
4956
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4957
+					$arIp[] = $row[$oldCol];
4958
+		}
4728 4959
 		$smcFunc['db_free_result']($request);
4729 4960
 
4730 4961
 		// Special case, null ip could keep us in a loop.
4731
-		if (is_null($arIp[0]))
4732
-			unset($arIp[0]);
4962
+		if (is_null($arIp[0])) {
4963
+					unset($arIp[0]);
4964
+		}
4733 4965
 
4734
-		if (empty($arIp))
4735
-			$is_done = true;
4966
+		if (empty($arIp)) {
4967
+					$is_done = true;
4968
+		}
4736 4969
 
4737 4970
 		$updates = array();
4738 4971
 		$cases = array();
@@ -4741,16 +4974,18 @@  discard block
 block discarded – undo
4741 4974
 		{
4742 4975
 			$arIp[$i] = trim($arIp[$i]);
4743 4976
 
4744
-			if (empty($arIp[$i]))
4745
-				continue;
4977
+			if (empty($arIp[$i])) {
4978
+							continue;
4979
+			}
4746 4980
 
4747 4981
 			$updates['ip' . $i] = $arIp[$i];
4748 4982
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4749 4983
 
4750 4984
 			if ($setSize > 0 && $i % $setSize === 0)
4751 4985
 			{
4752
-				if (count($updates) == 1)
4753
-					continue;
4986
+				if (count($updates) == 1) {
4987
+									continue;
4988
+				}
4754 4989
 
4755 4990
 				$updates['whereSet'] = array_values($updates);
4756 4991
 				$smcFunc['db_query']('', '
@@ -4784,8 +5019,7 @@  discard block
 block discarded – undo
4784 5019
 							'ip' => $ip
4785 5020
 					));
4786 5021
 				}
4787
-			}
4788
-			else
5022
+			} else
4789 5023
 			{
4790 5024
 				$updates['whereSet'] = array_values($updates);
4791 5025
 				$smcFunc['db_query']('', '
@@ -4799,9 +5033,9 @@  discard block
 block discarded – undo
4799 5033
 					$updates
4800 5034
 				);
4801 5035
 			}
5036
+		} else {
5037
+					$is_done = true;
4802 5038
 		}
4803
-		else
4804
-			$is_done = true;
4805 5039
 
4806 5040
 		$_GET['a'] += $limit;
4807 5041
 		$step_progress['current'] = $_GET['a'];
Please login to merge, or discard this patch.
other/upgrade-helper.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 /**
142 142
  * Make files writable. First try to use regular chmod, but if that fails, try to use FTP.
143 143
  *
144
- * @param $files
144
+ * @param string[] $files
145 145
  * @return bool
146 146
  */
147 147
 function makeFilesWritable(&$files)
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 /**
382 382
  * Prints an error to stderr.
383 383
  *
384
- * @param $message
384
+ * @param string $message
385 385
  * @param bool $fatal
386 386
  */
387 387
 function print_error($message, $fatal = false)
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 /**
401 401
  * Throws a graphical error message.
402 402
  *
403
- * @param $message
403
+ * @param string $message
404 404
  * @return bool
405 405
  */
406 406
 function throw_error($message)
Please login to merge, or discard this patch.
Indentation   +307 added lines, -307 removed lines patch added patch discarded remove patch
@@ -14,66 +14,66 @@  discard block
 block discarded – undo
14 14
  */
15 15
 
16 16
 if (!defined('SMF_VERSION'))
17
-    die('No direct access!');
17
+	die('No direct access!');
18 18
 
19 19
 if (!function_exists('un_htmlspecialchars'))
20 20
 {
21
-    /**
22
-     * Undo the voodoo htmlspecialchars does.
23
-     *
24
-     * @param $string
25
-     * @return string
26
-     */
27
-    function un_htmlspecialchars($string)
28
-    {
29
-        return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)) + array('&#039;' => '\'', '&nbsp;' => ' '));
30
-    }
21
+	/**
22
+	 * Undo the voodoo htmlspecialchars does.
23
+	 *
24
+	 * @param $string
25
+	 * @return string
26
+	 */
27
+	function un_htmlspecialchars($string)
28
+	{
29
+		return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)) + array('&#039;' => '\'', '&nbsp;' => ' '));
30
+	}
31 31
 }
32 32
 
33 33
 if (!function_exists('text2words'))
34 34
 {
35
-    /**
36
-     * Split a sentence into words.
37
-     *
38
-     * @param $text
39
-     * @return array
40
-     */
41
-    function text2words($text)
42
-    {
43
-        // Step 1: Remove entities/things we don't consider words:
44
-        $words = preg_replace('~(?:[\x0B\0\xA0\t\r\s\n(){}\\[\\]<>!@$%^*.,:+=`\~\?/\\\\]+|&(?:amp|lt|gt|quot);)+~', ' ', $text);
45
-
46
-        // Step 2: Entities we left to letters, where applicable, lowercase.
47
-        $words = preg_replace('~([^&\d]|^)[#;]~', '$1 ', un_htmlspecialchars(strtolower($words)));
48
-
49
-        // Step 3: Ready to split apart and index!
50
-        $words = explode(' ', $words);
51
-        $returned_words = array();
52
-        foreach ($words as $word)
53
-        {
54
-            $word = trim($word, '-_\'');
55
-
56
-            if ($word != '')
57
-                $returned_words[] = substr($word, 0, 20);
58
-        }
59
-
60
-        return array_unique($returned_words);
61
-    }
35
+	/**
36
+	 * Split a sentence into words.
37
+	 *
38
+	 * @param $text
39
+	 * @return array
40
+	 */
41
+	function text2words($text)
42
+	{
43
+		// Step 1: Remove entities/things we don't consider words:
44
+		$words = preg_replace('~(?:[\x0B\0\xA0\t\r\s\n(){}\\[\\]<>!@$%^*.,:+=`\~\?/\\\\]+|&(?:amp|lt|gt|quot);)+~', ' ', $text);
45
+
46
+		// Step 2: Entities we left to letters, where applicable, lowercase.
47
+		$words = preg_replace('~([^&\d]|^)[#;]~', '$1 ', un_htmlspecialchars(strtolower($words)));
48
+
49
+		// Step 3: Ready to split apart and index!
50
+		$words = explode(' ', $words);
51
+		$returned_words = array();
52
+		foreach ($words as $word)
53
+		{
54
+			$word = trim($word, '-_\'');
55
+
56
+			if ($word != '')
57
+				$returned_words[] = substr($word, 0, 20);
58
+		}
59
+
60
+		return array_unique($returned_words);
61
+	}
62 62
 }
63 63
 
64 64
 if (!function_exists('md5_hmac'))
65 65
 {
66
-    /**
67
-     * Generate an MD5 hash using the HMAC method.
68
-     *
69
-     * @param string $data
70
-     * @param string $key
71
-     * @return string
72
-     */
73
-    function md5_hmac($data, $key)
74
-    {
75
-        return hash_hmac('md5', $data, $key);
76
-    }
66
+	/**
67
+	 * Generate an MD5 hash using the HMAC method.
68
+	 *
69
+	 * @param string $data
70
+	 * @param string $key
71
+	 * @return string
72
+	 */
73
+	function md5_hmac($data, $key)
74
+	{
75
+		return hash_hmac('md5', $data, $key);
76
+	}
77 77
 }
78 78
 
79 79
 /**
@@ -82,17 +82,17 @@  discard block
 block discarded – undo
82 82
  */
83 83
 function upgrade_clean_cache()
84 84
 {
85
-    global $cacheAPI, $sourcedir;
85
+	global $cacheAPI, $sourcedir;
86 86
 
87
-    // Initialize the cache API if it does not have an instance yet.
88
-    if (empty($cacheAPI))
89
-    {
90
-        require_once($sourcedir . '/Load.php');
91
-        loadCacheAccelerator();
92
-    }
87
+	// Initialize the cache API if it does not have an instance yet.
88
+	if (empty($cacheAPI))
89
+	{
90
+		require_once($sourcedir . '/Load.php');
91
+		loadCacheAccelerator();
92
+	}
93 93
 
94
-    // Just fall back to Load.php's clean_cache function.
95
-    clean_cache();
94
+	// Just fall back to Load.php's clean_cache function.
95
+	clean_cache();
96 96
 }
97 97
 
98 98
 /**
@@ -102,40 +102,40 @@  discard block
 block discarded – undo
102 102
  */
103 103
 function getMemberGroups()
104 104
 {
105
-    global $smcFunc;
106
-    static $member_groups = array();
105
+	global $smcFunc;
106
+	static $member_groups = array();
107 107
 
108
-    if (!empty($member_groups))
109
-        return $member_groups;
108
+	if (!empty($member_groups))
109
+		return $member_groups;
110 110
 
111
-    $request = $smcFunc['db_query']('', '
111
+	$request = $smcFunc['db_query']('', '
112 112
 		SELECT group_name, id_group
113 113
 		FROM {db_prefix}membergroups
114 114
 		WHERE id_group = {int:admin_group} OR id_group > {int:old_group}',
115
-        array(
116
-            'admin_group' => 1,
117
-            'old_group' => 7,
118
-            'db_error_skip' => true,
119
-        )
120
-    );
121
-    if ($request === false)
122
-    {
123
-        $request = $smcFunc['db_query']('', '
115
+		array(
116
+			'admin_group' => 1,
117
+			'old_group' => 7,
118
+			'db_error_skip' => true,
119
+		)
120
+	);
121
+	if ($request === false)
122
+	{
123
+		$request = $smcFunc['db_query']('', '
124 124
 			SELECT membergroup, id_group
125 125
 			FROM {db_prefix}membergroups
126 126
 			WHERE id_group = {int:admin_group} OR id_group > {int:old_group}',
127
-            array(
128
-                'admin_group' => 1,
129
-                'old_group' => 7,
130
-                'db_error_skip' => true,
131
-            )
132
-        );
133
-    }
134
-    while ($row = $smcFunc['db_fetch_row']($request))
135
-        $member_groups[trim($row[0])] = $row[1];
136
-    $smcFunc['db_free_result']($request);
137
-
138
-    return $member_groups;
127
+			array(
128
+				'admin_group' => 1,
129
+				'old_group' => 7,
130
+				'db_error_skip' => true,
131
+			)
132
+		);
133
+	}
134
+	while ($row = $smcFunc['db_fetch_row']($request))
135
+		$member_groups[trim($row[0])] = $row[1];
136
+	$smcFunc['db_free_result']($request);
137
+
138
+	return $member_groups;
139 139
 }
140 140
 
141 141
 /**
@@ -146,197 +146,197 @@  discard block
 block discarded – undo
146 146
  */
147 147
 function makeFilesWritable(&$files)
148 148
 {
149
-    global $upcontext, $boarddir;
150
-
151
-    if (empty($files))
152
-        return true;
153
-
154
-    $failure = false;
155
-    // On linux, it's easy - just use is_writable!
156
-    if (substr(__FILE__, 1, 2) != ':\\')
157
-    {
158
-        $upcontext['systemos'] = 'linux';
159
-
160
-        foreach ($files as $k => $file)
161
-        {
162
-            if (!is_writable($file))
163
-            {
164
-                @chmod($file, 0755);
165
-
166
-                // Well, 755 hopefully worked... if not, try 777.
167
-                if (!is_writable($file) && !@chmod($file, 0777))
168
-                    $failure = true;
169
-                // Otherwise remove it as it's good!
170
-                else
171
-                    unset($files[$k]);
172
-            }
173
-            else
174
-                unset($files[$k]);
175
-        }
176
-    }
177
-    // Windows is trickier.  Let's try opening for r+...
178
-    else
179
-    {
180
-        $upcontext['systemos'] = 'windows';
181
-
182
-        foreach ($files as $k => $file)
183
-        {
184
-            // Folders can't be opened for write... but the index.php in them can ;).
185
-            if (is_dir($file))
186
-                $file .= '/index.php';
187
-
188
-            // Funny enough, chmod actually does do something on windows - it removes the read only attribute.
189
-            @chmod($file, 0777);
190
-            $fp = @fopen($file, 'r+');
191
-
192
-            // Hmm, okay, try just for write in that case...
193
-            if (!$fp)
194
-                $fp = @fopen($file, 'w');
195
-
196
-            if (!$fp)
197
-                $failure = true;
198
-            else
199
-                unset($files[$k]);
200
-            @fclose($fp);
201
-        }
202
-    }
203
-
204
-    if (empty($files))
205
-        return true;
206
-
207
-    if (!isset($_SERVER))
208
-        return !$failure;
209
-
210
-    // What still needs to be done?
211
-    $upcontext['chmod']['files'] = $files;
212
-
213
-    // If it's windows it's a mess...
214
-    if ($failure && substr(__FILE__, 1, 2) == ':\\')
215
-    {
216
-        $upcontext['chmod']['ftp_error'] = 'total_mess';
217
-
218
-        return false;
219
-    }
220
-    // We're going to have to use... FTP!
221
-    elseif ($failure)
222
-    {
223
-        // Load any session data we might have...
224
-        if (!isset($_POST['ftp_username']) && isset($_SESSION['installer_temp_ftp']))
225
-        {
226
-            $upcontext['chmod']['server'] = $_SESSION['installer_temp_ftp']['server'];
227
-            $upcontext['chmod']['port'] = $_SESSION['installer_temp_ftp']['port'];
228
-            $upcontext['chmod']['username'] = $_SESSION['installer_temp_ftp']['username'];
229
-            $upcontext['chmod']['password'] = $_SESSION['installer_temp_ftp']['password'];
230
-            $upcontext['chmod']['path'] = $_SESSION['installer_temp_ftp']['path'];
231
-        }
232
-        // Or have we submitted?
233
-        elseif (isset($_POST['ftp_username']))
234
-        {
235
-            $upcontext['chmod']['server'] = $_POST['ftp_server'];
236
-            $upcontext['chmod']['port'] = $_POST['ftp_port'];
237
-            $upcontext['chmod']['username'] = $_POST['ftp_username'];
238
-            $upcontext['chmod']['password'] = $_POST['ftp_password'];
239
-            $upcontext['chmod']['path'] = $_POST['ftp_path'];
240
-        }
241
-
242
-        if (isset($upcontext['chmod']['username']))
243
-        {
244
-            $ftp = new ftp_connection($upcontext['chmod']['server'], $upcontext['chmod']['port'], $upcontext['chmod']['username'], $upcontext['chmod']['password']);
245
-
246
-            if ($ftp->error === false)
247
-            {
248
-                // Try it without /home/abc just in case they messed up.
249
-                if (!$ftp->chdir($upcontext['chmod']['path']))
250
-                {
251
-                    $upcontext['chmod']['ftp_error'] = $ftp->last_message;
252
-                    $ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $upcontext['chmod']['path']));
253
-                }
254
-            }
255
-        }
256
-
257
-        if (!isset($ftp) || $ftp->error !== false)
258
-        {
259
-            if (!isset($ftp))
260
-                $ftp = new ftp_connection(null);
261
-            // Save the error so we can mess with listing...
262
-            elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error']))
263
-                $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
264
-
265
-            list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
266
-
267
-            if ($found_path || !isset($upcontext['chmod']['path']))
268
-                $upcontext['chmod']['path'] = $detect_path;
269
-
270
-            if (!isset($upcontext['chmod']['username']))
271
-                $upcontext['chmod']['username'] = $username;
272
-
273
-            // Don't forget the login token.
274
-            $upcontext += createToken('login');
275
-
276
-            return false;
277
-        }
278
-        else
279
-        {
280
-            // We want to do a relative path for FTP.
281
-            if (!in_array($upcontext['chmod']['path'], array('', '/')))
282
-            {
283
-                $ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => ''));
284
-                if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/'))
285
-                    $ftp_root = substr($ftp_root, 0, -1);
286
-            }
287
-            else
288
-                $ftp_root = $boarddir;
289
-
290
-            // Save the info for next time!
291
-            $_SESSION['installer_temp_ftp'] = array(
292
-                'server' => $upcontext['chmod']['server'],
293
-                'port' => $upcontext['chmod']['port'],
294
-                'username' => $upcontext['chmod']['username'],
295
-                'password' => $upcontext['chmod']['password'],
296
-                'path' => $upcontext['chmod']['path'],
297
-                'root' => $ftp_root,
298
-            );
299
-
300
-            foreach ($files as $k => $file)
301
-            {
302
-                if (!is_writable($file))
303
-                    $ftp->chmod($file, 0755);
304
-                if (!is_writable($file))
305
-                    $ftp->chmod($file, 0777);
306
-
307
-                // Assuming that didn't work calculate the path without the boarddir.
308
-                if (!is_writable($file))
309
-                {
310
-                    if (strpos($file, $boarddir) === 0)
311
-                    {
312
-                        $ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => ''));
313
-                        $ftp->chmod($ftp_file, 0755);
314
-                        if (!is_writable($file))
315
-                            $ftp->chmod($ftp_file, 0777);
316
-                        // Sometimes an extra slash can help...
317
-                        $ftp_file = '/' . $ftp_file;
318
-                        if (!is_writable($file))
319
-                            $ftp->chmod($ftp_file, 0755);
320
-                        if (!is_writable($file))
321
-                            $ftp->chmod($ftp_file, 0777);
322
-                    }
323
-                }
324
-
325
-                if (is_writable($file))
326
-                    unset($files[$k]);
327
-            }
328
-
329
-            $ftp->close();
330
-        }
331
-    }
332
-
333
-    // What remains?
334
-    $upcontext['chmod']['files'] = $files;
335
-
336
-    if (empty($files))
337
-        return true;
338
-
339
-    return false;
149
+	global $upcontext, $boarddir;
150
+
151
+	if (empty($files))
152
+		return true;
153
+
154
+	$failure = false;
155
+	// On linux, it's easy - just use is_writable!
156
+	if (substr(__FILE__, 1, 2) != ':\\')
157
+	{
158
+		$upcontext['systemos'] = 'linux';
159
+
160
+		foreach ($files as $k => $file)
161
+		{
162
+			if (!is_writable($file))
163
+			{
164
+				@chmod($file, 0755);
165
+
166
+				// Well, 755 hopefully worked... if not, try 777.
167
+				if (!is_writable($file) && !@chmod($file, 0777))
168
+					$failure = true;
169
+				// Otherwise remove it as it's good!
170
+				else
171
+					unset($files[$k]);
172
+			}
173
+			else
174
+				unset($files[$k]);
175
+		}
176
+	}
177
+	// Windows is trickier.  Let's try opening for r+...
178
+	else
179
+	{
180
+		$upcontext['systemos'] = 'windows';
181
+
182
+		foreach ($files as $k => $file)
183
+		{
184
+			// Folders can't be opened for write... but the index.php in them can ;).
185
+			if (is_dir($file))
186
+				$file .= '/index.php';
187
+
188
+			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
189
+			@chmod($file, 0777);
190
+			$fp = @fopen($file, 'r+');
191
+
192
+			// Hmm, okay, try just for write in that case...
193
+			if (!$fp)
194
+				$fp = @fopen($file, 'w');
195
+
196
+			if (!$fp)
197
+				$failure = true;
198
+			else
199
+				unset($files[$k]);
200
+			@fclose($fp);
201
+		}
202
+	}
203
+
204
+	if (empty($files))
205
+		return true;
206
+
207
+	if (!isset($_SERVER))
208
+		return !$failure;
209
+
210
+	// What still needs to be done?
211
+	$upcontext['chmod']['files'] = $files;
212
+
213
+	// If it's windows it's a mess...
214
+	if ($failure && substr(__FILE__, 1, 2) == ':\\')
215
+	{
216
+		$upcontext['chmod']['ftp_error'] = 'total_mess';
217
+
218
+		return false;
219
+	}
220
+	// We're going to have to use... FTP!
221
+	elseif ($failure)
222
+	{
223
+		// Load any session data we might have...
224
+		if (!isset($_POST['ftp_username']) && isset($_SESSION['installer_temp_ftp']))
225
+		{
226
+			$upcontext['chmod']['server'] = $_SESSION['installer_temp_ftp']['server'];
227
+			$upcontext['chmod']['port'] = $_SESSION['installer_temp_ftp']['port'];
228
+			$upcontext['chmod']['username'] = $_SESSION['installer_temp_ftp']['username'];
229
+			$upcontext['chmod']['password'] = $_SESSION['installer_temp_ftp']['password'];
230
+			$upcontext['chmod']['path'] = $_SESSION['installer_temp_ftp']['path'];
231
+		}
232
+		// Or have we submitted?
233
+		elseif (isset($_POST['ftp_username']))
234
+		{
235
+			$upcontext['chmod']['server'] = $_POST['ftp_server'];
236
+			$upcontext['chmod']['port'] = $_POST['ftp_port'];
237
+			$upcontext['chmod']['username'] = $_POST['ftp_username'];
238
+			$upcontext['chmod']['password'] = $_POST['ftp_password'];
239
+			$upcontext['chmod']['path'] = $_POST['ftp_path'];
240
+		}
241
+
242
+		if (isset($upcontext['chmod']['username']))
243
+		{
244
+			$ftp = new ftp_connection($upcontext['chmod']['server'], $upcontext['chmod']['port'], $upcontext['chmod']['username'], $upcontext['chmod']['password']);
245
+
246
+			if ($ftp->error === false)
247
+			{
248
+				// Try it without /home/abc just in case they messed up.
249
+				if (!$ftp->chdir($upcontext['chmod']['path']))
250
+				{
251
+					$upcontext['chmod']['ftp_error'] = $ftp->last_message;
252
+					$ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $upcontext['chmod']['path']));
253
+				}
254
+			}
255
+		}
256
+
257
+		if (!isset($ftp) || $ftp->error !== false)
258
+		{
259
+			if (!isset($ftp))
260
+				$ftp = new ftp_connection(null);
261
+			// Save the error so we can mess with listing...
262
+			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error']))
263
+				$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
264
+
265
+			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
266
+
267
+			if ($found_path || !isset($upcontext['chmod']['path']))
268
+				$upcontext['chmod']['path'] = $detect_path;
269
+
270
+			if (!isset($upcontext['chmod']['username']))
271
+				$upcontext['chmod']['username'] = $username;
272
+
273
+			// Don't forget the login token.
274
+			$upcontext += createToken('login');
275
+
276
+			return false;
277
+		}
278
+		else
279
+		{
280
+			// We want to do a relative path for FTP.
281
+			if (!in_array($upcontext['chmod']['path'], array('', '/')))
282
+			{
283
+				$ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => ''));
284
+				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/'))
285
+					$ftp_root = substr($ftp_root, 0, -1);
286
+			}
287
+			else
288
+				$ftp_root = $boarddir;
289
+
290
+			// Save the info for next time!
291
+			$_SESSION['installer_temp_ftp'] = array(
292
+				'server' => $upcontext['chmod']['server'],
293
+				'port' => $upcontext['chmod']['port'],
294
+				'username' => $upcontext['chmod']['username'],
295
+				'password' => $upcontext['chmod']['password'],
296
+				'path' => $upcontext['chmod']['path'],
297
+				'root' => $ftp_root,
298
+			);
299
+
300
+			foreach ($files as $k => $file)
301
+			{
302
+				if (!is_writable($file))
303
+					$ftp->chmod($file, 0755);
304
+				if (!is_writable($file))
305
+					$ftp->chmod($file, 0777);
306
+
307
+				// Assuming that didn't work calculate the path without the boarddir.
308
+				if (!is_writable($file))
309
+				{
310
+					if (strpos($file, $boarddir) === 0)
311
+					{
312
+						$ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => ''));
313
+						$ftp->chmod($ftp_file, 0755);
314
+						if (!is_writable($file))
315
+							$ftp->chmod($ftp_file, 0777);
316
+						// Sometimes an extra slash can help...
317
+						$ftp_file = '/' . $ftp_file;
318
+						if (!is_writable($file))
319
+							$ftp->chmod($ftp_file, 0755);
320
+						if (!is_writable($file))
321
+							$ftp->chmod($ftp_file, 0777);
322
+					}
323
+				}
324
+
325
+				if (is_writable($file))
326
+					unset($files[$k]);
327
+			}
328
+
329
+			$ftp->close();
330
+		}
331
+	}
332
+
333
+	// What remains?
334
+	$upcontext['chmod']['files'] = $files;
335
+
336
+	if (empty($files))
337
+		return true;
338
+
339
+	return false;
340 340
 }
341 341
 
342 342
 /**
@@ -347,24 +347,24 @@  discard block
 block discarded – undo
347 347
  */
348 348
 function quickFileWritable($file)
349 349
 {
350
-    if (is_writable($file))
351
-        return true;
350
+	if (is_writable($file))
351
+		return true;
352 352
 
353
-    @chmod($file, 0755);
353
+	@chmod($file, 0755);
354 354
 
355
-    // Try 755 and 775 first since 777 doesn't always work and could be a risk...
356
-    $chmod_values = array(0755, 0775, 0777);
355
+	// Try 755 and 775 first since 777 doesn't always work and could be a risk...
356
+	$chmod_values = array(0755, 0775, 0777);
357 357
 
358
-    foreach ($chmod_values as $val)
359
-    {
360
-        // If it's writable, break out of the loop
361
-        if (is_writable($file))
362
-            break;
363
-        else
364
-            @chmod($file, $val);
365
-    }
358
+	foreach ($chmod_values as $val)
359
+	{
360
+		// If it's writable, break out of the loop
361
+		if (is_writable($file))
362
+			break;
363
+		else
364
+			@chmod($file, $val);
365
+	}
366 366
 
367
-    return is_writable($file);
367
+	return is_writable($file);
368 368
 }
369 369
 
370 370
 /**
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
  */
376 376
 function smf_strtolower($string)
377 377
 {
378
-    return mb_strtolower($string, 'UTF-8');
378
+	return mb_strtolower($string, 'UTF-8');
379 379
 }
380 380
 
381 381
 /**
@@ -386,15 +386,15 @@  discard block
 block discarded – undo
386 386
  */
387 387
 function print_error($message, $fatal = false)
388 388
 {
389
-    static $fp = null;
389
+	static $fp = null;
390 390
 
391
-    if ($fp === null)
392
-        $fp = fopen('php://stderr', 'wb');
391
+	if ($fp === null)
392
+		$fp = fopen('php://stderr', 'wb');
393 393
 
394
-    fwrite($fp, $message . "\n");
394
+	fwrite($fp, $message . "\n");
395 395
 
396
-    if ($fatal)
397
-        exit;
396
+	if ($fatal)
397
+		exit;
398 398
 }
399 399
 
400 400
 /**
@@ -405,12 +405,12 @@  discard block
 block discarded – undo
405 405
  */
406 406
 function throw_error($message)
407 407
 {
408
-    global $upcontext;
408
+	global $upcontext;
409 409
 
410
-    $upcontext['error_msg'] = $message;
411
-    $upcontext['sub_template'] = 'error_message';
410
+	$upcontext['error_msg'] = $message;
411
+	$upcontext['sub_template'] = 'error_message';
412 412
 
413
-    return false;
413
+	return false;
414 414
 }
415 415
 
416 416
 /**
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
  */
423 423
 function smf_mysql_fetch_assoc($rs)
424 424
 {
425
-    return mysqli_fetch_assoc($rs);
425
+	return mysqli_fetch_assoc($rs);
426 426
 }
427 427
 
428 428
 /**
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
  */
432 432
 function smf_mysql_fetch_row($rs)
433 433
 {
434
-    return mysqli_fetch_row($rs);
434
+	return mysqli_fetch_row($rs);
435 435
 }
436 436
 
437 437
 /**
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
  */
440 440
 function smf_mysql_free_result($rs)
441 441
 {
442
-    mysqli_free_result($rs);
442
+	mysqli_free_result($rs);
443 443
 }
444 444
 
445 445
 /**
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
  */
449 449
 function smf_mysql_insert_id($rs)
450 450
 {
451
-    return mysqli_insert_id($rs);
451
+	return mysqli_insert_id($rs);
452 452
 }
453 453
 
454 454
 /**
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
  */
458 458
 function smf_mysql_num_rows($rs)
459 459
 {
460
-    return mysqli_num_rows($rs);
460
+	return mysqli_num_rows($rs);
461 461
 }
462 462
 
463 463
 /**
@@ -465,6 +465,6 @@  discard block
 block discarded – undo
465 465
  */
466 466
 function smf_mysql_real_escape_string($string)
467 467
 {
468
-    global $db_connection;
469
-    mysqli_real_escape_string($db_connection, $string);
468
+	global $db_connection;
469
+	mysqli_real_escape_string($db_connection, $string);
470 470
 }
471 471
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +93 added lines, -66 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * This file contains helper functions for upgrade.php
14 14
  */
15 15
 
16
-if (!defined('SMF_VERSION'))
16
+if (!defined('SMF_VERSION')) {
17 17
     die('No direct access!');
18
+}
18 19
 
19 20
 if (!function_exists('un_htmlspecialchars'))
20 21
 {
@@ -53,8 +54,9 @@  discard block
 block discarded – undo
53 54
         {
54 55
             $word = trim($word, '-_\'');
55 56
 
56
-            if ($word != '')
57
-                $returned_words[] = substr($word, 0, 20);
57
+            if ($word != '') {
58
+                            $returned_words[] = substr($word, 0, 20);
59
+            }
58 60
         }
59 61
 
60 62
         return array_unique($returned_words);
@@ -105,8 +107,9 @@  discard block
 block discarded – undo
105 107
     global $smcFunc;
106 108
     static $member_groups = array();
107 109
 
108
-    if (!empty($member_groups))
109
-        return $member_groups;
110
+    if (!empty($member_groups)) {
111
+            return $member_groups;
112
+    }
110 113
 
111 114
     $request = $smcFunc['db_query']('', '
112 115
 		SELECT group_name, id_group
@@ -131,8 +134,9 @@  discard block
 block discarded – undo
131 134
             )
132 135
         );
133 136
     }
134
-    while ($row = $smcFunc['db_fetch_row']($request))
135
-        $member_groups[trim($row[0])] = $row[1];
137
+    while ($row = $smcFunc['db_fetch_row']($request)) {
138
+            $member_groups[trim($row[0])] = $row[1];
139
+    }
136 140
     $smcFunc['db_free_result']($request);
137 141
 
138 142
     return $member_groups;
@@ -148,8 +152,9 @@  discard block
 block discarded – undo
148 152
 {
149 153
     global $upcontext, $boarddir;
150 154
 
151
-    if (empty($files))
152
-        return true;
155
+    if (empty($files)) {
156
+            return true;
157
+    }
153 158
 
154 159
     $failure = false;
155 160
     // On linux, it's easy - just use is_writable!
@@ -164,14 +169,16 @@  discard block
 block discarded – undo
164 169
                 @chmod($file, 0755);
165 170
 
166 171
                 // Well, 755 hopefully worked... if not, try 777.
167
-                if (!is_writable($file) && !@chmod($file, 0777))
168
-                    $failure = true;
172
+                if (!is_writable($file) && !@chmod($file, 0777)) {
173
+                                    $failure = true;
174
+                }
169 175
                 // Otherwise remove it as it's good!
170
-                else
171
-                    unset($files[$k]);
176
+                else {
177
+                                    unset($files[$k]);
178
+                }
179
+            } else {
180
+                            unset($files[$k]);
172 181
             }
173
-            else
174
-                unset($files[$k]);
175 182
         }
176 183
     }
177 184
     // Windows is trickier.  Let's try opening for r+...
@@ -182,30 +189,35 @@  discard block
 block discarded – undo
182 189
         foreach ($files as $k => $file)
183 190
         {
184 191
             // Folders can't be opened for write... but the index.php in them can ;).
185
-            if (is_dir($file))
186
-                $file .= '/index.php';
192
+            if (is_dir($file)) {
193
+                            $file .= '/index.php';
194
+            }
187 195
 
188 196
             // Funny enough, chmod actually does do something on windows - it removes the read only attribute.
189 197
             @chmod($file, 0777);
190 198
             $fp = @fopen($file, 'r+');
191 199
 
192 200
             // Hmm, okay, try just for write in that case...
193
-            if (!$fp)
194
-                $fp = @fopen($file, 'w');
201
+            if (!$fp) {
202
+                            $fp = @fopen($file, 'w');
203
+            }
195 204
 
196
-            if (!$fp)
197
-                $failure = true;
198
-            else
199
-                unset($files[$k]);
205
+            if (!$fp) {
206
+                            $failure = true;
207
+            } else {
208
+                            unset($files[$k]);
209
+            }
200 210
             @fclose($fp);
201 211
         }
202 212
     }
203 213
 
204
-    if (empty($files))
205
-        return true;
214
+    if (empty($files)) {
215
+            return true;
216
+    }
206 217
 
207
-    if (!isset($_SERVER))
208
-        return !$failure;
218
+    if (!isset($_SERVER)) {
219
+            return !$failure;
220
+    }
209 221
 
210 222
     // What still needs to be done?
211 223
     $upcontext['chmod']['files'] = $files;
@@ -256,36 +268,40 @@  discard block
 block discarded – undo
256 268
 
257 269
         if (!isset($ftp) || $ftp->error !== false)
258 270
         {
259
-            if (!isset($ftp))
260
-                $ftp = new ftp_connection(null);
271
+            if (!isset($ftp)) {
272
+                            $ftp = new ftp_connection(null);
273
+            }
261 274
             // Save the error so we can mess with listing...
262
-            elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error']))
263
-                $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
275
+            elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) {
276
+                            $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
277
+            }
264 278
 
265 279
             list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
266 280
 
267
-            if ($found_path || !isset($upcontext['chmod']['path']))
268
-                $upcontext['chmod']['path'] = $detect_path;
281
+            if ($found_path || !isset($upcontext['chmod']['path'])) {
282
+                            $upcontext['chmod']['path'] = $detect_path;
283
+            }
269 284
 
270
-            if (!isset($upcontext['chmod']['username']))
271
-                $upcontext['chmod']['username'] = $username;
285
+            if (!isset($upcontext['chmod']['username'])) {
286
+                            $upcontext['chmod']['username'] = $username;
287
+            }
272 288
 
273 289
             // Don't forget the login token.
274 290
             $upcontext += createToken('login');
275 291
 
276 292
             return false;
277
-        }
278
-        else
293
+        } else
279 294
         {
280 295
             // We want to do a relative path for FTP.
281 296
             if (!in_array($upcontext['chmod']['path'], array('', '/')))
282 297
             {
283 298
                 $ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => ''));
284
-                if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/'))
285
-                    $ftp_root = substr($ftp_root, 0, -1);
299
+                if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) {
300
+                                    $ftp_root = substr($ftp_root, 0, -1);
301
+                }
302
+            } else {
303
+                            $ftp_root = $boarddir;
286 304
             }
287
-            else
288
-                $ftp_root = $boarddir;
289 305
 
290 306
             // Save the info for next time!
291 307
             $_SESSION['installer_temp_ftp'] = array(
@@ -299,10 +315,12 @@  discard block
 block discarded – undo
299 315
 
300 316
             foreach ($files as $k => $file)
301 317
             {
302
-                if (!is_writable($file))
303
-                    $ftp->chmod($file, 0755);
304
-                if (!is_writable($file))
305
-                    $ftp->chmod($file, 0777);
318
+                if (!is_writable($file)) {
319
+                                    $ftp->chmod($file, 0755);
320
+                }
321
+                if (!is_writable($file)) {
322
+                                    $ftp->chmod($file, 0777);
323
+                }
306 324
 
307 325
                 // Assuming that didn't work calculate the path without the boarddir.
308 326
                 if (!is_writable($file))
@@ -311,19 +329,23 @@  discard block
 block discarded – undo
311 329
                     {
312 330
                         $ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => ''));
313 331
                         $ftp->chmod($ftp_file, 0755);
314
-                        if (!is_writable($file))
315
-                            $ftp->chmod($ftp_file, 0777);
332
+                        if (!is_writable($file)) {
333
+                                                    $ftp->chmod($ftp_file, 0777);
334
+                        }
316 335
                         // Sometimes an extra slash can help...
317 336
                         $ftp_file = '/' . $ftp_file;
318
-                        if (!is_writable($file))
319
-                            $ftp->chmod($ftp_file, 0755);
320
-                        if (!is_writable($file))
321
-                            $ftp->chmod($ftp_file, 0777);
337
+                        if (!is_writable($file)) {
338
+                                                    $ftp->chmod($ftp_file, 0755);
339
+                        }
340
+                        if (!is_writable($file)) {
341
+                                                    $ftp->chmod($ftp_file, 0777);
342
+                        }
322 343
                     }
323 344
                 }
324 345
 
325
-                if (is_writable($file))
326
-                    unset($files[$k]);
346
+                if (is_writable($file)) {
347
+                                    unset($files[$k]);
348
+                }
327 349
             }
328 350
 
329 351
             $ftp->close();
@@ -333,8 +355,9 @@  discard block
 block discarded – undo
333 355
     // What remains?
334 356
     $upcontext['chmod']['files'] = $files;
335 357
 
336
-    if (empty($files))
337
-        return true;
358
+    if (empty($files)) {
359
+            return true;
360
+    }
338 361
 
339 362
     return false;
340 363
 }
@@ -347,8 +370,9 @@  discard block
 block discarded – undo
347 370
  */
348 371
 function quickFileWritable($file)
349 372
 {
350
-    if (is_writable($file))
351
-        return true;
373
+    if (is_writable($file)) {
374
+            return true;
375
+    }
352 376
 
353 377
     @chmod($file, 0755);
354 378
 
@@ -358,10 +382,11 @@  discard block
 block discarded – undo
358 382
     foreach ($chmod_values as $val)
359 383
     {
360 384
         // If it's writable, break out of the loop
361
-        if (is_writable($file))
362
-            break;
363
-        else
364
-            @chmod($file, $val);
385
+        if (is_writable($file)) {
386
+                    break;
387
+        } else {
388
+                    @chmod($file, $val);
389
+        }
365 390
     }
366 391
 
367 392
     return is_writable($file);
@@ -388,14 +413,16 @@  discard block
 block discarded – undo
388 413
 {
389 414
     static $fp = null;
390 415
 
391
-    if ($fp === null)
392
-        $fp = fopen('php://stderr', 'wb');
416
+    if ($fp === null) {
417
+            $fp = fopen('php://stderr', 'wb');
418
+    }
393 419
 
394 420
     fwrite($fp, $message . "\n");
395 421
 
396
-    if ($fatal)
397
-        exit;
398
-}
422
+    if ($fatal) {
423
+            exit;
424
+    }
425
+    }
399 426
 
400 427
 /**
401 428
  * Throws a graphical error message.
Please login to merge, or discard this patch.