Completed
Push — release-2.1 ( 4bdd41...11eb43 )
by Mathias
07:36
created
Sources/CacheAPI-postgres.php 1 patch
Braces   +28 added lines, -19 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * PostgreSQL Cache API class
@@ -49,8 +50,9 @@  discard block
 block discarded – undo
49 50
 
50 51
 		$result = pg_execute($db_connection, '', array('public', $db_prefix . 'cache'));
51 52
 
52
-		if (pg_affected_rows($result) === 0)
53
-			pg_query($db_connection, 'CREATE UNLOGGED TABLE {db_prefix}cache (key text, value text, ttl bigint, PRIMARY KEY (key))');			
53
+		if (pg_affected_rows($result) === 0) {
54
+					pg_query($db_connection, 'CREATE UNLOGGED TABLE {db_prefix}cache (key text, value text, ttl bigint, PRIMARY KEY (key))');
55
+		}
54 56
 	}
55 57
 
56 58
 	/**
@@ -60,14 +62,16 @@  discard block
 block discarded – undo
60 62
 	{
61 63
 		global $smcFunc, $db_connection;
62 64
 
63
-		if ($smcFunc['db_title'] !== 'PostgreSQL')
64
-			return false;
65
+		if ($smcFunc['db_title'] !== 'PostgreSQL') {
66
+					return false;
67
+		}
65 68
 
66 69
 		$result = pg_query($db_connection, 'SHOW server_version_num');
67 70
 		$res = pg_fetch_assoc($result);
68 71
 		
69
-		if ($res['server_version_num'] < 90500)
70
-			return false;
72
+		if ($res['server_version_num'] < 90500) {
73
+					return false;
74
+		}
71 75
 		
72 76
 		return $test ? true : parent::isSupported();
73 77
 	}
@@ -81,13 +85,15 @@  discard block
 block discarded – undo
81 85
 
82 86
 		$ttl = time() - $ttl;
83 87
 		
84
-		if (empty($this->pg_get_data_prep))
85
-			$this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1');
88
+		if (empty($this->pg_get_data_prep)) {
89
+					$this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1');
90
+		}
86 91
 			
87 92
 		$result = pg_execute($db_connection, 'smf_cache_get_data', array($key, $ttl));
88 93
 		
89
-		if (pg_affected_rows($result) === 0)
90
-			return null;
94
+		if (pg_affected_rows($result) === 0) {
95
+					return null;
96
+		}
91 97
 
92 98
 		$res = pg_fetch_assoc($result);
93 99
 
@@ -101,23 +107,26 @@  discard block
 block discarded – undo
101 107
 	{
102 108
 		global  $db_prefix, $db_connection;
103 109
 
104
-		if (!isset($value))
105
-			$value = '';
110
+		if (!isset($value)) {
111
+					$value = '';
112
+		}
106 113
 
107 114
 		$ttl = time() + $ttl;
108 115
 
109
-		if (empty($this->pg_put_data_prep))
110
-			$this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data',
116
+		if (empty($this->pg_put_data_prep)) {
117
+					$this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data',
111 118
 				'INSERT INTO ' . $db_prefix . 'cache(key,value,ttl) VALUES($1,$2,$3)
112 119
 				ON CONFLICT(key) DO UPDATE SET value = excluded.value, ttl = excluded.ttl'
113 120
 			);
121
+		}
114 122
 
115 123
 		$result = pg_execute($db_connection, 'smf_cache_put_data', array($key, $value, $ttl));
116 124
 
117
-		if (pg_affected_rows($result) > 0)
118
-			return true;
119
-		else
120
-			return false;
125
+		if (pg_affected_rows($result) > 0) {
126
+					return true;
127
+		} else {
128
+					return false;
129
+		}
121 130
 	}
122 131
 
123 132
 	/**
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +785 added lines, -595 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
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,28 +48,36 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65 73
 		// We excpiclity do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded.
66
-		if (!is_array($modSettings['attachmentUploadDir']))
67
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
74
+		if (!is_array($modSettings['attachmentUploadDir'])) {
75
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
76
+		}
68 77
 
69
-		if (!empty($cache_enable))
70
-			cache_put_data('modSettings', $modSettings, 90);
78
+		if (!empty($cache_enable)) {
79
+					cache_put_data('modSettings', $modSettings, 90);
80
+		}
71 81
 	}
72 82
 
73 83
 	$modSettings['cache_enable'] = $cache_enable;
@@ -87,8 +97,9 @@  discard block
 block discarded – undo
87 97
 		};
88 98
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
89 99
 	{
90
-		if (!$utf8 || $smcFunc['db_mb4'])
91
-			return $string;
100
+		if (!$utf8 || $smcFunc['db_mb4']) {
101
+					return $string;
102
+		}
92 103
 
93 104
 		$i = 0;
94 105
 		$len = strlen($string);
@@ -100,18 +111,15 @@  discard block
 block discarded – undo
100 111
 			{
101 112
 				$new_string .= $string[$i];
102 113
 				$i++;
103
-			}
104
-			elseif ($ord < 224)
114
+			} elseif ($ord < 224)
105 115
 			{
106 116
 				$new_string .= $string[$i] . $string[$i + 1];
107 117
 				$i += 2;
108
-			}
109
-			elseif ($ord < 240)
118
+			} elseif ($ord < 240)
110 119
 			{
111 120
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
112 121
 				$i += 3;
113
-			}
114
-			elseif ($ord < 248)
122
+			} elseif ($ord < 248)
115 123
 			{
116 124
 				// Magic happens.
117 125
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -155,8 +163,7 @@  discard block
 block discarded – undo
155 163
 			{
156 164
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
157 165
 				return is_int($result) ? $result + $offset : false;
158
-			}
159
-			else
166
+			} else
160 167
 			{
161 168
 				$needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
162 169
 				$needle_size = count($needle_arr);
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 				while ((int) $result === $result)
166 173
 				{
167 174
 					$offset += $result;
168
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
169
-						return $offset;
175
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
176
+											return $offset;
177
+					}
170 178
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
171 179
 				}
172 180
 				return false;
@@ -204,8 +212,9 @@  discard block
 block discarded – undo
204 212
 			$string = $ent_check($string);
205 213
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
206 214
 			$string = $matches[0];
207
-			while (strlen($string) > $length)
208
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
215
+			while (strlen($string) > $length) {
216
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
217
+			}
209 218
 			return $string;
210 219
 		},
211 220
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -215,8 +224,9 @@  discard block
 block discarded – undo
215 224
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
216 225
 		{
217 226
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
218
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
219
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
227
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
228
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
229
+			}
220 230
 			return implode('', $words);
221 231
 		} : 'ucwords',
222 232
 		'json_decode' => 'smf_json_decode',
@@ -224,16 +234,17 @@  discard block
 block discarded – undo
224 234
 	);
225 235
 
226 236
 	// Setting the timezone is a requirement for some functions.
227
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
228
-		date_default_timezone_set($modSettings['default_timezone']);
229
-	else
237
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
238
+			date_default_timezone_set($modSettings['default_timezone']);
239
+	} else
230 240
 	{
231 241
 		// Get PHP's default timezone, if set
232 242
 		$ini_tz = ini_get('date.timezone');
233
-		if (!empty($ini_tz))
234
-			$modSettings['default_timezone'] = $ini_tz;
235
-		else
236
-			$modSettings['default_timezone'] = '';
243
+		if (!empty($ini_tz)) {
244
+					$modSettings['default_timezone'] = $ini_tz;
245
+		} else {
246
+					$modSettings['default_timezone'] = '';
247
+		}
237 248
 
238 249
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
239 250
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -251,22 +262,26 @@  discard block
 block discarded – undo
251 262
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
252 263
 		{
253 264
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
254
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
255
-				$modSettings['load_average'] = (float) $matches[1];
256
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
257
-				$modSettings['load_average'] = (float) $matches[1];
258
-			else
259
-				unset($modSettings['load_average']);
265
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
266
+							$modSettings['load_average'] = (float) $matches[1];
267
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
268
+							$modSettings['load_average'] = (float) $matches[1];
269
+			} else {
270
+							unset($modSettings['load_average']);
271
+			}
260 272
 
261
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
262
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
273
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
274
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
275
+			}
263 276
 		}
264 277
 
265
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
266
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
278
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
279
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
280
+		}
267 281
 
268
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
269
-			display_loadavg_error();
282
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
283
+					display_loadavg_error();
284
+		}
270 285
 	}
271 286
 
272 287
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -287,8 +302,9 @@  discard block
 block discarded – undo
287 302
 	if (defined('SMF_INTEGRATION_SETTINGS'))
288 303
 	{
289 304
 		$integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true);
290
-		foreach ($integration_settings as $hook => $function)
291
-			add_integration_function($hook, $function, '', false);
305
+		foreach ($integration_settings as $hook => $function) {
306
+					add_integration_function($hook, $function, '', false);
307
+		}
292 308
 	}
293 309
 
294 310
 	// Any files to pre include?
@@ -298,8 +314,9 @@  discard block
 block discarded – undo
298 314
 		foreach ($pre_includes as $include)
299 315
 		{
300 316
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
301
-			if (file_exists($include))
302
-				require_once($include);
317
+			if (file_exists($include)) {
318
+							require_once($include);
319
+			}
303 320
 		}
304 321
 	}
305 322
 
@@ -403,27 +420,28 @@  discard block
 block discarded – undo
403 420
 				break;
404 421
 			}
405 422
 		}
423
+	} else {
424
+			$id_member = 0;
406 425
 	}
407
-	else
408
-		$id_member = 0;
409 426
 
410 427
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
411 428
 	{
412 429
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
413 430
 
414
-		if (empty($cookie_data))
415
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
431
+		if (empty($cookie_data)) {
432
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
433
+		}
416 434
 
417 435
 		list ($id_member, $password) = $cookie_data;
418 436
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
419
-	}
420
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
437
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
421 438
 	{
422 439
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
423 440
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
424 441
 
425
-		if (empty($cookie_data))
426
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
442
+		if (empty($cookie_data)) {
443
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
444
+		}
427 445
 
428 446
 		list ($id_member, $password, $login_span) = $cookie_data;
429 447
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -448,24 +466,28 @@  discard block
 block discarded – undo
448 466
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
449 467
 			$smcFunc['db_free_result']($request);
450 468
 
451
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
452
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
469
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
470
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
471
+			}
453 472
 
454
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
455
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
473
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
474
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
475
+			}
456 476
 		}
457 477
 
458 478
 		// Did we find 'im?  If not, junk it.
459 479
 		if (!empty($user_settings))
460 480
 		{
461 481
 			// As much as the password should be right, we can assume the integration set things up.
462
-			if (!empty($already_verified) && $already_verified === true)
463
-				$check = true;
482
+			if (!empty($already_verified) && $already_verified === true) {
483
+							$check = true;
484
+			}
464 485
 			// SHA-512 hash should be 128 characters long.
465
-			elseif (strlen($password) == 128)
466
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
467
-			else
468
-				$check = false;
486
+			elseif (strlen($password) == 128) {
487
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
488
+			} else {
489
+							$check = false;
490
+			}
469 491
 
470 492
 			// Wrong password or not activated - either way, you're going nowhere.
471 493
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
@@ -474,9 +496,9 @@  discard block
 block discarded – undo
474 496
 				setLoginCookie(-3600, 0);
475 497
 				$user_settings = array();
476 498
 			}
499
+		} else {
500
+					$id_member = 0;
477 501
 		}
478
-		else
479
-			$id_member = 0;
480 502
 
481 503
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
482 504
 		if (!empty($id_member))
@@ -505,8 +527,9 @@  discard block
 block discarded – undo
505 527
 
506 528
 					list ($tfamember, $tfasecret) = $tfa_data;
507 529
 
508
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
509
-						$tfasecret = null;
530
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
531
+											$tfasecret = null;
532
+					}
510 533
 				}
511 534
 
512 535
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -526,10 +549,12 @@  discard block
 block discarded – undo
526 549
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
527 550
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
528 551
 		{
529
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
552
+			if ($modSettings['tfa_mode'] == 2) {
553
+				//only do this if we are just forcing SOME membergroups
530 554
 			{
531 555
 				//Build an array of ALL user membergroups.
532 556
 				$full_groups = array($user_settings['id_group']);
557
+			}
533 558
 				if (!empty($user_settings['additional_groups']))
534 559
 				{
535 560
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -549,17 +574,18 @@  discard block
 block discarded – undo
549 574
 				);
550 575
 				$row = $smcFunc['db_fetch_assoc']($request);
551 576
 				$smcFunc['db_free_result']($request);
577
+			} else {
578
+							$row['total'] = 1;
552 579
 			}
553
-			else
554
-				$row['total'] = 1; //simplifies logics in the next "if"
580
+			//simplifies logics in the next "if"
555 581
 
556 582
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
557 583
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
558 584
 
559
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
560
-				redirectexit('action=profile;area=tfasetup;forced');
561
-		}
562
-		else if (!empty($user_settings) && empty($id_member))
585
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
586
+							redirectexit('action=profile;area=tfasetup;forced');
587
+			}
588
+		} else if (!empty($user_settings) && empty($id_member))
563 589
 		{
564 590
 			$user_settings = array();
565 591
 		}
@@ -598,33 +624,37 @@  discard block
 block discarded – undo
598 624
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
599 625
 				$user_settings['last_login'] = time();
600 626
 
601
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
602
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
627
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
628
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
629
+				}
603 630
 
604
-				if (!empty($modSettings['cache_enable']))
605
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
631
+				if (!empty($modSettings['cache_enable'])) {
632
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
633
+				}
606 634
 			}
635
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
636
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
607 637
 		}
608
-		elseif (empty($_SESSION['id_msg_last_visit']))
609
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
610 638
 
611 639
 		$username = $user_settings['member_name'];
612 640
 
613
-		if (empty($user_settings['additional_groups']))
614
-			$user_info = array(
641
+		if (empty($user_settings['additional_groups'])) {
642
+					$user_info = array(
615 643
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
616 644
 			);
617
-		else
618
-			$user_info = array(
645
+		} else {
646
+					$user_info = array(
619 647
 				'groups' => array_merge(
620 648
 					array($user_settings['id_group'], $user_settings['id_post_group']),
621 649
 					explode(',', $user_settings['additional_groups'])
622 650
 				)
623 651
 			);
652
+		}
624 653
 
625 654
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
626
-		foreach ($user_info['groups'] as $k => $v)
627
-			$user_info['groups'][$k] = (int) $v;
655
+		foreach ($user_info['groups'] as $k => $v) {
656
+					$user_info['groups'][$k] = (int) $v;
657
+		}
628 658
 
629 659
 		// This is a logged in user, so definitely not a spider.
630 660
 		$user_info['possibly_robot'] = false;
@@ -638,8 +668,7 @@  discard block
 block discarded – undo
638 668
 			$time_system = new DateTime('now', $tz_system);
639 669
 			$time_user = new DateTime('now', $tz_user);
640 670
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
641
-		}
642
-		else
671
+		} else
643 672
 		{
644 673
 			// !!! Compatibility.
645 674
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -653,8 +682,9 @@  discard block
 block discarded – undo
653 682
 		$user_info = array('groups' => array(-1));
654 683
 		$user_settings = array();
655 684
 
656
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
657
-			$_COOKIE[$cookiename] = '';
685
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
686
+					$_COOKIE[$cookiename] = '';
687
+		}
658 688
 
659 689
 		// Expire the 2FA cookie
660 690
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -671,19 +701,20 @@  discard block
 block discarded – undo
671 701
 		}
672 702
 
673 703
 		// Create a login token if it doesn't exist yet.
674
-		if (!isset($_SESSION['token']['post-login']))
675
-			createToken('login');
676
-		else
677
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
704
+		if (!isset($_SESSION['token']['post-login'])) {
705
+					createToken('login');
706
+		} else {
707
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
708
+		}
678 709
 
679 710
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
680 711
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
681 712
 		{
682 713
 			require_once($sourcedir . '/ManageSearchEngines.php');
683 714
 			$user_info['possibly_robot'] = SpiderCheck();
715
+		} elseif (!empty($modSettings['spider_mode'])) {
716
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
684 717
 		}
685
-		elseif (!empty($modSettings['spider_mode']))
686
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
687 718
 		// If we haven't turned on proper spider hunts then have a guess!
688 719
 		else
689 720
 		{
@@ -731,8 +762,9 @@  discard block
 block discarded – undo
731 762
 	$user_info['groups'] = array_unique($user_info['groups']);
732 763
 
733 764
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
734
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
735
-		unset($user_info['ignoreboards'][$tmp]);
765
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
766
+			unset($user_info['ignoreboards'][$tmp]);
767
+	}
736 768
 
737 769
 	// Allow the user to change their language.
738 770
 	if (!empty($modSettings['userLanguage']))
@@ -745,13 +777,14 @@  discard block
 block discarded – undo
745 777
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
746 778
 
747 779
 			// Make it permanent for members.
748
-			if (!empty($user_info['id']))
749
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
750
-			else
751
-				$_SESSION['language'] = $user_info['language'];
780
+			if (!empty($user_info['id'])) {
781
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
782
+			} else {
783
+							$_SESSION['language'] = $user_info['language'];
784
+			}
785
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
786
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
752 787
 		}
753
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
754
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
755 788
 	}
756 789
 
757 790
 	$temp = build_query_board($user_info['id']);
@@ -814,9 +847,9 @@  discard block
 block discarded – undo
814 847
 		}
815 848
 
816 849
 		// Remember redirection is the key to avoiding fallout from your bosses.
817
-		if (!empty($topic))
818
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
819
-		else
850
+		if (!empty($topic)) {
851
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
852
+		} else
820 853
 		{
821 854
 			loadPermissions();
822 855
 			loadTheme();
@@ -834,10 +867,11 @@  discard block
 block discarded – undo
834 867
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
835 868
 	{
836 869
 		// @todo SLOW?
837
-		if (!empty($topic))
838
-			$temp = cache_get_data('topic_board-' . $topic, 120);
839
-		else
840
-			$temp = cache_get_data('board-' . $board, 120);
870
+		if (!empty($topic)) {
871
+					$temp = cache_get_data('topic_board-' . $topic, 120);
872
+		} else {
873
+					$temp = cache_get_data('board-' . $board, 120);
874
+		}
841 875
 
842 876
 		if (!empty($temp))
843 877
 		{
@@ -875,8 +909,9 @@  discard block
 block discarded – undo
875 909
 			$row = $smcFunc['db_fetch_assoc']($request);
876 910
 
877 911
 			// Set the current board.
878
-			if (!empty($row['id_board']))
879
-				$board = $row['id_board'];
912
+			if (!empty($row['id_board'])) {
913
+							$board = $row['id_board'];
914
+			}
880 915
 
881 916
 			// Basic operating information. (globals... :/)
882 917
 			$board_info = array(
@@ -912,21 +947,23 @@  discard block
 block discarded – undo
912 947
 
913 948
 			do
914 949
 			{
915
-				if (!empty($row['id_moderator']))
916
-					$board_info['moderators'][$row['id_moderator']] = array(
950
+				if (!empty($row['id_moderator'])) {
951
+									$board_info['moderators'][$row['id_moderator']] = array(
917 952
 						'id' => $row['id_moderator'],
918 953
 						'name' => $row['real_name'],
919 954
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
920 955
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
921 956
 					);
957
+				}
922 958
 
923
-				if (!empty($row['id_moderator_group']))
924
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
959
+				if (!empty($row['id_moderator_group'])) {
960
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
925 961
 						'id' => $row['id_moderator_group'],
926 962
 						'name' => $row['group_name'],
927 963
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
928 964
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
929 965
 					);
966
+				}
930 967
 			}
931 968
 			while ($row = $smcFunc['db_fetch_assoc']($request));
932 969
 
@@ -958,12 +995,12 @@  discard block
 block discarded – undo
958 995
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
959 996
 			{
960 997
 				// @todo SLOW?
961
-				if (!empty($topic))
962
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
998
+				if (!empty($topic)) {
999
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1000
+				}
963 1001
 				cache_put_data('board-' . $board, $board_info, 120);
964 1002
 			}
965
-		}
966
-		else
1003
+		} else
967 1004
 		{
968 1005
 			// Otherwise the topic is invalid, there are no moderators, etc.
969 1006
 			$board_info = array(
@@ -977,8 +1014,9 @@  discard block
 block discarded – undo
977 1014
 		$smcFunc['db_free_result']($request);
978 1015
 	}
979 1016
 
980
-	if (!empty($topic))
981
-		$_GET['board'] = (int) $board;
1017
+	if (!empty($topic)) {
1018
+			$_GET['board'] = (int) $board;
1019
+	}
982 1020
 
983 1021
 	if (!empty($board))
984 1022
 	{
@@ -988,10 +1026,12 @@  discard block
 block discarded – undo
988 1026
 		// Now check if the user is a moderator.
989 1027
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
990 1028
 
991
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
992
-			$board_info['error'] = 'access';
993
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
994
-			$board_info['error'] = 'access';
1029
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1030
+					$board_info['error'] = 'access';
1031
+		}
1032
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1033
+					$board_info['error'] = 'access';
1034
+		}
995 1035
 
996 1036
 		// Build up the linktree.
997 1037
 		$context['linktree'] = array_merge(
@@ -1014,8 +1054,9 @@  discard block
 block discarded – undo
1014 1054
 	$context['current_board'] = $board;
1015 1055
 
1016 1056
 	// No posting in redirection boards!
1017
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1018
-		$board_info['error'] == 'post_in_redirect';
1057
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1058
+			$board_info['error'] == 'post_in_redirect';
1059
+	}
1019 1060
 
1020 1061
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1021 1062
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1041,24 +1082,23 @@  discard block
 block discarded – undo
1041 1082
 			ob_end_clean();
1042 1083
 			header('HTTP/1.1 403 Forbidden');
1043 1084
 			die;
1044
-		}
1045
-		elseif ($board_info['error'] == 'post_in_redirect')
1085
+		} elseif ($board_info['error'] == 'post_in_redirect')
1046 1086
 		{
1047 1087
 			// Slightly different error message here...
1048 1088
 			fatal_lang_error('cannot_post_redirect', false);
1049
-		}
1050
-		elseif ($user_info['is_guest'])
1089
+		} elseif ($user_info['is_guest'])
1051 1090
 		{
1052 1091
 			loadLanguage('Errors');
1053 1092
 			is_not_guest($txt['topic_gone']);
1093
+		} else {
1094
+					fatal_lang_error('topic_gone', false);
1054 1095
 		}
1055
-		else
1056
-			fatal_lang_error('topic_gone', false);
1057 1096
 	}
1058 1097
 
1059
-	if ($user_info['is_mod'])
1060
-		$user_info['groups'][] = 3;
1061
-}
1098
+	if ($user_info['is_mod']) {
1099
+			$user_info['groups'][] = 3;
1100
+	}
1101
+	}
1062 1102
 
1063 1103
 /**
1064 1104
  * Load this user's permissions.
@@ -1079,8 +1119,9 @@  discard block
 block discarded – undo
1079 1119
 		asort($cache_groups);
1080 1120
 		$cache_groups = implode(',', $cache_groups);
1081 1121
 		// If it's a spider then cache it different.
1082
-		if ($user_info['possibly_robot'])
1083
-			$cache_groups .= '-spider';
1122
+		if ($user_info['possibly_robot']) {
1123
+					$cache_groups .= '-spider';
1124
+		}
1084 1125
 
1085 1126
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1086 1127
 		{
@@ -1088,9 +1129,9 @@  discard block
 block discarded – undo
1088 1129
 			banPermissions();
1089 1130
 
1090 1131
 			return;
1132
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1133
+					list ($user_info['permissions'], $removals) = $temp;
1091 1134
 		}
1092
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1093
-			list ($user_info['permissions'], $removals) = $temp;
1094 1135
 	}
1095 1136
 
1096 1137
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1112,23 +1153,26 @@  discard block
 block discarded – undo
1112 1153
 		$removals = array();
1113 1154
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1114 1155
 		{
1115
-			if (empty($row['add_deny']))
1116
-				$removals[] = $row['permission'];
1117
-			else
1118
-				$user_info['permissions'][] = $row['permission'];
1156
+			if (empty($row['add_deny'])) {
1157
+							$removals[] = $row['permission'];
1158
+			} else {
1159
+							$user_info['permissions'][] = $row['permission'];
1160
+			}
1119 1161
 		}
1120 1162
 		$smcFunc['db_free_result']($request);
1121 1163
 
1122
-		if (isset($cache_groups))
1123
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1164
+		if (isset($cache_groups)) {
1165
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1166
+		}
1124 1167
 	}
1125 1168
 
1126 1169
 	// Get the board permissions.
1127 1170
 	if (!empty($board))
1128 1171
 	{
1129 1172
 		// Make sure the board (if any) has been loaded by loadBoard().
1130
-		if (!isset($board_info['profile']))
1131
-			fatal_lang_error('no_board');
1173
+		if (!isset($board_info['profile'])) {
1174
+					fatal_lang_error('no_board');
1175
+		}
1132 1176
 
1133 1177
 		$request = $smcFunc['db_query']('', '
1134 1178
 			SELECT permission, add_deny
@@ -1144,20 +1188,23 @@  discard block
 block discarded – undo
1144 1188
 		);
1145 1189
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1146 1190
 		{
1147
-			if (empty($row['add_deny']))
1148
-				$removals[] = $row['permission'];
1149
-			else
1150
-				$user_info['permissions'][] = $row['permission'];
1191
+			if (empty($row['add_deny'])) {
1192
+							$removals[] = $row['permission'];
1193
+			} else {
1194
+							$user_info['permissions'][] = $row['permission'];
1195
+			}
1151 1196
 		}
1152 1197
 		$smcFunc['db_free_result']($request);
1153 1198
 	}
1154 1199
 
1155 1200
 	// Remove all the permissions they shouldn't have ;).
1156
-	if (!empty($modSettings['permission_enable_deny']))
1157
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1201
+	if (!empty($modSettings['permission_enable_deny'])) {
1202
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1203
+	}
1158 1204
 
1159
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1160
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1205
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1206
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1207
+	}
1161 1208
 
1162 1209
 	// Banned?  Watch, don't touch..
1163 1210
 	banPermissions();
@@ -1169,17 +1216,18 @@  discard block
 block discarded – undo
1169 1216
 		{
1170 1217
 			require_once($sourcedir . '/Subs-Auth.php');
1171 1218
 			rebuildModCache();
1219
+		} else {
1220
+					$user_info['mod_cache'] = $_SESSION['mc'];
1172 1221
 		}
1173
-		else
1174
-			$user_info['mod_cache'] = $_SESSION['mc'];
1175 1222
 
1176 1223
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1177 1224
 		// For example this drastically simplifies certain changes to the profile area.
1178 1225
 		$user_info['permissions'][] = 'is_not_guest';
1179 1226
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1180 1227
 		$user_info['permissions'][] = 'profile_view_own';
1181
-		if (in_array('profile_view', $user_info['permissions']))
1182
-			$user_info['permissions'][] = 'profile_view_any';
1228
+		if (in_array('profile_view', $user_info['permissions'])) {
1229
+					$user_info['permissions'][] = 'profile_view_any';
1230
+		}
1183 1231
 	}
1184 1232
 }
1185 1233
 
@@ -1197,8 +1245,9 @@  discard block
 block discarded – undo
1197 1245
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1198 1246
 
1199 1247
 	// Can't just look for no users :P.
1200
-	if (empty($users))
1201
-		return array();
1248
+	if (empty($users)) {
1249
+			return array();
1250
+	}
1202 1251
 
1203 1252
 	// Pass the set value
1204 1253
 	$context['loadMemberContext_set'] = $set;
@@ -1213,8 +1262,9 @@  discard block
 block discarded – undo
1213 1262
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1214 1263
 		{
1215 1264
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1216
-			if ($data == null)
1217
-				continue;
1265
+			if ($data == null) {
1266
+							continue;
1267
+			}
1218 1268
 
1219 1269
 			$loaded_ids[] = $data['id_member'];
1220 1270
 			$user_profile[$data['id_member']] = $data;
@@ -1281,16 +1331,19 @@  discard block
 block discarded – undo
1281 1331
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1282 1332
 
1283 1333
 			// Take care of proxying avatar if required, do this here for maximum reach
1284
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1285
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1334
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1335
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1336
+			}
1286 1337
 
1287 1338
 			// Keep track of the member's normal member group
1288 1339
 			$row['primary_group'] = $row['member_group'];
1289 1340
 
1290
-			if (isset($row['member_ip']))
1291
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1292
-			if (isset($row['member_ip2']))
1293
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1341
+			if (isset($row['member_ip'])) {
1342
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1343
+			}
1344
+			if (isset($row['member_ip2'])) {
1345
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1346
+			}
1294 1347
 			$new_loaded_ids[] = $row['id_member'];
1295 1348
 			$loaded_ids[] = $row['id_member'];
1296 1349
 			$row['options'] = array();
@@ -1309,8 +1362,9 @@  discard block
 block discarded – undo
1309 1362
 				'loaded_ids' => $new_loaded_ids,
1310 1363
 			)
1311 1364
 		);
1312
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1313
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1365
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1366
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1367
+		}
1314 1368
 		$smcFunc['db_free_result']($request);
1315 1369
 	}
1316 1370
 
@@ -1321,10 +1375,11 @@  discard block
 block discarded – undo
1321 1375
 	{
1322 1376
 		foreach ($loaded_ids as $a_member)
1323 1377
 		{
1324
-			if (!empty($user_profile[$a_member]['additional_groups']))
1325
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1326
-			else
1327
-				$groups = array($user_profile[$a_member]['id_group']);
1378
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1379
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1380
+			} else {
1381
+							$groups = array($user_profile[$a_member]['id_group']);
1382
+			}
1328 1383
 
1329 1384
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1330 1385
 
@@ -1337,8 +1392,9 @@  discard block
 block discarded – undo
1337 1392
 
1338 1393
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1339 1394
 	{
1340
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1341
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1395
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1396
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1397
+		}
1342 1398
 	}
1343 1399
 
1344 1400
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1364,14 +1420,17 @@  discard block
 block discarded – undo
1364 1420
 		foreach ($temp_mods as $id)
1365 1421
 		{
1366 1422
 			// By popular demand, don't show admins or global moderators as moderators.
1367
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1368
-				$user_profile[$id]['member_group'] = $row['member_group'];
1423
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1424
+							$user_profile[$id]['member_group'] = $row['member_group'];
1425
+			}
1369 1426
 
1370 1427
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1371
-			if (!empty($row['icons']))
1372
-				$user_profile[$id]['icons'] = $row['icons'];
1373
-			if (!empty($row['member_group_color']))
1374
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1428
+			if (!empty($row['icons'])) {
1429
+							$user_profile[$id]['icons'] = $row['icons'];
1430
+			}
1431
+			if (!empty($row['member_group_color'])) {
1432
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1433
+			}
1375 1434
 		}
1376 1435
 	}
1377 1436
 
@@ -1393,12 +1452,14 @@  discard block
 block discarded – undo
1393 1452
 	static $loadedLanguages = array();
1394 1453
 
1395 1454
 	// If this person's data is already loaded, skip it.
1396
-	if (isset($dataLoaded[$user]))
1397
-		return true;
1455
+	if (isset($dataLoaded[$user])) {
1456
+			return true;
1457
+	}
1398 1458
 
1399 1459
 	// We can't load guests or members not loaded by loadMemberData()!
1400
-	if ($user == 0)
1401
-		return false;
1460
+	if ($user == 0) {
1461
+			return false;
1462
+	}
1402 1463
 	if (!isset($user_profile[$user]))
1403 1464
 	{
1404 1465
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1424,12 +1485,16 @@  discard block
 block discarded – undo
1424 1485
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1425 1486
 
1426 1487
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1427
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1488
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1489
+		//icon is set and exists
1428 1490
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1429
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1491
+	} elseif (isset($profile['icons'][1])) {
1492
+		//icon is set and doesn't exist, fallback to default
1430 1493
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1431
-	else //not set, bye bye
1494
+	} else {
1495
+		//not set, bye bye
1432 1496
 		$group_icon_url = '';
1497
+	}
1433 1498
 
1434 1499
 	// These minimal values are always loaded
1435 1500
 	$memberContext[$user] = array(
@@ -1448,8 +1513,9 @@  discard block
 block discarded – undo
1448 1513
 	if ($context['loadMemberContext_set'] != 'minimal')
1449 1514
 	{
1450 1515
 		// Go the extra mile and load the user's native language name.
1451
-		if (empty($loadedLanguages))
1452
-			$loadedLanguages = getLanguages();
1516
+		if (empty($loadedLanguages)) {
1517
+					$loadedLanguages = getLanguages();
1518
+		}
1453 1519
 
1454 1520
 		$memberContext[$user] += array(
1455 1521
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1504,31 +1570,33 @@  discard block
 block discarded – undo
1504 1570
 	{
1505 1571
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1506 1572
 		{
1507
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1508
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1509
-			else
1510
-				$image = get_gravatar_url($profile['email_address']);
1511
-		}
1512
-		else
1573
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1574
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1575
+			} else {
1576
+							$image = get_gravatar_url($profile['email_address']);
1577
+			}
1578
+		} else
1513 1579
 		{
1514 1580
 			// So it's stored in the member table?
1515 1581
 			if (!empty($profile['avatar']))
1516 1582
 			{
1517 1583
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1584
+			} elseif (!empty($profile['filename'])) {
1585
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1518 1586
 			}
1519
-			elseif (!empty($profile['filename']))
1520
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1521 1587
 			// Right... no avatar...use the default one
1522
-			else
1523
-				$image = $modSettings['avatar_url'] . '/default.png';
1588
+			else {
1589
+							$image = $modSettings['avatar_url'] . '/default.png';
1590
+			}
1524 1591
 		}
1525
-		if (!empty($image))
1526
-			$memberContext[$user]['avatar'] = array(
1592
+		if (!empty($image)) {
1593
+					$memberContext[$user]['avatar'] = array(
1527 1594
 				'name' => $profile['avatar'],
1528 1595
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1529 1596
 				'href' => $image,
1530 1597
 				'url' => $image,
1531 1598
 			);
1599
+		}
1532 1600
 	}
1533 1601
 
1534 1602
 	// Are we also loading the members custom fields into context?
@@ -1536,35 +1604,41 @@  discard block
 block discarded – undo
1536 1604
 	{
1537 1605
 		$memberContext[$user]['custom_fields'] = array();
1538 1606
 
1539
-		if (!isset($context['display_fields']))
1540
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1607
+		if (!isset($context['display_fields'])) {
1608
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1609
+		}
1541 1610
 
1542 1611
 		foreach ($context['display_fields'] as $custom)
1543 1612
 		{
1544
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1545
-				continue;
1613
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1614
+							continue;
1615
+			}
1546 1616
 
1547 1617
 			$value = $profile['options'][$custom['col_name']];
1548 1618
 
1549 1619
 			// Don't show the "disabled" option for the "gender" field.
1550
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1551
-				continue;
1620
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1621
+							continue;
1622
+			}
1552 1623
 
1553 1624
 			// BBC?
1554
-			if ($custom['bbc'])
1555
-				$value = parse_bbc($value);
1625
+			if ($custom['bbc']) {
1626
+							$value = parse_bbc($value);
1627
+			}
1556 1628
 			// ... or checkbox?
1557
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1558
-				$value = $value ? $txt['yes'] : $txt['no'];
1629
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1630
+							$value = $value ? $txt['yes'] : $txt['no'];
1631
+			}
1559 1632
 
1560 1633
 			// Enclosing the user input within some other text?
1561
-			if (!empty($custom['enclose']))
1562
-				$value = strtr($custom['enclose'], array(
1634
+			if (!empty($custom['enclose'])) {
1635
+							$value = strtr($custom['enclose'], array(
1563 1636
 					'{SCRIPTURL}' => $scripturl,
1564 1637
 					'{IMAGES_URL}' => $settings['images_url'],
1565 1638
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1566 1639
 					'{INPUT}' => $value,
1567 1640
 				));
1641
+			}
1568 1642
 
1569 1643
 			$memberContext[$user]['custom_fields'][] = array(
1570 1644
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1591,8 +1665,9 @@  discard block
 block discarded – undo
1591 1665
 	global $smcFunc, $txt, $scripturl, $settings;
1592 1666
 
1593 1667
 	// Do not waste my time...
1594
-	if (empty($users) || empty($params))
1595
-		return false;
1668
+	if (empty($users) || empty($params)) {
1669
+			return false;
1670
+	}
1596 1671
 
1597 1672
 	// Make sure it's an array.
1598 1673
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1616,31 +1691,36 @@  discard block
 block discarded – undo
1616 1691
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1617 1692
 	{
1618 1693
 		// BBC?
1619
-		if (!empty($row['bbc']))
1620
-			$row['value'] = parse_bbc($row['value']);
1694
+		if (!empty($row['bbc'])) {
1695
+					$row['value'] = parse_bbc($row['value']);
1696
+		}
1621 1697
 
1622 1698
 		// ... or checkbox?
1623
-		elseif (isset($row['type']) && $row['type'] == 'check')
1624
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1699
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1700
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1701
+		}
1625 1702
 
1626 1703
 		// Enclosing the user input within some other text?
1627
-		if (!empty($row['enclose']))
1628
-			$row['value'] = strtr($row['enclose'], array(
1704
+		if (!empty($row['enclose'])) {
1705
+					$row['value'] = strtr($row['enclose'], array(
1629 1706
 				'{SCRIPTURL}' => $scripturl,
1630 1707
 				'{IMAGES_URL}' => $settings['images_url'],
1631 1708
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1632 1709
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1633 1710
 			));
1711
+		}
1634 1712
 
1635 1713
 		// Send a simple array if there is just 1 param
1636
-		if (count($params) == 1)
1637
-			$return[$row['id_member']] = $row;
1714
+		if (count($params) == 1) {
1715
+					$return[$row['id_member']] = $row;
1716
+		}
1638 1717
 
1639 1718
 		// More than 1? knock yourself out...
1640 1719
 		else
1641 1720
 		{
1642
-			if (!isset($return[$row['id_member']]))
1643
-				$return[$row['id_member']] = array();
1721
+			if (!isset($return[$row['id_member']])) {
1722
+							$return[$row['id_member']] = array();
1723
+			}
1644 1724
 
1645 1725
 			$return[$row['id_member']][$row['variable']] = $row;
1646 1726
 		}
@@ -1674,8 +1754,9 @@  discard block
 block discarded – undo
1674 1754
 	global $context;
1675 1755
 
1676 1756
 	// Don't know any browser!
1677
-	if (empty($context['browser']))
1678
-		detectBrowser();
1757
+	if (empty($context['browser'])) {
1758
+			detectBrowser();
1759
+	}
1679 1760
 
1680 1761
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1681 1762
 }
@@ -1693,8 +1774,9 @@  discard block
 block discarded – undo
1693 1774
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1694 1775
 
1695 1776
 	// The theme was specified by parameter.
1696
-	if (!empty($id_theme))
1697
-		$id_theme = (int) $id_theme;
1777
+	if (!empty($id_theme)) {
1778
+			$id_theme = (int) $id_theme;
1779
+	}
1698 1780
 	// The theme was specified by REQUEST.
1699 1781
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1700 1782
 	{
@@ -1702,54 +1784,61 @@  discard block
 block discarded – undo
1702 1784
 		$_SESSION['id_theme'] = $id_theme;
1703 1785
 	}
1704 1786
 	// The theme was specified by REQUEST... previously.
1705
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1706
-		$id_theme = (int) $_SESSION['id_theme'];
1787
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1788
+			$id_theme = (int) $_SESSION['id_theme'];
1789
+	}
1707 1790
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1708
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1709
-		$id_theme = $user_info['theme'];
1791
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1792
+			$id_theme = $user_info['theme'];
1793
+	}
1710 1794
 	// The theme was specified by the board.
1711
-	elseif (!empty($board_info['theme']))
1712
-		$id_theme = $board_info['theme'];
1795
+	elseif (!empty($board_info['theme'])) {
1796
+			$id_theme = $board_info['theme'];
1797
+	}
1713 1798
 	// The theme is the forum's default.
1714
-	else
1715
-		$id_theme = $modSettings['theme_guests'];
1799
+	else {
1800
+			$id_theme = $modSettings['theme_guests'];
1801
+	}
1716 1802
 
1717 1803
 	// We already load the basic stuff?
1718 1804
 	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme )
1719 1805
 	{
1720 1806
 		// Verify the id_theme... no foul play.
1721 1807
 		// Always allow the board specific theme, if they are overriding.
1722
-		if (!empty($board_info['theme']) && $board_info['override_theme'])
1723
-			$id_theme = $board_info['theme'];
1808
+		if (!empty($board_info['theme']) && $board_info['override_theme']) {
1809
+					$id_theme = $board_info['theme'];
1810
+		}
1724 1811
 		// If they have specified a particular theme to use with SSI allow it to be used.
1725
-		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1726
-			$id_theme = (int) $id_theme;
1727
-		elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1812
+		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1813
+					$id_theme = (int) $id_theme;
1814
+		} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1728 1815
 		{
1729 1816
 			$themes = explode(',', $modSettings['enableThemes']);
1730
-			if (!in_array($id_theme, $themes))
1731
-				$id_theme = $modSettings['theme_guests'];
1732
-			else
1733
-				$id_theme = (int) $id_theme;
1817
+			if (!in_array($id_theme, $themes)) {
1818
+							$id_theme = $modSettings['theme_guests'];
1819
+			} else {
1820
+							$id_theme = (int) $id_theme;
1821
+			}
1822
+		} else {
1823
+					$id_theme = (int) $id_theme;
1734 1824
 		}
1735
-		else
1736
-			$id_theme = (int) $id_theme;
1737 1825
 
1738 1826
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1739 1827
 
1740 1828
 		// Disable image proxy if we don't have SSL enabled
1741
-		if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1742
-			$image_proxy_enabled = false;
1829
+		if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1830
+					$image_proxy_enabled = false;
1831
+		}
1743 1832
 
1744 1833
 		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1745 1834
 		{
1746 1835
 			$themeData = $temp;
1747 1836
 			$flag = true;
1837
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1838
+					$themeData = $temp + array($member => array());
1839
+		} else {
1840
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1748 1841
 		}
1749
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1750
-			$themeData = $temp + array($member => array());
1751
-		else
1752
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1753 1842
 
1754 1843
 		if (empty($flag))
1755 1844
 		{
@@ -1768,31 +1857,37 @@  discard block
 block discarded – undo
1768 1857
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1769 1858
 			{
1770 1859
 				// There are just things we shouldn't be able to change as members.
1771
-				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1772
-					continue;
1860
+				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1861
+									continue;
1862
+				}
1773 1863
 
1774 1864
 				// If this is the theme_dir of the default theme, store it.
1775
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1776
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1865
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1866
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1867
+				}
1777 1868
 
1778 1869
 				// If this isn't set yet, is a theme option, or is not the default theme..
1779
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1780
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1870
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1871
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1872
+				}
1781 1873
 			}
1782 1874
 			$smcFunc['db_free_result']($result);
1783 1875
 
1784
-			if (!empty($themeData[-1]))
1785
-				foreach ($themeData[-1] as $k => $v)
1876
+			if (!empty($themeData[-1])) {
1877
+							foreach ($themeData[-1] as $k => $v)
1786 1878
 				{
1787 1879
 					if (!isset($themeData[$member][$k]))
1788 1880
 						$themeData[$member][$k] = $v;
1881
+			}
1789 1882
 				}
1790 1883
 
1791
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1792
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1884
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1885
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1886
+			}
1793 1887
 			// Only if we didn't already load that part of the cache...
1794
-			elseif (!isset($temp))
1795
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1888
+			elseif (!isset($temp)) {
1889
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1890
+			}
1796 1891
 		}
1797 1892
 
1798 1893
 		$settings = $themeData[0];
@@ -1809,22 +1904,26 @@  discard block
 block discarded – undo
1809 1904
 		$settings['template_dirs'][] = $settings['theme_dir'];
1810 1905
 
1811 1906
 		// Based on theme (if there is one).
1812
-		if (!empty($settings['base_theme_dir']))
1813
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1907
+		if (!empty($settings['base_theme_dir'])) {
1908
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1909
+		}
1814 1910
 
1815 1911
 		// Lastly the default theme.
1816
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1817
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1912
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1913
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1914
+		}
1818 1915
 	}
1819 1916
 	
1820 1917
 
1821
-	if (!$initialize)
1822
-		return;
1918
+	if (!$initialize) {
1919
+			return;
1920
+	}
1823 1921
 
1824 1922
 	// Check to see if we're forcing SSL
1825 1923
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1826
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1827
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1924
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1925
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1926
+	}
1828 1927
 
1829 1928
 	// Check to see if they're accessing it from the wrong place.
1830 1929
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1832,8 +1931,9 @@  discard block
 block discarded – undo
1832 1931
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1833 1932
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1834 1933
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1835
-		if ($temp != '/')
1836
-			$detected_url .= $temp;
1934
+		if ($temp != '/') {
1935
+					$detected_url .= $temp;
1936
+		}
1837 1937
 	}
1838 1938
 	if (isset($detected_url) && $detected_url != $boardurl)
1839 1939
 	{
@@ -1845,8 +1945,9 @@  discard block
 block discarded – undo
1845 1945
 			foreach ($aliases as $alias)
1846 1946
 			{
1847 1947
 				// Rip off all the boring parts, spaces, etc.
1848
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1849
-					$do_fix = true;
1948
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1949
+									$do_fix = true;
1950
+				}
1850 1951
 			}
1851 1952
 		}
1852 1953
 
@@ -1854,20 +1955,22 @@  discard block
 block discarded – undo
1854 1955
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1855 1956
 		{
1856 1957
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1857
-			if (empty($_GET))
1858
-				redirectexit('wwwRedirect');
1859
-			else
1958
+			if (empty($_GET)) {
1959
+							redirectexit('wwwRedirect');
1960
+			} else
1860 1961
 			{
1861 1962
 				list ($k, $v) = each($_GET);
1862 1963
 
1863
-				if ($k != 'wwwRedirect')
1864
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1964
+				if ($k != 'wwwRedirect') {
1965
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1966
+				}
1865 1967
 			}
1866 1968
 		}
1867 1969
 
1868 1970
 		// #3 is just a check for SSL...
1869
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1870
-			$do_fix = true;
1971
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1972
+					$do_fix = true;
1973
+		}
1871 1974
 
1872 1975
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1873 1976
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1901,8 +2004,9 @@  discard block
 block discarded – undo
1901 2004
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1902 2005
 				}
1903 2006
 			}
1904
-			foreach ($context['linktree'] as $k => $dummy)
1905
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2007
+			foreach ($context['linktree'] as $k => $dummy) {
2008
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2009
+			}
1906 2010
 		}
1907 2011
 	}
1908 2012
 	// Set up the contextual user array.
@@ -1921,16 +2025,16 @@  discard block
 block discarded – undo
1921 2025
 			'email' => $user_info['email'],
1922 2026
 			'ignoreusers' => $user_info['ignoreusers'],
1923 2027
 		);
1924
-		if (!$context['user']['is_guest'])
1925
-			$context['user']['name'] = $user_info['name'];
1926
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1927
-			$context['user']['name'] = $txt['guest_title'];
2028
+		if (!$context['user']['is_guest']) {
2029
+					$context['user']['name'] = $user_info['name'];
2030
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2031
+					$context['user']['name'] = $txt['guest_title'];
2032
+		}
1928 2033
 
1929 2034
 		// Determine the current smiley set.
1930 2035
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1931 2036
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1932
-	}
1933
-	else
2037
+	} else
1934 2038
 	{
1935 2039
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1936 2040
 		$context['user'] = array(
@@ -1964,18 +2068,24 @@  discard block
 block discarded – undo
1964 2068
 	}
1965 2069
 
1966 2070
 	// Some basic information...
1967
-	if (!isset($context['html_headers']))
1968
-		$context['html_headers'] = '';
1969
-	if (!isset($context['javascript_files']))
1970
-		$context['javascript_files'] = array();
1971
-	if (!isset($context['css_files']))
1972
-		$context['css_files'] = array();
1973
-	if (!isset($context['css_header']))
1974
-		$context['css_header'] = array();
1975
-	if (!isset($context['javascript_inline']))
1976
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1977
-	if (!isset($context['javascript_vars']))
1978
-		$context['javascript_vars'] = array();
2071
+	if (!isset($context['html_headers'])) {
2072
+			$context['html_headers'] = '';
2073
+	}
2074
+	if (!isset($context['javascript_files'])) {
2075
+			$context['javascript_files'] = array();
2076
+	}
2077
+	if (!isset($context['css_files'])) {
2078
+			$context['css_files'] = array();
2079
+	}
2080
+	if (!isset($context['css_header'])) {
2081
+			$context['css_header'] = array();
2082
+	}
2083
+	if (!isset($context['javascript_inline'])) {
2084
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2085
+	}
2086
+	if (!isset($context['javascript_vars'])) {
2087
+			$context['javascript_vars'] = array();
2088
+	}
1979 2089
 
1980 2090
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1981 2091
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1987,16 +2097,18 @@  discard block
 block discarded – undo
1987 2097
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1988 2098
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1989 2099
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1990
-	if (isset($modSettings['load_average']))
1991
-		$context['load_average'] = $modSettings['load_average'];
2100
+	if (isset($modSettings['load_average'])) {
2101
+			$context['load_average'] = $modSettings['load_average'];
2102
+	}
1992 2103
 
1993 2104
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1994 2105
 	detectBrowser();
1995 2106
 
1996 2107
 	// Set the top level linktree up.
1997 2108
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
1998
-	if (empty($context['linktree']))
1999
-		$context['linktree'] = array();
2109
+	if (empty($context['linktree'])) {
2110
+			$context['linktree'] = array();
2111
+	}
2000 2112
 	array_unshift($context['linktree'], array(
2001 2113
 		'url' => $scripturl,
2002 2114
 		'name' => $context['forum_name_html_safe']
@@ -2005,8 +2117,9 @@  discard block
 block discarded – undo
2005 2117
 	// This allows sticking some HTML on the page output - useful for controls.
2006 2118
 	$context['insert_after_template'] = '';
2007 2119
 
2008
-	if (!isset($txt))
2009
-		$txt = array();
2120
+	if (!isset($txt)) {
2121
+			$txt = array();
2122
+	}
2010 2123
 
2011 2124
 	$simpleActions = array(
2012 2125
 		'findmember',
@@ -2052,9 +2165,10 @@  discard block
 block discarded – undo
2052 2165
 
2053 2166
 	// See if theres any extra param to check.
2054 2167
 	$requiresXML = false;
2055
-	foreach ($extraParams as $key => $extra)
2056
-		if (isset($_REQUEST[$extra]))
2168
+	foreach ($extraParams as $key => $extra) {
2169
+			if (isset($_REQUEST[$extra]))
2057 2170
 			$requiresXML = true;
2171
+	}
2058 2172
 
2059 2173
 	// Output is fully XML, so no need for the index template.
2060 2174
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2069,37 +2183,39 @@  discard block
 block discarded – undo
2069 2183
 	{
2070 2184
 		loadLanguage('index+Modifications');
2071 2185
 		$context['template_layers'] = array();
2072
-	}
2073
-
2074
-	else
2186
+	} else
2075 2187
 	{
2076 2188
 		// Custom templates to load, or just default?
2077
-		if (isset($settings['theme_templates']))
2078
-			$templates = explode(',', $settings['theme_templates']);
2079
-		else
2080
-			$templates = array('index');
2189
+		if (isset($settings['theme_templates'])) {
2190
+					$templates = explode(',', $settings['theme_templates']);
2191
+		} else {
2192
+					$templates = array('index');
2193
+		}
2081 2194
 
2082 2195
 		// Load each template...
2083
-		foreach ($templates as $template)
2084
-			loadTemplate($template);
2196
+		foreach ($templates as $template) {
2197
+					loadTemplate($template);
2198
+		}
2085 2199
 
2086 2200
 		// ...and attempt to load their associated language files.
2087 2201
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2088 2202
 		loadLanguage($required_files, '', false);
2089 2203
 
2090 2204
 		// Custom template layers?
2091
-		if (isset($settings['theme_layers']))
2092
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2093
-		else
2094
-			$context['template_layers'] = array('html', 'body');
2205
+		if (isset($settings['theme_layers'])) {
2206
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2207
+		} else {
2208
+					$context['template_layers'] = array('html', 'body');
2209
+		}
2095 2210
 	}
2096 2211
 
2097 2212
 	// Initialize the theme.
2098 2213
 	loadSubTemplate('init', 'ignore');
2099 2214
 
2100 2215
 	// Allow overriding the board wide time/number formats.
2101
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2102
-		$user_info['time_format'] = $txt['time_format'];
2216
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2217
+			$user_info['time_format'] = $txt['time_format'];
2218
+	}
2103 2219
 
2104 2220
 	// Set the character set from the template.
2105 2221
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2107,12 +2223,14 @@  discard block
 block discarded – undo
2107 2223
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2108 2224
 
2109 2225
 	// Guests may still need a name.
2110
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2111
-		$context['user']['name'] = $txt['guest_title'];
2226
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2227
+			$context['user']['name'] = $txt['guest_title'];
2228
+	}
2112 2229
 
2113 2230
 	// Any theme-related strings that need to be loaded?
2114
-	if (!empty($settings['require_theme_strings']))
2115
-		loadLanguage('ThemeStrings', '', false);
2231
+	if (!empty($settings['require_theme_strings'])) {
2232
+			loadLanguage('ThemeStrings', '', false);
2233
+	}
2116 2234
 
2117 2235
 	// Make a special URL for the language.
2118 2236
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2123,8 +2241,9 @@  discard block
 block discarded – undo
2123 2241
 	// Here is my luvly Responsive CSS
2124 2242
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2125 2243
 
2126
-	if ($context['right_to_left'])
2127
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2244
+	if ($context['right_to_left']) {
2245
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2246
+	}
2128 2247
 
2129 2248
 	// We allow theme variants, because we're cool.
2130 2249
 	$context['theme_variant'] = '';
@@ -2132,14 +2251,17 @@  discard block
 block discarded – undo
2132 2251
 	if (!empty($settings['theme_variants']))
2133 2252
 	{
2134 2253
 		// Overriding - for previews and that ilk.
2135
-		if (!empty($_REQUEST['variant']))
2136
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2254
+		if (!empty($_REQUEST['variant'])) {
2255
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2256
+		}
2137 2257
 		// User selection?
2138
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2139
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2258
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2259
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2260
+		}
2140 2261
 		// If not a user variant, select the default.
2141
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2142
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2262
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2263
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2264
+		}
2143 2265
 
2144 2266
 		// Do this to keep things easier in the templates.
2145 2267
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2148,20 +2270,23 @@  discard block
 block discarded – undo
2148 2270
 		if (!empty($context['theme_variant']))
2149 2271
 		{
2150 2272
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2151
-			if ($context['right_to_left'])
2152
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2273
+			if ($context['right_to_left']) {
2274
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2275
+			}
2153 2276
 		}
2154 2277
 	}
2155 2278
 
2156 2279
 	// Let's be compatible with old themes!
2157
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2158
-		$context['template_layers'] = array('main');
2280
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2281
+			$context['template_layers'] = array('main');
2282
+	}
2159 2283
 
2160 2284
 	$context['tabindex'] = 1;
2161 2285
 
2162 2286
 	// Compatibility.
2163
-	if (!isset($settings['theme_version']))
2164
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2287
+	if (!isset($settings['theme_version'])) {
2288
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2289
+	}
2165 2290
 
2166 2291
 	// Default JS variables for use in every theme
2167 2292
 	$context['javascript_vars'] = array(
@@ -2180,18 +2305,18 @@  discard block
 block discarded – undo
2180 2305
 	);
2181 2306
 
2182 2307
 	// Add the JQuery library to the list of files to load.
2183
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2184
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2185
-
2186
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2187
-		loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2188
-
2189
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2190
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2308
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2309
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2310
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2311
+			loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2312
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2313
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2314
+	}
2191 2315
 
2192 2316
 	// Auto loading? template_javascript() will take care of the local half of this.
2193
-	else
2194
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2317
+	else {
2318
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2319
+	}
2195 2320
 
2196 2321
 	// Queue our JQuery plugins!
2197 2322
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2214,12 +2339,12 @@  discard block
 block discarded – undo
2214 2339
 			require_once($sourcedir . '/ScheduledTasks.php');
2215 2340
 
2216 2341
 			// What to do, what to do?!
2217
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2218
-				AutoTask();
2219
-			else
2220
-				ReduceMailQueue();
2221
-		}
2222
-		else
2342
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2343
+							AutoTask();
2344
+			} else {
2345
+							ReduceMailQueue();
2346
+			}
2347
+		} else
2223 2348
 		{
2224 2349
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2225 2350
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2270,8 +2395,9 @@  discard block
 block discarded – undo
2270 2395
 		foreach ($theme_includes as $include)
2271 2396
 		{
2272 2397
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2273
-			if (file_exists($include))
2274
-				require_once($include);
2398
+			if (file_exists($include)) {
2399
+							require_once($include);
2400
+			}
2275 2401
 		}
2276 2402
 	}
2277 2403
 
@@ -2301,16 +2427,19 @@  discard block
 block discarded – undo
2301 2427
 	// Do any style sheets first, cause we're easy with those.
2302 2428
 	if (!empty($style_sheets))
2303 2429
 	{
2304
-		if (!is_array($style_sheets))
2305
-			$style_sheets = array($style_sheets);
2430
+		if (!is_array($style_sheets)) {
2431
+					$style_sheets = array($style_sheets);
2432
+		}
2306 2433
 
2307
-		foreach ($style_sheets as $sheet)
2308
-			loadCSSFile($sheet . '.css', array(), $sheet);
2434
+		foreach ($style_sheets as $sheet) {
2435
+					loadCSSFile($sheet . '.css', array(), $sheet);
2436
+		}
2309 2437
 	}
2310 2438
 
2311 2439
 	// No template to load?
2312
-	if ($template_name === false)
2313
-		return true;
2440
+	if ($template_name === false) {
2441
+			return true;
2442
+	}
2314 2443
 
2315 2444
 	$loaded = false;
2316 2445
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2325,12 +2454,14 @@  discard block
 block discarded – undo
2325 2454
 
2326 2455
 	if ($loaded)
2327 2456
 	{
2328
-		if ($db_show_debug === true)
2329
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2457
+		if ($db_show_debug === true) {
2458
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2459
+		}
2330 2460
 
2331 2461
 		// If they have specified an initialization function for this template, go ahead and call it now.
2332
-		if (function_exists('template_' . $template_name . '_init'))
2333
-			call_user_func('template_' . $template_name . '_init');
2462
+		if (function_exists('template_' . $template_name . '_init')) {
2463
+					call_user_func('template_' . $template_name . '_init');
2464
+		}
2334 2465
 	}
2335 2466
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2336 2467
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2350,13 +2481,14 @@  discard block
 block discarded – undo
2350 2481
 		loadTemplate($template_name);
2351 2482
 	}
2352 2483
 	// Cause an error otherwise.
2353
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2354
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2355
-	elseif ($fatal)
2356
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2357
-	else
2358
-		return false;
2359
-}
2484
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2485
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2486
+	} elseif ($fatal) {
2487
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2488
+	} else {
2489
+			return false;
2490
+	}
2491
+	}
2360 2492
 
2361 2493
 /**
2362 2494
  * Load a sub-template.
@@ -2374,17 +2506,19 @@  discard block
 block discarded – undo
2374 2506
 {
2375 2507
 	global $context, $txt, $db_show_debug;
2376 2508
 
2377
-	if ($db_show_debug === true)
2378
-		$context['debug']['sub_templates'][] = $sub_template_name;
2509
+	if ($db_show_debug === true) {
2510
+			$context['debug']['sub_templates'][] = $sub_template_name;
2511
+	}
2379 2512
 
2380 2513
 	// Figure out what the template function is named.
2381 2514
 	$theme_function = 'template_' . $sub_template_name;
2382
-	if (function_exists($theme_function))
2383
-		$theme_function();
2384
-	elseif ($fatal === false)
2385
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2386
-	elseif ($fatal !== 'ignore')
2387
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2515
+	if (function_exists($theme_function)) {
2516
+			$theme_function();
2517
+	} elseif ($fatal === false) {
2518
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2519
+	} elseif ($fatal !== 'ignore') {
2520
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2521
+	}
2388 2522
 
2389 2523
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2390 2524
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2421,8 +2555,9 @@  discard block
 block discarded – undo
2421 2555
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2422 2556
 
2423 2557
 	// If this is an external file, automatically set this to false.
2424
-	if (!empty($params['external']))
2425
-		$params['minimize'] = false;
2558
+	if (!empty($params['external'])) {
2559
+			$params['minimize'] = false;
2560
+	}
2426 2561
 
2427 2562
 	// Account for shorthand like admin.css?alp21 filenames
2428 2563
 	$has_seed = strpos($fileName, '.css?');
@@ -2439,13 +2574,10 @@  discard block
 block discarded – undo
2439 2574
 			{
2440 2575
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2441 2576
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2577
+			} else {
2578
+							$fileUrl = false;
2442 2579
 			}
2443
-
2444
-			else
2445
-				$fileUrl = false;
2446
-		}
2447
-
2448
-		else
2580
+		} else
2449 2581
 		{
2450 2582
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2451 2583
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2460,12 +2592,14 @@  discard block
 block discarded – undo
2460 2592
 	}
2461 2593
 
2462 2594
 	// Add it to the array for use in the template
2463
-	if (!empty($fileName))
2464
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2595
+	if (!empty($fileName)) {
2596
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2597
+	}
2465 2598
 
2466
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2467
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2468
-}
2599
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2600
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2601
+	}
2602
+	}
2469 2603
 
2470 2604
 /**
2471 2605
  * Add a block of inline css code to be executed later
@@ -2482,8 +2616,9 @@  discard block
 block discarded – undo
2482 2616
 	global $context;
2483 2617
 
2484 2618
 	// Gotta add something...
2485
-	if (empty($css))
2486
-		return false;
2619
+	if (empty($css)) {
2620
+			return false;
2621
+	}
2487 2622
 
2488 2623
 	$context['css_header'][] = $css;
2489 2624
 }
@@ -2518,8 +2653,9 @@  discard block
 block discarded – undo
2518 2653
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2519 2654
 
2520 2655
 	// If this is an external file, automatically set this to false.
2521
-	if (!empty($params['external']))
2522
-		$params['minimize'] = false;
2656
+	if (!empty($params['external'])) {
2657
+			$params['minimize'] = false;
2658
+	}
2523 2659
 
2524 2660
 	// Account for shorthand like admin.js?alp21 filenames
2525 2661
 	$has_seed = strpos($fileName, '.js?');
@@ -2536,16 +2672,12 @@  discard block
 block discarded – undo
2536 2672
 			{
2537 2673
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2538 2674
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2539
-			}
2540
-
2541
-			else
2675
+			} else
2542 2676
 			{
2543 2677
 				$fileUrl = false;
2544 2678
 				$filePath = false;
2545 2679
 			}
2546
-		}
2547
-
2548
-		else
2680
+		} else
2549 2681
 		{
2550 2682
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2551 2683
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2560,9 +2692,10 @@  discard block
 block discarded – undo
2560 2692
 	}
2561 2693
 
2562 2694
 	// Add it to the array for use in the template
2563
-	if (!empty($fileName))
2564
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2565
-}
2695
+	if (!empty($fileName)) {
2696
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2697
+	}
2698
+	}
2566 2699
 
2567 2700
 /**
2568 2701
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2576,9 +2709,10 @@  discard block
 block discarded – undo
2576 2709
 {
2577 2710
 	global $context;
2578 2711
 
2579
-	if (!empty($key) && (!empty($value) || $value === '0'))
2580
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2581
-}
2712
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2713
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2714
+	}
2715
+	}
2582 2716
 
2583 2717
 /**
2584 2718
  * Add a block of inline Javascript code to be executed later
@@ -2595,8 +2729,9 @@  discard block
 block discarded – undo
2595 2729
 {
2596 2730
 	global $context;
2597 2731
 
2598
-	if (empty($javascript))
2599
-		return false;
2732
+	if (empty($javascript)) {
2733
+			return false;
2734
+	}
2600 2735
 
2601 2736
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2602 2737
 }
@@ -2617,15 +2752,18 @@  discard block
 block discarded – undo
2617 2752
 	static $already_loaded = array();
2618 2753
 
2619 2754
 	// Default to the user's language.
2620
-	if ($lang == '')
2621
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2755
+	if ($lang == '') {
2756
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2757
+	}
2622 2758
 
2623 2759
 	// Do we want the English version of language file as fallback?
2624
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2625
-		loadLanguage($template_name, 'english', false);
2760
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2761
+			loadLanguage($template_name, 'english', false);
2762
+	}
2626 2763
 
2627
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2628
-		return $lang;
2764
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2765
+			return $lang;
2766
+	}
2629 2767
 
2630 2768
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2631 2769
 	if (empty($settings['default_theme_dir']))
@@ -2636,8 +2774,9 @@  discard block
 block discarded – undo
2636 2774
 
2637 2775
 	// What theme are we in?
2638 2776
 	$theme_name = basename($settings['theme_url']);
2639
-	if (empty($theme_name))
2640
-		$theme_name = 'unknown';
2777
+	if (empty($theme_name)) {
2778
+			$theme_name = 'unknown';
2779
+	}
2641 2780
 
2642 2781
 	// For each file open it up and write it out!
2643 2782
 	foreach (explode('+', $template_name) as $template)
@@ -2679,8 +2818,9 @@  discard block
 block discarded – undo
2679 2818
 				$found = true;
2680 2819
 
2681 2820
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2682
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2683
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2821
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2822
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2823
+				}
2684 2824
 
2685 2825
 				break;
2686 2826
 			}
@@ -2720,8 +2860,9 @@  discard block
 block discarded – undo
2720 2860
 	}
2721 2861
 
2722 2862
 	// Keep track of what we're up to soldier.
2723
-	if ($db_show_debug === true)
2724
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2863
+	if ($db_show_debug === true) {
2864
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2865
+	}
2725 2866
 
2726 2867
 	// Remember what we have loaded, and in which language.
2727 2868
 	$already_loaded[$template_name] = $lang;
@@ -2767,8 +2908,9 @@  discard block
 block discarded – undo
2767 2908
 				)
2768 2909
 			);
2769 2910
 			// In the EXTREMELY unlikely event this happens, give an error message.
2770
-			if ($smcFunc['db_num_rows']($result) == 0)
2771
-				fatal_lang_error('parent_not_found', 'critical');
2911
+			if ($smcFunc['db_num_rows']($result) == 0) {
2912
+							fatal_lang_error('parent_not_found', 'critical');
2913
+			}
2772 2914
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2773 2915
 			{
2774 2916
 				if (!isset($boards[$row['id_board']]))
@@ -2785,8 +2927,8 @@  discard block
 block discarded – undo
2785 2927
 					);
2786 2928
 				}
2787 2929
 				// If a moderator exists for this board, add that moderator for all children too.
2788
-				if (!empty($row['id_moderator']))
2789
-					foreach ($boards as $id => $dummy)
2930
+				if (!empty($row['id_moderator'])) {
2931
+									foreach ($boards as $id => $dummy)
2790 2932
 					{
2791 2933
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2792 2934
 							'id' => $row['id_moderator'],
@@ -2794,11 +2936,12 @@  discard block
 block discarded – undo
2794 2936
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2795 2937
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2796 2938
 						);
2939
+				}
2797 2940
 					}
2798 2941
 
2799 2942
 				// If a moderator group exists for this board, add that moderator group for all children too
2800
-				if (!empty($row['id_moderator_group']))
2801
-					foreach ($boards as $id => $dummy)
2943
+				if (!empty($row['id_moderator_group'])) {
2944
+									foreach ($boards as $id => $dummy)
2802 2945
 					{
2803 2946
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2804 2947
 							'id' => $row['id_moderator_group'],
@@ -2806,6 +2949,7 @@  discard block
 block discarded – undo
2806 2949
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2807 2950
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2808 2951
 						);
2952
+				}
2809 2953
 					}
2810 2954
 			}
2811 2955
 			$smcFunc['db_free_result']($result);
@@ -2832,23 +2976,27 @@  discard block
 block discarded – undo
2832 2976
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2833 2977
 	{
2834 2978
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2835
-		if (empty($smcFunc['ucwords']))
2836
-			reloadSettings();
2979
+		if (empty($smcFunc['ucwords'])) {
2980
+					reloadSettings();
2981
+		}
2837 2982
 
2838 2983
 		// If we don't have our theme information yet, let's get it.
2839
-		if (empty($settings['default_theme_dir']))
2840
-			loadTheme(0, false);
2984
+		if (empty($settings['default_theme_dir'])) {
2985
+					loadTheme(0, false);
2986
+		}
2841 2987
 
2842 2988
 		// Default language directories to try.
2843 2989
 		$language_directories = array(
2844 2990
 			$settings['default_theme_dir'] . '/languages',
2845 2991
 		);
2846
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2847
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2992
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2993
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2994
+		}
2848 2995
 
2849 2996
 		// We possibly have a base theme directory.
2850
-		if (!empty($settings['base_theme_dir']))
2851
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2997
+		if (!empty($settings['base_theme_dir'])) {
2998
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2999
+		}
2852 3000
 
2853 3001
 		// Remove any duplicates.
2854 3002
 		$language_directories = array_unique($language_directories);
@@ -2862,20 +3010,21 @@  discard block
 block discarded – undo
2862 3010
 		foreach ($language_directories as $language_dir)
2863 3011
 		{
2864 3012
 			// Can't look in here... doesn't exist!
2865
-			if (!file_exists($language_dir))
2866
-				continue;
3013
+			if (!file_exists($language_dir)) {
3014
+							continue;
3015
+			}
2867 3016
 
2868 3017
 			$dir = dir($language_dir);
2869 3018
 			while ($entry = $dir->read())
2870 3019
 			{
2871 3020
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2872
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2873
-					continue;
2874
-
2875
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2876
-					$langName = $langList[$matches[1]];
3021
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3022
+									continue;
3023
+				}
2877 3024
 
2878
-				else
3025
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3026
+									$langName = $langList[$matches[1]];
3027
+				} else
2879 3028
 				{
2880 3029
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2881 3030
 
@@ -2916,12 +3065,14 @@  discard block
 block discarded – undo
2916 3065
 		}
2917 3066
 
2918 3067
 		// Do we need to store the lang list?
2919
-		if (empty($langList))
2920
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3068
+		if (empty($langList)) {
3069
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3070
+		}
2921 3071
 
2922 3072
 		// Let's cash in on this deal.
2923
-		if (!empty($modSettings['cache_enable']))
2924
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3073
+		if (!empty($modSettings['cache_enable'])) {
3074
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3075
+		}
2925 3076
 	}
2926 3077
 
2927 3078
 	return $context['languages'];
@@ -2944,8 +3095,9 @@  discard block
 block discarded – undo
2944 3095
 	global $modSettings, $options, $txt;
2945 3096
 	static $censor_vulgar = null, $censor_proper;
2946 3097
 
2947
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2948
-		return $text;
3098
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3099
+			return $text;
3100
+	}
2949 3101
 
2950 3102
 	// If they haven't yet been loaded, load them.
2951 3103
 	if ($censor_vulgar == null)
@@ -2973,9 +3125,9 @@  discard block
 block discarded – undo
2973 3125
 	{
2974 3126
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2975 3127
 		$text = $func($censor_vulgar, $censor_proper, $text);
3128
+	} else {
3129
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2976 3130
 	}
2977
-	else
2978
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2979 3131
 
2980 3132
 	return $text;
2981 3133
 }
@@ -3001,38 +3153,42 @@  discard block
 block discarded – undo
3001 3153
 	@ini_set('track_errors', '1');
3002 3154
 
3003 3155
 	// Don't include the file more than once, if $once is true.
3004
-	if ($once && in_array($filename, $templates))
3005
-		return;
3156
+	if ($once && in_array($filename, $templates)) {
3157
+			return;
3158
+	}
3006 3159
 	// Add this file to the include list, whether $once is true or not.
3007
-	else
3008
-		$templates[] = $filename;
3160
+	else {
3161
+			$templates[] = $filename;
3162
+	}
3009 3163
 
3010 3164
 	// Are we going to use eval?
3011 3165
 	if (empty($modSettings['disableTemplateEval']))
3012 3166
 	{
3013 3167
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
3014 3168
 		$settings['current_include_filename'] = $filename;
3015
-	}
3016
-	else
3169
+	} else
3017 3170
 	{
3018 3171
 		$file_found = file_exists($filename);
3019 3172
 
3020
-		if ($once && $file_found)
3021
-			require_once($filename);
3022
-		elseif ($file_found)
3023
-			require($filename);
3173
+		if ($once && $file_found) {
3174
+					require_once($filename);
3175
+		} elseif ($file_found) {
3176
+					require($filename);
3177
+		}
3024 3178
 	}
3025 3179
 
3026 3180
 	if ($file_found !== true)
3027 3181
 	{
3028 3182
 		ob_end_clean();
3029
-		if (!empty($modSettings['enableCompressedOutput']))
3030
-			@ob_start('ob_gzhandler');
3031
-		else
3032
-			ob_start();
3183
+		if (!empty($modSettings['enableCompressedOutput'])) {
3184
+					@ob_start('ob_gzhandler');
3185
+		} else {
3186
+					ob_start();
3187
+		}
3033 3188
 
3034
-		if (isset($_GET['debug']))
3035
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3189
+		if (isset($_GET['debug'])) {
3190
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3191
+		}
3036 3192
 
3037 3193
 		// Don't cache error pages!!
3038 3194
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3051,12 +3207,13 @@  discard block
 block discarded – undo
3051 3207
 		echo '<!DOCTYPE html>
3052 3208
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3053 3209
 	<head>';
3054
-		if (isset($context['character_set']))
3055
-			echo '
3210
+		if (isset($context['character_set'])) {
3211
+					echo '
3056 3212
 		<meta charset="', $context['character_set'], '">';
3213
+		}
3057 3214
 
3058
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3059
-			echo '
3215
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3216
+					echo '
3060 3217
 		<title>', $mtitle, '</title>
3061 3218
 	</head>
3062 3219
 	<body>
@@ -3064,8 +3221,8 @@  discard block
 block discarded – undo
3064 3221
 		', $mmessage, '
3065 3222
 	</body>
3066 3223
 </html>';
3067
-		elseif (!allowedTo('admin_forum'))
3068
-			echo '
3224
+		} elseif (!allowedTo('admin_forum')) {
3225
+					echo '
3069 3226
 		<title>', $txt['template_parse_error'], '</title>
3070 3227
 	</head>
3071 3228
 	<body>
@@ -3073,16 +3230,18 @@  discard block
 block discarded – undo
3073 3230
 		', $txt['template_parse_error_message'], '
3074 3231
 	</body>
3075 3232
 </html>';
3076
-		else
3233
+		} else
3077 3234
 		{
3078 3235
 			require_once($sourcedir . '/Subs-Package.php');
3079 3236
 
3080 3237
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3081 3238
 			$error_array = error_get_last();
3082
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3083
-				$error = $error_array['message'];
3084
-			if (empty($error))
3085
-				$error = $txt['template_parse_errmsg'];
3239
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3240
+							$error = $error_array['message'];
3241
+			}
3242
+			if (empty($error)) {
3243
+							$error = $txt['template_parse_errmsg'];
3244
+			}
3086 3245
 
3087 3246
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3088 3247
 
@@ -3093,11 +3252,12 @@  discard block
 block discarded – undo
3093 3252
 		<h3>', $txt['template_parse_error'], '</h3>
3094 3253
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3095 3254
 
3096
-			if (!empty($error))
3097
-				echo '
3255
+			if (!empty($error)) {
3256
+							echo '
3098 3257
 		<hr>
3099 3258
 
3100 3259
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3260
+			}
3101 3261
 
3102 3262
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3103 3263
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3107,10 +3267,11 @@  discard block
 block discarded – undo
3107 3267
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3108 3268
 
3109 3269
 				// Fix the PHP code stuff...
3110
-				if (!isBrowser('gecko'))
3111
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3112
-				else
3113
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3270
+				if (!isBrowser('gecko')) {
3271
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3272
+				} else {
3273
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3274
+				}
3114 3275
 
3115 3276
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3116 3277
 				$j = -1;
@@ -3118,8 +3279,9 @@  discard block
 block discarded – undo
3118 3279
 				{
3119 3280
 					$j++;
3120 3281
 
3121
-					if (substr_count($line, '<br>') == 0)
3122
-						continue;
3282
+					if (substr_count($line, '<br>') == 0) {
3283
+											continue;
3284
+					}
3123 3285
 
3124 3286
 					$n = substr_count($line, '<br>');
3125 3287
 					for ($i = 0; $i < $n; $i++)
@@ -3138,38 +3300,42 @@  discard block
 block discarded – undo
3138 3300
 				// Figure out what the color coding was before...
3139 3301
 				$line = max($match[1] - 9, 1);
3140 3302
 				$last_line = '';
3141
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3142
-					if (strpos($data2[$line2], '<') !== false)
3303
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3304
+									if (strpos($data2[$line2], '<') !== false)
3143 3305
 					{
3144 3306
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3145 3307
 							$last_line = $color_match[1];
3308
+				}
3146 3309
 						break;
3147 3310
 					}
3148 3311
 
3149 3312
 				// Show the relevant lines...
3150 3313
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3151 3314
 				{
3152
-					if ($line == $match[1])
3153
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3315
+					if ($line == $match[1]) {
3316
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3317
+					}
3154 3318
 
3155 3319
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3156
-					if (isset($data2[$line]) && $data2[$line] != '')
3157
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3320
+					if (isset($data2[$line]) && $data2[$line] != '') {
3321
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3322
+					}
3158 3323
 
3159 3324
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3160 3325
 					{
3161 3326
 						$last_line = $color_match[1];
3162 3327
 						echo '</', substr($last_line, 1, 4), '>';
3328
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3329
+											$last_line = '';
3330
+					} elseif ($last_line != '' && $data2[$line] != '') {
3331
+											echo '</', substr($last_line, 1, 4), '>';
3163 3332
 					}
3164
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3165
-						$last_line = '';
3166
-					elseif ($last_line != '' && $data2[$line] != '')
3167
-						echo '</', substr($last_line, 1, 4), '>';
3168 3333
 
3169
-					if ($line == $match[1])
3170
-						echo '</pre></div><pre style="margin: 0;">';
3171
-					else
3172
-						echo "\n";
3334
+					if ($line == $match[1]) {
3335
+											echo '</pre></div><pre style="margin: 0;">';
3336
+					} else {
3337
+											echo "\n";
3338
+					}
3173 3339
 				}
3174 3340
 
3175 3341
 				echo '</pre></div>';
@@ -3193,8 +3359,9 @@  discard block
 block discarded – undo
3193 3359
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3194 3360
 
3195 3361
 	// Figure out what type of database we are using.
3196
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3197
-		$db_type = 'mysql';
3362
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3363
+			$db_type = 'mysql';
3364
+	}
3198 3365
 
3199 3366
 	// Load the file for the database.
3200 3367
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3202,8 +3369,9 @@  discard block
 block discarded – undo
3202 3369
 	$db_options = array();
3203 3370
 
3204 3371
 	// Add in the port if needed
3205
-	if (!empty($db_port))
3206
-		$db_options['port'] = $db_port;
3372
+	if (!empty($db_port)) {
3373
+			$db_options['port'] = $db_port;
3374
+	}
3207 3375
 
3208 3376
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3209 3377
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3222,13 +3390,15 @@  discard block
 block discarded – undo
3222 3390
 	}
3223 3391
 
3224 3392
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3225
-	if (!$db_connection)
3226
-		display_db_error();
3393
+	if (!$db_connection) {
3394
+			display_db_error();
3395
+	}
3227 3396
 
3228 3397
 	// If in SSI mode fix up the prefix.
3229
-	if (SMF == 'SSI')
3230
-		db_fix_prefix($db_prefix, $db_name);
3231
-}
3398
+	if (SMF == 'SSI') {
3399
+			db_fix_prefix($db_prefix, $db_name);
3400
+	}
3401
+	}
3232 3402
 
3233 3403
 /**
3234 3404
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3242,10 +3412,11 @@  discard block
 block discarded – undo
3242 3412
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3243 3413
 
3244 3414
 	// Not overriding this and we have a cacheAPI, send it back.
3245
-	if (empty($overrideCache) && is_object($cacheAPI))
3246
-		return $cacheAPI;
3247
-	elseif (is_null($cacheAPI))
3248
-		$cacheAPI = false;
3415
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3416
+			return $cacheAPI;
3417
+	} elseif (is_null($cacheAPI)) {
3418
+			$cacheAPI = false;
3419
+	}
3249 3420
 
3250 3421
 	// Make sure our class is in session.
3251 3422
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3266,8 +3437,9 @@  discard block
 block discarded – undo
3266 3437
 		if (!$testAPI->isSupported())
3267 3438
 		{
3268 3439
 			// Can we save ourselves?
3269
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3270
-				return loadCacheAccelerator(null, false);
3440
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3441
+							return loadCacheAccelerator(null, false);
3442
+			}
3271 3443
 			return false;
3272 3444
 		}
3273 3445
 
@@ -3279,9 +3451,9 @@  discard block
 block discarded – undo
3279 3451
 		{
3280 3452
 			$cacheAPI = $testAPI;
3281 3453
 			return $cacheAPI;
3454
+		} else {
3455
+					return $testAPI;
3282 3456
 		}
3283
-		else
3284
-			return $testAPI;
3285 3457
 	}
3286 3458
 }
3287 3459
 
@@ -3301,8 +3473,9 @@  discard block
 block discarded – undo
3301 3473
 
3302 3474
 	// @todo Why are we doing this if caching is disabled?
3303 3475
 
3304
-	if (function_exists('call_integration_hook'))
3305
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3476
+	if (function_exists('call_integration_hook')) {
3477
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3478
+	}
3306 3479
 
3307 3480
 	/* Refresh the cache if either:
3308 3481
 		1. Caching is disabled.
@@ -3316,16 +3489,19 @@  discard block
 block discarded – undo
3316 3489
 		require_once($sourcedir . '/' . $file);
3317 3490
 		$cache_block = call_user_func_array($function, $params);
3318 3491
 
3319
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3320
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3492
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3493
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3494
+		}
3321 3495
 	}
3322 3496
 
3323 3497
 	// Some cached data may need a freshening up after retrieval.
3324
-	if (!empty($cache_block['post_retri_eval']))
3325
-		eval($cache_block['post_retri_eval']);
3498
+	if (!empty($cache_block['post_retri_eval'])) {
3499
+			eval($cache_block['post_retri_eval']);
3500
+	}
3326 3501
 
3327
-	if (function_exists('call_integration_hook'))
3328
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3502
+	if (function_exists('call_integration_hook')) {
3503
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3504
+	}
3329 3505
 
3330 3506
 	return $cache_block['data'];
3331 3507
 }
@@ -3352,8 +3528,9 @@  discard block
 block discarded – undo
3352 3528
 	global $smcFunc, $cache_enable, $cacheAPI;
3353 3529
 	global $cache_hits, $cache_count, $db_show_debug;
3354 3530
 
3355
-	if (empty($cache_enable) || empty($cacheAPI))
3356
-		return;
3531
+	if (empty($cache_enable) || empty($cacheAPI)) {
3532
+			return;
3533
+	}
3357 3534
 
3358 3535
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3359 3536
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3366,12 +3543,14 @@  discard block
 block discarded – undo
3366 3543
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3367 3544
 	$cacheAPI->putData($key, $value, $ttl);
3368 3545
 
3369
-	if (function_exists('call_integration_hook'))
3370
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3546
+	if (function_exists('call_integration_hook')) {
3547
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3548
+	}
3371 3549
 
3372
-	if (isset($db_show_debug) && $db_show_debug === true)
3373
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3374
-}
3550
+	if (isset($db_show_debug) && $db_show_debug === true) {
3551
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3552
+	}
3553
+	}
3375 3554
 
3376 3555
 /**
3377 3556
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3387,8 +3566,9 @@  discard block
 block discarded – undo
3387 3566
 	global $smcFunc, $cache_enable, $cacheAPI;
3388 3567
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3389 3568
 
3390
-	if (empty($cache_enable) || empty($cacheAPI))
3391
-		return;
3569
+	if (empty($cache_enable) || empty($cacheAPI)) {
3570
+			return;
3571
+	}
3392 3572
 
3393 3573
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3394 3574
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3408,16 +3588,18 @@  discard block
 block discarded – undo
3408 3588
 
3409 3589
 		if (empty($value))
3410 3590
 		{
3411
-			if (!is_array($cache_misses))
3412
-				$cache_misses = array();
3591
+			if (!is_array($cache_misses)) {
3592
+							$cache_misses = array();
3593
+			}
3413 3594
 
3414 3595
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3415 3596
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3416 3597
 		}
3417 3598
 	}
3418 3599
 
3419
-	if (function_exists('call_integration_hook') && isset($value))
3420
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3600
+	if (function_exists('call_integration_hook') && isset($value)) {
3601
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3602
+	}
3421 3603
 
3422 3604
 	return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3423 3605
 }
@@ -3439,8 +3621,9 @@  discard block
 block discarded – undo
3439 3621
 	global $cacheAPI;
3440 3622
 
3441 3623
 	// If we can't get to the API, can't do this.
3442
-	if (empty($cacheAPI))
3443
-		return;
3624
+	if (empty($cacheAPI)) {
3625
+			return;
3626
+	}
3444 3627
 
3445 3628
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3446 3629
 	$cacheAPI->cleanCache($type);
@@ -3465,8 +3648,9 @@  discard block
 block discarded – undo
3465 3648
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3466 3649
 
3467 3650
 	// Come on!
3468
-	if (empty($data))
3469
-		return array();
3651
+	if (empty($data)) {
3652
+			return array();
3653
+	}
3470 3654
 
3471 3655
 	// Set a nice default var.
3472 3656
 	$image = '';
@@ -3474,11 +3658,11 @@  discard block
 block discarded – undo
3474 3658
 	// Gravatar has been set as mandatory!
3475 3659
 	if (!empty($modSettings['gravatarOverride']))
3476 3660
 	{
3477
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3478
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3479
-
3480
-		else if (!empty($data['email']))
3481
-			$image = get_gravatar_url($data['email']);
3661
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3662
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3663
+		} else if (!empty($data['email'])) {
3664
+					$image = get_gravatar_url($data['email']);
3665
+		}
3482 3666
 	}
3483 3667
 
3484 3668
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3490,54 +3674,60 @@  discard block
 block discarded – undo
3490 3674
 			// Gravatar.
3491 3675
 			if (stristr($data['avatar'], 'gravatar://'))
3492 3676
 			{
3493
-				if ($data['avatar'] == 'gravatar://')
3494
-					$image = get_gravatar_url($data['email']);
3495
-
3496
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3497
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3677
+				if ($data['avatar'] == 'gravatar://') {
3678
+									$image = get_gravatar_url($data['email']);
3679
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3680
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3681
+				}
3498 3682
 			}
3499 3683
 
3500 3684
 			// External url.
3501 3685
 			else
3502 3686
 			{
3503 3687
 				// Using ssl?
3504
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3505
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3688
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3689
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3690
+				}
3506 3691
 
3507 3692
 				// Just a plain external url.
3508
-				else
3509
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3693
+				else {
3694
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3695
+				}
3510 3696
 			}
3511 3697
 		}
3512 3698
 
3513 3699
 		// Perhaps this user has an attachment as avatar...
3514
-		else if (!empty($data['filename']))
3515
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3700
+		else if (!empty($data['filename'])) {
3701
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3702
+		}
3516 3703
 
3517 3704
 		// Right... no avatar... use our default image.
3518
-		else
3519
-			$image = $modSettings['avatar_url'] . '/default.png';
3705
+		else {
3706
+					$image = $modSettings['avatar_url'] . '/default.png';
3707
+		}
3520 3708
 	}
3521 3709
 
3522 3710
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3523 3711
 
3524 3712
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3525
-	if (!empty($image))
3526
-		return array(
3713
+	if (!empty($image)) {
3714
+			return array(
3527 3715
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3528 3716
 			'image' => '<img class="avatar" src="' . $image . '" />',
3529 3717
 			'href' => $image,
3530 3718
 			'url' => $image,
3531 3719
 		);
3720
+	}
3532 3721
 
3533 3722
 	// Fallback to make life easier for everyone...
3534
-	else
3535
-		return array(
3723
+	else {
3724
+			return array(
3536 3725
 			'name' => '',
3537 3726
 			'image' => '',
3538 3727
 			'href' => '',
3539 3728
 			'url' => '',
3540 3729
 		);
3541
-}
3730
+	}
3731
+	}
3542 3732
 
3543 3733
 ?>
3544 3734
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 1 patch
Braces   +274 added lines, -203 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -62,9 +63,11 @@  discard block
 block discarded – undo
62 63
 			'db_fetch_all'              => 'smf_db_fetch_all',
63 64
 			'db_error_insert'			=> 'smf_db_error_insert',
64 65
 		);
66
+	}
65 67
 
66
-	if (!empty($db_options['persist']))
67
-		$db_server = 'p:' . $db_server;
68
+	if (!empty($db_options['persist'])) {
69
+			$db_server = 'p:' . $db_server;
70
+	}
68 71
 
69 72
 	$connection = mysqli_init();
70 73
 
@@ -73,24 +76,27 @@  discard block
 block discarded – undo
73 76
 	$success = false;
74 77
 
75 78
 	if ($connection) {
76
-		if (!empty($db_options['port']))
77
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
78
-		else
79
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
79
+		if (!empty($db_options['port'])) {
80
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
81
+		} else {
82
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
83
+		}
80 84
 	}
81 85
 
82 86
 	// Something's wrong, show an error if its fatal (which we assume it is)
83 87
 	if ($success === false)
84 88
 	{
85
-		if (!empty($db_options['non_fatal']))
86
-			return null;
87
-		else
88
-			display_db_error();
89
+		if (!empty($db_options['non_fatal'])) {
90
+					return null;
91
+		} else {
92
+					display_db_error();
93
+		}
89 94
 	}
90 95
 
91 96
 	// Select the database, unless told not to
92
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
93
-		display_db_error();
97
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
98
+			display_db_error();
99
+	}
94 100
 
95 101
 	$smcFunc['db_query']('', 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'',
96 102
 		array(),
@@ -166,34 +172,42 @@  discard block
 block discarded – undo
166 172
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
167 173
 
168 174
 	list ($values, $connection) = $db_callback;
169
-	if (!is_object($connection))
170
-		display_db_error();
175
+	if (!is_object($connection)) {
176
+			display_db_error();
177
+	}
171 178
 
172
-	if ($matches[1] === 'db_prefix')
173
-		return $db_prefix;
179
+	if ($matches[1] === 'db_prefix') {
180
+			return $db_prefix;
181
+	}
174 182
 
175
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
176
-		return $user_info[$matches[1]];
183
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
184
+			return $user_info[$matches[1]];
185
+	}
177 186
 
178
-	if ($matches[1] === 'empty')
179
-		return '\'\'';
187
+	if ($matches[1] === 'empty') {
188
+			return '\'\'';
189
+	}
180 190
 
181
-	if (!isset($matches[2]))
182
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
191
+	if (!isset($matches[2])) {
192
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
193
+	}
183 194
 
184
-	if ($matches[1] === 'literal')
185
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
195
+	if ($matches[1] === 'literal') {
196
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
197
+	}
186 198
 
187
-	if (!isset($values[$matches[2]]))
188
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
199
+	if (!isset($values[$matches[2]])) {
200
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
201
+	}
189 202
 
190 203
 	$replacement = $values[$matches[2]];
191 204
 
192 205
 	switch ($matches[1])
193 206
 	{
194 207
 		case 'int':
195
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
196
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
208
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
209
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
210
+			}
197 211
 			return (string) (int) $replacement;
198 212
 		break;
199 213
 
@@ -205,65 +219,73 @@  discard block
 block discarded – undo
205 219
 		case 'array_int':
206 220
 			if (is_array($replacement))
207 221
 			{
208
-				if (empty($replacement))
209
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222
+				if (empty($replacement)) {
223
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224
+				}
210 225
 
211 226
 				foreach ($replacement as $key => $value)
212 227
 				{
213
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
214
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
228
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
229
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
230
+					}
215 231
 
216 232
 					$replacement[$key] = (string) (int) $value;
217 233
 				}
218 234
 
219 235
 				return implode(', ', $replacement);
236
+			} else {
237
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220 238
 			}
221
-			else
222
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
223 239
 
224 240
 		break;
225 241
 
226 242
 		case 'array_string':
227 243
 			if (is_array($replacement))
228 244
 			{
229
-				if (empty($replacement))
230
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
245
+				if (empty($replacement)) {
246
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
247
+				}
231 248
 
232
-				foreach ($replacement as $key => $value)
233
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
249
+				foreach ($replacement as $key => $value) {
250
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
251
+				}
234 252
 
235 253
 				return implode(', ', $replacement);
254
+			} else {
255
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
236 256
 			}
237
-			else
238
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
239 257
 		break;
240 258
 
241 259
 		case 'date':
242
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
243
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
244
-			else
245
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
260
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
261
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
262
+			} else {
263
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
264
+			}
246 265
 		break;
247 266
 
248 267
 		case 'time':
249
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
250
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
251
-			else
252
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
268
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
269
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
270
+			} else {
271
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
272
+			}
253 273
 		break;
254 274
 
255 275
 		case 'datetime':
256
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
257
-				return 'str_to_date('.
276
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
277
+							return 'str_to_date('.
258 278
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
259 279
 					',\'%Y-%m-%d %h:%i:%s\')';
260
-			else
261
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
280
+			} else {
281
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
282
+			}
262 283
 		break;
263 284
 
264 285
 		case 'float':
265
-			if (!is_numeric($replacement))
266
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
286
+			if (!is_numeric($replacement)) {
287
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
288
+			}
267 289
 			return (string) (float) $replacement;
268 290
 		break;
269 291
 
@@ -277,32 +299,37 @@  discard block
 block discarded – undo
277 299
 		break;
278 300
 
279 301
 		case 'inet':
280
-			if ($replacement == 'null' || $replacement == '')
281
-				return 'null';
282
-			if (!isValidIP($replacement))
283
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
302
+			if ($replacement == 'null' || $replacement == '') {
303
+							return 'null';
304
+			}
305
+			if (!isValidIP($replacement)) {
306
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
307
+			}
284 308
 			//we don't use the native support of mysql > 5.6.2
285 309
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
286 310
 
287 311
 		case 'array_inet':
288 312
 			if (is_array($replacement))
289 313
 			{
290
-				if (empty($replacement))
291
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
314
+				if (empty($replacement)) {
315
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
316
+				}
292 317
 
293 318
 				foreach ($replacement as $key => $value)
294 319
 				{
295
-					if ($replacement == 'null' || $replacement == '')
296
-						$replacement[$key] = 'null';
297
-					if (!isValidIP($value))
298
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
320
+					if ($replacement == 'null' || $replacement == '') {
321
+											$replacement[$key] = 'null';
322
+					}
323
+					if (!isValidIP($value)) {
324
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
325
+					}
299 326
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
300 327
 				}
301 328
 
302 329
 				return implode(', ', $replacement);
330
+			} else {
331
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
303 332
 			}
304
-			else
305
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
306 333
 		break;
307 334
 
308 335
 		default:
@@ -378,22 +405,25 @@  discard block
 block discarded – undo
378 405
 		// Are we in SSI mode?  If so try that username and password first
379 406
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
380 407
 		{
381
-			if (empty($db_persist))
382
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
383
-			else
384
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
408
+			if (empty($db_persist)) {
409
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
410
+			} else {
411
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
412
+			}
385 413
 		}
386 414
 		// Fall back to the regular username and password if need be
387 415
 		if (!$db_connection)
388 416
 		{
389
-			if (empty($db_persist))
390
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
391
-			else
392
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
417
+			if (empty($db_persist)) {
418
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
419
+			} else {
420
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
421
+			}
393 422
 		}
394 423
 
395
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
396
-			$db_connection = false;
424
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
425
+					$db_connection = false;
426
+		}
397 427
 
398 428
 		$connection = $db_connection;
399 429
 	}
@@ -401,18 +431,20 @@  discard block
 block discarded – undo
401 431
 	// One more query....
402 432
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
403 433
 
404
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
405
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
434
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
435
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
436
+	}
406 437
 
407 438
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
408 439
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
409 440
 	{
410 441
 		// Add before LIMIT
411
-		if ($pos = strpos($db_string, 'LIMIT '))
412
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
413
-		else
414
-			// Append it.
442
+		if ($pos = strpos($db_string, 'LIMIT ')) {
443
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
444
+		} else {
445
+					// Append it.
415 446
 			$db_string .= "\n\t\t\tORDER BY null";
447
+		}
416 448
 	}
417 449
 
418 450
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -434,8 +466,9 @@  discard block
 block discarded – undo
434 466
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
435 467
 
436 468
 		// Initialize $db_cache if not already initialized.
437
-		if (!isset($db_cache))
438
-			$db_cache = array();
469
+		if (!isset($db_cache)) {
470
+					$db_cache = array();
471
+		}
439 472
 
440 473
 		if (!empty($_SESSION['debug_redirect']))
441 474
 		{
@@ -461,17 +494,18 @@  discard block
 block discarded – undo
461 494
 		while (true)
462 495
 		{
463 496
 			$pos = strpos($db_string, '\'', $pos + 1);
464
-			if ($pos === false)
465
-				break;
497
+			if ($pos === false) {
498
+							break;
499
+			}
466 500
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
467 501
 
468 502
 			while (true)
469 503
 			{
470 504
 				$pos1 = strpos($db_string, '\'', $pos + 1);
471 505
 				$pos2 = strpos($db_string, '\\', $pos + 1);
472
-				if ($pos1 === false)
473
-					break;
474
-				elseif ($pos2 === false || $pos2 > $pos1)
506
+				if ($pos1 === false) {
507
+									break;
508
+				} elseif ($pos2 === false || $pos2 > $pos1)
475 509
 				{
476 510
 					$pos = $pos1;
477 511
 					break;
@@ -487,29 +521,35 @@  discard block
 block discarded – undo
487 521
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
488 522
 
489 523
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
490
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
491
-			$fail = true;
524
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
525
+					$fail = true;
526
+		}
492 527
 		// Trying to change passwords, slow us down, or something?
493
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
494
-			$fail = true;
495
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
496
-			$fail = true;
528
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
529
+					$fail = true;
530
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
531
+					$fail = true;
532
+		}
497 533
 
498
-		if (!empty($fail) && function_exists('log_error'))
499
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
534
+		if (!empty($fail) && function_exists('log_error')) {
535
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
536
+		}
500 537
 	}
501 538
 
502
-	if (empty($db_unbuffered))
503
-		$ret = @mysqli_query($connection, $db_string);
504
-	else
505
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
539
+	if (empty($db_unbuffered)) {
540
+			$ret = @mysqli_query($connection, $db_string);
541
+	} else {
542
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
543
+	}
506 544
 
507
-	if ($ret === false && empty($db_values['db_error_skip']))
508
-		$ret = smf_db_error($db_string, $connection);
545
+	if ($ret === false && empty($db_values['db_error_skip'])) {
546
+			$ret = smf_db_error($db_string, $connection);
547
+	}
509 548
 
510 549
 	// Debugging.
511
-	if (isset($db_show_debug) && $db_show_debug === true)
512
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
550
+	if (isset($db_show_debug) && $db_show_debug === true) {
551
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
552
+	}
513 553
 
514 554
 	return $ret;
515 555
 }
@@ -556,12 +596,13 @@  discard block
 block discarded – undo
556 596
 	// Decide which connection to use
557 597
 	$connection = $connection === null ? $db_connection : $connection;
558 598
 
559
-	if ($type == 'begin')
560
-		return @mysqli_query($connection, 'BEGIN');
561
-	elseif ($type == 'rollback')
562
-		return @mysqli_query($connection, 'ROLLBACK');
563
-	elseif ($type == 'commit')
564
-		return @mysqli_query($connection, 'COMMIT');
599
+	if ($type == 'begin') {
600
+			return @mysqli_query($connection, 'BEGIN');
601
+	} elseif ($type == 'rollback') {
602
+			return @mysqli_query($connection, 'ROLLBACK');
603
+	} elseif ($type == 'commit') {
604
+			return @mysqli_query($connection, 'COMMIT');
605
+	}
565 606
 
566 607
 	return false;
567 608
 }
@@ -601,8 +642,9 @@  discard block
 block discarded – undo
601 642
 	//    2013: Lost connection to server during query.
602 643
 
603 644
 	// Log the error.
604
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
605
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
645
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
646
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
647
+	}
606 648
 
607 649
 	// Database error auto fixing ;).
608 650
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -611,8 +653,9 @@  discard block
 block discarded – undo
611 653
 		$old_cache = @$modSettings['cache_enable'];
612 654
 		$modSettings['cache_enable'] = '1';
613 655
 
614
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
615
-			$db_last_error = max(@$db_last_error, $temp);
656
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
657
+					$db_last_error = max(@$db_last_error, $temp);
658
+		}
616 659
 
617 660
 		if (@$db_last_error < time() - 3600 * 24 * 3)
618 661
 		{
@@ -628,8 +671,9 @@  discard block
 block discarded – undo
628 671
 					foreach ($tables as $table)
629 672
 					{
630 673
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
631
-						if (trim($table) != '')
632
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
674
+						if (trim($table) != '') {
675
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
676
+						}
633 677
 					}
634 678
 				}
635 679
 
@@ -638,8 +682,9 @@  discard block
 block discarded – undo
638 682
 			// Table crashed.  Let's try to fix it.
639 683
 			elseif ($query_errno == 1016)
640 684
 			{
641
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
642
-					$fix_tables = array('`' . $match[1] . '`');
685
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
686
+									$fix_tables = array('`' . $match[1] . '`');
687
+				}
643 688
 			}
644 689
 			// Indexes crashed.  Should be easy to fix!
645 690
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -658,13 +703,15 @@  discard block
 block discarded – undo
658 703
 
659 704
 			// Make a note of the REPAIR...
660 705
 			cache_put_data('db_last_error', time(), 600);
661
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
662
-				updateSettingsFile(array('db_last_error' => time()));
706
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
707
+							updateSettingsFile(array('db_last_error' => time()));
708
+			}
663 709
 
664 710
 			// Attempt to find and repair the broken table.
665
-			foreach ($fix_tables as $table)
666
-				$smcFunc['db_query']('', "
711
+			foreach ($fix_tables as $table) {
712
+							$smcFunc['db_query']('', "
667 713
 					REPAIR TABLE $table", false, false);
714
+			}
668 715
 
669 716
 			// And send off an email!
670 717
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -673,11 +720,12 @@  discard block
 block discarded – undo
673 720
 
674 721
 			// Try the query again...?
675 722
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
676
-			if ($ret !== false)
677
-				return $ret;
723
+			if ($ret !== false) {
724
+							return $ret;
725
+			}
726
+		} else {
727
+					$modSettings['cache_enable'] = $old_cache;
678 728
 		}
679
-		else
680
-			$modSettings['cache_enable'] = $old_cache;
681 729
 
682 730
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
683 731
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -687,22 +735,25 @@  discard block
 block discarded – undo
687 735
 				// Are we in SSI mode?  If so try that username and password first
688 736
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
689 737
 				{
690
-					if (empty($db_persist))
691
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
692
-					else
693
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
738
+					if (empty($db_persist)) {
739
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
740
+					} else {
741
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
742
+					}
694 743
 				}
695 744
 				// Fall back to the regular username and password if need be
696 745
 				if (!$db_connection)
697 746
 				{
698
-					if (empty($db_persist))
699
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
700
-					else
701
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
747
+					if (empty($db_persist)) {
748
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
749
+					} else {
750
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
751
+					}
702 752
 				}
703 753
 
704
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
705
-					$db_connection = false;
754
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
755
+									$db_connection = false;
756
+				}
706 757
 			}
707 758
 
708 759
 			if ($db_connection)
@@ -713,24 +764,27 @@  discard block
 block discarded – undo
713 764
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
714 765
 
715 766
 					$new_errno = mysqli_errno($db_connection);
716
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
717
-						break;
767
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
768
+											break;
769
+					}
718 770
 				}
719 771
 
720 772
 				// If it failed again, shucks to be you... we're not trying it over and over.
721
-				if ($ret !== false)
722
-					return $ret;
773
+				if ($ret !== false) {
774
+									return $ret;
775
+				}
723 776
 			}
724 777
 		}
725 778
 		// Are they out of space, perhaps?
726 779
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
727 780
 		{
728
-			if (!isset($txt))
729
-				$query_error .= ' - check database storage space.';
730
-			else
781
+			if (!isset($txt)) {
782
+							$query_error .= ' - check database storage space.';
783
+			} else
731 784
 			{
732
-				if (!isset($txt['mysql_error_space']))
733
-					loadLanguage('Errors');
785
+				if (!isset($txt['mysql_error_space'])) {
786
+									loadLanguage('Errors');
787
+				}
734 788
 
735 789
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
736 790
 			}
@@ -738,15 +792,17 @@  discard block
 block discarded – undo
738 792
 	}
739 793
 
740 794
 	// Nothing's defined yet... just die with it.
741
-	if (empty($context) || empty($txt))
742
-		die($query_error);
795
+	if (empty($context) || empty($txt)) {
796
+			die($query_error);
797
+	}
743 798
 
744 799
 	// Show an error message, if possible.
745 800
 	$context['error_title'] = $txt['database_error'];
746
-	if (allowedTo('admin_forum'))
747
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
748
-	else
749
-		$context['error_message'] = $txt['try_again'];
801
+	if (allowedTo('admin_forum')) {
802
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
803
+	} else {
804
+			$context['error_message'] = $txt['try_again'];
805
+	}
750 806
 
751 807
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
752 808
 	{
@@ -778,8 +834,9 @@  discard block
 block discarded – undo
778 834
 	$return_var = null;
779 835
 
780 836
 	// With nothing to insert, simply return.
781
-	if (empty($data))
782
-		return;
837
+	if (empty($data)) {
838
+			return;
839
+	}
783 840
 
784 841
 	// Replace the prefix holder with the actual prefix.
785 842
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -789,23 +846,26 @@  discard block
 block discarded – undo
789 846
 	if (!empty($keys) && (count($keys) > 0) && $returnmode > 0)
790 847
 	{
791 848
 		$with_returning = true;
792
-		if ($returnmode == 2)
793
-			$return_var = array();
849
+		if ($returnmode == 2) {
850
+					$return_var = array();
851
+		}
794 852
 	}
795 853
 
796 854
 	// Inserting data as a single row can be done as a single array.
797
-	if (!is_array($data[array_rand($data)]))
798
-		$data = array($data);
855
+	if (!is_array($data[array_rand($data)])) {
856
+			$data = array($data);
857
+	}
799 858
 
800 859
 	// Create the mold for a single row insert.
801 860
 	$insertData = '(';
802 861
 	foreach ($columns as $columnName => $type)
803 862
 	{
804 863
 		// Are we restricting the length?
805
-		if (strpos($type, 'string-') !== false)
806
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
807
-		else
808
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
864
+		if (strpos($type, 'string-') !== false) {
865
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
866
+		} else {
867
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
868
+		}
809 869
 	}
810 870
 	$insertData = substr($insertData, 0, -2) . ')';
811 871
 
@@ -814,8 +874,9 @@  discard block
 block discarded – undo
814 874
 
815 875
 	// Here's where the variables are injected to the query.
816 876
 	$insertRows = array();
817
-	foreach ($data as $dataRow)
818
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
877
+	foreach ($data as $dataRow) {
878
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
879
+	}
819 880
 
820 881
 	// Determine the method of insertion.
821 882
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -834,8 +895,7 @@  discard block
 block discarded – undo
834 895
 			),
835 896
 			$connection
836 897
 		);
837
-	}
838
-	else //special way for ignore method with returning
898
+	} else //special way for ignore method with returning
839 899
 	{
840 900
 		$count = count($insertRows);
841 901
 		$ai = 0;
@@ -855,19 +915,21 @@  discard block
 block discarded – undo
855 915
 			);
856 916
 			$new_id = $smcFunc['db_insert_id']();
857 917
 			
858
-			if ($last_id != $new_id) //the inserted value was new
918
+			if ($last_id != $new_id) {
919
+				//the inserted value was new
859 920
 			{
860 921
 				$ai = $new_id;
861 922
 			}
862
-			else	// the inserted value already exists we need to find the pk
923
+			} else	// the inserted value already exists we need to find the pk
863 924
 			{
864 925
 				$where_string = '';
865 926
 				$count2 = count($indexed_columns);
866 927
 				for ($x = 0; $x < $count2; $x++)
867 928
 				{
868 929
 					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
869
-					if (($x + 1) < $count2)
870
-						$where_string += ' AND ';
930
+					if (($x + 1) < $count2) {
931
+											$where_string += ' AND ';
932
+					}
871 933
 				}
872 934
 
873 935
 				$request = $smcFunc['db_query']('','
@@ -883,25 +945,27 @@  discard block
 block discarded – undo
883 945
 				}
884 946
 			}
885 947
 			
886
-			if ($returnmode == 1)
887
-				$return_var = $ai;
888
-			else if ($returnmode == 2)
889
-				$return_var[] = $ai;
948
+			if ($returnmode == 1) {
949
+							$return_var = $ai;
950
+			} else if ($returnmode == 2) {
951
+							$return_var[] = $ai;
952
+			}
890 953
 		}
891 954
 	}
892 955
 	
893 956
 
894 957
 	if ($with_returning)
895 958
 	{
896
-		if ($returnmode == 1 && empty($return_var))
897
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
898
-		else if ($returnmode == 2 && empty($return_var))
959
+		if ($returnmode == 1 && empty($return_var)) {
960
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
961
+		} else if ($returnmode == 2 && empty($return_var))
899 962
 		{
900 963
 			$return_var = array();
901 964
 			$count = count($insertRows);
902 965
 			$start = smf_db_insert_id($table, $keys[0]);
903
-			for ($i = 0; $i < $count; $i++ )
904
-				$return_var[] = $start + $i;
966
+			for ($i = 0; $i < $count; $i++ ) {
967
+							$return_var[] = $start + $i;
968
+			}
905 969
 		}
906 970
 		return $return_var;
907 971
 	}
@@ -919,8 +983,9 @@  discard block
 block discarded – undo
919 983
  */
920 984
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
921 985
 {
922
-	if (empty($log_message))
923
-		$log_message = $error_message;
986
+	if (empty($log_message)) {
987
+			$log_message = $error_message;
988
+	}
924 989
 
925 990
 	foreach (debug_backtrace() as $step)
926 991
 	{
@@ -939,12 +1004,14 @@  discard block
 block discarded – undo
939 1004
 	}
940 1005
 
941 1006
 	// A special case - we want the file and line numbers for debugging.
942
-	if ($error_type == 'return')
943
-		return array($file, $line);
1007
+	if ($error_type == 'return') {
1008
+			return array($file, $line);
1009
+	}
944 1010
 
945 1011
 	// Is always a critical error.
946
-	if (function_exists('log_error'))
947
-		log_error($log_message, 'critical', $file, $line);
1012
+	if (function_exists('log_error')) {
1013
+			log_error($log_message, 'critical', $file, $line);
1014
+	}
948 1015
 
949 1016
 	if (function_exists('fatal_error'))
950 1017
 	{
@@ -952,12 +1019,12 @@  discard block
 block discarded – undo
952 1019
 
953 1020
 		// Cannot continue...
954 1021
 		exit;
1022
+	} elseif ($error_type) {
1023
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
1024
+	} else {
1025
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
1026
+	}
955 1027
 	}
956
-	elseif ($error_type)
957
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
958
-	else
959
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
960
-}
961 1028
 
962 1029
 /**
963 1030
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -974,10 +1041,11 @@  discard block
 block discarded – undo
974 1041
 		'\\' => '\\\\',
975 1042
 	);
976 1043
 
977
-	if ($translate_human_wildcards)
978
-		$replacements += array(
1044
+	if ($translate_human_wildcards) {
1045
+			$replacements += array(
979 1046
 			'*' => '%',
980 1047
 		);
1048
+	}
981 1049
 
982 1050
 	return strtr($string, $replacements);
983 1051
 }
@@ -991,8 +1059,9 @@  discard block
 block discarded – undo
991 1059
  */
992 1060
 function smf_is_resource($result)
993 1061
 {
994
-	if ($result instanceof mysqli_result)
995
-		return true;
1062
+	if ($result instanceof mysqli_result) {
1063
+			return true;
1064
+	}
996 1065
 
997 1066
 	return false;
998 1067
 }
@@ -1020,16 +1089,18 @@  discard block
 block discarded – undo
1020 1089
 	global  $db_prefix, $db_connection;
1021 1090
 	static $mysql_error_data_prep;
1022 1091
 
1023
-	if (empty($mysql_error_data_prep))
1024
-			$mysql_error_data_prep = mysqli_prepare($db_connection,
1092
+	if (empty($mysql_error_data_prep)) {
1093
+				$mysql_error_data_prep = mysqli_prepare($db_connection,
1025 1094
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line)
1026 1095
 													VALUES(		?,		?,		unhex(?), ?, 		?,		?,			?,		?,	?)'
1027 1096
 			);
1097
+	}
1028 1098
 
1029
-	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false)
1030
-		$error_array[2] = bin2hex(inet_pton($error_array[2]));
1031
-	else
1032
-		$error_array[2] = null;
1099
+	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) {
1100
+			$error_array[2] = bin2hex(inet_pton($error_array[2]));
1101
+	} else {
1102
+			$error_array[2] = null;
1103
+	}
1033 1104
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi', 
1034 1105
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
1035 1106
 		$error_array[7], $error_array[8]);
Please login to merge, or discard this patch.
Sources/Admin.php 1 patch
Braces   +75 added lines, -52 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
  * The main admin handling function.<br>
@@ -444,8 +445,9 @@  discard block
 block discarded – undo
444 445
 		foreach ($admin_includes as $include)
445 446
 		{
446 447
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
447
-			if (file_exists($include))
448
-				require_once($include);
448
+			if (file_exists($include)) {
449
+							require_once($include);
450
+			}
449 451
 		}
450 452
 	}
451 453
 
@@ -457,24 +459,27 @@  discard block
 block discarded – undo
457 459
 	unset($admin_areas);
458 460
 
459 461
 	// Nothing valid?
460
-	if ($admin_include_data == false)
461
-		fatal_lang_error('no_access', false);
462
+	if ($admin_include_data == false) {
463
+			fatal_lang_error('no_access', false);
464
+	}
462 465
 
463 466
 	// Build the link tree.
464 467
 	$context['linktree'][] = array(
465 468
 		'url' => $scripturl . '?action=admin',
466 469
 		'name' => $txt['admin_center'],
467 470
 	);
468
-	if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index')
469
-		$context['linktree'][] = array(
471
+	if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index') {
472
+			$context['linktree'][] = array(
470 473
 			'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'],
471 474
 			'name' => $admin_include_data['label'],
472 475
 		);
473
-	if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label'])
474
-		$context['linktree'][] = array(
476
+	}
477
+	if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label']) {
478
+			$context['linktree'][] = array(
475 479
 			'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'],
476 480
 			'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0],
477 481
 		);
482
+	}
478 483
 
479 484
 	// Make a note of the Unique ID for this menu.
480 485
 	$context['admin_menu_id'] = $context['max_menu_id'];
@@ -484,16 +489,18 @@  discard block
 block discarded – undo
484 489
 	$context['admin_area'] = $admin_include_data['current_area'];
485 490
 
486 491
 	// Now - finally - call the right place!
487
-	if (isset($admin_include_data['file']))
488
-		require_once($sourcedir . '/' . $admin_include_data['file']);
492
+	if (isset($admin_include_data['file'])) {
493
+			require_once($sourcedir . '/' . $admin_include_data['file']);
494
+	}
489 495
 
490 496
 	// Get the right callable.
491 497
 	$call = call_helper($admin_include_data['function'], true);
492 498
 
493 499
 	// Is it valid?
494
-	if (!empty($call))
495
-		call_user_func($call);
496
-}
500
+	if (!empty($call)) {
501
+			call_user_func($call);
502
+	}
503
+	}
497 504
 
498 505
 /**
499 506
  * The main administration section.
@@ -547,13 +554,14 @@  discard block
 block discarded – undo
547 554
 
548 555
 	$context['sub_template'] = $context['admin_area'] == 'credits' ? 'credits' : 'admin';
549 556
 	$context['page_title'] = $context['admin_area'] == 'credits' ? $txt['support_credits_title'] : $txt['admin_center'];
550
-	if ($context['admin_area'] != 'credits')
551
-		$context[$context['admin_menu_name']]['tab_data'] = array(
557
+	if ($context['admin_area'] != 'credits') {
558
+			$context[$context['admin_menu_name']]['tab_data'] = array(
552 559
 			'title' => $txt['admin_center'],
553 560
 			'help' => '',
554 561
 			'description' => '<strong>' . $txt['hello_guest'] . ' ' . $context['user']['name'] . '!</strong>
555 562
 						' . sprintf($txt['admin_main_welcome'], $txt['admin_center'], $txt['help'], $txt['help']),
556 563
 		);
564
+	}
557 565
 
558 566
 	// Lastly, fill in the blanks in the support resources paragraphs.
559 567
 	$txt['support_resources_p1'] = sprintf($txt['support_resources_p1'],
@@ -571,9 +579,10 @@  discard block
 block discarded – undo
571 579
 		'https://www.simplemachines.org/redirect/customize_support'
572 580
 	);
573 581
 
574
-	if ($context['admin_area'] == 'admin')
575
-		loadJavaScriptFile('admin.js', array('defer' => false), 'smf_admin');
576
-}
582
+	if ($context['admin_area'] == 'admin') {
583
+			loadJavaScriptFile('admin.js', array('defer' => false), 'smf_admin');
584
+	}
585
+	}
577 586
 
578 587
 /**
579 588
  * Get one of the admin information files from Simple Machines.
@@ -584,8 +593,9 @@  discard block
 block discarded – undo
584 593
 
585 594
 	setMemoryLimit('32M');
586 595
 
587
-	if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename']))
588
-		fatal_lang_error('no_access', false);
596
+	if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename'])) {
597
+			fatal_lang_error('no_access', false);
598
+	}
589 599
 
590 600
 	// Strip off the forum cache part or we won't find it...
591 601
 	$_REQUEST['filename'] = str_replace($modSettings['browser_cache'], '', $_REQUEST['filename']);
@@ -600,27 +610,30 @@  discard block
 block discarded – undo
600 610
 		)
601 611
 	);
602 612
 
603
-	if ($smcFunc['db_num_rows']($request) == 0)
604
-		fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404);
613
+	if ($smcFunc['db_num_rows']($request) == 0) {
614
+			fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404);
615
+	}
605 616
 
606 617
 	list ($file_data, $filetype) = $smcFunc['db_fetch_row']($request);
607 618
 	$smcFunc['db_free_result']($request);
608 619
 
609 620
 	// @todo Temp
610 621
 	// Figure out if sesc is still being used.
611
-	if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript')
612
-		$file_data = '
622
+	if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript') {
623
+			$file_data = '
613 624
 if (!(\'smfForum_sessionvar\' in window))
614 625
 	window.smfForum_sessionvar = \'sesc\';
615 626
 ' . strtr($file_data, array(';sesc=' => ';\' + window.smfForum_sessionvar + \'='));
627
+	}
616 628
 
617 629
 	$context['template_layers'] = array();
618 630
 	// Lets make sure we aren't going to output anything nasty.
619 631
 	@ob_end_clean();
620
-	if (!empty($modSettings['enableCompressedOutput']))
621
-		@ob_start('ob_gzhandler');
622
-	else
623
-		@ob_start();
632
+	if (!empty($modSettings['enableCompressedOutput'])) {
633
+			@ob_start('ob_gzhandler');
634
+	} else {
635
+			@ob_start();
636
+	}
624 637
 
625 638
 	// Make sure they know what type of file we are.
626 639
 	header('Content-Type: ' . $filetype);
@@ -660,11 +673,12 @@  discard block
 block discarded – undo
660 673
 		updateAdminPreferences();
661 674
 	}
662 675
 
663
-	if (trim($context['search_term']) == '')
664
-		$context['search_results'] = array();
665
-	else
666
-		call_helper($subActions[$context['search_type']]);
667
-}
676
+	if (trim($context['search_term']) == '') {
677
+			$context['search_results'] = array();
678
+	} else {
679
+			call_helper($subActions[$context['search_type']]);
680
+	}
681
+	}
668 682
 
669 683
 /**
670 684
  * A complicated but relatively quick internal search.
@@ -728,8 +742,9 @@  discard block
 block discarded – undo
728 742
 
729 743
 	loadLanguage(implode('+', $language_files));
730 744
 
731
-	foreach ($include_files as $file)
732
-		require_once($sourcedir . '/' . $file . '.php');
745
+	foreach ($include_files as $file) {
746
+			require_once($sourcedir . '/' . $file . '.php');
747
+	}
733 748
 
734 749
 	/* This is the huge array that defines everything... it's a huge array of items formatted as follows:
735 750
 		0 = Language index (Can be array of indexes) to search through for this setting.
@@ -753,11 +768,12 @@  discard block
 block discarded – undo
753 768
 		foreach ($section['areas'] as $menu_key => $menu_item)
754 769
 		{
755 770
 			$search_data['sections'][] = array($menu_item['label'], 'area=' . $menu_key);
756
-			if (!empty($menu_item['subsections']))
757
-				foreach ($menu_item['subsections'] as $key => $sublabel)
771
+			if (!empty($menu_item['subsections'])) {
772
+							foreach ($menu_item['subsections'] as $key => $sublabel)
758 773
 				{
759 774
 					if (isset($sublabel['label']))
760 775
 						$search_data['sections'][] = array($sublabel['label'], 'area=' . $menu_key . ';sa=' . $key);
776
+			}
761 777
 				}
762 778
 		}
763 779
 	}
@@ -767,9 +783,10 @@  discard block
 block discarded – undo
767 783
 		// Get a list of their variables.
768 784
 		$config_vars = $setting_area[0](true);
769 785
 
770
-		foreach ($config_vars as $var)
771
-			if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc')))
786
+		foreach ($config_vars as $var) {
787
+					if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc')))
772 788
 				$search_data['settings'][] = array($var[(isset($var[2]) && in_array($var[2], array('file', 'db'))) ? 0 : 1], $setting_area[1], 'alttxt' => (isset($var[2]) && in_array($var[2], array('file', 'db'))) || isset($var[3]) ? (in_array($var[2], array('file', 'db')) ? $var[1] : $var[3]) : '');
789
+		}
773 790
 	}
774 791
 
775 792
 	$context['page_title'] = $txt['admin_search_results'];
@@ -782,8 +799,9 @@  discard block
 block discarded – undo
782 799
 		foreach ($data as $item)
783 800
 		{
784 801
 			$found = false;
785
-			if (!is_array($item[0]))
786
-				$item[0] = array($item[0]);
802
+			if (!is_array($item[0])) {
803
+							$item[0] = array($item[0]);
804
+			}
787 805
 			foreach ($item[0] as $term)
788 806
 			{
789 807
 				if (stripos($term, $search_term) !== false || (isset($txt[$term]) && stripos($txt[$term], $search_term) !== false) || (isset($txt['setting_' . $term]) && stripos($txt['setting_' . $term], $search_term) !== false))
@@ -841,8 +859,9 @@  discard block
 block discarded – undo
841 859
 	$postVars = explode(' ', $context['search_term']);
842 860
 
843 861
 	// Encode the search data.
844
-	foreach ($postVars as $k => $v)
845
-		$postVars[$k] = urlencode($v);
862
+	foreach ($postVars as $k => $v) {
863
+			$postVars[$k] = urlencode($v);
864
+	}
846 865
 
847 866
 	// This is what we will send.
848 867
 	$postVars = implode('+', $postVars);
@@ -854,8 +873,9 @@  discard block
 block discarded – undo
854 873
 	$search_results = fetch_web_data($context['doc_apiurl'] . '?action=query&list=search&srprop=timestamp|snippet&format=xml&srwhat=text&srsearch=' . $postVars);
855 874
 
856 875
 	// If we didn't get any xml back we are in trouble - perhaps the doc site is overloaded?
857
-	if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api>.+?</api>)~is', $search_results, $matches) != true)
858
-		fatal_lang_error('cannot_connect_doc_site');
876
+	if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api>.+?</api>)~is', $search_results, $matches) != true) {
877
+			fatal_lang_error('cannot_connect_doc_site');
878
+	}
859 879
 
860 880
 	$search_results = $matches[1];
861 881
 
@@ -867,8 +887,9 @@  discard block
 block discarded – undo
867 887
 	$results = new xmlArray($search_results, false);
868 888
 
869 889
 	// Move through the api layer.
870
-	if (!$results->exists('api'))
871
-		fatal_lang_error('cannot_connect_doc_site');
890
+	if (!$results->exists('api')) {
891
+			fatal_lang_error('cannot_connect_doc_site');
892
+	}
872 893
 
873 894
 	// Are there actually some results?
874 895
 	if ($results->exists('api/query/search/p'))
@@ -904,8 +925,9 @@  discard block
 block discarded – undo
904 925
 	);
905 926
 
906 927
 	// If it's not got a sa set it must have come here for first time, pretend error log should be reversed.
907
-	if (!isset($_REQUEST['sa']))
908
-		$_REQUEST['desc'] = true;
928
+	if (!isset($_REQUEST['sa'])) {
929
+			$_REQUEST['desc'] = true;
930
+	}
909 931
 
910 932
 	// Setup some tab stuff.
911 933
 	$context[$context['admin_menu_name']]['tab_data'] = array(
@@ -955,9 +977,10 @@  discard block
 block discarded – undo
955 977
 	unset($_SESSION['admin_time']);
956 978
 
957 979
 	// Clean any admin tokens as well.
958
-	foreach ($_SESSION['token'] as $key => $token)
959
-		if (strpos($key, '-admin') !== false)
980
+	foreach ($_SESSION['token'] as $key => $token) {
981
+			if (strpos($key, '-admin') !== false)
960 982
 			unset($_SESSION['token'][$key]);
983
+	}
961 984
 
962 985
 	redirectexit();
963 986
 }
Please login to merge, or discard this patch.
Sources/Errors.php 1 patch
Braces   +125 added lines, -89 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Log an error, if the error logging is enabled.
@@ -41,17 +42,19 @@  discard block
 block discarded – undo
41 42
 	// are we in a loop?
42 43
 	if($error_call > 2)
43 44
 	{
44
-		if (!isset($db_show_debug) || $db_show_debug === false)
45
-			$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
46
-		else
47
-			$backtrace = debug_backtrace();
45
+		if (!isset($db_show_debug) || $db_show_debug === false) {
46
+					$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
47
+		} else {
48
+					$backtrace = debug_backtrace();
49
+		}
48 50
 		var_dump($backtrace);
49 51
 		die('Error loop.');
50 52
 	}
51 53
 
52 54
 	// Check if error logging is actually on.
53
-	if (empty($modSettings['enableErrorLogging']))
54
-		return $error_message;
55
+	if (empty($modSettings['enableErrorLogging'])) {
56
+			return $error_message;
57
+	}
55 58
 
56 59
 	// Basically, htmlspecialchars it minus &. (for entities!)
57 60
 	$error_message = strtr($error_message, array('<' => '&lt;', '>' => '&gt;', '"' => '&quot;'));
@@ -59,33 +62,39 @@  discard block
 block discarded – undo
59 62
 
60 63
 	// Add a file and line to the error message?
61 64
 	// Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line
62
-	if ($file == null)
63
-		$file = '';
64
-	else
65
-		// Window style slashes don't play well, lets convert them to the unix style.
65
+	if ($file == null) {
66
+			$file = '';
67
+	} else {
68
+			// Window style slashes don't play well, lets convert them to the unix style.
66 69
 		$file = str_replace('\\', '/', $file);
70
+	}
67 71
 
68
-	if ($line == null)
69
-		$line = 0;
70
-	else
71
-		$line = (int) $line;
72
+	if ($line == null) {
73
+			$line = 0;
74
+	} else {
75
+			$line = (int) $line;
76
+	}
72 77
 
73 78
 	// Just in case there's no id_member or IP set yet.
74
-	if (empty($user_info['id']))
75
-		$user_info['id'] = 0;
76
-	if (empty($user_info['ip']))
77
-		$user_info['ip'] = '';
79
+	if (empty($user_info['id'])) {
80
+			$user_info['id'] = 0;
81
+	}
82
+	if (empty($user_info['ip'])) {
83
+			$user_info['ip'] = '';
84
+	}
78 85
 
79 86
 	// Find the best query string we can...
80 87
 	$query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING'];
81 88
 
82 89
 	// Don't log the session hash in the url twice, it's a waste.
83
-	if (!empty($smcFunc['htmlspecialchars']))
84
-		$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
90
+	if (!empty($smcFunc['htmlspecialchars'])) {
91
+			$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
92
+	}
85 93
 
86 94
 	// Just so we know what board error messages are from.
87
-	if (isset($_POST['board']) && !isset($_GET['board']))
88
-		$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
95
+	if (isset($_POST['board']) && !isset($_GET['board'])) {
96
+			$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
97
+	}
89 98
 
90 99
 	// What types of categories do we have?
91 100
 	$known_error_types = array(
@@ -146,12 +155,14 @@  discard block
 block discarded – undo
146 155
 	global $txt;
147 156
 
148 157
 	// Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all
149
-	if (!empty($status))
150
-		send_http_status($status);
158
+	if (!empty($status)) {
159
+			send_http_status($status);
160
+	}
151 161
 
152 162
 	// We don't have $txt yet, but that's okay...
153
-	if (empty($txt))
154
-		die($error);
163
+	if (empty($txt)) {
164
+			die($error);
165
+	}
155 166
 
156 167
 	log_error_online($error, false);
157 168
 	setup_fatal_error_context($log ? log_error($error, $log) : $error);
@@ -178,8 +189,9 @@  discard block
 block discarded – undo
178 189
 	static $fatal_error_called = false;
179 190
 
180 191
 	// Send the status header - set this to 0 or false if you don't want to send one at all
181
-	if (!empty($status))
182
-		send_http_status($status);
192
+	if (!empty($status)) {
193
+			send_http_status($status);
194
+	}
183 195
 
184 196
 	// Try to load a theme if we don't have one.
185 197
 	if (empty($context['theme_loaded']) && empty($fatal_error_called))
@@ -189,8 +201,9 @@  discard block
 block discarded – undo
189 201
 	}
190 202
 
191 203
 	// If we have no theme stuff we can't have the language file...
192
-	if (empty($context['theme_loaded']))
193
-		die($error);
204
+	if (empty($context['theme_loaded'])) {
205
+			die($error);
206
+	}
194 207
 
195 208
 	$reload_lang_file = true;
196 209
 	// Log the error in the forum's language, but don't waste the time if we aren't logging
@@ -226,8 +239,9 @@  discard block
 block discarded – undo
226 239
 	global $settings, $modSettings, $db_show_debug;
227 240
 
228 241
 	// Ignore errors if we're ignoring them or they are strict notices from PHP 5 (which cannot be solved without breaking PHP 4.)
229
-	if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging'])))
230
-		return;
242
+	if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) {
243
+			return;
244
+	}
231 245
 
232 246
 	if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename']))
233 247
 	{
@@ -235,19 +249,22 @@  discard block
 block discarded – undo
235 249
 		$count = count($array);
236 250
 		for ($i = 0; $i < $count; $i++)
237 251
 		{
238
-			if ($array[$i]['function'] != 'loadSubTemplate')
239
-				continue;
252
+			if ($array[$i]['function'] != 'loadSubTemplate') {
253
+							continue;
254
+			}
240 255
 
241 256
 			// This is a bug in PHP, with eval, it seems!
242
-			if (empty($array[$i]['args']))
243
-				$i++;
257
+			if (empty($array[$i]['args'])) {
258
+							$i++;
259
+			}
244 260
 			break;
245 261
 		}
246 262
 
247
-		if (isset($array[$i]) && !empty($array[$i]['args']))
248
-			$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
249
-		else
250
-			$file = realpath($settings['current_include_filename']) . ' (eval?)';
263
+		if (isset($array[$i]) && !empty($array[$i]['args'])) {
264
+					$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
265
+		} else {
266
+					$file = realpath($settings['current_include_filename']) . ' (eval?)';
267
+		}
251 268
 	}
252 269
 
253 270
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -256,8 +273,9 @@  discard block
 block discarded – undo
256 273
 		if ($error_level % 255 != E_ERROR)
257 274
 		{
258 275
 			$temporary = ob_get_contents();
259
-			if (substr($temporary, -2) == '="')
260
-				echo '"';
276
+			if (substr($temporary, -2) == '="') {
277
+							echo '"';
278
+			}
261 279
 		}
262 280
 
263 281
 		// Debugging!  This should look like a PHP error message.
@@ -273,23 +291,27 @@  discard block
 block discarded – undo
273 291
 	call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line));
274 292
 
275 293
 	// Dying on these errors only causes MORE problems (blank pages!)
276
-	if ($file == 'Unknown')
277
-		return;
294
+	if ($file == 'Unknown') {
295
+			return;
296
+	}
278 297
 
279 298
 	// If this is an E_ERROR or E_USER_ERROR.... die.  Violently so.
280
-	if ($error_level % 255 == E_ERROR)
281
-		obExit(false);
282
-	else
283
-		return;
299
+	if ($error_level % 255 == E_ERROR) {
300
+			obExit(false);
301
+	} else {
302
+			return;
303
+	}
284 304
 
285 305
 	// If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die.  Violently so.
286
-	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING)
287
-		fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
306
+	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) {
307
+			fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
308
+	}
288 309
 
289 310
 	// We should NEVER get to this point.  Any fatal error MUST quit, or very bad things can happen.
290
-	if ($error_level % 255 == E_ERROR)
291
-		die('No direct access...');
292
-}
311
+	if ($error_level % 255 == E_ERROR) {
312
+			die('No direct access...');
313
+	}
314
+	}
293 315
 
294 316
 /**
295 317
  * It is called by {@link fatal_error()} and {@link fatal_lang_error()}.
@@ -305,24 +327,28 @@  discard block
 block discarded – undo
305 327
 
306 328
 	// Attempt to prevent a recursive loop.
307 329
 	++$level;
308
-	if ($level > 1)
309
-		return false;
330
+	if ($level > 1) {
331
+			return false;
332
+	}
310 333
 
311 334
 	// Maybe they came from dlattach or similar?
312
-	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded']))
313
-		loadTheme();
335
+	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) {
336
+			loadTheme();
337
+	}
314 338
 
315 339
 	// Don't bother indexing errors mate...
316 340
 	$context['robot_no_index'] = true;
317 341
 
318
-	if (!isset($context['error_title']))
319
-		$context['error_title'] = $txt['error_occured'];
342
+	if (!isset($context['error_title'])) {
343
+			$context['error_title'] = $txt['error_occured'];
344
+	}
320 345
 	$context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message;
321 346
 
322 347
 	$context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : '';
323 348
 
324
-	if (empty($context['page_title']))
325
-		$context['page_title'] = $context['error_title'];
349
+	if (empty($context['page_title'])) {
350
+			$context['page_title'] = $context['error_title'];
351
+	}
326 352
 
327 353
 	loadTemplate('Errors');
328 354
 	$context['sub_template'] = 'fatal_error';
@@ -330,23 +356,26 @@  discard block
 block discarded – undo
330 356
 	// If this is SSI, what do they want us to do?
331 357
 	if (SMF == 'SSI')
332 358
 	{
333
-		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method))
334
-			$ssi_on_error_method();
335
-		elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
336
-			loadSubTemplate('fatal_error');
359
+		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) {
360
+					$ssi_on_error_method();
361
+		} elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
362
+					loadSubTemplate('fatal_error');
363
+		}
337 364
 
338 365
 		// No layers?
339
-		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
340
-			exit;
366
+		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
367
+					exit;
368
+		}
341 369
 	}
342 370
 	// Alternatively from the cron call?
343 371
 	elseif (SMF == 'BACKGROUND')
344 372
 	{
345 373
 		// We can't rely on even having language files available.
346
-		if (defined('FROM_CLI') && FROM_CLI)
347
-			echo 'cron error: ', $context['error_message'];
348
-		else
349
-			echo 'An error occurred. More information may be available in your logs.';
374
+		if (defined('FROM_CLI') && FROM_CLI) {
375
+					echo 'cron error: ', $context['error_message'];
376
+		} else {
377
+					echo 'An error occurred. More information may be available in your logs.';
378
+		}
350 379
 		exit;
351 380
 	}
352 381
 
@@ -374,8 +403,8 @@  discard block
 block discarded – undo
374 403
 
375 404
 	set_fatal_error_headers();
376 405
 
377
-	if (!empty($maintenance))
378
-		echo '<!DOCTYPE html>
406
+	if (!empty($maintenance)) {
407
+			echo '<!DOCTYPE html>
379 408
 <html>
380 409
 	<head>
381 410
 		<meta name="robots" content="noindex">
@@ -386,6 +415,7 @@  discard block
 block discarded – undo
386 415
 		', $mmessage, '
387 416
 	</body>
388 417
 </html>';
418
+	}
389 419
 
390 420
 	die();
391 421
 }
@@ -407,15 +437,17 @@  discard block
 block discarded – undo
407 437
 	// For our purposes, we're gonna want this on if at all possible.
408 438
 	$modSettings['cache_enable'] = '1';
409 439
 
410
-	if (($temp = cache_get_data('db_last_error', 600)) !== null)
411
-		$db_last_error = max($db_last_error, $temp);
440
+	if (($temp = cache_get_data('db_last_error', 600)) !== null) {
441
+			$db_last_error = max($db_last_error, $temp);
442
+	}
412 443
 
413 444
 	if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send))
414 445
 	{
415 446
 		// Avoid writing to the Settings.php file if at all possible; use shared memory instead.
416 447
 		cache_put_data('db_last_error', time(), 600);
417
-		if (($temp = cache_get_data('db_last_error', 600)) === null)
418
-			logLastDatabaseError();
448
+		if (($temp = cache_get_data('db_last_error', 600)) === null) {
449
+					logLastDatabaseError();
450
+		}
419 451
 
420 452
 		// Language files aren't loaded yet :(.
421 453
 		$db_error = @$smcFunc['db_error']($db_connection);
@@ -496,12 +528,14 @@  discard block
 block discarded – undo
496 528
 	global $smcFunc, $user_info, $modSettings;
497 529
 
498 530
 	// Don't bother if Who's Online is disabled.
499
-	if (empty($modSettings['who_enabled']))
500
-		return;
531
+	if (empty($modSettings['who_enabled'])) {
532
+			return;
533
+	}
501 534
 
502 535
 	// Maybe they came from SSI or similar where sessions are not recorded?
503
-	if (SMF == 'SSI' || SMF == 'BACKGROUND')
504
-		return;
536
+	if (SMF == 'SSI' || SMF == 'BACKGROUND') {
537
+			return;
538
+	}
505 539
 
506 540
 	$session_id = !empty($user_info['is_guest']) ? 'ip' . $user_info['ip'] : session_id();
507 541
 
@@ -527,8 +561,9 @@  discard block
 block discarded – undo
527 561
 		$url = $smcFunc['json_decode']($url, true);
528 562
 		$url['error'] = $error;
529 563
 
530
-		if (!empty($sprintf))
531
-			$url['error_params'] = $sprintf;
564
+		if (!empty($sprintf)) {
565
+					$url['error_params'] = $sprintf;
566
+		}
532 567
 
533 568
 		$smcFunc['db_query']('', '
534 569
 			UPDATE {db_prefix}log_online
@@ -559,10 +594,11 @@  discard block
 block discarded – undo
559 594
 
560 595
 	$protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
561 596
 
562
-	if (!isset($statuses[$code]))
563
-		header($protocol . ' 500 Internal Server Error');
564
-	else
565
-		header($protocol . ' ' . $code . ' ' . $statuses[$code]);
566
-}
597
+	if (!isset($statuses[$code])) {
598
+			header($protocol . ' 500 Internal Server Error');
599
+	} else {
600
+			header($protocol . ' ' . $code . ' ' . $statuses[$code]);
601
+	}
602
+	}
567 603
 
568 604
 ?>
569 605
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Admin.php 1 patch
Braces   +124 added lines, -89 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
  * Get a list of versions that are currently installed on the server.
@@ -45,8 +46,7 @@  discard block
 block discarded – undo
45 46
 			$temp2 = $temp->getVersion();
46 47
 			$im_version = $temp2['versionString'];
47 48
 			$extension_version = 'Imagick ' . phpversion('Imagick');
48
-		}
49
-		else
49
+		} else
50 50
 		{
51 51
 			$im_version = MagickGetVersionString();
52 52
 			$extension_version = 'MagickWand ' . phpversion('MagickWand');
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
 	if (in_array('db_server', $checkFor))
62 62
 	{
63 63
 		db_extend();
64
-		if (!isset($db_connection) || $db_connection === false)
65
-			trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE);
66
-		else
64
+		if (!isset($db_connection) || $db_connection === false) {
65
+					trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE);
66
+		} else
67 67
 		{
68 68
 			$versions['db_engine'] = array('title' => sprintf($txt['support_versions_db_engine'], $smcFunc['db_title']), 'version' => '');
69 69
 			$versions['db_engine']['version'] = $smcFunc['db_get_engine']();
@@ -75,24 +75,31 @@  discard block
 block discarded – undo
75 75
 
76 76
 	// If we're using memcache we need the server info.
77 77
 	$memcache_version = '???';
78
-	if (!empty($cache_accelerator) && ($cache_accelerator == 'memcached' || $cache_accelerator == 'memcache') && !empty($cache_memcached) && !empty($cacheAPI))
79
-		$memcache_version = $cacheAPI->getVersion();
78
+	if (!empty($cache_accelerator) && ($cache_accelerator == 'memcached' || $cache_accelerator == 'memcache') && !empty($cache_memcached) && !empty($cacheAPI)) {
79
+			$memcache_version = $cacheAPI->getVersion();
80
+	}
80 81
 
81 82
 	// Check to see if we have any accelerators installed...
82
-	if (in_array('phpa', $checkFor) && isset($_PHPA))
83
-		$versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']);
84
-	if (in_array('apc', $checkFor) && extension_loaded('apc'))
85
-		$versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc'));
86
-	if (in_array('memcache', $checkFor) && function_exists('memcache_set'))
87
-		$versions['memcache'] = array('title' => 'Memcached', 'version' => $memcache_version);
88
-	if (in_array('xcache', $checkFor) && function_exists('xcache_set'))
89
-		$versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION);
83
+	if (in_array('phpa', $checkFor) && isset($_PHPA)) {
84
+			$versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']);
85
+	}
86
+	if (in_array('apc', $checkFor) && extension_loaded('apc')) {
87
+			$versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc'));
88
+	}
89
+	if (in_array('memcache', $checkFor) && function_exists('memcache_set')) {
90
+			$versions['memcache'] = array('title' => 'Memcached', 'version' => $memcache_version);
91
+	}
92
+	if (in_array('xcache', $checkFor) && function_exists('xcache_set')) {
93
+			$versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION);
94
+	}
90 95
 
91
-	if (in_array('php', $checkFor))
92
-		$versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo');
96
+	if (in_array('php', $checkFor)) {
97
+			$versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo');
98
+	}
93 99
 
94
-	if (in_array('server', $checkFor))
95
-		$versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']);
100
+	if (in_array('server', $checkFor)) {
101
+			$versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']);
102
+	}
96 103
 
97 104
 	return $versions;
98 105
 }
@@ -132,11 +139,13 @@  discard block
 block discarded – undo
132 139
 		fclose($fp);
133 140
 
134 141
 		// The comment looks rougly like... that.
135
-		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
136
-			$version_info['file_versions']['SSI.php'] = $match[1];
142
+		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
143
+					$version_info['file_versions']['SSI.php'] = $match[1];
144
+		}
137 145
 		// Not found!  This is bad.
138
-		else
139
-			$version_info['file_versions']['SSI.php'] = '??';
146
+		else {
147
+					$version_info['file_versions']['SSI.php'] = '??';
148
+		}
140 149
 	}
141 150
 
142 151
 	// Do the paid subscriptions handler?
@@ -147,11 +156,13 @@  discard block
 block discarded – undo
147 156
 		fclose($fp);
148 157
 
149 158
 		// Found it?
150
-		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
151
-			$version_info['file_versions']['subscriptions.php'] = $match[1];
159
+		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
160
+					$version_info['file_versions']['subscriptions.php'] = $match[1];
161
+		}
152 162
 		// If we haven't how do we all get paid?
153
-		else
154
-			$version_info['file_versions']['subscriptions.php'] = '??';
163
+		else {
164
+					$version_info['file_versions']['subscriptions.php'] = '??';
165
+		}
155 166
 	}
156 167
 
157 168
 	// Load all the files in the Sources directory, except this file and the redirect.
@@ -166,11 +177,13 @@  discard block
 block discarded – undo
166 177
 			fclose($fp);
167 178
 
168 179
 			// Look for the version comment in the file header.
169
-			if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
170
-				$version_info['file_versions'][$entry] = $match[1];
180
+			if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
181
+							$version_info['file_versions'][$entry] = $match[1];
182
+			}
171 183
 			// It wasn't found, but the file was... show a '??'.
172
-			else
173
-				$version_info['file_versions'][$entry] = '??';
184
+			else {
185
+							$version_info['file_versions'][$entry] = '??';
186
+			}
174 187
 		}
175 188
 	}
176 189
 	$sources_dir->close();
@@ -189,11 +202,13 @@  discard block
 block discarded – undo
189 202
 				fclose($fp);
190 203
 
191 204
 				// Look for the version comment in the file header.
192
-				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
193
-					$version_info['tasks_versions'][$entry] = $match[1];
205
+				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
206
+									$version_info['tasks_versions'][$entry] = $match[1];
207
+				}
194 208
 				// It wasn't found, but the file was... show a '??'.
195
-				else
196
-					$version_info['tasks_versions'][$entry] = '??';
209
+				else {
210
+									$version_info['tasks_versions'][$entry] = '??';
211
+				}
197 212
 			}
198 213
 		}
199 214
 		$tasks_dir->close();
@@ -201,8 +216,9 @@  discard block
 block discarded – undo
201 216
 
202 217
 	// Load all the files in the default template directory - and the current theme if applicable.
203 218
 	$directories = array('default_template_versions' => $settings['default_theme_dir']);
204
-	if ($settings['theme_id'] != 1)
205
-		$directories += array('template_versions' => $settings['theme_dir']);
219
+	if ($settings['theme_id'] != 1) {
220
+			$directories += array('template_versions' => $settings['theme_dir']);
221
+	}
206 222
 
207 223
 	foreach ($directories as $type => $dirname)
208 224
 	{
@@ -217,11 +233,13 @@  discard block
 block discarded – undo
217 233
 				fclose($fp);
218 234
 
219 235
 				// Look for the version comment in the file header.
220
-				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
221
-					$version_info[$type][$entry] = $match[1];
236
+				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
237
+									$version_info[$type][$entry] = $match[1];
238
+				}
222 239
 				// It wasn't found, but the file was... show a '??'.
223
-				else
224
-					$version_info[$type][$entry] = '??';
240
+				else {
241
+									$version_info[$type][$entry] = '??';
242
+				}
225 243
 			}
226 244
 		}
227 245
 		$this_dir->close();
@@ -242,11 +260,13 @@  discard block
 block discarded – undo
242 260
 			list ($name, $language) = explode('.', $entry);
243 261
 
244 262
 			// Look for the version comment in the file header.
245
-			if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1)
246
-				$version_info['default_language_versions'][$language][$name] = $match[1];
263
+			if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1) {
264
+							$version_info['default_language_versions'][$language][$name] = $match[1];
265
+			}
247 266
 			// It wasn't found, but the file was... show a '??'.
248
-			else
249
-				$version_info['default_language_versions'][$language][$name] = '??';
267
+			else {
268
+							$version_info['default_language_versions'][$language][$name] = '??';
269
+			}
250 270
 		}
251 271
 	}
252 272
 	$this_dir->close();
@@ -261,8 +281,9 @@  discard block
 block discarded – undo
261 281
 		ksort($version_info['tasks_versions']);
262 282
 
263 283
 		// For languages sort each language too.
264
-		foreach ($version_info['default_language_versions'] as $language => $dummy)
265
-			ksort($version_info['default_language_versions'][$language]);
284
+		foreach ($version_info['default_language_versions'] as $language => $dummy) {
285
+					ksort($version_info['default_language_versions'][$language]);
286
+		}
266 287
 	}
267 288
 	return $version_info;
268 289
 }
@@ -304,27 +325,31 @@  discard block
 block discarded – undo
304 325
 	$settingsArray = trim(file_get_contents($boarddir . '/Settings.php'));
305 326
 
306 327
 	// Break it up based on \r or \n, and then clean out extra characters.
307
-	if (strpos($settingsArray, "\n") !== false)
308
-		$settingsArray = explode("\n", $settingsArray);
309
-	elseif (strpos($settingsArray, "\r") !== false)
310
-		$settingsArray = explode("\r", $settingsArray);
311
-	else
312
-		return;
328
+	if (strpos($settingsArray, "\n") !== false) {
329
+			$settingsArray = explode("\n", $settingsArray);
330
+	} elseif (strpos($settingsArray, "\r") !== false) {
331
+			$settingsArray = explode("\r", $settingsArray);
332
+	} else {
333
+			return;
334
+	}
313 335
 
314 336
 	// Presumably, the file has to have stuff in it for this function to be called :P.
315
-	if (count($settingsArray) < 10)
316
-		return;
337
+	if (count($settingsArray) < 10) {
338
+			return;
339
+	}
317 340
 
318 341
 	// remove any /r's that made there way in here
319
-	foreach ($settingsArray as $k => $dummy)
320
-		$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
342
+	foreach ($settingsArray as $k => $dummy) {
343
+			$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
344
+	}
321 345
 
322 346
 	// go line by line and see whats changing
323 347
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
324 348
 	{
325 349
 		// Don't trim or bother with it if it's not a variable.
326
-		if (substr($settingsArray[$i], 0, 1) != '$')
327
-			continue;
350
+		if (substr($settingsArray[$i], 0, 1) != '$') {
351
+					continue;
352
+		}
328 353
 
329 354
 		$settingsArray[$i] = trim($settingsArray[$i]) . "\n";
330 355
 
@@ -336,8 +361,7 @@  discard block
 block discarded – undo
336 361
 			{
337 362
 				updateDbLastError($val);
338 363
 				unset($config_vars[$var]);
339
-			}
340
-			elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
364
+			} elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
341 365
 			{
342 366
 				$comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#');
343 367
 				$settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment == '' ? '' : "\t\t" . rtrim($comment)) . "\n";
@@ -348,34 +372,39 @@  discard block
 block discarded – undo
348 372
 		}
349 373
 
350 374
 		// End of the file ... maybe
351
-		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>')
352
-			$end = $i;
375
+		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') {
376
+					$end = $i;
377
+		}
353 378
 	}
354 379
 
355 380
 	// This should never happen, but apparently it is happening.
356
-	if (empty($end) || $end < 10)
357
-		$end = count($settingsArray) - 1;
381
+	if (empty($end) || $end < 10) {
382
+			$end = count($settingsArray) - 1;
383
+	}
358 384
 
359 385
 	// Still more variables to go?  Then lets add them at the end.
360 386
 	if (!empty($config_vars))
361 387
 	{
362
-		if (trim($settingsArray[$end]) == '?' . '>')
363
-			$settingsArray[$end++] = '';
364
-		else
365
-			$end++;
388
+		if (trim($settingsArray[$end]) == '?' . '>') {
389
+					$settingsArray[$end++] = '';
390
+		} else {
391
+					$end++;
392
+		}
366 393
 
367 394
 		// Add in any newly defined vars that were passed
368
-		foreach ($config_vars as $var => $val)
369
-			$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
395
+		foreach ($config_vars as $var => $val) {
396
+					$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
397
+		}
370 398
 
371 399
 		$settingsArray[$end] = '?' . '>';
400
+	} else {
401
+			$settingsArray[$end] = trim($settingsArray[$end]);
372 402
 	}
373
-	else
374
-		$settingsArray[$end] = trim($settingsArray[$end]);
375 403
 
376 404
 	// Sanity error checking: the file needs to be at least 12 lines.
377
-	if (count($settingsArray) < 12)
378
-		return;
405
+	if (count($settingsArray) < 12) {
406
+			return;
407
+	}
379 408
 
380 409
 	// Try to avoid a few pitfalls:
381 410
 	//  - like a possible race condition,
@@ -383,8 +412,9 @@  discard block
 block discarded – undo
383 412
 	//
384 413
 	// Check before you act: if cache is enabled, we can do a simple write test
385 414
 	// to validate that we even write things on this filesystem.
386
-	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
387
-		$cachedir = $boarddir . '/cache';
415
+	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
416
+			$cachedir = $boarddir . '/cache';
417
+	}
388 418
 
389 419
 	$test_fp = @fopen($cachedir . '/settings_update.tmp', "w+");
390 420
 	if ($test_fp)
@@ -419,16 +449,18 @@  discard block
 block discarded – undo
419 449
 			// Well this is not good at all, lets see if we can save this
420 450
 			$context['settings_message'] = 'settings_error';
421 451
 
422
-			if (file_exists($boarddir . '/Settings_bak.php'))
423
-				@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
452
+			if (file_exists($boarddir . '/Settings_bak.php')) {
453
+							@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
454
+			}
424 455
 		}
425 456
 	}
426 457
 
427 458
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
428 459
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
429
-	if (function_exists('opcache_invalidate'))
430
-		opcache_invalidate($boarddir . '/Settings.php', true);
431
-}
460
+	if (function_exists('opcache_invalidate')) {
461
+			opcache_invalidate($boarddir . '/Settings.php', true);
462
+	}
463
+	}
432 464
 
433 465
 /**
434 466
  * Saves the time of the last db error for the error log
@@ -454,8 +486,9 @@  discard block
 block discarded – undo
454 486
 	global $options, $context, $smcFunc, $settings, $user_info;
455 487
 
456 488
 	// This must exist!
457
-	if (!isset($context['admin_preferences']))
458
-		return false;
489
+	if (!isset($context['admin_preferences'])) {
490
+			return false;
491
+	}
459 492
 
460 493
 	// This is what we'll be saving.
461 494
 	$options['admin_preferences'] = $smcFunc['json_encode']($context['admin_preferences']);
@@ -519,8 +552,9 @@  discard block
 block discarded – undo
519 552
 	$emails_sent = array();
520 553
 	while ($row = $smcFunc['db_fetch_assoc']($request))
521 554
 	{
522
-		if (empty($prefs[$row['id_member']]['announcements']))
523
-			continue;
555
+		if (empty($prefs[$row['id_member']]['announcements'])) {
556
+					continue;
557
+		}
524 558
 
525 559
 		// Stick their particulars in the replacement data.
526 560
 		$replacements['IDMEMBER'] = $row['id_member'];
@@ -539,11 +573,12 @@  discard block
 block discarded – undo
539 573
 	$smcFunc['db_free_result']($request);
540 574
 
541 575
 	// Any additional users we must email this to?
542
-	if (!empty($additional_recipients))
543
-		foreach ($additional_recipients as $recipient)
576
+	if (!empty($additional_recipients)) {
577
+			foreach ($additional_recipients as $recipient)
544 578
 		{
545 579
 			if (in_array($recipient['email'], $emails_sent))
546 580
 				continue;
581
+	}
547 582
 
548 583
 			$replacements['IDMEMBER'] = $recipient['id'];
549 584
 			$replacements['REALNAME'] = $recipient['name'];
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +158 added lines, -124 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
84 87
 
85 88
 	// Check to ensure we're forcing SSL for authentication
86
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -102,19 +106,20 @@  discard block
 block discarded – undo
102 106
 			list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
103 107
 
104 108
 			// That didn't work... Maybe it's using serialize?
105
-			if (is_null($timeout))
106
-				list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
107
-		}
108
-		elseif (isset($_SESSION['login_' . $cookiename]))
109
+			if (is_null($timeout)) {
110
+							list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
111
+			}
112
+		} elseif (isset($_SESSION['login_' . $cookiename]))
109 113
 		{
110 114
 			list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
111 115
 
112 116
 			// Try for old format
113
-			if (is_null($timeout))
114
-				list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
117
+			if (is_null($timeout)) {
118
+							list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
119
+			}
120
+		} else {
121
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
115 122
 		}
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
118 123
 
119 124
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
120 125
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -127,10 +132,11 @@  discard block
 block discarded – undo
127 132
 			list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
128 133
 
129 134
 			// If we're preserving the cookie, reset it with updated salt
130
-			if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp)
131
-				setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
132
-			else
133
-				setTFACookie(-3600, 0, '');
135
+			if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) {
136
+							setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
137
+			} else {
138
+							setTFACookie(-3600, 0, '');
139
+			}
134 140
 		}
135 141
 
136 142
 		setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
@@ -141,20 +147,20 @@  discard block
 block discarded – undo
141 147
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
142 148
 	{
143 149
 		// Strike!  You're outta there!
144
-		if ($_GET['member'] != $user_info['id'])
145
-			fatal_lang_error('login_cookie_error', false);
150
+		if ($_GET['member'] != $user_info['id']) {
151
+					fatal_lang_error('login_cookie_error', false);
152
+		}
146 153
 
147 154
 		$user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']))));
148 155
 
149 156
 		// Some whitelisting for login_url...
150
-		if (empty($_SESSION['login_url']))
151
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
152
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
157
+		if (empty($_SESSION['login_url'])) {
158
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
159
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
153 160
 		{
154 161
 			unset ($_SESSION['login_url']);
155 162
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
156
-		}
157
-		else
163
+		} else
158 164
 		{
159 165
 			// Best not to clutter the session data too much...
160 166
 			$temp = $_SESSION['login_url'];
@@ -165,8 +171,9 @@  discard block
 block discarded – undo
165 171
 	}
166 172
 
167 173
 	// Beyond this point you are assumed to be a guest trying to login.
168
-	if (!$user_info['is_guest'])
169
-		redirectexit();
174
+	if (!$user_info['is_guest']) {
175
+			redirectexit();
176
+	}
170 177
 
171 178
 	// Are you guessing with a script?
172 179
 	checkSession();
@@ -174,18 +181,21 @@  discard block
 block discarded – undo
174 181
 	spamProtection('login');
175 182
 
176 183
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
177
-	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false))
178
-		$_SESSION['login_url'] = $_SESSION['old_url'];
184
+	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) {
185
+			$_SESSION['login_url'] = $_SESSION['old_url'];
186
+	}
179 187
 
180 188
 	// Been guessing a lot, haven't we?
181
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
182
-		fatal_lang_error('login_threshold_fail', 'login');
189
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
190
+			fatal_lang_error('login_threshold_fail', 'login');
191
+	}
183 192
 
184 193
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
185
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
186
-		$modSettings['cookieTime'] = 3153600;
187
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600))
188
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
194
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
195
+			$modSettings['cookieTime'] = 3153600;
196
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) {
197
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
198
+	}
189 199
 
190 200
 	loadLanguage('Login');
191 201
 	// Load the template stuff.
@@ -305,8 +315,9 @@  discard block
 block discarded – undo
305 315
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
306 316
 
307 317
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
308
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
309
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
318
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
319
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
320
+			}
310 321
 
311 322
 			// phpBB3 users new hashing.  We now support it as well ;).
312 323
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -326,27 +337,29 @@  discard block
 block discarded – undo
326 337
 			// Some common md5 ones.
327 338
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
328 339
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
329
-		}
330
-		elseif (strlen($user_settings['passwd']) == 40)
340
+		} elseif (strlen($user_settings['passwd']) == 40)
331 341
 		{
332 342
 			// Maybe they are using a hash from before the password fix.
333 343
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
334 344
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
335 345
 
336 346
 			// BurningBoard3 style of hashing.
337
-			if (!empty($modSettings['enable_password_conversion']))
338
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
347
+			if (!empty($modSettings['enable_password_conversion'])) {
348
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
349
+			}
339 350
 
340 351
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
341 352
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
342 353
 			{
343 354
 				// Try iconv first, for no particular reason.
344
-				if (function_exists('iconv'))
345
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
355
+				if (function_exists('iconv')) {
356
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
357
+				}
346 358
 
347 359
 				// Say it aint so, iconv failed!
348
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
349
-					$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
360
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
361
+									$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
362
+				}
350 363
 			}
351 364
 		}
352 365
 
@@ -376,8 +389,9 @@  discard block
 block discarded – undo
376 389
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
377 390
 
378 391
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
379
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
380
-				redirectexit('action=reminder');
392
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
393
+							redirectexit('action=reminder');
394
+			}
381 395
 			// We'll give you another chance...
382 396
 			else
383 397
 			{
@@ -388,8 +402,7 @@  discard block
 block discarded – undo
388 402
 				return;
389 403
 			}
390 404
 		}
391
-	}
392
-	elseif (!empty($user_settings['passwd_flood']))
405
+	} elseif (!empty($user_settings['passwd_flood']))
393 406
 	{
394 407
 		// Let's be sure they weren't a little hacker.
395 408
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -406,8 +419,9 @@  discard block
 block discarded – undo
406 419
 	}
407 420
 
408 421
 	// Check their activation status.
409
-	if (!checkActivation())
410
-		return;
422
+	if (!checkActivation()) {
423
+			return;
424
+	}
411 425
 
412 426
 	DoLogin();
413 427
 }
@@ -419,8 +433,9 @@  discard block
 block discarded – undo
419 433
 {
420 434
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
421 435
 
422
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
423
-		fatal_lang_error('no_access', false);
436
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
437
+			fatal_lang_error('no_access', false);
438
+	}
424 439
 
425 440
 	loadLanguage('Profile');
426 441
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -428,8 +443,9 @@  discard block
 block discarded – undo
428 443
 	$member = $context['tfa_member'];
429 444
 
430 445
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
431
-	if (time() - $member['last_login'] < 120)
432
-		fatal_lang_error('tfa_wait', false);
446
+	if (time() - $member['last_login'] < 120) {
447
+			fatal_lang_error('tfa_wait', false);
448
+	}
433 449
 
434 450
 	$totp = new \TOTP\Auth($member['tfa_secret']);
435 451
 	$totp->setRange(1);
@@ -443,8 +459,9 @@  discard block
 block discarded – undo
443 459
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
444 460
 	{
445 461
 		// Check to ensure we're forcing SSL for authentication
446
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
447
-			fatal_lang_error('login_ssl_required');
462
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
463
+					fatal_lang_error('login_ssl_required');
464
+		}
448 465
 
449 466
 		$code = $_POST['tfa_code'];
450 467
 
@@ -454,20 +471,19 @@  discard block
 block discarded – undo
454 471
 
455 472
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve']));
456 473
 			redirectexit();
457
-		}
458
-		else
474
+		} else
459 475
 		{
460 476
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
461 477
 
462 478
 			$context['tfa_error'] = true;
463 479
 			$context['tfa_value'] = $_POST['tfa_code'];
464 480
 		}
465
-	}
466
-	elseif (!empty($_POST['tfa_backup']))
481
+	} elseif (!empty($_POST['tfa_backup']))
467 482
 	{
468 483
 		// Check to ensure we're forcing SSL for authentication
469
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
470
-			fatal_lang_error('login_ssl_required');
484
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
485
+					fatal_lang_error('login_ssl_required');
486
+		}
471 487
 
472 488
 		$backup = $_POST['tfa_backup'];
473 489
 
@@ -481,8 +497,7 @@  discard block
 block discarded – undo
481 497
 			));
482 498
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
483 499
 			redirectexit('action=profile;area=tfasetup;backup');
484
-		}
485
-		else
500
+		} else
486 501
 		{
487 502
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
488 503
 
@@ -505,8 +520,9 @@  discard block
 block discarded – undo
505 520
 {
506 521
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
507 522
 
508
-	if (!isset($context['login_errors']))
509
-		$context['login_errors'] = array();
523
+	if (!isset($context['login_errors'])) {
524
+			$context['login_errors'] = array();
525
+	}
510 526
 
511 527
 	// What is the true activation status of this account?
512 528
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -518,8 +534,9 @@  discard block
 block discarded – undo
518 534
 		return false;
519 535
 	}
520 536
 	// Awaiting approval still?
521
-	elseif ($activation_status == 3)
522
-		fatal_lang_error('still_awaiting_approval', 'user');
537
+	elseif ($activation_status == 3) {
538
+			fatal_lang_error('still_awaiting_approval', 'user');
539
+	}
523 540
 	// Awaiting deletion, changed their mind?
524 541
 	elseif ($activation_status == 4)
525 542
 	{
@@ -527,8 +544,7 @@  discard block
 block discarded – undo
527 544
 		{
528 545
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
529 546
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
530
-		}
531
-		else
547
+		} else
532 548
 		{
533 549
 			$context['disable_login_hashing'] = true;
534 550
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -568,8 +584,9 @@  discard block
 block discarded – undo
568 584
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
569 585
 
570 586
 	// Reset the login threshold.
571
-	if (isset($_SESSION['failed_login']))
572
-		unset($_SESSION['failed_login']);
587
+	if (isset($_SESSION['failed_login'])) {
588
+			unset($_SESSION['failed_login']);
589
+	}
573 590
 
574 591
 	$user_info['is_guest'] = false;
575 592
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -591,16 +608,18 @@  discard block
 block discarded – undo
591 608
 			'id_member' => $user_info['id'],
592 609
 		)
593 610
 	);
594
-	if ($smcFunc['db_num_rows']($request) == 1)
595
-		$_SESSION['first_login'] = true;
596
-	else
597
-		unset($_SESSION['first_login']);
611
+	if ($smcFunc['db_num_rows']($request) == 1) {
612
+			$_SESSION['first_login'] = true;
613
+	} else {
614
+			unset($_SESSION['first_login']);
615
+	}
598 616
 	$smcFunc['db_free_result']($request);
599 617
 
600 618
 	// You've logged in, haven't you?
601 619
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
602
-	if (empty($user_settings['tfa_secret']))
603
-		$update['last_login'] = time();
620
+	if (empty($user_settings['tfa_secret'])) {
621
+			$update['last_login'] = time();
622
+	}
604 623
 	updateMemberData($user_info['id'], $update);
605 624
 
606 625
 	// Get rid of the online entry for that old guest....
@@ -614,8 +633,8 @@  discard block
 block discarded – undo
614 633
 	$_SESSION['log_time'] = 0;
615 634
 
616 635
 	// Log this entry, only if we have it enabled.
617
-	if (!empty($modSettings['loginHistoryDays']))
618
-		$smcFunc['db_insert']('insert',
636
+	if (!empty($modSettings['loginHistoryDays'])) {
637
+			$smcFunc['db_insert']('insert',
619 638
 			'{db_prefix}member_logins',
620 639
 			array(
621 640
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -627,13 +646,15 @@  discard block
 block discarded – undo
627 646
 				'id_member', 'time'
628 647
 			)
629 648
 		);
649
+	}
630 650
 
631 651
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
632
-	if (empty($maintenance) || allowedTo('admin_forum'))
633
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
634
-	else
635
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
636
-}
652
+	if (empty($maintenance) || allowedTo('admin_forum')) {
653
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
654
+	} else {
655
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
656
+	}
657
+	}
637 658
 
638 659
 /**
639 660
  * Logs the current user out of their account.
@@ -649,13 +670,15 @@  discard block
 block discarded – undo
649 670
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
650 671
 
651 672
 	// Make sure they aren't being auto-logged out.
652
-	if (!$internal)
653
-		checkSession('get');
673
+	if (!$internal) {
674
+			checkSession('get');
675
+	}
654 676
 
655 677
 	require_once($sourcedir . '/Subs-Auth.php');
656 678
 
657
-	if (isset($_SESSION['pack_ftp']))
658
-		$_SESSION['pack_ftp'] = null;
679
+	if (isset($_SESSION['pack_ftp'])) {
680
+			$_SESSION['pack_ftp'] = null;
681
+	}
659 682
 
660 683
 	// It won't be first login anymore.
661 684
 	unset($_SESSION['first_login']);
@@ -683,8 +706,9 @@  discard block
 block discarded – undo
683 706
 
684 707
 	// And some other housekeeping while we're at it.
685 708
 	$salt = substr(md5(mt_rand()), 0, 4);
686
-	if (!empty($user_info['id']))
687
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
709
+	if (!empty($user_info['id'])) {
710
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
711
+	}
688 712
 
689 713
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
690 714
 	{
@@ -693,10 +717,11 @@  discard block
 block discarded – undo
693 717
 		list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
694 718
 
695 719
 		// If we're preserving the cookie, reset it with updated salt
696
-		if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp)
697
-			setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
698
-		else
699
-			setTFACookie(-3600, 0, '');
720
+		if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) {
721
+					setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
722
+		} else {
723
+					setTFACookie(-3600, 0, '');
724
+		}
700 725
 	}
701 726
 
702 727
 	session_destroy();
@@ -704,14 +729,13 @@  discard block
 block discarded – undo
704 729
 	// Off to the merry board index we go!
705 730
 	if ($redirect)
706 731
 	{
707
-		if (empty($_SESSION['logout_url']))
708
-			redirectexit('', $context['server']['needs_login_fix']);
709
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
732
+		if (empty($_SESSION['logout_url'])) {
733
+					redirectexit('', $context['server']['needs_login_fix']);
734
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
710 735
 		{
711 736
 			unset ($_SESSION['logout_url']);
712 737
 			redirectexit();
713
-		}
714
-		else
738
+		} else
715 739
 		{
716 740
 			$temp = $_SESSION['logout_url'];
717 741
 			unset($_SESSION['logout_url']);
@@ -744,8 +768,9 @@  discard block
 block discarded – undo
744 768
 function phpBB3_password_check($passwd, $passwd_hash)
745 769
 {
746 770
 	// Too long or too short?
747
-	if (strlen($passwd_hash) != 34)
748
-		return;
771
+	if (strlen($passwd_hash) != 34) {
772
+			return;
773
+	}
749 774
 
750 775
 	// Range of characters allowed.
751 776
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -756,8 +781,9 @@  discard block
 block discarded – undo
756 781
 	$salt = substr($passwd_hash, 4, 8);
757 782
 
758 783
 	$hash = md5($salt . $passwd, true);
759
-	for (; $count != 0; --$count)
760
-		$hash = md5($hash . $passwd, true);
784
+	for (; $count != 0; --$count) {
785
+			$hash = md5($hash . $passwd, true);
786
+	}
761 787
 
762 788
 	$output = substr($passwd_hash, 0, 12);
763 789
 	$i = 0;
@@ -766,21 +792,25 @@  discard block
 block discarded – undo
766 792
 		$value = ord($hash[$i++]);
767 793
 		$output .= $range[$value & 0x3f];
768 794
 
769
-		if ($i < 16)
770
-			$value |= ord($hash[$i]) << 8;
795
+		if ($i < 16) {
796
+					$value |= ord($hash[$i]) << 8;
797
+		}
771 798
 
772 799
 		$output .= $range[($value >> 6) & 0x3f];
773 800
 
774
-		if ($i++ >= 16)
775
-			break;
801
+		if ($i++ >= 16) {
802
+					break;
803
+		}
776 804
 
777
-		if ($i < 16)
778
-			$value |= ord($hash[$i]) << 16;
805
+		if ($i < 16) {
806
+					$value |= ord($hash[$i]) << 16;
807
+		}
779 808
 
780 809
 		$output .= $range[($value >> 12) & 0x3f];
781 810
 
782
-		if ($i++ >= 16)
783
-			break;
811
+		if ($i++ >= 16) {
812
+					break;
813
+		}
784 814
 
785 815
 		$output .= $range[($value >> 18) & 0x3f];
786 816
 	}
@@ -809,8 +839,9 @@  discard block
 block discarded – undo
809 839
 	// Only if they're not validating for 2FA
810 840
 	if (!$tfa)
811 841
 	{
812
-		if (isset($_SESSION['login_' . $cookiename]))
813
-			unset($_SESSION['login_' . $cookiename]);
842
+		if (isset($_SESSION['login_' . $cookiename])) {
843
+					unset($_SESSION['login_' . $cookiename]);
844
+		}
814 845
 	}
815 846
 
816 847
 	// We need a member!
@@ -824,8 +855,9 @@  discard block
 block discarded – undo
824 855
 	}
825 856
 
826 857
 	// Right, have we got a flood value?
827
-	if ($password_flood_value !== false)
828
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
858
+	if ($password_flood_value !== false) {
859
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
860
+	}
829 861
 
830 862
 	// Timestamp or number of tries invalid?
831 863
 	if (empty($number_tries) || empty($time_stamp))
@@ -841,15 +873,17 @@  discard block
 block discarded – undo
841 873
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
842 874
 
843 875
 		// They are trying too fast, make them wait longer
844
-		if ($time_stamp < time() - 10)
845
-			$time_stamp = time();
876
+		if ($time_stamp < time() - 10) {
877
+					$time_stamp = time();
878
+		}
846 879
 	}
847 880
 
848 881
 	$number_tries++;
849 882
 
850 883
 	// Broken the law?
851
-	if ($number_tries > 5)
852
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
884
+	if ($number_tries > 5) {
885
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
886
+	}
853 887
 
854 888
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
855 889
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
Sources/CacheAPI-sqlite.php 1 patch
Braces   +16 added lines, -11 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * SQLite Cache API class
@@ -68,8 +69,9 @@  discard block
 block discarded – undo
68 69
 	{
69 70
 		$supported = class_exists("SQLite3") && is_writable($this->cachedir);
70 71
 
71
-		if ($test)
72
-			return $supported;
72
+		if ($test) {
73
+					return $supported;
74
+		}
73 75
 
74 76
 		return parent::isSupported() && $supported;
75 77
 	}
@@ -84,8 +86,9 @@  discard block
 block discarded – undo
84 86
 		$result = $this->cacheDB->query($query);
85 87
 
86 88
 		$value = null;
87
-		while ($res = $result->fetchArray(SQLITE3_ASSOC))
88
-			$value = $res['value'];
89
+		while ($res = $result->fetchArray(SQLITE3_ASSOC)) {
90
+					$value = $res['value'];
91
+		}
89 92
 
90 93
 		return !empty($value) ? $value : null;
91 94
 	}
@@ -125,8 +128,9 @@  discard block
 block discarded – undo
125 128
 		$config_vars[] = $txt['cache_sqlite_settings'];
126 129
 		$config_vars[] = array('cachedir_sqlite', $txt['cachedir_sqlite'], 'file', 'text', 36, 'cache_sqlite_cachedir');
127 130
 
128
-		if (!isset($context['settings_post_javascript']))
129
-			$context['settings_post_javascript'] = '';
131
+		if (!isset($context['settings_post_javascript'])) {
132
+					$context['settings_post_javascript'] = '';
133
+		}
130 134
 
131 135
 		$context['settings_post_javascript'] .= '
132 136
 			$("#cache_accelerator").change(function (e) {
@@ -149,10 +153,11 @@  discard block
 block discarded – undo
149 153
 		global $cachedir_sqlite;
150 154
 
151 155
 		// If its invalid, use SMF's.
152
-		if (is_null($dir) || !is_writable($dir))
153
-			$this->cachedir = $cachedir_sqlite;
154
-		else
155
-			$this->cachedir = $dir;
156
+		if (is_null($dir) || !is_writable($dir)) {
157
+					$this->cachedir = $cachedir_sqlite;
158
+		} else {
159
+					$this->cachedir = $dir;
160
+		}
156 161
 	}
157 162
 
158 163
 	/**
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 1 patch
Braces   +229 added lines, -169 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Maps the implementations in this file (smf_db_function_name)
@@ -34,8 +35,8 @@  discard block
 block discarded – undo
34 35
 	global $smcFunc;
35 36
 
36 37
 	// Map some database specific functions, only do this once.
37
-	if (!isset($smcFunc['db_fetch_assoc']))
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_fetch_assoc'])) {
39
+			$smcFunc += array(
39 40
 			'db_query'					=> 'smf_db_query',
40 41
 			'db_quote'					=> 'smf_db_quote',
41 42
 			'db_insert'					=> 'smf_db_insert',
@@ -63,11 +64,13 @@  discard block
 block discarded – undo
63 64
 			'db_fetch_all'				=> 'smf_db_fetch_all',
64 65
 			'db_error_insert'			=> 'smf_db_error_insert',
65 66
 		);
67
+	}
66 68
 
67
-	if (!empty($db_options['persist']))
68
-		$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
69
-	else
70
-		$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
69
+	if (!empty($db_options['persist'])) {
70
+			$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
71
+	} else {
72
+			$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
73
+	}
71 74
 
72 75
 	// Something's wrong, show an error if its fatal (which we assume it is)
73 76
 	if (!$connection)
@@ -75,8 +78,7 @@  discard block
 block discarded – undo
75 78
 		if (!empty($db_options['non_fatal']))
76 79
 		{
77 80
 			return null;
78
-		}
79
-		else
81
+		} else
80 82
 		{
81 83
 			display_db_error();
82 84
 		}
@@ -127,31 +129,38 @@  discard block
 block discarded – undo
127 129
 
128 130
 	list ($values, $connection) = $db_callback;
129 131
 
130
-	if ($matches[1] === 'db_prefix')
131
-		return $db_prefix;
132
+	if ($matches[1] === 'db_prefix') {
133
+			return $db_prefix;
134
+	}
132 135
 
133
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
134
-		return $user_info[$matches[1]];
136
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
137
+			return $user_info[$matches[1]];
138
+	}
135 139
 
136
-	if ($matches[1] === 'empty')
137
-		return '\'\'';
140
+	if ($matches[1] === 'empty') {
141
+			return '\'\'';
142
+	}
138 143
 
139
-	if (!isset($matches[2]))
140
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
144
+	if (!isset($matches[2])) {
145
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
146
+	}
141 147
 
142
-	if ($matches[1] === 'literal')
143
-		return '\'' . pg_escape_string($matches[2]) . '\'';
148
+	if ($matches[1] === 'literal') {
149
+			return '\'' . pg_escape_string($matches[2]) . '\'';
150
+	}
144 151
 
145
-	if (!isset($values[$matches[2]]))
146
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
152
+	if (!isset($values[$matches[2]])) {
153
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
154
+	}
147 155
 
148 156
 	$replacement = $values[$matches[2]];
149 157
 
150 158
 	switch ($matches[1])
151 159
 	{
152 160
 		case 'int':
153
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
154
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
161
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
162
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
163
+			}
155 164
 			return (string) (int) $replacement;
156 165
 		break;
157 166
 
@@ -163,65 +172,73 @@  discard block
 block discarded – undo
163 172
 		case 'array_int':
164 173
 			if (is_array($replacement))
165 174
 			{
166
-				if (empty($replacement))
167
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
175
+				if (empty($replacement)) {
176
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
177
+				}
168 178
 
169 179
 				foreach ($replacement as $key => $value)
170 180
 				{
171
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
172
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
182
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183
+					}
173 184
 
174 185
 					$replacement[$key] = (string) (int) $value;
175 186
 				}
176 187
 
177 188
 				return implode(', ', $replacement);
189
+			} else {
190
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
178 191
 			}
179
-			else
180
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181 192
 
182 193
 		break;
183 194
 
184 195
 		case 'array_string':
185 196
 			if (is_array($replacement))
186 197
 			{
187
-				if (empty($replacement))
188
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
198
+				if (empty($replacement)) {
199
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
200
+				}
189 201
 
190
-				foreach ($replacement as $key => $value)
191
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
202
+				foreach ($replacement as $key => $value) {
203
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
204
+				}
192 205
 
193 206
 				return implode(', ', $replacement);
207
+			} else {
208
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
194 209
 			}
195
-			else
196
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
197 210
 		break;
198 211
 
199 212
 		case 'date':
200
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
201
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
202
-			else
203
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
214
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
215
+			} else {
216
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
217
+			}
204 218
 		break;
205 219
 
206 220
 		case 'time':
207
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
208
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
209
-			else
210
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
222
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
223
+			} else {
224
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+			}
211 226
 		break;
212 227
 
213 228
 		case 'datetime':
214
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
215
-				return 'to_timestamp('.
229
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
230
+							return 'to_timestamp('.
216 231
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
217 232
 					',\'YYYY-MM-DD HH24:MI:SS\')';
218
-			else
219
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+			} else {
234
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
235
+			}
220 236
 		break;
221 237
 
222 238
 		case 'float':
223
-			if (!is_numeric($replacement))
224
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
239
+			if (!is_numeric($replacement)) {
240
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
241
+			}
225 242
 			return (string) (float) $replacement;
226 243
 		break;
227 244
 
@@ -234,31 +251,36 @@  discard block
 block discarded – undo
234 251
 		break;
235 252
 
236 253
 		case 'inet':
237
-			if ($replacement == 'null' || $replacement == '')
238
-				return 'null';
239
-			if (inet_pton($replacement) === false)
240
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
254
+			if ($replacement == 'null' || $replacement == '') {
255
+							return 'null';
256
+			}
257
+			if (inet_pton($replacement) === false) {
258
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
259
+			}
241 260
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
242 261
 
243 262
 		case 'array_inet':
244 263
 			if (is_array($replacement))
245 264
 			{
246
-				if (empty($replacement))
247
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265
+				if (empty($replacement)) {
266
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
267
+				}
248 268
 
249 269
 				foreach ($replacement as $key => $value)
250 270
 				{
251
-					if ($replacement == 'null' || $replacement == '')
252
-						$replacement[$key] = 'null';
253
-					if (!isValidIP($value))
254
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
271
+					if ($replacement == 'null' || $replacement == '') {
272
+											$replacement[$key] = 'null';
273
+					}
274
+					if (!isValidIP($value)) {
275
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
276
+					}
255 277
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
256 278
 				}
257 279
 
258 280
 				return implode(', ', $replacement);
281
+			} else {
282
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
259 283
 			}
260
-			else
261
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
262 284
 		break;
263 285
 
264 286
 		default:
@@ -349,14 +371,16 @@  discard block
 block discarded – undo
349 371
 		),
350 372
 	);
351 373
 
352
-	if (isset($replacements[$identifier]))
353
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
374
+	if (isset($replacements[$identifier])) {
375
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
376
+	}
354 377
 
355 378
 	// Limits need to be a little different.
356 379
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
357 380
 
358
-	if (trim($db_string) == '')
359
-		return false;
381
+	if (trim($db_string) == '') {
382
+			return false;
383
+	}
360 384
 
361 385
 	// Comments that are allowed in a query are preg_removed.
362 386
 	static $allowed_comments_from = array(
@@ -376,8 +400,9 @@  discard block
 block discarded – undo
376 400
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
377 401
 	$db_replace_result = 0;
378 402
 
379
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
380
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
403
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
404
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
405
+	}
381 406
 
382 407
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
383 408
 	{
@@ -398,8 +423,9 @@  discard block
 block discarded – undo
398 423
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
399 424
 
400 425
 		// Initialize $db_cache if not already initialized.
401
-		if (!isset($db_cache))
402
-			$db_cache = array();
426
+		if (!isset($db_cache)) {
427
+					$db_cache = array();
428
+		}
403 429
 
404 430
 		if (!empty($_SESSION['debug_redirect']))
405 431
 		{
@@ -425,17 +451,18 @@  discard block
 block discarded – undo
425 451
 		while (true)
426 452
 		{
427 453
 			$pos = strpos($db_string, '\'', $pos + 1);
428
-			if ($pos === false)
429
-				break;
454
+			if ($pos === false) {
455
+							break;
456
+			}
430 457
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
431 458
 
432 459
 			while (true)
433 460
 			{
434 461
 				$pos1 = strpos($db_string, '\'', $pos + 1);
435 462
 				$pos2 = strpos($db_string, '\\', $pos + 1);
436
-				if ($pos1 === false)
437
-					break;
438
-				elseif ($pos2 === false || $pos2 > $pos1)
463
+				if ($pos1 === false) {
464
+									break;
465
+				} elseif ($pos2 === false || $pos2 > $pos1)
439 466
 				{
440 467
 					$pos = $pos1;
441 468
 					break;
@@ -451,16 +478,19 @@  discard block
 block discarded – undo
451 478
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
452 479
 
453 480
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
454
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
455
-			$fail = true;
481
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
482
+					$fail = true;
483
+		}
456 484
 		// Trying to change passwords, slow us down, or something?
457
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
458
-			$fail = true;
459
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
460
-			$fail = true;
485
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
486
+					$fail = true;
487
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
488
+					$fail = true;
489
+		}
461 490
 
462
-		if (!empty($fail) && function_exists('log_error'))
463
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
491
+		if (!empty($fail) && function_exists('log_error')) {
492
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
493
+		}
464 494
 	}
465 495
 
466 496
 	// Set optimize stuff
@@ -479,18 +509,21 @@  discard block
 block discarded – undo
479 509
 
480 510
 		$db_string = $query_hints_set . $db_string;
481 511
 		
482
-		if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...')
483
-			$db_cache[$db_count]['q'] = "\t\t" . $db_string;
512
+		if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...') {
513
+					$db_cache[$db_count]['q'] = "\t\t" . $db_string;
514
+		}
484 515
 	}
485 516
 
486 517
 	$db_last_result = @pg_query($connection, $db_string);
487 518
 
488
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
489
-		$db_last_result = smf_db_error($db_string, $connection);
519
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
520
+			$db_last_result = smf_db_error($db_string, $connection);
521
+	}
490 522
 
491 523
 	// Debugging.
492
-	if (isset($db_show_debug) && $db_show_debug === true)
493
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
524
+	if (isset($db_show_debug) && $db_show_debug === true) {
525
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
526
+	}
494 527
 
495 528
 	return $db_last_result;
496 529
 }
@@ -507,10 +540,11 @@  discard block
 block discarded – undo
507 540
 {
508 541
 	global $db_last_result, $db_replace_result;
509 542
 
510
-	if ($db_replace_result)
511
-		return $db_replace_result;
512
-	elseif ($result === null && !$db_last_result)
513
-		return 0;
543
+	if ($db_replace_result) {
544
+			return $db_replace_result;
545
+	} elseif ($result === null && !$db_last_result) {
546
+			return 0;
547
+	}
514 548
 
515 549
 	return pg_affected_rows($result === null ? $db_last_result : $result);
516 550
 }
@@ -534,8 +568,9 @@  discard block
 block discarded – undo
534 568
 		array(
535 569
 		)
536 570
 	);
537
-	if (!$request)
538
-		return false;
571
+	if (!$request) {
572
+			return false;
573
+	}
539 574
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
540 575
 	$smcFunc['db_free_result']($request);
541 576
 
@@ -556,12 +591,13 @@  discard block
 block discarded – undo
556 591
 	// Decide which connection to use
557 592
 	$connection = $connection === null ? $db_connection : $connection;
558 593
 
559
-	if ($type == 'begin')
560
-		return @pg_query($connection, 'BEGIN');
561
-	elseif ($type == 'rollback')
562
-		return @pg_query($connection, 'ROLLBACK');
563
-	elseif ($type == 'commit')
564
-		return @pg_query($connection, 'COMMIT');
594
+	if ($type == 'begin') {
595
+			return @pg_query($connection, 'BEGIN');
596
+	} elseif ($type == 'rollback') {
597
+			return @pg_query($connection, 'ROLLBACK');
598
+	} elseif ($type == 'commit') {
599
+			return @pg_query($connection, 'COMMIT');
600
+	}
565 601
 
566 602
 	return false;
567 603
 }
@@ -589,19 +625,22 @@  discard block
 block discarded – undo
589 625
 	$query_error = @pg_last_error($connection);
590 626
 
591 627
 	// Log the error.
592
-	if (function_exists('log_error'))
593
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
628
+	if (function_exists('log_error')) {
629
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
630
+	}
594 631
 
595 632
 	// Nothing's defined yet... just die with it.
596
-	if (empty($context) || empty($txt))
597
-		die($query_error);
633
+	if (empty($context) || empty($txt)) {
634
+			die($query_error);
635
+	}
598 636
 
599 637
 	// Show an error message, if possible.
600 638
 	$context['error_title'] = $txt['database_error'];
601
-	if (allowedTo('admin_forum'))
602
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
603
-	else
604
-		$context['error_message'] = $txt['try_again'];
639
+	if (allowedTo('admin_forum')) {
640
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
641
+	} else {
642
+			$context['error_message'] = $txt['try_again'];
643
+	}
605 644
 
606 645
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
607 646
 	{
@@ -623,12 +662,14 @@  discard block
 block discarded – undo
623 662
 {
624 663
 	global $db_row_count;
625 664
 
626
-	if ($counter !== false)
627
-		return pg_fetch_row($request, $counter);
665
+	if ($counter !== false) {
666
+			return pg_fetch_row($request, $counter);
667
+	}
628 668
 
629 669
 	// Reset the row counter...
630
-	if (!isset($db_row_count[(int) $request]))
631
-		$db_row_count[(int) $request] = 0;
670
+	if (!isset($db_row_count[(int) $request])) {
671
+			$db_row_count[(int) $request] = 0;
672
+	}
632 673
 
633 674
 	// Return the right row.
634 675
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -645,12 +686,14 @@  discard block
 block discarded – undo
645 686
 {
646 687
 	global $db_row_count;
647 688
 
648
-	if ($counter !== false)
649
-		return pg_fetch_assoc($request, $counter);
689
+	if ($counter !== false) {
690
+			return pg_fetch_assoc($request, $counter);
691
+	}
650 692
 
651 693
 	// Reset the row counter...
652
-	if (!isset($db_row_count[(int) $request]))
653
-		$db_row_count[(int) $request] = 0;
694
+	if (!isset($db_row_count[(int) $request])) {
695
+			$db_row_count[(int) $request] = 0;
696
+	}
654 697
 
655 698
 	// Return the right row.
656 699
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -703,11 +746,13 @@  discard block
 block discarded – undo
703 746
 
704 747
 	$replace = '';
705 748
 
706
-	if (empty($data))
707
-		return;
749
+	if (empty($data)) {
750
+			return;
751
+	}
708 752
 
709
-	if (!is_array($data[array_rand($data)]))
710
-		$data = array($data);
753
+	if (!is_array($data[array_rand($data)])) {
754
+			$data = array($data);
755
+	}
711 756
 
712 757
 	// Replace the prefix holder with the actual prefix.
713 758
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -726,11 +771,13 @@  discard block
 block discarded – undo
726 771
 			//pg 9.5 got replace support
727 772
 			$pg_version = $smcFunc['db_get_version']();
728 773
 			// if we got a Beta Version
729
-			if (stripos($pg_version, 'beta') !== false)
730
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
774
+			if (stripos($pg_version, 'beta') !== false) {
775
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
776
+			}
731 777
 			// or RC
732
-			if (stripos($pg_version, 'rc') !== false)
733
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
778
+			if (stripos($pg_version, 'rc') !== false) {
779
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
780
+			}
734 781
 
735 782
 			$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
736 783
 		}
@@ -749,32 +796,35 @@  discard block
 block discarded – undo
749 796
 					$key_str .= ($count_pk > 0 ? ',' : '');
750 797
 					$key_str .= $columnName;
751 798
 					$count_pk++;
752
-				}
753
-				else if ($method == 'replace') //normal field
799
+				} else if ($method == 'replace') {
800
+					//normal field
754 801
 				{
755 802
 					$col_str .= ($count > 0 ? ',' : '');
803
+				}
756 804
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
757 805
 					$count++;
758 806
 				}
759 807
 			}
760
-			if ($method == 'replace')
761
-				$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
762
-			else
763
-				$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
764
-		}
765
-		else if ($method == 'replace')
808
+			if ($method == 'replace') {
809
+							$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
810
+			} else {
811
+							$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
812
+			}
813
+		} else if ($method == 'replace')
766 814
 		{
767 815
 			foreach ($columns as $columnName => $type)
768 816
 			{
769 817
 				// Are we restricting the length?
770
-				if (strpos($type, 'string-') !== false)
771
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
772
-				else
773
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
818
+				if (strpos($type, 'string-') !== false) {
819
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
820
+				} else {
821
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
822
+				}
774 823
 
775 824
 				// A key? That's what we were looking for.
776
-				if (in_array($columnName, $keys))
777
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
825
+				if (in_array($columnName, $keys)) {
826
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
827
+				}
778 828
 				$count++;
779 829
 			}
780 830
 
@@ -810,10 +860,11 @@  discard block
 block discarded – undo
810 860
 		foreach ($columns as $columnName => $type)
811 861
 		{
812 862
 			// Are we restricting the length?
813
-			if (strpos($type, 'string-') !== false)
814
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
815
-			else
816
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
863
+			if (strpos($type, 'string-') !== false) {
864
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
865
+			} else {
866
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
867
+			}
817 868
 		}
818 869
 		$insertData = substr($insertData, 0, -2) . ')';
819 870
 
@@ -822,8 +873,9 @@  discard block
 block discarded – undo
822 873
 
823 874
 		// Here's where the variables are injected to the query.
824 875
 		$insertRows = array();
825
-		foreach ($data as $dataRow)
826
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
876
+		foreach ($data as $dataRow) {
877
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
878
+		}
827 879
 
828 880
 		// Do the insert.
829 881
 		$request = $smcFunc['db_query']('', '
@@ -840,19 +892,21 @@  discard block
 block discarded – undo
840 892
 
841 893
 		if ($with_returning && $request !== false)
842 894
 		{
843
-			if ($returnmode === 2)
844
-				$return_var = array();
895
+			if ($returnmode === 2) {
896
+							$return_var = array();
897
+			}
845 898
 
846 899
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
847 900
 			{
848
-				if (is_numeric($row[0])) // try to emulate mysql limitation
901
+				if (is_numeric($row[0])) {
902
+					// try to emulate mysql limitation
849 903
 				{
850 904
 					if ($returnmode === 1)
851 905
 						$return_var = $row[0];
852
-					elseif ($returnmode === 2)
853
-						$return_var[] = $row[0];
854
-				}
855
-				else
906
+				} elseif ($returnmode === 2) {
907
+											$return_var[] = $row[0];
908
+					}
909
+				} else
856 910
 				{
857 911
 					$with_returning = false;
858 912
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -861,9 +915,10 @@  discard block
 block discarded – undo
861 915
 		}
862 916
 	}
863 917
 
864
-	if ($with_returning && !empty($return_var))
865
-		return $return_var;
866
-}
918
+	if ($with_returning && !empty($return_var)) {
919
+			return $return_var;
920
+	}
921
+	}
867 922
 
868 923
 /**
869 924
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -900,8 +955,9 @@  discard block
 block discarded – undo
900 955
  */
901 956
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
902 957
 {
903
-	if (empty($log_message))
904
-		$log_message = $error_message;
958
+	if (empty($log_message)) {
959
+			$log_message = $error_message;
960
+	}
905 961
 
906 962
 	foreach (debug_backtrace() as $step)
907 963
 	{
@@ -920,12 +976,14 @@  discard block
 block discarded – undo
920 976
 	}
921 977
 
922 978
 	// A special case - we want the file and line numbers for debugging.
923
-	if ($error_type == 'return')
924
-		return array($file, $line);
979
+	if ($error_type == 'return') {
980
+			return array($file, $line);
981
+	}
925 982
 
926 983
 	// Is always a critical error.
927
-	if (function_exists('log_error'))
928
-		log_error($log_message, 'critical', $file, $line);
984
+	if (function_exists('log_error')) {
985
+			log_error($log_message, 'critical', $file, $line);
986
+	}
929 987
 
930 988
 	if (function_exists('fatal_error'))
931 989
 	{
@@ -933,12 +991,12 @@  discard block
 block discarded – undo
933 991
 
934 992
 		// Cannot continue...
935 993
 		exit;
994
+	} elseif ($error_type) {
995
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
996
+	} else {
997
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
998
+	}
936 999
 	}
937
-	elseif ($error_type)
938
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
939
-	else
940
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
941
-}
942 1000
 
943 1001
 /**
944 1002
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -955,10 +1013,11 @@  discard block
 block discarded – undo
955 1013
 		'\\' => '\\\\',
956 1014
 	);
957 1015
 
958
-	if ($translate_human_wildcards)
959
-		$replacements += array(
1016
+	if ($translate_human_wildcards) {
1017
+			$replacements += array(
960 1018
 			'*' => '%',
961 1019
 		);
1020
+	}
962 1021
 
963 1022
 	return strtr($string, $replacements);
964 1023
 }
@@ -986,11 +1045,12 @@  discard block
 block discarded – undo
986 1045
 	global  $db_prefix, $db_connection;
987 1046
 	static $pg_error_data_prep;
988 1047
 
989
-	if (empty($pg_error_data_prep))
990
-			$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
1048
+	if (empty($pg_error_data_prep)) {
1049
+				$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
991 1050
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line)
992 1051
 													VALUES(		$1,		$2,		$3, $4, 	$5,		$6,			$7,		$8,	$9)'
993 1052
 			);
1053
+	}
994 1054
 
995 1055
 	pg_execute($db_connection, 'smf_log_errors', $error_array);
996 1056
 }
Please login to merge, or discard this patch.