Completed
Push — release-2.1 ( 9df441...754615 )
by Mathias
15s
created
custom_avatar/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.
Smileys/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.
cache/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 1 patch
Braces   +254 added lines, -187 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -63,9 +64,11 @@  discard block
 block discarded – undo
63 64
 			'db_error_insert'			=> 'smf_db_error_insert',
64 65
 			'db_custom_order'			=> 'smf_db_custom_order',
65 66
 		);
67
+	}
66 68
 
67
-	if (!empty($db_options['persist']))
68
-		$db_server = 'p:' . $db_server;
69
+	if (!empty($db_options['persist'])) {
70
+			$db_server = 'p:' . $db_server;
71
+	}
69 72
 
70 73
 	$connection = mysqli_init();
71 74
 
@@ -74,24 +77,27 @@  discard block
 block discarded – undo
74 77
 	$success = false;
75 78
 
76 79
 	if ($connection) {
77
-		if (!empty($db_options['port']))
78
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
79
-		else
80
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
80
+		if (!empty($db_options['port'])) {
81
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
82
+		} else {
83
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
84
+		}
81 85
 	}
82 86
 
83 87
 	// Something's wrong, show an error if its fatal (which we assume it is)
84 88
 	if ($success === false)
85 89
 	{
86
-		if (!empty($db_options['non_fatal']))
87
-			return null;
88
-		else
89
-			display_db_error();
90
+		if (!empty($db_options['non_fatal'])) {
91
+					return null;
92
+		} else {
93
+					display_db_error();
94
+		}
90 95
 	}
91 96
 
92 97
 	// Select the database, unless told not to
93
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
94
-		display_db_error();
98
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
99
+			display_db_error();
100
+	}
95 101
 
96 102
 	mysqli_query($connection, 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'');
97 103
 
@@ -164,34 +170,42 @@  discard block
 block discarded – undo
164 170
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
165 171
 
166 172
 	list ($values, $connection) = $db_callback;
167
-	if (!is_object($connection))
168
-		display_db_error();
173
+	if (!is_object($connection)) {
174
+			display_db_error();
175
+	}
169 176
 
170
-	if ($matches[1] === 'db_prefix')
171
-		return $db_prefix;
177
+	if ($matches[1] === 'db_prefix') {
178
+			return $db_prefix;
179
+	}
172 180
 
173
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
174
-		return $user_info[$matches[1]];
181
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
182
+			return $user_info[$matches[1]];
183
+	}
175 184
 
176
-	if ($matches[1] === 'empty')
177
-		return '\'\'';
185
+	if ($matches[1] === 'empty') {
186
+			return '\'\'';
187
+	}
178 188
 
179
-	if (!isset($matches[2]))
180
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
189
+	if (!isset($matches[2])) {
190
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
191
+	}
181 192
 
182
-	if ($matches[1] === 'literal')
183
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
193
+	if ($matches[1] === 'literal') {
194
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
195
+	}
184 196
 
185
-	if (!isset($values[$matches[2]]))
186
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
197
+	if (!isset($values[$matches[2]])) {
198
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
199
+	}
187 200
 
188 201
 	$replacement = $values[$matches[2]];
189 202
 
190 203
 	switch ($matches[1])
191 204
 	{
192 205
 		case 'int':
193
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
194
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
206
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
207
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
208
+			}
195 209
 			return (string) (int) $replacement;
196 210
 		break;
197 211
 
@@ -203,65 +217,73 @@  discard block
 block discarded – undo
203 217
 		case 'array_int':
204 218
 			if (is_array($replacement))
205 219
 			{
206
-				if (empty($replacement))
207
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220
+				if (empty($replacement)) {
221
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222
+				}
208 223
 
209 224
 				foreach ($replacement as $key => $value)
210 225
 				{
211
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
212
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
226
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
227
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
228
+					}
213 229
 
214 230
 					$replacement[$key] = (string) (int) $value;
215 231
 				}
216 232
 
217 233
 				return implode(', ', $replacement);
234
+			} else {
235
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218 236
 			}
219
-			else
220
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221 237
 
222 238
 		break;
223 239
 
224 240
 		case 'array_string':
225 241
 			if (is_array($replacement))
226 242
 			{
227
-				if (empty($replacement))
228
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
243
+				if (empty($replacement)) {
244
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
245
+				}
229 246
 
230
-				foreach ($replacement as $key => $value)
231
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
247
+				foreach ($replacement as $key => $value) {
248
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
249
+				}
232 250
 
233 251
 				return implode(', ', $replacement);
252
+			} else {
253
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
234 254
 			}
235
-			else
236
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237 255
 		break;
238 256
 
239 257
 		case 'date':
240
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
241
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
242
-			else
243
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
258
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
259
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
260
+			} else {
261
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
262
+			}
244 263
 		break;
245 264
 
246 265
 		case 'time':
247
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
248
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
249
-			else
250
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
267
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
268
+			} else {
269
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+			}
251 271
 		break;
252 272
 
253 273
 		case 'datetime':
254
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
255
-				return 'str_to_date('.
274
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
275
+							return 'str_to_date('.
256 276
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
257 277
 					',\'%Y-%m-%d %h:%i:%s\')';
258
-			else
259
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
278
+			} else {
279
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
280
+			}
260 281
 		break;
261 282
 
262 283
 		case 'float':
263
-			if (!is_numeric($replacement))
264
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
284
+			if (!is_numeric($replacement)) {
285
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
286
+			}
265 287
 			return (string) (float) $replacement;
266 288
 		break;
267 289
 
@@ -275,32 +297,37 @@  discard block
 block discarded – undo
275 297
 		break;
276 298
 
277 299
 		case 'inet':
278
-			if ($replacement == 'null' || $replacement == '')
279
-				return 'null';
280
-			if (!isValidIP($replacement))
281
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
300
+			if ($replacement == 'null' || $replacement == '') {
301
+							return 'null';
302
+			}
303
+			if (!isValidIP($replacement)) {
304
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
305
+			}
282 306
 			//we don't use the native support of mysql > 5.6.2
283 307
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
284 308
 
285 309
 		case 'array_inet':
286 310
 			if (is_array($replacement))
287 311
 			{
288
-				if (empty($replacement))
289
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
312
+				if (empty($replacement)) {
313
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
314
+				}
290 315
 
291 316
 				foreach ($replacement as $key => $value)
292 317
 				{
293
-					if ($replacement == 'null' || $replacement == '')
294
-						$replacement[$key] = 'null';
295
-					if (!isValidIP($value))
296
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
318
+					if ($replacement == 'null' || $replacement == '') {
319
+											$replacement[$key] = 'null';
320
+					}
321
+					if (!isValidIP($value)) {
322
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
323
+					}
297 324
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
298 325
 				}
299 326
 
300 327
 				return implode(', ', $replacement);
328
+			} else {
329
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
301 330
 			}
302
-			else
303
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
304 331
 		break;
305 332
 
306 333
 		default:
@@ -371,18 +398,20 @@  discard block
 block discarded – undo
371 398
 	// One more query....
372 399
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
373 400
 
374
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
375
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
401
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
402
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
403
+	}
376 404
 
377 405
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
378 406
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
379 407
 	{
380 408
 		// Add before LIMIT
381
-		if ($pos = strpos($db_string, 'LIMIT '))
382
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
383
-		else
384
-			// Append it.
409
+		if ($pos = strpos($db_string, 'LIMIT ')) {
410
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
411
+		} else {
412
+					// Append it.
385 413
 			$db_string .= "\n\t\t\tORDER BY null";
414
+		}
386 415
 	}
387 416
 
388 417
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -408,17 +437,18 @@  discard block
 block discarded – undo
408 437
 		while (true)
409 438
 		{
410 439
 			$pos = strpos($db_string_1, '\'', $pos + 1);
411
-			if ($pos === false)
412
-				break;
440
+			if ($pos === false) {
441
+							break;
442
+			}
413 443
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
414 444
 
415 445
 			while (true)
416 446
 			{
417 447
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
418 448
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
419
-				if ($pos1 === false)
420
-					break;
421
-				elseif ($pos2 === false || $pos2 > $pos1)
449
+				if ($pos1 === false) {
450
+									break;
451
+				} elseif ($pos2 === false || $pos2 > $pos1)
422 452
 				{
423 453
 					$pos = $pos1;
424 454
 					break;
@@ -434,16 +464,19 @@  discard block
 block discarded – undo
434 464
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
435 465
 
436 466
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
437
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
438
-			$fail = true;
467
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
468
+					$fail = true;
469
+		}
439 470
 		// Trying to change passwords, slow us down, or something?
440
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
441
-			$fail = true;
442
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
443
-			$fail = true;
471
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
472
+					$fail = true;
473
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
474
+					$fail = true;
475
+		}
444 476
 
445
-		if (!empty($fail) && function_exists('log_error'))
446
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
477
+		if (!empty($fail) && function_exists('log_error')) {
478
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
479
+		}
447 480
 	}
448 481
 
449 482
 	// Debugging.
@@ -453,8 +486,9 @@  discard block
 block discarded – undo
453 486
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
454 487
 
455 488
 		// Initialize $db_cache if not already initialized.
456
-		if (!isset($db_cache))
457
-			$db_cache = array();
489
+		if (!isset($db_cache)) {
490
+					$db_cache = array();
491
+		}
458 492
 
459 493
 		if (!empty($_SESSION['debug_redirect']))
460 494
 		{
@@ -470,17 +504,20 @@  discard block
 block discarded – undo
470 504
 		$db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start;
471 505
 	}
472 506
 
473
-	if (empty($db_unbuffered))
474
-		$ret = @mysqli_query($connection, $db_string);
475
-	else
476
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
507
+	if (empty($db_unbuffered)) {
508
+			$ret = @mysqli_query($connection, $db_string);
509
+	} else {
510
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
511
+	}
477 512
 
478
-	if ($ret === false && empty($db_values['db_error_skip']))
479
-		$ret = smf_db_error($db_string, $connection);
513
+	if ($ret === false && empty($db_values['db_error_skip'])) {
514
+			$ret = smf_db_error($db_string, $connection);
515
+	}
480 516
 
481 517
 	// Debugging.
482
-	if (isset($db_show_debug) && $db_show_debug === true)
483
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
518
+	if (isset($db_show_debug) && $db_show_debug === true) {
519
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
520
+	}
484 521
 
485 522
 	return $ret;
486 523
 }
@@ -527,12 +564,13 @@  discard block
 block discarded – undo
527 564
 	// Decide which connection to use
528 565
 	$connection = $connection === null ? $db_connection : $connection;
529 566
 
530
-	if ($type == 'begin')
531
-		return @mysqli_query($connection, 'BEGIN');
532
-	elseif ($type == 'rollback')
533
-		return @mysqli_query($connection, 'ROLLBACK');
534
-	elseif ($type == 'commit')
535
-		return @mysqli_query($connection, 'COMMIT');
567
+	if ($type == 'begin') {
568
+			return @mysqli_query($connection, 'BEGIN');
569
+	} elseif ($type == 'rollback') {
570
+			return @mysqli_query($connection, 'ROLLBACK');
571
+	} elseif ($type == 'commit') {
572
+			return @mysqli_query($connection, 'COMMIT');
573
+	}
536 574
 
537 575
 	return false;
538 576
 }
@@ -570,8 +608,9 @@  discard block
 block discarded – undo
570 608
 	//    1213: Deadlock found.
571 609
 
572 610
 	// Log the error.
573
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
574
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
611
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
612
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
613
+	}
575 614
 
576 615
 	// Database error auto fixing ;).
577 616
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -580,8 +619,9 @@  discard block
 block discarded – undo
580 619
 		$old_cache = @$modSettings['cache_enable'];
581 620
 		$modSettings['cache_enable'] = '1';
582 621
 
583
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
584
-			$db_last_error = max(@$db_last_error, $temp);
622
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
623
+					$db_last_error = max(@$db_last_error, $temp);
624
+		}
585 625
 
586 626
 		if (@$db_last_error < time() - 3600 * 24 * 3)
587 627
 		{
@@ -597,8 +637,9 @@  discard block
 block discarded – undo
597 637
 					foreach ($tables as $table)
598 638
 					{
599 639
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
600
-						if (trim($table) != '')
601
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
640
+						if (trim($table) != '') {
641
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
642
+						}
602 643
 					}
603 644
 				}
604 645
 
@@ -607,8 +648,9 @@  discard block
 block discarded – undo
607 648
 			// Table crashed.  Let's try to fix it.
608 649
 			elseif ($query_errno == 1016)
609 650
 			{
610
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
611
-					$fix_tables = array('`' . $match[1] . '`');
651
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
652
+									$fix_tables = array('`' . $match[1] . '`');
653
+				}
612 654
 			}
613 655
 			// Indexes crashed.  Should be easy to fix!
614 656
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -627,13 +669,15 @@  discard block
 block discarded – undo
627 669
 
628 670
 			// Make a note of the REPAIR...
629 671
 			cache_put_data('db_last_error', time(), 600);
630
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
631
-				updateSettingsFile(array('db_last_error' => time()));
672
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
673
+							updateSettingsFile(array('db_last_error' => time()));
674
+			}
632 675
 
633 676
 			// Attempt to find and repair the broken table.
634
-			foreach ($fix_tables as $table)
635
-				$smcFunc['db_query']('', "
677
+			foreach ($fix_tables as $table) {
678
+							$smcFunc['db_query']('', "
636 679
 					REPAIR TABLE $table", false, false);
680
+			}
637 681
 
638 682
 			// And send off an email!
639 683
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -642,11 +686,12 @@  discard block
 block discarded – undo
642 686
 
643 687
 			// Try the query again...?
644 688
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
645
-			if ($ret !== false)
646
-				return $ret;
689
+			if ($ret !== false) {
690
+							return $ret;
691
+			}
692
+		} else {
693
+					$modSettings['cache_enable'] = $old_cache;
647 694
 		}
648
-		else
649
-			$modSettings['cache_enable'] = $old_cache;
650 695
 
651 696
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
652 697
 		if (in_array($query_errno, array(1205, 1213)))
@@ -659,24 +704,27 @@  discard block
 block discarded – undo
659 704
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
660 705
 
661 706
 					$new_errno = mysqli_errno($db_connection);
662
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
663
-						break;
707
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
708
+											break;
709
+					}
664 710
 				}
665 711
 
666 712
 				// If it failed again, shucks to be you... we're not trying it over and over.
667
-				if ($ret !== false)
668
-					return $ret;
713
+				if ($ret !== false) {
714
+									return $ret;
715
+				}
669 716
 			}
670 717
 		}
671 718
 		// Are they out of space, perhaps?
672 719
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
673 720
 		{
674
-			if (!isset($txt))
675
-				$query_error .= ' - check database storage space.';
676
-			else
721
+			if (!isset($txt)) {
722
+							$query_error .= ' - check database storage space.';
723
+			} else
677 724
 			{
678
-				if (!isset($txt['mysql_error_space']))
679
-					loadLanguage('Errors');
725
+				if (!isset($txt['mysql_error_space'])) {
726
+									loadLanguage('Errors');
727
+				}
680 728
 
681 729
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
682 730
 			}
@@ -684,15 +732,17 @@  discard block
 block discarded – undo
684 732
 	}
685 733
 
686 734
 	// Nothing's defined yet... just die with it.
687
-	if (empty($context) || empty($txt))
688
-		die($query_error);
735
+	if (empty($context) || empty($txt)) {
736
+			die($query_error);
737
+	}
689 738
 
690 739
 	// Show an error message, if possible.
691 740
 	$context['error_title'] = $txt['database_error'];
692
-	if (allowedTo('admin_forum'))
693
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
694
-	else
695
-		$context['error_message'] = $txt['try_again'];
741
+	if (allowedTo('admin_forum')) {
742
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
743
+	} else {
744
+			$context['error_message'] = $txt['try_again'];
745
+	}
696 746
 
697 747
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
698 748
 	{
@@ -724,8 +774,9 @@  discard block
 block discarded – undo
724 774
 	$return_var = null;
725 775
 
726 776
 	// With nothing to insert, simply return.
727
-	if (empty($data))
728
-		return;
777
+	if (empty($data)) {
778
+			return;
779
+	}
729 780
 
730 781
 	// Replace the prefix holder with the actual prefix.
731 782
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -735,23 +786,26 @@  discard block
 block discarded – undo
735 786
 	if (!empty($keys) && (count($keys) > 0) && $returnmode > 0)
736 787
 	{
737 788
 		$with_returning = true;
738
-		if ($returnmode == 2)
739
-			$return_var = array();
789
+		if ($returnmode == 2) {
790
+					$return_var = array();
791
+		}
740 792
 	}
741 793
 
742 794
 	// Inserting data as a single row can be done as a single array.
743
-	if (!is_array($data[array_rand($data)]))
744
-		$data = array($data);
795
+	if (!is_array($data[array_rand($data)])) {
796
+			$data = array($data);
797
+	}
745 798
 
746 799
 	// Create the mold for a single row insert.
747 800
 	$insertData = '(';
748 801
 	foreach ($columns as $columnName => $type)
749 802
 	{
750 803
 		// Are we restricting the length?
751
-		if (strpos($type, 'string-') !== false)
752
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
753
-		else
754
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
804
+		if (strpos($type, 'string-') !== false) {
805
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
806
+		} else {
807
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
808
+		}
755 809
 	}
756 810
 	$insertData = substr($insertData, 0, -2) . ')';
757 811
 
@@ -760,8 +814,9 @@  discard block
 block discarded – undo
760 814
 
761 815
 	// Here's where the variables are injected to the query.
762 816
 	$insertRows = array();
763
-	foreach ($data as $dataRow)
764
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
817
+	foreach ($data as $dataRow) {
818
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
819
+	}
765 820
 
766 821
 	// Determine the method of insertion.
767 822
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -780,8 +835,7 @@  discard block
 block discarded – undo
780 835
 			),
781 836
 			$connection
782 837
 		);
783
-	}
784
-	else //special way for ignore method with returning
838
+	} else //special way for ignore method with returning
785 839
 	{
786 840
 		$count = count($insertRows);
787 841
 		$ai = 0;
@@ -801,19 +855,21 @@  discard block
 block discarded – undo
801 855
 			);
802 856
 			$new_id = $smcFunc['db_insert_id']();
803 857
 
804
-			if ($last_id != $new_id) //the inserted value was new
858
+			if ($last_id != $new_id) {
859
+				//the inserted value was new
805 860
 			{
806 861
 				$ai = $new_id;
807 862
 			}
808
-			else	// the inserted value already exists we need to find the pk
863
+			} else	// the inserted value already exists we need to find the pk
809 864
 			{
810 865
 				$where_string = '';
811 866
 				$count2 = count($indexed_columns);
812 867
 				for ($x = 0; $x < $count2; $x++)
813 868
 				{
814 869
 					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
815
-					if (($x + 1) < $count2)
816
-						$where_string += ' AND ';
870
+					if (($x + 1) < $count2) {
871
+											$where_string += ' AND ';
872
+					}
817 873
 				}
818 874
 
819 875
 				$request = $smcFunc['db_query']('','
@@ -829,25 +885,27 @@  discard block
 block discarded – undo
829 885
 				}
830 886
 			}
831 887
 
832
-			if ($returnmode == 1)
833
-				$return_var = $ai;
834
-			else if ($returnmode == 2)
835
-				$return_var[] = $ai;
888
+			if ($returnmode == 1) {
889
+							$return_var = $ai;
890
+			} else if ($returnmode == 2) {
891
+							$return_var[] = $ai;
892
+			}
836 893
 		}
837 894
 	}
838 895
 
839 896
 
840 897
 	if ($with_returning)
841 898
 	{
842
-		if ($returnmode == 1 && empty($return_var))
843
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
844
-		else if ($returnmode == 2 && empty($return_var))
899
+		if ($returnmode == 1 && empty($return_var)) {
900
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
901
+		} else if ($returnmode == 2 && empty($return_var))
845 902
 		{
846 903
 			$return_var = array();
847 904
 			$count = count($insertRows);
848 905
 			$start = smf_db_insert_id($table, $keys[0]);
849
-			for ($i = 0; $i < $count; $i++ )
850
-				$return_var[] = $start + $i;
906
+			for ($i = 0; $i < $count; $i++ ) {
907
+							$return_var[] = $start + $i;
908
+			}
851 909
 		}
852 910
 		return $return_var;
853 911
 	}
@@ -865,8 +923,9 @@  discard block
 block discarded – undo
865 923
  */
866 924
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
867 925
 {
868
-	if (empty($log_message))
869
-		$log_message = $error_message;
926
+	if (empty($log_message)) {
927
+			$log_message = $error_message;
928
+	}
870 929
 
871 930
 	foreach (debug_backtrace() as $step)
872 931
 	{
@@ -885,12 +944,14 @@  discard block
 block discarded – undo
885 944
 	}
886 945
 
887 946
 	// A special case - we want the file and line numbers for debugging.
888
-	if ($error_type == 'return')
889
-		return array($file, $line);
947
+	if ($error_type == 'return') {
948
+			return array($file, $line);
949
+	}
890 950
 
891 951
 	// Is always a critical error.
892
-	if (function_exists('log_error'))
893
-		log_error($log_message, 'critical', $file, $line);
952
+	if (function_exists('log_error')) {
953
+			log_error($log_message, 'critical', $file, $line);
954
+	}
894 955
 
895 956
 	if (function_exists('fatal_error'))
896 957
 	{
@@ -898,12 +959,12 @@  discard block
 block discarded – undo
898 959
 
899 960
 		// Cannot continue...
900 961
 		exit;
962
+	} elseif ($error_type) {
963
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
964
+	} else {
965
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
966
+	}
901 967
 	}
902
-	elseif ($error_type)
903
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
904
-	else
905
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
906
-}
907 968
 
908 969
 /**
909 970
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -920,10 +981,11 @@  discard block
 block discarded – undo
920 981
 		'\\' => '\\\\',
921 982
 	);
922 983
 
923
-	if ($translate_human_wildcards)
924
-		$replacements += array(
984
+	if ($translate_human_wildcards) {
985
+			$replacements += array(
925 986
 			'*' => '%',
926 987
 		);
988
+	}
927 989
 
928 990
 	return strtr($string, $replacements);
929 991
 }
@@ -937,8 +999,9 @@  discard block
 block discarded – undo
937 999
  */
938 1000
 function smf_is_resource($result)
939 1001
 {
940
-	if ($result instanceof mysqli_result)
941
-		return true;
1002
+	if ($result instanceof mysqli_result) {
1003
+			return true;
1004
+	}
942 1005
 
943 1006
 	return false;
944 1007
 }
@@ -967,19 +1030,22 @@  discard block
 block discarded – undo
967 1030
 	static $mysql_error_data_prep;
968 1031
 
969 1032
 	// without database we can't do anything
970
-	if (empty($db_connection))
971
-		return;
1033
+	if (empty($db_connection)) {
1034
+			return;
1035
+	}
972 1036
 
973
-	if (empty($mysql_error_data_prep))
974
-			$mysql_error_data_prep = mysqli_prepare($db_connection,
1037
+	if (empty($mysql_error_data_prep)) {
1038
+				$mysql_error_data_prep = mysqli_prepare($db_connection,
975 1039
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line)
976 1040
 													VALUES(		?,		?,		unhex(?), ?, 		?,		?,			?,		?,	?)'
977 1041
 			);
1042
+	}
978 1043
 
979
-	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false)
980
-		$error_array[2] = bin2hex(inet_pton($error_array[2]));
981
-	else
982
-		$error_array[2] = null;
1044
+	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) {
1045
+			$error_array[2] = bin2hex(inet_pton($error_array[2]));
1046
+	} else {
1047
+			$error_array[2] = null;
1048
+	}
983 1049
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi',
984 1050
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
985 1051
 		$error_array[7], $error_array[8]);
@@ -1001,8 +1067,9 @@  discard block
 block discarded – undo
1001 1067
 	$count = count($array_values);
1002 1068
 	$then = ($desc ? ' THEN -' : ' THEN ');
1003 1069
 
1004
-	for ($i = 0; $i < $count; $i++)
1005
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1070
+	for ($i = 0; $i < $count; $i++) {
1071
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1072
+	}
1006 1073
 
1007 1074
 	$return .= 'END';
1008 1075
 	return $return;
Please login to merge, or discard this patch.
Sources/Errors.php 1 patch
Braces   +130 added lines, -93 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Log an error, if the error logging is enabled.
@@ -41,17 +42,19 @@  discard block
 block discarded – undo
41 42
 	// are we in a loop?
42 43
 	if($error_call > 2)
43 44
 	{
44
-		if (!isset($db_show_debug) || $db_show_debug === false)
45
-			$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
46
-		else
47
-			$backtrace = debug_backtrace();
45
+		if (!isset($db_show_debug) || $db_show_debug === false) {
46
+					$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
47
+		} else {
48
+					$backtrace = debug_backtrace();
49
+		}
48 50
 		var_dump($backtrace);
49 51
 		die('Error loop.');
50 52
 	}
51 53
 
52 54
 	// Check if error logging is actually on.
53
-	if (empty($modSettings['enableErrorLogging']))
54
-		return $error_message;
55
+	if (empty($modSettings['enableErrorLogging'])) {
56
+			return $error_message;
57
+	}
55 58
 
56 59
 	// Basically, htmlspecialchars it minus &. (for entities!)
57 60
 	$error_message = strtr($error_message, array('<' => '&lt;', '>' => '&gt;', '"' => '&quot;'));
@@ -59,33 +62,39 @@  discard block
 block discarded – undo
59 62
 
60 63
 	// Add a file and line to the error message?
61 64
 	// Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line
62
-	if ($file == null)
63
-		$file = '';
64
-	else
65
-		// Window style slashes don't play well, lets convert them to the unix style.
65
+	if ($file == null) {
66
+			$file = '';
67
+	} else {
68
+			// Window style slashes don't play well, lets convert them to the unix style.
66 69
 		$file = str_replace('\\', '/', $file);
70
+	}
67 71
 
68
-	if ($line == null)
69
-		$line = 0;
70
-	else
71
-		$line = (int) $line;
72
+	if ($line == null) {
73
+			$line = 0;
74
+	} else {
75
+			$line = (int) $line;
76
+	}
72 77
 
73 78
 	// Just in case there's no id_member or IP set yet.
74
-	if (empty($user_info['id']))
75
-		$user_info['id'] = 0;
76
-	if (empty($user_info['ip']))
77
-		$user_info['ip'] = '';
79
+	if (empty($user_info['id'])) {
80
+			$user_info['id'] = 0;
81
+	}
82
+	if (empty($user_info['ip'])) {
83
+			$user_info['ip'] = '';
84
+	}
78 85
 
79 86
 	// Find the best query string we can...
80 87
 	$query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING'];
81 88
 
82 89
 	// Don't log the session hash in the url twice, it's a waste.
83
-	if (!empty($smcFunc['htmlspecialchars']))
84
-		$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
90
+	if (!empty($smcFunc['htmlspecialchars'])) {
91
+			$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
92
+	}
85 93
 
86 94
 	// Just so we know what board error messages are from.
87
-	if (isset($_POST['board']) && !isset($_GET['board']))
88
-		$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
95
+	if (isset($_POST['board']) && !isset($_GET['board'])) {
96
+			$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
97
+	}
89 98
 
90 99
 	// What types of categories do we have?
91 100
 	$known_error_types = array(
@@ -134,9 +143,9 @@  discard block
 block discarded – undo
134 143
 
135 144
 			list($context['num_errors']) = $smcFunc['db_fetch_row']($query);
136 145
 			$smcFunc['db_free_result']($query);
146
+		} else {
147
+					$context['num_errors']++;
137 148
 		}
138
-		else
139
-			$context['num_errors']++;
140 149
 	}
141 150
 
142 151
 	// reset error call
@@ -158,12 +167,14 @@  discard block
 block discarded – undo
158 167
 	global $txt;
159 168
 
160 169
 	// Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all
161
-	if (!empty($status))
162
-		send_http_status($status);
170
+	if (!empty($status)) {
171
+			send_http_status($status);
172
+	}
163 173
 
164 174
 	// We don't have $txt yet, but that's okay...
165
-	if (empty($txt))
166
-		die($error);
175
+	if (empty($txt)) {
176
+			die($error);
177
+	}
167 178
 
168 179
 	log_error_online($error, false);
169 180
 	setup_fatal_error_context($log ? log_error($error, $log) : $error);
@@ -190,8 +201,9 @@  discard block
 block discarded – undo
190 201
 	static $fatal_error_called = false;
191 202
 
192 203
 	// Send the status header - set this to 0 or false if you don't want to send one at all
193
-	if (!empty($status))
194
-		send_http_status($status);
204
+	if (!empty($status)) {
205
+			send_http_status($status);
206
+	}
195 207
 
196 208
 	// Try to load a theme if we don't have one.
197 209
 	if (empty($context['theme_loaded']) && empty($fatal_error_called))
@@ -201,8 +213,9 @@  discard block
 block discarded – undo
201 213
 	}
202 214
 
203 215
 	// If we have no theme stuff we can't have the language file...
204
-	if (empty($context['theme_loaded']))
205
-		die($error);
216
+	if (empty($context['theme_loaded'])) {
217
+			die($error);
218
+	}
206 219
 
207 220
 	$reload_lang_file = true;
208 221
 	// Log the error in the forum's language, but don't waste the time if we aren't logging
@@ -238,8 +251,9 @@  discard block
 block discarded – undo
238 251
 	global $settings, $modSettings, $db_show_debug;
239 252
 
240 253
 	// Ignore errors if we're ignoring them or they are strict notices from PHP 5
241
-	if (error_reporting() == 0)
242
-		return;
254
+	if (error_reporting() == 0) {
255
+			return;
256
+	}
243 257
 
244 258
 	if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename']))
245 259
 	{
@@ -247,19 +261,22 @@  discard block
 block discarded – undo
247 261
 		$count = count($array);
248 262
 		for ($i = 0; $i < $count; $i++)
249 263
 		{
250
-			if ($array[$i]['function'] != 'loadSubTemplate')
251
-				continue;
264
+			if ($array[$i]['function'] != 'loadSubTemplate') {
265
+							continue;
266
+			}
252 267
 
253 268
 			// This is a bug in PHP, with eval, it seems!
254
-			if (empty($array[$i]['args']))
255
-				$i++;
269
+			if (empty($array[$i]['args'])) {
270
+							$i++;
271
+			}
256 272
 			break;
257 273
 		}
258 274
 
259
-		if (isset($array[$i]) && !empty($array[$i]['args']))
260
-			$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
261
-		else
262
-			$file = realpath($settings['current_include_filename']) . ' (eval?)';
275
+		if (isset($array[$i]) && !empty($array[$i]['args'])) {
276
+					$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
277
+		} else {
278
+					$file = realpath($settings['current_include_filename']) . ' (eval?)';
279
+		}
263 280
 	}
264 281
 
265 282
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -268,8 +285,9 @@  discard block
 block discarded – undo
268 285
 		if ($error_level % 255 != E_ERROR)
269 286
 		{
270 287
 			$temporary = ob_get_contents();
271
-			if (substr($temporary, -2) == '="')
272
-				echo '"';
288
+			if (substr($temporary, -2) == '="') {
289
+							echo '"';
290
+			}
273 291
 		}
274 292
 
275 293
 		// Debugging!  This should look like a PHP error message.
@@ -285,23 +303,27 @@  discard block
 block discarded – undo
285 303
 	call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line));
286 304
 
287 305
 	// Dying on these errors only causes MORE problems (blank pages!)
288
-	if ($file == 'Unknown')
289
-		return;
306
+	if ($file == 'Unknown') {
307
+			return;
308
+	}
290 309
 
291 310
 	// If this is an E_ERROR or E_USER_ERROR.... die.  Violently so.
292
-	if ($error_level % 255 == E_ERROR)
293
-		obExit(false);
294
-	else
295
-		return;
311
+	if ($error_level % 255 == E_ERROR) {
312
+			obExit(false);
313
+	} else {
314
+			return;
315
+	}
296 316
 
297 317
 	// If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die.  Violently so.
298
-	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING)
299
-		fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
318
+	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) {
319
+			fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
320
+	}
300 321
 
301 322
 	// We should NEVER get to this point.  Any fatal error MUST quit, or very bad things can happen.
302
-	if ($error_level % 255 == E_ERROR)
303
-		die('No direct access...');
304
-}
323
+	if ($error_level % 255 == E_ERROR) {
324
+			die('No direct access...');
325
+	}
326
+	}
305 327
 
306 328
 /**
307 329
  * It is called by {@link fatal_error()} and {@link fatal_lang_error()}.
@@ -317,24 +339,28 @@  discard block
 block discarded – undo
317 339
 
318 340
 	// Attempt to prevent a recursive loop.
319 341
 	++$level;
320
-	if ($level > 1)
321
-		return false;
342
+	if ($level > 1) {
343
+			return false;
344
+	}
322 345
 
323 346
 	// Maybe they came from dlattach or similar?
324
-	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded']))
325
-		loadTheme();
347
+	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) {
348
+			loadTheme();
349
+	}
326 350
 
327 351
 	// Don't bother indexing errors mate...
328 352
 	$context['robot_no_index'] = true;
329 353
 
330
-	if (!isset($context['error_title']))
331
-		$context['error_title'] = $txt['error_occured'];
354
+	if (!isset($context['error_title'])) {
355
+			$context['error_title'] = $txt['error_occured'];
356
+	}
332 357
 	$context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message;
333 358
 
334 359
 	$context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : '';
335 360
 
336
-	if (empty($context['page_title']))
337
-		$context['page_title'] = $context['error_title'];
361
+	if (empty($context['page_title'])) {
362
+			$context['page_title'] = $context['error_title'];
363
+	}
338 364
 
339 365
 	loadTemplate('Errors');
340 366
 	$context['sub_template'] = 'fatal_error';
@@ -342,23 +368,26 @@  discard block
 block discarded – undo
342 368
 	// If this is SSI, what do they want us to do?
343 369
 	if (SMF == 'SSI')
344 370
 	{
345
-		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method))
346
-			$ssi_on_error_method();
347
-		elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
348
-			loadSubTemplate('fatal_error');
371
+		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) {
372
+					$ssi_on_error_method();
373
+		} elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
374
+					loadSubTemplate('fatal_error');
375
+		}
349 376
 
350 377
 		// No layers?
351
-		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
352
-			exit;
378
+		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
379
+					exit;
380
+		}
353 381
 	}
354 382
 	// Alternatively from the cron call?
355 383
 	elseif (SMF == 'BACKGROUND')
356 384
 	{
357 385
 		// We can't rely on even having language files available.
358
-		if (defined('FROM_CLI') && FROM_CLI)
359
-			echo 'cron error: ', $context['error_message'];
360
-		else
361
-			echo 'An error occurred. More information may be available in your logs.';
386
+		if (defined('FROM_CLI') && FROM_CLI) {
387
+					echo 'cron error: ', $context['error_message'];
388
+		} else {
389
+					echo 'An error occurred. More information may be available in your logs.';
390
+		}
362 391
 		exit;
363 392
 	}
364 393
 
@@ -386,8 +415,8 @@  discard block
 block discarded – undo
386 415
 
387 416
 	set_fatal_error_headers();
388 417
 
389
-	if (!empty($maintenance))
390
-		echo '<!DOCTYPE html>
418
+	if (!empty($maintenance)) {
419
+			echo '<!DOCTYPE html>
391 420
 <html>
392 421
 	<head>
393 422
 		<meta name="robots" content="noindex">
@@ -398,6 +427,7 @@  discard block
 block discarded – undo
398 427
 		', $mmessage, '
399 428
 	</body>
400 429
 </html>';
430
+	}
401 431
 
402 432
 	die();
403 433
 }
@@ -419,15 +449,17 @@  discard block
 block discarded – undo
419 449
 	// For our purposes, we're gonna want this on if at all possible.
420 450
 	$modSettings['cache_enable'] = '1';
421 451
 
422
-	if (($temp = cache_get_data('db_last_error', 600)) !== null)
423
-		$db_last_error = max($db_last_error, $temp);
452
+	if (($temp = cache_get_data('db_last_error', 600)) !== null) {
453
+			$db_last_error = max($db_last_error, $temp);
454
+	}
424 455
 
425 456
 	if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send))
426 457
 	{
427 458
 		// Avoid writing to the Settings.php file if at all possible; use shared memory instead.
428 459
 		cache_put_data('db_last_error', time(), 600);
429
-		if (($temp = cache_get_data('db_last_error', 600)) === null)
430
-			logLastDatabaseError();
460
+		if (($temp = cache_get_data('db_last_error', 600)) === null) {
461
+					logLastDatabaseError();
462
+		}
431 463
 
432 464
 		// Language files aren't loaded yet :(.
433 465
 		$db_error = @$smcFunc['db_error']($db_connection);
@@ -484,8 +516,9 @@  discard block
 block discarded – undo
484 516
  */
485 517
 function set_fatal_error_headers()
486 518
 {
487
-	if (headers_sent())
488
-		return;
519
+	if (headers_sent()) {
520
+			return;
521
+	}
489 522
 
490 523
 	// Don't cache this page!
491 524
 	header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -511,12 +544,14 @@  discard block
 block discarded – undo
511 544
 	global $smcFunc, $user_info, $modSettings;
512 545
 
513 546
 	// Don't bother if Who's Online is disabled.
514
-	if (empty($modSettings['who_enabled']))
515
-		return;
547
+	if (empty($modSettings['who_enabled'])) {
548
+			return;
549
+	}
516 550
 
517 551
 	// Maybe they came from SSI or similar where sessions are not recorded?
518
-	if (SMF == 'SSI' || SMF == 'BACKGROUND')
519
-		return;
552
+	if (SMF == 'SSI' || SMF == 'BACKGROUND') {
553
+			return;
554
+	}
520 555
 
521 556
 	$session_id = !empty($user_info['is_guest']) ? 'ip' . $user_info['ip'] : session_id();
522 557
 
@@ -542,8 +577,9 @@  discard block
 block discarded – undo
542 577
 		$url = $smcFunc['json_decode']($url, true);
543 578
 		$url['error'] = $error;
544 579
 
545
-		if (!empty($sprintf))
546
-			$url['error_params'] = $sprintf;
580
+		if (!empty($sprintf)) {
581
+					$url['error_params'] = $sprintf;
582
+		}
547 583
 
548 584
 		$smcFunc['db_query']('', '
549 585
 			UPDATE {db_prefix}log_online
@@ -574,10 +610,11 @@  discard block
 block discarded – undo
574 610
 
575 611
 	$protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
576 612
 
577
-	if (!isset($statuses[$code]))
578
-		header($protocol . ' 500 Internal Server Error');
579
-	else
580
-		header($protocol . ' ' . $code . ' ' . $statuses[$code]);
581
-}
613
+	if (!isset($statuses[$code])) {
614
+			header($protocol . ' 500 Internal Server Error');
615
+	} else {
616
+			header($protocol . ' ' . $code . ' ' . $statuses[$code]);
617
+	}
618
+	}
582 619
 
583 620
 ?>
584 621
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 1 patch
Braces   +232 added lines, -171 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Maps the implementations in this file (smf_db_function_name)
@@ -34,8 +35,8 @@  discard block
 block discarded – undo
34 35
 	global $smcFunc;
35 36
 
36 37
 	// Map some database specific functions, only do this once.
37
-	if (!isset($smcFunc['db_fetch_assoc']))
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_fetch_assoc'])) {
39
+			$smcFunc += array(
39 40
 			'db_query'					=> 'smf_db_query',
40 41
 			'db_quote'					=> 'smf_db_quote',
41 42
 			'db_insert'					=> 'smf_db_insert',
@@ -64,11 +65,13 @@  discard block
 block discarded – undo
64 65
 			'db_error_insert'			=> 'smf_db_error_insert',
65 66
 			'db_custom_order'			=> 'smf_db_custom_order',
66 67
 		);
68
+	}
67 69
 
68
-	if (!empty($db_options['persist']))
69
-		$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
70
-	else
71
-		$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
70
+	if (!empty($db_options['persist'])) {
71
+			$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
72
+	} else {
73
+			$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
74
+	}
72 75
 
73 76
 	// Something's wrong, show an error if its fatal (which we assume it is)
74 77
 	if (!$connection)
@@ -76,8 +79,7 @@  discard block
 block discarded – undo
76 79
 		if (!empty($db_options['non_fatal']))
77 80
 		{
78 81
 			return null;
79
-		}
80
-		else
82
+		} else
81 83
 		{
82 84
 			display_db_error();
83 85
 		}
@@ -128,31 +130,38 @@  discard block
 block discarded – undo
128 130
 
129 131
 	list ($values, $connection) = $db_callback;
130 132
 
131
-	if ($matches[1] === 'db_prefix')
132
-		return $db_prefix;
133
+	if ($matches[1] === 'db_prefix') {
134
+			return $db_prefix;
135
+	}
133 136
 
134
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
135
-		return $user_info[$matches[1]];
137
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
138
+			return $user_info[$matches[1]];
139
+	}
136 140
 
137
-	if ($matches[1] === 'empty')
138
-		return '\'\'';
141
+	if ($matches[1] === 'empty') {
142
+			return '\'\'';
143
+	}
139 144
 
140
-	if (!isset($matches[2]))
141
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
145
+	if (!isset($matches[2])) {
146
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
147
+	}
142 148
 
143
-	if ($matches[1] === 'literal')
144
-		return '\'' . pg_escape_string($matches[2]) . '\'';
149
+	if ($matches[1] === 'literal') {
150
+			return '\'' . pg_escape_string($matches[2]) . '\'';
151
+	}
145 152
 
146
-	if (!isset($values[$matches[2]]))
147
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
153
+	if (!isset($values[$matches[2]])) {
154
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
155
+	}
148 156
 
149 157
 	$replacement = $values[$matches[2]];
150 158
 
151 159
 	switch ($matches[1])
152 160
 	{
153 161
 		case 'int':
154
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
155
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
162
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
163
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
164
+			}
156 165
 			return (string) (int) $replacement;
157 166
 		break;
158 167
 
@@ -164,65 +173,73 @@  discard block
 block discarded – undo
164 173
 		case 'array_int':
165 174
 			if (is_array($replacement))
166 175
 			{
167
-				if (empty($replacement))
168
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
176
+				if (empty($replacement)) {
177
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
178
+				}
169 179
 
170 180
 				foreach ($replacement as $key => $value)
171 181
 				{
172
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
173
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
182
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
183
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
184
+					}
174 185
 
175 186
 					$replacement[$key] = (string) (int) $value;
176 187
 				}
177 188
 
178 189
 				return implode(', ', $replacement);
190
+			} else {
191
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
179 192
 			}
180
-			else
181
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
182 193
 
183 194
 		break;
184 195
 
185 196
 		case 'array_string':
186 197
 			if (is_array($replacement))
187 198
 			{
188
-				if (empty($replacement))
189
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
199
+				if (empty($replacement)) {
200
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
201
+				}
190 202
 
191
-				foreach ($replacement as $key => $value)
192
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
203
+				foreach ($replacement as $key => $value) {
204
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
205
+				}
193 206
 
194 207
 				return implode(', ', $replacement);
208
+			} else {
209
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
195 210
 			}
196
-			else
197
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
198 211
 		break;
199 212
 
200 213
 		case 'date':
201
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
202
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
203
-			else
204
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
214
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
215
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
216
+			} else {
217
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218
+			}
205 219
 		break;
206 220
 
207 221
 		case 'time':
208
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
209
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
210
-			else
211
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
223
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
224
+			} else {
225
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
226
+			}
212 227
 		break;
213 228
 
214 229
 		case 'datetime':
215
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
216
-				return 'to_timestamp('.
230
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
231
+							return 'to_timestamp('.
217 232
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
218 233
 					',\'YYYY-MM-DD HH24:MI:SS\')';
219
-			else
220
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
234
+			} else {
235
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
236
+			}
221 237
 		break;
222 238
 
223 239
 		case 'float':
224
-			if (!is_numeric($replacement))
225
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240
+			if (!is_numeric($replacement)) {
241
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
242
+			}
226 243
 			return (string) (float) $replacement;
227 244
 		break;
228 245
 
@@ -235,31 +252,36 @@  discard block
 block discarded – undo
235 252
 		break;
236 253
 
237 254
 		case 'inet':
238
-			if ($replacement == 'null' || $replacement == '')
239
-				return 'null';
240
-			if (inet_pton($replacement) === false)
241
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
255
+			if ($replacement == 'null' || $replacement == '') {
256
+							return 'null';
257
+			}
258
+			if (inet_pton($replacement) === false) {
259
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
260
+			}
242 261
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
243 262
 
244 263
 		case 'array_inet':
245 264
 			if (is_array($replacement))
246 265
 			{
247
-				if (empty($replacement))
248
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+				if (empty($replacement)) {
267
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
268
+				}
249 269
 
250 270
 				foreach ($replacement as $key => $value)
251 271
 				{
252
-					if ($replacement == 'null' || $replacement == '')
253
-						$replacement[$key] = 'null';
254
-					if (!isValidIP($value))
255
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
272
+					if ($replacement == 'null' || $replacement == '') {
273
+											$replacement[$key] = 'null';
274
+					}
275
+					if (!isValidIP($value)) {
276
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
277
+					}
256 278
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
257 279
 				}
258 280
 
259 281
 				return implode(', ', $replacement);
282
+			} else {
283
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
260 284
 			}
261
-			else
262
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
263 285
 		break;
264 286
 
265 287
 		default:
@@ -350,14 +372,16 @@  discard block
 block discarded – undo
350 372
 		),
351 373
 	);
352 374
 
353
-	if (isset($replacements[$identifier]))
354
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
375
+	if (isset($replacements[$identifier])) {
376
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
377
+	}
355 378
 
356 379
 	// Limits need to be a little different.
357 380
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
358 381
 
359
-	if (trim($db_string) == '')
360
-		return false;
382
+	if (trim($db_string) == '') {
383
+			return false;
384
+	}
361 385
 
362 386
 	// Comments that are allowed in a query are preg_removed.
363 387
 	static $allowed_comments_from = array(
@@ -377,8 +401,9 @@  discard block
 block discarded – undo
377 401
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
378 402
 	$db_replace_result = 0;
379 403
 
380
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
381
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
404
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
405
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
406
+	}
382 407
 
383 408
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
384 409
 	{
@@ -403,17 +428,18 @@  discard block
 block discarded – undo
403 428
 		while (true)
404 429
 		{
405 430
 			$pos = strpos($db_string_1, '\'', $pos + 1);
406
-			if ($pos === false)
407
-				break;
431
+			if ($pos === false) {
432
+							break;
433
+			}
408 434
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
409 435
 
410 436
 			while (true)
411 437
 			{
412 438
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
413 439
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
414
-				if ($pos1 === false)
415
-					break;
416
-				elseif ($pos2 === false || $pos2 > $pos1)
440
+				if ($pos1 === false) {
441
+									break;
442
+				} elseif ($pos2 === false || $pos2 > $pos1)
417 443
 				{
418 444
 					$pos = $pos1;
419 445
 					break;
@@ -429,16 +455,19 @@  discard block
 block discarded – undo
429 455
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
430 456
 
431 457
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
432
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
433
-			$fail = true;
458
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
459
+					$fail = true;
460
+		}
434 461
 		// Trying to change passwords, slow us down, or something?
435
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
436
-			$fail = true;
437
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
438
-			$fail = true;
462
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
463
+					$fail = true;
464
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
465
+					$fail = true;
466
+		}
439 467
 
440
-		if (!empty($fail) && function_exists('log_error'))
441
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
468
+		if (!empty($fail) && function_exists('log_error')) {
469
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
470
+		}
442 471
 	}
443 472
 
444 473
 	// Set optimize stuff
@@ -465,8 +494,9 @@  discard block
 block discarded – undo
465 494
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
466 495
 
467 496
 		// Initialize $db_cache if not already initialized.
468
-		if (!isset($db_cache))
469
-			$db_cache = array();
497
+		if (!isset($db_cache)) {
498
+					$db_cache = array();
499
+		}
470 500
 
471 501
 		if (!empty($_SESSION['debug_redirect']))
472 502
 		{
@@ -484,12 +514,14 @@  discard block
 block discarded – undo
484 514
 
485 515
 	$db_last_result = @pg_query($connection, $db_string);
486 516
 
487
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
488
-		$db_last_result = smf_db_error($db_string, $connection);
517
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
518
+			$db_last_result = smf_db_error($db_string, $connection);
519
+	}
489 520
 
490 521
 	// Debugging.
491
-	if (isset($db_show_debug) && $db_show_debug === true)
492
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
522
+	if (isset($db_show_debug) && $db_show_debug === true) {
523
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
524
+	}
493 525
 
494 526
 	return $db_last_result;
495 527
 }
@@ -506,10 +538,11 @@  discard block
 block discarded – undo
506 538
 {
507 539
 	global $db_last_result, $db_replace_result;
508 540
 
509
-	if ($db_replace_result)
510
-		return $db_replace_result;
511
-	elseif ($result === null && !$db_last_result)
512
-		return 0;
541
+	if ($db_replace_result) {
542
+			return $db_replace_result;
543
+	} elseif ($result === null && !$db_last_result) {
544
+			return 0;
545
+	}
513 546
 
514 547
 	return pg_affected_rows($result === null ? $db_last_result : $result);
515 548
 }
@@ -533,8 +566,9 @@  discard block
 block discarded – undo
533 566
 		array(
534 567
 		)
535 568
 	);
536
-	if (!$request)
537
-		return false;
569
+	if (!$request) {
570
+			return false;
571
+	}
538 572
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
539 573
 	$smcFunc['db_free_result']($request);
540 574
 
@@ -555,12 +589,13 @@  discard block
 block discarded – undo
555 589
 	// Decide which connection to use
556 590
 	$connection = $connection === null ? $db_connection : $connection;
557 591
 
558
-	if ($type == 'begin')
559
-		return @pg_query($connection, 'BEGIN');
560
-	elseif ($type == 'rollback')
561
-		return @pg_query($connection, 'ROLLBACK');
562
-	elseif ($type == 'commit')
563
-		return @pg_query($connection, 'COMMIT');
592
+	if ($type == 'begin') {
593
+			return @pg_query($connection, 'BEGIN');
594
+	} elseif ($type == 'rollback') {
595
+			return @pg_query($connection, 'ROLLBACK');
596
+	} elseif ($type == 'commit') {
597
+			return @pg_query($connection, 'COMMIT');
598
+	}
564 599
 
565 600
 	return false;
566 601
 }
@@ -588,19 +623,22 @@  discard block
 block discarded – undo
588 623
 	$query_error = @pg_last_error($connection);
589 624
 
590 625
 	// Log the error.
591
-	if (function_exists('log_error'))
592
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
626
+	if (function_exists('log_error')) {
627
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
628
+	}
593 629
 
594 630
 	// Nothing's defined yet... just die with it.
595
-	if (empty($context) || empty($txt))
596
-		die($query_error);
631
+	if (empty($context) || empty($txt)) {
632
+			die($query_error);
633
+	}
597 634
 
598 635
 	// Show an error message, if possible.
599 636
 	$context['error_title'] = $txt['database_error'];
600
-	if (allowedTo('admin_forum'))
601
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
602
-	else
603
-		$context['error_message'] = $txt['try_again'];
637
+	if (allowedTo('admin_forum')) {
638
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
639
+	} else {
640
+			$context['error_message'] = $txt['try_again'];
641
+	}
604 642
 
605 643
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
606 644
 	{
@@ -622,12 +660,14 @@  discard block
 block discarded – undo
622 660
 {
623 661
 	global $db_row_count;
624 662
 
625
-	if ($counter !== false)
626
-		return pg_fetch_row($request, $counter);
663
+	if ($counter !== false) {
664
+			return pg_fetch_row($request, $counter);
665
+	}
627 666
 
628 667
 	// Reset the row counter...
629
-	if (!isset($db_row_count[(int) $request]))
630
-		$db_row_count[(int) $request] = 0;
668
+	if (!isset($db_row_count[(int) $request])) {
669
+			$db_row_count[(int) $request] = 0;
670
+	}
631 671
 
632 672
 	// Return the right row.
633 673
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -644,12 +684,14 @@  discard block
 block discarded – undo
644 684
 {
645 685
 	global $db_row_count;
646 686
 
647
-	if ($counter !== false)
648
-		return pg_fetch_assoc($request, $counter);
687
+	if ($counter !== false) {
688
+			return pg_fetch_assoc($request, $counter);
689
+	}
649 690
 
650 691
 	// Reset the row counter...
651
-	if (!isset($db_row_count[(int) $request]))
652
-		$db_row_count[(int) $request] = 0;
692
+	if (!isset($db_row_count[(int) $request])) {
693
+			$db_row_count[(int) $request] = 0;
694
+	}
653 695
 
654 696
 	// Return the right row.
655 697
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -702,11 +744,13 @@  discard block
 block discarded – undo
702 744
 
703 745
 	$replace = '';
704 746
 
705
-	if (empty($data))
706
-		return;
747
+	if (empty($data)) {
748
+			return;
749
+	}
707 750
 
708
-	if (!is_array($data[array_rand($data)]))
709
-		$data = array($data);
751
+	if (!is_array($data[array_rand($data)])) {
752
+			$data = array($data);
753
+	}
710 754
 
711 755
 	// Replace the prefix holder with the actual prefix.
712 756
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -725,11 +769,13 @@  discard block
 block discarded – undo
725 769
 			//pg 9.5 got replace support
726 770
 			$pg_version = $smcFunc['db_get_version']();
727 771
 			// if we got a Beta Version
728
-			if (stripos($pg_version, 'beta') !== false)
729
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
772
+			if (stripos($pg_version, 'beta') !== false) {
773
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
774
+			}
730 775
 			// or RC
731
-			if (stripos($pg_version, 'rc') !== false)
732
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
776
+			if (stripos($pg_version, 'rc') !== false) {
777
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
778
+			}
733 779
 
734 780
 			$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
735 781
 		}
@@ -748,32 +794,35 @@  discard block
 block discarded – undo
748 794
 					$key_str .= ($count_pk > 0 ? ',' : '');
749 795
 					$key_str .= $columnName;
750 796
 					$count_pk++;
751
-				}
752
-				else if ($method == 'replace') //normal field
797
+				} else if ($method == 'replace') {
798
+					//normal field
753 799
 				{
754 800
 					$col_str .= ($count > 0 ? ',' : '');
801
+				}
755 802
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
756 803
 					$count++;
757 804
 				}
758 805
 			}
759
-			if ($method == 'replace')
760
-				$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
761
-			else
762
-				$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
763
-		}
764
-		else if ($method == 'replace')
806
+			if ($method == 'replace') {
807
+							$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
808
+			} else {
809
+							$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
810
+			}
811
+		} else if ($method == 'replace')
765 812
 		{
766 813
 			foreach ($columns as $columnName => $type)
767 814
 			{
768 815
 				// Are we restricting the length?
769
-				if (strpos($type, 'string-') !== false)
770
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
771
-				else
772
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
816
+				if (strpos($type, 'string-') !== false) {
817
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
818
+				} else {
819
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
820
+				}
773 821
 
774 822
 				// A key? That's what we were looking for.
775
-				if (in_array($columnName, $keys))
776
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
823
+				if (in_array($columnName, $keys)) {
824
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
825
+				}
777 826
 				$count++;
778 827
 			}
779 828
 
@@ -809,10 +858,11 @@  discard block
 block discarded – undo
809 858
 		foreach ($columns as $columnName => $type)
810 859
 		{
811 860
 			// Are we restricting the length?
812
-			if (strpos($type, 'string-') !== false)
813
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
814
-			else
815
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
861
+			if (strpos($type, 'string-') !== false) {
862
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
863
+			} else {
864
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
865
+			}
816 866
 		}
817 867
 		$insertData = substr($insertData, 0, -2) . ')';
818 868
 
@@ -821,8 +871,9 @@  discard block
 block discarded – undo
821 871
 
822 872
 		// Here's where the variables are injected to the query.
823 873
 		$insertRows = array();
824
-		foreach ($data as $dataRow)
825
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
874
+		foreach ($data as $dataRow) {
875
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
876
+		}
826 877
 
827 878
 		// Do the insert.
828 879
 		$request = $smcFunc['db_query']('', '
@@ -839,19 +890,21 @@  discard block
 block discarded – undo
839 890
 
840 891
 		if ($with_returning && $request !== false)
841 892
 		{
842
-			if ($returnmode === 2)
843
-				$return_var = array();
893
+			if ($returnmode === 2) {
894
+							$return_var = array();
895
+			}
844 896
 
845 897
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
846 898
 			{
847
-				if (is_numeric($row[0])) // try to emulate mysql limitation
899
+				if (is_numeric($row[0])) {
900
+					// try to emulate mysql limitation
848 901
 				{
849 902
 					if ($returnmode === 1)
850 903
 						$return_var = $row[0];
851
-					elseif ($returnmode === 2)
852
-						$return_var[] = $row[0];
853
-				}
854
-				else
904
+				} elseif ($returnmode === 2) {
905
+											$return_var[] = $row[0];
906
+					}
907
+				} else
855 908
 				{
856 909
 					$with_returning = false;
857 910
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -860,9 +913,10 @@  discard block
 block discarded – undo
860 913
 		}
861 914
 	}
862 915
 
863
-	if ($with_returning && !empty($return_var))
864
-		return $return_var;
865
-}
916
+	if ($with_returning && !empty($return_var)) {
917
+			return $return_var;
918
+	}
919
+	}
866 920
 
867 921
 /**
868 922
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -899,8 +953,9 @@  discard block
 block discarded – undo
899 953
  */
900 954
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
901 955
 {
902
-	if (empty($log_message))
903
-		$log_message = $error_message;
956
+	if (empty($log_message)) {
957
+			$log_message = $error_message;
958
+	}
904 959
 
905 960
 	foreach (debug_backtrace() as $step)
906 961
 	{
@@ -919,12 +974,14 @@  discard block
 block discarded – undo
919 974
 	}
920 975
 
921 976
 	// A special case - we want the file and line numbers for debugging.
922
-	if ($error_type == 'return')
923
-		return array($file, $line);
977
+	if ($error_type == 'return') {
978
+			return array($file, $line);
979
+	}
924 980
 
925 981
 	// Is always a critical error.
926
-	if (function_exists('log_error'))
927
-		log_error($log_message, 'critical', $file, $line);
982
+	if (function_exists('log_error')) {
983
+			log_error($log_message, 'critical', $file, $line);
984
+	}
928 985
 
929 986
 	if (function_exists('fatal_error'))
930 987
 	{
@@ -932,12 +989,12 @@  discard block
 block discarded – undo
932 989
 
933 990
 		// Cannot continue...
934 991
 		exit;
992
+	} elseif ($error_type) {
993
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
994
+	} else {
995
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
996
+	}
935 997
 	}
936
-	elseif ($error_type)
937
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
938
-	else
939
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
940
-}
941 998
 
942 999
 /**
943 1000
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -954,10 +1011,11 @@  discard block
 block discarded – undo
954 1011
 		'\\' => '\\\\',
955 1012
 	);
956 1013
 
957
-	if ($translate_human_wildcards)
958
-		$replacements += array(
1014
+	if ($translate_human_wildcards) {
1015
+			$replacements += array(
959 1016
 			'*' => '%',
960 1017
 		);
1018
+	}
961 1019
 
962 1020
 	return strtr($string, $replacements);
963 1021
 }
@@ -986,14 +1044,16 @@  discard block
 block discarded – undo
986 1044
 	static $pg_error_data_prep;
987 1045
 
988 1046
 	// without database we can't do anything
989
-	if (empty($db_connection))
990
-		return;
1047
+	if (empty($db_connection)) {
1048
+			return;
1049
+	}
991 1050
 
992
-	if (empty($pg_error_data_prep))
993
-			$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
1051
+	if (empty($pg_error_data_prep)) {
1052
+				$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
994 1053
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line)
995 1054
 													VALUES(		$1,		$2,		$3, $4, 	$5,		$6,			$7,		$8,	$9)'
996 1055
 			);
1056
+	}
997 1057
 
998 1058
 	pg_execute($db_connection, 'smf_log_errors', $error_array);
999 1059
 }
@@ -1013,8 +1073,9 @@  discard block
 block discarded – undo
1013 1073
 	$count = count($array_values);
1014 1074
 	$then = ($desc ? ' THEN -' : ' THEN ');
1015 1075
 
1016
-	for ($i = 0; $i < $count; $i++)
1017
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1076
+	for ($i = 0; $i < $count; $i++) {
1077
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1078
+	}
1018 1079
 
1019 1080
 	$return .= 'END';
1020 1081
 	return $return;
Please login to merge, or discard this patch.
Sources/Session.php 1 patch
Braces   +37 added lines, -25 removed lines patch added patch discarded remove patch
@@ -17,8 +17,9 @@  discard block
 block discarded – undo
17 17
  * @version 2.1 Beta 4
18 18
  */
19 19
 
20
-if (!defined('SMF'))
20
+if (!defined('SMF')) {
21 21
 	die('No direct access...');
22
+}
22 23
 
23 24
 /**
24 25
  * Attempt to start the session, unless it already has been.
@@ -38,8 +39,9 @@  discard block
 block discarded – undo
38 39
 	{
39 40
 		$parsed_url = parse_url($boardurl);
40 41
 
41
-		if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
42
-			@ini_set('session.cookie_domain', '.' . $parts[1]);
42
+		if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
43
+					@ini_set('session.cookie_domain', '.' . $parts[1]);
44
+		}
43 45
 	}
44 46
 	// @todo Set the session cookie path?
45 47
 
@@ -47,8 +49,9 @@  discard block
 block discarded – undo
47 49
 	if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '')
48 50
 	{
49 51
 		// Attempt to end the already-started session.
50
-		if (ini_get('session.auto_start') == 1)
51
-			session_write_close();
52
+		if (ini_get('session.auto_start') == 1) {
53
+					session_write_close();
54
+		}
52 55
 
53 56
 		// This is here to stop people from using bad junky PHPSESSIDs.
54 57
 		if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()]))
@@ -63,23 +66,26 @@  discard block
 block discarded – undo
63 66
 		if (!empty($modSettings['databaseSession_enable']))
64 67
 		{
65 68
 			@ini_set('session.serialize_handler', 'php_serialize');
66
-			if (ini_get('session.serialize_handler') != 'php_serialize')
67
-				@ini_set('session.serialize_handler', 'php');
69
+			if (ini_get('session.serialize_handler') != 'php_serialize') {
70
+							@ini_set('session.serialize_handler', 'php');
71
+			}
68 72
 			session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC');
69 73
 			@ini_set('session.gc_probability', '1');
74
+		} elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) {
75
+					@ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60));
70 76
 		}
71
-		elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime']))
72
-			@ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60));
73 77
 
74 78
 		// Use cache setting sessions?
75
-		if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli')
76
-			call_integration_hook('integrate_session_handlers');
79
+		if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') {
80
+					call_integration_hook('integrate_session_handlers');
81
+		}
77 82
 
78 83
 		session_start();
79 84
 
80 85
 		// Change it so the cache settings are a little looser than default.
81
-		if (!empty($modSettings['databaseSession_loose']))
82
-			header('cache-control: private');
86
+		if (!empty($modSettings['databaseSession_loose'])) {
87
+					header('cache-control: private');
88
+		}
83 89
 	}
84 90
 
85 91
 	// Set the randomly generated code.
@@ -125,8 +131,9 @@  discard block
 block discarded – undo
125 131
 {
126 132
 	global $smcFunc;
127 133
 
128
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
129
-		return '';
134
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
135
+			return '';
136
+	}
130 137
 
131 138
 	// Look for it in the database.
132 139
 	$result = $smcFunc['db_query']('', '
@@ -155,8 +162,9 @@  discard block
 block discarded – undo
155 162
 {
156 163
 	global $smcFunc, $db_connection, $db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_persist, $db_port;
157 164
 
158
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
159
-		return false;
165
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
166
+			return false;
167
+	}
160 168
 
161 169
 	// php < 7.0 need this
162 170
 	if (empty($db_connection))
@@ -164,8 +172,9 @@  discard block
 block discarded – undo
164 172
 		$db_options = array();
165 173
 
166 174
 		// Add in the port if needed
167
-		if (!empty($db_port))
168
-			$db_options['port'] = $db_port;
175
+		if (!empty($db_port)) {
176
+					$db_options['port'] = $db_port;
177
+		}
169 178
 		$options = array_merge($db_options, array('persist' => $db_persist, 'dont_select_db' => SMF == 'SSI'));
170 179
 
171 180
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
@@ -184,13 +193,14 @@  discard block
 block discarded – undo
184 193
 	);
185 194
 
186 195
 	// If that didn't work, try inserting a new one.
187
-	if ($smcFunc['db_affected_rows']() == 0)
188
-		$smcFunc['db_insert']('ignore',
196
+	if ($smcFunc['db_affected_rows']() == 0) {
197
+			$smcFunc['db_insert']('ignore',
189 198
 			'{db_prefix}sessions',
190 199
 			array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'),
191 200
 			array($session_id, $data, time()),
192 201
 			array('session_id')
193 202
 		);
203
+	}
194 204
 
195 205
 	return ($smcFunc['db_affected_rows']() == 0 ? false : true);
196 206
 }
@@ -205,8 +215,9 @@  discard block
 block discarded – undo
205 215
 {
206 216
 	global $smcFunc;
207 217
 
208
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
209
-		return false;
218
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
219
+			return false;
220
+	}
210 221
 
211 222
 	// Just delete the row...
212 223
 	$smcFunc['db_query']('', '
@@ -232,8 +243,9 @@  discard block
 block discarded – undo
232 243
 	global $modSettings, $smcFunc;
233 244
 
234 245
 	// Just set to the default or lower?  Ignore it for a higher value. (hopefully)
235
-	if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime))
236
-		$max_lifetime = max($modSettings['databaseSession_lifetime'], 60);
246
+	if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) {
247
+			$max_lifetime = max($modSettings['databaseSession_lifetime'], 60);
248
+	}
237 249
 
238 250
 	// Clean up after yerself ;).
239 251
 	$smcFunc['db_query']('', '
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +898 added lines, -659 removed lines patch added patch discarded remove patch
@@ -75,8 +75,9 @@  discard block
 block discarded – undo
75 75
 $upcontext['inactive_timeout'] = 10;
76 76
 
77 77
 // The helper is crucial. Include it first thing.
78
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
78
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
79 79
     die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
80
+}
80 81
 
81 82
 require_once($upgrade_path . '/upgrade-helper.php');
82 83
 
@@ -107,11 +108,14 @@  discard block
 block discarded – undo
107 108
 	ini_set('default_socket_timeout', 900);
108 109
 }
109 110
 // Clean the upgrade path if this is from the client.
110
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
111
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
111
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
112
+	for ($i = 1;
113
+}
114
+$i < $_SERVER['argc']; $i++)
112 115
 	{
113
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
114
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
116
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
117
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
118
+		}
115 119
 	}
116 120
 
117 121
 // Are we from the client?
@@ -119,16 +123,17 @@  discard block
 block discarded – undo
119 123
 {
120 124
 	$command_line = true;
121 125
 	$disable_security = true;
122
-}
123
-else
126
+} else {
124 127
 	$command_line = false;
128
+}
125 129
 
126 130
 // Load this now just because we can.
127 131
 require_once($upgrade_path . '/Settings.php');
128 132
 
129 133
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
130
-if (isset($language))
134
+if (isset($language)) {
131 135
 	$language = str_ireplace('-utf8', '', $language);
136
+}
132 137
 
133 138
 // Are we logged in?
134 139
 if (isset($upgradeData))
@@ -136,10 +141,12 @@  discard block
 block discarded – undo
136 141
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
137 142
 
138 143
 	// Check for sensible values.
139
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
140
-		$upcontext['user']['started'] = time();
141
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
142
-		$upcontext['user']['updated'] = 0;
144
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
145
+			$upcontext['user']['started'] = time();
146
+	}
147
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
148
+			$upcontext['user']['updated'] = 0;
149
+	}
143 150
 
144 151
 	$upcontext['started'] = $upcontext['user']['started'];
145 152
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -204,8 +211,9 @@  discard block
 block discarded – undo
204 211
 			'db_error_skip' => true,
205 212
 		)
206 213
 	);
207
-	while ($row = $smcFunc['db_fetch_assoc']($request))
208
-		$modSettings[$row['variable']] = $row['value'];
214
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
215
+			$modSettings[$row['variable']] = $row['value'];
216
+	}
209 217
 	$smcFunc['db_free_result']($request);
210 218
 }
211 219
 
@@ -215,10 +223,12 @@  discard block
 block discarded – undo
215 223
 	$modSettings['theme_url'] = 'Themes/default';
216 224
 	$modSettings['images_url'] = 'Themes/default/images';
217 225
 }
218
-if (!isset($settings['default_theme_url']))
226
+if (!isset($settings['default_theme_url'])) {
219 227
 	$settings['default_theme_url'] = $modSettings['theme_url'];
220
-if (!isset($settings['default_theme_dir']))
228
+}
229
+if (!isset($settings['default_theme_dir'])) {
221 230
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
231
+}
222 232
 
223 233
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
224 234
 // Default title...
@@ -236,13 +246,15 @@  discard block
 block discarded – undo
236 246
 	$support_js = $upcontext['upgrade_status']['js'];
237 247
 
238 248
 	// Only set this if the upgrader status says so.
239
-	if (empty($is_debug))
240
-		$is_debug = $upcontext['upgrade_status']['debug'];
249
+	if (empty($is_debug)) {
250
+			$is_debug = $upcontext['upgrade_status']['debug'];
251
+	}
241 252
 
242 253
 	// Load the language.
243
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
244
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
245
-}
254
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
255
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
256
+	}
257
+	}
246 258
 // Set the defaults.
247 259
 else
248 260
 {
@@ -260,15 +272,18 @@  discard block
 block discarded – undo
260 272
 }
261 273
 
262 274
 // If this isn't the first stage see whether they are logging in and resuming.
263
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
275
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
264 276
 	checkLogin();
277
+}
265 278
 
266
-if ($command_line)
279
+if ($command_line) {
267 280
 	cmdStep0();
281
+}
268 282
 
269 283
 // Don't error if we're using xml.
270
-if (isset($_GET['xml']))
284
+if (isset($_GET['xml'])) {
271 285
 	$upcontext['return_error'] = true;
286
+}
272 287
 
273 288
 // Loop through all the steps doing each one as required.
274 289
 $upcontext['overall_percent'] = 0;
@@ -289,9 +304,9 @@  discard block
 block discarded – undo
289 304
 		}
290 305
 
291 306
 		// Call the step and if it returns false that means pause!
292
-		if (function_exists($step[2]) && $step[2]() === false)
293
-			break;
294
-		elseif (function_exists($step[2])) {
307
+		if (function_exists($step[2]) && $step[2]() === false) {
308
+					break;
309
+		} elseif (function_exists($step[2])) {
295 310
 			//Start each new step with this unset, so the 'normal' template is called first
296 311
 			unset($_GET['xml']);
297 312
 			//Clear out warnings at the start of each step
@@ -337,17 +352,18 @@  discard block
 block discarded – undo
337 352
 		// This should not happen my dear... HELP ME DEVELOPERS!!
338 353
 		if (!empty($command_line))
339 354
 		{
340
-			if (function_exists('debug_print_backtrace'))
341
-				debug_print_backtrace();
355
+			if (function_exists('debug_print_backtrace')) {
356
+							debug_print_backtrace();
357
+			}
342 358
 
343 359
 			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.';
344 360
 			flush();
345 361
 			die();
346 362
 		}
347 363
 
348
-		if (!isset($_GET['xml']))
349
-			template_upgrade_above();
350
-		else
364
+		if (!isset($_GET['xml'])) {
365
+					template_upgrade_above();
366
+		} else
351 367
 		{
352 368
 			header('content-type: text/xml; charset=UTF-8');
353 369
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -369,25 +385,29 @@  discard block
 block discarded – undo
369 385
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
370 386
 
371 387
 			// Custom stuff to pass back?
372
-			if (!empty($upcontext['query_string']))
373
-				$upcontext['form_url'] .= $upcontext['query_string'];
388
+			if (!empty($upcontext['query_string'])) {
389
+							$upcontext['form_url'] .= $upcontext['query_string'];
390
+			}
374 391
 
375 392
 			// Call the appropriate subtemplate
376
-			if (is_callable('template_' . $upcontext['sub_template']))
377
-				call_user_func('template_' . $upcontext['sub_template']);
378
-			else
379
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
393
+			if (is_callable('template_' . $upcontext['sub_template'])) {
394
+							call_user_func('template_' . $upcontext['sub_template']);
395
+			} else {
396
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
397
+			}
380 398
 		}
381 399
 
382 400
 		// Was there an error?
383
-		if (!empty($upcontext['forced_error_message']))
384
-			echo $upcontext['forced_error_message'];
401
+		if (!empty($upcontext['forced_error_message'])) {
402
+					echo $upcontext['forced_error_message'];
403
+		}
385 404
 
386 405
 		// Show the footer.
387
-		if (!isset($_GET['xml']))
388
-			template_upgrade_below();
389
-		else
390
-			template_xml_below();
406
+		if (!isset($_GET['xml'])) {
407
+					template_upgrade_below();
408
+		} else {
409
+					template_xml_below();
410
+		}
391 411
 	}
392 412
 
393 413
 
@@ -399,15 +419,19 @@  discard block
 block discarded – undo
399 419
 		$seconds = intval($active % 60);
400 420
 
401 421
 		$totalTime = '';
402
-		if ($hours > 0)
403
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
404
-		if ($minutes > 0)
405
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
406
-		if ($seconds > 0)
407
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
422
+		if ($hours > 0) {
423
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
424
+		}
425
+		if ($minutes > 0) {
426
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
427
+		}
428
+		if ($seconds > 0) {
429
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
430
+		}
408 431
 
409
-		if (!empty($totalTime))
410
-			echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
432
+		if (!empty($totalTime)) {
433
+					echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
434
+		}
411 435
 	}
412 436
 
413 437
 	// Bang - gone!
@@ -428,8 +452,9 @@  discard block
 block discarded – undo
428 452
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
429 453
 		while ($entry = $dir->read())
430 454
 		{
431
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
432
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
455
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
456
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
457
+			}
433 458
 		}
434 459
 		$dir->close();
435 460
 	}
@@ -464,10 +489,11 @@  discard block
 block discarded – undo
464 489
 	}
465 490
 
466 491
 		// Override the language file?
467
-		if (isset($_GET['lang_file']))
468
-			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
469
-		elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
470
-			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
492
+		if (isset($_GET['lang_file'])) {
493
+					$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
494
+		} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
495
+					$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
496
+		}
471 497
 
472 498
 		// Make sure it exists, if it doesn't reset it.
473 499
 		if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -476,8 +502,9 @@  discard block
 block discarded – undo
476 502
 			list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
477 503
 
478 504
 			// If we have english and some other language, use the other language.  We Americans hate english :P.
479
-			if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
480
-				list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
505
+			if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
506
+							list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
507
+			}
481 508
 		}
482 509
 
483 510
 		// And now include the actual language file itself.
@@ -494,8 +521,9 @@  discard block
 block discarded – undo
494 521
 	global $upgradeurl, $upcontext, $command_line;
495 522
 
496 523
 	// Command line users can't be redirected.
497
-	if ($command_line)
498
-		upgradeExit(true);
524
+	if ($command_line) {
525
+			upgradeExit(true);
526
+	}
499 527
 
500 528
 	// Are we providing the core info?
501 529
 	if ($addForm)
@@ -521,12 +549,14 @@  discard block
 block discarded – undo
521 549
 	define('SMF', 1);
522 550
 
523 551
 	// Start the session.
524
-	if (@ini_get('session.save_handler') == 'user')
525
-		@ini_set('session.save_handler', 'files');
552
+	if (@ini_get('session.save_handler') == 'user') {
553
+			@ini_set('session.save_handler', 'files');
554
+	}
526 555
 	@session_start();
527 556
 
528
-	if (empty($smcFunc))
529
-		$smcFunc = array();
557
+	if (empty($smcFunc)) {
558
+			$smcFunc = array();
559
+	}
530 560
 
531 561
 	// We need this for authentication and some upgrade code
532 562
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -553,24 +583,27 @@  discard block
 block discarded – undo
553 583
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
554 584
 
555 585
 		// Make the connection...
556
-		if (empty($db_connection))
557
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
558
-		else
559
-			// If we've returned here, ping/reconnect to be safe
586
+		if (empty($db_connection)) {
587
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
588
+		} else {
589
+					// If we've returned here, ping/reconnect to be safe
560 590
 			$smcFunc['db_ping']($db_connection);
591
+		}
561 592
 
562 593
 		// Oh dear god!!
563
-		if ($db_connection === null)
564
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
594
+		if ($db_connection === null) {
595
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
596
+		}
565 597
 
566
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
567
-			$smcFunc['db_query']('', '
598
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
599
+					$smcFunc['db_query']('', '
568 600
 			SET NAMES {string:db_character_set}',
569 601
 			array(
570 602
 				'db_error_skip' => true,
571 603
 				'db_character_set' => $db_character_set,
572 604
 			)
573 605
 		);
606
+		}
574 607
 
575 608
 		// Load the modSettings data...
576 609
 		$request = $smcFunc['db_query']('', '
@@ -581,11 +614,11 @@  discard block
 block discarded – undo
581 614
 			)
582 615
 		);
583 616
 		$modSettings = array();
584
-		while ($row = $smcFunc['db_fetch_assoc']($request))
585
-			$modSettings[$row['variable']] = $row['value'];
617
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
618
+					$modSettings[$row['variable']] = $row['value'];
619
+		}
586 620
 		$smcFunc['db_free_result']($request);
587
-	}
588
-	else
621
+	} else
589 622
 	{
590 623
 		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.');
591 624
 	}
@@ -599,9 +632,10 @@  discard block
 block discarded – undo
599 632
 		cleanRequest();
600 633
 	}
601 634
 
602
-	if (!isset($_GET['substep']))
603
-		$_GET['substep'] = 0;
604
-}
635
+	if (!isset($_GET['substep'])) {
636
+			$_GET['substep'] = 0;
637
+	}
638
+	}
605 639
 
606 640
 function initialize_inputs()
607 641
 {
@@ -631,8 +665,9 @@  discard block
 block discarded – undo
631 665
 		$dh = opendir(dirname(__FILE__));
632 666
 		while ($file = readdir($dh))
633 667
 		{
634
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
635
-				@unlink(dirname(__FILE__) . '/' . $file);
668
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
669
+							@unlink(dirname(__FILE__) . '/' . $file);
670
+			}
636 671
 		}
637 672
 		closedir($dh);
638 673
 
@@ -661,8 +696,9 @@  discard block
 block discarded – undo
661 696
 	$temp = 'upgrade_php?step';
662 697
 	while (strlen($temp) > 4)
663 698
 	{
664
-		if (isset($_GET[$temp]))
665
-			unset($_GET[$temp]);
699
+		if (isset($_GET[$temp])) {
700
+					unset($_GET[$temp]);
701
+		}
666 702
 		$temp = substr($temp, 1);
667 703
 	}
668 704
 
@@ -689,32 +725,39 @@  discard block
 block discarded – undo
689 725
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
690 726
 
691 727
 	// Need legacy scripts?
692
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
693
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
694
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
695
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
696
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
697
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
728
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
729
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
730
+	}
731
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
732
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
733
+	}
734
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
735
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
736
+	}
698 737
 
699 738
 	// We don't need "-utf8" files anymore...
700 739
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
701 740
 
702 741
 	// This needs to exist!
703
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
704
-		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>]');
705
-	else
706
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
742
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
743
+			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>]');
744
+	} else {
745
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
746
+	}
707 747
 
708
-	if (!$check)
709
-		// 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.
748
+	if (!$check) {
749
+			// 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.
710 750
 		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.');
751
+	}
711 752
 
712 753
 	// Do they meet the install requirements?
713
-	if (!php_version_check())
714
-		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.');
754
+	if (!php_version_check()) {
755
+			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.');
756
+	}
715 757
 
716
-	if (!db_version_check())
717
-		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.');
758
+	if (!db_version_check()) {
759
+			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.');
760
+	}
718 761
 
719 762
 	// Do some checks to make sure they have proper privileges
720 763
 	db_extend('packages');
@@ -729,14 +772,16 @@  discard block
 block discarded – undo
729 772
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
730 773
 
731 774
 	// Sorry... we need CREATE, ALTER and DROP
732
-	if (!$create || !$alter || !$drop)
733
-		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.');
775
+	if (!$create || !$alter || !$drop) {
776
+			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.');
777
+	}
734 778
 
735 779
 	// Do a quick version spot check.
736 780
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
737 781
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
738
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
739
-		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.');
782
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
783
+			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.');
784
+	}
740 785
 
741 786
 	// What absolutely needs to be writable?
742 787
 	$writable_files = array(
@@ -745,12 +790,13 @@  discard block
 block discarded – undo
745 790
 	);
746 791
 
747 792
 	// Only check for minified writable files if we have it enabled or not set.
748
-	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files']))
749
-		$writable_files += array(
793
+	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) {
794
+			$writable_files += array(
750 795
 			$modSettings['theme_dir'] . '/css/minified.css',
751 796
 			$modSettings['theme_dir'] . '/scripts/minified.js',
752 797
 			$modSettings['theme_dir'] . '/scripts/minified_deferred.js',
753 798
 		);
799
+	}
754 800
 
755 801
 	// Do we need to add this setting?
756 802
 	$need_settings_update = empty($modSettings['custom_avatar_dir']);
@@ -762,12 +808,13 @@  discard block
 block discarded – undo
762 808
 	quickFileWritable($custom_av_dir);
763 809
 
764 810
 	// Are we good now?
765
-	if (!is_writable($custom_av_dir))
766
-		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));
767
-	elseif ($need_settings_update)
811
+	if (!is_writable($custom_av_dir)) {
812
+			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));
813
+	} elseif ($need_settings_update)
768 814
 	{
769
-		if (!function_exists('cache_put_data'))
770
-			require_once($sourcedir . '/Load.php');
815
+		if (!function_exists('cache_put_data')) {
816
+					require_once($sourcedir . '/Load.php');
817
+		}
771 818
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
772 819
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
773 820
 	}
@@ -776,28 +823,33 @@  discard block
 block discarded – undo
776 823
 
777 824
 	// Check the cache directory.
778 825
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
779
-	if (!file_exists($cachedir_temp))
780
-		@mkdir($cachedir_temp);
781
-	if (!file_exists($cachedir_temp))
782
-		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.');
783
-
784
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
785
-		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>.');
786
-	elseif (!isset($_GET['skiplang']))
826
+	if (!file_exists($cachedir_temp)) {
827
+			@mkdir($cachedir_temp);
828
+	}
829
+	if (!file_exists($cachedir_temp)) {
830
+			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.');
831
+	}
832
+
833
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
834
+			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>.');
835
+	} elseif (!isset($_GET['skiplang']))
787 836
 	{
788 837
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
789 838
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
790 839
 
791
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
792
-			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>]');
840
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
841
+					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>]');
842
+		}
793 843
 	}
794 844
 
795
-	if (!makeFilesWritable($writable_files))
796
-		return false;
845
+	if (!makeFilesWritable($writable_files)) {
846
+			return false;
847
+	}
797 848
 
798 849
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
799
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
800
-		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.');
850
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
851
+			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.');
852
+	}
801 853
 
802 854
 	// Upgrade the agreement.
803 855
 	elseif (isset($modSettings['agreement']))
@@ -808,8 +860,8 @@  discard block
 block discarded – undo
808 860
 	}
809 861
 
810 862
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
811
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
812
-		$upcontext['warning'] = '
863
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
864
+			$upcontext['warning'] = '
813 865
 			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>
814 866
 			<ul>
815 867
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -817,19 +869,23 @@  discard block
 block discarded – undo
817 869
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
818 870
 			</ul>
819 871
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
872
+	}
820 873
 
821 874
 	// Confirm mbstring is loaded...
822
-	if (!extension_loaded('mbstring'))
823
-		return throw_error($txt['install_no_mbstring']);
875
+	if (!extension_loaded('mbstring')) {
876
+			return throw_error($txt['install_no_mbstring']);
877
+	}
824 878
 
825 879
 	// Check for https stream support.
826 880
 	$supported_streams = stream_get_wrappers();
827
-	if (!in_array('https', $supported_streams))
828
-		$upcontext['custom_warning'] = $txt['install_no_https'];
881
+	if (!in_array('https', $supported_streams)) {
882
+			$upcontext['custom_warning'] = $txt['install_no_https'];
883
+	}
829 884
 
830 885
 	// Either we're logged in or we're going to present the login.
831
-	if (checkLogin())
832
-		return true;
886
+	if (checkLogin()) {
887
+			return true;
888
+	}
833 889
 
834 890
 	$upcontext += createToken('login');
835 891
 
@@ -843,15 +899,17 @@  discard block
 block discarded – undo
843 899
 	global $smcFunc, $db_type, $support_js;
844 900
 
845 901
 	// Don't bother if the security is disabled.
846
-	if ($disable_security)
847
-		return true;
902
+	if ($disable_security) {
903
+			return true;
904
+	}
848 905
 
849 906
 	// Are we trying to login?
850 907
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
851 908
 	{
852 909
 		// If we've disabled security pick a suitable name!
853
-		if (empty($_POST['user']))
854
-			$_POST['user'] = 'Administrator';
910
+		if (empty($_POST['user'])) {
911
+					$_POST['user'] = 'Administrator';
912
+		}
855 913
 
856 914
 		// Before 2.0 these column names were different!
857 915
 		$oldDB = false;
@@ -866,16 +924,17 @@  discard block
 block discarded – undo
866 924
 					'db_error_skip' => true,
867 925
 				)
868 926
 			);
869
-			if ($smcFunc['db_num_rows']($request) != 0)
870
-				$oldDB = true;
927
+			if ($smcFunc['db_num_rows']($request) != 0) {
928
+							$oldDB = true;
929
+			}
871 930
 			$smcFunc['db_free_result']($request);
872 931
 		}
873 932
 
874 933
 		// Get what we believe to be their details.
875 934
 		if (!$disable_security)
876 935
 		{
877
-			if ($oldDB)
878
-				$request = $smcFunc['db_query']('', '
936
+			if ($oldDB) {
937
+							$request = $smcFunc['db_query']('', '
879 938
 					SELECT id_member, memberName AS member_name, passwd, id_group,
880 939
 					additionalGroups AS additional_groups, lngfile
881 940
 					FROM {db_prefix}members
@@ -885,8 +944,8 @@  discard block
 block discarded – undo
885 944
 						'db_error_skip' => true,
886 945
 					)
887 946
 				);
888
-			else
889
-				$request = $smcFunc['db_query']('', '
947
+			} else {
948
+							$request = $smcFunc['db_query']('', '
890 949
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
891 950
 					FROM {db_prefix}members
892 951
 					WHERE member_name = {string:member_name}',
@@ -895,6 +954,7 @@  discard block
 block discarded – undo
895 954
 						'db_error_skip' => true,
896 955
 					)
897 956
 				);
957
+			}
898 958
 			if ($smcFunc['db_num_rows']($request) != 0)
899 959
 			{
900 960
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -902,16 +962,17 @@  discard block
 block discarded – undo
902 962
 				$groups = explode(',', $addGroups);
903 963
 				$groups[] = $id_group;
904 964
 
905
-				foreach ($groups as $k => $v)
906
-					$groups[$k] = (int) $v;
965
+				foreach ($groups as $k => $v) {
966
+									$groups[$k] = (int) $v;
967
+				}
907 968
 
908 969
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
909 970
 
910 971
 				// We don't use "-utf8" anymore...
911 972
 				$user_language = str_ireplace('-utf8', '', $user_language);
973
+			} else {
974
+							$upcontext['username_incorrect'] = true;
912 975
 			}
913
-			else
914
-				$upcontext['username_incorrect'] = true;
915 976
 			$smcFunc['db_free_result']($request);
916 977
 		}
917 978
 		$upcontext['username'] = $_POST['user'];
@@ -921,13 +982,14 @@  discard block
 block discarded – undo
921 982
 		{
922 983
 			$upcontext['upgrade_status']['js'] = 1;
923 984
 			$support_js = 1;
985
+		} else {
986
+					$support_js = 0;
924 987
 		}
925
-		else
926
-			$support_js = 0;
927 988
 
928 989
 		// Note down the version we are coming from.
929
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
930
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
990
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
991
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
992
+		}
931 993
 
932 994
 		// Didn't get anywhere?
933 995
 		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']))
@@ -961,15 +1023,15 @@  discard block
 block discarded – undo
961 1023
 							'db_error_skip' => true,
962 1024
 						)
963 1025
 					);
964
-					if ($smcFunc['db_num_rows']($request) == 0)
965
-						return throw_error('You need to be an admin to perform an upgrade!');
1026
+					if ($smcFunc['db_num_rows']($request) == 0) {
1027
+											return throw_error('You need to be an admin to perform an upgrade!');
1028
+					}
966 1029
 					$smcFunc['db_free_result']($request);
967 1030
 				}
968 1031
 
969 1032
 				$upcontext['user']['id'] = $id_member;
970 1033
 				$upcontext['user']['name'] = $name;
971
-			}
972
-			else
1034
+			} else
973 1035
 			{
974 1036
 				$upcontext['user']['id'] = 1;
975 1037
 				$upcontext['user']['name'] = 'Administrator';
@@ -985,11 +1047,11 @@  discard block
 block discarded – undo
985 1047
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
986 1048
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
987 1049
 
988
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
989
-					$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'] . '.';
990
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
991
-					$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'] . '.';
992
-				else
1050
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
1051
+									$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'] . '.';
1052
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
1053
+									$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'] . '.';
1054
+				} else
993 1055
 				{
994 1056
 					// Set this as the new language.
995 1057
 					$upcontext['language'] = $user_language;
@@ -1033,8 +1095,9 @@  discard block
 block discarded – undo
1033 1095
 	unset($member_columns);
1034 1096
 
1035 1097
 	// If we've not submitted then we're done.
1036
-	if (empty($_POST['upcont']))
1037
-		return false;
1098
+	if (empty($_POST['upcont'])) {
1099
+			return false;
1100
+	}
1038 1101
 
1039 1102
 	// Firstly, if they're enabling SM stat collection just do it.
1040 1103
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -1054,16 +1117,17 @@  discard block
 block discarded – undo
1054 1117
 				fwrite($fp, $out);
1055 1118
 
1056 1119
 				$return_data = '';
1057
-				while (!feof($fp))
1058
-					$return_data .= fgets($fp, 128);
1120
+				while (!feof($fp)) {
1121
+									$return_data .= fgets($fp, 128);
1122
+				}
1059 1123
 
1060 1124
 				fclose($fp);
1061 1125
 
1062 1126
 				// Get the unique site ID.
1063 1127
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1064 1128
 
1065
-				if (!empty($ID[1]))
1066
-					$smcFunc['db_insert']('replace',
1129
+				if (!empty($ID[1])) {
1130
+									$smcFunc['db_insert']('replace',
1067 1131
 						$db_prefix . 'settings',
1068 1132
 						array('variable' => 'string', 'value' => 'string'),
1069 1133
 						array(
@@ -1072,9 +1136,9 @@  discard block
 block discarded – undo
1072 1136
 						),
1073 1137
 						array('variable')
1074 1138
 					);
1139
+				}
1075 1140
 			}
1076
-		}
1077
-		else
1141
+		} else
1078 1142
 		{
1079 1143
 			$smcFunc['db_insert']('replace',
1080 1144
 				$db_prefix . 'settings',
@@ -1085,8 +1149,8 @@  discard block
 block discarded – undo
1085 1149
 		}
1086 1150
 	}
1087 1151
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1088
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1089
-		$smcFunc['db_query']('', '
1152
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1153
+			$smcFunc['db_query']('', '
1090 1154
 			DELETE FROM {db_prefix}settings
1091 1155
 			WHERE variable = {string:enable_sm_stats}',
1092 1156
 			array(
@@ -1094,6 +1158,7 @@  discard block
 block discarded – undo
1094 1158
 				'db_error_skip' => true,
1095 1159
 			)
1096 1160
 		);
1161
+	}
1097 1162
 
1098 1163
 	// Deleting old karma stuff?
1099 1164
 	if (!empty($_POST['delete_karma']))
@@ -1108,20 +1173,22 @@  discard block
 block discarded – undo
1108 1173
 		);
1109 1174
 
1110 1175
 		// Cleaning up old karma member settings.
1111
-		if ($upcontext['karma_installed']['good'])
1112
-			$smcFunc['db_query']('', '
1176
+		if ($upcontext['karma_installed']['good']) {
1177
+					$smcFunc['db_query']('', '
1113 1178
 				ALTER TABLE {db_prefix}members
1114 1179
 				DROP karma_good',
1115 1180
 				array()
1116 1181
 			);
1182
+		}
1117 1183
 
1118 1184
 		// Does karma bad was enable?
1119
-		if ($upcontext['karma_installed']['bad'])
1120
-			$smcFunc['db_query']('', '
1185
+		if ($upcontext['karma_installed']['bad']) {
1186
+					$smcFunc['db_query']('', '
1121 1187
 				ALTER TABLE {db_prefix}members
1122 1188
 				DROP karma_bad',
1123 1189
 				array()
1124 1190
 			);
1191
+		}
1125 1192
 
1126 1193
 		// Cleaning up old karma permissions.
1127 1194
 		$smcFunc['db_query']('', '
@@ -1139,32 +1206,37 @@  discard block
 block discarded – undo
1139 1206
 	}
1140 1207
 
1141 1208
 	// Emptying the error log?
1142
-	if (!empty($_POST['empty_error']))
1143
-		$smcFunc['db_query']('truncate_table', '
1209
+	if (!empty($_POST['empty_error'])) {
1210
+			$smcFunc['db_query']('truncate_table', '
1144 1211
 			TRUNCATE {db_prefix}log_errors',
1145 1212
 			array(
1146 1213
 			)
1147 1214
 		);
1215
+	}
1148 1216
 
1149 1217
 	$changes = array();
1150 1218
 
1151 1219
 	// Add proxy settings.
1152
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1153
-		$changes += array(
1220
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1221
+			$changes += array(
1154 1222
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1155 1223
 			'image_proxy_maxsize' => 5190,
1156 1224
 			'image_proxy_enabled' => 0,
1157 1225
 		);
1226
+	}
1158 1227
 
1159 1228
 	// If $boardurl reflects https, set force_ssl
1160
-	if (!function_exists('cache_put_data'))
1161
-		require_once($sourcedir . '/Load.php');
1162
-	if (stripos($boardurl, 'https://') !== false)
1163
-		updateSettings(array('force_ssl' => '1'));
1229
+	if (!function_exists('cache_put_data')) {
1230
+			require_once($sourcedir . '/Load.php');
1231
+	}
1232
+	if (stripos($boardurl, 'https://') !== false) {
1233
+			updateSettings(array('force_ssl' => '1'));
1234
+	}
1164 1235
 
1165 1236
 	// If we're overriding the language follow it through.
1166
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1167
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1237
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1238
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1239
+	}
1168 1240
 
1169 1241
 	if (!empty($_POST['maint']))
1170 1242
 	{
@@ -1176,26 +1248,29 @@  discard block
 block discarded – undo
1176 1248
 		{
1177 1249
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1178 1250
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1179
-		}
1180
-		else
1251
+		} else
1181 1252
 		{
1182 1253
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1183 1254
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1184 1255
 		}
1185 1256
 	}
1186 1257
 
1187
-	if ($command_line)
1188
-		echo ' * Updating Settings.php...';
1258
+	if ($command_line) {
1259
+			echo ' * Updating Settings.php...';
1260
+	}
1189 1261
 
1190 1262
 	// Fix some old paths.
1191
-	if (substr($boarddir, 0, 1) == '.')
1192
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1263
+	if (substr($boarddir, 0, 1) == '.') {
1264
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1265
+	}
1193 1266
 
1194
-	if (substr($sourcedir, 0, 1) == '.')
1195
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1267
+	if (substr($sourcedir, 0, 1) == '.') {
1268
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1269
+	}
1196 1270
 
1197
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1198
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1271
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1272
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1273
+	}
1199 1274
 
1200 1275
 	// If they have a "host:port" setup for the host, split that into separate values
1201 1276
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1206,32 +1281,36 @@  discard block
 block discarded – undo
1206 1281
 		$changes['db_server'] = '\'' . $db_server . '\'';
1207 1282
 
1208 1283
 		// Only set this if we're not using the default port
1209
-		if ($db_port != ini_get('mysqli.default_port'))
1210
-			$changes['db_port'] = (int) $db_port;
1211
-	}
1212
-	elseif (!empty($db_port))
1284
+		if ($db_port != ini_get('mysqli.default_port')) {
1285
+					$changes['db_port'] = (int) $db_port;
1286
+		}
1287
+	} elseif (!empty($db_port))
1213 1288
 	{
1214 1289
 		// If db_port is set and is the same as the default, set it to ''
1215 1290
 		if ($db_type == 'mysql')
1216 1291
 		{
1217
-			if ($db_port == ini_get('mysqli.default_port'))
1218
-				$changes['db_port'] = '\'\'';
1219
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1220
-				$changes['db_port'] = '\'\'';
1292
+			if ($db_port == ini_get('mysqli.default_port')) {
1293
+							$changes['db_port'] = '\'\'';
1294
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1295
+							$changes['db_port'] = '\'\'';
1296
+			}
1221 1297
 		}
1222 1298
 	}
1223 1299
 
1224 1300
 	// Maybe we haven't had this option yet?
1225
-	if (empty($packagesdir))
1226
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1301
+	if (empty($packagesdir)) {
1302
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1303
+	}
1227 1304
 
1228 1305
 	// Add support for $tasksdir var.
1229
-	if (empty($tasksdir))
1230
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1306
+	if (empty($tasksdir)) {
1307
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1308
+	}
1231 1309
 
1232 1310
 	// Make sure we fix the language as well.
1233
-	if (stristr($language, '-utf8'))
1234
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1311
+	if (stristr($language, '-utf8')) {
1312
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1313
+	}
1235 1314
 
1236 1315
 	// @todo Maybe change the cookie name if going to 1.1, too?
1237 1316
 
@@ -1242,8 +1321,9 @@  discard block
 block discarded – undo
1242 1321
 	// Tell Settings.php to store db_last_error.php in the cache
1243 1322
 	move_db_last_error_to_cachedir();
1244 1323
 
1245
-	if ($command_line)
1246
-		echo ' Successful.' . "\n";
1324
+	if ($command_line) {
1325
+			echo ' Successful.' . "\n";
1326
+	}
1247 1327
 
1248 1328
 	// Are we doing debug?
1249 1329
 	if (isset($_POST['debug']))
@@ -1253,8 +1333,9 @@  discard block
 block discarded – undo
1253 1333
 	}
1254 1334
 
1255 1335
 	// If we're not backing up then jump one.
1256
-	if (empty($_POST['backup']))
1257
-		$upcontext['current_step']++;
1336
+	if (empty($_POST['backup'])) {
1337
+			$upcontext['current_step']++;
1338
+	}
1258 1339
 
1259 1340
 	// If we've got here then let's proceed to the next step!
1260 1341
 	return true;
@@ -1269,8 +1350,9 @@  discard block
 block discarded – undo
1269 1350
 	$upcontext['page_title'] = $txt['backup_database'];
1270 1351
 
1271 1352
 	// Done it already - js wise?
1272
-	if (!empty($_POST['backup_done']))
1273
-		return true;
1353
+	if (!empty($_POST['backup_done'])) {
1354
+			return true;
1355
+	}
1274 1356
 
1275 1357
 	// Some useful stuff here.
1276 1358
 	db_extend();
@@ -1284,9 +1366,10 @@  discard block
 block discarded – undo
1284 1366
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1285 1367
 
1286 1368
 	$table_names = array();
1287
-	foreach ($tables as $table)
1288
-		if (substr($table, 0, 7) !== 'backup_')
1369
+	foreach ($tables as $table) {
1370
+			if (substr($table, 0, 7) !== 'backup_')
1289 1371
 			$table_names[] = $table;
1372
+	}
1290 1373
 
1291 1374
 	$upcontext['table_count'] = count($table_names);
1292 1375
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1296,12 +1379,14 @@  discard block
 block discarded – undo
1296 1379
 	$file_steps = $upcontext['table_count'];
1297 1380
 
1298 1381
 	// What ones have we already done?
1299
-	foreach ($table_names as $id => $table)
1300
-		if ($id < $_GET['substep'])
1382
+	foreach ($table_names as $id => $table) {
1383
+			if ($id < $_GET['substep'])
1301 1384
 			$upcontext['previous_tables'][] = $table;
1385
+	}
1302 1386
 
1303
-	if ($command_line)
1304
-		echo 'Backing Up Tables.';
1387
+	if ($command_line) {
1388
+			echo 'Backing Up Tables.';
1389
+	}
1305 1390
 
1306 1391
 	// If we don't support javascript we backup here.
1307 1392
 	if (!$support_js || isset($_GET['xml']))
@@ -1320,8 +1405,9 @@  discard block
 block discarded – undo
1320 1405
 			backupTable($table_names[$substep]);
1321 1406
 
1322 1407
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1323
-			if (isset($_GET['xml']))
1324
-				return upgradeExit();
1408
+			if (isset($_GET['xml'])) {
1409
+							return upgradeExit();
1410
+			}
1325 1411
 		}
1326 1412
 
1327 1413
 		if ($command_line)
@@ -1354,9 +1440,10 @@  discard block
 block discarded – undo
1354 1440
 
1355 1441
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1356 1442
 
1357
-	if ($command_line)
1358
-		echo ' done.';
1359
-}
1443
+	if ($command_line) {
1444
+			echo ' done.';
1445
+	}
1446
+	}
1360 1447
 
1361 1448
 // Step 2: Everything.
1362 1449
 function DatabaseChanges()
@@ -1365,8 +1452,9 @@  discard block
 block discarded – undo
1365 1452
 	global $upcontext, $support_js, $db_type;
1366 1453
 
1367 1454
 	// Have we just completed this?
1368
-	if (!empty($_POST['database_done']))
1369
-		return true;
1455
+	if (!empty($_POST['database_done'])) {
1456
+			return true;
1457
+	}
1370 1458
 
1371 1459
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1372 1460
 	$upcontext['page_title'] = $txt['database_changes'];
@@ -1381,15 +1469,16 @@  discard block
 block discarded – undo
1381 1469
 	);
1382 1470
 
1383 1471
 	// How many files are there in total?
1384
-	if (isset($_GET['filecount']))
1385
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1386
-	else
1472
+	if (isset($_GET['filecount'])) {
1473
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1474
+	} else
1387 1475
 	{
1388 1476
 		$upcontext['file_count'] = 0;
1389 1477
 		foreach ($files as $file)
1390 1478
 		{
1391
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1392
-				$upcontext['file_count']++;
1479
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1480
+							$upcontext['file_count']++;
1481
+			}
1393 1482
 		}
1394 1483
 	}
1395 1484
 
@@ -1399,9 +1488,9 @@  discard block
 block discarded – undo
1399 1488
 	$upcontext['cur_file_num'] = 0;
1400 1489
 	foreach ($files as $file)
1401 1490
 	{
1402
-		if ($did_not_do)
1403
-			$did_not_do--;
1404
-		else
1491
+		if ($did_not_do) {
1492
+					$did_not_do--;
1493
+		} else
1405 1494
 		{
1406 1495
 			$upcontext['cur_file_num']++;
1407 1496
 			$upcontext['cur_file_name'] = $file[0];
@@ -1428,12 +1517,13 @@  discard block
 block discarded – undo
1428 1517
 					// Flag to move on to the next.
1429 1518
 					$upcontext['completed_step'] = true;
1430 1519
 					// Did we complete the whole file?
1431
-					if ($nextFile)
1432
-						$upcontext['current_debug_item_num'] = -1;
1520
+					if ($nextFile) {
1521
+											$upcontext['current_debug_item_num'] = -1;
1522
+					}
1433 1523
 					return upgradeExit();
1524
+				} elseif ($support_js) {
1525
+									break;
1434 1526
 				}
1435
-				elseif ($support_js)
1436
-					break;
1437 1527
 			}
1438 1528
 			// Set the progress bar to be right as if we had - even if we hadn't...
1439 1529
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1459,8 +1549,9 @@  discard block
 block discarded – undo
1459 1549
 	global $user_info, $maintenance, $smcFunc, $db_type, $txt;
1460 1550
 
1461 1551
 	// Now it's nice to have some of the basic SMF source files.
1462
-	if (!isset($_GET['ssi']) && !$command_line)
1463
-		redirectLocation('&ssi=1');
1552
+	if (!isset($_GET['ssi']) && !$command_line) {
1553
+			redirectLocation('&ssi=1');
1554
+	}
1464 1555
 
1465 1556
 	$upcontext['sub_template'] = 'upgrade_complete';
1466 1557
 	$upcontext['page_title'] = $txt['upgrade_complete'];
@@ -1476,14 +1567,16 @@  discard block
 block discarded – undo
1476 1567
 	// Are we in maintenance mode?
1477 1568
 	if (isset($upcontext['user']['main']))
1478 1569
 	{
1479
-		if ($command_line)
1480
-			echo ' * ';
1570
+		if ($command_line) {
1571
+					echo ' * ';
1572
+		}
1481 1573
 		$upcontext['removed_maintenance'] = true;
1482 1574
 		$changes['maintenance'] = $upcontext['user']['main'];
1483 1575
 	}
1484 1576
 	// Otherwise if somehow we are in 2 let's go to 1.
1485
-	elseif (!empty($maintenance) && $maintenance == 2)
1486
-		$changes['maintenance'] = 1;
1577
+	elseif (!empty($maintenance) && $maintenance == 2) {
1578
+			$changes['maintenance'] = 1;
1579
+	}
1487 1580
 
1488 1581
 	// Wipe this out...
1489 1582
 	$upcontext['user'] = array();
@@ -1498,9 +1591,9 @@  discard block
 block discarded – undo
1498 1591
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1499 1592
 
1500 1593
 	// Now is the perfect time to fetch the SM files.
1501
-	if ($command_line)
1502
-		cli_scheduled_fetchSMfiles();
1503
-	else
1594
+	if ($command_line) {
1595
+			cli_scheduled_fetchSMfiles();
1596
+	} else
1504 1597
 	{
1505 1598
 		require_once($sourcedir . '/ScheduledTasks.php');
1506 1599
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1508,8 +1601,9 @@  discard block
 block discarded – undo
1508 1601
 	}
1509 1602
 
1510 1603
 	// Log what we've done.
1511
-	if (empty($user_info['id']))
1512
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1604
+	if (empty($user_info['id'])) {
1605
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1606
+	}
1513 1607
 
1514 1608
 	// Log the action manually, so CLI still works.
1515 1609
 	$smcFunc['db_insert']('',
@@ -1528,8 +1622,9 @@  discard block
 block discarded – undo
1528 1622
 
1529 1623
 	// Save the current database version.
1530 1624
 	$server_version = $smcFunc['db_server_info']();
1531
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1532
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1625
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1626
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1627
+	}
1533 1628
 
1534 1629
 	if ($command_line)
1535 1630
 	{
@@ -1541,8 +1636,9 @@  discard block
 block discarded – undo
1541 1636
 
1542 1637
 	// Make sure it says we're done.
1543 1638
 	$upcontext['overall_percent'] = 100;
1544
-	if (isset($upcontext['step_progress']))
1545
-		unset($upcontext['step_progress']);
1639
+	if (isset($upcontext['step_progress'])) {
1640
+			unset($upcontext['step_progress']);
1641
+	}
1546 1642
 
1547 1643
 	$_GET['substep'] = 0;
1548 1644
 	return false;
@@ -1553,8 +1649,9 @@  discard block
 block discarded – undo
1553 1649
 {
1554 1650
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1555 1651
 
1556
-	if (empty($modSettings['time_format']))
1557
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1652
+	if (empty($modSettings['time_format'])) {
1653
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1654
+	}
1558 1655
 
1559 1656
 	// What files do we want to get
1560 1657
 	$request = $smcFunc['db_query']('', '
@@ -1588,8 +1685,9 @@  discard block
 block discarded – undo
1588 1685
 		$file_data = fetch_web_data($url);
1589 1686
 
1590 1687
 		// If we got an error - give up - the site might be down.
1591
-		if ($file_data === false)
1592
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1688
+		if ($file_data === false) {
1689
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1690
+		}
1593 1691
 
1594 1692
 		// Save the file to the database.
1595 1693
 		$smcFunc['db_query']('substring', '
@@ -1631,8 +1729,9 @@  discard block
 block discarded – undo
1631 1729
 	$themeData = array();
1632 1730
 	foreach ($values as $variable => $value)
1633 1731
 	{
1634
-		if (!isset($value) || $value === null)
1635
-			$value = 0;
1732
+		if (!isset($value) || $value === null) {
1733
+					$value = 0;
1734
+		}
1636 1735
 
1637 1736
 		$themeData[] = array(0, 1, $variable, $value);
1638 1737
 	}
@@ -1661,8 +1760,9 @@  discard block
 block discarded – undo
1661 1760
 
1662 1761
 	foreach ($values as $variable => $value)
1663 1762
 	{
1664
-		if (empty($modSettings[$value[0]]))
1665
-			continue;
1763
+		if (empty($modSettings[$value[0]])) {
1764
+					continue;
1765
+		}
1666 1766
 
1667 1767
 		$smcFunc['db_query']('', '
1668 1768
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1748,19 +1848,21 @@  discard block
 block discarded – undo
1748 1848
 	set_error_handler(
1749 1849
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1750 1850
 		{
1751
-			if ($support_js)
1752
-				return true;
1753
-			else
1754
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1851
+			if ($support_js) {
1852
+							return true;
1853
+			} else {
1854
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1855
+			}
1755 1856
 		}
1756 1857
 	);
1757 1858
 
1758 1859
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1759 1860
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1760
-	if ($db_type == 'mysql')
1761
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1762
-	else
1763
-		$db_collation = '';
1861
+	if ($db_type == 'mysql') {
1862
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1863
+	} else {
1864
+			$db_collation = '';
1865
+	}
1764 1866
 
1765 1867
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1766 1868
 
@@ -1772,8 +1874,9 @@  discard block
 block discarded – undo
1772 1874
 	$last_step = '';
1773 1875
 
1774 1876
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1775
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1776
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1877
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1878
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1879
+	}
1777 1880
 
1778 1881
 	// Count the total number of steps within this file - for progress.
1779 1882
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1793,15 +1896,18 @@  discard block
 block discarded – undo
1793 1896
 		$do_current = $substep >= $_GET['substep'];
1794 1897
 
1795 1898
 		// Get rid of any comments in the beginning of the line...
1796
-		if (substr(trim($line), 0, 2) === '/*')
1797
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1899
+		if (substr(trim($line), 0, 2) === '/*') {
1900
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1901
+		}
1798 1902
 
1799 1903
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1800
-		if ($is_debug && !$support_js && $command_line)
1801
-			flush();
1904
+		if ($is_debug && !$support_js && $command_line) {
1905
+					flush();
1906
+		}
1802 1907
 
1803
-		if (trim($line) === '')
1804
-			continue;
1908
+		if (trim($line) === '') {
1909
+					continue;
1910
+		}
1805 1911
 
1806 1912
 		if (trim(substr($line, 0, 3)) === '---')
1807 1913
 		{
@@ -1811,8 +1917,9 @@  discard block
 block discarded – undo
1811 1917
 			if (trim($current_data) != '' && $type !== '}')
1812 1918
 			{
1813 1919
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1814
-				if ($command_line)
1815
-					echo $upcontext['error_message'];
1920
+				if ($command_line) {
1921
+									echo $upcontext['error_message'];
1922
+				}
1816 1923
 			}
1817 1924
 
1818 1925
 			if ($type == ' ')
@@ -1830,17 +1937,18 @@  discard block
 block discarded – undo
1830 1937
 				if ($do_current)
1831 1938
 				{
1832 1939
 					$upcontext['actioned_items'][] = $last_step;
1833
-					if ($command_line)
1834
-						echo ' * ';
1940
+					if ($command_line) {
1941
+											echo ' * ';
1942
+					}
1835 1943
 				}
1836
-			}
1837
-			elseif ($type == '#')
1944
+			} elseif ($type == '#')
1838 1945
 			{
1839 1946
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1840 1947
 
1841 1948
 				$upcontext['current_debug_item_num']++;
1842
-				if (trim($line) != '---#')
1843
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1949
+				if (trim($line) != '---#') {
1950
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1951
+				}
1844 1952
 
1845 1953
 				// Have we already done something?
1846 1954
 				if (isset($_GET['xml']) && $done_something)
@@ -1851,34 +1959,36 @@  discard block
 block discarded – undo
1851 1959
 
1852 1960
 				if ($do_current)
1853 1961
 				{
1854
-					if (trim($line) == '---#' && $command_line)
1855
-						echo ' done.', $endl;
1856
-					elseif ($command_line)
1857
-						echo ' +++ ', rtrim(substr($line, 4));
1858
-					elseif (trim($line) != '---#')
1962
+					if (trim($line) == '---#' && $command_line) {
1963
+											echo ' done.', $endl;
1964
+					} elseif ($command_line) {
1965
+											echo ' +++ ', rtrim(substr($line, 4));
1966
+					} elseif (trim($line) != '---#')
1859 1967
 					{
1860
-						if ($is_debug)
1861
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1968
+						if ($is_debug) {
1969
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1970
+						}
1862 1971
 					}
1863 1972
 				}
1864 1973
 
1865 1974
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1866 1975
 				{
1867
-					if ($command_line)
1868
-						echo ' * ';
1869
-					else
1870
-						$upcontext['actioned_items'][] = $last_step;
1976
+					if ($command_line) {
1977
+											echo ' * ';
1978
+					} else {
1979
+											$upcontext['actioned_items'][] = $last_step;
1980
+					}
1871 1981
 				}
1872 1982
 
1873 1983
 				// Small step - only if we're actually doing stuff.
1874
-				if ($do_current)
1875
-					nextSubstep(++$substep);
1876
-				else
1877
-					$substep++;
1878
-			}
1879
-			elseif ($type == '{')
1880
-				$current_type = 'code';
1881
-			elseif ($type == '}')
1984
+				if ($do_current) {
1985
+									nextSubstep(++$substep);
1986
+				} else {
1987
+									$substep++;
1988
+				}
1989
+			} elseif ($type == '{') {
1990
+							$current_type = 'code';
1991
+			} elseif ($type == '}')
1882 1992
 			{
1883 1993
 				$current_type = 'sql';
1884 1994
 
@@ -1891,8 +2001,9 @@  discard block
 block discarded – undo
1891 2001
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1892 2002
 				{
1893 2003
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1894
-					if ($command_line)
1895
-						echo $upcontext['error_message'];
2004
+					if ($command_line) {
2005
+											echo $upcontext['error_message'];
2006
+					}
1896 2007
 				}
1897 2008
 
1898 2009
 				// Done with code!
@@ -1972,8 +2083,9 @@  discard block
 block discarded – undo
1972 2083
 	$db_unbuffered = false;
1973 2084
 
1974 2085
 	// Failure?!
1975
-	if ($result !== false)
1976
-		return $result;
2086
+	if ($result !== false) {
2087
+			return $result;
2088
+	}
1977 2089
 
1978 2090
 	$db_error_message = $smcFunc['db_error']($db_connection);
1979 2091
 	// If MySQL we do something more clever.
@@ -2001,54 +2113,61 @@  discard block
 block discarded – undo
2001 2113
 			{
2002 2114
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
2003 2115
 				$result = mysqli_query($db_connection, $string);
2004
-				if ($result !== false)
2005
-					return $result;
2116
+				if ($result !== false) {
2117
+									return $result;
2118
+				}
2006 2119
 			}
2007
-		}
2008
-		elseif ($mysqli_errno == 2013)
2120
+		} elseif ($mysqli_errno == 2013)
2009 2121
 		{
2010 2122
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
2011 2123
 			mysqli_select_db($db_connection, $db_name);
2012 2124
 			if ($db_connection)
2013 2125
 			{
2014 2126
 				$result = mysqli_query($db_connection, $string);
2015
-				if ($result !== false)
2016
-					return $result;
2127
+				if ($result !== false) {
2128
+									return $result;
2129
+				}
2017 2130
 			}
2018 2131
 		}
2019 2132
 		// Duplicate column name... should be okay ;).
2020
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
2021
-			return false;
2133
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2134
+					return false;
2135
+		}
2022 2136
 		// Duplicate insert... make sure it's the proper type of query ;).
2023
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
2024
-			return false;
2137
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2138
+					return false;
2139
+		}
2025 2140
 		// Creating an index on a non-existent column.
2026
-		elseif ($mysqli_errno == 1072)
2027
-			return false;
2028
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
2029
-			return false;
2141
+		elseif ($mysqli_errno == 1072) {
2142
+					return false;
2143
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2144
+					return false;
2145
+		}
2030 2146
 	}
2031 2147
 	// If a table already exists don't go potty.
2032 2148
 	else
2033 2149
 	{
2034 2150
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
2035 2151
 		{
2036
-			if (strpos($db_error_message, 'exist') !== false)
2037
-				return true;
2038
-		}
2039
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2152
+			if (strpos($db_error_message, 'exist') !== false) {
2153
+							return true;
2154
+			}
2155
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
2040 2156
 		{
2041
-			if (strpos($db_error_message, 'duplicate') !== false)
2042
-				return true;
2157
+			if (strpos($db_error_message, 'duplicate') !== false) {
2158
+							return true;
2159
+			}
2043 2160
 		}
2044 2161
 	}
2045 2162
 
2046 2163
 	// Get the query string so we pass everything.
2047 2164
 	$query_string = '';
2048
-	foreach ($_GET as $k => $v)
2049
-		$query_string .= ';' . $k . '=' . $v;
2050
-	if (strlen($query_string) != 0)
2051
-		$query_string = '?' . substr($query_string, 1);
2165
+	foreach ($_GET as $k => $v) {
2166
+			$query_string .= ';' . $k . '=' . $v;
2167
+	}
2168
+	if (strlen($query_string) != 0) {
2169
+			$query_string = '?' . substr($query_string, 1);
2170
+	}
2052 2171
 
2053 2172
 	if ($command_line)
2054 2173
 	{
@@ -2103,16 +2222,18 @@  discard block
 block discarded – undo
2103 2222
 			{
2104 2223
 				$found |= 1;
2105 2224
 				// Do some checks on the data if we have it set.
2106
-				if (isset($change['col_type']))
2107
-					$found &= $change['col_type'] === $column['type'];
2108
-				if (isset($change['null_allowed']))
2109
-					$found &= $column['null'] == $change['null_allowed'];
2110
-				if (isset($change['default']))
2111
-					$found &= $change['default'] === $column['default'];
2225
+				if (isset($change['col_type'])) {
2226
+									$found &= $change['col_type'] === $column['type'];
2227
+				}
2228
+				if (isset($change['null_allowed'])) {
2229
+									$found &= $column['null'] == $change['null_allowed'];
2230
+				}
2231
+				if (isset($change['default'])) {
2232
+									$found &= $change['default'] === $column['default'];
2233
+				}
2112 2234
 			}
2113 2235
 		}
2114
-	}
2115
-	elseif ($change['type'] === 'index')
2236
+	} elseif ($change['type'] === 'index')
2116 2237
 	{
2117 2238
 		$request = upgrade_query('
2118 2239
 			SHOW INDEX
@@ -2121,9 +2242,10 @@  discard block
 block discarded – undo
2121 2242
 		{
2122 2243
 			$cur_index = array();
2123 2244
 
2124
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2125
-				if ($row['Key_name'] === $change['name'])
2245
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2246
+							if ($row['Key_name'] === $change['name'])
2126 2247
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2248
+			}
2127 2249
 
2128 2250
 			ksort($cur_index, SORT_NUMERIC);
2129 2251
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2133,14 +2255,17 @@  discard block
 block discarded – undo
2133 2255
 	}
2134 2256
 
2135 2257
 	// If we're trying to add and it's added, we're done.
2136
-	if ($found && in_array($change['method'], array('add', 'change')))
2137
-		return true;
2258
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2259
+			return true;
2260
+	}
2138 2261
 	// Otherwise if we're removing and it wasn't found we're also done.
2139
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2140
-		return true;
2262
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2263
+			return true;
2264
+	}
2141 2265
 	// Otherwise is it just a test?
2142
-	elseif ($is_test)
2143
-		return false;
2266
+	elseif ($is_test) {
2267
+			return false;
2268
+	}
2144 2269
 
2145 2270
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2146 2271
 	$running = false;
@@ -2151,8 +2276,9 @@  discard block
 block discarded – undo
2151 2276
 			SHOW FULL PROCESSLIST');
2152 2277
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2153 2278
 		{
2154
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2155
-				$found = true;
2279
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2280
+							$found = true;
2281
+			}
2156 2282
 		}
2157 2283
 
2158 2284
 		// Can't find it? Then we need to run it fools!
@@ -2164,8 +2290,9 @@  discard block
 block discarded – undo
2164 2290
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2165 2291
 				' . $change['text'], true) !== false;
2166 2292
 
2167
-			if (!$success)
2168
-				return false;
2293
+			if (!$success) {
2294
+							return false;
2295
+			}
2169 2296
 
2170 2297
 			// Return
2171 2298
 			$running = true;
@@ -2207,8 +2334,9 @@  discard block
 block discarded – undo
2207 2334
 			'db_error_skip' => true,
2208 2335
 		)
2209 2336
 	);
2210
-	if ($smcFunc['db_num_rows']($request) === 0)
2211
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2337
+	if ($smcFunc['db_num_rows']($request) === 0) {
2338
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2339
+	}
2212 2340
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2213 2341
 	$smcFunc['db_free_result']($request);
2214 2342
 
@@ -2230,18 +2358,19 @@  discard block
 block discarded – undo
2230 2358
 			)
2231 2359
 		);
2232 2360
 		// No results? Just forget it all together.
2233
-		if ($smcFunc['db_num_rows']($request) === 0)
2234
-			unset($table_row['Collation']);
2235
-		else
2236
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2361
+		if ($smcFunc['db_num_rows']($request) === 0) {
2362
+					unset($table_row['Collation']);
2363
+		} else {
2364
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2365
+		}
2237 2366
 		$smcFunc['db_free_result']($request);
2238 2367
 	}
2239 2368
 
2240 2369
 	if ($column_fix)
2241 2370
 	{
2242 2371
 		// Make sure there are no NULL's left.
2243
-		if ($null_fix)
2244
-			$smcFunc['db_query']('', '
2372
+		if ($null_fix) {
2373
+					$smcFunc['db_query']('', '
2245 2374
 				UPDATE {db_prefix}' . $change['table'] . '
2246 2375
 				SET ' . $change['column'] . ' = {string:default}
2247 2376
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2250,6 +2379,7 @@  discard block
 block discarded – undo
2250 2379
 					'db_error_skip' => true,
2251 2380
 				)
2252 2381
 			);
2382
+		}
2253 2383
 
2254 2384
 		// Do the actual alteration.
2255 2385
 		$smcFunc['db_query']('', '
@@ -2278,8 +2408,9 @@  discard block
 block discarded – undo
2278 2408
 	}
2279 2409
 
2280 2410
 	// Not a column we need to check on?
2281
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2282
-		return;
2411
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2412
+			return;
2413
+	}
2283 2414
 
2284 2415
 	// Break it up you (six|seven).
2285 2416
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2298,13 +2429,13 @@  discard block
 block discarded – undo
2298 2429
 				'new_name' => $temp[2],
2299 2430
 		));
2300 2431
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2301
-		if ($smcFunc['db_num_rows'] != 1)
2302
-			return;
2432
+		if ($smcFunc['db_num_rows'] != 1) {
2433
+					return;
2434
+		}
2303 2435
 
2304 2436
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2305 2437
 		$smcFunc['db_free_result']($request);
2306
-	}
2307
-	else
2438
+	} else
2308 2439
 	{
2309 2440
 		// Do this the old fashion, sure method way.
2310 2441
 		$request = $smcFunc['db_query']('', '
@@ -2315,21 +2446,24 @@  discard block
 block discarded – undo
2315 2446
 		));
2316 2447
 		// Mayday!
2317 2448
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2318
-		if ($smcFunc['db_num_rows'] == 0)
2319
-			return;
2449
+		if ($smcFunc['db_num_rows'] == 0) {
2450
+					return;
2451
+		}
2320 2452
 
2321 2453
 		// Oh where, oh where has my little field gone. Oh where can it be...
2322
-		while ($row = $smcFunc['db_query']($request))
2323
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2454
+		while ($row = $smcFunc['db_query']($request)) {
2455
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2324 2456
 			{
2325 2457
 				$current_type = $row['Type'];
2458
+		}
2326 2459
 				break;
2327 2460
 			}
2328 2461
 	}
2329 2462
 
2330 2463
 	// If this doesn't match, the column may of been altered for a reason.
2331
-	if (trim($current_type) != trim($temp[3]))
2332
-		$temp[3] = $current_type;
2464
+	if (trim($current_type) != trim($temp[3])) {
2465
+			$temp[3] = $current_type;
2466
+	}
2333 2467
 
2334 2468
 	// Piece this back together.
2335 2469
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2341,8 +2475,9 @@  discard block
 block discarded – undo
2341 2475
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2342 2476
 	global $step_progress, $is_debug, $upcontext;
2343 2477
 
2344
-	if ($_GET['substep'] < $substep)
2345
-		$_GET['substep'] = $substep;
2478
+	if ($_GET['substep'] < $substep) {
2479
+			$_GET['substep'] = $substep;
2480
+	}
2346 2481
 
2347 2482
 	if ($command_line)
2348 2483
 	{
@@ -2355,29 +2490,33 @@  discard block
 block discarded – undo
2355 2490
 	}
2356 2491
 
2357 2492
 	@set_time_limit(300);
2358
-	if (function_exists('apache_reset_timeout'))
2359
-		@apache_reset_timeout();
2493
+	if (function_exists('apache_reset_timeout')) {
2494
+			@apache_reset_timeout();
2495
+	}
2360 2496
 
2361
-	if (time() - $start_time <= $timeLimitThreshold)
2362
-		return;
2497
+	if (time() - $start_time <= $timeLimitThreshold) {
2498
+			return;
2499
+	}
2363 2500
 
2364 2501
 	// Do we have some custom step progress stuff?
2365 2502
 	if (!empty($step_progress))
2366 2503
 	{
2367 2504
 		$upcontext['substep_progress'] = 0;
2368 2505
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2369
-		if ($step_progress['current'] > $step_progress['total'])
2370
-			$upcontext['substep_progress'] = 99.9;
2371
-		else
2372
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2506
+		if ($step_progress['current'] > $step_progress['total']) {
2507
+					$upcontext['substep_progress'] = 99.9;
2508
+		} else {
2509
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2510
+		}
2373 2511
 
2374 2512
 		// Make it nicely rounded.
2375 2513
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2376 2514
 	}
2377 2515
 
2378 2516
 	// If this is XML we just exit right away!
2379
-	if (isset($_GET['xml']))
2380
-		return upgradeExit();
2517
+	if (isset($_GET['xml'])) {
2518
+			return upgradeExit();
2519
+	}
2381 2520
 
2382 2521
 	// We're going to pause after this!
2383 2522
 	$upcontext['pause'] = true;
@@ -2385,13 +2524,15 @@  discard block
 block discarded – undo
2385 2524
 	$upcontext['query_string'] = '';
2386 2525
 	foreach ($_GET as $k => $v)
2387 2526
 	{
2388
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2389
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2527
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2528
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2529
+		}
2390 2530
 	}
2391 2531
 
2392 2532
 	// Custom warning?
2393
-	if (!empty($custom_warning))
2394
-		$upcontext['custom_warning'] = $custom_warning;
2533
+	if (!empty($custom_warning)) {
2534
+			$upcontext['custom_warning'] = $custom_warning;
2535
+	}
2395 2536
 
2396 2537
 	upgradeExit();
2397 2538
 }
@@ -2406,25 +2547,26 @@  discard block
 block discarded – undo
2406 2547
 	ob_implicit_flush(true);
2407 2548
 	@set_time_limit(600);
2408 2549
 
2409
-	if (!isset($_SERVER['argv']))
2410
-		$_SERVER['argv'] = array();
2550
+	if (!isset($_SERVER['argv'])) {
2551
+			$_SERVER['argv'] = array();
2552
+	}
2411 2553
 	$_GET['maint'] = 1;
2412 2554
 
2413 2555
 	foreach ($_SERVER['argv'] as $i => $arg)
2414 2556
 	{
2415
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2416
-			$_GET['lang'] = $match[1];
2417
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2418
-			continue;
2419
-		elseif ($arg == '--no-maintenance')
2420
-			$_GET['maint'] = 0;
2421
-		elseif ($arg == '--debug')
2422
-			$is_debug = true;
2423
-		elseif ($arg == '--backup')
2424
-			$_POST['backup'] = 1;
2425
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2426
-			$_GET['conv'] = 1;
2427
-		elseif ($i != 0)
2557
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2558
+					$_GET['lang'] = $match[1];
2559
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2560
+					continue;
2561
+		} elseif ($arg == '--no-maintenance') {
2562
+					$_GET['maint'] = 0;
2563
+		} elseif ($arg == '--debug') {
2564
+					$is_debug = true;
2565
+		} elseif ($arg == '--backup') {
2566
+					$_POST['backup'] = 1;
2567
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2568
+					$_GET['conv'] = 1;
2569
+		} elseif ($i != 0)
2428 2570
 		{
2429 2571
 			echo 'SMF Command-line Upgrader
2430 2572
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2438,10 +2580,12 @@  discard block
 block discarded – undo
2438 2580
 		}
2439 2581
 	}
2440 2582
 
2441
-	if (!php_version_check())
2442
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2443
-	if (!db_version_check())
2444
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2583
+	if (!php_version_check()) {
2584
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2585
+	}
2586
+	if (!db_version_check()) {
2587
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2588
+	}
2445 2589
 
2446 2590
 	// Do some checks to make sure they have proper privileges
2447 2591
 	db_extend('packages');
@@ -2456,34 +2600,39 @@  discard block
 block discarded – undo
2456 2600
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2457 2601
 
2458 2602
 	// Sorry... we need CREATE, ALTER and DROP
2459
-	if (!$create || !$alter || !$drop)
2460
-		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);
2603
+	if (!$create || !$alter || !$drop) {
2604
+			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);
2605
+	}
2461 2606
 
2462 2607
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2463 2608
 		&& @file_exists($sourcedir . '/QueryString.php')
2464 2609
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2465
-	if (!$check && !isset($modSettings['smfVersion']))
2466
-		print_error('Error: Some files are missing or out-of-date.', true);
2610
+	if (!$check && !isset($modSettings['smfVersion'])) {
2611
+			print_error('Error: Some files are missing or out-of-date.', true);
2612
+	}
2467 2613
 
2468 2614
 	// Do a quick version spot check.
2469 2615
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2470 2616
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2471
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2472
-		print_error('Error: Some files have not yet been updated properly.');
2617
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2618
+			print_error('Error: Some files have not yet been updated properly.');
2619
+	}
2473 2620
 
2474 2621
 	// Make sure Settings.php is writable.
2475 2622
 	quickFileWritable($boarddir . '/Settings.php');
2476
-	if (!is_writable($boarddir . '/Settings.php'))
2477
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2623
+	if (!is_writable($boarddir . '/Settings.php')) {
2624
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2625
+	}
2478 2626
 
2479 2627
 	// Make sure Settings_bak.php is writable.
2480 2628
 	quickFileWritable($boarddir . '/Settings_bak.php');
2481
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2482
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2629
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2630
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2631
+	}
2483 2632
 
2484
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2485
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2486
-	elseif (isset($modSettings['agreement']))
2633
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2634
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2635
+	} elseif (isset($modSettings['agreement']))
2487 2636
 	{
2488 2637
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2489 2638
 		fwrite($fp, $modSettings['agreement']);
@@ -2493,36 +2642,42 @@  discard block
 block discarded – undo
2493 2642
 	// Make sure Themes is writable.
2494 2643
 	quickFileWritable($modSettings['theme_dir']);
2495 2644
 
2496
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2497
-		print_error('Error: Unable to obtain write access to "Themes".');
2645
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2646
+			print_error('Error: Unable to obtain write access to "Themes".');
2647
+	}
2498 2648
 
2499 2649
 	// Make sure cache directory exists and is writable!
2500 2650
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2501
-	if (!file_exists($cachedir_temp))
2502
-		@mkdir($cachedir_temp);
2651
+	if (!file_exists($cachedir_temp)) {
2652
+			@mkdir($cachedir_temp);
2653
+	}
2503 2654
 
2504 2655
 	// Make sure the cache temp dir is writable.
2505 2656
 	quickFileWritable($cachedir_temp);
2506 2657
 
2507
-	if (!is_writable($cachedir_temp))
2508
-		print_error('Error: Unable to obtain write access to "cache".', true);
2658
+	if (!is_writable($cachedir_temp)) {
2659
+			print_error('Error: Unable to obtain write access to "cache".', true);
2660
+	}
2509 2661
 
2510 2662
 	// Make sure db_last_error.php is writable.
2511 2663
 	quickFileWritable($cachedir_temp . '/db_last_error.php');
2512
-	if (!is_writable($cachedir_temp . '/db_last_error.php'))
2513
-		print_error('Error: Unable to obtain write access to "db_last_error.php".');
2664
+	if (!is_writable($cachedir_temp . '/db_last_error.php')) {
2665
+			print_error('Error: Unable to obtain write access to "db_last_error.php".');
2666
+	}
2514 2667
 
2515
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2516
-		print_error('Error: Unable to find language files!', true);
2517
-	else
2668
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2669
+			print_error('Error: Unable to find language files!', true);
2670
+	} else
2518 2671
 	{
2519 2672
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2520 2673
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2521 2674
 
2522
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2523
-			print_error('Error: Language files out of date.', true);
2524
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2525
-			print_error('Error: Install language is missing for selected language.', true);
2675
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2676
+					print_error('Error: Language files out of date.', true);
2677
+		}
2678
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2679
+					print_error('Error: Install language is missing for selected language.', true);
2680
+		}
2526 2681
 
2527 2682
 		// Otherwise include it!
2528 2683
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2542,8 +2697,9 @@  discard block
 block discarded – undo
2542 2697
 	global $db_prefix, $db_type, $command_line, $support_js, $txt;
2543 2698
 
2544 2699
 	// Done it already?
2545
-	if (!empty($_POST['utf8_done']))
2546
-		return true;
2700
+	if (!empty($_POST['utf8_done'])) {
2701
+			return true;
2702
+	}
2547 2703
 
2548 2704
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2549 2705
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2556,8 +2712,7 @@  discard block
 block discarded – undo
2556 2712
 		);
2557 2713
 
2558 2714
 		return true;
2559
-	}
2560
-	else
2715
+	} else
2561 2716
 	{
2562 2717
 		$upcontext['page_title'] = $txt['converting_utf8'];
2563 2718
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2601,8 +2756,9 @@  discard block
 block discarded – undo
2601 2756
 			)
2602 2757
 		);
2603 2758
 		$db_charsets = array();
2604
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2605
-			$db_charsets[] = $row['Charset'];
2759
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2760
+					$db_charsets[] = $row['Charset'];
2761
+		}
2606 2762
 
2607 2763
 		$smcFunc['db_free_result']($request);
2608 2764
 
@@ -2638,13 +2794,15 @@  discard block
 block discarded – undo
2638 2794
 		// If there's a fulltext index, we need to drop it first...
2639 2795
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2640 2796
 		{
2641
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2642
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2797
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2798
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2643 2799
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2800
+			}
2644 2801
 			$smcFunc['db_free_result']($request);
2645 2802
 
2646
-			if (isset($upcontext['fulltext_index']))
2647
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2803
+			if (isset($upcontext['fulltext_index'])) {
2804
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2805
+			}
2648 2806
 		}
2649 2807
 
2650 2808
 		// Drop it and make a note...
@@ -2834,8 +2992,9 @@  discard block
 block discarded – undo
2834 2992
 			$replace = '%field%';
2835 2993
 
2836 2994
 			// Build a huge REPLACE statement...
2837
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2838
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2995
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2996
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2997
+			}
2839 2998
 		}
2840 2999
 
2841 3000
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2845,9 +3004,10 @@  discard block
 block discarded – undo
2845 3004
 		$upcontext['table_count'] = count($queryTables);
2846 3005
 
2847 3006
 		// What ones have we already done?
2848
-		foreach ($queryTables as $id => $table)
2849
-			if ($id < $_GET['substep'])
3007
+		foreach ($queryTables as $id => $table) {
3008
+					if ($id < $_GET['substep'])
2850 3009
 				$upcontext['previous_tables'][] = $table;
3010
+		}
2851 3011
 
2852 3012
 		$upcontext['cur_table_num'] = $_GET['substep'];
2853 3013
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2884,8 +3044,9 @@  discard block
 block discarded – undo
2884 3044
 			nextSubstep($substep);
2885 3045
 
2886 3046
 			// Just to make sure it doesn't time out.
2887
-			if (function_exists('apache_reset_timeout'))
2888
-				@apache_reset_timeout();
3047
+			if (function_exists('apache_reset_timeout')) {
3048
+							@apache_reset_timeout();
3049
+			}
2889 3050
 
2890 3051
 			$table_charsets = array();
2891 3052
 
@@ -2908,8 +3069,9 @@  discard block
 block discarded – undo
2908 3069
 
2909 3070
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2910 3071
 						if ($charset != 'utf8') {
2911
-							if (!isset($table_charsets[$charset]))
2912
-								$table_charsets[$charset] = array();
3072
+							if (!isset($table_charsets[$charset])) {
3073
+															$table_charsets[$charset] = array();
3074
+							}
2913 3075
 
2914 3076
 							$table_charsets[$charset][] = $column_info;
2915 3077
 						}
@@ -2950,10 +3112,11 @@  discard block
 block discarded – undo
2950 3112
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2951 3113
 				{
2952 3114
 					$update = '';
2953
-					foreach ($table_charsets as $charset => $columns)
2954
-						foreach ($columns as $column)
3115
+					foreach ($table_charsets as $charset => $columns) {
3116
+											foreach ($columns as $column)
2955 3117
 							$update .= '
2956 3118
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3119
+					}
2957 3120
 
2958 3121
 					$smcFunc['db_query']('', '
2959 3122
 						UPDATE {raw:table_name}
@@ -2978,8 +3141,9 @@  discard block
 block discarded – undo
2978 3141
 			// Now do the actual conversion (if still needed).
2979 3142
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2980 3143
 			{
2981
-				if ($command_line)
2982
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3144
+				if ($command_line) {
3145
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3146
+				}
2983 3147
 
2984 3148
 				$smcFunc['db_query']('', '
2985 3149
 					ALTER TABLE {raw:table_name}
@@ -2989,12 +3153,14 @@  discard block
 block discarded – undo
2989 3153
 					)
2990 3154
 				);
2991 3155
 
2992
-				if ($command_line)
2993
-					echo " done.\n";
3156
+				if ($command_line) {
3157
+									echo " done.\n";
3158
+				}
2994 3159
 			}
2995 3160
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2996
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
2997
-				return upgradeExit();
3161
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3162
+							return upgradeExit();
3163
+			}
2998 3164
 		}
2999 3165
 
3000 3166
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -3023,8 +3189,8 @@  discard block
 block discarded – undo
3023 3189
 		);
3024 3190
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3025 3191
 		{
3026
-			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)
3027
-				$smcFunc['db_query']('', '
3192
+			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) {
3193
+							$smcFunc['db_query']('', '
3028 3194
 					UPDATE {db_prefix}log_actions
3029 3195
 					SET extra = {string:extra}
3030 3196
 					WHERE id_action = {int:current_action}',
@@ -3033,6 +3199,7 @@  discard block
 block discarded – undo
3033 3199
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
3034 3200
 					)
3035 3201
 				);
3202
+			}
3036 3203
 		}
3037 3204
 		$smcFunc['db_free_result']($request);
3038 3205
 
@@ -3054,15 +3221,17 @@  discard block
 block discarded – undo
3054 3221
 	// First thing's first - did we already do this?
3055 3222
 	if (!empty($modSettings['json_done']))
3056 3223
 	{
3057
-		if ($command_line)
3058
-			return DeleteUpgrade();
3059
-		else
3060
-			return true;
3224
+		if ($command_line) {
3225
+					return DeleteUpgrade();
3226
+		} else {
3227
+					return true;
3228
+		}
3061 3229
 	}
3062 3230
 
3063 3231
 	// Done it already - js wise?
3064
-	if (!empty($_POST['json_done']))
3065
-		return true;
3232
+	if (!empty($_POST['json_done'])) {
3233
+			return true;
3234
+	}
3066 3235
 
3067 3236
 	// List of tables affected by this function
3068 3237
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3094,12 +3263,14 @@  discard block
 block discarded – undo
3094 3263
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3095 3264
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3096 3265
 
3097
-	foreach ($keys as $id => $table)
3098
-		if ($id < $_GET['substep'])
3266
+	foreach ($keys as $id => $table) {
3267
+			if ($id < $_GET['substep'])
3099 3268
 			$upcontext['previous_tables'][] = $table;
3269
+	}
3100 3270
 
3101
-	if ($command_line)
3102
-		echo 'Converting data from serialize() to json_encode().';
3271
+	if ($command_line) {
3272
+			echo 'Converting data from serialize() to json_encode().';
3273
+	}
3103 3274
 
3104 3275
 	if (!$support_js || isset($_GET['xml']))
3105 3276
 	{
@@ -3139,8 +3310,9 @@  discard block
 block discarded – undo
3139 3310
 
3140 3311
 				// Loop through and fix these...
3141 3312
 				$new_settings = array();
3142
-				if ($command_line)
3143
-					echo "\n" . 'Fixing some settings...';
3313
+				if ($command_line) {
3314
+									echo "\n" . 'Fixing some settings...';
3315
+				}
3144 3316
 
3145 3317
 				foreach ($serialized_settings as $var)
3146 3318
 				{
@@ -3148,22 +3320,24 @@  discard block
 block discarded – undo
3148 3320
 					{
3149 3321
 						// Attempt to unserialize the setting
3150 3322
 						$temp = @safe_unserialize($modSettings[$var]);
3151
-						if (!$temp && $command_line)
3152
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3153
-						elseif ($temp !== false)
3154
-							$new_settings[$var] = json_encode($temp);
3323
+						if (!$temp && $command_line) {
3324
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3325
+						} elseif ($temp !== false) {
3326
+													$new_settings[$var] = json_encode($temp);
3327
+						}
3155 3328
 					}
3156 3329
 				}
3157 3330
 
3158 3331
 				// Update everything at once
3159
-				if (!function_exists('cache_put_data'))
3160
-					require_once($sourcedir . '/Load.php');
3332
+				if (!function_exists('cache_put_data')) {
3333
+									require_once($sourcedir . '/Load.php');
3334
+				}
3161 3335
 				updateSettings($new_settings, true);
3162 3336
 
3163
-				if ($command_line)
3164
-					echo ' done.';
3165
-			}
3166
-			elseif ($table == 'themes')
3337
+				if ($command_line) {
3338
+									echo ' done.';
3339
+				}
3340
+			} elseif ($table == 'themes')
3167 3341
 			{
3168 3342
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3169 3343
 				$query = $smcFunc['db_query']('', '
@@ -3182,10 +3356,11 @@  discard block
 block discarded – undo
3182 3356
 
3183 3357
 						if ($command_line)
3184 3358
 						{
3185
-							if ($temp === false)
3186
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3187
-							else
3188
-								echo "\n" . 'Fixing admin preferences...';
3359
+							if ($temp === false) {
3360
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3361
+							} else {
3362
+															echo "\n" . 'Fixing admin preferences...';
3363
+							}
3189 3364
 						}
3190 3365
 
3191 3366
 						if ($temp !== false)
@@ -3207,15 +3382,15 @@  discard block
 block discarded – undo
3207 3382
 								)
3208 3383
 							);
3209 3384
 
3210
-							if ($command_line)
3211
-								echo ' done.';
3385
+							if ($command_line) {
3386
+															echo ' done.';
3387
+							}
3212 3388
 						}
3213 3389
 					}
3214 3390
 
3215 3391
 					$smcFunc['db_free_result']($query);
3216 3392
 				}
3217
-			}
3218
-			else
3393
+			} else
3219 3394
 			{
3220 3395
 				// First item is always the key...
3221 3396
 				$key = $info[0];
@@ -3226,8 +3401,7 @@  discard block
 block discarded – undo
3226 3401
 				{
3227 3402
 					$col_select = $info[1];
3228 3403
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3229
-				}
3230
-				else
3404
+				} else
3231 3405
 				{
3232 3406
 					$col_select = implode(', ', $info);
3233 3407
 				}
@@ -3260,8 +3434,7 @@  discard block
 block discarded – undo
3260 3434
 								if ($temp === false && $command_line)
3261 3435
 								{
3262 3436
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3263
-								}
3264
-								else
3437
+								} else
3265 3438
 								{
3266 3439
 									$row[$col] = json_encode($temp);
3267 3440
 
@@ -3286,16 +3459,18 @@  discard block
 block discarded – undo
3286 3459
 						}
3287 3460
 					}
3288 3461
 
3289
-					if ($command_line)
3290
-						echo ' done.';
3462
+					if ($command_line) {
3463
+											echo ' done.';
3464
+					}
3291 3465
 
3292 3466
 					// Free up some memory...
3293 3467
 					$smcFunc['db_free_result']($query);
3294 3468
 				}
3295 3469
 			}
3296 3470
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3297
-			if (isset($_GET['xml']))
3298
-				return upgradeExit();
3471
+			if (isset($_GET['xml'])) {
3472
+							return upgradeExit();
3473
+			}
3299 3474
 		}
3300 3475
 
3301 3476
 		if ($command_line)
@@ -3310,8 +3485,9 @@  discard block
 block discarded – undo
3310 3485
 
3311 3486
 		$_GET['substep'] = 0;
3312 3487
 		// Make sure we move on!
3313
-		if ($command_line)
3314
-			return DeleteUpgrade();
3488
+		if ($command_line) {
3489
+					return DeleteUpgrade();
3490
+		}
3315 3491
 
3316 3492
 		return true;
3317 3493
 	}
@@ -3368,14 +3544,16 @@  discard block
 block discarded – undo
3368 3544
 	global $upcontext, $txt, $settings;
3369 3545
 
3370 3546
 	// Don't call me twice!
3371
-	if (!empty($upcontext['chmod_called']))
3372
-		return;
3547
+	if (!empty($upcontext['chmod_called'])) {
3548
+			return;
3549
+	}
3373 3550
 
3374 3551
 	$upcontext['chmod_called'] = true;
3375 3552
 
3376 3553
 	// Nothing?
3377
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3378
-		return;
3554
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3555
+			return;
3556
+	}
3379 3557
 
3380 3558
 	// Was it a problem with Windows?
3381 3559
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3407,11 +3585,12 @@  discard block
 block discarded – undo
3407 3585
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\');
3408 3586
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3409 3587
 
3410
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3411
-		echo '
3588
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3589
+			echo '
3412 3590
 					content.write(\'<hr>\n\t\t\t\');
3413 3591
 					content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\');
3414 3592
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3593
+	}
3415 3594
 
3416 3595
 	echo '
3417 3596
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3419,17 +3598,19 @@  discard block
 block discarded – undo
3419 3598
 				}
3420 3599
 			</script>';
3421 3600
 
3422
-	if (!empty($upcontext['chmod']['ftp_error']))
3423
-		echo '
3601
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3602
+			echo '
3424 3603
 			<div class="error_message red">
3425 3604
 				', $txt['upgrade_ftp_error'], '<br><br>
3426 3605
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3427 3606
 			</div>
3428 3607
 			<br>';
3608
+	}
3429 3609
 
3430
-	if (empty($upcontext['chmod_in_form']))
3431
-		echo '
3610
+	if (empty($upcontext['chmod_in_form'])) {
3611
+			echo '
3432 3612
 	<form action="', $upcontext['form_url'], '" method="post">';
3613
+	}
3433 3614
 
3434 3615
 	echo '
3435 3616
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3464,10 +3645,11 @@  discard block
 block discarded – undo
3464 3645
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button"></div>
3465 3646
 	</div>';
3466 3647
 
3467
-	if (empty($upcontext['chmod_in_form']))
3468
-		echo '
3648
+	if (empty($upcontext['chmod_in_form'])) {
3649
+			echo '
3469 3650
 	</form>';
3470
-}
3651
+	}
3652
+	}
3471 3653
 
3472 3654
 function template_upgrade_above()
3473 3655
 {
@@ -3527,9 +3709,10 @@  discard block
 block discarded – undo
3527 3709
 				<h2>', $txt['upgrade_progress'], '</h2>
3528 3710
 				<ul>';
3529 3711
 
3530
-	foreach ($upcontext['steps'] as $num => $step)
3531
-		echo '
3712
+	foreach ($upcontext['steps'] as $num => $step) {
3713
+			echo '
3532 3714
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3715
+	}
3533 3716
 
3534 3717
 	echo '
3535 3718
 					</ul>
@@ -3542,8 +3725,8 @@  discard block
 block discarded – undo
3542 3725
 				</div>
3543 3726
 			</div>';
3544 3727
 
3545
-	if (isset($upcontext['step_progress']))
3546
-		echo '
3728
+	if (isset($upcontext['step_progress'])) {
3729
+			echo '
3547 3730
 				<br>
3548 3731
 				<br>
3549 3732
 				<div id="progress_bar_step">
@@ -3552,6 +3735,7 @@  discard block
 block discarded – undo
3552 3735
 						<span>', $txt['upgrade_step_progress'], '</span>
3553 3736
 					</div>
3554 3737
 				</div>';
3738
+	}
3555 3739
 
3556 3740
 	echo '
3557 3741
 				<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>
@@ -3582,32 +3766,36 @@  discard block
 block discarded – undo
3582 3766
 {
3583 3767
 	global $upcontext, $txt;
3584 3768
 
3585
-	if (!empty($upcontext['pause']))
3586
-		echo '
3769
+	if (!empty($upcontext['pause'])) {
3770
+			echo '
3587 3771
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3588 3772
 
3589 3773
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3590 3774
 								<h3>
3591 3775
 									', $txt['upgrade_paused_overload'], '
3592 3776
 								</h3>';
3777
+	}
3593 3778
 
3594
-	if (!empty($upcontext['custom_warning']))
3595
-		echo '
3779
+	if (!empty($upcontext['custom_warning'])) {
3780
+			echo '
3596 3781
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3597 3782
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3598 3783
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3599 3784
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3600 3785
 								</div>';
3786
+	}
3601 3787
 
3602 3788
 	echo '
3603 3789
 								<div class="righttext" style="margin: 1ex;">';
3604 3790
 
3605
-	if (!empty($upcontext['continue']))
3606
-		echo '
3791
+	if (!empty($upcontext['continue'])) {
3792
+			echo '
3607 3793
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">';
3608
-	if (!empty($upcontext['skip']))
3609
-		echo '
3794
+	}
3795
+	if (!empty($upcontext['skip'])) {
3796
+			echo '
3610 3797
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">';
3798
+	}
3611 3799
 
3612 3800
 	echo '
3613 3801
 								</div>
@@ -3657,11 +3845,12 @@  discard block
 block discarded – undo
3657 3845
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3658 3846
 	<smf>';
3659 3847
 
3660
-	if (!empty($upcontext['get_data']))
3661
-		foreach ($upcontext['get_data'] as $k => $v)
3848
+	if (!empty($upcontext['get_data'])) {
3849
+			foreach ($upcontext['get_data'] as $k => $v)
3662 3850
 			echo '
3663 3851
 		<get key="', $k, '">', $v, '</get>';
3664
-}
3852
+	}
3853
+	}
3665 3854
 
3666 3855
 function template_xml_below()
3667 3856
 {
@@ -3702,8 +3891,8 @@  discard block
 block discarded – undo
3702 3891
 	template_chmod();
3703 3892
 
3704 3893
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3705
-	if ($upcontext['is_large_forum'])
3706
-		echo '
3894
+	if ($upcontext['is_large_forum']) {
3895
+			echo '
3707 3896
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3708 3897
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3709 3898
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3711,10 +3900,11 @@  discard block
 block discarded – undo
3711 3900
 				', $txt['upgrade_warning_lots_data'], '
3712 3901
 			</div>
3713 3902
 		</div>';
3903
+	}
3714 3904
 
3715 3905
 	// A warning message?
3716
-	if (!empty($upcontext['warning']))
3717
-		echo '
3906
+	if (!empty($upcontext['warning'])) {
3907
+			echo '
3718 3908
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3719 3909
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3720 3910
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3722,6 +3912,7 @@  discard block
 block discarded – undo
3722 3912
 				', $upcontext['warning'], '
3723 3913
 			</div>
3724 3914
 		</div>';
3915
+	}
3725 3916
 
3726 3917
 	// Paths are incorrect?
3727 3918
 	echo '
@@ -3737,20 +3928,22 @@  discard block
 block discarded – undo
3737 3928
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3738 3929
 	{
3739 3930
 		$ago = time() - $upcontext['started'];
3740
-		if ($ago < 60)
3741
-			$ago = $ago . ' seconds';
3742
-		elseif ($ago < 3600)
3743
-			$ago = (int) ($ago / 60) . ' minutes';
3744
-		else
3745
-			$ago = (int) ($ago / 3600) . ' hours';
3931
+		if ($ago < 60) {
3932
+					$ago = $ago . ' seconds';
3933
+		} elseif ($ago < 3600) {
3934
+					$ago = (int) ($ago / 60) . ' minutes';
3935
+		} else {
3936
+					$ago = (int) ($ago / 3600) . ' hours';
3937
+		}
3746 3938
 
3747 3939
 		$active = time() - $upcontext['updated'];
3748
-		if ($active < 60)
3749
-			$updated = $active . ' seconds';
3750
-		elseif ($active < 3600)
3751
-			$updated = (int) ($active / 60) . ' minutes';
3752
-		else
3753
-			$updated = (int) ($active / 3600) . ' hours';
3940
+		if ($active < 60) {
3941
+					$updated = $active . ' seconds';
3942
+		} elseif ($active < 3600) {
3943
+					$updated = (int) ($active / 60) . ' minutes';
3944
+		} else {
3945
+					$updated = (int) ($active / 3600) . ' hours';
3946
+		}
3754 3947
 
3755 3948
 		echo '
3756 3949
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3759,16 +3952,18 @@  discard block
 block discarded – undo
3759 3952
 			<div style="padding-left: 6ex;">
3760 3953
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3761 3954
 
3762
-		if ($active < 600)
3763
-			echo '
3955
+		if ($active < 600) {
3956
+					echo '
3764 3957
 				', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '';
3958
+		}
3765 3959
 
3766
-		if ($active > $upcontext['inactive_timeout'])
3767
-			echo '
3960
+		if ($active > $upcontext['inactive_timeout']) {
3961
+					echo '
3768 3962
 				<br><br>',$txt['upgrade_run'], '';
3769
-		else
3770
-			echo '
3963
+		} else {
3964
+					echo '
3771 3965
 				<br><br>', $txt['upgrade_script_timeout'], ' ', $upcontext['user']['name'], ' ', $txt['upgrade_script_timeout2'], ' ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3966
+		}
3772 3967
 
3773 3968
 		echo '
3774 3969
 			</div>
@@ -3784,9 +3979,10 @@  discard block
 block discarded – undo
3784 3979
 					<td>
3785 3980
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>';
3786 3981
 
3787
-	if (!empty($upcontext['username_incorrect']))
3788
-		echo '
3982
+	if (!empty($upcontext['username_incorrect'])) {
3983
+			echo '
3789 3984
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_username'], '</div>';
3985
+	}
3790 3986
 
3791 3987
 	echo '
3792 3988
 					</td>
@@ -3797,9 +3993,10 @@  discard block
 block discarded – undo
3797 3993
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '>
3798 3994
 						<input type="hidden" name="hash_passwrd" value="">';
3799 3995
 
3800
-	if (!empty($upcontext['password_failed']))
3801
-		echo '
3996
+	if (!empty($upcontext['password_failed'])) {
3997
+			echo '
3802 3998
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_password'], '</div>';
3999
+	}
3803 4000
 
3804 4001
 	echo '
3805 4002
 					</td>
@@ -3870,8 +4067,8 @@  discard block
 block discarded – undo
3870 4067
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3871 4068
 
3872 4069
 	// Warning message?
3873
-	if (!empty($upcontext['upgrade_options_warning']))
3874
-		echo '
4070
+	if (!empty($upcontext['upgrade_options_warning'])) {
4071
+			echo '
3875 4072
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3876 4073
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3877 4074
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3879,6 +4076,7 @@  discard block
 block discarded – undo
3879 4076
 				', $upcontext['upgrade_options_warning'], '
3880 4077
 			</div>
3881 4078
 		</div>';
4079
+	}
3882 4080
 
3883 4081
 	echo '
3884 4082
 				<table>
@@ -3921,8 +4119,8 @@  discard block
 block discarded – undo
3921 4119
 						</td>
3922 4120
 					</tr>';
3923 4121
 
3924
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3925
-		echo '
4122
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4123
+			echo '
3926 4124
 					<tr valign="top">
3927 4125
 						<td width="2%">
3928 4126
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1">
@@ -3931,6 +4129,7 @@  discard block
 block discarded – undo
3931 4129
 							<label for="delete_karma">', $txt['upgrade_delete_karma'], '</label>
3932 4130
 						</td>
3933 4131
 					</tr>';
4132
+	}
3934 4133
 
3935 4134
 	echo '
3936 4135
 					<tr valign="top">
@@ -3968,10 +4167,11 @@  discard block
 block discarded – undo
3968 4167
 			</div>';
3969 4168
 
3970 4169
 	// Dont any tables so far?
3971
-	if (!empty($upcontext['previous_tables']))
3972
-		foreach ($upcontext['previous_tables'] as $table)
4170
+	if (!empty($upcontext['previous_tables'])) {
4171
+			foreach ($upcontext['previous_tables'] as $table)
3973 4172
 			echo '
3974 4173
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4174
+	}
3975 4175
 
3976 4176
 	echo '
3977 4177
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -4008,12 +4208,13 @@  discard block
 block discarded – undo
4008 4208
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4009 4209
 
4010 4210
 		// If debug flood the screen.
4011
-		if ($is_debug)
4012
-			echo '
4211
+		if ($is_debug) {
4212
+					echo '
4013 4213
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4014 4214
 
4015 4215
 				if (document.getElementById(\'debug_section\').scrollHeight)
4016 4216
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4217
+		}
4017 4218
 
4018 4219
 		echo '
4019 4220
 				// Get the next update...
@@ -4046,8 +4247,9 @@  discard block
 block discarded – undo
4046 4247
 {
4047 4248
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold, $txt;
4048 4249
 
4049
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
4050
-		$is_debug = true;
4250
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4251
+			$is_debug = true;
4252
+	}
4051 4253
 
4052 4254
 	echo '
4053 4255
 		<h3>', $txt['upgrade_db_changes'], '</h3>
@@ -4062,8 +4264,9 @@  discard block
 block discarded – undo
4062 4264
 	{
4063 4265
 		foreach ($upcontext['actioned_items'] as $num => $item)
4064 4266
 		{
4065
-			if ($num != 0)
4066
-				echo ' Successful!';
4267
+			if ($num != 0) {
4268
+							echo ' Successful!';
4269
+			}
4067 4270
 			echo '<br>' . $item;
4068 4271
 		}
4069 4272
 		if (!empty($upcontext['changes_complete']))
@@ -4076,28 +4279,32 @@  discard block
 block discarded – undo
4076 4279
 				$seconds = intval($active % 60);
4077 4280
 
4078 4281
 				$totalTime = '';
4079
-				if ($hours > 0)
4080
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4081
-				if ($minutes > 0)
4082
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4083
-				if ($seconds > 0)
4084
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4282
+				if ($hours > 0) {
4283
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4284
+				}
4285
+				if ($minutes > 0) {
4286
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4287
+				}
4288
+				if ($seconds > 0) {
4289
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4290
+				}
4085 4291
 			}
4086 4292
 
4087
-			if ($is_debug && !empty($totalTime))
4088
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
4089
-			else
4090
-				echo ' Successful!<br><br>';
4293
+			if ($is_debug && !empty($totalTime)) {
4294
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4295
+			} else {
4296
+							echo ' Successful!<br><br>';
4297
+			}
4091 4298
 
4092 4299
 			echo '<span id="commess" style="font-weight: bold;">', $txt['upgrade_db_complete'], '</span><br>';
4093 4300
 		}
4094
-	}
4095
-	else
4301
+	} else
4096 4302
 	{
4097 4303
 		// Tell them how many files we have in total.
4098
-		if ($upcontext['file_count'] > 1)
4099
-			echo '
4304
+		if ($upcontext['file_count'] > 1) {
4305
+					echo '
4100 4306
 		<strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4307
+		}
4101 4308
 
4102 4309
 		echo '
4103 4310
 		<h3 id="info2"><strong>', $txt['upgrade_executing'], '</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> ', $txt['upgrade_of'], ' <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -4113,19 +4320,23 @@  discard block
 block discarded – undo
4113 4320
 				$seconds = intval($active % 60);
4114 4321
 
4115 4322
 				$totalTime = '';
4116
-				if ($hours > 0)
4117
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4118
-				if ($minutes > 0)
4119
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4120
-				if ($seconds > 0)
4121
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4323
+				if ($hours > 0) {
4324
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4325
+				}
4326
+				if ($minutes > 0) {
4327
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4328
+				}
4329
+				if ($seconds > 0) {
4330
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4331
+				}
4122 4332
 			}
4123 4333
 
4124 4334
 			echo '
4125 4335
 			<br><span id="upgradeCompleted">';
4126 4336
 
4127
-			if (!empty($totalTime))
4128
-				echo 'Completed in ', $totalTime, '<br>';
4337
+			if (!empty($totalTime)) {
4338
+							echo 'Completed in ', $totalTime, '<br>';
4339
+			}
4129 4340
 
4130 4341
 			echo '</span>
4131 4342
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -4162,9 +4373,10 @@  discard block
 block discarded – undo
4162 4373
 			var getData = "";
4163 4374
 			var debugItems = ', $upcontext['debug_items'], ';';
4164 4375
 
4165
-		if ($is_debug)
4166
-			echo '
4376
+		if ($is_debug) {
4377
+					echo '
4167 4378
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4379
+		}
4168 4380
 
4169 4381
 		echo '
4170 4382
 			function getNextItem()
@@ -4204,9 +4416,10 @@  discard block
 block discarded – undo
4204 4416
 						document.getElementById("error_block").style.display = "";
4205 4417
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4206 4418
 
4207
-	if ($is_debug)
4208
-		echo '
4419
+	if ($is_debug) {
4420
+			echo '
4209 4421
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4422
+	}
4210 4423
 
4211 4424
 	echo '
4212 4425
 					}
@@ -4227,9 +4440,10 @@  discard block
 block discarded – undo
4227 4440
 						document.getElementById("error_block").style.display = "";
4228 4441
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4229 4442
 
4230
-	if ($is_debug)
4231
-		echo '
4443
+	if ($is_debug) {
4444
+			echo '
4232 4445
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4446
+	}
4233 4447
 
4234 4448
 	echo '
4235 4449
 					}
@@ -4288,8 +4502,8 @@  discard block
 block discarded – undo
4288 4502
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4289 4503
 				{';
4290 4504
 
4291
-		if ($is_debug)
4292
-			echo '
4505
+		if ($is_debug) {
4506
+					echo '
4293 4507
 					document.getElementById(\'debug_section\').style.display = "none";
4294 4508
 
4295 4509
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4307,6 +4521,7 @@  discard block
 block discarded – undo
4307 4521
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4308 4522
 
4309 4523
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4524
+		}
4310 4525
 
4311 4526
 		echo '
4312 4527
 
@@ -4314,9 +4529,10 @@  discard block
 block discarded – undo
4314 4529
 					document.getElementById(\'contbutt\').disabled = 0;
4315 4530
 					document.getElementById(\'database_done\').value = 1;';
4316 4531
 
4317
-		if ($upcontext['file_count'] > 1)
4318
-			echo '
4532
+		if ($upcontext['file_count'] > 1) {
4533
+					echo '
4319 4534
 					document.getElementById(\'info1\').style.display = "none";';
4535
+		}
4320 4536
 
4321 4537
 		echo '
4322 4538
 					document.getElementById(\'info2\').style.display = "none";
@@ -4329,9 +4545,10 @@  discard block
 block discarded – undo
4329 4545
 					lastItem = 0;
4330 4546
 					prevFile = curFile;';
4331 4547
 
4332
-		if ($is_debug)
4333
-			echo '
4548
+		if ($is_debug) {
4549
+					echo '
4334 4550
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4551
+		}
4335 4552
 
4336 4553
 		echo '
4337 4554
 					getNextItem();
@@ -4339,8 +4556,8 @@  discard block
 block discarded – undo
4339 4556
 				}';
4340 4557
 
4341 4558
 		// If debug scroll the screen.
4342
-		if ($is_debug)
4343
-			echo '
4559
+		if ($is_debug) {
4560
+					echo '
4344 4561
 				if (iLastSubStepProgress == -1)
4345 4562
 				{
4346 4563
 					// Give it consistent dots.
@@ -4359,6 +4576,7 @@  discard block
 block discarded – undo
4359 4576
 
4360 4577
 				if (document.getElementById(\'debug_section\').scrollHeight)
4361 4578
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4579
+		}
4362 4580
 
4363 4581
 		echo '
4364 4582
 				// Update the page.
@@ -4419,9 +4637,10 @@  discard block
 block discarded – undo
4419 4637
 			}';
4420 4638
 
4421 4639
 		// Start things off assuming we've not errored.
4422
-		if (empty($upcontext['error_message']))
4423
-			echo '
4640
+		if (empty($upcontext['error_message'])) {
4641
+					echo '
4424 4642
 			getNextItem();';
4643
+		}
4425 4644
 
4426 4645
 		echo '
4427 4646
 		//# sourceURL=dynamicScript-dbch.js
@@ -4439,18 +4658,21 @@  discard block
 block discarded – undo
4439 4658
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4440 4659
 	<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>';
4441 4660
 
4442
-	if (!empty($upcontext['error_message']))
4443
-		echo '
4661
+	if (!empty($upcontext['error_message'])) {
4662
+			echo '
4444 4663
 	<error>', $upcontext['error_message'], '</error>';
4664
+	}
4445 4665
 
4446
-	if (!empty($upcontext['error_string']))
4447
-		echo '
4666
+	if (!empty($upcontext['error_string'])) {
4667
+			echo '
4448 4668
 	<sql>', $upcontext['error_string'], '</sql>';
4669
+	}
4449 4670
 
4450
-	if ($is_debug)
4451
-		echo '
4671
+	if ($is_debug) {
4672
+			echo '
4452 4673
 	<curtime>', time(), '</curtime>';
4453
-}
4674
+	}
4675
+	}
4454 4676
 
4455 4677
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4456 4678
 function template_convert_utf8()
@@ -4469,18 +4691,20 @@  discard block
 block discarded – undo
4469 4691
 			</div>';
4470 4692
 
4471 4693
 	// Done any tables so far?
4472
-	if (!empty($upcontext['previous_tables']))
4473
-		foreach ($upcontext['previous_tables'] as $table)
4694
+	if (!empty($upcontext['previous_tables'])) {
4695
+			foreach ($upcontext['previous_tables'] as $table)
4474 4696
 			echo '
4475 4697
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4698
+	}
4476 4699
 
4477 4700
 	echo '
4478 4701
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4479 4702
 
4480 4703
 	// If we dropped their index, let's let them know
4481
-	if ($upcontext['dropping_index'])
4482
-		echo '
4704
+	if ($upcontext['dropping_index']) {
4705
+			echo '
4483 4706
 				<br><span id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_fulltext'], '</span>';
4707
+	}
4484 4708
 
4485 4709
 	// Completion notification
4486 4710
 	echo '
@@ -4517,12 +4741,13 @@  discard block
 block discarded – undo
4517 4741
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4518 4742
 
4519 4743
 		// If debug flood the screen.
4520
-		if ($is_debug)
4521
-			echo '
4744
+		if ($is_debug) {
4745
+					echo '
4522 4746
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4523 4747
 
4524 4748
 				if (document.getElementById(\'debug_section\').scrollHeight)
4525 4749
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4750
+		}
4526 4751
 
4527 4752
 		echo '
4528 4753
 				// Get the next update...
@@ -4570,19 +4795,21 @@  discard block
 block discarded – undo
4570 4795
 			</div>';
4571 4796
 
4572 4797
 	// Dont any tables so far?
4573
-	if (!empty($upcontext['previous_tables']))
4574
-		foreach ($upcontext['previous_tables'] as $table)
4798
+	if (!empty($upcontext['previous_tables'])) {
4799
+			foreach ($upcontext['previous_tables'] as $table)
4575 4800
 			echo '
4576 4801
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4802
+	}
4577 4803
 
4578 4804
 	echo '
4579 4805
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4580 4806
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_json_completed'], '</span>';
4581 4807
 
4582 4808
 	// Try to make sure substep was reset.
4583
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4584
-		echo '
4809
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4810
+			echo '
4585 4811
 			<input type="hidden" name="substep" id="substep" value="0">';
4812
+	}
4586 4813
 
4587 4814
 	// Continue please!
4588 4815
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4615,12 +4842,13 @@  discard block
 block discarded – undo
4615 4842
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4616 4843
 
4617 4844
 		// If debug flood the screen.
4618
-		if ($is_debug)
4619
-			echo '
4845
+		if ($is_debug) {
4846
+					echo '
4620 4847
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4621 4848
 
4622 4849
 				if (document.getElementById(\'debug_section\').scrollHeight)
4623 4850
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4851
+		}
4624 4852
 
4625 4853
 		echo '
4626 4854
 				// Get the next update...
@@ -4656,8 +4884,8 @@  discard block
 block discarded – undo
4656 4884
 	<h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>.  ', $txt['upgrade_done3'], '</h3>
4657 4885
 	<form action="', $boardurl, '/index.php">';
4658 4886
 
4659
-	if (!empty($upcontext['can_delete_script']))
4660
-		echo '
4887
+	if (!empty($upcontext['can_delete_script'])) {
4888
+			echo '
4661 4889
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], '</label> <em>', $txt['upgrade_delete_server'], '</em>
4662 4890
 			<script>
4663 4891
 				function doTheDelete(theCheck)
@@ -4669,6 +4897,7 @@  discard block
 block discarded – undo
4669 4897
 				}
4670 4898
 			</script>
4671 4899
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4900
+	}
4672 4901
 
4673 4902
 	$active = time() - $upcontext['started'];
4674 4903
 	$hours = floor($active / 3600);
@@ -4678,16 +4907,20 @@  discard block
 block discarded – undo
4678 4907
 	if ($is_debug)
4679 4908
 	{
4680 4909
 		$totalTime = '';
4681
-		if ($hours > 0)
4682
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4683
-		if ($minutes > 0)
4684
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4685
-		if ($seconds > 0)
4686
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4910
+		if ($hours > 0) {
4911
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4912
+		}
4913
+		if ($minutes > 0) {
4914
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4915
+		}
4916
+		if ($seconds > 0) {
4917
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4918
+		}
4687 4919
 	}
4688 4920
 
4689
-	if ($is_debug && !empty($totalTime))
4690
-		echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4921
+	if ($is_debug && !empty($totalTime)) {
4922
+			echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4923
+	}
4691 4924
 
4692 4925
 	echo '<br>
4693 4926
 			', sprintf($txt['upgrade_problems'], 'http://simplemachines.org'), '<br>
@@ -4714,8 +4947,9 @@  discard block
 block discarded – undo
4714 4947
 
4715 4948
 	$current_substep = $_GET['substep'];
4716 4949
 
4717
-	if (empty($_GET['a']))
4718
-		$_GET['a'] = 0;
4950
+	if (empty($_GET['a'])) {
4951
+			$_GET['a'] = 0;
4952
+	}
4719 4953
 	$step_progress['name'] = 'Converting ips';
4720 4954
 	$step_progress['current'] = $_GET['a'];
4721 4955
 
@@ -4758,16 +4992,19 @@  discard block
 block discarded – undo
4758 4992
 				'empty' => '',
4759 4993
 				'limit' => $limit,
4760 4994
 		));
4761
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4762
-			$arIp[] = $row[$oldCol];
4995
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4996
+					$arIp[] = $row[$oldCol];
4997
+		}
4763 4998
 		$smcFunc['db_free_result']($request);
4764 4999
 
4765 5000
 		// Special case, null ip could keep us in a loop.
4766
-		if (is_null($arIp[0]))
4767
-			unset($arIp[0]);
5001
+		if (is_null($arIp[0])) {
5002
+					unset($arIp[0]);
5003
+		}
4768 5004
 
4769
-		if (empty($arIp))
4770
-			$is_done = true;
5005
+		if (empty($arIp)) {
5006
+					$is_done = true;
5007
+		}
4771 5008
 
4772 5009
 		$updates = array();
4773 5010
 		$cases = array();
@@ -4776,16 +5013,18 @@  discard block
 block discarded – undo
4776 5013
 		{
4777 5014
 			$arIp[$i] = trim($arIp[$i]);
4778 5015
 
4779
-			if (empty($arIp[$i]))
4780
-				continue;
5016
+			if (empty($arIp[$i])) {
5017
+							continue;
5018
+			}
4781 5019
 
4782 5020
 			$updates['ip' . $i] = $arIp[$i];
4783 5021
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4784 5022
 
4785 5023
 			if ($setSize > 0 && $i % $setSize === 0)
4786 5024
 			{
4787
-				if (count($updates) == 1)
4788
-					continue;
5025
+				if (count($updates) == 1) {
5026
+									continue;
5027
+				}
4789 5028
 
4790 5029
 				$updates['whereSet'] = array_values($updates);
4791 5030
 				$smcFunc['db_query']('', '
@@ -4819,8 +5058,7 @@  discard block
 block discarded – undo
4819 5058
 							'ip' => $ip
4820 5059
 					));
4821 5060
 				}
4822
-			}
4823
-			else
5061
+			} else
4824 5062
 			{
4825 5063
 				$updates['whereSet'] = array_values($updates);
4826 5064
 				$smcFunc['db_query']('', '
@@ -4834,9 +5072,9 @@  discard block
 block discarded – undo
4834 5072
 					$updates
4835 5073
 				);
4836 5074
 			}
5075
+		} else {
5076
+					$is_done = true;
4837 5077
 		}
4838
-		else
4839
-			$is_done = true;
4840 5078
 
4841 5079
 		$_GET['a'] += $limit;
4842 5080
 		$step_progress['current'] = $_GET['a'];
@@ -4862,10 +5100,11 @@  discard block
 block discarded – undo
4862 5100
 
4863 5101
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4864 5102
 
4865
-	if (isset($columns[$column]))
4866
-		return $columns[$column];
4867
-	else
4868
-		return null;
4869
-}
5103
+	if (isset($columns[$column])) {
5104
+			return $columns[$column];
5105
+	} else {
5106
+			return null;
5107
+	}
5108
+	}
4870 5109
 
4871 5110
 ?>
4872 5111
\ No newline at end of file
Please login to merge, or discard this patch.