Completed
Push — release-2.1 ( 4c1e0c...0ba540 )
by John
13s
created
other/upgrade-helper.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 /**
142 142
  * Make files writable. First try to use regular chmod, but if that fails, try to use FTP.
143 143
  *
144
- * @param $files
144
+ * @param string[] $files
145 145
  * @return bool
146 146
  */
147 147
 function makeFilesWritable(&$files)
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 /**
382 382
  * Prints an error to stderr.
383 383
  *
384
- * @param $message
384
+ * @param string $message
385 385
  * @param bool $fatal
386 386
  */
387 387
 function print_error($message, $fatal = false)
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 /**
401 401
  * Throws a graphical error message.
402 402
  *
403
- * @param $message
403
+ * @param string $message
404 404
  * @return bool
405 405
  */
406 406
 function throw_error($message)
Please login to merge, or discard this patch.
Braces   +90 added lines, -64 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * This file contains helper functions for upgrade.php
14 14
  */
15 15
 
16
-if (!defined('SMF_VERSION'))
16
+if (!defined('SMF_VERSION')) {
17 17
 	die('No direct access!');
18
+}
18 19
 
19 20
 /**
20 21
  * Clean the cache using the SMF 2.1 CacheAPI.
@@ -45,8 +46,9 @@  discard block
 block discarded – undo
45 46
 	global $smcFunc;
46 47
 	static $member_groups = array();
47 48
 
48
-	if (!empty($member_groups))
49
-		return $member_groups;
49
+	if (!empty($member_groups)) {
50
+			return $member_groups;
51
+	}
50 52
 
51 53
 	$request = $smcFunc['db_query']('', '
52 54
 		SELECT group_name, id_group
@@ -71,8 +73,9 @@  discard block
 block discarded – undo
71 73
 			)
72 74
 		);
73 75
 	}
74
-	while ($row = $smcFunc['db_fetch_row']($request))
75
-		$member_groups[trim($row[0])] = $row[1];
76
+	while ($row = $smcFunc['db_fetch_row']($request)) {
77
+			$member_groups[trim($row[0])] = $row[1];
78
+	}
76 79
 	$smcFunc['db_free_result']($request);
77 80
 
78 81
 	return $member_groups;
@@ -88,8 +91,9 @@  discard block
 block discarded – undo
88 91
 {
89 92
 	global $upcontext, $boarddir, $sourcedir;
90 93
 
91
-	if (empty($files))
92
-		return true;
94
+	if (empty($files)) {
95
+			return true;
96
+	}
93 97
 
94 98
 	$failure = false;
95 99
 	// On linux, it's easy - just use is_writable!
@@ -104,14 +108,16 @@  discard block
 block discarded – undo
104 108
 				@chmod($file, 0755);
105 109
 
106 110
 				// Well, 755 hopefully worked... if not, try 777.
107
-				if (!is_writable($file) && !@chmod($file, 0777))
108
-					$failure = true;
111
+				if (!is_writable($file) && !@chmod($file, 0777)) {
112
+									$failure = true;
113
+				}
109 114
 				// Otherwise remove it as it's good!
110
-				else
111
-					unset($files[$k]);
115
+				else {
116
+									unset($files[$k]);
117
+				}
118
+			} else {
119
+							unset($files[$k]);
112 120
 			}
113
-			else
114
-				unset($files[$k]);
115 121
 		}
116 122
 	}
117 123
 	// Windows is trickier.  Let's try opening for r+...
@@ -122,30 +128,35 @@  discard block
 block discarded – undo
122 128
 		foreach ($files as $k => $file)
123 129
 		{
124 130
 			// Folders can't be opened for write... but the index.php in them can ;).
125
-			if (is_dir($file))
126
-				$file .= '/index.php';
131
+			if (is_dir($file)) {
132
+							$file .= '/index.php';
133
+			}
127 134
 
128 135
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
129 136
 			@chmod($file, 0777);
130 137
 			$fp = @fopen($file, 'r+');
131 138
 
132 139
 			// Hmm, okay, try just for write in that case...
133
-			if (!$fp)
134
-				$fp = @fopen($file, 'w');
140
+			if (!$fp) {
141
+							$fp = @fopen($file, 'w');
142
+			}
135 143
 
136
-			if (!$fp)
137
-				$failure = true;
138
-			else
139
-				unset($files[$k]);
144
+			if (!$fp) {
145
+							$failure = true;
146
+			} else {
147
+							unset($files[$k]);
148
+			}
140 149
 			@fclose($fp);
141 150
 		}
142 151
 	}
143 152
 
144
-	if (empty($files))
145
-		return true;
153
+	if (empty($files)) {
154
+			return true;
155
+	}
146 156
 
147
-	if (!isset($_SERVER))
148
-		return !$failure;
157
+	if (!isset($_SERVER)) {
158
+			return !$failure;
159
+	}
149 160
 
150 161
 	// What still needs to be done?
151 162
 	$upcontext['chmod']['files'] = $files;
@@ -197,36 +208,40 @@  discard block
 block discarded – undo
197 208
 
198 209
 		if (!isset($ftp) || $ftp->error !== false)
199 210
 		{
200
-			if (!isset($ftp))
201
-				$ftp = new ftp_connection(null);
211
+			if (!isset($ftp)) {
212
+							$ftp = new ftp_connection(null);
213
+			}
202 214
 			// Save the error so we can mess with listing...
203
-			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error']))
204
-				$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
215
+			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) {
216
+							$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
217
+			}
205 218
 
206 219
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
207 220
 
208
-			if ($found_path || !isset($upcontext['chmod']['path']))
209
-				$upcontext['chmod']['path'] = $detect_path;
221
+			if ($found_path || !isset($upcontext['chmod']['path'])) {
222
+							$upcontext['chmod']['path'] = $detect_path;
223
+			}
210 224
 
211
-			if (!isset($upcontext['chmod']['username']))
212
-				$upcontext['chmod']['username'] = $username;
225
+			if (!isset($upcontext['chmod']['username'])) {
226
+							$upcontext['chmod']['username'] = $username;
227
+			}
213 228
 
214 229
 			// Don't forget the login token.
215 230
 			$upcontext += createToken('login');
216 231
 
217 232
 			return false;
218
-		}
219
-		else
233
+		} else
220 234
 		{
221 235
 			// We want to do a relative path for FTP.
222 236
 			if (!in_array($upcontext['chmod']['path'], array('', '/')))
223 237
 			{
224 238
 				$ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => ''));
225
-				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/'))
226
-					$ftp_root = substr($ftp_root, 0, -1);
239
+				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) {
240
+									$ftp_root = substr($ftp_root, 0, -1);
241
+				}
242
+			} else {
243
+							$ftp_root = $boarddir;
227 244
 			}
228
-			else
229
-				$ftp_root = $boarddir;
230 245
 
231 246
 			// Save the info for next time!
232 247
 			$_SESSION['installer_temp_ftp'] = array(
@@ -240,10 +255,12 @@  discard block
 block discarded – undo
240 255
 
241 256
 			foreach ($files as $k => $file)
242 257
 			{
243
-				if (!is_writable($file))
244
-					$ftp->chmod($file, 0755);
245
-				if (!is_writable($file))
246
-					$ftp->chmod($file, 0777);
258
+				if (!is_writable($file)) {
259
+									$ftp->chmod($file, 0755);
260
+				}
261
+				if (!is_writable($file)) {
262
+									$ftp->chmod($file, 0777);
263
+				}
247 264
 
248 265
 				// Assuming that didn't work calculate the path without the boarddir.
249 266
 				if (!is_writable($file))
@@ -252,19 +269,23 @@  discard block
 block discarded – undo
252 269
 					{
253 270
 						$ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => ''));
254 271
 						$ftp->chmod($ftp_file, 0755);
255
-						if (!is_writable($file))
256
-							$ftp->chmod($ftp_file, 0777);
272
+						if (!is_writable($file)) {
273
+													$ftp->chmod($ftp_file, 0777);
274
+						}
257 275
 						// Sometimes an extra slash can help...
258 276
 						$ftp_file = '/' . $ftp_file;
259
-						if (!is_writable($file))
260
-							$ftp->chmod($ftp_file, 0755);
261
-						if (!is_writable($file))
262
-							$ftp->chmod($ftp_file, 0777);
277
+						if (!is_writable($file)) {
278
+													$ftp->chmod($ftp_file, 0755);
279
+						}
280
+						if (!is_writable($file)) {
281
+													$ftp->chmod($ftp_file, 0777);
282
+						}
263 283
 					}
264 284
 				}
265 285
 
266
-				if (is_writable($file))
267
-					unset($files[$k]);
286
+				if (is_writable($file)) {
287
+									unset($files[$k]);
288
+				}
268 289
 			}
269 290
 
270 291
 			$ftp->close();
@@ -274,8 +295,9 @@  discard block
 block discarded – undo
274 295
 	// What remains?
275 296
 	$upcontext['chmod']['files'] = $files;
276 297
 
277
-	if (empty($files))
278
-		return true;
298
+	if (empty($files)) {
299
+			return true;
300
+	}
279 301
 
280 302
 	return false;
281 303
 }
@@ -288,8 +310,9 @@  discard block
 block discarded – undo
288 310
  */
289 311
 function quickFileWritable($file)
290 312
 {
291
-	if (is_writable($file))
292
-		return true;
313
+	if (is_writable($file)) {
314
+			return true;
315
+	}
293 316
 
294 317
 	@chmod($file, 0755);
295 318
 
@@ -299,10 +322,11 @@  discard block
 block discarded – undo
299 322
 	foreach ($chmod_values as $val)
300 323
 	{
301 324
 		// If it's writable, break out of the loop
302
-		if (is_writable($file))
303
-			break;
304
-		else
305
-			@chmod($file, $val);
325
+		if (is_writable($file)) {
326
+					break;
327
+		} else {
328
+					@chmod($file, $val);
329
+		}
306 330
 	}
307 331
 
308 332
 	return is_writable($file);
@@ -329,14 +353,16 @@  discard block
 block discarded – undo
329 353
 {
330 354
 	static $fp = null;
331 355
 
332
-	if ($fp === null)
333
-		$fp = fopen('php://stderr', 'wb');
356
+	if ($fp === null) {
357
+			$fp = fopen('php://stderr', 'wb');
358
+	}
334 359
 
335 360
 	fwrite($fp, $message . "\n");
336 361
 
337
-	if ($fatal)
338
-		exit;
339
-}
362
+	if ($fatal) {
363
+			exit;
364
+	}
365
+	}
340 366
 
341 367
 /**
342 368
  * Throws a graphical error message.
Please login to merge, or discard this patch.
other/upgrade.php 3 patches
Doc Comments   +14 added lines, -1 removed lines patch added patch discarded remove patch
@@ -388,6 +388,9 @@  discard block
 block discarded – undo
388 388
 }
389 389
 
390 390
 // Used to direct the user to another location.
391
+/**
392
+ * @param string $location
393
+ */
391 394
 function redirectLocation($location, $addForm = true)
392 395
 {
393 396
 	global $upgradeurl, $upcontext, $command_line;
@@ -1560,6 +1563,9 @@  discard block
 block discarded – undo
1560 1563
 	return addslashes(preg_replace(array('~^\.([/\\\]|$)~', '~[/]+~', '~[\\\]+~', '~[/\\\]$~'), array($install_path . '$1', '/', '\\', ''), $path));
1561 1564
 }
1562 1565
 
1566
+/**
1567
+ * @param string $filename
1568
+ */
1563 1569
 function parse_sql($filename)
1564 1570
 {
1565 1571
 	global $db_prefix, $db_collation, $boarddir, $boardurl, $command_line, $file_steps, $step_progress, $custom_warning;
@@ -1594,6 +1600,10 @@  discard block
 block discarded – undo
1594 1600
 
1595 1601
 	// Our custom error handler - does nothing but does stop public errors from XML!
1596 1602
 	set_error_handler(
1603
+
1604
+		/**
1605
+		 * @param string $errno
1606
+		 */
1597 1607
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1598 1608
 		{
1599 1609
 			if ($support_js)
@@ -1840,6 +1850,9 @@  discard block
 block discarded – undo
1840 1850
 	return true;
1841 1851
 }
1842 1852
 
1853
+/**
1854
+ * @param string $string
1855
+ */
1843 1856
 function upgrade_query($string, $unbuffered = false)
1844 1857
 {
1845 1858
 	global $db_connection, $db_server, $db_user, $db_passwd, $db_type, $command_line, $upcontext, $upgradeurl, $modSettings;
@@ -4495,7 +4508,7 @@  discard block
 block discarded – undo
4495 4508
  * @param int $setSize The amount of entries after which to update the database.
4496 4509
  *
4497 4510
  * newCol needs to be a varbinary(16) null able field
4498
- * @return bool
4511
+ * @return boolean|null
4499 4512
  */
4500 4513
 function MySQLConvertOldIp($targetTable, $oldCol, $newCol, $limit = 50000, $setSize = 100)
4501 4514
 {
Please login to merge, or discard this patch.
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -1594,7 +1594,7 @@  discard block
 block discarded – undo
1594 1594
 
1595 1595
 	// Our custom error handler - does nothing but does stop public errors from XML!
1596 1596
 	set_error_handler(
1597
-		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1597
+		function($errno, $errstr, $errfile, $errline) use ($support_js)
1598 1598
 		{
1599 1599
 			if ($support_js)
1600 1600
 				return true;
@@ -2607,94 +2607,94 @@  discard block
 block discarded – undo
2607 2607
 		// Translation table for the character sets not native for MySQL.
2608 2608
 		$translation_tables = array(
2609 2609
 			'windows-1255' => array(
2610
-				'0x81' => '\'\'',		'0x8A' => '\'\'',		'0x8C' => '\'\'',
2611
-				'0x8D' => '\'\'',		'0x8E' => '\'\'',		'0x8F' => '\'\'',
2612
-				'0x90' => '\'\'',		'0x9A' => '\'\'',		'0x9C' => '\'\'',
2613
-				'0x9D' => '\'\'',		'0x9E' => '\'\'',		'0x9F' => '\'\'',
2614
-				'0xCA' => '\'\'',		'0xD9' => '\'\'',		'0xDA' => '\'\'',
2615
-				'0xDB' => '\'\'',		'0xDC' => '\'\'',		'0xDD' => '\'\'',
2616
-				'0xDE' => '\'\'',		'0xDF' => '\'\'',		'0xFB' => '0xD792',
2617
-				'0xFC' => '0xE282AC',		'0xFF' => '0xD6B2',		'0xC2' => '0xFF',
2618
-				'0x80' => '0xFC',		'0xE2' => '0xFB',		'0xA0' => '0xC2A0',
2619
-				'0xA1' => '0xC2A1',		'0xA2' => '0xC2A2',		'0xA3' => '0xC2A3',
2620
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
2621
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
2622
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
2623
-				'0xAF' => '0xC2AF',		'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',
2624
-				'0xB2' => '0xC2B2',		'0xB3' => '0xC2B3',		'0xB4' => '0xC2B4',
2625
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
2626
-				'0xB8' => '0xC2B8',		'0xB9' => '0xC2B9',		'0xBB' => '0xC2BB',
2627
-				'0xBC' => '0xC2BC',		'0xBD' => '0xC2BD',		'0xBE' => '0xC2BE',
2628
-				'0xBF' => '0xC2BF',		'0xD7' => '0xD7B3',		'0xD1' => '0xD781',
2629
-				'0xD4' => '0xD7B0',		'0xD5' => '0xD7B1',		'0xD6' => '0xD7B2',
2630
-				'0xE0' => '0xD790',		'0xEA' => '0xD79A',		'0xEC' => '0xD79C',
2631
-				'0xED' => '0xD79D',		'0xEE' => '0xD79E',		'0xEF' => '0xD79F',
2632
-				'0xF0' => '0xD7A0',		'0xF1' => '0xD7A1',		'0xF2' => '0xD7A2',
2633
-				'0xF3' => '0xD7A3',		'0xF5' => '0xD7A5',		'0xF6' => '0xD7A6',
2634
-				'0xF7' => '0xD7A7',		'0xF8' => '0xD7A8',		'0xF9' => '0xD7A9',
2635
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
2636
-				'0x86' => '0xE280A0',	'0x87' => '0xE280A1',	'0x89' => '0xE280B0',
2637
-				'0x8B' => '0xE280B9',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
2638
-				'0x95' => '0xE280A2',	'0x97' => '0xE28094',	'0x99' => '0xE284A2',
2639
-				'0xC0' => '0xD6B0',		'0xC1' => '0xD6B1',		'0xC3' => '0xD6B3',
2640
-				'0xC4' => '0xD6B4',		'0xC5' => '0xD6B5',		'0xC6' => '0xD6B6',
2641
-				'0xC7' => '0xD6B7',		'0xC8' => '0xD6B8',		'0xC9' => '0xD6B9',
2642
-				'0xCB' => '0xD6BB',		'0xCC' => '0xD6BC',		'0xCD' => '0xD6BD',
2643
-				'0xCE' => '0xD6BE',		'0xCF' => '0xD6BF',		'0xD0' => '0xD780',
2644
-				'0xD2' => '0xD782',		'0xE3' => '0xD793',		'0xE4' => '0xD794',
2645
-				'0xE5' => '0xD795',		'0xE7' => '0xD797',		'0xE9' => '0xD799',
2646
-				'0xFD' => '0xE2808E',	'0xFE' => '0xE2808F',	'0x92' => '0xE28099',
2647
-				'0x83' => '0xC692',		'0xD3' => '0xD783',		'0x88' => '0xCB86',
2648
-				'0x98' => '0xCB9C',		'0x91' => '0xE28098',	'0x96' => '0xE28093',
2649
-				'0xBA' => '0xC3B7',		'0x9B' => '0xE280BA',	'0xAA' => '0xC397',
2650
-				'0xA4' => '0xE282AA',	'0xE1' => '0xD791',		'0xE6' => '0xD796',
2651
-				'0xE8' => '0xD798',		'0xEB' => '0xD79B',		'0xF4' => '0xD7A4',
2610
+				'0x81' => '\'\'', '0x8A' => '\'\'', '0x8C' => '\'\'',
2611
+				'0x8D' => '\'\'', '0x8E' => '\'\'', '0x8F' => '\'\'',
2612
+				'0x90' => '\'\'', '0x9A' => '\'\'', '0x9C' => '\'\'',
2613
+				'0x9D' => '\'\'', '0x9E' => '\'\'', '0x9F' => '\'\'',
2614
+				'0xCA' => '\'\'', '0xD9' => '\'\'', '0xDA' => '\'\'',
2615
+				'0xDB' => '\'\'', '0xDC' => '\'\'', '0xDD' => '\'\'',
2616
+				'0xDE' => '\'\'', '0xDF' => '\'\'', '0xFB' => '0xD792',
2617
+				'0xFC' => '0xE282AC', '0xFF' => '0xD6B2', '0xC2' => '0xFF',
2618
+				'0x80' => '0xFC', '0xE2' => '0xFB', '0xA0' => '0xC2A0',
2619
+				'0xA1' => '0xC2A1', '0xA2' => '0xC2A2', '0xA3' => '0xC2A3',
2620
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
2621
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
2622
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
2623
+				'0xAF' => '0xC2AF', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1',
2624
+				'0xB2' => '0xC2B2', '0xB3' => '0xC2B3', '0xB4' => '0xC2B4',
2625
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
2626
+				'0xB8' => '0xC2B8', '0xB9' => '0xC2B9', '0xBB' => '0xC2BB',
2627
+				'0xBC' => '0xC2BC', '0xBD' => '0xC2BD', '0xBE' => '0xC2BE',
2628
+				'0xBF' => '0xC2BF', '0xD7' => '0xD7B3', '0xD1' => '0xD781',
2629
+				'0xD4' => '0xD7B0', '0xD5' => '0xD7B1', '0xD6' => '0xD7B2',
2630
+				'0xE0' => '0xD790', '0xEA' => '0xD79A', '0xEC' => '0xD79C',
2631
+				'0xED' => '0xD79D', '0xEE' => '0xD79E', '0xEF' => '0xD79F',
2632
+				'0xF0' => '0xD7A0', '0xF1' => '0xD7A1', '0xF2' => '0xD7A2',
2633
+				'0xF3' => '0xD7A3', '0xF5' => '0xD7A5', '0xF6' => '0xD7A6',
2634
+				'0xF7' => '0xD7A7', '0xF8' => '0xD7A8', '0xF9' => '0xD7A9',
2635
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
2636
+				'0x86' => '0xE280A0', '0x87' => '0xE280A1', '0x89' => '0xE280B0',
2637
+				'0x8B' => '0xE280B9', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
2638
+				'0x95' => '0xE280A2', '0x97' => '0xE28094', '0x99' => '0xE284A2',
2639
+				'0xC0' => '0xD6B0', '0xC1' => '0xD6B1', '0xC3' => '0xD6B3',
2640
+				'0xC4' => '0xD6B4', '0xC5' => '0xD6B5', '0xC6' => '0xD6B6',
2641
+				'0xC7' => '0xD6B7', '0xC8' => '0xD6B8', '0xC9' => '0xD6B9',
2642
+				'0xCB' => '0xD6BB', '0xCC' => '0xD6BC', '0xCD' => '0xD6BD',
2643
+				'0xCE' => '0xD6BE', '0xCF' => '0xD6BF', '0xD0' => '0xD780',
2644
+				'0xD2' => '0xD782', '0xE3' => '0xD793', '0xE4' => '0xD794',
2645
+				'0xE5' => '0xD795', '0xE7' => '0xD797', '0xE9' => '0xD799',
2646
+				'0xFD' => '0xE2808E', '0xFE' => '0xE2808F', '0x92' => '0xE28099',
2647
+				'0x83' => '0xC692', '0xD3' => '0xD783', '0x88' => '0xCB86',
2648
+				'0x98' => '0xCB9C', '0x91' => '0xE28098', '0x96' => '0xE28093',
2649
+				'0xBA' => '0xC3B7', '0x9B' => '0xE280BA', '0xAA' => '0xC397',
2650
+				'0xA4' => '0xE282AA', '0xE1' => '0xD791', '0xE6' => '0xD796',
2651
+				'0xE8' => '0xD798', '0xEB' => '0xD79B', '0xF4' => '0xD7A4',
2652 2652
 				'0xFA' => '0xD7AA',
2653 2653
 			),
2654 2654
 			'windows-1253' => array(
2655
-				'0x81' => '\'\'',			'0x88' => '\'\'',			'0x8A' => '\'\'',
2656
-				'0x8C' => '\'\'',			'0x8D' => '\'\'',			'0x8E' => '\'\'',
2657
-				'0x8F' => '\'\'',			'0x90' => '\'\'',			'0x98' => '\'\'',
2658
-				'0x9A' => '\'\'',			'0x9C' => '\'\'',			'0x9D' => '\'\'',
2659
-				'0x9E' => '\'\'',			'0x9F' => '\'\'',			'0xAA' => '\'\'',
2660
-				'0xD2' => '0xE282AC',			'0xFF' => '0xCE92',			'0xCE' => '0xCE9E',
2661
-				'0xB8' => '0xCE88',		'0xBA' => '0xCE8A',		'0xBC' => '0xCE8C',
2662
-				'0xBE' => '0xCE8E',		'0xBF' => '0xCE8F',		'0xC0' => '0xCE90',
2663
-				'0xC8' => '0xCE98',		'0xCA' => '0xCE9A',		'0xCC' => '0xCE9C',
2664
-				'0xCD' => '0xCE9D',		'0xCF' => '0xCE9F',		'0xDA' => '0xCEAA',
2665
-				'0xE8' => '0xCEB8',		'0xEA' => '0xCEBA',		'0xEC' => '0xCEBC',
2666
-				'0xEE' => '0xCEBE',		'0xEF' => '0xCEBF',		'0xC2' => '0xFF',
2667
-				'0xBD' => '0xC2BD',		'0xED' => '0xCEBD',		'0xB2' => '0xC2B2',
2668
-				'0xA0' => '0xC2A0',		'0xA3' => '0xC2A3',		'0xA4' => '0xC2A4',
2669
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
2670
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
2671
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
2672
-				'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',		'0xB3' => '0xC2B3',
2673
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
2674
-				'0xBB' => '0xC2BB',		'0xE2' => '0xCEB2',		'0x80' => '0xD2',
2675
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
2676
-				'0x86' => '0xE280A0',	'0xA1' => '0xCE85',		'0xA2' => '0xCE86',
2677
-				'0x87' => '0xE280A1',	'0x89' => '0xE280B0',	'0xB9' => '0xCE89',
2678
-				'0x8B' => '0xE280B9',	'0x91' => '0xE28098',	'0x99' => '0xE284A2',
2679
-				'0x92' => '0xE28099',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
2680
-				'0x95' => '0xE280A2',	'0x96' => '0xE28093',	'0x97' => '0xE28094',
2681
-				'0x9B' => '0xE280BA',	'0xAF' => '0xE28095',	'0xB4' => '0xCE84',
2682
-				'0xC1' => '0xCE91',		'0xC3' => '0xCE93',		'0xC4' => '0xCE94',
2683
-				'0xC5' => '0xCE95',		'0xC6' => '0xCE96',		'0x83' => '0xC692',
2684
-				'0xC7' => '0xCE97',		'0xC9' => '0xCE99',		'0xCB' => '0xCE9B',
2685
-				'0xD0' => '0xCEA0',		'0xD1' => '0xCEA1',		'0xD3' => '0xCEA3',
2686
-				'0xD4' => '0xCEA4',		'0xD5' => '0xCEA5',		'0xD6' => '0xCEA6',
2687
-				'0xD7' => '0xCEA7',		'0xD8' => '0xCEA8',		'0xD9' => '0xCEA9',
2688
-				'0xDB' => '0xCEAB',		'0xDC' => '0xCEAC',		'0xDD' => '0xCEAD',
2689
-				'0xDE' => '0xCEAE',		'0xDF' => '0xCEAF',		'0xE0' => '0xCEB0',
2690
-				'0xE1' => '0xCEB1',		'0xE3' => '0xCEB3',		'0xE4' => '0xCEB4',
2691
-				'0xE5' => '0xCEB5',		'0xE6' => '0xCEB6',		'0xE7' => '0xCEB7',
2692
-				'0xE9' => '0xCEB9',		'0xEB' => '0xCEBB',		'0xF0' => '0xCF80',
2693
-				'0xF1' => '0xCF81',		'0xF2' => '0xCF82',		'0xF3' => '0xCF83',
2694
-				'0xF4' => '0xCF84',		'0xF5' => '0xCF85',		'0xF6' => '0xCF86',
2695
-				'0xF7' => '0xCF87',		'0xF8' => '0xCF88',		'0xF9' => '0xCF89',
2696
-				'0xFA' => '0xCF8A',		'0xFB' => '0xCF8B',		'0xFC' => '0xCF8C',
2697
-				'0xFD' => '0xCF8D',		'0xFE' => '0xCF8E',
2655
+				'0x81' => '\'\'', '0x88' => '\'\'', '0x8A' => '\'\'',
2656
+				'0x8C' => '\'\'', '0x8D' => '\'\'', '0x8E' => '\'\'',
2657
+				'0x8F' => '\'\'', '0x90' => '\'\'', '0x98' => '\'\'',
2658
+				'0x9A' => '\'\'', '0x9C' => '\'\'', '0x9D' => '\'\'',
2659
+				'0x9E' => '\'\'', '0x9F' => '\'\'', '0xAA' => '\'\'',
2660
+				'0xD2' => '0xE282AC', '0xFF' => '0xCE92', '0xCE' => '0xCE9E',
2661
+				'0xB8' => '0xCE88', '0xBA' => '0xCE8A', '0xBC' => '0xCE8C',
2662
+				'0xBE' => '0xCE8E', '0xBF' => '0xCE8F', '0xC0' => '0xCE90',
2663
+				'0xC8' => '0xCE98', '0xCA' => '0xCE9A', '0xCC' => '0xCE9C',
2664
+				'0xCD' => '0xCE9D', '0xCF' => '0xCE9F', '0xDA' => '0xCEAA',
2665
+				'0xE8' => '0xCEB8', '0xEA' => '0xCEBA', '0xEC' => '0xCEBC',
2666
+				'0xEE' => '0xCEBE', '0xEF' => '0xCEBF', '0xC2' => '0xFF',
2667
+				'0xBD' => '0xC2BD', '0xED' => '0xCEBD', '0xB2' => '0xC2B2',
2668
+				'0xA0' => '0xC2A0', '0xA3' => '0xC2A3', '0xA4' => '0xC2A4',
2669
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
2670
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
2671
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
2672
+				'0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB3' => '0xC2B3',
2673
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
2674
+				'0xBB' => '0xC2BB', '0xE2' => '0xCEB2', '0x80' => '0xD2',
2675
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
2676
+				'0x86' => '0xE280A0', '0xA1' => '0xCE85', '0xA2' => '0xCE86',
2677
+				'0x87' => '0xE280A1', '0x89' => '0xE280B0', '0xB9' => '0xCE89',
2678
+				'0x8B' => '0xE280B9', '0x91' => '0xE28098', '0x99' => '0xE284A2',
2679
+				'0x92' => '0xE28099', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
2680
+				'0x95' => '0xE280A2', '0x96' => '0xE28093', '0x97' => '0xE28094',
2681
+				'0x9B' => '0xE280BA', '0xAF' => '0xE28095', '0xB4' => '0xCE84',
2682
+				'0xC1' => '0xCE91', '0xC3' => '0xCE93', '0xC4' => '0xCE94',
2683
+				'0xC5' => '0xCE95', '0xC6' => '0xCE96', '0x83' => '0xC692',
2684
+				'0xC7' => '0xCE97', '0xC9' => '0xCE99', '0xCB' => '0xCE9B',
2685
+				'0xD0' => '0xCEA0', '0xD1' => '0xCEA1', '0xD3' => '0xCEA3',
2686
+				'0xD4' => '0xCEA4', '0xD5' => '0xCEA5', '0xD6' => '0xCEA6',
2687
+				'0xD7' => '0xCEA7', '0xD8' => '0xCEA8', '0xD9' => '0xCEA9',
2688
+				'0xDB' => '0xCEAB', '0xDC' => '0xCEAC', '0xDD' => '0xCEAD',
2689
+				'0xDE' => '0xCEAE', '0xDF' => '0xCEAF', '0xE0' => '0xCEB0',
2690
+				'0xE1' => '0xCEB1', '0xE3' => '0xCEB3', '0xE4' => '0xCEB4',
2691
+				'0xE5' => '0xCEB5', '0xE6' => '0xCEB6', '0xE7' => '0xCEB7',
2692
+				'0xE9' => '0xCEB9', '0xEB' => '0xCEBB', '0xF0' => '0xCF80',
2693
+				'0xF1' => '0xCF81', '0xF2' => '0xCF82', '0xF3' => '0xCF83',
2694
+				'0xF4' => '0xCF84', '0xF5' => '0xCF85', '0xF6' => '0xCF86',
2695
+				'0xF7' => '0xCF87', '0xF8' => '0xCF88', '0xF9' => '0xCF89',
2696
+				'0xFA' => '0xCF8A', '0xFB' => '0xCF8B', '0xFC' => '0xCF8C',
2697
+				'0xFD' => '0xCF8D', '0xFE' => '0xCF8E',
2698 2698
 			),
2699 2699
 		);
2700 2700
 
Please login to merge, or discard this patch.
Braces   +854 added lines, -626 removed lines patch added patch discarded remove patch
@@ -100,11 +100,14 @@  discard block
 block discarded – undo
100 100
 	ini_set('default_socket_timeout', 900);
101 101
 }
102 102
 // Clean the upgrade path if this is from the client.
103
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
104
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
103
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
104
+	for ($i = 1;
105
+}
106
+$i < $_SERVER['argc']; $i++)
105 107
 	{
106
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
107
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
108
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
109
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
110
+		}
108 111
 	}
109 112
 
110 113
 // Are we from the client?
@@ -112,9 +115,9 @@  discard block
 block discarded – undo
112 115
 {
113 116
 	$command_line = true;
114 117
 	$disable_security = 1;
115
-}
116
-else
118
+} else {
117 119
 	$command_line = false;
120
+}
118 121
 
119 122
 // Load this now just because we can.
120 123
 require_once($upgrade_path . '/Settings.php');
@@ -125,10 +128,12 @@  discard block
 block discarded – undo
125 128
 	$upcontext['user'] = unserialize(base64_decode($upgradeData));
126 129
 
127 130
 	// Check for sensible values.
128
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
129
-		$upcontext['user']['started'] = time();
130
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
131
-		$upcontext['user']['updated'] = 0;
131
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
132
+			$upcontext['user']['started'] = time();
133
+	}
134
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
135
+			$upcontext['user']['updated'] = 0;
136
+	}
132 137
 
133 138
 	$upcontext['started'] = $upcontext['user']['started'];
134 139
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -187,8 +192,9 @@  discard block
 block discarded – undo
187 192
 			'db_error_skip' => true,
188 193
 		)
189 194
 	);
190
-	while ($row = $smcFunc['db_fetch_assoc']($request))
191
-		$modSettings[$row['variable']] = $row['value'];
195
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
196
+			$modSettings[$row['variable']] = $row['value'];
197
+	}
192 198
 	$smcFunc['db_free_result']($request);
193 199
 }
194 200
 
@@ -198,10 +204,12 @@  discard block
 block discarded – undo
198 204
 	$modSettings['theme_url'] = 'Themes/default';
199 205
 	$modSettings['images_url'] = 'Themes/default/images';
200 206
 }
201
-if (!isset($settings['default_theme_url']))
207
+if (!isset($settings['default_theme_url'])) {
202 208
 	$settings['default_theme_url'] = $modSettings['theme_url'];
203
-if (!isset($settings['default_theme_dir']))
209
+}
210
+if (!isset($settings['default_theme_dir'])) {
204 211
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
212
+}
205 213
 
206 214
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
207 215
 // Default title...
@@ -219,13 +227,15 @@  discard block
 block discarded – undo
219 227
 	$support_js = $upcontext['upgrade_status']['js'];
220 228
 
221 229
 	// Only set this if the upgrader status says so.
222
-	if (empty($is_debug))
223
-		$is_debug = $upcontext['upgrade_status']['debug'];
230
+	if (empty($is_debug)) {
231
+			$is_debug = $upcontext['upgrade_status']['debug'];
232
+	}
224 233
 
225 234
 	// Load the language.
226
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
227
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
228
-}
235
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
236
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
237
+	}
238
+	}
229 239
 // Set the defaults.
230 240
 else
231 241
 {
@@ -243,15 +253,18 @@  discard block
 block discarded – undo
243 253
 }
244 254
 
245 255
 // If this isn't the first stage see whether they are logging in and resuming.
246
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
256
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
247 257
 	checkLogin();
258
+}
248 259
 
249
-if ($command_line)
260
+if ($command_line) {
250 261
 	cmdStep0();
262
+}
251 263
 
252 264
 // Don't error if we're using xml.
253
-if (isset($_GET['xml']))
265
+if (isset($_GET['xml'])) {
254 266
 	$upcontext['return_error'] = true;
267
+}
255 268
 
256 269
 // Loop through all the steps doing each one as required.
257 270
 $upcontext['overall_percent'] = 0;
@@ -272,10 +285,11 @@  discard block
 block discarded – undo
272 285
 		}
273 286
 
274 287
 		// Call the step and if it returns false that means pause!
275
-		if (function_exists($step[2]) && $step[2]() === false)
276
-			break;
277
-		elseif (function_exists($step[2]))
278
-			$upcontext['current_step']++;
288
+		if (function_exists($step[2]) && $step[2]() === false) {
289
+					break;
290
+		} elseif (function_exists($step[2])) {
291
+					$upcontext['current_step']++;
292
+		}
279 293
 	}
280 294
 	$upcontext['overall_percent'] += $step[3];
281 295
 }
@@ -314,17 +328,18 @@  discard block
 block discarded – undo
314 328
 		// This should not happen my dear... HELP ME DEVELOPERS!!
315 329
 		if (!empty($command_line))
316 330
 		{
317
-			if (function_exists('debug_print_backtrace'))
318
-				debug_print_backtrace();
331
+			if (function_exists('debug_print_backtrace')) {
332
+							debug_print_backtrace();
333
+			}
319 334
 
320 335
 			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.';
321 336
 			flush();
322 337
 			die();
323 338
 		}
324 339
 
325
-		if (!isset($_GET['xml']))
326
-			template_upgrade_above();
327
-		else
340
+		if (!isset($_GET['xml'])) {
341
+					template_upgrade_above();
342
+		} else
328 343
 		{
329 344
 			header('Content-Type: text/xml; charset=UTF-8');
330 345
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -346,21 +361,24 @@  discard block
 block discarded – undo
346 361
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(safe_serialize($upcontext['upgrade_status']));
347 362
 
348 363
 			// Custom stuff to pass back?
349
-			if (!empty($upcontext['query_string']))
350
-				$upcontext['form_url'] .= $upcontext['query_string'];
364
+			if (!empty($upcontext['query_string'])) {
365
+							$upcontext['form_url'] .= $upcontext['query_string'];
366
+			}
351 367
 
352 368
 			call_user_func('template_' . $upcontext['sub_template']);
353 369
 		}
354 370
 
355 371
 		// Was there an error?
356
-		if (!empty($upcontext['forced_error_message']))
357
-			echo $upcontext['forced_error_message'];
372
+		if (!empty($upcontext['forced_error_message'])) {
373
+					echo $upcontext['forced_error_message'];
374
+		}
358 375
 
359 376
 		// Show the footer.
360
-		if (!isset($_GET['xml']))
361
-			template_upgrade_below();
362
-		else
363
-			template_xml_below();
377
+		if (!isset($_GET['xml'])) {
378
+					template_upgrade_below();
379
+		} else {
380
+					template_xml_below();
381
+		}
364 382
 	}
365 383
 
366 384
 
@@ -372,15 +390,19 @@  discard block
 block discarded – undo
372 390
 		$seconds = intval($active % 60);
373 391
 
374 392
 		$totalTime = '';
375
-		if ($hours > 0)
376
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
377
-		if ($minutes > 0)
378
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
379
-		if ($seconds > 0)
380
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
393
+		if ($hours > 0) {
394
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
395
+		}
396
+		if ($minutes > 0) {
397
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
398
+		}
399
+		if ($seconds > 0) {
400
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
401
+		}
381 402
 
382
-		if (!empty($totalTime))
383
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
403
+		if (!empty($totalTime)) {
404
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
405
+		}
384 406
 	}
385 407
 
386 408
 	// Bang - gone!
@@ -393,8 +415,9 @@  discard block
 block discarded – undo
393 415
 	global $upgradeurl, $upcontext, $command_line;
394 416
 
395 417
 	// Command line users can't be redirected.
396
-	if ($command_line)
397
-		upgradeExit(true);
418
+	if ($command_line) {
419
+			upgradeExit(true);
420
+	}
398 421
 
399 422
 	// Are we providing the core info?
400 423
 	if ($addForm)
@@ -417,19 +440,22 @@  discard block
 block discarded – undo
417 440
 	global $modSettings, $sourcedir, $smcFunc;
418 441
 
419 442
 	// Do the non-SSI stuff...
420
-	if (function_exists('set_magic_quotes_runtime'))
421
-		@set_magic_quotes_runtime(0);
443
+	if (function_exists('set_magic_quotes_runtime')) {
444
+			@set_magic_quotes_runtime(0);
445
+	}
422 446
 
423 447
 	error_reporting(E_ALL);
424 448
 	define('SMF', 1);
425 449
 
426 450
 	// Start the session.
427
-	if (@ini_get('session.save_handler') == 'user')
428
-		@ini_set('session.save_handler', 'files');
451
+	if (@ini_get('session.save_handler') == 'user') {
452
+			@ini_set('session.save_handler', 'files');
453
+	}
429 454
 	@session_start();
430 455
 
431
-	if (empty($smcFunc))
432
-		$smcFunc = array();
456
+	if (empty($smcFunc)) {
457
+			$smcFunc = array();
458
+	}
433 459
 
434 460
 	// We need this for authentication and some upgrade code
435 461
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -441,8 +467,9 @@  discard block
 block discarded – undo
441 467
 	initialize_inputs();
442 468
 
443 469
 	// Get the database going!
444
-	if (empty($db_type))
445
-		$db_type = 'mysql';
470
+	if (empty($db_type)) {
471
+			$db_type = 'mysql';
472
+	}
446 473
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
447 474
 	{
448 475
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -451,17 +478,19 @@  discard block
 block discarded – undo
451 478
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
452 479
 
453 480
 		// Oh dear god!!
454
-		if ($db_connection === null)
455
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
481
+		if ($db_connection === null) {
482
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
483
+		}
456 484
 
457
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
458
-			$smcFunc['db_query']('', '
485
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
486
+					$smcFunc['db_query']('', '
459 487
 			SET NAMES {string:db_character_set}',
460 488
 			array(
461 489
 				'db_error_skip' => true,
462 490
 				'db_character_set' => $db_character_set,
463 491
 			)
464 492
 		);
493
+		}
465 494
 
466 495
 		// Load the modSettings data...
467 496
 		$request = $smcFunc['db_query']('', '
@@ -472,11 +501,11 @@  discard block
 block discarded – undo
472 501
 			)
473 502
 		);
474 503
 		$modSettings = array();
475
-		while ($row = $smcFunc['db_fetch_assoc']($request))
476
-			$modSettings[$row['variable']] = $row['value'];
504
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
505
+					$modSettings[$row['variable']] = $row['value'];
506
+		}
477 507
 		$smcFunc['db_free_result']($request);
478
-	}
479
-	else
508
+	} else
480 509
 	{
481 510
 		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.');
482 511
 	}
@@ -490,9 +519,10 @@  discard block
 block discarded – undo
490 519
 		cleanRequest();
491 520
 	}
492 521
 
493
-	if (!isset($_GET['substep']))
494
-		$_GET['substep'] = 0;
495
-}
522
+	if (!isset($_GET['substep'])) {
523
+			$_GET['substep'] = 0;
524
+	}
525
+	}
496 526
 
497 527
 function initialize_inputs()
498 528
 {
@@ -522,8 +552,9 @@  discard block
 block discarded – undo
522 552
 		$dh = opendir(dirname(__FILE__));
523 553
 		while ($file = readdir($dh))
524 554
 		{
525
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
526
-				@unlink(dirname(__FILE__) . '/' . $file);
555
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
556
+							@unlink(dirname(__FILE__) . '/' . $file);
557
+			}
527 558
 		}
528 559
 		closedir($dh);
529 560
 
@@ -553,8 +584,9 @@  discard block
 block discarded – undo
553 584
 	{
554 585
 		$upcontext['remote_files_available'] = false;
555 586
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
556
-		if ($test)
557
-			$upcontext['remote_files_available'] = true;
587
+		if ($test) {
588
+					$upcontext['remote_files_available'] = true;
589
+		}
558 590
 		@fclose($test);
559 591
 	}
560 592
 
@@ -562,8 +594,9 @@  discard block
 block discarded – undo
562 594
 	$temp = 'upgrade_php?step';
563 595
 	while (strlen($temp) > 4)
564 596
 	{
565
-		if (isset($_GET[$temp]))
566
-			unset($_GET[$temp]);
597
+		if (isset($_GET[$temp])) {
598
+					unset($_GET[$temp]);
599
+		}
567 600
 		$temp = substr($temp, 1);
568 601
 	}
569 602
 
@@ -590,29 +623,36 @@  discard block
 block discarded – undo
590 623
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
591 624
 
592 625
 	// Need legacy scripts?
593
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
594
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
595
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
596
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
597
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
598
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
626
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
627
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
628
+	}
629
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
630
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
631
+	}
632
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
633
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
634
+	}
599 635
 
600 636
 	// This needs to exist!
601
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
602
-		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>]');
603
-	else
604
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
637
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
638
+			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>]');
639
+	} else {
640
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
641
+	}
605 642
 
606
-	if (!$check)
607
-		// 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.
643
+	if (!$check) {
644
+			// 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.
608 645
 		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.');
646
+	}
609 647
 
610 648
 	// Do they meet the install requirements?
611
-	if (!php_version_check())
612
-		return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
649
+	if (!php_version_check()) {
650
+			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.');
651
+	}
613 652
 
614
-	if (!db_version_check())
615
-		return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
653
+	if (!db_version_check()) {
654
+			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.');
655
+	}
616 656
 
617 657
 	// Do some checks to make sure they have proper privileges
618 658
 	db_extend('packages');
@@ -627,14 +667,16 @@  discard block
 block discarded – undo
627 667
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
628 668
 
629 669
 	// Sorry... we need CREATE, ALTER and DROP
630
-	if (!$create || !$alter || !$drop)
631
-		return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
670
+	if (!$create || !$alter || !$drop) {
671
+			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.');
672
+	}
632 673
 
633 674
 	// Do a quick version spot check.
634 675
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
635 676
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
636
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
637
-		return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
677
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
678
+			return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
679
+	}
638 680
 
639 681
 	// What absolutely needs to be writable?
640 682
 	$writable_files = array(
@@ -656,12 +698,13 @@  discard block
 block discarded – undo
656 698
 	quickFileWritable($custom_av_dir);
657 699
 
658 700
 	// Are we good now?
659
-	if (!is_writable($custom_av_dir))
660
-		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));
661
-	elseif ($need_settings_update)
701
+	if (!is_writable($custom_av_dir)) {
702
+			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));
703
+	} elseif ($need_settings_update)
662 704
 	{
663
-		if (!function_exists('cache_put_data'))
664
-			require_once($sourcedir . '/Load.php');
705
+		if (!function_exists('cache_put_data')) {
706
+					require_once($sourcedir . '/Load.php');
707
+		}
665 708
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
666 709
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
667 710
 	}
@@ -670,28 +713,33 @@  discard block
 block discarded – undo
670 713
 
671 714
 	// Check the cache directory.
672 715
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
673
-	if (!file_exists($cachedir_temp))
674
-		@mkdir($cachedir_temp);
675
-	if (!file_exists($cachedir_temp))
676
-		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.');
677
-
678
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
679
-		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>.');
680
-	elseif (!isset($_GET['skiplang']))
716
+	if (!file_exists($cachedir_temp)) {
717
+			@mkdir($cachedir_temp);
718
+	}
719
+	if (!file_exists($cachedir_temp)) {
720
+			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.');
721
+	}
722
+
723
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
724
+			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>.');
725
+	} elseif (!isset($_GET['skiplang']))
681 726
 	{
682 727
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
683 728
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
684 729
 
685
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
686
-			return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
730
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
731
+					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>]');
732
+		}
687 733
 	}
688 734
 
689
-	if (!makeFilesWritable($writable_files))
690
-		return false;
735
+	if (!makeFilesWritable($writable_files)) {
736
+			return false;
737
+	}
691 738
 
692 739
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
693
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
694
-		return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
740
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
741
+			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.');
742
+	}
695 743
 
696 744
 	// Upgrade the agreement.
697 745
 	elseif (isset($modSettings['agreement']))
@@ -702,8 +750,8 @@  discard block
 block discarded – undo
702 750
 	}
703 751
 
704 752
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
705
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
706
-		$upcontext['warning'] = '
753
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
754
+			$upcontext['warning'] = '
707 755
 			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>
708 756
 			<ul>
709 757
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -711,10 +759,12 @@  discard block
 block discarded – undo
711 759
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
712 760
 			</ul>
713 761
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="http://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
762
+	}
714 763
 
715 764
 	// Either we're logged in or we're going to present the login.
716
-	if (checkLogin())
717
-		return true;
765
+	if (checkLogin()) {
766
+			return true;
767
+	}
718 768
 
719 769
 	$upcontext += createToken('login');
720 770
 
@@ -728,15 +778,17 @@  discard block
 block discarded – undo
728 778
 	global $smcFunc, $db_type, $support_js;
729 779
 
730 780
 	// Don't bother if the security is disabled.
731
-	if ($disable_security)
732
-		return true;
781
+	if ($disable_security) {
782
+			return true;
783
+	}
733 784
 
734 785
 	// Are we trying to login?
735 786
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
736 787
 	{
737 788
 		// If we've disabled security pick a suitable name!
738
-		if (empty($_POST['user']))
739
-			$_POST['user'] = 'Administrator';
789
+		if (empty($_POST['user'])) {
790
+					$_POST['user'] = 'Administrator';
791
+		}
740 792
 
741 793
 		// Before 2.0 these column names were different!
742 794
 		$oldDB = false;
@@ -751,16 +803,17 @@  discard block
 block discarded – undo
751 803
 					'db_error_skip' => true,
752 804
 				)
753 805
 			);
754
-			if ($smcFunc['db_num_rows']($request) != 0)
755
-				$oldDB = true;
806
+			if ($smcFunc['db_num_rows']($request) != 0) {
807
+							$oldDB = true;
808
+			}
756 809
 			$smcFunc['db_free_result']($request);
757 810
 		}
758 811
 
759 812
 		// Get what we believe to be their details.
760 813
 		if (!$disable_security)
761 814
 		{
762
-			if ($oldDB)
763
-				$request = $smcFunc['db_query']('', '
815
+			if ($oldDB) {
816
+							$request = $smcFunc['db_query']('', '
764 817
 					SELECT id_member, memberName AS member_name, passwd, id_group,
765 818
 					additionalGroups AS additional_groups, lngfile
766 819
 					FROM {db_prefix}members
@@ -770,8 +823,8 @@  discard block
 block discarded – undo
770 823
 						'db_error_skip' => true,
771 824
 					)
772 825
 				);
773
-			else
774
-				$request = $smcFunc['db_query']('', '
826
+			} else {
827
+							$request = $smcFunc['db_query']('', '
775 828
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
776 829
 					FROM {db_prefix}members
777 830
 					WHERE member_name = {string:member_name}',
@@ -780,6 +833,7 @@  discard block
 block discarded – undo
780 833
 						'db_error_skip' => true,
781 834
 					)
782 835
 				);
836
+			}
783 837
 			if ($smcFunc['db_num_rows']($request) != 0)
784 838
 			{
785 839
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -787,13 +841,14 @@  discard block
 block discarded – undo
787 841
 				$groups = explode(',', $addGroups);
788 842
 				$groups[] = $id_group;
789 843
 
790
-				foreach ($groups as $k => $v)
791
-					$groups[$k] = (int) $v;
844
+				foreach ($groups as $k => $v) {
845
+									$groups[$k] = (int) $v;
846
+				}
792 847
 
793 848
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
849
+			} else {
850
+							$upcontext['username_incorrect'] = true;
794 851
 			}
795
-			else
796
-				$upcontext['username_incorrect'] = true;
797 852
 			$smcFunc['db_free_result']($request);
798 853
 		}
799 854
 		$upcontext['username'] = $_POST['user'];
@@ -803,13 +858,14 @@  discard block
 block discarded – undo
803 858
 		{
804 859
 			$upcontext['upgrade_status']['js'] = 1;
805 860
 			$support_js = 1;
861
+		} else {
862
+					$support_js = 0;
806 863
 		}
807
-		else
808
-			$support_js = 0;
809 864
 
810 865
 		// Note down the version we are coming from.
811
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
812
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
866
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
867
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
868
+		}
813 869
 
814 870
 		// Didn't get anywhere?
815 871
 		if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect']))
@@ -843,15 +899,15 @@  discard block
 block discarded – undo
843 899
 							'db_error_skip' => true,
844 900
 						)
845 901
 					);
846
-					if ($smcFunc['db_num_rows']($request) == 0)
847
-						return throw_error('You need to be an admin to perform an upgrade!');
902
+					if ($smcFunc['db_num_rows']($request) == 0) {
903
+											return throw_error('You need to be an admin to perform an upgrade!');
904
+					}
848 905
 					$smcFunc['db_free_result']($request);
849 906
 				}
850 907
 
851 908
 				$upcontext['user']['id'] = $id_member;
852 909
 				$upcontext['user']['name'] = $name;
853
-			}
854
-			else
910
+			} else
855 911
 			{
856 912
 				$upcontext['user']['id'] = 1;
857 913
 				$upcontext['user']['name'] = 'Administrator';
@@ -867,11 +923,11 @@  discard block
 block discarded – undo
867 923
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
868 924
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
869 925
 
870
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
871
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
872
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
873
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
874
-				else
926
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
927
+									$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'] . '.';
928
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
929
+									$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'] . '.';
930
+				} else
875 931
 				{
876 932
 					// Set this as the new language.
877 933
 					$upcontext['language'] = $user_language;
@@ -915,8 +971,9 @@  discard block
 block discarded – undo
915 971
 	unset($member_columns);
916 972
 
917 973
 	// If we've not submitted then we're done.
918
-	if (empty($_POST['upcont']))
919
-		return false;
974
+	if (empty($_POST['upcont'])) {
975
+			return false;
976
+	}
920 977
 
921 978
 	// Firstly, if they're enabling SM stat collection just do it.
922 979
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']))
@@ -931,25 +988,26 @@  discard block
 block discarded – undo
931 988
 			fwrite($fp, $out);
932 989
 
933 990
 			$return_data = '';
934
-			while (!feof($fp))
935
-				$return_data .= fgets($fp, 128);
991
+			while (!feof($fp)) {
992
+							$return_data .= fgets($fp, 128);
993
+			}
936 994
 
937 995
 			fclose($fp);
938 996
 
939 997
 			// Get the unique site ID.
940 998
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
941 999
 
942
-			if (!empty($ID[1]))
943
-				$smcFunc['db_insert']('replace',
1000
+			if (!empty($ID[1])) {
1001
+							$smcFunc['db_insert']('replace',
944 1002
 					$db_prefix . 'settings',
945 1003
 					array('variable' => 'string', 'value' => 'string'),
946 1004
 					array('allow_sm_stats', $ID[1]),
947 1005
 					array('variable')
948 1006
 				);
1007
+			}
949 1008
 		}
950
-	}
951
-	else
952
-		$smcFunc['db_query']('', '
1009
+	} else {
1010
+			$smcFunc['db_query']('', '
953 1011
 			DELETE FROM {db_prefix}settings
954 1012
 			WHERE variable = {string:allow_sm_stats}',
955 1013
 			array(
@@ -957,6 +1015,7 @@  discard block
 block discarded – undo
957 1015
 				'db_error_skip' => true,
958 1016
 			)
959 1017
 		);
1018
+	}
960 1019
 
961 1020
 	// Deleting old karma stuff?
962 1021
 	if (!empty($_POST['delete_karma']))
@@ -971,20 +1030,22 @@  discard block
 block discarded – undo
971 1030
 		);
972 1031
 
973 1032
 		// Cleaning up old karma member settings.
974
-		if ($upcontext['karma_installed']['good'])
975
-			$smcFunc['db_query']('', '
1033
+		if ($upcontext['karma_installed']['good']) {
1034
+					$smcFunc['db_query']('', '
976 1035
 				ALTER TABLE {db_prefix}members
977 1036
 				DROP karma_good',
978 1037
 				array()
979 1038
 			);
1039
+		}
980 1040
 
981 1041
 		// Does karma bad was enable?
982
-		if ($upcontext['karma_installed']['bad'])
983
-			$smcFunc['db_query']('', '
1042
+		if ($upcontext['karma_installed']['bad']) {
1043
+					$smcFunc['db_query']('', '
984 1044
 				ALTER TABLE {db_prefix}members
985 1045
 				DROP karma_bad',
986 1046
 				array()
987 1047
 			);
1048
+		}
988 1049
 
989 1050
 		// Cleaning up old karma permissions.
990 1051
 		$smcFunc['db_query']('', '
@@ -997,26 +1058,29 @@  discard block
 block discarded – undo
997 1058
 	}
998 1059
 
999 1060
 	// Emptying the error log?
1000
-	if (!empty($_POST['empty_error']))
1001
-		$smcFunc['db_query']('truncate_table', '
1061
+	if (!empty($_POST['empty_error'])) {
1062
+			$smcFunc['db_query']('truncate_table', '
1002 1063
 			TRUNCATE {db_prefix}log_errors',
1003 1064
 			array(
1004 1065
 			)
1005 1066
 		);
1067
+	}
1006 1068
 
1007 1069
 	$changes = array();
1008 1070
 
1009 1071
 	// Add proxy settings.
1010
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1011
-		$changes += array(
1072
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1073
+			$changes += array(
1012 1074
 			'image_proxy_secret' => substr(sha1(mt_rand()), 0, 20),
1013 1075
 			'image_proxy_maxsize' => 5190,
1014 1076
 			'image_proxy_enabled' => 0,
1015 1077
 		);
1078
+	}
1016 1079
 
1017 1080
 	// If we're overriding the language follow it through.
1018
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1019
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1081
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1082
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1083
+	}
1020 1084
 
1021 1085
 	if (!empty($_POST['maint']))
1022 1086
 	{
@@ -1028,30 +1092,34 @@  discard block
 block discarded – undo
1028 1092
 		{
1029 1093
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1030 1094
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1031
-		}
1032
-		else
1095
+		} else
1033 1096
 		{
1034 1097
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1035 1098
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1036 1099
 		}
1037 1100
 	}
1038 1101
 
1039
-	if ($command_line)
1040
-		echo ' * Updating Settings.php...';
1102
+	if ($command_line) {
1103
+			echo ' * Updating Settings.php...';
1104
+	}
1041 1105
 
1042 1106
 	// Fix some old paths.
1043
-	if (substr($boarddir, 0, 1) == '.')
1044
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1107
+	if (substr($boarddir, 0, 1) == '.') {
1108
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1109
+	}
1045 1110
 
1046
-	if (substr($sourcedir, 0, 1) == '.')
1047
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1111
+	if (substr($sourcedir, 0, 1) == '.') {
1112
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1113
+	}
1048 1114
 
1049
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1050
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1115
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1116
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1117
+	}
1051 1118
 
1052 1119
 	// Not had the database type added before?
1053
-	if (empty($db_type))
1054
-		$changes['db_type'] = 'mysql';
1120
+	if (empty($db_type)) {
1121
+			$changes['db_type'] = 'mysql';
1122
+	}
1055 1123
 
1056 1124
 	// If they have a "host:port" setup for the host, split that into separate values
1057 1125
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1062,28 +1130,31 @@  discard block
 block discarded – undo
1062 1130
 		$changes['db_server'] = '\'' . $db_server . '\'';
1063 1131
 
1064 1132
 		// Only set this if we're not using the default port
1065
-		if ($db_port != ini_get('mysqli.default_port'))
1066
-			$changes['db_port'] = (int) $db_port;
1067
-	}
1068
-	elseif (!empty($db_port))
1133
+		if ($db_port != ini_get('mysqli.default_port')) {
1134
+					$changes['db_port'] = (int) $db_port;
1135
+		}
1136
+	} elseif (!empty($db_port))
1069 1137
 	{
1070 1138
 		// If db_port is set and is the same as the default, set it to ''
1071 1139
 		if ($db_type == 'mysql')
1072 1140
 		{
1073
-			if ($db_port == ini_get('mysqli.default_port'))
1074
-				$changes['db_port'] = '\'\'';
1075
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1076
-				$changes['db_port'] = '\'\'';
1141
+			if ($db_port == ini_get('mysqli.default_port')) {
1142
+							$changes['db_port'] = '\'\'';
1143
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1144
+							$changes['db_port'] = '\'\'';
1145
+			}
1077 1146
 		}
1078 1147
 	}
1079 1148
 
1080 1149
 	// Maybe we haven't had this option yet?
1081
-	if (empty($packagesdir))
1082
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1150
+	if (empty($packagesdir)) {
1151
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1152
+	}
1083 1153
 
1084 1154
 	// Add support for $tasksdir var.
1085
-	if (empty($tasksdir))
1086
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1155
+	if (empty($tasksdir)) {
1156
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1157
+	}
1087 1158
 
1088 1159
 	// @todo Maybe change the cookie name if going to 1.1, too?
1089 1160
 
@@ -1091,8 +1162,9 @@  discard block
 block discarded – undo
1091 1162
 	require_once($sourcedir . '/Subs-Admin.php');
1092 1163
 	updateSettingsFile($changes);
1093 1164
 
1094
-	if ($command_line)
1095
-		echo ' Successful.' . "\n";
1165
+	if ($command_line) {
1166
+			echo ' Successful.' . "\n";
1167
+	}
1096 1168
 
1097 1169
 	// Are we doing debug?
1098 1170
 	if (isset($_POST['debug']))
@@ -1102,8 +1174,9 @@  discard block
 block discarded – undo
1102 1174
 	}
1103 1175
 
1104 1176
 	// If we're not backing up then jump one.
1105
-	if (empty($_POST['backup']))
1106
-		$upcontext['current_step']++;
1177
+	if (empty($_POST['backup'])) {
1178
+			$upcontext['current_step']++;
1179
+	}
1107 1180
 
1108 1181
 	// If we've got here then let's proceed to the next step!
1109 1182
 	return true;
@@ -1118,8 +1191,9 @@  discard block
 block discarded – undo
1118 1191
 	$upcontext['page_title'] = 'Backup Database';
1119 1192
 
1120 1193
 	// Done it already - js wise?
1121
-	if (!empty($_POST['backup_done']))
1122
-		return true;
1194
+	if (!empty($_POST['backup_done'])) {
1195
+			return true;
1196
+	}
1123 1197
 
1124 1198
 	// Some useful stuff here.
1125 1199
 	db_extend();
@@ -1133,9 +1207,10 @@  discard block
 block discarded – undo
1133 1207
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1134 1208
 
1135 1209
 	$table_names = array();
1136
-	foreach ($tables as $table)
1137
-		if (substr($table, 0, 7) !== 'backup_')
1210
+	foreach ($tables as $table) {
1211
+			if (substr($table, 0, 7) !== 'backup_')
1138 1212
 			$table_names[] = $table;
1213
+	}
1139 1214
 
1140 1215
 	$upcontext['table_count'] = count($table_names);
1141 1216
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1145,12 +1220,14 @@  discard block
 block discarded – undo
1145 1220
 	$file_steps = $upcontext['table_count'];
1146 1221
 
1147 1222
 	// What ones have we already done?
1148
-	foreach ($table_names as $id => $table)
1149
-		if ($id < $_GET['substep'])
1223
+	foreach ($table_names as $id => $table) {
1224
+			if ($id < $_GET['substep'])
1150 1225
 			$upcontext['previous_tables'][] = $table;
1226
+	}
1151 1227
 
1152
-	if ($command_line)
1153
-		echo 'Backing Up Tables.';
1228
+	if ($command_line) {
1229
+			echo 'Backing Up Tables.';
1230
+	}
1154 1231
 
1155 1232
 	// If we don't support javascript we backup here.
1156 1233
 	if (!$support_js || isset($_GET['xml']))
@@ -1169,8 +1246,9 @@  discard block
 block discarded – undo
1169 1246
 			backupTable($table_names[$substep]);
1170 1247
 
1171 1248
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1172
-			if (isset($_GET['xml']))
1173
-				return upgradeExit();
1249
+			if (isset($_GET['xml'])) {
1250
+							return upgradeExit();
1251
+			}
1174 1252
 		}
1175 1253
 
1176 1254
 		if ($command_line)
@@ -1203,9 +1281,10 @@  discard block
 block discarded – undo
1203 1281
 
1204 1282
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1205 1283
 
1206
-	if ($command_line)
1207
-		echo ' done.';
1208
-}
1284
+	if ($command_line) {
1285
+			echo ' done.';
1286
+	}
1287
+	}
1209 1288
 
1210 1289
 // Step 2: Everything.
1211 1290
 function DatabaseChanges()
@@ -1214,8 +1293,9 @@  discard block
 block discarded – undo
1214 1293
 	global $upcontext, $support_js, $db_type;
1215 1294
 
1216 1295
 	// Have we just completed this?
1217
-	if (!empty($_POST['database_done']))
1218
-		return true;
1296
+	if (!empty($_POST['database_done'])) {
1297
+			return true;
1298
+	}
1219 1299
 
1220 1300
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1221 1301
 	$upcontext['page_title'] = 'Database Changes';
@@ -1230,15 +1310,16 @@  discard block
 block discarded – undo
1230 1310
 	);
1231 1311
 
1232 1312
 	// How many files are there in total?
1233
-	if (isset($_GET['filecount']))
1234
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1235
-	else
1313
+	if (isset($_GET['filecount'])) {
1314
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1315
+	} else
1236 1316
 	{
1237 1317
 		$upcontext['file_count'] = 0;
1238 1318
 		foreach ($files as $file)
1239 1319
 		{
1240
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1241
-				$upcontext['file_count']++;
1320
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1321
+							$upcontext['file_count']++;
1322
+			}
1242 1323
 		}
1243 1324
 	}
1244 1325
 
@@ -1248,9 +1329,9 @@  discard block
 block discarded – undo
1248 1329
 	$upcontext['cur_file_num'] = 0;
1249 1330
 	foreach ($files as $file)
1250 1331
 	{
1251
-		if ($did_not_do)
1252
-			$did_not_do--;
1253
-		else
1332
+		if ($did_not_do) {
1333
+					$did_not_do--;
1334
+		} else
1254 1335
 		{
1255 1336
 			$upcontext['cur_file_num']++;
1256 1337
 			$upcontext['cur_file_name'] = $file[0];
@@ -1277,12 +1358,13 @@  discard block
 block discarded – undo
1277 1358
 					// Flag to move on to the next.
1278 1359
 					$upcontext['completed_step'] = true;
1279 1360
 					// Did we complete the whole file?
1280
-					if ($nextFile)
1281
-						$upcontext['current_debug_item_num'] = -1;
1361
+					if ($nextFile) {
1362
+											$upcontext['current_debug_item_num'] = -1;
1363
+					}
1282 1364
 					return upgradeExit();
1365
+				} elseif ($support_js) {
1366
+									break;
1283 1367
 				}
1284
-				elseif ($support_js)
1285
-					break;
1286 1368
 			}
1287 1369
 			// Set the progress bar to be right as if we had - even if we hadn't...
1288 1370
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1307,8 +1389,9 @@  discard block
 block discarded – undo
1307 1389
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1308 1390
 
1309 1391
 	// Now it's nice to have some of the basic SMF source files.
1310
-	if (!isset($_GET['ssi']) && !$command_line)
1311
-		redirectLocation('&ssi=1');
1392
+	if (!isset($_GET['ssi']) && !$command_line) {
1393
+			redirectLocation('&ssi=1');
1394
+	}
1312 1395
 
1313 1396
 	$upcontext['sub_template'] = 'upgrade_complete';
1314 1397
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1324,14 +1407,16 @@  discard block
 block discarded – undo
1324 1407
 	// Are we in maintenance mode?
1325 1408
 	if (isset($upcontext['user']['main']))
1326 1409
 	{
1327
-		if ($command_line)
1328
-			echo ' * ';
1410
+		if ($command_line) {
1411
+					echo ' * ';
1412
+		}
1329 1413
 		$upcontext['removed_maintenance'] = true;
1330 1414
 		$changes['maintenance'] = $upcontext['user']['main'];
1331 1415
 	}
1332 1416
 	// Otherwise if somehow we are in 2 let's go to 1.
1333
-	elseif (!empty($maintenance) && $maintenance == 2)
1334
-		$changes['maintenance'] = 1;
1417
+	elseif (!empty($maintenance) && $maintenance == 2) {
1418
+			$changes['maintenance'] = 1;
1419
+	}
1335 1420
 
1336 1421
 	// Wipe this out...
1337 1422
 	$upcontext['user'] = array();
@@ -1346,9 +1431,9 @@  discard block
 block discarded – undo
1346 1431
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1347 1432
 
1348 1433
 	// Now is the perfect time to fetch the SM files.
1349
-	if ($command_line)
1350
-		cli_scheduled_fetchSMfiles();
1351
-	else
1434
+	if ($command_line) {
1435
+			cli_scheduled_fetchSMfiles();
1436
+	} else
1352 1437
 	{
1353 1438
 		require_once($sourcedir . '/ScheduledTasks.php');
1354 1439
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1356,8 +1441,9 @@  discard block
 block discarded – undo
1356 1441
 	}
1357 1442
 
1358 1443
 	// Log what we've done.
1359
-	if (empty($user_info['id']))
1360
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1444
+	if (empty($user_info['id'])) {
1445
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1446
+	}
1361 1447
 
1362 1448
 	// Log the action manually, so CLI still works.
1363 1449
 	$smcFunc['db_insert']('',
@@ -1376,8 +1462,9 @@  discard block
 block discarded – undo
1376 1462
 
1377 1463
 	// Save the current database version.
1378 1464
 	$server_version = $smcFunc['db_server_info']();
1379
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1380
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1465
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1466
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1467
+	}
1381 1468
 
1382 1469
 	if ($command_line)
1383 1470
 	{
@@ -1389,8 +1476,9 @@  discard block
 block discarded – undo
1389 1476
 
1390 1477
 	// Make sure it says we're done.
1391 1478
 	$upcontext['overall_percent'] = 100;
1392
-	if (isset($upcontext['step_progress']))
1393
-		unset($upcontext['step_progress']);
1479
+	if (isset($upcontext['step_progress'])) {
1480
+			unset($upcontext['step_progress']);
1481
+	}
1394 1482
 
1395 1483
 	$_GET['substep'] = 0;
1396 1484
 	return false;
@@ -1401,8 +1489,9 @@  discard block
 block discarded – undo
1401 1489
 {
1402 1490
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1403 1491
 
1404
-	if (empty($modSettings['time_format']))
1405
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1492
+	if (empty($modSettings['time_format'])) {
1493
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1494
+	}
1406 1495
 
1407 1496
 	// What files do we want to get
1408 1497
 	$request = $smcFunc['db_query']('', '
@@ -1436,8 +1525,9 @@  discard block
 block discarded – undo
1436 1525
 		$file_data = fetch_web_data($url);
1437 1526
 
1438 1527
 		// If we got an error - give up - the site might be down.
1439
-		if ($file_data === false)
1440
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1528
+		if ($file_data === false) {
1529
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1530
+		}
1441 1531
 
1442 1532
 		// Save the file to the database.
1443 1533
 		$smcFunc['db_query']('substring', '
@@ -1479,8 +1569,9 @@  discard block
 block discarded – undo
1479 1569
 	$themeData = array();
1480 1570
 	foreach ($values as $variable => $value)
1481 1571
 	{
1482
-		if (!isset($value) || $value === null)
1483
-			$value = 0;
1572
+		if (!isset($value) || $value === null) {
1573
+					$value = 0;
1574
+		}
1484 1575
 
1485 1576
 		$themeData[] = array(0, 1, $variable, $value);
1486 1577
 	}
@@ -1509,8 +1600,9 @@  discard block
 block discarded – undo
1509 1600
 
1510 1601
 	foreach ($values as $variable => $value)
1511 1602
 	{
1512
-		if (empty($modSettings[$value[0]]))
1513
-			continue;
1603
+		if (empty($modSettings[$value[0]])) {
1604
+					continue;
1605
+		}
1514 1606
 
1515 1607
 		$smcFunc['db_query']('', '
1516 1608
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1596,10 +1688,11 @@  discard block
 block discarded – undo
1596 1688
 	set_error_handler(
1597 1689
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1598 1690
 		{
1599
-			if ($support_js)
1600
-				return true;
1601
-			else
1602
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1691
+			if ($support_js) {
1692
+							return true;
1693
+			} else {
1694
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1695
+			}
1603 1696
 		}
1604 1697
 	);
1605 1698
 
@@ -1614,8 +1707,9 @@  discard block
 block discarded – undo
1614 1707
 				'db_error_skip' => true,
1615 1708
 			)
1616 1709
 		);
1617
-		if ($smcFunc['db_num_rows']($request) === 0)
1618
-			die('Unable to find members table!');
1710
+		if ($smcFunc['db_num_rows']($request) === 0) {
1711
+					die('Unable to find members table!');
1712
+		}
1619 1713
 		$table_status = $smcFunc['db_fetch_assoc']($request);
1620 1714
 		$smcFunc['db_free_result']($request);
1621 1715
 
@@ -1630,17 +1724,20 @@  discard block
 block discarded – undo
1630 1724
 				)
1631 1725
 			);
1632 1726
 			// Got something?
1633
-			if ($smcFunc['db_num_rows']($request) !== 0)
1634
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
1727
+			if ($smcFunc['db_num_rows']($request) !== 0) {
1728
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
1729
+			}
1635 1730
 			$smcFunc['db_free_result']($request);
1636 1731
 
1637 1732
 			// Excellent!
1638
-			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset']))
1639
-				$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1733
+			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) {
1734
+							$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1735
+			}
1640 1736
 		}
1641 1737
 	}
1642
-	if (empty($db_collation))
1643
-		$db_collation = '';
1738
+	if (empty($db_collation)) {
1739
+			$db_collation = '';
1740
+	}
1644 1741
 
1645 1742
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1646 1743
 
@@ -1652,8 +1749,9 @@  discard block
 block discarded – undo
1652 1749
 	$last_step = '';
1653 1750
 
1654 1751
 	// Make sure all newly created tables will have the proper characters set.
1655
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1656
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1752
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1753
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1754
+	}
1657 1755
 
1658 1756
 	// Count the total number of steps within this file - for progress.
1659 1757
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1673,15 +1771,18 @@  discard block
 block discarded – undo
1673 1771
 		$do_current = $substep >= $_GET['substep'];
1674 1772
 
1675 1773
 		// Get rid of any comments in the beginning of the line...
1676
-		if (substr(trim($line), 0, 2) === '/*')
1677
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1774
+		if (substr(trim($line), 0, 2) === '/*') {
1775
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1776
+		}
1678 1777
 
1679 1778
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1680
-		if ($is_debug && !$support_js && $command_line)
1681
-			flush();
1779
+		if ($is_debug && !$support_js && $command_line) {
1780
+					flush();
1781
+		}
1682 1782
 
1683
-		if (trim($line) === '')
1684
-			continue;
1783
+		if (trim($line) === '') {
1784
+					continue;
1785
+		}
1685 1786
 
1686 1787
 		if (trim(substr($line, 0, 3)) === '---')
1687 1788
 		{
@@ -1691,8 +1792,9 @@  discard block
 block discarded – undo
1691 1792
 			if (trim($current_data) != '' && $type !== '}')
1692 1793
 			{
1693 1794
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1694
-				if ($command_line)
1695
-					echo $upcontext['error_message'];
1795
+				if ($command_line) {
1796
+									echo $upcontext['error_message'];
1797
+				}
1696 1798
 			}
1697 1799
 
1698 1800
 			if ($type == ' ')
@@ -1710,17 +1812,18 @@  discard block
 block discarded – undo
1710 1812
 				if ($do_current)
1711 1813
 				{
1712 1814
 					$upcontext['actioned_items'][] = $last_step;
1713
-					if ($command_line)
1714
-						echo ' * ';
1815
+					if ($command_line) {
1816
+											echo ' * ';
1817
+					}
1715 1818
 				}
1716
-			}
1717
-			elseif ($type == '#')
1819
+			} elseif ($type == '#')
1718 1820
 			{
1719 1821
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1720 1822
 
1721 1823
 				$upcontext['current_debug_item_num']++;
1722
-				if (trim($line) != '---#')
1723
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1824
+				if (trim($line) != '---#') {
1825
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1826
+				}
1724 1827
 
1725 1828
 				// Have we already done something?
1726 1829
 				if (isset($_GET['xml']) && $done_something)
@@ -1731,34 +1834,36 @@  discard block
 block discarded – undo
1731 1834
 
1732 1835
 				if ($do_current)
1733 1836
 				{
1734
-					if (trim($line) == '---#' && $command_line)
1735
-						echo ' done.', $endl;
1736
-					elseif ($command_line)
1737
-						echo ' +++ ', rtrim(substr($line, 4));
1738
-					elseif (trim($line) != '---#')
1837
+					if (trim($line) == '---#' && $command_line) {
1838
+											echo ' done.', $endl;
1839
+					} elseif ($command_line) {
1840
+											echo ' +++ ', rtrim(substr($line, 4));
1841
+					} elseif (trim($line) != '---#')
1739 1842
 					{
1740
-						if ($is_debug)
1741
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1843
+						if ($is_debug) {
1844
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1845
+						}
1742 1846
 					}
1743 1847
 				}
1744 1848
 
1745 1849
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1746 1850
 				{
1747
-					if ($command_line)
1748
-						echo ' * ';
1749
-					else
1750
-						$upcontext['actioned_items'][] = $last_step;
1851
+					if ($command_line) {
1852
+											echo ' * ';
1853
+					} else {
1854
+											$upcontext['actioned_items'][] = $last_step;
1855
+					}
1751 1856
 				}
1752 1857
 
1753 1858
 				// Small step - only if we're actually doing stuff.
1754
-				if ($do_current)
1755
-					nextSubstep(++$substep);
1756
-				else
1757
-					$substep++;
1758
-			}
1759
-			elseif ($type == '{')
1760
-				$current_type = 'code';
1761
-			elseif ($type == '}')
1859
+				if ($do_current) {
1860
+									nextSubstep(++$substep);
1861
+				} else {
1862
+									$substep++;
1863
+				}
1864
+			} elseif ($type == '{') {
1865
+							$current_type = 'code';
1866
+			} elseif ($type == '}')
1762 1867
 			{
1763 1868
 				$current_type = 'sql';
1764 1869
 
@@ -1771,8 +1876,9 @@  discard block
 block discarded – undo
1771 1876
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1772 1877
 				{
1773 1878
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1774
-					if ($command_line)
1775
-						echo $upcontext['error_message'];
1879
+					if ($command_line) {
1880
+											echo $upcontext['error_message'];
1881
+					}
1776 1882
 				}
1777 1883
 
1778 1884
 				// Done with code!
@@ -1852,8 +1958,9 @@  discard block
 block discarded – undo
1852 1958
 	$db_unbuffered = false;
1853 1959
 
1854 1960
 	// Failure?!
1855
-	if ($result !== false)
1856
-		return $result;
1961
+	if ($result !== false) {
1962
+			return $result;
1963
+	}
1857 1964
 
1858 1965
 	$db_error_message = $smcFunc['db_error']($db_connection);
1859 1966
 	// If MySQL we do something more clever.
@@ -1881,54 +1988,61 @@  discard block
 block discarded – undo
1881 1988
 			{
1882 1989
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1883 1990
 				$result = mysqli_query($db_connection, $string);
1884
-				if ($result !== false)
1885
-					return $result;
1991
+				if ($result !== false) {
1992
+									return $result;
1993
+				}
1886 1994
 			}
1887
-		}
1888
-		elseif ($mysqli_errno == 2013)
1995
+		} elseif ($mysqli_errno == 2013)
1889 1996
 		{
1890 1997
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1891 1998
 			mysqli_select_db($db_connection, $db_name);
1892 1999
 			if ($db_connection)
1893 2000
 			{
1894 2001
 				$result = mysqli_query($db_connection, $string);
1895
-				if ($result !== false)
1896
-					return $result;
2002
+				if ($result !== false) {
2003
+									return $result;
2004
+				}
1897 2005
 			}
1898 2006
 		}
1899 2007
 		// Duplicate column name... should be okay ;).
1900
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1901
-			return false;
2008
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2009
+					return false;
2010
+		}
1902 2011
 		// Duplicate insert... make sure it's the proper type of query ;).
1903
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1904
-			return false;
2012
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2013
+					return false;
2014
+		}
1905 2015
 		// Creating an index on a non-existent column.
1906
-		elseif ($mysqli_errno == 1072)
1907
-			return false;
1908
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1909
-			return false;
2016
+		elseif ($mysqli_errno == 1072) {
2017
+					return false;
2018
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2019
+					return false;
2020
+		}
1910 2021
 	}
1911 2022
 	// If a table already exists don't go potty.
1912 2023
 	else
1913 2024
 	{
1914 2025
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1915 2026
 		{
1916
-			if (strpos($db_error_message, 'exist') !== false)
1917
-				return true;
1918
-		}
1919
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2027
+			if (strpos($db_error_message, 'exist') !== false) {
2028
+							return true;
2029
+			}
2030
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1920 2031
 		{
1921
-			if (strpos($db_error_message, 'duplicate') !== false)
1922
-				return true;
2032
+			if (strpos($db_error_message, 'duplicate') !== false) {
2033
+							return true;
2034
+			}
1923 2035
 		}
1924 2036
 	}
1925 2037
 
1926 2038
 	// Get the query string so we pass everything.
1927 2039
 	$query_string = '';
1928
-	foreach ($_GET as $k => $v)
1929
-		$query_string .= ';' . $k . '=' . $v;
1930
-	if (strlen($query_string) != 0)
1931
-		$query_string = '?' . substr($query_string, 1);
2040
+	foreach ($_GET as $k => $v) {
2041
+			$query_string .= ';' . $k . '=' . $v;
2042
+	}
2043
+	if (strlen($query_string) != 0) {
2044
+			$query_string = '?' . substr($query_string, 1);
2045
+	}
1932 2046
 
1933 2047
 	if ($command_line)
1934 2048
 	{
@@ -1983,16 +2097,18 @@  discard block
 block discarded – undo
1983 2097
 			{
1984 2098
 				$found |= 1;
1985 2099
 				// Do some checks on the data if we have it set.
1986
-				if (isset($change['col_type']))
1987
-					$found &= $change['col_type'] === $column['type'];
1988
-				if (isset($change['null_allowed']))
1989
-					$found &= $column['null'] == $change['null_allowed'];
1990
-				if (isset($change['default']))
1991
-					$found &= $change['default'] === $column['default'];
2100
+				if (isset($change['col_type'])) {
2101
+									$found &= $change['col_type'] === $column['type'];
2102
+				}
2103
+				if (isset($change['null_allowed'])) {
2104
+									$found &= $column['null'] == $change['null_allowed'];
2105
+				}
2106
+				if (isset($change['default'])) {
2107
+									$found &= $change['default'] === $column['default'];
2108
+				}
1992 2109
 			}
1993 2110
 		}
1994
-	}
1995
-	elseif ($change['type'] === 'index')
2111
+	} elseif ($change['type'] === 'index')
1996 2112
 	{
1997 2113
 		$request = upgrade_query('
1998 2114
 			SHOW INDEX
@@ -2001,9 +2117,10 @@  discard block
 block discarded – undo
2001 2117
 		{
2002 2118
 			$cur_index = array();
2003 2119
 
2004
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2005
-				if ($row['Key_name'] === $change['name'])
2120
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2121
+							if ($row['Key_name'] === $change['name'])
2006 2122
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2123
+			}
2007 2124
 
2008 2125
 			ksort($cur_index, SORT_NUMERIC);
2009 2126
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2013,14 +2130,17 @@  discard block
 block discarded – undo
2013 2130
 	}
2014 2131
 
2015 2132
 	// If we're trying to add and it's added, we're done.
2016
-	if ($found && in_array($change['method'], array('add', 'change')))
2017
-		return true;
2133
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2134
+			return true;
2135
+	}
2018 2136
 	// Otherwise if we're removing and it wasn't found we're also done.
2019
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2020
-		return true;
2137
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2138
+			return true;
2139
+	}
2021 2140
 	// Otherwise is it just a test?
2022
-	elseif ($is_test)
2023
-		return false;
2141
+	elseif ($is_test) {
2142
+			return false;
2143
+	}
2024 2144
 
2025 2145
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2026 2146
 	$running = false;
@@ -2031,8 +2151,9 @@  discard block
 block discarded – undo
2031 2151
 			SHOW FULL PROCESSLIST');
2032 2152
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2033 2153
 		{
2034
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2035
-				$found = true;
2154
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2155
+							$found = true;
2156
+			}
2036 2157
 		}
2037 2158
 
2038 2159
 		// Can't find it? Then we need to run it fools!
@@ -2044,8 +2165,9 @@  discard block
 block discarded – undo
2044 2165
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2045 2166
 				' . $change['text'], true) !== false;
2046 2167
 
2047
-			if (!$success)
2048
-				return false;
2168
+			if (!$success) {
2169
+							return false;
2170
+			}
2049 2171
 
2050 2172
 			// Return
2051 2173
 			$running = true;
@@ -2087,8 +2209,9 @@  discard block
 block discarded – undo
2087 2209
 			'db_error_skip' => true,
2088 2210
 		)
2089 2211
 	);
2090
-	if ($smcFunc['db_num_rows']($request) === 0)
2091
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2212
+	if ($smcFunc['db_num_rows']($request) === 0) {
2213
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2214
+	}
2092 2215
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2093 2216
 	$smcFunc['db_free_result']($request);
2094 2217
 
@@ -2110,18 +2233,19 @@  discard block
 block discarded – undo
2110 2233
 			)
2111 2234
 		);
2112 2235
 		// No results? Just forget it all together.
2113
-		if ($smcFunc['db_num_rows']($request) === 0)
2114
-			unset($table_row['Collation']);
2115
-		else
2116
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2236
+		if ($smcFunc['db_num_rows']($request) === 0) {
2237
+					unset($table_row['Collation']);
2238
+		} else {
2239
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2240
+		}
2117 2241
 		$smcFunc['db_free_result']($request);
2118 2242
 	}
2119 2243
 
2120 2244
 	if ($column_fix)
2121 2245
 	{
2122 2246
 		// Make sure there are no NULL's left.
2123
-		if ($null_fix)
2124
-			$smcFunc['db_query']('', '
2247
+		if ($null_fix) {
2248
+					$smcFunc['db_query']('', '
2125 2249
 				UPDATE {db_prefix}' . $change['table'] . '
2126 2250
 				SET ' . $change['column'] . ' = {string:default}
2127 2251
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2130,6 +2254,7 @@  discard block
 block discarded – undo
2130 2254
 					'db_error_skip' => true,
2131 2255
 				)
2132 2256
 			);
2257
+		}
2133 2258
 
2134 2259
 		// Do the actual alteration.
2135 2260
 		$smcFunc['db_query']('', '
@@ -2158,8 +2283,9 @@  discard block
 block discarded – undo
2158 2283
 	}
2159 2284
 
2160 2285
 	// Not a column we need to check on?
2161
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2162
-		return;
2286
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2287
+			return;
2288
+	}
2163 2289
 
2164 2290
 	// Break it up you (six|seven).
2165 2291
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2178,13 +2304,13 @@  discard block
 block discarded – undo
2178 2304
 				'new_name' => $temp[2],
2179 2305
 		));
2180 2306
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2181
-		if ($smcFunc['db_num_rows'] != 1)
2182
-			return;
2307
+		if ($smcFunc['db_num_rows'] != 1) {
2308
+					return;
2309
+		}
2183 2310
 
2184 2311
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2185 2312
 		$smcFunc['db_free_result']($request);
2186
-	}
2187
-	else
2313
+	} else
2188 2314
 	{
2189 2315
 		// Do this the old fashion, sure method way.
2190 2316
 		$request = $smcFunc['db_query']('', '
@@ -2195,21 +2321,24 @@  discard block
 block discarded – undo
2195 2321
 		));
2196 2322
 		// Mayday!
2197 2323
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2198
-		if ($smcFunc['db_num_rows'] == 0)
2199
-			return;
2324
+		if ($smcFunc['db_num_rows'] == 0) {
2325
+					return;
2326
+		}
2200 2327
 
2201 2328
 		// Oh where, oh where has my little field gone. Oh where can it be...
2202
-		while ($row = $smcFunc['db_query']($request))
2203
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2329
+		while ($row = $smcFunc['db_query']($request)) {
2330
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2204 2331
 			{
2205 2332
 				$current_type = $row['Type'];
2333
+		}
2206 2334
 				break;
2207 2335
 			}
2208 2336
 	}
2209 2337
 
2210 2338
 	// If this doesn't match, the column may of been altered for a reason.
2211
-	if (trim($current_type) != trim($temp[3]))
2212
-		$temp[3] = $current_type;
2339
+	if (trim($current_type) != trim($temp[3])) {
2340
+			$temp[3] = $current_type;
2341
+	}
2213 2342
 
2214 2343
 	// Piece this back together.
2215 2344
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2221,8 +2350,9 @@  discard block
 block discarded – undo
2221 2350
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2222 2351
 	global $step_progress, $is_debug, $upcontext;
2223 2352
 
2224
-	if ($_GET['substep'] < $substep)
2225
-		$_GET['substep'] = $substep;
2353
+	if ($_GET['substep'] < $substep) {
2354
+			$_GET['substep'] = $substep;
2355
+	}
2226 2356
 
2227 2357
 	if ($command_line)
2228 2358
 	{
@@ -2235,29 +2365,33 @@  discard block
 block discarded – undo
2235 2365
 	}
2236 2366
 
2237 2367
 	@set_time_limit(300);
2238
-	if (function_exists('apache_reset_timeout'))
2239
-		@apache_reset_timeout();
2368
+	if (function_exists('apache_reset_timeout')) {
2369
+			@apache_reset_timeout();
2370
+	}
2240 2371
 
2241
-	if (time() - $start_time <= $timeLimitThreshold)
2242
-		return;
2372
+	if (time() - $start_time <= $timeLimitThreshold) {
2373
+			return;
2374
+	}
2243 2375
 
2244 2376
 	// Do we have some custom step progress stuff?
2245 2377
 	if (!empty($step_progress))
2246 2378
 	{
2247 2379
 		$upcontext['substep_progress'] = 0;
2248 2380
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2249
-		if ($step_progress['current'] > $step_progress['total'])
2250
-			$upcontext['substep_progress'] = 99.9;
2251
-		else
2252
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2381
+		if ($step_progress['current'] > $step_progress['total']) {
2382
+					$upcontext['substep_progress'] = 99.9;
2383
+		} else {
2384
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2385
+		}
2253 2386
 
2254 2387
 		// Make it nicely rounded.
2255 2388
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2256 2389
 	}
2257 2390
 
2258 2391
 	// If this is XML we just exit right away!
2259
-	if (isset($_GET['xml']))
2260
-		return upgradeExit();
2392
+	if (isset($_GET['xml'])) {
2393
+			return upgradeExit();
2394
+	}
2261 2395
 
2262 2396
 	// We're going to pause after this!
2263 2397
 	$upcontext['pause'] = true;
@@ -2265,13 +2399,15 @@  discard block
 block discarded – undo
2265 2399
 	$upcontext['query_string'] = '';
2266 2400
 	foreach ($_GET as $k => $v)
2267 2401
 	{
2268
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2269
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2402
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2403
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2404
+		}
2270 2405
 	}
2271 2406
 
2272 2407
 	// Custom warning?
2273
-	if (!empty($custom_warning))
2274
-		$upcontext['custom_warning'] = $custom_warning;
2408
+	if (!empty($custom_warning)) {
2409
+			$upcontext['custom_warning'] = $custom_warning;
2410
+	}
2275 2411
 
2276 2412
 	upgradeExit();
2277 2413
 }
@@ -2286,25 +2422,26 @@  discard block
 block discarded – undo
2286 2422
 	ob_implicit_flush(true);
2287 2423
 	@set_time_limit(600);
2288 2424
 
2289
-	if (!isset($_SERVER['argv']))
2290
-		$_SERVER['argv'] = array();
2425
+	if (!isset($_SERVER['argv'])) {
2426
+			$_SERVER['argv'] = array();
2427
+	}
2291 2428
 	$_GET['maint'] = 1;
2292 2429
 
2293 2430
 	foreach ($_SERVER['argv'] as $i => $arg)
2294 2431
 	{
2295
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2296
-			$_GET['lang'] = $match[1];
2297
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2298
-			continue;
2299
-		elseif ($arg == '--no-maintenance')
2300
-			$_GET['maint'] = 0;
2301
-		elseif ($arg == '--debug')
2302
-			$is_debug = true;
2303
-		elseif ($arg == '--backup')
2304
-			$_POST['backup'] = 1;
2305
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2306
-			$_GET['conv'] = 1;
2307
-		elseif ($i != 0)
2432
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2433
+					$_GET['lang'] = $match[1];
2434
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2435
+					continue;
2436
+		} elseif ($arg == '--no-maintenance') {
2437
+					$_GET['maint'] = 0;
2438
+		} elseif ($arg == '--debug') {
2439
+					$is_debug = true;
2440
+		} elseif ($arg == '--backup') {
2441
+					$_POST['backup'] = 1;
2442
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2443
+					$_GET['conv'] = 1;
2444
+		} elseif ($i != 0)
2308 2445
 		{
2309 2446
 			echo 'SMF Command-line Upgrader
2310 2447
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2318,10 +2455,12 @@  discard block
 block discarded – undo
2318 2455
 		}
2319 2456
 	}
2320 2457
 
2321
-	if (!php_version_check())
2322
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2323
-	if (!db_version_check())
2324
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2458
+	if (!php_version_check()) {
2459
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2460
+	}
2461
+	if (!db_version_check()) {
2462
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2463
+	}
2325 2464
 
2326 2465
 	// Do some checks to make sure they have proper privileges
2327 2466
 	db_extend('packages');
@@ -2336,34 +2475,39 @@  discard block
 block discarded – undo
2336 2475
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2337 2476
 
2338 2477
 	// Sorry... we need CREATE, ALTER and DROP
2339
-	if (!$create || !$alter || !$drop)
2340
-		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);
2478
+	if (!$create || !$alter || !$drop) {
2479
+			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);
2480
+	}
2341 2481
 
2342 2482
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2343 2483
 		&& @file_exists($sourcedir . '/QueryString.php')
2344 2484
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2345
-	if (!$check && !isset($modSettings['smfVersion']))
2346
-		print_error('Error: Some files are missing or out-of-date.', true);
2485
+	if (!$check && !isset($modSettings['smfVersion'])) {
2486
+			print_error('Error: Some files are missing or out-of-date.', true);
2487
+	}
2347 2488
 
2348 2489
 	// Do a quick version spot check.
2349 2490
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2350 2491
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2351
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2352
-		print_error('Error: Some files have not yet been updated properly.');
2492
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2493
+			print_error('Error: Some files have not yet been updated properly.');
2494
+	}
2353 2495
 
2354 2496
 	// Make sure Settings.php is writable.
2355 2497
 		quickFileWritable($boarddir . '/Settings.php');
2356
-	if (!is_writable($boarddir . '/Settings.php'))
2357
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2498
+	if (!is_writable($boarddir . '/Settings.php')) {
2499
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2500
+	}
2358 2501
 
2359 2502
 	// Make sure Settings_bak.php is writable.
2360 2503
 		quickFileWritable($boarddir . '/Settings_bak.php');
2361
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2362
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2504
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2505
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2506
+	}
2363 2507
 
2364
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2365
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2366
-	elseif (isset($modSettings['agreement']))
2508
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2509
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2510
+	} elseif (isset($modSettings['agreement']))
2367 2511
 	{
2368 2512
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2369 2513
 		fwrite($fp, $modSettings['agreement']);
@@ -2373,31 +2517,36 @@  discard block
 block discarded – undo
2373 2517
 	// Make sure Themes is writable.
2374 2518
 	quickFileWritable($modSettings['theme_dir']);
2375 2519
 
2376
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2377
-		print_error('Error: Unable to obtain write access to "Themes".');
2520
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2521
+			print_error('Error: Unable to obtain write access to "Themes".');
2522
+	}
2378 2523
 
2379 2524
 	// Make sure cache directory exists and is writable!
2380 2525
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2381
-	if (!file_exists($cachedir_temp))
2382
-		@mkdir($cachedir_temp);
2526
+	if (!file_exists($cachedir_temp)) {
2527
+			@mkdir($cachedir_temp);
2528
+	}
2383 2529
 
2384 2530
 	// Make sure the cache temp dir is writable.
2385 2531
 	quickFileWritable($cachedir_temp);
2386 2532
 
2387
-	if (!is_writable($cachedir_temp))
2388
-		print_error('Error: Unable to obtain write access to "cache".', true);
2533
+	if (!is_writable($cachedir_temp)) {
2534
+			print_error('Error: Unable to obtain write access to "cache".', true);
2535
+	}
2389 2536
 
2390
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2391
-		print_error('Error: Unable to find language files!', true);
2392
-	else
2537
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2538
+			print_error('Error: Unable to find language files!', true);
2539
+	} else
2393 2540
 	{
2394 2541
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2395 2542
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2396 2543
 
2397
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2398
-			print_error('Error: Language files out of date.', true);
2399
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2400
-			print_error('Error: Install language is missing for selected language.', true);
2544
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2545
+					print_error('Error: Language files out of date.', true);
2546
+		}
2547
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2548
+					print_error('Error: Install language is missing for selected language.', true);
2549
+		}
2401 2550
 
2402 2551
 		// Otherwise include it!
2403 2552
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2426,8 +2575,7 @@  discard block
 block discarded – undo
2426 2575
 		);
2427 2576
 
2428 2577
 		return true;
2429
-	}
2430
-	else
2578
+	} else
2431 2579
 	{
2432 2580
 		$upcontext['page_title'] = 'Converting to UTF8';
2433 2581
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2471,8 +2619,9 @@  discard block
 block discarded – undo
2471 2619
 			)
2472 2620
 		);
2473 2621
 		$db_charsets = array();
2474
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2475
-			$db_charsets[] = $row['Charset'];
2622
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2623
+					$db_charsets[] = $row['Charset'];
2624
+		}
2476 2625
 
2477 2626
 		$smcFunc['db_free_result']($request);
2478 2627
 
@@ -2508,13 +2657,15 @@  discard block
 block discarded – undo
2508 2657
 		// If there's a fulltext index, we need to drop it first...
2509 2658
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2510 2659
 		{
2511
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2512
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2660
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2661
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2513 2662
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2663
+			}
2514 2664
 			$smcFunc['db_free_result']($request);
2515 2665
 
2516
-			if (isset($upcontext['fulltext_index']))
2517
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2666
+			if (isset($upcontext['fulltext_index'])) {
2667
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2668
+			}
2518 2669
 		}
2519 2670
 
2520 2671
 		// Drop it and make a note...
@@ -2704,8 +2855,9 @@  discard block
 block discarded – undo
2704 2855
 			$replace = '%field%';
2705 2856
 
2706 2857
 			// Build a huge REPLACE statement...
2707
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2708
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2858
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2859
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2860
+			}
2709 2861
 		}
2710 2862
 
2711 2863
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2739,8 +2891,9 @@  discard block
 block discarded – undo
2739 2891
 			$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2740 2892
 
2741 2893
 			// Just to make sure it doesn't time out.
2742
-			if (function_exists('apache_reset_timeout'))
2743
-				@apache_reset_timeout();
2894
+			if (function_exists('apache_reset_timeout')) {
2895
+							@apache_reset_timeout();
2896
+			}
2744 2897
 
2745 2898
 			$table_charsets = array();
2746 2899
 
@@ -2761,8 +2914,9 @@  discard block
 block discarded – undo
2761 2914
 					{
2762 2915
 						list($charset) = explode('_', $collation);
2763 2916
 
2764
-						if (!isset($table_charsets[$charset]))
2765
-							$table_charsets[$charset] = array();
2917
+						if (!isset($table_charsets[$charset])) {
2918
+													$table_charsets[$charset] = array();
2919
+						}
2766 2920
 
2767 2921
 						$table_charsets[$charset][] = $column_info;
2768 2922
 					}
@@ -2802,10 +2956,11 @@  discard block
 block discarded – undo
2802 2956
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2803 2957
 				{
2804 2958
 					$update = '';
2805
-					foreach ($table_charsets as $charset => $columns)
2806
-						foreach ($columns as $column)
2959
+					foreach ($table_charsets as $charset => $columns) {
2960
+											foreach ($columns as $column)
2807 2961
 							$update .= '
2808 2962
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2963
+					}
2809 2964
 
2810 2965
 					$smcFunc['db_query']('', '
2811 2966
 						UPDATE {raw:table_name}
@@ -2830,8 +2985,9 @@  discard block
 block discarded – undo
2830 2985
 			// Now do the actual conversion (if still needed).
2831 2986
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2832 2987
 			{
2833
-				if ($command_line)
2834
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
2988
+				if ($command_line) {
2989
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
2990
+				}
2835 2991
 
2836 2992
 				$smcFunc['db_query']('', '
2837 2993
 					ALTER TABLE {raw:table_name}
@@ -2841,8 +2997,9 @@  discard block
 block discarded – undo
2841 2997
 						)
2842 2998
 				);
2843 2999
 
2844
-				if ($command_line)
2845
-					echo " done.\n";
3000
+				if ($command_line) {
3001
+									echo " done.\n";
3002
+				}
2846 3003
 			}
2847 3004
 		}
2848 3005
 
@@ -2872,8 +3029,8 @@  discard block
 block discarded – undo
2872 3029
 		);
2873 3030
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2874 3031
 		{
2875
-			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)
2876
-				$smcFunc['db_query']('', '
3032
+			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) {
3033
+							$smcFunc['db_query']('', '
2877 3034
 					UPDATE {db_prefix}log_actions
2878 3035
 					SET extra = {string:extra}
2879 3036
 					WHERE id_action = {int:current_action}',
@@ -2882,6 +3039,7 @@  discard block
 block discarded – undo
2882 3039
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2883 3040
 					)
2884 3041
 				);
3042
+			}
2885 3043
 		}
2886 3044
 		$smcFunc['db_free_result']($request);
2887 3045
 
@@ -2903,15 +3061,17 @@  discard block
 block discarded – undo
2903 3061
 	// First thing's first - did we already do this?
2904 3062
 	if (!empty($modSettings['json_done']))
2905 3063
 	{
2906
-		if ($command_line)
2907
-			return DeleteUpgrade();
2908
-		else
2909
-			return true;
3064
+		if ($command_line) {
3065
+					return DeleteUpgrade();
3066
+		} else {
3067
+					return true;
3068
+		}
2910 3069
 	}
2911 3070
 
2912 3071
 	// Done it already - js wise?
2913
-	if (!empty($_POST['json_done']))
2914
-		return true;
3072
+	if (!empty($_POST['json_done'])) {
3073
+			return true;
3074
+	}
2915 3075
 
2916 3076
 	// List of tables affected by this function
2917 3077
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2942,12 +3102,14 @@  discard block
 block discarded – undo
2942 3102
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2943 3103
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2944 3104
 
2945
-	foreach ($keys as $id => $table)
2946
-		if ($id < $_GET['substep'])
3105
+	foreach ($keys as $id => $table) {
3106
+			if ($id < $_GET['substep'])
2947 3107
 			$upcontext['previous_tables'][] = $table;
3108
+	}
2948 3109
 
2949
-	if ($command_line)
2950
-		echo 'Converting data from serialize() to json_encode().';
3110
+	if ($command_line) {
3111
+			echo 'Converting data from serialize() to json_encode().';
3112
+	}
2951 3113
 
2952 3114
 	if (!$support_js || isset($_GET['xml']))
2953 3115
 	{
@@ -2987,8 +3149,9 @@  discard block
 block discarded – undo
2987 3149
 
2988 3150
 				// Loop through and fix these...
2989 3151
 				$new_settings = array();
2990
-				if ($command_line)
2991
-					echo "\n" . 'Fixing some settings...';
3152
+				if ($command_line) {
3153
+									echo "\n" . 'Fixing some settings...';
3154
+				}
2992 3155
 
2993 3156
 				foreach ($serialized_settings as $var)
2994 3157
 				{
@@ -2996,22 +3159,24 @@  discard block
 block discarded – undo
2996 3159
 					{
2997 3160
 						// Attempt to unserialize the setting
2998 3161
 						$temp = @safe_unserialize($modSettings[$var]);
2999
-						if (!$temp && $command_line)
3000
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3001
-						elseif ($temp !== false)
3002
-							$new_settings[$var] = json_encode($temp);
3162
+						if (!$temp && $command_line) {
3163
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3164
+						} elseif ($temp !== false) {
3165
+													$new_settings[$var] = json_encode($temp);
3166
+						}
3003 3167
 					}
3004 3168
 				}
3005 3169
 
3006 3170
 				// Update everything at once
3007
-				if (!function_exists('cache_put_data'))
3008
-					require_once($sourcedir . '/Load.php');
3171
+				if (!function_exists('cache_put_data')) {
3172
+									require_once($sourcedir . '/Load.php');
3173
+				}
3009 3174
 				updateSettings($new_settings, true);
3010 3175
 
3011
-				if ($command_line)
3012
-					echo ' done.';
3013
-			}
3014
-			elseif ($table == 'themes')
3176
+				if ($command_line) {
3177
+									echo ' done.';
3178
+				}
3179
+			} elseif ($table == 'themes')
3015 3180
 			{
3016 3181
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3017 3182
 				$query = $smcFunc['db_query']('', '
@@ -3030,10 +3195,11 @@  discard block
 block discarded – undo
3030 3195
 
3031 3196
 						if ($command_line)
3032 3197
 						{
3033
-							if ($temp === false)
3034
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3035
-							else
3036
-								echo "\n" . 'Fixing admin preferences...';
3198
+							if ($temp === false) {
3199
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3200
+							} else {
3201
+															echo "\n" . 'Fixing admin preferences...';
3202
+							}
3037 3203
 						}
3038 3204
 
3039 3205
 						if ($temp !== false)
@@ -3053,15 +3219,15 @@  discard block
 block discarded – undo
3053 3219
 								)
3054 3220
 							);
3055 3221
 
3056
-							if ($command_line)
3057
-								echo ' done.';
3222
+							if ($command_line) {
3223
+															echo ' done.';
3224
+							}
3058 3225
 						}
3059 3226
 					}
3060 3227
 
3061 3228
 					$smcFunc['db_free_result']($query);
3062 3229
 				}
3063
-			}
3064
-			else
3230
+			} else
3065 3231
 			{
3066 3232
 				// First item is always the key...
3067 3233
 				$key = $info[0];
@@ -3072,8 +3238,7 @@  discard block
 block discarded – undo
3072 3238
 				{
3073 3239
 					$col_select = $info[1];
3074 3240
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3075
-				}
3076
-				else
3241
+				} else
3077 3242
 				{
3078 3243
 					$col_select = implode(', ', $info);
3079 3244
 				}
@@ -3106,8 +3271,7 @@  discard block
 block discarded – undo
3106 3271
 								if ($temp === false && $command_line)
3107 3272
 								{
3108 3273
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3109
-								}
3110
-								else
3274
+								} else
3111 3275
 								{
3112 3276
 									$row[$col] = json_encode($temp);
3113 3277
 
@@ -3132,16 +3296,18 @@  discard block
 block discarded – undo
3132 3296
 						}
3133 3297
 					}
3134 3298
 
3135
-					if ($command_line)
3136
-						echo ' done.';
3299
+					if ($command_line) {
3300
+											echo ' done.';
3301
+					}
3137 3302
 
3138 3303
 					// Free up some memory...
3139 3304
 					$smcFunc['db_free_result']($query);
3140 3305
 				}
3141 3306
 			}
3142 3307
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3143
-			if (isset($_GET['xml']))
3144
-				return upgradeExit();
3308
+			if (isset($_GET['xml'])) {
3309
+							return upgradeExit();
3310
+			}
3145 3311
 		}
3146 3312
 
3147 3313
 		if ($command_line)
@@ -3156,8 +3322,9 @@  discard block
 block discarded – undo
3156 3322
 
3157 3323
 		$_GET['substep'] = 0;
3158 3324
 		// Make sure we move on!
3159
-		if ($command_line)
3160
-			return DeleteUpgrade();
3325
+		if ($command_line) {
3326
+					return DeleteUpgrade();
3327
+		}
3161 3328
 
3162 3329
 		return true;
3163 3330
 	}
@@ -3177,14 +3344,16 @@  discard block
 block discarded – undo
3177 3344
 	global $upcontext, $txt, $settings;
3178 3345
 
3179 3346
 	// Don't call me twice!
3180
-	if (!empty($upcontext['chmod_called']))
3181
-		return;
3347
+	if (!empty($upcontext['chmod_called'])) {
3348
+			return;
3349
+	}
3182 3350
 
3183 3351
 	$upcontext['chmod_called'] = true;
3184 3352
 
3185 3353
 	// Nothing?
3186
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3187
-		return;
3354
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3355
+			return;
3356
+	}
3188 3357
 
3189 3358
 	// Was it a problem with Windows?
3190 3359
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3216,11 +3385,12 @@  discard block
 block discarded – undo
3216 3385
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>The following files needs to be made writable to continue:</h4>\n\t\t\t\');
3217 3386
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3218 3387
 
3219
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3220
-		echo '
3388
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3389
+			echo '
3221 3390
 					content.write(\'<hr>\n\t\t\t\');
3222 3391
 					content.write(\'<p>If you have a shell account, the convenient below command can automatically correct permissions on these files</p>\n\t\t\t\');
3223 3392
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3393
+	}
3224 3394
 
3225 3395
 	echo '
3226 3396
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3228,17 +3398,19 @@  discard block
 block discarded – undo
3228 3398
 				}
3229 3399
 		</script>';
3230 3400
 
3231
-	if (!empty($upcontext['chmod']['ftp_error']))
3232
-		echo '
3401
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3402
+			echo '
3233 3403
 			<div class="error_message red">
3234 3404
 				The following error was encountered when trying to connect:<br><br>
3235 3405
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3236 3406
 			</div>
3237 3407
 			<br>';
3408
+	}
3238 3409
 
3239
-	if (empty($upcontext['chmod_in_form']))
3240
-		echo '
3410
+	if (empty($upcontext['chmod_in_form'])) {
3411
+			echo '
3241 3412
 	<form action="', $upcontext['form_url'], '" method="post">';
3413
+	}
3242 3414
 
3243 3415
 	echo '
3244 3416
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3273,10 +3445,11 @@  discard block
 block discarded – undo
3273 3445
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3274 3446
 	</div>';
3275 3447
 
3276
-	if (empty($upcontext['chmod_in_form']))
3277
-		echo '
3448
+	if (empty($upcontext['chmod_in_form'])) {
3449
+			echo '
3278 3450
 	</form>';
3279
-}
3451
+	}
3452
+	}
3280 3453
 
3281 3454
 function template_upgrade_above()
3282 3455
 {
@@ -3336,9 +3509,10 @@  discard block
 block discarded – undo
3336 3509
 				<h2>', $txt['upgrade_progress'], '</h2>
3337 3510
 				<ul>';
3338 3511
 
3339
-	foreach ($upcontext['steps'] as $num => $step)
3340
-		echo '
3512
+	foreach ($upcontext['steps'] as $num => $step) {
3513
+			echo '
3341 3514
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3515
+	}
3342 3516
 
3343 3517
 	echo '
3344 3518
 					</ul>
@@ -3351,8 +3525,8 @@  discard block
 block discarded – undo
3351 3525
 				</div>
3352 3526
 			</div>';
3353 3527
 
3354
-	if (isset($upcontext['step_progress']))
3355
-		echo '
3528
+	if (isset($upcontext['step_progress'])) {
3529
+			echo '
3356 3530
 				<br>
3357 3531
 				<br>
3358 3532
 				<div id="progress_bar_step">
@@ -3361,6 +3535,7 @@  discard block
 block discarded – undo
3361 3535
 						<span>', $txt['upgrade_step_progress'], '</span>
3362 3536
 					</div>
3363 3537
 				</div>';
3538
+	}
3364 3539
 
3365 3540
 	echo '
3366 3541
 				<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>
@@ -3391,32 +3566,36 @@  discard block
 block discarded – undo
3391 3566
 {
3392 3567
 	global $upcontext, $txt;
3393 3568
 
3394
-	if (!empty($upcontext['pause']))
3395
-		echo '
3569
+	if (!empty($upcontext['pause'])) {
3570
+			echo '
3396 3571
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3397 3572
 
3398 3573
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3399 3574
 								<h3>
3400 3575
 									', $txt['upgrade_paused_overload'], '
3401 3576
 								</h3>';
3577
+	}
3402 3578
 
3403
-	if (!empty($upcontext['custom_warning']))
3404
-		echo '
3579
+	if (!empty($upcontext['custom_warning'])) {
3580
+			echo '
3405 3581
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3406 3582
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3407 3583
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3408 3584
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3409 3585
 								</div>';
3586
+	}
3410 3587
 
3411 3588
 	echo '
3412 3589
 								<div class="righttext" style="margin: 1ex;">';
3413 3590
 
3414
-	if (!empty($upcontext['continue']))
3415
-		echo '
3591
+	if (!empty($upcontext['continue'])) {
3592
+			echo '
3416 3593
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3417
-	if (!empty($upcontext['skip']))
3418
-		echo '
3594
+	}
3595
+	if (!empty($upcontext['skip'])) {
3596
+			echo '
3419 3597
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3598
+	}
3420 3599
 
3421 3600
 	echo '
3422 3601
 								</div>
@@ -3466,11 +3645,12 @@  discard block
 block discarded – undo
3466 3645
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3467 3646
 	<smf>';
3468 3647
 
3469
-	if (!empty($upcontext['get_data']))
3470
-		foreach ($upcontext['get_data'] as $k => $v)
3648
+	if (!empty($upcontext['get_data'])) {
3649
+			foreach ($upcontext['get_data'] as $k => $v)
3471 3650
 			echo '
3472 3651
 		<get key="', $k, '">', $v, '</get>';
3473
-}
3652
+	}
3653
+	}
3474 3654
 
3475 3655
 function template_xml_below()
3476 3656
 {
@@ -3511,8 +3691,8 @@  discard block
 block discarded – undo
3511 3691
 	template_chmod();
3512 3692
 
3513 3693
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3514
-	if ($upcontext['is_large_forum'])
3515
-		echo '
3694
+	if ($upcontext['is_large_forum']) {
3695
+			echo '
3516 3696
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3517 3697
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3518 3698
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3520,10 +3700,11 @@  discard block
 block discarded – undo
3520 3700
 				', $txt['upgrade_warning_lots_data'], '
3521 3701
 			</div>
3522 3702
 		</div>';
3703
+	}
3523 3704
 
3524 3705
 	// A warning message?
3525
-	if (!empty($upcontext['warning']))
3526
-		echo '
3706
+	if (!empty($upcontext['warning'])) {
3707
+			echo '
3527 3708
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3528 3709
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3529 3710
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3531,6 +3712,7 @@  discard block
 block discarded – undo
3531 3712
 				', $upcontext['warning'], '
3532 3713
 			</div>
3533 3714
 		</div>';
3715
+	}
3534 3716
 
3535 3717
 	// Paths are incorrect?
3536 3718
 	echo '
@@ -3546,20 +3728,22 @@  discard block
 block discarded – undo
3546 3728
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3547 3729
 	{
3548 3730
 		$ago = time() - $upcontext['started'];
3549
-		if ($ago < 60)
3550
-			$ago = $ago . ' seconds';
3551
-		elseif ($ago < 3600)
3552
-			$ago = (int) ($ago / 60) . ' minutes';
3553
-		else
3554
-			$ago = (int) ($ago / 3600) . ' hours';
3731
+		if ($ago < 60) {
3732
+					$ago = $ago . ' seconds';
3733
+		} elseif ($ago < 3600) {
3734
+					$ago = (int) ($ago / 60) . ' minutes';
3735
+		} else {
3736
+					$ago = (int) ($ago / 3600) . ' hours';
3737
+		}
3555 3738
 
3556 3739
 		$active = time() - $upcontext['updated'];
3557
-		if ($active < 60)
3558
-			$updated = $active . ' seconds';
3559
-		elseif ($active < 3600)
3560
-			$updated = (int) ($active / 60) . ' minutes';
3561
-		else
3562
-			$updated = (int) ($active / 3600) . ' hours';
3740
+		if ($active < 60) {
3741
+					$updated = $active . ' seconds';
3742
+		} elseif ($active < 3600) {
3743
+					$updated = (int) ($active / 60) . ' minutes';
3744
+		} else {
3745
+					$updated = (int) ($active / 3600) . ' hours';
3746
+		}
3563 3747
 
3564 3748
 		echo '
3565 3749
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3568,16 +3752,18 @@  discard block
 block discarded – undo
3568 3752
 			<div style="padding-left: 6ex;">
3569 3753
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3570 3754
 
3571
-		if ($active < 600)
3572
-			echo '
3755
+		if ($active < 600) {
3756
+					echo '
3573 3757
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3758
+		}
3574 3759
 
3575
-		if ($active > $upcontext['inactive_timeout'])
3576
-			echo '
3760
+		if ($active > $upcontext['inactive_timeout']) {
3761
+					echo '
3577 3762
 				<br><br>You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.';
3578
-		else
3579
-			echo '
3763
+		} else {
3764
+					echo '
3580 3765
 				<br><br>This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3766
+		}
3581 3767
 
3582 3768
 		echo '
3583 3769
 			</div>
@@ -3593,9 +3779,10 @@  discard block
 block discarded – undo
3593 3779
 					<td>
3594 3780
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3595 3781
 
3596
-	if (!empty($upcontext['username_incorrect']))
3597
-		echo '
3782
+	if (!empty($upcontext['username_incorrect'])) {
3783
+			echo '
3598 3784
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3785
+	}
3599 3786
 
3600 3787
 	echo '
3601 3788
 					</td>
@@ -3606,9 +3793,10 @@  discard block
 block discarded – undo
3606 3793
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3607 3794
 						<input type="hidden" name="hash_passwrd" value="">';
3608 3795
 
3609
-	if (!empty($upcontext['password_failed']))
3610
-		echo '
3796
+	if (!empty($upcontext['password_failed'])) {
3797
+			echo '
3611 3798
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3799
+	}
3612 3800
 
3613 3801
 	echo '
3614 3802
 					</td>
@@ -3679,8 +3867,8 @@  discard block
 block discarded – undo
3679 3867
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3680 3868
 
3681 3869
 	// Warning message?
3682
-	if (!empty($upcontext['upgrade_options_warning']))
3683
-		echo '
3870
+	if (!empty($upcontext['upgrade_options_warning'])) {
3871
+			echo '
3684 3872
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3685 3873
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3686 3874
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3688,6 +3876,7 @@  discard block
 block discarded – undo
3688 3876
 				', $upcontext['upgrade_options_warning'], '
3689 3877
 			</div>
3690 3878
 		</div>';
3879
+	}
3691 3880
 
3692 3881
 	echo '
3693 3882
 				<table>
@@ -3730,8 +3919,8 @@  discard block
 block discarded – undo
3730 3919
 						</td>
3731 3920
 					</tr>';
3732 3921
 
3733
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3734
-		echo '
3922
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3923
+			echo '
3735 3924
 					<tr valign="top">
3736 3925
 						<td width="2%">
3737 3926
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3740,6 +3929,7 @@  discard block
 block discarded – undo
3740 3929
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3741 3930
 						</td>
3742 3931
 					</tr>';
3932
+	}
3743 3933
 
3744 3934
 	echo '
3745 3935
 					<tr valign="top">
@@ -3775,10 +3965,11 @@  discard block
 block discarded – undo
3775 3965
 			<span id="debuginfo"></span>';
3776 3966
 
3777 3967
 	// Dont any tables so far?
3778
-	if (!empty($upcontext['previous_tables']))
3779
-		foreach ($upcontext['previous_tables'] as $table)
3968
+	if (!empty($upcontext['previous_tables'])) {
3969
+			foreach ($upcontext['previous_tables'] as $table)
3780 3970
 			echo '
3781 3971
 			<br>Completed Table: &quot;', $table, '&quot;.';
3972
+	}
3782 3973
 
3783 3974
 	echo '
3784 3975
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3815,12 +4006,13 @@  discard block
 block discarded – undo
3815 4006
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3816 4007
 
3817 4008
 		// If debug flood the screen.
3818
-		if ($is_debug)
3819
-			echo '
4009
+		if ($is_debug) {
4010
+					echo '
3820 4011
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3821 4012
 
3822 4013
 				if (document.getElementById(\'debuginfo\').scrollHeight)
3823 4014
 					document.getElementById(\'debuginfo\').scrollTop = document.getElementById(\'debuginfo\').scrollHeight;';
4015
+		}
3824 4016
 
3825 4017
 		echo '
3826 4018
 				// Get the next update...
@@ -3852,8 +4044,9 @@  discard block
 block discarded – undo
3852 4044
 {
3853 4045
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3854 4046
 
3855
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3856
-		$is_debug = true;
4047
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4048
+			$is_debug = true;
4049
+	}
3857 4050
 
3858 4051
 	echo '
3859 4052
 		<h3>Executing database changes</h3>
@@ -3868,8 +4061,9 @@  discard block
 block discarded – undo
3868 4061
 	{
3869 4062
 		foreach ($upcontext['actioned_items'] as $num => $item)
3870 4063
 		{
3871
-			if ($num != 0)
3872
-				echo ' Successful!';
4064
+			if ($num != 0) {
4065
+							echo ' Successful!';
4066
+			}
3873 4067
 			echo '<br>' . $item;
3874 4068
 		}
3875 4069
 		if (!empty($upcontext['changes_complete']))
@@ -3882,28 +4076,32 @@  discard block
 block discarded – undo
3882 4076
 				$seconds = intval($active % 60);
3883 4077
 
3884 4078
 				$totalTime = '';
3885
-				if ($hours > 0)
3886
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3887
-				if ($minutes > 0)
3888
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3889
-				if ($seconds > 0)
3890
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4079
+				if ($hours > 0) {
4080
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4081
+				}
4082
+				if ($minutes > 0) {
4083
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4084
+				}
4085
+				if ($seconds > 0) {
4086
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4087
+				}
3891 4088
 			}
3892 4089
 
3893
-			if ($is_debug && !empty($totalTime))
3894
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3895
-			else
3896
-				echo ' Successful!<br><br>';
4090
+			if ($is_debug && !empty($totalTime)) {
4091
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4092
+			} else {
4093
+							echo ' Successful!<br><br>';
4094
+			}
3897 4095
 
3898 4096
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3899 4097
 		}
3900
-	}
3901
-	else
4098
+	} else
3902 4099
 	{
3903 4100
 		// Tell them how many files we have in total.
3904
-		if ($upcontext['file_count'] > 1)
3905
-			echo '
4101
+		if ($upcontext['file_count'] > 1) {
4102
+					echo '
3906 4103
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4104
+		}
3907 4105
 
3908 4106
 		echo '
3909 4107
 		<h3 id="info2"><strong>Executing:</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> of <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -3919,19 +4117,23 @@  discard block
 block discarded – undo
3919 4117
 				$seconds = intval($active % 60);
3920 4118
 
3921 4119
 				$totalTime = '';
3922
-				if ($hours > 0)
3923
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3924
-				if ($minutes > 0)
3925
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3926
-				if ($seconds > 0)
3927
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4120
+				if ($hours > 0) {
4121
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4122
+				}
4123
+				if ($minutes > 0) {
4124
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4125
+				}
4126
+				if ($seconds > 0) {
4127
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4128
+				}
3928 4129
 			}
3929 4130
 
3930 4131
 			echo '
3931 4132
 			<br><span id="upgradeCompleted">';
3932 4133
 
3933
-			if (!empty($totalTime))
3934
-				echo 'Completed in ', $totalTime, '<br>';
4134
+			if (!empty($totalTime)) {
4135
+							echo 'Completed in ', $totalTime, '<br>';
4136
+			}
3935 4137
 
3936 4138
 			echo '</span>
3937 4139
 			<div id="debug_section" style="height: 200px; overflow: auto;">
@@ -3968,9 +4170,10 @@  discard block
 block discarded – undo
3968 4170
 			var getData = "";
3969 4171
 			var debugItems = ', $upcontext['debug_items'], ';';
3970 4172
 
3971
-		if ($is_debug)
3972
-			echo '
4173
+		if ($is_debug) {
4174
+					echo '
3973 4175
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4176
+		}
3974 4177
 
3975 4178
 		echo '
3976 4179
 			function getNextItem()
@@ -4010,9 +4213,10 @@  discard block
 block discarded – undo
4010 4213
 						document.getElementById("error_block").style.display = "";
4011 4214
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4012 4215
 
4013
-	if ($is_debug)
4014
-		echo '
4216
+	if ($is_debug) {
4217
+			echo '
4015 4218
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4219
+	}
4016 4220
 
4017 4221
 	echo '
4018 4222
 					}
@@ -4033,9 +4237,10 @@  discard block
 block discarded – undo
4033 4237
 						document.getElementById("error_block").style.display = "";
4034 4238
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4035 4239
 
4036
-	if ($is_debug)
4037
-		echo '
4240
+	if ($is_debug) {
4241
+			echo '
4038 4242
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4243
+	}
4039 4244
 
4040 4245
 	echo '
4041 4246
 					}
@@ -4094,8 +4299,8 @@  discard block
 block discarded – undo
4094 4299
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4095 4300
 				{';
4096 4301
 
4097
-		if ($is_debug)
4098
-			echo '
4302
+		if ($is_debug) {
4303
+					echo '
4099 4304
 					document.getElementById(\'debug_section\').style.display = "none";
4100 4305
 
4101 4306
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4113,6 +4318,7 @@  discard block
 block discarded – undo
4113 4318
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4114 4319
 
4115 4320
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4321
+		}
4116 4322
 
4117 4323
 		echo '
4118 4324
 
@@ -4120,9 +4326,10 @@  discard block
 block discarded – undo
4120 4326
 					document.getElementById(\'contbutt\').disabled = 0;
4121 4327
 					document.getElementById(\'database_done\').value = 1;';
4122 4328
 
4123
-		if ($upcontext['file_count'] > 1)
4124
-			echo '
4329
+		if ($upcontext['file_count'] > 1) {
4330
+					echo '
4125 4331
 					document.getElementById(\'info1\').style.display = "none";';
4332
+		}
4126 4333
 
4127 4334
 		echo '
4128 4335
 					document.getElementById(\'info2\').style.display = "none";
@@ -4135,9 +4342,10 @@  discard block
 block discarded – undo
4135 4342
 					lastItem = 0;
4136 4343
 					prevFile = curFile;';
4137 4344
 
4138
-		if ($is_debug)
4139
-			echo '
4345
+		if ($is_debug) {
4346
+					echo '
4140 4347
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4348
+		}
4141 4349
 
4142 4350
 		echo '
4143 4351
 					getNextItem();
@@ -4145,8 +4353,8 @@  discard block
 block discarded – undo
4145 4353
 				}';
4146 4354
 
4147 4355
 		// If debug scroll the screen.
4148
-		if ($is_debug)
4149
-			echo '
4356
+		if ($is_debug) {
4357
+					echo '
4150 4358
 				if (iLastSubStepProgress == -1)
4151 4359
 				{
4152 4360
 					// Give it consistent dots.
@@ -4165,6 +4373,7 @@  discard block
 block discarded – undo
4165 4373
 
4166 4374
 				if (document.getElementById(\'debug_section\').scrollHeight)
4167 4375
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4376
+		}
4168 4377
 
4169 4378
 		echo '
4170 4379
 				// Update the page.
@@ -4225,9 +4434,10 @@  discard block
 block discarded – undo
4225 4434
 			}';
4226 4435
 
4227 4436
 		// Start things off assuming we've not errored.
4228
-		if (empty($upcontext['error_message']))
4229
-			echo '
4437
+		if (empty($upcontext['error_message'])) {
4438
+					echo '
4230 4439
 			getNextItem();';
4440
+		}
4231 4441
 
4232 4442
 		echo '
4233 4443
 		</script>';
@@ -4244,18 +4454,21 @@  discard block
 block discarded – undo
4244 4454
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4245 4455
 	<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>';
4246 4456
 
4247
-	if (!empty($upcontext['error_message']))
4248
-		echo '
4457
+	if (!empty($upcontext['error_message'])) {
4458
+			echo '
4249 4459
 	<error>', $upcontext['error_message'], '</error>';
4460
+	}
4250 4461
 
4251
-	if (!empty($upcontext['error_string']))
4252
-		echo '
4462
+	if (!empty($upcontext['error_string'])) {
4463
+			echo '
4253 4464
 	<sql>', $upcontext['error_string'], '</sql>';
4465
+	}
4254 4466
 
4255
-	if ($is_debug)
4256
-		echo '
4467
+	if ($is_debug) {
4468
+			echo '
4257 4469
 	<curtime>', time(), '</curtime>';
4258
-}
4470
+	}
4471
+	}
4259 4472
 
4260 4473
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4261 4474
 function template_convert_utf8()
@@ -4272,18 +4485,20 @@  discard block
 block discarded – undo
4272 4485
 			<span id="debuginfo"></span>';
4273 4486
 
4274 4487
 	// Done any tables so far?
4275
-	if (!empty($upcontext['previous_tables']))
4276
-		foreach ($upcontext['previous_tables'] as $table)
4488
+	if (!empty($upcontext['previous_tables'])) {
4489
+			foreach ($upcontext['previous_tables'] as $table)
4277 4490
 			echo '
4278 4491
 			<br>Completed Table: &quot;', $table, '&quot;.';
4492
+	}
4279 4493
 
4280 4494
 	echo '
4281 4495
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4282 4496
 
4283 4497
 	// If we dropped their index, let's let them know
4284
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
4285
-		echo '
4498
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
4499
+			echo '
4286 4500
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
4501
+	}
4287 4502
 
4288 4503
 	echo '
4289 4504
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Conversion Complete! Click Continue to Proceed.</span>';
@@ -4319,9 +4534,10 @@  discard block
 block discarded – undo
4319 4534
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4320 4535
 
4321 4536
 		// If debug flood the screen.
4322
-		if ($is_debug)
4323
-			echo '
4537
+		if ($is_debug) {
4538
+					echo '
4324 4539
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4540
+		}
4325 4541
 
4326 4542
 		echo '
4327 4543
 				// Get the next update...
@@ -4363,19 +4579,21 @@  discard block
 block discarded – undo
4363 4579
 			<span id="debuginfo"></span>';
4364 4580
 
4365 4581
 	// Dont any tables so far?
4366
-	if (!empty($upcontext['previous_tables']))
4367
-		foreach ($upcontext['previous_tables'] as $table)
4582
+	if (!empty($upcontext['previous_tables'])) {
4583
+			foreach ($upcontext['previous_tables'] as $table)
4368 4584
 			echo '
4369 4585
 			<br>Completed Table: &quot;', $table, '&quot;.';
4586
+	}
4370 4587
 
4371 4588
 	echo '
4372 4589
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4373 4590
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Convert to JSON Complete! Click Continue to Proceed.</span>';
4374 4591
 
4375 4592
 	// Try to make sure substep was reset.
4376
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4377
-		echo '
4593
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4594
+			echo '
4378 4595
 			<input type="hidden" name="substep" id="substep" value="0">';
4596
+	}
4379 4597
 
4380 4598
 	// Continue please!
4381 4599
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4408,9 +4626,10 @@  discard block
 block discarded – undo
4408 4626
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4409 4627
 
4410 4628
 		// If debug flood the screen.
4411
-		if ($is_debug)
4412
-			echo '
4629
+		if ($is_debug) {
4630
+					echo '
4413 4631
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4632
+		}
4414 4633
 
4415 4634
 		echo '
4416 4635
 				// Get the next update...
@@ -4445,8 +4664,8 @@  discard block
 block discarded – undo
4445 4664
 	<h3>That wasn\'t so hard, was it?  Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>.  Hope you like it!</h3>
4446 4665
 	<form action="', $boardurl, '/index.php">';
4447 4666
 
4448
-	if (!empty($upcontext['can_delete_script']))
4449
-		echo '
4667
+	if (!empty($upcontext['can_delete_script'])) {
4668
+			echo '
4450 4669
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em>
4451 4670
 			<script>
4452 4671
 				function doTheDelete(theCheck)
@@ -4458,6 +4677,7 @@  discard block
 block discarded – undo
4458 4677
 				}
4459 4678
 			</script>
4460 4679
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4680
+	}
4461 4681
 
4462 4682
 	$active = time() - $upcontext['started'];
4463 4683
 	$hours = floor($active / 3600);
@@ -4467,16 +4687,20 @@  discard block
 block discarded – undo
4467 4687
 	if ($is_debug)
4468 4688
 	{
4469 4689
 		$totalTime = '';
4470
-		if ($hours > 0)
4471
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4472
-		if ($minutes > 0)
4473
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4474
-		if ($seconds > 0)
4475
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4690
+		if ($hours > 0) {
4691
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4692
+		}
4693
+		if ($minutes > 0) {
4694
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4695
+		}
4696
+		if ($seconds > 0) {
4697
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4698
+		}
4476 4699
 	}
4477 4700
 
4478
-	if ($is_debug && !empty($totalTime))
4479
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4701
+	if ($is_debug && !empty($totalTime)) {
4702
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4703
+	}
4480 4704
 
4481 4705
 	echo '<br>
4482 4706
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="http://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -4543,16 +4767,19 @@  discard block
 block discarded – undo
4543 4767
 				'empty' => '',
4544 4768
 				'limit' => $limit,
4545 4769
 		));
4546
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4547
-			$arIp[] = $row[$oldCol];
4770
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4771
+					$arIp[] = $row[$oldCol];
4772
+		}
4548 4773
 		$smcFunc['db_free_result']($request);
4549 4774
 
4550 4775
 		// Special case, null ip could keep us in a loop.
4551
-		if (is_null($arIp[0]))
4552
-			unset($arIp[0]);
4776
+		if (is_null($arIp[0])) {
4777
+					unset($arIp[0]);
4778
+		}
4553 4779
 
4554
-		if (empty($arIp))
4555
-			$is_done = true;
4780
+		if (empty($arIp)) {
4781
+					$is_done = true;
4782
+		}
4556 4783
 
4557 4784
 		$updates = array();
4558 4785
 		$cases = array();
@@ -4561,16 +4788,18 @@  discard block
 block discarded – undo
4561 4788
 		{
4562 4789
 			$arIp[$i] = trim($arIp[$i]);
4563 4790
 
4564
-			if (empty($arIp[$i]))
4565
-				continue;
4791
+			if (empty($arIp[$i])) {
4792
+							continue;
4793
+			}
4566 4794
 
4567 4795
 			$updates['ip' . $i] = $arIp[$i];
4568 4796
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4569 4797
 
4570 4798
 			if ($setSize > 0 && $i % $setSize === 0)
4571 4799
 			{
4572
-				if (count($updates) == 1)
4573
-					continue;
4800
+				if (count($updates) == 1) {
4801
+									continue;
4802
+				}
4574 4803
 
4575 4804
 				$updates['whereSet'] = array_values($updates);
4576 4805
 				$smcFunc['db_query']('', '
@@ -4604,8 +4833,7 @@  discard block
 block discarded – undo
4604 4833
 							'ip' => $ip
4605 4834
 					));
4606 4835
 				}
4607
-			}
4608
-			else
4836
+			} else
4609 4837
 			{
4610 4838
 				$updates['whereSet'] = array_values($updates);
4611 4839
 				$smcFunc['db_query']('', '
@@ -4619,9 +4847,9 @@  discard block
 block discarded – undo
4619 4847
 					$updates
4620 4848
 				);
4621 4849
 			}
4850
+		} else {
4851
+					$is_done = true;
4622 4852
 		}
4623
-		else
4624
-			$is_done = true;
4625 4853
 
4626 4854
 		$_GET['a'] += $limit;
4627 4855
 		$step_progress['current'] = $_GET['a'];
Please login to merge, or discard this patch.
other/install.php 1 patch
Braces   +436 added lines, -324 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -63,12 +64,14 @@  discard block
 block discarded – undo
63 64
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
64 65
 
65 66
 			// Is it reserved?
66
-			if ($value == 'pg_')
67
-				return $txt['error_db_prefix_reserved'];
67
+			if ($value == 'pg_') {
68
+							return $txt['error_db_prefix_reserved'];
69
+			}
68 70
 
69 71
 			// Is the prefix numeric?
70
-			if (preg_match('~^\d~', $value))
71
-				return $txt['error_db_prefix_numeric'];
72
+			if (preg_match('~^\d~', $value)) {
73
+							return $txt['error_db_prefix_numeric'];
74
+			}
72 75
 
73 76
 			return true;
74 77
 		},
@@ -115,10 +118,11 @@  discard block
 block discarded – undo
115 118
 		$incontext['skip'] = false;
116 119
 
117 120
 		// Call the step and if it returns false that means pause!
118
-		if (function_exists($step[2]) && $step[2]() === false)
119
-			break;
120
-		elseif (function_exists($step[2]))
121
-			$incontext['current_step']++;
121
+		if (function_exists($step[2]) && $step[2]() === false) {
122
+					break;
123
+		} elseif (function_exists($step[2])) {
124
+					$incontext['current_step']++;
125
+		}
122 126
 
123 127
 		// No warnings pass on.
124 128
 		$incontext['warning'] = '';
@@ -134,12 +138,14 @@  discard block
 block discarded – undo
134 138
 	global $databases, $incontext;
135 139
 
136 140
 	// Just so people using older versions of PHP aren't left in the cold.
137
-	if (!isset($_SERVER['PHP_SELF']))
138
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
141
+	if (!isset($_SERVER['PHP_SELF'])) {
142
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
143
+	}
139 144
 
140 145
 	// Turn off magic quotes runtime and enable error reporting.
141
-	if (function_exists('set_magic_quotes_runtime'))
142
-		@set_magic_quotes_runtime(0);
146
+	if (function_exists('set_magic_quotes_runtime')) {
147
+			@set_magic_quotes_runtime(0);
148
+	}
143 149
 	error_reporting(E_ALL);
144 150
 
145 151
 	// Fun.  Low PHP version...
@@ -153,21 +159,23 @@  discard block
 block discarded – undo
153 159
 	{
154 160
 		ob_start();
155 161
 
156
-		if (ini_get('session.save_handler') == 'user')
157
-			@ini_set('session.save_handler', 'files');
158
-		if (function_exists('session_start'))
159
-			@session_start();
160
-	}
161
-	else
162
+		if (ini_get('session.save_handler') == 'user') {
163
+					@ini_set('session.save_handler', 'files');
164
+		}
165
+		if (function_exists('session_start')) {
166
+					@session_start();
167
+		}
168
+	} else
162 169
 	{
163 170
 		ob_start('ob_gzhandler');
164 171
 
165
-		if (ini_get('session.save_handler') == 'user')
166
-			@ini_set('session.save_handler', 'files');
172
+		if (ini_get('session.save_handler') == 'user') {
173
+					@ini_set('session.save_handler', 'files');
174
+		}
167 175
 		session_start();
168 176
 
169
-		if (!headers_sent())
170
-			echo '<!DOCTYPE html>
177
+		if (!headers_sent()) {
178
+					echo '<!DOCTYPE html>
171 179
 <html>
172 180
 	<head>
173 181
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -176,6 +184,7 @@  discard block
 block discarded – undo
176 184
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
177 185
 	</body>
178 186
 </html>';
187
+		}
179 188
 		exit;
180 189
 	}
181 190
 
@@ -184,16 +193,18 @@  discard block
 block discarded – undo
184 193
 	{
185 194
 		$incontext['remote_files_available'] = false;
186 195
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
187
-		if ($test)
188
-			$incontext['remote_files_available'] = true;
196
+		if ($test) {
197
+					$incontext['remote_files_available'] = true;
198
+		}
189 199
 		@fclose($test);
190 200
 	}
191 201
 
192 202
 	// Add slashes, as long as they aren't already being added.
193
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
194
-		foreach ($_POST as $k => $v)
203
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
204
+			foreach ($_POST as $k => $v)
195 205
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
196 206
 				$_POST[$k] = addslashes($v);
207
+	}
197 208
 
198 209
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
199 210
 	if (isset($_GET['delete']))
@@ -214,8 +225,7 @@  discard block
 block discarded – undo
214 225
 			$ftp->close();
215 226
 
216 227
 			unset($_SESSION['installer_temp_ftp']);
217
-		}
218
-		else
228
+		} else
219 229
 		{
220 230
 			@unlink(__FILE__);
221 231
 
@@ -236,10 +246,11 @@  discard block
 block discarded – undo
236 246
 	{
237 247
 		// Get PHP's default timezone, if set
238 248
 		$ini_tz = ini_get('date.timezone');
239
-		if (!empty($ini_tz))
240
-			$timezone_id = $ini_tz;
241
-		else
242
-			$timezone_id = '';
249
+		if (!empty($ini_tz)) {
250
+					$timezone_id = $ini_tz;
251
+		} else {
252
+					$timezone_id = '';
253
+		}
243 254
 
244 255
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
245 256
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -269,8 +280,9 @@  discard block
 block discarded – undo
269 280
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
270 281
 		while ($entry = $dir->read())
271 282
 		{
272
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
273
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
283
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
284
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
285
+			}
274 286
 		}
275 287
 		$dir->close();
276 288
 	}
@@ -305,10 +317,11 @@  discard block
 block discarded – undo
305 317
 	}
306 318
 
307 319
 	// Override the language file?
308
-	if (isset($_GET['lang_file']))
309
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
310
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
311
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
320
+	if (isset($_GET['lang_file'])) {
321
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
322
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
323
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
324
+	}
312 325
 
313 326
 	// Make sure it exists, if it doesn't reset it.
314 327
 	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']))
@@ -317,8 +330,9 @@  discard block
 block discarded – undo
317 330
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
318 331
 
319 332
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
320
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
321
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
333
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
334
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
335
+		}
322 336
 	}
323 337
 
324 338
 	// And now include the actual language file itself.
@@ -331,15 +345,18 @@  discard block
 block discarded – undo
331 345
 	global $db_prefix, $db_connection, $sourcedir;
332 346
 	global $smcFunc, $modSettings, $db_type, $db_name, $db_user, $db_persist;
333 347
 
334
-	if (empty($sourcedir))
335
-		$sourcedir = dirname(__FILE__) . '/Sources';
348
+	if (empty($sourcedir)) {
349
+			$sourcedir = dirname(__FILE__) . '/Sources';
350
+	}
336 351
 
337 352
 	// Need this to check whether we need the database password.
338 353
 	require(dirname(__FILE__) . '/Settings.php');
339
-	if (!defined('SMF'))
340
-		define('SMF', 1);
341
-	if (empty($smcFunc))
342
-		$smcFunc = array();
354
+	if (!defined('SMF')) {
355
+			define('SMF', 1);
356
+	}
357
+	if (empty($smcFunc)) {
358
+			$smcFunc = array();
359
+	}
343 360
 
344 361
 	$modSettings['disableQueryCheck'] = true;
345 362
 
@@ -347,8 +364,9 @@  discard block
 block discarded – undo
347 364
 	if (!$db_connection)
348 365
 	{
349 366
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
350
-		if (version_compare(PHP_VERSION, '5', '<'))
351
-			require_once($sourcedir . '/Subs-Compat.php');
367
+		if (version_compare(PHP_VERSION, '5', '<')) {
368
+					require_once($sourcedir . '/Subs-Compat.php');
369
+		}
352 370
 
353 371
 		$db_options = array('persist' => $db_persist);
354 372
 		$port = '';
@@ -359,19 +377,20 @@  discard block
 block discarded – undo
359 377
 			if ($db_type == 'mysql')
360 378
 			{
361 379
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
362
-			}
363
-			elseif ($db_type == 'postgresql')
380
+			} elseif ($db_type == 'postgresql')
364 381
 			{
365 382
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
366 383
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
367 384
 			}
368 385
 		}
369 386
 
370
-		if (!empty($port))
371
-			$db_options['port'] = $port;
387
+		if (!empty($port)) {
388
+					$db_options['port'] = $port;
389
+		}
372 390
 
373
-		if (!$db_connection)
374
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
391
+		if (!$db_connection) {
392
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
393
+		}
375 394
 	}
376 395
 }
377 396
 
@@ -399,8 +418,9 @@  discard block
 block discarded – undo
399 418
 		// @todo REMOVE THIS!!
400 419
 		else
401 420
 		{
402
-			if (function_exists('doStep' . $_GET['step']))
403
-				call_user_func('doStep' . $_GET['step']);
421
+			if (function_exists('doStep' . $_GET['step'])) {
422
+							call_user_func('doStep' . $_GET['step']);
423
+			}
404 424
 		}
405 425
 		// Show the footer.
406 426
 		template_install_below();
@@ -418,8 +438,9 @@  discard block
 block discarded – undo
418 438
 	$incontext['sub_template'] = 'welcome_message';
419 439
 
420 440
 	// Done the submission?
421
-	if (isset($_POST['contbutt']))
422
-		return true;
441
+	if (isset($_POST['contbutt'])) {
442
+			return true;
443
+	}
423 444
 
424 445
 	// See if we think they have already installed it?
425 446
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -427,14 +448,17 @@  discard block
 block discarded – undo
427 448
 		$probably_installed = 0;
428 449
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
429 450
 		{
430
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
431
-				$probably_installed++;
432
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
433
-				$probably_installed++;
451
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
452
+							$probably_installed++;
453
+			}
454
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
455
+							$probably_installed++;
456
+			}
434 457
 		}
435 458
 
436
-		if ($probably_installed == 2)
437
-			$incontext['warning'] = $txt['error_already_installed'];
459
+		if ($probably_installed == 2) {
460
+					$incontext['warning'] = $txt['error_already_installed'];
461
+		}
438 462
 	}
439 463
 
440 464
 	// Is some database support even compiled in?
@@ -449,36 +473,43 @@  discard block
 block discarded – undo
449 473
 				$databases[$key]['supported'] = false;
450 474
 				$notFoundSQLFile = true;
451 475
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
476
+			} else {
477
+							$incontext['supported_databases'][] = $db;
452 478
 			}
453
-			else
454
-				$incontext['supported_databases'][] = $db;
455 479
 		}
456 480
 	}
457 481
 
458 482
 	// Check the PHP version.
459
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>')))
460
-		$error = 'error_php_too_low';
483
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) {
484
+			$error = 'error_php_too_low';
485
+	}
461 486
 	// Make sure we have a supported database
462
-	elseif (empty($incontext['supported_databases']))
463
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
487
+	elseif (empty($incontext['supported_databases'])) {
488
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
489
+	}
464 490
 	// How about session support?  Some crazy sysadmin remove it?
465
-	elseif (!function_exists('session_start'))
466
-		$error = 'error_session_missing';
491
+	elseif (!function_exists('session_start')) {
492
+			$error = 'error_session_missing';
493
+	}
467 494
 	// Make sure they uploaded all the files.
468
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
469
-		$error = 'error_missing_files';
495
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
496
+			$error = 'error_missing_files';
497
+	}
470 498
 	// Very simple check on the session.save_path for Windows.
471 499
 	// @todo Move this down later if they don't use database-driven sessions?
472
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
473
-		$error = 'error_session_save_path';
500
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
501
+			$error = 'error_session_save_path';
502
+	}
474 503
 
475 504
 	// Since each of the three messages would look the same, anyway...
476
-	if (isset($error))
477
-		$incontext['error'] = $txt[$error];
505
+	if (isset($error)) {
506
+			$incontext['error'] = $txt[$error];
507
+	}
478 508
 
479 509
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
480
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
481
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
510
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
511
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
512
+	}
482 513
 
483 514
 	return false;
484 515
 }
@@ -503,12 +534,14 @@  discard block
 block discarded – undo
503 534
 		'Settings_bak.php',
504 535
 	);
505 536
 
506
-	foreach ($incontext['detected_languages'] as $lang => $temp)
507
-		$extra_files[] = 'Themes/default/languages/' . $lang;
537
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
538
+			$extra_files[] = 'Themes/default/languages/' . $lang;
539
+	}
508 540
 
509 541
 	// With mod_security installed, we could attempt to fix it with .htaccess.
510
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
511
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
542
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
543
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
544
+	}
512 545
 
513 546
 	$failed_files = array();
514 547
 
@@ -524,12 +557,14 @@  discard block
 block discarded – undo
524 557
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
525 558
 
526 559
 				// Well, 755 hopefully worked... if not, try 777.
527
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
528
-					$failed_files[] = $file;
560
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
561
+									$failed_files[] = $file;
562
+				}
529 563
 			}
530 564
 		}
531
-		foreach ($extra_files as $file)
532
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
565
+		foreach ($extra_files as $file) {
566
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
567
+		}
533 568
 	}
534 569
 	// Windows is trickier.  Let's try opening for r+...
535 570
 	else
@@ -539,30 +574,35 @@  discard block
 block discarded – undo
539 574
 		foreach ($writable_files as $file)
540 575
 		{
541 576
 			// Folders can't be opened for write... but the index.php in them can ;)
542
-			if (is_dir(dirname(__FILE__) . '/' . $file))
543
-				$file .= '/index.php';
577
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
578
+							$file .= '/index.php';
579
+			}
544 580
 
545 581
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
546 582
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
547 583
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
548 584
 
549 585
 			// Hmm, okay, try just for write in that case...
550
-			if (!is_resource($fp))
551
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
586
+			if (!is_resource($fp)) {
587
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
588
+			}
552 589
 
553
-			if (!is_resource($fp))
554
-				$failed_files[] = $file;
590
+			if (!is_resource($fp)) {
591
+							$failed_files[] = $file;
592
+			}
555 593
 
556 594
 			@fclose($fp);
557 595
 		}
558
-		foreach ($extra_files as $file)
559
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
596
+		foreach ($extra_files as $file) {
597
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
598
+		}
560 599
 	}
561 600
 
562 601
 	$failure = count($failed_files) >= 1;
563 602
 
564
-	if (!isset($_SERVER))
565
-		return !$failure;
603
+	if (!isset($_SERVER)) {
604
+			return !$failure;
605
+	}
566 606
 
567 607
 	// Put the list into context.
568 608
 	$incontext['failed_files'] = $failed_files;
@@ -610,19 +650,23 @@  discard block
 block discarded – undo
610 650
 
611 651
 		if (!isset($ftp) || $ftp->error !== false)
612 652
 		{
613
-			if (!isset($ftp))
614
-				$ftp = new ftp_connection(null);
653
+			if (!isset($ftp)) {
654
+							$ftp = new ftp_connection(null);
655
+			}
615 656
 			// Save the error so we can mess with listing...
616
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
617
-				$incontext['ftp_errors'][] = $ftp->last_message;
657
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
658
+							$incontext['ftp_errors'][] = $ftp->last_message;
659
+			}
618 660
 
619 661
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
620 662
 
621
-			if (empty($_POST['ftp_path']) && $found_path)
622
-				$_POST['ftp_path'] = $detect_path;
663
+			if (empty($_POST['ftp_path']) && $found_path) {
664
+							$_POST['ftp_path'] = $detect_path;
665
+			}
623 666
 
624
-			if (!isset($_POST['ftp_username']))
625
-				$_POST['ftp_username'] = $username;
667
+			if (!isset($_POST['ftp_username'])) {
668
+							$_POST['ftp_username'] = $username;
669
+			}
626 670
 
627 671
 			// Set the username etc, into context.
628 672
 			$incontext['ftp'] = array(
@@ -634,8 +678,7 @@  discard block
 block discarded – undo
634 678
 			);
635 679
 
636 680
 			return false;
637
-		}
638
-		else
681
+		} else
639 682
 		{
640 683
 			$_SESSION['installer_temp_ftp'] = array(
641 684
 				'server' => $_POST['ftp_server'],
@@ -649,10 +692,12 @@  discard block
 block discarded – undo
649 692
 
650 693
 			foreach ($failed_files as $file)
651 694
 			{
652
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
653
-					$ftp->chmod($file, 0755);
654
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
655
-					$ftp->chmod($file, 0777);
695
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
696
+									$ftp->chmod($file, 0755);
697
+				}
698
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
699
+									$ftp->chmod($file, 0777);
700
+				}
656 701
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
657 702
 				{
658 703
 					$failed_files_updated[] = $file;
@@ -707,15 +752,17 @@  discard block
 block discarded – undo
707 752
 
708 753
 			if (!$foundOne)
709 754
 			{
710
-				if (isset($db['default_host']))
711
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
755
+				if (isset($db['default_host'])) {
756
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
757
+				}
712 758
 				if (isset($db['default_user']))
713 759
 				{
714 760
 					$incontext['db']['user'] = ini_get($db['default_user']);
715 761
 					$incontext['db']['name'] = ini_get($db['default_user']);
716 762
 				}
717
-				if (isset($db['default_password']))
718
-					$incontext['db']['pass'] = ini_get($db['default_password']);
763
+				if (isset($db['default_password'])) {
764
+									$incontext['db']['pass'] = ini_get($db['default_password']);
765
+				}
719 766
 
720 767
 				// For simplicity and less confusion, leave the port blank by default
721 768
 				$incontext['db']['port'] = '';
@@ -734,10 +781,10 @@  discard block
 block discarded – undo
734 781
 		$incontext['db']['server'] = $_POST['db_server'];
735 782
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
736 783
 
737
-		if (!empty($_POST['db_port']))
738
-			$incontext['db']['port'] = $_POST['db_port'];
739
-	}
740
-	else
784
+		if (!empty($_POST['db_port'])) {
785
+					$incontext['db']['port'] = $_POST['db_port'];
786
+		}
787
+	} else
741 788
 	{
742 789
 		$incontext['db']['prefix'] = 'smf_';
743 790
 	}
@@ -773,10 +820,11 @@  discard block
 block discarded – undo
773 820
 		if (!empty($_POST['db_port']))
774 821
 		{
775 822
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
776
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
777
-				$vars['db_port'] = (int) $_POST['db_port'];
778
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
779
-				$vars['db_port'] = (int) $_POST['db_port'];
823
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
824
+							$vars['db_port'] = (int) $_POST['db_port'];
825
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
826
+							$vars['db_port'] = (int) $_POST['db_port'];
827
+			}
780 828
 		}
781 829
 
782 830
 		// God I hope it saved!
@@ -789,8 +837,9 @@  discard block
 block discarded – undo
789 837
 		// Make sure it works.
790 838
 		require(dirname(__FILE__) . '/Settings.php');
791 839
 
792
-		if (empty($sourcedir))
793
-			$sourcedir = dirname(__FILE__) . '/Sources';
840
+		if (empty($sourcedir)) {
841
+					$sourcedir = dirname(__FILE__) . '/Sources';
842
+		}
794 843
 
795 844
 		// Better find the database file!
796 845
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -800,18 +849,21 @@  discard block
 block discarded – undo
800 849
 		}
801 850
 
802 851
 		// Now include it for database functions!
803
-		if (!defined('SMF'))
804
-			define('SMF', 1);
852
+		if (!defined('SMF')) {
853
+					define('SMF', 1);
854
+		}
805 855
 
806 856
 		$modSettings['disableQueryCheck'] = true;
807
-		if (empty($smcFunc))
808
-			$smcFunc = array();
857
+		if (empty($smcFunc)) {
858
+					$smcFunc = array();
859
+		}
809 860
 
810 861
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
811 862
 
812 863
 		// What - running PHP4? The shame!
813
-		if (version_compare(PHP_VERSION, '5', '<'))
814
-			require_once($sourcedir . '/Subs-Compat.php');
864
+		if (version_compare(PHP_VERSION, '5', '<')) {
865
+					require_once($sourcedir . '/Subs-Compat.php');
866
+		}
815 867
 
816 868
 		// Attempt a connection.
817 869
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -899,12 +951,14 @@  discard block
 block discarded – undo
899 951
 	$incontext['page_title'] = $txt['install_settings'];
900 952
 
901 953
 	// Let's see if we got the database type correct.
902
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
903
-		$db_type = $_POST['db_type'];
954
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
955
+			$db_type = $_POST['db_type'];
956
+	}
904 957
 
905 958
 	// Else we'd better be able to get the connection.
906
-	else
907
-		load_database();
959
+	else {
960
+			load_database();
961
+	}
908 962
 
909 963
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
910 964
 
@@ -924,12 +978,14 @@  discard block
 block discarded – undo
924 978
 	// Submitting?
925 979
 	if (isset($_POST['boardurl']))
926 980
 	{
927
-		if (substr($_POST['boardurl'], -10) == '/index.php')
928
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
929
-		elseif (substr($_POST['boardurl'], -1) == '/')
930
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
931
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
932
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
981
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
982
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
983
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
984
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
985
+		}
986
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
987
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
988
+		}
933 989
 
934 990
 		// Save these variables.
935 991
 		$vars = array(
@@ -960,10 +1016,10 @@  discard block
 block discarded – undo
960 1016
 			{
961 1017
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
962 1018
 				return false;
963
-			}
964
-			else
965
-				// Set the character set here.
1019
+			} else {
1020
+							// Set the character set here.
966 1021
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1022
+			}
967 1023
 		}
968 1024
 
969 1025
 		// Good, skip on.
@@ -983,8 +1039,9 @@  discard block
 block discarded – undo
983 1039
 	$incontext['continue'] = 1;
984 1040
 
985 1041
 	// Already done?
986
-	if (isset($_POST['pop_done']))
987
-		return true;
1042
+	if (isset($_POST['pop_done'])) {
1043
+			return true;
1044
+	}
988 1045
 
989 1046
 	// Reload settings.
990 1047
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1002,8 +1059,9 @@  discard block
 block discarded – undo
1002 1059
 	$modSettings = array();
1003 1060
 	if ($result !== false)
1004 1061
 	{
1005
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1006
-			$modSettings[$row['variable']] = $row['value'];
1062
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1063
+					$modSettings[$row['variable']] = $row['value'];
1064
+		}
1007 1065
 		$smcFunc['db_free_result']($result);
1008 1066
 
1009 1067
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1016,20 +1074,22 @@  discard block
 block discarded – undo
1016 1074
 	$modSettings['disableQueryCheck'] = true;
1017 1075
 
1018 1076
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1019
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1020
-		$smcFunc['db_query']('', '
1077
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1078
+			$smcFunc['db_query']('', '
1021 1079
 			SET NAMES {string:utf8}',
1022 1080
 			array(
1023 1081
 				'db_error_skip' => true,
1024 1082
 				'utf8' => 'utf8',
1025 1083
 			)
1026 1084
 		);
1085
+	}
1027 1086
 
1028 1087
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1029
-	if (substr(__DIR__, -1) == '\\')
1030
-		$attachdir = __DIR__ . 'attachments';
1031
-	else
1032
-		$attachdir = __DIR__ . '/attachments';
1088
+	if (substr(__DIR__, -1) == '\\') {
1089
+			$attachdir = __DIR__ . 'attachments';
1090
+	} else {
1091
+			$attachdir = __DIR__ . '/attachments';
1092
+	}
1033 1093
 
1034 1094
 	$replaces = array(
1035 1095
 		'{$db_prefix}' => $db_prefix,
@@ -1046,8 +1106,9 @@  discard block
 block discarded – undo
1046 1106
 
1047 1107
 	foreach ($txt as $key => $value)
1048 1108
 	{
1049
-		if (substr($key, 0, 8) == 'default_')
1050
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1109
+		if (substr($key, 0, 8) == 'default_') {
1110
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1111
+		}
1051 1112
 	}
1052 1113
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1053 1114
 
@@ -1062,8 +1123,9 @@  discard block
 block discarded – undo
1062 1123
 
1063 1124
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1064 1125
 		{
1065
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1066
-				$engines[] = $row['Engine'];
1126
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1127
+							$engines[] = $row['Engine'];
1128
+			}
1067 1129
 		}
1068 1130
 
1069 1131
 		// Done with this now
@@ -1087,8 +1149,7 @@  discard block
 block discarded – undo
1087 1149
 			$replaces['START TRANSACTION;'] = '';
1088 1150
 			$replaces['COMMIT;'] = '';
1089 1151
 		}
1090
-	}
1091
-	else
1152
+	} else
1092 1153
 	{
1093 1154
 		$has_innodb = false;
1094 1155
 	}
@@ -1110,21 +1171,24 @@  discard block
 block discarded – undo
1110 1171
 	foreach ($sql_lines as $count => $line)
1111 1172
 	{
1112 1173
 		// No comments allowed!
1113
-		if (substr(trim($line), 0, 1) != '#')
1114
-			$current_statement .= "\n" . rtrim($line);
1174
+		if (substr(trim($line), 0, 1) != '#') {
1175
+					$current_statement .= "\n" . rtrim($line);
1176
+		}
1115 1177
 
1116 1178
 		// Is this the end of the query string?
1117
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1118
-			continue;
1179
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1180
+					continue;
1181
+		}
1119 1182
 
1120 1183
 		// Does this table already exist?  If so, don't insert more data into it!
1121 1184
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1122 1185
 		{
1123 1186
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1124
-			if (!empty($matches[0]))
1125
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1126
-			else
1127
-				$incontext['sql_results']['insert_dups']++;
1187
+			if (!empty($matches[0])) {
1188
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1189
+			} else {
1190
+							$incontext['sql_results']['insert_dups']++;
1191
+			}
1128 1192
 
1129 1193
 			$current_statement = '';
1130 1194
 			continue;
@@ -1133,8 +1197,9 @@  discard block
 block discarded – undo
1133 1197
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1134 1198
 		{
1135 1199
 			// Use the appropriate function based on the DB type
1136
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1137
-				$db_errorno = $db_type . '_errno';
1200
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1201
+							$db_errorno = $db_type . '_errno';
1202
+			}
1138 1203
 
1139 1204
 			// Error 1050: Table already exists!
1140 1205
 			// @todo Needs to be made better!
@@ -1149,18 +1214,18 @@  discard block
 block discarded – undo
1149 1214
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1150 1215
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1151 1216
 			}
1152
-		}
1153
-		else
1217
+		} else
1154 1218
 		{
1155
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1156
-				$incontext['sql_results']['tables']++;
1157
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1219
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1220
+							$incontext['sql_results']['tables']++;
1221
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1158 1222
 			{
1159 1223
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1160
-				if (!empty($matches[0]))
1161
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1162
-				else
1163
-					$incontext['sql_results']['inserts']++;
1224
+				if (!empty($matches[0])) {
1225
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1226
+				} else {
1227
+									$incontext['sql_results']['inserts']++;
1228
+				}
1164 1229
 			}
1165 1230
 		}
1166 1231
 
@@ -1173,15 +1238,17 @@  discard block
 block discarded – undo
1173 1238
 	// Sort out the context for the SQL.
1174 1239
 	foreach ($incontext['sql_results'] as $key => $number)
1175 1240
 	{
1176
-		if ($number == 0)
1177
-			unset($incontext['sql_results'][$key]);
1178
-		else
1179
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1241
+		if ($number == 0) {
1242
+					unset($incontext['sql_results'][$key]);
1243
+		} else {
1244
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1245
+		}
1180 1246
 	}
1181 1247
 
1182 1248
 	// Make sure UTF will be used globally.
1183
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1184
-		$newSettings[] = array('global_character_set', 'UTF-8');
1249
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1250
+			$newSettings[] = array('global_character_set', 'UTF-8');
1251
+	}
1185 1252
 
1186 1253
 	// Maybe we can auto-detect better cookie settings?
1187 1254
 	preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
@@ -1192,16 +1259,20 @@  discard block
 block discarded – undo
1192 1259
 		$globalCookies = false;
1193 1260
 
1194 1261
 		// Okay... let's see.  Using a subdomain other than www.? (not a perfect check.)
1195
-		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
1196
-			$globalCookies = true;
1262
+		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) {
1263
+					$globalCookies = true;
1264
+		}
1197 1265
 		// If there's a / in the middle of the path, or it starts with ~... we want local.
1198
-		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
1199
-			$localCookies = true;
1266
+		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) {
1267
+					$localCookies = true;
1268
+		}
1200 1269
 
1201
-		if ($globalCookies)
1202
-			$newSettings[] = array('globalCookies', '1');
1203
-		if ($localCookies)
1204
-			$newSettings[] = array('localCookies', '1');
1270
+		if ($globalCookies) {
1271
+					$newSettings[] = array('globalCookies', '1');
1272
+		}
1273
+		if ($localCookies) {
1274
+					$newSettings[] = array('localCookies', '1');
1275
+		}
1205 1276
 	}
1206 1277
 
1207 1278
 	// Are we allowing stat collection?
@@ -1217,32 +1288,36 @@  discard block
 block discarded – undo
1217 1288
 			fwrite($fp, $out);
1218 1289
 
1219 1290
 			$return_data = '';
1220
-			while (!feof($fp))
1221
-				$return_data .= fgets($fp, 128);
1291
+			while (!feof($fp)) {
1292
+							$return_data .= fgets($fp, 128);
1293
+			}
1222 1294
 
1223 1295
 			fclose($fp);
1224 1296
 
1225 1297
 			// Get the unique site ID.
1226 1298
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1227 1299
 
1228
-			if (!empty($ID[1]))
1229
-				$newSettings[] = array('allow_sm_stats', $ID[1]);
1300
+			if (!empty($ID[1])) {
1301
+							$newSettings[] = array('allow_sm_stats', $ID[1]);
1302
+			}
1230 1303
 		}
1231 1304
 	}
1232 1305
 
1233 1306
 	// Are we enabling SSL?
1234
-	if (!empty($_POST['force_ssl']))
1235
-		$newSettings[] = array('force_ssl', 2);
1307
+	if (!empty($_POST['force_ssl'])) {
1308
+			$newSettings[] = array('force_ssl', 2);
1309
+	}
1236 1310
 
1237 1311
 	// Setting a timezone is required.
1238 1312
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1239 1313
 	{
1240 1314
 		// Get PHP's default timezone, if set
1241 1315
 		$ini_tz = ini_get('date.timezone');
1242
-		if (!empty($ini_tz))
1243
-			$timezone_id = $ini_tz;
1244
-		else
1245
-			$timezone_id = '';
1316
+		if (!empty($ini_tz)) {
1317
+					$timezone_id = $ini_tz;
1318
+		} else {
1319
+					$timezone_id = '';
1320
+		}
1246 1321
 
1247 1322
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1248 1323
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1251,8 +1326,9 @@  discard block
 block discarded – undo
1251 1326
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1252 1327
 		}
1253 1328
 
1254
-		if (date_default_timezone_set($timezone_id))
1255
-			$newSettings[] = array('default_timezone', $timezone_id);
1329
+		if (date_default_timezone_set($timezone_id)) {
1330
+					$newSettings[] = array('default_timezone', $timezone_id);
1331
+		}
1256 1332
 	}
1257 1333
 
1258 1334
 	if (!empty($newSettings))
@@ -1283,16 +1359,18 @@  discard block
 block discarded – undo
1283 1359
 	}
1284 1360
 
1285 1361
 	// MySQL specific stuff
1286
-	if (substr($db_type, 0, 5) != 'mysql')
1287
-		return false;
1362
+	if (substr($db_type, 0, 5) != 'mysql') {
1363
+			return false;
1364
+	}
1288 1365
 
1289 1366
 	// Find database user privileges.
1290 1367
 	$privs = array();
1291 1368
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1292 1369
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1293 1370
 	{
1294
-		if ($row['Privilege'] == 'Alter')
1295
-			$privs[] = $row['Privilege'];
1371
+		if ($row['Privilege'] == 'Alter') {
1372
+					$privs[] = $row['Privilege'];
1373
+		}
1296 1374
 	}
1297 1375
 	$smcFunc['db_free_result']($get_privs);
1298 1376
 
@@ -1322,8 +1400,9 @@  discard block
 block discarded – undo
1322 1400
 	$incontext['continue'] = 1;
1323 1401
 
1324 1402
 	// Skipping?
1325
-	if (!empty($_POST['skip']))
1326
-		return true;
1403
+	if (!empty($_POST['skip'])) {
1404
+			return true;
1405
+	}
1327 1406
 
1328 1407
 	// Need this to check whether we need the database password.
1329 1408
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1336,18 +1415,22 @@  discard block
 block discarded – undo
1336 1415
 	// We need this to properly hash the password for Admin
1337 1416
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1338 1417
 			global $sourcedir;
1339
-			if (function_exists('mb_strtolower'))
1340
-				return mb_strtolower($string, 'UTF-8');
1418
+			if (function_exists('mb_strtolower')) {
1419
+							return mb_strtolower($string, 'UTF-8');
1420
+			}
1341 1421
 			require_once($sourcedir . '/Subs-Charset.php');
1342 1422
 			return utf8_strtolower($string);
1343 1423
 		};
1344 1424
 
1345
-	if (!isset($_POST['username']))
1346
-		$_POST['username'] = '';
1347
-	if (!isset($_POST['email']))
1348
-		$_POST['email'] = '';
1349
-	if (!isset($_POST['server_email']))
1350
-		$_POST['server_email'] = '';
1425
+	if (!isset($_POST['username'])) {
1426
+			$_POST['username'] = '';
1427
+	}
1428
+	if (!isset($_POST['email'])) {
1429
+			$_POST['email'] = '';
1430
+	}
1431
+	if (!isset($_POST['server_email'])) {
1432
+			$_POST['server_email'] = '';
1433
+	}
1351 1434
 
1352 1435
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1353 1436
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1366,8 +1449,9 @@  discard block
 block discarded – undo
1366 1449
 			'admin_group' => 1,
1367 1450
 		)
1368 1451
 	);
1369
-	if ($smcFunc['db_num_rows']($request) != 0)
1370
-		$incontext['skip'] = 1;
1452
+	if ($smcFunc['db_num_rows']($request) != 0) {
1453
+			$incontext['skip'] = 1;
1454
+	}
1371 1455
 	$smcFunc['db_free_result']($request);
1372 1456
 
1373 1457
 	// Trying to create an account?
@@ -1398,8 +1482,9 @@  discard block
 block discarded – undo
1398 1482
 		}
1399 1483
 
1400 1484
 		// Update the webmaster's email?
1401
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1402
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1485
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1486
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1487
+		}
1403 1488
 
1404 1489
 		// Work out whether we're going to have dodgy characters and remove them.
1405 1490
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1422,32 +1507,27 @@  discard block
 block discarded – undo
1422 1507
 			$smcFunc['db_free_result']($result);
1423 1508
 
1424 1509
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1425
-		}
1426
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1510
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1427 1511
 		{
1428 1512
 			// Try the previous step again.
1429 1513
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1430 1514
 			return false;
1431
-		}
1432
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1515
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1433 1516
 		{
1434 1517
 			// Try the previous step again.
1435 1518
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1436 1519
 			return false;
1437
-		}
1438
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1520
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1439 1521
 		{
1440 1522
 			// One step back, this time fill out a proper admin email address.
1441 1523
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1442 1524
 			return false;
1443
-		}
1444
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1525
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1445 1526
 		{
1446 1527
 			// One step back, this time fill out a proper admin email address.
1447 1528
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1448 1529
 			return false;
1449
-		}
1450
-		elseif ($_POST['username'] != '')
1530
+		} elseif ($_POST['username'] != '')
1451 1531
 		{
1452 1532
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1453 1533
 
@@ -1513,17 +1593,19 @@  discard block
 block discarded – undo
1513 1593
 	require_once($sourcedir . '/Subs-Auth.php');
1514 1594
 
1515 1595
 	// Bring a warning over.
1516
-	if (!empty($incontext['account_existed']))
1517
-		$incontext['warning'] = $incontext['account_existed'];
1596
+	if (!empty($incontext['account_existed'])) {
1597
+			$incontext['warning'] = $incontext['account_existed'];
1598
+	}
1518 1599
 
1519
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1520
-		$smcFunc['db_query']('', '
1600
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1601
+			$smcFunc['db_query']('', '
1521 1602
 			SET NAMES {string:db_character_set}',
1522 1603
 			array(
1523 1604
 				'db_character_set' => $db_character_set,
1524 1605
 				'db_error_skip' => true,
1525 1606
 			)
1526 1607
 		);
1608
+	}
1527 1609
 
1528 1610
 	// As track stats is by default enabled let's add some activity.
1529 1611
 	$smcFunc['db_insert']('ignore',
@@ -1544,14 +1626,16 @@  discard block
 block discarded – undo
1544 1626
 	// Only proceed if we can load the data.
1545 1627
 	if ($request)
1546 1628
 	{
1547
-		while ($row = $smcFunc['db_fetch_row']($request))
1548
-			$modSettings[$row[0]] = $row[1];
1629
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1630
+					$modSettings[$row[0]] = $row[1];
1631
+		}
1549 1632
 		$smcFunc['db_free_result']($request);
1550 1633
 	}
1551 1634
 
1552 1635
 	// Automatically log them in ;)
1553
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1554
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1636
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1637
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1638
+	}
1555 1639
 
1556 1640
 	$result = $smcFunc['db_query']('', '
1557 1641
 		SELECT value
@@ -1562,13 +1646,14 @@  discard block
 block discarded – undo
1562 1646
 			'db_error_skip' => true,
1563 1647
 		)
1564 1648
 	);
1565
-	if ($smcFunc['db_num_rows']($result) != 0)
1566
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1649
+	if ($smcFunc['db_num_rows']($result) != 0) {
1650
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1651
+	}
1567 1652
 	$smcFunc['db_free_result']($result);
1568 1653
 
1569
-	if (empty($db_sessions))
1570
-		$_SESSION['admin_time'] = time();
1571
-	else
1654
+	if (empty($db_sessions)) {
1655
+			$_SESSION['admin_time'] = time();
1656
+	} else
1572 1657
 	{
1573 1658
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1574 1659
 
@@ -1592,8 +1677,9 @@  discard block
 block discarded – undo
1592 1677
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1593 1678
 		function($string){
1594 1679
 			global $sourcedir;
1595
-			if (function_exists('mb_strtolower'))
1596
-				return mb_strtolower($string, 'UTF-8');
1680
+			if (function_exists('mb_strtolower')) {
1681
+							return mb_strtolower($string, 'UTF-8');
1682
+			}
1597 1683
 			require_once($sourcedir . '/Subs-Charset.php');
1598 1684
 			return utf8_strtolower($string);
1599 1685
 		};
@@ -1609,8 +1695,9 @@  discard block
 block discarded – undo
1609 1695
 		)
1610 1696
 	);
1611 1697
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1612
-	if ($smcFunc['db_num_rows']($request) > 0)
1613
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1698
+	if ($smcFunc['db_num_rows']($request) > 0) {
1699
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1700
+	}
1614 1701
 	$smcFunc['db_free_result']($request);
1615 1702
 
1616 1703
 	// Now is the perfect time to fetch the SM files.
@@ -1629,8 +1716,9 @@  discard block
 block discarded – undo
1629 1716
 
1630 1717
 	// Check if we need some stupid MySQL fix.
1631 1718
 	$server_version = $smcFunc['db_server_info']();
1632
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1633
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1719
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1720
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1721
+	}
1634 1722
 
1635 1723
 	// Some final context for the template.
1636 1724
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1650,8 +1738,9 @@  discard block
 block discarded – undo
1650 1738
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1651 1739
 
1652 1740
 	// @todo Do we just want to read the file in clean, and split it this way always?
1653
-	if (count($settingsArray) == 1)
1654
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1741
+	if (count($settingsArray) == 1) {
1742
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1743
+	}
1655 1744
 
1656 1745
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1657 1746
 	{
@@ -1666,19 +1755,22 @@  discard block
 block discarded – undo
1666 1755
 			continue;
1667 1756
 		}
1668 1757
 
1669
-		if (trim($settingsArray[$i]) == '?' . '>')
1670
-			$settingsArray[$i] = '';
1758
+		if (trim($settingsArray[$i]) == '?' . '>') {
1759
+					$settingsArray[$i] = '';
1760
+		}
1671 1761
 
1672 1762
 		// Don't trim or bother with it if it's not a variable.
1673
-		if (substr($settingsArray[$i], 0, 1) != '$')
1674
-			continue;
1763
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1764
+					continue;
1765
+		}
1675 1766
 
1676 1767
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1677 1768
 
1678
-		foreach ($vars as $var => $val)
1679
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1769
+		foreach ($vars as $var => $val) {
1770
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1680 1771
 			{
1681 1772
 				$comment = strstr($settingsArray[$i], '#');
1773
+		}
1682 1774
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1683 1775
 				unset($vars[$var]);
1684 1776
 			}
@@ -1688,36 +1780,41 @@  discard block
 block discarded – undo
1688 1780
 	if (!empty($vars))
1689 1781
 	{
1690 1782
 		$settingsArray[$i++] = '';
1691
-		foreach ($vars as $var => $val)
1692
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1783
+		foreach ($vars as $var => $val) {
1784
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1785
+		}
1693 1786
 	}
1694 1787
 
1695 1788
 	// Blank out the file - done to fix a oddity with some servers.
1696 1789
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1697
-	if (!$fp)
1698
-		return false;
1790
+	if (!$fp) {
1791
+			return false;
1792
+	}
1699 1793
 	fclose($fp);
1700 1794
 
1701 1795
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1702 1796
 
1703 1797
 	// Gotta have one of these ;)
1704
-	if (trim($settingsArray[0]) != '<?php')
1705
-		fwrite($fp, "<?php\n");
1798
+	if (trim($settingsArray[0]) != '<?php') {
1799
+			fwrite($fp, "<?php\n");
1800
+	}
1706 1801
 
1707 1802
 	$lines = count($settingsArray);
1708 1803
 	for ($i = 0; $i < $lines - 1; $i++)
1709 1804
 	{
1710 1805
 		// Don't just write a bunch of blank lines.
1711
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1712
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1806
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1807
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1808
+		}
1713 1809
 	}
1714 1810
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1715 1811
 	fclose($fp);
1716 1812
 
1717 1813
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1718 1814
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1719
-	if (function_exists('opcache_invalidate'))
1720
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1815
+	if (function_exists('opcache_invalidate')) {
1816
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1817
+	}
1721 1818
 
1722 1819
 	return true;
1723 1820
 }
@@ -1742,9 +1839,9 @@  discard block
 block discarded – undo
1742 1839
 	SecFilterScanPOST Off
1743 1840
 </IfModule>';
1744 1841
 
1745
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1746
-		return true;
1747
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1842
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1843
+			return true;
1844
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1748 1845
 	{
1749 1846
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1750 1847
 
@@ -1756,29 +1853,28 @@  discard block
 block discarded – undo
1756 1853
 				fwrite($ht_handle, $htaccess_addition);
1757 1854
 				fclose($ht_handle);
1758 1855
 				return true;
1856
+			} else {
1857
+							return false;
1759 1858
 			}
1760
-			else
1761
-				return false;
1859
+		} else {
1860
+					return true;
1762 1861
 		}
1763
-		else
1764
-			return true;
1765
-	}
1766
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1767
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1768
-	elseif (is_writable(dirname(__FILE__)))
1862
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1863
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1864
+	} elseif (is_writable(dirname(__FILE__)))
1769 1865
 	{
1770 1866
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1771 1867
 		{
1772 1868
 			fwrite($ht_handle, $htaccess_addition);
1773 1869
 			fclose($ht_handle);
1774 1870
 			return true;
1871
+		} else {
1872
+					return false;
1775 1873
 		}
1776
-		else
1874
+	} else {
1777 1875
 			return false;
1778 1876
 	}
1779
-	else
1780
-		return false;
1781
-}
1877
+	}
1782 1878
 
1783 1879
 function template_install_above()
1784 1880
 {
@@ -1816,9 +1912,10 @@  discard block
 block discarded – undo
1816 1912
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1817 1913
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1818 1914
 
1819
-		foreach ($incontext['detected_languages'] as $lang => $name)
1820
-			echo '
1915
+		foreach ($incontext['detected_languages'] as $lang => $name) {
1916
+					echo '
1821 1917
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
1918
+		}
1822 1919
 
1823 1920
 		echo '
1824 1921
 								</select>
@@ -1838,9 +1935,10 @@  discard block
 block discarded – undo
1838 1935
 						<h2>', $txt['upgrade_progress'], '</h2>
1839 1936
 						<ul>';
1840 1937
 
1841
-	foreach ($incontext['steps'] as $num => $step)
1842
-		echo '
1938
+	foreach ($incontext['steps'] as $num => $step) {
1939
+			echo '
1843 1940
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
1941
+	}
1844 1942
 
1845 1943
 	echo '
1846 1944
 						</ul>
@@ -1865,20 +1963,23 @@  discard block
 block discarded – undo
1865 1963
 		echo '
1866 1964
 								<div>';
1867 1965
 
1868
-		if (!empty($incontext['continue']))
1869
-			echo '
1966
+		if (!empty($incontext['continue'])) {
1967
+					echo '
1870 1968
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1871
-		if (!empty($incontext['skip']))
1872
-			echo '
1969
+		}
1970
+		if (!empty($incontext['skip'])) {
1971
+					echo '
1873 1972
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1973
+		}
1874 1974
 		echo '
1875 1975
 								</div>';
1876 1976
 	}
1877 1977
 
1878 1978
 	// Show the closing form tag and other data only if not in the last step
1879
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1880
-		echo '
1979
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
1980
+			echo '
1881 1981
 							</form>';
1982
+	}
1882 1983
 
1883 1984
 	echo '
1884 1985
 						</div>
@@ -1913,13 +2014,15 @@  discard block
 block discarded – undo
1913 2014
 		</div>';
1914 2015
 
1915 2016
 	// Show the warnings, or not.
1916
-	if (template_warning_divs())
1917
-		echo '
2017
+	if (template_warning_divs()) {
2018
+			echo '
1918 2019
 		<h3>', $txt['install_all_lovely'], '</h3>';
2020
+	}
1919 2021
 
1920 2022
 	// Say we want the continue button!
1921
-	if (empty($incontext['error']))
1922
-		$incontext['continue'] = 1;
2023
+	if (empty($incontext['error'])) {
2024
+			$incontext['continue'] = 1;
2025
+	}
1923 2026
 
1924 2027
 	// For the latest version stuff.
1925 2028
 	echo '
@@ -1953,8 +2056,8 @@  discard block
 block discarded – undo
1953 2056
 	global $txt, $incontext;
1954 2057
 
1955 2058
 	// Errors are very serious..
1956
-	if (!empty($incontext['error']))
1957
-		echo '
2059
+	if (!empty($incontext['error'])) {
2060
+			echo '
1958 2061
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1959 2062
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1960 2063
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -1962,9 +2065,10 @@  discard block
 block discarded – undo
1962 2065
 				', $incontext['error'], '
1963 2066
 			</div>
1964 2067
 		</div>';
2068
+	}
1965 2069
 	// A warning message?
1966
-	elseif (!empty($incontext['warning']))
1967
-		echo '
2070
+	elseif (!empty($incontext['warning'])) {
2071
+			echo '
1968 2072
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1969 2073
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1970 2074
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -1972,6 +2076,7 @@  discard block
 block discarded – undo
1972 2076
 				', $incontext['warning'], '
1973 2077
 			</div>
1974 2078
 		</div>';
2079
+	}
1975 2080
 
1976 2081
 	return empty($incontext['error']) && empty($incontext['warning']);
1977 2082
 }
@@ -1987,27 +2092,30 @@  discard block
 block discarded – undo
1987 2092
 			<li>', $incontext['failed_files']), '</li>
1988 2093
 		</ul>';
1989 2094
 
1990
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
1991
-		echo '
2095
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2096
+			echo '
1992 2097
 		<hr>
1993 2098
 		<p>', $txt['chmod_linux_info'], '</p>
1994 2099
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2100
+	}
1995 2101
 
1996 2102
 	// This is serious!
1997
-	if (!template_warning_divs())
1998
-		return;
2103
+	if (!template_warning_divs()) {
2104
+			return;
2105
+	}
1999 2106
 
2000 2107
 	echo '
2001 2108
 		<hr>
2002 2109
 		<p>', $txt['ftp_setup_info'], '</p>';
2003 2110
 
2004
-	if (!empty($incontext['ftp_errors']))
2005
-		echo '
2111
+	if (!empty($incontext['ftp_errors'])) {
2112
+			echo '
2006 2113
 		<div class="error_message">
2007 2114
 			', $txt['error_ftp_no_connect'], '<br><br>
2008 2115
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2009 2116
 		</div>
2010 2117
 		<br>';
2118
+	}
2011 2119
 
2012 2120
 	echo '
2013 2121
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2067,17 +2175,17 @@  discard block
 block discarded – undo
2067 2175
 				<td>
2068 2176
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2069 2177
 
2070
-	foreach ($incontext['supported_databases'] as $key => $db)
2071
-			echo '
2178
+	foreach ($incontext['supported_databases'] as $key => $db) {
2179
+				echo '
2072 2180
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2181
+	}
2073 2182
 
2074 2183
 	echo '
2075 2184
 					</select>
2076 2185
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2077 2186
 				</td>
2078 2187
 			</tr>';
2079
-	}
2080
-	else
2188
+	} else
2081 2189
 	{
2082 2190
 		echo '
2083 2191
 			<tr style="display: none;">
@@ -2269,9 +2377,10 @@  discard block
 block discarded – undo
2269 2377
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2270 2378
 				<ul>';
2271 2379
 
2272
-		foreach ($incontext['failures'] as $line => $fail)
2273
-			echo '
2380
+		foreach ($incontext['failures'] as $line => $fail) {
2381
+					echo '
2274 2382
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2383
+		}
2275 2384
 
2276 2385
 		echo '
2277 2386
 				</ul>';
@@ -2332,15 +2441,16 @@  discard block
 block discarded – undo
2332 2441
 			</tr>
2333 2442
 		</table>';
2334 2443
 
2335
-	if ($incontext['require_db_confirm'])
2336
-		echo '
2444
+	if ($incontext['require_db_confirm']) {
2445
+			echo '
2337 2446
 		<h2>', $txt['user_settings_database'], '</h2>
2338 2447
 		<p>', $txt['user_settings_database_info'], '</p>
2339 2448
 
2340 2449
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2341 2450
 			<input type="password" name="password3" size="30" class="input_password" />
2342 2451
 		</div>';
2343
-}
2452
+	}
2453
+	}
2344 2454
 
2345 2455
 // Tell them it's done, and to delete.
2346 2456
 function template_delete_install()
@@ -2353,14 +2463,15 @@  discard block
 block discarded – undo
2353 2463
 	template_warning_divs();
2354 2464
 
2355 2465
 	// Install directory still writable?
2356
-	if ($incontext['dir_still_writable'])
2357
-		echo '
2466
+	if ($incontext['dir_still_writable']) {
2467
+			echo '
2358 2468
 		<em>', $txt['still_writable'], '</em><br>
2359 2469
 		<br>';
2470
+	}
2360 2471
 
2361 2472
 	// Don't show the box if it's like 99% sure it won't work :P.
2362
-	if ($incontext['probably_delete_install'])
2363
-		echo '
2473
+	if ($incontext['probably_delete_install']) {
2474
+			echo '
2364 2475
 		<div style="margin: 1ex; font-weight: bold;">
2365 2476
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" class="input_check" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
2366 2477
 		</div>
@@ -2376,6 +2487,7 @@  discard block
 block discarded – undo
2376 2487
 			}
2377 2488
 		</script>
2378 2489
 		<br>';
2490
+	}
2379 2491
 
2380 2492
 	echo '
2381 2493
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.