Completed
Pull Request — release-2.1 (#5058)
by 01
120:18 queued 71:00
created
other/upgrade-helper.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 /**
82 82
  * Make files writable. First try to use regular chmod, but if that fails, try to use FTP.
83 83
  *
84
- * @param $files
84
+ * @param string[] $files
85 85
  * @return bool
86 86
  */
87 87
 function makeFilesWritable(&$files)
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 /**
323 323
  * Prints an error to stderr.
324 324
  *
325
- * @param $message
325
+ * @param string $message
326 326
  * @param bool $fatal
327 327
  */
328 328
 function print_error($message, $fatal = false)
Please login to merge, or discard this patch.
Braces   +96 added lines, -68 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * This file contains helper functions for upgrade.php
14 14
  */
15 15
 
16
-if (!defined('SMF_VERSION'))
16
+if (!defined('SMF_VERSION')) {
17 17
 	die('No direct access!');
18
+}
18 19
 
19 20
 /**
20 21
  * Clean the cache using the SMF 2.1 CacheAPI.
@@ -45,8 +46,9 @@  discard block
 block discarded – undo
45 46
 	global $smcFunc;
46 47
 	static $member_groups = array();
47 48
 
48
-	if (!empty($member_groups))
49
-		return $member_groups;
49
+	if (!empty($member_groups)) {
50
+			return $member_groups;
51
+	}
50 52
 
51 53
 	$request = $smcFunc['db_query']('', '
52 54
 		SELECT group_name, id_group
@@ -71,8 +73,9 @@  discard block
 block discarded – undo
71 73
 			)
72 74
 		);
73 75
 	}
74
-	while ($row = $smcFunc['db_fetch_row']($request))
75
-		$member_groups[trim($row[0])] = $row[1];
76
+	while ($row = $smcFunc['db_fetch_row']($request)) {
77
+			$member_groups[trim($row[0])] = $row[1];
78
+	}
76 79
 	$smcFunc['db_free_result']($request);
77 80
 
78 81
 	return $member_groups;
@@ -88,8 +91,9 @@  discard block
 block discarded – undo
88 91
 {
89 92
 	global $upcontext, $boarddir, $sourcedir;
90 93
 
91
-	if (empty($files))
92
-		return true;
94
+	if (empty($files)) {
95
+			return true;
96
+	}
93 97
 
94 98
 	$failure = false;
95 99
 	// On linux, it's easy - just use is_writable!
@@ -100,22 +104,25 @@  discard block
 block discarded – undo
100 104
 		foreach ($files as $k => $file)
101 105
 		{
102 106
 			// Some files won't exist, try to address up front
103
-			if (!file_exists($file))
104
-				@touch($file);
107
+			if (!file_exists($file)) {
108
+							@touch($file);
109
+			}
105 110
 			// NOW do the writable check...
106 111
 			if (!is_writable($file))
107 112
 			{
108 113
 				@chmod($file, 0755);
109 114
 
110 115
 				// Well, 755 hopefully worked... if not, try 777.
111
-				if (!is_writable($file) && !@chmod($file, 0777))
112
-					$failure = true;
116
+				if (!is_writable($file) && !@chmod($file, 0777)) {
117
+									$failure = true;
118
+				}
113 119
 				// Otherwise remove it as it's good!
114
-				else
115
-					unset($files[$k]);
120
+				else {
121
+									unset($files[$k]);
122
+				}
123
+			} else {
124
+							unset($files[$k]);
116 125
 			}
117
-			else
118
-				unset($files[$k]);
119 126
 		}
120 127
 	}
121 128
 	// Windows is trickier.  Let's try opening for r+...
@@ -126,30 +133,35 @@  discard block
 block discarded – undo
126 133
 		foreach ($files as $k => $file)
127 134
 		{
128 135
 			// Folders can't be opened for write... but the index.php in them can ;).
129
-			if (is_dir($file))
130
-				$file .= '/index.php';
136
+			if (is_dir($file)) {
137
+							$file .= '/index.php';
138
+			}
131 139
 
132 140
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
133 141
 			@chmod($file, 0777);
134 142
 			$fp = @fopen($file, 'r+');
135 143
 
136 144
 			// Hmm, okay, try just for write in that case...
137
-			if (!$fp)
138
-				$fp = @fopen($file, 'w');
145
+			if (!$fp) {
146
+							$fp = @fopen($file, 'w');
147
+			}
139 148
 
140
-			if (!$fp)
141
-				$failure = true;
142
-			else
143
-				unset($files[$k]);
149
+			if (!$fp) {
150
+							$failure = true;
151
+			} else {
152
+							unset($files[$k]);
153
+			}
144 154
 			@fclose($fp);
145 155
 		}
146 156
 	}
147 157
 
148
-	if (empty($files))
149
-		return true;
158
+	if (empty($files)) {
159
+			return true;
160
+	}
150 161
 
151
-	if (!isset($_SERVER))
152
-		return !$failure;
162
+	if (!isset($_SERVER)) {
163
+			return !$failure;
164
+	}
153 165
 
154 166
 	// What still needs to be done?
155 167
 	$upcontext['chmod']['files'] = $files;
@@ -201,36 +213,40 @@  discard block
 block discarded – undo
201 213
 
202 214
 		if (!isset($ftp) || $ftp->error !== false)
203 215
 		{
204
-			if (!isset($ftp))
205
-				$ftp = new ftp_connection(null);
216
+			if (!isset($ftp)) {
217
+							$ftp = new ftp_connection(null);
218
+			}
206 219
 			// Save the error so we can mess with listing...
207
-			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error']))
208
-				$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
220
+			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) {
221
+							$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
222
+			}
209 223
 
210 224
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
211 225
 
212
-			if ($found_path || !isset($upcontext['chmod']['path']))
213
-				$upcontext['chmod']['path'] = $detect_path;
226
+			if ($found_path || !isset($upcontext['chmod']['path'])) {
227
+							$upcontext['chmod']['path'] = $detect_path;
228
+			}
214 229
 
215
-			if (!isset($upcontext['chmod']['username']))
216
-				$upcontext['chmod']['username'] = $username;
230
+			if (!isset($upcontext['chmod']['username'])) {
231
+							$upcontext['chmod']['username'] = $username;
232
+			}
217 233
 
218 234
 			// Don't forget the login token.
219 235
 			$upcontext += createToken('login');
220 236
 
221 237
 			return false;
222
-		}
223
-		else
238
+		} else
224 239
 		{
225 240
 			// We want to do a relative path for FTP.
226 241
 			if (!in_array($upcontext['chmod']['path'], array('', '/')))
227 242
 			{
228 243
 				$ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => ''));
229
-				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/'))
230
-					$ftp_root = substr($ftp_root, 0, -1);
244
+				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) {
245
+									$ftp_root = substr($ftp_root, 0, -1);
246
+				}
247
+			} else {
248
+							$ftp_root = $boarddir;
231 249
 			}
232
-			else
233
-				$ftp_root = $boarddir;
234 250
 
235 251
 			// Save the info for next time!
236 252
 			$_SESSION['installer_temp_ftp'] = array(
@@ -244,10 +260,12 @@  discard block
 block discarded – undo
244 260
 
245 261
 			foreach ($files as $k => $file)
246 262
 			{
247
-				if (!is_writable($file))
248
-					$ftp->chmod($file, 0755);
249
-				if (!is_writable($file))
250
-					$ftp->chmod($file, 0777);
263
+				if (!is_writable($file)) {
264
+									$ftp->chmod($file, 0755);
265
+				}
266
+				if (!is_writable($file)) {
267
+									$ftp->chmod($file, 0777);
268
+				}
251 269
 
252 270
 				// Assuming that didn't work calculate the path without the boarddir.
253 271
 				if (!is_writable($file))
@@ -256,19 +274,23 @@  discard block
 block discarded – undo
256 274
 					{
257 275
 						$ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => ''));
258 276
 						$ftp->chmod($ftp_file, 0755);
259
-						if (!is_writable($file))
260
-							$ftp->chmod($ftp_file, 0777);
277
+						if (!is_writable($file)) {
278
+													$ftp->chmod($ftp_file, 0777);
279
+						}
261 280
 						// Sometimes an extra slash can help...
262 281
 						$ftp_file = '/' . $ftp_file;
263
-						if (!is_writable($file))
264
-							$ftp->chmod($ftp_file, 0755);
265
-						if (!is_writable($file))
266
-							$ftp->chmod($ftp_file, 0777);
282
+						if (!is_writable($file)) {
283
+													$ftp->chmod($ftp_file, 0755);
284
+						}
285
+						if (!is_writable($file)) {
286
+													$ftp->chmod($ftp_file, 0777);
287
+						}
267 288
 					}
268 289
 				}
269 290
 
270
-				if (is_writable($file))
271
-					unset($files[$k]);
291
+				if (is_writable($file)) {
292
+									unset($files[$k]);
293
+				}
272 294
 			}
273 295
 
274 296
 			$ftp->close();
@@ -278,8 +300,9 @@  discard block
 block discarded – undo
278 300
 	// What remains?
279 301
 	$upcontext['chmod']['files'] = $files;
280 302
 
281
-	if (empty($files))
282
-		return true;
303
+	if (empty($files)) {
304
+			return true;
305
+	}
283 306
 
284 307
 	return false;
285 308
 }
@@ -293,12 +316,14 @@  discard block
 block discarded – undo
293 316
 function quickFileWritable($file)
294 317
 {
295 318
 	// Some files won't exist, try to address up front
296
-	if (!file_exists($file))
297
-		@touch($file);
319
+	if (!file_exists($file)) {
320
+			@touch($file);
321
+	}
298 322
 
299 323
 	// NOW do the writable check...
300
-	if (is_writable($file))
301
-		return true;
324
+	if (is_writable($file)) {
325
+			return true;
326
+	}
302 327
 
303 328
 	@chmod($file, 0755);
304 329
 
@@ -308,10 +333,11 @@  discard block
 block discarded – undo
308 333
 	foreach ($chmod_values as $val)
309 334
 	{
310 335
 		// If it's writable, break out of the loop
311
-		if (is_writable($file))
312
-			break;
313
-		else
314
-			@chmod($file, $val);
336
+		if (is_writable($file)) {
337
+					break;
338
+		} else {
339
+					@chmod($file, $val);
340
+		}
315 341
 	}
316 342
 
317 343
 	return is_writable($file);
@@ -338,14 +364,16 @@  discard block
 block discarded – undo
338 364
 {
339 365
 	static $fp = null;
340 366
 
341
-	if ($fp === null)
342
-		$fp = fopen('php://stderr', 'wb');
367
+	if ($fp === null) {
368
+			$fp = fopen('php://stderr', 'wb');
369
+	}
343 370
 
344 371
 	fwrite($fp, $message . "\n");
345 372
 
346
-	if ($fatal)
347
-		exit;
348
-}
373
+	if ($fatal) {
374
+			exit;
375
+	}
376
+	}
349 377
 
350 378
 /**
351 379
  * Throws a graphical error message.
Please login to merge, or discard this patch.
Sources/ManageSearchEngines.php 1 patch
Braces   +109 added lines, -77 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
  * Entry point for this section.
@@ -38,8 +39,7 @@  discard block
 block discarded – undo
38 39
 			'stats' => 'SpiderStats',
39 40
 		);
40 41
 		$default = 'stats';
41
-	}
42
-	else
42
+	} else
43 43
 	{
44 44
 		$subActions = array(
45 45
 			'settings' => 'ManageSearchEngineSettings',
@@ -90,11 +90,12 @@  discard block
 block discarded – undo
90 90
 		{
91 91
 			disabledState = document.getElementById(\'spider_mode\').value == 0;';
92 92
 
93
-	foreach ($config_vars as $variable)
94
-		if ($variable[1] != 'spider_mode')
93
+	foreach ($config_vars as $variable) {
94
+			if ($variable[1] != 'spider_mode')
95 95
 			$javascript_function .= '
96 96
 			if (document.getElementById(\'' . $variable[1] . '\'))
97 97
 				document.getElementById(\'' . $variable[1] . '\').disabled = disabledState;';
98
+	}
98 99
 
99 100
 	$javascript_function .= '
100 101
 		}
@@ -102,8 +103,9 @@  discard block
 block discarded – undo
102 103
 
103 104
 	call_integration_hook('integrate_modify_search_engine_settings', array(&$config_vars));
104 105
 
105
-	if ($return_config)
106
-		return $config_vars;
106
+	if ($return_config) {
107
+			return $config_vars;
108
+	}
107 109
 
108 110
 	// We need to load the groups for the spider group thingy.
109 111
 	$request = $smcFunc['db_query']('', '
@@ -116,13 +118,15 @@  discard block
 block discarded – undo
116 118
 			'moderator_group' => 3,
117 119
 		)
118 120
 	);
119
-	while ($row = $smcFunc['db_fetch_assoc']($request))
120
-		$config_vars['spider_group'][2][$row['id_group']] = $row['group_name'];
121
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
122
+			$config_vars['spider_group'][2][$row['id_group']] = $row['group_name'];
123
+	}
121 124
 	$smcFunc['db_free_result']($request);
122 125
 
123 126
 	// Make sure it's valid - note that regular members are given id_group = 1 which is reversed in Load.php - no admins here!
124
-	if (isset($_POST['spider_group']) && !isset($config_vars['spider_group'][2][$_POST['spider_group']]))
125
-		$_POST['spider_group'] = 0;
127
+	if (isset($_POST['spider_group']) && !isset($config_vars['spider_group'][2][$_POST['spider_group']])) {
128
+			$_POST['spider_group'] = 0;
129
+	}
126 130
 
127 131
 	// We'll want this for our easy save.
128 132
 	require_once($sourcedir . '/ManageServer.php');
@@ -166,8 +170,9 @@  discard block
 block discarded – undo
166 170
 	}
167 171
 
168 172
 	// Are we adding a new one?
169
-	if (!empty($_POST['addSpider']))
170
-		return EditSpider();
173
+	if (!empty($_POST['addSpider'])) {
174
+			return EditSpider();
175
+	}
171 176
 	// User pressed the 'remove selection button'.
172 177
 	elseif (!empty($_POST['removeSpiders']) && !empty($_POST['remove']) && is_array($_POST['remove']))
173 178
 	{
@@ -175,8 +180,9 @@  discard block
 block discarded – undo
175 180
 		validateToken('admin-ser');
176 181
 
177 182
 		// Make sure every entry is a proper integer.
178
-		foreach ($_POST['remove'] as $index => $spider_id)
179
-			$_POST['remove'][(int) $index] = (int) $spider_id;
183
+		foreach ($_POST['remove'] as $index => $spider_id) {
184
+					$_POST['remove'][(int) $index] = (int) $spider_id;
185
+		}
180 186
 
181 187
 		// Delete them all!
182 188
 		$smcFunc['db_query']('', '
@@ -215,8 +221,9 @@  discard block
 block discarded – undo
215 221
 	);
216 222
 
217 223
 	$context['spider_last_seen'] = array();
218
-	while ($row = $smcFunc['db_fetch_assoc']($request))
219
-		$context['spider_last_seen'][$row['id_spider']] = $row['last_seen_time'];
224
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
225
+			$context['spider_last_seen'][$row['id_spider']] = $row['last_seen_time'];
226
+	}
220 227
 	$smcFunc['db_free_result']($request);
221 228
 
222 229
 	createToken('admin-ser');
@@ -346,8 +353,9 @@  discard block
 block discarded – undo
346 353
 		)
347 354
 	);
348 355
 	$spiders = array();
349
-	while ($row = $smcFunc['db_fetch_assoc']($request))
350
-		$spiders[$row['id_spider']] = $row;
356
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
357
+			$spiders[$row['id_spider']] = $row;
358
+	}
351 359
 	$smcFunc['db_free_result']($request);
352 360
 
353 361
 	return $spiders;
@@ -397,14 +405,15 @@  discard block
 block discarded – undo
397 405
 		foreach ($ip_sets as $set)
398 406
 		{
399 407
 			$test = ip2range(trim($set));
400
-			if (!empty($test))
401
-				$ips[] = $set;
408
+			if (!empty($test)) {
409
+							$ips[] = $set;
410
+			}
402 411
 		}
403 412
 		$ips = implode(',', $ips);
404 413
 
405 414
 		// Goes in as it is...
406
-		if ($context['id_spider'])
407
-			$smcFunc['db_query']('', '
415
+		if ($context['id_spider']) {
416
+					$smcFunc['db_query']('', '
408 417
 				UPDATE {db_prefix}spiders
409 418
 				SET spider_name = {string:spider_name}, user_agent = {string:spider_agent},
410 419
 					ip_info = {string:ip_info}
@@ -416,8 +425,8 @@  discard block
 block discarded – undo
416 425
 					'ip_info' => $ips,
417 426
 				)
418 427
 			);
419
-		else
420
-			$smcFunc['db_insert']('insert',
428
+		} else {
429
+					$smcFunc['db_insert']('insert',
421 430
 				'{db_prefix}spiders',
422 431
 				array(
423 432
 					'spider_name' => 'string', 'user_agent' => 'string', 'ip_info' => 'string',
@@ -427,6 +436,7 @@  discard block
 block discarded – undo
427 436
 				),
428 437
 				array('id_spider')
429 438
 			);
439
+		}
430 440
 
431 441
 
432 442
 		cache_put_data('spider_search', null);
@@ -454,13 +464,14 @@  discard block
 block discarded – undo
454 464
 				'current_spider' => $context['id_spider'],
455 465
 			)
456 466
 		);
457
-		if ($row = $smcFunc['db_fetch_assoc']($request))
458
-			$context['spider'] = array(
467
+		if ($row = $smcFunc['db_fetch_assoc']($request)) {
468
+					$context['spider'] = array(
459 469
 				'id' => $row['id_spider'],
460 470
 				'name' => $row['spider_name'],
461 471
 				'agent' => $row['user_agent'],
462 472
 				'ip_info' => $row['ip_info'],
463 473
 			);
474
+		}
464 475
 		$smcFunc['db_free_result']($request);
465 476
 	}
466 477
 
@@ -477,8 +488,9 @@  discard block
 block discarded – undo
477 488
 {
478 489
 	global $modSettings, $smcFunc;
479 490
 
480
-	if (isset($_SESSION['id_robot']))
481
-		unset($_SESSION['id_robot']);
491
+	if (isset($_SESSION['id_robot'])) {
492
+			unset($_SESSION['id_robot']);
493
+	}
482 494
 	$_SESSION['robot_check'] = time();
483 495
 
484 496
 	// We cache the spider data for ten minutes if we can.
@@ -492,15 +504,17 @@  discard block
 block discarded – undo
492 504
 			)
493 505
 		);
494 506
 		$spider_data = array();
495
-		while ($row = $smcFunc['db_fetch_assoc']($request))
496
-			$spider_data[] = $row;
507
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
508
+					$spider_data[] = $row;
509
+		}
497 510
 		$smcFunc['db_free_result']($request);
498 511
 
499 512
 		cache_put_data('spider_search', $spider_data, 600);
500 513
 	}
501 514
 
502
-	if (empty($spider_data))
503
-		return false;
515
+	if (empty($spider_data)) {
516
+			return false;
517
+	}
504 518
 
505 519
 	// Only do these bits once.
506 520
 	$ci_user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
@@ -508,33 +522,38 @@  discard block
 block discarded – undo
508 522
 	foreach ($spider_data as $spider)
509 523
 	{
510 524
 		// User agent is easy.
511
-		if (!empty($spider['user_agent']) && strpos($ci_user_agent, strtolower($spider['user_agent'])) !== false)
512
-			$_SESSION['id_robot'] = $spider['id_spider'];
525
+		if (!empty($spider['user_agent']) && strpos($ci_user_agent, strtolower($spider['user_agent'])) !== false) {
526
+					$_SESSION['id_robot'] = $spider['id_spider'];
527
+		}
513 528
 		// IP stuff is harder.
514 529
 		elseif ($_SERVER['REMOTE_ADDR'])
515 530
 		{
516 531
 			$ips = explode(',', $spider['ip_info']);
517 532
 			foreach ($ips as $ip)
518 533
 			{
519
-				if ($ip === '')
520
-					continue;
534
+				if ($ip === '') {
535
+									continue;
536
+				}
521 537
 
522 538
 				$ip = ip2range($ip);
523 539
 				if (!empty($ip))
524 540
 				{
525
-					if (inet_ptod($ip['low']) <= inet_ptod($_SERVER['REMOTE_ADDR']) && inet_ptod($ip['high']) >= inet_ptod($_SERVER['REMOTE_ADDR']))
526
-						$_SESSION['id_robot'] = $spider['id_spider'];
541
+					if (inet_ptod($ip['low']) <= inet_ptod($_SERVER['REMOTE_ADDR']) && inet_ptod($ip['high']) >= inet_ptod($_SERVER['REMOTE_ADDR'])) {
542
+											$_SESSION['id_robot'] = $spider['id_spider'];
543
+					}
527 544
 				}
528 545
 			}
529 546
 		}
530 547
 
531
-		if (isset($_SESSION['id_robot']))
532
-			break;
548
+		if (isset($_SESSION['id_robot'])) {
549
+					break;
550
+		}
533 551
 	}
534 552
 
535 553
 	// If this is low server tracking then log the spider here as opposed to the main logging function.
536
-	if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] == 1 && !empty($_SESSION['id_robot']))
537
-		logSpider();
554
+	if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] == 1 && !empty($_SESSION['id_robot'])) {
555
+			logSpider();
556
+	}
538 557
 
539 558
 	return !empty($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
540 559
 }
@@ -548,8 +567,9 @@  discard block
 block discarded – undo
548 567
 {
549 568
 	global $smcFunc, $modSettings, $context;
550 569
 
551
-	if (empty($modSettings['spider_mode']) || empty($_SESSION['id_robot']))
552
-		return;
570
+	if (empty($modSettings['spider_mode']) || empty($_SESSION['id_robot'])) {
571
+			return;
572
+	}
553 573
 
554 574
 	// Attempt to update today's entry.
555 575
 	if ($modSettings['spider_mode'] == 1)
@@ -590,9 +610,9 @@  discard block
 block discarded – undo
590 610
 			$url = $_GET + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
591 611
 			unset($url['sesc'], $url[$context['session_var']]);
592 612
 			$url = $smcFunc['json_encode']($url);
613
+		} else {
614
+					$url = '';
593 615
 		}
594
-		else
595
-			$url = '';
596 616
 
597 617
 		$smcFunc['db_insert']('insert',
598 618
 			'{db_prefix}log_spider_hits',
@@ -620,12 +640,14 @@  discard block
 block discarded – undo
620 640
 		)
621 641
 	);
622 642
 	$spider_hits = array();
623
-	while ($row = $smcFunc['db_fetch_assoc']($request))
624
-		$spider_hits[] = $row;
643
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
644
+			$spider_hits[] = $row;
645
+	}
625 646
 	$smcFunc['db_free_result']($request);
626 647
 
627
-	if (empty($spider_hits))
628
-		return;
648
+	if (empty($spider_hits)) {
649
+			return;
650
+	}
629 651
 
630 652
 	// Attempt to update the master data.
631 653
 	$stat_inserts = array();
@@ -646,18 +668,20 @@  discard block
 block discarded – undo
646 668
 				'hits' => $stat['num_hits'],
647 669
 			)
648 670
 		);
649
-		if ($smcFunc['db_affected_rows']() == 0)
650
-			$stat_inserts[] = array($date, $stat['id_spider'], $stat['num_hits'], $stat['last_seen']);
671
+		if ($smcFunc['db_affected_rows']() == 0) {
672
+					$stat_inserts[] = array($date, $stat['id_spider'], $stat['num_hits'], $stat['last_seen']);
673
+		}
651 674
 	}
652 675
 
653 676
 	// New stats?
654
-	if (!empty($stat_inserts))
655
-		$smcFunc['db_insert']('ignore',
677
+	if (!empty($stat_inserts)) {
678
+			$smcFunc['db_insert']('ignore',
656 679
 			'{db_prefix}log_spider_stats',
657 680
 			array('stat_date' => 'date', 'id_spider' => 'int', 'page_hits' => 'int', 'last_seen' => 'int'),
658 681
 			$stat_inserts,
659 682
 			array('stat_date', 'id_spider')
660 683
 		);
684
+	}
661 685
 
662 686
 	// All processed.
663 687
 	$smcFunc['db_query']('', '
@@ -700,8 +724,7 @@  discard block
 block discarded – undo
700 724
 					'delete_period' => $deleteTime,
701 725
 				)
702 726
 			);
703
-		}
704
-		else
727
+		} else
705 728
 		{
706 729
 			// Deleting all of them
707 730
 			$smcFunc['db_query']('', '
@@ -791,10 +814,11 @@  discard block
 block discarded – undo
791 814
 		foreach ($context['spider_logs']['rows'] as $k => $row)
792 815
 		{
793 816
 			// Feature disabled?
794
-			if (empty($row['data']['viewing']['value']) && isset($modSettings['spider_mode']) && $modSettings['spider_mode'] < 3)
795
-				$context['spider_logs']['rows'][$k]['viewing']['value'] = '<em>' . $txt['spider_disabled'] . '</em>';
796
-			else
797
-				$urls[$k] = array($row['data']['viewing']['value'], -1);
817
+			if (empty($row['data']['viewing']['value']) && isset($modSettings['spider_mode']) && $modSettings['spider_mode'] < 3) {
818
+							$context['spider_logs']['rows'][$k]['viewing']['value'] = '<em>' . $txt['spider_disabled'] . '</em>';
819
+			} else {
820
+							$urls[$k] = array($row['data']['viewing']['value'], -1);
821
+			}
798 822
 		}
799 823
 
800 824
 		// Now stick in the new URLs.
@@ -836,8 +860,9 @@  discard block
 block discarded – undo
836 860
 		)
837 861
 	);
838 862
 	$spider_logs = array();
839
-	while ($row = $smcFunc['db_fetch_assoc']($request))
840
-		$spider_logs[] = $row;
863
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
864
+			$spider_logs[] = $row;
865
+	}
841 866
 	$smcFunc['db_free_result']($request);
842 867
 
843 868
 	return $spider_logs;
@@ -913,14 +938,18 @@  discard block
 block discarded – undo
913 938
 
914 939
 	// Prepare the dates for the drop down.
915 940
 	$date_choices = array();
916
-	for ($y = $min_year; $y <= $max_year; $y++)
917
-		for ($m = 1; $m <= 12; $m++)
941
+	for ($y = $min_year; $y <= $max_year; $y++) {
942
+			for ($m = 1;
943
+	}
944
+	$m <= 12; $m++)
918 945
 		{
919 946
 			// This doesn't count?
920
-			if ($y == $min_year && $m < $min_month)
921
-				continue;
922
-			if ($y == $max_year && $m > $max_month)
923
-				break;
947
+			if ($y == $min_year && $m < $min_month) {
948
+							continue;
949
+			}
950
+			if ($y == $max_year && $m > $max_month) {
951
+							break;
952
+			}
924 953
 
925 954
 			$date_choices[$y . $m] = $txt['months_short'][$m] . ' ' . $y;
926 955
 		}
@@ -933,13 +962,14 @@  discard block
 block discarded – undo
933 962
 		' . $txt['spider_stats_select_month'] . ':
934 963
 		<select name="new_date" onchange="document.spider_stat_list.submit();">';
935 964
 
936
-	if (empty($date_choices))
937
-		$date_select .= '
965
+	if (empty($date_choices)) {
966
+			$date_select .= '
938 967
 			<option></option>';
939
-	else
940
-		foreach ($date_choices as $id => $text)
968
+	} else {
969
+			foreach ($date_choices as $id => $text)
941 970
 			$date_select .= '
942 971
 			<option value="' . $id . '"' . ($current_date == $id ? ' selected' : '') . '>' . $text . '</option>';
972
+	}
943 973
 
944 974
 	$date_select .= '
945 975
 		</select>
@@ -1063,8 +1093,9 @@  discard block
 block discarded – undo
1063 1093
 		)
1064 1094
 	);
1065 1095
 	$spider_stats = array();
1066
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1067
-		$spider_stats[] = $row;
1096
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1097
+			$spider_stats[] = $row;
1098
+	}
1068 1099
 	$smcFunc['db_free_result']($request);
1069 1100
 
1070 1101
 	return $spider_stats;
@@ -1105,8 +1136,9 @@  discard block
 block discarded – undo
1105 1136
 		array()
1106 1137
 	);
1107 1138
 	$spiders = array();
1108
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1109
-		$spiders[$row['id_spider']] = $row['spider_name'];
1139
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1140
+			$spiders[$row['id_spider']] = $row['spider_name'];
1141
+	}
1110 1142
 	$smcFunc['db_free_result']($request);
1111 1143
 
1112 1144
 	updateSettings(array('spider_name_cache' => $smcFunc['json_encode']($spiders)));
Please login to merge, or discard this patch.
Sources/Who.php 2 patches
Braces   +126 added lines, -95 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
  * Who's online, and what are they doing?
@@ -35,8 +36,9 @@  discard block
 block discarded – undo
35 36
 	isAllowedTo('who_view');
36 37
 
37 38
 	// You can't do anything if this is off.
38
-	if (empty($modSettings['who_enabled']))
39
-		fatal_lang_error('who_off', false);
39
+	if (empty($modSettings['who_enabled'])) {
40
+			fatal_lang_error('who_off', false);
41
+	}
40 42
 
41 43
 	// Load the 'Who' template.
42 44
 	loadTemplate('Who');
@@ -71,9 +73,9 @@  discard block
 block discarded – undo
71 73
 		$show_methods['spiders'] = '(lo.id_member = 0 AND lo.id_spider > 0)';
72 74
 		$show_methods['guests'] = '(lo.id_member = 0 AND lo.id_spider = 0)';
73 75
 		$context['show_methods']['spiders'] = $txt['who_show_spiders_only'];
76
+	} elseif (empty($modSettings['show_spider_online']) && isset($_SESSION['who_online_filter']) && $_SESSION['who_online_filter'] == 'spiders') {
77
+			unset($_SESSION['who_online_filter']);
74 78
 	}
75
-	elseif (empty($modSettings['show_spider_online']) && isset($_SESSION['who_online_filter']) && $_SESSION['who_online_filter'] == 'spiders')
76
-		unset($_SESSION['who_online_filter']);
77 79
 
78 80
 	// Does the user prefer a different sort direction?
79 81
 	if (isset($_REQUEST['sort']) && isset($sort_methods[$_REQUEST['sort']]))
@@ -97,20 +99,24 @@  discard block
 block discarded – undo
97 99
 	$context['sort_direction'] = isset($_REQUEST['asc']) || (isset($_REQUEST['sort_dir']) && $_REQUEST['sort_dir'] == 'asc') ? 'up' : 'down';
98 100
 
99 101
 	$conditions = array();
100
-	if (!allowedTo('moderate_forum'))
101
-		$conditions[] = '(COALESCE(mem.show_online, 1) = 1)';
102
+	if (!allowedTo('moderate_forum')) {
103
+			$conditions[] = '(COALESCE(mem.show_online, 1) = 1)';
104
+	}
102 105
 
103 106
 	// Fallback to top filter?
104
-	if (isset($_REQUEST['submit_top']) && isset($_REQUEST['show_top']))
105
-		$_REQUEST['show'] = $_REQUEST['show_top'];
107
+	if (isset($_REQUEST['submit_top']) && isset($_REQUEST['show_top'])) {
108
+			$_REQUEST['show'] = $_REQUEST['show_top'];
109
+	}
106 110
 	// Does the user wish to apply a filter?
107
-	if (isset($_REQUEST['show']) && isset($show_methods[$_REQUEST['show']]))
108
-		$context['show_by'] = $_SESSION['who_online_filter'] = $_REQUEST['show'];
111
+	if (isset($_REQUEST['show']) && isset($show_methods[$_REQUEST['show']])) {
112
+			$context['show_by'] = $_SESSION['who_online_filter'] = $_REQUEST['show'];
113
+	}
109 114
 	// Perhaps we saved a filter earlier in the session?
110
-	elseif (isset($_SESSION['who_online_filter']))
111
-		$context['show_by'] = $_SESSION['who_online_filter'];
112
-	else
113
-		$context['show_by'] = 'members';
115
+	elseif (isset($_SESSION['who_online_filter'])) {
116
+			$context['show_by'] = $_SESSION['who_online_filter'];
117
+	} else {
118
+			$context['show_by'] = 'members';
119
+	}
114 120
 
115 121
 	$conditions[] = $show_methods[$context['show_by']];
116 122
 
@@ -156,8 +162,9 @@  discard block
 block discarded – undo
156 162
 	while ($row = $smcFunc['db_fetch_assoc']($request))
157 163
 	{
158 164
 		$actions = $smcFunc['json_decode']($row['url'], true);
159
-		if ($actions === false)
160
-			continue;
165
+		if ($actions === false) {
166
+					continue;
167
+		}
161 168
 
162 169
 		// Send the information to the template.
163 170
 		$context['members'][$row['session']] = array(
@@ -195,8 +202,8 @@  discard block
 block discarded – undo
195 202
 	$spiderContext = array();
196 203
 	if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] == 2 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache']))
197 204
 	{
198
-		foreach ($smcFunc['json_decode']($modSettings['spider_name_cache'], true) as $id => $name)
199
-			$spiderContext[$id] = array(
205
+		foreach ($smcFunc['json_decode']($modSettings['spider_name_cache'], true) as $id => $name) {
206
+					$spiderContext[$id] = array(
200 207
 				'id' => 0,
201 208
 				'name' => $name,
202 209
 				'group' => $txt['spiders'],
@@ -205,6 +212,7 @@  discard block
 block discarded – undo
205 212
 				'email' => $name,
206 213
 				'is_guest' => true
207 214
 			);
215
+		}
208 216
 	}
209 217
 
210 218
 	$url_data = determineActions($url_data);
@@ -219,16 +227,18 @@  discard block
 block discarded – undo
219 227
 	// Put it in the context variables.
220 228
 	foreach ($context['members'] as $i => $member)
221 229
 	{
222
-		if ($member['id'] != 0)
223
-			$member['id'] = loadMemberContext($member['id']) ? $member['id'] : 0;
230
+		if ($member['id'] != 0) {
231
+					$member['id'] = loadMemberContext($member['id']) ? $member['id'] : 0;
232
+		}
224 233
 
225 234
 		// Keep the IP that came from the database.
226 235
 		$memberContext[$member['id']]['ip'] = $member['ip'];
227 236
 		$context['members'][$i]['action'] = isset($url_data[$i]) ? $url_data[$i] : $txt['who_hidden'];
228
-		if ($member['id'] == 0 && isset($spiderContext[$member['id_spider']]))
229
-			$context['members'][$i] += $spiderContext[$member['id_spider']];
230
-		else
231
-			$context['members'][$i] += $memberContext[$member['id']];
237
+		if ($member['id'] == 0 && isset($spiderContext[$member['id_spider']])) {
238
+					$context['members'][$i] += $spiderContext[$member['id_spider']];
239
+		} else {
240
+					$context['members'][$i] += $memberContext[$member['id']];
241
+		}
232 242
 	}
233 243
 
234 244
 	// Some people can't send personal messages...
@@ -263,8 +273,9 @@  discard block
 block discarded – undo
263 273
 {
264 274
 	global $txt, $user_info, $modSettings, $smcFunc;
265 275
 
266
-	if (!allowedTo('who_view'))
267
-		return array();
276
+	if (!allowedTo('who_view')) {
277
+			return array();
278
+	}
268 279
 	loadLanguage('Who');
269 280
 
270 281
 	// Actions that require a specific permission level.
@@ -292,10 +303,11 @@  discard block
 block discarded – undo
292 303
 	);
293 304
 	call_integration_hook('who_allowed', array(&$allowedActions));
294 305
 
295
-	if (!is_array($urls))
296
-		$url_list = array(array($urls, $user_info['id']));
297
-	else
298
-		$url_list = $urls;
306
+	if (!is_array($urls)) {
307
+			$url_list = array(array($urls, $user_info['id']));
308
+	} else {
309
+			$url_list = $urls;
310
+	}
299 311
 
300 312
 	// These are done to later query these in large chunks. (instead of one by one.)
301 313
 	$topic_ids = array();
@@ -307,12 +319,14 @@  discard block
 block discarded – undo
307 319
 	{
308 320
 		// Get the request parameters..
309 321
 		$actions = $smcFunc['json_decode']($url[0], true);
310
-		if ($actions === false)
311
-			continue;
322
+		if ($actions === false) {
323
+					continue;
324
+		}
312 325
 
313 326
 		// If it's the admin or moderation center, and there is an area set, use that instead.
314
-		if (isset($actions['action']) && ($actions['action'] == 'admin' || $actions['action'] == 'moderate') && isset($actions['area']))
315
-			$actions['action'] = $actions['area'];
327
+		if (isset($actions['action']) && ($actions['action'] == 'admin' || $actions['action'] == 'moderate') && isset($actions['area'])) {
328
+					$actions['action'] = $actions['area'];
329
+		}
316 330
 
317 331
 		// Check if there was no action or the action is display.
318 332
 		if (!isset($actions['action']) || $actions['action'] == 'display')
@@ -332,12 +346,14 @@  discard block
 block discarded – undo
332 346
 				$board_ids[$actions['board']][$k] = $txt['who_board'];
333 347
 			}
334 348
 			// It's the board index!!  It must be!
335
-			else
336
-				$data[$k] = $txt['who_index'];
349
+			else {
350
+							$data[$k] = $txt['who_index'];
351
+			}
337 352
 		}
338 353
 		// Probably an error or some goon?
339
-		elseif ($actions['action'] == '')
340
-			$data[$k] = $txt['who_index'];
354
+		elseif ($actions['action'] == '') {
355
+					$data[$k] = $txt['who_index'];
356
+		}
341 357
 		// Some other normal action...?
342 358
 		else
343 359
 		{
@@ -345,23 +361,25 @@  discard block
 block discarded – undo
345 361
 			if ($actions['action'] == 'profile')
346 362
 			{
347 363
 				// Whose?  Their own?
348
-				if (empty($actions['u']))
349
-					$actions['u'] = $url[1];
364
+				if (empty($actions['u'])) {
365
+									$actions['u'] = $url[1];
366
+				}
350 367
 
351 368
 				$data[$k] = $txt['who_hidden'];
352 369
 				$profile_ids[(int) $actions['u']][$k] = $actions['u'] == $url[1] ? $txt['who_viewownprofile'] : $txt['who_viewprofile'];
353
-			}
354
-			elseif (($actions['action'] == 'post' || $actions['action'] == 'post2') && empty($actions['topic']) && isset($actions['board']))
370
+			} elseif (($actions['action'] == 'post' || $actions['action'] == 'post2') && empty($actions['topic']) && isset($actions['board']))
355 371
 			{
356 372
 				$data[$k] = $txt['who_hidden'];
357 373
 				$board_ids[(int) $actions['board']][$k] = isset($actions['poll']) ? $txt['who_poll'] : $txt['who_post'];
358 374
 			}
359 375
 			// A subaction anyone can view... if the language string is there, show it.
360
-			elseif (isset($actions['sa']) && isset($txt['whoall_' . $actions['action'] . '_' . $actions['sa']]))
361
-				$data[$k] = $preferred_prefix && isset($txt[$preferred_prefix . $actions['action'] . '_' . $actions['sa']]) ? $txt[$preferred_prefix . $actions['action'] . '_' . $actions['sa']] : $txt['whoall_' . $actions['action'] . '_' . $actions['sa']];
376
+			elseif (isset($actions['sa']) && isset($txt['whoall_' . $actions['action'] . '_' . $actions['sa']])) {
377
+							$data[$k] = $preferred_prefix && isset($txt[$preferred_prefix . $actions['action'] . '_' . $actions['sa']]) ? $txt[$preferred_prefix . $actions['action'] . '_' . $actions['sa']] : $txt['whoall_' . $actions['action'] . '_' . $actions['sa']];
378
+			}
362 379
 			// An action any old fellow can look at. (if ['whoall_' . $action] exists, we know everyone can see it.)
363
-			elseif (isset($txt['whoall_' . $actions['action']]))
364
-				$data[$k] = $preferred_prefix && isset($txt[$preferred_prefix . $actions['action']]) ? $txt[$preferred_prefix . $actions['action']] : $txt['whoall_' . $actions['action']];
380
+			elseif (isset($txt['whoall_' . $actions['action']])) {
381
+							$data[$k] = $preferred_prefix && isset($txt[$preferred_prefix . $actions['action']]) ? $txt[$preferred_prefix . $actions['action']] : $txt['whoall_' . $actions['action']];
382
+			}
365 383
 			// Viewable if and only if they can see the board...
366 384
 			elseif (isset($txt['whotopic_' . $actions['action']]))
367 385
 			{
@@ -370,8 +388,7 @@  discard block
 block discarded – undo
370 388
 
371 389
 				$data[$k] = $txt['who_hidden'];
372 390
 				$topic_ids[$topic][$k] = $txt['whotopic_' . $actions['action']];
373
-			}
374
-			elseif (isset($txt['whopost_' . $actions['action']]))
391
+			} elseif (isset($txt['whopost_' . $actions['action']]))
375 392
 			{
376 393
 				// Find out what message they are accessing.
377 394
 				$msgid = (int) (isset($actions['msg']) ? $actions['msg'] : (isset($actions['quote']) ? $actions['quote'] : 0));
@@ -394,41 +411,46 @@  discard block
 block discarded – undo
394 411
 				$data[$k] = sprintf($txt['whopost_' . $actions['action']], $id_topic, $subject);
395 412
 				$smcFunc['db_free_result']($result);
396 413
 
397
-				if (empty($id_topic))
398
-					$data[$k] = $txt['who_hidden'];
414
+				if (empty($id_topic)) {
415
+									$data[$k] = $txt['who_hidden'];
416
+				}
399 417
 			}
400 418
 			// Viewable only by administrators.. (if it starts with whoadmin, it's admin only!)
401
-			elseif (allowedTo('moderate_forum') && isset($txt['whoadmin_' . $actions['action']]))
402
-				$data[$k] = $txt['whoadmin_' . $actions['action']];
419
+			elseif (allowedTo('moderate_forum') && isset($txt['whoadmin_' . $actions['action']])) {
420
+							$data[$k] = $txt['whoadmin_' . $actions['action']];
421
+			}
403 422
 			// Viewable by permission level.
404 423
 			elseif (isset($allowedActions[$actions['action']]))
405 424
 			{
406
-				if (allowedTo($allowedActions[$actions['action']]))
407
-					$data[$k] = $txt['whoallow_' . $actions['action']];
408
-				elseif (in_array('moderate_forum', $allowedActions[$actions['action']]))
409
-					$data[$k] = $txt['who_moderate'];
410
-				elseif (in_array('admin_forum', $allowedActions[$actions['action']]))
411
-					$data[$k] = $txt['who_admin'];
412
-				else
413
-					$data[$k] = $txt['who_hidden'];
425
+				if (allowedTo($allowedActions[$actions['action']])) {
426
+									$data[$k] = $txt['whoallow_' . $actions['action']];
427
+				} elseif (in_array('moderate_forum', $allowedActions[$actions['action']])) {
428
+									$data[$k] = $txt['who_moderate'];
429
+				} elseif (in_array('admin_forum', $allowedActions[$actions['action']])) {
430
+									$data[$k] = $txt['who_admin'];
431
+				} else {
432
+									$data[$k] = $txt['who_hidden'];
433
+				}
434
+			} elseif (!empty($actions['action'])) {
435
+							$data[$k] = $txt['who_generic'] . ' ' . $actions['action'];
436
+			} else {
437
+							$data[$k] = $txt['who_unknown'];
414 438
 			}
415
-			elseif (!empty($actions['action']))
416
-				$data[$k] = $txt['who_generic'] . ' ' . $actions['action'];
417
-			else
418
-				$data[$k] = $txt['who_unknown'];
419 439
 		}
420 440
 
421 441
 		if (isset($actions['error']))
422 442
 		{
423
-			if (isset($txt[$actions['error']]))
424
-				$error_message = str_replace('"', '&quot;', empty($actions['who_error_params']) ? $txt[$actions['error']] : vsprintf($txt[$actions['error']], $actions['who_error_params']));
425
-			elseif ($actions['error'] == 'guest_login')
426
-				$error_message = str_replace('"', '&quot;', $txt['who_guest_login']);
427
-			else
428
-				$error_message = str_replace('"', '&quot;', $actions['error']);
429
-
430
-			if (!empty($error_message))
431
-				$data[$k] .= ' <span class="generic_icons error" title="' . $error_message . '"></span>';
443
+			if (isset($txt[$actions['error']])) {
444
+							$error_message = str_replace('"', '&quot;', empty($actions['who_error_params']) ? $txt[$actions['error']] : vsprintf($txt[$actions['error']], $actions['who_error_params']));
445
+			} elseif ($actions['error'] == 'guest_login') {
446
+							$error_message = str_replace('"', '&quot;', $txt['who_guest_login']);
447
+			} else {
448
+							$error_message = str_replace('"', '&quot;', $actions['error']);
449
+			}
450
+
451
+			if (!empty($error_message)) {
452
+							$data[$k] .= ' <span class="generic_icons error" title="' . $error_message . '"></span>';
453
+			}
432 454
 		}
433 455
 
434 456
 		// Maybe the action is integrated into another system?
@@ -439,12 +461,15 @@  discard block
 block discarded – undo
439 461
 				if (!empty($integrate_action))
440 462
 				{
441 463
 					$data[$k] = $integrate_action;
442
-					if (isset($actions['topic']) && isset($topic_ids[(int) $actions['topic']][$k]))
443
-						$topic_ids[(int) $actions['topic']][$k] = $integrate_action;
444
-					if (isset($actions['board']) && isset($board_ids[(int) $actions['board']][$k]))
445
-						$board_ids[(int) $actions['board']][$k] = $integrate_action;
446
-					if (isset($actions['u']) && isset($profile_ids[(int) $actions['u']][$k]))
447
-						$profile_ids[(int) $actions['u']][$k] = $integrate_action;
464
+					if (isset($actions['topic']) && isset($topic_ids[(int) $actions['topic']][$k])) {
465
+											$topic_ids[(int) $actions['topic']][$k] = $integrate_action;
466
+					}
467
+					if (isset($actions['board']) && isset($board_ids[(int) $actions['board']][$k])) {
468
+											$board_ids[(int) $actions['board']][$k] = $integrate_action;
469
+					}
470
+					if (isset($actions['u']) && isset($profile_ids[(int) $actions['u']][$k])) {
471
+											$profile_ids[(int) $actions['u']][$k] = $integrate_action;
472
+					}
448 473
 					break;
449 474
 				}
450 475
 			}
@@ -472,8 +497,9 @@  discard block
 block discarded – undo
472 497
 		while ($row = $smcFunc['db_fetch_assoc']($result))
473 498
 		{
474 499
 			// Show the topic's subject for each of the actions.
475
-			foreach ($topic_ids[$row['id_topic']] as $k => $session_text)
476
-				$data[$k] = sprintf($session_text, $row['id_topic'], censorText($row['subject']));
500
+			foreach ($topic_ids[$row['id_topic']] as $k => $session_text) {
501
+							$data[$k] = sprintf($session_text, $row['id_topic'], censorText($row['subject']));
502
+			}
477 503
 		}
478 504
 		$smcFunc['db_free_result']($result);
479 505
 	}
@@ -495,8 +521,9 @@  discard block
 block discarded – undo
495 521
 		while ($row = $smcFunc['db_fetch_assoc']($result))
496 522
 		{
497 523
 			// Put the board name into the string for each member...
498
-			foreach ($board_ids[$row['id_board']] as $k => $session_text)
499
-				$data[$k] = sprintf($session_text, $row['id_board'], $row['name']);
524
+			foreach ($board_ids[$row['id_board']] as $k => $session_text) {
525
+							$data[$k] = sprintf($session_text, $row['id_board'], $row['name']);
526
+			}
500 527
 		}
501 528
 		$smcFunc['db_free_result']($result);
502 529
 	}
@@ -518,23 +545,26 @@  discard block
 block discarded – undo
518 545
 		while ($row = $smcFunc['db_fetch_assoc']($result))
519 546
 		{
520 547
 			// If they aren't allowed to view this person's profile, skip it.
521
-			if (!$allow_view_any && ($user_info['id'] != $row['id_member']))
522
-				continue;
548
+			if (!$allow_view_any && ($user_info['id'] != $row['id_member'])) {
549
+							continue;
550
+			}
523 551
 
524 552
 			// Set their action on each - session/text to sprintf.
525
-			foreach ($profile_ids[$row['id_member']] as $k => $session_text)
526
-				$data[$k] = sprintf($session_text, $row['id_member'], $row['real_name']);
553
+			foreach ($profile_ids[$row['id_member']] as $k => $session_text) {
554
+							$data[$k] = sprintf($session_text, $row['id_member'], $row['real_name']);
555
+			}
527 556
 		}
528 557
 		$smcFunc['db_free_result']($result);
529 558
 	}
530 559
 
531 560
 	call_integration_hook('whos_online_after', array(&$urls, &$data));
532 561
 
533
-	if (!is_array($urls))
534
-		return isset($data[0]) ? $data[0] : false;
535
-	else
536
-		return $data;
537
-}
562
+	if (!is_array($urls)) {
563
+			return isset($data[0]) ? $data[0] : false;
564
+	} else {
565
+			return $data;
566
+	}
567
+	}
538 568
 
539 569
 /**
540 570
  * It prepares credit and copyright information for the credits page or the admin page
@@ -710,8 +740,8 @@  discard block
 block discarded – undo
710 740
 	);
711 741
 
712 742
 	// Give the translators some credit for their hard work.
713
-	if (!empty($txt['translation_credits']))
714
-		$context['credits'][] = array(
743
+	if (!empty($txt['translation_credits'])) {
744
+			$context['credits'][] = array(
715 745
 			'title' => $txt['credits_groups_translation'],
716 746
 			'groups' => array(
717 747
 				array(
@@ -720,6 +750,7 @@  discard block
 block discarded – undo
720 750
 				),
721 751
 			),
722 752
 		);
753
+	}
723 754
 
724 755
 	$context['credits'][] = array(
725 756
 		'title' => $txt['credits_special'],
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 						'Jessica "Suki" Gonz&aacute;lez',
593 593
 						'Karl "RegularExpression" Benson',
594 594
 						'Matthew "Labradoodle-360" Kerle',
595
-						$user_info['is_admin'] ? 'Matt "Grudge" Wolf': 'Grudge',
595
+						$user_info['is_admin'] ? 'Matt "Grudge" Wolf' : 'Grudge',
596 596
 						'Michael "Thantos" Miller',
597 597
 						'Norv',
598 598
 						'Peter "Arantor" Spicer',
@@ -824,13 +824,13 @@  discard block
 block discarded – undo
824 824
 			$credit_info = $smcFunc['json_decode']($row['credits'], true);
825 825
 
826 826
 			$copyright = empty($credit_info['copyright']) ? '' : $txt['credits_copyright'] . ' &copy; ' . $smcFunc['htmlspecialchars']($credit_info['copyright']);
827
-			$license = empty($credit_info['license']) ? '' : $txt['credits_license'] . ': ' . (!empty($credit_info['licenseurl']) ? '<a href="'. $smcFunc['htmlspecialchars']($credit_info['licenseurl']) .'">'. $smcFunc['htmlspecialchars']($credit_info['license']) .'</a>' : $smcFunc['htmlspecialchars']($credit_info['license']));
827
+			$license = empty($credit_info['license']) ? '' : $txt['credits_license'] . ': ' . (!empty($credit_info['licenseurl']) ? '<a href="' . $smcFunc['htmlspecialchars']($credit_info['licenseurl']) . '">' . $smcFunc['htmlspecialchars']($credit_info['license']) . '</a>' : $smcFunc['htmlspecialchars']($credit_info['license']));
828 828
 			$version = $txt['credits_version'] . ' ' . $row['version'];
829 829
 			$title = (empty($credit_info['title']) ? $row['name'] : $smcFunc['htmlspecialchars']($credit_info['title'])) . ': ' . $version;
830 830
 
831 831
 			// build this one out and stash it away
832 832
 			$mod_name = empty($credit_info['url']) ? $title : '<a href="' . $credit_info['url'] . '">' . $title . '</a>';
833
-			$mods[] = $mod_name . (!empty($license) ? ' | ' . $license  : '') . (!empty($copyright) ? ' | ' . $copyright  : '');
833
+			$mods[] = $mod_name . (!empty($license) ? ' | ' . $license : '') . (!empty($copyright) ? ' | ' . $copyright : '');
834 834
 		}
835 835
 		cache_put_data('mods_credits', $mods, 86400);
836 836
 	}
Please login to merge, or discard this patch.
Sources/Drafts.php 2 patches
Braces   +75 added lines, -53 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
 loadLanguage('Drafts');
21 22
 
@@ -33,8 +34,9 @@  discard block
 block discarded – undo
33 34
 	global $context, $user_info, $smcFunc, $modSettings, $board;
34 35
 
35 36
 	// can you be, should you be ... here?
36
-	if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft']))
37
-		return false;
37
+	if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) {
38
+			return false;
39
+	}
38 40
 
39 41
 	// read in what they sent us, if anything
40 42
 	$id_draft = (int) $_POST['id_draft'];
@@ -46,14 +48,16 @@  discard block
 block discarded – undo
46 48
 		$context['draft_saved_on'] = $draft_info['poster_time'];
47 49
 
48 50
 		// since we were called from the autosave function, send something back
49
-		if (!empty($id_draft))
50
-			XmlDraft($id_draft);
51
+		if (!empty($id_draft)) {
52
+					XmlDraft($id_draft);
53
+		}
51 54
 
52 55
 		return true;
53 56
 	}
54 57
 
55
-	if (!isset($_POST['message']))
56
-		$_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : '';
58
+	if (!isset($_POST['message'])) {
59
+			$_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : '';
60
+	}
57 61
 
58 62
 	// prepare any data from the form
59 63
 	$topic_id = empty($_REQUEST['topic']) ? 0 : (int) $_REQUEST['topic'];
@@ -66,8 +70,9 @@  discard block
 block discarded – undo
66 70
 
67 71
 	// message and subject still need a bit more work
68 72
 	preparsecode($draft['body']);
69
-	if ($smcFunc['strlen']($draft['subject']) > 100)
70
-		$draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100);
73
+	if ($smcFunc['strlen']($draft['subject']) > 100) {
74
+			$draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100);
75
+	}
71 76
 
72 77
 	// Modifying an existing draft, like hitting the save draft button or autosave enabled?
73 78
 	if (!empty($id_draft) && !empty($draft_info))
@@ -148,9 +153,9 @@  discard block
 block discarded – undo
148 153
 		{
149 154
 			$context['draft_saved'] = true;
150 155
 			$context['id_draft'] = $id_draft;
156
+		} else {
157
+					$post_errors[] = 'draft_not_saved';
151 158
 		}
152
-		else
153
-			$post_errors[] = 'draft_not_saved';
154 159
 
155 160
 		// cleanup
156 161
 		unset($_POST['save_draft']);
@@ -180,8 +185,9 @@  discard block
 block discarded – undo
180 185
 	global $context, $user_info, $smcFunc, $modSettings;
181 186
 
182 187
 	// PM survey says ... can you stay or must you go
183
-	if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft']))
184
-		return false;
188
+	if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) {
189
+			return false;
190
+	}
185 191
 
186 192
 	// read in what you sent us
187 193
 	$id_pm_draft = (int) $_POST['id_pm_draft'];
@@ -193,8 +199,9 @@  discard block
 block discarded – undo
193 199
 		$context['draft_saved_on'] = $draft_info['poster_time'];
194 200
 
195 201
 		// Send something back to the javascript caller
196
-		if (!empty($id_draft))
197
-			XmlDraft($id_draft);
202
+		if (!empty($id_draft)) {
203
+					XmlDraft($id_draft);
204
+		}
198 205
 
199 206
 		return true;
200 207
 	}
@@ -204,9 +211,9 @@  discard block
 block discarded – undo
204 211
 	{
205 212
 		$recipientList['to'] = isset($_POST['recipient_to']) ? explode(',', $_POST['recipient_to']) : array();
206 213
 		$recipientList['bcc'] = isset($_POST['recipient_bcc']) ? explode(',', $_POST['recipient_bcc']) : array();
214
+	} elseif (!empty($draft_info['to_list']) && empty($recipientList)) {
215
+			$recipientList = $smcFunc['json_decode']($draft_info['to_list'], true);
207 216
 	}
208
-	elseif (!empty($draft_info['to_list']) && empty($recipientList))
209
-		$recipientList = $smcFunc['json_decode']($draft_info['to_list'], true);
210 217
 
211 218
 	// prepare the data we got from the form
212 219
 	$reply_id = empty($_POST['replied_to']) ? 0 : (int) $_POST['replied_to'];
@@ -215,8 +222,9 @@  discard block
 block discarded – undo
215 222
 
216 223
 	// message and subject always need a bit more work
217 224
 	preparsecode($draft['body']);
218
-	if ($smcFunc['strlen']($draft['subject']) > 100)
219
-		$draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100);
225
+	if ($smcFunc['strlen']($draft['subject']) > 100) {
226
+			$draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100);
227
+	}
220 228
 
221 229
 	// Modifying an existing PM draft?
222 230
 	if (!empty($id_pm_draft) && !empty($draft_info))
@@ -280,9 +288,9 @@  discard block
 block discarded – undo
280 288
 		{
281 289
 			$context['draft_saved'] = true;
282 290
 			$context['id_pm_draft'] = $id_pm_draft;
291
+		} else {
292
+					$post_errors[] = 'draft_not_saved';
283 293
 		}
284
-		else
285
-			$post_errors[] = 'draft_not_saved';
286 294
 	}
287 295
 
288 296
 	// if we were called from the autosave function, send something back
@@ -315,8 +323,9 @@  discard block
 block discarded – undo
315 323
 	$type = (int) $type;
316 324
 
317 325
 	// nothing to read, nothing to do
318
-	if (empty($id_draft))
319
-		return false;
326
+	if (empty($id_draft)) {
327
+			return false;
328
+	}
320 329
 
321 330
 	// load in this draft from the DB
322 331
 	$request = $smcFunc['db_query']('', '
@@ -337,8 +346,9 @@  discard block
 block discarded – undo
337 346
 	);
338 347
 
339 348
 	// no results?
340
-	if (!$smcFunc['db_num_rows']($request))
341
-		return false;
349
+	if (!$smcFunc['db_num_rows']($request)) {
350
+			return false;
351
+	}
342 352
 
343 353
 	// load up the data
344 354
 	$draft_info = $smcFunc['db_fetch_assoc']($request);
@@ -358,8 +368,7 @@  discard block
 block discarded – undo
358 368
 			$context['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : '';
359 369
 			$context['board'] = !empty($draft_info['id_board']) ? $draft_info['id_board'] : '';
360 370
 			$context['id_draft'] = !empty($draft_info['id_draft']) ? $draft_info['id_draft'] : 0;
361
-		}
362
-		elseif ($type === 1)
371
+		} elseif ($type === 1)
363 372
 		{
364 373
 			// one of those pm drafts? then set it up like we have an error
365 374
 			$_REQUEST['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : '';
@@ -395,12 +404,14 @@  discard block
 block discarded – undo
395 404
 	global $user_info, $smcFunc;
396 405
 
397 406
 	// Only a single draft.
398
-	if (is_numeric($id_draft))
399
-		$id_draft = array($id_draft);
407
+	if (is_numeric($id_draft)) {
408
+			$id_draft = array($id_draft);
409
+	}
400 410
 
401 411
 	// can't delete nothing
402
-	if (empty($id_draft) || ($check && empty($user_info['id'])))
403
-		return false;
412
+	if (empty($id_draft) || ($check && empty($user_info['id']))) {
413
+			return false;
414
+	}
404 415
 
405 416
 	$smcFunc['db_query']('', '
406 417
 		DELETE FROM {db_prefix}user_drafts
@@ -429,14 +440,16 @@  discard block
 block discarded – undo
429 440
 	global $smcFunc, $scripturl, $context, $txt, $modSettings;
430 441
 
431 442
 	// Permissions
432
-	if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id))
433
-		return false;
443
+	if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) {
444
+			return false;
445
+	}
434 446
 
435 447
 	$context['drafts'] = array();
436 448
 
437 449
 	// has a specific draft has been selected?  Load it up if there is not a message already in the editor
438
-	if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message']))
439
-		ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true);
450
+	if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) {
451
+			ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true);
452
+	}
440 453
 
441 454
 	// load the drafts this user has available
442 455
 	$request = $smcFunc['db_query']('', '
@@ -459,8 +472,9 @@  discard block
 block discarded – undo
459 472
 	// add them to the draft array for display
460 473
 	while ($row = $smcFunc['db_fetch_assoc']($request))
461 474
 	{
462
-		if (empty($row['subject']))
463
-			$row['subject'] = $txt['no_subject'];
475
+		if (empty($row['subject'])) {
476
+					$row['subject'] = $txt['no_subject'];
477
+		}
464 478
 
465 479
 		// Post drafts
466 480
 		if ($draft_type === 0)
@@ -545,8 +559,9 @@  discard block
 block discarded – undo
545 559
 	}
546 560
 
547 561
 	// Default to 10.
548
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
549
-		$_REQUEST['viewscount'] = 10;
562
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
563
+			$_REQUEST['viewscount'] = 10;
564
+	}
550 565
 
551 566
 	// Get the count of applicable drafts on the boards they can (still) see ...
552 567
 	// @todo .. should we just let them see their drafts even if they have lost board access ?
@@ -611,12 +626,14 @@  discard block
 block discarded – undo
611 626
 	while ($row = $smcFunc['db_fetch_assoc']($request))
612 627
 	{
613 628
 		// Censor....
614
-		if (empty($row['body']))
615
-			$row['body'] = '';
629
+		if (empty($row['body'])) {
630
+					$row['body'] = '';
631
+		}
616 632
 
617 633
 		$row['subject'] = $smcFunc['htmltrim']($row['subject']);
618
-		if (empty($row['subject']))
619
-			$row['subject'] = $txt['no_subject'];
634
+		if (empty($row['subject'])) {
635
+					$row['subject'] = $txt['no_subject'];
636
+		}
620 637
 
621 638
 		censorText($row['body']);
622 639
 		censorText($row['subject']);
@@ -648,8 +665,9 @@  discard block
 block discarded – undo
648 665
 	$smcFunc['db_free_result']($request);
649 666
 
650 667
 	// If the drafts were retrieved in reverse order, get them right again.
651
-	if ($reverse)
652
-		$context['drafts'] = array_reverse($context['drafts'], true);
668
+	if ($reverse) {
669
+			$context['drafts'] = array_reverse($context['drafts'], true);
670
+	}
653 671
 
654 672
 	// Menu tab
655 673
 	$context[$context['profile_menu_name']]['tab_data'] = array(
@@ -707,8 +725,9 @@  discard block
 block discarded – undo
707 725
 	}
708 726
 
709 727
 	// Default to 10.
710
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
711
-		$_REQUEST['viewscount'] = 10;
728
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
729
+			$_REQUEST['viewscount'] = 10;
730
+	}
712 731
 
713 732
 	// Get the count of applicable drafts
714 733
 	$request = $smcFunc['db_query']('', '
@@ -767,12 +786,14 @@  discard block
 block discarded – undo
767 786
 	while ($row = $smcFunc['db_fetch_assoc']($request))
768 787
 	{
769 788
 		// Censor....
770
-		if (empty($row['body']))
771
-			$row['body'] = '';
789
+		if (empty($row['body'])) {
790
+					$row['body'] = '';
791
+		}
772 792
 
773 793
 		$row['subject'] = $smcFunc['htmltrim']($row['subject']);
774
-		if (empty($row['subject']))
775
-			$row['subject'] = $txt['no_subject'];
794
+		if (empty($row['subject'])) {
795
+					$row['subject'] = $txt['no_subject'];
796
+		}
776 797
 
777 798
 		censorText($row['body']);
778 799
 		censorText($row['subject']);
@@ -827,8 +848,9 @@  discard block
 block discarded – undo
827 848
 	$smcFunc['db_free_result']($request);
828 849
 
829 850
 	// if the drafts were retrieved in reverse order, then put them in the right order again.
830
-	if ($reverse)
831
-		$context['drafts'] = array_reverse($context['drafts'], true);
851
+	if ($reverse) {
852
+			$context['drafts'] = array_reverse($context['drafts'], true);
853
+	}
832 854
 
833 855
 	// off to the template we go
834 856
 	$context['page_title'] = $txt['drafts'];
Please login to merge, or discard this patch.
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
  *
174 174
  * @param string $post_errors A string of info about errors encountered trying to save this draft
175 175
  * @param array $recipientList An array of data about who this PM is being sent to
176
- * @return boolean false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise
176
+ * @return boolean|null false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise
177 177
  */
178 178
 function SavePMDraft(&$post_errors, $recipientList)
179 179
 {
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
  *
389 389
  * @param int $id_draft The ID of the draft to delete
390 390
  * @param boolean $check Whether or not to check that the draft belongs to the current user
391
- * @return boolean False if it couldn't be deleted (doesn't return anything otherwise)
391
+ * @return false|null False if it couldn't be deleted (doesn't return anything otherwise)
392 392
  */
393 393
 function DeleteDraft($id_draft, $check = true)
394 394
 {
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
  * @param int $member_id ID of the member to show drafts for
423 423
  * @param boolean|integer $topic If $type is 1, this can be set to only load drafts for posts in the specific topic
424 424
  * @param int $draft_type The type of drafts to show - 0 for post drafts, 1 for PM drafts
425
- * @return boolean False if the drafts couldn't be loaded, nothing otherwise
425
+ * @return false|null False if the drafts couldn't be loaded, nothing otherwise
426 426
  */
427 427
 function ShowDrafts($member_id, $topic = false, $draft_type = 0)
428 428
 {
Please login to merge, or discard this patch.
subscriptions.php 1 patch
Braces   +38 added lines, -28 removed lines patch added patch discarded remove patch
@@ -16,8 +16,9 @@  discard block
 block discarded – undo
16 16
 
17 17
 // Start things rolling by getting SMF alive...
18 18
 $ssi_guest_access = true;
19
-if (!file_exists(dirname(__FILE__) . '/SSI.php'))
19
+if (!file_exists(dirname(__FILE__) . '/SSI.php')) {
20 20
 	die('Cannot find SSI.php');
21
+}
21 22
 
22 23
 require_once(dirname(__FILE__) . '/SSI.php');
23 24
 require_once($sourcedir . '/ManagePaid.php');
@@ -35,20 +36,22 @@  discard block
 block discarded – undo
35 36
 }
36 37
 
37 38
 // I assume we're even active?
38
-if (empty($modSettings['paid_enabled']))
39
+if (empty($modSettings['paid_enabled'])) {
39 40
 	exit;
41
+}
40 42
 
41 43
 // If we have some custom people who find out about problems load them here.
42 44
 $notify_users = array();
43 45
 if (!empty($modSettings['paid_email_to']))
44 46
 {
45
-	foreach (explode(',', $modSettings['paid_email_to']) as $email)
46
-		$notify_users[] = array(
47
+	foreach (explode(',', $modSettings['paid_email_to']) as $email) {
48
+			$notify_users[] = array(
47 49
 			'email' => $email,
48 50
 			'name' => $txt['who_member'],
49 51
 			'id' => 0,
50 52
 		);
51
-}
53
+	}
54
+	}
52 55
 
53 56
 // We need to see whether we can find the correct payment gateway,
54 57
 // we'll going to go through all our gateway scripts and find out
@@ -65,8 +68,9 @@  discard block
 block discarded – undo
65 68
 	}
66 69
 }
67 70
 
68
-if (empty($txnType))
71
+if (empty($txnType)) {
69 72
 	generateSubscriptionError($txt['paid_unknown_transaction_type']);
73
+}
70 74
 
71 75
 // Get the subscription and member ID amoungst others...
72 76
 @list($subscription_id, $member_id) = $gatewayClass->precheck();
@@ -76,8 +80,9 @@  discard block
 block discarded – undo
76 80
 $member_id = (int) $member_id;
77 81
 
78 82
 // This would be bad...
79
-if (empty($member_id))
83
+if (empty($member_id)) {
80 84
 	generateSubscriptionError($txt['paid_empty_member']);
85
+}
81 86
 
82 87
 // Verify the member.
83 88
 $request = $smcFunc['db_query']('', '
@@ -89,8 +94,9 @@  discard block
 block discarded – undo
89 94
 	)
90 95
 );
91 96
 // Didn't find them?
92
-if ($smcFunc['db_num_rows']($request) === 0)
97
+if ($smcFunc['db_num_rows']($request) === 0) {
93 98
 	generateSubscriptionError(sprintf($txt['paid_could_not_find_member'], $member_id));
99
+}
94 100
 $member_info = $smcFunc['db_fetch_assoc']($request);
95 101
 $smcFunc['db_free_result']($request);
96 102
 
@@ -105,8 +111,9 @@  discard block
 block discarded – undo
105 111
 );
106 112
 
107 113
 // Didn't find it?
108
-if ($smcFunc['db_num_rows']($request) === 0)
114
+if ($smcFunc['db_num_rows']($request) === 0) {
109 115
 	generateSubscriptionError(sprintf($txt['paid_count_not_find_subscription'], $member_id, $subscription_id));
116
+}
110 117
 
111 118
 $subscription_info = $smcFunc['db_fetch_assoc']($request);
112 119
 $smcFunc['db_free_result']($request);
@@ -123,8 +130,9 @@  discard block
 block discarded – undo
123 130
 		'current_member' => $member_id,
124 131
 	)
125 132
 );
126
-if ($smcFunc['db_num_rows']($request) === 0)
133
+if ($smcFunc['db_num_rows']($request) === 0) {
127 134
 	generateSubscriptionError(sprintf($txt['paid_count_not_find_subscription_log'], $member_id, $subscription_id));
135
+}
128 136
 $subscription_info += $smcFunc['db_fetch_assoc']($request);
129 137
 $smcFunc['db_free_result']($request);
130 138
 
@@ -139,8 +147,7 @@  discard block
 block discarded – undo
139 147
 		removeSubscription($subscription_id, $member_id);
140 148
 		$subscription_act = time();
141 149
 		$status = 0;
142
-	}
143
-	else
150
+	} else
144 151
 	{
145 152
 		loadSubscriptions();
146 153
 		$subscription_act = $subscription_info['end_time'] - $context['subscriptions'][$subscription_id]['num_length'];
@@ -188,16 +195,18 @@  discard block
 block discarded – undo
188 195
 	if (!$gatewayClass->isSubscription())
189 196
 	{
190 197
 		$real_details = $smcFunc['json_decode']($subscription_info['pending_details'], true);
191
-		if (empty($real_details))
192
-			generateSubscriptionError(sprintf($txt['paid_count_not_find_outstanding_payment'], $member_id, $subscription_id));
198
+		if (empty($real_details)) {
199
+					generateSubscriptionError(sprintf($txt['paid_count_not_find_outstanding_payment'], $member_id, $subscription_id));
200
+		}
193 201
 
194 202
 		// Now we just try to find anything pending.
195 203
 		// We don't really care which it is as security happens later.
196 204
 		foreach ($real_details as $id => $detail)
197 205
 		{
198 206
 			unset($real_details[$id]);
199
-			if ($detail[3] == 'payback' && $subscription_info['payments_pending'])
200
-				$subscription_info['payments_pending']--;
207
+			if ($detail[3] == 'payback' && $subscription_info['payments_pending']) {
208
+							$subscription_info['payments_pending']--;
209
+			}
201 210
 			break;
202 211
 		}
203 212
 
@@ -223,10 +232,11 @@  discard block
 block discarded – undo
223 232
 		// This is a little harder, can we find the right duration?
224 233
 		foreach ($cost as $duration => $value)
225 234
 		{
226
-			if ($duration == 'fixed')
227
-				continue;
228
-			elseif ((float) $value == (float) $total_cost)
229
-				$found_duration = strtoupper(substr($duration, 0, 1));
235
+			if ($duration == 'fixed') {
236
+							continue;
237
+			} elseif ((float) $value == (float) $total_cost) {
238
+							$found_duration = strtoupper(substr($duration, 0, 1));
239
+			}
230 240
 		}
231 241
 
232 242
 		// If we have the duration then we're done.
@@ -235,8 +245,7 @@  discard block
 block discarded – undo
235 245
 			$notify = true;
236 246
 			addSubscription($subscription_id, $member_id, $found_duration);
237 247
 		}
238
-	}
239
-	else
248
+	} else
240 249
 	{
241 250
 		$actual_cost = $cost['fixed'];
242 251
 
@@ -268,10 +277,10 @@  discard block
 block discarded – undo
268 277
 // Maybe they're cancelling. Some subscriptions may require actively doing something, but PayPal doesn't, for example.
269 278
 elseif ($gatewayClass->isCancellation())
270 279
 {
271
-	if (method_exists($gatewayClass, 'performCancel'))
272
-		$gatewayClass->performCancel($subscription_id, $member_id, $subscription_info);
273
-}
274
-else
280
+	if (method_exists($gatewayClass, 'performCancel')) {
281
+			$gatewayClass->performCancel($subscription_id, $member_id, $subscription_info);
282
+	}
283
+	} else
275 284
 {
276 285
 	// Some other "valid" transaction such as:
277 286
 	//
@@ -308,8 +317,9 @@  discard block
 block discarded – undo
308 317
 	// Maybe we can try to give them the post data?
309 318
 	if (!empty($_POST))
310 319
 	{
311
-		foreach ($_POST as $key => $val)
312
-			$text .= '<br>' . $smcFunc['htmlspecialchars']($key) . ': ' . $smcFunc['htmlspecialchars']($val);
320
+		foreach ($_POST as $key => $val) {
321
+					$text .= '<br>' . $smcFunc['htmlspecialchars']($key) . ': ' . $smcFunc['htmlspecialchars']($val);
322
+		}
313 323
 	}
314 324
 
315 325
 	// Then just log and die.
Please login to merge, or discard this patch.
Sources/Load.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -2259,9 +2259,9 @@  discard block
 block discarded – undo
2259 2259
  *
2260 2260
  * @uses the template_include() function to include the file.
2261 2261
  * @param string $template_name The name of the template to load
2262
- * @param array|string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load
2262
+ * @param string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load
2263 2263
  * @param bool $fatal If true, dies with an error message if the template cannot be found
2264
- * @return boolean Whether or not the template was loaded
2264
+ * @return boolean|null Whether or not the template was loaded
2265 2265
  */
2266 2266
 function loadTemplate($template_name, $style_sheets = array(), $fatal = true)
2267 2267
 {
@@ -2444,7 +2444,7 @@  discard block
 block discarded – undo
2444 2444
  * - all code added with this function is added to the same <style> tag so do make sure your css is valid!
2445 2445
  *
2446 2446
  * @param string $css Some css code
2447
- * @return void|bool Adds the CSS to the $context['css_header'] array or returns if no CSS is specified
2447
+ * @return false|null Adds the CSS to the $context['css_header'] array or returns if no CSS is specified
2448 2448
  */
2449 2449
 function addInlineCss($css)
2450 2450
 {
@@ -2558,7 +2558,7 @@  discard block
 block discarded – undo
2558 2558
  *
2559 2559
  * @param string $javascript Some JS code
2560 2560
  * @param bool $defer Whether the script should load in <head> or before the closing <html> tag
2561
- * @return void|bool Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified
2561
+ * @return false|null Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified
2562 2562
  */
2563 2563
 function addInlineJavaScript($javascript, $defer = false)
2564 2564
 {
@@ -2791,7 +2791,7 @@  discard block
 block discarded – undo
2791 2791
  * It will try to choose only utf8 or non-utf8 languages.
2792 2792
  *
2793 2793
  * @param bool $use_cache Whether or not to use the cache
2794
- * @return array An array of information about available languages
2794
+ * @return string An array of information about available languages
2795 2795
  */
2796 2796
 function getLanguages($use_cache = true)
2797 2797
 {
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1774,7 +1774,7 @@  discard block
 block discarded – undo
1774 1774
 	call_integration_hook('integrate_pre_load_theme', array(&$id_theme));
1775 1775
 
1776 1776
 	// We already load the basic stuff?
1777
-	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme )
1777
+	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme)
1778 1778
 	{
1779 1779
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1780 1780
 
@@ -1799,7 +1799,7 @@  discard block
 block discarded – undo
1799 1799
 				SELECT variable, value, id_member, id_theme
1800 1800
 				FROM {db_prefix}themes
1801 1801
 				WHERE id_member' . (empty($themeData[0]) ? ' IN (-1, 0, {int:id_member})' : ' = {int:id_member}') . '
1802
-					AND id_theme' . ($id_theme == 1 ? ' = {int:id_theme}' : ' IN ({int:id_theme}, 1)') .'
1802
+					AND id_theme' . ($id_theme == 1 ? ' = {int:id_theme}' : ' IN ({int:id_theme}, 1)') . '
1803 1803
 				ORDER BY id_theme asc',
1804 1804
 				array(
1805 1805
 					'id_theme' => $id_theme,
@@ -2029,7 +2029,7 @@  discard block
 block discarded – undo
2029 2029
 	if (!isset($context['javascript_vars']))
2030 2030
 		$context['javascript_vars'] = array();
2031 2031
 
2032
-	$context['login_url'] =  $scripturl . '?action=login2';
2032
+	$context['login_url'] = $scripturl . '?action=login2';
2033 2033
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
2034 2034
 	$context['session_var'] = $_SESSION['session_var'];
2035 2035
 	$context['session_id'] = $_SESSION['session_value'];
Please login to merge, or discard this patch.
Braces   +795 added lines, -599 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 explicitly 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('~(' . $ent_list . '|.)~' . ($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
 
@@ -410,9 +427,9 @@  discard block
 block discarded – undo
410 427
 				break;
411 428
 			}
412 429
 		}
430
+	} else {
431
+			$id_member = 0;
413 432
 	}
414
-	else
415
-		$id_member = 0;
416 433
 
417 434
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
418 435
 	{
@@ -420,8 +437,9 @@  discard block
 block discarded – undo
420 437
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
421 438
 
422 439
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
423
-		if (empty($cookie_data))
424
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
440
+		if (empty($cookie_data)) {
441
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
442
+		}
425 443
 
426 444
 		list($id_member, $password, $login_span, $cookie_domain, $cookie_path) = array_pad((array) $cookie_data, 5, '');
427 445
 
@@ -429,16 +447,17 @@  discard block
 block discarded – undo
429 447
 
430 448
 		// Make sure the cookie is set to the correct domain and path
431 449
 		require_once($sourcedir . '/Subs-Auth.php');
432
-		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])))
433
-			setLoginCookie((int) $login_span - time(), $id_member);
434
-	}
435
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
450
+		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) {
451
+					setLoginCookie((int) $login_span - time(), $id_member);
452
+		}
453
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
436 454
 	{
437 455
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
438 456
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename], true);
439 457
 
440
-		if (empty($cookie_data))
441
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
458
+		if (empty($cookie_data)) {
459
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
460
+		}
442 461
 
443 462
 		list($id_member, $password, $login_span) = array_pad((array) $cookie_data, 3, '');
444 463
 		$id_member = !empty($id_member) && strlen($password) == 128 && (int) $login_span > time() ? (int) $id_member : 0;
@@ -463,30 +482,34 @@  discard block
 block discarded – undo
463 482
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
464 483
 			$smcFunc['db_free_result']($request);
465 484
 
466
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
467
-				$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
485
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
486
+							$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
487
+			}
468 488
 
469
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
470
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
489
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
490
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
491
+			}
471 492
 		}
472 493
 
473 494
 		// Did we find 'im?  If not, junk it.
474 495
 		if (!empty($user_settings))
475 496
 		{
476 497
 			// As much as the password should be right, we can assume the integration set things up.
477
-			if (!empty($already_verified) && $already_verified === true)
478
-				$check = true;
498
+			if (!empty($already_verified) && $already_verified === true) {
499
+							$check = true;
500
+			}
479 501
 			// SHA-512 hash should be 128 characters long.
480
-			elseif (strlen($password) == 128)
481
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
482
-			else
483
-				$check = false;
502
+			elseif (strlen($password) == 128) {
503
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
504
+			} else {
505
+							$check = false;
506
+			}
484 507
 
485 508
 			// Wrong password or not activated - either way, you're going nowhere.
486 509
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
510
+		} else {
511
+					$id_member = 0;
487 512
 		}
488
-		else
489
-			$id_member = 0;
490 513
 
491 514
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
492 515
 		if (!$id_member)
@@ -515,8 +538,9 @@  discard block
 block discarded – undo
515 538
 
516 539
 					list ($tfamember, $tfasecret) = array_pad((array) $tfa_data, 2, '');
517 540
 
518
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
519
-						$tfasecret = null;
541
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
542
+											$tfasecret = null;
543
+					}
520 544
 				}
521 545
 
522 546
 				// They didn't finish logging in before coming here? Then they're no one to us.
@@ -538,10 +562,12 @@  discard block
 block discarded – undo
538 562
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
539 563
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
540 564
 		{
541
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
565
+			if ($modSettings['tfa_mode'] == 2) {
566
+				//only do this if we are just forcing SOME membergroups
542 567
 			{
543 568
 				//Build an array of ALL user membergroups.
544 569
 				$full_groups = array($user_settings['id_group']);
570
+			}
545 571
 				if (!empty($user_settings['additional_groups']))
546 572
 				{
547 573
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -561,15 +587,17 @@  discard block
 block discarded – undo
561 587
 				);
562 588
 				$row = $smcFunc['db_fetch_assoc']($request);
563 589
 				$smcFunc['db_free_result']($request);
590
+			} else {
591
+							$row['total'] = 1;
564 592
 			}
565
-			else
566
-				$row['total'] = 1; //simplifies logics in the next "if"
593
+			//simplifies logics in the next "if"
567 594
 
568 595
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
569 596
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
570 597
 
571
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
572
-				redirectexit('action=profile;area=tfasetup;forced');
598
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
599
+							redirectexit('action=profile;area=tfasetup;forced');
600
+			}
573 601
 		}
574 602
 	}
575 603
 
@@ -606,29 +634,32 @@  discard block
 block discarded – undo
606 634
 				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']));
607 635
 				$user_settings['last_login'] = time();
608 636
 
609
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
610
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
637
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
638
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
639
+				}
611 640
 
612
-				if (!empty($modSettings['cache_enable']))
613
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
641
+				if (!empty($modSettings['cache_enable'])) {
642
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
643
+				}
614 644
 			}
645
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
646
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
615 647
 		}
616
-		elseif (empty($_SESSION['id_msg_last_visit']))
617
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
618 648
 
619 649
 		$username = $user_settings['member_name'];
620 650
 
621
-		if (empty($user_settings['additional_groups']))
622
-			$user_info = array(
651
+		if (empty($user_settings['additional_groups'])) {
652
+					$user_info = array(
623 653
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
624 654
 			);
625
-		else
626
-			$user_info = array(
655
+		} else {
656
+					$user_info = array(
627 657
 				'groups' => array_merge(
628 658
 					array($user_settings['id_group'], $user_settings['id_post_group']),
629 659
 					explode(',', $user_settings['additional_groups'])
630 660
 				)
631 661
 			);
662
+		}
632 663
 
633 664
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
634 665
 		$user_info['groups'] = array_map('intval', $user_info['groups']);
@@ -645,8 +676,7 @@  discard block
 block discarded – undo
645 676
 			$time_system = new DateTime('now', $tz_system);
646 677
 			$time_user = new DateTime('now', $tz_user);
647 678
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
648
-		}
649
-		else
679
+		} else
650 680
 		{
651 681
 			// !!! Compatibility.
652 682
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -660,8 +690,9 @@  discard block
 block discarded – undo
660 690
 		$user_info = array('groups' => array(-1));
661 691
 		$user_settings = array();
662 692
 
663
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
664
-			$_COOKIE[$cookiename] = '';
693
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
694
+					$_COOKIE[$cookiename] = '';
695
+		}
665 696
 
666 697
 		// Expire the 2FA cookie
667 698
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -678,19 +709,20 @@  discard block
 block discarded – undo
678 709
 		}
679 710
 
680 711
 		// Create a login token if it doesn't exist yet.
681
-		if (!isset($_SESSION['token']['post-login']))
682
-			createToken('login');
683
-		else
684
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
712
+		if (!isset($_SESSION['token']['post-login'])) {
713
+					createToken('login');
714
+		} else {
715
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
716
+		}
685 717
 
686 718
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
687 719
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
688 720
 		{
689 721
 			require_once($sourcedir . '/ManageSearchEngines.php');
690 722
 			$user_info['possibly_robot'] = SpiderCheck();
723
+		} elseif (!empty($modSettings['spider_mode'])) {
724
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
691 725
 		}
692
-		elseif (!empty($modSettings['spider_mode']))
693
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
694 726
 		// If we haven't turned on proper spider hunts then have a guess!
695 727
 		else
696 728
 		{
@@ -747,8 +779,9 @@  discard block
 block discarded – undo
747 779
 	$user_info['groups'] = array_unique($user_info['groups']);
748 780
 
749 781
 	// 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.
750
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
751
-		unset($user_info['ignoreboards'][$tmp]);
782
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
783
+			unset($user_info['ignoreboards'][$tmp]);
784
+	}
752 785
 
753 786
 	// Allow the user to change their language.
754 787
 	if (!empty($modSettings['userLanguage']))
@@ -761,13 +794,14 @@  discard block
 block discarded – undo
761 794
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
762 795
 
763 796
 			// Make it permanent for members.
764
-			if (!empty($user_info['id']))
765
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
766
-			else
767
-				$_SESSION['language'] = $user_info['language'];
797
+			if (!empty($user_info['id'])) {
798
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
799
+			} else {
800
+							$_SESSION['language'] = $user_info['language'];
801
+			}
802
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
803
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
768 804
 		}
769
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
770
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
771 805
 	}
772 806
 
773 807
 	$temp = build_query_board($user_info['id']);
@@ -830,9 +864,9 @@  discard block
 block discarded – undo
830 864
 		}
831 865
 
832 866
 		// Remember redirection is the key to avoiding fallout from your bosses.
833
-		if (!empty($topic))
834
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
835
-		else
867
+		if (!empty($topic)) {
868
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
869
+		} else
836 870
 		{
837 871
 			loadPermissions();
838 872
 			loadTheme();
@@ -850,10 +884,11 @@  discard block
 block discarded – undo
850 884
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
851 885
 	{
852 886
 		// @todo SLOW?
853
-		if (!empty($topic))
854
-			$temp = cache_get_data('topic_board-' . $topic, 120);
855
-		else
856
-			$temp = cache_get_data('board-' . $board, 120);
887
+		if (!empty($topic)) {
888
+					$temp = cache_get_data('topic_board-' . $topic, 120);
889
+		} else {
890
+					$temp = cache_get_data('board-' . $board, 120);
891
+		}
857 892
 
858 893
 		if (!empty($temp))
859 894
 		{
@@ -891,8 +926,9 @@  discard block
 block discarded – undo
891 926
 			$row = $smcFunc['db_fetch_assoc']($request);
892 927
 
893 928
 			// Set the current board.
894
-			if (!empty($row['id_board']))
895
-				$board = $row['id_board'];
929
+			if (!empty($row['id_board'])) {
930
+							$board = $row['id_board'];
931
+			}
896 932
 
897 933
 			// Basic operating information. (globals... :/)
898 934
 			$board_info = array(
@@ -928,21 +964,23 @@  discard block
 block discarded – undo
928 964
 
929 965
 			do
930 966
 			{
931
-				if (!empty($row['id_moderator']))
932
-					$board_info['moderators'][$row['id_moderator']] = array(
967
+				if (!empty($row['id_moderator'])) {
968
+									$board_info['moderators'][$row['id_moderator']] = array(
933 969
 						'id' => $row['id_moderator'],
934 970
 						'name' => $row['real_name'],
935 971
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
936 972
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
937 973
 					);
974
+				}
938 975
 
939
-				if (!empty($row['id_moderator_group']))
940
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
976
+				if (!empty($row['id_moderator_group'])) {
977
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
941 978
 						'id' => $row['id_moderator_group'],
942 979
 						'name' => $row['group_name'],
943 980
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
944 981
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
945 982
 					);
983
+				}
946 984
 			}
947 985
 			while ($row = $smcFunc['db_fetch_assoc']($request));
948 986
 
@@ -974,12 +1012,12 @@  discard block
 block discarded – undo
974 1012
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
975 1013
 			{
976 1014
 				// @todo SLOW?
977
-				if (!empty($topic))
978
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
1015
+				if (!empty($topic)) {
1016
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1017
+				}
979 1018
 				cache_put_data('board-' . $board, $board_info, 120);
980 1019
 			}
981
-		}
982
-		else
1020
+		} else
983 1021
 		{
984 1022
 			// Otherwise the topic is invalid, there are no moderators, etc.
985 1023
 			$board_info = array(
@@ -993,8 +1031,9 @@  discard block
 block discarded – undo
993 1031
 		$smcFunc['db_free_result']($request);
994 1032
 	}
995 1033
 
996
-	if (!empty($topic))
997
-		$_GET['board'] = (int) $board;
1034
+	if (!empty($topic)) {
1035
+			$_GET['board'] = (int) $board;
1036
+	}
998 1037
 
999 1038
 	if (!empty($board))
1000 1039
 	{
@@ -1004,10 +1043,12 @@  discard block
 block discarded – undo
1004 1043
 		// Now check if the user is a moderator.
1005 1044
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
1006 1045
 
1007
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
1008
-			$board_info['error'] = 'access';
1009
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
1010
-			$board_info['error'] = 'access';
1046
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1047
+					$board_info['error'] = 'access';
1048
+		}
1049
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1050
+					$board_info['error'] = 'access';
1051
+		}
1011 1052
 
1012 1053
 		// Build up the linktree.
1013 1054
 		$context['linktree'] = array_merge(
@@ -1030,8 +1071,9 @@  discard block
 block discarded – undo
1030 1071
 	$context['current_board'] = $board;
1031 1072
 
1032 1073
 	// No posting in redirection boards!
1033
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1034
-		$board_info['error'] == 'post_in_redirect';
1074
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1075
+			$board_info['error'] == 'post_in_redirect';
1076
+	}
1035 1077
 
1036 1078
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1037 1079
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1057,24 +1099,23 @@  discard block
 block discarded – undo
1057 1099
 			ob_end_clean();
1058 1100
 			send_http_status(403);
1059 1101
 			die;
1060
-		}
1061
-		elseif ($board_info['error'] == 'post_in_redirect')
1102
+		} elseif ($board_info['error'] == 'post_in_redirect')
1062 1103
 		{
1063 1104
 			// Slightly different error message here...
1064 1105
 			fatal_lang_error('cannot_post_redirect', false);
1065
-		}
1066
-		elseif ($user_info['is_guest'])
1106
+		} elseif ($user_info['is_guest'])
1067 1107
 		{
1068 1108
 			loadLanguage('Errors');
1069 1109
 			is_not_guest($txt['topic_gone']);
1110
+		} else {
1111
+					fatal_lang_error('topic_gone', false);
1070 1112
 		}
1071
-		else
1072
-			fatal_lang_error('topic_gone', false);
1073 1113
 	}
1074 1114
 
1075
-	if ($user_info['is_mod'])
1076
-		$user_info['groups'][] = 3;
1077
-}
1115
+	if ($user_info['is_mod']) {
1116
+			$user_info['groups'][] = 3;
1117
+	}
1118
+	}
1078 1119
 
1079 1120
 /**
1080 1121
  * Load this user's permissions.
@@ -1095,8 +1136,9 @@  discard block
 block discarded – undo
1095 1136
 		asort($cache_groups);
1096 1137
 		$cache_groups = implode(',', $cache_groups);
1097 1138
 		// If it's a spider then cache it different.
1098
-		if ($user_info['possibly_robot'])
1099
-			$cache_groups .= '-spider';
1139
+		if ($user_info['possibly_robot']) {
1140
+					$cache_groups .= '-spider';
1141
+		}
1100 1142
 
1101 1143
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1102 1144
 		{
@@ -1104,9 +1146,9 @@  discard block
 block discarded – undo
1104 1146
 			banPermissions();
1105 1147
 
1106 1148
 			return;
1149
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1150
+					list ($user_info['permissions'], $removals) = $temp;
1107 1151
 		}
1108
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1109
-			list ($user_info['permissions'], $removals) = $temp;
1110 1152
 	}
1111 1153
 
1112 1154
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1128,23 +1170,26 @@  discard block
 block discarded – undo
1128 1170
 		$removals = array();
1129 1171
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1130 1172
 		{
1131
-			if (empty($row['add_deny']))
1132
-				$removals[] = $row['permission'];
1133
-			else
1134
-				$user_info['permissions'][] = $row['permission'];
1173
+			if (empty($row['add_deny'])) {
1174
+							$removals[] = $row['permission'];
1175
+			} else {
1176
+							$user_info['permissions'][] = $row['permission'];
1177
+			}
1135 1178
 		}
1136 1179
 		$smcFunc['db_free_result']($request);
1137 1180
 
1138
-		if (isset($cache_groups))
1139
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1181
+		if (isset($cache_groups)) {
1182
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1183
+		}
1140 1184
 	}
1141 1185
 
1142 1186
 	// Get the board permissions.
1143 1187
 	if (!empty($board))
1144 1188
 	{
1145 1189
 		// Make sure the board (if any) has been loaded by loadBoard().
1146
-		if (!isset($board_info['profile']))
1147
-			fatal_lang_error('no_board');
1190
+		if (!isset($board_info['profile'])) {
1191
+					fatal_lang_error('no_board');
1192
+		}
1148 1193
 
1149 1194
 		$request = $smcFunc['db_query']('', '
1150 1195
 			SELECT permission, add_deny
@@ -1160,20 +1205,23 @@  discard block
 block discarded – undo
1160 1205
 		);
1161 1206
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1162 1207
 		{
1163
-			if (empty($row['add_deny']))
1164
-				$removals[] = $row['permission'];
1165
-			else
1166
-				$user_info['permissions'][] = $row['permission'];
1208
+			if (empty($row['add_deny'])) {
1209
+							$removals[] = $row['permission'];
1210
+			} else {
1211
+							$user_info['permissions'][] = $row['permission'];
1212
+			}
1167 1213
 		}
1168 1214
 		$smcFunc['db_free_result']($request);
1169 1215
 	}
1170 1216
 
1171 1217
 	// Remove all the permissions they shouldn't have ;).
1172
-	if (!empty($modSettings['permission_enable_deny']))
1173
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1218
+	if (!empty($modSettings['permission_enable_deny'])) {
1219
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1220
+	}
1174 1221
 
1175
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1176
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1222
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1223
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1224
+	}
1177 1225
 
1178 1226
 	// Banned?  Watch, don't touch..
1179 1227
 	banPermissions();
@@ -1185,17 +1233,18 @@  discard block
 block discarded – undo
1185 1233
 		{
1186 1234
 			require_once($sourcedir . '/Subs-Auth.php');
1187 1235
 			rebuildModCache();
1236
+		} else {
1237
+					$user_info['mod_cache'] = $_SESSION['mc'];
1188 1238
 		}
1189
-		else
1190
-			$user_info['mod_cache'] = $_SESSION['mc'];
1191 1239
 
1192 1240
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1193 1241
 		// For example this drastically simplifies certain changes to the profile area.
1194 1242
 		$user_info['permissions'][] = 'is_not_guest';
1195 1243
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1196 1244
 		$user_info['permissions'][] = 'profile_view_own';
1197
-		if (in_array('profile_view', $user_info['permissions']))
1198
-			$user_info['permissions'][] = 'profile_view_any';
1245
+		if (in_array('profile_view', $user_info['permissions'])) {
1246
+					$user_info['permissions'][] = 'profile_view_any';
1247
+		}
1199 1248
 	}
1200 1249
 }
1201 1250
 
@@ -1213,8 +1262,9 @@  discard block
 block discarded – undo
1213 1262
 	global $image_proxy_enabled, $user_info;
1214 1263
 
1215 1264
 	// Can't just look for no users :P.
1216
-	if (empty($users))
1217
-		return array();
1265
+	if (empty($users)) {
1266
+			return array();
1267
+	}
1218 1268
 
1219 1269
 	// Pass the set value
1220 1270
 	$context['loadMemberContext_set'] = $set;
@@ -1229,8 +1279,9 @@  discard block
 block discarded – undo
1229 1279
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1230 1280
 		{
1231 1281
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1232
-			if ($data == null)
1233
-				continue;
1282
+			if ($data == null) {
1283
+							continue;
1284
+			}
1234 1285
 
1235 1286
 			$loaded_ids[] = $data['id_member'];
1236 1287
 			$user_profile[$data['id_member']] = $data;
@@ -1297,16 +1348,19 @@  discard block
 block discarded – undo
1297 1348
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1298 1349
 
1299 1350
 			// Take care of proxying avatar if required, do this here for maximum reach
1300
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
1301
-				$row['avatar'] = get_proxied_url($row['avatar']);
1351
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
1352
+							$row['avatar'] = get_proxied_url($row['avatar']);
1353
+			}
1302 1354
 
1303 1355
 			// Keep track of the member's normal member group
1304 1356
 			$row['primary_group'] = !empty($row['member_group']) ? $row['member_group'] : '';
1305 1357
 
1306
-			if (isset($row['member_ip']))
1307
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1308
-			if (isset($row['member_ip2']))
1309
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1358
+			if (isset($row['member_ip'])) {
1359
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1360
+			}
1361
+			if (isset($row['member_ip2'])) {
1362
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1363
+			}
1310 1364
 			$row['id_member'] = (int) $row['id_member'];
1311 1365
 			$new_loaded_ids[] = $row['id_member'];
1312 1366
 			$loaded_ids[] = $row['id_member'];
@@ -1326,8 +1380,9 @@  discard block
 block discarded – undo
1326 1380
 				'loaded_ids' => $new_loaded_ids,
1327 1381
 			)
1328 1382
 		);
1329
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1330
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1383
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1384
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1385
+		}
1331 1386
 		$smcFunc['db_free_result']($request);
1332 1387
 	}
1333 1388
 
@@ -1338,10 +1393,11 @@  discard block
 block discarded – undo
1338 1393
 	{
1339 1394
 		foreach ($loaded_ids as $a_member)
1340 1395
 		{
1341
-			if (!empty($user_profile[$a_member]['additional_groups']))
1342
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1343
-			else
1344
-				$groups = array($user_profile[$a_member]['id_group']);
1396
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1397
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1398
+			} else {
1399
+							$groups = array($user_profile[$a_member]['id_group']);
1400
+			}
1345 1401
 
1346 1402
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1347 1403
 
@@ -1354,8 +1410,9 @@  discard block
 block discarded – undo
1354 1410
 
1355 1411
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1356 1412
 	{
1357
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1358
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1413
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1414
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1415
+		}
1359 1416
 	}
1360 1417
 
1361 1418
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1381,14 +1438,17 @@  discard block
 block discarded – undo
1381 1438
 		foreach ($temp_mods as $id)
1382 1439
 		{
1383 1440
 			// By popular demand, don't show admins or global moderators as moderators.
1384
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1385
-				$user_profile[$id]['member_group'] = $row['member_group'];
1441
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1442
+							$user_profile[$id]['member_group'] = $row['member_group'];
1443
+			}
1386 1444
 
1387 1445
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1388
-			if (!empty($row['icons']))
1389
-				$user_profile[$id]['icons'] = $row['icons'];
1390
-			if (!empty($row['member_group_color']))
1391
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1446
+			if (!empty($row['icons'])) {
1447
+							$user_profile[$id]['icons'] = $row['icons'];
1448
+			}
1449
+			if (!empty($row['member_group_color'])) {
1450
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1451
+			}
1392 1452
 		}
1393 1453
 	}
1394 1454
 
@@ -1410,12 +1470,14 @@  discard block
 block discarded – undo
1410 1470
 	static $loadedLanguages = array();
1411 1471
 
1412 1472
 	// If this person's data is already loaded, skip it.
1413
-	if (isset($dataLoaded[$user]))
1414
-		return true;
1473
+	if (isset($dataLoaded[$user])) {
1474
+			return true;
1475
+	}
1415 1476
 
1416 1477
 	// We can't load guests or members not loaded by loadMemberData()!
1417
-	if ($user == 0)
1418
-		return false;
1478
+	if ($user == 0) {
1479
+			return false;
1480
+	}
1419 1481
 	if (!isset($user_profile[$user]))
1420 1482
 	{
1421 1483
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1441,12 +1503,16 @@  discard block
 block discarded – undo
1441 1503
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1442 1504
 
1443 1505
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1444
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1506
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1507
+		//icon is set and exists
1445 1508
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1446
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1509
+	} elseif (isset($profile['icons'][1])) {
1510
+		//icon is set and doesn't exist, fallback to default
1447 1511
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1448
-	else //not set, bye bye
1512
+	} else {
1513
+		//not set, bye bye
1449 1514
 		$group_icon_url = '';
1515
+	}
1450 1516
 
1451 1517
 	// These minimal values are always loaded
1452 1518
 	$memberContext[$user] = array(
@@ -1465,8 +1531,9 @@  discard block
 block discarded – undo
1465 1531
 	if ($context['loadMemberContext_set'] != 'minimal')
1466 1532
 	{
1467 1533
 		// Go the extra mile and load the user's native language name.
1468
-		if (empty($loadedLanguages))
1469
-			$loadedLanguages = getLanguages();
1534
+		if (empty($loadedLanguages)) {
1535
+					$loadedLanguages = getLanguages();
1536
+		}
1470 1537
 
1471 1538
 		$memberContext[$user] += array(
1472 1539
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1521,31 +1588,33 @@  discard block
 block discarded – undo
1521 1588
 	{
1522 1589
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1523 1590
 		{
1524
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1525
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1526
-			else
1527
-				$image = get_gravatar_url($profile['email_address']);
1528
-		}
1529
-		else
1591
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1592
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1593
+			} else {
1594
+							$image = get_gravatar_url($profile['email_address']);
1595
+			}
1596
+		} else
1530 1597
 		{
1531 1598
 			// So it's stored in the member table?
1532 1599
 			if (!empty($profile['avatar']))
1533 1600
 			{
1534 1601
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1602
+			} elseif (!empty($profile['filename'])) {
1603
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1535 1604
 			}
1536
-			elseif (!empty($profile['filename']))
1537
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1538 1605
 			// Right... no avatar...use the default one
1539
-			else
1540
-				$image = $modSettings['avatar_url'] . '/default.png';
1606
+			else {
1607
+							$image = $modSettings['avatar_url'] . '/default.png';
1608
+			}
1541 1609
 		}
1542
-		if (!empty($image))
1543
-			$memberContext[$user]['avatar'] = array(
1610
+		if (!empty($image)) {
1611
+					$memberContext[$user]['avatar'] = array(
1544 1612
 				'name' => $profile['avatar'],
1545 1613
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1546 1614
 				'href' => $image,
1547 1615
 				'url' => $image,
1548 1616
 			);
1617
+		}
1549 1618
 	}
1550 1619
 
1551 1620
 	// Are we also loading the members custom fields into context?
@@ -1553,13 +1622,15 @@  discard block
 block discarded – undo
1553 1622
 	{
1554 1623
 		$memberContext[$user]['custom_fields'] = array();
1555 1624
 
1556
-		if (!isset($context['display_fields']))
1557
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1625
+		if (!isset($context['display_fields'])) {
1626
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1627
+		}
1558 1628
 
1559 1629
 		foreach ($context['display_fields'] as $custom)
1560 1630
 		{
1561
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1562
-				continue;
1631
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1632
+							continue;
1633
+			}
1563 1634
 
1564 1635
 			$value = $profile['options'][$custom['col_name']];
1565 1636
 
@@ -1567,31 +1638,36 @@  discard block
 block discarded – undo
1567 1638
 			$currentKey = 0;
1568 1639
 
1569 1640
 			// Create a key => value array for multiple options fields
1570
-			if (!empty($custom['options']))
1571
-				foreach ($custom['options'] as $k => $v)
1641
+			if (!empty($custom['options'])) {
1642
+							foreach ($custom['options'] as $k => $v)
1572 1643
 				{
1573 1644
 					$fieldOptions[] = $v;
1574
-					if (empty($currentKey))
1575
-						$currentKey = $v == $value ? $k : 0;
1645
+			}
1646
+					if (empty($currentKey)) {
1647
+											$currentKey = $v == $value ? $k : 0;
1648
+					}
1576 1649
 				}
1577 1650
 
1578 1651
 			// BBC?
1579
-			if ($custom['bbc'])
1580
-				$value = parse_bbc($value);
1652
+			if ($custom['bbc']) {
1653
+							$value = parse_bbc($value);
1654
+			}
1581 1655
 
1582 1656
 			// ... or checkbox?
1583
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1584
-				$value = $value ? $txt['yes'] : $txt['no'];
1657
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1658
+							$value = $value ? $txt['yes'] : $txt['no'];
1659
+			}
1585 1660
 
1586 1661
 			// Enclosing the user input within some other text?
1587
-			if (!empty($custom['enclose']))
1588
-				$value = strtr($custom['enclose'], array(
1662
+			if (!empty($custom['enclose'])) {
1663
+							$value = strtr($custom['enclose'], array(
1589 1664
 					'{SCRIPTURL}' => $scripturl,
1590 1665
 					'{IMAGES_URL}' => $settings['images_url'],
1591 1666
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1592 1667
 					'{INPUT}' => $value,
1593 1668
 					'{KEY}' => $currentKey,
1594 1669
 				));
1670
+			}
1595 1671
 
1596 1672
 			$memberContext[$user]['custom_fields'][] = array(
1597 1673
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1618,8 +1694,9 @@  discard block
 block discarded – undo
1618 1694
 	global $smcFunc, $txt, $scripturl, $settings;
1619 1695
 
1620 1696
 	// Do not waste my time...
1621
-	if (empty($users) || empty($params))
1622
-		return false;
1697
+	if (empty($users) || empty($params)) {
1698
+			return false;
1699
+	}
1623 1700
 
1624 1701
 	// Make sure it's an array.
1625 1702
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1646,41 +1723,48 @@  discard block
 block discarded – undo
1646 1723
 		$currentKey = 0;
1647 1724
 
1648 1725
 		// Create a key => value array for multiple options fields
1649
-		if (!empty($row['field_options']))
1650
-			foreach (explode(',', $row['field_options']) as $k => $v)
1726
+		if (!empty($row['field_options'])) {
1727
+					foreach (explode(',', $row['field_options']) as $k => $v)
1651 1728
 			{
1652 1729
 				$fieldOptions[] = $v;
1653
-				if (empty($currentKey))
1654
-					$currentKey = $v == $row['value'] ? $k : 0;
1730
+		}
1731
+				if (empty($currentKey)) {
1732
+									$currentKey = $v == $row['value'] ? $k : 0;
1733
+				}
1655 1734
 			}
1656 1735
 
1657 1736
 		// BBC?
1658
-		if (!empty($row['bbc']))
1659
-			$row['value'] = parse_bbc($row['value']);
1737
+		if (!empty($row['bbc'])) {
1738
+					$row['value'] = parse_bbc($row['value']);
1739
+		}
1660 1740
 
1661 1741
 		// ... or checkbox?
1662
-		elseif (isset($row['type']) && $row['type'] == 'check')
1663
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1742
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1743
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1744
+		}
1664 1745
 
1665 1746
 		// Enclosing the user input within some other text?
1666
-		if (!empty($row['enclose']))
1667
-			$row['value'] = strtr($row['enclose'], array(
1747
+		if (!empty($row['enclose'])) {
1748
+					$row['value'] = strtr($row['enclose'], array(
1668 1749
 				'{SCRIPTURL}' => $scripturl,
1669 1750
 				'{IMAGES_URL}' => $settings['images_url'],
1670 1751
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1671 1752
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1672 1753
 				'{KEY}' => $currentKey,
1673 1754
 			));
1755
+		}
1674 1756
 
1675 1757
 		// Send a simple array if there is just 1 param
1676
-		if (count($params) == 1)
1677
-			$return[$row['id_member']] = $row;
1758
+		if (count($params) == 1) {
1759
+					$return[$row['id_member']] = $row;
1760
+		}
1678 1761
 
1679 1762
 		// More than 1? knock yourself out...
1680 1763
 		else
1681 1764
 		{
1682
-			if (!isset($return[$row['id_member']]))
1683
-				$return[$row['id_member']] = array();
1765
+			if (!isset($return[$row['id_member']])) {
1766
+							$return[$row['id_member']] = array();
1767
+			}
1684 1768
 
1685 1769
 			$return[$row['id_member']][$row['variable']] = $row;
1686 1770
 		}
@@ -1714,8 +1798,9 @@  discard block
 block discarded – undo
1714 1798
 	global $context;
1715 1799
 
1716 1800
 	// Don't know any browser!
1717
-	if (empty($context['browser']))
1718
-		detectBrowser();
1801
+	if (empty($context['browser'])) {
1802
+			detectBrowser();
1803
+	}
1719 1804
 
1720 1805
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1721 1806
 }
@@ -1733,8 +1818,9 @@  discard block
 block discarded – undo
1733 1818
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1734 1819
 
1735 1820
 	// The theme was specified by parameter.
1736
-	if (!empty($id_theme))
1737
-		$id_theme = (int) $id_theme;
1821
+	if (!empty($id_theme)) {
1822
+			$id_theme = (int) $id_theme;
1823
+	}
1738 1824
 	// The theme was specified by REQUEST.
1739 1825
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1740 1826
 	{
@@ -1742,32 +1828,38 @@  discard block
 block discarded – undo
1742 1828
 		$_SESSION['id_theme'] = $id_theme;
1743 1829
 	}
1744 1830
 	// The theme was specified by REQUEST... previously.
1745
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1746
-		$id_theme = (int) $_SESSION['id_theme'];
1831
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1832
+			$id_theme = (int) $_SESSION['id_theme'];
1833
+	}
1747 1834
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1748
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1749
-		$id_theme = $user_info['theme'];
1835
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1836
+			$id_theme = $user_info['theme'];
1837
+	}
1750 1838
 	// The theme was specified by the board.
1751
-	elseif (!empty($board_info['theme']))
1752
-		$id_theme = $board_info['theme'];
1839
+	elseif (!empty($board_info['theme'])) {
1840
+			$id_theme = $board_info['theme'];
1841
+	}
1753 1842
 	// The theme is the forum's default.
1754
-	else
1755
-		$id_theme = $modSettings['theme_guests'];
1843
+	else {
1844
+			$id_theme = $modSettings['theme_guests'];
1845
+	}
1756 1846
 
1757 1847
 	// Verify the id_theme... no foul play.
1758 1848
 	// Always allow the board specific theme, if they are overriding.
1759
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1760
-		$id_theme = $board_info['theme'];
1849
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1850
+			$id_theme = $board_info['theme'];
1851
+	}
1761 1852
 	// If they have specified a particular theme to use with SSI allow it to be used.
1762
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1763
-		$id_theme = (int) $id_theme;
1764
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1853
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1854
+			$id_theme = (int) $id_theme;
1855
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1765 1856
 	{
1766 1857
 		$themes = explode(',', $modSettings['enableThemes']);
1767
-		if (!in_array($id_theme, $themes))
1768
-			$id_theme = $modSettings['theme_guests'];
1769
-		else
1770
-			$id_theme = (int) $id_theme;
1858
+		if (!in_array($id_theme, $themes)) {
1859
+					$id_theme = $modSettings['theme_guests'];
1860
+		} else {
1861
+					$id_theme = (int) $id_theme;
1862
+		}
1771 1863
 	}
1772 1864
 		
1773 1865
 	// Allow mod authors the option to override the theme id for custom page themes
@@ -1779,18 +1871,19 @@  discard block
 block discarded – undo
1779 1871
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1780 1872
 
1781 1873
 		// Disable image proxy if we don't have SSL enabled
1782
-		if (empty($modSettings['force_ssl']))
1783
-			$image_proxy_enabled = false;
1874
+		if (empty($modSettings['force_ssl'])) {
1875
+					$image_proxy_enabled = false;
1876
+		}
1784 1877
 
1785 1878
 		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'])
1786 1879
 		{
1787 1880
 			$themeData = $temp;
1788 1881
 			$flag = true;
1882
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1883
+					$themeData = $temp + array($member => array());
1884
+		} else {
1885
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1789 1886
 		}
1790
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1791
-			$themeData = $temp + array($member => array());
1792
-		else
1793
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1794 1887
 
1795 1888
 		if (empty($flag))
1796 1889
 		{
@@ -1810,31 +1903,37 @@  discard block
 block discarded – undo
1810 1903
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1811 1904
 			{
1812 1905
 				// There are just things we shouldn't be able to change as members.
1813
-				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')))
1814
-					continue;
1906
+				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'))) {
1907
+									continue;
1908
+				}
1815 1909
 
1816 1910
 				// If this is the theme_dir of the default theme, store it.
1817
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1818
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1911
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1912
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1913
+				}
1819 1914
 
1820 1915
 				// If this isn't set yet, is a theme option, or is not the default theme..
1821
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1822
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1916
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1917
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1918
+				}
1823 1919
 			}
1824 1920
 			$smcFunc['db_free_result']($result);
1825 1921
 
1826
-			if (!empty($themeData[-1]))
1827
-				foreach ($themeData[-1] as $k => $v)
1922
+			if (!empty($themeData[-1])) {
1923
+							foreach ($themeData[-1] as $k => $v)
1828 1924
 				{
1829 1925
 					if (!isset($themeData[$member][$k]))
1830 1926
 						$themeData[$member][$k] = $v;
1927
+			}
1831 1928
 				}
1832 1929
 
1833
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1834
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1930
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1931
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1932
+			}
1835 1933
 			// Only if we didn't already load that part of the cache...
1836
-			elseif (!isset($temp))
1837
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1934
+			elseif (!isset($temp)) {
1935
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1936
+			}
1838 1937
 		}
1839 1938
 
1840 1939
 		$settings = $themeData[0];
@@ -1851,17 +1950,20 @@  discard block
 block discarded – undo
1851 1950
 		$settings['template_dirs'][] = $settings['theme_dir'];
1852 1951
 
1853 1952
 		// Based on theme (if there is one).
1854
-		if (!empty($settings['base_theme_dir']))
1855
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1953
+		if (!empty($settings['base_theme_dir'])) {
1954
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1955
+		}
1856 1956
 
1857 1957
 		// Lastly the default theme.
1858
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1859
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1958
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1959
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1960
+		}
1860 1961
 	}
1861 1962
 
1862 1963
 
1863
-	if (!$initialize)
1864
-		return;
1964
+	if (!$initialize) {
1965
+			return;
1966
+	}
1865 1967
 
1866 1968
 	// Check to see if we're forcing SSL
1867 1969
 	if (!empty($modSettings['force_ssl']) && empty($maintenance) &&
@@ -1882,8 +1984,9 @@  discard block
 block discarded – undo
1882 1984
 		$detected_url = httpsOn() ? 'https://' : 'http://';
1883 1985
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1884 1986
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1885
-		if ($temp != '/')
1886
-			$detected_url .= $temp;
1987
+		if ($temp != '/') {
1988
+					$detected_url .= $temp;
1989
+		}
1887 1990
 	}
1888 1991
 	if (isset($detected_url) && $detected_url != $boardurl)
1889 1992
 	{
@@ -1895,8 +1998,9 @@  discard block
 block discarded – undo
1895 1998
 			foreach ($aliases as $alias)
1896 1999
 			{
1897 2000
 				// Rip off all the boring parts, spaces, etc.
1898
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1899
-					$do_fix = true;
2001
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
2002
+									$do_fix = true;
2003
+				}
1900 2004
 			}
1901 2005
 		}
1902 2006
 
@@ -1904,21 +2008,23 @@  discard block
 block discarded – undo
1904 2008
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1905 2009
 		{
1906 2010
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1907
-			if (empty($_GET))
1908
-				redirectexit('wwwRedirect');
1909
-			else
2011
+			if (empty($_GET)) {
2012
+							redirectexit('wwwRedirect');
2013
+			} else
1910 2014
 			{
1911 2015
 				$k = key($_GET);
1912 2016
 				$v = current($_GET);
1913 2017
 
1914
-				if ($k != 'wwwRedirect')
1915
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
2018
+				if ($k != 'wwwRedirect') {
2019
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
2020
+				}
1916 2021
 			}
1917 2022
 		}
1918 2023
 
1919 2024
 		// #3 is just a check for SSL...
1920
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1921
-			$do_fix = true;
2025
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
2026
+					$do_fix = true;
2027
+		}
1922 2028
 
1923 2029
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1924 2030
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1953,8 +2059,9 @@  discard block
 block discarded – undo
1953 2059
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1954 2060
 				}
1955 2061
 			}
1956
-			foreach ($context['linktree'] as $k => $dummy)
1957
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2062
+			foreach ($context['linktree'] as $k => $dummy) {
2063
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2064
+			}
1958 2065
 		}
1959 2066
 	}
1960 2067
 	// Set up the contextual user array.
@@ -1973,10 +2080,11 @@  discard block
 block discarded – undo
1973 2080
 			'email' => $user_info['email'],
1974 2081
 			'ignoreusers' => $user_info['ignoreusers'],
1975 2082
 		);
1976
-		if (!$context['user']['is_guest'])
1977
-			$context['user']['name'] = $user_info['name'];
1978
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1979
-			$context['user']['name'] = $txt['guest_title'];
2083
+		if (!$context['user']['is_guest']) {
2084
+					$context['user']['name'] = $user_info['name'];
2085
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2086
+					$context['user']['name'] = $txt['guest_title'];
2087
+		}
1980 2088
 
1981 2089
 		// Determine the current smiley set.
1982 2090
 		$smiley_sets_known = explode(',', $modSettings['smiley_sets_known']);
@@ -1990,8 +2098,7 @@  discard block
 block discarded – undo
1990 2098
 
1991 2099
 		// Determine global default smiley set extension
1992 2100
 		$context['user']['smiley_set_default_ext'] = $smiley_sets_exts[array_search($modSettings['smiley_sets_default'], $smiley_sets_known)];
1993
-	}
1994
-	else
2101
+	} else
1995 2102
 	{
1996 2103
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1997 2104
 		$context['user'] = array(
@@ -2025,18 +2132,24 @@  discard block
 block discarded – undo
2025 2132
 	}
2026 2133
 
2027 2134
 	// Some basic information...
2028
-	if (!isset($context['html_headers']))
2029
-		$context['html_headers'] = '';
2030
-	if (!isset($context['javascript_files']))
2031
-		$context['javascript_files'] = array();
2032
-	if (!isset($context['css_files']))
2033
-		$context['css_files'] = array();
2034
-	if (!isset($context['css_header']))
2035
-		$context['css_header'] = array();
2036
-	if (!isset($context['javascript_inline']))
2037
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2038
-	if (!isset($context['javascript_vars']))
2039
-		$context['javascript_vars'] = array();
2135
+	if (!isset($context['html_headers'])) {
2136
+			$context['html_headers'] = '';
2137
+	}
2138
+	if (!isset($context['javascript_files'])) {
2139
+			$context['javascript_files'] = array();
2140
+	}
2141
+	if (!isset($context['css_files'])) {
2142
+			$context['css_files'] = array();
2143
+	}
2144
+	if (!isset($context['css_header'])) {
2145
+			$context['css_header'] = array();
2146
+	}
2147
+	if (!isset($context['javascript_inline'])) {
2148
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2149
+	}
2150
+	if (!isset($context['javascript_vars'])) {
2151
+			$context['javascript_vars'] = array();
2152
+	}
2040 2153
 
2041 2154
 	$context['login_url'] =  $scripturl . '?action=login2';
2042 2155
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -2048,16 +2161,18 @@  discard block
 block discarded – undo
2048 2161
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
2049 2162
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
2050 2163
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
2051
-	if (isset($modSettings['load_average']))
2052
-		$context['load_average'] = $modSettings['load_average'];
2164
+	if (isset($modSettings['load_average'])) {
2165
+			$context['load_average'] = $modSettings['load_average'];
2166
+	}
2053 2167
 
2054 2168
 	// Detect the browser. This is separated out because it's also used in attachment downloads
2055 2169
 	detectBrowser();
2056 2170
 
2057 2171
 	// Set the top level linktree up.
2058 2172
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2059
-	if (empty($context['linktree']))
2060
-		$context['linktree'] = array();
2173
+	if (empty($context['linktree'])) {
2174
+			$context['linktree'] = array();
2175
+	}
2061 2176
 	array_unshift($context['linktree'], array(
2062 2177
 		'url' => $scripturl,
2063 2178
 		'name' => $context['forum_name_html_safe']
@@ -2066,8 +2181,9 @@  discard block
 block discarded – undo
2066 2181
 	// This allows sticking some HTML on the page output - useful for controls.
2067 2182
 	$context['insert_after_template'] = '';
2068 2183
 
2069
-	if (!isset($txt))
2070
-		$txt = array();
2184
+	if (!isset($txt)) {
2185
+			$txt = array();
2186
+	}
2071 2187
 
2072 2188
 	$simpleActions = array(
2073 2189
 		'findmember',
@@ -2113,9 +2229,10 @@  discard block
 block discarded – undo
2113 2229
 
2114 2230
 	// See if theres any extra param to check.
2115 2231
 	$requiresXML = false;
2116
-	foreach ($extraParams as $key => $extra)
2117
-		if (isset($_REQUEST[$extra]))
2232
+	foreach ($extraParams as $key => $extra) {
2233
+			if (isset($_REQUEST[$extra]))
2118 2234
 			$requiresXML = true;
2235
+	}
2119 2236
 
2120 2237
 	// Output is fully XML, so no need for the index template.
2121 2238
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2130,37 +2247,39 @@  discard block
 block discarded – undo
2130 2247
 	{
2131 2248
 		loadLanguage('index+Modifications');
2132 2249
 		$context['template_layers'] = array();
2133
-	}
2134
-
2135
-	else
2250
+	} else
2136 2251
 	{
2137 2252
 		// Custom templates to load, or just default?
2138
-		if (isset($settings['theme_templates']))
2139
-			$templates = explode(',', $settings['theme_templates']);
2140
-		else
2141
-			$templates = array('index');
2253
+		if (isset($settings['theme_templates'])) {
2254
+					$templates = explode(',', $settings['theme_templates']);
2255
+		} else {
2256
+					$templates = array('index');
2257
+		}
2142 2258
 
2143 2259
 		// Load each template...
2144
-		foreach ($templates as $template)
2145
-			loadTemplate($template);
2260
+		foreach ($templates as $template) {
2261
+					loadTemplate($template);
2262
+		}
2146 2263
 
2147 2264
 		// ...and attempt to load their associated language files.
2148 2265
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2149 2266
 		loadLanguage($required_files, '', false);
2150 2267
 
2151 2268
 		// Custom template layers?
2152
-		if (isset($settings['theme_layers']))
2153
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2154
-		else
2155
-			$context['template_layers'] = array('html', 'body');
2269
+		if (isset($settings['theme_layers'])) {
2270
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2271
+		} else {
2272
+					$context['template_layers'] = array('html', 'body');
2273
+		}
2156 2274
 	}
2157 2275
 
2158 2276
 	// Initialize the theme.
2159 2277
 	loadSubTemplate('init', 'ignore');
2160 2278
 
2161 2279
 	// Allow overriding the board wide time/number formats.
2162
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2163
-		$user_info['time_format'] = $txt['time_format'];
2280
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2281
+			$user_info['time_format'] = $txt['time_format'];
2282
+	}
2164 2283
 
2165 2284
 	// Set the character set from the template.
2166 2285
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2168,12 +2287,14 @@  discard block
 block discarded – undo
2168 2287
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2169 2288
 
2170 2289
 	// Guests may still need a name.
2171
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2172
-		$context['user']['name'] = $txt['guest_title'];
2290
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2291
+			$context['user']['name'] = $txt['guest_title'];
2292
+	}
2173 2293
 
2174 2294
 	// Any theme-related strings that need to be loaded?
2175
-	if (!empty($settings['require_theme_strings']))
2176
-		loadLanguage('ThemeStrings', '', false);
2295
+	if (!empty($settings['require_theme_strings'])) {
2296
+			loadLanguage('ThemeStrings', '', false);
2297
+	}
2177 2298
 
2178 2299
 	// Make a special URL for the language.
2179 2300
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2184,8 +2305,9 @@  discard block
 block discarded – undo
2184 2305
 	// Here is my luvly Responsive CSS
2185 2306
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive');
2186 2307
 
2187
-	if ($context['right_to_left'])
2188
-		loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2308
+	if ($context['right_to_left']) {
2309
+			loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2310
+	}
2189 2311
 
2190 2312
 	// We allow theme variants, because we're cool.
2191 2313
 	$context['theme_variant'] = '';
@@ -2193,14 +2315,17 @@  discard block
 block discarded – undo
2193 2315
 	if (!empty($settings['theme_variants']))
2194 2316
 	{
2195 2317
 		// Overriding - for previews and that ilk.
2196
-		if (!empty($_REQUEST['variant']))
2197
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2318
+		if (!empty($_REQUEST['variant'])) {
2319
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2320
+		}
2198 2321
 		// User selection?
2199
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2200
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2322
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2323
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2324
+		}
2201 2325
 		// If not a user variant, select the default.
2202
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2203
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2326
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2327
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2328
+		}
2204 2329
 
2205 2330
 		// Do this to keep things easier in the templates.
2206 2331
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2209,20 +2334,23 @@  discard block
 block discarded – undo
2209 2334
 		if (!empty($context['theme_variant']))
2210 2335
 		{
2211 2336
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']);
2212
-			if ($context['right_to_left'])
2213
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2337
+			if ($context['right_to_left']) {
2338
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2339
+			}
2214 2340
 		}
2215 2341
 	}
2216 2342
 
2217 2343
 	// Let's be compatible with old themes!
2218
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2219
-		$context['template_layers'] = array('main');
2344
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2345
+			$context['template_layers'] = array('main');
2346
+	}
2220 2347
 
2221 2348
 	$context['tabindex'] = 1;
2222 2349
 
2223 2350
 	// Compatibility.
2224
-	if (!isset($settings['theme_version']))
2225
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2351
+	if (!isset($settings['theme_version'])) {
2352
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2353
+	}
2226 2354
 
2227 2355
 	// Default JS variables for use in every theme
2228 2356
 	$context['javascript_vars'] = array(
@@ -2245,18 +2373,18 @@  discard block
 block discarded – undo
2245 2373
 	);
2246 2374
 
2247 2375
 	// Add the JQuery library to the list of files to load.
2248
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2249
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2250
-
2251
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2252
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2253
-
2254
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2255
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2376
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2377
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2378
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2379
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2380
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2381
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2382
+	}
2256 2383
 
2257 2384
 	// Auto loading? template_javascript() will take care of the local half of this.
2258
-	else
2259
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2385
+	else {
2386
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2387
+	}
2260 2388
 
2261 2389
 	// Queue our JQuery plugins!
2262 2390
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2279,12 +2407,12 @@  discard block
 block discarded – undo
2279 2407
 			require_once($sourcedir . '/ScheduledTasks.php');
2280 2408
 
2281 2409
 			// What to do, what to do?!
2282
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2283
-				AutoTask();
2284
-			else
2285
-				ReduceMailQueue();
2286
-		}
2287
-		else
2410
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2411
+							AutoTask();
2412
+			} else {
2413
+							ReduceMailQueue();
2414
+			}
2415
+		} else
2288 2416
 		{
2289 2417
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2290 2418
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2335,8 +2463,9 @@  discard block
 block discarded – undo
2335 2463
 		foreach ($theme_includes as $include)
2336 2464
 		{
2337 2465
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2338
-			if (file_exists($include))
2339
-				require_once($include);
2466
+			if (file_exists($include)) {
2467
+							require_once($include);
2468
+			}
2340 2469
 		}
2341 2470
 	}
2342 2471
 
@@ -2366,16 +2495,19 @@  discard block
 block discarded – undo
2366 2495
 	// Do any style sheets first, cause we're easy with those.
2367 2496
 	if (!empty($style_sheets))
2368 2497
 	{
2369
-		if (!is_array($style_sheets))
2370
-			$style_sheets = array($style_sheets);
2498
+		if (!is_array($style_sheets)) {
2499
+					$style_sheets = array($style_sheets);
2500
+		}
2371 2501
 
2372
-		foreach ($style_sheets as $sheet)
2373
-			loadCSSFile($sheet . '.css', array(), $sheet);
2502
+		foreach ($style_sheets as $sheet) {
2503
+					loadCSSFile($sheet . '.css', array(), $sheet);
2504
+		}
2374 2505
 	}
2375 2506
 
2376 2507
 	// No template to load?
2377
-	if ($template_name === false)
2378
-		return true;
2508
+	if ($template_name === false) {
2509
+			return true;
2510
+	}
2379 2511
 
2380 2512
 	$loaded = false;
2381 2513
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2390,12 +2522,14 @@  discard block
 block discarded – undo
2390 2522
 
2391 2523
 	if ($loaded)
2392 2524
 	{
2393
-		if ($db_show_debug === true)
2394
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2525
+		if ($db_show_debug === true) {
2526
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2527
+		}
2395 2528
 
2396 2529
 		// If they have specified an initialization function for this template, go ahead and call it now.
2397
-		if (function_exists('template_' . $template_name . '_init'))
2398
-			call_user_func('template_' . $template_name . '_init');
2530
+		if (function_exists('template_' . $template_name . '_init')) {
2531
+					call_user_func('template_' . $template_name . '_init');
2532
+		}
2399 2533
 	}
2400 2534
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2401 2535
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2415,13 +2549,14 @@  discard block
 block discarded – undo
2415 2549
 		loadTemplate($template_name);
2416 2550
 	}
2417 2551
 	// Cause an error otherwise.
2418
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2419
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2420
-	elseif ($fatal)
2421
-		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'));
2422
-	else
2423
-		return false;
2424
-}
2552
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2553
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2554
+	} elseif ($fatal) {
2555
+			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'));
2556
+	} else {
2557
+			return false;
2558
+	}
2559
+	}
2425 2560
 
2426 2561
 /**
2427 2562
  * Load a sub-template.
@@ -2439,17 +2574,19 @@  discard block
 block discarded – undo
2439 2574
 {
2440 2575
 	global $context, $txt, $db_show_debug;
2441 2576
 
2442
-	if ($db_show_debug === true)
2443
-		$context['debug']['sub_templates'][] = $sub_template_name;
2577
+	if ($db_show_debug === true) {
2578
+			$context['debug']['sub_templates'][] = $sub_template_name;
2579
+	}
2444 2580
 
2445 2581
 	// Figure out what the template function is named.
2446 2582
 	$theme_function = 'template_' . $sub_template_name;
2447
-	if (function_exists($theme_function))
2448
-		$theme_function();
2449
-	elseif ($fatal === false)
2450
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2451
-	elseif ($fatal !== 'ignore')
2452
-		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'));
2583
+	if (function_exists($theme_function)) {
2584
+			$theme_function();
2585
+	} elseif ($fatal === false) {
2586
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2587
+	} elseif ($fatal !== 'ignore') {
2588
+			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'));
2589
+	}
2453 2590
 
2454 2591
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2455 2592
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2479,8 +2616,9 @@  discard block
 block discarded – undo
2479 2616
 {
2480 2617
 	global $settings, $context, $modSettings;
2481 2618
 
2482
-	if (empty($context['css_files_order']))
2483
-		$context['css_files_order'] = array();
2619
+	if (empty($context['css_files_order'])) {
2620
+			$context['css_files_order'] = array();
2621
+	}
2484 2622
 
2485 2623
 	$params['seed'] = (!array_key_exists('seed', $params) || (array_key_exists('seed', $params) && $params['seed'] === true)) ? (array_key_exists('browser_cache', $modSettings) ? $modSettings['browser_cache'] : '') : (is_string($params['seed']) ? ($params['seed'] = $params['seed'][0] === '?' ? $params['seed'] : '?' . $params['seed']) : '');
2486 2624
 	$params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false;
@@ -2491,8 +2629,9 @@  discard block
 block discarded – undo
2491 2629
 	$params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000;
2492 2630
 
2493 2631
 	// If this is an external file, automatically set this to false.
2494
-	if (!empty($params['external']))
2495
-		$params['minimize'] = false;
2632
+	if (!empty($params['external'])) {
2633
+			$params['minimize'] = false;
2634
+	}
2496 2635
 
2497 2636
 	// Account for shorthand like admin.css?alp21 filenames
2498 2637
 	$has_seed = strpos($fileName, '.css?');
@@ -2509,16 +2648,12 @@  discard block
 block discarded – undo
2509 2648
 			{
2510 2649
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2511 2650
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2512
-			}
2513
-
2514
-			else
2651
+			} else
2515 2652
 			{
2516 2653
 				$fileUrl = false;
2517 2654
 				$filePath = false;
2518 2655
 			}
2519
-		}
2520
-
2521
-		else
2656
+		} else
2522 2657
 		{
2523 2658
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2524 2659
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2536,16 +2671,18 @@  discard block
 block discarded – undo
2536 2671
 	if (!empty($fileName))
2537 2672
 	{
2538 2673
 		// find a free number/position
2539
-		while (isset($context['css_files_order'][$params['order_pos']]))
2540
-			$params['order_pos']++;
2674
+		while (isset($context['css_files_order'][$params['order_pos']])) {
2675
+					$params['order_pos']++;
2676
+		}
2541 2677
 		$context['css_files_order'][$params['order_pos']] = $id;
2542 2678
 
2543 2679
 		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2544 2680
 	}
2545 2681
 
2546
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2547
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2548
-}
2682
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2683
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2684
+	}
2685
+	}
2549 2686
 
2550 2687
 /**
2551 2688
  * Add a block of inline css code to be executed later
@@ -2562,8 +2699,9 @@  discard block
 block discarded – undo
2562 2699
 	global $context;
2563 2700
 
2564 2701
 	// Gotta add something...
2565
-	if (empty($css))
2566
-		return false;
2702
+	if (empty($css)) {
2703
+			return false;
2704
+	}
2567 2705
 
2568 2706
 	$context['css_header'][] = $css;
2569 2707
 }
@@ -2599,8 +2737,9 @@  discard block
 block discarded – undo
2599 2737
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2600 2738
 
2601 2739
 	// If this is an external file, automatically set this to false.
2602
-	if (!empty($params['external']))
2603
-		$params['minimize'] = false;
2740
+	if (!empty($params['external'])) {
2741
+			$params['minimize'] = false;
2742
+	}
2604 2743
 
2605 2744
 	// Account for shorthand like admin.js?alp21 filenames
2606 2745
 	$has_seed = strpos($fileName, '.js?');
@@ -2617,16 +2756,12 @@  discard block
 block discarded – undo
2617 2756
 			{
2618 2757
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2619 2758
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2620
-			}
2621
-
2622
-			else
2759
+			} else
2623 2760
 			{
2624 2761
 				$fileUrl = false;
2625 2762
 				$filePath = false;
2626 2763
 			}
2627
-		}
2628
-
2629
-		else
2764
+		} else
2630 2765
 		{
2631 2766
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2632 2767
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2641,9 +2776,10 @@  discard block
 block discarded – undo
2641 2776
 	}
2642 2777
 
2643 2778
 	// Add it to the array for use in the template
2644
-	if (!empty($fileName))
2645
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2646
-}
2779
+	if (!empty($fileName)) {
2780
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2781
+	}
2782
+	}
2647 2783
 
2648 2784
 /**
2649 2785
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2657,9 +2793,10 @@  discard block
 block discarded – undo
2657 2793
 {
2658 2794
 	global $context;
2659 2795
 
2660
-	if (!empty($key) && (!empty($value) || $value === '0'))
2661
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2662
-}
2796
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2797
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2798
+	}
2799
+	}
2663 2800
 
2664 2801
 /**
2665 2802
  * Add a block of inline Javascript code to be executed later
@@ -2676,8 +2813,9 @@  discard block
 block discarded – undo
2676 2813
 {
2677 2814
 	global $context;
2678 2815
 
2679
-	if (empty($javascript))
2680
-		return false;
2816
+	if (empty($javascript)) {
2817
+			return false;
2818
+	}
2681 2819
 
2682 2820
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2683 2821
 }
@@ -2698,15 +2836,18 @@  discard block
 block discarded – undo
2698 2836
 	static $already_loaded = array();
2699 2837
 
2700 2838
 	// Default to the user's language.
2701
-	if ($lang == '')
2702
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2839
+	if ($lang == '') {
2840
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2841
+	}
2703 2842
 
2704 2843
 	// Do we want the English version of language file as fallback?
2705
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2706
-		loadLanguage($template_name, 'english', false);
2844
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2845
+			loadLanguage($template_name, 'english', false);
2846
+	}
2707 2847
 
2708
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2709
-		return $lang;
2848
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2849
+			return $lang;
2850
+	}
2710 2851
 
2711 2852
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2712 2853
 	if (empty($settings['default_theme_dir']))
@@ -2717,8 +2858,9 @@  discard block
 block discarded – undo
2717 2858
 
2718 2859
 	// What theme are we in?
2719 2860
 	$theme_name = basename($settings['theme_url']);
2720
-	if (empty($theme_name))
2721
-		$theme_name = 'unknown';
2861
+	if (empty($theme_name)) {
2862
+			$theme_name = 'unknown';
2863
+	}
2722 2864
 
2723 2865
 	// For each file open it up and write it out!
2724 2866
 	foreach (explode('+', $template_name) as $template)
@@ -2760,8 +2902,9 @@  discard block
 block discarded – undo
2760 2902
 				$found = true;
2761 2903
 
2762 2904
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2763
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2764
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2905
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2906
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2907
+				}
2765 2908
 
2766 2909
 				break;
2767 2910
 			}
@@ -2801,8 +2944,9 @@  discard block
 block discarded – undo
2801 2944
 	}
2802 2945
 
2803 2946
 	// Keep track of what we're up to soldier.
2804
-	if ($db_show_debug === true)
2805
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2947
+	if ($db_show_debug === true) {
2948
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2949
+	}
2806 2950
 
2807 2951
 	// Remember what we have loaded, and in which language.
2808 2952
 	$already_loaded[$template_name] = $lang;
@@ -2848,8 +2992,9 @@  discard block
 block discarded – undo
2848 2992
 				)
2849 2993
 			);
2850 2994
 			// In the EXTREMELY unlikely event this happens, give an error message.
2851
-			if ($smcFunc['db_num_rows']($result) == 0)
2852
-				fatal_lang_error('parent_not_found', 'critical');
2995
+			if ($smcFunc['db_num_rows']($result) == 0) {
2996
+							fatal_lang_error('parent_not_found', 'critical');
2997
+			}
2853 2998
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2854 2999
 			{
2855 3000
 				if (!isset($boards[$row['id_board']]))
@@ -2866,8 +3011,8 @@  discard block
 block discarded – undo
2866 3011
 					);
2867 3012
 				}
2868 3013
 				// If a moderator exists for this board, add that moderator for all children too.
2869
-				if (!empty($row['id_moderator']))
2870
-					foreach ($boards as $id => $dummy)
3014
+				if (!empty($row['id_moderator'])) {
3015
+									foreach ($boards as $id => $dummy)
2871 3016
 					{
2872 3017
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2873 3018
 							'id' => $row['id_moderator'],
@@ -2875,11 +3020,12 @@  discard block
 block discarded – undo
2875 3020
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2876 3021
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2877 3022
 						);
3023
+				}
2878 3024
 					}
2879 3025
 
2880 3026
 				// If a moderator group exists for this board, add that moderator group for all children too
2881
-				if (!empty($row['id_moderator_group']))
2882
-					foreach ($boards as $id => $dummy)
3027
+				if (!empty($row['id_moderator_group'])) {
3028
+									foreach ($boards as $id => $dummy)
2883 3029
 					{
2884 3030
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2885 3031
 							'id' => $row['id_moderator_group'],
@@ -2887,6 +3033,7 @@  discard block
 block discarded – undo
2887 3033
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2888 3034
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2889 3035
 						);
3036
+				}
2890 3037
 					}
2891 3038
 			}
2892 3039
 			$smcFunc['db_free_result']($result);
@@ -2913,23 +3060,27 @@  discard block
 block discarded – undo
2913 3060
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2914 3061
 	{
2915 3062
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2916
-		if (empty($smcFunc['ucwords']))
2917
-			reloadSettings();
3063
+		if (empty($smcFunc['ucwords'])) {
3064
+					reloadSettings();
3065
+		}
2918 3066
 
2919 3067
 		// If we don't have our theme information yet, let's get it.
2920
-		if (empty($settings['default_theme_dir']))
2921
-			loadTheme(0, false);
3068
+		if (empty($settings['default_theme_dir'])) {
3069
+					loadTheme(0, false);
3070
+		}
2922 3071
 
2923 3072
 		// Default language directories to try.
2924 3073
 		$language_directories = array(
2925 3074
 			$settings['default_theme_dir'] . '/languages',
2926 3075
 		);
2927
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2928
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3076
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
3077
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3078
+		}
2929 3079
 
2930 3080
 		// We possibly have a base theme directory.
2931
-		if (!empty($settings['base_theme_dir']))
2932
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3081
+		if (!empty($settings['base_theme_dir'])) {
3082
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3083
+		}
2933 3084
 
2934 3085
 		// Remove any duplicates.
2935 3086
 		$language_directories = array_unique($language_directories);
@@ -2943,20 +3094,21 @@  discard block
 block discarded – undo
2943 3094
 		foreach ($language_directories as $language_dir)
2944 3095
 		{
2945 3096
 			// Can't look in here... doesn't exist!
2946
-			if (!file_exists($language_dir))
2947
-				continue;
3097
+			if (!file_exists($language_dir)) {
3098
+							continue;
3099
+			}
2948 3100
 
2949 3101
 			$dir = dir($language_dir);
2950 3102
 			while ($entry = $dir->read())
2951 3103
 			{
2952 3104
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2953
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2954
-					continue;
2955
-
2956
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2957
-					$langName = $langList[$matches[1]];
3105
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3106
+									continue;
3107
+				}
2958 3108
 
2959
-				else
3109
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3110
+									$langName = $langList[$matches[1]];
3111
+				} else
2960 3112
 				{
2961 3113
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2962 3114
 
@@ -2997,12 +3149,14 @@  discard block
 block discarded – undo
2997 3149
 		}
2998 3150
 
2999 3151
 		// Do we need to store the lang list?
3000
-		if (empty($langList))
3001
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3152
+		if (empty($langList)) {
3153
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3154
+		}
3002 3155
 
3003 3156
 		// Let's cash in on this deal.
3004
-		if (!empty($modSettings['cache_enable']))
3005
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3157
+		if (!empty($modSettings['cache_enable'])) {
3158
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3159
+		}
3006 3160
 	}
3007 3161
 
3008 3162
 	return $context['languages'];
@@ -3025,8 +3179,9 @@  discard block
 block discarded – undo
3025 3179
 	global $modSettings, $options, $txt;
3026 3180
 	static $censor_vulgar = null, $censor_proper;
3027 3181
 
3028
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
3029
-		return $text;
3182
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3183
+			return $text;
3184
+	}
3030 3185
 
3031 3186
 	// If they haven't yet been loaded, load them.
3032 3187
 	if ($censor_vulgar == null)
@@ -3057,9 +3212,9 @@  discard block
 block discarded – undo
3057 3212
 	{
3058 3213
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
3059 3214
 		$text = $func($censor_vulgar, $censor_proper, $text);
3215
+	} else {
3216
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
3060 3217
 	}
3061
-	else
3062
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
3063 3218
 
3064 3219
 	return $text;
3065 3220
 }
@@ -3085,30 +3240,35 @@  discard block
 block discarded – undo
3085 3240
 	@ini_set('track_errors', '1');
3086 3241
 
3087 3242
 	// Don't include the file more than once, if $once is true.
3088
-	if ($once && in_array($filename, $templates))
3089
-		return;
3243
+	if ($once && in_array($filename, $templates)) {
3244
+			return;
3245
+	}
3090 3246
 	// Add this file to the include list, whether $once is true or not.
3091
-	else
3092
-		$templates[] = $filename;
3247
+	else {
3248
+			$templates[] = $filename;
3249
+	}
3093 3250
 
3094 3251
 
3095 3252
 	$file_found = file_exists($filename);
3096 3253
 
3097
-	if ($once && $file_found)
3098
-		require_once($filename);
3099
-	elseif ($file_found)
3100
-		require($filename);
3254
+	if ($once && $file_found) {
3255
+			require_once($filename);
3256
+	} elseif ($file_found) {
3257
+			require($filename);
3258
+	}
3101 3259
 
3102 3260
 	if ($file_found !== true)
3103 3261
 	{
3104 3262
 		ob_end_clean();
3105
-		if (!empty($modSettings['enableCompressedOutput']))
3106
-			@ob_start('ob_gzhandler');
3107
-		else
3108
-			ob_start();
3263
+		if (!empty($modSettings['enableCompressedOutput'])) {
3264
+					@ob_start('ob_gzhandler');
3265
+		} else {
3266
+					ob_start();
3267
+		}
3109 3268
 
3110
-		if (isset($_GET['debug']))
3111
-			header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3269
+		if (isset($_GET['debug'])) {
3270
+					header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3271
+		}
3112 3272
 
3113 3273
 		// Don't cache error pages!!
3114 3274
 		header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3127,12 +3287,13 @@  discard block
 block discarded – undo
3127 3287
 		echo '<!DOCTYPE html>
3128 3288
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3129 3289
 	<head>';
3130
-		if (isset($context['character_set']))
3131
-			echo '
3290
+		if (isset($context['character_set'])) {
3291
+					echo '
3132 3292
 		<meta charset="', $context['character_set'], '">';
3293
+		}
3133 3294
 
3134
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3135
-			echo '
3295
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3296
+					echo '
3136 3297
 		<title>', $mtitle, '</title>
3137 3298
 	</head>
3138 3299
 	<body>
@@ -3140,8 +3301,8 @@  discard block
 block discarded – undo
3140 3301
 		', $mmessage, '
3141 3302
 	</body>
3142 3303
 </html>';
3143
-		elseif (!allowedTo('admin_forum'))
3144
-			echo '
3304
+		} elseif (!allowedTo('admin_forum')) {
3305
+					echo '
3145 3306
 		<title>', $txt['template_parse_error'], '</title>
3146 3307
 	</head>
3147 3308
 	<body>
@@ -3149,14 +3310,16 @@  discard block
 block discarded – undo
3149 3310
 		', $txt['template_parse_error_message'], '
3150 3311
 	</body>
3151 3312
 </html>';
3152
-		else
3313
+		} else
3153 3314
 		{
3154 3315
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3155 3316
 			$error_array = error_get_last();
3156
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3157
-				$error = $error_array['message'];
3158
-			if (empty($error))
3159
-				$error = $txt['template_parse_errmsg'];
3317
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3318
+							$error = $error_array['message'];
3319
+			}
3320
+			if (empty($error)) {
3321
+							$error = $txt['template_parse_errmsg'];
3322
+			}
3160 3323
 
3161 3324
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3162 3325
 
@@ -3167,11 +3330,12 @@  discard block
 block discarded – undo
3167 3330
 		<h3>', $txt['template_parse_error'], '</h3>
3168 3331
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3169 3332
 
3170
-			if (!empty($error))
3171
-				echo '
3333
+			if (!empty($error)) {
3334
+							echo '
3172 3335
 		<hr>
3173 3336
 
3174 3337
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3338
+			}
3175 3339
 
3176 3340
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3177 3341
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3181,10 +3345,11 @@  discard block
 block discarded – undo
3181 3345
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3182 3346
 
3183 3347
 				// Fix the PHP code stuff...
3184
-				if (!isBrowser('gecko'))
3185
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3186
-				else
3187
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3348
+				if (!isBrowser('gecko')) {
3349
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3350
+				} else {
3351
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3352
+				}
3188 3353
 
3189 3354
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3190 3355
 				$j = -1;
@@ -3192,8 +3357,9 @@  discard block
 block discarded – undo
3192 3357
 				{
3193 3358
 					$j++;
3194 3359
 
3195
-					if (substr_count($line, '<br>') == 0)
3196
-						continue;
3360
+					if (substr_count($line, '<br>') == 0) {
3361
+											continue;
3362
+					}
3197 3363
 
3198 3364
 					$n = substr_count($line, '<br>');
3199 3365
 					for ($i = 0; $i < $n; $i++)
@@ -3212,38 +3378,42 @@  discard block
 block discarded – undo
3212 3378
 				// Figure out what the color coding was before...
3213 3379
 				$line = max($match[1] - 9, 1);
3214 3380
 				$last_line = '';
3215
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3216
-					if (strpos($data2[$line2], '<') !== false)
3381
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3382
+									if (strpos($data2[$line2], '<') !== false)
3217 3383
 					{
3218 3384
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3219 3385
 							$last_line = $color_match[1];
3386
+				}
3220 3387
 						break;
3221 3388
 					}
3222 3389
 
3223 3390
 				// Show the relevant lines...
3224 3391
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3225 3392
 				{
3226
-					if ($line == $match[1])
3227
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3393
+					if ($line == $match[1]) {
3394
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3395
+					}
3228 3396
 
3229 3397
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3230
-					if (isset($data2[$line]) && $data2[$line] != '')
3231
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3398
+					if (isset($data2[$line]) && $data2[$line] != '') {
3399
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3400
+					}
3232 3401
 
3233 3402
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3234 3403
 					{
3235 3404
 						$last_line = $color_match[1];
3236 3405
 						echo '</', substr($last_line, 1, 4), '>';
3406
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3407
+											$last_line = '';
3408
+					} elseif ($last_line != '' && $data2[$line] != '') {
3409
+											echo '</', substr($last_line, 1, 4), '>';
3237 3410
 					}
3238
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3239
-						$last_line = '';
3240
-					elseif ($last_line != '' && $data2[$line] != '')
3241
-						echo '</', substr($last_line, 1, 4), '>';
3242 3411
 
3243
-					if ($line == $match[1])
3244
-						echo '</pre></div><pre style="margin: 0;">';
3245
-					else
3246
-						echo "\n";
3412
+					if ($line == $match[1]) {
3413
+											echo '</pre></div><pre style="margin: 0;">';
3414
+					} else {
3415
+											echo "\n";
3416
+					}
3247 3417
 				}
3248 3418
 
3249 3419
 				echo '</pre></div>';
@@ -3267,8 +3437,9 @@  discard block
 block discarded – undo
3267 3437
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port, $db_mb4;
3268 3438
 
3269 3439
 	// Figure out what type of database we are using.
3270
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3271
-		$db_type = 'mysql';
3440
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3441
+			$db_type = 'mysql';
3442
+	}
3272 3443
 
3273 3444
 	// Load the file for the database.
3274 3445
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3276,11 +3447,13 @@  discard block
 block discarded – undo
3276 3447
 	$db_options = array();
3277 3448
 
3278 3449
 	// Add in the port if needed
3279
-	if (!empty($db_port))
3280
-		$db_options['port'] = $db_port;
3450
+	if (!empty($db_port)) {
3451
+			$db_options['port'] = $db_port;
3452
+	}
3281 3453
 
3282
-	if (!empty($db_mb4))
3283
-		$db_options['db_mb4'] = $db_mb4;
3454
+	if (!empty($db_mb4)) {
3455
+			$db_options['db_mb4'] = $db_mb4;
3456
+	}
3284 3457
 
3285 3458
 	// 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.
3286 3459
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3299,13 +3472,15 @@  discard block
 block discarded – undo
3299 3472
 	}
3300 3473
 
3301 3474
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3302
-	if (!$db_connection)
3303
-		display_db_error();
3475
+	if (!$db_connection) {
3476
+			display_db_error();
3477
+	}
3304 3478
 
3305 3479
 	// If in SSI mode fix up the prefix.
3306
-	if (SMF == 'SSI')
3307
-		db_fix_prefix($db_prefix, $db_name);
3308
-}
3480
+	if (SMF == 'SSI') {
3481
+			db_fix_prefix($db_prefix, $db_name);
3482
+	}
3483
+	}
3309 3484
 
3310 3485
 /**
3311 3486
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3319,14 +3494,16 @@  discard block
 block discarded – undo
3319 3494
 	global $sourcedir, $cacheAPI, $cache_accelerator, $cache_enable;
3320 3495
 
3321 3496
 	// is caching enabled?
3322
-	if (empty($cache_enable) && empty($overrideCache))
3323
-		return false;
3497
+	if (empty($cache_enable) && empty($overrideCache)) {
3498
+			return false;
3499
+	}
3324 3500
 
3325 3501
 	// Not overriding this and we have a cacheAPI, send it back.
3326
-	if (empty($overrideCache) && is_object($cacheAPI))
3327
-		return $cacheAPI;
3328
-	elseif (is_null($cacheAPI))
3329
-		$cacheAPI = false;
3502
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3503
+			return $cacheAPI;
3504
+	} elseif (is_null($cacheAPI)) {
3505
+			$cacheAPI = false;
3506
+	}
3330 3507
 
3331 3508
 	// Make sure our class is in session.
3332 3509
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3347,8 +3524,9 @@  discard block
 block discarded – undo
3347 3524
 		if (!$testAPI->isSupported())
3348 3525
 		{
3349 3526
 			// Can we save ourselves?
3350
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3351
-				return loadCacheAccelerator(null, false);
3527
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3528
+							return loadCacheAccelerator(null, false);
3529
+			}
3352 3530
 			return false;
3353 3531
 		}
3354 3532
 
@@ -3360,9 +3538,9 @@  discard block
 block discarded – undo
3360 3538
 		{
3361 3539
 			$cacheAPI = $testAPI;
3362 3540
 			return $cacheAPI;
3541
+		} else {
3542
+					return $testAPI;
3363 3543
 		}
3364
-		else
3365
-			return $testAPI;
3366 3544
 	}
3367 3545
 }
3368 3546
 
@@ -3382,8 +3560,9 @@  discard block
 block discarded – undo
3382 3560
 
3383 3561
 	// @todo Why are we doing this if caching is disabled?
3384 3562
 
3385
-	if (function_exists('call_integration_hook'))
3386
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3563
+	if (function_exists('call_integration_hook')) {
3564
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3565
+	}
3387 3566
 
3388 3567
 	/* Refresh the cache if either:
3389 3568
 		1. Caching is disabled.
@@ -3397,16 +3576,19 @@  discard block
 block discarded – undo
3397 3576
 		require_once($sourcedir . '/' . $file);
3398 3577
 		$cache_block = call_user_func_array($function, $params);
3399 3578
 
3400
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3401
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3579
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3580
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3581
+		}
3402 3582
 	}
3403 3583
 
3404 3584
 	// Some cached data may need a freshening up after retrieval.
3405
-	if (!empty($cache_block['post_retri_eval']))
3406
-		eval($cache_block['post_retri_eval']);
3585
+	if (!empty($cache_block['post_retri_eval'])) {
3586
+			eval($cache_block['post_retri_eval']);
3587
+	}
3407 3588
 
3408
-	if (function_exists('call_integration_hook'))
3409
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3589
+	if (function_exists('call_integration_hook')) {
3590
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3591
+	}
3410 3592
 
3411 3593
 	return $cache_block['data'];
3412 3594
 }
@@ -3433,8 +3615,9 @@  discard block
 block discarded – undo
3433 3615
 	global $smcFunc, $cache_enable, $cacheAPI;
3434 3616
 	global $cache_hits, $cache_count, $db_show_debug;
3435 3617
 
3436
-	if (empty($cache_enable) || empty($cacheAPI))
3437
-		return;
3618
+	if (empty($cache_enable) || empty($cacheAPI)) {
3619
+			return;
3620
+	}
3438 3621
 
3439 3622
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3440 3623
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3447,12 +3630,14 @@  discard block
 block discarded – undo
3447 3630
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3448 3631
 	$cacheAPI->putData($key, $value, $ttl);
3449 3632
 
3450
-	if (function_exists('call_integration_hook'))
3451
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3633
+	if (function_exists('call_integration_hook')) {
3634
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3635
+	}
3452 3636
 
3453
-	if (isset($db_show_debug) && $db_show_debug === true)
3454
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3455
-}
3637
+	if (isset($db_show_debug) && $db_show_debug === true) {
3638
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3639
+	}
3640
+	}
3456 3641
 
3457 3642
 /**
3458 3643
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3468,8 +3653,9 @@  discard block
 block discarded – undo
3468 3653
 	global $smcFunc, $cache_enable, $cacheAPI;
3469 3654
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3470 3655
 
3471
-	if (empty($cache_enable) || empty($cacheAPI))
3472
-		return;
3656
+	if (empty($cache_enable) || empty($cacheAPI)) {
3657
+			return;
3658
+	}
3473 3659
 
3474 3660
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3475 3661
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3489,16 +3675,18 @@  discard block
 block discarded – undo
3489 3675
 
3490 3676
 		if (empty($value))
3491 3677
 		{
3492
-			if (!is_array($cache_misses))
3493
-				$cache_misses = array();
3678
+			if (!is_array($cache_misses)) {
3679
+							$cache_misses = array();
3680
+			}
3494 3681
 
3495 3682
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3496 3683
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3497 3684
 		}
3498 3685
 	}
3499 3686
 
3500
-	if (function_exists('call_integration_hook') && isset($value))
3501
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3687
+	if (function_exists('call_integration_hook') && isset($value)) {
3688
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3689
+	}
3502 3690
 
3503 3691
 	return empty($value) ? null : (isset($smcFunc['json_decode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3504 3692
 }
@@ -3520,8 +3708,9 @@  discard block
 block discarded – undo
3520 3708
 	global $cacheAPI;
3521 3709
 
3522 3710
 	// If we can't get to the API, can't do this.
3523
-	if (empty($cacheAPI))
3524
-		return;
3711
+	if (empty($cacheAPI)) {
3712
+			return;
3713
+	}
3525 3714
 
3526 3715
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3527 3716
 	$cacheAPI->cleanCache($type);
@@ -3546,8 +3735,9 @@  discard block
 block discarded – undo
3546 3735
 	global $modSettings, $smcFunc, $image_proxy_enabled, $user_info;
3547 3736
 
3548 3737
 	// Come on!
3549
-	if (empty($data))
3550
-		return array();
3738
+	if (empty($data)) {
3739
+			return array();
3740
+	}
3551 3741
 
3552 3742
 	// Set a nice default var.
3553 3743
 	$image = '';
@@ -3555,11 +3745,11 @@  discard block
 block discarded – undo
3555 3745
 	// Gravatar has been set as mandatory!
3556 3746
 	if (!empty($modSettings['gravatarOverride']))
3557 3747
 	{
3558
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3559
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3560
-
3561
-		else if (!empty($data['email']))
3562
-			$image = get_gravatar_url($data['email']);
3748
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3749
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3750
+		} else if (!empty($data['email'])) {
3751
+					$image = get_gravatar_url($data['email']);
3752
+		}
3563 3753
 	}
3564 3754
 
3565 3755
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3571,54 +3761,60 @@  discard block
 block discarded – undo
3571 3761
 			// Gravatar.
3572 3762
 			if (stristr($data['avatar'], 'gravatar://'))
3573 3763
 			{
3574
-				if ($data['avatar'] == 'gravatar://')
3575
-					$image = get_gravatar_url($data['email']);
3576
-
3577
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3578
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3764
+				if ($data['avatar'] == 'gravatar://') {
3765
+									$image = get_gravatar_url($data['email']);
3766
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3767
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3768
+				}
3579 3769
 			}
3580 3770
 
3581 3771
 			// External url.
3582 3772
 			else
3583 3773
 			{
3584 3774
 				// Using ssl?
3585
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
3586
-					$image = get_proxied_url($data['avatar']);
3775
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
3776
+									$image = get_proxied_url($data['avatar']);
3777
+				}
3587 3778
 
3588 3779
 				// Just a plain external url.
3589
-				else
3590
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3780
+				else {
3781
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3782
+				}
3591 3783
 			}
3592 3784
 		}
3593 3785
 
3594 3786
 		// Perhaps this user has an attachment as avatar...
3595
-		else if (!empty($data['filename']))
3596
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3787
+		else if (!empty($data['filename'])) {
3788
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3789
+		}
3597 3790
 
3598 3791
 		// Right... no avatar... use our default image.
3599
-		else
3600
-			$image = $modSettings['avatar_url'] . '/default.png';
3792
+		else {
3793
+					$image = $modSettings['avatar_url'] . '/default.png';
3794
+		}
3601 3795
 	}
3602 3796
 
3603 3797
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3604 3798
 
3605 3799
 	// 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.
3606
-	if (!empty($image))
3607
-		return array(
3800
+	if (!empty($image)) {
3801
+			return array(
3608 3802
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3609 3803
 			'image' => '<img class="avatar" src="' . $image . '" />',
3610 3804
 			'href' => $image,
3611 3805
 			'url' => $image,
3612 3806
 		);
3807
+	}
3613 3808
 
3614 3809
 	// Fallback to make life easier for everyone...
3615
-	else
3616
-		return array(
3810
+	else {
3811
+			return array(
3617 3812
 			'name' => '',
3618 3813
 			'image' => '',
3619 3814
 			'href' => '',
3620 3815
 			'url' => '',
3621 3816
 		);
3622
-}
3817
+	}
3818
+	}
3623 3819
 
3624 3820
 ?>
3625 3821
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 /**
501 501
  * Returns the amount of affected rows for a query.
502 502
  *
503
- * @param mixed $result
503
+ * @param resource|null $result
504 504
  *
505 505
  * @return int
506 506
  *
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
  *
870 870
  * @param string $db_name The database name
871 871
  * @param resource $db_connection The database connection
872
- * @return true Always returns true
872
+ * @return boolean Always returns true
873 873
  */
874 874
 function smf_db_select_db($db_name, $db_connection)
875 875
 {
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -199,22 +199,22 @@  discard block
 block discarded – undo
199 199
 
200 200
 		case 'date':
201 201
 			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
202
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
202
+				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]) . '::date';
203 203
 			else
204 204
 				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
205 205
 		break;
206 206
 
207 207
 		case 'time':
208 208
 			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
209
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
209
+				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]) . '::time';
210 210
 			else
211 211
 				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
212 212
 		break;
213 213
 
214 214
 		case 'datetime':
215 215
 			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
216
-				return 'to_timestamp('.
217
-					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]).
216
+				return 'to_timestamp(' .
217
+					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) .
218 218
 					',\'YYYY-MM-DD HH24:MI:SS\')';
219 219
 			else
220 220
 				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 		$old_pos = 0;
425 425
 		$pos = -1;
426 426
 		// Remove the string escape for better runtime
427
-		$db_string_1 = str_replace('\'\'','',$db_string);
427
+		$db_string_1 = str_replace('\'\'', '', $db_string);
428 428
 		while (true)
429 429
 		{
430 430
 			$pos = strpos($db_string_1, '\'', $pos + 1);
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
 	if (!empty($keys) && (count($keys) > 0) && $returnmode > 0)
803 803
 	{
804 804
 		// we only take the first key
805
-		$returning = ' RETURNING '.$keys[0];
805
+		$returning = ' RETURNING ' . $keys[0];
806 806
 		$with_returning = true;
807 807
 	}
808 808
 
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
 			INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '")
834 834
 			VALUES
835 835
 				' . implode(',
836
-				', $insertRows).$replace.$returning,
836
+				', $insertRows) . $replace . $returning,
837 837
 			array(
838 838
 				'security_override' => true,
839 839
 				'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors',
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 			if ($returnmode === 2)
847 847
 				$return_var = array();
848 848
 
849
-			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
849
+			while (($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
850 850
 			{
851 851
 				if (is_numeric($row[0])) // try to emulate mysql limitation
852 852
 				{
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
  */
1010 1010
 function smf_db_custom_order($field, $array_values, $desc = false)
1011 1011
 {
1012
-	$return = 'CASE '. $field . ' ';
1012
+	$return = 'CASE ' . $field . ' ';
1013 1013
 	$count = count($array_values);
1014 1014
 	$then = ($desc ? ' THEN -' : ' THEN ');
1015 1015
 
Please login to merge, or discard this patch.
Braces   +241 added lines, -177 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',
@@ -66,15 +67,18 @@  discard block
 block discarded – undo
66 67
 			'db_native_replace'         => 'smf_db_native_replace',
67 68
 			'db_cte_support'            => 'smf_db_cte_support',
68 69
 		);
70
+	}
69 71
 
70 72
 	// We are not going to make it very far without these.
71
-	if (!function_exists('pg_pconnect'))
72
-		display_db_error();
73
+	if (!function_exists('pg_pconnect')) {
74
+			display_db_error();
75
+	}
73 76
 
74
-	if (!empty($db_options['persist']))
75
-		$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
76
-	else
77
-		$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
77
+	if (!empty($db_options['persist'])) {
78
+			$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
79
+	} else {
80
+			$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
81
+	}
78 82
 
79 83
 	// Something's wrong, show an error if its fatal (which we assume it is)
80 84
 	if (!$connection)
@@ -82,15 +86,15 @@  discard block
 block discarded – undo
82 86
 		if (!empty($db_options['non_fatal']))
83 87
 		{
84 88
 			return null;
85
-		}
86
-		else
89
+		} else
87 90
 		{
88 91
 			display_db_error();
89 92
 		}
90 93
 	}
91 94
 
92
-	if (!empty($db_options['db_mb4']))
93
-		$smcFunc['db_mb4'] = (bool) $db_options['db_mb4'];
95
+	if (!empty($db_options['db_mb4'])) {
96
+			$smcFunc['db_mb4'] = (bool) $db_options['db_mb4'];
97
+	}
94 98
 
95 99
 	return $connection;
96 100
 }
@@ -137,31 +141,38 @@  discard block
 block discarded – undo
137 141
 
138 142
 	list ($values, $connection) = $db_callback;
139 143
 
140
-	if ($matches[1] === 'db_prefix')
141
-		return $db_prefix;
144
+	if ($matches[1] === 'db_prefix') {
145
+			return $db_prefix;
146
+	}
142 147
 
143
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
144
-		return $user_info[$matches[1]];
148
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
149
+			return $user_info[$matches[1]];
150
+	}
145 151
 
146
-	if ($matches[1] === 'empty')
147
-		return '\'\'';
152
+	if ($matches[1] === 'empty') {
153
+			return '\'\'';
154
+	}
148 155
 
149
-	if (!isset($matches[2]))
150
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
156
+	if (!isset($matches[2])) {
157
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
158
+	}
151 159
 
152
-	if ($matches[1] === 'literal')
153
-		return '\'' . pg_escape_string($matches[2]) . '\'';
160
+	if ($matches[1] === 'literal') {
161
+			return '\'' . pg_escape_string($matches[2]) . '\'';
162
+	}
154 163
 
155
-	if (!isset($values[$matches[2]]))
156
-		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__);
164
+	if (!isset($values[$matches[2]])) {
165
+			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__);
166
+	}
157 167
 
158 168
 	$replacement = $values[$matches[2]];
159 169
 
160 170
 	switch ($matches[1])
161 171
 	{
162 172
 		case 'int':
163
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
164
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
173
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
174
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
175
+			}
165 176
 			return (string) (int) $replacement;
166 177
 		break;
167 178
 
@@ -173,65 +184,73 @@  discard block
 block discarded – undo
173 184
 		case 'array_int':
174 185
 			if (is_array($replacement))
175 186
 			{
176
-				if (empty($replacement))
177
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
187
+				if (empty($replacement)) {
188
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
189
+				}
178 190
 
179 191
 				foreach ($replacement as $key => $value)
180 192
 				{
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__);
193
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
194
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
195
+					}
183 196
 
184 197
 					$replacement[$key] = (string) (int) $value;
185 198
 				}
186 199
 
187 200
 				return implode(', ', $replacement);
201
+			} else {
202
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
188 203
 			}
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__);
191 204
 
192 205
 		break;
193 206
 
194 207
 		case 'array_string':
195 208
 			if (is_array($replacement))
196 209
 			{
197
-				if (empty($replacement))
198
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
210
+				if (empty($replacement)) {
211
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
212
+				}
199 213
 
200
-				foreach ($replacement as $key => $value)
201
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
214
+				foreach ($replacement as $key => $value) {
215
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
216
+				}
202 217
 
203 218
 				return implode(', ', $replacement);
219
+			} else {
220
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
204 221
 			}
205
-			else
206
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
207 222
 		break;
208 223
 
209 224
 		case 'date':
210
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
211
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
212
-			else
213
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
226
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
227
+			} else {
228
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
229
+			}
214 230
 		break;
215 231
 
216 232
 		case 'time':
217
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
218
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
219
-			else
220
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
234
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
235
+			} else {
236
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237
+			}
221 238
 		break;
222 239
 
223 240
 		case 'datetime':
224
-			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)
225
-				return 'to_timestamp('.
241
+			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) {
242
+							return 'to_timestamp('.
226 243
 					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]).
227 244
 					',\'YYYY-MM-DD HH24:MI:SS\')';
228
-			else
229
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
245
+			} else {
246
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
247
+			}
230 248
 		break;
231 249
 
232 250
 		case 'float':
233
-			if (!is_numeric($replacement))
234
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
251
+			if (!is_numeric($replacement)) {
252
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
253
+			}
235 254
 			return (string) (float) $replacement;
236 255
 		break;
237 256
 
@@ -244,31 +263,36 @@  discard block
 block discarded – undo
244 263
 		break;
245 264
 
246 265
 		case 'inet':
247
-			if ($replacement == 'null' || $replacement == '')
248
-				return 'null';
249
-			if (inet_pton($replacement) === false)
250
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+			if ($replacement == 'null' || $replacement == '') {
267
+							return 'null';
268
+			}
269
+			if (inet_pton($replacement) === false) {
270
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
271
+			}
251 272
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
252 273
 
253 274
 		case 'array_inet':
254 275
 			if (is_array($replacement))
255 276
 			{
256
-				if (empty($replacement))
257
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
277
+				if (empty($replacement)) {
278
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
279
+				}
258 280
 
259 281
 				foreach ($replacement as $key => $value)
260 282
 				{
261
-					if ($replacement == 'null' || $replacement == '')
262
-						$replacement[$key] = 'null';
263
-					if (!isValidIP($value))
264
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
283
+					if ($replacement == 'null' || $replacement == '') {
284
+											$replacement[$key] = 'null';
285
+					}
286
+					if (!isValidIP($value)) {
287
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
288
+					}
265 289
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
266 290
 				}
267 291
 
268 292
 				return implode(', ', $replacement);
293
+			} else {
294
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
269 295
 			}
270
-			else
271
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
272 296
 		break;
273 297
 
274 298
 		default:
@@ -356,14 +380,16 @@  discard block
 block discarded – undo
356 380
 		),
357 381
 	);
358 382
 
359
-	if (isset($replacements[$identifier]))
360
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
383
+	if (isset($replacements[$identifier])) {
384
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
385
+	}
361 386
 
362 387
 	// Limits need to be a little different.
363 388
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
364 389
 
365
-	if (trim($db_string) == '')
366
-		return false;
390
+	if (trim($db_string) == '') {
391
+			return false;
392
+	}
367 393
 
368 394
 	// Comments that are allowed in a query are preg_removed.
369 395
 	static $allowed_comments_from = array(
@@ -383,8 +409,9 @@  discard block
 block discarded – undo
383 409
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
384 410
 	$db_replace_result = 0;
385 411
 
386
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
387
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
412
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
413
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
414
+	}
388 415
 
389 416
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
390 417
 	{
@@ -409,17 +436,18 @@  discard block
 block discarded – undo
409 436
 		while (true)
410 437
 		{
411 438
 			$pos = strpos($db_string_1, '\'', $pos + 1);
412
-			if ($pos === false)
413
-				break;
439
+			if ($pos === false) {
440
+							break;
441
+			}
414 442
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
415 443
 
416 444
 			while (true)
417 445
 			{
418 446
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
419 447
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
420
-				if ($pos1 === false)
421
-					break;
422
-				elseif ($pos2 === false || $pos2 > $pos1)
448
+				if ($pos1 === false) {
449
+									break;
450
+				} elseif ($pos2 === false || $pos2 > $pos1)
423 451
 				{
424 452
 					$pos = $pos1;
425 453
 					break;
@@ -435,16 +463,19 @@  discard block
 block discarded – undo
435 463
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
436 464
 
437 465
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
438
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
439
-			$fail = true;
466
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
467
+					$fail = true;
468
+		}
440 469
 		// Trying to change passwords, slow us down, or something?
441
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
442
-			$fail = true;
443
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
444
-			$fail = true;
470
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
471
+					$fail = true;
472
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
473
+					$fail = true;
474
+		}
445 475
 
446
-		if (!empty($fail) && function_exists('log_error'))
447
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
476
+		if (!empty($fail) && function_exists('log_error')) {
477
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
478
+		}
448 479
 	}
449 480
 
450 481
 	// Set optimize stuff
@@ -471,8 +502,9 @@  discard block
 block discarded – undo
471 502
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
472 503
 
473 504
 		// Initialize $db_cache if not already initialized.
474
-		if (!isset($db_cache))
475
-			$db_cache = array();
505
+		if (!isset($db_cache)) {
506
+					$db_cache = array();
507
+		}
476 508
 
477 509
 		if (!empty($_SESSION['debug_redirect']))
478 510
 		{
@@ -490,12 +522,14 @@  discard block
 block discarded – undo
490 522
 
491 523
 	$db_last_result = @pg_query($connection, $db_string);
492 524
 
493
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
494
-		$db_last_result = smf_db_error($db_string, $connection);
525
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
526
+			$db_last_result = smf_db_error($db_string, $connection);
527
+	}
495 528
 
496 529
 	// Debugging.
497
-	if (isset($db_show_debug) && $db_show_debug === true)
498
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
530
+	if (isset($db_show_debug) && $db_show_debug === true) {
531
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
532
+	}
499 533
 
500 534
 	return $db_last_result;
501 535
 }
@@ -512,10 +546,11 @@  discard block
 block discarded – undo
512 546
 {
513 547
 	global $db_last_result, $db_replace_result;
514 548
 
515
-	if ($db_replace_result)
516
-		return $db_replace_result;
517
-	elseif ($result === null && !$db_last_result)
518
-		return 0;
549
+	if ($db_replace_result) {
550
+			return $db_replace_result;
551
+	} elseif ($result === null && !$db_last_result) {
552
+			return 0;
553
+	}
519 554
 
520 555
 	return pg_affected_rows($result === null ? $db_last_result : $result);
521 556
 }
@@ -539,8 +574,9 @@  discard block
 block discarded – undo
539 574
 		array(
540 575
 		)
541 576
 	);
542
-	if (!$request)
543
-		return false;
577
+	if (!$request) {
578
+			return false;
579
+	}
544 580
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
545 581
 	$smcFunc['db_free_result']($request);
546 582
 
@@ -561,12 +597,13 @@  discard block
 block discarded – undo
561 597
 	// Decide which connection to use
562 598
 	$connection = $connection === null ? $db_connection : $connection;
563 599
 
564
-	if ($type == 'begin')
565
-		return @pg_query($connection, 'BEGIN');
566
-	elseif ($type == 'rollback')
567
-		return @pg_query($connection, 'ROLLBACK');
568
-	elseif ($type == 'commit')
569
-		return @pg_query($connection, 'COMMIT');
600
+	if ($type == 'begin') {
601
+			return @pg_query($connection, 'BEGIN');
602
+	} elseif ($type == 'rollback') {
603
+			return @pg_query($connection, 'ROLLBACK');
604
+	} elseif ($type == 'commit') {
605
+			return @pg_query($connection, 'COMMIT');
606
+	}
570 607
 
571 608
 	return false;
572 609
 }
@@ -594,19 +631,22 @@  discard block
 block discarded – undo
594 631
 	$query_error = @pg_last_error($connection);
595 632
 
596 633
 	// Log the error.
597
-	if (function_exists('log_error'))
598
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
634
+	if (function_exists('log_error')) {
635
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
636
+	}
599 637
 
600 638
 	// Nothing's defined yet... just die with it.
601
-	if (empty($context) || empty($txt))
602
-		die($query_error);
639
+	if (empty($context) || empty($txt)) {
640
+			die($query_error);
641
+	}
603 642
 
604 643
 	// Show an error message, if possible.
605 644
 	$context['error_title'] = $txt['database_error'];
606
-	if (allowedTo('admin_forum'))
607
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
608
-	else
609
-		$context['error_message'] = $txt['try_again'];
645
+	if (allowedTo('admin_forum')) {
646
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
647
+	} else {
648
+			$context['error_message'] = $txt['try_again'];
649
+	}
610 650
 
611 651
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
612 652
 	{
@@ -628,12 +668,14 @@  discard block
 block discarded – undo
628 668
 {
629 669
 	global $db_row_count;
630 670
 
631
-	if ($counter !== false)
632
-		return pg_fetch_row($request, $counter);
671
+	if ($counter !== false) {
672
+			return pg_fetch_row($request, $counter);
673
+	}
633 674
 
634 675
 	// Reset the row counter...
635
-	if (!isset($db_row_count[(int) $request]))
636
-		$db_row_count[(int) $request] = 0;
676
+	if (!isset($db_row_count[(int) $request])) {
677
+			$db_row_count[(int) $request] = 0;
678
+	}
637 679
 
638 680
 	// Return the right row.
639 681
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -650,12 +692,14 @@  discard block
 block discarded – undo
650 692
 {
651 693
 	global $db_row_count;
652 694
 
653
-	if ($counter !== false)
654
-		return pg_fetch_assoc($request, $counter);
695
+	if ($counter !== false) {
696
+			return pg_fetch_assoc($request, $counter);
697
+	}
655 698
 
656 699
 	// Reset the row counter...
657
-	if (!isset($db_row_count[(int) $request]))
658
-		$db_row_count[(int) $request] = 0;
700
+	if (!isset($db_row_count[(int) $request])) {
701
+			$db_row_count[(int) $request] = 0;
702
+	}
659 703
 
660 704
 	// Return the right row.
661 705
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -697,19 +741,22 @@  discard block
 block discarded – undo
697 741
 
698 742
 	$replace = '';
699 743
 
700
-	if (empty($data))
701
-		return;
744
+	if (empty($data)) {
745
+			return;
746
+	}
702 747
 
703
-	if (!is_array($data[array_rand($data)]))
704
-		$data = array($data);
748
+	if (!is_array($data[array_rand($data)])) {
749
+			$data = array($data);
750
+	}
705 751
 
706 752
 	// Replace the prefix holder with the actual prefix.
707 753
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
708 754
 
709 755
 	// Sanity check for replace is key part of the columns array
710
-	if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys))
711
-		smf_db_error_backtrace('Primary Key field missing in insert call',
756
+	if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) {
757
+			smf_db_error_backtrace('Primary Key field missing in insert call',
712 758
 				'Change the method of db insert to insert or add the pk field to the columns array', E_USER_ERROR, __FILE__, __LINE__);
759
+	}
713 760
 
714 761
 	// PostgreSQL doesn't support replace: we implement a MySQL-compatible behavior instead
715 762
 	if ($method == 'replace' || $method == 'ignore')
@@ -732,32 +779,35 @@  discard block
 block discarded – undo
732 779
 					$key_str .= ($count_pk > 0 ? ',' : '');
733 780
 					$key_str .= $columnName;
734 781
 					$count_pk++;
735
-				}
736
-				else if ($method == 'replace') //normal field
782
+				} else if ($method == 'replace') {
783
+					//normal field
737 784
 				{
738 785
 					$col_str .= ($count > 0 ? ',' : '');
786
+				}
739 787
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
740 788
 					$count++;
741 789
 				}
742 790
 			}
743
-			if ($method == 'replace')
744
-				$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
745
-			else
746
-				$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
747
-		}
748
-		else if ($method == 'replace')
791
+			if ($method == 'replace') {
792
+							$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
793
+			} else {
794
+							$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
795
+			}
796
+		} else if ($method == 'replace')
749 797
 		{
750 798
 			foreach ($columns as $columnName => $type)
751 799
 			{
752 800
 				// Are we restricting the length?
753
-				if (strpos($type, 'string-') !== false)
754
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
755
-				else
756
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
801
+				if (strpos($type, 'string-') !== false) {
802
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
803
+				} else {
804
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
805
+				}
757 806
 
758 807
 				// A key? That's what we were looking for.
759
-				if (in_array($columnName, $keys))
760
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
808
+				if (in_array($columnName, $keys)) {
809
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
810
+				}
761 811
 				$count++;
762 812
 			}
763 813
 
@@ -793,10 +843,11 @@  discard block
 block discarded – undo
793 843
 		foreach ($columns as $columnName => $type)
794 844
 		{
795 845
 			// Are we restricting the length?
796
-			if (strpos($type, 'string-') !== false)
797
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
798
-			else
799
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
846
+			if (strpos($type, 'string-') !== false) {
847
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
848
+			} else {
849
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
850
+			}
800 851
 		}
801 852
 		$insertData = substr($insertData, 0, -2) . ')';
802 853
 
@@ -805,8 +856,9 @@  discard block
 block discarded – undo
805 856
 
806 857
 		// Here's where the variables are injected to the query.
807 858
 		$insertRows = array();
808
-		foreach ($data as $dataRow)
809
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
859
+		foreach ($data as $dataRow) {
860
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
861
+		}
810 862
 
811 863
 		// Do the insert.
812 864
 		$request = $smcFunc['db_query']('', '
@@ -823,19 +875,21 @@  discard block
 block discarded – undo
823 875
 
824 876
 		if ($with_returning && $request !== false)
825 877
 		{
826
-			if ($returnmode === 2)
827
-				$return_var = array();
878
+			if ($returnmode === 2) {
879
+							$return_var = array();
880
+			}
828 881
 
829 882
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
830 883
 			{
831
-				if (is_numeric($row[0])) // try to emulate mysql limitation
884
+				if (is_numeric($row[0])) {
885
+					// try to emulate mysql limitation
832 886
 				{
833 887
 					if ($returnmode === 1)
834 888
 						$return_var = $row[0];
835
-					elseif ($returnmode === 2)
836
-						$return_var[] = $row[0];
837
-				}
838
-				else
889
+				} elseif ($returnmode === 2) {
890
+											$return_var[] = $row[0];
891
+					}
892
+				} else
839 893
 				{
840 894
 					$with_returning = false;
841 895
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -844,9 +898,10 @@  discard block
 block discarded – undo
844 898
 		}
845 899
 	}
846 900
 
847
-	if ($with_returning && !empty($return_var))
848
-		return $return_var;
849
-}
901
+	if ($with_returning && !empty($return_var)) {
902
+			return $return_var;
903
+	}
904
+	}
850 905
 
851 906
 /**
852 907
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -883,8 +938,9 @@  discard block
 block discarded – undo
883 938
  */
884 939
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
885 940
 {
886
-	if (empty($log_message))
887
-		$log_message = $error_message;
941
+	if (empty($log_message)) {
942
+			$log_message = $error_message;
943
+	}
888 944
 
889 945
 	foreach (debug_backtrace() as $step)
890 946
 	{
@@ -903,12 +959,14 @@  discard block
 block discarded – undo
903 959
 	}
904 960
 
905 961
 	// A special case - we want the file and line numbers for debugging.
906
-	if ($error_type == 'return')
907
-		return array($file, $line);
962
+	if ($error_type == 'return') {
963
+			return array($file, $line);
964
+	}
908 965
 
909 966
 	// Is always a critical error.
910
-	if (function_exists('log_error'))
911
-		log_error($log_message, 'critical', $file, $line);
967
+	if (function_exists('log_error')) {
968
+			log_error($log_message, 'critical', $file, $line);
969
+	}
912 970
 
913 971
 	if (function_exists('fatal_error'))
914 972
 	{
@@ -916,12 +974,12 @@  discard block
 block discarded – undo
916 974
 
917 975
 		// Cannot continue...
918 976
 		exit;
977
+	} elseif ($error_type) {
978
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
979
+	} else {
980
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
981
+	}
919 982
 	}
920
-	elseif ($error_type)
921
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
922
-	else
923
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
924
-}
925 983
 
926 984
 /**
927 985
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -938,10 +996,11 @@  discard block
 block discarded – undo
938 996
 		'\\' => '\\\\',
939 997
 	);
940 998
 
941
-	if ($translate_human_wildcards)
942
-		$replacements += array(
999
+	if ($translate_human_wildcards) {
1000
+			$replacements += array(
943 1001
 			'*' => '%',
944 1002
 		);
1003
+	}
945 1004
 
946 1005
 	return strtr($string, $replacements);
947 1006
 }
@@ -970,14 +1029,16 @@  discard block
 block discarded – undo
970 1029
 	static $pg_error_data_prep;
971 1030
 
972 1031
 	// without database we can't do anything
973
-	if (empty($db_connection))
974
-		return;
1032
+	if (empty($db_connection)) {
1033
+			return;
1034
+	}
975 1035
 
976
-	if (empty($pg_error_data_prep))
977
-			$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
1036
+	if (empty($pg_error_data_prep)) {
1037
+				$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
978 1038
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace)
979 1039
 													VALUES(		$1,		$2,		$3, $4, 	$5,		$6,			$7,		$8,	$9, $10)'
980 1040
 			);
1041
+	}
981 1042
 
982 1043
 	pg_execute($db_connection, 'smf_log_errors', $error_array);
983 1044
 }
@@ -997,8 +1058,9 @@  discard block
 block discarded – undo
997 1058
 	$count = count($array_values);
998 1059
 	$then = ($desc ? ' THEN -' : ' THEN ');
999 1060
 
1000
-	for ($i = 0; $i < $count; $i++)
1001
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1061
+	for ($i = 0; $i < $count; $i++) {
1062
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1063
+	}
1002 1064
 
1003 1065
 	$return .= 'END';
1004 1066
 	return $return;
@@ -1021,11 +1083,13 @@  discard block
 block discarded – undo
1021 1083
 		//pg 9.5 got replace support
1022 1084
 		$pg_version = $smcFunc['db_get_version']();
1023 1085
 		// if we got a Beta Version
1024
-		if (stripos($pg_version, 'beta') !== false)
1025
-			$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
1086
+		if (stripos($pg_version, 'beta') !== false) {
1087
+					$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
1088
+		}
1026 1089
 		// or RC
1027
-		if (stripos($pg_version, 'rc') !== false)
1028
-			$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
1090
+		if (stripos($pg_version, 'rc') !== false) {
1091
+					$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
1092
+		}
1029 1093
 
1030 1094
 		$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
1031 1095
 	}
Please login to merge, or discard this patch.
Sources/ManageSettings.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1334,7 +1334,7 @@  discard block
 block discarded – undo
1334 1334
 					'class' => 'centercol',
1335 1335
 				),
1336 1336
 				'data' => array(
1337
-					'function' => function ($rowData)
1337
+					'function' => function($rowData)
1338 1338
 					{
1339 1339
 						$isChecked = $rowData['disabled'] ? '' : ' checked';
1340 1340
 						$onClickHandler = $rowData['can_show_register'] ? sprintf(' onclick="document.getElementById(\'reg_%1$s\').disabled = !this.checked;"', $rowData['id']) : '';
@@ -1350,7 +1350,7 @@  discard block
 block discarded – undo
1350 1350
 					'class' => 'centercol',
1351 1351
 				),
1352 1352
 				'data' => array(
1353
-					'function' => function ($rowData)
1353
+					'function' => function($rowData)
1354 1354
 					{
1355 1355
 						$isChecked = $rowData['on_register'] && !$rowData['disabled'] ? ' checked' : '';
1356 1356
 						$isDisabled = $rowData['can_show_register'] ? '' : ' disabled';
@@ -1397,15 +1397,15 @@  discard block
 block discarded – undo
1397 1397
 					'value' => $txt['custom_profile_fieldorder'],
1398 1398
 				),
1399 1399
 				'data' => array(
1400
-					'function' => function ($rowData) use ($context, $txt, $scripturl)
1400
+					'function' => function($rowData) use ($context, $txt, $scripturl)
1401 1401
 					{
1402
-						$return = '<p class="centertext bold_text">'. $rowData['field_order'] .'<br>';
1402
+						$return = '<p class="centertext bold_text">' . $rowData['field_order'] . '<br>';
1403 1403
 
1404 1404
 						if ($rowData['field_order'] > 1)
1405
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1405
+							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="' . $txt['custom_edit_order_move'] . ' ' . $txt['custom_edit_order_up'] . '"></span></a>';
1406 1406
 
1407 1407
 						if ($rowData['field_order'] < $context['custFieldsMaxOrder'])
1408
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1408
+							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="' . $txt['custom_edit_order_move'] . ' ' . $txt['custom_edit_order_down'] . '"></span></a>';
1409 1409
 
1410 1410
 						$return .= '</p>';
1411 1411
 
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
 					'value' => $txt['custom_profile_fieldname'],
1424 1424
 				),
1425 1425
 				'data' => array(
1426
-					'function' => function ($rowData) use ($scripturl)
1426
+					'function' => function($rowData) use ($scripturl)
1427 1427
 					{
1428 1428
 						return sprintf('<a href="%1$s?action=admin;area=featuresettings;sa=profileedit;fid=%2$d">%3$s</a><div class="smalltext">%4$s</div>', $scripturl, $rowData['id_field'], $rowData['field_name'], $rowData['field_desc']);
1429 1429
 					},
@@ -1439,7 +1439,7 @@  discard block
 block discarded – undo
1439 1439
 					'value' => $txt['custom_profile_fieldtype'],
1440 1440
 				),
1441 1441
 				'data' => array(
1442
-					'function' => function ($rowData) use ($txt)
1442
+					'function' => function($rowData) use ($txt)
1443 1443
 					{
1444 1444
 						$textKey = sprintf('custom_profile_type_%1$s', $rowData['field_type']);
1445 1445
 						return isset($txt[$textKey]) ? $txt[$textKey] : $textKey;
@@ -1457,7 +1457,7 @@  discard block
 block discarded – undo
1457 1457
 					'value' => $txt['custom_profile_active'],
1458 1458
 				),
1459 1459
 				'data' => array(
1460
-					'function' => function ($rowData) use ($txt)
1460
+					'function' => function($rowData) use ($txt)
1461 1461
 					{
1462 1462
 						return $rowData['active'] ? $txt['yes'] : $txt['no'];
1463 1463
 					},
@@ -1474,7 +1474,7 @@  discard block
 block discarded – undo
1474 1474
 					'value' => $txt['custom_profile_placement'],
1475 1475
 				),
1476 1476
 				'data' => array(
1477
-					'function' => function ($rowData)
1477
+					'function' => function($rowData)
1478 1478
 					{
1479 1479
 						global $txt, $context;
1480 1480
 
@@ -1709,7 +1709,7 @@  discard block
 block discarded – undo
1709 1709
 			redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler
1710 1710
 
1711 1711
 		// All good, proceed.
1712
-		$smcFunc['db_query']('','
1712
+		$smcFunc['db_query']('', '
1713 1713
 			UPDATE {db_prefix}custom_fields
1714 1714
 			SET field_order = {int:old_order}
1715 1715
 			WHERE field_order = {int:new_order}',
@@ -1718,7 +1718,7 @@  discard block
 block discarded – undo
1718 1718
 				'old_order' => $context['field']['order'],
1719 1719
 			)
1720 1720
 		);
1721
-		$smcFunc['db_query']('','
1721
+		$smcFunc['db_query']('', '
1722 1722
 			UPDATE {db_prefix}custom_fields
1723 1723
 			SET field_order = {int:new_order}
1724 1724
 			WHERE id_field = {int:id_field}',
@@ -1820,7 +1820,7 @@  discard block
 block discarded – undo
1820 1820
 			$smcFunc['db_free_result']($request);
1821 1821
 
1822 1822
 			$unique = false;
1823
-			for ($i = 0; !$unique && $i < 9; $i ++)
1823
+			for ($i = 0; !$unique && $i < 9; $i++)
1824 1824
 			{
1825 1825
 				if (!in_array($col_name, $current_fields))
1826 1826
 					$unique = true;
@@ -1993,7 +1993,7 @@  discard block
 block discarded – undo
1993 1993
 		);
1994 1994
 
1995 1995
 		// Re-arrange the order.
1996
-		$smcFunc['db_query']('','
1996
+		$smcFunc['db_query']('', '
1997 1997
 			UPDATE {db_prefix}custom_fields
1998 1998
 			SET field_order = field_order - 1
1999 1999
 			WHERE field_order > {int:current_order}',
@@ -2257,7 +2257,7 @@  discard block
 block discarded – undo
2257 2257
 	$context['token_check'] = 'noti-admin';
2258 2258
 
2259 2259
 	// Specify our action since we'll want to post back here instead of the profile
2260
-	$context['action'] = 'action=admin;area=featuresettings;sa=alerts;'. $context['session_var'] .'='. $context['session_id'];
2260
+	$context['action'] = 'action=admin;area=featuresettings;sa=alerts;' . $context['session_var'] . '=' . $context['session_id'];
2261 2261
 
2262 2262
 	loadTemplate('Profile');
2263 2263
 	loadLanguage('Profile');
Please login to merge, or discard this patch.
Braces   +276 added lines, -201 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
  * This function makes sure the requested subaction does exists, if it doesn't, it sets a default action or.
@@ -206,16 +207,18 @@  discard block
 block discarded – undo
206 207
 	{
207 208
 		$all_zones = timezone_identifiers_list();
208 209
 		// Make sure we set the value to the same as the printed value.
209
-		foreach ($all_zones as $zone)
210
-			$config_vars['default_timezone'][2][$zone] = $zone;
210
+		foreach ($all_zones as $zone) {
211
+					$config_vars['default_timezone'][2][$zone] = $zone;
212
+		}
213
+	} else {
214
+			unset($config_vars['default_timezone']);
211 215
 	}
212
-	else
213
-		unset($config_vars['default_timezone']);
214 216
 
215 217
 	call_integration_hook('integrate_modify_basic_settings', array(&$config_vars));
216 218
 
217
-	if ($return_config)
218
-		return $config_vars;
219
+	if ($return_config) {
220
+			return $config_vars;
221
+	}
219 222
 
220 223
 	// Saving?
221 224
 	if (isset($_GET['save']))
@@ -223,8 +226,9 @@  discard block
 block discarded – undo
223 226
 		checkSession();
224 227
 
225 228
 		// Prevent absurd boundaries here - make it a day tops.
226
-		if (isset($_POST['lastActive']))
227
-			$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
229
+		if (isset($_POST['lastActive'])) {
230
+					$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
231
+		}
228 232
 
229 233
 		call_integration_hook('integrate_save_basic_settings');
230 234
 
@@ -232,8 +236,9 @@  discard block
 block discarded – undo
232 236
 		$_SESSION['adm-save'] = true;
233 237
 
234 238
 		// Do a bit of housekeeping
235
-		if (empty($_POST['minimize_files']))
236
-			deleteAllMinified();
239
+		if (empty($_POST['minimize_files'])) {
240
+					deleteAllMinified();
241
+		}
237 242
 
238 243
 		writeLog();
239 244
 		redirectexit('action=admin;area=featuresettings;sa=basic');
@@ -273,8 +278,9 @@  discard block
 block discarded – undo
273 278
 
274 279
 	call_integration_hook('integrate_modify_bbc_settings', array(&$config_vars));
275 280
 
276
-	if ($return_config)
277
-		return $config_vars;
281
+	if ($return_config) {
282
+			return $config_vars;
283
+	}
278 284
 
279 285
 	// Setup the template.
280 286
 	require_once($sourcedir . '/ManageServer.php');
@@ -291,13 +297,15 @@  discard block
 block discarded – undo
291 297
 
292 298
 		// Clean up the tags.
293 299
 		$bbcTags = array();
294
-		foreach (parse_bbc(false) as $tag)
295
-			$bbcTags[] = $tag['tag'];
300
+		foreach (parse_bbc(false) as $tag) {
301
+					$bbcTags[] = $tag['tag'];
302
+		}
296 303
 
297
-		if (!isset($_POST['disabledBBC_enabledTags']))
298
-			$_POST['disabledBBC_enabledTags'] = array();
299
-		elseif (!is_array($_POST['disabledBBC_enabledTags']))
300
-			$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
304
+		if (!isset($_POST['disabledBBC_enabledTags'])) {
305
+					$_POST['disabledBBC_enabledTags'] = array();
306
+		} elseif (!is_array($_POST['disabledBBC_enabledTags'])) {
307
+					$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
308
+		}
301 309
 		// Work out what is actually disabled!
302 310
 		$_POST['disabledBBC'] = implode(',', array_diff($bbcTags, $_POST['disabledBBC_enabledTags']));
303 311
 
@@ -341,8 +349,9 @@  discard block
 block discarded – undo
341 349
 
342 350
 	call_integration_hook('integrate_layout_settings', array(&$config_vars));
343 351
 
344
-	if ($return_config)
345
-		return $config_vars;
352
+	if ($return_config) {
353
+			return $config_vars;
354
+	}
346 355
 
347 356
 	// Saving?
348 357
 	if (isset($_GET['save']))
@@ -382,8 +391,9 @@  discard block
 block discarded – undo
382 391
 
383 392
 	call_integration_hook('integrate_likes_settings', array(&$config_vars));
384 393
 
385
-	if ($return_config)
386
-		return $config_vars;
394
+	if ($return_config) {
395
+			return $config_vars;
396
+	}
387 397
 
388 398
 	// Saving?
389 399
 	if (isset($_GET['save']))
@@ -421,8 +431,9 @@  discard block
 block discarded – undo
421 431
 
422 432
 	call_integration_hook('integrate_mentions_settings', array(&$config_vars));
423 433
 
424
-	if ($return_config)
425
-		return $config_vars;
434
+	if ($return_config) {
435
+			return $config_vars;
436
+	}
426 437
 
427 438
 	// Saving?
428 439
 	if (isset($_GET['save']))
@@ -466,8 +477,8 @@  discard block
 block discarded – undo
466 477
 			'enable' => array('check', 'warning_enable'),
467 478
 	);
468 479
 
469
-	if (!empty($modSettings['warning_settings']) && $currently_enabled)
470
-		$config_vars += array(
480
+	if (!empty($modSettings['warning_settings']) && $currently_enabled) {
481
+			$config_vars += array(
471 482
 			'',
472 483
 				array('int', 'warning_watch', 'subtext' => $txt['setting_warning_watch_note'] . ' ' . $txt['zero_to_disable']),
473 484
 				'moderate' => array('int', 'warning_moderate', 'subtext' => $txt['setting_warning_moderate_note'] . ' ' . $txt['zero_to_disable']),
@@ -476,15 +487,18 @@  discard block
 block discarded – undo
476 487
 				'rem2' => array('int', 'warning_decrement', 'subtext' => $txt['setting_warning_decrement_note'] . ' ' . $txt['zero_to_disable']),
477 488
 				array('permissions', 'view_warning'),
478 489
 		);
490
+	}
479 491
 
480 492
 	call_integration_hook('integrate_warning_settings', array(&$config_vars));
481 493
 
482
-	if ($return_config)
483
-		return $config_vars;
494
+	if ($return_config) {
495
+			return $config_vars;
496
+	}
484 497
 
485 498
 	// Cannot use moderation if post moderation is not enabled.
486
-	if (!$modSettings['postmod_active'])
487
-		unset($config_vars['moderate']);
499
+	if (!$modSettings['postmod_active']) {
500
+			unset($config_vars['moderate']);
501
+	}
488 502
 
489 503
 	// Will need the utility functions from here.
490 504
 	require_once($sourcedir . '/ManageServer.php');
@@ -509,16 +523,16 @@  discard block
 block discarded – undo
509 523
 				'warning_watch' => 10,
510 524
 				'warning_mute' => 60,
511 525
 			);
512
-			if ($modSettings['postmod_active'])
513
-				$vars['warning_moderate'] = 35;
526
+			if ($modSettings['postmod_active']) {
527
+							$vars['warning_moderate'] = 35;
528
+			}
514 529
 
515 530
 			foreach ($vars as $var => $value)
516 531
 			{
517 532
 				$config_vars[] = array('int', $var);
518 533
 				$_POST[$var] = $value;
519 534
 			}
520
-		}
521
-		else
535
+		} else
522 536
 		{
523 537
 			$_POST['warning_watch'] = min($_POST['warning_watch'], 100);
524 538
 			$_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0;
@@ -606,8 +620,9 @@  discard block
 block discarded – undo
606 620
 
607 621
 	call_integration_hook('integrate_spam_settings', array(&$config_vars));
608 622
 
609
-	if ($return_config)
610
-		return $config_vars;
623
+	if ($return_config) {
624
+			return $config_vars;
625
+	}
611 626
 
612 627
 	// You need to be an admin to edit settings!
613 628
 	isAllowedTo('admin_forum');
@@ -641,8 +656,9 @@  discard block
 block discarded – undo
641 656
 
642 657
 	if (empty($context['qa_by_lang'][strtr($language, array('-utf8' => ''))]) && !empty($context['question_answers']))
643 658
 	{
644
-		if (empty($context['settings_insert_above']))
645
-			$context['settings_insert_above'] = '';
659
+		if (empty($context['settings_insert_above'])) {
660
+					$context['settings_insert_above'] = '';
661
+		}
646 662
 
647 663
 		$context['settings_insert_above'] .= '<div class="noticebox">' . sprintf($txt['question_not_defined'], $context['languages'][$language]['name']) . '</div>';
648 664
 	}
@@ -685,8 +701,9 @@  discard block
 block discarded – undo
685 701
 		$_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour'];
686 702
 
687 703
 		// Hack in guest requiring verification!
688
-		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha']))
689
-			$_POST['posts_require_captcha'] = -1;
704
+		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha'])) {
705
+					$_POST['posts_require_captcha'] = -1;
706
+		}
690 707
 
691 708
 		$save_vars = $config_vars;
692 709
 		unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']);
@@ -703,14 +720,16 @@  discard block
 block discarded – undo
703 720
 		foreach ($context['qa_languages'] as $lang_id => $dummy)
704 721
 		{
705 722
 			// If we had some questions for this language before, but don't now, delete everything from that language.
706
-			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id]))
707
-				$changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
723
+			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id])) {
724
+							$changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
725
+			}
708 726
 
709 727
 			// Now step through and see if any existing questions no longer exist.
710
-			if (!empty($context['qa_by_lang'][$lang_id]))
711
-				foreach ($context['qa_by_lang'][$lang_id] as $q_id)
728
+			if (!empty($context['qa_by_lang'][$lang_id])) {
729
+							foreach ($context['qa_by_lang'][$lang_id] as $q_id)
712 730
 					if (empty($_POST['question'][$lang_id][$q_id]))
713 731
 						$changes['delete'][] = $q_id;
732
+			}
714 733
 
715 734
 			// Now let's see if there are new questions or ones that need updating.
716 735
 			if (isset($_POST['question'][$lang_id]))
@@ -719,14 +738,16 @@  discard block
 block discarded – undo
719 738
 				{
720 739
 					// Ignore junky ids.
721 740
 					$q_id = (int) $q_id;
722
-					if ($q_id <= 0)
723
-						continue;
741
+					if ($q_id <= 0) {
742
+											continue;
743
+					}
724 744
 
725 745
 					// Check the question isn't empty (because they want to delete it?)
726 746
 					if (empty($question) || trim($question) == '')
727 747
 					{
728
-						if (isset($context['question_answers'][$q_id]))
729
-							$changes['delete'][] = $q_id;
748
+						if (isset($context['question_answers'][$q_id])) {
749
+													$changes['delete'][] = $q_id;
750
+						}
730 751
 						continue;
731 752
 					}
732 753
 					$question = $smcFunc['htmlspecialchars'](trim($question));
@@ -734,19 +755,22 @@  discard block
 block discarded – undo
734 755
 					// Get the answers. Firstly check there actually might be some.
735 756
 					if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id]))
736 757
 					{
737
-						if (isset($context['question_answers'][$q_id]))
738
-							$changes['delete'][] = $q_id;
758
+						if (isset($context['question_answers'][$q_id])) {
759
+													$changes['delete'][] = $q_id;
760
+						}
739 761
 						continue;
740 762
 					}
741 763
 					// Now get them and check that they might be viable.
742 764
 					$answers = array();
743
-					foreach ($_POST['answer'][$lang_id][$q_id] as $answer)
744
-						if (!empty($answer) && trim($answer) !== '')
765
+					foreach ($_POST['answer'][$lang_id][$q_id] as $answer) {
766
+											if (!empty($answer) && trim($answer) !== '')
745 767
 							$answers[] = $smcFunc['htmlspecialchars'](trim($answer));
768
+					}
746 769
 					if (empty($answers))
747 770
 					{
748
-						if (isset($context['question_answers'][$q_id]))
749
-							$changes['delete'][] = $q_id;
771
+						if (isset($context['question_answers'][$q_id])) {
772
+													$changes['delete'][] = $q_id;
773
+						}
750 774
 						continue;
751 775
 					}
752 776
 					$answers = $smcFunc['json_encode']($answers);
@@ -756,16 +780,17 @@  discard block
 block discarded – undo
756 780
 					{
757 781
 						// New question. Now, we don't want to randomly consume ids, so we'll set those, rather than trusting the browser's supplied ids.
758 782
 						$changes['insert'][] = array($lang_id, $question, $answers);
759
-					}
760
-					else
783
+					} else
761 784
 					{
762 785
 						// It's an existing question. Let's see what's changed, if anything.
763
-						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers'])
764
-							$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
786
+						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers']) {
787
+													$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
788
+						}
765 789
 					}
766 790
 
767
-					if (!isset($qs_per_lang[$lang_id]))
768
-						$qs_per_lang[$lang_id] = 0;
791
+					if (!isset($qs_per_lang[$lang_id])) {
792
+											$qs_per_lang[$lang_id] = 0;
793
+					}
769 794
 					$qs_per_lang[$lang_id]++;
770 795
 				}
771 796
 			}
@@ -815,8 +840,9 @@  discard block
 block discarded – undo
815 840
 
816 841
 		// Lastly, the count of messages needs to be no more than the lowest number of questions for any one language.
817 842
 		$count_questions = empty($qs_per_lang) ? 0 : min($qs_per_lang);
818
-		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions)
819
-			$_POST['qa_verification_number'] = $count_questions;
843
+		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions) {
844
+					$_POST['qa_verification_number'] = $count_questions;
845
+		}
820 846
 
821 847
 		call_integration_hook('integrate_save_spam_settings', array(&$save_vars));
822 848
 
@@ -831,24 +857,27 @@  discard block
 block discarded – undo
831 857
 
832 858
 	$character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y'));
833 859
 	$_SESSION['visual_verification_code'] = '';
834
-	for ($i = 0; $i < 6; $i++)
835
-		$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
860
+	for ($i = 0; $i < 6; $i++) {
861
+			$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
862
+	}
836 863
 
837 864
 	// Some javascript for CAPTCHA.
838 865
 	$context['settings_post_javascript'] = '';
839
-	if ($context['use_graphic_library'])
840
-		$context['settings_post_javascript'] .= '
866
+	if ($context['use_graphic_library']) {
867
+			$context['settings_post_javascript'] .= '
841 868
 		function refreshImages()
842 869
 		{
843 870
 			var imageType = document.getElementById(\'visual_verification_type\').value;
844 871
 			document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType;
845 872
 		}';
873
+	}
846 874
 
847 875
 	// Show the image itself, or text saying we can't.
848
-	if ($context['use_graphic_library'])
849
-		$config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>';
850
-	else
851
-		$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
876
+	if ($context['use_graphic_library']) {
877
+			$config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>';
878
+	} else {
879
+			$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
880
+	}
852 881
 
853 882
 	// Hack for PM spam settings.
854 883
 	list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
@@ -858,9 +887,10 @@  discard block
 block discarded – undo
858 887
 	$modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha'];
859 888
 
860 889
 	// Some minor javascript for the guest post setting.
861
-	if ($modSettings['posts_require_captcha'])
862
-		$context['settings_post_javascript'] .= '
890
+	if ($modSettings['posts_require_captcha']) {
891
+			$context['settings_post_javascript'] .= '
863 892
 		document.getElementById(\'guests_require_captcha\').disabled = true;';
893
+	}
864 894
 
865 895
 	// And everything else.
866 896
 	$context['post_url'] = $scripturl . '?action=admin;area=antispam;save';
@@ -907,8 +937,9 @@  discard block
 block discarded – undo
907 937
 
908 938
 	call_integration_hook('integrate_signature_settings', array(&$config_vars));
909 939
 
910
-	if ($return_config)
911
-		return $config_vars;
940
+	if ($return_config) {
941
+			return $config_vars;
942
+	}
912 943
 
913 944
 	// Setup the template.
914 945
 	$context['page_title'] = $txt['signature_settings'];
@@ -963,8 +994,9 @@  discard block
 block discarded – undo
963 994
 				$sig = strtr($row['signature'], array('<br>' => "\n"));
964 995
 
965 996
 				// Max characters...
966
-				if (!empty($sig_limits[1]))
967
-					$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
997
+				if (!empty($sig_limits[1])) {
998
+									$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
999
+				}
968 1000
 				// Max lines...
969 1001
 				if (!empty($sig_limits[2]))
970 1002
 				{
@@ -974,8 +1006,9 @@  discard block
 block discarded – undo
974 1006
 						if ($sig[$i] == "\n")
975 1007
 						{
976 1008
 							$count++;
977
-							if ($count >= $sig_limits[2])
978
-								$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
1009
+							if ($count >= $sig_limits[2]) {
1010
+															$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
1011
+							}
979 1012
 						}
980 1013
 					}
981 1014
 				}
@@ -986,17 +1019,19 @@  discard block
 block discarded – undo
986 1019
 					{
987 1020
 						$limit_broke = 0;
988 1021
 						// Attempt to allow all sizes of abuse, so to speak.
989
-						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
990
-							$limit_broke = $sig_limits[7] . 'px';
991
-						elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
992
-							$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
993
-						elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
994
-							$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
995
-						elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
996
-							$limit_broke = 'large';
997
-
998
-						if ($limit_broke)
999
-							$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1022
+						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
1023
+													$limit_broke = $sig_limits[7] . 'px';
1024
+						} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
1025
+													$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
1026
+						} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
1027
+													$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
1028
+						} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
1029
+													$limit_broke = 'large';
1030
+						}
1031
+
1032
+						if ($limit_broke) {
1033
+													$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1034
+						}
1000 1035
 					}
1001 1036
 				}
1002 1037
 
@@ -1052,32 +1087,34 @@  discard block
 block discarded – undo
1052 1087
 											$img_offset = false;
1053 1088
 										}
1054 1089
 									}
1090
+								} else {
1091
+																	$replaces[$image] = '';
1055 1092
 								}
1056
-								else
1057
-									$replaces[$image] = '';
1058 1093
 
1059 1094
 								continue;
1060 1095
 							}
1061 1096
 
1062 1097
 							// Does it have predefined restraints? Width first.
1063
-							if ($matches[6][$key])
1064
-								$matches[2][$key] = $matches[6][$key];
1098
+							if ($matches[6][$key]) {
1099
+															$matches[2][$key] = $matches[6][$key];
1100
+							}
1065 1101
 							if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
1066 1102
 							{
1067 1103
 								$width = $sig_limits[5];
1068 1104
 								$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
1105
+							} elseif ($matches[2][$key]) {
1106
+															$width = $matches[2][$key];
1069 1107
 							}
1070
-							elseif ($matches[2][$key])
1071
-								$width = $matches[2][$key];
1072 1108
 							// ... and height.
1073 1109
 							if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
1074 1110
 							{
1075 1111
 								$height = $sig_limits[6];
1076
-								if ($width != -1)
1077
-									$width = $width * ($height / $matches[4][$key]);
1112
+								if ($width != -1) {
1113
+																	$width = $width * ($height / $matches[4][$key]);
1114
+								}
1115
+							} elseif ($matches[4][$key]) {
1116
+															$height = $matches[4][$key];
1078 1117
 							}
1079
-							elseif ($matches[4][$key])
1080
-								$height = $matches[4][$key];
1081 1118
 
1082 1119
 							// If the dimensions are still not fixed - we need to check the actual image.
1083 1120
 							if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -1095,12 +1132,13 @@  discard block
 block discarded – undo
1095 1132
 									if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
1096 1133
 									{
1097 1134
 										$height = $sig_limits[6];
1098
-										if ($width == -1)
1099
-											$width = $sizes[0];
1135
+										if ($width == -1) {
1136
+																					$width = $sizes[0];
1137
+										}
1100 1138
 										$width = $width * ($height / $sizes[1]);
1139
+									} elseif ($width != -1) {
1140
+																			$height = $sizes[1];
1101 1141
 									}
1102
-									elseif ($width != -1)
1103
-										$height = $sizes[1];
1104 1142
 								}
1105 1143
 							}
1106 1144
 
@@ -1113,8 +1151,9 @@  discard block
 block discarded – undo
1113 1151
 							// Record that we got one.
1114 1152
 							$image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1;
1115 1153
 						}
1116
-						if (!empty($replaces))
1117
-							$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1154
+						if (!empty($replaces)) {
1155
+													$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1156
+						}
1118 1157
 					}
1119 1158
 				}
1120 1159
 				// Try to fix disabled tags.
@@ -1126,18 +1165,20 @@  discard block
 block discarded – undo
1126 1165
 
1127 1166
 				$sig = strtr($sig, array("\n" => '<br>'));
1128 1167
 				call_integration_hook('integrate_apply_signature_settings', array(&$sig, $sig_limits, $disabledTags));
1129
-				if ($sig != $row['signature'])
1130
-					$changes[$row['id_member']] = $sig;
1168
+				if ($sig != $row['signature']) {
1169
+									$changes[$row['id_member']] = $sig;
1170
+				}
1171
+			}
1172
+			if ($smcFunc['db_num_rows']($request) == 0) {
1173
+							$done = true;
1131 1174
 			}
1132
-			if ($smcFunc['db_num_rows']($request) == 0)
1133
-				$done = true;
1134 1175
 			$smcFunc['db_free_result']($request);
1135 1176
 
1136 1177
 			// Do we need to delete what we have?
1137 1178
 			if (!empty($changes))
1138 1179
 			{
1139
-				foreach ($changes as $id => $sig)
1140
-					$smcFunc['db_query']('', '
1180
+				foreach ($changes as $id => $sig) {
1181
+									$smcFunc['db_query']('', '
1141 1182
 						UPDATE {db_prefix}members
1142 1183
 						SET signature = {string:signature}
1143 1184
 						WHERE id_member = {int:id_member}',
@@ -1146,11 +1187,13 @@  discard block
 block discarded – undo
1146 1187
 							'signature' => $sig,
1147 1188
 						)
1148 1189
 					);
1190
+				}
1149 1191
 			}
1150 1192
 
1151 1193
 			$_GET['step'] += 50;
1152
-			if (!$done)
1153
-				pauseSignatureApplySettings();
1194
+			if (!$done) {
1195
+							pauseSignatureApplySettings();
1196
+			}
1154 1197
 		}
1155 1198
 		$settings_applied = true;
1156 1199
 	}
@@ -1168,8 +1211,9 @@  discard block
 block discarded – undo
1168 1211
 	);
1169 1212
 
1170 1213
 	// Temporarily make each setting a modSetting!
1171
-	foreach ($context['signature_settings'] as $key => $value)
1172
-		$modSettings['signature_' . $key] = $value;
1214
+	foreach ($context['signature_settings'] as $key => $value) {
1215
+			$modSettings['signature_' . $key] = $value;
1216
+	}
1173 1217
 
1174 1218
 	// Make sure we check the right tags!
1175 1219
 	$modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
@@ -1181,23 +1225,26 @@  discard block
 block discarded – undo
1181 1225
 
1182 1226
 		// Clean up the tag stuff!
1183 1227
 		$bbcTags = array();
1184
-		foreach (parse_bbc(false) as $tag)
1185
-			$bbcTags[] = $tag['tag'];
1228
+		foreach (parse_bbc(false) as $tag) {
1229
+					$bbcTags[] = $tag['tag'];
1230
+		}
1186 1231
 
1187
-		if (!isset($_POST['signature_bbc_enabledTags']))
1188
-			$_POST['signature_bbc_enabledTags'] = array();
1189
-		elseif (!is_array($_POST['signature_bbc_enabledTags']))
1190
-			$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1232
+		if (!isset($_POST['signature_bbc_enabledTags'])) {
1233
+					$_POST['signature_bbc_enabledTags'] = array();
1234
+		} elseif (!is_array($_POST['signature_bbc_enabledTags'])) {
1235
+					$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1236
+		}
1191 1237
 
1192 1238
 		$sig_limits = array();
1193 1239
 		foreach ($context['signature_settings'] as $key => $value)
1194 1240
 		{
1195
-			if ($key == 'allow_smileys')
1196
-				continue;
1197
-			elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys']))
1198
-				$sig_limits[] = -1;
1199
-			else
1200
-				$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1241
+			if ($key == 'allow_smileys') {
1242
+							continue;
1243
+			} elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys'])) {
1244
+							$sig_limits[] = -1;
1245
+			} else {
1246
+							$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1247
+			}
1201 1248
 		}
1202 1249
 
1203 1250
 		call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags));
@@ -1230,12 +1277,14 @@  discard block
 block discarded – undo
1230 1277
 
1231 1278
 	// Try get more time...
1232 1279
 	@set_time_limit(600);
1233
-	if (function_exists('apache_reset_timeout'))
1234
-		@apache_reset_timeout();
1280
+	if (function_exists('apache_reset_timeout')) {
1281
+			@apache_reset_timeout();
1282
+	}
1235 1283
 
1236 1284
 	// Have we exhausted all the time we allowed?
1237
-	if (time() - array_sum(explode(' ', $sig_start)) < 3)
1238
-		return;
1285
+	if (time() - array_sum(explode(' ', $sig_start)) < 3) {
1286
+			return;
1287
+	}
1239 1288
 
1240 1289
 	$context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1241 1290
 	$context['page_title'] = $txt['not_done_title'];
@@ -1281,9 +1330,10 @@  discard block
 block discarded – undo
1281 1330
 		$disable_fields = array_flip($standard_fields);
1282 1331
 		if (!empty($_POST['active']))
1283 1332
 		{
1284
-			foreach ($_POST['active'] as $value)
1285
-				if (isset($disable_fields[$value]))
1333
+			foreach ($_POST['active'] as $value) {
1334
+							if (isset($disable_fields[$value]))
1286 1335
 					unset($disable_fields[$value]);
1336
+			}
1287 1337
 		}
1288 1338
 		// What we have left!
1289 1339
 		$changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields));
@@ -1292,16 +1342,18 @@  discard block
 block discarded – undo
1292 1342
 		$reg_fields = array();
1293 1343
 		if (!empty($_POST['reg']))
1294 1344
 		{
1295
-			foreach ($_POST['reg'] as $value)
1296
-				if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1345
+			foreach ($_POST['reg'] as $value) {
1346
+							if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1297 1347
 					$reg_fields[] = $value;
1348
+			}
1298 1349
 		}
1299 1350
 		// What we have left!
1300 1351
 		$changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
1301 1352
 
1302 1353
 		$_SESSION['adm-save'] = true;
1303
-		if (!empty($changes))
1304
-			updateSettings($changes);
1354
+		if (!empty($changes)) {
1355
+					updateSettings($changes);
1356
+		}
1305 1357
 	}
1306 1358
 
1307 1359
 	createToken('admin-scp');
@@ -1404,11 +1456,13 @@  discard block
 block discarded – undo
1404 1456
 					{
1405 1457
 						$return = '<p class="centertext bold_text">'. $rowData['field_order'] .'<br>';
1406 1458
 
1407
-						if ($rowData['field_order'] > 1)
1408
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1459
+						if ($rowData['field_order'] > 1) {
1460
+													$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1461
+						}
1409 1462
 
1410
-						if ($rowData['field_order'] < $context['custFieldsMaxOrder'])
1411
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1463
+						if ($rowData['field_order'] < $context['custFieldsMaxOrder']) {
1464
+													$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1465
+						}
1412 1466
 
1413 1467
 						$return .= '</p>';
1414 1468
 
@@ -1546,16 +1600,16 @@  discard block
 block discarded – undo
1546 1600
 		$disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
1547 1601
 		$registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array();
1548 1602
 
1549
-		foreach ($standard_fields as $field)
1550
-			$list[] = array(
1603
+		foreach ($standard_fields as $field) {
1604
+					$list[] = array(
1551 1605
 				'id' => $field,
1552 1606
 				'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field),
1553 1607
 				'disabled' => in_array($field, $disabled_fields),
1554 1608
 				'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration),
1555 1609
 				'can_show_register' => !in_array($field, $fields_no_registration),
1556 1610
 			);
1557
-	}
1558
-	else
1611
+		}
1612
+	} else
1559 1613
 	{
1560 1614
 		// Load all the fields.
1561 1615
 		$request = $smcFunc['db_query']('', '
@@ -1569,8 +1623,9 @@  discard block
 block discarded – undo
1569 1623
 				'items_per_page' => $items_per_page,
1570 1624
 			)
1571 1625
 		);
1572
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1573
-			$list[] = $row;
1626
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1627
+					$list[] = $row;
1628
+		}
1574 1629
 		$smcFunc['db_free_result']($request);
1575 1630
 	}
1576 1631
 
@@ -1636,9 +1691,9 @@  discard block
 block discarded – undo
1636 1691
 		$context['field'] = array();
1637 1692
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1638 1693
 		{
1639
-			if ($row['field_type'] == 'textarea')
1640
-				@list ($rows, $cols) = @explode(',', $row['default_value']);
1641
-			else
1694
+			if ($row['field_type'] == 'textarea') {
1695
+							@list ($rows, $cols) = @explode(',', $row['default_value']);
1696
+			} else
1642 1697
 			{
1643 1698
 				$rows = 3;
1644 1699
 				$cols = 30;
@@ -1674,8 +1729,8 @@  discard block
 block discarded – undo
1674 1729
 	}
1675 1730
 
1676 1731
 	// Setup the default values as needed.
1677
-	if (empty($context['field']))
1678
-		$context['field'] = array(
1732
+	if (empty($context['field'])) {
1733
+			$context['field'] = array(
1679 1734
 			'name' => '',
1680 1735
 			'col_name' => '???',
1681 1736
 			'desc' => '',
@@ -1700,6 +1755,7 @@  discard block
 block discarded – undo
1700 1755
 			'enclose' => '',
1701 1756
 			'placement' => 0,
1702 1757
 		);
1758
+	}
1703 1759
 
1704 1760
 	// Are we moving it?
1705 1761
 	if (isset($_GET['move']) && in_array($smcFunc['htmlspecialchars']($_GET['move']), $move_to))
@@ -1708,8 +1764,10 @@  discard block
 block discarded – undo
1708 1764
 		$new_order = ($_GET['move'] == 'up' ? ($context['field']['order'] - 1) : ($context['field']['order'] + 1));
1709 1765
 
1710 1766
 		// Is this a valid position?
1711
-		if ($new_order <= 0 || $new_order > $order_count)
1712
-			redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler
1767
+		if ($new_order <= 0 || $new_order > $order_count) {
1768
+					redirectexit('action=admin;area=featuresettings;sa=profile');
1769
+		}
1770
+		// @todo implement an error handler
1713 1771
 
1714 1772
 		// All good, proceed.
1715 1773
 		$smcFunc['db_query']('','
@@ -1740,12 +1798,14 @@  discard block
 block discarded – undo
1740 1798
 		validateToken('admin-ecp');
1741 1799
 
1742 1800
 		// Everyone needs a name - even the (bracket) unknown...
1743
-		if (trim($_POST['field_name']) == '')
1744
-			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1801
+		if (trim($_POST['field_name']) == '') {
1802
+					redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1803
+		}
1745 1804
 
1746 1805
 		// Regex you say?  Do a very basic test to see if the pattern is valid
1747
-		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false)
1748
-			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1806
+		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false) {
1807
+					redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1808
+		}
1749 1809
 
1750 1810
 		$_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']);
1751 1811
 		$_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']);
@@ -1762,8 +1822,9 @@  discard block
 block discarded – undo
1762 1822
 
1763 1823
 		// Some masking stuff...
1764 1824
 		$mask = isset($_POST['mask']) ? $_POST['mask'] : '';
1765
-		if ($mask == 'regex' && isset($_POST['regex']))
1766
-			$mask .= $_POST['regex'];
1825
+		if ($mask == 'regex' && isset($_POST['regex'])) {
1826
+					$mask .= $_POST['regex'];
1827
+		}
1767 1828
 
1768 1829
 		$field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255;
1769 1830
 		$enclose = isset($_POST['enclose']) ? $_POST['enclose'] : '';
@@ -1782,8 +1843,9 @@  discard block
 block discarded – undo
1782 1843
 				$v = strtr($v, array(',' => ''));
1783 1844
 
1784 1845
 				// Nada, zip, etc...
1785
-				if (trim($v) == '')
1786
-					continue;
1846
+				if (trim($v) == '') {
1847
+									continue;
1848
+				}
1787 1849
 
1788 1850
 				// Otherwise, save it boy.
1789 1851
 				$field_options .= $v . ',';
@@ -1791,15 +1853,17 @@  discard block
 block discarded – undo
1791 1853
 				$newOptions[$k] = $v;
1792 1854
 
1793 1855
 				// Is it default?
1794
-				if (isset($_POST['default_select']) && $_POST['default_select'] == $k)
1795
-					$default = $v;
1856
+				if (isset($_POST['default_select']) && $_POST['default_select'] == $k) {
1857
+									$default = $v;
1858
+				}
1796 1859
 			}
1797 1860
 			$field_options = substr($field_options, 0, -1);
1798 1861
 		}
1799 1862
 
1800 1863
 		// Text area has default has dimensions
1801
-		if ($_POST['field_type'] == 'textarea')
1802
-			$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1864
+		if ($_POST['field_type'] == 'textarea') {
1865
+					$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1866
+		}
1803 1867
 
1804 1868
 		// Come up with the unique name?
1805 1869
 		if (empty($context['fid']))
@@ -1808,32 +1872,36 @@  discard block
 block discarded – undo
1808 1872
 			preg_match('~([\w\d_-]+)~', $col_name, $matches);
1809 1873
 
1810 1874
 			// If there is nothing to the name, then let's start out own - for foreign languages etc.
1811
-			if (isset($matches[1]))
1812
-				$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1813
-			else
1814
-				$col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999);
1875
+			if (isset($matches[1])) {
1876
+							$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1877
+			} else {
1878
+							$col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999);
1879
+			}
1815 1880
 
1816 1881
 			// Make sure this is unique.
1817 1882
 			$current_fields = array();
1818 1883
 			$request = $smcFunc['db_query']('', '
1819 1884
 				SELECT id_field, col_name
1820 1885
 				FROM {db_prefix}custom_fields');
1821
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1822
-				$current_fields[$row['id_field']] = $row['col_name'];
1886
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1887
+							$current_fields[$row['id_field']] = $row['col_name'];
1888
+			}
1823 1889
 			$smcFunc['db_free_result']($request);
1824 1890
 
1825 1891
 			$unique = false;
1826 1892
 			for ($i = 0; !$unique && $i < 9; $i ++)
1827 1893
 			{
1828
-				if (!in_array($col_name, $current_fields))
1829
-					$unique = true;
1830
-				else
1831
-					$col_name = $initial_col_name . $i;
1894
+				if (!in_array($col_name, $current_fields)) {
1895
+									$unique = true;
1896
+				} else {
1897
+									$col_name = $initial_col_name . $i;
1898
+				}
1832 1899
 			}
1833 1900
 
1834 1901
 			// Still not a unique column name? Leave it up to the user, then.
1835
-			if (!$unique)
1836
-				fatal_lang_error('custom_option_not_unique');
1902
+			if (!$unique) {
1903
+							fatal_lang_error('custom_option_not_unique');
1904
+			}
1837 1905
 		}
1838 1906
 		// Work out what to do with the user data otherwise...
1839 1907
 		else
@@ -1861,8 +1929,9 @@  discard block
 block discarded – undo
1861 1929
 				// Work out what's changed!
1862 1930
 				foreach ($context['field']['options'] as $k => $option)
1863 1931
 				{
1864
-					if (trim($option) == '')
1865
-						continue;
1932
+					if (trim($option) == '') {
1933
+											continue;
1934
+					}
1866 1935
 
1867 1936
 					// Still exists?
1868 1937
 					if (in_array($option, $newOptions))
@@ -1876,8 +1945,8 @@  discard block
 block discarded – undo
1876 1945
 				foreach ($optionChanges as $k => $option)
1877 1946
 				{
1878 1947
 					// Just been renamed?
1879
-					if (!in_array($k, $takenKeys) && !empty($newOptions[$k]))
1880
-						$smcFunc['db_query']('', '
1948
+					if (!in_array($k, $takenKeys) && !empty($newOptions[$k])) {
1949
+											$smcFunc['db_query']('', '
1881 1950
 							UPDATE {db_prefix}themes
1882 1951
 							SET value = {string:new_value}
1883 1952
 							WHERE variable = {string:current_column}
@@ -1890,6 +1959,7 @@  discard block
 block discarded – undo
1890 1959
 								'old_value' => $option,
1891 1960
 							)
1892 1961
 						);
1962
+					}
1893 1963
 				}
1894 1964
 			}
1895 1965
 			// @todo Maybe we should adjust based on new text length limits?
@@ -1932,8 +2002,8 @@  discard block
 block discarded – undo
1932 2002
 			);
1933 2003
 
1934 2004
 			// Just clean up any old selects - these are a pain!
1935
-			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions))
1936
-				$smcFunc['db_query']('', '
2005
+			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions)) {
2006
+							$smcFunc['db_query']('', '
1937 2007
 					DELETE FROM {db_prefix}themes
1938 2008
 					WHERE variable = {string:current_column}
1939 2009
 						AND value NOT IN ({array_string:new_option_values})
@@ -1944,8 +2014,8 @@  discard block
 block discarded – undo
1944 2014
 						'current_column' => $context['field']['col_name'],
1945 2015
 					)
1946 2016
 				);
1947
-		}
1948
-		else
2017
+			}
2018
+		} else
1949 2019
 		{
1950 2020
 			// Gotta figure it out the order.
1951 2021
 			$new_order = $order_count > 1 ? ($order_count + 1) : 1;
@@ -2120,11 +2190,13 @@  discard block
 block discarded – undo
2120 2190
 	call_integration_hook('integrate_prune_settings', array(&$config_vars, &$prune_toggle, false));
2121 2191
 
2122 2192
 	$prune_toggle_dt = array();
2123
-	foreach ($prune_toggle as $item)
2124
-		$prune_toggle_dt[] = 'setting_' . $item;
2193
+	foreach ($prune_toggle as $item) {
2194
+			$prune_toggle_dt[] = 'setting_' . $item;
2195
+	}
2125 2196
 
2126
-	if ($return_config)
2127
-		return $config_vars;
2197
+	if ($return_config) {
2198
+			return $config_vars;
2199
+	}
2128 2200
 
2129 2201
 	addInlineJavaScript('
2130 2202
 	function togglePruned()
@@ -2162,15 +2234,16 @@  discard block
 block discarded – undo
2162 2234
 			$vals = array();
2163 2235
 			foreach ($config_vars as $index => $dummy)
2164 2236
 			{
2165
-				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle))
2166
-					continue;
2237
+				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle)) {
2238
+									continue;
2239
+				}
2167 2240
 
2168 2241
 				$vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]];
2169 2242
 			}
2170 2243
 			$_POST['pruningOptions'] = implode(',', $vals);
2244
+		} else {
2245
+					$_POST['pruningOptions'] = '';
2171 2246
 		}
2172
-		else
2173
-			$_POST['pruningOptions'] = '';
2174 2247
 
2175 2248
 		saveDBSettings($savevar);
2176 2249
 		$_SESSION['adm-save'] = true;
@@ -2182,10 +2255,11 @@  discard block
 block discarded – undo
2182 2255
 	$context['sub_template'] = 'show_settings';
2183 2256
 
2184 2257
 	// Get the actual values
2185
-	if (!empty($modSettings['pruningOptions']))
2186
-		@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2187
-	else
2188
-		$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2258
+	if (!empty($modSettings['pruningOptions'])) {
2259
+			@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2260
+	} else {
2261
+			$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2262
+	}
2189 2263
 
2190 2264
 	prepareDBSettingContext($config_vars);
2191 2265
 }
@@ -2207,8 +2281,9 @@  discard block
 block discarded – undo
2207 2281
 	// Make it even easier to add new settings.
2208 2282
 	call_integration_hook('integrate_general_mod_settings', array(&$config_vars));
2209 2283
 
2210
-	if ($return_config)
2211
-		return $config_vars;
2284
+	if ($return_config) {
2285
+			return $config_vars;
2286
+	}
2212 2287
 
2213 2288
 	$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general';
2214 2289
 	$context['settings_title'] = $txt['mods_cat_modifications_misc'];
Please login to merge, or discard this patch.
Sources/Modlog.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 					'class' => 'centercol',
257 257
 				),
258 258
 				'data' => array(
259
-					'function' => function ($entry)
259
+					'function' => function($entry)
260 260
 					{
261 261
 						return '<input type="checkbox" name="delete[]" value="' . $entry['id'] . '"' . ($entry['editable'] ? '' : ' disabled') . '>';
262 262
 					},
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 		if (empty($entries[$k]['action_text']))
639 639
 			$entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action'];
640 640
 		$entries[$k]['action_text'] = preg_replace_callback('~\{([A-Za-z\d_]+)\}~i',
641
-			function ($matches) use ($entries, $k)
641
+			function($matches) use ($entries, $k)
642 642
 			{
643 643
 				return isset($entries[$k]['extra'][$matches[1]]) ? $entries[$k]['extra'][$matches[1]] : '';
644 644
 			}, $entries[$k]['action_text']);
Please login to merge, or discard this patch.
Braces   +99 added lines, -75 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
  * Prepares the information from the moderation log for viewing.
@@ -32,14 +33,16 @@  discard block
 block discarded – undo
32 33
 
33 34
 	// Are we looking at the moderation log or the administration log.
34 35
 	$context['log_type'] = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 3 : 1;
35
-	if ($context['log_type'] == 3)
36
-		isAllowedTo('admin_forum');
36
+	if ($context['log_type'] == 3) {
37
+			isAllowedTo('admin_forum');
38
+	}
37 39
 
38 40
 	// These change dependant on whether we are viewing the moderation or admin log.
39
-	if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin')
40
-		$context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type'];
41
-	else
42
-		$context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type'];
41
+	if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin') {
42
+			$context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type'];
43
+	} else {
44
+			$context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type'];
45
+	}
43 46
 
44 47
 	$context['can_delete'] = allowedTo('admin_forum');
45 48
 
@@ -67,8 +70,7 @@  discard block
 block discarded – undo
67 70
 		$log_type = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 'admin' : 'moderate';
68 71
 		logAction('clearlog_' . $log_type, array(), $log_type);
69 72
 
70
-	}
71
-	elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete'])
73
+	} elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete'])
72 74
 	{
73 75
 		checkSession();
74 76
 		validateToken('mod-ml');
@@ -114,15 +116,17 @@  discard block
 block discarded – undo
114 116
 		'ip' => array('sql' => 'lm.ip', 'label' => $txt['modlog_ip'])
115 117
 	);
116 118
 
117
-	if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search']))
118
-		$search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
119
-	else
120
-		$search_params_string = $search_params['string'];
119
+	if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) {
120
+			$search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
121
+	} else {
122
+			$search_params_string = $search_params['string'];
123
+	}
121 124
 
122
-	if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']]))
123
-		$search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
124
-	else
125
-		$search_params_type = $search_params['type'];
125
+	if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) {
126
+			$search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
127
+	} else {
128
+			$search_params_type = $search_params['type'];
129
+	}
126 130
 
127 131
 	$search_params_column = $searchTypes[$search_params_type]['sql'];
128 132
 	$search_params = array(
@@ -301,15 +305,16 @@  discard block
 block discarded – undo
301 305
 	$context['default_list'] = 'moderation_log_list';
302 306
 
303 307
 	// If a hook has changed this, respect it.
304
-	if (!empty($moderation_menu_name))
305
-		$context[$context['moderation_menu_name']]['tab_data'] = $moderation_menu_name;
306
-	elseif (isset($context['moderation_menu_name']))
307
-		$context[$context['moderation_menu_name']]['tab_data'] = array(
308
+	if (!empty($moderation_menu_name)) {
309
+			$context[$context['moderation_menu_name']]['tab_data'] = $moderation_menu_name;
310
+	} elseif (isset($context['moderation_menu_name'])) {
311
+			$context[$context['moderation_menu_name']]['tab_data'] = array(
308 312
 			'title' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log'],
309 313
 			'help' => $context['log_type'] == 3 ? 'adminlog' : 'modlog',
310 314
 			'description' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log_desc']
311 315
 		);
312
-}
316
+	}
317
+	}
313 318
 
314 319
 /**
315 320
  * Get the number of mod log entries.
@@ -413,30 +418,35 @@  discard block
 block discarded – undo
413 418
 		// Add on some of the column stuff info
414 419
 		if (!empty($row['id_board']))
415 420
 		{
416
-			if ($row['action'] == 'move')
417
-				$row['extra']['board_to'] = $row['id_board'];
418
-			else
419
-				$row['extra']['board'] = $row['id_board'];
421
+			if ($row['action'] == 'move') {
422
+							$row['extra']['board_to'] = $row['id_board'];
423
+			} else {
424
+							$row['extra']['board'] = $row['id_board'];
425
+			}
420 426
 		}
421 427
 
422
-		if (!empty($row['id_topic']))
423
-			$row['extra']['topic'] = $row['id_topic'];
424
-		if (!empty($row['id_msg']))
425
-			$row['extra']['message'] = $row['id_msg'];
428
+		if (!empty($row['id_topic'])) {
429
+					$row['extra']['topic'] = $row['id_topic'];
430
+		}
431
+		if (!empty($row['id_msg'])) {
432
+					$row['extra']['message'] = $row['id_msg'];
433
+		}
426 434
 
427 435
 		// Is this associated with a topic?
428
-		if (isset($row['extra']['topic']))
429
-			$topics[(int) $row['extra']['topic']][] = $row['id_action'];
430
-		if (isset($row['extra']['new_topic']))
431
-			$topics[(int) $row['extra']['new_topic']][] = $row['id_action'];
436
+		if (isset($row['extra']['topic'])) {
437
+					$topics[(int) $row['extra']['topic']][] = $row['id_action'];
438
+		}
439
+		if (isset($row['extra']['new_topic'])) {
440
+					$topics[(int) $row['extra']['new_topic']][] = $row['id_action'];
441
+		}
432 442
 
433 443
 		// How about a member?
434 444
 		if (isset($row['extra']['member']))
435 445
 		{
436 446
 			// Guests don't have names!
437
-			if (empty($row['extra']['member']))
438
-				$row['extra']['member'] = $txt['modlog_parameter_guest'];
439
-			else
447
+			if (empty($row['extra']['member'])) {
448
+							$row['extra']['member'] = $txt['modlog_parameter_guest'];
449
+			} else
440 450
 			{
441 451
 				// Try to find it...
442 452
 				$members[(int) $row['extra']['member']][] = $row['id_action'];
@@ -444,35 +454,42 @@  discard block
 block discarded – undo
444 454
 		}
445 455
 
446 456
 		// Associated with a board?
447
-		if (isset($row['extra']['board_to']))
448
-			$boards[(int) $row['extra']['board_to']][] = $row['id_action'];
449
-		if (isset($row['extra']['board_from']))
450
-			$boards[(int) $row['extra']['board_from']][] = $row['id_action'];
451
-		if (isset($row['extra']['board']))
452
-			$boards[(int) $row['extra']['board']][] = $row['id_action'];
457
+		if (isset($row['extra']['board_to'])) {
458
+					$boards[(int) $row['extra']['board_to']][] = $row['id_action'];
459
+		}
460
+		if (isset($row['extra']['board_from'])) {
461
+					$boards[(int) $row['extra']['board_from']][] = $row['id_action'];
462
+		}
463
+		if (isset($row['extra']['board'])) {
464
+					$boards[(int) $row['extra']['board']][] = $row['id_action'];
465
+		}
453 466
 
454 467
 		// A message?
455
-		if (isset($row['extra']['message']))
456
-			$messages[(int) $row['extra']['message']][] = $row['id_action'];
468
+		if (isset($row['extra']['message'])) {
469
+					$messages[(int) $row['extra']['message']][] = $row['id_action'];
470
+		}
457 471
 
458 472
 		// IP Info?
459
-		if (isset($row['extra']['ip_range']))
460
-			if ($seeIP)
473
+		if (isset($row['extra']['ip_range'])) {
474
+					if ($seeIP)
461 475
 				$row['extra']['ip_range'] = '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['extra']['ip_range'] . '">' . $row['extra']['ip_range'] . '</a>';
462
-			else
463
-				$row['extra']['ip_range'] = $txt['logged'];
476
+		} else {
477
+							$row['extra']['ip_range'] = $txt['logged'];
478
+			}
464 479
 
465 480
 		// Email?
466
-		if (isset($row['extra']['email']))
467
-			$row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>';
481
+		if (isset($row['extra']['email'])) {
482
+					$row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>';
483
+		}
468 484
 
469 485
 		// Bans are complex.
470 486
 		if ($row['action'] == 'ban' || $row['action'] == 'banremove')
471 487
 		{
472 488
 			$row['action_text'] = $txt['modlog_ac_ban' . ($row['action'] == 'banremove' ? '_remove' : '')];
473
-			foreach (array('member', 'email', 'ip_range', 'hostname') as $type)
474
-				if (isset($row['extra'][$type]))
489
+			foreach (array('member', 'email', 'ip_range', 'hostname') as $type) {
490
+							if (isset($row['extra'][$type]))
475 491
 					$row['action_text'] .= $txt['modlog_ac_ban_trigger_' . $type];
492
+			}
476 493
 		}
477 494
 
478 495
 		// The array to go to the template. Note here that action is set to a "default" value of the action doesn't match anything in the descriptions. Allows easy adding of logging events with basic details.
@@ -508,12 +525,13 @@  discard block
 block discarded – undo
508 525
 			foreach ($boards[$row['id_board']] as $action)
509 526
 			{
510 527
 				// Make the board number into a link - dealing with moving too.
511
-				if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board'])
512
-					$entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
513
-				elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board'])
514
-					$entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
515
-				elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board'])
516
-					$entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
528
+				if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board']) {
529
+									$entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
530
+				} elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board']) {
531
+									$entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
532
+				} elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board']) {
533
+									$entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
534
+				}
517 535
 			}
518 536
 		}
519 537
 		$smcFunc['db_free_result']($request);
@@ -547,10 +565,11 @@  discard block
 block discarded – undo
547 565
 				);
548 566
 
549 567
 				// Make the topic number into a link - dealing with splitting too.
550
-				if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic'])
551
-					$this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
552
-				elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic'])
553
-					$this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
568
+				if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic']) {
569
+									$this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
570
+				} elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic']) {
571
+									$this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
572
+				}
554 573
 			}
555 574
 		}
556 575
 		$smcFunc['db_free_result']($request);
@@ -583,8 +602,9 @@  discard block
 block discarded – undo
583 602
 				);
584 603
 
585 604
 				// Make the message number into a link.
586
-				if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg'])
587
-					$this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
605
+				if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg']) {
606
+									$this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
607
+				}
588 608
 			}
589 609
 		}
590 610
 		$smcFunc['db_free_result']($request);
@@ -624,25 +644,29 @@  discard block
 block discarded – undo
624 644
 	foreach ($entries as $k => $entry)
625 645
 	{
626 646
 		// Make any message info links so its easier to go find that message.
627
-		if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id'])))
628
-			$entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>';
647
+		if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id']))) {
648
+					$entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>';
649
+		}
629 650
 
630 651
 		// Mark up any deleted members, topics and boards.
631
-		foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type)
632
-			if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type]))
652
+		foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type) {
653
+					if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type]))
633 654
 				$entries[$k]['extra'][$type] = sprintf($txt['modlog_id'], $entry['extra'][$type]);
655
+		}
634 656
 
635 657
 		if (isset($entry['extra']['report']))
636 658
 		{
637 659
 			// Member profile reports go in a different area
638
-			if (stristr($entry['action'], 'user_report'))
639
-				$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
640
-			else
641
-				$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
660
+			if (stristr($entry['action'], 'user_report')) {
661
+							$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
662
+			} else {
663
+							$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
664
+			}
642 665
 		}
643 666
 
644
-		if (empty($entries[$k]['action_text']))
645
-			$entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action'];
667
+		if (empty($entries[$k]['action_text'])) {
668
+					$entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action'];
669
+		}
646 670
 		$entries[$k]['action_text'] = preg_replace_callback('~\{([A-Za-z\d_]+)\}~i',
647 671
 			function ($matches) use ($entries, $k)
648 672
 			{
Please login to merge, or discard this patch.