Completed
Pull Request — release-2.1 (#4597)
by Michael
08:14
created
Sources/Session.php 1 patch
Braces   +37 added lines, -25 removed lines patch added patch discarded remove patch
@@ -17,8 +17,9 @@  discard block
 block discarded – undo
17 17
  * @version 2.1 Beta 4
18 18
  */
19 19
 
20
-if (!defined('SMF'))
20
+if (!defined('SMF')) {
21 21
 	die('No direct access...');
22
+}
22 23
 
23 24
 /**
24 25
  * Attempt to start the session, unless it already has been.
@@ -38,8 +39,9 @@  discard block
 block discarded – undo
38 39
 	{
39 40
 		$parsed_url = parse_url($boardurl);
40 41
 
41
-		if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
42
-			@ini_set('session.cookie_domain', '.' . $parts[1]);
42
+		if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
43
+					@ini_set('session.cookie_domain', '.' . $parts[1]);
44
+		}
43 45
 	}
44 46
 	// @todo Set the session cookie path?
45 47
 
@@ -47,8 +49,9 @@  discard block
 block discarded – undo
47 49
 	if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '')
48 50
 	{
49 51
 		// Attempt to end the already-started session.
50
-		if (ini_get('session.auto_start') == 1)
51
-			session_write_close();
52
+		if (ini_get('session.auto_start') == 1) {
53
+					session_write_close();
54
+		}
52 55
 
53 56
 		// This is here to stop people from using bad junky PHPSESSIDs.
54 57
 		if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()]))
@@ -63,23 +66,26 @@  discard block
 block discarded – undo
63 66
 		if (!empty($modSettings['databaseSession_enable']))
64 67
 		{
65 68
 			@ini_set('session.serialize_handler', 'php_serialize');
66
-			if (ini_get('session.serialize_handler') != 'php_serialize')
67
-				@ini_set('session.serialize_handler', 'php');
69
+			if (ini_get('session.serialize_handler') != 'php_serialize') {
70
+							@ini_set('session.serialize_handler', 'php');
71
+			}
68 72
 			session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC');
69 73
 			@ini_set('session.gc_probability', '1');
74
+		} elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) {
75
+					@ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60));
70 76
 		}
71
-		elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime']))
72
-			@ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60));
73 77
 
74 78
 		// Use cache setting sessions?
75
-		if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli')
76
-			call_integration_hook('integrate_session_handlers');
79
+		if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') {
80
+					call_integration_hook('integrate_session_handlers');
81
+		}
77 82
 
78 83
 		session_start();
79 84
 
80 85
 		// Change it so the cache settings are a little looser than default.
81
-		if (!empty($modSettings['databaseSession_loose']))
82
-			header('cache-control: private');
86
+		if (!empty($modSettings['databaseSession_loose'])) {
87
+					header('cache-control: private');
88
+		}
83 89
 	}
84 90
 
85 91
 	// Set the randomly generated code.
@@ -125,8 +131,9 @@  discard block
 block discarded – undo
125 131
 {
126 132
 	global $smcFunc;
127 133
 
128
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
129
-		return '';
134
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
135
+			return '';
136
+	}
130 137
 
131 138
 	// Look for it in the database.
132 139
 	$result = $smcFunc['db_query']('', '
@@ -155,8 +162,9 @@  discard block
 block discarded – undo
155 162
 {
156 163
 	global $smcFunc, $db_connection, $db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_persist, $db_port;
157 164
 
158
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
159
-		return false;
165
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
166
+			return false;
167
+	}
160 168
 
161 169
 	// php < 7.0 need this
162 170
 	if (empty($db_connection))
@@ -164,8 +172,9 @@  discard block
 block discarded – undo
164 172
 		$db_options = array();
165 173
 
166 174
 		// Add in the port if needed
167
-		if (!empty($db_port))
168
-			$db_options['port'] = $db_port;
175
+		if (!empty($db_port)) {
176
+					$db_options['port'] = $db_port;
177
+		}
169 178
 		$options = array_merge($db_options, array('persist' => $db_persist, 'dont_select_db' => SMF == 'SSI'));
170 179
 
171 180
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
@@ -184,13 +193,14 @@  discard block
 block discarded – undo
184 193
 	);
185 194
 
186 195
 	// If that didn't work, try inserting a new one.
187
-	if ($smcFunc['db_affected_rows']() == 0)
188
-		$smcFunc['db_insert']('ignore',
196
+	if ($smcFunc['db_affected_rows']() == 0) {
197
+			$smcFunc['db_insert']('ignore',
189 198
 			'{db_prefix}sessions',
190 199
 			array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'),
191 200
 			array($session_id, $data, time()),
192 201
 			array('session_id')
193 202
 		);
203
+	}
194 204
 
195 205
 	return ($smcFunc['db_affected_rows']() == 0 ? false : true);
196 206
 }
@@ -205,8 +215,9 @@  discard block
 block discarded – undo
205 215
 {
206 216
 	global $smcFunc;
207 217
 
208
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
209
-		return false;
218
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
219
+			return false;
220
+	}
210 221
 
211 222
 	// Just delete the row...
212 223
 	$smcFunc['db_query']('', '
@@ -232,8 +243,9 @@  discard block
 block discarded – undo
232 243
 	global $modSettings, $smcFunc;
233 244
 
234 245
 	// Just set to the default or lower?  Ignore it for a higher value. (hopefully)
235
-	if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime))
236
-		$max_lifetime = max($modSettings['databaseSession_lifetime'], 60);
246
+	if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) {
247
+			$max_lifetime = max($modSettings['databaseSession_lifetime'], 60);
248
+	}
237 249
 
238 250
 	// Clean up after yerself ;).
239 251
 	$smcFunc['db_query']('', '
Please login to merge, or discard this patch.
Sources/DbExtra-mysql.php 1 patch
Braces   +72 added lines, -51 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Add the functions implemented in this file to the $smcFunc array.
@@ -23,8 +24,8 @@  discard block
 block discarded – undo
23 24
 {
24 25
 	global $smcFunc;
25 26
 
26
-	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table')
27
-		$smcFunc += array(
27
+	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') {
28
+			$smcFunc += array(
28 29
 			'db_backup_table' => 'smf_db_backup_table',
29 30
 			'db_optimize_table' => 'smf_db_optimize_table',
30 31
 			'db_table_sql' => 'smf_db_table_sql',
@@ -33,7 +34,8 @@  discard block
 block discarded – undo
33 34
 			'db_get_vendor' => 'smf_db_get_vendor',
34 35
 			'db_allow_persistent' => 'smf_db_allow_persistent',
35 36
 		);
36
-}
37
+	}
38
+	}
37 39
 
38 40
 /**
39 41
  * Backup $table to $backup_table.
@@ -75,8 +77,9 @@  discard block
 block discarded – undo
75 77
 			));
76 78
 
77 79
 		// Old school or no school?
78
-		if ($request)
79
-			return $request;
80
+		if ($request) {
81
+					return $request;
82
+		}
80 83
 	}
81 84
 
82 85
 	// At this point, the quick method failed.
@@ -100,8 +103,9 @@  discard block
 block discarded – undo
100 103
 	foreach ($create as $k => $l)
101 104
 	{
102 105
 		// Get the name of the auto_increment column.
103
-		if (strpos($l, 'auto_increment'))
104
-			$auto_inc = trim($l);
106
+		if (strpos($l, 'auto_increment')) {
107
+					$auto_inc = trim($l);
108
+		}
105 109
 
106 110
 		// For the engine type, see if we can work out what it is.
107 111
 		if (strpos($l, 'ENGINE') !== false || strpos($l, 'TYPE') !== false)
@@ -109,30 +113,36 @@  discard block
 block discarded – undo
109 113
 			// Extract the engine type.
110 114
 			preg_match('~(ENGINE|TYPE)=(\w+)(\sDEFAULT)?(\sCHARSET=(\w+))?(\sCOLLATE=(\w+))?~', $l, $match);
111 115
 
112
-			if (!empty($match[1]))
113
-				$engine = $match[1];
116
+			if (!empty($match[1])) {
117
+							$engine = $match[1];
118
+			}
114 119
 
115
-			if (!empty($match[2]))
116
-				$engine = $match[2];
120
+			if (!empty($match[2])) {
121
+							$engine = $match[2];
122
+			}
117 123
 
118
-			if (!empty($match[5]))
119
-				$charset = $match[5];
124
+			if (!empty($match[5])) {
125
+							$charset = $match[5];
126
+			}
120 127
 
121
-			if (!empty($match[7]))
122
-				$collate = $match[7];
128
+			if (!empty($match[7])) {
129
+							$collate = $match[7];
130
+			}
123 131
 		}
124 132
 
125 133
 		// Skip everything but keys...
126
-		if (strpos($l, 'KEY') === false)
127
-			unset($create[$k]);
134
+		if (strpos($l, 'KEY') === false) {
135
+					unset($create[$k]);
136
+		}
128 137
 	}
129 138
 
130
-	if (!empty($create))
131
-		$create = '(
139
+	if (!empty($create)) {
140
+			$create = '(
132 141
 			' . implode('
133 142
 			', $create) . ')';
134
-	else
135
-		$create = '';
143
+	} else {
144
+			$create = '';
145
+	}
136 146
 
137 147
 	$request = $smcFunc['db_query']('', '
138 148
 		CREATE TABLE {raw:backup_table} {raw:create}
@@ -151,8 +161,9 @@  discard block
 block discarded – undo
151 161
 
152 162
 	if ($auto_inc != '')
153 163
 	{
154
-		if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',')
155
-			$auto_inc = substr($auto_inc, 0, -1);
164
+		if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',') {
165
+					$auto_inc = substr($auto_inc, 0, -1);
166
+		}
156 167
 
157 168
 		$smcFunc['db_query']('', '
158 169
 			ALTER TABLE {raw:backup_table}
@@ -196,8 +207,9 @@  discard block
 block discarded – undo
196 207
 				'table' => $table,
197 208
 			)
198 209
 		);
199
-	if (!$request)
200
-		return -1;
210
+	if (!$request) {
211
+			return -1;
212
+	}
201 213
 
202 214
 	// How much left?
203 215
 	$request = $smcFunc['db_query']('', '
@@ -240,8 +252,9 @@  discard block
 block discarded – undo
240 252
 		)
241 253
 	);
242 254
 	$tables = array();
243
-	while ($row = $smcFunc['db_fetch_row']($request))
244
-		$tables[] = $row[0];
255
+	while ($row = $smcFunc['db_fetch_row']($request)) {
256
+			$tables[] = $row[0];
257
+	}
245 258
 	$smcFunc['db_free_result']($request);
246 259
 
247 260
 	return $tables;
@@ -285,8 +298,9 @@  discard block
 block discarded – undo
285 298
 		if (!empty($row['Default']) || $row['Null'] !== 'YES')
286 299
 		{
287 300
 			// Make a special case of auto-timestamp.
288
-			if ($row['Default'] == 'CURRENT_TIMESTAMP')
289
-				$schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */';
301
+			if ($row['Default'] == 'CURRENT_TIMESTAMP') {
302
+							$schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */';
303
+			}
290 304
 			// Text shouldn't have a default.
291 305
 			elseif ($row['Default'] !== null)
292 306
 			{
@@ -321,14 +335,16 @@  discard block
 block discarded – undo
321 335
 		$row['Key_name'] = $row['Key_name'] == 'PRIMARY' ? 'PRIMARY KEY' : (empty($row['Non_unique']) ? 'UNIQUE ' : ($row['Comment'] == 'FULLTEXT' || (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') ? 'FULLTEXT ' : 'KEY ')) . '`' . $row['Key_name'] . '`';
322 336
 
323 337
 		// Is this the first column in the index?
324
-		if (empty($indexes[$row['Key_name']]))
325
-			$indexes[$row['Key_name']] = array();
338
+		if (empty($indexes[$row['Key_name']])) {
339
+					$indexes[$row['Key_name']] = array();
340
+		}
326 341
 
327 342
 		// A sub part, like only indexing 15 characters of a varchar.
328
-		if (!empty($row['Sub_part']))
329
-			$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')';
330
-		else
331
-			$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`';
343
+		if (!empty($row['Sub_part'])) {
344
+					$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')';
345
+		} else {
346
+					$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`';
347
+		}
332 348
 	}
333 349
 	$smcFunc['db_free_result']($result);
334 350
 
@@ -366,8 +382,9 @@  discard block
 block discarded – undo
366 382
 {
367 383
 	static $ver;
368 384
 
369
-	if (!empty($ver))
370
-		return $ver;
385
+	if (!empty($ver)) {
386
+			return $ver;
387
+	}
371 388
 
372 389
 	global $smcFunc;
373 390
 
@@ -392,8 +409,9 @@  discard block
 block discarded – undo
392 409
 	global $smcFunc;
393 410
 	static $db_type;
394 411
 
395
-	if (!empty($db_type))
396
-		return $db_type;
412
+	if (!empty($db_type)) {
413
+			return $db_type;
414
+	}
397 415
 
398 416
 	$request = $smcFunc['db_query']('', 'SELECT @@version_comment');
399 417
 	list ($comment) = $smcFunc['db_fetch_row']($request);
@@ -402,13 +420,15 @@  discard block
 block discarded – undo
402 420
 	// Skip these if we don't have a comment.
403 421
 	if (!empty($comment))
404 422
 	{
405
-		if (stripos($comment, 'percona') !== false)
406
-			return 'Percona';
407
-		if (stripos($comment, 'mariadb') !== false)
408
-			return 'MariaDB';
423
+		if (stripos($comment, 'percona') !== false) {
424
+					return 'Percona';
425
+		}
426
+		if (stripos($comment, 'mariadb') !== false) {
427
+					return 'MariaDB';
428
+		}
429
+	} else {
430
+			return 'fail';
409 431
 	}
410
-	else
411
-		return 'fail';
412 432
 
413 433
 	return 'MySQL';
414 434
 }
@@ -421,10 +441,11 @@  discard block
 block discarded – undo
421 441
 function smf_db_allow_persistent()
422 442
 {
423 443
 	$value = ini_get('mysqli.allow_persistent');
424
-	if ($value == 'on' || $value == 'true')
425
-		return true;
426
-	else
427
-		return false;
428
-}
444
+	if ($value == 'on' || $value == 'true') {
445
+			return true;
446
+	} else {
447
+			return false;
448
+	}
449
+	}
429 450
 
430 451
 ?>
431 452
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/DbExtra-postgresql.php 1 patch
Braces   +43 added lines, -32 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Add the functions implemented in this file to the $smcFunc array.
@@ -23,8 +24,8 @@  discard block
 block discarded – undo
23 24
 {
24 25
 	global $smcFunc;
25 26
 
26
-	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table')
27
-		$smcFunc += array(
27
+	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') {
28
+			$smcFunc += array(
28 29
 			'db_backup_table' => 'smf_db_backup_table',
29 30
 			'db_optimize_table' => 'smf_db_optimize_table',
30 31
 			'db_table_sql' => 'smf_db_table_sql',
@@ -33,7 +34,8 @@  discard block
 block discarded – undo
33 34
 			'db_get_vendor' => 'smf_db_get_vendor',
34 35
 			'db_allow_persistent' => 'smf_db_allow_persistent',
35 36
 		);
36
-}
37
+	}
38
+	}
37 39
 
38 40
 /**
39 41
  * Backup $table to $backup_table.
@@ -49,13 +51,14 @@  discard block
 block discarded – undo
49 51
 
50 52
 	// Do we need to drop it first?
51 53
 	$tables = smf_db_list_tables(false, $backup_table);
52
-	if (!empty($tables))
53
-		$smcFunc['db_query']('', '
54
+	if (!empty($tables)) {
55
+			$smcFunc['db_query']('', '
54 56
 			DROP TABLE {raw:backup_table}',
55 57
 			array(
56 58
 				'backup_table' => $backup_table,
57 59
 			)
58 60
 		);
61
+	}
59 62
 
60 63
 	/**
61 64
 	 * @todo Should we create backups of sequences as well?
@@ -118,8 +121,9 @@  discard block
 block discarded – undo
118 121
 			)
119 122
 		);
120 123
 
121
-	if (!$request)
122
-		return -1;
124
+	if (!$request) {
125
+			return -1;
126
+	}
123 127
 
124 128
 	$request = $smcFunc['db_query']('', '
125 129
 		SELECT pg_relation_size(C.oid) AS "size"
@@ -137,11 +141,12 @@  discard block
 block discarded – undo
137 141
 	$row = $smcFunc['db_fetch_assoc']($request);
138 142
 	$smcFunc['db_free_result']($request);
139 143
 
140
-	if (isset($row['size']))
141
-			return ($old_size - $row['size']) / 1024;
142
-	else
143
-		return 0;
144
-}
144
+	if (isset($row['size'])) {
145
+				return ($old_size - $row['size']) / 1024;
146
+	} else {
147
+			return 0;
148
+	}
149
+	}
145 150
 
146 151
 /**
147 152
  * This function lists all tables in the database.
@@ -168,8 +173,9 @@  discard block
 block discarded – undo
168 173
 	);
169 174
 
170 175
 	$tables = array();
171
-	while ($row = $smcFunc['db_fetch_row']($request))
172
-		$tables[] = $row[0];
176
+	while ($row = $smcFunc['db_fetch_row']($request)) {
177
+			$tables[] = $row[0];
178
+	}
173 179
 	$smcFunc['db_free_result']($request);
174 180
 
175 181
 	return $tables;
@@ -210,12 +216,14 @@  discard block
 block discarded – undo
210 216
 	);
211 217
 	while ($row = $smcFunc['db_fetch_assoc']($result))
212 218
 	{
213
-		if ($row['data_type'] == 'character varying')
214
-			$row['data_type'] = 'varchar';
215
-		elseif ($row['data_type'] == 'character')
216
-			$row['data_type'] = 'char';
217
-		if ($row['character_maximum_length'])
218
-			$row['data_type'] .= '(' . $row['character_maximum_length'] . ')';
219
+		if ($row['data_type'] == 'character varying') {
220
+					$row['data_type'] = 'varchar';
221
+		} elseif ($row['data_type'] == 'character') {
222
+					$row['data_type'] = 'char';
223
+		}
224
+		if ($row['character_maximum_length']) {
225
+					$row['data_type'] .= '(' . $row['character_maximum_length'] . ')';
226
+		}
219 227
 
220 228
 		// Make the CREATE for this column.
221 229
 		$schema_create .= ' "' . $row['column_name'] . '" ' . $row['data_type'] . ($row['is_nullable'] != 'YES' ? ' NOT NULL' : '');
@@ -266,13 +274,14 @@  discard block
 block discarded – undo
266 274
 	{
267 275
 		if ($row['is_primary'])
268 276
 		{
269
-			if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0)
270
-				continue;
277
+			if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) {
278
+							continue;
279
+			}
271 280
 
272 281
 			$index_create .= $crlf . 'ALTER TABLE ' . $tableName . ' ADD PRIMARY KEY ("' . $matches[1] . '");';
282
+		} else {
283
+					$index_create .= $crlf . $row['inddef'] . ';';
273 284
 		}
274
-		else
275
-			$index_create .= $crlf . $row['inddef'] . ';';
276 285
 	}
277 286
 	$smcFunc['db_free_result']($result);
278 287
 
@@ -291,8 +300,9 @@  discard block
 block discarded – undo
291 300
 	global $db_connection;
292 301
 	static $ver;
293 302
 
294
-	if(!empty($ver))
295
-		return $ver;
303
+	if(!empty($ver)) {
304
+			return $ver;
305
+	}
296 306
 
297 307
 	$ver = pg_version($db_connection)['server'];
298 308
 
@@ -317,10 +327,11 @@  discard block
 block discarded – undo
317 327
 function smf_db_allow_persistent()
318 328
 {
319 329
 	$value = ini_get('pgsql.allow_persistent');
320
-	if ($value == 'on' || $value == 'true')
321
-		return true;
322
-	else
323
-		return false;
324
-}
330
+	if ($value == 'on' || $value == 'true') {
331
+			return true;
332
+	} else {
333
+			return false;
334
+	}
335
+	}
325 336
 
326 337
 ?>
327 338
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/ManageServer.php 1 patch
Braces   +315 added lines, -243 removed lines patch added patch discarded remove patch
@@ -59,8 +59,9 @@  discard block
 block discarded – undo
59 59
  * @version 2.1 Beta 4
60 60
  */
61 61
 
62
-if (!defined('SMF'))
62
+if (!defined('SMF')) {
63 63
 	die('No direct access...');
64
+}
64 65
 
65 66
 /**
66 67
  * This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects
@@ -111,10 +112,11 @@  discard block
 block discarded – undo
111 112
 	$settings_not_writable = !is_writable($boarddir . '/Settings.php');
112 113
 	$settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
113 114
 
114
-	if ($settings_not_writable)
115
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
116
-	elseif ($settings_backup_fail)
117
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
115
+	if ($settings_not_writable) {
116
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
117
+	} elseif ($settings_backup_fail) {
118
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
119
+	}
118 120
 
119 121
 	$context['settings_not_writable'] = $settings_not_writable;
120 122
 
@@ -142,10 +144,11 @@  discard block
 block discarded – undo
142 144
 
143 145
 	// If no cert, force_ssl must remain 0
144 146
 	require_once($sourcedir . '/Subs.php');
145
-	if (!ssl_cert_found($boardurl) && empty($modSettings['force_ssl']))
146
-		$disable_force_ssl = true;
147
-	else
148
-		$disable_force_ssl = false;
147
+	if (!ssl_cert_found($boardurl) && empty($modSettings['force_ssl'])) {
148
+			$disable_force_ssl = true;
149
+	} else {
150
+			$disable_force_ssl = false;
151
+	}
149 152
 
150 153
 	/* If you're writing a mod, it's a bad idea to add things here....
151 154
 	For each option:
@@ -175,8 +178,9 @@  discard block
 block discarded – undo
175 178
 
176 179
 	call_integration_hook('integrate_general_settings', array(&$config_vars));
177 180
 
178
-	if ($return_config)
179
-		return $config_vars;
181
+	if ($return_config) {
182
+			return $config_vars;
183
+	}
180 184
 
181 185
 	// Setup the template stuff.
182 186
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=general;save';
@@ -193,16 +197,18 @@  discard block
 block discarded – undo
193 197
 			$registerSMStats = registerSMStats();
194 198
 
195 199
 			// Failed to register, disable it again.
196
-			if (empty($registerSMStats))
197
-				$_POST['enable_sm_stats'] = 0;
200
+			if (empty($registerSMStats)) {
201
+							$_POST['enable_sm_stats'] = 0;
202
+			}
198 203
 		}
199 204
 
200 205
 		// Ensure all URLs are aligned with the new force_ssl setting
201 206
 		// Treat unset like 0
202
-		if (isset($_POST['force_ssl']))
203
-			AlignURLsWithSSLSetting($_POST['force_ssl']);
204
-		else
205
-			AlignURLsWithSSLSetting(0);
207
+		if (isset($_POST['force_ssl'])) {
208
+					AlignURLsWithSSLSetting($_POST['force_ssl']);
209
+		} else {
210
+					AlignURLsWithSSLSetting(0);
211
+		}
206 212
 
207 213
 		saveSettings($config_vars);
208 214
 		$_SESSION['adm-save'] = true;
@@ -255,10 +261,11 @@  discard block
 block discarded – undo
255 261
 	require_once($sourcedir . '/Subs-Admin.php');
256 262
 
257 263
 	// Check $boardurl
258
-	if (!empty($new_force_ssl))
259
-		$newval = strtr($boardurl, array('http://' => 'https://'));
260
-	else
261
-		$newval = strtr($boardurl, array('https://' => 'http://'));
264
+	if (!empty($new_force_ssl)) {
265
+			$newval = strtr($boardurl, array('http://' => 'https://'));
266
+	} else {
267
+			$newval = strtr($boardurl, array('https://' => 'http://'));
268
+	}
262 269
 	updateSettingsFile(array('boardurl' => '\'' . addslashes($newval) . '\''));
263 270
 
264 271
 	$new_settings = array();
@@ -266,20 +273,22 @@  discard block
 block discarded – undo
266 273
 	// Check $smileys_url, but only if it points to a subfolder of $boardurl
267 274
 	if (BoardurlMatch($modSettings['smileys_url']))
268 275
 	{
269
-		if (!empty($new_force_ssl))
270
-			$newval = strtr($modSettings['smileys_url'], array('http://' => 'https://'));
271
-		else
272
-			$newval = strtr($modSettings['smileys_url'], array('https://' => 'http://'));
276
+		if (!empty($new_force_ssl)) {
277
+					$newval = strtr($modSettings['smileys_url'], array('http://' => 'https://'));
278
+		} else {
279
+					$newval = strtr($modSettings['smileys_url'], array('https://' => 'http://'));
280
+		}
273 281
 		$new_settings['smileys_url'] = $newval;
274 282
 	}
275 283
 
276 284
 	// Check $avatar_url, but only if it points to a subfolder of $boardurl
277 285
 	if (BoardurlMatch($modSettings['avatar_url']))
278 286
 	{
279
-		if (!empty($new_force_ssl))
280
-			$newval = strtr($modSettings['avatar_url'], array('http://' => 'https://'));
281
-		else
282
-			$newval = strtr($modSettings['avatar_url'], array('https://' => 'http://'));
287
+		if (!empty($new_force_ssl)) {
288
+					$newval = strtr($modSettings['avatar_url'], array('http://' => 'https://'));
289
+		} else {
290
+					$newval = strtr($modSettings['avatar_url'], array('https://' => 'http://'));
291
+		}
283 292
 		$new_settings['avatar_url'] = $newval;
284 293
 	}
285 294
 
@@ -287,16 +296,18 @@  discard block
 block discarded – undo
287 296
 	// This one had been optional in the past, make sure it is set first
288 297
 	if (isset($modSettings['custom_avatar_url']) && BoardurlMatch($modSettings['custom_avatar_url']))
289 298
 	{
290
-		if (!empty($new_force_ssl))
291
-			$newval = strtr($modSettings['custom_avatar_url'], array('http://' => 'https://'));
292
-		else
293
-			$newval = strtr($modSettings['custom_avatar_url'], array('https://' => 'http://'));
299
+		if (!empty($new_force_ssl)) {
300
+					$newval = strtr($modSettings['custom_avatar_url'], array('http://' => 'https://'));
301
+		} else {
302
+					$newval = strtr($modSettings['custom_avatar_url'], array('https://' => 'http://'));
303
+		}
294 304
 		$new_settings['custom_avatar_url'] = $newval;
295 305
 	}
296 306
 
297 307
 	// Save updates to the settings table
298
-	if (!empty($new_settings))
299
-		updateSettings($new_settings, true);
308
+	if (!empty($new_settings)) {
309
+			updateSettings($new_settings, true);
310
+	}
300 311
 
301 312
 	// Now we move onto the themes.
302 313
 	// First, get a list of theme URLs...
@@ -317,10 +328,11 @@  discard block
 block discarded – undo
317 328
 		// First check to see if it points to a subfolder of $boardurl
318 329
 		if (BoardurlMatch($row['value']))
319 330
 		{
320
-			if (!empty($new_force_ssl))
321
-				$newval = strtr($row['value'], array('http://' => 'https://'));
322
-			else
323
-				$newval = strtr($row['value'], array('https://' => 'http://'));
331
+			if (!empty($new_force_ssl)) {
332
+							$newval = strtr($row['value'], array('http://' => 'https://'));
333
+			} else {
334
+							$newval = strtr($row['value'], array('https://' => 'http://'));
335
+			}
324 336
 			$smcFunc['db_query']('', '
325 337
 				UPDATE {db_prefix}themes
326 338
 				   SET value = {string:theme_val}
@@ -360,11 +372,12 @@  discard block
 block discarded – undo
360 372
 
361 373
 	// If leftmost portion of path matches boardurl, return true
362 374
 	$result = strpos($urlpath, $boardurlpath);
363
-	if ($result === false || $result != 0)
364
-		return false;
365
-	else
366
-		return true;
367
-}
375
+	if ($result === false || $result != 0) {
376
+			return false;
377
+	} else {
378
+			return true;
379
+	}
380
+	}
368 381
 
369 382
 /**
370 383
  * Basic database and paths settings - database name, host, etc.
@@ -403,8 +416,9 @@  discard block
 block discarded – undo
403 416
 		$request = $smcFunc['db_query']('', 'SELECT cfgname FROM pg_ts_config', array());
404 417
 		$fts_language = array();
405 418
 
406
-		while ($row = $smcFunc['db_fetch_assoc']($request))
407
-			$fts_language[$row['cfgname']] = $row['cfgname'];
419
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
420
+					$fts_language[$row['cfgname']] = $row['cfgname'];
421
+		}
408 422
 
409 423
 		$config_vars = array_merge ($config_vars, array(
410 424
 				'',
@@ -416,20 +430,22 @@  discard block
 block discarded – undo
416 430
 
417 431
 	call_integration_hook('integrate_database_settings', array(&$config_vars));
418 432
 
419
-	if ($return_config)
420
-		return $config_vars;
433
+	if ($return_config) {
434
+			return $config_vars;
435
+	}
421 436
 
422 437
 	// Setup the template stuff.
423 438
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save';
424 439
 	$context['settings_title'] = $txt['database_settings'];
425 440
 	$context['save_disabled'] = $context['settings_not_writable'];
426 441
 
427
-	if (!$smcFunc['db_allow_persistent'])
428
-		addInlineJavaScript('
442
+	if (!$smcFunc['db_allow_persistent']) {
443
+			addInlineJavaScript('
429 444
 			$(function()
430 445
 			{
431 446
 				$("#db_persist").prop("disabled", true);
432 447
 			});', true);
448
+	}
433 449
 
434 450
 	// Saving settings?
435 451
 	if (isset($_REQUEST['save']))
@@ -499,13 +515,15 @@  discard block
 block discarded – undo
499 515
 		hideGlobalCookies();
500 516
 	});', true);
501 517
 
502
-	if (empty($user_settings['tfa_secret']))
503
-		addInlineJavaScript('');
518
+	if (empty($user_settings['tfa_secret'])) {
519
+			addInlineJavaScript('');
520
+	}
504 521
 
505 522
 	call_integration_hook('integrate_cookie_settings', array(&$config_vars));
506 523
 
507
-	if ($return_config)
508
-		return $config_vars;
524
+	if ($return_config) {
525
+			return $config_vars;
526
+	}
509 527
 
510 528
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save';
511 529
 	$context['settings_title'] = $txt['cookies_sessions_settings'];
@@ -516,14 +534,17 @@  discard block
 block discarded – undo
516 534
 		call_integration_hook('integrate_save_cookie_settings');
517 535
 
518 536
 		// Local and global do not play nicely together.
519
-		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies']))
520
-			unset ($_POST['globalCookies']);
537
+		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) {
538
+					unset ($_POST['globalCookies']);
539
+		}
521 540
 
522
-		if (empty($modSettings['localCookies']) != empty($_POST['localCookies']) || empty($modSettings['globalCookies']) != empty($_POST['globalCookies']))
523
-			$scope_changed = true;
541
+		if (empty($modSettings['localCookies']) != empty($_POST['localCookies']) || empty($modSettings['globalCookies']) != empty($_POST['globalCookies'])) {
542
+					$scope_changed = true;
543
+		}
524 544
 
525
-		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false)
526
-			fatal_lang_error('invalid_cookie_domain', false);
545
+		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) {
546
+					fatal_lang_error('invalid_cookie_domain', false);
547
+		}
527 548
 
528 549
 		saveSettings($config_vars);
529 550
 
@@ -606,8 +627,9 @@  discard block
 block discarded – undo
606 627
 
607 628
 	call_integration_hook('integrate_general_security_settings', array(&$config_vars));
608 629
 
609
-	if ($return_config)
610
-		return $config_vars;
630
+	if ($return_config) {
631
+			return $config_vars;
632
+	}
611 633
 
612 634
 	// Saving?
613 635
 	if (isset($_GET['save']))
@@ -646,8 +668,7 @@  discard block
 block discarded – undo
646 668
 		$txt['cache_settings_message'] = $txt['detected_no_caching'];
647 669
 		$cache_level = array($txt['cache_off']);
648 670
 		$detected['none'] = $txt['cache_off'];
649
-	}
650
-	else
671
+	} else
651 672
 	{
652 673
 		$txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected));
653 674
 		$cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']);
@@ -684,8 +705,9 @@  discard block
 block discarded – undo
684 705
 			}
685 706
 		}
686 707
 	}
687
-	if ($return_config)
688
-		return $config_vars;
708
+	if ($return_config) {
709
+			return $config_vars;
710
+	}
689 711
 
690 712
 	// Saving again?
691 713
 	if (isset($_GET['save']))
@@ -713,8 +735,9 @@  discard block
 block discarded – undo
713 735
 	$context['save_disabled'] = $context['settings_not_writable'];
714 736
 
715 737
 	// Decide what message to show.
716
-	if (!$context['save_disabled'])
717
-		$context['settings_message'] = $txt['caching_information'];
738
+	if (!$context['save_disabled']) {
739
+			$context['settings_message'] = $txt['caching_information'];
740
+	}
718 741
 
719 742
 	// Prepare the template.
720 743
 	prepareServerSettingsContext($config_vars);
@@ -737,24 +760,25 @@  discard block
 block discarded – undo
737 760
 	if (stripos(PHP_OS, 'win') === 0)
738 761
 	{
739 762
 		$context['settings_message'] = $txt['loadavg_disabled_windows'];
740
-		if (isset($_GET['save']))
741
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
742
-	}
743
-	elseif (stripos(PHP_OS, 'darwin') === 0)
763
+		if (isset($_GET['save'])) {
764
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
765
+		}
766
+	} elseif (stripos(PHP_OS, 'darwin') === 0)
744 767
 	{
745 768
 		$context['settings_message'] = $txt['loadavg_disabled_osx'];
746
-		if (isset($_GET['save']))
747
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
748
-	}
749
-	else
769
+		if (isset($_GET['save'])) {
770
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
771
+		}
772
+	} else
750 773
 	{
751 774
 		$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
752
-		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0)
753
-			$modSettings['load_average'] = (float) $matches[1];
754
-		elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0)
755
-			$modSettings['load_average'] = (float) $matches[1];
756
-		else
757
-			unset($modSettings['load_average']);
775
+		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) {
776
+					$modSettings['load_average'] = (float) $matches[1];
777
+		} elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) {
778
+					$modSettings['load_average'] = (float) $matches[1];
779
+		} else {
780
+					unset($modSettings['load_average']);
781
+		}
758 782
 
759 783
 		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
760 784
 		{
@@ -790,8 +814,9 @@  discard block
 block discarded – undo
790 814
 
791 815
 	call_integration_hook('integrate_loadavg_settings', array(&$config_vars));
792 816
 
793
-	if ($return_config)
794
-		return $config_vars;
817
+	if ($return_config) {
818
+			return $config_vars;
819
+	}
795 820
 
796 821
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save';
797 822
 	$context['settings_title'] = $txt['load_balancing_settings'];
@@ -802,24 +827,27 @@  discard block
 block discarded – undo
802 827
 		// Stupidity is not allowed.
803 828
 		foreach ($_POST as $key => $value)
804 829
 		{
805
-			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values)))
806
-				continue;
807
-			else
808
-				$_POST[$key] = (float) $value;
809
-
810
-			if ($key == 'loadavg_auto_opt' && $value <= 1)
811
-				$_POST['loadavg_auto_opt'] = 1.0;
812
-			elseif ($key == 'loadavg_forum' && $value < 10)
813
-				$_POST['loadavg_forum'] = 10.0;
814
-			elseif ($value < 2)
815
-				$_POST[$key] = 2.0;
830
+			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) {
831
+							continue;
832
+			} else {
833
+							$_POST[$key] = (float) $value;
834
+			}
835
+
836
+			if ($key == 'loadavg_auto_opt' && $value <= 1) {
837
+							$_POST['loadavg_auto_opt'] = 1.0;
838
+			} elseif ($key == 'loadavg_forum' && $value < 10) {
839
+							$_POST['loadavg_forum'] = 10.0;
840
+			} elseif ($value < 2) {
841
+							$_POST[$key] = 2.0;
842
+			}
816 843
 		}
817 844
 
818 845
 		call_integration_hook('integrate_save_loadavg_settings');
819 846
 
820 847
 		saveDBSettings($config_vars);
821
-		if (!isset($_SESSION['adm-save']))
822
-			$_SESSION['adm-save'] = true;
848
+		if (!isset($_SESSION['adm-save'])) {
849
+					$_SESSION['adm-save'] = true;
850
+		}
823 851
 		redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']);
824 852
 	}
825 853
 
@@ -855,10 +883,11 @@  discard block
 block discarded – undo
855 883
 
856 884
 	if (isset($_SESSION['adm-save']))
857 885
 	{
858
-		if ($_SESSION['adm-save'] === true)
859
-			$context['saved_successful'] = true;
860
-		else
861
-			$context['saved_failed'] = $_SESSION['adm-save'];
886
+		if ($_SESSION['adm-save'] === true) {
887
+					$context['saved_successful'] = true;
888
+		} else {
889
+					$context['saved_failed'] = $_SESSION['adm-save'];
890
+		}
862 891
 
863 892
 		unset($_SESSION['adm-save']);
864 893
 	}
@@ -866,9 +895,9 @@  discard block
 block discarded – undo
866 895
 	$context['config_vars'] = array();
867 896
 	foreach ($config_vars as $identifier => $config_var)
868 897
 	{
869
-		if (!is_array($config_var) || !isset($config_var[1]))
870
-			$context['config_vars'][] = $config_var;
871
-		else
898
+		if (!is_array($config_var) || !isset($config_var[1])) {
899
+					$context['config_vars'][] = $config_var;
900
+		} else
872 901
 		{
873 902
 			$varname = $config_var[0];
874 903
 			global $$varname;
@@ -903,16 +932,19 @@  discard block
 block discarded – undo
903 932
 			if ($config_var[3] == 'int' || $config_var[3] == 'float')
904 933
 			{
905 934
 				// Default to a min of 0 if one isn't set
906
-				if (isset($config_var['min']))
907
-					$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
908
-				else
909
-					$context['config_vars'][$config_var[0]]['min'] = 0;
935
+				if (isset($config_var['min'])) {
936
+									$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
937
+				} else {
938
+									$context['config_vars'][$config_var[0]]['min'] = 0;
939
+				}
910 940
 
911
-				if (isset($config_var['max']))
912
-					$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
941
+				if (isset($config_var['max'])) {
942
+									$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
943
+				}
913 944
 
914
-				if (isset($config_var['step']))
915
-					$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
945
+				if (isset($config_var['step'])) {
946
+									$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
947
+				}
916 948
 			}
917 949
 
918 950
 			// If this is a select box handle any data.
@@ -920,12 +952,13 @@  discard block
 block discarded – undo
920 952
 			{
921 953
 				// If it's associative
922 954
 				$config_values = array_values($config_var[4]);
923
-				if (isset($config_values[0]) && is_array($config_values[0]))
924
-					$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
925
-				else
955
+				if (isset($config_values[0]) && is_array($config_values[0])) {
956
+									$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
957
+				} else
926 958
 				{
927
-					foreach ($config_var[4] as $key => $item)
928
-						$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
959
+					foreach ($config_var[4] as $key => $item) {
960
+											$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
961
+					}
929 962
 				}
930 963
 			}
931 964
 		}
@@ -950,10 +983,11 @@  discard block
 block discarded – undo
950 983
 
951 984
 	if (isset($_SESSION['adm-save']))
952 985
 	{
953
-		if ($_SESSION['adm-save'] === true)
954
-			$context['saved_successful'] = true;
955
-		else
956
-			$context['saved_failed'] = $_SESSION['adm-save'];
986
+		if ($_SESSION['adm-save'] === true) {
987
+					$context['saved_successful'] = true;
988
+		} else {
989
+					$context['saved_failed'] = $_SESSION['adm-save'];
990
+		}
957 991
 
958 992
 		unset($_SESSION['adm-save']);
959 993
 	}
@@ -965,26 +999,30 @@  discard block
 block discarded – undo
965 999
 	foreach ($config_vars as $config_var)
966 1000
 	{
967 1001
 		// HR?
968
-		if (!is_array($config_var))
969
-			$context['config_vars'][] = $config_var;
970
-		else
1002
+		if (!is_array($config_var)) {
1003
+					$context['config_vars'][] = $config_var;
1004
+		} else
971 1005
 		{
972 1006
 			// If it has no name it doesn't have any purpose!
973
-			if (empty($config_var[1]))
974
-				continue;
1007
+			if (empty($config_var[1])) {
1008
+							continue;
1009
+			}
975 1010
 
976 1011
 			// Special case for inline permissions
977
-			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions'))
978
-				$inlinePermissions[] = $config_var[1];
979
-			elseif ($config_var[0] == 'permissions')
980
-				continue;
1012
+			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) {
1013
+							$inlinePermissions[] = $config_var[1];
1014
+			} elseif ($config_var[0] == 'permissions') {
1015
+							continue;
1016
+			}
981 1017
 
982
-			if ($config_var[0] == 'boards')
983
-				$board_list = true;
1018
+			if ($config_var[0] == 'boards') {
1019
+							$board_list = true;
1020
+			}
984 1021
 
985 1022
 			// Are we showing the BBC selection box?
986
-			if ($config_var[0] == 'bbc')
987
-				$bbcChoice[] = $config_var[1];
1023
+			if ($config_var[0] == 'bbc') {
1024
+							$bbcChoice[] = $config_var[1];
1025
+			}
988 1026
 
989 1027
 			// We need to do some parsing of the value before we pass it in.
990 1028
 			if (isset($modSettings[$config_var[1]]))
@@ -1003,8 +1041,7 @@  discard block
 block discarded – undo
1003 1041
 					default:
1004 1042
 						$value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]);
1005 1043
 				}
1006
-			}
1007
-			else
1044
+			} else
1008 1045
 			{
1009 1046
 				// Darn, it's empty. What type is expected?
1010 1047
 				switch ($config_var[0])
@@ -1044,16 +1081,19 @@  discard block
 block discarded – undo
1044 1081
 			if ($config_var[0] == 'int' || $config_var[0] == 'float')
1045 1082
 			{
1046 1083
 				// Default to a min of 0 if one isn't set
1047
-				if (isset($config_var['min']))
1048
-					$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
1049
-				else
1050
-					$context['config_vars'][$config_var[1]]['min'] = 0;
1084
+				if (isset($config_var['min'])) {
1085
+									$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
1086
+				} else {
1087
+									$context['config_vars'][$config_var[1]]['min'] = 0;
1088
+				}
1051 1089
 
1052
-				if (isset($config_var['max']))
1053
-					$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
1090
+				if (isset($config_var['max'])) {
1091
+									$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
1092
+				}
1054 1093
 
1055
-				if (isset($config_var['step']))
1056
-					$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
1094
+				if (isset($config_var['step'])) {
1095
+									$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
1096
+				}
1057 1097
 			}
1058 1098
 
1059 1099
 			// If this is a select box handle any data.
@@ -1067,12 +1107,13 @@  discard block
 block discarded – undo
1067 1107
 				}
1068 1108
 
1069 1109
 				// If it's associative
1070
-				if (isset($config_var[2][0]) && is_array($config_var[2][0]))
1071
-					$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
1072
-				else
1110
+				if (isset($config_var[2][0]) && is_array($config_var[2][0])) {
1111
+									$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
1112
+				} else
1073 1113
 				{
1074
-					foreach ($config_var[2] as $key => $item)
1075
-						$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
1114
+					foreach ($config_var[2] as $key => $item) {
1115
+											$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
1116
+					}
1076 1117
 				}
1077 1118
 			}
1078 1119
 
@@ -1081,17 +1122,19 @@  discard block
 block discarded – undo
1081 1122
 			{
1082 1123
 				if (!is_numeric($k))
1083 1124
 				{
1084
-					if (substr($k, 0, 2) == 'on')
1085
-						$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
1086
-					else
1087
-						$context['config_vars'][$config_var[1]][$k] = $v;
1125
+					if (substr($k, 0, 2) == 'on') {
1126
+											$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
1127
+					} else {
1128
+											$context['config_vars'][$config_var[1]][$k] = $v;
1129
+					}
1088 1130
 				}
1089 1131
 
1090 1132
 				// See if there are any other labels that might fit?
1091
-				if (isset($txt['setting_' . $config_var[1]]))
1092
-					$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
1093
-				elseif (isset($txt['groups_' . $config_var[1]]))
1094
-					$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
1133
+				if (isset($txt['setting_' . $config_var[1]])) {
1134
+									$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
1135
+				} elseif (isset($txt['groups_' . $config_var[1]])) {
1136
+									$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
1137
+				}
1095 1138
 			}
1096 1139
 
1097 1140
 			// Set the subtext in case it's part of the label.
@@ -1124,8 +1167,9 @@  discard block
 block discarded – undo
1124 1167
 		// What are the options, eh?
1125 1168
 		$temp = parse_bbc(false);
1126 1169
 		$bbcTags = array();
1127
-		foreach ($temp as $tag)
1128
-			$bbcTags[] = $tag['tag'];
1170
+		foreach ($temp as $tag) {
1171
+					$bbcTags[] = $tag['tag'];
1172
+		}
1129 1173
 
1130 1174
 		$bbcTags = array_unique($bbcTags);
1131 1175
 		$totalTags = count($bbcTags);
@@ -1140,8 +1184,9 @@  discard block
 block discarded – undo
1140 1184
 		$col = 0; $i = 0;
1141 1185
 		foreach ($bbcTags as $tag)
1142 1186
 		{
1143
-			if ($i % $tagsPerColumn == 0 && $i != 0)
1144
-				$col++;
1187
+			if ($i % $tagsPerColumn == 0 && $i != 0) {
1188
+							$col++;
1189
+			}
1145 1190
 
1146 1191
 			$context['bbc_columns'][$col][] = array(
1147 1192
 				'tag' => $tag,
@@ -1184,18 +1229,21 @@  discard block
 block discarded – undo
1184 1229
 	validateToken('admin-ssc');
1185 1230
 
1186 1231
 	// Fix the darn stupid cookiename! (more may not be allowed, but these for sure!)
1187
-	if (isset($_POST['cookiename']))
1188
-		$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1232
+	if (isset($_POST['cookiename'])) {
1233
+			$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1234
+	}
1189 1235
 
1190 1236
 	// Fix the forum's URL if necessary.
1191 1237
 	if (isset($_POST['boardurl']))
1192 1238
 	{
1193
-		if (substr($_POST['boardurl'], -10) == '/index.php')
1194
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1195
-		elseif (substr($_POST['boardurl'], -1) == '/')
1196
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1197
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
1198
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1239
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1240
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1241
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1242
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1243
+		}
1244
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1245
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1246
+		}
1199 1247
 	}
1200 1248
 
1201 1249
 	// Any passwords?
@@ -1230,21 +1278,21 @@  discard block
 block discarded – undo
1230 1278
 	// Figure out which config vars we're saving here...
1231 1279
 	foreach ($config_vars as $var)
1232 1280
 	{
1233
-		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]])))
1234
-			continue;
1281
+		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) {
1282
+					continue;
1283
+		}
1235 1284
 
1236 1285
 		$config_var = $var[0];
1237 1286
 
1238 1287
 		if (in_array($config_var, $config_passwords))
1239 1288
 		{
1240
-			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1])
1241
-				$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1242
-		}
1243
-		elseif (in_array($config_var, $config_strs))
1289
+			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) {
1290
+							$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1291
+			}
1292
+		} elseif (in_array($config_var, $config_strs))
1244 1293
 		{
1245 1294
 			$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var], '\'\\') . '\'';
1246
-		}
1247
-		elseif (in_array($config_var, $config_ints))
1295
+		} elseif (in_array($config_var, $config_ints))
1248 1296
 		{
1249 1297
 			$new_settings[$config_var] = (int) $_POST[$config_var];
1250 1298
 
@@ -1253,17 +1301,17 @@  discard block
 block discarded – undo
1253 1301
 			$new_settings[$config_var] = max($min, $new_settings[$config_var]);
1254 1302
 
1255 1303
 			// Is there a max value for this as well?
1256
-			if (isset($var['max']))
1257
-				$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1258
-		}
1259
-		elseif (in_array($config_var, $config_bools))
1304
+			if (isset($var['max'])) {
1305
+							$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1306
+			}
1307
+		} elseif (in_array($config_var, $config_bools))
1260 1308
 		{
1261
-			if (!empty($_POST[$config_var]))
1262
-				$new_settings[$config_var] = '1';
1263
-			else
1264
-				$new_settings[$config_var] = '0';
1265
-		}
1266
-		else
1309
+			if (!empty($_POST[$config_var])) {
1310
+							$new_settings[$config_var] = '1';
1311
+			} else {
1312
+							$new_settings[$config_var] = '0';
1313
+			}
1314
+		} else
1267 1315
 		{
1268 1316
 			// This shouldn't happen, but it might...
1269 1317
 			fatal_error('Unknown config_var \'' . $config_var . '\'');
@@ -1279,30 +1327,35 @@  discard block
 block discarded – undo
1279 1327
 	foreach ($config_vars as $config_var)
1280 1328
 	{
1281 1329
 		// We just saved the file-based settings, so skip their definitions.
1282
-		if (!is_array($config_var) || $config_var[2] == 'file')
1283
-			continue;
1330
+		if (!is_array($config_var) || $config_var[2] == 'file') {
1331
+					continue;
1332
+		}
1284 1333
 
1285 1334
 		$new_setting = array($config_var[3], $config_var[0]);
1286 1335
 
1287 1336
 		// Select options need carried over, too.
1288
-		if (isset($config_var[4]))
1289
-			$new_setting[] = $config_var[4];
1337
+		if (isset($config_var[4])) {
1338
+					$new_setting[] = $config_var[4];
1339
+		}
1290 1340
 
1291 1341
 		// Include min and max if necessary
1292
-		if (isset($config_var['min']))
1293
-			$new_setting['min'] = $config_var['min'];
1342
+		if (isset($config_var['min'])) {
1343
+					$new_setting['min'] = $config_var['min'];
1344
+		}
1294 1345
 
1295
-		if (isset($config_var['max']))
1296
-			$new_setting['max'] = $config_var['max'];
1346
+		if (isset($config_var['max'])) {
1347
+					$new_setting['max'] = $config_var['max'];
1348
+		}
1297 1349
 
1298 1350
 		// Rewrite the definition a bit.
1299 1351
 		$new_settings[] = $new_setting;
1300 1352
 	}
1301 1353
 
1302 1354
 	// Save the new database-based settings, if any.
1303
-	if (!empty($new_settings))
1304
-		saveDBSettings($new_settings);
1305
-}
1355
+	if (!empty($new_settings)) {
1356
+			saveDBSettings($new_settings);
1357
+	}
1358
+	}
1306 1359
 
1307 1360
 /**
1308 1361
  * Helper function for saving database settings.
@@ -1320,22 +1373,25 @@  discard block
 block discarded – undo
1320 1373
 	$inlinePermissions = array();
1321 1374
 	foreach ($config_vars as $var)
1322 1375
 	{
1323
-		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags']))))
1324
-			continue;
1376
+		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) {
1377
+					continue;
1378
+		}
1325 1379
 
1326 1380
 		// Checkboxes!
1327
-		elseif ($var[0] == 'check')
1328
-			$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1381
+		elseif ($var[0] == 'check') {
1382
+					$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1383
+		}
1329 1384
 		// Select boxes!
1330
-		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2])))
1331
-			$setArray[$var[1]] = $_POST[$var[1]];
1332
-		elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1385
+		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) {
1386
+					$setArray[$var[1]] = $_POST[$var[1]];
1387
+		} elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1333 1388
 		{
1334 1389
 			// For security purposes we validate this line by line.
1335 1390
 			$lOptions = array();
1336
-			foreach ($_POST[$var[1]] as $invar)
1337
-				if (in_array($invar, array_keys($var[2])))
1391
+			foreach ($_POST[$var[1]] as $invar) {
1392
+							if (in_array($invar, array_keys($var[2])))
1338 1393
 					$lOptions[] = $invar;
1394
+			}
1339 1395
 
1340 1396
 			$setArray[$var[1]] = $smcFunc['json_encode']($lOptions);
1341 1397
 		}
@@ -1349,18 +1405,20 @@  discard block
 block discarded – undo
1349 1405
 				$request = $smcFunc['db_query']('', '
1350 1406
 					SELECT id_board
1351 1407
 					FROM {db_prefix}boards');
1352
-				while ($row = $smcFunc['db_fetch_row']($request))
1353
-					$board_list[$row[0]] = true;
1408
+				while ($row = $smcFunc['db_fetch_row']($request)) {
1409
+									$board_list[$row[0]] = true;
1410
+				}
1354 1411
 
1355 1412
 				$smcFunc['db_free_result']($request);
1356 1413
 			}
1357 1414
 
1358 1415
 			$lOptions = array();
1359 1416
 
1360
-			if (!empty($_POST[$var[1]]))
1361
-				foreach ($_POST[$var[1]] as $invar => $dummy)
1417
+			if (!empty($_POST[$var[1]])) {
1418
+							foreach ($_POST[$var[1]] as $invar => $dummy)
1362 1419
 					if (isset($board_list[$invar]))
1363 1420
 						$lOptions[] = $invar;
1421
+			}
1364 1422
 
1365 1423
 			$setArray[$var[1]] = !empty($lOptions) ? implode(',', $lOptions) : '';
1366 1424
 		}
@@ -1374,8 +1432,9 @@  discard block
 block discarded – undo
1374 1432
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1375 1433
 
1376 1434
 			// Do we have a max value for this as well?
1377
-			if (isset($var['max']))
1378
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1435
+			if (isset($var['max'])) {
1436
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1437
+			}
1379 1438
 		}
1380 1439
 		// Floating point!
1381 1440
 		elseif ($var[0] == 'float')
@@ -1387,40 +1446,47 @@  discard block
 block discarded – undo
1387 1446
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1388 1447
 
1389 1448
 			// Do we have a max value for this as well?
1390
-			if (isset($var['max']))
1391
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1449
+			if (isset($var['max'])) {
1450
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1451
+			}
1392 1452
 		}
1393 1453
 		// Text!
1394
-		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time')))
1395
-			$setArray[$var[1]] = $_POST[$var[1]];
1454
+		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) {
1455
+					$setArray[$var[1]] = $_POST[$var[1]];
1456
+		}
1396 1457
 		// Passwords!
1397 1458
 		elseif ($var[0] == 'password')
1398 1459
 		{
1399
-			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1])
1400
-				$setArray[$var[1]] = $_POST[$var[1]][0];
1460
+			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) {
1461
+							$setArray[$var[1]] = $_POST[$var[1]][0];
1462
+			}
1401 1463
 		}
1402 1464
 		// BBC.
1403 1465
 		elseif ($var[0] == 'bbc')
1404 1466
 		{
1405 1467
 
1406 1468
 			$bbcTags = array();
1407
-			foreach (parse_bbc(false) as $tag)
1408
-				$bbcTags[] = $tag['tag'];
1469
+			foreach (parse_bbc(false) as $tag) {
1470
+							$bbcTags[] = $tag['tag'];
1471
+			}
1409 1472
 
1410
-			if (!isset($_POST[$var[1] . '_enabledTags']))
1411
-				$_POST[$var[1] . '_enabledTags'] = array();
1412
-			elseif (!is_array($_POST[$var[1] . '_enabledTags']))
1413
-				$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1473
+			if (!isset($_POST[$var[1] . '_enabledTags'])) {
1474
+							$_POST[$var[1] . '_enabledTags'] = array();
1475
+			} elseif (!is_array($_POST[$var[1] . '_enabledTags'])) {
1476
+							$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1477
+			}
1414 1478
 
1415 1479
 			$setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags']));
1416 1480
 		}
1417 1481
 		// Permissions?
1418
-		elseif ($var[0] == 'permissions')
1419
-			$inlinePermissions[] = $var[1];
1482
+		elseif ($var[0] == 'permissions') {
1483
+					$inlinePermissions[] = $var[1];
1484
+		}
1420 1485
 	}
1421 1486
 
1422
-	if (!empty($setArray))
1423
-		updateSettings($setArray);
1487
+	if (!empty($setArray)) {
1488
+			updateSettings($setArray);
1489
+	}
1424 1490
 
1425 1491
 	// If we have inline permissions we need to save them.
1426 1492
 	if (!empty($inlinePermissions) && allowedTo('manage_permissions'))
@@ -1457,18 +1523,21 @@  discard block
 block discarded – undo
1457 1523
 	// put all of it into an array
1458 1524
 	foreach ($info_lines as $line)
1459 1525
 	{
1460
-		if (preg_match('~(' . $remove . ')~', $line))
1461
-			continue;
1526
+		if (preg_match('~(' . $remove . ')~', $line)) {
1527
+					continue;
1528
+		}
1462 1529
 
1463 1530
 		// new category?
1464
-		if (strpos($line, '<h2>') !== false)
1465
-			$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1531
+		if (strpos($line, '<h2>') !== false) {
1532
+					$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1533
+		}
1466 1534
 
1467 1535
 		// load it as setting => value or the old setting local master
1468
-		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1469
-			$pinfo[$category][$val[1]] = $val[2];
1470
-		elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1471
-			$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1536
+		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1537
+					$pinfo[$category][$val[1]] = $val[2];
1538
+		} elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1539
+					$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1540
+		}
1472 1541
 	}
1473 1542
 
1474 1543
 	// load it in to context and display it
@@ -1503,8 +1572,9 @@  discard block
 block discarded – undo
1503 1572
 				$testAPI = new $cache_class_name();
1504 1573
 
1505 1574
 				// No Support?  NEXT!
1506
-				if (!$testAPI->isSupported(true))
1507
-					continue;
1575
+				if (!$testAPI->isSupported(true)) {
1576
+									continue;
1577
+				}
1508 1578
 
1509 1579
 				$apis[$tryCache] = isset($txt[$tryCache . '_cache']) ? $txt[$tryCache . '_cache'] : $tryCache;
1510 1580
 			}
@@ -1529,8 +1599,9 @@  discard block
 block discarded – undo
1529 1599
 	global $modSettings, $boardurl, $smcFunc;
1530 1600
 
1531 1601
 	// Already have a key?  Can't register again.
1532
-	if (!empty($modSettings['sm_stats_key']))
1533
-		return true;
1602
+	if (!empty($modSettings['sm_stats_key'])) {
1603
+			return true;
1604
+	}
1534 1605
 
1535 1606
 	$fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr);
1536 1607
 	if ($fp)
@@ -1541,8 +1612,9 @@  discard block
 block discarded – undo
1541 1612
 		fwrite($fp, $out);
1542 1613
 
1543 1614
 		$return_data = '';
1544
-		while (!feof($fp))
1545
-			$return_data .= fgets($fp, 128);
1615
+		while (!feof($fp)) {
1616
+					$return_data .= fgets($fp, 128);
1617
+		}
1546 1618
 
1547 1619
 		fclose($fp);
1548 1620
 
Please login to merge, or discard this patch.
Themes/default/Profile.template.php 1 patch
Braces   +508 added lines, -392 removed lines patch added patch discarded remove patch
@@ -18,23 +18,25 @@  discard block
 block discarded – undo
18 18
 	global $context;
19 19
 
20 20
 	// Prevent Chrome from auto completing fields when viewing/editing other members profiles
21
-	if (isBrowser('is_chrome') && !$context['user']['is_owner'])
22
-		echo '
21
+	if (isBrowser('is_chrome') && !$context['user']['is_owner']) {
22
+			echo '
23 23
 			<script>
24 24
 				disableAutoComplete();
25 25
 			</script>';
26
+	}
26 27
 
27 28
 	// If an error occurred while trying to save previously, give the user a clue!
28 29
 	echo '
29 30
 			', template_error_message();
30 31
 
31 32
 	// If the profile was update successfully, let the user know this.
32
-	if (!empty($context['profile_updated']))
33
-		echo '
33
+	if (!empty($context['profile_updated'])) {
34
+			echo '
34 35
 			<div class="infobox">
35 36
 				', $context['profile_updated'], '
36 37
 			</div>';
37
-}
38
+	}
39
+	}
38 40
 
39 41
 /**
40 42
  * Template for any HTML needed below the profile (closing off divs/tables, etc.)
@@ -99,19 +101,19 @@  discard block
 block discarded – undo
99 101
 		</div>
100 102
 		<div class="alerts_unread">';
101 103
 
102
-	if (empty($context['unread_alerts']))
103
-		template_alerts_all_read();
104
-
105
-	else
104
+	if (empty($context['unread_alerts'])) {
105
+			template_alerts_all_read();
106
+	} else
106 107
 	{
107
-		foreach ($context['unread_alerts'] as $id_alert => $details)
108
-			echo '
108
+		foreach ($context['unread_alerts'] as $id_alert => $details) {
109
+					echo '
109 110
 			<div class="unread">
110 111
 				', !empty($details['sender']) ? $details['sender']['avatar']['image'] : '', '
111 112
 				<div class="details">
112 113
 					', !empty($details['icon']) ? $details['icon'] : '', '<span>', $details['text'], '</span> - ', $details['time'], '
113 114
 				</div>
114 115
 			</div>';
116
+		}
115 117
 	}
116 118
 
117 119
 	echo '
@@ -158,10 +160,11 @@  discard block
 block discarded – undo
158 160
 	if (!empty($context['print_custom_fields']['above_member']))
159 161
 	{
160 162
 		$fields = '';
161
-		foreach ($context['print_custom_fields']['above_member'] as $field)
162
-			if (!empty($field['output_html']))
163
+		foreach ($context['print_custom_fields']['above_member'] as $field) {
164
+					if (!empty($field['output_html']))
163 165
 				$fields .= '
164 166
 					<li>' . $field['output_html'] . '</li>';
167
+		}
165 168
 
166 169
 		if (!empty($fields))
167 170
 		{
@@ -181,20 +184,22 @@  discard block
 block discarded – undo
181 184
 			<div class="username clear">
182 185
 				<h4>';
183 186
 
184
-	if (!empty($context['print_custom_fields']['before_member']))
185
-		foreach ($context['print_custom_fields']['before_member'] as $field)
187
+	if (!empty($context['print_custom_fields']['before_member'])) {
188
+			foreach ($context['print_custom_fields']['before_member'] as $field)
186 189
 			if (!empty($field['output_html']))
187 190
 				echo '
188 191
 					<span>', $field['output_html'], '</span>';
192
+	}
189 193
 
190 194
 	echo '
191 195
 					', $context['member']['name'];
192 196
 
193
-	if (!empty($context['print_custom_fields']['after_member']))
194
-		foreach ($context['print_custom_fields']['after_member'] as $field)
197
+	if (!empty($context['print_custom_fields']['after_member'])) {
198
+			foreach ($context['print_custom_fields']['after_member'] as $field)
195 199
 			if (!empty($field['output_html']))
196 200
 				echo '
197 201
 					<span>', $field['output_html'], '</span>';
202
+	}
198 203
 
199 204
 
200 205
 	echo '
@@ -210,10 +215,11 @@  discard block
 block discarded – undo
210 215
 			<div class="custom_fields_below_avatar">
211 216
 				<ul>';
212 217
 
213
-		foreach ($context['print_custom_fields']['below_avatar'] as $field)
214
-			if (!empty($field['output_html']))
218
+		foreach ($context['print_custom_fields']['below_avatar'] as $field) {
219
+					if (!empty($field['output_html']))
215 220
 				echo '
216 221
 					<li>', $field['output_html'], '</li>';
222
+		}
217 223
 
218 224
 		echo '
219 225
 				</ul>
@@ -225,22 +231,25 @@  discard block
 block discarded – undo
225 231
 			<ul class="clear">';
226 232
 
227 233
 	// Email is only visible if it's your profile or you have the moderate_forum permission
228
-	if ($context['member']['show_email'])
229
-		echo '
234
+	if ($context['member']['show_email']) {
235
+			echo '
230 236
 				<li><a href="mailto:', $context['member']['email'], '" title="', $context['member']['email'], '" rel="nofollow"><span class="generic_icons mail" title="' . $txt['email'] . '"></span></a></li>';
237
+	}
231 238
 
232 239
 	// Don't show an icon if they haven't specified a website.
233
-	if ($context['member']['website']['url'] !== '' && !isset($context['disabled_fields']['website']))
234
-		echo '
240
+	if ($context['member']['website']['url'] !== '' && !isset($context['disabled_fields']['website'])) {
241
+			echo '
235 242
 				<li><a href="', $context['member']['website']['url'], '" title="' . $context['member']['website']['title'] . '" target="_blank" rel="noopener">', ($settings['use_image_buttons'] ? '<span class="generic_icons www" title="' . $context['member']['website']['title'] . '"></span>' : $txt['www']), '</a></li>';
243
+	}
236 244
 
237 245
 	// Are there any custom profile fields as icons?
238 246
 	if (!empty($context['print_custom_fields']['icons']))
239 247
 	{
240
-		foreach ($context['print_custom_fields']['icons'] as $field)
241
-			if (!empty($field['output_html']))
248
+		foreach ($context['print_custom_fields']['icons'] as $field) {
249
+					if (!empty($field['output_html']))
242 250
 				echo '
243 251
 				<li class="custom_field">', $field['output_html'], '</li>';
252
+		}
244 253
 	}
245 254
 
246 255
 	echo '
@@ -249,24 +258,27 @@  discard block
 block discarded – undo
249 258
 				', $context['can_send_pm'] ? '<a href="' . $context['member']['online']['href'] . '" title="' . $context['member']['online']['text'] . '" rel="nofollow">' : '', $settings['use_image_buttons'] ? '<span class="' . ($context['member']['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $context['member']['online']['text'] . '"></span>' : $context['member']['online']['label'], $context['can_send_pm'] ? '</a>' : '', $settings['use_image_buttons'] ? '<span class="smalltext"> ' . $context['member']['online']['label'] . '</span>' : '';
250 259
 
251 260
 	// Can they add this member as a buddy?
252
-	if (!empty($context['can_have_buddy']) && !$context['user']['is_owner'])
253
-		echo '
261
+	if (!empty($context['can_have_buddy']) && !$context['user']['is_owner']) {
262
+			echo '
254 263
 				<br>
255 264
 				<a href="', $scripturl, '?action=buddy;u=', $context['id_member'], ';', $context['session_var'], '=', $context['session_id'], '">[', $txt['buddy_' . ($context['member']['is_buddy'] ? 'remove' : 'add')], ']</a>';
265
+	}
256 266
 
257 267
 	echo '
258 268
 			</span>';
259 269
 
260
-	if (!$context['user']['is_owner'] && $context['can_send_pm'])
261
-		echo '
270
+	if (!$context['user']['is_owner'] && $context['can_send_pm']) {
271
+			echo '
262 272
 			<a href="', $scripturl, '?action=pm;sa=send;u=', $context['id_member'], '" class="infolinks">', $txt['profile_sendpm_short'], '</a>';
273
+	}
263 274
 
264 275
 	echo '
265 276
 			<a href="', $scripturl, '?action=profile;area=showposts;u=', $context['id_member'], '" class="infolinks">', $txt['showPosts'], '</a>';
266 277
 
267
-	if ($context['user']['is_owner'] && !empty($modSettings['drafts_post_enabled']))
268
-		echo '
278
+	if ($context['user']['is_owner'] && !empty($modSettings['drafts_post_enabled'])) {
279
+			echo '
269 280
 			<a href="', $scripturl, '?action=profile;area=showdrafts;u=', $context['id_member'], '" class="infolinks">', $txt['drafts_show'], '</a>';
281
+	}
270 282
 
271 283
 	echo '
272 284
 			<a href="', $scripturl, '?action=profile;area=statistics;u=', $context['id_member'], '" class="infolinks">', $txt['statPanel'], '</a>';
@@ -278,10 +290,11 @@  discard block
 block discarded – undo
278 290
 			<div class="custom_fields_bottom">
279 291
 				<ul class="nolist">';
280 292
 
281
-		foreach ($context['print_custom_fields']['bottom_poster'] as $field)
282
-			if (!empty($field['output_html']))
293
+		foreach ($context['print_custom_fields']['bottom_poster'] as $field) {
294
+					if (!empty($field['output_html']))
283 295
 				echo '
284 296
 					<li>', $field['output_html'], '</li>';
297
+		}
285 298
 
286 299
 		echo '
287 300
 				</ul>
@@ -294,30 +307,35 @@  discard block
 block discarded – undo
294 307
 		<div id="detailedinfo">
295 308
 			<dl class="settings">';
296 309
 
297
-	if ($context['user']['is_owner'] || $context['user']['is_admin'])
298
-		echo '
310
+	if ($context['user']['is_owner'] || $context['user']['is_admin']) {
311
+			echo '
299 312
 				<dt>', $txt['username'], ': </dt>
300 313
 				<dd>', $context['member']['username'], '</dd>';
314
+	}
301 315
 
302
-	if (!isset($context['disabled_fields']['posts']))
303
-		echo '
316
+	if (!isset($context['disabled_fields']['posts'])) {
317
+			echo '
304 318
 				<dt>', $txt['profile_posts'], ': </dt>
305 319
 				<dd>', $context['member']['posts'], ' (', $context['member']['posts_per_day'], ' ', $txt['posts_per_day'], ')</dd>';
320
+	}
306 321
 
307
-	if ($context['member']['show_email'])
308
-		echo '
322
+	if ($context['member']['show_email']) {
323
+			echo '
309 324
 				<dt>', $txt['email'], ': </dt>
310 325
 				<dd><a href="mailto:', $context['member']['email'], '">', $context['member']['email'], '</a></dd>';
326
+	}
311 327
 
312
-	if (!empty($modSettings['titlesEnable']) && !empty($context['member']['title']))
313
-		echo '
328
+	if (!empty($modSettings['titlesEnable']) && !empty($context['member']['title'])) {
329
+			echo '
314 330
 				<dt>', $txt['custom_title'], ': </dt>
315 331
 				<dd>', $context['member']['title'], '</dd>';
332
+	}
316 333
 
317
-	if (!empty($context['member']['blurb']))
318
-		echo '
334
+	if (!empty($context['member']['blurb'])) {
335
+			echo '
319 336
 				<dt>', $txt['personal_text'], ': </dt>
320 337
 				<dd>', $context['member']['blurb'], '</dd>';
338
+	}
321 339
 
322 340
 	echo '
323 341
 				<dt>', $txt['age'], ':</dt>
@@ -331,19 +349,21 @@  discard block
 block discarded – undo
331 349
 	{
332 350
 		$fields = array();
333 351
 
334
-		foreach ($context['print_custom_fields']['standard'] as $field)
335
-			if (!empty($field['output_html']))
352
+		foreach ($context['print_custom_fields']['standard'] as $field) {
353
+					if (!empty($field['output_html']))
336 354
 				$fields[] = $field;
355
+		}
337 356
 
338 357
 		if (count($fields) > 0)
339 358
 		{
340 359
 			echo '
341 360
 			<dl class="settings">';
342 361
 
343
-			foreach ($fields as $field)
344
-				echo '
362
+			foreach ($fields as $field) {
363
+							echo '
345 364
 				<dt>', $field['name'], ':</dt>
346 365
 				<dd>', $field['output_html'], '</dd>';
366
+			}
347 367
 
348 368
 			echo '
349 369
 			</dl>';
@@ -363,9 +383,10 @@  discard block
 block discarded – undo
363 383
 					<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=', ($context['can_issue_warning'] && !$context['user']['is_owner'] ? 'issuewarning' : 'viewwarning'), '">', $context['member']['warning'], '%</a>';
364 384
 
365 385
 		// Can we provide information on what this means?
366
-		if (!empty($context['warning_status']))
367
-			echo '
386
+		if (!empty($context['warning_status'])) {
387
+					echo '
368 388
 					<span class="smalltext">(', $context['warning_status'], ')</span>';
389
+		}
369 390
 
370 391
 		echo '
371 392
 				</dd>';
@@ -376,11 +397,12 @@  discard block
 block discarded – undo
376 397
 	{
377 398
 
378 399
 		// If the person looking at the summary has permission, and the account isn't activated, give the viewer the ability to do it themselves.
379
-		if (!empty($context['activate_message']))
380
-			echo '
400
+		if (!empty($context['activate_message'])) {
401
+					echo '
381 402
 				<dt class="clear">
382 403
 					<span class="alert">', $context['activate_message'], '</span> (<a href="', $context['activate_link'], '"', ($context['activate_type'] == 4 ? ' class="you_sure" data-confirm="' . $txt['profileConfirm'] . '"' : ''), '>', $context['activate_link_text'], '</a>)
383 404
 				</dt>';
405
+		}
384 406
 
385 407
 		// If the current member is banned, show a message and possibly a link to the ban.
386 408
 		if (!empty($context['member']['bans']))
@@ -392,10 +414,11 @@  discard block
 block discarded – undo
392 414
 				<dt class="clear" id="ban_info" style="display: none;">
393 415
 					<strong>', $txt['user_banned_by_following'], ':</strong>';
394 416
 
395
-			foreach ($context['member']['bans'] as $ban)
396
-				echo '
417
+			foreach ($context['member']['bans'] as $ban) {
418
+							echo '
397 419
 					<br>
398 420
 					<span class="smalltext">', $ban['explanation'], '</span>';
421
+			}
399 422
 
400 423
 			echo '
401 424
 				</dt>';
@@ -409,30 +432,34 @@  discard block
 block discarded – undo
409 432
 	// If the person looking is allowed, they can check the members IP address and hostname.
410 433
 	if ($context['can_see_ip'])
411 434
 	{
412
-		if (!empty($context['member']['ip']))
413
-		echo '
435
+		if (!empty($context['member']['ip'])) {
436
+				echo '
414 437
 				<dt>', $txt['ip'], ': </dt>
415 438
 				<dd><a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['member']['ip'], ';u=', $context['member']['id'], '">', $context['member']['ip'], '</a></dd>';
439
+		}
416 440
 
417
-		if (empty($modSettings['disableHostnameLookup']) && !empty($context['member']['ip']))
418
-			echo '
441
+		if (empty($modSettings['disableHostnameLookup']) && !empty($context['member']['ip'])) {
442
+					echo '
419 443
 				<dt>', $txt['hostname'], ': </dt>
420 444
 				<dd>', $context['member']['hostname'], '</dd>';
445
+		}
421 446
 	}
422 447
 
423 448
 	echo '
424 449
 				<dt>', $txt['local_time'], ':</dt>
425 450
 				<dd>', $context['member']['local_time'], '</dd>';
426 451
 
427
-	if (!empty($modSettings['userLanguage']) && !empty($context['member']['language']))
428
-		echo '
452
+	if (!empty($modSettings['userLanguage']) && !empty($context['member']['language'])) {
453
+			echo '
429 454
 				<dt>', $txt['language'], ':</dt>
430 455
 				<dd>', $context['member']['language'], '</dd>';
456
+	}
431 457
 
432
-	if ($context['member']['show_last_login'])
433
-		echo '
458
+	if ($context['member']['show_last_login']) {
459
+			echo '
434 460
 				<dt>', $txt['lastLoggedIn'], ': </dt>
435 461
 				<dd>', $context['member']['last_login'], (!empty($context['member']['is_hidden']) ? ' (' . $txt['hidden'] . ')' : ''), '</dd>';
462
+	}
436 463
 
437 464
 	echo '
438 465
 			</dl>';
@@ -444,10 +471,11 @@  discard block
 block discarded – undo
444 471
 			<div class="custom_fields_above_signature">
445 472
 				<ul class="nolist">';
446 473
 
447
-		foreach ($context['print_custom_fields']['above_signature'] as $field)
448
-			if (!empty($field['output_html']))
474
+		foreach ($context['print_custom_fields']['above_signature'] as $field) {
475
+					if (!empty($field['output_html']))
449 476
 				echo '
450 477
 					<li>', $field['output_html'], '</li>';
478
+		}
451 479
 
452 480
 		echo '
453 481
 				</ul>
@@ -455,12 +483,13 @@  discard block
 block discarded – undo
455 483
 	}
456 484
 
457 485
 	// Show the users signature.
458
-	if ($context['signature_enabled'] && !empty($context['member']['signature']))
459
-		echo '
486
+	if ($context['signature_enabled'] && !empty($context['member']['signature'])) {
487
+			echo '
460 488
 			<div class="signature">
461 489
 				<h5>', $txt['signature'], ':</h5>
462 490
 				', $context['member']['signature'], '
463 491
 			</div>';
492
+	}
464 493
 
465 494
 	// Are there any custom profile fields for below the signature?
466 495
 	if (!empty($context['print_custom_fields']['below_signature']))
@@ -469,10 +498,11 @@  discard block
 block discarded – undo
469 498
 			<div class="custom_fields_below_signature">
470 499
 				<ul class="nolist">';
471 500
 
472
-		foreach ($context['print_custom_fields']['below_signature'] as $field)
473
-			if (!empty($field['output_html']))
501
+		foreach ($context['print_custom_fields']['below_signature'] as $field) {
502
+					if (!empty($field['output_html']))
474 503
 				echo '
475 504
 					<li>', $field['output_html'], '</li>';
505
+		}
476 506
 
477 507
 		echo '
478 508
 				</ul>
@@ -518,62 +548,70 @@  discard block
 block discarded – undo
518 548
 			</div>
519 549
 			<div class="list_posts">';
520 550
 
521
-			if (!$post['approved'])
522
-				echo '
551
+			if (!$post['approved']) {
552
+							echo '
523 553
 				<div class="approve_post">
524 554
 					<em>', $txt['post_awaiting_approval'], '</em>
525 555
 				</div>';
556
+			}
526 557
 
527 558
 			echo '
528 559
 				', $post['body'], '
529 560
 			</div>';
530 561
 
531
-			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete'])
532
-				echo '
562
+			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete']) {
563
+							echo '
533 564
 			<div class="floatright">
534 565
 				<ul class="quickbuttons">';
566
+			}
535 567
 
536 568
 			// If they *can* reply?
537
-			if ($post['can_reply'])
538
-				echo '
569
+			if ($post['can_reply']) {
570
+							echo '
539 571
 					<li><a href="', $scripturl, '?action=post;topic=', $post['topic'], '.', $post['start'], '"><span class="generic_icons reply_button"></span>', $txt['reply'], '</a></li>';
572
+			}
540 573
 
541 574
 			// If they *can* quote?
542
-			if ($post['can_quote'])
543
-				echo '
575
+			if ($post['can_quote']) {
576
+							echo '
544 577
 					<li><a href="', $scripturl . '?action=post;topic=', $post['topic'], '.', $post['start'], ';quote=', $post['id'], '"><span class="generic_icons quote"></span>', $txt['quote_action'], '</a></li>';
578
+			}
545 579
 
546 580
 			// How about... even... remove it entirely?!
547
-			if ($post['can_delete'])
548
-				echo '
581
+			if ($post['can_delete']) {
582
+							echo '
549 583
 					<li><a href="', $scripturl, '?action=deletemsg;msg=', $post['id'], ';topic=', $post['topic'], ';profile;u=', $context['member']['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['remove_message'], '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove'], '</a></li>';
584
+			}
550 585
 
551
-			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete'])
552
-				echo '
586
+			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete']) {
587
+							echo '
553 588
 				</ul>
554 589
 			</div><!-- .floatright -->';
590
+			}
555 591
 
556 592
 			echo '
557 593
 		</div><!-- $post[css_class] -->';
558 594
 		}
595
+	} else {
596
+			template_show_list('attachments');
559 597
 	}
560
-	else
561
-		template_show_list('attachments');
562 598
 
563 599
 	// No posts? Just end with a informative message.
564
-	if ((isset($context['attachments']) && empty($context['attachments'])) || (!isset($context['attachments']) && empty($context['posts'])))
565
-		echo '
600
+	if ((isset($context['attachments']) && empty($context['attachments'])) || (!isset($context['attachments']) && empty($context['posts']))) {
601
+			echo '
566 602
 		<div class="windowbg2">
567 603
 			', isset($context['attachments']) ? $txt['show_attachments_none'] : ($context['is_topics'] ? $txt['show_topics_none'] : $txt['show_posts_none']), '
568 604
 		</div>';
605
+	}
569 606
 
570 607
 	// Show more page numbers.
571
-	if (!empty($context['page_index']))
572
-		echo '
608
+	if (!empty($context['page_index'])) {
609
+			echo '
573 610
 		<div class="pagesection">
574 611
 			<div class="pagelinks">', $context['page_index'], '</div>
575 612
 		</div>';
576
-}
613
+	}
614
+	}
577 615
 
578 616
 /**
579 617
  * Template for showing alerts within the alerts popup
@@ -583,11 +621,12 @@  discard block
 block discarded – undo
583 621
 	global $context, $txt, $scripturl;
584 622
 
585 623
 	// Do we have an update message?
586
-	if (!empty($context['update_message']))
587
-		echo '
624
+	if (!empty($context['update_message'])) {
625
+			echo '
588 626
 		<div class="infobox">
589 627
 			', $context['update_message'], '.
590 628
 		</div>';
629
+	}
591 630
 
592 631
 	echo '
593 632
 		<div class="cat_bar">
@@ -596,13 +635,12 @@  discard block
 block discarded – undo
596 635
 			</h3>
597 636
 		</div>';
598 637
 
599
-	if (empty($context['alerts']))
600
-		echo '
638
+	if (empty($context['alerts'])) {
639
+			echo '
601 640
 		<div class="information">
602 641
 			', $txt['alerts_none'], '
603 642
 		</div>';
604
-
605
-	else
643
+	} else
606 644
 	{
607 645
 		// Start the form.
608 646
 		echo '
@@ -664,12 +702,12 @@  discard block
 block discarded – undo
664 702
 		</div>' : '';
665 703
 
666 704
 	// No drafts? Just show an informative message.
667
-	if (empty($context['drafts']))
668
-		echo '
705
+	if (empty($context['drafts'])) {
706
+			echo '
669 707
 		<div class="windowbg2 centertext">
670 708
 			', $txt['draft_none'], '
671 709
 		</div>';
672
-	else
710
+	} else
673 711
 	{
674 712
 		// For every draft to be displayed, give it its own div, and show the important details of the draft.
675 713
 		foreach ($context['drafts'] as $draft)
@@ -681,13 +719,15 @@  discard block
 block discarded – undo
681 719
 				<h5>
682 720
 					<strong><a href="', $scripturl, '?board=', $draft['board']['id'], '.0">', $draft['board']['name'], '</a> / ', $draft['topic']['link'], '</strong> &nbsp; &nbsp;';
683 721
 
684
-			if (!empty($draft['sticky']))
685
-				echo '
722
+			if (!empty($draft['sticky'])) {
723
+							echo '
686 724
 					<span class="generic_icons sticky" title="', $txt['sticky_topic'], '"></span>';
725
+			}
687 726
 
688
-			if (!empty($draft['locked']))
689
-				echo '
727
+			if (!empty($draft['locked'])) {
728
+							echo '
690 729
 					<span class="generic_icons lock" title="', $txt['locked_topic'], '"></span>';
730
+			}
691 731
 
692 732
 			echo '
693 733
 				</h5>
@@ -720,13 +760,13 @@  discard block
 block discarded – undo
720 760
 {
721 761
 	global $context, $scripturl, $txt;
722 762
 
723
-	if (!empty($context['saved_successful']))
724
-		echo '
763
+	if (!empty($context['saved_successful'])) {
764
+			echo '
725 765
 	<div class="infobox">', $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $context['member']['name']), '</div>';
726
-
727
-	elseif (!empty($context['saved_failed']))
728
-		echo '
766
+	} elseif (!empty($context['saved_failed'])) {
767
+			echo '
729 768
 	<div class="errorbox">', $context['saved_failed'], '</div>';
769
+	}
730 770
 
731 771
 	echo '
732 772
 	<div id="edit_buddies">
@@ -741,14 +781,16 @@  discard block
 block discarded – undo
741 781
 					<th scope="col" class="quarter_table">', $txt['name'], '</th>
742 782
 					<th scope="col">', $txt['status'], '</th>';
743 783
 
744
-	if (allowedTo('moderate_forum'))
745
-		echo '
784
+	if (allowedTo('moderate_forum')) {
785
+			echo '
746 786
 					<th scope="col">', $txt['email'], '</th>';
787
+	}
747 788
 
748
-	if (!empty($context['custom_pf']))
749
-		foreach ($context['custom_pf'] as $column)
789
+	if (!empty($context['custom_pf'])) {
790
+			foreach ($context['custom_pf'] as $column)
750 791
 				echo '
751 792
 					<th scope="col">', $column['label'], '</th>';
793
+	}
752 794
 
753 795
 	echo '
754 796
 					<th scope="col">', $txt['remove'], '</th>
@@ -757,13 +799,14 @@  discard block
 block discarded – undo
757 799
 			<tbody>';
758 800
 
759 801
 	// If they don't have any buddies don't list them!
760
-	if (empty($context['buddies']))
761
-		echo '
802
+	if (empty($context['buddies'])) {
803
+			echo '
762 804
 				<tr class="windowbg">
763 805
 					<td colspan="', allowedTo('moderate_forum') ? '10' : '9', '">
764 806
 						<strong>', $txt['no_buddies'], '</strong>
765 807
 					</td>
766 808
 				</tr>';
809
+	}
767 810
 
768 811
 		// Now loop through each buddy showing info on each.
769 812
 	else
@@ -777,17 +820,19 @@  discard block
 block discarded – undo
777 820
 						<a href="', $buddy['online']['href'], '"><span class="' . ($buddy['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $buddy['online']['text'] . '"></span></a>
778 821
 					</td>';
779 822
 
780
-			if ($buddy['show_email'])
781
-				echo '
823
+			if ($buddy['show_email']) {
824
+							echo '
782 825
 					<td>
783 826
 						<a href="mailto:' . $buddy['email'] . '" rel="nofollow"><span class="generic_icons mail icon" title="' . $txt['email'] . ' ' . $buddy['name'] . '"></span></a>
784 827
 					</td>';
828
+			}
785 829
 
786 830
 			// Show the custom profile fields for this user.
787
-			if (!empty($context['custom_pf']))
788
-				foreach ($context['custom_pf'] as $key => $column)
831
+			if (!empty($context['custom_pf'])) {
832
+							foreach ($context['custom_pf'] as $key => $column)
789 833
 					echo '
790 834
 					<td class="lefttext">', $buddy['options'][$key], '</td>';
835
+			}
791 836
 
792 837
 			echo '
793 838
 					<td>
@@ -820,9 +865,10 @@  discard block
 block discarded – undo
820 865
 			</dl>
821 866
 		</div>';
822 867
 
823
-	if (!empty($context['token_check']))
824
-		echo '
868
+	if (!empty($context['token_check'])) {
869
+			echo '
825 870
 		<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
871
+	}
826 872
 
827 873
 	echo '
828 874
 		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -848,13 +894,13 @@  discard block
 block discarded – undo
848 894
 {
849 895
 	global $context, $scripturl, $txt;
850 896
 
851
-	if (!empty($context['saved_successful']))
852
-		echo '
897
+	if (!empty($context['saved_successful'])) {
898
+			echo '
853 899
 	<div class="infobox">', $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $context['member']['name']), '</div>';
854
-
855
-	elseif (!empty($context['saved_failed']))
856
-		echo '
900
+	} elseif (!empty($context['saved_failed'])) {
901
+			echo '
857 902
 	<div class="errorbox">', $context['saved_failed'], '</div>';
903
+	}
858 904
 
859 905
 	echo '
860 906
 	<div id="edit_buddies">
@@ -869,9 +915,10 @@  discard block
 block discarded – undo
869 915
 					<th scope="col" class="quarter_table">', $txt['name'], '</th>
870 916
 					<th scope="col">', $txt['status'], '</th>';
871 917
 
872
-	if (allowedTo('moderate_forum'))
873
-		echo '
918
+	if (allowedTo('moderate_forum')) {
919
+			echo '
874 920
 					<th scope="col">', $txt['email'], '</th>';
921
+	}
875 922
 
876 923
 	echo '
877 924
 					<th scope="col">', $txt['ignore_remove'], '</th>
@@ -880,13 +927,14 @@  discard block
 block discarded – undo
880 927
 			<tbody>';
881 928
 
882 929
 	// If they don't have anyone on their ignore list, don't list it!
883
-	if (empty($context['ignore_list']))
884
-		echo '
930
+	if (empty($context['ignore_list'])) {
931
+			echo '
885 932
 				<tr class="windowbg">
886 933
 					<td colspan="', allowedTo('moderate_forum') ? '4' : '3', '">
887 934
 						<strong>', $txt['no_ignore'], '</strong>
888 935
 					</td>
889 936
 				</tr>';
937
+	}
890 938
 
891 939
 	// Now loop through each buddy showing info on each.
892 940
 	foreach ($context['ignore_list'] as $member)
@@ -898,11 +946,12 @@  discard block
 block discarded – undo
898 946
 						<a href="', $member['online']['href'], '"><span class="' . ($member['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $member['online']['text'] . '"></span></a>
899 947
 					</td>';
900 948
 
901
-		if ($member['show_email'])
902
-			echo '
949
+		if ($member['show_email']) {
950
+					echo '
903 951
 					<td>
904 952
 						<a href="mailto:' . $member['email'] . '" rel="nofollow"><span class="generic_icons mail icon" title="' . $txt['email'] . ' ' . $member['name'] . '"></span></a>
905 953
 					</td>';
954
+		}
906 955
 		echo '
907 956
 					<td>
908 957
 						<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=ignore;remove=', $member['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons delete" title="', $txt['ignore_remove'], '"></span></a>
@@ -932,9 +981,10 @@  discard block
 block discarded – undo
932 981
 			</dl>
933 982
 		</div>';
934 983
 
935
-	if (!empty($context['token_check']))
936
-		echo '
984
+	if (!empty($context['token_check'])) {
985
+			echo '
937 986
 		<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
987
+	}
938 988
 
939 989
 	echo '
940 990
 		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -980,9 +1030,10 @@  discard block
 block discarded – undo
980 1030
 					<a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['last_ip'], ';u=', $context['member']['id'], '">', $context['last_ip'], '</a>';
981 1031
 
982 1032
 	// Second address detected?
983
-	if (!empty($context['last_ip2']))
984
-		echo '
1033
+	if (!empty($context['last_ip2'])) {
1034
+			echo '
985 1035
 					, <a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['last_ip2'], ';u=', $context['member']['id'], '">', $context['last_ip2'], '</a>';
1036
+	}
986 1037
 
987 1038
 	echo '
988 1039
 				</dd>';
@@ -1048,9 +1099,10 @@  discard block
 block discarded – undo
1048 1099
 		</div>
1049 1100
 		<div class="windowbg2 noup">';
1050 1101
 
1051
-		foreach ($context['whois_servers'] as $server)
1052
-			echo '
1102
+		foreach ($context['whois_servers'] as $server) {
1103
+					echo '
1053 1104
 			<a href="', $server['url'], '" target="_blank" rel="noopener"', isset($context['auto_whois_server']) && $context['auto_whois_server']['name'] == $server['name'] ? ' style="font-weight: bold;"' : '', '>', $server['name'], '</a><br>';
1105
+		}
1054 1106
 		echo '
1055 1107
 		</div>
1056 1108
 		<br>';
@@ -1062,13 +1114,12 @@  discard block
 block discarded – undo
1062 1114
 			<h3 class="catbg">', $txt['members_from_ip'], ' ', $context['ip'], '</h3>
1063 1115
 		</div>';
1064 1116
 
1065
-	if (empty($context['ips']))
1066
-		echo '
1117
+	if (empty($context['ips'])) {
1118
+			echo '
1067 1119
 		<p class="windowbg2 description">
1068 1120
 			<em>', $txt['no_members_from_ip'], '</em>
1069 1121
 		</p>';
1070
-
1071
-	else
1122
+	} else
1072 1123
 	{
1073 1124
 		echo '
1074 1125
 		<table class="table_grid">
@@ -1081,12 +1132,13 @@  discard block
 block discarded – undo
1081 1132
 			<tbody>';
1082 1133
 
1083 1134
 		// Loop through each of the members and display them.
1084
-		foreach ($context['ips'] as $ip => $memberlist)
1085
-			echo '
1135
+		foreach ($context['ips'] as $ip => $memberlist) {
1136
+					echo '
1086 1137
 				<tr class="windowbg">
1087 1138
 					<td><a href="', $context['base_url'], ';searchip=', $ip, '">', $ip, '</a></td>
1088 1139
 					<td>', implode(', ', $memberlist), '</td>
1089 1140
 				</tr>';
1141
+		}
1090 1142
 
1091 1143
 		echo '
1092 1144
 			</tbody>
@@ -1128,11 +1180,10 @@  discard block
 block discarded – undo
1128 1180
 			</h3>
1129 1181
 		</div>';
1130 1182
 
1131
-	if ($context['member']['has_all_permissions'])
1132
-		echo '
1183
+	if ($context['member']['has_all_permissions']) {
1184
+			echo '
1133 1185
 		<div class="information">', $txt['showPermissions_all'], '</div>';
1134
-
1135
-	else
1186
+	} else
1136 1187
 	{
1137 1188
 		echo '
1138 1189
 		<div class="information">',$txt['showPermissions_help'], '</div>
@@ -1147,9 +1198,10 @@  discard block
 block discarded – undo
1147 1198
 			<div class="windowbg smalltext">
1148 1199
 				', $txt['showPermissions_restricted_boards_desc'], ':<br>';
1149 1200
 
1150
-			foreach ($context['no_access_boards'] as $no_access_board)
1151
-				echo '
1201
+			foreach ($context['no_access_boards'] as $no_access_board) {
1202
+							echo '
1152 1203
 				<a href="', $scripturl, '?board=', $no_access_board['id'], '.0">', $no_access_board['name'], '</a>', $no_access_board['is_last'] ? '' : ', ';
1204
+			}
1153 1205
 			echo '
1154 1206
 			</div>';
1155 1207
 		}
@@ -1181,12 +1233,13 @@  discard block
 block discarded – undo
1181 1233
 							</td>
1182 1234
 							<td class="smalltext">';
1183 1235
 
1184
-				if ($permission['is_denied'])
1185
-					echo '
1236
+				if ($permission['is_denied']) {
1237
+									echo '
1186 1238
 								<span class="alert">', $txt['showPermissions_denied'], ': ', implode(', ', $permission['groups']['denied']), '</span>';
1187
-				else
1188
-					echo '
1239
+				} else {
1240
+									echo '
1189 1241
 								', $txt['showPermissions_given'], ': ', implode(', ', $permission['groups']['allowed']);
1242
+				}
1190 1243
 
1191 1244
 				echo '
1192 1245
 							</td>
@@ -1197,10 +1250,10 @@  discard block
 block discarded – undo
1197 1250
 				</table>
1198 1251
 			</div><!-- .tborder -->
1199 1252
 			<br>';
1200
-		}
1201
-		else
1202
-			echo '
1253
+		} else {
1254
+					echo '
1203 1255
 			<p class="windowbg2">', $txt['showPermissions_none_general'], '</p>';
1256
+		}
1204 1257
 
1205 1258
 		// Board permission section.
1206 1259
 		echo '
@@ -1211,14 +1264,16 @@  discard block
 block discarded – undo
1211 1264
 						<select name="board" onchange="if (this.options[this.selectedIndex].value) this.form.submit();">
1212 1265
 							<option value="0"', $context['board'] == 0 ? ' selected' : '', '>', $txt['showPermissions_global'], '</option>';
1213 1266
 
1214
-		if (!empty($context['boards']))
1215
-			echo '
1267
+		if (!empty($context['boards'])) {
1268
+					echo '
1216 1269
 							<option value="" disabled>---------------------------</option>';
1270
+		}
1217 1271
 
1218 1272
 		// Fill the box with any local permission boards.
1219
-		foreach ($context['boards'] as $board)
1220
-			echo '
1273
+		foreach ($context['boards'] as $board) {
1274
+					echo '
1221 1275
 							<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['name'], ' (', $board['profile_name'], ')</option>';
1276
+		}
1222 1277
 
1223 1278
 		echo '
1224 1279
 						</select>
@@ -1247,13 +1302,13 @@  discard block
 block discarded – undo
1247 1302
 						</td>
1248 1303
 						<td class="smalltext">';
1249 1304
 
1250
-				if ($permission['is_denied'])
1251
-					echo '
1305
+				if ($permission['is_denied']) {
1306
+									echo '
1252 1307
 							<span class="alert">', $txt['showPermissions_denied'], ': ', implode(', ', $permission['groups']['denied']), '</span>';
1253
-
1254
-				else
1255
-					echo '
1308
+				} else {
1309
+									echo '
1256 1310
 							', $txt['showPermissions_given'], ': ', implode(', ', $permission['groups']['allowed']);
1311
+				}
1257 1312
 
1258 1313
 				echo '
1259 1314
 						</td>
@@ -1262,10 +1317,10 @@  discard block
 block discarded – undo
1262 1317
 			echo '
1263 1318
 				</tbody>
1264 1319
 			</table>';
1265
-		}
1266
-		else
1267
-			echo '
1320
+		} else {
1321
+					echo '
1268 1322
 			<p class="windowbg2">', $txt['showPermissions_none_board'], '</p>';
1323
+		}
1269 1324
 	echo '
1270 1325
 		</div><!-- #permissions -->';
1271 1326
 	}
@@ -1306,9 +1361,10 @@  discard block
 block discarded – undo
1306 1361
 			</div>';
1307 1362
 
1308 1363
 	// If they haven't post at all, don't draw the graph.
1309
-	if (empty($context['posts_by_time']))
1310
-		echo '
1364
+	if (empty($context['posts_by_time'])) {
1365
+			echo '
1311 1366
 			<p class="centertext padding">', $txt['statPanel_noPosts'], '</p>';
1367
+	}
1312 1368
 
1313 1369
 	// Otherwise do!
1314 1370
 	else
@@ -1317,8 +1373,8 @@  discard block
 block discarded – undo
1317 1373
 			<ul class="activity_stats flow_hidden">';
1318 1374
 
1319 1375
 		// The labels.
1320
-		foreach ($context['posts_by_time'] as $time_of_day)
1321
-			echo '
1376
+		foreach ($context['posts_by_time'] as $time_of_day) {
1377
+					echo '
1322 1378
 				<li', $time_of_day['is_last'] ? ' class="last"' : '', '>
1323 1379
 					<div class="bar" style="padding-top: ', ((int) (100 - $time_of_day['relative_percent'])), 'px;" title="', sprintf($txt['statPanel_activityTime_posts'], $time_of_day['posts'], $time_of_day['posts_percent']), '">
1324 1380
 						<div style="height: ', (int) $time_of_day['relative_percent'], 'px;">
@@ -1327,6 +1383,7 @@  discard block
 block discarded – undo
1327 1383
 					</div>
1328 1384
 					<span class="stats_hour">', $time_of_day['hour_format'], '</span>
1329 1385
 				</li>';
1386
+		}
1330 1387
 
1331 1388
 		echo '
1332 1389
 			</ul>';
@@ -1345,11 +1402,10 @@  discard block
 block discarded – undo
1345 1402
 					</h3>
1346 1403
 				</div>';
1347 1404
 
1348
-	if (empty($context['popular_boards']))
1349
-		echo '
1405
+	if (empty($context['popular_boards'])) {
1406
+			echo '
1350 1407
 				<p class="centertext padding">', $txt['statPanel_noPosts'], '</p>';
1351
-
1352
-	else
1408
+	} else
1353 1409
 	{
1354 1410
 		echo '
1355 1411
 				<dl class="stats">';
@@ -1379,10 +1435,10 @@  discard block
 block discarded – undo
1379 1435
 					</h3>
1380 1436
 				</div>';
1381 1437
 
1382
-	if (empty($context['board_activity']))
1383
-		echo '
1438
+	if (empty($context['board_activity'])) {
1439
+			echo '
1384 1440
 				<p class="centertext padding">', $txt['statPanel_noPosts'], '</p>';
1385
-	else
1441
+	} else
1386 1442
 	{
1387 1443
 		echo '
1388 1444
 				<dl class="stats">';
@@ -1433,90 +1489,97 @@  discard block
 block discarded – undo
1433 1489
 				<h3 class="catbg profile_hd">';
1434 1490
 
1435 1491
 		// Don't say "Profile" if this isn't the profile...
1436
-		if (!empty($context['profile_header_text']))
1437
-			echo '
1492
+		if (!empty($context['profile_header_text'])) {
1493
+					echo '
1438 1494
 					', $context['profile_header_text'];
1439
-		else
1440
-			echo '
1495
+		} else {
1496
+					echo '
1441 1497
 					', $txt['profile'];
1498
+		}
1442 1499
 
1443 1500
 		echo '
1444 1501
 				</h3>
1445 1502
 			</div>';
1446 1503
 
1447 1504
 	// Have we some description?
1448
-	if ($context['page_desc'])
1449
-		echo '
1505
+	if ($context['page_desc']) {
1506
+			echo '
1450 1507
 			<p class="information">', $context['page_desc'], '</p>';
1508
+	}
1451 1509
 
1452 1510
 	echo '
1453 1511
 			<div class="roundframe">';
1454 1512
 
1455 1513
 	// Any bits at the start?
1456
-	if (!empty($context['profile_prehtml']))
1457
-		echo '
1514
+	if (!empty($context['profile_prehtml'])) {
1515
+			echo '
1458 1516
 				<div>', $context['profile_prehtml'], '</div>';
1517
+	}
1459 1518
 
1460
-	if (!empty($context['profile_fields']))
1461
-		echo '
1519
+	if (!empty($context['profile_fields'])) {
1520
+			echo '
1462 1521
 				<dl class="settings">';
1522
+	}
1463 1523
 
1464 1524
 	// Start the big old loop 'of love.
1465 1525
 	$lastItem = 'hr';
1466 1526
 	foreach ($context['profile_fields'] as $key => $field)
1467 1527
 	{
1468 1528
 		// We add a little hack to be sure we never get more than one hr in a row!
1469
-		if ($lastItem == 'hr' && $field['type'] == 'hr')
1470
-			continue;
1529
+		if ($lastItem == 'hr' && $field['type'] == 'hr') {
1530
+					continue;
1531
+		}
1471 1532
 
1472 1533
 		$lastItem = $field['type'];
1473
-		if ($field['type'] == 'hr')
1474
-			echo '
1534
+		if ($field['type'] == 'hr') {
1535
+					echo '
1475 1536
 				</dl>
1476 1537
 				<hr>
1477 1538
 				<dl class="settings">';
1478
-
1479
-		elseif ($field['type'] == 'callback')
1539
+		} elseif ($field['type'] == 'callback')
1480 1540
 		{
1481 1541
 			if (isset($field['callback_func']) && function_exists('template_profile_' . $field['callback_func']))
1482 1542
 			{
1483 1543
 				$callback_func = 'template_profile_' . $field['callback_func'];
1484 1544
 				$callback_func();
1485 1545
 			}
1486
-		}
1487
-		else
1546
+		} else
1488 1547
 		{
1489 1548
 			echo '
1490 1549
 					<dt>
1491 1550
 						<strong', !empty($field['is_error']) ? ' class="error"' : '', '>', $field['type'] !== 'label' ? '<label for="' . $key . '">' : '', $field['label'], $field['type'] !== 'label' ? '</label>' : '', '</strong>';
1492 1551
 
1493 1552
 			// Does it have any subtext to show?
1494
-			if (!empty($field['subtext']))
1495
-				echo '
1553
+			if (!empty($field['subtext'])) {
1554
+							echo '
1496 1555
 						<br>
1497 1556
 						<span class="smalltext">', $field['subtext'], '</span>';
1557
+			}
1498 1558
 
1499 1559
 			echo '
1500 1560
 					</dt>
1501 1561
 					<dd>';
1502 1562
 
1503 1563
 			// Want to put something infront of the box?
1504
-			if (!empty($field['preinput']))
1505
-				echo '
1564
+			if (!empty($field['preinput'])) {
1565
+							echo '
1506 1566
 						', $field['preinput'];
1567
+			}
1507 1568
 
1508 1569
 			// What type of data are we showing?
1509
-			if ($field['type'] == 'label')
1510
-				echo '
1570
+			if ($field['type'] == 'label') {
1571
+							echo '
1511 1572
 						', $field['value'];
1573
+			}
1512 1574
 
1513 1575
 			// Maybe it's a text box - very likely!
1514 1576
 			elseif (in_array($field['type'], array('int', 'float', 'text', 'password', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'number', 'time', 'url')))
1515 1577
 			{
1516
-				if ($field['type'] == 'int' || $field['type'] == 'float')
1517
-					$type = 'number';
1518
-				else
1519
-					$type = $field['type'];
1578
+				if ($field['type'] == 'int' || $field['type'] == 'float') {
1579
+									$type = 'number';
1580
+				} else {
1581
+									$type = $field['type'];
1582
+				}
1520 1583
 				$step = $field['type'] == 'float' ? ' step="0.1"' : '';
1521 1584
 
1522 1585
 
@@ -1524,10 +1587,11 @@  discard block
 block discarded – undo
1524 1587
 						<input type="', $type, '" name="', $key, '" id="', $key, '" size="', empty($field['size']) ? 30 : $field['size'], '" value="', $field['value'], '" ', $field['input_attr'], ' ', $step, '>';
1525 1588
 			}
1526 1589
 			// You "checking" me out? ;)
1527
-			elseif ($field['type'] == 'check')
1528
-				echo '
1590
+			elseif ($field['type'] == 'check') {
1591
+							echo '
1529 1592
 						<input type="hidden" name="', $key, '" value="0">
1530 1593
 						<input type="checkbox" name="', $key, '" id="', $key, '"', !empty($field['value']) ? ' checked' : '', ' value="1" ', $field['input_attr'], '>';
1594
+			}
1531 1595
 
1532 1596
 			// Always fun - select boxes!
1533 1597
 			elseif ($field['type'] == 'select')
@@ -1538,14 +1602,16 @@  discard block
 block discarded – undo
1538 1602
 				if (isset($field['options']))
1539 1603
 				{
1540 1604
 					// Is this some code to generate the options?
1541
-					if (!is_array($field['options']))
1542
-						$field['options'] = $field['options']();
1605
+					if (!is_array($field['options'])) {
1606
+											$field['options'] = $field['options']();
1607
+					}
1543 1608
 
1544 1609
 					// Assuming we now have some!
1545
-					if (is_array($field['options']))
1546
-						foreach ($field['options'] as $value => $name)
1610
+					if (is_array($field['options'])) {
1611
+											foreach ($field['options'] as $value => $name)
1547 1612
 							echo '
1548 1613
 							<option value="', $value, '"', $value == $field['value'] ? ' selected' : '', '>', $name, '</option>';
1614
+					}
1549 1615
 				}
1550 1616
 
1551 1617
 				echo '
@@ -1553,31 +1619,34 @@  discard block
 block discarded – undo
1553 1619
 			}
1554 1620
 
1555 1621
 			// Something to end with?
1556
-			if (!empty($field['postinput']))
1557
-				echo '
1622
+			if (!empty($field['postinput'])) {
1623
+							echo '
1558 1624
 						', $field['postinput'];
1625
+			}
1559 1626
 
1560 1627
 			echo '
1561 1628
 					</dd>';
1562 1629
 		}
1563 1630
 	}
1564 1631
 
1565
-	if (!empty($context['profile_fields']))
1566
-		echo '
1632
+	if (!empty($context['profile_fields'])) {
1633
+			echo '
1567 1634
 				</dl>';
1635
+	}
1568 1636
 
1569 1637
 	// Are there any custom profile fields - if so print them!
1570 1638
 	if (!empty($context['custom_fields']))
1571 1639
 	{
1572
-		if ($lastItem != 'hr')
1573
-			echo '
1640
+		if ($lastItem != 'hr') {
1641
+					echo '
1574 1642
 				<hr>';
1643
+		}
1575 1644
 
1576 1645
 		echo '
1577 1646
 				<dl class="settings">';
1578 1647
 
1579
-		foreach ($context['custom_fields'] as $field)
1580
-			echo '
1648
+		foreach ($context['custom_fields'] as $field) {
1649
+					echo '
1581 1650
 					<dt>
1582 1651
 						<strong>', $field['name'], ': </strong><br>
1583 1652
 						<span class="smalltext">', $field['desc'], '</span>
@@ -1585,6 +1654,7 @@  discard block
 block discarded – undo
1585 1654
 					<dd>
1586 1655
 						', $field['input_html'], '
1587 1656
 					</dd>';
1657
+		}
1588 1658
 
1589 1659
 		echo '
1590 1660
 				</dl>';
@@ -1592,13 +1662,14 @@  discard block
 block discarded – undo
1592 1662
 	}
1593 1663
 
1594 1664
 	// Any closing HTML?
1595
-	if (!empty($context['profile_posthtml']))
1596
-		echo '
1665
+	if (!empty($context['profile_posthtml'])) {
1666
+			echo '
1597 1667
 				<div>', $context['profile_posthtml'], '</div>';
1668
+	}
1598 1669
 
1599 1670
 	// Only show the password box if it's actually needed.
1600
-	if ($context['require_password'])
1601
-		echo '
1671
+	if ($context['require_password']) {
1672
+			echo '
1602 1673
 				<dl class="settings">
1603 1674
 					<dt>
1604 1675
 						<strong', isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : '', '><label for="oldpasswrd">', $txt['current_password'], ': </label></strong><br>
@@ -1608,18 +1679,21 @@  discard block
 block discarded – undo
1608 1679
 						<input type="password" name="oldpasswrd" id="oldpasswrd" size="20">
1609 1680
 					</dd>
1610 1681
 				</dl>';
1682
+	}
1611 1683
 
1612 1684
 	// The button shouldn't say "Change profile" unless we're changing the profile...
1613
-	if (!empty($context['submit_button_text']))
1614
-		echo '
1685
+	if (!empty($context['submit_button_text'])) {
1686
+			echo '
1615 1687
 				<input type="submit" name="save" value="', $context['submit_button_text'], '" class="button floatright">';
1616
-	else
1617
-		echo '
1688
+	} else {
1689
+			echo '
1618 1690
 				<input type="submit" name="save" value="', $txt['change_profile'], '" class="button floatright">';
1691
+	}
1619 1692
 
1620
-	if (!empty($context['token_check']))
1621
-		echo '
1693
+	if (!empty($context['token_check'])) {
1694
+			echo '
1622 1695
 				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
1696
+	}
1623 1697
 
1624 1698
 	echo '
1625 1699
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -1629,10 +1703,11 @@  discard block
 block discarded – undo
1629 1703
 		</form>';
1630 1704
 
1631 1705
 	// Any final spellchecking stuff?
1632
-	if (!empty($context['show_spellchecking']))
1633
-		echo '
1706
+	if (!empty($context['show_spellchecking'])) {
1707
+			echo '
1634 1708
 		<form name="spell_form" id="spell_form" method="post" accept-charset="', $context['character_set'], '" target="spellWindow" action="', $scripturl, '?action=spellcheck"><input type="hidden" name="spellstring" value=""></form>';
1635
-}
1709
+	}
1710
+	}
1636 1711
 
1637 1712
 /**
1638 1713
  * Personal Message settings.
@@ -1669,10 +1744,11 @@  discard block
 block discarded – undo
1669 1744
 						<select name="pm_receive_from" id="pm_receive_from">
1670 1745
 							<option value="0"', empty($context['receive_from']) || (empty($modSettings['enable_buddylist']) && $context['receive_from'] < 3) ? ' selected' : '', '>', $txt['pm_receive_from_everyone'], '</option>';
1671 1746
 
1672
-	if (!empty($modSettings['enable_buddylist']))
1673
-		echo '
1747
+	if (!empty($modSettings['enable_buddylist'])) {
1748
+			echo '
1674 1749
 							<option value="1"', !empty($context['receive_from']) && $context['receive_from'] == 1 ? ' selected' : '', '>', $txt['pm_receive_from_ignore'], '</option>
1675 1750
 							<option value="2"', !empty($context['receive_from']) && $context['receive_from'] == 2 ? ' selected' : '', '>', $txt['pm_receive_from_buddies'], '</option>';
1751
+	}
1676 1752
 
1677 1753
 	echo '
1678 1754
 							<option value="3"', !empty($context['receive_from']) && $context['receive_from'] > 2 ? ' selected' : '', '>', $txt['pm_receive_from_admins'], '</option>
@@ -1715,11 +1791,12 @@  discard block
 block discarded – undo
1715 1791
 		if (empty($setting) || !is_array($setting))
1716 1792
 		{
1717 1793
 			// Insert a separator (unless this is the first item in the list)
1718
-			if ($i !== $first_option_key)
1719
-				echo '
1794
+			if ($i !== $first_option_key) {
1795
+							echo '
1720 1796
 				</dl>
1721 1797
 				<hr>
1722 1798
 				<dl class="settings">';
1799
+			}
1723 1800
 
1724 1801
 			// Should we give a name to this section?
1725 1802
 			if (is_string($setting) && !empty($setting))
@@ -1728,69 +1805,67 @@  discard block
 block discarded – undo
1728 1805
 				echo '
1729 1806
 					<dt><strong>' . $setting . '</strong></dt>
1730 1807
 					<dd></dd>';
1808
+			} else {
1809
+							$titled_section = false;
1731 1810
 			}
1732
-			else
1733
-				$titled_section = false;
1734 1811
 
1735 1812
 			continue;
1736 1813
 		}
1737 1814
 
1738 1815
 		// Is this disabled?
1739
-		if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled']))
1740
-			continue;
1741
-
1742
-		elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
1743
-			continue;
1744
-
1745
-		elseif ($setting['id'] == 'show_no_censored' && empty($modSettings['allow_no_censored']))
1746
-			continue;
1747
-
1748
-		elseif ($setting['id'] == 'posts_apply_ignore_list' && empty($modSettings['enable_buddylist']))
1749
-			continue;
1750
-
1751
-		elseif ($setting['id'] == 'wysiwyg_default' && !empty($modSettings['disable_wysiwyg']))
1752
-			continue;
1753
-
1754
-		elseif ($setting['id'] == 'drafts_autosave_enabled' && (empty($modSettings['drafts_autosave_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled']))))
1755
-			continue;
1756
-
1757
-		elseif ($setting['id'] == 'drafts_show_saved_enabled' && (empty($modSettings['drafts_show_saved_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled']))))
1758
-			continue;
1816
+		if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled'])) {
1817
+					continue;
1818
+		} elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage'])) {
1819
+					continue;
1820
+		} elseif ($setting['id'] == 'show_no_censored' && empty($modSettings['allow_no_censored'])) {
1821
+					continue;
1822
+		} elseif ($setting['id'] == 'posts_apply_ignore_list' && empty($modSettings['enable_buddylist'])) {
1823
+					continue;
1824
+		} elseif ($setting['id'] == 'wysiwyg_default' && !empty($modSettings['disable_wysiwyg'])) {
1825
+					continue;
1826
+		} elseif ($setting['id'] == 'drafts_autosave_enabled' && (empty($modSettings['drafts_autosave_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled'])))) {
1827
+					continue;
1828
+		} elseif ($setting['id'] == 'drafts_show_saved_enabled' && (empty($modSettings['drafts_show_saved_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled'])))) {
1829
+					continue;
1830
+		}
1759 1831
 
1760 1832
 		// Some of these may not be set...  Set to defaults here
1761 1833
 		$opts = array('topics_per_page', 'messages_per_page', 'display_quick_mod');
1762
-		if (in_array($setting['id'], $opts) && !isset($context['member']['options'][$setting['id']]))
1763
-			$context['member']['options'][$setting['id']] = 0;
1764
-
1765
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
1766
-			$setting['type'] = 'checkbox';
1767
-
1768
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
1769
-			$setting['type'] = 'number';
1834
+		if (in_array($setting['id'], $opts) && !isset($context['member']['options'][$setting['id']])) {
1835
+					$context['member']['options'][$setting['id']] = 0;
1836
+		}
1770 1837
 
1771
-		elseif ($setting['type'] == 'string')
1772
-			$setting['type'] = 'text';
1838
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
1839
+					$setting['type'] = 'checkbox';
1840
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
1841
+					$setting['type'] = 'number';
1842
+		} elseif ($setting['type'] == 'string') {
1843
+					$setting['type'] = 'text';
1844
+		}
1773 1845
 
1774
-		if (isset($setting['options']))
1775
-			$setting['type'] = 'list';
1846
+		if (isset($setting['options'])) {
1847
+					$setting['type'] = 'list';
1848
+		}
1776 1849
 
1777 1850
 		echo '
1778 1851
 					<dt>
1779 1852
 						<label for="', $setting['id'], '">', !$titled_section ? '<strong>' : '', $setting['label'], !$titled_section ? '</strong>' : '', '</label>';
1780 1853
 
1781
-		if (isset($setting['description']))
1782
-			echo '
1854
+		if (isset($setting['description'])) {
1855
+					echo '
1783 1856
 						<br>
1784 1857
 						<span class="smalltext">', $setting['description'], '</span>';
1858
+		}
1785 1859
 		echo '
1786 1860
 					</dt>
1787 1861
 					<dd>';
1788 1862
 
1789 1863
 		// Display checkbox options
1790
-		if ($setting['type'] == 'checkbox')
1791
-			echo '
1864
+		if ($setting['type'] == 'checkbox') {
1865
+					echo '
1792 1866
 						<input type="hidden" name="default_options[' . $setting['id'] . ']" value="0">
1793 1867
 						<input type="checkbox" name="default_options[', $setting['id'], ']" id="', $setting['id'], '"', !empty($context['member']['options'][$setting['id']]) ? ' checked' : '', ' value="1">';
1868
+		}
1794 1869
 
1795 1870
 		// How about selection lists, we all love them
1796 1871
 		elseif ($setting['type'] == 'list')
@@ -1798,9 +1873,10 @@  discard block
 block discarded – undo
1798 1873
 			echo '
1799 1874
 						<select name="default_options[', $setting['id'], ']" id="', $setting['id'], '"', '>';
1800 1875
 
1801
-			foreach ($setting['options'] as $value => $label)
1802
-				echo '
1876
+			foreach ($setting['options'] as $value => $label) {
1877
+							echo '
1803 1878
 							<option value="', $value, '"', $value == $context['member']['options'][$setting['id']] ? ' selected' : '', '>', $label, '</option>';
1879
+			}
1804 1880
 
1805 1881
 			echo '
1806 1882
 						</select>';
@@ -1816,14 +1892,13 @@  discard block
 block discarded – undo
1816 1892
 
1817 1893
 				echo '
1818 1894
 						<input type="number"', $min . $max . $step;
1819
-			}
1820
-			elseif (isset($setting['type']) && $setting['type'] == 'url')
1821
-				echo'
1895
+			} elseif (isset($setting['type']) && $setting['type'] == 'url') {
1896
+							echo'
1822 1897
 						<input type="url"';
1823
-
1824
-			else
1825
-				echo '
1898
+			} else {
1899
+							echo '
1826 1900
 						<input type="text"';
1901
+			}
1827 1902
 
1828 1903
 			echo ' name="default_options[', $setting['id'], ']" id="', $setting['id'], '" value="', isset($context['member']['options'][$setting['id']]) ? $context['member']['options'][$setting['id']] : $setting['value'], '"', $setting['type'] == 'number' ? ' size="5"' : '', '>';
1829 1904
 		}
@@ -1860,8 +1935,8 @@  discard block
 block discarded – undo
1860 1935
 				<dl class="settings">';
1861 1936
 
1862 1937
 	// Allow notification on announcements to be disabled?
1863
-	if (!empty($modSettings['allow_disableAnnounce']))
1864
-		echo '
1938
+	if (!empty($modSettings['allow_disableAnnounce'])) {
1939
+			echo '
1865 1940
 					<dt>
1866 1941
 						<label for="notify_announcements">', $txt['notify_important_email'], '</label>
1867 1942
 					</dt>
@@ -1869,15 +1944,17 @@  discard block
 block discarded – undo
1869 1944
 						<input type="hidden" name="notify_announcements" value="0">
1870 1945
 						<input type="checkbox" id="notify_announcements" name="notify_announcements" value="1"', !empty($context['member']['notify_announcements']) ? ' checked' : '', '>
1871 1946
 					</dd>';
1947
+	}
1872 1948
 
1873
-	if (!empty($modSettings['enable_ajax_alerts']))
1874
-		echo '
1949
+	if (!empty($modSettings['enable_ajax_alerts'])) {
1950
+			echo '
1875 1951
 					<dt>
1876 1952
 						<label for="notify_send_body">', $txt['notify_alert_timeout'], '</label>
1877 1953
 					</dt>
1878 1954
 					<dd>
1879 1955
 						<input type="number" size="4" id="notify_alert_timeout" name="opt_alert_timeout" min="0" value="', $context['member']['alert_timeout'], '">
1880 1956
 					</dd>';
1957
+	}
1881 1958
 
1882 1959
 	echo '
1883 1960
 				</dl>
@@ -1909,9 +1986,10 @@  discard block
 block discarded – undo
1909 1986
 
1910 1987
 				$label = $txt['alert_opt_' . $opts[1]];
1911 1988
 				$label_pos = isset($opts['label']) ? $opts['label'] : '';
1912
-				if ($label_pos == 'before')
1913
-					echo '
1989
+				if ($label_pos == 'before') {
1990
+									echo '
1914 1991
 						<label for="opt_', $opts[1], '">', $label, '</label>';
1992
+				}
1915 1993
 
1916 1994
 				$this_value = isset($context['alert_prefs'][$opts[1]]) ? $context['alert_prefs'][$opts[1]] : 0;
1917 1995
 				switch ($opts[0])
@@ -1925,17 +2003,19 @@  discard block
 block discarded – undo
1925 2003
 						echo '
1926 2004
 						<select name="opt_', $opts[1], '" id="opt_', $opts[1], '">';
1927 2005
 
1928
-						foreach ($opts['opts'] as $k => $v)
1929
-							echo '
2006
+						foreach ($opts['opts'] as $k => $v) {
2007
+													echo '
1930 2008
 							<option value="', $k, '"', $this_value == $k ? ' selected' : '', '>', $v, '</option>';
2009
+						}
1931 2010
 						echo '
1932 2011
 						</select>';
1933 2012
 						break;
1934 2013
 				}
1935 2014
 
1936
-				if ($label_pos == 'after')
1937
-					echo '
2015
+				if ($label_pos == 'after') {
2016
+									echo '
1938 2017
 						<label for="opt_', $opts[1], '">', $label, '</label>';
2018
+				}
1939 2019
 
1940 2020
 				echo '
1941 2021
 					</td>
@@ -2052,11 +2132,12 @@  discard block
 block discarded – undo
2052 2132
 			<p class="information">', $txt['groupMembership_info'], '</p>';
2053 2133
 
2054 2134
 	// Do we have an update message?
2055
-	if (!empty($context['update_message']))
2056
-		echo '
2135
+	if (!empty($context['update_message'])) {
2136
+			echo '
2057 2137
 			<div class="infobox">
2058 2138
 				', $context['update_message'], '.
2059 2139
 			</div>';
2140
+	}
2060 2141
 
2061 2142
 	echo '
2062 2143
 			<div id="groups">';
@@ -2078,8 +2159,7 @@  discard block
 block discarded – undo
2078 2159
 						</div>
2079 2160
 					</div>
2080 2161
 				</div><!-- .groupmembership -->';
2081
-	}
2082
-	else
2162
+	} else
2083 2163
 	{
2084 2164
 		echo '
2085 2165
 				<div class="title_bar">
@@ -2091,27 +2171,30 @@  discard block
 block discarded – undo
2091 2171
 			echo '
2092 2172
 				<div class="windowbg" id="primdiv_', $group['id'], '">';
2093 2173
 
2094
-				if ($context['can_edit_primary'])
2095
-					echo '
2174
+				if ($context['can_edit_primary']) {
2175
+									echo '
2096 2176
 					<input type="radio" name="primary" id="primary_', $group['id'], '" value="', $group['id'], '"', $group['is_primary'] ? ' checked' : '', ' onclick="highlightSelected(\'primdiv_' . $group['id'] . '\');"', $group['can_be_primary'] ? '' : ' disabled', '>';
2177
+				}
2097 2178
 
2098 2179
 				echo '
2099 2180
 					<label for="primary_', $group['id'], '"><strong>', (empty($group['color']) ? $group['name'] : '<span style="color: ' . $group['color'] . '">' . $group['name'] . '</span>'), '</strong>', (!empty($group['desc']) ? '<br><span class="smalltext">' . $group['desc'] . '</span>' : ''), '</label>';
2100 2181
 
2101 2182
 				// Can they leave their group?
2102
-				if ($group['can_leave'])
2103
-					echo '
2183
+				if ($group['can_leave']) {
2184
+									echo '
2104 2185
 					<a href="' . $scripturl . '?action=profile;save;u=' . $context['id_member'] . ';area=groupmembership;' . $context['session_var'] . '=' . $context['session_id'] . ';gid=' . $group['id'] . ';', $context[$context['token_check'] . '_token_var'], '=', $context[$context['token_check'] . '_token'], '">' . $txt['leave_group'] . '</a>';
2186
+				}
2105 2187
 
2106 2188
 				echo '
2107 2189
 				</div><!-- .windowbg -->';
2108 2190
 		}
2109 2191
 
2110
-		if ($context['can_edit_primary'])
2111
-			echo '
2192
+		if ($context['can_edit_primary']) {
2193
+					echo '
2112 2194
 				<div class="padding righttext">
2113 2195
 					<input type="submit" value="', $txt['make_primary'], '" class="button">
2114 2196
 				</div>';
2197
+		}
2115 2198
 
2116 2199
 		// Any groups they can join?
2117 2200
 		if (!empty($context['groups']['available']))
@@ -2127,17 +2210,16 @@  discard block
 block discarded – undo
2127 2210
 				<div class="windowbg">
2128 2211
 					<strong>', (empty($group['color']) ? $group['name'] : '<span style="color: ' . $group['color'] . '">' . $group['name'] . '</span>'), '</strong>', (!empty($group['desc']) ? '<br><span class="smalltext">' . $group['desc'] . '</span>' : ''), '';
2129 2212
 
2130
-				if ($group['type'] == 3)
2131
-					echo '
2213
+				if ($group['type'] == 3) {
2214
+									echo '
2132 2215
 					<a href="', $scripturl, '?action=profile;save;u=', $context['id_member'], ';area=groupmembership;', $context['session_var'], '=', $context['session_id'], ';gid=', $group['id'], ';', $context[$context['token_check'] . '_token_var'], '=', $context[$context['token_check'] . '_token'], '" class="button floatright">', $txt['join_group'], '</a>';
2133
-
2134
-				elseif ($group['type'] == 2 && $group['pending'])
2135
-					echo '
2216
+				} elseif ($group['type'] == 2 && $group['pending']) {
2217
+									echo '
2136 2218
 					<span class="floatright">', $txt['approval_pending'], '</span>';
2137
-
2138
-				elseif ($group['type'] == 2)
2139
-					echo '
2219
+				} elseif ($group['type'] == 2) {
2220
+									echo '
2140 2221
 					<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=groupmembership;request=', $group['id'], '" class="button floatright">', $txt['request_group'], '</a>';
2222
+				}
2141 2223
 
2142 2224
 				echo '
2143 2225
 				</div><!-- .windowbg -->';
@@ -2160,9 +2242,10 @@  discard block
 block discarded – undo
2160 2242
 
2161 2243
 						prevDiv.className = "windowbg";
2162 2244
 					}';
2163
-		if (isset($context['groups']['member'][$context['primary_group']]))
2164
-			echo '
2245
+		if (isset($context['groups']['member'][$context['primary_group']])) {
2246
+					echo '
2165 2247
 					highlightSelected("primdiv_' . $context['primary_group'] . '");';
2248
+		}
2166 2249
 
2167 2250
 		echo '
2168 2251
 				</script>';
@@ -2171,9 +2254,10 @@  discard block
 block discarded – undo
2171 2254
 	echo '
2172 2255
 			</div><!-- #groups -->';
2173 2256
 
2174
-	if (!empty($context['token_check']))
2175
-		echo '
2257
+	if (!empty($context['token_check'])) {
2258
+			echo '
2176 2259
 			<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2260
+	}
2177 2261
 
2178 2262
 	echo '
2179 2263
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2221,14 +2305,15 @@  discard block
 block discarded – undo
2221 2305
 
2222 2306
 		foreach ($category['boards'] as $board)
2223 2307
 		{
2224
-			if ($i == $limit)
2225
-				echo '
2308
+			if ($i == $limit) {
2309
+							echo '
2226 2310
 						</ul>
2227 2311
 					</li>
2228 2312
 				</ul>
2229 2313
 				<ul class="ignoreboards floatright">
2230 2314
 					<li class="category">
2231 2315
 						<ul>';
2316
+			}
2232 2317
 
2233 2318
 			echo '
2234 2319
 							<li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
@@ -2274,10 +2359,11 @@  discard block
 block discarded – undo
2274 2359
 
2275 2360
 	// Work out the starting color.
2276 2361
 	$context['current_color'] = $context['colors'][0];
2277
-	foreach ($context['colors'] as $limit => $color)
2278
-		if ($context['member']['warning'] >= $limit)
2362
+	foreach ($context['colors'] as $limit => $color) {
2363
+			if ($context['member']['warning'] >= $limit)
2279 2364
 			$context['current_color'] = $color;
2280
-}
2365
+	}
2366
+	}
2281 2367
 
2282 2368
 // Show all warnings of a user?
2283 2369
 function template_viewWarning()
@@ -2316,14 +2402,15 @@  discard block
 block discarded – undo
2316 2402
 				</dd>';
2317 2403
 
2318 2404
 	// There's some impact of this?
2319
-	if (!empty($context['level_effects'][$context['current_level']]))
2320
-		echo '
2405
+	if (!empty($context['level_effects'][$context['current_level']])) {
2406
+			echo '
2321 2407
 				<dt>
2322 2408
 					<strong>', $txt['profile_viewwarning_impact'], ':</strong>
2323 2409
 				</dt>
2324 2410
 				<dd>
2325 2411
 					', $context['level_effects'][$context['current_level']], '
2326 2412
 				</dd>';
2413
+	}
2327 2414
 
2328 2415
 	echo '
2329 2416
 			</dl>
@@ -2361,10 +2448,11 @@  discard block
 block discarded – undo
2361 2448
 
2362 2449
 			// Otherwise see what we can do...';
2363 2450
 
2364
-	foreach ($context['notification_templates'] as $k => $type)
2365
-		echo '
2451
+	foreach ($context['notification_templates'] as $k => $type) {
2452
+			echo '
2366 2453
 			if (index == ', $k, ')
2367 2454
 				document.getElementById(\'warn_body\').value = "', strtr($type['body'], array('"' => "'", "\n" => '\\n', "\r" => '')), '";';
2455
+	}
2368 2456
 
2369 2457
 	echo '
2370 2458
 		}
@@ -2374,10 +2462,11 @@  discard block
 block discarded – undo
2374 2462
 			// Also set the right effect.
2375 2463
 			effectText = "";';
2376 2464
 
2377
-	foreach ($context['level_effects'] as $limit => $text)
2378
-		echo '
2465
+	foreach ($context['level_effects'] as $limit => $text) {
2466
+			echo '
2379 2467
 			if (slideAmount >= ', $limit, ')
2380 2468
 				effectText = "', $text, '";';
2469
+	}
2381 2470
 
2382 2471
 	echo '
2383 2472
 			setInnerHTML(document.getElementById(\'cur_level_div\'), slideAmount + \'% (\' + effectText + \')\');
@@ -2392,32 +2481,35 @@  discard block
 block discarded – undo
2392 2481
 			</h3>
2393 2482
 		</div>';
2394 2483
 
2395
-	if (!$context['user']['is_owner'])
2396
-		echo '
2484
+	if (!$context['user']['is_owner']) {
2485
+			echo '
2397 2486
 		<p class="information">', $txt['profile_warning_desc'], '</p>';
2487
+	}
2398 2488
 
2399 2489
 	echo '
2400 2490
 		<div class="windowbg">
2401 2491
 			<dl class="settings">';
2402 2492
 
2403
-	if (!$context['user']['is_owner'])
2404
-		echo '
2493
+	if (!$context['user']['is_owner']) {
2494
+			echo '
2405 2495
 				<dt>
2406 2496
 					<strong>', $txt['profile_warning_name'], ':</strong>
2407 2497
 				</dt>
2408 2498
 				<dd>
2409 2499
 					<strong>', $context['member']['name'], '</strong>
2410 2500
 				</dd>';
2501
+	}
2411 2502
 
2412 2503
 	echo '
2413 2504
 				<dt>
2414 2505
 					<strong>', $txt['profile_warning_level'], ':</strong>';
2415 2506
 
2416 2507
 	// Is there only so much they can apply?
2417
-	if ($context['warning_limit'])
2418
-		echo '
2508
+	if ($context['warning_limit']) {
2509
+			echo '
2419 2510
 					<br>
2420 2511
 					<span class="smalltext">', sprintf($txt['profile_warning_limit_attribute'], $context['warning_limit']), '</span>';
2512
+	}
2421 2513
 
2422 2514
 	echo '
2423 2515
 				</dt>
@@ -2472,9 +2564,10 @@  discard block
 block discarded – undo
2472 2564
 						<option value="-1">', $txt['profile_warning_notify_template'], '</option>
2473 2565
 						<option value="-1" disabled>------------------------------</option>';
2474 2566
 
2475
-		foreach ($context['notification_templates'] as $id_template => $template)
2476
-			echo '
2567
+		foreach ($context['notification_templates'] as $id_template => $template) {
2568
+					echo '
2477 2569
 						<option value="', $id_template, '">', $template['title'], '</option>';
2570
+		}
2478 2571
 
2479 2572
 		echo '
2480 2573
 					</select>
@@ -2487,9 +2580,10 @@  discard block
 block discarded – undo
2487 2580
 			</dl>
2488 2581
 			<div class="righttext">';
2489 2582
 
2490
-	if (!empty($context['token_check']))
2491
-		echo '
2583
+	if (!empty($context['token_check'])) {
2584
+			echo '
2492 2585
 				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2586
+	}
2493 2587
 
2494 2588
 	echo '
2495 2589
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2505,8 +2599,8 @@  discard block
 block discarded – undo
2505 2599
 	echo '
2506 2600
 	<script>';
2507 2601
 
2508
-	if (!$context['user']['is_owner'])
2509
-		echo '
2602
+	if (!$context['user']['is_owner']) {
2603
+			echo '
2510 2604
 		modifyWarnNotify();
2511 2605
 		$(document).ready(function() {
2512 2606
 			$("#preview_button").click(function() {
@@ -2545,6 +2639,7 @@  discard block
 block discarded – undo
2545 2639
 			});
2546 2640
 			return false;
2547 2641
 		}';
2642
+	}
2548 2643
 
2549 2644
 	echo '
2550 2645
 	</script>';
@@ -2567,17 +2662,19 @@  discard block
 block discarded – undo
2567 2662
 			</div>';
2568 2663
 
2569 2664
 	// If deleting another account give them a lovely info box.
2570
-	if (!$context['user']['is_owner'])
2571
-		echo '
2665
+	if (!$context['user']['is_owner']) {
2666
+			echo '
2572 2667
 			<p class="information">', $txt['deleteAccount_desc'], '</p>';
2668
+	}
2573 2669
 
2574 2670
 	echo '
2575 2671
 			<div class="windowbg2">';
2576 2672
 
2577 2673
 	// If they are deleting their account AND the admin needs to approve it - give them another piece of info ;)
2578
-	if ($context['needs_approval'])
2579
-		echo '
2674
+	if ($context['needs_approval']) {
2675
+			echo '
2580 2676
 				<div class="errorbox">', $txt['deleteAccount_approval'], '</div>';
2677
+	}
2581 2678
 
2582 2679
 	// If the user is deleting their own account warn them first - and require a password!
2583 2680
 	if ($context['user']['is_owner'])
@@ -2589,9 +2686,10 @@  discard block
 block discarded – undo
2589 2686
 					<input type="password" name="oldpasswrd" size="20">
2590 2687
 					<input type="submit" value="', $txt['yes'], '" class="button">';
2591 2688
 
2592
-		if (!empty($context['token_check']))
2593
-			echo '
2689
+		if (!empty($context['token_check'])) {
2690
+					echo '
2594 2691
 					<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2692
+		}
2595 2693
 
2596 2694
 		echo '
2597 2695
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2621,10 +2719,11 @@  discard block
 block discarded – undo
2621 2719
 						<option value="topics">', $txt['deleteAccount_topics'], '</option>
2622 2720
 					</select>';
2623 2721
 
2624
-			if ($context['show_perma_delete'])
2625
-				echo '
2722
+			if ($context['show_perma_delete']) {
2723
+							echo '
2626 2724
 					<br>
2627 2725
 					<label for="perma_delete"><input type="checkbox" name="perma_delete" id="perma_delete" value="1">', $txt['deleteAccount_permanent'], ':</label>';
2726
+			}
2628 2727
 
2629 2728
 			echo '
2630 2729
 				</div>';
@@ -2637,9 +2736,10 @@  discard block
 block discarded – undo
2637 2736
 				<div>
2638 2737
 					<input type="submit" value="', $txt['delete'], '" class="button">';
2639 2738
 
2640
-		if (!empty($context['token_check']))
2641
-			echo '
2739
+		if (!empty($context['token_check'])) {
2740
+					echo '
2642 2741
 				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2742
+		}
2643 2743
 
2644 2744
 		echo '
2645 2745
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2665,8 +2765,8 @@  discard block
 block discarded – undo
2665 2765
 					<hr>';
2666 2766
 
2667 2767
 	// Only show the password box if it's actually needed.
2668
-	if ($context['require_password'])
2669
-		echo '
2768
+	if ($context['require_password']) {
2769
+			echo '
2670 2770
 					<dl class="settings">
2671 2771
 						<dt>
2672 2772
 							<strong', isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : '', '>', $txt['current_password'], ': </strong><br>
@@ -2676,13 +2776,15 @@  discard block
 block discarded – undo
2676 2776
 							<input type="password" name="oldpasswrd" size="20">
2677 2777
 						</dd>
2678 2778
 					</dl>';
2779
+	}
2679 2780
 
2680 2781
 	echo '
2681 2782
 					<div class="righttext">';
2682 2783
 
2683
-	if (!empty($context['token_check']))
2684
-		echo '
2784
+	if (!empty($context['token_check'])) {
2785
+			echo '
2685 2786
 						<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2787
+	}
2686 2788
 
2687 2789
 	echo '
2688 2790
 						<input type="submit" value="', $txt['change_profile'], '" class="button">
@@ -2709,9 +2811,10 @@  discard block
 block discarded – undo
2709 2811
 			<ul id="list_errors">';
2710 2812
 
2711 2813
 		// Cycle through each error and display an error message.
2712
-		foreach ($context['post_errors'] as $error)
2713
-			echo '
2814
+		foreach ($context['post_errors'] as $error) {
2815
+					echo '
2714 2816
 				<li>', isset($txt['profile_error_' . $error]) ? $txt['profile_error_' . $error] : $error, '</li>';
2817
+		}
2715 2818
 
2716 2819
 		echo '
2717 2820
 			</ul>';
@@ -2737,12 +2840,13 @@  discard block
 block discarded – undo
2737 2840
 								<select name="id_group" ', ($context['user']['is_owner'] && $context['member']['group_id'] == 1 ? 'onchange="if (this.value != 1 &amp;&amp; !confirm(\'' . $txt['deadmin_confirm'] . '\')) this.value = 1;"' : ''), '>';
2738 2841
 
2739 2842
 	// Fill the select box with all primary member groups that can be assigned to a member.
2740
-	foreach ($context['member_groups'] as $member_group)
2741
-		if (!empty($member_group['can_be_primary']))
2843
+	foreach ($context['member_groups'] as $member_group) {
2844
+			if (!empty($member_group['can_be_primary']))
2742 2845
 			echo '
2743 2846
 									<option value="', $member_group['id'], '"', $member_group['is_primary'] ? ' selected' : '', '>
2744 2847
 										', $member_group['name'], '
2745 2848
 									</option>';
2849
+	}
2746 2850
 
2747 2851
 	echo '
2748 2852
 								</select>
@@ -2755,10 +2859,11 @@  discard block
 block discarded – undo
2755 2859
 									<input type="hidden" name="additional_groups[]" value="0">';
2756 2860
 
2757 2861
 	// For each membergroup show a checkbox so members can be assigned to more than one group.
2758
-	foreach ($context['member_groups'] as $member_group)
2759
-		if ($member_group['can_be_additional'])
2862
+	foreach ($context['member_groups'] as $member_group) {
2863
+			if ($member_group['can_be_additional'])
2760 2864
 			echo '
2761 2865
 									<label for="additional_groups-', $member_group['id'], '"><input type="checkbox" name="additional_groups[]" value="', $member_group['id'], '" id="additional_groups-', $member_group['id'], '"', $member_group['is_additional'] ? ' checked' : '', '> ', $member_group['name'], '</label><br>';
2866
+	}
2762 2867
 
2763 2868
 	echo '
2764 2869
 								</span>
@@ -2818,9 +2923,10 @@  discard block
 block discarded – undo
2818 2923
 								<span class="smalltext">', $txt['sig_info'], '</span><br>
2819 2924
 								<br>';
2820 2925
 
2821
-	if ($context['show_spellchecking'])
2822
-		echo '
2926
+	if ($context['show_spellchecking']) {
2927
+			echo '
2823 2928
 								<input type="button" value="', $txt['spell_check'], '" onclick="spellCheck(\'creator\', \'signature\');" class="button">';
2929
+	}
2824 2930
 
2825 2931
 	echo '
2826 2932
 							</dt>
@@ -2828,17 +2934,20 @@  discard block
 block discarded – undo
2828 2934
 								<textarea class="editor" onkeyup="calcCharLeft();" id="signature" name="signature" rows="5" cols="50">', $context['member']['signature'], '</textarea><br>';
2829 2935
 
2830 2936
 	// If there is a limit at all!
2831
-	if (!empty($context['signature_limits']['max_length']))
2832
-		echo '
2937
+	if (!empty($context['signature_limits']['max_length'])) {
2938
+			echo '
2833 2939
 								<span class="smalltext">', sprintf($txt['max_sig_characters'], $context['signature_limits']['max_length']), ' <span id="signatureLeft">', $context['signature_limits']['max_length'], '</span></span><br>';
2940
+	}
2834 2941
 
2835
-	if (!empty($context['show_preview_button']))
2836
-		echo '
2942
+	if (!empty($context['show_preview_button'])) {
2943
+			echo '
2837 2944
 								<input type="button" name="preview_signature" id="preview_button" value="', $txt['preview_signature'], '" class="button floatright">';
2945
+	}
2838 2946
 
2839
-	if ($context['signature_warning'])
2840
-		echo '
2947
+	if ($context['signature_warning']) {
2948
+			echo '
2841 2949
 								<span class="smalltext">', $context['signature_warning'], '</span>';
2950
+	}
2842 2951
 
2843 2952
 	// Some javascript used to count how many characters have been used so far in the signature.
2844 2953
 	echo '
@@ -2883,9 +2992,10 @@  discard block
 block discarded – undo
2883 2992
 										<select name="cat" id="cat" size="10" onchange="changeSel(\'\');" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'server_stored\');">';
2884 2993
 
2885 2994
 		// This lists all the file categories.
2886
-		foreach ($context['avatars'] as $avatar)
2887
-			echo '
2995
+		foreach ($context['avatars'] as $avatar) {
2996
+					echo '
2888 2997
 											<option value="', $avatar['filename'] . ($avatar['is_dir'] ? '/' : ''), '"', ($avatar['checked'] ? ' selected' : ''), '>', $avatar['name'], '</option>';
2998
+		}
2889 2999
 
2890 3000
 		echo '
2891 3001
 										</select>
@@ -2917,20 +3027,22 @@  discard block
 block discarded – undo
2917 3027
 	}
2918 3028
 
2919 3029
 	// If the user can link to an off server avatar, show them a box to input the address.
2920
-	if (!empty($context['member']['avatar']['allow_external']))
2921
-		echo '
3030
+	if (!empty($context['member']['avatar']['allow_external'])) {
3031
+			echo '
2922 3032
 								<div id="avatar_external">
2923 3033
 									<div class="smalltext">', $txt['avatar_by_url'], '</div>', !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_download_and_resize' ? template_max_size('external') : '', '
2924 3034
 									<input type="text" name="userpicpersonal" size="45" value="', ((stristr($context['member']['avatar']['external'], 'http://') || stristr($context['member']['avatar']['external'], 'https://')) ? $context['member']['avatar']['external'] : 'http://'), '" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'external\');" onchange="if (typeof(previewExternalAvatar) != \'undefined\') previewExternalAvatar(this.value);">
2925 3035
 								</div>';
3036
+	}
2926 3037
 
2927 3038
 	// If the user is able to upload avatars to the server show them an upload box.
2928
-	if (!empty($context['member']['avatar']['allow_upload']))
2929
-		echo '
3039
+	if (!empty($context['member']['avatar']['allow_upload'])) {
3040
+			echo '
2930 3041
 								<div id="avatar_upload">
2931 3042
 									<input type="file" size="44" name="attachment" id="avatar_upload_box" value="" onchange="readfromUpload(this)"  onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'upload\');" accept="image/gif, image/jpeg, image/jpg, image/png">', template_max_size('upload'), '
2932 3043
 									', (!empty($context['member']['avatar']['id_attach']) ? '<br><img src="' . $context['member']['avatar']['href'] . (strpos($context['member']['avatar']['href'], '?') === false ? '?' : '&amp;') . 'time=' . time() . '" alt="" id="attached_image"><input type="hidden" name="id_attach" value="' . $context['member']['avatar']['id_attach'] . '">' : ''), '
2933 3044
 								</div>';
3045
+	}
2934 3046
 
2935 3047
 	// if the user is able to use Gravatar avatars show then the image preview
2936 3048
 	if (!empty($context['member']['avatar']['allow_gravatar']))
@@ -2939,16 +3051,17 @@  discard block
 block discarded – undo
2939 3051
 								<div id="avatar_gravatar">
2940 3052
 									<img src="' . $context['member']['avatar']['href'] . '" alt="">';
2941 3053
 
2942
-		if (empty($modSettings['gravatarAllowExtraEmail']))
2943
-			echo '
3054
+		if (empty($modSettings['gravatarAllowExtraEmail'])) {
3055
+					echo '
2944 3056
 									<div class="smalltext">', $txt['gravatar_noAlternateEmail'], '</div>';
2945
-		else
3057
+		} else
2946 3058
 		{
2947 3059
 			// Depending on other stuff, the stored value here might have some odd things in it from other areas.
2948
-			if ($context['member']['avatar']['external'] == $context['member']['email'])
2949
-				$textbox_value = '';
2950
-			else
2951
-				$textbox_value = $context['member']['avatar']['external'];
3060
+			if ($context['member']['avatar']['external'] == $context['member']['email']) {
3061
+							$textbox_value = '';
3062
+			} else {
3063
+							$textbox_value = $context['member']['avatar']['external'];
3064
+			}
2952 3065
 
2953 3066
 			echo '
2954 3067
 									<div class="smalltext">', $txt['gravatar_alternateEmail'], '</div>
@@ -3020,8 +3133,9 @@  discard block
 block discarded – undo
3020 3133
 	$h = !empty($modSettings['avatar_max_height_' . $type]) ? comma_format($modSettings['avatar_max_height_' . $type]) : 0;
3021 3134
 
3022 3135
 	$suffix = (!empty($w) ? 'w' : '') . (!empty($h) ? 'h' : '');
3023
-	if (empty($suffix))
3024
-		return;
3136
+	if (empty($suffix)) {
3137
+			return;
3138
+	}
3025 3139
 
3026 3140
 	echo '
3027 3141
 								<div class="smalltext">', sprintf($txt['avatar_max_size_' . $suffix], $w, $h), '</div>';
@@ -3046,9 +3160,10 @@  discard block
 block discarded – undo
3046 3160
 								<select name="easyformat" id="easyformat" onchange="document.forms.creator.time_format.value = this.options[this.selectedIndex].value;">';
3047 3161
 
3048 3162
 	// Help the user by showing a list of common time formats.
3049
-	foreach ($context['easy_timeformats'] as $time_format)
3050
-		echo '
3163
+	foreach ($context['easy_timeformats'] as $time_format) {
3164
+			echo '
3051 3165
 									<option value="', $time_format['format'], '"', $time_format['format'] == $context['member']['time_format'] ? ' selected' : '', '>', $time_format['title'], '</option>';
3166
+	}
3052 3167
 
3053 3168
 	echo '
3054 3169
 								</select>
@@ -3086,9 +3201,10 @@  discard block
 block discarded – undo
3086 3201
 							<dd>
3087 3202
 								<select name="smiley_set" id="smiley_set" onchange="document.getElementById(\'smileypr\').src = this.selectedIndex == 0 ? \'', $settings['images_url'], '/blank.png\' : \'', $modSettings['smileys_url'], '/\' + (this.selectedIndex != 1 ? this.options[this.selectedIndex].value : \'', !empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default'], '\') + \'/smiley.png\';">';
3088 3203
 
3089
-	foreach ($context['smiley_sets'] as $set)
3090
-		echo '
3204
+	foreach ($context['smiley_sets'] as $set) {
3205
+			echo '
3091 3206
 									<option value="', $set['id'], '"', $set['selected'] ? ' selected' : '', '>', $set['name'], '</option>';
3207
+	}
3092 3208
 
3093 3209
 	echo '
3094 3210
 								</select>
@@ -3140,10 +3256,11 @@  discard block
 block discarded – undo
3140 3256
 										<img src="', $context['tfa_qr_url'], '" alt="">
3141 3257
 									</div>';
3142 3258
 
3143
-	if (!empty($context['from_ajax']))
3144
-		echo '
3259
+	if (!empty($context['from_ajax'])) {
3260
+			echo '
3145 3261
 					<br>
3146 3262
 					<a href="javascript:self.close();"></a>';
3263
+	}
3147 3264
 
3148 3265
 	echo '
3149 3266
 				</div>
@@ -3183,17 +3300,16 @@  discard block
 block discarded – undo
3183 3300
 							</dt>
3184 3301
 							<dd>';
3185 3302
 
3186
-	if (!$context['tfa_enabled'] && $context['user']['is_owner'])
3187
-		echo '
3303
+	if (!$context['tfa_enabled'] && $context['user']['is_owner']) {
3304
+			echo '
3188 3305
 								<a href="', !empty($modSettings['force_ssl']) ? strtr($scripturl, array('http://' => 'https://')) : $scripturl, '?action=profile;area=tfasetup" id="enable_tfa">', $txt['tfa_profile_enable'], '</a>';
3189
-
3190
-	elseif (!$context['tfa_enabled'])
3191
-		echo '
3306
+	} elseif (!$context['tfa_enabled']) {
3307
+			echo '
3192 3308
 								', $txt['tfa_profile_disabled'];
3193
-
3194
-	else
3195
-		echo '
3309
+	} else {
3310
+			echo '
3196 3311
 								', sprintf($txt['tfa_profile_enabled'], $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=tfasetup;disable');
3312
+	}
3197 3313
 
3198 3314
 	echo '
3199 3315
 							</dd>';
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +898 added lines, -659 removed lines patch added patch discarded remove patch
@@ -75,8 +75,9 @@  discard block
 block discarded – undo
75 75
 $upcontext['inactive_timeout'] = 10;
76 76
 
77 77
 // The helper is crucial. Include it first thing.
78
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
78
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
79 79
     die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
80
+}
80 81
 
81 82
 require_once($upgrade_path . '/upgrade-helper.php');
82 83
 
@@ -107,11 +108,14 @@  discard block
 block discarded – undo
107 108
 	ini_set('default_socket_timeout', 900);
108 109
 }
109 110
 // Clean the upgrade path if this is from the client.
110
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
111
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
111
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
112
+	for ($i = 1;
113
+}
114
+$i < $_SERVER['argc']; $i++)
112 115
 	{
113
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
114
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
116
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
117
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
118
+		}
115 119
 	}
116 120
 
117 121
 // Are we from the client?
@@ -119,16 +123,17 @@  discard block
 block discarded – undo
119 123
 {
120 124
 	$command_line = true;
121 125
 	$disable_security = true;
122
-}
123
-else
126
+} else {
124 127
 	$command_line = false;
128
+}
125 129
 
126 130
 // Load this now just because we can.
127 131
 require_once($upgrade_path . '/Settings.php');
128 132
 
129 133
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
130
-if (isset($language))
134
+if (isset($language)) {
131 135
 	$language = str_ireplace('-utf8', '', $language);
136
+}
132 137
 
133 138
 // Are we logged in?
134 139
 if (isset($upgradeData))
@@ -136,10 +141,12 @@  discard block
 block discarded – undo
136 141
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
137 142
 
138 143
 	// Check for sensible values.
139
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
140
-		$upcontext['user']['started'] = time();
141
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
142
-		$upcontext['user']['updated'] = 0;
144
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
145
+			$upcontext['user']['started'] = time();
146
+	}
147
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
148
+			$upcontext['user']['updated'] = 0;
149
+	}
143 150
 
144 151
 	$upcontext['started'] = $upcontext['user']['started'];
145 152
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -204,8 +211,9 @@  discard block
 block discarded – undo
204 211
 			'db_error_skip' => true,
205 212
 		)
206 213
 	);
207
-	while ($row = $smcFunc['db_fetch_assoc']($request))
208
-		$modSettings[$row['variable']] = $row['value'];
214
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
215
+			$modSettings[$row['variable']] = $row['value'];
216
+	}
209 217
 	$smcFunc['db_free_result']($request);
210 218
 }
211 219
 
@@ -215,10 +223,12 @@  discard block
 block discarded – undo
215 223
 	$modSettings['theme_url'] = 'Themes/default';
216 224
 	$modSettings['images_url'] = 'Themes/default/images';
217 225
 }
218
-if (!isset($settings['default_theme_url']))
226
+if (!isset($settings['default_theme_url'])) {
219 227
 	$settings['default_theme_url'] = $modSettings['theme_url'];
220
-if (!isset($settings['default_theme_dir']))
228
+}
229
+if (!isset($settings['default_theme_dir'])) {
221 230
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
231
+}
222 232
 
223 233
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
224 234
 // Default title...
@@ -236,13 +246,15 @@  discard block
 block discarded – undo
236 246
 	$support_js = $upcontext['upgrade_status']['js'];
237 247
 
238 248
 	// Only set this if the upgrader status says so.
239
-	if (empty($is_debug))
240
-		$is_debug = $upcontext['upgrade_status']['debug'];
249
+	if (empty($is_debug)) {
250
+			$is_debug = $upcontext['upgrade_status']['debug'];
251
+	}
241 252
 
242 253
 	// Load the language.
243
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
244
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
245
-}
254
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
255
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
256
+	}
257
+	}
246 258
 // Set the defaults.
247 259
 else
248 260
 {
@@ -260,15 +272,18 @@  discard block
 block discarded – undo
260 272
 }
261 273
 
262 274
 // If this isn't the first stage see whether they are logging in and resuming.
263
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
275
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
264 276
 	checkLogin();
277
+}
265 278
 
266
-if ($command_line)
279
+if ($command_line) {
267 280
 	cmdStep0();
281
+}
268 282
 
269 283
 // Don't error if we're using xml.
270
-if (isset($_GET['xml']))
284
+if (isset($_GET['xml'])) {
271 285
 	$upcontext['return_error'] = true;
286
+}
272 287
 
273 288
 // Loop through all the steps doing each one as required.
274 289
 $upcontext['overall_percent'] = 0;
@@ -289,9 +304,9 @@  discard block
 block discarded – undo
289 304
 		}
290 305
 
291 306
 		// Call the step and if it returns false that means pause!
292
-		if (function_exists($step[2]) && $step[2]() === false)
293
-			break;
294
-		elseif (function_exists($step[2])) {
307
+		if (function_exists($step[2]) && $step[2]() === false) {
308
+					break;
309
+		} elseif (function_exists($step[2])) {
295 310
 			//Start each new step with this unset, so the 'normal' template is called first
296 311
 			unset($_GET['xml']);
297 312
 			//Clear out warnings at the start of each step
@@ -337,17 +352,18 @@  discard block
 block discarded – undo
337 352
 		// This should not happen my dear... HELP ME DEVELOPERS!!
338 353
 		if (!empty($command_line))
339 354
 		{
340
-			if (function_exists('debug_print_backtrace'))
341
-				debug_print_backtrace();
355
+			if (function_exists('debug_print_backtrace')) {
356
+							debug_print_backtrace();
357
+			}
342 358
 
343 359
 			echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
344 360
 			flush();
345 361
 			die();
346 362
 		}
347 363
 
348
-		if (!isset($_GET['xml']))
349
-			template_upgrade_above();
350
-		else
364
+		if (!isset($_GET['xml'])) {
365
+					template_upgrade_above();
366
+		} else
351 367
 		{
352 368
 			header('content-type: text/xml; charset=UTF-8');
353 369
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -369,25 +385,29 @@  discard block
 block discarded – undo
369 385
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
370 386
 
371 387
 			// Custom stuff to pass back?
372
-			if (!empty($upcontext['query_string']))
373
-				$upcontext['form_url'] .= $upcontext['query_string'];
388
+			if (!empty($upcontext['query_string'])) {
389
+							$upcontext['form_url'] .= $upcontext['query_string'];
390
+			}
374 391
 
375 392
 			// Call the appropriate subtemplate
376
-			if (is_callable('template_' . $upcontext['sub_template']))
377
-				call_user_func('template_' . $upcontext['sub_template']);
378
-			else
379
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
393
+			if (is_callable('template_' . $upcontext['sub_template'])) {
394
+							call_user_func('template_' . $upcontext['sub_template']);
395
+			} else {
396
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
397
+			}
380 398
 		}
381 399
 
382 400
 		// Was there an error?
383
-		if (!empty($upcontext['forced_error_message']))
384
-			echo $upcontext['forced_error_message'];
401
+		if (!empty($upcontext['forced_error_message'])) {
402
+					echo $upcontext['forced_error_message'];
403
+		}
385 404
 
386 405
 		// Show the footer.
387
-		if (!isset($_GET['xml']))
388
-			template_upgrade_below();
389
-		else
390
-			template_xml_below();
406
+		if (!isset($_GET['xml'])) {
407
+					template_upgrade_below();
408
+		} else {
409
+					template_xml_below();
410
+		}
391 411
 	}
392 412
 
393 413
 
@@ -399,15 +419,19 @@  discard block
 block discarded – undo
399 419
 		$seconds = intval($active % 60);
400 420
 
401 421
 		$totalTime = '';
402
-		if ($hours > 0)
403
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
404
-		if ($minutes > 0)
405
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
406
-		if ($seconds > 0)
407
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
422
+		if ($hours > 0) {
423
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
424
+		}
425
+		if ($minutes > 0) {
426
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
427
+		}
428
+		if ($seconds > 0) {
429
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
430
+		}
408 431
 
409
-		if (!empty($totalTime))
410
-			echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
432
+		if (!empty($totalTime)) {
433
+					echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
434
+		}
411 435
 	}
412 436
 
413 437
 	// Bang - gone!
@@ -428,8 +452,9 @@  discard block
 block discarded – undo
428 452
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
429 453
 		while ($entry = $dir->read())
430 454
 		{
431
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
432
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
455
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
456
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
457
+			}
433 458
 		}
434 459
 		$dir->close();
435 460
 	}
@@ -464,10 +489,11 @@  discard block
 block discarded – undo
464 489
 	}
465 490
 
466 491
 		// Override the language file?
467
-		if (isset($_GET['lang_file']))
468
-			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
469
-		elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
470
-			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
492
+		if (isset($_GET['lang_file'])) {
493
+					$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
494
+		} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
495
+					$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
496
+		}
471 497
 
472 498
 		// Make sure it exists, if it doesn't reset it.
473 499
 		if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -476,8 +502,9 @@  discard block
 block discarded – undo
476 502
 			list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
477 503
 
478 504
 			// If we have english and some other language, use the other language.  We Americans hate english :P.
479
-			if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
480
-				list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
505
+			if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
506
+							list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
507
+			}
481 508
 		}
482 509
 
483 510
 		// And now include the actual language file itself.
@@ -494,8 +521,9 @@  discard block
 block discarded – undo
494 521
 	global $upgradeurl, $upcontext, $command_line;
495 522
 
496 523
 	// Command line users can't be redirected.
497
-	if ($command_line)
498
-		upgradeExit(true);
524
+	if ($command_line) {
525
+			upgradeExit(true);
526
+	}
499 527
 
500 528
 	// Are we providing the core info?
501 529
 	if ($addForm)
@@ -521,12 +549,14 @@  discard block
 block discarded – undo
521 549
 	define('SMF', 1);
522 550
 
523 551
 	// Start the session.
524
-	if (@ini_get('session.save_handler') == 'user')
525
-		@ini_set('session.save_handler', 'files');
552
+	if (@ini_get('session.save_handler') == 'user') {
553
+			@ini_set('session.save_handler', 'files');
554
+	}
526 555
 	@session_start();
527 556
 
528
-	if (empty($smcFunc))
529
-		$smcFunc = array();
557
+	if (empty($smcFunc)) {
558
+			$smcFunc = array();
559
+	}
530 560
 
531 561
 	// We need this for authentication and some upgrade code
532 562
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -553,24 +583,27 @@  discard block
 block discarded – undo
553 583
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
554 584
 
555 585
 		// Make the connection...
556
-		if (empty($db_connection))
557
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
558
-		else
559
-			// If we've returned here, ping/reconnect to be safe
586
+		if (empty($db_connection)) {
587
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
588
+		} else {
589
+					// If we've returned here, ping/reconnect to be safe
560 590
 			$smcFunc['db_ping']($db_connection);
591
+		}
561 592
 
562 593
 		// Oh dear god!!
563
-		if ($db_connection === null)
564
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
594
+		if ($db_connection === null) {
595
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
596
+		}
565 597
 
566
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
567
-			$smcFunc['db_query']('', '
598
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
599
+					$smcFunc['db_query']('', '
568 600
 			SET NAMES {string:db_character_set}',
569 601
 			array(
570 602
 				'db_error_skip' => true,
571 603
 				'db_character_set' => $db_character_set,
572 604
 			)
573 605
 		);
606
+		}
574 607
 
575 608
 		// Load the modSettings data...
576 609
 		$request = $smcFunc['db_query']('', '
@@ -581,11 +614,11 @@  discard block
 block discarded – undo
581 614
 			)
582 615
 		);
583 616
 		$modSettings = array();
584
-		while ($row = $smcFunc['db_fetch_assoc']($request))
585
-			$modSettings[$row['variable']] = $row['value'];
617
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
618
+					$modSettings[$row['variable']] = $row['value'];
619
+		}
586 620
 		$smcFunc['db_free_result']($request);
587
-	}
588
-	else
621
+	} else
589 622
 	{
590 623
 		return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.');
591 624
 	}
@@ -599,9 +632,10 @@  discard block
 block discarded – undo
599 632
 		cleanRequest();
600 633
 	}
601 634
 
602
-	if (!isset($_GET['substep']))
603
-		$_GET['substep'] = 0;
604
-}
635
+	if (!isset($_GET['substep'])) {
636
+			$_GET['substep'] = 0;
637
+	}
638
+	}
605 639
 
606 640
 function initialize_inputs()
607 641
 {
@@ -631,8 +665,9 @@  discard block
 block discarded – undo
631 665
 		$dh = opendir(dirname(__FILE__));
632 666
 		while ($file = readdir($dh))
633 667
 		{
634
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
635
-				@unlink(dirname(__FILE__) . '/' . $file);
668
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
669
+							@unlink(dirname(__FILE__) . '/' . $file);
670
+			}
636 671
 		}
637 672
 		closedir($dh);
638 673
 
@@ -661,8 +696,9 @@  discard block
 block discarded – undo
661 696
 	$temp = 'upgrade_php?step';
662 697
 	while (strlen($temp) > 4)
663 698
 	{
664
-		if (isset($_GET[$temp]))
665
-			unset($_GET[$temp]);
699
+		if (isset($_GET[$temp])) {
700
+					unset($_GET[$temp]);
701
+		}
666 702
 		$temp = substr($temp, 1);
667 703
 	}
668 704
 
@@ -689,32 +725,39 @@  discard block
 block discarded – undo
689 725
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
690 726
 
691 727
 	// Need legacy scripts?
692
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
693
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
694
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
695
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
696
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
697
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
728
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
729
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
730
+	}
731
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
732
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
733
+	}
734
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
735
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
736
+	}
698 737
 
699 738
 	// We don't need "-utf8" files anymore...
700 739
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
701 740
 
702 741
 	// This needs to exist!
703
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
704
-		return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
705
-	else
706
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
742
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
743
+			return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
744
+	} else {
745
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
746
+	}
707 747
 
708
-	if (!$check)
709
-		// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
748
+	if (!$check) {
749
+			// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
710 750
 		return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.');
751
+	}
711 752
 
712 753
 	// Do they meet the install requirements?
713
-	if (!php_version_check())
714
-		return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
754
+	if (!php_version_check()) {
755
+			return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
756
+	}
715 757
 
716
-	if (!db_version_check())
717
-		return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
758
+	if (!db_version_check()) {
759
+			return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
760
+	}
718 761
 
719 762
 	// Do some checks to make sure they have proper privileges
720 763
 	db_extend('packages');
@@ -729,14 +772,16 @@  discard block
 block discarded – undo
729 772
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
730 773
 
731 774
 	// Sorry... we need CREATE, ALTER and DROP
732
-	if (!$create || !$alter || !$drop)
733
-		return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
775
+	if (!$create || !$alter || !$drop) {
776
+			return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
777
+	}
734 778
 
735 779
 	// Do a quick version spot check.
736 780
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
737 781
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
738
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
739
-		return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
782
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
783
+			return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
784
+	}
740 785
 
741 786
 	// What absolutely needs to be writable?
742 787
 	$writable_files = array(
@@ -745,12 +790,13 @@  discard block
 block discarded – undo
745 790
 	);
746 791
 
747 792
 	// Only check for minified writable files if we have it enabled or not set.
748
-	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files']))
749
-		$writable_files += array(
793
+	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) {
794
+			$writable_files += array(
750 795
 			$modSettings['theme_dir'] . '/css/minified.css',
751 796
 			$modSettings['theme_dir'] . '/scripts/minified.js',
752 797
 			$modSettings['theme_dir'] . '/scripts/minified_deferred.js',
753 798
 		);
799
+	}
754 800
 
755 801
 	// Do we need to add this setting?
756 802
 	$need_settings_update = empty($modSettings['custom_avatar_dir']);
@@ -762,12 +808,13 @@  discard block
 block discarded – undo
762 808
 	quickFileWritable($custom_av_dir);
763 809
 
764 810
 	// Are we good now?
765
-	if (!is_writable($custom_av_dir))
766
-		return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
767
-	elseif ($need_settings_update)
811
+	if (!is_writable($custom_av_dir)) {
812
+			return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
813
+	} elseif ($need_settings_update)
768 814
 	{
769
-		if (!function_exists('cache_put_data'))
770
-			require_once($sourcedir . '/Load.php');
815
+		if (!function_exists('cache_put_data')) {
816
+					require_once($sourcedir . '/Load.php');
817
+		}
771 818
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
772 819
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
773 820
 	}
@@ -776,28 +823,33 @@  discard block
 block discarded – undo
776 823
 
777 824
 	// Check the cache directory.
778 825
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
779
-	if (!file_exists($cachedir_temp))
780
-		@mkdir($cachedir_temp);
781
-	if (!file_exists($cachedir_temp))
782
-		return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
783
-
784
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
785
-		return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
786
-	elseif (!isset($_GET['skiplang']))
826
+	if (!file_exists($cachedir_temp)) {
827
+			@mkdir($cachedir_temp);
828
+	}
829
+	if (!file_exists($cachedir_temp)) {
830
+			return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
831
+	}
832
+
833
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
834
+			return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
835
+	} elseif (!isset($_GET['skiplang']))
787 836
 	{
788 837
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
789 838
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
790 839
 
791
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
792
-			return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
840
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
841
+					return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
842
+		}
793 843
 	}
794 844
 
795
-	if (!makeFilesWritable($writable_files))
796
-		return false;
845
+	if (!makeFilesWritable($writable_files)) {
846
+			return false;
847
+	}
797 848
 
798 849
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
799
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
800
-		return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
850
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
851
+			return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
852
+	}
801 853
 
802 854
 	// Upgrade the agreement.
803 855
 	elseif (isset($modSettings['agreement']))
@@ -808,8 +860,8 @@  discard block
 block discarded – undo
808 860
 	}
809 861
 
810 862
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
811
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
812
-		$upcontext['warning'] = '
863
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
864
+			$upcontext['warning'] = '
813 865
 			It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to &quot;' . $boarddir . '&quot; but should probably be &quot;' . dirname(__FILE__) . '&quot;. Settings.php currently lists your paths as:<br>
814 866
 			<ul>
815 867
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -817,19 +869,23 @@  discard block
 block discarded – undo
817 869
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
818 870
 			</ul>
819 871
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
872
+	}
820 873
 
821 874
 	// Confirm mbstring is loaded...
822
-	if (!extension_loaded('mbstring'))
823
-		return throw_error($txt['install_no_mbstring']);
875
+	if (!extension_loaded('mbstring')) {
876
+			return throw_error($txt['install_no_mbstring']);
877
+	}
824 878
 
825 879
 	// Check for https stream support.
826 880
 	$supported_streams = stream_get_wrappers();
827
-	if (!in_array('https', $supported_streams))
828
-		$upcontext['custom_warning'] = $txt['install_no_https'];
881
+	if (!in_array('https', $supported_streams)) {
882
+			$upcontext['custom_warning'] = $txt['install_no_https'];
883
+	}
829 884
 
830 885
 	// Either we're logged in or we're going to present the login.
831
-	if (checkLogin())
832
-		return true;
886
+	if (checkLogin()) {
887
+			return true;
888
+	}
833 889
 
834 890
 	$upcontext += createToken('login');
835 891
 
@@ -843,15 +899,17 @@  discard block
 block discarded – undo
843 899
 	global $smcFunc, $db_type, $support_js;
844 900
 
845 901
 	// Don't bother if the security is disabled.
846
-	if ($disable_security)
847
-		return true;
902
+	if ($disable_security) {
903
+			return true;
904
+	}
848 905
 
849 906
 	// Are we trying to login?
850 907
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
851 908
 	{
852 909
 		// If we've disabled security pick a suitable name!
853
-		if (empty($_POST['user']))
854
-			$_POST['user'] = 'Administrator';
910
+		if (empty($_POST['user'])) {
911
+					$_POST['user'] = 'Administrator';
912
+		}
855 913
 
856 914
 		// Before 2.0 these column names were different!
857 915
 		$oldDB = false;
@@ -866,16 +924,17 @@  discard block
 block discarded – undo
866 924
 					'db_error_skip' => true,
867 925
 				)
868 926
 			);
869
-			if ($smcFunc['db_num_rows']($request) != 0)
870
-				$oldDB = true;
927
+			if ($smcFunc['db_num_rows']($request) != 0) {
928
+							$oldDB = true;
929
+			}
871 930
 			$smcFunc['db_free_result']($request);
872 931
 		}
873 932
 
874 933
 		// Get what we believe to be their details.
875 934
 		if (!$disable_security)
876 935
 		{
877
-			if ($oldDB)
878
-				$request = $smcFunc['db_query']('', '
936
+			if ($oldDB) {
937
+							$request = $smcFunc['db_query']('', '
879 938
 					SELECT id_member, memberName AS member_name, passwd, id_group,
880 939
 					additionalGroups AS additional_groups, lngfile
881 940
 					FROM {db_prefix}members
@@ -885,8 +944,8 @@  discard block
 block discarded – undo
885 944
 						'db_error_skip' => true,
886 945
 					)
887 946
 				);
888
-			else
889
-				$request = $smcFunc['db_query']('', '
947
+			} else {
948
+							$request = $smcFunc['db_query']('', '
890 949
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
891 950
 					FROM {db_prefix}members
892 951
 					WHERE member_name = {string:member_name}',
@@ -895,6 +954,7 @@  discard block
 block discarded – undo
895 954
 						'db_error_skip' => true,
896 955
 					)
897 956
 				);
957
+			}
898 958
 			if ($smcFunc['db_num_rows']($request) != 0)
899 959
 			{
900 960
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -902,16 +962,17 @@  discard block
 block discarded – undo
902 962
 				$groups = explode(',', $addGroups);
903 963
 				$groups[] = $id_group;
904 964
 
905
-				foreach ($groups as $k => $v)
906
-					$groups[$k] = (int) $v;
965
+				foreach ($groups as $k => $v) {
966
+									$groups[$k] = (int) $v;
967
+				}
907 968
 
908 969
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
909 970
 
910 971
 				// We don't use "-utf8" anymore...
911 972
 				$user_language = str_ireplace('-utf8', '', $user_language);
973
+			} else {
974
+							$upcontext['username_incorrect'] = true;
912 975
 			}
913
-			else
914
-				$upcontext['username_incorrect'] = true;
915 976
 			$smcFunc['db_free_result']($request);
916 977
 		}
917 978
 		$upcontext['username'] = $_POST['user'];
@@ -921,13 +982,14 @@  discard block
 block discarded – undo
921 982
 		{
922 983
 			$upcontext['upgrade_status']['js'] = 1;
923 984
 			$support_js = 1;
985
+		} else {
986
+					$support_js = 0;
924 987
 		}
925
-		else
926
-			$support_js = 0;
927 988
 
928 989
 		// Note down the version we are coming from.
929
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
930
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
990
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
991
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
992
+		}
931 993
 
932 994
 		// Didn't get anywhere?
933 995
 		if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect']))
@@ -961,15 +1023,15 @@  discard block
 block discarded – undo
961 1023
 							'db_error_skip' => true,
962 1024
 						)
963 1025
 					);
964
-					if ($smcFunc['db_num_rows']($request) == 0)
965
-						return throw_error('You need to be an admin to perform an upgrade!');
1026
+					if ($smcFunc['db_num_rows']($request) == 0) {
1027
+											return throw_error('You need to be an admin to perform an upgrade!');
1028
+					}
966 1029
 					$smcFunc['db_free_result']($request);
967 1030
 				}
968 1031
 
969 1032
 				$upcontext['user']['id'] = $id_member;
970 1033
 				$upcontext['user']['name'] = $name;
971
-			}
972
-			else
1034
+			} else
973 1035
 			{
974 1036
 				$upcontext['user']['id'] = 1;
975 1037
 				$upcontext['user']['name'] = 'Administrator';
@@ -985,11 +1047,11 @@  discard block
 block discarded – undo
985 1047
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
986 1048
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
987 1049
 
988
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
989
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
990
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
991
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
992
-				else
1050
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
1051
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
1052
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
1053
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
1054
+				} else
993 1055
 				{
994 1056
 					// Set this as the new language.
995 1057
 					$upcontext['language'] = $user_language;
@@ -1033,8 +1095,9 @@  discard block
 block discarded – undo
1033 1095
 	unset($member_columns);
1034 1096
 
1035 1097
 	// If we've not submitted then we're done.
1036
-	if (empty($_POST['upcont']))
1037
-		return false;
1098
+	if (empty($_POST['upcont'])) {
1099
+			return false;
1100
+	}
1038 1101
 
1039 1102
 	// Firstly, if they're enabling SM stat collection just do it.
1040 1103
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -1054,16 +1117,17 @@  discard block
 block discarded – undo
1054 1117
 				fwrite($fp, $out);
1055 1118
 
1056 1119
 				$return_data = '';
1057
-				while (!feof($fp))
1058
-					$return_data .= fgets($fp, 128);
1120
+				while (!feof($fp)) {
1121
+									$return_data .= fgets($fp, 128);
1122
+				}
1059 1123
 
1060 1124
 				fclose($fp);
1061 1125
 
1062 1126
 				// Get the unique site ID.
1063 1127
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1064 1128
 
1065
-				if (!empty($ID[1]))
1066
-					$smcFunc['db_insert']('replace',
1129
+				if (!empty($ID[1])) {
1130
+									$smcFunc['db_insert']('replace',
1067 1131
 						$db_prefix . 'settings',
1068 1132
 						array('variable' => 'string', 'value' => 'string'),
1069 1133
 						array(
@@ -1072,9 +1136,9 @@  discard block
 block discarded – undo
1072 1136
 						),
1073 1137
 						array('variable')
1074 1138
 					);
1139
+				}
1075 1140
 			}
1076
-		}
1077
-		else
1141
+		} else
1078 1142
 		{
1079 1143
 			$smcFunc['db_insert']('replace',
1080 1144
 				$db_prefix . 'settings',
@@ -1085,8 +1149,8 @@  discard block
 block discarded – undo
1085 1149
 		}
1086 1150
 	}
1087 1151
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1088
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1089
-		$smcFunc['db_query']('', '
1152
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1153
+			$smcFunc['db_query']('', '
1090 1154
 			DELETE FROM {db_prefix}settings
1091 1155
 			WHERE variable = {string:enable_sm_stats}',
1092 1156
 			array(
@@ -1094,6 +1158,7 @@  discard block
 block discarded – undo
1094 1158
 				'db_error_skip' => true,
1095 1159
 			)
1096 1160
 		);
1161
+	}
1097 1162
 
1098 1163
 	// Deleting old karma stuff?
1099 1164
 	if (!empty($_POST['delete_karma']))
@@ -1108,20 +1173,22 @@  discard block
 block discarded – undo
1108 1173
 		);
1109 1174
 
1110 1175
 		// Cleaning up old karma member settings.
1111
-		if ($upcontext['karma_installed']['good'])
1112
-			$smcFunc['db_query']('', '
1176
+		if ($upcontext['karma_installed']['good']) {
1177
+					$smcFunc['db_query']('', '
1113 1178
 				ALTER TABLE {db_prefix}members
1114 1179
 				DROP karma_good',
1115 1180
 				array()
1116 1181
 			);
1182
+		}
1117 1183
 
1118 1184
 		// Does karma bad was enable?
1119
-		if ($upcontext['karma_installed']['bad'])
1120
-			$smcFunc['db_query']('', '
1185
+		if ($upcontext['karma_installed']['bad']) {
1186
+					$smcFunc['db_query']('', '
1121 1187
 				ALTER TABLE {db_prefix}members
1122 1188
 				DROP karma_bad',
1123 1189
 				array()
1124 1190
 			);
1191
+		}
1125 1192
 
1126 1193
 		// Cleaning up old karma permissions.
1127 1194
 		$smcFunc['db_query']('', '
@@ -1139,32 +1206,37 @@  discard block
 block discarded – undo
1139 1206
 	}
1140 1207
 
1141 1208
 	// Emptying the error log?
1142
-	if (!empty($_POST['empty_error']))
1143
-		$smcFunc['db_query']('truncate_table', '
1209
+	if (!empty($_POST['empty_error'])) {
1210
+			$smcFunc['db_query']('truncate_table', '
1144 1211
 			TRUNCATE {db_prefix}log_errors',
1145 1212
 			array(
1146 1213
 			)
1147 1214
 		);
1215
+	}
1148 1216
 
1149 1217
 	$changes = array();
1150 1218
 
1151 1219
 	// Add proxy settings.
1152
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1153
-		$changes += array(
1220
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1221
+			$changes += array(
1154 1222
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1155 1223
 			'image_proxy_maxsize' => 5190,
1156 1224
 			'image_proxy_enabled' => 0,
1157 1225
 		);
1226
+	}
1158 1227
 
1159 1228
 	// If $boardurl reflects https, set force_ssl
1160
-	if (!function_exists('cache_put_data'))
1161
-		require_once($sourcedir . '/Load.php');
1162
-	if (stripos($boardurl, 'https://') !== false)
1163
-		updateSettings(array('force_ssl' => '1'));
1229
+	if (!function_exists('cache_put_data')) {
1230
+			require_once($sourcedir . '/Load.php');
1231
+	}
1232
+	if (stripos($boardurl, 'https://') !== false) {
1233
+			updateSettings(array('force_ssl' => '1'));
1234
+	}
1164 1235
 
1165 1236
 	// If we're overriding the language follow it through.
1166
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1167
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1237
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1238
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1239
+	}
1168 1240
 
1169 1241
 	if (!empty($_POST['maint']))
1170 1242
 	{
@@ -1176,26 +1248,29 @@  discard block
 block discarded – undo
1176 1248
 		{
1177 1249
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1178 1250
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1179
-		}
1180
-		else
1251
+		} else
1181 1252
 		{
1182 1253
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1183 1254
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1184 1255
 		}
1185 1256
 	}
1186 1257
 
1187
-	if ($command_line)
1188
-		echo ' * Updating Settings.php...';
1258
+	if ($command_line) {
1259
+			echo ' * Updating Settings.php...';
1260
+	}
1189 1261
 
1190 1262
 	// Fix some old paths.
1191
-	if (substr($boarddir, 0, 1) == '.')
1192
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1263
+	if (substr($boarddir, 0, 1) == '.') {
1264
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1265
+	}
1193 1266
 
1194
-	if (substr($sourcedir, 0, 1) == '.')
1195
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1267
+	if (substr($sourcedir, 0, 1) == '.') {
1268
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1269
+	}
1196 1270
 
1197
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1198
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1271
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1272
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1273
+	}
1199 1274
 
1200 1275
 	// If they have a "host:port" setup for the host, split that into separate values
1201 1276
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1206,32 +1281,36 @@  discard block
 block discarded – undo
1206 1281
 		$changes['db_server'] = '\'' . $db_server . '\'';
1207 1282
 
1208 1283
 		// Only set this if we're not using the default port
1209
-		if ($db_port != ini_get('mysqli.default_port'))
1210
-			$changes['db_port'] = (int) $db_port;
1211
-	}
1212
-	elseif (!empty($db_port))
1284
+		if ($db_port != ini_get('mysqli.default_port')) {
1285
+					$changes['db_port'] = (int) $db_port;
1286
+		}
1287
+	} elseif (!empty($db_port))
1213 1288
 	{
1214 1289
 		// If db_port is set and is the same as the default, set it to ''
1215 1290
 		if ($db_type == 'mysql')
1216 1291
 		{
1217
-			if ($db_port == ini_get('mysqli.default_port'))
1218
-				$changes['db_port'] = '\'\'';
1219
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1220
-				$changes['db_port'] = '\'\'';
1292
+			if ($db_port == ini_get('mysqli.default_port')) {
1293
+							$changes['db_port'] = '\'\'';
1294
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1295
+							$changes['db_port'] = '\'\'';
1296
+			}
1221 1297
 		}
1222 1298
 	}
1223 1299
 
1224 1300
 	// Maybe we haven't had this option yet?
1225
-	if (empty($packagesdir))
1226
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1301
+	if (empty($packagesdir)) {
1302
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1303
+	}
1227 1304
 
1228 1305
 	// Add support for $tasksdir var.
1229
-	if (empty($tasksdir))
1230
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1306
+	if (empty($tasksdir)) {
1307
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1308
+	}
1231 1309
 
1232 1310
 	// Make sure we fix the language as well.
1233
-	if (stristr($language, '-utf8'))
1234
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1311
+	if (stristr($language, '-utf8')) {
1312
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1313
+	}
1235 1314
 
1236 1315
 	// @todo Maybe change the cookie name if going to 1.1, too?
1237 1316
 
@@ -1242,8 +1321,9 @@  discard block
 block discarded – undo
1242 1321
 	// Tell Settings.php to store db_last_error.php in the cache
1243 1322
 	move_db_last_error_to_cachedir();
1244 1323
 
1245
-	if ($command_line)
1246
-		echo ' Successful.' . "\n";
1324
+	if ($command_line) {
1325
+			echo ' Successful.' . "\n";
1326
+	}
1247 1327
 
1248 1328
 	// Are we doing debug?
1249 1329
 	if (isset($_POST['debug']))
@@ -1253,8 +1333,9 @@  discard block
 block discarded – undo
1253 1333
 	}
1254 1334
 
1255 1335
 	// If we're not backing up then jump one.
1256
-	if (empty($_POST['backup']))
1257
-		$upcontext['current_step']++;
1336
+	if (empty($_POST['backup'])) {
1337
+			$upcontext['current_step']++;
1338
+	}
1258 1339
 
1259 1340
 	// If we've got here then let's proceed to the next step!
1260 1341
 	return true;
@@ -1269,8 +1350,9 @@  discard block
 block discarded – undo
1269 1350
 	$upcontext['page_title'] = $txt['backup_database'];
1270 1351
 
1271 1352
 	// Done it already - js wise?
1272
-	if (!empty($_POST['backup_done']))
1273
-		return true;
1353
+	if (!empty($_POST['backup_done'])) {
1354
+			return true;
1355
+	}
1274 1356
 
1275 1357
 	// Some useful stuff here.
1276 1358
 	db_extend();
@@ -1284,9 +1366,10 @@  discard block
 block discarded – undo
1284 1366
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1285 1367
 
1286 1368
 	$table_names = array();
1287
-	foreach ($tables as $table)
1288
-		if (substr($table, 0, 7) !== 'backup_')
1369
+	foreach ($tables as $table) {
1370
+			if (substr($table, 0, 7) !== 'backup_')
1289 1371
 			$table_names[] = $table;
1372
+	}
1290 1373
 
1291 1374
 	$upcontext['table_count'] = count($table_names);
1292 1375
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1296,12 +1379,14 @@  discard block
 block discarded – undo
1296 1379
 	$file_steps = $upcontext['table_count'];
1297 1380
 
1298 1381
 	// What ones have we already done?
1299
-	foreach ($table_names as $id => $table)
1300
-		if ($id < $_GET['substep'])
1382
+	foreach ($table_names as $id => $table) {
1383
+			if ($id < $_GET['substep'])
1301 1384
 			$upcontext['previous_tables'][] = $table;
1385
+	}
1302 1386
 
1303
-	if ($command_line)
1304
-		echo 'Backing Up Tables.';
1387
+	if ($command_line) {
1388
+			echo 'Backing Up Tables.';
1389
+	}
1305 1390
 
1306 1391
 	// If we don't support javascript we backup here.
1307 1392
 	if (!$support_js || isset($_GET['xml']))
@@ -1320,8 +1405,9 @@  discard block
 block discarded – undo
1320 1405
 			backupTable($table_names[$substep]);
1321 1406
 
1322 1407
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1323
-			if (isset($_GET['xml']))
1324
-				return upgradeExit();
1408
+			if (isset($_GET['xml'])) {
1409
+							return upgradeExit();
1410
+			}
1325 1411
 		}
1326 1412
 
1327 1413
 		if ($command_line)
@@ -1354,9 +1440,10 @@  discard block
 block discarded – undo
1354 1440
 
1355 1441
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1356 1442
 
1357
-	if ($command_line)
1358
-		echo ' done.';
1359
-}
1443
+	if ($command_line) {
1444
+			echo ' done.';
1445
+	}
1446
+	}
1360 1447
 
1361 1448
 // Step 2: Everything.
1362 1449
 function DatabaseChanges()
@@ -1365,8 +1452,9 @@  discard block
 block discarded – undo
1365 1452
 	global $upcontext, $support_js, $db_type;
1366 1453
 
1367 1454
 	// Have we just completed this?
1368
-	if (!empty($_POST['database_done']))
1369
-		return true;
1455
+	if (!empty($_POST['database_done'])) {
1456
+			return true;
1457
+	}
1370 1458
 
1371 1459
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1372 1460
 	$upcontext['page_title'] = $txt['database_changes'];
@@ -1381,15 +1469,16 @@  discard block
 block discarded – undo
1381 1469
 	);
1382 1470
 
1383 1471
 	// How many files are there in total?
1384
-	if (isset($_GET['filecount']))
1385
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1386
-	else
1472
+	if (isset($_GET['filecount'])) {
1473
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1474
+	} else
1387 1475
 	{
1388 1476
 		$upcontext['file_count'] = 0;
1389 1477
 		foreach ($files as $file)
1390 1478
 		{
1391
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1392
-				$upcontext['file_count']++;
1479
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1480
+							$upcontext['file_count']++;
1481
+			}
1393 1482
 		}
1394 1483
 	}
1395 1484
 
@@ -1399,9 +1488,9 @@  discard block
 block discarded – undo
1399 1488
 	$upcontext['cur_file_num'] = 0;
1400 1489
 	foreach ($files as $file)
1401 1490
 	{
1402
-		if ($did_not_do)
1403
-			$did_not_do--;
1404
-		else
1491
+		if ($did_not_do) {
1492
+					$did_not_do--;
1493
+		} else
1405 1494
 		{
1406 1495
 			$upcontext['cur_file_num']++;
1407 1496
 			$upcontext['cur_file_name'] = $file[0];
@@ -1428,12 +1517,13 @@  discard block
 block discarded – undo
1428 1517
 					// Flag to move on to the next.
1429 1518
 					$upcontext['completed_step'] = true;
1430 1519
 					// Did we complete the whole file?
1431
-					if ($nextFile)
1432
-						$upcontext['current_debug_item_num'] = -1;
1520
+					if ($nextFile) {
1521
+											$upcontext['current_debug_item_num'] = -1;
1522
+					}
1433 1523
 					return upgradeExit();
1524
+				} elseif ($support_js) {
1525
+									break;
1434 1526
 				}
1435
-				elseif ($support_js)
1436
-					break;
1437 1527
 			}
1438 1528
 			// Set the progress bar to be right as if we had - even if we hadn't...
1439 1529
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1459,8 +1549,9 @@  discard block
 block discarded – undo
1459 1549
 	global $user_info, $maintenance, $smcFunc, $db_type, $txt;
1460 1550
 
1461 1551
 	// Now it's nice to have some of the basic SMF source files.
1462
-	if (!isset($_GET['ssi']) && !$command_line)
1463
-		redirectLocation('&ssi=1');
1552
+	if (!isset($_GET['ssi']) && !$command_line) {
1553
+			redirectLocation('&ssi=1');
1554
+	}
1464 1555
 
1465 1556
 	$upcontext['sub_template'] = 'upgrade_complete';
1466 1557
 	$upcontext['page_title'] = $txt['upgrade_complete'];
@@ -1476,14 +1567,16 @@  discard block
 block discarded – undo
1476 1567
 	// Are we in maintenance mode?
1477 1568
 	if (isset($upcontext['user']['main']))
1478 1569
 	{
1479
-		if ($command_line)
1480
-			echo ' * ';
1570
+		if ($command_line) {
1571
+					echo ' * ';
1572
+		}
1481 1573
 		$upcontext['removed_maintenance'] = true;
1482 1574
 		$changes['maintenance'] = $upcontext['user']['main'];
1483 1575
 	}
1484 1576
 	// Otherwise if somehow we are in 2 let's go to 1.
1485
-	elseif (!empty($maintenance) && $maintenance == 2)
1486
-		$changes['maintenance'] = 1;
1577
+	elseif (!empty($maintenance) && $maintenance == 2) {
1578
+			$changes['maintenance'] = 1;
1579
+	}
1487 1580
 
1488 1581
 	// Wipe this out...
1489 1582
 	$upcontext['user'] = array();
@@ -1498,9 +1591,9 @@  discard block
 block discarded – undo
1498 1591
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1499 1592
 
1500 1593
 	// Now is the perfect time to fetch the SM files.
1501
-	if ($command_line)
1502
-		cli_scheduled_fetchSMfiles();
1503
-	else
1594
+	if ($command_line) {
1595
+			cli_scheduled_fetchSMfiles();
1596
+	} else
1504 1597
 	{
1505 1598
 		require_once($sourcedir . '/ScheduledTasks.php');
1506 1599
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1508,8 +1601,9 @@  discard block
 block discarded – undo
1508 1601
 	}
1509 1602
 
1510 1603
 	// Log what we've done.
1511
-	if (empty($user_info['id']))
1512
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1604
+	if (empty($user_info['id'])) {
1605
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1606
+	}
1513 1607
 
1514 1608
 	// Log the action manually, so CLI still works.
1515 1609
 	$smcFunc['db_insert']('',
@@ -1528,8 +1622,9 @@  discard block
 block discarded – undo
1528 1622
 
1529 1623
 	// Save the current database version.
1530 1624
 	$server_version = $smcFunc['db_server_info']();
1531
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1532
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1625
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1626
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1627
+	}
1533 1628
 
1534 1629
 	if ($command_line)
1535 1630
 	{
@@ -1541,8 +1636,9 @@  discard block
 block discarded – undo
1541 1636
 
1542 1637
 	// Make sure it says we're done.
1543 1638
 	$upcontext['overall_percent'] = 100;
1544
-	if (isset($upcontext['step_progress']))
1545
-		unset($upcontext['step_progress']);
1639
+	if (isset($upcontext['step_progress'])) {
1640
+			unset($upcontext['step_progress']);
1641
+	}
1546 1642
 
1547 1643
 	$_GET['substep'] = 0;
1548 1644
 	return false;
@@ -1553,8 +1649,9 @@  discard block
 block discarded – undo
1553 1649
 {
1554 1650
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1555 1651
 
1556
-	if (empty($modSettings['time_format']))
1557
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1652
+	if (empty($modSettings['time_format'])) {
1653
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1654
+	}
1558 1655
 
1559 1656
 	// What files do we want to get
1560 1657
 	$request = $smcFunc['db_query']('', '
@@ -1588,8 +1685,9 @@  discard block
 block discarded – undo
1588 1685
 		$file_data = fetch_web_data($url);
1589 1686
 
1590 1687
 		// If we got an error - give up - the site might be down.
1591
-		if ($file_data === false)
1592
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1688
+		if ($file_data === false) {
1689
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1690
+		}
1593 1691
 
1594 1692
 		// Save the file to the database.
1595 1693
 		$smcFunc['db_query']('substring', '
@@ -1631,8 +1729,9 @@  discard block
 block discarded – undo
1631 1729
 	$themeData = array();
1632 1730
 	foreach ($values as $variable => $value)
1633 1731
 	{
1634
-		if (!isset($value) || $value === null)
1635
-			$value = 0;
1732
+		if (!isset($value) || $value === null) {
1733
+					$value = 0;
1734
+		}
1636 1735
 
1637 1736
 		$themeData[] = array(0, 1, $variable, $value);
1638 1737
 	}
@@ -1661,8 +1760,9 @@  discard block
 block discarded – undo
1661 1760
 
1662 1761
 	foreach ($values as $variable => $value)
1663 1762
 	{
1664
-		if (empty($modSettings[$value[0]]))
1665
-			continue;
1763
+		if (empty($modSettings[$value[0]])) {
1764
+					continue;
1765
+		}
1666 1766
 
1667 1767
 		$smcFunc['db_query']('', '
1668 1768
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1748,19 +1848,21 @@  discard block
 block discarded – undo
1748 1848
 	set_error_handler(
1749 1849
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1750 1850
 		{
1751
-			if ($support_js)
1752
-				return true;
1753
-			else
1754
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1851
+			if ($support_js) {
1852
+							return true;
1853
+			} else {
1854
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1855
+			}
1755 1856
 		}
1756 1857
 	);
1757 1858
 
1758 1859
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1759 1860
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1760
-	if ($db_type == 'mysql')
1761
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1762
-	else
1763
-		$db_collation = '';
1861
+	if ($db_type == 'mysql') {
1862
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1863
+	} else {
1864
+			$db_collation = '';
1865
+	}
1764 1866
 
1765 1867
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1766 1868
 
@@ -1772,8 +1874,9 @@  discard block
 block discarded – undo
1772 1874
 	$last_step = '';
1773 1875
 
1774 1876
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1775
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1776
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1877
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1878
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1879
+	}
1777 1880
 
1778 1881
 	// Count the total number of steps within this file - for progress.
1779 1882
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1793,15 +1896,18 @@  discard block
 block discarded – undo
1793 1896
 		$do_current = $substep >= $_GET['substep'];
1794 1897
 
1795 1898
 		// Get rid of any comments in the beginning of the line...
1796
-		if (substr(trim($line), 0, 2) === '/*')
1797
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1899
+		if (substr(trim($line), 0, 2) === '/*') {
1900
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1901
+		}
1798 1902
 
1799 1903
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1800
-		if ($is_debug && !$support_js && $command_line)
1801
-			flush();
1904
+		if ($is_debug && !$support_js && $command_line) {
1905
+					flush();
1906
+		}
1802 1907
 
1803
-		if (trim($line) === '')
1804
-			continue;
1908
+		if (trim($line) === '') {
1909
+					continue;
1910
+		}
1805 1911
 
1806 1912
 		if (trim(substr($line, 0, 3)) === '---')
1807 1913
 		{
@@ -1811,8 +1917,9 @@  discard block
 block discarded – undo
1811 1917
 			if (trim($current_data) != '' && $type !== '}')
1812 1918
 			{
1813 1919
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1814
-				if ($command_line)
1815
-					echo $upcontext['error_message'];
1920
+				if ($command_line) {
1921
+									echo $upcontext['error_message'];
1922
+				}
1816 1923
 			}
1817 1924
 
1818 1925
 			if ($type == ' ')
@@ -1830,17 +1937,18 @@  discard block
 block discarded – undo
1830 1937
 				if ($do_current)
1831 1938
 				{
1832 1939
 					$upcontext['actioned_items'][] = $last_step;
1833
-					if ($command_line)
1834
-						echo ' * ';
1940
+					if ($command_line) {
1941
+											echo ' * ';
1942
+					}
1835 1943
 				}
1836
-			}
1837
-			elseif ($type == '#')
1944
+			} elseif ($type == '#')
1838 1945
 			{
1839 1946
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1840 1947
 
1841 1948
 				$upcontext['current_debug_item_num']++;
1842
-				if (trim($line) != '---#')
1843
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1949
+				if (trim($line) != '---#') {
1950
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1951
+				}
1844 1952
 
1845 1953
 				// Have we already done something?
1846 1954
 				if (isset($_GET['xml']) && $done_something)
@@ -1851,34 +1959,36 @@  discard block
 block discarded – undo
1851 1959
 
1852 1960
 				if ($do_current)
1853 1961
 				{
1854
-					if (trim($line) == '---#' && $command_line)
1855
-						echo ' done.', $endl;
1856
-					elseif ($command_line)
1857
-						echo ' +++ ', rtrim(substr($line, 4));
1858
-					elseif (trim($line) != '---#')
1962
+					if (trim($line) == '---#' && $command_line) {
1963
+											echo ' done.', $endl;
1964
+					} elseif ($command_line) {
1965
+											echo ' +++ ', rtrim(substr($line, 4));
1966
+					} elseif (trim($line) != '---#')
1859 1967
 					{
1860
-						if ($is_debug)
1861
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1968
+						if ($is_debug) {
1969
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1970
+						}
1862 1971
 					}
1863 1972
 				}
1864 1973
 
1865 1974
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1866 1975
 				{
1867
-					if ($command_line)
1868
-						echo ' * ';
1869
-					else
1870
-						$upcontext['actioned_items'][] = $last_step;
1976
+					if ($command_line) {
1977
+											echo ' * ';
1978
+					} else {
1979
+											$upcontext['actioned_items'][] = $last_step;
1980
+					}
1871 1981
 				}
1872 1982
 
1873 1983
 				// Small step - only if we're actually doing stuff.
1874
-				if ($do_current)
1875
-					nextSubstep(++$substep);
1876
-				else
1877
-					$substep++;
1878
-			}
1879
-			elseif ($type == '{')
1880
-				$current_type = 'code';
1881
-			elseif ($type == '}')
1984
+				if ($do_current) {
1985
+									nextSubstep(++$substep);
1986
+				} else {
1987
+									$substep++;
1988
+				}
1989
+			} elseif ($type == '{') {
1990
+							$current_type = 'code';
1991
+			} elseif ($type == '}')
1882 1992
 			{
1883 1993
 				$current_type = 'sql';
1884 1994
 
@@ -1891,8 +2001,9 @@  discard block
 block discarded – undo
1891 2001
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1892 2002
 				{
1893 2003
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1894
-					if ($command_line)
1895
-						echo $upcontext['error_message'];
2004
+					if ($command_line) {
2005
+											echo $upcontext['error_message'];
2006
+					}
1896 2007
 				}
1897 2008
 
1898 2009
 				// Done with code!
@@ -1972,8 +2083,9 @@  discard block
 block discarded – undo
1972 2083
 	$db_unbuffered = false;
1973 2084
 
1974 2085
 	// Failure?!
1975
-	if ($result !== false)
1976
-		return $result;
2086
+	if ($result !== false) {
2087
+			return $result;
2088
+	}
1977 2089
 
1978 2090
 	$db_error_message = $smcFunc['db_error']($db_connection);
1979 2091
 	// If MySQL we do something more clever.
@@ -2001,54 +2113,61 @@  discard block
 block discarded – undo
2001 2113
 			{
2002 2114
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
2003 2115
 				$result = mysqli_query($db_connection, $string);
2004
-				if ($result !== false)
2005
-					return $result;
2116
+				if ($result !== false) {
2117
+									return $result;
2118
+				}
2006 2119
 			}
2007
-		}
2008
-		elseif ($mysqli_errno == 2013)
2120
+		} elseif ($mysqli_errno == 2013)
2009 2121
 		{
2010 2122
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
2011 2123
 			mysqli_select_db($db_connection, $db_name);
2012 2124
 			if ($db_connection)
2013 2125
 			{
2014 2126
 				$result = mysqli_query($db_connection, $string);
2015
-				if ($result !== false)
2016
-					return $result;
2127
+				if ($result !== false) {
2128
+									return $result;
2129
+				}
2017 2130
 			}
2018 2131
 		}
2019 2132
 		// Duplicate column name... should be okay ;).
2020
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
2021
-			return false;
2133
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2134
+					return false;
2135
+		}
2022 2136
 		// Duplicate insert... make sure it's the proper type of query ;).
2023
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
2024
-			return false;
2137
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2138
+					return false;
2139
+		}
2025 2140
 		// Creating an index on a non-existent column.
2026
-		elseif ($mysqli_errno == 1072)
2027
-			return false;
2028
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
2029
-			return false;
2141
+		elseif ($mysqli_errno == 1072) {
2142
+					return false;
2143
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2144
+					return false;
2145
+		}
2030 2146
 	}
2031 2147
 	// If a table already exists don't go potty.
2032 2148
 	else
2033 2149
 	{
2034 2150
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
2035 2151
 		{
2036
-			if (strpos($db_error_message, 'exist') !== false)
2037
-				return true;
2038
-		}
2039
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2152
+			if (strpos($db_error_message, 'exist') !== false) {
2153
+							return true;
2154
+			}
2155
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
2040 2156
 		{
2041
-			if (strpos($db_error_message, 'duplicate') !== false)
2042
-				return true;
2157
+			if (strpos($db_error_message, 'duplicate') !== false) {
2158
+							return true;
2159
+			}
2043 2160
 		}
2044 2161
 	}
2045 2162
 
2046 2163
 	// Get the query string so we pass everything.
2047 2164
 	$query_string = '';
2048
-	foreach ($_GET as $k => $v)
2049
-		$query_string .= ';' . $k . '=' . $v;
2050
-	if (strlen($query_string) != 0)
2051
-		$query_string = '?' . substr($query_string, 1);
2165
+	foreach ($_GET as $k => $v) {
2166
+			$query_string .= ';' . $k . '=' . $v;
2167
+	}
2168
+	if (strlen($query_string) != 0) {
2169
+			$query_string = '?' . substr($query_string, 1);
2170
+	}
2052 2171
 
2053 2172
 	if ($command_line)
2054 2173
 	{
@@ -2103,16 +2222,18 @@  discard block
 block discarded – undo
2103 2222
 			{
2104 2223
 				$found |= 1;
2105 2224
 				// Do some checks on the data if we have it set.
2106
-				if (isset($change['col_type']))
2107
-					$found &= $change['col_type'] === $column['type'];
2108
-				if (isset($change['null_allowed']))
2109
-					$found &= $column['null'] == $change['null_allowed'];
2110
-				if (isset($change['default']))
2111
-					$found &= $change['default'] === $column['default'];
2225
+				if (isset($change['col_type'])) {
2226
+									$found &= $change['col_type'] === $column['type'];
2227
+				}
2228
+				if (isset($change['null_allowed'])) {
2229
+									$found &= $column['null'] == $change['null_allowed'];
2230
+				}
2231
+				if (isset($change['default'])) {
2232
+									$found &= $change['default'] === $column['default'];
2233
+				}
2112 2234
 			}
2113 2235
 		}
2114
-	}
2115
-	elseif ($change['type'] === 'index')
2236
+	} elseif ($change['type'] === 'index')
2116 2237
 	{
2117 2238
 		$request = upgrade_query('
2118 2239
 			SHOW INDEX
@@ -2121,9 +2242,10 @@  discard block
 block discarded – undo
2121 2242
 		{
2122 2243
 			$cur_index = array();
2123 2244
 
2124
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2125
-				if ($row['Key_name'] === $change['name'])
2245
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2246
+							if ($row['Key_name'] === $change['name'])
2126 2247
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2248
+			}
2127 2249
 
2128 2250
 			ksort($cur_index, SORT_NUMERIC);
2129 2251
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2133,14 +2255,17 @@  discard block
 block discarded – undo
2133 2255
 	}
2134 2256
 
2135 2257
 	// If we're trying to add and it's added, we're done.
2136
-	if ($found && in_array($change['method'], array('add', 'change')))
2137
-		return true;
2258
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2259
+			return true;
2260
+	}
2138 2261
 	// Otherwise if we're removing and it wasn't found we're also done.
2139
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2140
-		return true;
2262
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2263
+			return true;
2264
+	}
2141 2265
 	// Otherwise is it just a test?
2142
-	elseif ($is_test)
2143
-		return false;
2266
+	elseif ($is_test) {
2267
+			return false;
2268
+	}
2144 2269
 
2145 2270
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2146 2271
 	$running = false;
@@ -2151,8 +2276,9 @@  discard block
 block discarded – undo
2151 2276
 			SHOW FULL PROCESSLIST');
2152 2277
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2153 2278
 		{
2154
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2155
-				$found = true;
2279
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2280
+							$found = true;
2281
+			}
2156 2282
 		}
2157 2283
 
2158 2284
 		// Can't find it? Then we need to run it fools!
@@ -2164,8 +2290,9 @@  discard block
 block discarded – undo
2164 2290
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2165 2291
 				' . $change['text'], true) !== false;
2166 2292
 
2167
-			if (!$success)
2168
-				return false;
2293
+			if (!$success) {
2294
+							return false;
2295
+			}
2169 2296
 
2170 2297
 			// Return
2171 2298
 			$running = true;
@@ -2207,8 +2334,9 @@  discard block
 block discarded – undo
2207 2334
 			'db_error_skip' => true,
2208 2335
 		)
2209 2336
 	);
2210
-	if ($smcFunc['db_num_rows']($request) === 0)
2211
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2337
+	if ($smcFunc['db_num_rows']($request) === 0) {
2338
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2339
+	}
2212 2340
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2213 2341
 	$smcFunc['db_free_result']($request);
2214 2342
 
@@ -2230,18 +2358,19 @@  discard block
 block discarded – undo
2230 2358
 			)
2231 2359
 		);
2232 2360
 		// No results? Just forget it all together.
2233
-		if ($smcFunc['db_num_rows']($request) === 0)
2234
-			unset($table_row['Collation']);
2235
-		else
2236
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2361
+		if ($smcFunc['db_num_rows']($request) === 0) {
2362
+					unset($table_row['Collation']);
2363
+		} else {
2364
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2365
+		}
2237 2366
 		$smcFunc['db_free_result']($request);
2238 2367
 	}
2239 2368
 
2240 2369
 	if ($column_fix)
2241 2370
 	{
2242 2371
 		// Make sure there are no NULL's left.
2243
-		if ($null_fix)
2244
-			$smcFunc['db_query']('', '
2372
+		if ($null_fix) {
2373
+					$smcFunc['db_query']('', '
2245 2374
 				UPDATE {db_prefix}' . $change['table'] . '
2246 2375
 				SET ' . $change['column'] . ' = {string:default}
2247 2376
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2250,6 +2379,7 @@  discard block
 block discarded – undo
2250 2379
 					'db_error_skip' => true,
2251 2380
 				)
2252 2381
 			);
2382
+		}
2253 2383
 
2254 2384
 		// Do the actual alteration.
2255 2385
 		$smcFunc['db_query']('', '
@@ -2278,8 +2408,9 @@  discard block
 block discarded – undo
2278 2408
 	}
2279 2409
 
2280 2410
 	// Not a column we need to check on?
2281
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2282
-		return;
2411
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2412
+			return;
2413
+	}
2283 2414
 
2284 2415
 	// Break it up you (six|seven).
2285 2416
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2298,13 +2429,13 @@  discard block
 block discarded – undo
2298 2429
 				'new_name' => $temp[2],
2299 2430
 		));
2300 2431
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2301
-		if ($smcFunc['db_num_rows'] != 1)
2302
-			return;
2432
+		if ($smcFunc['db_num_rows'] != 1) {
2433
+					return;
2434
+		}
2303 2435
 
2304 2436
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2305 2437
 		$smcFunc['db_free_result']($request);
2306
-	}
2307
-	else
2438
+	} else
2308 2439
 	{
2309 2440
 		// Do this the old fashion, sure method way.
2310 2441
 		$request = $smcFunc['db_query']('', '
@@ -2315,21 +2446,24 @@  discard block
 block discarded – undo
2315 2446
 		));
2316 2447
 		// Mayday!
2317 2448
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2318
-		if ($smcFunc['db_num_rows'] == 0)
2319
-			return;
2449
+		if ($smcFunc['db_num_rows'] == 0) {
2450
+					return;
2451
+		}
2320 2452
 
2321 2453
 		// Oh where, oh where has my little field gone. Oh where can it be...
2322
-		while ($row = $smcFunc['db_query']($request))
2323
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2454
+		while ($row = $smcFunc['db_query']($request)) {
2455
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2324 2456
 			{
2325 2457
 				$current_type = $row['Type'];
2458
+		}
2326 2459
 				break;
2327 2460
 			}
2328 2461
 	}
2329 2462
 
2330 2463
 	// If this doesn't match, the column may of been altered for a reason.
2331
-	if (trim($current_type) != trim($temp[3]))
2332
-		$temp[3] = $current_type;
2464
+	if (trim($current_type) != trim($temp[3])) {
2465
+			$temp[3] = $current_type;
2466
+	}
2333 2467
 
2334 2468
 	// Piece this back together.
2335 2469
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2341,8 +2475,9 @@  discard block
 block discarded – undo
2341 2475
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2342 2476
 	global $step_progress, $is_debug, $upcontext;
2343 2477
 
2344
-	if ($_GET['substep'] < $substep)
2345
-		$_GET['substep'] = $substep;
2478
+	if ($_GET['substep'] < $substep) {
2479
+			$_GET['substep'] = $substep;
2480
+	}
2346 2481
 
2347 2482
 	if ($command_line)
2348 2483
 	{
@@ -2355,29 +2490,33 @@  discard block
 block discarded – undo
2355 2490
 	}
2356 2491
 
2357 2492
 	@set_time_limit(300);
2358
-	if (function_exists('apache_reset_timeout'))
2359
-		@apache_reset_timeout();
2493
+	if (function_exists('apache_reset_timeout')) {
2494
+			@apache_reset_timeout();
2495
+	}
2360 2496
 
2361
-	if (time() - $start_time <= $timeLimitThreshold)
2362
-		return;
2497
+	if (time() - $start_time <= $timeLimitThreshold) {
2498
+			return;
2499
+	}
2363 2500
 
2364 2501
 	// Do we have some custom step progress stuff?
2365 2502
 	if (!empty($step_progress))
2366 2503
 	{
2367 2504
 		$upcontext['substep_progress'] = 0;
2368 2505
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2369
-		if ($step_progress['current'] > $step_progress['total'])
2370
-			$upcontext['substep_progress'] = 99.9;
2371
-		else
2372
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2506
+		if ($step_progress['current'] > $step_progress['total']) {
2507
+					$upcontext['substep_progress'] = 99.9;
2508
+		} else {
2509
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2510
+		}
2373 2511
 
2374 2512
 		// Make it nicely rounded.
2375 2513
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2376 2514
 	}
2377 2515
 
2378 2516
 	// If this is XML we just exit right away!
2379
-	if (isset($_GET['xml']))
2380
-		return upgradeExit();
2517
+	if (isset($_GET['xml'])) {
2518
+			return upgradeExit();
2519
+	}
2381 2520
 
2382 2521
 	// We're going to pause after this!
2383 2522
 	$upcontext['pause'] = true;
@@ -2385,13 +2524,15 @@  discard block
 block discarded – undo
2385 2524
 	$upcontext['query_string'] = '';
2386 2525
 	foreach ($_GET as $k => $v)
2387 2526
 	{
2388
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2389
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2527
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2528
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2529
+		}
2390 2530
 	}
2391 2531
 
2392 2532
 	// Custom warning?
2393
-	if (!empty($custom_warning))
2394
-		$upcontext['custom_warning'] = $custom_warning;
2533
+	if (!empty($custom_warning)) {
2534
+			$upcontext['custom_warning'] = $custom_warning;
2535
+	}
2395 2536
 
2396 2537
 	upgradeExit();
2397 2538
 }
@@ -2406,25 +2547,26 @@  discard block
 block discarded – undo
2406 2547
 	ob_implicit_flush(true);
2407 2548
 	@set_time_limit(600);
2408 2549
 
2409
-	if (!isset($_SERVER['argv']))
2410
-		$_SERVER['argv'] = array();
2550
+	if (!isset($_SERVER['argv'])) {
2551
+			$_SERVER['argv'] = array();
2552
+	}
2411 2553
 	$_GET['maint'] = 1;
2412 2554
 
2413 2555
 	foreach ($_SERVER['argv'] as $i => $arg)
2414 2556
 	{
2415
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2416
-			$_GET['lang'] = $match[1];
2417
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2418
-			continue;
2419
-		elseif ($arg == '--no-maintenance')
2420
-			$_GET['maint'] = 0;
2421
-		elseif ($arg == '--debug')
2422
-			$is_debug = true;
2423
-		elseif ($arg == '--backup')
2424
-			$_POST['backup'] = 1;
2425
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2426
-			$_GET['conv'] = 1;
2427
-		elseif ($i != 0)
2557
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2558
+					$_GET['lang'] = $match[1];
2559
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2560
+					continue;
2561
+		} elseif ($arg == '--no-maintenance') {
2562
+					$_GET['maint'] = 0;
2563
+		} elseif ($arg == '--debug') {
2564
+					$is_debug = true;
2565
+		} elseif ($arg == '--backup') {
2566
+					$_POST['backup'] = 1;
2567
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2568
+					$_GET['conv'] = 1;
2569
+		} elseif ($i != 0)
2428 2570
 		{
2429 2571
 			echo 'SMF Command-line Upgrader
2430 2572
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2438,10 +2580,12 @@  discard block
 block discarded – undo
2438 2580
 		}
2439 2581
 	}
2440 2582
 
2441
-	if (!php_version_check())
2442
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2443
-	if (!db_version_check())
2444
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2583
+	if (!php_version_check()) {
2584
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2585
+	}
2586
+	if (!db_version_check()) {
2587
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2588
+	}
2445 2589
 
2446 2590
 	// Do some checks to make sure they have proper privileges
2447 2591
 	db_extend('packages');
@@ -2456,34 +2600,39 @@  discard block
 block discarded – undo
2456 2600
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2457 2601
 
2458 2602
 	// Sorry... we need CREATE, ALTER and DROP
2459
-	if (!$create || !$alter || !$drop)
2460
-		print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2603
+	if (!$create || !$alter || !$drop) {
2604
+			print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2605
+	}
2461 2606
 
2462 2607
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2463 2608
 		&& @file_exists($sourcedir . '/QueryString.php')
2464 2609
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2465
-	if (!$check && !isset($modSettings['smfVersion']))
2466
-		print_error('Error: Some files are missing or out-of-date.', true);
2610
+	if (!$check && !isset($modSettings['smfVersion'])) {
2611
+			print_error('Error: Some files are missing or out-of-date.', true);
2612
+	}
2467 2613
 
2468 2614
 	// Do a quick version spot check.
2469 2615
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2470 2616
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2471
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2472
-		print_error('Error: Some files have not yet been updated properly.');
2617
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2618
+			print_error('Error: Some files have not yet been updated properly.');
2619
+	}
2473 2620
 
2474 2621
 	// Make sure Settings.php is writable.
2475 2622
 	quickFileWritable($boarddir . '/Settings.php');
2476
-	if (!is_writable($boarddir . '/Settings.php'))
2477
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2623
+	if (!is_writable($boarddir . '/Settings.php')) {
2624
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2625
+	}
2478 2626
 
2479 2627
 	// Make sure Settings_bak.php is writable.
2480 2628
 	quickFileWritable($boarddir . '/Settings_bak.php');
2481
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2482
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2629
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2630
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2631
+	}
2483 2632
 
2484
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2485
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2486
-	elseif (isset($modSettings['agreement']))
2633
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2634
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2635
+	} elseif (isset($modSettings['agreement']))
2487 2636
 	{
2488 2637
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2489 2638
 		fwrite($fp, $modSettings['agreement']);
@@ -2493,36 +2642,42 @@  discard block
 block discarded – undo
2493 2642
 	// Make sure Themes is writable.
2494 2643
 	quickFileWritable($modSettings['theme_dir']);
2495 2644
 
2496
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2497
-		print_error('Error: Unable to obtain write access to "Themes".');
2645
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2646
+			print_error('Error: Unable to obtain write access to "Themes".');
2647
+	}
2498 2648
 
2499 2649
 	// Make sure cache directory exists and is writable!
2500 2650
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2501
-	if (!file_exists($cachedir_temp))
2502
-		@mkdir($cachedir_temp);
2651
+	if (!file_exists($cachedir_temp)) {
2652
+			@mkdir($cachedir_temp);
2653
+	}
2503 2654
 
2504 2655
 	// Make sure the cache temp dir is writable.
2505 2656
 	quickFileWritable($cachedir_temp);
2506 2657
 
2507
-	if (!is_writable($cachedir_temp))
2508
-		print_error('Error: Unable to obtain write access to "cache".', true);
2658
+	if (!is_writable($cachedir_temp)) {
2659
+			print_error('Error: Unable to obtain write access to "cache".', true);
2660
+	}
2509 2661
 
2510 2662
 	// Make sure db_last_error.php is writable.
2511 2663
 	quickFileWritable($cachedir_temp . '/db_last_error.php');
2512
-	if (!is_writable($cachedir_temp . '/db_last_error.php'))
2513
-		print_error('Error: Unable to obtain write access to "db_last_error.php".');
2664
+	if (!is_writable($cachedir_temp . '/db_last_error.php')) {
2665
+			print_error('Error: Unable to obtain write access to "db_last_error.php".');
2666
+	}
2514 2667
 
2515
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2516
-		print_error('Error: Unable to find language files!', true);
2517
-	else
2668
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2669
+			print_error('Error: Unable to find language files!', true);
2670
+	} else
2518 2671
 	{
2519 2672
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2520 2673
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2521 2674
 
2522
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2523
-			print_error('Error: Language files out of date.', true);
2524
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2525
-			print_error('Error: Install language is missing for selected language.', true);
2675
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2676
+					print_error('Error: Language files out of date.', true);
2677
+		}
2678
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2679
+					print_error('Error: Install language is missing for selected language.', true);
2680
+		}
2526 2681
 
2527 2682
 		// Otherwise include it!
2528 2683
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2542,8 +2697,9 @@  discard block
 block discarded – undo
2542 2697
 	global $db_prefix, $db_type, $command_line, $support_js, $txt;
2543 2698
 
2544 2699
 	// Done it already?
2545
-	if (!empty($_POST['utf8_done']))
2546
-		return true;
2700
+	if (!empty($_POST['utf8_done'])) {
2701
+			return true;
2702
+	}
2547 2703
 
2548 2704
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2549 2705
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2556,8 +2712,7 @@  discard block
 block discarded – undo
2556 2712
 		);
2557 2713
 
2558 2714
 		return true;
2559
-	}
2560
-	else
2715
+	} else
2561 2716
 	{
2562 2717
 		$upcontext['page_title'] = $txt['converting_utf8'];
2563 2718
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2601,8 +2756,9 @@  discard block
 block discarded – undo
2601 2756
 			)
2602 2757
 		);
2603 2758
 		$db_charsets = array();
2604
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2605
-			$db_charsets[] = $row['Charset'];
2759
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2760
+					$db_charsets[] = $row['Charset'];
2761
+		}
2606 2762
 
2607 2763
 		$smcFunc['db_free_result']($request);
2608 2764
 
@@ -2638,13 +2794,15 @@  discard block
 block discarded – undo
2638 2794
 		// If there's a fulltext index, we need to drop it first...
2639 2795
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2640 2796
 		{
2641
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2642
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2797
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2798
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2643 2799
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2800
+			}
2644 2801
 			$smcFunc['db_free_result']($request);
2645 2802
 
2646
-			if (isset($upcontext['fulltext_index']))
2647
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2803
+			if (isset($upcontext['fulltext_index'])) {
2804
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2805
+			}
2648 2806
 		}
2649 2807
 
2650 2808
 		// Drop it and make a note...
@@ -2834,8 +2992,9 @@  discard block
 block discarded – undo
2834 2992
 			$replace = '%field%';
2835 2993
 
2836 2994
 			// Build a huge REPLACE statement...
2837
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2838
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2995
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2996
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2997
+			}
2839 2998
 		}
2840 2999
 
2841 3000
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2845,9 +3004,10 @@  discard block
 block discarded – undo
2845 3004
 		$upcontext['table_count'] = count($queryTables);
2846 3005
 
2847 3006
 		// What ones have we already done?
2848
-		foreach ($queryTables as $id => $table)
2849
-			if ($id < $_GET['substep'])
3007
+		foreach ($queryTables as $id => $table) {
3008
+					if ($id < $_GET['substep'])
2850 3009
 				$upcontext['previous_tables'][] = $table;
3010
+		}
2851 3011
 
2852 3012
 		$upcontext['cur_table_num'] = $_GET['substep'];
2853 3013
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2884,8 +3044,9 @@  discard block
 block discarded – undo
2884 3044
 			nextSubstep($substep);
2885 3045
 
2886 3046
 			// Just to make sure it doesn't time out.
2887
-			if (function_exists('apache_reset_timeout'))
2888
-				@apache_reset_timeout();
3047
+			if (function_exists('apache_reset_timeout')) {
3048
+							@apache_reset_timeout();
3049
+			}
2889 3050
 
2890 3051
 			$table_charsets = array();
2891 3052
 
@@ -2908,8 +3069,9 @@  discard block
 block discarded – undo
2908 3069
 
2909 3070
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2910 3071
 						if ($charset != 'utf8') {
2911
-							if (!isset($table_charsets[$charset]))
2912
-								$table_charsets[$charset] = array();
3072
+							if (!isset($table_charsets[$charset])) {
3073
+															$table_charsets[$charset] = array();
3074
+							}
2913 3075
 
2914 3076
 							$table_charsets[$charset][] = $column_info;
2915 3077
 						}
@@ -2950,10 +3112,11 @@  discard block
 block discarded – undo
2950 3112
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2951 3113
 				{
2952 3114
 					$update = '';
2953
-					foreach ($table_charsets as $charset => $columns)
2954
-						foreach ($columns as $column)
3115
+					foreach ($table_charsets as $charset => $columns) {
3116
+											foreach ($columns as $column)
2955 3117
 							$update .= '
2956 3118
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3119
+					}
2957 3120
 
2958 3121
 					$smcFunc['db_query']('', '
2959 3122
 						UPDATE {raw:table_name}
@@ -2978,8 +3141,9 @@  discard block
 block discarded – undo
2978 3141
 			// Now do the actual conversion (if still needed).
2979 3142
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2980 3143
 			{
2981
-				if ($command_line)
2982
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3144
+				if ($command_line) {
3145
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3146
+				}
2983 3147
 
2984 3148
 				$smcFunc['db_query']('', '
2985 3149
 					ALTER TABLE {raw:table_name}
@@ -2989,12 +3153,14 @@  discard block
 block discarded – undo
2989 3153
 					)
2990 3154
 				);
2991 3155
 
2992
-				if ($command_line)
2993
-					echo " done.\n";
3156
+				if ($command_line) {
3157
+									echo " done.\n";
3158
+				}
2994 3159
 			}
2995 3160
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2996
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
2997
-				return upgradeExit();
3161
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3162
+							return upgradeExit();
3163
+			}
2998 3164
 		}
2999 3165
 
3000 3166
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -3023,8 +3189,8 @@  discard block
 block discarded – undo
3023 3189
 		);
3024 3190
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3025 3191
 		{
3026
-			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1)
3027
-				$smcFunc['db_query']('', '
3192
+			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) {
3193
+							$smcFunc['db_query']('', '
3028 3194
 					UPDATE {db_prefix}log_actions
3029 3195
 					SET extra = {string:extra}
3030 3196
 					WHERE id_action = {int:current_action}',
@@ -3033,6 +3199,7 @@  discard block
 block discarded – undo
3033 3199
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
3034 3200
 					)
3035 3201
 				);
3202
+			}
3036 3203
 		}
3037 3204
 		$smcFunc['db_free_result']($request);
3038 3205
 
@@ -3054,15 +3221,17 @@  discard block
 block discarded – undo
3054 3221
 	// First thing's first - did we already do this?
3055 3222
 	if (!empty($modSettings['json_done']))
3056 3223
 	{
3057
-		if ($command_line)
3058
-			return DeleteUpgrade();
3059
-		else
3060
-			return true;
3224
+		if ($command_line) {
3225
+					return DeleteUpgrade();
3226
+		} else {
3227
+					return true;
3228
+		}
3061 3229
 	}
3062 3230
 
3063 3231
 	// Done it already - js wise?
3064
-	if (!empty($_POST['json_done']))
3065
-		return true;
3232
+	if (!empty($_POST['json_done'])) {
3233
+			return true;
3234
+	}
3066 3235
 
3067 3236
 	// List of tables affected by this function
3068 3237
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3094,12 +3263,14 @@  discard block
 block discarded – undo
3094 3263
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3095 3264
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3096 3265
 
3097
-	foreach ($keys as $id => $table)
3098
-		if ($id < $_GET['substep'])
3266
+	foreach ($keys as $id => $table) {
3267
+			if ($id < $_GET['substep'])
3099 3268
 			$upcontext['previous_tables'][] = $table;
3269
+	}
3100 3270
 
3101
-	if ($command_line)
3102
-		echo 'Converting data from serialize() to json_encode().';
3271
+	if ($command_line) {
3272
+			echo 'Converting data from serialize() to json_encode().';
3273
+	}
3103 3274
 
3104 3275
 	if (!$support_js || isset($_GET['xml']))
3105 3276
 	{
@@ -3139,8 +3310,9 @@  discard block
 block discarded – undo
3139 3310
 
3140 3311
 				// Loop through and fix these...
3141 3312
 				$new_settings = array();
3142
-				if ($command_line)
3143
-					echo "\n" . 'Fixing some settings...';
3313
+				if ($command_line) {
3314
+									echo "\n" . 'Fixing some settings...';
3315
+				}
3144 3316
 
3145 3317
 				foreach ($serialized_settings as $var)
3146 3318
 				{
@@ -3148,22 +3320,24 @@  discard block
 block discarded – undo
3148 3320
 					{
3149 3321
 						// Attempt to unserialize the setting
3150 3322
 						$temp = @safe_unserialize($modSettings[$var]);
3151
-						if (!$temp && $command_line)
3152
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3153
-						elseif ($temp !== false)
3154
-							$new_settings[$var] = json_encode($temp);
3323
+						if (!$temp && $command_line) {
3324
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3325
+						} elseif ($temp !== false) {
3326
+													$new_settings[$var] = json_encode($temp);
3327
+						}
3155 3328
 					}
3156 3329
 				}
3157 3330
 
3158 3331
 				// Update everything at once
3159
-				if (!function_exists('cache_put_data'))
3160
-					require_once($sourcedir . '/Load.php');
3332
+				if (!function_exists('cache_put_data')) {
3333
+									require_once($sourcedir . '/Load.php');
3334
+				}
3161 3335
 				updateSettings($new_settings, true);
3162 3336
 
3163
-				if ($command_line)
3164
-					echo ' done.';
3165
-			}
3166
-			elseif ($table == 'themes')
3337
+				if ($command_line) {
3338
+									echo ' done.';
3339
+				}
3340
+			} elseif ($table == 'themes')
3167 3341
 			{
3168 3342
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3169 3343
 				$query = $smcFunc['db_query']('', '
@@ -3182,10 +3356,11 @@  discard block
 block discarded – undo
3182 3356
 
3183 3357
 						if ($command_line)
3184 3358
 						{
3185
-							if ($temp === false)
3186
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3187
-							else
3188
-								echo "\n" . 'Fixing admin preferences...';
3359
+							if ($temp === false) {
3360
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3361
+							} else {
3362
+															echo "\n" . 'Fixing admin preferences...';
3363
+							}
3189 3364
 						}
3190 3365
 
3191 3366
 						if ($temp !== false)
@@ -3207,15 +3382,15 @@  discard block
 block discarded – undo
3207 3382
 								)
3208 3383
 							);
3209 3384
 
3210
-							if ($command_line)
3211
-								echo ' done.';
3385
+							if ($command_line) {
3386
+															echo ' done.';
3387
+							}
3212 3388
 						}
3213 3389
 					}
3214 3390
 
3215 3391
 					$smcFunc['db_free_result']($query);
3216 3392
 				}
3217
-			}
3218
-			else
3393
+			} else
3219 3394
 			{
3220 3395
 				// First item is always the key...
3221 3396
 				$key = $info[0];
@@ -3226,8 +3401,7 @@  discard block
 block discarded – undo
3226 3401
 				{
3227 3402
 					$col_select = $info[1];
3228 3403
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3229
-				}
3230
-				else
3404
+				} else
3231 3405
 				{
3232 3406
 					$col_select = implode(', ', $info);
3233 3407
 				}
@@ -3260,8 +3434,7 @@  discard block
 block discarded – undo
3260 3434
 								if ($temp === false && $command_line)
3261 3435
 								{
3262 3436
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3263
-								}
3264
-								else
3437
+								} else
3265 3438
 								{
3266 3439
 									$row[$col] = json_encode($temp);
3267 3440
 
@@ -3286,16 +3459,18 @@  discard block
 block discarded – undo
3286 3459
 						}
3287 3460
 					}
3288 3461
 
3289
-					if ($command_line)
3290
-						echo ' done.';
3462
+					if ($command_line) {
3463
+											echo ' done.';
3464
+					}
3291 3465
 
3292 3466
 					// Free up some memory...
3293 3467
 					$smcFunc['db_free_result']($query);
3294 3468
 				}
3295 3469
 			}
3296 3470
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3297
-			if (isset($_GET['xml']))
3298
-				return upgradeExit();
3471
+			if (isset($_GET['xml'])) {
3472
+							return upgradeExit();
3473
+			}
3299 3474
 		}
3300 3475
 
3301 3476
 		if ($command_line)
@@ -3310,8 +3485,9 @@  discard block
 block discarded – undo
3310 3485
 
3311 3486
 		$_GET['substep'] = 0;
3312 3487
 		// Make sure we move on!
3313
-		if ($command_line)
3314
-			return DeleteUpgrade();
3488
+		if ($command_line) {
3489
+					return DeleteUpgrade();
3490
+		}
3315 3491
 
3316 3492
 		return true;
3317 3493
 	}
@@ -3368,14 +3544,16 @@  discard block
 block discarded – undo
3368 3544
 	global $upcontext, $txt, $settings;
3369 3545
 
3370 3546
 	// Don't call me twice!
3371
-	if (!empty($upcontext['chmod_called']))
3372
-		return;
3547
+	if (!empty($upcontext['chmod_called'])) {
3548
+			return;
3549
+	}
3373 3550
 
3374 3551
 	$upcontext['chmod_called'] = true;
3375 3552
 
3376 3553
 	// Nothing?
3377
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3378
-		return;
3554
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3555
+			return;
3556
+	}
3379 3557
 
3380 3558
 	// Was it a problem with Windows?
3381 3559
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3407,11 +3585,12 @@  discard block
 block discarded – undo
3407 3585
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\');
3408 3586
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3409 3587
 
3410
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3411
-		echo '
3588
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3589
+			echo '
3412 3590
 					content.write(\'<hr>\n\t\t\t\');
3413 3591
 					content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\');
3414 3592
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3593
+	}
3415 3594
 
3416 3595
 	echo '
3417 3596
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3419,17 +3598,19 @@  discard block
 block discarded – undo
3419 3598
 				}
3420 3599
 			</script>';
3421 3600
 
3422
-	if (!empty($upcontext['chmod']['ftp_error']))
3423
-		echo '
3601
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3602
+			echo '
3424 3603
 			<div class="error_message red">
3425 3604
 				', $txt['upgrade_ftp_error'], '<br><br>
3426 3605
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3427 3606
 			</div>
3428 3607
 			<br>';
3608
+	}
3429 3609
 
3430
-	if (empty($upcontext['chmod_in_form']))
3431
-		echo '
3610
+	if (empty($upcontext['chmod_in_form'])) {
3611
+			echo '
3432 3612
 	<form action="', $upcontext['form_url'], '" method="post">';
3613
+	}
3433 3614
 
3434 3615
 	echo '
3435 3616
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3464,10 +3645,11 @@  discard block
 block discarded – undo
3464 3645
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button"></div>
3465 3646
 	</div>';
3466 3647
 
3467
-	if (empty($upcontext['chmod_in_form']))
3468
-		echo '
3648
+	if (empty($upcontext['chmod_in_form'])) {
3649
+			echo '
3469 3650
 	</form>';
3470
-}
3651
+	}
3652
+	}
3471 3653
 
3472 3654
 function template_upgrade_above()
3473 3655
 {
@@ -3527,9 +3709,10 @@  discard block
 block discarded – undo
3527 3709
 				<h2>', $txt['upgrade_progress'], '</h2>
3528 3710
 				<ul>';
3529 3711
 
3530
-	foreach ($upcontext['steps'] as $num => $step)
3531
-		echo '
3712
+	foreach ($upcontext['steps'] as $num => $step) {
3713
+			echo '
3532 3714
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3715
+	}
3533 3716
 
3534 3717
 	echo '
3535 3718
 					</ul>
@@ -3542,8 +3725,8 @@  discard block
 block discarded – undo
3542 3725
 				</div>
3543 3726
 			</div>';
3544 3727
 
3545
-	if (isset($upcontext['step_progress']))
3546
-		echo '
3728
+	if (isset($upcontext['step_progress'])) {
3729
+			echo '
3547 3730
 				<br>
3548 3731
 				<br>
3549 3732
 				<div id="progress_bar_step">
@@ -3552,6 +3735,7 @@  discard block
 block discarded – undo
3552 3735
 						<span>', $txt['upgrade_step_progress'], '</span>
3553 3736
 					</div>
3554 3737
 				</div>';
3738
+	}
3555 3739
 
3556 3740
 	echo '
3557 3741
 				<div id="substep_bar_div" class="smalltext" style="float: left;width: 50%;margin-top: 0.6em;display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div>
@@ -3582,32 +3766,36 @@  discard block
 block discarded – undo
3582 3766
 {
3583 3767
 	global $upcontext, $txt;
3584 3768
 
3585
-	if (!empty($upcontext['pause']))
3586
-		echo '
3769
+	if (!empty($upcontext['pause'])) {
3770
+			echo '
3587 3771
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3588 3772
 
3589 3773
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3590 3774
 								<h3>
3591 3775
 									', $txt['upgrade_paused_overload'], '
3592 3776
 								</h3>';
3777
+	}
3593 3778
 
3594
-	if (!empty($upcontext['custom_warning']))
3595
-		echo '
3779
+	if (!empty($upcontext['custom_warning'])) {
3780
+			echo '
3596 3781
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3597 3782
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3598 3783
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3599 3784
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3600 3785
 								</div>';
3786
+	}
3601 3787
 
3602 3788
 	echo '
3603 3789
 								<div class="righttext" style="margin: 1ex;">';
3604 3790
 
3605
-	if (!empty($upcontext['continue']))
3606
-		echo '
3791
+	if (!empty($upcontext['continue'])) {
3792
+			echo '
3607 3793
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">';
3608
-	if (!empty($upcontext['skip']))
3609
-		echo '
3794
+	}
3795
+	if (!empty($upcontext['skip'])) {
3796
+			echo '
3610 3797
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">';
3798
+	}
3611 3799
 
3612 3800
 	echo '
3613 3801
 								</div>
@@ -3657,11 +3845,12 @@  discard block
 block discarded – undo
3657 3845
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3658 3846
 	<smf>';
3659 3847
 
3660
-	if (!empty($upcontext['get_data']))
3661
-		foreach ($upcontext['get_data'] as $k => $v)
3848
+	if (!empty($upcontext['get_data'])) {
3849
+			foreach ($upcontext['get_data'] as $k => $v)
3662 3850
 			echo '
3663 3851
 		<get key="', $k, '">', $v, '</get>';
3664
-}
3852
+	}
3853
+	}
3665 3854
 
3666 3855
 function template_xml_below()
3667 3856
 {
@@ -3702,8 +3891,8 @@  discard block
 block discarded – undo
3702 3891
 	template_chmod();
3703 3892
 
3704 3893
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3705
-	if ($upcontext['is_large_forum'])
3706
-		echo '
3894
+	if ($upcontext['is_large_forum']) {
3895
+			echo '
3707 3896
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3708 3897
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3709 3898
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3711,10 +3900,11 @@  discard block
 block discarded – undo
3711 3900
 				', $txt['upgrade_warning_lots_data'], '
3712 3901
 			</div>
3713 3902
 		</div>';
3903
+	}
3714 3904
 
3715 3905
 	// A warning message?
3716
-	if (!empty($upcontext['warning']))
3717
-		echo '
3906
+	if (!empty($upcontext['warning'])) {
3907
+			echo '
3718 3908
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3719 3909
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3720 3910
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3722,6 +3912,7 @@  discard block
 block discarded – undo
3722 3912
 				', $upcontext['warning'], '
3723 3913
 			</div>
3724 3914
 		</div>';
3915
+	}
3725 3916
 
3726 3917
 	// Paths are incorrect?
3727 3918
 	echo '
@@ -3737,20 +3928,22 @@  discard block
 block discarded – undo
3737 3928
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3738 3929
 	{
3739 3930
 		$ago = time() - $upcontext['started'];
3740
-		if ($ago < 60)
3741
-			$ago = $ago . ' seconds';
3742
-		elseif ($ago < 3600)
3743
-			$ago = (int) ($ago / 60) . ' minutes';
3744
-		else
3745
-			$ago = (int) ($ago / 3600) . ' hours';
3931
+		if ($ago < 60) {
3932
+					$ago = $ago . ' seconds';
3933
+		} elseif ($ago < 3600) {
3934
+					$ago = (int) ($ago / 60) . ' minutes';
3935
+		} else {
3936
+					$ago = (int) ($ago / 3600) . ' hours';
3937
+		}
3746 3938
 
3747 3939
 		$active = time() - $upcontext['updated'];
3748
-		if ($active < 60)
3749
-			$updated = $active . ' seconds';
3750
-		elseif ($active < 3600)
3751
-			$updated = (int) ($active / 60) . ' minutes';
3752
-		else
3753
-			$updated = (int) ($active / 3600) . ' hours';
3940
+		if ($active < 60) {
3941
+					$updated = $active . ' seconds';
3942
+		} elseif ($active < 3600) {
3943
+					$updated = (int) ($active / 60) . ' minutes';
3944
+		} else {
3945
+					$updated = (int) ($active / 3600) . ' hours';
3946
+		}
3754 3947
 
3755 3948
 		echo '
3756 3949
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3759,16 +3952,18 @@  discard block
 block discarded – undo
3759 3952
 			<div style="padding-left: 6ex;">
3760 3953
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3761 3954
 
3762
-		if ($active < 600)
3763
-			echo '
3955
+		if ($active < 600) {
3956
+					echo '
3764 3957
 				', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '';
3958
+		}
3765 3959
 
3766
-		if ($active > $upcontext['inactive_timeout'])
3767
-			echo '
3960
+		if ($active > $upcontext['inactive_timeout']) {
3961
+					echo '
3768 3962
 				<br><br>',$txt['upgrade_run'], '';
3769
-		else
3770
-			echo '
3963
+		} else {
3964
+					echo '
3771 3965
 				<br><br>', $txt['upgrade_script_timeout'], ' ', $upcontext['user']['name'], ' ', $txt['upgrade_script_timeout2'], ' ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3966
+		}
3772 3967
 
3773 3968
 		echo '
3774 3969
 			</div>
@@ -3784,9 +3979,10 @@  discard block
 block discarded – undo
3784 3979
 					<td>
3785 3980
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>';
3786 3981
 
3787
-	if (!empty($upcontext['username_incorrect']))
3788
-		echo '
3982
+	if (!empty($upcontext['username_incorrect'])) {
3983
+			echo '
3789 3984
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_username'], '</div>';
3985
+	}
3790 3986
 
3791 3987
 	echo '
3792 3988
 					</td>
@@ -3797,9 +3993,10 @@  discard block
 block discarded – undo
3797 3993
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '>
3798 3994
 						<input type="hidden" name="hash_passwrd" value="">';
3799 3995
 
3800
-	if (!empty($upcontext['password_failed']))
3801
-		echo '
3996
+	if (!empty($upcontext['password_failed'])) {
3997
+			echo '
3802 3998
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_password'], '</div>';
3999
+	}
3803 4000
 
3804 4001
 	echo '
3805 4002
 					</td>
@@ -3870,8 +4067,8 @@  discard block
 block discarded – undo
3870 4067
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3871 4068
 
3872 4069
 	// Warning message?
3873
-	if (!empty($upcontext['upgrade_options_warning']))
3874
-		echo '
4070
+	if (!empty($upcontext['upgrade_options_warning'])) {
4071
+			echo '
3875 4072
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3876 4073
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3877 4074
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3879,6 +4076,7 @@  discard block
 block discarded – undo
3879 4076
 				', $upcontext['upgrade_options_warning'], '
3880 4077
 			</div>
3881 4078
 		</div>';
4079
+	}
3882 4080
 
3883 4081
 	echo '
3884 4082
 				<table>
@@ -3921,8 +4119,8 @@  discard block
 block discarded – undo
3921 4119
 						</td>
3922 4120
 					</tr>';
3923 4121
 
3924
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3925
-		echo '
4122
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4123
+			echo '
3926 4124
 					<tr valign="top">
3927 4125
 						<td width="2%">
3928 4126
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1">
@@ -3931,6 +4129,7 @@  discard block
 block discarded – undo
3931 4129
 							<label for="delete_karma">', $txt['upgrade_delete_karma'], '</label>
3932 4130
 						</td>
3933 4131
 					</tr>';
4132
+	}
3934 4133
 
3935 4134
 	echo '
3936 4135
 					<tr valign="top">
@@ -3968,10 +4167,11 @@  discard block
 block discarded – undo
3968 4167
 			</div>';
3969 4168
 
3970 4169
 	// Dont any tables so far?
3971
-	if (!empty($upcontext['previous_tables']))
3972
-		foreach ($upcontext['previous_tables'] as $table)
4170
+	if (!empty($upcontext['previous_tables'])) {
4171
+			foreach ($upcontext['previous_tables'] as $table)
3973 4172
 			echo '
3974 4173
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4174
+	}
3975 4175
 
3976 4176
 	echo '
3977 4177
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -4008,12 +4208,13 @@  discard block
 block discarded – undo
4008 4208
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4009 4209
 
4010 4210
 		// If debug flood the screen.
4011
-		if ($is_debug)
4012
-			echo '
4211
+		if ($is_debug) {
4212
+					echo '
4013 4213
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4014 4214
 
4015 4215
 				if (document.getElementById(\'debug_section\').scrollHeight)
4016 4216
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4217
+		}
4017 4218
 
4018 4219
 		echo '
4019 4220
 				// Get the next update...
@@ -4046,8 +4247,9 @@  discard block
 block discarded – undo
4046 4247
 {
4047 4248
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold, $txt;
4048 4249
 
4049
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
4050
-		$is_debug = true;
4250
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4251
+			$is_debug = true;
4252
+	}
4051 4253
 
4052 4254
 	echo '
4053 4255
 		<h3>', $txt['upgrade_db_changes'], '</h3>
@@ -4062,8 +4264,9 @@  discard block
 block discarded – undo
4062 4264
 	{
4063 4265
 		foreach ($upcontext['actioned_items'] as $num => $item)
4064 4266
 		{
4065
-			if ($num != 0)
4066
-				echo ' Successful!';
4267
+			if ($num != 0) {
4268
+							echo ' Successful!';
4269
+			}
4067 4270
 			echo '<br>' . $item;
4068 4271
 		}
4069 4272
 		if (!empty($upcontext['changes_complete']))
@@ -4076,28 +4279,32 @@  discard block
 block discarded – undo
4076 4279
 				$seconds = intval($active % 60);
4077 4280
 
4078 4281
 				$totalTime = '';
4079
-				if ($hours > 0)
4080
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4081
-				if ($minutes > 0)
4082
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4083
-				if ($seconds > 0)
4084
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4282
+				if ($hours > 0) {
4283
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4284
+				}
4285
+				if ($minutes > 0) {
4286
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4287
+				}
4288
+				if ($seconds > 0) {
4289
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4290
+				}
4085 4291
 			}
4086 4292
 
4087
-			if ($is_debug && !empty($totalTime))
4088
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
4089
-			else
4090
-				echo ' Successful!<br><br>';
4293
+			if ($is_debug && !empty($totalTime)) {
4294
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4295
+			} else {
4296
+							echo ' Successful!<br><br>';
4297
+			}
4091 4298
 
4092 4299
 			echo '<span id="commess" style="font-weight: bold;">', $txt['upgrade_db_complete'], '</span><br>';
4093 4300
 		}
4094
-	}
4095
-	else
4301
+	} else
4096 4302
 	{
4097 4303
 		// Tell them how many files we have in total.
4098
-		if ($upcontext['file_count'] > 1)
4099
-			echo '
4304
+		if ($upcontext['file_count'] > 1) {
4305
+					echo '
4100 4306
 		<strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4307
+		}
4101 4308
 
4102 4309
 		echo '
4103 4310
 		<h3 id="info2"><strong>', $txt['upgrade_executing'], '</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> ', $txt['upgrade_of'], ' <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -4113,19 +4320,23 @@  discard block
 block discarded – undo
4113 4320
 				$seconds = intval($active % 60);
4114 4321
 
4115 4322
 				$totalTime = '';
4116
-				if ($hours > 0)
4117
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4118
-				if ($minutes > 0)
4119
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4120
-				if ($seconds > 0)
4121
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4323
+				if ($hours > 0) {
4324
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4325
+				}
4326
+				if ($minutes > 0) {
4327
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4328
+				}
4329
+				if ($seconds > 0) {
4330
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4331
+				}
4122 4332
 			}
4123 4333
 
4124 4334
 			echo '
4125 4335
 			<br><span id="upgradeCompleted">';
4126 4336
 
4127
-			if (!empty($totalTime))
4128
-				echo 'Completed in ', $totalTime, '<br>';
4337
+			if (!empty($totalTime)) {
4338
+							echo 'Completed in ', $totalTime, '<br>';
4339
+			}
4129 4340
 
4130 4341
 			echo '</span>
4131 4342
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -4162,9 +4373,10 @@  discard block
 block discarded – undo
4162 4373
 			var getData = "";
4163 4374
 			var debugItems = ', $upcontext['debug_items'], ';';
4164 4375
 
4165
-		if ($is_debug)
4166
-			echo '
4376
+		if ($is_debug) {
4377
+					echo '
4167 4378
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4379
+		}
4168 4380
 
4169 4381
 		echo '
4170 4382
 			function getNextItem()
@@ -4204,9 +4416,10 @@  discard block
 block discarded – undo
4204 4416
 						document.getElementById("error_block").style.display = "";
4205 4417
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4206 4418
 
4207
-	if ($is_debug)
4208
-		echo '
4419
+	if ($is_debug) {
4420
+			echo '
4209 4421
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4422
+	}
4210 4423
 
4211 4424
 	echo '
4212 4425
 					}
@@ -4227,9 +4440,10 @@  discard block
 block discarded – undo
4227 4440
 						document.getElementById("error_block").style.display = "";
4228 4441
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4229 4442
 
4230
-	if ($is_debug)
4231
-		echo '
4443
+	if ($is_debug) {
4444
+			echo '
4232 4445
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4446
+	}
4233 4447
 
4234 4448
 	echo '
4235 4449
 					}
@@ -4288,8 +4502,8 @@  discard block
 block discarded – undo
4288 4502
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4289 4503
 				{';
4290 4504
 
4291
-		if ($is_debug)
4292
-			echo '
4505
+		if ($is_debug) {
4506
+					echo '
4293 4507
 					document.getElementById(\'debug_section\').style.display = "none";
4294 4508
 
4295 4509
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4307,6 +4521,7 @@  discard block
 block discarded – undo
4307 4521
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4308 4522
 
4309 4523
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4524
+		}
4310 4525
 
4311 4526
 		echo '
4312 4527
 
@@ -4314,9 +4529,10 @@  discard block
 block discarded – undo
4314 4529
 					document.getElementById(\'contbutt\').disabled = 0;
4315 4530
 					document.getElementById(\'database_done\').value = 1;';
4316 4531
 
4317
-		if ($upcontext['file_count'] > 1)
4318
-			echo '
4532
+		if ($upcontext['file_count'] > 1) {
4533
+					echo '
4319 4534
 					document.getElementById(\'info1\').style.display = "none";';
4535
+		}
4320 4536
 
4321 4537
 		echo '
4322 4538
 					document.getElementById(\'info2\').style.display = "none";
@@ -4329,9 +4545,10 @@  discard block
 block discarded – undo
4329 4545
 					lastItem = 0;
4330 4546
 					prevFile = curFile;';
4331 4547
 
4332
-		if ($is_debug)
4333
-			echo '
4548
+		if ($is_debug) {
4549
+					echo '
4334 4550
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4551
+		}
4335 4552
 
4336 4553
 		echo '
4337 4554
 					getNextItem();
@@ -4339,8 +4556,8 @@  discard block
 block discarded – undo
4339 4556
 				}';
4340 4557
 
4341 4558
 		// If debug scroll the screen.
4342
-		if ($is_debug)
4343
-			echo '
4559
+		if ($is_debug) {
4560
+					echo '
4344 4561
 				if (iLastSubStepProgress == -1)
4345 4562
 				{
4346 4563
 					// Give it consistent dots.
@@ -4359,6 +4576,7 @@  discard block
 block discarded – undo
4359 4576
 
4360 4577
 				if (document.getElementById(\'debug_section\').scrollHeight)
4361 4578
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4579
+		}
4362 4580
 
4363 4581
 		echo '
4364 4582
 				// Update the page.
@@ -4419,9 +4637,10 @@  discard block
 block discarded – undo
4419 4637
 			}';
4420 4638
 
4421 4639
 		// Start things off assuming we've not errored.
4422
-		if (empty($upcontext['error_message']))
4423
-			echo '
4640
+		if (empty($upcontext['error_message'])) {
4641
+					echo '
4424 4642
 			getNextItem();';
4643
+		}
4425 4644
 
4426 4645
 		echo '
4427 4646
 		//# sourceURL=dynamicScript-dbch.js
@@ -4439,18 +4658,21 @@  discard block
 block discarded – undo
4439 4658
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4440 4659
 	<debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>';
4441 4660
 
4442
-	if (!empty($upcontext['error_message']))
4443
-		echo '
4661
+	if (!empty($upcontext['error_message'])) {
4662
+			echo '
4444 4663
 	<error>', $upcontext['error_message'], '</error>';
4664
+	}
4445 4665
 
4446
-	if (!empty($upcontext['error_string']))
4447
-		echo '
4666
+	if (!empty($upcontext['error_string'])) {
4667
+			echo '
4448 4668
 	<sql>', $upcontext['error_string'], '</sql>';
4669
+	}
4449 4670
 
4450
-	if ($is_debug)
4451
-		echo '
4671
+	if ($is_debug) {
4672
+			echo '
4452 4673
 	<curtime>', time(), '</curtime>';
4453
-}
4674
+	}
4675
+	}
4454 4676
 
4455 4677
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4456 4678
 function template_convert_utf8()
@@ -4469,18 +4691,20 @@  discard block
 block discarded – undo
4469 4691
 			</div>';
4470 4692
 
4471 4693
 	// Done any tables so far?
4472
-	if (!empty($upcontext['previous_tables']))
4473
-		foreach ($upcontext['previous_tables'] as $table)
4694
+	if (!empty($upcontext['previous_tables'])) {
4695
+			foreach ($upcontext['previous_tables'] as $table)
4474 4696
 			echo '
4475 4697
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4698
+	}
4476 4699
 
4477 4700
 	echo '
4478 4701
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4479 4702
 
4480 4703
 	// If we dropped their index, let's let them know
4481
-	if ($upcontext['dropping_index'])
4482
-		echo '
4704
+	if ($upcontext['dropping_index']) {
4705
+			echo '
4483 4706
 				<br><span id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_fulltext'], '</span>';
4707
+	}
4484 4708
 
4485 4709
 	// Completion notification
4486 4710
 	echo '
@@ -4517,12 +4741,13 @@  discard block
 block discarded – undo
4517 4741
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4518 4742
 
4519 4743
 		// If debug flood the screen.
4520
-		if ($is_debug)
4521
-			echo '
4744
+		if ($is_debug) {
4745
+					echo '
4522 4746
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4523 4747
 
4524 4748
 				if (document.getElementById(\'debug_section\').scrollHeight)
4525 4749
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4750
+		}
4526 4751
 
4527 4752
 		echo '
4528 4753
 				// Get the next update...
@@ -4570,19 +4795,21 @@  discard block
 block discarded – undo
4570 4795
 			</div>';
4571 4796
 
4572 4797
 	// Dont any tables so far?
4573
-	if (!empty($upcontext['previous_tables']))
4574
-		foreach ($upcontext['previous_tables'] as $table)
4798
+	if (!empty($upcontext['previous_tables'])) {
4799
+			foreach ($upcontext['previous_tables'] as $table)
4575 4800
 			echo '
4576 4801
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4802
+	}
4577 4803
 
4578 4804
 	echo '
4579 4805
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4580 4806
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_json_completed'], '</span>';
4581 4807
 
4582 4808
 	// Try to make sure substep was reset.
4583
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4584
-		echo '
4809
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4810
+			echo '
4585 4811
 			<input type="hidden" name="substep" id="substep" value="0">';
4812
+	}
4586 4813
 
4587 4814
 	// Continue please!
4588 4815
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4615,12 +4842,13 @@  discard block
 block discarded – undo
4615 4842
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4616 4843
 
4617 4844
 		// If debug flood the screen.
4618
-		if ($is_debug)
4619
-			echo '
4845
+		if ($is_debug) {
4846
+					echo '
4620 4847
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4621 4848
 
4622 4849
 				if (document.getElementById(\'debug_section\').scrollHeight)
4623 4850
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4851
+		}
4624 4852
 
4625 4853
 		echo '
4626 4854
 				// Get the next update...
@@ -4656,8 +4884,8 @@  discard block
 block discarded – undo
4656 4884
 	<h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>.  ', $txt['upgrade_done3'], '</h3>
4657 4885
 	<form action="', $boardurl, '/index.php">';
4658 4886
 
4659
-	if (!empty($upcontext['can_delete_script']))
4660
-		echo '
4887
+	if (!empty($upcontext['can_delete_script'])) {
4888
+			echo '
4661 4889
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], '</label> <em>', $txt['upgrade_delete_server'], '</em>
4662 4890
 			<script>
4663 4891
 				function doTheDelete(theCheck)
@@ -4669,6 +4897,7 @@  discard block
 block discarded – undo
4669 4897
 				}
4670 4898
 			</script>
4671 4899
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4900
+	}
4672 4901
 
4673 4902
 	$active = time() - $upcontext['started'];
4674 4903
 	$hours = floor($active / 3600);
@@ -4678,16 +4907,20 @@  discard block
 block discarded – undo
4678 4907
 	if ($is_debug)
4679 4908
 	{
4680 4909
 		$totalTime = '';
4681
-		if ($hours > 0)
4682
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4683
-		if ($minutes > 0)
4684
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4685
-		if ($seconds > 0)
4686
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4910
+		if ($hours > 0) {
4911
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4912
+		}
4913
+		if ($minutes > 0) {
4914
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4915
+		}
4916
+		if ($seconds > 0) {
4917
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4918
+		}
4687 4919
 	}
4688 4920
 
4689
-	if ($is_debug && !empty($totalTime))
4690
-		echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4921
+	if ($is_debug && !empty($totalTime)) {
4922
+			echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4923
+	}
4691 4924
 
4692 4925
 	echo '<br>
4693 4926
 			', sprintf($txt['upgrade_problems'], 'http://simplemachines.org'), '<br>
@@ -4714,8 +4947,9 @@  discard block
 block discarded – undo
4714 4947
 
4715 4948
 	$current_substep = $_GET['substep'];
4716 4949
 
4717
-	if (empty($_GET['a']))
4718
-		$_GET['a'] = 0;
4950
+	if (empty($_GET['a'])) {
4951
+			$_GET['a'] = 0;
4952
+	}
4719 4953
 	$step_progress['name'] = 'Converting ips';
4720 4954
 	$step_progress['current'] = $_GET['a'];
4721 4955
 
@@ -4758,16 +4992,19 @@  discard block
 block discarded – undo
4758 4992
 				'empty' => '',
4759 4993
 				'limit' => $limit,
4760 4994
 		));
4761
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4762
-			$arIp[] = $row[$oldCol];
4995
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4996
+					$arIp[] = $row[$oldCol];
4997
+		}
4763 4998
 		$smcFunc['db_free_result']($request);
4764 4999
 
4765 5000
 		// Special case, null ip could keep us in a loop.
4766
-		if (is_null($arIp[0]))
4767
-			unset($arIp[0]);
5001
+		if (is_null($arIp[0])) {
5002
+					unset($arIp[0]);
5003
+		}
4768 5004
 
4769
-		if (empty($arIp))
4770
-			$is_done = true;
5005
+		if (empty($arIp)) {
5006
+					$is_done = true;
5007
+		}
4771 5008
 
4772 5009
 		$updates = array();
4773 5010
 		$cases = array();
@@ -4776,16 +5013,18 @@  discard block
 block discarded – undo
4776 5013
 		{
4777 5014
 			$arIp[$i] = trim($arIp[$i]);
4778 5015
 
4779
-			if (empty($arIp[$i]))
4780
-				continue;
5016
+			if (empty($arIp[$i])) {
5017
+							continue;
5018
+			}
4781 5019
 
4782 5020
 			$updates['ip' . $i] = $arIp[$i];
4783 5021
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4784 5022
 
4785 5023
 			if ($setSize > 0 && $i % $setSize === 0)
4786 5024
 			{
4787
-				if (count($updates) == 1)
4788
-					continue;
5025
+				if (count($updates) == 1) {
5026
+									continue;
5027
+				}
4789 5028
 
4790 5029
 				$updates['whereSet'] = array_values($updates);
4791 5030
 				$smcFunc['db_query']('', '
@@ -4819,8 +5058,7 @@  discard block
 block discarded – undo
4819 5058
 							'ip' => $ip
4820 5059
 					));
4821 5060
 				}
4822
-			}
4823
-			else
5061
+			} else
4824 5062
 			{
4825 5063
 				$updates['whereSet'] = array_values($updates);
4826 5064
 				$smcFunc['db_query']('', '
@@ -4834,9 +5072,9 @@  discard block
 block discarded – undo
4834 5072
 					$updates
4835 5073
 				);
4836 5074
 			}
5075
+		} else {
5076
+					$is_done = true;
4837 5077
 		}
4838
-		else
4839
-			$is_done = true;
4840 5078
 
4841 5079
 		$_GET['a'] += $limit;
4842 5080
 		$step_progress['current'] = $_GET['a'];
@@ -4862,10 +5100,11 @@  discard block
 block discarded – undo
4862 5100
 
4863 5101
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4864 5102
 
4865
-	if (isset($columns[$column]))
4866
-		return $columns[$column];
4867
-	else
4868
-		return null;
4869
-}
5103
+	if (isset($columns[$column])) {
5104
+			return $columns[$column];
5105
+	} else {
5106
+			return null;
5107
+	}
5108
+	}
4870 5109
 
4871 5110
 ?>
4872 5111
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Auth.php 1 patch
Braces   +165 added lines, -119 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Sets the SMF-style login cookie and session based on the id_member and password passed.
@@ -47,8 +48,9 @@  discard block
 block discarded – undo
47 48
 	if (isset($_COOKIE[$cookiename]))
48 49
 	{
49 50
 		// First check for 2.1 json-format cookie
50
-		if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1)
51
-			list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
51
+		if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1) {
52
+					list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
53
+		}
52 54
 
53 55
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
54 56
 		elseif (preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;(i:3;i:\d;)?~', $_COOKIE[$cookiename]) === 1)
@@ -58,15 +60,17 @@  discard block
 block discarded – undo
58 60
 			$cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2);
59 61
 
60 62
 			// Maybe we need to temporarily pretend to be using local cookies
61
-			if ($cookie_state == 0 && $old_state == 1)
62
-				list($old_domain, $old_path) = url_parts(true, false);
63
-			else
64
-				list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0);
63
+			if ($cookie_state == 0 && $old_state == 1) {
64
+							list($old_domain, $old_path) = url_parts(true, false);
65
+			} else {
66
+							list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0);
67
+			}
65 68
 		}
66 69
 
67 70
 		// Out with the old, in with the new!
68
-		if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1])
69
-			smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain);
71
+		if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1]) {
72
+					smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain);
73
+		}
70 74
 	}
71 75
 
72 76
 	// Get the data and path to set it on.
@@ -82,8 +86,9 @@  discard block
 block discarded – undo
82 86
 	smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], $cookie_url[0]);
83 87
 
84 88
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
85
-	if (empty($id) && !empty($modSettings['globalCookies']))
86
-		smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], '');
89
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
90
+			smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], '');
91
+	}
87 92
 
88 93
 	// Any alias URLs?  This is mainly for use with frames, etc.
89 94
 	if (!empty($modSettings['forum_alias_urls']))
@@ -99,8 +104,9 @@  discard block
 block discarded – undo
99 104
 
100 105
 			$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
101 106
 
102
-			if ($cookie_url[0] == '')
103
-				$cookie_url[0] = strtok($alias, '/');
107
+			if ($cookie_url[0] == '') {
108
+							$cookie_url[0] = strtok($alias, '/');
109
+			}
104 110
 
105 111
 			$alias_data = $smcFunc['json_decode']($data, true);
106 112
 			$alias_data[3] = $cookie_url[0];
@@ -159,8 +165,9 @@  discard block
 block discarded – undo
159 165
 	smf_setcookie($identifier, $data, $expiry_time, $cookie_url[1], $cookie_url[0]);
160 166
 
161 167
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
162
-	if (empty($id) && !empty($modSettings['globalCookies']))
163
-		smf_setcookie($identifier, $data, $expiry_time, $cookie_url[1], '');
168
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
169
+			smf_setcookie($identifier, $data, $expiry_time, $cookie_url[1], '');
170
+	}
164 171
 
165 172
 	$_COOKIE[$identifier] = $data;
166 173
 }
@@ -182,23 +189,28 @@  discard block
 block discarded – undo
182 189
 	$parsed_url = parse_url($boardurl);
183 190
 
184 191
 	// Is local cookies off?
185
-	if (empty($parsed_url['path']) || !$local)
186
-		$parsed_url['path'] = '';
192
+	if (empty($parsed_url['path']) || !$local) {
193
+			$parsed_url['path'] = '';
194
+	}
187 195
 
188
-	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false)
189
-		$parsed_url['host'] = $modSettings['globalCookiesDomain'];
196
+	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) {
197
+			$parsed_url['host'] = $modSettings['globalCookiesDomain'];
198
+	}
190 199
 
191 200
 	// Globalize cookies across domains (filter out IP-addresses)?
192
-	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
193
-		$parsed_url['host'] = '.' . $parts[1];
201
+	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
202
+			$parsed_url['host'] = '.' . $parts[1];
203
+	}
194 204
 
195 205
 	// We shouldn't use a host at all if both options are off.
196
-	elseif (!$local && !$global)
197
-		$parsed_url['host'] = '';
206
+	elseif (!$local && !$global) {
207
+			$parsed_url['host'] = '';
208
+	}
198 209
 
199 210
 	// The host also shouldn't be set if there aren't any dots in it.
200
-	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false)
201
-		$parsed_url['host'] = '';
211
+	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) {
212
+			$parsed_url['host'] = '';
213
+	}
202 214
 
203 215
 	return array($parsed_url['host'], $parsed_url['path'] . '/');
204 216
 }
@@ -217,8 +229,9 @@  discard block
 block discarded – undo
217 229
 	createToken('login');
218 230
 
219 231
 	// Never redirect to an attachment
220
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
221
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
232
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
233
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
234
+	}
222 235
 
223 236
 	$context['sub_template'] = 'kick_guest';
224 237
 	$context['page_title'] = $txt['login'];
@@ -273,10 +286,12 @@  discard block
 block discarded – undo
273 286
 		$txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']);
274 287
 		log_error($txt['security_wrong'], 'critical');
275 288
 
276
-		if (isset($_POST[$type . '_hash_pass']))
277
-			unset($_POST[$type . '_hash_pass']);
278
-		if (isset($_POST[$type . '_pass']))
279
-			unset($_POST[$type . '_pass']);
289
+		if (isset($_POST[$type . '_hash_pass'])) {
290
+					unset($_POST[$type . '_hash_pass']);
291
+		}
292
+		if (isset($_POST[$type . '_pass'])) {
293
+					unset($_POST[$type . '_pass']);
294
+		}
280 295
 
281 296
 		$context['incorrect_password'] = true;
282 297
 	}
@@ -289,15 +304,17 @@  discard block
 block discarded – undo
289 304
 
290 305
 	// Now go through $_POST.  Make sure the session hash is sent.
291 306
 	$_POST[$context['session_var']] = $context['session_id'];
292
-	foreach ($_POST as $k => $v)
293
-		$context['post_data'] .= adminLogin_outputPostVars($k, $v);
307
+	foreach ($_POST as $k => $v) {
308
+			$context['post_data'] .= adminLogin_outputPostVars($k, $v);
309
+	}
294 310
 
295 311
 	// Now we'll use the admin_login sub template of the Login template.
296 312
 	$context['sub_template'] = 'admin_login';
297 313
 
298 314
 	// And title the page something like "Login".
299
-	if (!isset($context['page_title']))
300
-		$context['page_title'] = $txt['login'];
315
+	if (!isset($context['page_title'])) {
316
+			$context['page_title'] = $txt['login'];
317
+	}
301 318
 
302 319
 	// The type of action.
303 320
 	$context['sessionCheckType'] = $type;
@@ -320,14 +337,15 @@  discard block
 block discarded – undo
320 337
 {
321 338
 	global $smcFunc;
322 339
 
323
-	if (!is_array($v))
324
-		return '
340
+	if (!is_array($v)) {
341
+			return '
325 342
 <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '&quot;', '<' => '&lt;', '>' => '&gt;')) . '">';
326
-	else
343
+	} else
327 344
 	{
328 345
 		$ret = '';
329
-		foreach ($v as $k2 => $v2)
330
-			$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
346
+		foreach ($v as $k2 => $v2) {
347
+					$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
348
+		}
331 349
 
332 350
 		return $ret;
333 351
 	}
@@ -354,18 +372,20 @@  discard block
 block discarded – undo
354 372
 		foreach ($get as $k => $v)
355 373
 		{
356 374
 			// Only if it's not already in the $scripturl!
357
-			if (!isset($temp[$k]))
358
-				$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
375
+			if (!isset($temp[$k])) {
376
+							$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
377
+			}
359 378
 			// If it changed, put it out there, but with an ampersand.
360
-			elseif ($temp[$k] != $get[$k])
361
-				$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
379
+			elseif ($temp[$k] != $get[$k]) {
380
+							$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
381
+			}
362 382
 		}
363
-	}
364
-	else
383
+	} else
365 384
 	{
366 385
 		// Add up all the data from $_GET into get_data.
367
-		foreach ($get as $k => $v)
368
-			$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
386
+		foreach ($get as $k => $v) {
387
+					$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
388
+		}
369 389
 	}
370 390
 
371 391
 	$query_string = substr($query_string, 0, -1);
@@ -388,8 +408,9 @@  discard block
 block discarded – undo
388 408
 	global $scripturl, $user_info, $smcFunc;
389 409
 
390 410
 	// If it's not already an array, make it one.
391
-	if (!is_array($names))
392
-		$names = explode(',', $names);
411
+	if (!is_array($names)) {
412
+			$names = explode(',', $names);
413
+	}
393 414
 
394 415
 	$maybe_email = false;
395 416
 	$names_list = array();
@@ -401,10 +422,11 @@  discard block
 block discarded – undo
401 422
 		$maybe_email |= strpos($name, '@') !== false;
402 423
 
403 424
 		// Make it so standard wildcards will work. (* and ?)
404
-		if ($use_wildcards)
405
-			$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
406
-		else
407
-			$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
425
+		if ($use_wildcards) {
426
+					$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
427
+		} else {
428
+					$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
429
+		}
408 430
 
409 431
 		$names_list[] = '{string:lookup_name_' . $i . '}';
410 432
 		$where_params['lookup_name_' . $i] = $names[$i];
@@ -417,11 +439,12 @@  discard block
 block discarded – undo
417 439
 	$results = array();
418 440
 
419 441
 	// This ensures you can't search someones email address if you can't see it.
420
-	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum'))
421
-		$email_condition = '
442
+	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) {
443
+			$email_condition = '
422 444
 			OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
423
-	else
424
-		$email_condition = '';
445
+	} else {
446
+			$email_condition = '';
447
+	}
425 448
 
426 449
 	// Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise.
427 450
 	$member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name';
@@ -480,10 +503,11 @@  discard block
 block discarded – undo
480 503
 	$context['template_layers'] = array();
481 504
 	$context['sub_template'] = 'find_members';
482 505
 
483
-	if (isset($_REQUEST['search']))
484
-		$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
485
-	else
486
-		$_REQUEST['start'] = 0;
506
+	if (isset($_REQUEST['search'])) {
507
+			$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
508
+	} else {
509
+			$_REQUEST['start'] = 0;
510
+	}
487 511
 
488 512
 	// Allow the user to pass the input to be added to to the box.
489 513
 	$context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to';
@@ -524,10 +548,10 @@  discard block
 block discarded – undo
524 548
 		);
525 549
 
526 550
 		$context['results'] = array_slice($context['results'], $_REQUEST['start'], 7);
551
+	} else {
552
+			$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
553
+	}
527 554
 	}
528
-	else
529
-		$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
530
-}
531 555
 
532 556
 /**
533 557
  * Outputs each member name on its own line.
@@ -543,8 +567,9 @@  discard block
 block discarded – undo
543 567
 	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search']));
544 568
 	$_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;'));
545 569
 
546
-	if (function_exists('iconv'))
547
-		header('content-type: text/plain; charset=UTF-8');
570
+	if (function_exists('iconv')) {
571
+			header('content-type: text/plain; charset=UTF-8');
572
+	}
548 573
 
549 574
 	$request = $smcFunc['db_query']('', '
550 575
 		SELECT real_name
@@ -564,14 +589,16 @@  discard block
 block discarded – undo
564 589
 		if (function_exists('iconv'))
565 590
 		{
566 591
 			$utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']);
567
-			if ($utf8)
568
-				$row['real_name'] = $utf8;
592
+			if ($utf8) {
593
+							$row['real_name'] = $utf8;
594
+			}
569 595
 		}
570 596
 
571 597
 		$row['real_name'] = strtr($row['real_name'], array('&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;'));
572 598
 
573
-		if (preg_match('~&#\d+;~', $row['real_name']) != 0)
574
-			$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
599
+		if (preg_match('~&#\d+;~', $row['real_name']) != 0) {
600
+					$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
601
+		}
575 602
 
576 603
 		echo $row['real_name'], "\n";
577 604
 	}
@@ -628,9 +655,9 @@  discard block
 block discarded – undo
628 655
 
629 656
 		// Update the database...
630 657
 		updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1));
658
+	} else {
659
+			updateMemberData($memID, array('passwd' => $newPassword_sha1));
631 660
 	}
632
-	else
633
-		updateMemberData($memID, array('passwd' => $newPassword_sha1));
634 661
 
635 662
 	call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword));
636 663
 
@@ -661,31 +688,37 @@  discard block
 block discarded – undo
661 688
 	$errors = array();
662 689
 
663 690
 	// Don't use too long a name.
664
-	if ($smcFunc['strlen']($username) > 25)
665
-		$errors[] = array('lang', 'error_long_name');
691
+	if ($smcFunc['strlen']($username) > 25) {
692
+			$errors[] = array('lang', 'error_long_name');
693
+	}
666 694
 
667 695
 	// No name?!  How can you register with no name?
668
-	if ($username == '')
669
-		$errors[] = array('lang', 'need_username');
696
+	if ($username == '') {
697
+			$errors[] = array('lang', 'need_username');
698
+	}
670 699
 
671 700
 	// Only these characters are permitted.
672
-	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false)
673
-		$errors[] = array('lang', 'error_invalid_characters_username');
701
+	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) {
702
+			$errors[] = array('lang', 'error_invalid_characters_username');
703
+	}
674 704
 
675
-	if (stristr($username, $txt['guest_title']) !== false)
676
-		$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
705
+	if (stristr($username, $txt['guest_title']) !== false) {
706
+			$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
707
+	}
677 708
 
678 709
 	if ($check_reserved_name)
679 710
 	{
680 711
 		require_once($sourcedir . '/Subs-Members.php');
681
-		if (isReservedName($username, $memID, false))
682
-			$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
712
+		if (isReservedName($username, $memID, false)) {
713
+					$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
714
+		}
683 715
 	}
684 716
 
685
-	if ($return_error)
686
-		return $errors;
687
-	elseif (empty($errors))
688
-		return null;
717
+	if ($return_error) {
718
+			return $errors;
719
+	} elseif (empty($errors)) {
720
+			return null;
721
+	}
689 722
 
690 723
 	loadLanguage('Errors');
691 724
 	$error = $errors[0];
@@ -711,22 +744,26 @@  discard block
 block discarded – undo
711 744
 	global $modSettings, $smcFunc;
712 745
 
713 746
 	// Perform basic requirements first.
714
-	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8))
715
-		return 'short';
747
+	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) {
748
+			return 'short';
749
+	}
716 750
 
717 751
 	// Is this enough?
718
-	if (empty($modSettings['password_strength']))
719
-		return null;
752
+	if (empty($modSettings['password_strength'])) {
753
+			return null;
754
+	}
720 755
 
721 756
 	// Otherwise, perform the medium strength test - checking if password appears in the restricted string.
722
-	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0)
723
-		return 'restricted_words';
724
-	elseif ($smcFunc['strpos']($password, $username) !== false)
725
-		return 'restricted_words';
757
+	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) {
758
+			return 'restricted_words';
759
+	} elseif ($smcFunc['strpos']($password, $username) !== false) {
760
+			return 'restricted_words';
761
+	}
726 762
 
727 763
 	// If just medium, we're done.
728
-	if ($modSettings['password_strength'] == 1)
729
-		return null;
764
+	if ($modSettings['password_strength'] == 1) {
765
+			return null;
766
+	}
730 767
 
731 768
 	// Otherwise, hard test next, check for numbers and letters, uppercase too.
732 769
 	$good = preg_match('~(\D\d|\d\D)~', $password) != 0;
@@ -758,14 +795,16 @@  discard block
 block discarded – undo
758 795
 			)
759 796
 		);
760 797
 		$groups = array();
761
-		while ($row = $smcFunc['db_fetch_assoc']($request))
762
-			$groups[] = $row['id_group'];
798
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
799
+					$groups[] = $row['id_group'];
800
+		}
763 801
 		$smcFunc['db_free_result']($request);
764 802
 
765
-		if (empty($groups))
766
-			$group_query = '0=1';
767
-		else
768
-			$group_query = 'id_group IN (' . implode(',', $groups) . ')';
803
+		if (empty($groups)) {
804
+					$group_query = '0=1';
805
+		} else {
806
+					$group_query = 'id_group IN (' . implode(',', $groups) . ')';
807
+		}
769 808
 	}
770 809
 
771 810
 	// Then, same again, just the boards this time!
@@ -775,10 +814,11 @@  discard block
 block discarded – undo
775 814
 	{
776 815
 		$boards = boardsAllowedTo('moderate_board', true);
777 816
 
778
-		if (empty($boards))
779
-			$board_query = '0=1';
780
-		else
781
-			$board_query = 'id_board IN (' . implode(',', $boards) . ')';
817
+		if (empty($boards)) {
818
+					$board_query = '0=1';
819
+		} else {
820
+					$board_query = 'id_board IN (' . implode(',', $boards) . ')';
821
+		}
782 822
 	}
783 823
 
784 824
 	// What boards are they the moderator of?
@@ -793,8 +833,9 @@  discard block
 block discarded – undo
793 833
 				'current_member' => $user_info['id'],
794 834
 			)
795 835
 		);
796
-		while ($row = $smcFunc['db_fetch_assoc']($request))
797
-			$boards_mod[] = $row['id_board'];
836
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
837
+					$boards_mod[] = $row['id_board'];
838
+		}
798 839
 		$smcFunc['db_free_result']($request);
799 840
 
800 841
 		// Can any of the groups they're in moderate any of the boards?
@@ -806,8 +847,9 @@  discard block
 block discarded – undo
806 847
 				'groups' => $user_info['groups'],
807 848
 			)
808 849
 		);
809
-		while ($row = $smcFunc['db_fetch_assoc']($request))
810
-			$boards_mod[] = $row['id_board'];
850
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
851
+					$boards_mod[] = $row['id_board'];
852
+		}
811 853
 		$smcFunc['db_free_result']($request);
812 854
 
813 855
 		// Just in case we've got duplicates here...
@@ -852,10 +894,12 @@  discard block
 block discarded – undo
852 894
 	global $modSettings;
853 895
 
854 896
 	// In case a customization wants to override the default settings
855
-	if ($httponly === null)
856
-		$httponly = !empty($modSettings['httponlyCookies']);
857
-	if ($secure === null)
858
-		$secure = !empty($modSettings['secureCookies']);
897
+	if ($httponly === null) {
898
+			$httponly = !empty($modSettings['httponlyCookies']);
899
+	}
900
+	if ($secure === null) {
901
+			$secure = !empty($modSettings['secureCookies']);
902
+	}
859 903
 
860 904
 	// Intercept cookie?
861 905
 	call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly));
@@ -875,8 +919,9 @@  discard block
 block discarded – undo
875 919
 function hash_password($username, $password, $cost = null)
876 920
 {
877 921
 	global $sourcedir, $smcFunc, $modSettings;
878
-	if (!function_exists('password_hash'))
879
-		require_once($sourcedir . '/Subs-Password.php');
922
+	if (!function_exists('password_hash')) {
923
+			require_once($sourcedir . '/Subs-Password.php');
924
+	}
880 925
 
881 926
 	$cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost;
882 927
 
@@ -908,8 +953,9 @@  discard block
 block discarded – undo
908 953
 function hash_verify_password($username, $password, $hash)
909 954
 {
910 955
 	global $sourcedir, $smcFunc;
911
-	if (!function_exists('password_verify'))
912
-		require_once($sourcedir . '/Subs-Password.php');
956
+	if (!function_exists('password_verify')) {
957
+			require_once($sourcedir . '/Subs-Password.php');
958
+	}
913 959
 
914 960
 	return password_verify($smcFunc['strtolower']($username) . $password, $hash);
915 961
 }
Please login to merge, or discard this patch.
Sources/Subs.php 1 patch
Braces   +1368 added lines, -1014 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,23 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($var == 'alerts' && ($val === '+' || $val === '-'))
@@ -385,18 +394,17 @@  discard block
 block discarded – undo
385 394
 			if (is_array($members))
386 395
 			{
387 396
 				$val = 'CASE ';
388
-				foreach ($members as $k => $v)
389
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
397
+				foreach ($members as $k => $v) {
398
+									$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
399
+				}
390 400
 				$val = $val . ' END';
391 401
 				$type = 'raw';
392
-			}
393
-			else
402
+			} else
394 403
 			{
395 404
 				$blub = fetch_alerts($members, false, 0, array(), false);
396 405
 				$val = count($blub);
397 406
 			}
398
-		}
399
-		else if ($type == 'int' && ($val === '+' || $val === '-'))
407
+		} else if ($type == 'int' && ($val === '+' || $val === '-'))
400 408
 		{
401 409
 			$val = $var . ' ' . $val . ' 1';
402 410
 			$type = 'raw';
@@ -407,8 +415,9 @@  discard block
 block discarded – undo
407 415
 		{
408 416
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
409 417
 			{
410
-				if ($match[1] != '+ ')
411
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
418
+				if ($match[1] != '+ ') {
419
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
420
+				}
412 421
 				$type = 'raw';
413 422
 			}
414 423
 		}
@@ -429,8 +438,9 @@  discard block
 block discarded – undo
429 438
 	// Clear any caching?
430 439
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
431 440
 	{
432
-		if (!is_array($members))
433
-			$members = array($members);
441
+		if (!is_array($members)) {
442
+					$members = array($members);
443
+		}
434 444
 
435 445
 		foreach ($members as $member)
436 446
 		{
@@ -463,29 +473,32 @@  discard block
 block discarded – undo
463 473
 {
464 474
 	global $modSettings, $smcFunc;
465 475
 
466
-	if (empty($changeArray) || !is_array($changeArray))
467
-		return;
476
+	if (empty($changeArray) || !is_array($changeArray)) {
477
+			return;
478
+	}
468 479
 
469 480
 	$toRemove = array();
470 481
 
471 482
 	// Go check if there is any setting to be removed.
472
-	foreach ($changeArray as $k => $v)
473
-		if ($v === null)
483
+	foreach ($changeArray as $k => $v) {
484
+			if ($v === null)
474 485
 		{
475 486
 			// Found some, remove them from the original array and add them to ours.
476 487
 			unset($changeArray[$k]);
488
+	}
477 489
 			$toRemove[] = $k;
478 490
 		}
479 491
 
480 492
 	// Proceed with the deletion.
481
-	if (!empty($toRemove))
482
-		$smcFunc['db_query']('', '
493
+	if (!empty($toRemove)) {
494
+			$smcFunc['db_query']('', '
483 495
 			DELETE FROM {db_prefix}settings
484 496
 			WHERE variable IN ({array_string:remove})',
485 497
 			array(
486 498
 				'remove' => $toRemove,
487 499
 			)
488 500
 		);
501
+	}
489 502
 
490 503
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
491 504
 	if ($update)
@@ -514,19 +527,22 @@  discard block
 block discarded – undo
514 527
 	foreach ($changeArray as $variable => $value)
515 528
 	{
516 529
 		// Don't bother if it's already like that ;).
517
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
518
-			continue;
530
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
531
+					continue;
532
+		}
519 533
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
520
-		elseif (!isset($modSettings[$variable]) && empty($value))
521
-			continue;
534
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
535
+					continue;
536
+		}
522 537
 
523 538
 		$replaceArray[] = array($variable, $value);
524 539
 
525 540
 		$modSettings[$variable] = $value;
526 541
 	}
527 542
 
528
-	if (empty($replaceArray))
529
-		return;
543
+	if (empty($replaceArray)) {
544
+			return;
545
+	}
530 546
 
531 547
 	$smcFunc['db_insert']('replace',
532 548
 		'{db_prefix}settings',
@@ -572,14 +588,17 @@  discard block
 block discarded – undo
572 588
 	$start_invalid = $start < 0;
573 589
 
574 590
 	// Make sure $start is a proper variable - not less than 0.
575
-	if ($start_invalid)
576
-		$start = 0;
591
+	if ($start_invalid) {
592
+			$start = 0;
593
+	}
577 594
 	// Not greater than the upper bound.
578
-	elseif ($start >= $max_value)
579
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
595
+	elseif ($start >= $max_value) {
596
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
597
+	}
580 598
 	// And it has to be a multiple of $num_per_page!
581
-	else
582
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
599
+	else {
600
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
601
+	}
583 602
 
584 603
 	$context['current_page'] = $start / $num_per_page;
585 604
 
@@ -609,77 +628,87 @@  discard block
 block discarded – undo
609 628
 
610 629
 		// Show all the pages.
611 630
 		$display_page = 1;
612
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
613
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
631
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
632
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
633
+		}
614 634
 
615 635
 		// Show the right arrow.
616 636
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
617
-		if ($start != $counter - $max_value && !$start_invalid)
618
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
619
-	}
620
-	else
637
+		if ($start != $counter - $max_value && !$start_invalid) {
638
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
639
+		}
640
+	} else
621 641
 	{
622 642
 		// If they didn't enter an odd value, pretend they did.
623 643
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
624 644
 
625 645
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
626
-		if (!empty($start) && $show_prevnext)
627
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
628
-		else
629
-			$pageindex .= '';
646
+		if (!empty($start) && $show_prevnext) {
647
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
648
+		} else {
649
+					$pageindex .= '';
650
+		}
630 651
 
631 652
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
632
-		if ($start > $num_per_page * $PageContiguous)
633
-			$pageindex .= sprintf($base_link, 0, '1');
653
+		if ($start > $num_per_page * $PageContiguous) {
654
+					$pageindex .= sprintf($base_link, 0, '1');
655
+		}
634 656
 
635 657
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
636
-		if ($start > $num_per_page * ($PageContiguous + 1))
637
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
658
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
659
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
638 660
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
639 661
 				'{FIRST_PAGE}' => $num_per_page,
640 662
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
641 663
 				'{PER_PAGE}' => $num_per_page,
642 664
 			));
665
+		}
643 666
 
644 667
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
645
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
646
-			if ($start >= $num_per_page * $nCont)
668
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
669
+					if ($start >= $num_per_page * $nCont)
647 670
 			{
648 671
 				$tmpStart = $start - $num_per_page * $nCont;
672
+		}
649 673
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
650 674
 			}
651 675
 
652 676
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
653
-		if (!$start_invalid)
654
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
655
-		else
656
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
677
+		if (!$start_invalid) {
678
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
679
+		} else {
680
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
681
+		}
657 682
 
658 683
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
659 684
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
660
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
661
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
685
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
686
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
662 687
 			{
663 688
 				$tmpStart = $start + $num_per_page * $nCont;
689
+		}
664 690
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
665 691
 			}
666 692
 
667 693
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
668
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
669
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
694
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
695
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
670 696
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
671 697
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
672 698
 				'{LAST_PAGE}' => $tmpMaxPages,
673 699
 				'{PER_PAGE}' => $num_per_page,
674 700
 			));
701
+		}
675 702
 
676 703
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
677
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
678
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
704
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
705
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
706
+		}
679 707
 
680 708
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
681
-		if ($start != $tmpMaxPages && $show_prevnext)
682
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
709
+		if ($start != $tmpMaxPages && $show_prevnext) {
710
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
711
+		}
683 712
 	}
684 713
 	$pageindex .= $settings['page_index']['extra_after'];
685 714
 
@@ -705,8 +734,9 @@  discard block
 block discarded – undo
705 734
 	if ($decimal_separator === null)
706 735
 	{
707 736
 		// Not set for whatever reason?
708
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
709
-			return $number;
737
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
738
+					return $number;
739
+		}
710 740
 
711 741
 		// Cache these each load...
712 742
 		$thousands_separator = $matches[1];
@@ -740,17 +770,20 @@  discard block
 block discarded – undo
740 770
 	static $unsupportedFormats, $finalizedFormats;
741 771
 
742 772
 	// Offset the time.
743
-	if (!$offset_type)
744
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
773
+	if (!$offset_type) {
774
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
775
+	}
745 776
 	// Just the forum offset?
746
-	elseif ($offset_type == 'forum')
747
-		$time = $log_time + $modSettings['time_offset'] * 3600;
748
-	else
749
-		$time = $log_time;
777
+	elseif ($offset_type == 'forum') {
778
+			$time = $log_time + $modSettings['time_offset'] * 3600;
779
+	} else {
780
+			$time = $log_time;
781
+	}
750 782
 
751 783
 	// We can't have a negative date (on Windows, at least.)
752
-	if ($log_time < 0)
753
-		$log_time = 0;
784
+	if ($log_time < 0) {
785
+			$log_time = 0;
786
+	}
754 787
 
755 788
 	// Today and Yesterday?
756 789
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -767,24 +800,27 @@  discard block
 block discarded – undo
767 800
 		{
768 801
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
769 802
 			$today_fmt = $h . ':%M' . $s . ' %p';
803
+		} else {
804
+					$today_fmt = '%H:%M' . $s;
770 805
 		}
771
-		else
772
-			$today_fmt = '%H:%M' . $s;
773 806
 
774 807
 		// Same day of the year, same year.... Today!
775
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
776
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
808
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
809
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
810
+		}
777 811
 
778 812
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
779
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
780
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
813
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
814
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
815
+		}
781 816
 	}
782 817
 
783 818
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
784 819
 
785 820
 	// Use the cached formats if available
786
-	if (is_null($finalizedFormats))
787
-		$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
821
+	if (is_null($finalizedFormats)) {
822
+			$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
823
+	}
788 824
 
789 825
 	// Make a supported version for this format if we don't already have one
790 826
 	if (empty($finalizedFormats[$str]))
@@ -813,8 +849,9 @@  discard block
 block discarded – undo
813 849
 		);
814 850
 
815 851
 		// No need to do this part again if we already did it once
816
-		if (is_null($unsupportedFormats))
817
-			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
852
+		if (is_null($unsupportedFormats)) {
853
+					$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
854
+		}
818 855
 		if (empty($unsupportedFormats))
819 856
 		{
820 857
 			foreach($strftimeFormatSubstitutions as $format => $substitution)
@@ -823,20 +860,23 @@  discard block
 block discarded – undo
823 860
 
824 861
 				// Windows will return false for unsupported formats
825 862
 				// Other operating systems return the format string as a literal
826
-				if ($value === false || $value === $format)
827
-					$unsupportedFormats[] = $format;
863
+				if ($value === false || $value === $format) {
864
+									$unsupportedFormats[] = $format;
865
+				}
828 866
 			}
829 867
 			cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400);
830 868
 		}
831 869
 
832 870
 		// Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q'
833
-		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
834
-			$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
871
+		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
872
+					$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
873
+		}
835 874
 
836 875
 		// Substitute unsupported formats with supported ones
837
-		if (!empty($unsupportedFormats))
838
-			while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
876
+		if (!empty($unsupportedFormats)) {
877
+					while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
839 878
 				$timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat);
879
+		}
840 880
 
841 881
 		// Remember this so we don't need to do it again
842 882
 		$finalizedFormats[$str] = $timeformat;
@@ -845,33 +885,39 @@  discard block
 block discarded – undo
845 885
 
846 886
 	$str = $finalizedFormats[$str];
847 887
 
848
-	if (!isset($locale_cache))
849
-		$locale_cache = setlocale(LC_TIME, $txt['lang_locale']);
888
+	if (!isset($locale_cache)) {
889
+			$locale_cache = setlocale(LC_TIME, $txt['lang_locale']);
890
+	}
850 891
 
851 892
 	if ($locale_cache !== false)
852 893
 	{
853 894
 		// Check if another process changed the locale
854
-		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache)
855
-			setlocale(LC_TIME, $txt['lang_locale']);
895
+		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) {
896
+					setlocale(LC_TIME, $txt['lang_locale']);
897
+		}
856 898
 
857
-		if (!isset($non_twelve_hour))
858
-			$non_twelve_hour = trim(strftime('%p')) === '';
859
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
860
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
899
+		if (!isset($non_twelve_hour)) {
900
+					$non_twelve_hour = trim(strftime('%p')) === '';
901
+		}
902
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
903
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
904
+		}
861 905
 
862
-		foreach (array('%a', '%A', '%b', '%B') as $token)
863
-			if (strpos($str, $token) !== false)
906
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
907
+					if (strpos($str, $token) !== false)
864 908
 				$str = str_replace($token, strftime($token, $time), $str);
865
-	}
866
-	else
909
+		}
910
+	} else
867 911
 	{
868 912
 		// Do-it-yourself time localization.  Fun.
869
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
870
-			if (strpos($str, $token) !== false)
913
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
914
+					if (strpos($str, $token) !== false)
871 915
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
916
+		}
872 917
 
873
-		if (strpos($str, '%p') !== false)
874
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
918
+		if (strpos($str, '%p') !== false) {
919
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
920
+		}
875 921
 	}
876 922
 
877 923
 	// Format the time and then restore any literal percent characters
@@ -894,16 +940,19 @@  discard block
 block discarded – undo
894 940
 	static $translation = array();
895 941
 
896 942
 	// Determine the character set... Default to UTF-8
897
-	if (empty($context['character_set']))
898
-		$charset = 'UTF-8';
943
+	if (empty($context['character_set'])) {
944
+			$charset = 'UTF-8';
945
+	}
899 946
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
900
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
901
-		$charset = 'ISO-8859-1';
902
-	else
903
-		$charset = $context['character_set'];
947
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
948
+			$charset = 'ISO-8859-1';
949
+	} else {
950
+			$charset = $context['character_set'];
951
+	}
904 952
 
905
-	if (empty($translation))
906
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
953
+	if (empty($translation)) {
954
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
955
+	}
907 956
 
908 957
 	return strtr($string, $translation);
909 958
 }
@@ -925,8 +974,9 @@  discard block
 block discarded – undo
925 974
 	global $smcFunc;
926 975
 
927 976
 	// It was already short enough!
928
-	if ($smcFunc['strlen']($subject) <= $len)
929
-		return $subject;
977
+	if ($smcFunc['strlen']($subject) <= $len) {
978
+			return $subject;
979
+	}
930 980
 
931 981
 	// Shorten it by the length it was too long, and strip off junk from the end.
932 982
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -945,10 +995,11 @@  discard block
 block discarded – undo
945 995
 {
946 996
 	global $user_info, $modSettings;
947 997
 
948
-	if ($timestamp === null)
949
-		$timestamp = time();
950
-	elseif ($timestamp == 0)
951
-		return 0;
998
+	if ($timestamp === null) {
999
+			$timestamp = time();
1000
+	} elseif ($timestamp == 0) {
1001
+			return 0;
1002
+	}
952 1003
 
953 1004
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
954 1005
 }
@@ -977,8 +1028,9 @@  discard block
 block discarded – undo
977 1028
 		$array[$i] = $array[$j];
978 1029
 		$array[$j] = $temp;
979 1030
 
980
-		for ($i = 1; $p[$i] == 0; $i++)
981
-			$p[$i] = 1;
1031
+		for ($i = 1; $p[$i] == 0; $i++) {
1032
+					$p[$i] = 1;
1033
+		}
982 1034
 
983 1035
 		$orders[] = $array;
984 1036
 	}
@@ -1010,12 +1062,14 @@  discard block
 block discarded – undo
1010 1062
 	static $disabled;
1011 1063
 
1012 1064
 	// Don't waste cycles
1013
-	if ($message === '')
1014
-		return '';
1065
+	if ($message === '') {
1066
+			return '';
1067
+	}
1015 1068
 
1016 1069
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
1017
-	if (!isset($context['utf8']))
1018
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1070
+	if (!isset($context['utf8'])) {
1071
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1072
+	}
1019 1073
 
1020 1074
 	// Clean up any cut/paste issues we may have
1021 1075
 	$message = sanitizeMSCutPaste($message);
@@ -1027,13 +1081,15 @@  discard block
 block discarded – undo
1027 1081
 		return $message;
1028 1082
 	}
1029 1083
 
1030
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
1031
-		$smileys = (bool) $smileys;
1084
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1085
+			$smileys = (bool) $smileys;
1086
+	}
1032 1087
 
1033 1088
 	if (empty($modSettings['enableBBC']) && $message !== false)
1034 1089
 	{
1035
-		if ($smileys === true)
1036
-			parsesmileys($message);
1090
+		if ($smileys === true) {
1091
+					parsesmileys($message);
1092
+		}
1037 1093
 
1038 1094
 		return $message;
1039 1095
 	}
@@ -1046,8 +1102,9 @@  discard block
 block discarded – undo
1046 1102
 	}
1047 1103
 
1048 1104
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1049
-	if (!empty($modSettings['autoLinkUrls']))
1050
-		set_tld_regex();
1105
+	if (!empty($modSettings['autoLinkUrls'])) {
1106
+			set_tld_regex();
1107
+	}
1051 1108
 
1052 1109
 	// Allow mods access before entering the main parse_bbc loop
1053 1110
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1061,12 +1118,14 @@  discard block
 block discarded – undo
1061 1118
 
1062 1119
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1063 1120
 
1064
-			foreach ($temp as $tag)
1065
-				$disabled[trim($tag)] = true;
1121
+			foreach ($temp as $tag) {
1122
+							$disabled[trim($tag)] = true;
1123
+			}
1066 1124
 		}
1067 1125
 
1068
-		if (empty($modSettings['enableEmbeddedFlash']))
1069
-			$disabled['flash'] = true;
1126
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1127
+					$disabled['flash'] = true;
1128
+		}
1070 1129
 
1071 1130
 		/* The following bbc are formatted as an array, with keys as follows:
1072 1131
 
@@ -1187,8 +1246,9 @@  discard block
 block discarded – undo
1187 1246
 					$returnContext = '';
1188 1247
 
1189 1248
 					// BBC or the entire attachments feature is disabled
1190
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1191
-						return $data;
1249
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1250
+											return $data;
1251
+					}
1192 1252
 
1193 1253
 					// Save the attach ID.
1194 1254
 					$attachID = $data;
@@ -1199,8 +1259,9 @@  discard block
 block discarded – undo
1199 1259
 					$currentAttachment = parseAttachBBC($attachID);
1200 1260
 
1201 1261
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1202
-					if (is_string($currentAttachment))
1203
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1262
+					if (is_string($currentAttachment)) {
1263
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1264
+					}
1204 1265
 
1205 1266
 					if (!empty($currentAttachment['is_image']))
1206 1267
 					{
@@ -1216,15 +1277,17 @@  discard block
 block discarded – undo
1216 1277
 							$height = ' height="' . $currentAttachment['height'] . '"';
1217 1278
 						}
1218 1279
 
1219
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1220
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1221
-						else
1222
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1280
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1281
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1282
+						} else {
1283
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1284
+						}
1223 1285
 					}
1224 1286
 
1225 1287
 					// No image. Show a link.
1226
-					else
1227
-						$returnContext .= $currentAttachment['link'];
1288
+					else {
1289
+											$returnContext .= $currentAttachment['link'];
1290
+					}
1228 1291
 
1229 1292
 					// Gotta append what we just did.
1230 1293
 					$data = $returnContext;
@@ -1255,8 +1318,9 @@  discard block
 block discarded – undo
1255 1318
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1256 1319
 						{
1257 1320
 							// Do PHP code coloring?
1258
-							if ($php_parts[$php_i] != '&lt;?php')
1259
-								continue;
1321
+							if ($php_parts[$php_i] != '&lt;?php') {
1322
+															continue;
1323
+							}
1260 1324
 
1261 1325
 							$php_string = '';
1262 1326
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1272,8 +1336,9 @@  discard block
 block discarded – undo
1272 1336
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1273 1337
 
1274 1338
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1275
-						if ($context['browser']['is_opera'])
1276
-							$data .= '&nbsp;';
1339
+						if ($context['browser']['is_opera']) {
1340
+													$data .= '&nbsp;';
1341
+						}
1277 1342
 					}
1278 1343
 				},
1279 1344
 				'block_level' => true,
@@ -1292,8 +1357,9 @@  discard block
 block discarded – undo
1292 1357
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1293 1358
 						{
1294 1359
 							// Do PHP code coloring?
1295
-							if ($php_parts[$php_i] != '&lt;?php')
1296
-								continue;
1360
+							if ($php_parts[$php_i] != '&lt;?php') {
1361
+															continue;
1362
+							}
1297 1363
 
1298 1364
 							$php_string = '';
1299 1365
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1309,8 +1375,9 @@  discard block
 block discarded – undo
1309 1375
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1310 1376
 
1311 1377
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1312
-						if ($context['browser']['is_opera'])
1313
-							$data[0] .= '&nbsp;';
1378
+						if ($context['browser']['is_opera']) {
1379
+													$data[0] .= '&nbsp;';
1380
+						}
1314 1381
 					}
1315 1382
 				},
1316 1383
 				'block_level' => true,
@@ -1348,11 +1415,13 @@  discard block
 block discarded – undo
1348 1415
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1349 1416
 				'validate' => function (&$tag, &$data, $disabled)
1350 1417
 				{
1351
-					if (isset($disabled['url']))
1352
-						$tag['content'] = '$1';
1418
+					if (isset($disabled['url'])) {
1419
+											$tag['content'] = '$1';
1420
+					}
1353 1421
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1354
-					if (empty($scheme))
1355
-						$data[0] = '//' . ltrim($data[0], ':/');
1422
+					if (empty($scheme)) {
1423
+											$data[0] = '//' . ltrim($data[0], ':/');
1424
+					}
1356 1425
 				},
1357 1426
 				'disabled_content' => '<a href="$1" target="_blank" rel="noopener">$1</a>',
1358 1427
 			),
@@ -1366,10 +1435,11 @@  discard block
 block discarded – undo
1366 1435
 				{
1367 1436
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1368 1437
 
1369
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1370
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1371
-					else
1372
-						$css = '';
1438
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1439
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1440
+					} else {
1441
+											$css = '';
1442
+					}
1373 1443
 
1374 1444
 					$data = $class . $css;
1375 1445
 				},
@@ -1419,20 +1489,23 @@  discard block
 block discarded – undo
1419 1489
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1420 1490
 					if ($image_proxy_enabled)
1421 1491
 					{
1422
-						if (!empty($user_info['possibly_robot']))
1423
-							return;
1492
+						if (!empty($user_info['possibly_robot'])) {
1493
+													return;
1494
+						}
1424 1495
 
1425
-						if (empty($scheme))
1426
-							$data = 'http://' . ltrim($data, ':/');
1496
+						if (empty($scheme)) {
1497
+													$data = 'http://' . ltrim($data, ':/');
1498
+						}
1427 1499
 
1428
-						if ($scheme != 'https')
1429
-							if ($image_proxy_enabled === 2 && !empty($image_proxy_url))
1500
+						if ($scheme != 'https') {
1501
+													if ($image_proxy_enabled === 2 && !empty($image_proxy_url))
1430 1502
 								$data = $image_proxy_url . urlencode($data);
1431
-							else
1432
-								$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1503
+						} else {
1504
+															$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1505
+							}
1506
+					} elseif (empty($scheme)) {
1507
+											$data = '//' . ltrim($data, ':/');
1433 1508
 					}
1434
-					elseif (empty($scheme))
1435
-						$data = '//' . ltrim($data, ':/');
1436 1509
 				},
1437 1510
 				'disabled_content' => '($1)',
1438 1511
 			),
@@ -1448,20 +1521,23 @@  discard block
 block discarded – undo
1448 1521
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1449 1522
 					if ($image_proxy_enabled)
1450 1523
 					{
1451
-						if (!empty($user_info['possibly_robot']))
1452
-							return;
1524
+						if (!empty($user_info['possibly_robot'])) {
1525
+													return;
1526
+						}
1453 1527
 
1454
-						if (empty($scheme))
1455
-							$data = 'http://' . ltrim($data, ':/');
1528
+						if (empty($scheme)) {
1529
+													$data = 'http://' . ltrim($data, ':/');
1530
+						}
1456 1531
 
1457
-						if ($scheme != 'https')
1458
-							if ($image_proxy_enabled === 2 && !empty($image_proxy_url))
1532
+						if ($scheme != 'https') {
1533
+													if ($image_proxy_enabled === 2 && !empty($image_proxy_url))
1459 1534
 								$data = $image_proxy_url . urlencode($data);
1460
-							else
1461
-								$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1535
+						} else {
1536
+															$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1537
+							}
1538
+					} elseif (empty($scheme)) {
1539
+											$data = '//' . ltrim($data, ':/');
1462 1540
 					}
1463
-					elseif (empty($scheme))
1464
-						$data = '//' . ltrim($data, ':/');
1465 1541
 				},
1466 1542
 				'disabled_content' => '($1)',
1467 1543
 			),
@@ -1473,8 +1549,9 @@  discard block
 block discarded – undo
1473 1549
 				{
1474 1550
 					$data = strtr($data, array('<br>' => ''));
1475 1551
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1476
-					if (empty($scheme))
1477
-						$data = '//' . ltrim($data, ':/');
1552
+					if (empty($scheme)) {
1553
+											$data = '//' . ltrim($data, ':/');
1554
+					}
1478 1555
 				},
1479 1556
 			),
1480 1557
 			array(
@@ -1485,13 +1562,14 @@  discard block
 block discarded – undo
1485 1562
 				'after' => '</a>',
1486 1563
 				'validate' => function (&$tag, &$data, $disabled)
1487 1564
 				{
1488
-					if (substr($data, 0, 1) == '#')
1489
-						$data = '#post_' . substr($data, 1);
1490
-					else
1565
+					if (substr($data, 0, 1) == '#') {
1566
+											$data = '#post_' . substr($data, 1);
1567
+					} else
1491 1568
 					{
1492 1569
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1493
-						if (empty($scheme))
1494
-							$data = '//' . ltrim($data, ':/');
1570
+						if (empty($scheme)) {
1571
+													$data = '//' . ltrim($data, ':/');
1572
+						}
1495 1573
 					}
1496 1574
 				},
1497 1575
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1569,8 +1647,9 @@  discard block
 block discarded – undo
1569 1647
 					{
1570 1648
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1571 1649
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1572
-						if ($add_begin)
1573
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1650
+						if ($add_begin) {
1651
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1652
+						}
1574 1653
 					}
1575 1654
 				},
1576 1655
 				'block_level' => false,
@@ -1701,10 +1780,11 @@  discard block
 block discarded – undo
1701 1780
 				'content' => '$1',
1702 1781
 				'validate' => function (&$tag, &$data, $disabled)
1703 1782
 				{
1704
-					if (is_numeric($data))
1705
-						$data = timeformat($data);
1706
-					else
1707
-						$tag['content'] = '[time]$1[/time]';
1783
+					if (is_numeric($data)) {
1784
+											$data = timeformat($data);
1785
+					} else {
1786
+											$tag['content'] = '[time]$1[/time]';
1787
+					}
1708 1788
 				},
1709 1789
 			),
1710 1790
 			array(
@@ -1731,8 +1811,9 @@  discard block
 block discarded – undo
1731 1811
 				{
1732 1812
 					$data = strtr($data, array('<br>' => ''));
1733 1813
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1734
-					if (empty($scheme))
1735
-						$data = '//' . ltrim($data, ':/');
1814
+					if (empty($scheme)) {
1815
+											$data = '//' . ltrim($data, ':/');
1816
+					}
1736 1817
 				},
1737 1818
 			),
1738 1819
 			array(
@@ -1744,8 +1825,9 @@  discard block
 block discarded – undo
1744 1825
 				'validate' => function (&$tag, &$data, $disabled)
1745 1826
 				{
1746 1827
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1747
-					if (empty($scheme))
1748
-						$data = '//' . ltrim($data, ':/');
1828
+					if (empty($scheme)) {
1829
+											$data = '//' . ltrim($data, ':/');
1830
+					}
1749 1831
 				},
1750 1832
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1751 1833
 				'disabled_after' => ' ($1)',
@@ -1765,8 +1847,9 @@  discard block
 block discarded – undo
1765 1847
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1766 1848
 		if ($message === false)
1767 1849
 		{
1768
-			if (isset($temp_bbc))
1769
-				$bbc_codes = $temp_bbc;
1850
+			if (isset($temp_bbc)) {
1851
+							$bbc_codes = $temp_bbc;
1852
+			}
1770 1853
 			usort($codes, function ($a, $b) {
1771 1854
 				return strcmp($a['tag'], $b['tag']);
1772 1855
 			});
@@ -1786,8 +1869,9 @@  discard block
 block discarded – undo
1786 1869
 		);
1787 1870
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1788 1871
 		{
1789
-			foreach ($itemcodes as $c => $dummy)
1790
-				$bbc_codes[$c] = array();
1872
+			foreach ($itemcodes as $c => $dummy) {
1873
+							$bbc_codes[$c] = array();
1874
+			}
1791 1875
 		}
1792 1876
 
1793 1877
 		// Shhhh!
@@ -1808,12 +1892,14 @@  discard block
 block discarded – undo
1808 1892
 		foreach ($codes as $code)
1809 1893
 		{
1810 1894
 			// Make it easier to process parameters later
1811
-			if (!empty($code['parameters']))
1812
-				ksort($code['parameters'], SORT_STRING);
1895
+			if (!empty($code['parameters'])) {
1896
+							ksort($code['parameters'], SORT_STRING);
1897
+			}
1813 1898
 
1814 1899
 			// If we are not doing every tag only do ones we are interested in.
1815
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1816
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1900
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1901
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1902
+			}
1817 1903
 		}
1818 1904
 		$codes = null;
1819 1905
 	}
@@ -1824,8 +1910,9 @@  discard block
 block discarded – undo
1824 1910
 		// It's likely this will change if the message is modified.
1825 1911
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1826 1912
 
1827
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1828
-			return $temp;
1913
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1914
+					return $temp;
1915
+		}
1829 1916
 
1830 1917
 		$cache_t = microtime();
1831 1918
 	}
@@ -1857,8 +1944,9 @@  discard block
 block discarded – undo
1857 1944
 		$disabled['flash'] = true;
1858 1945
 
1859 1946
 		// @todo Change maybe?
1860
-		if (!isset($_GET['images']))
1861
-			$disabled['img'] = true;
1947
+		if (!isset($_GET['images'])) {
1948
+					$disabled['img'] = true;
1949
+		}
1862 1950
 
1863 1951
 		// @todo Interface/setting to add more?
1864 1952
 	}
@@ -1882,8 +1970,9 @@  discard block
 block discarded – undo
1882 1970
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1883 1971
 
1884 1972
 		// Failsafe.
1885
-		if ($pos === false || $last_pos > $pos)
1886
-			$pos = strlen($message) + 1;
1973
+		if ($pos === false || $last_pos > $pos) {
1974
+					$pos = strlen($message) + 1;
1975
+		}
1887 1976
 
1888 1977
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1889 1978
 		if ($last_pos < $pos - 1)
@@ -1901,8 +1990,9 @@  discard block
 block discarded – undo
1901 1990
 
1902 1991
 				// <br> should be empty.
1903 1992
 				$empty_tags = array('br', 'hr');
1904
-				foreach ($empty_tags as $tag)
1905
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
1993
+				foreach ($empty_tags as $tag) {
1994
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
1995
+				}
1906 1996
 
1907 1997
 				// b, u, i, s, pre... basic tags.
1908 1998
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong');
@@ -1911,8 +2001,9 @@  discard block
 block discarded – undo
1911 2001
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1912 2002
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1913 2003
 
1914
-					if ($diff > 0)
1915
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2004
+					if ($diff > 0) {
2005
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2006
+					}
1916 2007
 				}
1917 2008
 
1918 2009
 				// Do <img ...> - with security... action= -> action-.
@@ -1925,8 +2016,9 @@  discard block
 block discarded – undo
1925 2016
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1926 2017
 
1927 2018
 						// Remove action= from the URL - no funny business, now.
1928
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1929
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2019
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
2020
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2021
+						}
1930 2022
 
1931 2023
 						// Check if the image is larger than allowed.
1932 2024
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1947,9 +2039,9 @@  discard block
 block discarded – undo
1947 2039
 
1948 2040
 							// Set the new image tag.
1949 2041
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
2042
+						} else {
2043
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1950 2044
 						}
1951
-						else
1952
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1953 2045
 					}
1954 2046
 
1955 2047
 					$data = strtr($data, $replaces);
@@ -1962,16 +2054,18 @@  discard block
 block discarded – undo
1962 2054
 				$no_autolink_area = false;
1963 2055
 				if (!empty($open_tags))
1964 2056
 				{
1965
-					foreach ($open_tags as $open_tag)
1966
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2057
+					foreach ($open_tags as $open_tag) {
2058
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1967 2059
 							$no_autolink_area = true;
2060
+					}
1968 2061
 				}
1969 2062
 
1970 2063
 				// Don't go backwards.
1971 2064
 				// @todo Don't think is the real solution....
1972 2065
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1973
-				if ($pos < $lastAutoPos)
1974
-					$no_autolink_area = true;
2066
+				if ($pos < $lastAutoPos) {
2067
+									$no_autolink_area = true;
2068
+				}
1975 2069
 				$lastAutoPos = $pos;
1976 2070
 
1977 2071
 				if (!$no_autolink_area)
@@ -2080,17 +2174,19 @@  discard block
 block discarded – undo
2080 2174
 							if ($scheme == 'mailto')
2081 2175
 							{
2082 2176
 								$email_address = str_replace('mailto:', '', $url);
2083
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2084
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2085
-								else
2086
-									return $url;
2177
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2178
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2179
+								} else {
2180
+																	return $url;
2181
+								}
2087 2182
 							}
2088 2183
 
2089 2184
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2090
-							if (empty($scheme))
2091
-								$fullUrl = '//' . ltrim($url, ':/');
2092
-							else
2093
-								$fullUrl = $url;
2185
+							if (empty($scheme)) {
2186
+															$fullUrl = '//' . ltrim($url, ':/');
2187
+							} else {
2188
+															$fullUrl = $url;
2189
+							}
2094 2190
 
2095 2191
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2096 2192
 						}, $data);
@@ -2139,22 +2235,25 @@  discard block
 block discarded – undo
2139 2235
 		}
2140 2236
 
2141 2237
 		// Are we there yet?  Are we there yet?
2142
-		if ($pos >= strlen($message) - 1)
2143
-			break;
2238
+		if ($pos >= strlen($message) - 1) {
2239
+					break;
2240
+		}
2144 2241
 
2145 2242
 		$tags = strtolower($message[$pos + 1]);
2146 2243
 
2147 2244
 		if ($tags == '/' && !empty($open_tags))
2148 2245
 		{
2149 2246
 			$pos2 = strpos($message, ']', $pos + 1);
2150
-			if ($pos2 == $pos + 2)
2151
-				continue;
2247
+			if ($pos2 == $pos + 2) {
2248
+							continue;
2249
+			}
2152 2250
 
2153 2251
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2154 2252
 
2155 2253
 			// A closing tag that doesn't match any open tags? Skip it.
2156
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2157
-				continue;
2254
+			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) {
2255
+							continue;
2256
+			}
2158 2257
 
2159 2258
 			$to_close = array();
2160 2259
 			$block_level = null;
@@ -2162,8 +2261,9 @@  discard block
 block discarded – undo
2162 2261
 			do
2163 2262
 			{
2164 2263
 				$tag = array_pop($open_tags);
2165
-				if (!$tag)
2166
-					break;
2264
+				if (!$tag) {
2265
+									break;
2266
+				}
2167 2267
 
2168 2268
 				if (!empty($tag['block_level']))
2169 2269
 				{
@@ -2177,10 +2277,11 @@  discard block
 block discarded – undo
2177 2277
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2178 2278
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2179 2279
 					{
2180
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2181
-							if ($temp['tag'] == $look_for)
2280
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2281
+													if ($temp['tag'] == $look_for)
2182 2282
 							{
2183 2283
 								$block_level = !empty($temp['block_level']);
2284
+						}
2184 2285
 								break;
2185 2286
 							}
2186 2287
 					}
@@ -2202,15 +2303,15 @@  discard block
 block discarded – undo
2202 2303
 			{
2203 2304
 				$open_tags = $to_close;
2204 2305
 				continue;
2205
-			}
2206
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2306
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2207 2307
 			{
2208 2308
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2209 2309
 				{
2210
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2211
-						if ($temp['tag'] == $look_for)
2310
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2311
+											if ($temp['tag'] == $look_for)
2212 2312
 						{
2213 2313
 							$block_level = !empty($temp['block_level']);
2314
+					}
2214 2315
 							break;
2215 2316
 						}
2216 2317
 				}
@@ -2218,8 +2319,9 @@  discard block
 block discarded – undo
2218 2319
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2219 2320
 				if (!$block_level)
2220 2321
 				{
2221
-					foreach ($to_close as $tag)
2222
-						array_push($open_tags, $tag);
2322
+					foreach ($to_close as $tag) {
2323
+											array_push($open_tags, $tag);
2324
+					}
2223 2325
 					continue;
2224 2326
 				}
2225 2327
 			}
@@ -2232,14 +2334,17 @@  discard block
 block discarded – undo
2232 2334
 
2233 2335
 				// See the comment at the end of the big loop - just eating whitespace ;).
2234 2336
 				$whitespace_regex = '';
2235
-				if (!empty($tag['block_level']))
2236
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2337
+				if (!empty($tag['block_level'])) {
2338
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2339
+				}
2237 2340
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2238
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2239
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2341
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2342
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2343
+				}
2240 2344
 
2241
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2242
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2345
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2346
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2347
+				}
2243 2348
 			}
2244 2349
 
2245 2350
 			if (!empty($to_close))
@@ -2252,8 +2357,9 @@  discard block
 block discarded – undo
2252 2357
 		}
2253 2358
 
2254 2359
 		// No tags for this character, so just keep going (fastest possible course.)
2255
-		if (!isset($bbc_codes[$tags]))
2256
-			continue;
2360
+		if (!isset($bbc_codes[$tags])) {
2361
+					continue;
2362
+		}
2257 2363
 
2258 2364
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2259 2365
 		$tag = null;
@@ -2262,48 +2368,57 @@  discard block
 block discarded – undo
2262 2368
 			$pt_strlen = strlen($possible['tag']);
2263 2369
 
2264 2370
 			// Not a match?
2265
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2266
-				continue;
2371
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2372
+							continue;
2373
+			}
2267 2374
 
2268 2375
 			$next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : '';
2269 2376
 
2270 2377
 			// A tag is the last char maybe
2271
-			if ($next_c == '')
2272
-				break;
2378
+			if ($next_c == '') {
2379
+							break;
2380
+			}
2273 2381
 
2274 2382
 			// A test validation?
2275
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2276
-				continue;
2383
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2384
+							continue;
2385
+			}
2277 2386
 			// Do we want parameters?
2278 2387
 			elseif (!empty($possible['parameters']))
2279 2388
 			{
2280
-				if ($next_c != ' ')
2281
-					continue;
2282
-			}
2283
-			elseif (isset($possible['type']))
2389
+				if ($next_c != ' ') {
2390
+									continue;
2391
+				}
2392
+			} elseif (isset($possible['type']))
2284 2393
 			{
2285 2394
 				// Do we need an equal sign?
2286
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2287
-					continue;
2395
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2396
+									continue;
2397
+				}
2288 2398
 				// Maybe we just want a /...
2289
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2290
-					continue;
2399
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2400
+									continue;
2401
+				}
2291 2402
 				// An immediate ]?
2292
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2293
-					continue;
2403
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2404
+									continue;
2405
+				}
2294 2406
 			}
2295 2407
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2296
-			elseif ($next_c != ']')
2297
-				continue;
2408
+			elseif ($next_c != ']') {
2409
+							continue;
2410
+			}
2298 2411
 
2299 2412
 			// Check allowed tree?
2300
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2301
-				continue;
2302
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2303
-				continue;
2413
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2414
+							continue;
2415
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2416
+							continue;
2417
+			}
2304 2418
 			// If this is in the list of disallowed child tags, don't parse it.
2305
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2306
-				continue;
2419
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2420
+							continue;
2421
+			}
2307 2422
 
2308 2423
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2309 2424
 
@@ -2315,8 +2430,9 @@  discard block
 block discarded – undo
2315 2430
 				foreach ($open_tags as $open_quote)
2316 2431
 				{
2317 2432
 					// Every parent quote this quote has flips the styling
2318
-					if ($open_quote['tag'] == 'quote')
2319
-						$quote_alt = !$quote_alt;
2433
+					if ($open_quote['tag'] == 'quote') {
2434
+											$quote_alt = !$quote_alt;
2435
+					}
2320 2436
 				}
2321 2437
 				// Add a class to the quote to style alternating blockquotes
2322 2438
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2327,8 +2443,9 @@  discard block
 block discarded – undo
2327 2443
 			{
2328 2444
 				// Build a regular expression for each parameter for the current tag.
2329 2445
 				$preg = array();
2330
-				foreach ($possible['parameters'] as $p => $info)
2331
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2446
+				foreach ($possible['parameters'] as $p => $info) {
2447
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2448
+				}
2332 2449
 
2333 2450
 				// Extract the string that potentially holds our parameters.
2334 2451
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2348,24 +2465,27 @@  discard block
 block discarded – undo
2348 2465
 
2349 2466
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2350 2467
 
2351
-					if ($match)
2352
-						$blob_counter = count($blobs) + 1;
2468
+					if ($match) {
2469
+											$blob_counter = count($blobs) + 1;
2470
+					}
2353 2471
 				}
2354 2472
 
2355 2473
 				// Didn't match our parameter list, try the next possible.
2356
-				if (!$match)
2357
-					continue;
2474
+				if (!$match) {
2475
+									continue;
2476
+				}
2358 2477
 
2359 2478
 				$params = array();
2360 2479
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2361 2480
 				{
2362 2481
 					$key = strtok(ltrim($matches[$i]), '=');
2363
-					if (isset($possible['parameters'][$key]['value']))
2364
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2365
-					elseif (isset($possible['parameters'][$key]['validate']))
2366
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2367
-					else
2368
-						$params['{' . $key . '}'] = $matches[$i + 1];
2482
+					if (isset($possible['parameters'][$key]['value'])) {
2483
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2484
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2485
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2486
+					} else {
2487
+											$params['{' . $key . '}'] = $matches[$i + 1];
2488
+					}
2369 2489
 
2370 2490
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2371 2491
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2373,23 +2493,26 @@  discard block
 block discarded – undo
2373 2493
 
2374 2494
 				foreach ($possible['parameters'] as $p => $info)
2375 2495
 				{
2376
-					if (!isset($params['{' . $p . '}']))
2377
-						$params['{' . $p . '}'] = '';
2496
+					if (!isset($params['{' . $p . '}'])) {
2497
+											$params['{' . $p . '}'] = '';
2498
+					}
2378 2499
 				}
2379 2500
 
2380 2501
 				$tag = $possible;
2381 2502
 
2382 2503
 				// Put the parameters into the string.
2383
-				if (isset($tag['before']))
2384
-					$tag['before'] = strtr($tag['before'], $params);
2385
-				if (isset($tag['after']))
2386
-					$tag['after'] = strtr($tag['after'], $params);
2387
-				if (isset($tag['content']))
2388
-					$tag['content'] = strtr($tag['content'], $params);
2504
+				if (isset($tag['before'])) {
2505
+									$tag['before'] = strtr($tag['before'], $params);
2506
+				}
2507
+				if (isset($tag['after'])) {
2508
+									$tag['after'] = strtr($tag['after'], $params);
2509
+				}
2510
+				if (isset($tag['content'])) {
2511
+									$tag['content'] = strtr($tag['content'], $params);
2512
+				}
2389 2513
 
2390 2514
 				$pos1 += strlen($given_param_string);
2391
-			}
2392
-			else
2515
+			} else
2393 2516
 			{
2394 2517
 				$tag = $possible;
2395 2518
 				$params = array();
@@ -2400,8 +2523,9 @@  discard block
 block discarded – undo
2400 2523
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2401 2524
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2402 2525
 		{
2403
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2404
-				continue;
2526
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2527
+							continue;
2528
+			}
2405 2529
 
2406 2530
 			$tag = $itemcodes[$message[$pos + 1]];
2407 2531
 
@@ -2422,9 +2546,9 @@  discard block
 block discarded – undo
2422 2546
 			{
2423 2547
 				array_pop($open_tags);
2424 2548
 				$code = '</li>';
2549
+			} else {
2550
+							$code = '';
2425 2551
 			}
2426
-			else
2427
-				$code = '';
2428 2552
 
2429 2553
 			// Now we open a new tag.
2430 2554
 			$open_tags[] = array(
@@ -2471,12 +2595,14 @@  discard block
 block discarded – undo
2471 2595
 		}
2472 2596
 
2473 2597
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2474
-		if ($tag === null)
2475
-			continue;
2598
+		if ($tag === null) {
2599
+					continue;
2600
+		}
2476 2601
 
2477 2602
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2478
-		if (isset($inside['disallow_children']))
2479
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2603
+		if (isset($inside['disallow_children'])) {
2604
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2605
+		}
2480 2606
 
2481 2607
 		// Is this tag disabled?
2482 2608
 		if (isset($disabled[$tag['tag']]))
@@ -2486,14 +2612,13 @@  discard block
 block discarded – undo
2486 2612
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2487 2613
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2488 2614
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2489
-			}
2490
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2615
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2491 2616
 			{
2492 2617
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2493 2618
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2619
+			} else {
2620
+							$tag['content'] = $tag['disabled_content'];
2494 2621
 			}
2495
-			else
2496
-				$tag['content'] = $tag['disabled_content'];
2497 2622
 		}
2498 2623
 
2499 2624
 		// we use this a lot
@@ -2503,8 +2628,9 @@  discard block
 block discarded – undo
2503 2628
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2504 2629
 		{
2505 2630
 			$n = count($open_tags) - 1;
2506
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2507
-				$n--;
2631
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2632
+							$n--;
2633
+			}
2508 2634
 
2509 2635
 			// Close all the non block level tags so this tag isn't surrounded by them.
2510 2636
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2516,12 +2642,15 @@  discard block
 block discarded – undo
2516 2642
 
2517 2643
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2518 2644
 				$whitespace_regex = '';
2519
-				if (!empty($tag['block_level']))
2520
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2521
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2522
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2523
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2524
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2645
+				if (!empty($tag['block_level'])) {
2646
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2647
+				}
2648
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2649
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2650
+				}
2651
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2652
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2653
+				}
2525 2654
 
2526 2655
 				array_pop($open_tags);
2527 2656
 			}
@@ -2542,16 +2671,19 @@  discard block
 block discarded – undo
2542 2671
 		elseif ($tag['type'] == 'unparsed_content')
2543 2672
 		{
2544 2673
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2545
-			if ($pos2 === false)
2546
-				continue;
2674
+			if ($pos2 === false) {
2675
+							continue;
2676
+			}
2547 2677
 
2548 2678
 			$data = substr($message, $pos1, $pos2 - $pos1);
2549 2679
 
2550
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2551
-				$data = substr($data, 4);
2680
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2681
+							$data = substr($data, 4);
2682
+			}
2552 2683
 
2553
-			if (isset($tag['validate']))
2554
-				$tag['validate']($tag, $data, $disabled, $params);
2684
+			if (isset($tag['validate'])) {
2685
+							$tag['validate']($tag, $data, $disabled, $params);
2686
+			}
2555 2687
 
2556 2688
 			$code = strtr($tag['content'], array('$1' => $data));
2557 2689
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2567,34 +2699,40 @@  discard block
 block discarded – undo
2567 2699
 			if (isset($tag['quoted']))
2568 2700
 			{
2569 2701
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2570
-				if ($tag['quoted'] != 'optional' && !$quoted)
2571
-					continue;
2702
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2703
+									continue;
2704
+				}
2572 2705
 
2573
-				if ($quoted)
2574
-					$pos1 += 6;
2706
+				if ($quoted) {
2707
+									$pos1 += 6;
2708
+				}
2709
+			} else {
2710
+							$quoted = false;
2575 2711
 			}
2576
-			else
2577
-				$quoted = false;
2578 2712
 
2579 2713
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2580
-			if ($pos2 === false)
2581
-				continue;
2714
+			if ($pos2 === false) {
2715
+							continue;
2716
+			}
2582 2717
 
2583 2718
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2584
-			if ($pos3 === false)
2585
-				continue;
2719
+			if ($pos3 === false) {
2720
+							continue;
2721
+			}
2586 2722
 
2587 2723
 			$data = array(
2588 2724
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2589 2725
 				substr($message, $pos1, $pos2 - $pos1)
2590 2726
 			);
2591 2727
 
2592
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2593
-				$data[0] = substr($data[0], 4);
2728
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2729
+							$data[0] = substr($data[0], 4);
2730
+			}
2594 2731
 
2595 2732
 			// Validation for my parking, please!
2596
-			if (isset($tag['validate']))
2597
-				$tag['validate']($tag, $data, $disabled, $params);
2733
+			if (isset($tag['validate'])) {
2734
+							$tag['validate']($tag, $data, $disabled, $params);
2735
+			}
2598 2736
 
2599 2737
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2600 2738
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2611,23 +2749,27 @@  discard block
 block discarded – undo
2611 2749
 		elseif ($tag['type'] == 'unparsed_commas_content')
2612 2750
 		{
2613 2751
 			$pos2 = strpos($message, ']', $pos1);
2614
-			if ($pos2 === false)
2615
-				continue;
2752
+			if ($pos2 === false) {
2753
+							continue;
2754
+			}
2616 2755
 
2617 2756
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2618
-			if ($pos3 === false)
2619
-				continue;
2757
+			if ($pos3 === false) {
2758
+							continue;
2759
+			}
2620 2760
 
2621 2761
 			// We want $1 to be the content, and the rest to be csv.
2622 2762
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2623 2763
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2624 2764
 
2625
-			if (isset($tag['validate']))
2626
-				$tag['validate']($tag, $data, $disabled, $params);
2765
+			if (isset($tag['validate'])) {
2766
+							$tag['validate']($tag, $data, $disabled, $params);
2767
+			}
2627 2768
 
2628 2769
 			$code = $tag['content'];
2629
-			foreach ($data as $k => $d)
2630
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2770
+			foreach ($data as $k => $d) {
2771
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2772
+			}
2631 2773
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2632 2774
 			$pos += strlen($code) - 1 + 2;
2633 2775
 		}
@@ -2635,24 +2777,28 @@  discard block
 block discarded – undo
2635 2777
 		elseif ($tag['type'] == 'unparsed_commas')
2636 2778
 		{
2637 2779
 			$pos2 = strpos($message, ']', $pos1);
2638
-			if ($pos2 === false)
2639
-				continue;
2780
+			if ($pos2 === false) {
2781
+							continue;
2782
+			}
2640 2783
 
2641 2784
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2642 2785
 
2643
-			if (isset($tag['validate']))
2644
-				$tag['validate']($tag, $data, $disabled, $params);
2786
+			if (isset($tag['validate'])) {
2787
+							$tag['validate']($tag, $data, $disabled, $params);
2788
+			}
2645 2789
 
2646 2790
 			// Fix after, for disabled code mainly.
2647
-			foreach ($data as $k => $d)
2648
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2791
+			foreach ($data as $k => $d) {
2792
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2793
+			}
2649 2794
 
2650 2795
 			$open_tags[] = $tag;
2651 2796
 
2652 2797
 			// Replace them out, $1, $2, $3, $4, etc.
2653 2798
 			$code = $tag['before'];
2654
-			foreach ($data as $k => $d)
2655
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2799
+			foreach ($data as $k => $d) {
2800
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2801
+			}
2656 2802
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2657 2803
 			$pos += strlen($code) - 1 + 2;
2658 2804
 		}
@@ -2663,28 +2809,33 @@  discard block
 block discarded – undo
2663 2809
 			if (isset($tag['quoted']))
2664 2810
 			{
2665 2811
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2666
-				if ($tag['quoted'] != 'optional' && !$quoted)
2667
-					continue;
2812
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2813
+									continue;
2814
+				}
2668 2815
 
2669
-				if ($quoted)
2670
-					$pos1 += 6;
2816
+				if ($quoted) {
2817
+									$pos1 += 6;
2818
+				}
2819
+			} else {
2820
+							$quoted = false;
2671 2821
 			}
2672
-			else
2673
-				$quoted = false;
2674 2822
 
2675 2823
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2676
-			if ($pos2 === false)
2677
-				continue;
2824
+			if ($pos2 === false) {
2825
+							continue;
2826
+			}
2678 2827
 
2679 2828
 			$data = substr($message, $pos1, $pos2 - $pos1);
2680 2829
 
2681 2830
 			// Validation for my parking, please!
2682
-			if (isset($tag['validate']))
2683
-				$tag['validate']($tag, $data, $disabled, $params);
2831
+			if (isset($tag['validate'])) {
2832
+							$tag['validate']($tag, $data, $disabled, $params);
2833
+			}
2684 2834
 
2685 2835
 			// For parsed content, we must recurse to avoid security problems.
2686
-			if ($tag['type'] != 'unparsed_equals')
2687
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2836
+			if ($tag['type'] != 'unparsed_equals') {
2837
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2838
+			}
2688 2839
 
2689 2840
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2690 2841
 
@@ -2696,34 +2847,40 @@  discard block
 block discarded – undo
2696 2847
 		}
2697 2848
 
2698 2849
 		// If this is block level, eat any breaks after it.
2699
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2700
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2850
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2851
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2852
+		}
2701 2853
 
2702 2854
 		// Are we trimming outside this tag?
2703
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2704
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2855
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2856
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2857
+		}
2705 2858
 	}
2706 2859
 
2707 2860
 	// Close any remaining tags.
2708
-	while ($tag = array_pop($open_tags))
2709
-		$message .= "\n" . $tag['after'] . "\n";
2861
+	while ($tag = array_pop($open_tags)) {
2862
+			$message .= "\n" . $tag['after'] . "\n";
2863
+	}
2710 2864
 
2711 2865
 	// Parse the smileys within the parts where it can be done safely.
2712 2866
 	if ($smileys === true)
2713 2867
 	{
2714 2868
 		$message_parts = explode("\n", $message);
2715
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2716
-			parsesmileys($message_parts[$i]);
2869
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2870
+					parsesmileys($message_parts[$i]);
2871
+		}
2717 2872
 
2718 2873
 		$message = implode('', $message_parts);
2719 2874
 	}
2720 2875
 
2721 2876
 	// No smileys, just get rid of the markers.
2722
-	else
2723
-		$message = strtr($message, array("\n" => ''));
2877
+	else {
2878
+			$message = strtr($message, array("\n" => ''));
2879
+	}
2724 2880
 
2725
-	if ($message !== '' && $message[0] === ' ')
2726
-		$message = '&nbsp;' . substr($message, 1);
2881
+	if ($message !== '' && $message[0] === ' ') {
2882
+			$message = '&nbsp;' . substr($message, 1);
2883
+	}
2727 2884
 
2728 2885
 	// Cleanup whitespace.
2729 2886
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2732,15 +2889,16 @@  discard block
 block discarded – undo
2732 2889
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2733 2890
 
2734 2891
 	// Cache the output if it took some time...
2735
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2736
-		cache_put_data($cache_key, $message, 240);
2892
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2893
+			cache_put_data($cache_key, $message, 240);
2894
+	}
2737 2895
 
2738 2896
 	// If this was a force parse revert if needed.
2739 2897
 	if (!empty($parse_tags))
2740 2898
 	{
2741
-		if (empty($temp_bbc))
2742
-			$bbc_codes = array();
2743
-		else
2899
+		if (empty($temp_bbc)) {
2900
+					$bbc_codes = array();
2901
+		} else
2744 2902
 		{
2745 2903
 			$bbc_codes = $temp_bbc;
2746 2904
 			unset($temp_bbc);
@@ -2767,8 +2925,9 @@  discard block
 block discarded – undo
2767 2925
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2768 2926
 
2769 2927
 	// No smiley set at all?!
2770
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2771
-		return;
2928
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2929
+			return;
2930
+	}
2772 2931
 
2773 2932
 	// If smileyPregSearch hasn't been set, do it now.
2774 2933
 	if (empty($smileyPregSearch))
@@ -2779,8 +2938,7 @@  discard block
 block discarded – undo
2779 2938
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2780 2939
 			$smileysto = array('evil.png', 'cheesy.png', 'rolleyes.png', 'angry.png', 'laugh.png', 'smiley.png', 'wink.png', 'grin.png', 'sad.png', 'shocked.png', 'cool.png', 'tongue.png', 'huh.png', 'embarrassed.png', 'lipsrsealed.png', 'kiss.png', 'cry.png', 'undecided.png', 'azn.png', 'afro.png', 'police.png', 'angel.png');
2781 2940
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2782
-		}
2783
-		else
2941
+		} else
2784 2942
 		{
2785 2943
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2786 2944
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2804,9 +2962,9 @@  discard block
 block discarded – undo
2804 2962
 				$smcFunc['db_free_result']($result);
2805 2963
 
2806 2964
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2965
+			} else {
2966
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2807 2967
 			}
2808
-			else
2809
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2810 2968
 		}
2811 2969
 
2812 2970
 		// The non-breaking-space is a complex thing...
@@ -2883,35 +3041,41 @@  discard block
 block discarded – undo
2883 3041
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2884 3042
 
2885 3043
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2886
-	if (!empty($context['flush_mail']))
2887
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3044
+	if (!empty($context['flush_mail'])) {
3045
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2888 3046
 		AddMailQueue(true);
3047
+	}
2889 3048
 
2890 3049
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2891 3050
 
2892
-	if ($add)
2893
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3051
+	if ($add) {
3052
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3053
+	}
2894 3054
 
2895 3055
 	// Put the session ID in.
2896
-	if (defined('SID') && SID != '')
2897
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3056
+	if (defined('SID') && SID != '') {
3057
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3058
+	}
2898 3059
 	// Keep that debug in their for template debugging!
2899
-	elseif (isset($_GET['debug']))
2900
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3060
+	elseif (isset($_GET['debug'])) {
3061
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3062
+	}
2901 3063
 
2902 3064
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
2903 3065
 	{
2904
-		if (defined('SID') && SID != '')
2905
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3066
+		if (defined('SID') && SID != '') {
3067
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2906 3068
 				function ($m) use ($scripturl)
2907 3069
 				{
2908 3070
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3071
+		}
2909 3072
 				}, $setLocation);
2910
-		else
2911
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3073
+		else {
3074
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2912 3075
 				function ($m) use ($scripturl)
2913 3076
 				{
2914 3077
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3078
+		}
2915 3079
 				}, $setLocation);
2916 3080
 	}
2917 3081
 
@@ -2922,8 +3086,9 @@  discard block
 block discarded – undo
2922 3086
 	header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2923 3087
 
2924 3088
 	// Debugging.
2925
-	if (isset($db_show_debug) && $db_show_debug === true)
2926
-		$_SESSION['debug_redirect'] = $db_cache;
3089
+	if (isset($db_show_debug) && $db_show_debug === true) {
3090
+			$_SESSION['debug_redirect'] = $db_cache;
3091
+	}
2927 3092
 
2928 3093
 	obExit(false);
2929 3094
 }
@@ -2942,51 +3107,60 @@  discard block
 block discarded – undo
2942 3107
 
2943 3108
 	// Attempt to prevent a recursive loop.
2944 3109
 	++$level;
2945
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2946
-		exit;
2947
-	if ($from_fatal_error)
2948
-		$has_fatal_error = true;
3110
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3111
+			exit;
3112
+	}
3113
+	if ($from_fatal_error) {
3114
+			$has_fatal_error = true;
3115
+	}
2949 3116
 
2950 3117
 	// Clear out the stat cache.
2951 3118
 	trackStats();
2952 3119
 
2953 3120
 	// If we have mail to send, send it.
2954
-	if (!empty($context['flush_mail']))
2955
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3121
+	if (!empty($context['flush_mail'])) {
3122
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2956 3123
 		AddMailQueue(true);
3124
+	}
2957 3125
 
2958 3126
 	$do_header = $header === null ? !$header_done : $header;
2959
-	if ($do_footer === null)
2960
-		$do_footer = $do_header;
3127
+	if ($do_footer === null) {
3128
+			$do_footer = $do_header;
3129
+	}
2961 3130
 
2962 3131
 	// Has the template/header been done yet?
2963 3132
 	if ($do_header)
2964 3133
 	{
2965 3134
 		// Was the page title set last minute? Also update the HTML safe one.
2966
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2967
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3135
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3136
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3137
+		}
2968 3138
 
2969 3139
 		// Start up the session URL fixer.
2970 3140
 		ob_start('ob_sessrewrite');
2971 3141
 
2972
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2973
-			$buffers = explode(',', $settings['output_buffers']);
2974
-		elseif (!empty($settings['output_buffers']))
2975
-			$buffers = $settings['output_buffers'];
2976
-		else
2977
-			$buffers = array();
3142
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3143
+					$buffers = explode(',', $settings['output_buffers']);
3144
+		} elseif (!empty($settings['output_buffers'])) {
3145
+					$buffers = $settings['output_buffers'];
3146
+		} else {
3147
+					$buffers = array();
3148
+		}
2978 3149
 
2979
-		if (isset($modSettings['integrate_buffer']))
2980
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3150
+		if (isset($modSettings['integrate_buffer'])) {
3151
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3152
+		}
2981 3153
 
2982
-		if (!empty($buffers))
2983
-			foreach ($buffers as $function)
3154
+		if (!empty($buffers)) {
3155
+					foreach ($buffers as $function)
2984 3156
 			{
2985 3157
 				$call = call_helper($function, true);
3158
+		}
2986 3159
 
2987 3160
 				// Is it valid?
2988
-				if (!empty($call))
2989
-					ob_start($call);
3161
+				if (!empty($call)) {
3162
+									ob_start($call);
3163
+				}
2990 3164
 			}
2991 3165
 
2992 3166
 		// Display the screen in the logical order.
@@ -2998,8 +3172,9 @@  discard block
 block discarded – undo
2998 3172
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2999 3173
 
3000 3174
 		// Anything special to put out?
3001
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
3002
-			echo $context['insert_after_template'];
3175
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3176
+					echo $context['insert_after_template'];
3177
+		}
3003 3178
 
3004 3179
 		// Just so we don't get caught in an endless loop of errors from the footer...
3005 3180
 		if (!$footer_done)
@@ -3008,14 +3183,16 @@  discard block
 block discarded – undo
3008 3183
 			template_footer();
3009 3184
 
3010 3185
 			// (since this is just debugging... it's okay that it's after </html>.)
3011
-			if (!isset($_REQUEST['xml']))
3012
-				displayDebug();
3186
+			if (!isset($_REQUEST['xml'])) {
3187
+							displayDebug();
3188
+			}
3013 3189
 		}
3014 3190
 	}
3015 3191
 
3016 3192
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
3017
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
3018
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3193
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3194
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3195
+	}
3019 3196
 
3020 3197
 	// For session check verification.... don't switch browsers...
3021 3198
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -3024,9 +3201,10 @@  discard block
 block discarded – undo
3024 3201
 	call_integration_hook('integrate_exit', array($do_footer));
3025 3202
 
3026 3203
 	// Don't exit if we're coming from index.php; that will pass through normally.
3027
-	if (!$from_index)
3028
-		exit;
3029
-}
3204
+	if (!$from_index) {
3205
+			exit;
3206
+	}
3207
+	}
3030 3208
 
3031 3209
 /**
3032 3210
  * Get the size of a specified image with better error handling.
@@ -3045,8 +3223,9 @@  discard block
 block discarded – undo
3045 3223
 	$url = str_replace(' ', '%20', $url);
3046 3224
 
3047 3225
 	// Can we pull this from the cache... please please?
3048
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3049
-		return $temp;
3226
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3227
+			return $temp;
3228
+	}
3050 3229
 	$t = microtime();
3051 3230
 
3052 3231
 	// Get the host to pester...
@@ -3056,12 +3235,10 @@  discard block
 block discarded – undo
3056 3235
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3057 3236
 	{
3058 3237
 		return false;
3059
-	}
3060
-	elseif (!isset($match[1]))
3238
+	} elseif (!isset($match[1]))
3061 3239
 	{
3062 3240
 		$size = @getimagesize($url);
3063
-	}
3064
-	else
3241
+	} else
3065 3242
 	{
3066 3243
 		// Try to connect to the server... give it half a second.
3067 3244
 		$temp = 0;
@@ -3100,12 +3277,14 @@  discard block
 block discarded – undo
3100 3277
 	}
3101 3278
 
3102 3279
 	// If we didn't get it, we failed.
3103
-	if (!isset($size))
3104
-		$size = false;
3280
+	if (!isset($size)) {
3281
+			$size = false;
3282
+	}
3105 3283
 
3106 3284
 	// If this took a long time, we may never have to do it again, but then again we might...
3107
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3108
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3285
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3286
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3287
+	}
3109 3288
 
3110 3289
 	// Didn't work.
3111 3290
 	return $size;
@@ -3123,8 +3302,9 @@  discard block
 block discarded – undo
3123 3302
 
3124 3303
 	// Under SSI this function can be called more then once.  That can cause some problems.
3125 3304
 	//   So only run the function once unless we are forced to run it again.
3126
-	if ($loaded && !$forceload)
3127
-		return;
3305
+	if ($loaded && !$forceload) {
3306
+			return;
3307
+	}
3128 3308
 
3129 3309
 	$loaded = true;
3130 3310
 
@@ -3136,14 +3316,16 @@  discard block
 block discarded – undo
3136 3316
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3137 3317
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3138 3318
 	{
3139
-		if (trim($context['news_lines'][$i]) == '')
3140
-			continue;
3319
+		if (trim($context['news_lines'][$i]) == '') {
3320
+					continue;
3321
+		}
3141 3322
 
3142 3323
 		// Clean it up for presentation ;).
3143 3324
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3144 3325
 	}
3145
-	if (!empty($context['news_lines']))
3146
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3326
+	if (!empty($context['news_lines'])) {
3327
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3328
+	}
3147 3329
 
3148 3330
 	if (!$user_info['is_guest'])
3149 3331
 	{
@@ -3152,40 +3334,48 @@  discard block
 block discarded – undo
3152 3334
 		$context['user']['alerts'] = &$user_info['alerts'];
3153 3335
 
3154 3336
 		// Personal message popup...
3155
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3156
-			$context['user']['popup_messages'] = true;
3157
-		else
3158
-			$context['user']['popup_messages'] = false;
3337
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3338
+					$context['user']['popup_messages'] = true;
3339
+		} else {
3340
+					$context['user']['popup_messages'] = false;
3341
+		}
3159 3342
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3160 3343
 
3161
-		if (allowedTo('moderate_forum'))
3162
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3344
+		if (allowedTo('moderate_forum')) {
3345
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3346
+		}
3163 3347
 
3164 3348
 		$context['user']['avatar'] = array();
3165 3349
 
3166 3350
 		// Check for gravatar first since we might be forcing them...
3167 3351
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3168 3352
 		{
3169
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3170
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3171
-			else
3172
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3353
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3354
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3355
+			} else {
3356
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3357
+			}
3173 3358
 		}
3174 3359
 		// Uploaded?
3175
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3176
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3360
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3361
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3362
+		}
3177 3363
 		// Full URL?
3178
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3179
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3364
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3365
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3366
+		}
3180 3367
 		// Otherwise we assume it's server stored.
3181
-		elseif ($user_info['avatar']['url'] != '')
3182
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3368
+		elseif ($user_info['avatar']['url'] != '') {
3369
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3370
+		}
3183 3371
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3184
-		else
3185
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3372
+		else {
3373
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3374
+		}
3186 3375
 
3187
-		if (!empty($context['user']['avatar']))
3188
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3376
+		if (!empty($context['user']['avatar'])) {
3377
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3378
+		}
3189 3379
 
3190 3380
 		// Figure out how long they've been logged in.
3191 3381
 		$context['user']['total_time_logged_in'] = array(
@@ -3193,8 +3383,7 @@  discard block
 block discarded – undo
3193 3383
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3194 3384
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3195 3385
 		);
3196
-	}
3197
-	else
3386
+	} else
3198 3387
 	{
3199 3388
 		$context['user']['messages'] = 0;
3200 3389
 		$context['user']['unread_messages'] = 0;
@@ -3202,12 +3391,14 @@  discard block
 block discarded – undo
3202 3391
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3203 3392
 		$context['user']['popup_messages'] = false;
3204 3393
 
3205
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3206
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3394
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3395
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3396
+		}
3207 3397
 
3208 3398
 		// If we've upgraded recently, go easy on the passwords.
3209
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3210
-			$context['disable_login_hashing'] = true;
3399
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3400
+					$context['disable_login_hashing'] = true;
3401
+		}
3211 3402
 	}
3212 3403
 
3213 3404
 	// Setup the main menu items.
@@ -3220,8 +3411,8 @@  discard block
 block discarded – undo
3220 3411
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3221 3412
 
3222 3413
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3223
-	if ($context['show_pm_popup'])
3224
-		addInlineJavaScript('
3414
+	if ($context['show_pm_popup']) {
3415
+			addInlineJavaScript('
3225 3416
 		jQuery(document).ready(function($) {
3226 3417
 			new smc_Popup({
3227 3418
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3229,15 +3420,17 @@  discard block
 block discarded – undo
3229 3420
 				icon_class: \'generic_icons mail_new\'
3230 3421
 			});
3231 3422
 		});');
3423
+	}
3232 3424
 
3233 3425
 	// Add a generic "Are you sure?" confirmation message.
3234 3426
 	addInlineJavaScript('
3235 3427
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3236 3428
 
3237 3429
 	// Now add the capping code for avatars.
3238
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3239
-		addInlineCss('
3430
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3431
+			addInlineCss('
3240 3432
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3433
+	}
3241 3434
 
3242 3435
 	// This looks weird, but it's because BoardIndex.php references the variable.
3243 3436
 	$context['common_stats']['latest_member'] = array(
@@ -3254,11 +3447,13 @@  discard block
 block discarded – undo
3254 3447
 	);
3255 3448
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3256 3449
 
3257
-	if (empty($settings['theme_version']))
3258
-		addJavaScriptVar('smf_scripturl', $scripturl);
3450
+	if (empty($settings['theme_version'])) {
3451
+			addJavaScriptVar('smf_scripturl', $scripturl);
3452
+	}
3259 3453
 
3260
-	if (!isset($context['page_title']))
3261
-		$context['page_title'] = '';
3454
+	if (!isset($context['page_title'])) {
3455
+			$context['page_title'] = '';
3456
+	}
3262 3457
 
3263 3458
 	// Set some specific vars.
3264 3459
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3268,21 +3463,23 @@  discard block
 block discarded – undo
3268 3463
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3269 3464
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3270 3465
 
3271
-	if (!empty($context['meta_keywords']))
3272
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3466
+	if (!empty($context['meta_keywords'])) {
3467
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3468
+	}
3273 3469
 
3274
-	if (!empty($context['canonical_url']))
3275
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3470
+	if (!empty($context['canonical_url'])) {
3471
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3472
+	}
3276 3473
 
3277
-	if (!empty($settings['og_image']))
3278
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3474
+	if (!empty($settings['og_image'])) {
3475
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3476
+	}
3279 3477
 
3280 3478
 	if (!empty($context['meta_description']))
3281 3479
 	{
3282 3480
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3283 3481
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3284
-	}
3285
-	else
3482
+	} else
3286 3483
 	{
3287 3484
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3288 3485
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3307,8 +3504,9 @@  discard block
 block discarded – undo
3307 3504
 	$memory_needed = memoryReturnBytes($needed);
3308 3505
 
3309 3506
 	// should we account for how much is currently being used?
3310
-	if ($in_use)
3311
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3507
+	if ($in_use) {
3508
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3509
+	}
3312 3510
 
3313 3511
 	// if more is needed, request it
3314 3512
 	if ($memory_current < $memory_needed)
@@ -3331,8 +3529,9 @@  discard block
 block discarded – undo
3331 3529
  */
3332 3530
 function memoryReturnBytes($val)
3333 3531
 {
3334
-	if (is_integer($val))
3335
-		return $val;
3532
+	if (is_integer($val)) {
3533
+			return $val;
3534
+	}
3336 3535
 
3337 3536
 	// Separate the number from the designator
3338 3537
 	$val = trim($val);
@@ -3368,10 +3567,11 @@  discard block
 block discarded – undo
3368 3567
 		header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3369 3568
 
3370 3569
 		// Are we debugging the template/html content?
3371
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3372
-			header('content-type: application/xhtml+xml');
3373
-		elseif (!isset($_REQUEST['xml']))
3374
-			header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3570
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3571
+					header('content-type: application/xhtml+xml');
3572
+		} elseif (!isset($_REQUEST['xml'])) {
3573
+					header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3574
+		}
3375 3575
 	}
3376 3576
 
3377 3577
 	header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3380,8 +3580,9 @@  discard block
 block discarded – undo
3380 3580
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3381 3581
 	{
3382 3582
 		$position = array_search('body', $context['template_layers']);
3383
-		if ($position === false)
3384
-			$position = array_search('main', $context['template_layers']);
3583
+		if ($position === false) {
3584
+					$position = array_search('main', $context['template_layers']);
3585
+		}
3385 3586
 
3386 3587
 		if ($position !== false)
3387 3588
 		{
@@ -3409,23 +3610,25 @@  discard block
 block discarded – undo
3409 3610
 
3410 3611
 			foreach ($securityFiles as $i => $securityFile)
3411 3612
 			{
3412
-				if (!file_exists($boarddir . '/' . $securityFile))
3413
-					unset($securityFiles[$i]);
3613
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3614
+									unset($securityFiles[$i]);
3615
+				}
3414 3616
 			}
3415 3617
 
3416 3618
 			// We are already checking so many files...just few more doesn't make any difference! :P
3417
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3418
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3419
-
3420
-			else
3421
-				$path = $modSettings['attachmentUploadDir'];
3619
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3620
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3621
+			} else {
3622
+							$path = $modSettings['attachmentUploadDir'];
3623
+			}
3422 3624
 
3423 3625
 			secureDirectory($path, true);
3424 3626
 			secureDirectory($cachedir);
3425 3627
 
3426 3628
 			// If agreement is enabled, at least the english version shall exists
3427
-			if ($modSettings['requireAgreement'])
3428
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3629
+			if ($modSettings['requireAgreement']) {
3630
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3631
+			}
3429 3632
 
3430 3633
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3431 3634
 			{
@@ -3440,18 +3643,21 @@  discard block
 block discarded – undo
3440 3643
 					echo '
3441 3644
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3442 3645
 
3443
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3444
-						echo '
3646
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3647
+											echo '
3445 3648
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3649
+					}
3446 3650
 				}
3447 3651
 
3448
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3449
-					echo '
3652
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3653
+									echo '
3450 3654
 				<strong>', $txt['cache_writable'], '</strong><br>';
3655
+				}
3451 3656
 
3452
-				if (!empty($agreement))
3453
-					echo '
3657
+				if (!empty($agreement)) {
3658
+									echo '
3454 3659
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3660
+				}
3455 3661
 
3456 3662
 				echo '
3457 3663
 			</p>
@@ -3466,16 +3672,18 @@  discard block
 block discarded – undo
3466 3672
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3467 3673
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3468 3674
 
3469
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3470
-				echo '
3675
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3676
+							echo '
3471 3677
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3678
+			}
3472 3679
 
3473
-			if (!empty($_SESSION['ban']['expire_time']))
3474
-				echo '
3680
+			if (!empty($_SESSION['ban']['expire_time'])) {
3681
+							echo '
3475 3682
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3476
-			else
3477
-				echo '
3683
+			} else {
3684
+							echo '
3478 3685
 					<div>', $txt['your_ban_expires_never'], '</div>';
3686
+			}
3479 3687
 
3480 3688
 			echo '
3481 3689
 				</div>';
@@ -3491,8 +3699,9 @@  discard block
 block discarded – undo
3491 3699
 	global $forum_copyright, $software_year, $forum_version;
3492 3700
 
3493 3701
 	// Don't display copyright for things like SSI.
3494
-	if (!isset($forum_version) || !isset($software_year))
3495
-		return;
3702
+	if (!isset($forum_version) || !isset($software_year)) {
3703
+			return;
3704
+	}
3496 3705
 
3497 3706
 	// Put in the version...
3498 3707
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3510,9 +3719,10 @@  discard block
 block discarded – undo
3510 3719
 	$context['load_time'] = round(microtime(true) - $time_start, 3);
3511 3720
 	$context['load_queries'] = $db_count;
3512 3721
 
3513
-	foreach (array_reverse($context['template_layers']) as $layer)
3514
-		loadSubTemplate($layer . '_below', true);
3515
-}
3722
+	foreach (array_reverse($context['template_layers']) as $layer) {
3723
+			loadSubTemplate($layer . '_below', true);
3724
+	}
3725
+	}
3516 3726
 
3517 3727
 /**
3518 3728
  * Output the Javascript files
@@ -3543,8 +3753,7 @@  discard block
 block discarded – undo
3543 3753
 			{
3544 3754
 				echo '
3545 3755
 		var ', $key, ';';
3546
-			}
3547
-			else
3756
+			} else
3548 3757
 			{
3549 3758
 				echo '
3550 3759
 		var ', $key, ' = ', $value, ';';
@@ -3559,26 +3768,27 @@  discard block
 block discarded – undo
3559 3768
 	foreach ($context['javascript_files'] as $id => $js_file)
3560 3769
 	{
3561 3770
 		// Last minute call! allow theme authors to disable single files.
3562
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3563
-			continue;
3771
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3772
+					continue;
3773
+		}
3564 3774
 
3565 3775
 		// By default all files don't get minimized unless the file explicitly says so!
3566 3776
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3567 3777
 		{
3568
-			if ($do_deferred && !empty($js_file['options']['defer']))
3569
-				$toMinifyDefer[] = $js_file;
3570
-
3571
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3572
-				$toMinify[] = $js_file;
3778
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3779
+							$toMinifyDefer[] = $js_file;
3780
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3781
+							$toMinify[] = $js_file;
3782
+			}
3573 3783
 
3574 3784
 			// Grab a random seed.
3575
-			if (!isset($minSeed) && isset($js_file['options']['seed']))
3576
-				$minSeed = $js_file['options']['seed'];
3577
-		}
3578
-
3579
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3580
-			echo '
3785
+			if (!isset($minSeed) && isset($js_file['options']['seed'])) {
3786
+							$minSeed = $js_file['options']['seed'];
3787
+			}
3788
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3789
+					echo '
3581 3790
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3791
+		}
3582 3792
 	}
3583 3793
 
3584 3794
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3587,9 +3797,10 @@  discard block
 block discarded – undo
3587 3797
 
3588 3798
 		$minSuccessful = array_keys($result) === array('smf_minified');
3589 3799
 
3590
-		foreach ($result as $minFile)
3591
-			echo '
3800
+		foreach ($result as $minFile) {
3801
+					echo '
3592 3802
 	<script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async="async"' : '', '></script>';
3803
+		}
3593 3804
 
3594 3805
 	}
3595 3806
 
@@ -3601,8 +3812,9 @@  discard block
 block discarded – undo
3601 3812
 			echo '
3602 3813
 <script>';
3603 3814
 
3604
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3605
-				echo $js_code;
3815
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3816
+							echo $js_code;
3817
+			}
3606 3818
 
3607 3819
 			echo '
3608 3820
 </script>';
@@ -3613,8 +3825,9 @@  discard block
 block discarded – undo
3613 3825
 			echo '
3614 3826
 	<script>';
3615 3827
 
3616
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3617
-				echo $js_code;
3828
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3829
+							echo $js_code;
3830
+			}
3618 3831
 
3619 3832
 			echo '
3620 3833
 	</script>';
@@ -3642,23 +3855,26 @@  discard block
 block discarded – undo
3642 3855
 	foreach ($context['css_files'] as $id => $file)
3643 3856
 	{
3644 3857
 		// Last minute call! allow theme authors to disable single files.
3645
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3646
-			continue;
3858
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3859
+					continue;
3860
+		}
3647 3861
 
3648 3862
 		// Files are minimized unless they explicitly opt out.
3649
-		if (!isset($file['options']['minimize']))
3650
-			$file['options']['minimize'] = true;
3863
+		if (!isset($file['options']['minimize'])) {
3864
+					$file['options']['minimize'] = true;
3865
+		}
3651 3866
 
3652 3867
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
3653 3868
 		{
3654 3869
 			$toMinify[] = $file;
3655 3870
 
3656 3871
 			// Grab a random seed.
3657
-			if (!isset($minSeed) && isset($file['options']['seed']))
3658
-				$minSeed = $file['options']['seed'];
3872
+			if (!isset($minSeed) && isset($file['options']['seed'])) {
3873
+							$minSeed = $file['options']['seed'];
3874
+			}
3875
+		} else {
3876
+					$normal[] = $file['fileUrl'];
3659 3877
 		}
3660
-		else
3661
-			$normal[] = $file['fileUrl'];
3662 3878
 	}
3663 3879
 
3664 3880
 	if (!empty($toMinify))
@@ -3667,23 +3883,26 @@  discard block
 block discarded – undo
3667 3883
 
3668 3884
 		$minSuccessful = array_keys($result) === array('smf_minified');
3669 3885
 
3670
-		foreach ($result as $minFile)
3671
-			echo '
3886
+		foreach ($result as $minFile) {
3887
+					echo '
3672 3888
 	<link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">';
3889
+		}
3673 3890
 	}
3674 3891
 
3675 3892
 	// Print the rest after the minified files.
3676
-	if (!empty($normal))
3677
-		foreach ($normal as $nf)
3893
+	if (!empty($normal)) {
3894
+			foreach ($normal as $nf)
3678 3895
 			echo '
3679 3896
 	<link rel="stylesheet" href="', $nf ,'">';
3897
+	}
3680 3898
 
3681 3899
 	if ($db_show_debug === true)
3682 3900
 	{
3683 3901
 		// Try to keep only what's useful.
3684 3902
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3685
-		foreach ($context['css_files'] as $file)
3686
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3903
+		foreach ($context['css_files'] as $file) {
3904
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3905
+		}
3687 3906
 	}
3688 3907
 
3689 3908
 	if (!empty($context['css_header']))
@@ -3691,9 +3910,10 @@  discard block
 block discarded – undo
3691 3910
 		echo '
3692 3911
 	<style>';
3693 3912
 
3694
-		foreach ($context['css_header'] as $css)
3695
-			echo $css .'
3913
+		foreach ($context['css_header'] as $css) {
3914
+					echo $css .'
3696 3915
 	';
3916
+		}
3697 3917
 
3698 3918
 		echo'
3699 3919
 	</style>';
@@ -3717,8 +3937,9 @@  discard block
 block discarded – undo
3717 3937
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3718 3938
 	$data = !empty($data) ? $data : false;
3719 3939
 
3720
-	if (empty($type) || empty($data))
3721
-		return false;
3940
+	if (empty($type) || empty($data)) {
3941
+			return false;
3942
+	}
3722 3943
 
3723 3944
 	// Different pages include different files, so we use a hash to label the different combinations
3724 3945
 	$hash = md5(implode(' ', array_keys($data)));
@@ -3727,8 +3948,9 @@  discard block
 block discarded – undo
3727 3948
 	$toCache = cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400);
3728 3949
 
3729 3950
 	// Already done?
3730
-	if (!empty($toCache))
3731
-		return true;
3951
+	if (!empty($toCache)) {
3952
+			return true;
3953
+	}
3732 3954
 
3733 3955
 	// No namespaces, sorry!
3734 3956
 	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
@@ -3760,8 +3982,9 @@  discard block
 block discarded – undo
3760 3982
 		$toAdd = file_exists($tempFile) ? $tempFile : false;
3761 3983
 
3762 3984
 		// A minified script should only be loaded asynchronously if all its components wanted to be.
3763
-		if (empty($file['options']['async']))
3764
-			$async = false;
3985
+		if (empty($file['options']['async'])) {
3986
+					$async = false;
3987
+		}
3765 3988
 
3766 3989
 		// The file couldn't be located so it won't be added. Log this error.
3767 3990
 		if (empty($toAdd))
@@ -3821,8 +4044,9 @@  discard block
 block discarded – undo
3821 4044
 	global $modSettings, $smcFunc;
3822 4045
 
3823 4046
 	// Just make up a nice hash...
3824
-	if ($new)
3825
-		return sha1(md5($filename . time()) . mt_rand());
4047
+	if ($new) {
4048
+			return sha1(md5($filename . time()) . mt_rand());
4049
+	}
3826 4050
 
3827 4051
 	// Just make sure that attachment id is only a int
3828 4052
 	$attachment_id = (int) $attachment_id;
@@ -3839,23 +4063,25 @@  discard block
 block discarded – undo
3839 4063
 				'id_attach' => $attachment_id,
3840 4064
 			));
3841 4065
 
3842
-		if ($smcFunc['db_num_rows']($request) === 0)
3843
-			return false;
4066
+		if ($smcFunc['db_num_rows']($request) === 0) {
4067
+					return false;
4068
+		}
3844 4069
 
3845 4070
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3846 4071
 		$smcFunc['db_free_result']($request);
3847 4072
 	}
3848 4073
 
3849 4074
 	// Still no hash? mmm...
3850
-	if (empty($file_hash))
3851
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
4075
+	if (empty($file_hash)) {
4076
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
4077
+	}
3852 4078
 
3853 4079
 	// Are we using multiple directories?
3854
-	if (is_array($modSettings['attachmentUploadDir']))
3855
-		$path = $modSettings['attachmentUploadDir'][$dir];
3856
-
3857
-	else
3858
-		$path = $modSettings['attachmentUploadDir'];
4080
+	if (is_array($modSettings['attachmentUploadDir'])) {
4081
+			$path = $modSettings['attachmentUploadDir'][$dir];
4082
+	} else {
4083
+			$path = $modSettings['attachmentUploadDir'];
4084
+	}
3859 4085
 
3860 4086
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3861 4087
 }
@@ -3870,8 +4096,9 @@  discard block
 block discarded – undo
3870 4096
 function ip2range($fullip)
3871 4097
 {
3872 4098
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3873
-	if ($fullip == 'unknown')
3874
-		$fullip = '255.255.255.255';
4099
+	if ($fullip == 'unknown') {
4100
+			$fullip = '255.255.255.255';
4101
+	}
3875 4102
 
3876 4103
 	$ip_parts = explode('-', $fullip);
3877 4104
 	$ip_array = array();
@@ -3895,10 +4122,11 @@  discard block
 block discarded – undo
3895 4122
 		$ip_array['low'] = $ip_parts[0];
3896 4123
 		$ip_array['high'] = $ip_parts[1];
3897 4124
 		return $ip_array;
3898
-	}
3899
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4125
+	} elseif (count($ip_parts) == 2) {
4126
+		// if ip 22.22.*-22.22.*
3900 4127
 	{
3901 4128
 		$valid_low = isValidIP($ip_parts[0]);
4129
+	}
3902 4130
 		$valid_high = isValidIP($ip_parts[1]);
3903 4131
 		$count = 0;
3904 4132
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3913,7 +4141,9 @@  discard block
 block discarded – undo
3913 4141
 				$ip_parts[0] .= $mode . $min;
3914 4142
 				$valid_low = isValidIP($ip_parts[0]);
3915 4143
 				$count++;
3916
-				if ($count > 9) break;
4144
+				if ($count > 9) {
4145
+					break;
4146
+				}
3917 4147
 			}
3918 4148
 		}
3919 4149
 
@@ -3927,7 +4157,9 @@  discard block
 block discarded – undo
3927 4157
 				$ip_parts[1] .= $mode . $max;
3928 4158
 				$valid_high = isValidIP($ip_parts[1]);
3929 4159
 				$count++;
3930
-				if ($count > 9) break;
4160
+				if ($count > 9) {
4161
+					break;
4162
+				}
3931 4163
 			}
3932 4164
 		}
3933 4165
 
@@ -3952,46 +4184,54 @@  discard block
 block discarded – undo
3952 4184
 {
3953 4185
 	global $modSettings;
3954 4186
 
3955
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3956
-		return $host;
4187
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4188
+			return $host;
4189
+	}
3957 4190
 	$t = microtime();
3958 4191
 
3959 4192
 	// Try the Linux host command, perhaps?
3960 4193
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3961 4194
 	{
3962
-		if (!isset($modSettings['host_to_dis']))
3963
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3964
-		else
3965
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4195
+		if (!isset($modSettings['host_to_dis'])) {
4196
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4197
+		} else {
4198
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4199
+		}
3966 4200
 
3967 4201
 		// Did host say it didn't find anything?
3968
-		if (strpos($test, 'not found') !== false)
3969
-			$host = '';
4202
+		if (strpos($test, 'not found') !== false) {
4203
+					$host = '';
4204
+		}
3970 4205
 		// Invalid server option?
3971
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3972
-			updateSettings(array('host_to_dis' => 1));
4206
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4207
+					updateSettings(array('host_to_dis' => 1));
4208
+		}
3973 4209
 		// Maybe it found something, after all?
3974
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3975
-			$host = $match[1];
4210
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4211
+					$host = $match[1];
4212
+		}
3976 4213
 	}
3977 4214
 
3978 4215
 	// This is nslookup; usually only Windows, but possibly some Unix?
3979 4216
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3980 4217
 	{
3981 4218
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3982
-		if (strpos($test, 'Non-existent domain') !== false)
3983
-			$host = '';
3984
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3985
-			$host = $match[1];
4219
+		if (strpos($test, 'Non-existent domain') !== false) {
4220
+					$host = '';
4221
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4222
+					$host = $match[1];
4223
+		}
3986 4224
 	}
3987 4225
 
3988 4226
 	// This is the last try :/.
3989
-	if (!isset($host) || $host === false)
3990
-		$host = @gethostbyaddr($ip);
4227
+	if (!isset($host) || $host === false) {
4228
+			$host = @gethostbyaddr($ip);
4229
+	}
3991 4230
 
3992 4231
 	// It took a long time, so let's cache it!
3993
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3994
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4232
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4233
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4234
+	}
3995 4235
 
3996 4236
 	return $host;
3997 4237
 }
@@ -4027,20 +4267,21 @@  discard block
 block discarded – undo
4027 4267
 			{
4028 4268
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
4029 4269
 				$total = 0;
4030
-				for ($i = 0; $i < $max_chars; $i++)
4031
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4270
+				for ($i = 0; $i < $max_chars; $i++) {
4271
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4272
+				}
4032 4273
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
4033 4274
 			}
4034 4275
 		}
4035 4276
 		return array_unique($returned_ints);
4036
-	}
4037
-	else
4277
+	} else
4038 4278
 	{
4039 4279
 		// Trim characters before and after and add slashes for database insertion.
4040 4280
 		$returned_words = array();
4041
-		foreach ($words as $word)
4042
-			if (($word = trim($word, '-_\'')) !== '')
4281
+		foreach ($words as $word) {
4282
+					if (($word = trim($word, '-_\'')) !== '')
4043 4283
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4284
+		}
4044 4285
 
4045 4286
 		// Filter out all words that occur more than once.
4046 4287
 		return array_unique($returned_words);
@@ -4062,16 +4303,18 @@  discard block
 block discarded – undo
4062 4303
 	global $settings, $txt;
4063 4304
 
4064 4305
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4065
-	if (function_exists('template_create_button') && !$force_use)
4066
-		return template_create_button($name, $alt, $label = '', $custom = '');
4306
+	if (function_exists('template_create_button') && !$force_use) {
4307
+			return template_create_button($name, $alt, $label = '', $custom = '');
4308
+	}
4067 4309
 
4068
-	if (!$settings['use_image_buttons'])
4069
-		return $txt[$alt];
4070
-	elseif (!empty($settings['use_buttons']))
4071
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4072
-	else
4073
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4074
-}
4310
+	if (!$settings['use_image_buttons']) {
4311
+			return $txt[$alt];
4312
+	} elseif (!empty($settings['use_buttons'])) {
4313
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4314
+	} else {
4315
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4316
+	}
4317
+	}
4075 4318
 
4076 4319
 /**
4077 4320
  * Sets up all of the top menu buttons
@@ -4114,9 +4357,10 @@  discard block
 block discarded – undo
4114 4357
 	var user_menus = new smc_PopupMenu();
4115 4358
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4116 4359
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4117
-		if ($context['allow_pm'])
4118
-			addInlineJavaScript('
4360
+		if ($context['allow_pm']) {
4361
+					addInlineJavaScript('
4119 4362
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4363
+		}
4120 4364
 
4121 4365
 		if (!empty($modSettings['enable_ajax_alerts']))
4122 4366
 		{
@@ -4276,88 +4520,96 @@  discard block
 block discarded – undo
4276 4520
 
4277 4521
 		// Now we put the buttons in the context so the theme can use them.
4278 4522
 		$menu_buttons = array();
4279
-		foreach ($buttons as $act => $button)
4280
-			if (!empty($button['show']))
4523
+		foreach ($buttons as $act => $button) {
4524
+					if (!empty($button['show']))
4281 4525
 			{
4282 4526
 				$button['active_button'] = false;
4527
+		}
4283 4528
 
4284 4529
 				// This button needs some action.
4285
-				if (isset($button['action_hook']))
4286
-					$needs_action_hook = true;
4530
+				if (isset($button['action_hook'])) {
4531
+									$needs_action_hook = true;
4532
+				}
4287 4533
 
4288 4534
 				// Make sure the last button truly is the last button.
4289 4535
 				if (!empty($button['is_last']))
4290 4536
 				{
4291
-					if (isset($last_button))
4292
-						unset($menu_buttons[$last_button]['is_last']);
4537
+					if (isset($last_button)) {
4538
+											unset($menu_buttons[$last_button]['is_last']);
4539
+					}
4293 4540
 					$last_button = $act;
4294 4541
 				}
4295 4542
 
4296 4543
 				// Go through the sub buttons if there are any.
4297
-				if (!empty($button['sub_buttons']))
4298
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4544
+				if (!empty($button['sub_buttons'])) {
4545
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4299 4546
 					{
4300 4547
 						if (empty($subbutton['show']))
4301 4548
 							unset($button['sub_buttons'][$key]);
4549
+				}
4302 4550
 
4303 4551
 						// 2nd level sub buttons next...
4304 4552
 						if (!empty($subbutton['sub_buttons']))
4305 4553
 						{
4306 4554
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4307 4555
 							{
4308
-								if (empty($sub_button2['show']))
4309
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4556
+								if (empty($sub_button2['show'])) {
4557
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4558
+								}
4310 4559
 							}
4311 4560
 						}
4312 4561
 					}
4313 4562
 
4314 4563
 				// Does this button have its own icon?
4315
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4316
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4317
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4318
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4319
-				elseif (isset($button['icon']))
4320
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4321
-				else
4322
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4564
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4565
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4566
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4567
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4568
+				} elseif (isset($button['icon'])) {
4569
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4570
+				} else {
4571
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4572
+				}
4323 4573
 
4324 4574
 				$menu_buttons[$act] = $button;
4325 4575
 			}
4326 4576
 
4327
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4328
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4577
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4578
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4579
+		}
4329 4580
 	}
4330 4581
 
4331 4582
 	$context['menu_buttons'] = $menu_buttons;
4332 4583
 
4333 4584
 	// Logging out requires the session id in the url.
4334
-	if (isset($context['menu_buttons']['logout']))
4335
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4585
+	if (isset($context['menu_buttons']['logout'])) {
4586
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4587
+	}
4336 4588
 
4337 4589
 	// Figure out which action we are doing so we can set the active tab.
4338 4590
 	// Default to home.
4339 4591
 	$current_action = 'home';
4340 4592
 
4341
-	if (isset($context['menu_buttons'][$context['current_action']]))
4342
-		$current_action = $context['current_action'];
4343
-	elseif ($context['current_action'] == 'search2')
4344
-		$current_action = 'search';
4345
-	elseif ($context['current_action'] == 'theme')
4346
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4347
-	elseif ($context['current_action'] == 'register2')
4348
-		$current_action = 'register';
4349
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4350
-		$current_action = 'login';
4351
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4352
-		$current_action = 'moderate';
4593
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4594
+			$current_action = $context['current_action'];
4595
+	} elseif ($context['current_action'] == 'search2') {
4596
+			$current_action = 'search';
4597
+	} elseif ($context['current_action'] == 'theme') {
4598
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4599
+	} elseif ($context['current_action'] == 'register2') {
4600
+			$current_action = 'register';
4601
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4602
+			$current_action = 'login';
4603
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4604
+			$current_action = 'moderate';
4605
+	}
4353 4606
 
4354 4607
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4355 4608
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4356 4609
 	{
4357 4610
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4358 4611
 		$context[$current_action] = true;
4359
-	}
4360
-	elseif ($context['current_action'] == 'pm')
4612
+	} elseif ($context['current_action'] == 'pm')
4361 4613
 	{
4362 4614
 		$current_action = 'self_pm';
4363 4615
 		$context['self_pm'] = true;
@@ -4414,12 +4666,14 @@  discard block
 block discarded – undo
4414 4666
 	}
4415 4667
 
4416 4668
 	// Not all actions are simple.
4417
-	if (!empty($needs_action_hook))
4418
-		call_integration_hook('integrate_current_action', array(&$current_action));
4669
+	if (!empty($needs_action_hook)) {
4670
+			call_integration_hook('integrate_current_action', array(&$current_action));
4671
+	}
4419 4672
 
4420
-	if (isset($context['menu_buttons'][$current_action]))
4421
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4422
-}
4673
+	if (isset($context['menu_buttons'][$current_action])) {
4674
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4675
+	}
4676
+	}
4423 4677
 
4424 4678
 /**
4425 4679
  * Generate a random seed and ensure it's stored in settings.
@@ -4443,30 +4697,35 @@  discard block
 block discarded – undo
4443 4697
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4444 4698
 	global $context, $txt;
4445 4699
 
4446
-	if ($db_show_debug === true)
4447
-		$context['debug']['hooks'][] = $hook;
4700
+	if ($db_show_debug === true) {
4701
+			$context['debug']['hooks'][] = $hook;
4702
+	}
4448 4703
 
4449 4704
 	// Need to have some control.
4450
-	if (!isset($context['instances']))
4451
-		$context['instances'] = array();
4705
+	if (!isset($context['instances'])) {
4706
+			$context['instances'] = array();
4707
+	}
4452 4708
 
4453 4709
 	$results = array();
4454
-	if (empty($modSettings[$hook]))
4455
-		return $results;
4710
+	if (empty($modSettings[$hook])) {
4711
+			return $results;
4712
+	}
4456 4713
 
4457 4714
 	$functions = explode(',', $modSettings[$hook]);
4458 4715
 	// Loop through each function.
4459 4716
 	foreach ($functions as $function)
4460 4717
 	{
4461 4718
 		// Hook has been marked as "disabled". Skip it!
4462
-		if (strpos($function, '!') !== false)
4463
-			continue;
4719
+		if (strpos($function, '!') !== false) {
4720
+					continue;
4721
+		}
4464 4722
 
4465 4723
 		$call = call_helper($function, true);
4466 4724
 
4467 4725
 		// Is it valid?
4468
-		if (!empty($call))
4469
-			$results[$function] = call_user_func_array($call, $parameters);
4726
+		if (!empty($call)) {
4727
+					$results[$function] = call_user_func_array($call, $parameters);
4728
+		}
4470 4729
 
4471 4730
 		// Whatever it was suppose to call, it failed :(
4472 4731
 		elseif (!empty($function))
@@ -4482,8 +4741,9 @@  discard block
 block discarded – undo
4482 4741
 			}
4483 4742
 
4484 4743
 			// "Assume" the file resides on $boarddir somewhere...
4485
-			else
4486
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4744
+			else {
4745
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4746
+			}
4487 4747
 		}
4488 4748
 	}
4489 4749
 
@@ -4505,12 +4765,14 @@  discard block
 block discarded – undo
4505 4765
 	global $smcFunc, $modSettings;
4506 4766
 
4507 4767
 	// Any objects?
4508
-	if ($object)
4509
-		$function = $function . '#';
4768
+	if ($object) {
4769
+			$function = $function . '#';
4770
+	}
4510 4771
 
4511 4772
 	// Any files  to load?
4512
-	if (!empty($file) && is_string($file))
4513
-		$function = $file . (!empty($function) ? '|' . $function : '');
4773
+	if (!empty($file) && is_string($file)) {
4774
+			$function = $file . (!empty($function) ? '|' . $function : '');
4775
+	}
4514 4776
 
4515 4777
 	// Get the correct string.
4516 4778
 	$integration_call = $function;
@@ -4532,13 +4794,14 @@  discard block
 block discarded – undo
4532 4794
 		if (!empty($current_functions))
4533 4795
 		{
4534 4796
 			$current_functions = explode(',', $current_functions);
4535
-			if (in_array($integration_call, $current_functions))
4536
-				return;
4797
+			if (in_array($integration_call, $current_functions)) {
4798
+							return;
4799
+			}
4537 4800
 
4538 4801
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4802
+		} else {
4803
+					$permanent_functions = array($integration_call);
4539 4804
 		}
4540
-		else
4541
-			$permanent_functions = array($integration_call);
4542 4805
 
4543 4806
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4544 4807
 	}
@@ -4547,8 +4810,9 @@  discard block
 block discarded – undo
4547 4810
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4548 4811
 
4549 4812
 	// Do nothing, if it's already there.
4550
-	if (in_array($integration_call, $functions))
4551
-		return;
4813
+	if (in_array($integration_call, $functions)) {
4814
+			return;
4815
+	}
4552 4816
 
4553 4817
 	$functions[] = $integration_call;
4554 4818
 	$modSettings[$hook] = implode(',', $functions);
@@ -4571,12 +4835,14 @@  discard block
 block discarded – undo
4571 4835
 	global $smcFunc, $modSettings;
4572 4836
 
4573 4837
 	// Any objects?
4574
-	if ($object)
4575
-		$function = $function . '#';
4838
+	if ($object) {
4839
+			$function = $function . '#';
4840
+	}
4576 4841
 
4577 4842
 	// Any files  to load?
4578
-	if (!empty($file) && is_string($file))
4579
-		$function = $file . '|' . $function;
4843
+	if (!empty($file) && is_string($file)) {
4844
+			$function = $file . '|' . $function;
4845
+	}
4580 4846
 
4581 4847
 	// Get the correct string.
4582 4848
 	$integration_call = $function;
@@ -4597,16 +4863,18 @@  discard block
 block discarded – undo
4597 4863
 	{
4598 4864
 		$current_functions = explode(',', $current_functions);
4599 4865
 
4600
-		if (in_array($integration_call, $current_functions))
4601
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4866
+		if (in_array($integration_call, $current_functions)) {
4867
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4868
+		}
4602 4869
 	}
4603 4870
 
4604 4871
 	// Turn the function list into something usable.
4605 4872
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4606 4873
 
4607 4874
 	// You can only remove it if it's available.
4608
-	if (!in_array($integration_call, $functions))
4609
-		return;
4875
+	if (!in_array($integration_call, $functions)) {
4876
+			return;
4877
+	}
4610 4878
 
4611 4879
 	$functions = array_diff($functions, array($integration_call));
4612 4880
 	$modSettings[$hook] = implode(',', $functions);
@@ -4627,17 +4895,20 @@  discard block
 block discarded – undo
4627 4895
 	global $context, $smcFunc, $txt, $db_show_debug;
4628 4896
 
4629 4897
 	// Really?
4630
-	if (empty($string))
4631
-		return false;
4898
+	if (empty($string)) {
4899
+			return false;
4900
+	}
4632 4901
 
4633 4902
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4634 4903
 	// A closure? should be a callable one.
4635
-	if (is_array($string) || $string instanceof Closure)
4636
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4904
+	if (is_array($string) || $string instanceof Closure) {
4905
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4906
+	}
4637 4907
 
4638 4908
 	// No full objects, sorry! pass a method or a property instead!
4639
-	if (is_object($string))
4640
-		return false;
4909
+	if (is_object($string)) {
4910
+			return false;
4911
+	}
4641 4912
 
4642 4913
 	// Stay vitaminized my friends...
4643 4914
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4646,8 +4917,9 @@  discard block
 block discarded – undo
4646 4917
 	$string = load_file($string);
4647 4918
 
4648 4919
 	// Loaded file failed
4649
-	if (empty($string))
4650
-		return false;
4920
+	if (empty($string)) {
4921
+			return false;
4922
+	}
4651 4923
 
4652 4924
 	// Found a method.
4653 4925
 	if (strpos($string, '::') !== false)
@@ -4668,8 +4940,9 @@  discard block
 block discarded – undo
4668 4940
 				// Add another one to the list.
4669 4941
 				if ($db_show_debug === true)
4670 4942
 				{
4671
-					if (!isset($context['debug']['instances']))
4672
-						$context['debug']['instances'] = array();
4943
+					if (!isset($context['debug']['instances'])) {
4944
+											$context['debug']['instances'] = array();
4945
+					}
4673 4946
 
4674 4947
 					$context['debug']['instances'][$class] = $class;
4675 4948
 				}
@@ -4679,13 +4952,15 @@  discard block
 block discarded – undo
4679 4952
 		}
4680 4953
 
4681 4954
 		// Right then. This is a call to a static method.
4682
-		else
4683
-			$func = array($class, $method);
4955
+		else {
4956
+					$func = array($class, $method);
4957
+		}
4684 4958
 	}
4685 4959
 
4686 4960
 	// Nope! just a plain regular function.
4687
-	else
4688
-		$func = $string;
4961
+	else {
4962
+			$func = $string;
4963
+	}
4689 4964
 
4690 4965
 	// Right, we got what we need, time to do some checks.
4691 4966
 	if (!is_callable($func, false, $callable_name))
@@ -4701,17 +4976,18 @@  discard block
 block discarded – undo
4701 4976
 	else
4702 4977
 	{
4703 4978
 		// What are we gonna do about it?
4704
-		if ($return)
4705
-			return $func;
4979
+		if ($return) {
4980
+					return $func;
4981
+		}
4706 4982
 
4707 4983
 		// If this is a plain function, avoid the heat of calling call_user_func().
4708 4984
 		else
4709 4985
 		{
4710
-			if (is_array($func))
4711
-				call_user_func($func);
4712
-
4713
-			else
4714
-				$func();
4986
+			if (is_array($func)) {
4987
+							call_user_func($func);
4988
+			} else {
4989
+							$func();
4990
+			}
4715 4991
 		}
4716 4992
 	}
4717 4993
 }
@@ -4728,31 +5004,34 @@  discard block
 block discarded – undo
4728 5004
 {
4729 5005
 	global $sourcedir, $txt, $boarddir, $settings;
4730 5006
 
4731
-	if (empty($string))
4732
-		return false;
5007
+	if (empty($string)) {
5008
+			return false;
5009
+	}
4733 5010
 
4734 5011
 	if (strpos($string, '|') !== false)
4735 5012
 	{
4736 5013
 		list ($file, $string) = explode('|', $string);
4737 5014
 
4738 5015
 		// Match the wildcards to their regular vars.
4739
-		if (empty($settings['theme_dir']))
4740
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4741
-
4742
-		else
4743
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5016
+		if (empty($settings['theme_dir'])) {
5017
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5018
+		} else {
5019
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5020
+		}
4744 5021
 
4745 5022
 		// Load the file if it can be loaded.
4746
-		if (file_exists($absPath))
4747
-			require_once($absPath);
5023
+		if (file_exists($absPath)) {
5024
+					require_once($absPath);
5025
+		}
4748 5026
 
4749 5027
 		// No? try a fallback to $sourcedir
4750 5028
 		else
4751 5029
 		{
4752 5030
 			$absPath = $sourcedir .'/'. $file;
4753 5031
 
4754
-			if (file_exists($absPath))
4755
-				require_once($absPath);
5032
+			if (file_exists($absPath)) {
5033
+							require_once($absPath);
5034
+			}
4756 5035
 
4757 5036
 			// Sorry, can't do much for you at this point.
4758 5037
 			else
@@ -4779,8 +5058,9 @@  discard block
 block discarded – undo
4779 5058
 	global $user_info, $smcFunc;
4780 5059
 
4781 5060
 	// Make sure we have something to work with.
4782
-	if (empty($topic))
4783
-		return array();
5061
+	if (empty($topic)) {
5062
+			return array();
5063
+	}
4784 5064
 
4785 5065
 
4786 5066
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4803,8 +5083,9 @@  discard block
 block discarded – undo
4803 5083
 				'topic' => $topic,
4804 5084
 			)
4805 5085
 		);
4806
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4807
-			$temp[] = (int) $row['content_id'];
5086
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5087
+					$temp[] = (int) $row['content_id'];
5088
+		}
4808 5089
 
4809 5090
 		cache_put_data($cache_key, $temp, $ttl);
4810 5091
 	}
@@ -4825,8 +5106,9 @@  discard block
 block discarded – undo
4825 5106
 {
4826 5107
 	global $context;
4827 5108
 
4828
-	if (empty($string))
4829
-		return $string;
5109
+	if (empty($string)) {
5110
+			return $string;
5111
+	}
4830 5112
 
4831 5113
 	// UTF-8 occurences of MS special characters
4832 5114
 	$findchars_utf8 = array(
@@ -4867,10 +5149,11 @@  discard block
 block discarded – undo
4867 5149
 		'--',	// &mdash;
4868 5150
 	);
4869 5151
 
4870
-	if ($context['utf8'])
4871
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4872
-	else
4873
-		$string = str_replace($findchars_iso, $replacechars, $string);
5152
+	if ($context['utf8']) {
5153
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5154
+	} else {
5155
+			$string = str_replace($findchars_iso, $replacechars, $string);
5156
+	}
4874 5157
 
4875 5158
 	return $string;
4876 5159
 }
@@ -4889,49 +5172,59 @@  discard block
 block discarded – undo
4889 5172
 {
4890 5173
 	global $context;
4891 5174
 
4892
-	if (!isset($matches[2]))
4893
-		return '';
5175
+	if (!isset($matches[2])) {
5176
+			return '';
5177
+	}
4894 5178
 
4895 5179
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4896 5180
 
4897 5181
 	// remove left to right / right to left overrides
4898
-	if ($num === 0x202D || $num === 0x202E)
4899
-		return '';
5182
+	if ($num === 0x202D || $num === 0x202E) {
5183
+			return '';
5184
+	}
4900 5185
 
4901 5186
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4902
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4903
-		return '&#' . $num . ';';
5187
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5188
+			return '&#' . $num . ';';
5189
+	}
4904 5190
 
4905 5191
 	if (empty($context['utf8']))
4906 5192
 	{
4907 5193
 		// no control characters
4908
-		if ($num < 0x20)
4909
-			return '';
5194
+		if ($num < 0x20) {
5195
+					return '';
5196
+		}
4910 5197
 		// text is text
4911
-		elseif ($num < 0x80)
4912
-			return chr($num);
5198
+		elseif ($num < 0x80) {
5199
+					return chr($num);
5200
+		}
4913 5201
 		// all others get html-ised
4914
-		else
4915
-			return '&#' . $matches[2] . ';';
4916
-	}
4917
-	else
5202
+		else {
5203
+					return '&#' . $matches[2] . ';';
5204
+		}
5205
+	} else
4918 5206
 	{
4919 5207
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4920 5208
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4921
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4922
-			return '';
5209
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5210
+					return '';
5211
+		}
4923 5212
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4924
-		elseif ($num < 0x80)
4925
-			return chr($num);
5213
+		elseif ($num < 0x80) {
5214
+					return chr($num);
5215
+		}
4926 5216
 		// <0x800 (2048)
4927
-		elseif ($num < 0x800)
4928
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5217
+		elseif ($num < 0x800) {
5218
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5219
+		}
4929 5220
 		// < 0x10000 (65536)
4930
-		elseif ($num < 0x10000)
4931
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5221
+		elseif ($num < 0x10000) {
5222
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5223
+		}
4932 5224
 		// <= 0x10FFFF (1114111)
4933
-		else
4934
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5225
+		else {
5226
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5227
+		}
4935 5228
 	}
4936 5229
 }
4937 5230
 
@@ -4947,28 +5240,34 @@  discard block
 block discarded – undo
4947 5240
  */
4948 5241
 function fixchar__callback($matches)
4949 5242
 {
4950
-	if (!isset($matches[1]))
4951
-		return '';
5243
+	if (!isset($matches[1])) {
5244
+			return '';
5245
+	}
4952 5246
 
4953 5247
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4954 5248
 
4955 5249
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4956 5250
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4957
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4958
-		return '';
5251
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5252
+			return '';
5253
+	}
4959 5254
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4960
-	elseif ($num < 0x80)
4961
-		return chr($num);
5255
+	elseif ($num < 0x80) {
5256
+			return chr($num);
5257
+	}
4962 5258
 	// <0x800 (2048)
4963
-	elseif ($num < 0x800)
4964
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5259
+	elseif ($num < 0x800) {
5260
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5261
+	}
4965 5262
 	// < 0x10000 (65536)
4966
-	elseif ($num < 0x10000)
4967
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5263
+	elseif ($num < 0x10000) {
5264
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5265
+	}
4968 5266
 	// <= 0x10FFFF (1114111)
4969
-	else
4970
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4971
-}
5267
+	else {
5268
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5269
+	}
5270
+	}
4972 5271
 
4973 5272
 /**
4974 5273
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4981,17 +5280,19 @@  discard block
 block discarded – undo
4981 5280
  */
4982 5281
 function entity_fix__callback($matches)
4983 5282
 {
4984
-	if (!isset($matches[2]))
4985
-		return '';
5283
+	if (!isset($matches[2])) {
5284
+			return '';
5285
+	}
4986 5286
 
4987 5287
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4988 5288
 
4989 5289
 	// we don't allow control characters, characters out of range, byte markers, etc
4990
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4991
-		return '';
4992
-	else
4993
-		return '&#' . $num . ';';
4994
-}
5290
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5291
+			return '';
5292
+	} else {
5293
+			return '&#' . $num . ';';
5294
+	}
5295
+	}
4995 5296
 
4996 5297
 /**
4997 5298
  * Return a Gravatar URL based on
@@ -5015,18 +5316,23 @@  discard block
 block discarded – undo
5015 5316
 		$ratings = array('G', 'PG', 'R', 'X');
5016 5317
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
5017 5318
 		$url_params = array();
5018
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
5019
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5020
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
5021
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5022
-		if (!empty($modSettings['avatar_max_width_external']))
5023
-			$size_string = (int) $modSettings['avatar_max_width_external'];
5024
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
5025
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5319
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5320
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5321
+		}
5322
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5323
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5324
+		}
5325
+		if (!empty($modSettings['avatar_max_width_external'])) {
5326
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5327
+		}
5328
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5329
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5026 5330
 				$size_string = $modSettings['avatar_max_height_external'];
5331
+		}
5027 5332
 
5028
-		if (!empty($size_string))
5029
-			$url_params[] = 's=' . $size_string;
5333
+		if (!empty($size_string)) {
5334
+					$url_params[] = 's=' . $size_string;
5335
+		}
5030 5336
 	}
5031 5337
 	$http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www';
5032 5338
 
@@ -5045,22 +5351,26 @@  discard block
 block discarded – undo
5045 5351
 	static $timezones = null, $lastwhen = null;
5046 5352
 
5047 5353
 	// No point doing this over if we already did it once
5048
-	if (!empty($timezones) && $when == $lastwhen)
5049
-		return $timezones;
5050
-	else
5051
-		$lastwhen = $when;
5354
+	if (!empty($timezones) && $when == $lastwhen) {
5355
+			return $timezones;
5356
+	} else {
5357
+			$lastwhen = $when;
5358
+	}
5052 5359
 
5053 5360
 	// Parseable datetime string?
5054
-	if (is_int($timestamp = strtotime($when)))
5055
-		$when = $timestamp;
5361
+	if (is_int($timestamp = strtotime($when))) {
5362
+			$when = $timestamp;
5363
+	}
5056 5364
 
5057 5365
 	// A Unix timestamp?
5058
-	elseif (is_numeric($when))
5059
-		$when = intval($when);
5366
+	elseif (is_numeric($when)) {
5367
+			$when = intval($when);
5368
+	}
5060 5369
 
5061 5370
 	// Invalid value? Just get current Unix timestamp.
5062
-	else
5063
-		$when = time();
5371
+	else {
5372
+			$when = time();
5373
+	}
5064 5374
 
5065 5375
 	// We'll need these too
5066 5376
 	$date_when = date_create('@' . $when);
@@ -5124,8 +5434,9 @@  discard block
 block discarded – undo
5124 5434
 	foreach ($priority_countries as $country)
5125 5435
 	{
5126 5436
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5127
-		if (!empty($country_tzids))
5128
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5437
+		if (!empty($country_tzids)) {
5438
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5439
+		}
5129 5440
 	}
5130 5441
 
5131 5442
 	// Process the preferred timezones first, then the rest.
@@ -5135,8 +5446,9 @@  discard block
 block discarded – undo
5135 5446
 	foreach ($tzids as $tzid)
5136 5447
 	{
5137 5448
 		// We don't want UTC right now
5138
-		if ($tzid == 'UTC')
5139
-			continue;
5449
+		if ($tzid == 'UTC') {
5450
+					continue;
5451
+		}
5140 5452
 
5141 5453
 		$tz = timezone_open($tzid);
5142 5454
 
@@ -5157,8 +5469,9 @@  discard block
 block discarded – undo
5157 5469
 		}
5158 5470
 
5159 5471
 		// A time zone from a prioritized country?
5160
-		if (in_array($tzid, $priority_tzids))
5161
-			$priority_zones[$tzkey] = true;
5472
+		if (in_array($tzid, $priority_tzids)) {
5473
+					$priority_zones[$tzkey] = true;
5474
+		}
5162 5475
 
5163 5476
 		// Keep track of the location and offset for this tzid
5164 5477
 		$tzid_parts = explode('/', $tzid);
@@ -5177,15 +5490,17 @@  discard block
 block discarded – undo
5177 5490
 	{
5178 5491
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5179 5492
 
5180
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5181
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5182
-		else
5183
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5493
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5494
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5495
+		} else {
5496
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5497
+		}
5184 5498
 
5185
-		if (isset($priority_zones[$tzkey]))
5186
-			$priority_timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5187
-		else
5188
-			$timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5499
+		if (isset($priority_zones[$tzkey])) {
5500
+					$priority_timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5501
+		} else {
5502
+					$timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5503
+		}
5189 5504
 	}
5190 5505
 
5191 5506
 	$timezones = array_merge(
@@ -5239,9 +5554,9 @@  discard block
 block discarded – undo
5239 5554
 			'Indian/Kerguelen' => 'TFT',
5240 5555
 		);
5241 5556
 
5242
-		if (!empty($missing_tz_abbrs[$tzid]))
5243
-			$tz_abbrev = $missing_tz_abbrs[$tzid];
5244
-		else
5557
+		if (!empty($missing_tz_abbrs[$tzid])) {
5558
+					$tz_abbrev = $missing_tz_abbrs[$tzid];
5559
+		} else
5245 5560
 		{
5246 5561
 			// Russia likes to experiment with time zones often, and names them as offsets from Moscow
5247 5562
 			$tz_location = timezone_location_get(timezone_open($tzid));
@@ -5269,8 +5584,9 @@  discard block
 block discarded – undo
5269 5584
  */
5270 5585
 function inet_ptod($ip_address)
5271 5586
 {
5272
-	if (!isValidIP($ip_address))
5273
-		return $ip_address;
5587
+	if (!isValidIP($ip_address)) {
5588
+			return $ip_address;
5589
+	}
5274 5590
 
5275 5591
 	$bin = inet_pton($ip_address);
5276 5592
 	return $bin;
@@ -5282,13 +5598,15 @@  discard block
 block discarded – undo
5282 5598
  */
5283 5599
 function inet_dtop($bin)
5284 5600
 {
5285
-	if(empty($bin))
5286
-		return '';
5601
+	if(empty($bin)) {
5602
+			return '';
5603
+	}
5287 5604
 
5288 5605
 	global $db_type;
5289 5606
 
5290
-	if ($db_type == 'postgresql')
5291
-		return $bin;
5607
+	if ($db_type == 'postgresql') {
5608
+			return $bin;
5609
+	}
5292 5610
 
5293 5611
 	$ip_address = inet_ntop($bin);
5294 5612
 
@@ -5313,26 +5631,32 @@  discard block
 block discarded – undo
5313 5631
  */
5314 5632
 function _safe_serialize($value)
5315 5633
 {
5316
-	if(is_null($value))
5317
-		return 'N;';
5634
+	if(is_null($value)) {
5635
+			return 'N;';
5636
+	}
5318 5637
 
5319
-	if(is_bool($value))
5320
-		return 'b:'. (int) $value .';';
5638
+	if(is_bool($value)) {
5639
+			return 'b:'. (int) $value .';';
5640
+	}
5321 5641
 
5322
-	if(is_int($value))
5323
-		return 'i:'. $value .';';
5642
+	if(is_int($value)) {
5643
+			return 'i:'. $value .';';
5644
+	}
5324 5645
 
5325
-	if(is_float($value))
5326
-		return 'd:'. str_replace(',', '.', $value) .';';
5646
+	if(is_float($value)) {
5647
+			return 'd:'. str_replace(',', '.', $value) .';';
5648
+	}
5327 5649
 
5328
-	if(is_string($value))
5329
-		return 's:'. strlen($value) .':"'. $value .'";';
5650
+	if(is_string($value)) {
5651
+			return 's:'. strlen($value) .':"'. $value .'";';
5652
+	}
5330 5653
 
5331 5654
 	if(is_array($value))
5332 5655
 	{
5333 5656
 		$out = '';
5334
-		foreach($value as $k => $v)
5335
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5657
+		foreach($value as $k => $v) {
5658
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5659
+		}
5336 5660
 
5337 5661
 		return 'a:'. count($value) .':{'. $out .'}';
5338 5662
 	}
@@ -5358,8 +5682,9 @@  discard block
 block discarded – undo
5358 5682
 
5359 5683
 	$out = _safe_serialize($value);
5360 5684
 
5361
-	if (isset($mbIntEnc))
5362
-		mb_internal_encoding($mbIntEnc);
5685
+	if (isset($mbIntEnc)) {
5686
+			mb_internal_encoding($mbIntEnc);
5687
+	}
5363 5688
 
5364 5689
 	return $out;
5365 5690
 }
@@ -5376,8 +5701,9 @@  discard block
 block discarded – undo
5376 5701
 function _safe_unserialize($str)
5377 5702
 {
5378 5703
 	// Input  is not a string.
5379
-	if(empty($str) || !is_string($str))
5380
-		return false;
5704
+	if(empty($str) || !is_string($str)) {
5705
+			return false;
5706
+	}
5381 5707
 
5382 5708
 	$stack = array();
5383 5709
 	$expected = array();
@@ -5393,43 +5719,38 @@  discard block
 block discarded – undo
5393 5719
 	while($state != 1)
5394 5720
 	{
5395 5721
 		$type = isset($str[0]) ? $str[0] : '';
5396
-		if($type == '}')
5397
-			$str = substr($str, 1);
5398
-
5399
-		else if($type == 'N' && $str[1] == ';')
5722
+		if($type == '}') {
5723
+					$str = substr($str, 1);
5724
+		} else if($type == 'N' && $str[1] == ';')
5400 5725
 		{
5401 5726
 			$value = null;
5402 5727
 			$str = substr($str, 2);
5403
-		}
5404
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5728
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5405 5729
 		{
5406 5730
 			$value = $matches[1] == '1' ? true : false;
5407 5731
 			$str = substr($str, 4);
5408
-		}
5409
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5732
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5410 5733
 		{
5411 5734
 			$value = (int)$matches[1];
5412 5735
 			$str = $matches[2];
5413
-		}
5414
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5736
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5415 5737
 		{
5416 5738
 			$value = (float)$matches[1];
5417 5739
 			$str = $matches[3];
5418
-		}
5419
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5740
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5420 5741
 		{
5421 5742
 			$value = substr($matches[2], 0, (int)$matches[1]);
5422 5743
 			$str = substr($matches[2], (int)$matches[1] + 2);
5423
-		}
5424
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5744
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5425 5745
 		{
5426 5746
 			$expectedLength = (int)$matches[1];
5427 5747
 			$str = $matches[2];
5428 5748
 		}
5429 5749
 
5430 5750
 		// Object or unknown/malformed type.
5431
-		else
5432
-			return false;
5751
+		else {
5752
+					return false;
5753
+		}
5433 5754
 
5434 5755
 		switch($state)
5435 5756
 		{
@@ -5457,8 +5778,9 @@  discard block
 block discarded – undo
5457 5778
 				if($type == '}')
5458 5779
 				{
5459 5780
 					// Array size is less than expected.
5460
-					if(count($list) < end($expected))
5461
-						return false;
5781
+					if(count($list) < end($expected)) {
5782
+											return false;
5783
+					}
5462 5784
 
5463 5785
 					unset($list);
5464 5786
 					$list = &$stack[count($stack)-1];
@@ -5467,8 +5789,9 @@  discard block
 block discarded – undo
5467 5789
 					// Go to terminal state if we're at the end of the root array.
5468 5790
 					array_pop($expected);
5469 5791
 
5470
-					if(count($expected) == 0)
5471
-						$state = 1;
5792
+					if(count($expected) == 0) {
5793
+											$state = 1;
5794
+					}
5472 5795
 
5473 5796
 					break;
5474 5797
 				}
@@ -5476,8 +5799,9 @@  discard block
 block discarded – undo
5476 5799
 				if($type == 'i' || $type == 's')
5477 5800
 				{
5478 5801
 					// Array size exceeds expected length.
5479
-					if(count($list) >= end($expected))
5480
-						return false;
5802
+					if(count($list) >= end($expected)) {
5803
+											return false;
5804
+					}
5481 5805
 
5482 5806
 					$key = $value;
5483 5807
 					$state = 3;
@@ -5511,8 +5835,9 @@  discard block
 block discarded – undo
5511 5835
 	}
5512 5836
 
5513 5837
 	// Trailing data in input.
5514
-	if(!empty($str))
5515
-		return false;
5838
+	if(!empty($str)) {
5839
+			return false;
5840
+	}
5516 5841
 
5517 5842
 	return $data;
5518 5843
 }
@@ -5535,8 +5860,9 @@  discard block
 block discarded – undo
5535 5860
 
5536 5861
 	$out = _safe_unserialize($str);
5537 5862
 
5538
-	if (isset($mbIntEnc))
5539
-		mb_internal_encoding($mbIntEnc);
5863
+	if (isset($mbIntEnc)) {
5864
+			mb_internal_encoding($mbIntEnc);
5865
+	}
5540 5866
 
5541 5867
 	return $out;
5542 5868
 }
@@ -5551,12 +5877,14 @@  discard block
 block discarded – undo
5551 5877
 function smf_chmod($file, $value = 0)
5552 5878
 {
5553 5879
 	// No file? no checks!
5554
-	if (empty($file))
5555
-		return false;
5880
+	if (empty($file)) {
5881
+			return false;
5882
+	}
5556 5883
 
5557 5884
 	// Already writable?
5558
-	if (is_writable($file))
5559
-		return true;
5885
+	if (is_writable($file)) {
5886
+			return true;
5887
+	}
5560 5888
 
5561 5889
 	// Do we have a file or a dir?
5562 5890
 	$isDir = is_dir($file);
@@ -5572,10 +5900,9 @@  discard block
 block discarded – undo
5572 5900
 		{
5573 5901
 			$isWritable = true;
5574 5902
 			break;
5903
+		} else {
5904
+					@chmod($file, $val);
5575 5905
 		}
5576
-
5577
-		else
5578
-			@chmod($file, $val);
5579 5906
 	}
5580 5907
 
5581 5908
 	return $isWritable;
@@ -5594,8 +5921,9 @@  discard block
 block discarded – undo
5594 5921
 	global $txt;
5595 5922
 
5596 5923
 	// Come on...
5597
-	if (empty($json) || !is_string($json))
5598
-		return array();
5924
+	if (empty($json) || !is_string($json)) {
5925
+			return array();
5926
+	}
5599 5927
 
5600 5928
 	$returnArray = @json_decode($json, $returnAsArray);
5601 5929
 
@@ -5633,11 +5961,11 @@  discard block
 block discarded – undo
5633 5961
 		$jsonDebug = $jsonDebug[0];
5634 5962
 		loadLanguage('Errors');
5635 5963
 
5636
-		if (!empty($jsonDebug))
5637
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5638
-
5639
-		else
5640
-			log_error($txt['json_'. $jsonError], 'critical');
5964
+		if (!empty($jsonDebug)) {
5965
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5966
+		} else {
5967
+					log_error($txt['json_'. $jsonError], 'critical');
5968
+		}
5641 5969
 
5642 5970
 		// Everyone expects an array.
5643 5971
 		return array();
@@ -5671,8 +5999,9 @@  discard block
 block discarded – undo
5671 5999
 	global $db_show_debug, $modSettings;
5672 6000
 
5673 6001
 	// Defensive programming anyone?
5674
-	if (empty($data))
5675
-		return false;
6002
+	if (empty($data)) {
6003
+			return false;
6004
+	}
5676 6005
 
5677 6006
 	// Don't need extra stuff...
5678 6007
 	$db_show_debug = false;
@@ -5680,11 +6009,11 @@  discard block
 block discarded – undo
5680 6009
 	// Kill anything else.
5681 6010
 	ob_end_clean();
5682 6011
 
5683
-	if (!empty($modSettings['CompressedOutput']))
5684
-		@ob_start('ob_gzhandler');
5685
-
5686
-	else
5687
-		ob_start();
6012
+	if (!empty($modSettings['CompressedOutput'])) {
6013
+			@ob_start('ob_gzhandler');
6014
+	} else {
6015
+			ob_start();
6016
+	}
5688 6017
 
5689 6018
 	// Set the header.
5690 6019
 	header($type);
@@ -5716,8 +6045,9 @@  discard block
 block discarded – undo
5716 6045
 	static $done = false;
5717 6046
 
5718 6047
 	// If we don't need to do anything, don't
5719
-	if (!$update && $done)
5720
-		return;
6048
+	if (!$update && $done) {
6049
+			return;
6050
+	}
5721 6051
 
5722 6052
 	// Should we get a new copy of the official list of TLDs?
5723 6053
 	if ($update)
@@ -5726,8 +6056,9 @@  discard block
 block discarded – undo
5726 6056
 		$tlds = fetch_web_data('https://data.iana.org/TLD/tlds-alpha-by-domain.txt');
5727 6057
 
5728 6058
 		// If the Internet Assigned Numbers Authority can't be reached, the Internet is gone. We're probably running on a server hidden in a bunker deep underground to protect it from marauding bandits roaming on the surface. We don't want to waste precious electricity on pointlessly repeating background tasks, so we'll wait until the next regularly scheduled update to see if civilization has been restored.
5729
-		if ($tlds === false)
5730
-			$postapocalypticNightmare = true;
6059
+		if ($tlds === false) {
6060
+					$postapocalypticNightmare = true;
6061
+		}
5731 6062
 	}
5732 6063
 	// If we aren't updating and the regex is valid, we're done
5733 6064
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -5742,10 +6073,11 @@  discard block
 block discarded – undo
5742 6073
 		// Clean $tlds and convert it to an array
5743 6074
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5744 6075
 			$line = trim($line);
5745
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5746
-				return false;
5747
-			else
5748
-				return true;
6076
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6077
+							return false;
6078
+			} else {
6079
+							return true;
6080
+			}
5749 6081
 		});
5750 6082
 
5751 6083
 		// Convert Punycode to Unicode
@@ -5799,8 +6131,9 @@  discard block
 block discarded – undo
5799 6131
 						$idx += $digit * $w;
5800 6132
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5801 6133
 
5802
-						if ($digit < $t)
5803
-							break;
6134
+						if ($digit < $t) {
6135
+													break;
6136
+						}
5804 6137
 
5805 6138
 						$w = (int) ($w * ($base - $t));
5806 6139
 					}
@@ -5809,8 +6142,9 @@  discard block
 block discarded – undo
5809 6142
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5810 6143
 					$delta += intval($delta / ($deco_len + 1));
5811 6144
 
5812
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5813
-						$delta = intval($delta / ($base - $tmin));
6145
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
6146
+											$delta = intval($delta / ($base - $tmin));
6147
+					}
5814 6148
 
5815 6149
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5816 6150
 					$is_first = false;
@@ -5819,8 +6153,9 @@  discard block
 block discarded – undo
5819 6153
 
5820 6154
 					if ($deco_len > 0)
5821 6155
 					{
5822
-						for ($i = $deco_len; $i > $idx; $i--)
5823
-							$decoded[$i] = $decoded[($i - 1)];
6156
+						for ($i = $deco_len; $i > $idx; $i--) {
6157
+													$decoded[$i] = $decoded[($i - 1)];
6158
+						}
5824 6159
 					}
5825 6160
 					$decoded[$idx++] = $char;
5826 6161
 				}
@@ -5828,24 +6163,29 @@  discard block
 block discarded – undo
5828 6163
 				foreach ($decoded as $k => $v)
5829 6164
 				{
5830 6165
 					// 7bit are transferred literally
5831
-					if ($v < 128)
5832
-						$output .= chr($v);
6166
+					if ($v < 128) {
6167
+											$output .= chr($v);
6168
+					}
5833 6169
 
5834 6170
 					// 2 bytes
5835
-					elseif ($v < (1 << 11))
5836
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6171
+					elseif ($v < (1 << 11)) {
6172
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6173
+					}
5837 6174
 
5838 6175
 					// 3 bytes
5839
-					elseif ($v < (1 << 16))
5840
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6176
+					elseif ($v < (1 << 16)) {
6177
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6178
+					}
5841 6179
 
5842 6180
 					// 4 bytes
5843
-					elseif ($v < (1 << 21))
5844
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6181
+					elseif ($v < (1 << 21)) {
6182
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6183
+					}
5845 6184
 
5846 6185
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5847
-					else
5848
-						$output .= $safe_char;
6186
+					else {
6187
+											$output .= $safe_char;
6188
+					}
5849 6189
 				}
5850 6190
 
5851 6191
 				$output_parts[] = $output;
@@ -5938,8 +6278,7 @@  discard block
 block discarded – undo
5938 6278
 
5939 6279
 		$strlen = 'mb_strlen';
5940 6280
 		$substr = 'mb_substr';
5941
-	}
5942
-	else
6281
+	} else
5943 6282
 	{
5944 6283
 		$strlen = $smcFunc['strlen'];
5945 6284
 		$substr = $smcFunc['substr'];
@@ -5953,20 +6292,21 @@  discard block
 block discarded – undo
5953 6292
 
5954 6293
 		$first = $substr($string, 0, 1);
5955 6294
 
5956
-		if (empty($index[$first]))
5957
-			$index[$first] = array();
6295
+		if (empty($index[$first])) {
6296
+					$index[$first] = array();
6297
+		}
5958 6298
 
5959 6299
 		if ($strlen($string) > 1)
5960 6300
 		{
5961 6301
 			// Sanity check on recursion
5962
-			if ($depth > 99)
5963
-				$index[$first][$substr($string, 1)] = '';
5964
-
5965
-			else
5966
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6302
+			if ($depth > 99) {
6303
+							$index[$first][$substr($string, 1)] = '';
6304
+			} else {
6305
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6306
+			}
6307
+		} else {
6308
+					$index[$first][''] = '';
5967 6309
 		}
5968
-		else
5969
-			$index[$first][''] = '';
5970 6310
 
5971 6311
 		$depth--;
5972 6312
 		return $index;
@@ -5989,9 +6329,9 @@  discard block
 block discarded – undo
5989 6329
 			$key_regex = preg_quote($key, $delim);
5990 6330
 			$new_key = $key;
5991 6331
 
5992
-			if (empty($value))
5993
-				$sub_regex = '';
5994
-			else
6332
+			if (empty($value)) {
6333
+							$sub_regex = '';
6334
+			} else
5995 6335
 			{
5996 6336
 				$sub_regex = $index_to_regex($value, $delim);
5997 6337
 
@@ -5999,22 +6339,22 @@  discard block
 block discarded – undo
5999 6339
 				{
6000 6340
 					$new_key_array = explode('(?'.'>', $sub_regex);
6001 6341
 					$new_key .= $new_key_array[0];
6342
+				} else {
6343
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6002 6344
 				}
6003
-				else
6004
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6005 6345
 			}
6006 6346
 
6007
-			if ($depth > 1)
6008
-				$regex[$new_key] = $key_regex . $sub_regex;
6009
-			else
6347
+			if ($depth > 1) {
6348
+							$regex[$new_key] = $key_regex . $sub_regex;
6349
+			} else
6010 6350
 			{
6011 6351
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
6012 6352
 				{
6013 6353
 					$regex[$new_key] = $key_regex . $sub_regex;
6014 6354
 					unset($index[$key]);
6355
+				} else {
6356
+									break;
6015 6357
 				}
6016
-				else
6017
-					break;
6018 6358
 			}
6019 6359
 		}
6020 6360
 
@@ -6023,10 +6363,11 @@  discard block
 block discarded – undo
6023 6363
 			$l1 = $strlen($k1);
6024 6364
 			$l2 = $strlen($k2);
6025 6365
 
6026
-			if ($l1 == $l2)
6027
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
6028
-			else
6029
-				return $l1 > $l2 ? -1 : 1;
6366
+			if ($l1 == $l2) {
6367
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6368
+			} else {
6369
+							return $l1 > $l2 ? -1 : 1;
6370
+			}
6030 6371
 		});
6031 6372
 
6032 6373
 		$depth--;
@@ -6037,21 +6378,24 @@  discard block
 block discarded – undo
6037 6378
 	$index = array();
6038 6379
 	$regex = '';
6039 6380
 
6040
-	foreach ($strings as $string)
6041
-		$index = $add_string_to_index($string, $index);
6381
+	foreach ($strings as $string) {
6382
+			$index = $add_string_to_index($string, $index);
6383
+	}
6042 6384
 
6043 6385
 	if ($returnArray === true)
6044 6386
 	{
6045 6387
 		$regex = array();
6046
-		while (!empty($index))
6047
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6388
+		while (!empty($index)) {
6389
+					$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6390
+		}
6391
+	} else {
6392
+			$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6048 6393
 	}
6049
-	else
6050
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6051 6394
 
6052 6395
 	// Restore PHP's internal character encoding to whatever it was originally
6053
-	if (!empty($current_encoding))
6054
-		mb_internal_encoding($current_encoding);
6396
+	if (!empty($current_encoding)) {
6397
+			mb_internal_encoding($current_encoding);
6398
+	}
6055 6399
 
6056 6400
 	return $regex;
6057 6401
 }
@@ -6094,13 +6438,15 @@  discard block
 block discarded – undo
6094 6438
 	// Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't...
6095 6439
 	$url = str_ireplace('https://', 'http://', $url) . '/';
6096 6440
 	$headers = @get_headers($url);
6097
-	if ($headers === false)
6098
-		return false;
6441
+	if ($headers === false) {
6442
+			return false;
6443
+	}
6099 6444
 
6100 6445
 	// Now to see if it came back https...
6101 6446
 	// First check for a redirect status code in first row (301, 302, 307)
6102
-	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false)
6103
-		return false;
6447
+	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) {
6448
+			return false;
6449
+	}
6104 6450
 
6105 6451
 	// Search for the location entry to confirm https
6106 6452
 	$result = false;
@@ -6136,8 +6482,7 @@  discard block
 block discarded – undo
6136 6482
 		$is_admin = $user_info['is_admin'];
6137 6483
 		$mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null;
6138 6484
 		$ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null;
6139
-	}
6140
-	else
6485
+	} else
6141 6486
 	{
6142 6487
 		$request = $smcFunc['db_query']('', '
6143 6488
 				SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group
@@ -6151,17 +6496,19 @@  discard block
 block discarded – undo
6151 6496
 
6152 6497
 		$row = $smcFunc['db_fetch_assoc']($request);
6153 6498
 
6154
-		if (empty($row['additional_groups']))
6155
-			$groups = array($row['id_group'], $row['id_post_group']);
6156
-		else
6157
-			$groups = array_merge(
6499
+		if (empty($row['additional_groups'])) {
6500
+					$groups = array($row['id_group'], $row['id_post_group']);
6501
+		} else {
6502
+					$groups = array_merge(
6158 6503
 					array($row['id_group'], $row['id_post_group']),
6159 6504
 					explode(',', $row['additional_groups'])
6160 6505
 			);
6506
+		}
6161 6507
 
6162 6508
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
6163
-		foreach ($groups as $k => $v)
6164
-			$groups[$k] = (int) $v;
6509
+		foreach ($groups as $k => $v) {
6510
+					$groups[$k] = (int) $v;
6511
+		}
6165 6512
 
6166 6513
 		$is_admin = in_array(1, $groups);
6167 6514
 
@@ -6178,8 +6525,9 @@  discard block
 block discarded – undo
6178 6525
 				'current_member' => $userid,
6179 6526
 			)
6180 6527
 		);
6181
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6182
-			$boards_mod[] = $row['id_board'];
6528
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6529
+					$boards_mod[] = $row['id_board'];
6530
+		}
6183 6531
 		$smcFunc['db_free_result']($request);
6184 6532
 
6185 6533
 		// Can any of the groups they're in moderate any of the boards?
@@ -6191,8 +6539,9 @@  discard block
 block discarded – undo
6191 6539
 				'groups' => $groups,
6192 6540
 			)
6193 6541
 		);
6194
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6195
-			$boards_mod[] = $row['id_board'];
6542
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6543
+					$boards_mod[] = $row['id_board'];
6544
+		}
6196 6545
 		$smcFunc['db_free_result']($request);
6197 6546
 
6198 6547
 		// Just in case we've got duplicates here...
@@ -6202,21 +6551,25 @@  discard block
 block discarded – undo
6202 6551
 	}
6203 6552
 
6204 6553
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
6205
-	if ($is_admin)
6206
-		$query_part['query_see_board'] = '1=1';
6554
+	if ($is_admin) {
6555
+			$query_part['query_see_board'] = '1=1';
6556
+	}
6207 6557
 	// Otherwise just the groups in $user_info['groups'].
6208
-	else
6209
-		$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6558
+	else {
6559
+			$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6560
+	}
6210 6561
 
6211 6562
 	// Build the list of boards they WANT to see.
6212 6563
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
6213 6564
 
6214 6565
 	// If they aren't ignoring any boards then they want to see all the boards they can see
6215
-	if (empty($ignoreboards))
6216
-		$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6566
+	if (empty($ignoreboards)) {
6567
+			$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6568
+	}
6217 6569
 	// Ok I guess they don't want to see all the boards
6218
-	else
6219
-		$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6570
+	else {
6571
+			$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6572
+	}
6220 6573
 
6221 6574
 	return $query_part;
6222 6575
 }
@@ -6230,10 +6583,11 @@  discard block
 block discarded – undo
6230 6583
 {
6231 6584
 	$secure = false;
6232 6585
 
6233
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
6234
-		$secure = true;
6235
-	elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
6236
-		$secure = true;
6586
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
6587
+			$secure = true;
6588
+	} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
6589
+			$secure = true;
6590
+	}
6237 6591
 
6238 6592
 	return $secure;
6239 6593
 }
Please login to merge, or discard this patch.
proxy.php 1 patch
Braces   +27 added lines, -18 removed lines patch added patch discarded remove patch
@@ -70,26 +70,31 @@  discard block
 block discarded – undo
70 70
 	 */
71 71
 	public function checkRequest()
72 72
 	{
73
-		if (!$this->enabled)
74
-			return false;
73
+		if (!$this->enabled) {
74
+					return false;
75
+		}
75 76
 
76 77
 		// Try to create the image cache directory if it doesn't exist
77
-		if (!file_exists($this->cache))
78
-			if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php'))
78
+		if (!file_exists($this->cache)) {
79
+					if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php'))
79 80
 				return false;
81
+		}
80 82
 
81
-		if (empty($_GET['hash']) || empty($_GET['request']) || ($_GET['request'] === "http:") || ($_GET['request'] === "https:"))
82
-			return false;
83
+		if (empty($_GET['hash']) || empty($_GET['request']) || ($_GET['request'] === "http:") || ($_GET['request'] === "https:")) {
84
+					return false;
85
+		}
83 86
 
84 87
 		$hash = $_GET['hash'];
85 88
 		$request = $_GET['request'];
86 89
 
87
-		if (md5($request . $this->secret) != $hash)
88
-			return false;
90
+		if (md5($request . $this->secret) != $hash) {
91
+					return false;
92
+		}
89 93
 
90 94
 		// Attempt to cache the request if it doesn't exist
91
-		if (!$this->isCached($request))
92
-			return $this->cacheImage($request);
95
+		if (!$this->isCached($request)) {
96
+					return $this->cacheImage($request);
97
+		}
93 98
 
94 99
 		return true;
95 100
 	}
@@ -126,8 +131,9 @@  discard block
 block discarded – undo
126 131
 		if (!$cached || time() - $cached['time'] > ($this->maxDays * 86400))
127 132
 		{
128 133
 			@unlink($cached_file);
129
-			if ($this->checkRequest())
130
-				$this->serve();
134
+			if ($this->checkRequest()) {
135
+							$this->serve();
136
+			}
131 137
 			$this::redirectexit($request);
132 138
 		}
133 139
 
@@ -140,8 +146,9 @@  discard block
 block discarded – undo
140 146
 
141 147
 		// Make sure we're serving an image
142 148
 		$contentParts = explode('/', !empty($cached['content_type']) ? $cached['content_type'] : '');
143
-		if ($contentParts[0] != 'image')
144
-			exit;
149
+		if ($contentParts[0] != 'image') {
150
+					exit;
151
+		}
145 152
 
146 153
 		$max_age = $time - $cached['time'] + (5 * 86400);
147 154
 		header('content-type: ' . $cached['content_type']);
@@ -200,12 +207,14 @@  discard block
 block discarded – undo
200 207
 
201 208
 		// Make sure the url is returning an image
202 209
 		$contentParts = explode('/', !empty($headers['content-type']) ? $headers['content-type'] : '');
203
-		if ($contentParts[0] != 'image')
204
-			return -1;
210
+		if ($contentParts[0] != 'image') {
211
+					return -1;
212
+		}
205 213
 
206 214
 		// Validate the filesize
207
-		if ($response['size'] > ($this->maxSize * 1024))
208
-			return 0;
215
+		if ($response['size'] > ($this->maxSize * 1024)) {
216
+					return 0;
217
+		}
209 218
 
210 219
 		$time = $this->getTime();
211 220
 
Please login to merge, or discard this patch.