Completed
Push — release-2.1 ( 9df441...754615 )
by Mathias
15s
created
Sources/Subs-Package.php 1 patch
Braces   +796 added lines, -622 removed lines patch added patch discarded remove patch
@@ -16,8 +16,9 @@  discard block
 block discarded – undo
16 16
  * @version 2.1 Beta 4
17 17
  */
18 18
 
19
-if (!defined('SMF'))
19
+if (!defined('SMF')) {
20 20
 	die('No direct access...');
21
+}
21 22
 
22 23
 /**
23 24
  * Reads a .tar.gz file, filename, in and extracts file(s) from it.
@@ -67,47 +68,53 @@  discard block
 block discarded – undo
67 68
 	loadLanguage('Packages');
68 69
 
69 70
 	// This function sorta needs gzinflate!
70
-	if (!function_exists('gzinflate'))
71
-		fatal_lang_error('package_no_zlib', 'critical');
71
+	if (!function_exists('gzinflate')) {
72
+			fatal_lang_error('package_no_zlib', 'critical');
73
+	}
72 74
 
73 75
 	if (substr($gzfilename, 0, 7) == 'http://' || substr($gzfilename, 0, 8) == 'https://')
74 76
 	{
75 77
 		$data = fetch_web_data($gzfilename);
76 78
 
77
-		if ($data === false)
78
-			return false;
79
-	}
80
-	else
79
+		if ($data === false) {
80
+					return false;
81
+		}
82
+	} else
81 83
 	{
82 84
 		$data = @file_get_contents($gzfilename);
83 85
 
84
-		if ($data === false)
85
-			return false;
86
+		if ($data === false) {
87
+					return false;
88
+		}
86 89
 	}
87 90
 
88 91
 	umask(0);
89
-	if (!$single_file && $destination !== null && !file_exists($destination))
90
-		mktree($destination, 0777);
92
+	if (!$single_file && $destination !== null && !file_exists($destination)) {
93
+			mktree($destination, 0777);
94
+	}
91 95
 
92 96
 	// No signature?
93
-	if (strlen($data) < 2)
94
-		return false;
97
+	if (strlen($data) < 2) {
98
+			return false;
99
+	}
95 100
 
96 101
 	$id = unpack('H2a/H2b', substr($data, 0, 2));
97 102
 	if (strtolower($id['a'] . $id['b']) != '1f8b')
98 103
 	{
99 104
 		// Okay, this ain't no tar.gz, but maybe it's a zip file.
100
-		if (substr($data, 0, 2) == 'PK')
101
-			return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract);
102
-		else
103
-			return false;
105
+		if (substr($data, 0, 2) == 'PK') {
106
+					return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract);
107
+		} else {
108
+					return false;
109
+		}
104 110
 	}
105 111
 
106 112
 	$flags = unpack('Ct/Cf', substr($data, 2, 2));
107 113
 
108 114
 	// Not deflate!
109
-	if ($flags['t'] != 8)
110
-		return false;
115
+	if ($flags['t'] != 8) {
116
+			return false;
117
+	}
111 118
 	$flags = $flags['f'];
112 119
 
113 120
 	$offset = 10;
@@ -117,18 +124,21 @@  discard block
 block discarded – undo
117 124
 	// @todo Might be mussed.
118 125
 	if ($flags & 12)
119 126
 	{
120
-		while ($flags & 8 && $data{$offset++} != "\0")
121
-			continue;
122
-		while ($flags & 4 && $data{$offset++} != "\0")
123
-			continue;
127
+		while ($flags & 8 && $data{$offset++} != "\0") {
128
+					continue;
129
+		}
130
+		while ($flags & 4 && $data{$offset++} != "\0") {
131
+					continue;
132
+		}
124 133
 	}
125 134
 
126 135
 	$crc = unpack('Vcrc32/Visize', substr($data, strlen($data) - 8, 8));
127 136
 	$data = @gzinflate(substr($data, $offset, strlen($data) - 8 - $offset));
128 137
 
129 138
 	// smf_crc32 and crc32 may not return the same results, so we accept either.
130
-	if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data))
131
-		return false;
139
+	if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data)) {
140
+			return false;
141
+	}
132 142
 
133 143
 	$blocks = strlen($data) / 512 - 1;
134 144
 	$offset = 0;
@@ -149,83 +159,98 @@  discard block
 block discarded – undo
149 159
 
150 160
 		foreach ($current as $k => $v)
151 161
 		{
152
-			if (in_array($k, $octdec))
153
-				$current[$k] = octdec(trim($v));
154
-			else
155
-				$current[$k] = trim($v);
162
+			if (in_array($k, $octdec)) {
163
+							$current[$k] = octdec(trim($v));
164
+			} else {
165
+							$current[$k] = trim($v);
166
+			}
156 167
 		}
157 168
 
158
-		if ($current['type'] == 5 && substr($current['filename'], -1) != '/')
159
-			$current['filename'] .= '/';
169
+		if ($current['type'] == 5 && substr($current['filename'], -1) != '/') {
170
+					$current['filename'] .= '/';
171
+		}
160 172
 
161 173
 		$checksum = 256;
162
-		for ($i = 0; $i < 148; $i++)
163
-			$checksum += ord($header{$i});
164
-		for ($i = 156; $i < 512; $i++)
165
-			$checksum += ord($header{$i});
174
+		for ($i = 0; $i < 148; $i++) {
175
+					$checksum += ord($header{$i});
176
+		}
177
+		for ($i = 156; $i < 512; $i++) {
178
+					$checksum += ord($header{$i});
179
+		}
166 180
 
167
-		if ($current['checksum'] != $checksum)
168
-			break;
181
+		if ($current['checksum'] != $checksum) {
182
+					break;
183
+		}
169 184
 
170 185
 		$size = ceil($current['size'] / 512);
171 186
 		$current['data'] = substr($data, ++$offset << 9, $current['size']);
172 187
 		$offset += $size;
173 188
 
174 189
 		// Not a directory and doesn't exist already...
175
-		if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename']))
176
-			$write_this = true;
190
+		if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename'])) {
191
+					$write_this = true;
192
+		}
177 193
 		// File exists... check if it is newer.
178
-		elseif (substr($current['filename'], -1, 1) != '/')
179
-			$write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime'];
194
+		elseif (substr($current['filename'], -1, 1) != '/') {
195
+					$write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime'];
196
+		}
180 197
 		// Folder... create.
181 198
 		elseif ($destination !== null && !$single_file)
182 199
 		{
183 200
 			// Protect from accidental parent directory writing...
184 201
 			$current['filename'] = strtr($current['filename'], array('../' => '', '/..' => ''));
185 202
 
186
-			if (!file_exists($destination . '/' . $current['filename']))
187
-				mktree($destination . '/' . $current['filename'], 0777);
203
+			if (!file_exists($destination . '/' . $current['filename'])) {
204
+							mktree($destination . '/' . $current['filename'], 0777);
205
+			}
188 206
 			$write_this = false;
207
+		} else {
208
+					$write_this = false;
189 209
 		}
190
-		else
191
-			$write_this = false;
192 210
 
193 211
 		if ($write_this && $destination !== null)
194 212
 		{
195
-			if (strpos($current['filename'], '/') !== false && !$single_file)
196
-				mktree($destination . '/' . dirname($current['filename']), 0777);
213
+			if (strpos($current['filename'], '/') !== false && !$single_file) {
214
+							mktree($destination . '/' . dirname($current['filename']), 0777);
215
+			}
197 216
 
198 217
 			// Is this the file we're looking for?
199
-			if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename'])))
200
-				return $current['data'];
218
+			if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename']))) {
219
+							return $current['data'];
220
+			}
201 221
 			// If we're looking for another file, keep going.
202
-			elseif ($single_file)
203
-				continue;
222
+			elseif ($single_file) {
223
+							continue;
224
+			}
204 225
 			// Looking for restricted files?
205
-			elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract))
206
-				continue;
226
+			elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) {
227
+							continue;
228
+			}
207 229
 
208 230
 			package_put_contents($destination . '/' . $current['filename'], $current['data']);
209 231
 		}
210 232
 
211
-		if (substr($current['filename'], -1, 1) != '/')
212
-			$return[] = array(
233
+		if (substr($current['filename'], -1, 1) != '/') {
234
+					$return[] = array(
213 235
 				'filename' => $current['filename'],
214 236
 				'md5' => md5($current['data']),
215 237
 				'preview' => substr($current['data'], 0, 100),
216 238
 				'size' => $current['size'],
217 239
 				'skipped' => false
218 240
 			);
241
+		}
219 242
 	}
220 243
 
221
-	if ($destination !== null && !$single_file)
222
-		package_flush_cache();
244
+	if ($destination !== null && !$single_file) {
245
+			package_flush_cache();
246
+	}
223 247
 
224
-	if ($single_file)
225
-		return false;
226
-	else
227
-		return $return;
228
-}
248
+	if ($single_file) {
249
+			return false;
250
+	} else {
251
+			return $return;
252
+	}
253
+	}
229 254
 
230 255
 /**
231 256
  * Extract zip data. A functional copy of {@list read_zip_data()}.
@@ -247,9 +272,10 @@  discard block
 block discarded – undo
247 272
 		$return = array();
248 273
 
249 274
 		// Some hosted unix platforms require an extension; win may have .tmp & that works ok
250
-		if (!in_array(strtolower(pathinfo($file, PATHINFO_EXTENSION)), array('zip', 'tmp')))
251
-			if (@rename($file, $file . '.zip'))
275
+		if (!in_array(strtolower(pathinfo($file, PATHINFO_EXTENSION)), array('zip', 'tmp'))) {
276
+					if (@rename($file, $file . '.zip'))
252 277
 				$file = $file . '.zip';
278
+		}
253 279
 
254 280
 		$archive = new PharData($file, RecursiveIteratorIterator::SELF_FIRST, null, Phar::ZIP);
255 281
 		$iterator = new RecursiveIteratorIterator($archive, RecursiveIteratorIterator::SELF_FIRST);
@@ -259,65 +285,74 @@  discard block
 block discarded – undo
259 285
 			{
260 286
 				$i = $iterator->getSubPathname();
261 287
 				// If this is a file, and it doesn't exist.... happy days!
262
-				if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i))
263
-					$write_this = true;
288
+				if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i)) {
289
+									$write_this = true;
290
+				}
264 291
 				// If the file exists, we may not want to overwrite it.
265
-				elseif (substr($i, -1) != '/')
266
-					$write_this = $overwrite;
267
-				else
268
-					$write_this = false;
292
+				elseif (substr($i, -1) != '/') {
293
+									$write_this = $overwrite;
294
+				} else {
295
+									$write_this = false;
296
+				}
269 297
 
270 298
 				// Get the actual compressed data.
271
-				if (!$file_info->isDir())
272
-					$file_data = file_get_contents($file_info);
273
-				elseif ($destination !== null && !$single_file)
299
+				if (!$file_info->isDir()) {
300
+									$file_data = file_get_contents($file_info);
301
+				} elseif ($destination !== null && !$single_file)
274 302
 				{
275 303
 					// Folder... create.
276
-					if (!file_exists($destination . '/' . $i))
277
-						mktree($destination . '/' . $i, 0777);
304
+					if (!file_exists($destination . '/' . $i)) {
305
+											mktree($destination . '/' . $i, 0777);
306
+					}
278 307
 					$file_data = null;
308
+				} else {
309
+									$file_data = null;
279 310
 				}
280
-				else
281
-					$file_data = null;
282 311
 
283 312
 				// Okay!  We can write this file, looks good from here...
284 313
 				if ($write_this && $destination !== null)
285 314
 				{
286
-					if (!$single_file && !is_dir($destination . '/' . dirname($i)))
287
-						mktree($destination . '/' . dirname($i), 0777);
315
+					if (!$single_file && !is_dir($destination . '/' . dirname($i))) {
316
+											mktree($destination . '/' . dirname($i), 0777);
317
+					}
288 318
 
289 319
 					// If we're looking for a specific file, and this is it... ka-bam, baby.
290
-					if ($single_file && ($destination == $i || $destination == '*/' . basename($i)))
291
-						return $file_data;
320
+					if ($single_file && ($destination == $i || $destination == '*/' . basename($i))) {
321
+											return $file_data;
322
+					}
292 323
 					// Oh?  Another file.  Fine.  You don't like this file, do you?  I know how it is.  Yeah... just go away.  No, don't apologize.  I know this file's just not *good enough* for you.
293
-					elseif ($single_file)
294
-						continue;
324
+					elseif ($single_file) {
325
+											continue;
326
+					}
295 327
 					// Don't really want this?
296
-					elseif ($files_to_extract !== null && !in_array($i, $files_to_extract))
297
-						continue;
328
+					elseif ($files_to_extract !== null && !in_array($i, $files_to_extract)) {
329
+											continue;
330
+					}
298 331
 
299 332
 					package_put_contents($destination . '/' . $i, $file_data);
300 333
 				}
301 334
 
302
-				if (substr($i, -1, 1) != '/')
303
-					$return[] = array(
335
+				if (substr($i, -1, 1) != '/') {
336
+									$return[] = array(
304 337
 						'filename' => $i,
305 338
 						'md5' => md5($file_data),
306 339
 						'preview' => substr($file_data, 0, 100),
307 340
 						'size' => strlen($file_data),
308 341
 						'skipped' => false
309 342
 					);
343
+				}
310 344
 			}
311 345
 
312
-		if ($destination !== null && !$single_file)
313
-			package_flush_cache();
346
+		if ($destination !== null && !$single_file) {
347
+					package_flush_cache();
348
+		}
314 349
 
315
-		if ($single_file)
316
-			return false;
317
-		else
318
-			return $return;
319
-	}
320
-	catch (Exception $e)
350
+		if ($single_file) {
351
+					return false;
352
+		} else {
353
+					return $return;
354
+		}
355
+	} catch (Exception $e)
321 356
 	{
322 357
 		log_error($e->getMessage(), 'general', $e->getFile(), $e->getLine());
323 358
 		return false;
@@ -340,13 +375,15 @@  discard block
 block discarded – undo
340 375
 function read_zip_data($data, $destination, $single_file = false, $overwrite = false, $files_to_extract = null)
341 376
 {
342 377
 	umask(0);
343
-	if ($destination !== null && !file_exists($destination) && !$single_file)
344
-		mktree($destination, 0777);
378
+	if ($destination !== null && !file_exists($destination) && !$single_file) {
379
+			mktree($destination, 0777);
380
+	}
345 381
 
346 382
 	// Look for the end of directory signature 0x06054b50
347 383
 	$data_ecr = explode("\x50\x4b\x05\x06", $data);
348
-	if (!isset($data_ecr[1]))
349
-		return false;
384
+	if (!isset($data_ecr[1])) {
385
+			return false;
386
+	}
350 387
 
351 388
 	$return = array();
352 389
 
@@ -361,8 +398,9 @@  discard block
 block discarded – undo
361 398
 	array_shift($file_sections);
362 399
 
363 400
 	// sections and count from the signature must match or the zip file is bad
364
-	if (count($file_sections) != $zip_info['files'])
365
-		return false;
401
+	if (count($file_sections) != $zip_info['files']) {
402
+			return false;
403
+	}
366 404
 
367 405
 	// go though each file in the archive
368 406
 	foreach ($file_sections as $data)
@@ -384,68 +422,79 @@  discard block
 block discarded – undo
384 422
 		}
385 423
 
386 424
 		// If this is a file, and it doesn't exist.... happy days!
387
-		if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename']))
388
-			$write_this = true;
425
+		if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename'])) {
426
+					$write_this = true;
427
+		}
389 428
 		// If the file exists, we may not want to overwrite it.
390
-		elseif (substr($file_info['filename'], -1) != '/')
391
-			$write_this = $overwrite;
429
+		elseif (substr($file_info['filename'], -1) != '/') {
430
+					$write_this = $overwrite;
431
+		}
392 432
 		// This is a directory, so we're gonna want to create it. (probably...)
393 433
 		elseif ($destination !== null && !$single_file)
394 434
 		{
395 435
 			// Just a little accident prevention, don't mind me.
396 436
 			$file_info['filename'] = strtr($file_info['filename'], array('../' => '', '/..' => ''));
397 437
 
398
-			if (!file_exists($destination . '/' . $file_info['filename']))
399
-				mktree($destination . '/' . $file_info['filename'], 0777);
438
+			if (!file_exists($destination . '/' . $file_info['filename'])) {
439
+							mktree($destination . '/' . $file_info['filename'], 0777);
440
+			}
400 441
 			$write_this = false;
442
+		} else {
443
+					$write_this = false;
401 444
 		}
402
-		else
403
-			$write_this = false;
404 445
 
405 446
 		// Get the actual compressed data.
406 447
 		$file_info['data'] = substr($data, 26 + $file_info['filename_length'] + $file_info['extrafield_length']);
407 448
 
408 449
 		// Only inflate it if we need to ;)
409
-		if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size']))
410
-			$file_info['data'] = gzinflate($file_info['data']);
450
+		if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size'])) {
451
+					$file_info['data'] = gzinflate($file_info['data']);
452
+		}
411 453
 
412 454
 		// Okay!  We can write this file, looks good from here...
413 455
 		if ($write_this && $destination !== null)
414 456
 		{
415
-			if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir'])))
416
-				mktree($file_info['dir'], 0777);
457
+			if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir']))) {
458
+							mktree($file_info['dir'], 0777);
459
+			}
417 460
 
418 461
 			// If we're looking for a specific file, and this is it... ka-bam, baby.
419
-			if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename'])))
420
-				return $file_info['data'];
462
+			if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename']))) {
463
+							return $file_info['data'];
464
+			}
421 465
 			// Oh?  Another file.  Fine.  You don't like this file, do you?  I know how it is.  Yeah... just go away.  No, don't apologize.  I know this file's just not *good enough* for you.
422
-			elseif ($single_file)
423
-				continue;
466
+			elseif ($single_file) {
467
+							continue;
468
+			}
424 469
 			// Don't really want this?
425
-			elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract))
426
-				continue;
470
+			elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract)) {
471
+							continue;
472
+			}
427 473
 
428 474
 			package_put_contents($destination . '/' . $file_info['filename'], $file_info['data']);
429 475
 		}
430 476
 
431
-		if (substr($file_info['filename'], -1, 1) != '/')
432
-			$return[] = array(
477
+		if (substr($file_info['filename'], -1, 1) != '/') {
478
+					$return[] = array(
433 479
 				'filename' => $file_info['filename'],
434 480
 				'md5' => md5($file_info['data']),
435 481
 				'preview' => substr($file_info['data'], 0, 100),
436 482
 				'size' => $file_info['size'],
437 483
 				'skipped' => false
438 484
 			);
485
+		}
439 486
 	}
440 487
 
441
-	if ($destination !== null && !$single_file)
442
-		package_flush_cache();
488
+	if ($destination !== null && !$single_file) {
489
+			package_flush_cache();
490
+	}
443 491
 
444
-	if ($single_file)
445
-		return false;
446
-	else
447
-		return $return;
448
-}
492
+	if ($single_file) {
493
+			return false;
494
+	} else {
495
+			return $return;
496
+	}
497
+	}
449 498
 
450 499
 /**
451 500
  * Checks the existence of a remote file since file_exists() does not do remote.
@@ -457,14 +506,16 @@  discard block
 block discarded – undo
457 506
 {
458 507
 	$a_url = parse_url($url);
459 508
 
460
-	if (!isset($a_url['scheme']))
461
-		return false;
509
+	if (!isset($a_url['scheme'])) {
510
+			return false;
511
+	}
462 512
 
463 513
 	// Attempt to connect...
464 514
 	$temp = '';
465 515
 	$fid = fsockopen($a_url['host'], !isset($a_url['port']) ? 80 : $a_url['port'], $temp, $temp, 8);
466
-	if (!$fid)
467
-		return false;
516
+	if (!$fid) {
517
+			return false;
518
+	}
468 519
 
469 520
 	fputs($fid, 'HEAD ' . $a_url['path'] . ' HTTP/1.0' . "\r\n" . 'Host: ' . $a_url['host'] . "\r\n\r\n");
470 521
 	$head = fread($fid, 1024);
@@ -499,8 +550,9 @@  discard block
 block discarded – undo
499 550
 	while ($row = $smcFunc['db_fetch_assoc']($request))
500 551
 	{
501 552
 		// Already found this? If so don't add it twice!
502
-		if (in_array($row['package_id'], $found))
503
-			continue;
553
+		if (in_array($row['package_id'], $found)) {
554
+					continue;
555
+		}
504 556
 
505 557
 		$found[] = $row['package_id'];
506 558
 
@@ -535,19 +587,21 @@  discard block
 block discarded – undo
535 587
 	global $sourcedir, $packagesdir;
536 588
 
537 589
 	// Extract package-info.xml from downloaded file. (*/ is used because it could be in any directory.)
538
-	if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false)
539
-		$packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true);
540
-	else
590
+	if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false) {
591
+			$packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true);
592
+	} else
541 593
 	{
542
-		if (!file_exists($packagesdir . '/' . $gzfilename))
543
-			return 'package_get_error_not_found';
594
+		if (!file_exists($packagesdir . '/' . $gzfilename)) {
595
+					return 'package_get_error_not_found';
596
+		}
544 597
 
545
-		if (is_file($packagesdir . '/' . $gzfilename))
546
-			$packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true);
547
-		elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml'))
548
-			$packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml');
549
-		else
550
-			return 'package_get_error_missing_xml';
598
+		if (is_file($packagesdir . '/' . $gzfilename)) {
599
+					$packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true);
600
+		} elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml')) {
601
+					$packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml');
602
+		} else {
603
+					return 'package_get_error_missing_xml';
604
+		}
551 605
 	}
552 606
 
553 607
 	// Nothing?
@@ -555,10 +609,11 @@  discard block
 block discarded – undo
555 609
 	{
556 610
 		// Perhaps they are trying to install a theme, lets tell them nicely this is the wrong function
557 611
 		$packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/theme_info.xml', true);
558
-		if (!empty($packageInfo))
559
-			return 'package_get_error_is_theme';
560
-		else
561
-			return 'package_get_error_is_zero';
612
+		if (!empty($packageInfo)) {
613
+					return 'package_get_error_is_theme';
614
+		} else {
615
+					return 'package_get_error_is_zero';
616
+		}
562 617
 	}
563 618
 
564 619
 	// Parse package-info.xml into an xmlArray.
@@ -566,8 +621,9 @@  discard block
 block discarded – undo
566 621
 	$packageInfo = new xmlArray($packageInfo);
567 622
 
568 623
 	// @todo Error message of some sort?
569
-	if (!$packageInfo->exists('package-info[0]'))
570
-		return 'package_get_error_packageinfo_corrupt';
624
+	if (!$packageInfo->exists('package-info[0]')) {
625
+			return 'package_get_error_packageinfo_corrupt';
626
+	}
571 627
 
572 628
 	$packageInfo = $packageInfo->path('package-info[0]');
573 629
 
@@ -586,8 +642,9 @@  discard block
 block discarded – undo
586 642
 		}
587 643
 	}
588 644
 
589
-	if (!isset($package['type']))
590
-		$package['type'] = 'modification';
645
+	if (!isset($package['type'])) {
646
+			$package['type'] = 'modification';
647
+	}
591 648
 
592 649
 	return $package;
593 650
 }
@@ -640,15 +697,14 @@  discard block
 block discarded – undo
640 697
 					{
641 698
 						$ftp_file = strtr($file, array($_SESSION['pack_ftp']['root'] => ''));
642 699
 						$package_ftp->chmod($ftp_file, $perms);
700
+					} else {
701
+											smf_chmod($file, $perms);
643 702
 					}
644
-					else
645
-						smf_chmod($file, $perms);
646 703
 
647 704
 					$new_permissions = @fileperms($file);
648 705
 					$result = $new_permissions == $perms ? 'success' : 'failure';
649 706
 					unset($_SESSION['pack_ftp']['original_perms'][$file]);
650
-				}
651
-				elseif ($do_change)
707
+				} elseif ($do_change)
652 708
 				{
653 709
 					$new_permissions = '';
654 710
 					$result = 'skipped';
@@ -764,8 +820,7 @@  discard block
 block discarded – undo
764 820
 
765 821
 			$context['sub_template'] = 'show_list';
766 822
 			$context['default_list'] = 'restore_file_permissions';
767
-		}
768
-		else
823
+		} else
769 824
 		{
770 825
 			unset($listOptions['columns']['result']);
771 826
 		}
@@ -775,12 +830,14 @@  discard block
 block discarded – undo
775 830
 		createList($listOptions);
776 831
 
777 832
 		// If we just restored permissions then whereever we are, we are now done and dusted.
778
-		if (!empty($_POST['restore_perms']))
779
-			obExit();
833
+		if (!empty($_POST['restore_perms'])) {
834
+					obExit();
835
+		}
780 836
 	}
781 837
 	// Otherwise, it's entirely irrelevant?
782
-	elseif ($restore_write_status)
783
-		return true;
838
+	elseif ($restore_write_status) {
839
+			return true;
840
+	}
784 841
 
785 842
 	// This is where we report what we got up to.
786 843
 	$return_data = array(
@@ -818,11 +875,12 @@  discard block
 block discarded – undo
818 875
 			if (!in_array($_POST['ftp_path'], array('', '/')))
819 876
 			{
820 877
 				$ftp_root = strtr($boarddir, array($_POST['ftp_path'] => ''));
821
-				if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/'))
822
-					$ftp_root = substr($ftp_root, 0, -1);
878
+				if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) {
879
+									$ftp_root = substr($ftp_root, 0, -1);
880
+				}
881
+			} else {
882
+							$ftp_root = $boarddir;
823 883
 			}
824
-			else
825
-				$ftp_root = $boarddir;
826 884
 
827 885
 			$_SESSION['pack_ftp'] = array(
828 886
 				'server' => $_POST['ftp_server'],
@@ -834,8 +892,9 @@  discard block
 block discarded – undo
834 892
 				'connected' => true,
835 893
 			);
836 894
 
837
-			if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path'])
838
-				updateSettings(array('package_path' => $_POST['ftp_path']));
895
+			if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) {
896
+							updateSettings(array('package_path' => $_POST['ftp_path']));
897
+			}
839 898
 
840 899
 			// This is now the primary connection.
841 900
 			$package_ftp = $ftp;
@@ -848,12 +907,13 @@  discard block
 block discarded – undo
848 907
 		foreach ($chmodFiles as $k => $file)
849 908
 		{
850 909
 			// Sometimes this can somehow happen maybe?
851
-			if (empty($file))
852
-				unset($chmodFiles[$k]);
910
+			if (empty($file)) {
911
+							unset($chmodFiles[$k]);
912
+			}
853 913
 			// Already writable?
854
-			elseif (@is_writable($file))
855
-				$return_data['files']['writable'][] = $file;
856
-			else
914
+			elseif (@is_writable($file)) {
915
+							$return_data['files']['writable'][] = $file;
916
+			} else
857 917
 			{
858 918
 				// Now try to change that.
859 919
 				$return_data['files'][package_chmod($file, 'writable', true) ? 'writable' : 'notwritable'][] = $file;
@@ -870,19 +930,21 @@  discard block
 block discarded – undo
870 930
 			{
871 931
 				require_once($sourcedir . '/Class-Package.php');
872 932
 				$ftp = new ftp_connection(null);
933
+			} elseif ($ftp->error !== false && !isset($ftp_error)) {
934
+							$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
873 935
 			}
874
-			elseif ($ftp->error !== false && !isset($ftp_error))
875
-				$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
876 936
 
877 937
 			list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir);
878 938
 
879
-			if ($found_path)
880
-				$_POST['ftp_path'] = $detect_path;
881
-			elseif (!isset($_POST['ftp_path']))
882
-				$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
939
+			if ($found_path) {
940
+							$_POST['ftp_path'] = $detect_path;
941
+			} elseif (!isset($_POST['ftp_path'])) {
942
+							$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
943
+			}
883 944
 
884
-			if (!isset($_POST['ftp_username']))
885
-				$_POST['ftp_username'] = $username;
945
+			if (!isset($_POST['ftp_username'])) {
946
+							$_POST['ftp_username'] = $username;
947
+			}
886 948
 		}
887 949
 
888 950
 		$context['package_ftp'] = array(
@@ -895,8 +957,9 @@  discard block
 block discarded – undo
895 957
 		);
896 958
 
897 959
 		// Which files failed?
898
-		if (!isset($context['notwritable_files']))
899
-			$context['notwritable_files'] = array();
960
+		if (!isset($context['notwritable_files'])) {
961
+					$context['notwritable_files'] = array();
962
+		}
900 963
 		$context['notwritable_files'] = array_merge($context['notwritable_files'], $return_data['files']['notwritable']);
901 964
 
902 965
 		// Sent here to die?
@@ -929,40 +992,48 @@  discard block
 block discarded – undo
929 992
 		foreach ($files as $k => $file)
930 993
 		{
931 994
 			// If this file doesn't exist, then we actually want to look at the directory, no?
932
-			if (!file_exists($file))
933
-				$file = dirname($file);
995
+			if (!file_exists($file)) {
996
+							$file = dirname($file);
997
+			}
934 998
 
935 999
 			// This looks odd, but it's an attempt to work around PHP suExec.
936
-			if (!@is_writable($file))
937
-				smf_chmod($file, 0755);
938
-			if (!@is_writable($file))
939
-				smf_chmod($file, 0777);
940
-			if (!@is_writable(dirname($file)))
941
-				smf_chmod($file, 0755);
942
-			if (!@is_writable(dirname($file)))
943
-				smf_chmod($file, 0777);
1000
+			if (!@is_writable($file)) {
1001
+							smf_chmod($file, 0755);
1002
+			}
1003
+			if (!@is_writable($file)) {
1004
+							smf_chmod($file, 0777);
1005
+			}
1006
+			if (!@is_writable(dirname($file))) {
1007
+							smf_chmod($file, 0755);
1008
+			}
1009
+			if (!@is_writable(dirname($file))) {
1010
+							smf_chmod($file, 0777);
1011
+			}
944 1012
 
945 1013
 			$fp = is_dir($file) ? @opendir($file) : @fopen($file, 'rb');
946 1014
 			if (@is_writable($file) && $fp)
947 1015
 			{
948 1016
 				unset($files[$k]);
949
-				if (!is_dir($file))
950
-					fclose($fp);
951
-				else
952
-					closedir($fp);
1017
+				if (!is_dir($file)) {
1018
+									fclose($fp);
1019
+				} else {
1020
+									closedir($fp);
1021
+				}
953 1022
 			}
954 1023
 		}
955 1024
 
956 1025
 		// No FTP required!
957
-		if (empty($files))
958
-			return array();
1026
+		if (empty($files)) {
1027
+					return array();
1028
+		}
959 1029
 	}
960 1030
 
961 1031
 	// They've opted to not use FTP, and try anyway.
962 1032
 	if (isset($_SESSION['pack_ftp']) && $_SESSION['pack_ftp'] == false)
963 1033
 	{
964
-		if ($files === null)
965
-			return array();
1034
+		if ($files === null) {
1035
+					return array();
1036
+		}
966 1037
 
967 1038
 		foreach ($files as $k => $file)
968 1039
 		{
@@ -974,26 +1045,29 @@  discard block
 block discarded – undo
974 1045
 				smf_chmod($file, 0755);
975 1046
 			}
976 1047
 
977
-			if (!@is_writable($file))
978
-				smf_chmod($file, 0777);
979
-			if (!@is_writable(dirname($file)))
980
-				smf_chmod(dirname($file), 0777);
1048
+			if (!@is_writable($file)) {
1049
+							smf_chmod($file, 0777);
1050
+			}
1051
+			if (!@is_writable(dirname($file))) {
1052
+							smf_chmod(dirname($file), 0777);
1053
+			}
981 1054
 
982
-			if (@is_writable($file))
983
-				unset($files[$k]);
1055
+			if (@is_writable($file)) {
1056
+							unset($files[$k]);
1057
+			}
984 1058
 		}
985 1059
 
986 1060
 		return $files;
987
-	}
988
-	elseif (isset($_SESSION['pack_ftp']))
1061
+	} elseif (isset($_SESSION['pack_ftp']))
989 1062
 	{
990 1063
 		// Load the file containing the ftp_connection class.
991 1064
 		require_once($sourcedir . '/Class-Package.php');
992 1065
 
993 1066
 		$package_ftp = new ftp_connection($_SESSION['pack_ftp']['server'], $_SESSION['pack_ftp']['port'], $_SESSION['pack_ftp']['username'], package_crypt($_SESSION['pack_ftp']['password']));
994 1067
 
995
-		if ($files === null)
996
-			return array();
1068
+		if ($files === null) {
1069
+					return array();
1070
+		}
997 1071
 
998 1072
 		foreach ($files as $k => $file)
999 1073
 		{
@@ -1007,13 +1081,16 @@  discard block
 block discarded – undo
1007 1081
 				$package_ftp->chmod($ftp_file, 0755);
1008 1082
 			}
1009 1083
 
1010
-			if (!@is_writable($file))
1011
-				$package_ftp->chmod($ftp_file, 0777);
1012
-			if (!@is_writable(dirname($file)))
1013
-				$package_ftp->chmod(dirname($ftp_file), 0777);
1084
+			if (!@is_writable($file)) {
1085
+							$package_ftp->chmod($ftp_file, 0777);
1086
+			}
1087
+			if (!@is_writable(dirname($file))) {
1088
+							$package_ftp->chmod(dirname($ftp_file), 0777);
1089
+			}
1014 1090
 
1015
-			if (@is_writable($file))
1016
-				unset($files[$k]);
1091
+			if (@is_writable($file)) {
1092
+							unset($files[$k]);
1093
+			}
1017 1094
 		}
1018 1095
 
1019 1096
 		return $files;
@@ -1025,8 +1102,7 @@  discard block
 block discarded – undo
1025 1102
 
1026 1103
 		$files = packageRequireFTP($destination_url, $files, $return);
1027 1104
 		return $files;
1028
-	}
1029
-	elseif (isset($_POST['ftp_username']))
1105
+	} elseif (isset($_POST['ftp_username']))
1030 1106
 	{
1031 1107
 		require_once($sourcedir . '/Class-Package.php');
1032 1108
 		$ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']);
@@ -1048,19 +1124,21 @@  discard block
 block discarded – undo
1048 1124
 		{
1049 1125
 			require_once($sourcedir . '/Class-Package.php');
1050 1126
 			$ftp = new ftp_connection(null);
1127
+		} elseif ($ftp->error !== false && !isset($ftp_error)) {
1128
+					$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
1051 1129
 		}
1052
-		elseif ($ftp->error !== false && !isset($ftp_error))
1053
-			$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
1054 1130
 
1055 1131
 		list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir);
1056 1132
 
1057
-		if ($found_path)
1058
-			$_POST['ftp_path'] = $detect_path;
1059
-		elseif (!isset($_POST['ftp_path']))
1060
-			$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
1133
+		if ($found_path) {
1134
+					$_POST['ftp_path'] = $detect_path;
1135
+		} elseif (!isset($_POST['ftp_path'])) {
1136
+					$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
1137
+		}
1061 1138
 
1062
-		if (!isset($_POST['ftp_username']))
1063
-			$_POST['ftp_username'] = $username;
1139
+		if (!isset($_POST['ftp_username'])) {
1140
+					$_POST['ftp_username'] = $username;
1141
+		}
1064 1142
 
1065 1143
 		$context['package_ftp'] = array(
1066 1144
 			'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'),
@@ -1072,23 +1150,24 @@  discard block
 block discarded – undo
1072 1150
 		);
1073 1151
 
1074 1152
 		// If we're returning dump out here.
1075
-		if ($return)
1076
-			return $files;
1153
+		if ($return) {
1154
+					return $files;
1155
+		}
1077 1156
 
1078 1157
 		$context['page_title'] = $txt['package_ftp_necessary'];
1079 1158
 		$context['sub_template'] = 'ftp_required';
1080 1159
 		obExit();
1081
-	}
1082
-	else
1160
+	} else
1083 1161
 	{
1084 1162
 		if (!in_array($_POST['ftp_path'], array('', '/')))
1085 1163
 		{
1086 1164
 			$ftp_root = strtr($boarddir, array($_POST['ftp_path'] => ''));
1087
-			if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/'))
1088
-				$ftp_root = substr($ftp_root, 0, -1);
1165
+			if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) {
1166
+							$ftp_root = substr($ftp_root, 0, -1);
1167
+			}
1168
+		} else {
1169
+					$ftp_root = $boarddir;
1089 1170
 		}
1090
-		else
1091
-			$ftp_root = $boarddir;
1092 1171
 
1093 1172
 		$_SESSION['pack_ftp'] = array(
1094 1173
 			'server' => $_POST['ftp_server'],
@@ -1099,8 +1178,9 @@  discard block
 block discarded – undo
1099 1178
 			'root' => $ftp_root,
1100 1179
 		);
1101 1180
 
1102
-		if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path'])
1103
-			updateSettings(array('package_path' => $_POST['ftp_path']));
1181
+		if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) {
1182
+					updateSettings(array('package_path' => $_POST['ftp_path']));
1183
+		}
1104 1184
 
1105 1185
 		$files = packageRequireFTP($destination_url, $files, $return);
1106 1186
 	}
@@ -1128,16 +1208,18 @@  discard block
 block discarded – undo
1128 1208
 	global $packagesdir, $forum_version, $context, $temp_path, $language, $smcFunc;
1129 1209
 
1130 1210
 	// Mayday!  That action doesn't exist!!
1131
-	if (empty($packageXML) || !$packageXML->exists($method))
1132
-		return array();
1211
+	if (empty($packageXML) || !$packageXML->exists($method)) {
1212
+			return array();
1213
+	}
1133 1214
 
1134 1215
 	// We haven't found the package script yet...
1135 1216
 	$script = false;
1136 1217
 	$the_version = strtr($forum_version, array('SMF ' => ''));
1137 1218
 
1138 1219
 	// Emulation support...
1139
-	if (!empty($_SESSION['version_emulate']))
1140
-		$the_version = $_SESSION['version_emulate'];
1220
+	if (!empty($_SESSION['version_emulate'])) {
1221
+			$the_version = $_SESSION['version_emulate'];
1222
+	}
1141 1223
 
1142 1224
 	// Single package emulation
1143 1225
 	if (!empty($_REQUEST['ve']) && !empty($_REQUEST['package']))
@@ -1145,8 +1227,9 @@  discard block
 block discarded – undo
1145 1227
 		$the_version = $_REQUEST['ve'];
1146 1228
 		$_SESSION['single_version_emulate'][$_REQUEST['package']] = $the_version;
1147 1229
 	}
1148
-	if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']])))
1149
-		$the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']];
1230
+	if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']]))) {
1231
+			$the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']];
1232
+	}
1150 1233
 
1151 1234
 	// Get all the versions of this method and find the right one.
1152 1235
 	$these_methods = $packageXML->set($method);
@@ -1156,16 +1239,18 @@  discard block
 block discarded – undo
1156 1239
 		if ($this_method->exists('@for'))
1157 1240
 		{
1158 1241
 			// Don't keep going if this won't work for this version of SMF.
1159
-			if (!matchPackageVersion($the_version, $this_method->fetch('@for')))
1160
-				continue;
1242
+			if (!matchPackageVersion($the_version, $this_method->fetch('@for'))) {
1243
+							continue;
1244
+			}
1161 1245
 		}
1162 1246
 
1163 1247
 		// Upgrades may go from a certain old version of the mod.
1164 1248
 		if ($method == 'upgrade' && $this_method->exists('@from'))
1165 1249
 		{
1166 1250
 			// Well, this is for the wrong old version...
1167
-			if (!matchPackageVersion($previous_version, $this_method->fetch('@from')))
1168
-				continue;
1251
+			if (!matchPackageVersion($previous_version, $this_method->fetch('@from'))) {
1252
+							continue;
1253
+			}
1169 1254
 		}
1170 1255
 
1171 1256
 		// We've found it!
@@ -1174,8 +1259,9 @@  discard block
 block discarded – undo
1174 1259
 	}
1175 1260
 
1176 1261
 	// Bad news, a matching script wasn't found!
1177
-	if (!($script instanceof xmlArray))
1178
-		return array();
1262
+	if (!($script instanceof xmlArray)) {
1263
+			return array();
1264
+	}
1179 1265
 
1180 1266
 	// Find all the actions in this method - in theory, these should only be allowed actions. (* means all.)
1181 1267
 	$actions = $script->set('*');
@@ -1204,12 +1290,12 @@  discard block
 block discarded – undo
1204 1290
 					if ((isset($_REQUEST['readme']) && $action->fetch('@lang') == $_REQUEST['readme']) || (isset($_REQUEST['license']) && $action->fetch('@lang') == $_REQUEST['license']) || (!isset($_REQUEST['readme']) && $action->fetch('@lang') == $language) || (!isset($_REQUEST['license']) && $action->fetch('@lang') == $language))
1205 1291
 					{
1206 1292
 						// In case the user put the blocks in the wrong order.
1207
-						if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default')
1208
-							$context[$type][] = 'default';
1293
+						if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') {
1294
+													$context[$type][] = 'default';
1295
+						}
1209 1296
 
1210 1297
 						$context[$type]['selected'] = $smcFunc['htmlspecialchars']($action->fetch('@lang'));
1211
-					}
1212
-					else
1298
+					} else
1213 1299
 					{
1214 1300
 						// We don't want this now, but we'll allow the user to select to read it.
1215 1301
 						$context[$type][] = $smcFunc['htmlspecialchars']($action->fetch('@lang'));
@@ -1224,9 +1310,9 @@  discard block
 block discarded – undo
1224 1310
 					{
1225 1311
 						$context[$type][] = 'default';
1226 1312
 						continue;
1313
+					} else {
1314
+											$context[$type]['selected'] = 'default';
1227 1315
 					}
1228
-					else
1229
-						$context[$type]['selected'] = 'default';
1230 1316
 				}
1231 1317
 			}
1232 1318
 
@@ -1236,9 +1322,9 @@  discard block
 block discarded – undo
1236 1322
 				$filename = $temp_path . '$auto_' . $temp_auto++ . (in_array($actionType, array('readme', 'redirect', 'license')) ? '.txt' : ($actionType == 'code' || $actionType == 'database' ? '.php' : '.mod'));
1237 1323
 				package_put_contents($filename, $action->fetch('.'));
1238 1324
 				$filename = strtr($filename, array($temp_path => ''));
1325
+			} else {
1326
+							$filename = $action->fetch('.');
1239 1327
 			}
1240
-			else
1241
-				$filename = $action->fetch('.');
1242 1328
 
1243 1329
 			$return[] = array(
1244 1330
 				'type' => $actionType,
@@ -1253,8 +1339,7 @@  discard block
 block discarded – undo
1253 1339
 			);
1254 1340
 
1255 1341
 			continue;
1256
-		}
1257
-		elseif ($actionType == 'hook')
1342
+		} elseif ($actionType == 'hook')
1258 1343
 		{
1259 1344
 			$return[] = array(
1260 1345
 				'type' => $actionType,
@@ -1266,16 +1351,16 @@  discard block
 block discarded – undo
1266 1351
 				'description' => '',
1267 1352
 			);
1268 1353
 			continue;
1269
-		}
1270
-		elseif ($actionType == 'credits')
1354
+		} elseif ($actionType == 'credits')
1271 1355
 		{
1272 1356
 			// quick check of any supplied url
1273 1357
 			$url = $action->exists('@url') ? $action->fetch('@url') : '';
1274 1358
 			if (strlen(trim($url)) > 0 && substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')
1275 1359
 			{
1276 1360
 				$url = 'http://' . $url;
1277
-				if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://'))
1278
-					$url = '';
1361
+				if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')) {
1362
+									$url = '';
1363
+				}
1279 1364
 			}
1280 1365
 
1281 1366
 			$return[] = array(
@@ -1287,8 +1372,7 @@  discard block
 block discarded – undo
1287 1372
 				'title' => $action->fetch('.'),
1288 1373
 			);
1289 1374
 			continue;
1290
-		}
1291
-		elseif ($actionType == 'requires')
1375
+		} elseif ($actionType == 'requires')
1292 1376
 		{
1293 1377
 			$return[] = array(
1294 1378
 				'type' => $actionType,
@@ -1297,14 +1381,12 @@  discard block
 block discarded – undo
1297 1381
 				'description' => '',
1298 1382
 			);
1299 1383
 			continue;
1300
-		}
1301
-		elseif ($actionType == 'error')
1384
+		} elseif ($actionType == 'error')
1302 1385
 		{
1303 1386
 			$return[] = array(
1304 1387
 				'type' => 'error',
1305 1388
 			);
1306
-		}
1307
-		elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir')))
1389
+		} elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir')))
1308 1390
 		{
1309 1391
 			$this_action = &$return[];
1310 1392
 			$this_action = array(
@@ -1318,8 +1400,7 @@  discard block
 block discarded – undo
1318 1400
 			{
1319 1401
 				$this_action['unparsed_destination'] = $action->fetch('@destination');
1320 1402
 				$this_action['destination'] = parse_path($action->fetch('@destination')) . '/' . basename($this_action['filename']);
1321
-			}
1322
-			else
1403
+			} else
1323 1404
 			{
1324 1405
 				$this_action['unparsed_filename'] = $this_action['filename'];
1325 1406
 				$this_action['filename'] = parse_path($this_action['filename']);
@@ -1328,10 +1409,11 @@  discard block
 block discarded – undo
1328 1409
 			// If we're moving or requiring (copying) a file.
1329 1410
 			if (substr($actionType, 0, 4) == 'move' || substr($actionType, 0, 7) == 'require')
1330 1411
 			{
1331
-				if ($action->exists('@from'))
1332
-					$this_action['source'] = parse_path($action->fetch('@from'));
1333
-				else
1334
-					$this_action['source'] = $temp_path . $this_action['filename'];
1412
+				if ($action->exists('@from')) {
1413
+									$this_action['source'] = parse_path($action->fetch('@from'));
1414
+				} else {
1415
+									$this_action['source'] = $temp_path . $this_action['filename'];
1416
+				}
1335 1417
 			}
1336 1418
 
1337 1419
 			// Check if these things can be done. (chmod's etc.)
@@ -1340,22 +1422,23 @@  discard block
 block discarded – undo
1340 1422
 				if (!mktree($this_action['destination'], false))
1341 1423
 				{
1342 1424
 					$temp = $this_action['destination'];
1343
-					while (!file_exists($temp) && strlen($temp) > 1)
1344
-						$temp = dirname($temp);
1425
+					while (!file_exists($temp) && strlen($temp) > 1) {
1426
+											$temp = dirname($temp);
1427
+					}
1345 1428
 
1346 1429
 					$return[] = array(
1347 1430
 						'type' => 'chmod',
1348 1431
 						'filename' => $temp
1349 1432
 					);
1350 1433
 				}
1351
-			}
1352
-			elseif ($actionType == 'create-file')
1434
+			} elseif ($actionType == 'create-file')
1353 1435
 			{
1354 1436
 				if (!mktree(dirname($this_action['destination']), false))
1355 1437
 				{
1356 1438
 					$temp = dirname($this_action['destination']);
1357
-					while (!file_exists($temp) && strlen($temp) > 1)
1358
-						$temp = dirname($temp);
1439
+					while (!file_exists($temp) && strlen($temp) > 1) {
1440
+											$temp = dirname($temp);
1441
+					}
1359 1442
 
1360 1443
 					$return[] = array(
1361 1444
 						'type' => 'chmod',
@@ -1363,36 +1446,38 @@  discard block
 block discarded – undo
1363 1446
 					);
1364 1447
 				}
1365 1448
 
1366
-				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination']))))
1367
-					$return[] = array(
1449
+				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) {
1450
+									$return[] = array(
1368 1451
 						'type' => 'chmod',
1369 1452
 						'filename' => $this_action['destination']
1370 1453
 					);
1371
-			}
1372
-			elseif ($actionType == 'require-dir')
1454
+				}
1455
+			} elseif ($actionType == 'require-dir')
1373 1456
 			{
1374 1457
 				if (!mktree($this_action['destination'], false))
1375 1458
 				{
1376 1459
 					$temp = $this_action['destination'];
1377
-					while (!file_exists($temp) && strlen($temp) > 1)
1378
-						$temp = dirname($temp);
1460
+					while (!file_exists($temp) && strlen($temp) > 1) {
1461
+											$temp = dirname($temp);
1462
+					}
1379 1463
 
1380 1464
 					$return[] = array(
1381 1465
 						'type' => 'chmod',
1382 1466
 						'filename' => $temp
1383 1467
 					);
1384 1468
 				}
1385
-			}
1386
-			elseif ($actionType == 'require-file')
1469
+			} elseif ($actionType == 'require-file')
1387 1470
 			{
1388
-				if ($action->exists('@theme'))
1389
-					$this_action['theme_action'] = $action->fetch('@theme');
1471
+				if ($action->exists('@theme')) {
1472
+									$this_action['theme_action'] = $action->fetch('@theme');
1473
+				}
1390 1474
 
1391 1475
 				if (!mktree(dirname($this_action['destination']), false))
1392 1476
 				{
1393 1477
 					$temp = dirname($this_action['destination']);
1394
-					while (!file_exists($temp) && strlen($temp) > 1)
1395
-						$temp = dirname($temp);
1478
+					while (!file_exists($temp) && strlen($temp) > 1) {
1479
+											$temp = dirname($temp);
1480
+					}
1396 1481
 
1397 1482
 					$return[] = array(
1398 1483
 						'type' => 'chmod',
@@ -1400,19 +1485,20 @@  discard block
 block discarded – undo
1400 1485
 					);
1401 1486
 				}
1402 1487
 
1403
-				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination']))))
1404
-					$return[] = array(
1488
+				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) {
1489
+									$return[] = array(
1405 1490
 						'type' => 'chmod',
1406 1491
 						'filename' => $this_action['destination']
1407 1492
 					);
1408
-			}
1409
-			elseif ($actionType == 'move-dir' || $actionType == 'move-file')
1493
+				}
1494
+			} elseif ($actionType == 'move-dir' || $actionType == 'move-file')
1410 1495
 			{
1411 1496
 				if (!mktree(dirname($this_action['destination']), false))
1412 1497
 				{
1413 1498
 					$temp = dirname($this_action['destination']);
1414
-					while (!file_exists($temp) && strlen($temp) > 1)
1415
-						$temp = dirname($temp);
1499
+					while (!file_exists($temp) && strlen($temp) > 1) {
1500
+											$temp = dirname($temp);
1501
+					}
1416 1502
 
1417 1503
 					$return[] = array(
1418 1504
 						'type' => 'chmod',
@@ -1420,30 +1506,30 @@  discard block
 block discarded – undo
1420 1506
 					);
1421 1507
 				}
1422 1508
 
1423
-				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination']))))
1424
-					$return[] = array(
1509
+				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) {
1510
+									$return[] = array(
1425 1511
 						'type' => 'chmod',
1426 1512
 						'filename' => $this_action['destination']
1427 1513
 					);
1428
-			}
1429
-			elseif ($actionType == 'remove-dir')
1514
+				}
1515
+			} elseif ($actionType == 'remove-dir')
1430 1516
 			{
1431
-				if (!is_writable($this_action['filename']) && file_exists($this_action['filename']))
1432
-					$return[] = array(
1517
+				if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) {
1518
+									$return[] = array(
1433 1519
 						'type' => 'chmod',
1434 1520
 						'filename' => $this_action['filename']
1435 1521
 					);
1436
-			}
1437
-			elseif ($actionType == 'remove-file')
1522
+				}
1523
+			} elseif ($actionType == 'remove-file')
1438 1524
 			{
1439
-				if (!is_writable($this_action['filename']) && file_exists($this_action['filename']))
1440
-					$return[] = array(
1525
+				if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) {
1526
+									$return[] = array(
1441 1527
 						'type' => 'chmod',
1442 1528
 						'filename' => $this_action['filename']
1443 1529
 					);
1530
+				}
1444 1531
 			}
1445
-		}
1446
-		else
1532
+		} else
1447 1533
 		{
1448 1534
 			$return[] = array(
1449 1535
 				'type' => 'error',
@@ -1454,8 +1540,9 @@  discard block
 block discarded – undo
1454 1540
 	}
1455 1541
 
1456 1542
 	// Only testing - just return a list of things to be done.
1457
-	if ($testing_only)
1458
-		return $return;
1543
+	if ($testing_only) {
1544
+			return $return;
1545
+	}
1459 1546
 
1460 1547
 	umask(0);
1461 1548
 
@@ -1463,78 +1550,81 @@  discard block
 block discarded – undo
1463 1550
 	$not_done = array(array('type' => '!'));
1464 1551
 	foreach ($return as $action)
1465 1552
 	{
1466
-		if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits')))
1467
-			$not_done[] = $action;
1553
+		if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits'))) {
1554
+					$not_done[] = $action;
1555
+		}
1468 1556
 
1469 1557
 		if ($action['type'] == 'create-dir')
1470 1558
 		{
1471
-			if (!mktree($action['destination'], 0755) || !is_writable($action['destination']))
1472
-				$failure |= !mktree($action['destination'], 0777);
1473
-		}
1474
-		elseif ($action['type'] == 'create-file')
1559
+			if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) {
1560
+							$failure |= !mktree($action['destination'], 0777);
1561
+			}
1562
+		} elseif ($action['type'] == 'create-file')
1475 1563
 		{
1476
-			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination'])))
1477
-				$failure |= !mktree(dirname($action['destination']), 0777);
1564
+			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) {
1565
+							$failure |= !mktree(dirname($action['destination']), 0777);
1566
+			}
1478 1567
 
1479 1568
 			// Create an empty file.
1480 1569
 			package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only);
1481 1570
 
1482
-			if (!file_exists($action['destination']))
1483
-				$failure = true;
1484
-		}
1485
-		elseif ($action['type'] == 'require-dir')
1571
+			if (!file_exists($action['destination'])) {
1572
+							$failure = true;
1573
+			}
1574
+		} elseif ($action['type'] == 'require-dir')
1486 1575
 		{
1487 1576
 			copytree($action['source'], $action['destination']);
1488 1577
 			// Any other theme folders?
1489
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']]))
1490
-				foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1578
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) {
1579
+							foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1491 1580
 					copytree($action['source'], $theme_destination);
1492
-		}
1493
-		elseif ($action['type'] == 'require-file')
1581
+			}
1582
+		} elseif ($action['type'] == 'require-file')
1494 1583
 		{
1495
-			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination'])))
1496
-				$failure |= !mktree(dirname($action['destination']), 0777);
1584
+			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) {
1585
+							$failure |= !mktree(dirname($action['destination']), 0777);
1586
+			}
1497 1587
 
1498 1588
 			package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only);
1499 1589
 
1500 1590
 			$failure |= !copy($action['source'], $action['destination']);
1501 1591
 
1502 1592
 			// Any other theme files?
1503
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']]))
1504
-				foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1593
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) {
1594
+							foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1505 1595
 				{
1506 1596
 					if (!mktree(dirname($theme_destination), 0755) || !is_writable(dirname($theme_destination)))
1507 1597
 						$failure |= !mktree(dirname($theme_destination), 0777);
1598
+			}
1508 1599
 
1509 1600
 					package_put_contents($theme_destination, package_get_contents($action['source']), $testing_only);
1510 1601
 
1511 1602
 					$failure |= !copy($action['source'], $theme_destination);
1512 1603
 				}
1513
-		}
1514
-		elseif ($action['type'] == 'move-file')
1604
+		} elseif ($action['type'] == 'move-file')
1515 1605
 		{
1516
-			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination'])))
1517
-				$failure |= !mktree(dirname($action['destination']), 0777);
1606
+			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) {
1607
+							$failure |= !mktree(dirname($action['destination']), 0777);
1608
+			}
1518 1609
 
1519 1610
 			$failure |= !rename($action['source'], $action['destination']);
1520
-		}
1521
-		elseif ($action['type'] == 'move-dir')
1611
+		} elseif ($action['type'] == 'move-dir')
1522 1612
 		{
1523
-			if (!mktree($action['destination'], 0755) || !is_writable($action['destination']))
1524
-				$failure |= !mktree($action['destination'], 0777);
1613
+			if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) {
1614
+							$failure |= !mktree($action['destination'], 0777);
1615
+			}
1525 1616
 
1526 1617
 			$failure |= !rename($action['source'], $action['destination']);
1527
-		}
1528
-		elseif ($action['type'] == 'remove-dir')
1618
+		} elseif ($action['type'] == 'remove-dir')
1529 1619
 		{
1530 1620
 			deltree($action['filename']);
1531 1621
 
1532 1622
 			// Any other theme folders?
1533
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']]))
1534
-				foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1623
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) {
1624
+							foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1535 1625
 					deltree($theme_destination);
1536
-		}
1537
-		elseif ($action['type'] == 'remove-file')
1626
+			}
1627
+		} elseif ($action['type'] == 'remove-file')
1538 1628
 		{
1539 1629
 			// Make sure the file exists before deleting it.
1540 1630
 			if (file_exists($action['filename']))
@@ -1543,16 +1633,18 @@  discard block
 block discarded – undo
1543 1633
 				$failure |= !unlink($action['filename']);
1544 1634
 			}
1545 1635
 			// The file that was supposed to be deleted couldn't be found.
1546
-			else
1547
-				$failure = true;
1636
+			else {
1637
+							$failure = true;
1638
+			}
1548 1639
 
1549 1640
 			// Any other theme folders?
1550
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']]))
1551
-				foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1641
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) {
1642
+							foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1552 1643
 					if (file_exists($theme_destination))
1553 1644
 						$failure |= !unlink($theme_destination);
1554
-					else
1555
-						$failure = true;
1645
+			} else {
1646
+											$failure = true;
1647
+					}
1556 1648
 		}
1557 1649
 	}
1558 1650
 
@@ -1574,8 +1666,9 @@  discard block
 block discarded – undo
1574 1666
 {
1575 1667
 	static $near_version = 0;
1576 1668
 
1577
-	if ($reset)
1578
-		$near_version = 0;
1669
+	if ($reset) {
1670
+			$near_version = 0;
1671
+	}
1579 1672
 
1580 1673
 	// Normalize the $versions while we remove our previous Doh!
1581 1674
 	$versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions)));
@@ -1584,16 +1677,19 @@  discard block
 block discarded – undo
1584 1677
 	foreach ($versions as $for)
1585 1678
 	{
1586 1679
 		// Adjust for those wild cards
1587
-		if (strpos($for, '*') !== false)
1588
-			$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1680
+		if (strpos($for, '*') !== false) {
1681
+					$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1682
+		}
1589 1683
 
1590 1684
 		// If we have a range, grab the lower value, done this way so it looks normal-er to the user e.g. 2.0 vs 2.0.99
1591
-		if (strpos($for, '-') !== false)
1592
-			list ($for, $higher) = explode('-', $for);
1685
+		if (strpos($for, '-') !== false) {
1686
+					list ($for, $higher) = explode('-', $for);
1687
+		}
1593 1688
 
1594 1689
 		// Do the compare, if the for is greater, than what we have but not greater than what we are running .....
1595
-		if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1)
1596
-			$near_version = $for;
1690
+		if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1) {
1691
+					$near_version = $for;
1692
+		}
1597 1693
 	}
1598 1694
 
1599 1695
 	return !empty($near_version) ? $near_version : false;
@@ -1616,15 +1712,17 @@  discard block
 block discarded – undo
1616 1712
 	$versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions)));
1617 1713
 
1618 1714
 	// Perhaps we do accept anything?
1619
-	if (in_array('all', $versions))
1620
-		return true;
1715
+	if (in_array('all', $versions)) {
1716
+			return true;
1717
+	}
1621 1718
 
1622 1719
 	// Loop through each version.
1623 1720
 	foreach ($versions as $for)
1624 1721
 	{
1625 1722
 		// Wild card spotted?
1626
-		if (strpos($for, '*') !== false)
1627
-			$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1723
+		if (strpos($for, '*') !== false) {
1724
+					$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1725
+		}
1628 1726
 
1629 1727
 		// Do we have a range?
1630 1728
 		if (strpos($for, '-') !== false)
@@ -1632,12 +1730,14 @@  discard block
 block discarded – undo
1632 1730
 			list ($lower, $upper) = explode('-', $for);
1633 1731
 
1634 1732
 			// Compare the version against lower and upper bounds.
1635
-			if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1)
1636
-				return true;
1733
+			if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1) {
1734
+							return true;
1735
+			}
1637 1736
 		}
1638 1737
 		// Otherwise check if they are equal...
1639
-		elseif (compareVersions($version, $for) === 0)
1640
-			return true;
1738
+		elseif (compareVersions($version, $for) === 0) {
1739
+					return true;
1740
+		}
1641 1741
 	}
1642 1742
 
1643 1743
 	return false;
@@ -1677,12 +1777,14 @@  discard block
 block discarded – undo
1677 1777
 	}
1678 1778
 
1679 1779
 	// Are they the same, perhaps?
1680
-	if ($versions[1] === $versions[2])
1681
-		return 0;
1780
+	if ($versions[1] === $versions[2]) {
1781
+			return 0;
1782
+	}
1682 1783
 
1683 1784
 	// Get version numbering categories...
1684
-	if (!isset($categories))
1685
-		$categories = array_keys($versions[1]);
1785
+	if (!isset($categories)) {
1786
+			$categories = array_keys($versions[1]);
1787
+	}
1686 1788
 
1687 1789
 	// Loop through each category.
1688 1790
 	foreach ($categories as $category)
@@ -1692,13 +1794,15 @@  discard block
 block discarded – undo
1692 1794
 		{
1693 1795
 			// Dev builds are a problematic exception.
1694 1796
 			// (stable) dev < (stable) but (unstable) dev = (unstable)
1695
-			if ($category == 'type')
1696
-				return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1);
1697
-			elseif ($category == 'dev')
1698
-				return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0);
1797
+			if ($category == 'type') {
1798
+							return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1);
1799
+			} elseif ($category == 'dev') {
1800
+							return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0);
1801
+			}
1699 1802
 			// Otherwise a simple comparison.
1700
-			else
1701
-				return $versions[1][$category] > $versions[2][$category] ? 1 : -1;
1803
+			else {
1804
+							return $versions[1][$category] > $versions[2][$category] ? 1 : -1;
1805
+			}
1702 1806
 		}
1703 1807
 	}
1704 1808
 
@@ -1732,11 +1836,13 @@  discard block
 block discarded – undo
1732 1836
 	);
1733 1837
 
1734 1838
 	// do we parse in a package directory?
1735
-	if (!empty($temp_path))
1736
-		$dirs['$package'] = $temp_path;
1839
+	if (!empty($temp_path)) {
1840
+			$dirs['$package'] = $temp_path;
1841
+	}
1737 1842
 
1738
-	if (strlen($path) == 0)
1739
-		trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR);
1843
+	if (strlen($path) == 0) {
1844
+			trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR);
1845
+	}
1740 1846
 
1741 1847
 	return strtr($path, $dirs);
1742 1848
 }
@@ -1753,8 +1859,9 @@  discard block
 block discarded – undo
1753 1859
 	/** @var ftp_connection $package_ftp */
1754 1860
 	global $package_ftp;
1755 1861
 
1756
-	if (!file_exists($dir))
1757
-		return;
1862
+	if (!file_exists($dir)) {
1863
+			return;
1864
+	}
1758 1865
 
1759 1866
 	$current_dir = @opendir($dir);
1760 1867
 	if ($current_dir == false)
@@ -1762,8 +1869,9 @@  discard block
 block discarded – undo
1762 1869
 		if ($delete_dir && isset($package_ftp))
1763 1870
 		{
1764 1871
 			$ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => ''));
1765
-			if (!is_dir($dir))
1766
-				$package_ftp->chmod($ftp_file, 0777);
1872
+			if (!is_dir($dir)) {
1873
+							$package_ftp->chmod($ftp_file, 0777);
1874
+			}
1767 1875
 			$package_ftp->unlink($ftp_file);
1768 1876
 		}
1769 1877
 
@@ -1772,26 +1880,28 @@  discard block
 block discarded – undo
1772 1880
 
1773 1881
 	while ($entryname = readdir($current_dir))
1774 1882
 	{
1775
-		if (in_array($entryname, array('.', '..')))
1776
-			continue;
1883
+		if (in_array($entryname, array('.', '..'))) {
1884
+					continue;
1885
+		}
1777 1886
 
1778
-		if (is_dir($dir . '/' . $entryname))
1779
-			deltree($dir . '/' . $entryname);
1780
-		else
1887
+		if (is_dir($dir . '/' . $entryname)) {
1888
+					deltree($dir . '/' . $entryname);
1889
+		} else
1781 1890
 		{
1782 1891
 			// Here, 755 doesn't really matter since we're deleting it anyway.
1783 1892
 			if (isset($package_ftp))
1784 1893
 			{
1785 1894
 				$ftp_file = strtr($dir . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
1786 1895
 
1787
-				if (!is_writable($dir . '/' . $entryname))
1788
-					$package_ftp->chmod($ftp_file, 0777);
1896
+				if (!is_writable($dir . '/' . $entryname)) {
1897
+									$package_ftp->chmod($ftp_file, 0777);
1898
+				}
1789 1899
 				$package_ftp->unlink($ftp_file);
1790
-			}
1791
-			else
1900
+			} else
1792 1901
 			{
1793
-				if (!is_writable($dir . '/' . $entryname))
1794
-					smf_chmod($dir . '/' . $entryname, 0777);
1902
+				if (!is_writable($dir . '/' . $entryname)) {
1903
+									smf_chmod($dir . '/' . $entryname, 0777);
1904
+				}
1795 1905
 				unlink($dir . '/' . $entryname);
1796 1906
 			}
1797 1907
 		}
@@ -1804,14 +1914,15 @@  discard block
 block discarded – undo
1804 1914
 		if (isset($package_ftp))
1805 1915
 		{
1806 1916
 			$ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => ''));
1807
-			if (!is_writable($dir . '/' . $entryname))
1808
-				$package_ftp->chmod($ftp_file, 0777);
1917
+			if (!is_writable($dir . '/' . $entryname)) {
1918
+							$package_ftp->chmod($ftp_file, 0777);
1919
+			}
1809 1920
 			$package_ftp->unlink($ftp_file);
1810
-		}
1811
-		else
1921
+		} else
1812 1922
 		{
1813
-			if (!is_writable($dir))
1814
-				smf_chmod($dir, 0777);
1923
+			if (!is_writable($dir)) {
1924
+							smf_chmod($dir, 0777);
1925
+			}
1815 1926
 			@rmdir($dir);
1816 1927
 		}
1817 1928
 	}
@@ -1834,10 +1945,11 @@  discard block
 block discarded – undo
1834 1945
 	{
1835 1946
 		if (!is_writable($strPath) && $mode !== false)
1836 1947
 		{
1837
-			if (isset($package_ftp))
1838
-				$package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode);
1839
-			else
1840
-				smf_chmod($strPath, $mode);
1948
+			if (isset($package_ftp)) {
1949
+							$package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode);
1950
+			} else {
1951
+							smf_chmod($strPath, $mode);
1952
+			}
1841 1953
 		}
1842 1954
 
1843 1955
 		$test = @opendir($strPath);
@@ -1845,36 +1957,37 @@  discard block
 block discarded – undo
1845 1957
 		{
1846 1958
 			closedir($test);
1847 1959
 			return is_writable($strPath);
1960
+		} else {
1961
+					return false;
1848 1962
 		}
1849
-		else
1850
-			return false;
1851 1963
 	}
1852 1964
 	// Is this an invalid path and/or we can't make the directory?
1853
-	if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode))
1854
-		return false;
1965
+	if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode)) {
1966
+			return false;
1967
+	}
1855 1968
 
1856 1969
 	if (!is_writable(dirname($strPath)) && $mode !== false)
1857 1970
 	{
1858
-		if (isset($package_ftp))
1859
-			$package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode);
1860
-		else
1861
-			smf_chmod(dirname($strPath), $mode);
1971
+		if (isset($package_ftp)) {
1972
+					$package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode);
1973
+		} else {
1974
+					smf_chmod(dirname($strPath), $mode);
1975
+		}
1862 1976
 	}
1863 1977
 
1864
-	if ($mode !== false && isset($package_ftp))
1865
-		return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')));
1866
-	elseif ($mode === false)
1978
+	if ($mode !== false && isset($package_ftp)) {
1979
+			return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')));
1980
+	} elseif ($mode === false)
1867 1981
 	{
1868 1982
 		$test = @opendir(dirname($strPath));
1869 1983
 		if ($test)
1870 1984
 		{
1871 1985
 			closedir($test);
1872 1986
 			return true;
1987
+		} else {
1988
+					return false;
1873 1989
 		}
1874
-		else
1875
-			return false;
1876
-	}
1877
-	else
1990
+	} else
1878 1991
 	{
1879 1992
 		@mkdir($strPath, $mode);
1880 1993
 		$test = @opendir($strPath);
@@ -1882,9 +1995,9 @@  discard block
 block discarded – undo
1882 1995
 		{
1883 1996
 			closedir($test);
1884 1997
 			return true;
1998
+		} else {
1999
+					return false;
1885 2000
 		}
1886
-		else
1887
-			return false;
1888 2001
 	}
1889 2002
 }
1890 2003
 
@@ -1900,39 +2013,46 @@  discard block
 block discarded – undo
1900 2013
 	/** @var ftp_connection $package_ftp */
1901 2014
 	global $package_ftp;
1902 2015
 
1903
-	if (!file_exists($destination) || !is_writable($destination))
1904
-		mktree($destination, 0755);
1905
-	if (!is_writable($destination))
1906
-		mktree($destination, 0777);
2016
+	if (!file_exists($destination) || !is_writable($destination)) {
2017
+			mktree($destination, 0755);
2018
+	}
2019
+	if (!is_writable($destination)) {
2020
+			mktree($destination, 0777);
2021
+	}
1907 2022
 
1908 2023
 	$current_dir = opendir($source);
1909
-	if ($current_dir == false)
1910
-		return;
2024
+	if ($current_dir == false) {
2025
+			return;
2026
+	}
1911 2027
 
1912 2028
 	while ($entryname = readdir($current_dir))
1913 2029
 	{
1914
-		if (in_array($entryname, array('.', '..')))
1915
-			continue;
2030
+		if (in_array($entryname, array('.', '..'))) {
2031
+					continue;
2032
+		}
1916 2033
 
1917
-		if (isset($package_ftp))
1918
-			$ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
2034
+		if (isset($package_ftp)) {
2035
+					$ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
2036
+		}
1919 2037
 
1920 2038
 		if (is_file($source . '/' . $entryname))
1921 2039
 		{
1922
-			if (isset($package_ftp) && !file_exists($destination . '/' . $entryname))
1923
-				$package_ftp->create_file($ftp_file);
1924
-			elseif (!file_exists($destination . '/' . $entryname))
1925
-				@touch($destination . '/' . $entryname);
2040
+			if (isset($package_ftp) && !file_exists($destination . '/' . $entryname)) {
2041
+							$package_ftp->create_file($ftp_file);
2042
+			} elseif (!file_exists($destination . '/' . $entryname)) {
2043
+							@touch($destination . '/' . $entryname);
2044
+			}
1926 2045
 		}
1927 2046
 
1928 2047
 		package_chmod($destination . '/' . $entryname);
1929 2048
 
1930
-		if (is_dir($source . '/' . $entryname))
1931
-			copytree($source . '/' . $entryname, $destination . '/' . $entryname);
1932
-		elseif (file_exists($destination . '/' . $entryname))
1933
-			package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname));
1934
-		else
1935
-			copy($source . '/' . $entryname, $destination . '/' . $entryname);
2049
+		if (is_dir($source . '/' . $entryname)) {
2050
+					copytree($source . '/' . $entryname, $destination . '/' . $entryname);
2051
+		} elseif (file_exists($destination . '/' . $entryname)) {
2052
+					package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname));
2053
+		} else {
2054
+					copy($source . '/' . $entryname, $destination . '/' . $entryname);
2055
+		}
1936 2056
 	}
1937 2057
 
1938 2058
 	closedir($current_dir);
@@ -1950,21 +2070,24 @@  discard block
 block discarded – undo
1950 2070
 	$data = array();
1951 2071
 
1952 2072
 	$dir = @dir($path . $sub_path);
1953
-	if (!$dir)
1954
-		return array();
2073
+	if (!$dir) {
2074
+			return array();
2075
+	}
1955 2076
 	while ($entry = $dir->read())
1956 2077
 	{
1957
-		if ($entry == '.' || $entry == '..')
1958
-			continue;
2078
+		if ($entry == '.' || $entry == '..') {
2079
+					continue;
2080
+		}
1959 2081
 
1960
-		if (is_dir($path . $sub_path . '/' . $entry))
1961
-			$data = array_merge($data, listtree($path, $sub_path . '/' . $entry));
1962
-		else
1963
-			$data[] = array(
2082
+		if (is_dir($path . $sub_path . '/' . $entry)) {
2083
+					$data = array_merge($data, listtree($path, $sub_path . '/' . $entry));
2084
+		} else {
2085
+					$data[] = array(
1964 2086
 				'filename' => $sub_path == '' ? $entry : $sub_path . '/' . $entry,
1965 2087
 				'size' => filesize($path . $sub_path . '/' . $entry),
1966 2088
 				'skipped' => false,
1967 2089
 			);
2090
+		}
1968 2091
 	}
1969 2092
 	$dir->close();
1970 2093
 
@@ -2019,8 +2142,9 @@  discard block
 block discarded – undo
2019 2142
 		{
2020 2143
 			// If this filename is relative, if so take a guess at what it should be.
2021 2144
 			$real_filename = $filename;
2022
-			if (strpos($filename, 'Themes') === 0)
2023
-				$real_filename = $boarddir . '/' . $filename;
2145
+			if (strpos($filename, 'Themes') === 0) {
2146
+							$real_filename = $boarddir . '/' . $filename;
2147
+			}
2024 2148
 
2025 2149
 			if (strpos($real_filename, $theme['theme_dir']) === 0)
2026 2150
 			{
@@ -2039,8 +2163,9 @@  discard block
 block discarded – undo
2039 2163
 		foreach ($theme_paths as $id => $theme)
2040 2164
 		{
2041 2165
 			// Default is getting done anyway, so no need for involvement here.
2042
-			if ($id == 1)
2043
-				continue;
2166
+			if ($id == 1) {
2167
+							continue;
2168
+			}
2044 2169
 
2045 2170
 			// For every template, do we want it? Yea, no, maybe?
2046 2171
 			foreach ($template_changes[1] as $index => $template_file)
@@ -2063,8 +2188,9 @@  discard block
 block discarded – undo
2063 2188
 		);
2064 2189
 
2065 2190
 		// Sometimes though, we have some additional files for other themes, if we have add them to the mix.
2066
-		if (isset($custom_themes_add[$files_to_change[1]]))
2067
-			$files_to_change += $custom_themes_add[$files_to_change[1]];
2191
+		if (isset($custom_themes_add[$files_to_change[1]])) {
2192
+					$files_to_change += $custom_themes_add[$files_to_change[1]];
2193
+		}
2068 2194
 
2069 2195
 		// Now, loop through all the files we're changing, and, well, change them ;)
2070 2196
 		foreach ($files_to_change as $theme => $working_file)
@@ -2098,11 +2224,13 @@  discard block
 block discarded – undo
2098 2224
 				continue;
2099 2225
 			}
2100 2226
 			// Okay, we're creating this file then...?
2101
-			elseif (!file_exists($working_file))
2102
-				$working_data = '';
2227
+			elseif (!file_exists($working_file)) {
2228
+							$working_data = '';
2229
+			}
2103 2230
 			// Phew, it exists!  Load 'er up!
2104
-			else
2105
-				$working_data = str_replace("\r", '', package_get_contents($working_file));
2231
+			else {
2232
+							$working_data = str_replace("\r", '', package_get_contents($working_file));
2233
+			}
2106 2234
 
2107 2235
 			$actions[] = array(
2108 2236
 				'type' => 'opened',
@@ -2123,8 +2251,8 @@  discard block
 block discarded – undo
2123 2251
 
2124 2252
 				// Grab all search items of this operation (in most cases just 1).
2125 2253
 				$searches = $operation->set('search');
2126
-				foreach ($searches as $i => $search)
2127
-					$actual_operation['searches'][] = array(
2254
+				foreach ($searches as $i => $search) {
2255
+									$actual_operation['searches'][] = array(
2128 2256
 						'position' => $search->exists('@position') && in_array(trim($search->fetch('@position')), array('before', 'after', 'replace', 'end')) ? trim($search->fetch('@position')) : 'replace',
2129 2257
 						'is_reg_exp' => $search->exists('@regexp') && trim($search->fetch('@regexp')) === 'true',
2130 2258
 						'loose_whitespace' => $search->exists('@whitespace') && trim($search->fetch('@whitespace')) === 'loose',
@@ -2133,6 +2261,7 @@  discard block
 block discarded – undo
2133 2261
 						'preg_search' => '',
2134 2262
 						'preg_replace' => '',
2135 2263
 					);
2264
+				}
2136 2265
 
2137 2266
 				// At least one search should be defined.
2138 2267
 				if (empty($actual_operation['searches']))
@@ -2157,30 +2286,32 @@  discard block
 block discarded – undo
2157 2286
 						// Reverse modification of regular expressions are not allowed.
2158 2287
 						if ($search['is_reg_exp'])
2159 2288
 						{
2160
-							if ($actual_operation['error'] === 'fatal')
2161
-								$actions[] = array(
2289
+							if ($actual_operation['error'] === 'fatal') {
2290
+															$actions[] = array(
2162 2291
 									'type' => 'failure',
2163 2292
 									'filename' => $working_file,
2164 2293
 									'search' => $search['search'],
2165 2294
 									'is_custom' => $theme > 1 ? $theme : 0,
2166 2295
 								);
2296
+							}
2167 2297
 
2168 2298
 							// Continue to the next operation.
2169 2299
 							continue 2;
2170 2300
 						}
2171 2301
 
2172 2302
 						// The replacement is now the search subject...
2173
-						if ($search['position'] === 'replace' || $search['position'] === 'end')
2174
-							$actual_operation['searches'][$i]['search'] = $search['add'];
2175
-						else
2303
+						if ($search['position'] === 'replace' || $search['position'] === 'end') {
2304
+													$actual_operation['searches'][$i]['search'] = $search['add'];
2305
+						} else
2176 2306
 						{
2177 2307
 							// Reversing a before/after modification becomes a replacement.
2178 2308
 							$actual_operation['searches'][$i]['position'] = 'replace';
2179 2309
 
2180
-							if ($search['position'] === 'before')
2181
-								$actual_operation['searches'][$i]['search'] .= $search['add'];
2182
-							elseif ($search['position'] === 'after')
2183
-								$actual_operation['searches'][$i]['search'] = $search['add'] . $search['search'];
2310
+							if ($search['position'] === 'before') {
2311
+															$actual_operation['searches'][$i]['search'] .= $search['add'];
2312
+							} elseif ($search['position'] === 'after') {
2313
+															$actual_operation['searches'][$i]['search'] = $search['add'] . $search['search'];
2314
+							}
2184 2315
 						}
2185 2316
 
2186 2317
 						// ...and the search subject is now the replacement.
@@ -2208,16 +2339,17 @@  discard block
 block discarded – undo
2208 2339
 				foreach ($actual_operation['searches'] as $i => $search)
2209 2340
 				{
2210 2341
 					// Not much needed if the search subject is already a regexp.
2211
-					if ($search['is_reg_exp'])
2212
-						$actual_operation['searches'][$i]['preg_search'] = $search['search'];
2213
-					else
2342
+					if ($search['is_reg_exp']) {
2343
+											$actual_operation['searches'][$i]['preg_search'] = $search['search'];
2344
+					} else
2214 2345
 					{
2215 2346
 						// Make the search subject fit into a regular expression.
2216 2347
 						$actual_operation['searches'][$i]['preg_search'] = preg_quote($search['search'], '~');
2217 2348
 
2218 2349
 						// Using 'loose', a random amount of tabs and spaces may be used.
2219
-						if ($search['loose_whitespace'])
2220
-							$actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']);
2350
+						if ($search['loose_whitespace']) {
2351
+													$actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']);
2352
+						}
2221 2353
 					}
2222 2354
 
2223 2355
 					// Shuzzup.  This is done so we can safely use a regular expression. ($0 is bad!!)
@@ -2243,8 +2375,7 @@  discard block
 block discarded – undo
2243 2375
 						if ($undo)
2244 2376
 						{
2245 2377
 							$actual_operation['searches'][$i]['preg_replace'] = '';
2246
-						}
2247
-						else
2378
+						} else
2248 2379
 						{
2249 2380
 							$actual_operation['searches'][$i]['preg_search'] = '(\\n\\?\\>)?$';
2250 2381
 							$actual_operation['searches'][$i]['preg_replace'] .= '$1';
@@ -2291,8 +2422,9 @@  discard block
 block discarded – undo
2291 2422
 					}
2292 2423
 
2293 2424
 					// Replace it into nothing? That's not an option...unless it's an undoing end.
2294
-					if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo))
2295
-						continue;
2425
+					if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo)) {
2426
+											continue;
2427
+					}
2296 2428
 
2297 2429
 					// Finally, we're doing some replacements.
2298 2430
 					$working_data = preg_replace('~' . $actual_operation['searches'][$i]['preg_search'] . '~s', $actual_operation['searches'][$i]['preg_replace'], $working_data, 1);
@@ -2317,22 +2449,25 @@  discard block
 block discarded – undo
2317 2449
 
2318 2450
 			package_chmod($working_file);
2319 2451
 
2320
-			if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file))))
2321
-				$actions[] = array(
2452
+			if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) {
2453
+							$actions[] = array(
2322 2454
 					'type' => 'chmod',
2323 2455
 					'filename' => $working_file
2324 2456
 				);
2457
+			}
2325 2458
 
2326
-			if (basename($working_file) == 'Settings_bak.php')
2327
-				continue;
2459
+			if (basename($working_file) == 'Settings_bak.php') {
2460
+							continue;
2461
+			}
2328 2462
 
2329 2463
 			if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file))
2330 2464
 			{
2331 2465
 				// No, no, not Settings.php!
2332
-				if (basename($working_file) == 'Settings.php')
2333
-					@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2334
-				else
2335
-					@copy($working_file, $working_file . '~');
2466
+				if (basename($working_file) == 'Settings.php') {
2467
+									@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2468
+				} else {
2469
+									@copy($working_file, $working_file . '~');
2470
+				}
2336 2471
 			}
2337 2472
 
2338 2473
 			// Always call this, even if in testing, because it won't really be written in testing mode.
@@ -2399,8 +2534,9 @@  discard block
 block discarded – undo
2399 2534
 		if ($code_match[1] != 'edit file' && $code_match[1] != 'file')
2400 2535
 		{
2401 2536
 			// It's a step, let's add that to the current steps.
2402
-			if (isset($temp_changes[$step_counter]))
2403
-				$temp_changes[$step_counter]['changes'][] = $code_match[0];
2537
+			if (isset($temp_changes[$step_counter])) {
2538
+							$temp_changes[$step_counter]['changes'][] = $code_match[0];
2539
+			}
2404 2540
 			continue;
2405 2541
 		}
2406 2542
 
@@ -2417,11 +2553,13 @@  discard block
 block discarded – undo
2417 2553
 		foreach ($theme_paths as $id => $theme)
2418 2554
 		{
2419 2555
 			// If this filename is relative, if so take a guess at what it should be.
2420
-			if (strpos($filename, 'Themes') === 0)
2421
-				$filename = $boarddir . '/' . $filename;
2556
+			if (strpos($filename, 'Themes') === 0) {
2557
+							$filename = $boarddir . '/' . $filename;
2558
+			}
2422 2559
 
2423
-			if (strpos($filename, $theme['theme_dir']) === 0)
2424
-				$template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1);
2560
+			if (strpos($filename, $theme['theme_dir']) === 0) {
2561
+							$template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1);
2562
+			}
2425 2563
 		}
2426 2564
 	}
2427 2565
 
@@ -2434,8 +2572,9 @@  discard block
 block discarded – undo
2434 2572
 		foreach ($theme_paths as $id => $theme)
2435 2573
 		{
2436 2574
 			// Don't do default, it means nothing to me.
2437
-			if ($id == 1)
2438
-				continue;
2575
+			if ($id == 1) {
2576
+							continue;
2577
+			}
2439 2578
 
2440 2579
 			// Now, for each file do we need to edit it?
2441 2580
 			foreach ($template_changes[1] as $pos => $template_file)
@@ -2471,32 +2610,36 @@  discard block
 block discarded – undo
2471 2610
 				package_chmod($working_file);
2472 2611
 
2473 2612
 				// Don't even dare.
2474
-				if (basename($working_file) == 'Settings_bak.php')
2475
-					continue;
2613
+				if (basename($working_file) == 'Settings_bak.php') {
2614
+									continue;
2615
+				}
2476 2616
 
2477
-				if (!is_writable($working_file))
2478
-					$actions[] = array(
2617
+				if (!is_writable($working_file)) {
2618
+									$actions[] = array(
2479 2619
 						'type' => 'chmod',
2480 2620
 						'filename' => $working_file
2481 2621
 					);
2622
+				}
2482 2623
 
2483 2624
 				if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file))
2484 2625
 				{
2485
-					if (basename($working_file) == 'Settings.php')
2486
-						@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2487
-					else
2488
-						@copy($working_file, $working_file . '~');
2626
+					if (basename($working_file) == 'Settings.php') {
2627
+											@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2628
+					} else {
2629
+											@copy($working_file, $working_file . '~');
2630
+					}
2489 2631
 				}
2490 2632
 
2491 2633
 				package_put_contents($working_file, $working_data, $testing);
2492 2634
 			}
2493 2635
 
2494
-			if ($working_file !== null)
2495
-				$actions[] = array(
2636
+			if ($working_file !== null) {
2637
+							$actions[] = array(
2496 2638
 					'type' => 'saved',
2497 2639
 					'filename' => $working_file,
2498 2640
 					'is_custom' => $is_custom,
2499 2641
 				);
2642
+			}
2500 2643
 
2501 2644
 			// Is this "now working on" file a theme specific one?
2502 2645
 			$is_custom = isset($theme_id_ref[$counter - 1]) ? $theme_id_ref[$counter - 1] : 0;
@@ -2515,10 +2658,11 @@  discard block
 block discarded – undo
2515 2658
 			{
2516 2659
 				$places_to_check = array($boarddir, $sourcedir, $settings['default_theme_dir'], $settings['default_theme_dir'] . '/languages');
2517 2660
 
2518
-				foreach ($places_to_check as $place)
2519
-					if (file_exists($place . '/' . $working_file))
2661
+				foreach ($places_to_check as $place) {
2662
+									if (file_exists($place . '/' . $working_file))
2520 2663
 					{
2521 2664
 						$working_file = $place . '/' . $working_file;
2665
+				}
2522 2666
 						break;
2523 2667
 					}
2524 2668
 			}
@@ -2532,8 +2676,7 @@  discard block
 block discarded – undo
2532 2676
 					'type' => 'opened',
2533 2677
 					'filename' => $working_file
2534 2678
 				);
2535
-			}
2536
-			else
2679
+			} else
2537 2680
 			{
2538 2681
 				$actions[] = array(
2539 2682
 					'type' => 'missing',
@@ -2569,11 +2712,13 @@  discard block
 block discarded – undo
2569 2712
 			$replace_with = $code_match[2];
2570 2713
 
2571 2714
 			// Add this afterward...
2572
-			if ($code_match[1] == 'add' || $code_match[1] == 'add after')
2573
-				$replace_with = $working_search . "\n" . $replace_with;
2715
+			if ($code_match[1] == 'add' || $code_match[1] == 'add after') {
2716
+							$replace_with = $working_search . "\n" . $replace_with;
2717
+			}
2574 2718
 			// Add this beforehand.
2575
-			elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above')
2576
-				$replace_with .= "\n" . $working_search;
2719
+			elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') {
2720
+							$replace_with .= "\n" . $working_search;
2721
+			}
2577 2722
 			// Otherwise.. replace with $replace_with ;).
2578 2723
 		}
2579 2724
 
@@ -2636,29 +2781,32 @@  discard block
 block discarded – undo
2636 2781
 	{
2637 2782
 		package_chmod($working_file);
2638 2783
 
2639
-		if (!is_writable($working_file))
2640
-			$actions[] = array(
2784
+		if (!is_writable($working_file)) {
2785
+					$actions[] = array(
2641 2786
 				'type' => 'chmod',
2642 2787
 				'filename' => $working_file
2643 2788
 			);
2789
+		}
2644 2790
 
2645 2791
 		if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file))
2646 2792
 		{
2647
-			if (basename($working_file) == 'Settings.php')
2648
-				@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2649
-			else
2650
-				@copy($working_file, $working_file . '~');
2793
+			if (basename($working_file) == 'Settings.php') {
2794
+							@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2795
+			} else {
2796
+							@copy($working_file, $working_file . '~');
2797
+			}
2651 2798
 		}
2652 2799
 
2653 2800
 		package_put_contents($working_file, $working_data, $testing);
2654 2801
 	}
2655 2802
 
2656
-	if ($working_file !== null)
2657
-		$actions[] = array(
2803
+	if ($working_file !== null) {
2804
+			$actions[] = array(
2658 2805
 			'type' => 'saved',
2659 2806
 			'filename' => $working_file,
2660 2807
 			'is_custom' => $is_custom,
2661 2808
 		);
2809
+	}
2662 2810
 
2663 2811
 	$actions[] = array(
2664 2812
 		'type' => 'result',
@@ -2684,17 +2832,19 @@  discard block
 block discarded – undo
2684 2832
 		$mem_check = setMemoryLimit('128M');
2685 2833
 
2686 2834
 		// Windows doesn't seem to care about the memory_limit.
2687
-		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false)
2688
-			$package_cache = array();
2689
-		else
2690
-			$package_cache = false;
2835
+		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) {
2836
+					$package_cache = array();
2837
+		} else {
2838
+					$package_cache = false;
2839
+		}
2691 2840
 	}
2692 2841
 
2693
-	if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename]))
2694
-		return file_get_contents($filename);
2695
-	else
2696
-		return $package_cache[$filename];
2697
-}
2842
+	if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename])) {
2843
+			return file_get_contents($filename);
2844
+	} else {
2845
+			return $package_cache[$filename];
2846
+	}
2847
+	}
2698 2848
 
2699 2849
 /**
2700 2850
  * Writes data to a file, almost exactly like the file_put_contents() function.
@@ -2718,19 +2868,22 @@  discard block
 block discarded – undo
2718 2868
 		// Try to increase the memory limit - we don't want to run out of ram!
2719 2869
 		$mem_check = setMemoryLimit('128M');
2720 2870
 
2721
-		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false)
2722
-			$package_cache = array();
2723
-		else
2724
-			$package_cache = false;
2871
+		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) {
2872
+					$package_cache = array();
2873
+		} else {
2874
+					$package_cache = false;
2875
+		}
2725 2876
 	}
2726 2877
 
2727
-	if (isset($package_ftp))
2728
-		$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2878
+	if (isset($package_ftp)) {
2879
+			$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2880
+	}
2729 2881
 
2730
-	if (!file_exists($filename) && isset($package_ftp))
2731
-		$package_ftp->create_file($ftp_file);
2732
-	elseif (!file_exists($filename))
2733
-		@touch($filename);
2882
+	if (!file_exists($filename) && isset($package_ftp)) {
2883
+			$package_ftp->create_file($ftp_file);
2884
+	} elseif (!file_exists($filename)) {
2885
+			@touch($filename);
2886
+	}
2734 2887
 
2735 2888
 	package_chmod($filename);
2736 2889
 
@@ -2739,22 +2892,23 @@  discard block
 block discarded – undo
2739 2892
 		$fp = @fopen($filename, in_array(substr($filename, -3), $text_filetypes) ? 'w' : 'wb');
2740 2893
 
2741 2894
 		// We should show an error message or attempt a rollback, no?
2742
-		if (!$fp)
2743
-			return false;
2895
+		if (!$fp) {
2896
+					return false;
2897
+		}
2744 2898
 
2745 2899
 		fwrite($fp, $data);
2746 2900
 		fclose($fp);
2747
-	}
2748
-	elseif (strpos($filename, 'Packages/') !== false || $package_cache === false)
2749
-		return strlen($data);
2750
-	else
2901
+	} elseif (strpos($filename, 'Packages/') !== false || $package_cache === false) {
2902
+			return strlen($data);
2903
+	} else
2751 2904
 	{
2752 2905
 		$package_cache[$filename] = $data;
2753 2906
 
2754 2907
 		// Permission denied, eh?
2755 2908
 		$fp = @fopen($filename, 'r+');
2756
-		if (!$fp)
2757
-			return false;
2909
+		if (!$fp) {
2910
+					return false;
2911
+		}
2758 2912
 		fclose($fp);
2759 2913
 	}
2760 2914
 
@@ -2772,19 +2926,22 @@  discard block
 block discarded – undo
2772 2926
 	global $package_ftp, $package_cache;
2773 2927
 	static $text_filetypes = array('php', 'txt', '.js', 'css', 'vbs', 'tml', 'htm');
2774 2928
 
2775
-	if (empty($package_cache))
2776
-		return;
2929
+	if (empty($package_cache)) {
2930
+			return;
2931
+	}
2777 2932
 
2778 2933
 	// First, let's check permissions!
2779 2934
 	foreach ($package_cache as $filename => $data)
2780 2935
 	{
2781
-		if (isset($package_ftp))
2782
-			$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2936
+		if (isset($package_ftp)) {
2937
+					$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2938
+		}
2783 2939
 
2784
-		if (!file_exists($filename) && isset($package_ftp))
2785
-			$package_ftp->create_file($ftp_file);
2786
-		elseif (!file_exists($filename))
2787
-			@touch($filename);
2940
+		if (!file_exists($filename) && isset($package_ftp)) {
2941
+					$package_ftp->create_file($ftp_file);
2942
+		} elseif (!file_exists($filename)) {
2943
+					@touch($filename);
2944
+		}
2788 2945
 
2789 2946
 		$result = package_chmod($filename);
2790 2947
 
@@ -2838,8 +2995,9 @@  discard block
 block discarded – undo
2838 2995
 	/** @var ftp_connection $package_ftp */
2839 2996
 	global $package_ftp;
2840 2997
 
2841
-	if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable')
2842
-		return true;
2998
+	if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable') {
2999
+			return true;
3000
+	}
2843 3001
 
2844 3002
 	// Start off checking without FTP.
2845 3003
 	if (!isset($package_ftp) || $package_ftp === false)
@@ -2861,8 +3019,7 @@  discard block
 block discarded – undo
2861 3019
 
2862 3020
 				// Keep track of the writable status here.
2863 3021
 				$file_permissions = @fileperms($chmod_file);
2864
-			}
2865
-			else
3022
+			} else
2866 3023
 			{
2867 3024
 				// This looks odd, but it's an attempt to work around PHP suExec.
2868 3025
 				if (!file_exists($chmod_file) && $perm_state == 'writable')
@@ -2872,24 +3029,28 @@  discard block
 block discarded – undo
2872 3029
 					mktree(dirname($chmod_file), 0755);
2873 3030
 					@touch($chmod_file);
2874 3031
 					smf_chmod($chmod_file, 0755);
3032
+				} else {
3033
+									$file_permissions = @fileperms($chmod_file);
2875 3034
 				}
2876
-				else
2877
-					$file_permissions = @fileperms($chmod_file);
2878 3035
 			}
2879 3036
 
2880 3037
 			// This looks odd, but it's another attempt to work around PHP suExec.
2881
-			if ($perm_state != 'writable')
2882
-				smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644);
2883
-			else
3038
+			if ($perm_state != 'writable') {
3039
+							smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644);
3040
+			} else
2884 3041
 			{
2885
-				if (!@is_writable($chmod_file))
2886
-					smf_chmod($chmod_file, 0755);
2887
-				if (!@is_writable($chmod_file))
2888
-					smf_chmod($chmod_file, 0777);
2889
-				if (!@is_writable(dirname($chmod_file)))
2890
-					smf_chmod($chmod_file, 0755);
2891
-				if (!@is_writable(dirname($chmod_file)))
2892
-					smf_chmod($chmod_file, 0777);
3042
+				if (!@is_writable($chmod_file)) {
3043
+									smf_chmod($chmod_file, 0755);
3044
+				}
3045
+				if (!@is_writable($chmod_file)) {
3046
+									smf_chmod($chmod_file, 0777);
3047
+				}
3048
+				if (!@is_writable(dirname($chmod_file))) {
3049
+									smf_chmod($chmod_file, 0755);
3050
+				}
3051
+				if (!@is_writable(dirname($chmod_file))) {
3052
+									smf_chmod($chmod_file, 0777);
3053
+				}
2893 3054
 			}
2894 3055
 
2895 3056
 			// The ultimate writable test.
@@ -2898,20 +3059,22 @@  discard block
 block discarded – undo
2898 3059
 				$fp = is_dir($chmod_file) ? @opendir($chmod_file) : @fopen($chmod_file, 'rb');
2899 3060
 				if (@is_writable($chmod_file) && $fp)
2900 3061
 				{
2901
-					if (!is_dir($chmod_file))
2902
-						fclose($fp);
2903
-					else
2904
-						closedir($fp);
3062
+					if (!is_dir($chmod_file)) {
3063
+											fclose($fp);
3064
+					} else {
3065
+											closedir($fp);
3066
+					}
2905 3067
 
2906 3068
 					// It worked!
2907
-					if ($track_change)
2908
-						$_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions;
3069
+					if ($track_change) {
3070
+											$_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions;
3071
+					}
2909 3072
 
2910 3073
 					return true;
2911 3074
 				}
3075
+			} elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file])) {
3076
+							unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]);
2912 3077
 			}
2913
-			elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file]))
2914
-				unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]);
2915 3078
 		}
2916 3079
 
2917 3080
 		// If we're here we're a failure.
@@ -2930,31 +3093,33 @@  discard block
 block discarded – undo
2930 3093
 			mktree(dirname($filename), 0755);
2931 3094
 			$package_ftp->create_file($ftp_file);
2932 3095
 			$package_ftp->chmod($ftp_file, 0755);
3096
+		} else {
3097
+					$file_permissions = @fileperms($filename);
2933 3098
 		}
2934
-		else
2935
-			$file_permissions = @fileperms($filename);
2936 3099
 
2937 3100
 		if ($perm_state != 'writable')
2938 3101
 		{
2939 3102
 			$package_ftp->chmod($ftp_file, $perm_state == 'execute' ? 0755 : 0644);
2940
-		}
2941
-		else
3103
+		} else
2942 3104
 		{
2943
-			if (!@is_writable($filename))
2944
-				$package_ftp->chmod($ftp_file, 0777);
2945
-			if (!@is_writable(dirname($filename)))
2946
-				$package_ftp->chmod(dirname($ftp_file), 0777);
3105
+			if (!@is_writable($filename)) {
3106
+							$package_ftp->chmod($ftp_file, 0777);
3107
+			}
3108
+			if (!@is_writable(dirname($filename))) {
3109
+							$package_ftp->chmod(dirname($ftp_file), 0777);
3110
+			}
2947 3111
 		}
2948 3112
 
2949 3113
 		if (@is_writable($filename))
2950 3114
 		{
2951
-			if ($track_change)
2952
-				$_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions;
3115
+			if ($track_change) {
3116
+							$_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions;
3117
+			}
2953 3118
 
2954 3119
 			return true;
3120
+		} elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename])) {
3121
+					unset($_SESSION['pack_ftp']['original_perms'][$filename]);
2955 3122
 		}
2956
-		elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename]))
2957
-			unset($_SESSION['pack_ftp']['original_perms'][$filename]);
2958 3123
 	}
2959 3124
 
2960 3125
 	// Oh dear, we failed if we get here.
@@ -2972,11 +3137,13 @@  discard block
 block discarded – undo
2972 3137
 	$n = strlen($pass);
2973 3138
 
2974 3139
 	$salt = session_id();
2975
-	while (strlen($salt) < $n)
2976
-		$salt .= session_id();
3140
+	while (strlen($salt) < $n) {
3141
+			$salt .= session_id();
3142
+	}
2977 3143
 
2978
-	for ($i = 0; $i < $n; $i++)
2979
-		$pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32));
3144
+	for ($i = 0; $i < $n; $i++) {
3145
+			$pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32));
3146
+	}
2980 3147
 
2981 3148
 	return $pass;
2982 3149
 }
@@ -2995,8 +3162,9 @@  discard block
 block discarded – undo
2995 3162
 	$base_files = array('index.php', 'SSI.php', 'agreement.txt', 'cron.php', 'ssi_examples.php', 'ssi_examples.shtml', 'subscriptions.php');
2996 3163
 	foreach ($base_files as $file)
2997 3164
 	{
2998
-		if (file_exists($boarddir . '/' . $file))
2999
-			$files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file;
3165
+		if (file_exists($boarddir . '/' . $file)) {
3166
+					$files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file;
3167
+		}
3000 3168
 	}
3001 3169
 
3002 3170
 	$dirs = array(
@@ -3013,8 +3181,9 @@  discard block
 block discarded – undo
3013 3181
 			'theme_dir' => 'theme_dir',
3014 3182
 		)
3015 3183
 	);
3016
-	while ($row = $smcFunc['db_fetch_assoc']($request))
3017
-		$dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/');
3184
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
3185
+			$dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/');
3186
+	}
3018 3187
 	$smcFunc['db_free_result']($request);
3019 3188
 
3020 3189
 	try
@@ -3029,11 +3198,13 @@  discard block
 block discarded – undo
3029 3198
 
3030 3199
 			foreach ($iter as $entry => $dir)
3031 3200
 			{
3032
-				if ($dir->isDir())
3033
-					continue;
3201
+				if ($dir->isDir()) {
3202
+									continue;
3203
+				}
3034 3204
 
3035
-				if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0)
3036
-					continue;
3205
+				if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0) {
3206
+									continue;
3207
+				}
3037 3208
 
3038 3209
 				$files[empty($_REQUEST['use_full_paths']) ? str_replace(realpath($boarddir), '', $entry) : $entry] = $entry;
3039 3210
 			}
@@ -3041,10 +3212,12 @@  discard block
 block discarded – undo
3041 3212
 		$obj = new ArrayObject($files);
3042 3213
 		$iterator = $obj->getIterator();
3043 3214
 
3044
-		if (!file_exists($packagesdir . '/backups'))
3045
-			mktree($packagesdir . '/backups', 0777);
3046
-		if (!is_writable($packagesdir . '/backups'))
3047
-			package_chmod($packagesdir . '/backups');
3215
+		if (!file_exists($packagesdir . '/backups')) {
3216
+					mktree($packagesdir . '/backups', 0777);
3217
+		}
3218
+		if (!is_writable($packagesdir . '/backups')) {
3219
+					package_chmod($packagesdir . '/backups');
3220
+		}
3048 3221
 		$output_file = $packagesdir . '/backups/' . strftime('%Y-%m-%d_') . preg_replace('~[$\\\\/:<>|?*"\']~', '', $id);
3049 3222
 		$output_ext = '.tar';
3050 3223
 		$output_ext_target = '.tar.gz';
@@ -3052,16 +3225,18 @@  discard block
 block discarded – undo
3052 3225
 		if (file_exists($output_file . $output_ext_target))
3053 3226
 		{
3054 3227
 			$i = 2;
3055
-			while (file_exists($output_file . '_' . $i . $output_ext_target))
3056
-				$i++;
3228
+			while (file_exists($output_file . '_' . $i . $output_ext_target)) {
3229
+							$i++;
3230
+			}
3057 3231
 			$output_file = $output_file . '_' . $i . $output_ext;
3232
+		} else {
3233
+					$output_file .= $output_ext;
3058 3234
 		}
3059
-		else
3060
-			$output_file .= $output_ext;
3061 3235
 
3062 3236
 		@set_time_limit(300);
3063
-		if (function_exists('apache_reset_timeout'))
3064
-			@apache_reset_timeout();
3237
+		if (function_exists('apache_reset_timeout')) {
3238
+					@apache_reset_timeout();
3239
+		}
3065 3240
 
3066 3241
 		$a = new PharData($output_file);
3067 3242
 		$a->buildFromIterator($iterator);
@@ -3073,8 +3248,7 @@  discard block
 block discarded – undo
3073 3248
 		 */
3074 3249
 		unset($a);
3075 3250
 		unlink($output_file);
3076
-	}
3077
-	catch (Exception $e)
3251
+	} catch (Exception $e)
3078 3252
 	{
3079 3253
 		log_error($e->getMessage(), 'backup');
3080 3254
 
Please login to merge, or discard this patch.
Sources/Subs-Post.php 1 patch
Braces   +520 added lines, -389 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Takes a message and parses it, returning nothing.
@@ -31,8 +32,9 @@  discard block
 block discarded – undo
31 32
 	global $user_info, $modSettings, $context, $sourcedir;
32 33
 
33 34
 	// This line makes all languages *theoretically* work even with the wrong charset ;).
34
-	if (empty($context['utf8']))
35
-		$message = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
35
+	if (empty($context['utf8'])) {
36
+			$message = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
37
+	}
36 38
 
37 39
 	// Clean up after nobbc ;).
38 40
 	$message = preg_replace_callback('~\[nobbc\](.+?)\[/nobbc\]~is', function($a)
@@ -47,17 +49,19 @@  discard block
 block discarded – undo
47 49
 	$message = preg_replace('~\.{100,}~', '...', $message);
48 50
 
49 51
 	// Trim off trailing quotes - these often happen by accident.
50
-	while (substr($message, -7) == '[quote]')
51
-		$message = substr($message, 0, -7);
52
-	while (substr($message, 0, 8) == '[/quote]')
53
-		$message = substr($message, 8);
52
+	while (substr($message, -7) == '[quote]') {
53
+			$message = substr($message, 0, -7);
54
+	}
55
+	while (substr($message, 0, 8) == '[/quote]') {
56
+			$message = substr($message, 8);
57
+	}
54 58
 
55 59
 	// Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed.
56 60
 	$in_tag = false;
57 61
 	$had_tag = false;
58 62
 	$codeopen = 0;
59
-	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches))
60
-		foreach ($matches[0] as $index => $dummy)
63
+	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) {
64
+			foreach ($matches[0] as $index => $dummy)
61 65
 		{
62 66
 			// Closing?
63 67
 			if (!empty($matches[2][$index]))
@@ -65,6 +69,7 @@  discard block
 block discarded – undo
65 69
 				// If it's closing and we're not in a tag we need to open it...
66 70
 				if (!$in_tag)
67 71
 					$codeopen = true;
72
+	}
68 73
 				// Either way we ain't in one any more.
69 74
 				$in_tag = false;
70 75
 			}
@@ -73,17 +78,20 @@  discard block
 block discarded – undo
73 78
 			{
74 79
 				$had_tag = true;
75 80
 				// If we're in a tag don't do nought!
76
-				if (!$in_tag)
77
-					$in_tag = true;
81
+				if (!$in_tag) {
82
+									$in_tag = true;
83
+				}
78 84
 			}
79 85
 		}
80 86
 
81 87
 	// If we have an open tag, close it.
82
-	if ($in_tag)
83
-		$message .= '[/code]';
88
+	if ($in_tag) {
89
+			$message .= '[/code]';
90
+	}
84 91
 	// Open any ones that need to be open, only if we've never had a tag.
85
-	if ($codeopen && !$had_tag)
86
-		$message = '[code]' . $message;
92
+	if ($codeopen && !$had_tag) {
93
+			$message = '[code]' . $message;
94
+	}
87 95
 
88 96
 	// Now that we've fixed all the code tags, let's fix the img and url tags...
89 97
 	$parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
@@ -109,23 +117,26 @@  discard block
 block discarded – undo
109 117
 	fixTags($message);
110 118
 
111 119
 	// Replace /me.+?\n with [me=name]dsf[/me]\n.
112
-	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false)
113
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
114
-	else
115
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
120
+	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) {
121
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
122
+	} else {
123
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
124
+	}
116 125
 
117 126
 	if (!$previewing && strpos($message, '[html]') !== false)
118 127
 	{
119
-		if (allowedTo('admin_forum'))
120
-			$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
128
+		if (allowedTo('admin_forum')) {
129
+					$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
121 130
 				return '[html]' . strtr(un_htmlspecialchars($m[1]), array("\n" => '&#13;', '  ' => ' &#32;', '[' => '&#91;', ']' => '&#93;')) . '[/html]';
131
+		}
122 132
 			}, $message);
123 133
 
124 134
 		// We should edit them out, or else if an admin edits the message they will get shown...
125 135
 		else
126 136
 		{
127
-			while (strpos($message, '[html]') !== false)
128
-				$message = preg_replace('~\[[/]?html\]~i', '', $message);
137
+			while (strpos($message, '[html]') !== false) {
138
+							$message = preg_replace('~\[[/]?html\]~i', '', $message);
139
+			}
129 140
 		}
130 141
 	}
131 142
 
@@ -147,10 +158,12 @@  discard block
 block discarded – undo
147 158
 
148 159
 	$list_open = substr_count($message, '[list]') + substr_count($message, '[list ');
149 160
 	$list_close = substr_count($message, '[/list]');
150
-	if ($list_close - $list_open > 0)
151
-		$message = str_repeat('[list]', $list_close - $list_open) . $message;
152
-	if ($list_open - $list_close > 0)
153
-		$message = $message . str_repeat('[/list]', $list_open - $list_close);
161
+	if ($list_close - $list_open > 0) {
162
+			$message = str_repeat('[list]', $list_close - $list_open) . $message;
163
+	}
164
+	if ($list_open - $list_close > 0) {
165
+			$message = $message . str_repeat('[/list]', $list_open - $list_close);
166
+	}
154 167
 
155 168
 	$mistake_fixes = array(
156 169
 		// Find [table]s not followed by [tr].
@@ -199,8 +212,9 @@  discard block
 block discarded – undo
199 212
 	);
200 213
 
201 214
 	// Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.)
202
-	for ($j = 0; $j < 3; $j++)
203
-		$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
215
+	for ($j = 0; $j < 3; $j++) {
216
+			$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
217
+	}
204 218
 
205 219
 	// Remove empty bbc from the sections outside the code tags
206 220
 	$allowedEmpty = array(
@@ -211,24 +225,28 @@  discard block
 block discarded – undo
211 225
 	require_once($sourcedir . '/Subs.php');
212 226
 
213 227
 	$alltags = array();
214
-	foreach (($codes = parse_bbc(false)) as $code)
215
-		if (!in_array($code['tag'], $allowedEmpty))
228
+	foreach (($codes = parse_bbc(false)) as $code) {
229
+			if (!in_array($code['tag'], $allowedEmpty))
216 230
 			$alltags[] = $code['tag'];
231
+	}
217 232
 
218 233
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
219 234
 
220
-	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message))
221
-		$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
235
+	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) {
236
+			$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
237
+	}
222 238
 
223 239
 	// Restore code blocks
224
-	if (!empty($code_tags))
225
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
240
+	if (!empty($code_tags)) {
241
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
242
+	}
226 243
 
227 244
 	// Restore white space entities
228
-	if (!$previewing)
229
-		$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
230
-	else
231
-		$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
245
+	if (!$previewing) {
246
+			$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
247
+	} else {
248
+			$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
249
+	}
232 250
 
233 251
 	// Now let's quickly clean up things that will slow our parser (which are common in posted code.)
234 252
 	$message = strtr($message, array('[]' => '&#91;]', '[&#039;' => '&#91;&#039;'));
@@ -271,8 +289,9 @@  discard block
 block discarded – undo
271 289
 		return "[time]" . timeformat("$m[1]", false) . "[/time]";
272 290
 	}, $message);
273 291
 
274
-	if (!empty($code_tags))
275
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
292
+	if (!empty($code_tags)) {
293
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
294
+	}
276 295
 
277 296
 	// Change breaks back to \n's and &nsbp; back to spaces.
278 297
 	return preg_replace('~<br( /)?' . '>~', "\n", str_replace('&nbsp;', ' ', $message));
@@ -353,8 +372,9 @@  discard block
 block discarded – undo
353 372
 	);
354 373
 
355 374
 	// Fix each type of tag.
356
-	foreach ($fixArray as $param)
357
-		fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
375
+	foreach ($fixArray as $param) {
376
+			fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
377
+	}
358 378
 
359 379
 	// Now fix possible security problems with images loading links automatically...
360 380
 	$message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m)
@@ -379,10 +399,11 @@  discard block
 block discarded – undo
379 399
 {
380 400
 	global $boardurl, $scripturl;
381 401
 
382
-	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0)
383
-		$domain_url = $match[1];
384
-	else
385
-		$domain_url = $boardurl . '/';
402
+	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) {
403
+			$domain_url = $match[1];
404
+	} else {
405
+			$domain_url = $boardurl . '/';
406
+	}
386 407
 
387 408
 	$replaces = array();
388 409
 
@@ -390,11 +411,11 @@  discard block
 block discarded – undo
390 411
 	{
391 412
 		$quoted = preg_match('~\[(' . $myTag . ')=&quot;~', $message);
392 413
 		preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '&quot;(.*?)&quot;' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
414
+	} elseif ($hasEqualSign) {
415
+			preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
416
+	} else {
417
+			preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
393 418
 	}
394
-	elseif ($hasEqualSign)
395
-		preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
396
-	else
397
-		preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
398 419
 
399 420
 	foreach ($matches[0] as $k => $dummy)
400 421
 	{
@@ -407,49 +428,53 @@  discard block
 block discarded – undo
407 428
 		foreach ($protocols as $protocol)
408 429
 		{
409 430
 			$found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0;
410
-			if ($found)
411
-				break;
431
+			if ($found) {
432
+							break;
433
+			}
412 434
 		}
413 435
 
414 436
 		if (!$found && $protocols[0] == 'http')
415 437
 		{
416
-			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//')
417
-				$replace = $domain_url . $replace;
418
-			elseif (substr($replace, 0, 1) == '?')
419
-				$replace = $scripturl . $replace;
420
-			elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
438
+			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') {
439
+							$replace = $domain_url . $replace;
440
+			} elseif (substr($replace, 0, 1) == '?') {
441
+							$replace = $scripturl . $replace;
442
+			} elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
421 443
 			{
422 444
 				$replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1));
423 445
 				$this_tag = 'iurl';
424 446
 				$this_close = 'iurl';
447
+			} elseif (substr($replace, 0, 2) != '//') {
448
+							$replace = $protocols[0] . '://' . $replace;
425 449
 			}
426
-			elseif (substr($replace, 0, 2) != '//')
427
-				$replace = $protocols[0] . '://' . $replace;
428
-		}
429
-		elseif (!$found && $protocols[0] == 'ftp')
430
-			$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
431
-		elseif (!$found)
432
-			$replace = $protocols[0] . '://' . $replace;
433
-
434
-		if ($hasEqualSign && $embeddedUrl)
435
-			$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
436
-		elseif ($hasEqualSign)
437
-			$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
438
-		elseif ($embeddedUrl)
439
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
440
-		else
441
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
450
+		} elseif (!$found && $protocols[0] == 'ftp') {
451
+					$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
452
+		} elseif (!$found) {
453
+					$replace = $protocols[0] . '://' . $replace;
454
+		}
455
+
456
+		if ($hasEqualSign && $embeddedUrl) {
457
+					$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
458
+		} elseif ($hasEqualSign) {
459
+					$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
460
+		} elseif ($embeddedUrl) {
461
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
462
+		} else {
463
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
464
+		}
442 465
 	}
443 466
 
444 467
 	foreach ($replaces as $k => $v)
445 468
 	{
446
-		if ($k == $v)
447
-			unset($replaces[$k]);
469
+		if ($k == $v) {
470
+					unset($replaces[$k]);
471
+		}
448 472
 	}
449 473
 
450
-	if (!empty($replaces))
451
-		$message = strtr($message, $replaces);
452
-}
474
+	if (!empty($replaces)) {
475
+			$message = strtr($message, $replaces);
476
+	}
477
+	}
453 478
 
454 479
 /**
455 480
  * This function sends an email to the specified recipient(s).
@@ -493,8 +518,9 @@  discard block
 block discarded – undo
493 518
 	}
494 519
 
495 520
 	// Nothing left? Nothing else to do
496
-	if (empty($to_array))
497
-		return true;
521
+	if (empty($to_array)) {
522
+			return true;
523
+	}
498 524
 
499 525
 	// Once upon a time, Hotmail could not interpret non-ASCII mails.
500 526
 	// In honour of those days, it's still called the 'hotmail fix'.
@@ -511,15 +537,17 @@  discard block
 block discarded – undo
511 537
 		}
512 538
 
513 539
 		// Call this function recursively for the hotmail addresses.
514
-		if (!empty($hotmail_to))
515
-			$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
540
+		if (!empty($hotmail_to)) {
541
+					$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
542
+		}
516 543
 
517 544
 		// The remaining addresses no longer need the fix.
518 545
 		$hotmail_fix = false;
519 546
 
520 547
 		// No other addresses left? Return instantly.
521
-		if (empty($to_array))
522
-			return $mail_result;
548
+		if (empty($to_array)) {
549
+					return $mail_result;
550
+		}
523 551
 	}
524 552
 
525 553
 	// Get rid of entities.
@@ -544,13 +572,15 @@  discard block
 block discarded – undo
544 572
 	$headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break;
545 573
 	$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;
546 574
 
547
-	if ($message_id !== null && empty($modSettings['mail_no_message_id']))
548
-		$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
575
+	if ($message_id !== null && empty($modSettings['mail_no_message_id'])) {
576
+			$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
577
+	}
549 578
 	$headers .= 'X-Mailer: SMF' . $line_break;
550 579
 
551 580
 	// Pass this to the integration before we start modifying the output -- it'll make it easier later.
552
-	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true))
553
-		return false;
581
+	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) {
582
+			return false;
583
+	}
554 584
 
555 585
 	// Save the original message...
556 586
 	$orig_message = $message;
@@ -599,17 +629,19 @@  discard block
 block discarded – undo
599 629
 	}
600 630
 
601 631
 	// Are we using the mail queue, if so this is where we butt in...
602
-	if ($priority != 0)
603
-		return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
632
+	if ($priority != 0) {
633
+			return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
634
+	}
604 635
 
605 636
 	// If it's a priority mail, send it now - note though that this should NOT be used for sending many at once.
606 637
 	elseif (!empty($modSettings['mail_limit']))
607 638
 	{
608 639
 		list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
609
-		if (empty($mails_this_minute) || time() > $last_mail_time + 60)
610
-			$new_queue_stat = time() . '|' . 1;
611
-		else
612
-			$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
640
+		if (empty($mails_this_minute) || time() > $last_mail_time + 60) {
641
+					$new_queue_stat = time() . '|' . 1;
642
+		} else {
643
+					$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
644
+		}
613 645
 
614 646
 		updateSettings(array('mail_recent' => $new_queue_stat));
615 647
 	}
@@ -643,8 +675,7 @@  discard block
 block discarded – undo
643 675
 					log_error(sprintf($txt['mail_send_unable'], $to));
644 676
 					$mail_result = false;
645 677
 				}
646
-			}
647
-			catch(ErrorException $e)
678
+			} catch(ErrorException $e)
648 679
 			{
649 680
 				log_error($e->getMessage(), 'general', $e->getFile(), $e->getLine());
650 681
 				log_error(sprintf($txt['mail_send_unable'], $to));
@@ -654,12 +685,13 @@  discard block
 block discarded – undo
654 685
 
655 686
 			// Wait, wait, I'm still sending here!
656 687
 			@set_time_limit(300);
657
-			if (function_exists('apache_reset_timeout'))
658
-				@apache_reset_timeout();
688
+			if (function_exists('apache_reset_timeout')) {
689
+							@apache_reset_timeout();
690
+			}
659 691
 		}
692
+	} else {
693
+			$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
660 694
 	}
661
-	else
662
-		$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
663 695
 
664 696
 	// Everything go smoothly?
665 697
 	return $mail_result;
@@ -685,8 +717,9 @@  discard block
 block discarded – undo
685 717
 	static $cur_insert = array();
686 718
 	static $cur_insert_len = 0;
687 719
 
688
-	if ($cur_insert_len == 0)
689
-		$cur_insert = array();
720
+	if ($cur_insert_len == 0) {
721
+			$cur_insert = array();
722
+	}
690 723
 
691 724
 	// If we're flushing, make the final inserts - also if we're near the MySQL length limit!
692 725
 	if (($flush || $cur_insert_len > 800000) && !empty($cur_insert))
@@ -761,8 +794,9 @@  discard block
 block discarded – undo
761 794
 	}
762 795
 
763 796
 	// If they are using SSI there is a good chance obExit will never be called.  So lets be nice and flush it for them.
764
-	if (SMF === 'SSI' || SMF === 'BACKGROUND')
765
-		return AddMailQueue(true);
797
+	if (SMF === 'SSI' || SMF === 'BACKGROUND') {
798
+			return AddMailQueue(true);
799
+	}
766 800
 
767 801
 	return true;
768 802
 }
@@ -793,23 +827,26 @@  discard block
 block discarded – undo
793 827
 		'sent' => array()
794 828
 	);
795 829
 
796
-	if ($from === null)
797
-		$from = array(
830
+	if ($from === null) {
831
+			$from = array(
798 832
 			'id' => $user_info['id'],
799 833
 			'name' => $user_info['name'],
800 834
 			'username' => $user_info['username']
801 835
 		);
836
+	}
802 837
 
803 838
 	// This is the one that will go in their inbox.
804 839
 	$htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES);
805 840
 	preparsecode($htmlmessage);
806 841
 	$htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => ''));
807
-	if ($smcFunc['strlen']($htmlsubject) > 100)
808
-		$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
842
+	if ($smcFunc['strlen']($htmlsubject) > 100) {
843
+			$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
844
+	}
809 845
 
810 846
 	// Make sure is an array
811
-	if (!is_array($recipients))
812
-		$recipients = array($recipients);
847
+	if (!is_array($recipients)) {
848
+			$recipients = array($recipients);
849
+	}
813 850
 
814 851
 	// Integrated PMs
815 852
 	call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message));
@@ -837,21 +874,23 @@  discard block
 block discarded – undo
837 874
 				'usernames' => array_keys($usernames),
838 875
 			)
839 876
 		);
840
-		while ($row = $smcFunc['db_fetch_assoc']($request))
841
-			if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
877
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
878
+					if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
842 879
 				$usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member'];
880
+		}
843 881
 		$smcFunc['db_free_result']($request);
844 882
 
845 883
 		// Replace the usernames with IDs. Drop usernames that couldn't be found.
846
-		foreach ($recipients as $rec_type => $rec)
847
-			foreach ($rec as $id => $member)
884
+		foreach ($recipients as $rec_type => $rec) {
885
+					foreach ($rec as $id => $member)
848 886
 			{
849 887
 				if (is_numeric($recipients[$rec_type][$id]))
850 888
 					continue;
889
+		}
851 890
 
852
-				if (!empty($usernames[$member]))
853
-					$recipients[$rec_type][$id] = $usernames[$member];
854
-				else
891
+				if (!empty($usernames[$member])) {
892
+									$recipients[$rec_type][$id] = $usernames[$member];
893
+				} else
855 894
 				{
856 895
 					$log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]);
857 896
 					unset($recipients[$rec_type][$id]);
@@ -889,8 +928,9 @@  discard block
 block discarded – undo
889 928
 		$delete = false;
890 929
 		foreach ($criteria as $criterium)
891 930
 		{
892
-			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false))
893
-				$delete = true;
931
+			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) {
932
+							$delete = true;
933
+			}
894 934
 			// If we're adding and one criteria don't match then we stop!
895 935
 			elseif (!$row['is_or'])
896 936
 			{
@@ -898,8 +938,9 @@  discard block
 block discarded – undo
898 938
 				break;
899 939
 			}
900 940
 		}
901
-		if ($delete)
902
-			$deletes[$row['id_member']] = 1;
941
+		if ($delete) {
942
+					$deletes[$row['id_member']] = 1;
943
+		}
903 944
 	}
904 945
 	$smcFunc['db_free_result']($request);
905 946
 
@@ -914,8 +955,9 @@  discard block
 block discarded – undo
914 955
 			array(
915 956
 			)
916 957
 		);
917
-		while ($row = $smcFunc['db_fetch_assoc']($request))
918
-			$message_limit_cache[$row['id_group']] = $row['max_messages'];
958
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
959
+					$message_limit_cache[$row['id_group']] = $row['max_messages'];
960
+		}
919 961
 		$smcFunc['db_free_result']($request);
920 962
 	}
921 963
 
@@ -923,8 +965,9 @@  discard block
 block discarded – undo
923 965
 	require_once($sourcedir . '/Subs-Members.php');
924 966
 	$pmReadGroups = groupsAllowedTo('pm_read');
925 967
 
926
-	if (empty($modSettings['permission_enable_deny']))
927
-		$pmReadGroups['denied'] = array();
968
+	if (empty($modSettings['permission_enable_deny'])) {
969
+			$pmReadGroups['denied'] = array();
970
+	}
928 971
 
929 972
 	// Load their alert preferences
930 973
 	require_once($sourcedir . '/Subs-Notify.php');
@@ -956,8 +999,9 @@  discard block
 block discarded – undo
956 999
 	while ($row = $smcFunc['db_fetch_assoc']($request))
957 1000
 	{
958 1001
 		// Don't do anything for members to be deleted!
959
-		if (isset($deletes[$row['id_member']]))
960
-			continue;
1002
+		if (isset($deletes[$row['id_member']])) {
1003
+					continue;
1004
+		}
961 1005
 
962 1006
 		// Load the preferences for this member (if any)
963 1007
 		$prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array();
@@ -978,8 +1022,9 @@  discard block
 block discarded – undo
978 1022
 		{
979 1023
 			foreach ($groups as $id)
980 1024
 			{
981
-				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id])
982
-					$message_limit = $message_limit_cache[$id];
1025
+				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) {
1026
+									$message_limit = $message_limit_cache[$id];
1027
+				}
983 1028
 			}
984 1029
 
985 1030
 			if ($message_limit > 0 && $message_limit <= $row['instant_messages'])
@@ -1027,8 +1072,9 @@  discard block
 block discarded – undo
1027 1072
 	$smcFunc['db_free_result']($request);
1028 1073
 
1029 1074
 	// Only 'send' the message if there are any recipients left.
1030
-	if (empty($all_to))
1031
-		return $log;
1075
+	if (empty($all_to)) {
1076
+			return $log;
1077
+	}
1032 1078
 
1033 1079
 	// Insert the message itself and then grab the last insert id.
1034 1080
 	$id_pm = $smcFunc['db_insert']('',
@@ -1049,8 +1095,8 @@  discard block
 block discarded – undo
1049 1095
 	if (!empty($id_pm))
1050 1096
 	{
1051 1097
 		// If this is new we need to set it part of it's own conversation.
1052
-		if (empty($pm_head))
1053
-			$smcFunc['db_query']('', '
1098
+		if (empty($pm_head)) {
1099
+					$smcFunc['db_query']('', '
1054 1100
 				UPDATE {db_prefix}personal_messages
1055 1101
 				SET id_pm_head = {int:id_pm_head}
1056 1102
 				WHERE id_pm = {int:id_pm_head}',
@@ -1058,6 +1104,7 @@  discard block
 block discarded – undo
1058 1104
 					'id_pm_head' => $id_pm,
1059 1105
 				)
1060 1106
 			);
1107
+		}
1061 1108
 
1062 1109
 		// Some people think manually deleting personal_messages is fun... it's not. We protect against it though :)
1063 1110
 		$smcFunc['db_query']('', '
@@ -1073,8 +1120,9 @@  discard block
 block discarded – undo
1073 1120
 		foreach ($all_to as $to)
1074 1121
 		{
1075 1122
 			$insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1);
1076
-			if (!in_array($to, $recipients['bcc']))
1077
-				$to_list[] = $to;
1123
+			if (!in_array($to, $recipients['bcc'])) {
1124
+							$to_list[] = $to;
1125
+			}
1078 1126
 		}
1079 1127
 
1080 1128
 		$smcFunc['db_insert']('insert',
@@ -1092,9 +1140,9 @@  discard block
 block discarded – undo
1092 1140
 	{
1093 1141
 		censorText($message);
1094 1142
 		$message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '&#91;' => '[', '&#93;' => ']')))));
1143
+	} else {
1144
+			$message = '';
1095 1145
 	}
1096
-	else
1097
-		$message = '';
1098 1146
 
1099 1147
 	$to_names = array();
1100 1148
 	if (count($to_list) > 1)
@@ -1107,8 +1155,9 @@  discard block
 block discarded – undo
1107 1155
 				'to_members' => $to_list,
1108 1156
 			)
1109 1157
 		);
1110
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1111
-			$to_names[] = un_htmlspecialchars($row['real_name']);
1158
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1159
+					$to_names[] = un_htmlspecialchars($row['real_name']);
1160
+		}
1112 1161
 		$smcFunc['db_free_result']($request);
1113 1162
 	}
1114 1163
 	$replacements = array(
@@ -1136,11 +1185,13 @@  discard block
 block discarded – undo
1136 1185
 	loadLanguage('index+PersonalMessage');
1137 1186
 
1138 1187
 	// Add one to their unread and read message counts.
1139
-	foreach ($all_to as $k => $id)
1140
-		if (isset($deletes[$id]))
1188
+	foreach ($all_to as $k => $id) {
1189
+			if (isset($deletes[$id]))
1141 1190
 			unset($all_to[$k]);
1142
-	if (!empty($all_to))
1143
-		updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1191
+	}
1192
+	if (!empty($all_to)) {
1193
+			updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1194
+	}
1144 1195
 
1145 1196
 	return $log;
1146 1197
 }
@@ -1170,15 +1221,17 @@  discard block
 block discarded – undo
1170 1221
 		// Let's, for now, assume there are only &#021;'ish characters.
1171 1222
 		$simple = true;
1172 1223
 
1173
-		foreach ($matches[1] as $entity)
1174
-			if ($entity > 128)
1224
+		foreach ($matches[1] as $entity) {
1225
+					if ($entity > 128)
1175 1226
 				$simple = false;
1227
+		}
1176 1228
 		unset($matches);
1177 1229
 
1178
-		if ($simple)
1179
-			$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1230
+		if ($simple) {
1231
+					$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1180 1232
 			{
1181 1233
 				return chr("$m[1]");
1234
+		}
1182 1235
 			}, $string);
1183 1236
 		else
1184 1237
 		{
@@ -1186,8 +1239,9 @@  discard block
 block discarded – undo
1186 1239
 			if (!$context['utf8'] && function_exists('iconv'))
1187 1240
 			{
1188 1241
 				$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1189
-				if ($newstring)
1190
-					$string = $newstring;
1242
+				if ($newstring) {
1243
+									$string = $newstring;
1244
+				}
1191 1245
 			}
1192 1246
 
1193 1247
 			$string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string);
@@ -1203,23 +1257,25 @@  discard block
 block discarded – undo
1203 1257
 		if (!$context['utf8'] && function_exists('iconv'))
1204 1258
 		{
1205 1259
 			$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1206
-			if ($newstring)
1207
-				$string = $newstring;
1260
+			if ($newstring) {
1261
+							$string = $newstring;
1262
+			}
1208 1263
 		}
1209 1264
 
1210 1265
 		$entityConvert = function($m)
1211 1266
 		{
1212 1267
 			$c = $m[1];
1213
-			if (strlen($c) === 1 && ord($c[0]) <= 0x7F)
1214
-				return $c;
1215
-			elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF)
1216
-				return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1217
-			elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF)
1218
-				return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1219
-			elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7)
1220
-				return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1221
-			else
1222
-				return "";
1268
+			if (strlen($c) === 1 && ord($c[0]) <= 0x7F) {
1269
+							return $c;
1270
+			} elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) {
1271
+							return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1272
+			} elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) {
1273
+							return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1274
+			} elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) {
1275
+							return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1276
+			} else {
1277
+							return "";
1278
+			}
1223 1279
 		};
1224 1280
 
1225 1281
 		// Convert all 'special' characters to HTML entities.
@@ -1233,19 +1289,20 @@  discard block
 block discarded – undo
1233 1289
 		$string = base64_encode($string);
1234 1290
 
1235 1291
 		// Show the characterset and the transfer-encoding for header strings.
1236
-		if ($with_charset)
1237
-			$string = '=?' . $charset . '?B?' . $string . '?=';
1292
+		if ($with_charset) {
1293
+					$string = '=?' . $charset . '?B?' . $string . '?=';
1294
+		}
1238 1295
 
1239 1296
 		// Break it up in lines (mail body).
1240
-		else
1241
-			$string = chunk_split($string, 76, $line_break);
1297
+		else {
1298
+					$string = chunk_split($string, 76, $line_break);
1299
+		}
1242 1300
 
1243 1301
 		return array($charset, $string, 'base64');
1302
+	} else {
1303
+			return array($charset, $string, '7bit');
1304
+	}
1244 1305
 	}
1245
-
1246
-	else
1247
-		return array($charset, $string, '7bit');
1248
-}
1249 1306
 
1250 1307
 /**
1251 1308
  * Sends mail, like mail() but over SMTP.
@@ -1269,8 +1326,9 @@  discard block
 block discarded – undo
1269 1326
 	if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
1270 1327
 	{
1271 1328
 		$socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
1272
-		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.'))
1273
-			$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1329
+		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) {
1330
+					$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1331
+		}
1274 1332
 
1275 1333
 		if ($socket)
1276 1334
 		{
@@ -1291,8 +1349,9 @@  discard block
 block discarded – undo
1291 1349
 		// Maybe we can still save this?  The port might be wrong.
1292 1350
 		if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
1293 1351
 		{
1294
-			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
1295
-				log_error($txt['smtp_port_ssl']);
1352
+			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
1353
+							log_error($txt['smtp_port_ssl']);
1354
+			}
1296 1355
 		}
1297 1356
 
1298 1357
 		// Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
@@ -1304,20 +1363,23 @@  discard block
 block discarded – undo
1304 1363
 	}
1305 1364
 
1306 1365
 	// Wait for a response of 220, without "-" continuer.
1307
-	if (!server_parse(null, $socket, '220'))
1308
-		return false;
1366
+	if (!server_parse(null, $socket, '220')) {
1367
+			return false;
1368
+	}
1309 1369
 
1310 1370
 	// Try and determine the servers name, fall back to the mail servers if not found
1311 1371
 	$helo = false;
1312
-	if (function_exists('gethostname') && gethostname() !== false)
1313
-		$helo = gethostname();
1314
-	elseif (function_exists('php_uname'))
1315
-		$helo = php_uname('n');
1316
-	elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME']))
1317
-		$helo = $_SERVER['SERVER_NAME'];
1372
+	if (function_exists('gethostname') && gethostname() !== false) {
1373
+			$helo = gethostname();
1374
+	} elseif (function_exists('php_uname')) {
1375
+			$helo = php_uname('n');
1376
+	} elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) {
1377
+			$helo = $_SERVER['SERVER_NAME'];
1378
+	}
1318 1379
 
1319
-	if (empty($helo))
1320
-		$helo = $modSettings['smtp_host'];
1380
+	if (empty($helo)) {
1381
+			$helo = $modSettings['smtp_host'];
1382
+	}
1321 1383
 
1322 1384
 	// SMTP = 1, SMTP - STARTTLS = 2
1323 1385
 	if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
@@ -1329,33 +1391,39 @@  discard block
 block discarded – undo
1329 1391
 			if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response))
1330 1392
 			{
1331 1393
 				// Send STARTTLS to enable encryption
1332
-				if (!server_parse('STARTTLS', $socket, '220'))
1333
-					return false;
1394
+				if (!server_parse('STARTTLS', $socket, '220')) {
1395
+									return false;
1396
+				}
1334 1397
 				// Enable the encryption
1335
-				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
1336
-					return false;
1398
+				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
1399
+									return false;
1400
+				}
1337 1401
 				// Send the EHLO command again
1338
-				if (!server_parse('EHLO ' . $helo, $socket, null) == '250')
1339
-					return false;
1402
+				if (!server_parse('EHLO ' . $helo, $socket, null) == '250') {
1403
+									return false;
1404
+				}
1340 1405
 			}
1341 1406
 
1342
-			if (!server_parse('AUTH LOGIN', $socket, '334'))
1343
-				return false;
1407
+			if (!server_parse('AUTH LOGIN', $socket, '334')) {
1408
+							return false;
1409
+			}
1344 1410
 			// Send the username and password, encoded.
1345
-			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
1346
-				return false;
1411
+			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
1412
+							return false;
1413
+			}
1347 1414
 			// The password is already encoded ;)
1348
-			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
1349
-				return false;
1415
+			if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
1416
+							return false;
1417
+			}
1418
+		} elseif (!server_parse('HELO ' . $helo, $socket, '250')) {
1419
+					return false;
1350 1420
 		}
1351
-		elseif (!server_parse('HELO ' . $helo, $socket, '250'))
1352
-			return false;
1353
-	}
1354
-	else
1421
+	} else
1355 1422
 	{
1356 1423
 		// Just say "helo".
1357
-		if (!server_parse('HELO ' . $helo, $socket, '250'))
1358
-			return false;
1424
+		if (!server_parse('HELO ' . $helo, $socket, '250')) {
1425
+					return false;
1426
+		}
1359 1427
 	}
1360 1428
 
1361 1429
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -1368,31 +1436,38 @@  discard block
 block discarded – undo
1368 1436
 		// Reset the connection to send another email.
1369 1437
 		if ($i != 0)
1370 1438
 		{
1371
-			if (!server_parse('RSET', $socket, '250'))
1372
-				return false;
1439
+			if (!server_parse('RSET', $socket, '250')) {
1440
+							return false;
1441
+			}
1373 1442
 		}
1374 1443
 
1375 1444
 		// From, to, and then start the data...
1376
-		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
1377
-			return false;
1378
-		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
1379
-			return false;
1380
-		if (!server_parse('DATA', $socket, '354'))
1381
-			return false;
1445
+		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
1446
+					return false;
1447
+		}
1448
+		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
1449
+					return false;
1450
+		}
1451
+		if (!server_parse('DATA', $socket, '354')) {
1452
+					return false;
1453
+		}
1382 1454
 		fputs($socket, 'Subject: ' . $subject . "\r\n");
1383
-		if (strlen($mail_to) > 0)
1384
-			fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1455
+		if (strlen($mail_to) > 0) {
1456
+					fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1457
+		}
1385 1458
 		fputs($socket, $headers . "\r\n\r\n");
1386 1459
 		fputs($socket, $message . "\r\n");
1387 1460
 
1388 1461
 		// Send a ., or in other words "end of data".
1389
-		if (!server_parse('.', $socket, '250'))
1390
-			return false;
1462
+		if (!server_parse('.', $socket, '250')) {
1463
+					return false;
1464
+		}
1391 1465
 
1392 1466
 		// Almost done, almost done... don't stop me just yet!
1393 1467
 		@set_time_limit(300);
1394
-		if (function_exists('apache_reset_timeout'))
1395
-			@apache_reset_timeout();
1468
+		if (function_exists('apache_reset_timeout')) {
1469
+					@apache_reset_timeout();
1470
+		}
1396 1471
 	}
1397 1472
 	fputs($socket, 'QUIT' . "\r\n");
1398 1473
 	fclose($socket);
@@ -1416,8 +1491,9 @@  discard block
 block discarded – undo
1416 1491
 {
1417 1492
 	global $txt;
1418 1493
 
1419
-	if ($message !== null)
1420
-		fputs($socket, $message . "\r\n");
1494
+	if ($message !== null) {
1495
+			fputs($socket, $message . "\r\n");
1496
+	}
1421 1497
 
1422 1498
 	// No response yet.
1423 1499
 	$server_response = '';
@@ -1433,8 +1509,9 @@  discard block
 block discarded – undo
1433 1509
 		$response .= $server_response;
1434 1510
 	}
1435 1511
 
1436
-	if ($code === null)
1437
-		return substr($server_response, 0, 3);
1512
+	if ($code === null) {
1513
+			return substr($server_response, 0, 3);
1514
+	}
1438 1515
 
1439 1516
 	if (substr($server_response, 0, 3) != $code)
1440 1517
 	{
@@ -1464,8 +1541,9 @@  discard block
 block discarded – undo
1464 1541
 	// Create a pspell or enchant dictionary resource
1465 1542
 	$dict = spell_init();
1466 1543
 
1467
-	if (!isset($_POST['spellstring']) || !$dict)
1468
-		die;
1544
+	if (!isset($_POST['spellstring']) || !$dict) {
1545
+			die;
1546
+	}
1469 1547
 
1470 1548
 	// Construct a bit of Javascript code.
1471 1549
 	$context['spell_js'] = '
@@ -1483,8 +1561,9 @@  discard block
 block discarded – undo
1483 1561
 		$check_word = explode('|', $alphas[$i]);
1484 1562
 
1485 1563
 		// If the word is a known word, or spelled right...
1486
-		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2]))
1487
-			continue;
1564
+		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) {
1565
+					continue;
1566
+		}
1488 1567
 
1489 1568
 		// Find the word, and move up the "last occurrence" to here.
1490 1569
 		$found_words = true;
@@ -1498,20 +1577,23 @@  discard block
 block discarded – undo
1498 1577
 		if (!empty($suggestions))
1499 1578
 		{
1500 1579
 			// But first check they aren't going to be censored - no naughty words!
1501
-			foreach ($suggestions as $k => $word)
1502
-				if ($suggestions[$k] != censorText($word))
1580
+			foreach ($suggestions as $k => $word) {
1581
+							if ($suggestions[$k] != censorText($word))
1503 1582
 					unset($suggestions[$k]);
1583
+			}
1504 1584
 
1505
-			if (!empty($suggestions))
1506
-				$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1585
+			if (!empty($suggestions)) {
1586
+							$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1587
+			}
1507 1588
 		}
1508 1589
 
1509 1590
 		$context['spell_js'] .= ']),';
1510 1591
 	}
1511 1592
 
1512 1593
 	// If words were found, take off the last comma.
1513
-	if ($found_words)
1514
-		$context['spell_js'] = substr($context['spell_js'], 0, -1);
1594
+	if ($found_words) {
1595
+			$context['spell_js'] = substr($context['spell_js'], 0, -1);
1596
+	}
1515 1597
 
1516 1598
 	$context['spell_js'] .= '
1517 1599
 		);';
@@ -1546,11 +1628,13 @@  discard block
 block discarded – undo
1546 1628
 	global $user_info, $smcFunc;
1547 1629
 
1548 1630
 	// Can't do it if there's no topics.
1549
-	if (empty($topics))
1550
-		return;
1631
+	if (empty($topics)) {
1632
+			return;
1633
+	}
1551 1634
 	// It must be an array - it must!
1552
-	if (!is_array($topics))
1553
-		$topics = array($topics);
1635
+	if (!is_array($topics)) {
1636
+			$topics = array($topics);
1637
+	}
1554 1638
 
1555 1639
 	// Get the subject and body...
1556 1640
 	$result = $smcFunc['db_query']('', '
@@ -1598,14 +1682,15 @@  discard block
 block discarded – undo
1598 1682
 	}
1599 1683
 	$smcFunc['db_free_result']($result);
1600 1684
 
1601
-	if (!empty($task_rows))
1602
-		$smcFunc['db_insert']('',
1685
+	if (!empty($task_rows)) {
1686
+			$smcFunc['db_insert']('',
1603 1687
 			'{db_prefix}background_tasks',
1604 1688
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1605 1689
 			$task_rows,
1606 1690
 			array('id_task')
1607 1691
 		);
1608
-}
1692
+	}
1693
+	}
1609 1694
 
1610 1695
 /**
1611 1696
  * Create a post, either as new topic (id_topic = 0) or in an existing one.
@@ -1643,9 +1728,9 @@  discard block
 block discarded – undo
1643 1728
 	$msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true;
1644 1729
 
1645 1730
 	// We need to know if the topic is approved. If we're told that's great - if not find out.
1646
-	if (!$modSettings['postmod_active'])
1647
-		$topicOptions['is_approved'] = true;
1648
-	elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1731
+	if (!$modSettings['postmod_active']) {
1732
+			$topicOptions['is_approved'] = true;
1733
+	} elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1649 1734
 	{
1650 1735
 		$request = $smcFunc['db_query']('', '
1651 1736
 			SELECT approved
@@ -1668,8 +1753,7 @@  discard block
 block discarded – undo
1668 1753
 			$posterOptions['id'] = 0;
1669 1754
 			$posterOptions['name'] = $txt['guest_title'];
1670 1755
 			$posterOptions['email'] = '';
1671
-		}
1672
-		elseif ($posterOptions['id'] != $user_info['id'])
1756
+		} elseif ($posterOptions['id'] != $user_info['id'])
1673 1757
 		{
1674 1758
 			$request = $smcFunc['db_query']('', '
1675 1759
 				SELECT member_name, email_address
@@ -1687,12 +1771,11 @@  discard block
 block discarded – undo
1687 1771
 				$posterOptions['id'] = 0;
1688 1772
 				$posterOptions['name'] = $txt['guest_title'];
1689 1773
 				$posterOptions['email'] = '';
1774
+			} else {
1775
+							list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1690 1776
 			}
1691
-			else
1692
-				list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1693 1777
 			$smcFunc['db_free_result']($request);
1694
-		}
1695
-		else
1778
+		} else
1696 1779
 		{
1697 1780
 			$posterOptions['name'] = $user_info['name'];
1698 1781
 			$posterOptions['email'] = $user_info['email'];
@@ -1702,8 +1785,9 @@  discard block
 block discarded – undo
1702 1785
 	if (!empty($modSettings['enable_mentions']))
1703 1786
 	{
1704 1787
 		$msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']);
1705
-		if (!empty($msgOptions['mentioned_members']))
1706
-			$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1788
+		if (!empty($msgOptions['mentioned_members'])) {
1789
+					$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1790
+		}
1707 1791
 	}
1708 1792
 
1709 1793
 	// It's do or die time: forget any user aborts!
@@ -1736,12 +1820,13 @@  discard block
 block discarded – undo
1736 1820
 	);
1737 1821
 
1738 1822
 	// Something went wrong creating the message...
1739
-	if (empty($msgOptions['id']))
1740
-		return false;
1823
+	if (empty($msgOptions['id'])) {
1824
+			return false;
1825
+	}
1741 1826
 
1742 1827
 	// Fix the attachments.
1743
-	if (!empty($msgOptions['attachments']))
1744
-		$smcFunc['db_query']('', '
1828
+	if (!empty($msgOptions['attachments'])) {
1829
+			$smcFunc['db_query']('', '
1745 1830
 			UPDATE {db_prefix}attachments
1746 1831
 			SET id_msg = {int:id_msg}
1747 1832
 			WHERE id_attach IN ({array_int:attachment_list})',
@@ -1750,6 +1835,7 @@  discard block
 block discarded – undo
1750 1835
 				'id_msg' => $msgOptions['id'],
1751 1836
 			)
1752 1837
 		);
1838
+	}
1753 1839
 
1754 1840
 	// What if we want to export new posts out to a CMS?
1755 1841
 	call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters));
@@ -1826,20 +1912,23 @@  discard block
 block discarded – undo
1826 1912
 			'id_topic' => $topicOptions['id'],
1827 1913
 			'counter_increment' => 1,
1828 1914
 		);
1829
-		if ($msgOptions['approved'])
1830
-			$topics_columns = array(
1915
+		if ($msgOptions['approved']) {
1916
+					$topics_columns = array(
1831 1917
 				'id_member_updated = {int:poster_id}',
1832 1918
 				'id_last_msg = {int:id_msg}',
1833 1919
 				'num_replies = num_replies + {int:counter_increment}',
1834 1920
 			);
1835
-		else
1836
-			$topics_columns = array(
1921
+		} else {
1922
+					$topics_columns = array(
1837 1923
 				'unapproved_posts = unapproved_posts + {int:counter_increment}',
1838 1924
 			);
1839
-		if ($topicOptions['lock_mode'] !== null)
1840
-			$topics_columns[] = 'locked = {int:locked}';
1841
-		if ($topicOptions['sticky_mode'] !== null)
1842
-			$topics_columns[] = 'is_sticky = {int:is_sticky}';
1925
+		}
1926
+		if ($topicOptions['lock_mode'] !== null) {
1927
+					$topics_columns[] = 'locked = {int:locked}';
1928
+		}
1929
+		if ($topicOptions['sticky_mode'] !== null) {
1930
+					$topics_columns[] = 'is_sticky = {int:is_sticky}';
1931
+		}
1843 1932
 
1844 1933
 		call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions));
1845 1934
 
@@ -1868,8 +1957,8 @@  discard block
 block discarded – undo
1868 1957
 	);
1869 1958
 
1870 1959
 	// Increase the number of posts and topics on the board.
1871
-	if ($msgOptions['approved'])
1872
-		$smcFunc['db_query']('', '
1960
+	if ($msgOptions['approved']) {
1961
+			$smcFunc['db_query']('', '
1873 1962
 			UPDATE {db_prefix}boards
1874 1963
 			SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
1875 1964
 			WHERE id_board = {int:id_board}',
@@ -1877,7 +1966,7 @@  discard block
 block discarded – undo
1877 1966
 				'id_board' => $topicOptions['board'],
1878 1967
 			)
1879 1968
 		);
1880
-	else
1969
+	} else
1881 1970
 	{
1882 1971
 		$smcFunc['db_query']('', '
1883 1972
 			UPDATE {db_prefix}boards
@@ -1947,8 +2036,8 @@  discard block
 block discarded – undo
1947 2036
 		}
1948 2037
 	}
1949 2038
 
1950
-	if ($msgOptions['approved'] && empty($topicOptions['is_approved']))
1951
-		$smcFunc['db_insert']('',
2039
+	if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) {
2040
+			$smcFunc['db_insert']('',
1952 2041
 			'{db_prefix}background_tasks',
1953 2042
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1954 2043
 			array(
@@ -1960,19 +2049,22 @@  discard block
 block discarded – undo
1960 2049
 			),
1961 2050
 			array('id_task')
1962 2051
 		);
2052
+	}
1963 2053
 
1964 2054
 	// If there's a custom search index, it may need updating...
1965 2055
 	require_once($sourcedir . '/Search.php');
1966 2056
 	$searchAPI = findSearchAPI();
1967
-	if (is_callable(array($searchAPI, 'postCreated')))
1968
-		$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2057
+	if (is_callable(array($searchAPI, 'postCreated'))) {
2058
+			$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2059
+	}
1969 2060
 
1970 2061
 	// Increase the post counter for the user that created the post.
1971 2062
 	if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
1972 2063
 	{
1973 2064
 		// Are you the one that happened to create this post?
1974
-		if ($user_info['id'] == $posterOptions['id'])
1975
-			$user_info['posts']++;
2065
+		if ($user_info['id'] == $posterOptions['id']) {
2066
+					$user_info['posts']++;
2067
+		}
1976 2068
 		updateMemberData($posterOptions['id'], array('posts' => '+'));
1977 2069
 	}
1978 2070
 
@@ -1980,19 +2072,21 @@  discard block
 block discarded – undo
1980 2072
 	$_SESSION['last_read_topic'] = 0;
1981 2073
 
1982 2074
 	// Better safe than sorry.
1983
-	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
1984
-		$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2075
+	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
2076
+			$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2077
+	}
1985 2078
 
1986 2079
 	// Update all the stats so everyone knows about this new topic and message.
1987 2080
 	updateStats('message', true, $msgOptions['id']);
1988 2081
 
1989 2082
 	// Update the last message on the board assuming it's approved AND the topic is.
1990
-	if ($msgOptions['approved'])
1991
-		updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2083
+	if ($msgOptions['approved']) {
2084
+			updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2085
+	}
1992 2086
 
1993 2087
 	// Queue createPost background notification
1994
-	if ($msgOptions['send_notifications'] && $msgOptions['approved'])
1995
-		$smcFunc['db_insert']('',
2088
+	if ($msgOptions['send_notifications'] && $msgOptions['approved']) {
2089
+			$smcFunc['db_insert']('',
1996 2090
 			'{db_prefix}background_tasks',
1997 2091
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1998 2092
 			array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
@@ -2003,6 +2097,7 @@  discard block
 block discarded – undo
2003 2097
 			)), 0),
2004 2098
 			array('id_task')
2005 2099
 		);
2100
+	}
2006 2101
 
2007 2102
 	// Alright, done now... we can abort now, I guess... at least this much is done.
2008 2103
 	ignore_user_abort($previous_ignore_user_abort);
@@ -2029,14 +2124,18 @@  discard block
 block discarded – undo
2029 2124
 
2030 2125
 	// This is longer than it has to be, but makes it so we only set/change what we have to.
2031 2126
 	$messages_columns = array();
2032
-	if (isset($posterOptions['name']))
2033
-		$messages_columns['poster_name'] = $posterOptions['name'];
2034
-	if (isset($posterOptions['email']))
2035
-		$messages_columns['poster_email'] = $posterOptions['email'];
2036
-	if (isset($msgOptions['icon']))
2037
-		$messages_columns['icon'] = $msgOptions['icon'];
2038
-	if (isset($msgOptions['subject']))
2039
-		$messages_columns['subject'] = $msgOptions['subject'];
2127
+	if (isset($posterOptions['name'])) {
2128
+			$messages_columns['poster_name'] = $posterOptions['name'];
2129
+	}
2130
+	if (isset($posterOptions['email'])) {
2131
+			$messages_columns['poster_email'] = $posterOptions['email'];
2132
+	}
2133
+	if (isset($msgOptions['icon'])) {
2134
+			$messages_columns['icon'] = $msgOptions['icon'];
2135
+	}
2136
+	if (isset($msgOptions['subject'])) {
2137
+			$messages_columns['subject'] = $msgOptions['subject'];
2138
+	}
2040 2139
 	if (isset($msgOptions['body']))
2041 2140
 	{
2042 2141
 		$messages_columns['body'] = $msgOptions['body'];
@@ -2063,8 +2162,9 @@  discard block
 block discarded – undo
2063 2162
 		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
2064 2163
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
2065 2164
 	}
2066
-	if (isset($msgOptions['smileys_enabled']))
2067
-		$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2165
+	if (isset($msgOptions['smileys_enabled'])) {
2166
+			$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2167
+	}
2068 2168
 
2069 2169
 	// Which columns need to be ints?
2070 2170
 	$messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
@@ -2082,23 +2182,27 @@  discard block
 block discarded – undo
2082 2182
 		{
2083 2183
 			preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match);
2084 2184
 
2085
-			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2]))
2086
-				foreach ($match[1] as $i => $oldID)
2185
+			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) {
2186
+							foreach ($match[1] as $i => $oldID)
2087 2187
 					$oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]);
2188
+			}
2088 2189
 
2089
-			if (empty($modSettings['search_custom_index_config']))
2090
-				unset($msgOptions['old_body']);
2190
+			if (empty($modSettings['search_custom_index_config'])) {
2191
+							unset($msgOptions['old_body']);
2192
+			}
2091 2193
 		}
2092 2194
 
2093 2195
 		$mentions = Mentions::getMentionedMembers($msgOptions['body']);
2094 2196
 		$messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions);
2095 2197
 
2096 2198
 		// Remove the poster.
2097
-		if (isset($mentions[$user_info['id']]))
2098
-			unset($mentions[$user_info['id']]);
2199
+		if (isset($mentions[$user_info['id']])) {
2200
+					unset($mentions[$user_info['id']]);
2201
+		}
2099 2202
 
2100
-		if (isset($oldmentions[$user_info['id']]))
2101
-			unset($oldmentions[$user_info['id']]);
2203
+		if (isset($oldmentions[$user_info['id']])) {
2204
+					unset($oldmentions[$user_info['id']]);
2205
+		}
2102 2206
 
2103 2207
 		if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions))
2104 2208
 		{
@@ -2128,8 +2232,9 @@  discard block
 block discarded – undo
2128 2232
 	}
2129 2233
 
2130 2234
 	// Nothing to do?
2131
-	if (empty($messages_columns))
2132
-		return true;
2235
+	if (empty($messages_columns)) {
2236
+			return true;
2237
+	}
2133 2238
 
2134 2239
 	// Change the post.
2135 2240
 	$smcFunc['db_query']('', '
@@ -2190,8 +2295,9 @@  discard block
 block discarded – undo
2190 2295
 	// If there's a custom search index, it needs to be modified...
2191 2296
 	require_once($sourcedir . '/Search.php');
2192 2297
 	$searchAPI = findSearchAPI();
2193
-	if (is_callable(array($searchAPI, 'postModified')))
2194
-		$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2298
+	if (is_callable(array($searchAPI, 'postModified'))) {
2299
+			$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2300
+	}
2195 2301
 
2196 2302
 	if (isset($msgOptions['subject']))
2197 2303
 	{
@@ -2205,14 +2311,16 @@  discard block
 block discarded – undo
2205 2311
 				'id_first_msg' => $msgOptions['id'],
2206 2312
 			)
2207 2313
 		);
2208
-		if ($smcFunc['db_num_rows']($request) == 1)
2209
-			updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2314
+		if ($smcFunc['db_num_rows']($request) == 1) {
2315
+					updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2316
+		}
2210 2317
 		$smcFunc['db_free_result']($request);
2211 2318
 	}
2212 2319
 
2213 2320
 	// Finally, if we are setting the approved state we need to do much more work :(
2214
-	if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
2215
-		approvePosts($msgOptions['id'], $msgOptions['approved']);
2321
+	if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
2322
+			approvePosts($msgOptions['id'], $msgOptions['approved']);
2323
+	}
2216 2324
 
2217 2325
 	return true;
2218 2326
 }
@@ -2229,11 +2337,13 @@  discard block
 block discarded – undo
2229 2337
 {
2230 2338
 	global $smcFunc;
2231 2339
 
2232
-	if (!is_array($msgs))
2233
-		$msgs = array($msgs);
2340
+	if (!is_array($msgs)) {
2341
+			$msgs = array($msgs);
2342
+	}
2234 2343
 
2235
-	if (empty($msgs))
2236
-		return false;
2344
+	if (empty($msgs)) {
2345
+			return false;
2346
+	}
2237 2347
 
2238 2348
 	// May as well start at the beginning, working out *what* we need to change.
2239 2349
 	$request = $smcFunc['db_query']('', '
@@ -2265,20 +2375,22 @@  discard block
 block discarded – undo
2265 2375
 		$topics[] = $row['id_topic'];
2266 2376
 
2267 2377
 		// Ensure our change array exists already.
2268
-		if (!isset($topic_changes[$row['id_topic']]))
2269
-			$topic_changes[$row['id_topic']] = array(
2378
+		if (!isset($topic_changes[$row['id_topic']])) {
2379
+					$topic_changes[$row['id_topic']] = array(
2270 2380
 				'id_last_msg' => $row['id_last_msg'],
2271 2381
 				'approved' => $row['topic_approved'],
2272 2382
 				'replies' => 0,
2273 2383
 				'unapproved_posts' => 0,
2274 2384
 			);
2275
-		if (!isset($board_changes[$row['id_board']]))
2276
-			$board_changes[$row['id_board']] = array(
2385
+		}
2386
+		if (!isset($board_changes[$row['id_board']])) {
2387
+					$board_changes[$row['id_board']] = array(
2277 2388
 				'posts' => 0,
2278 2389
 				'topics' => 0,
2279 2390
 				'unapproved_posts' => 0,
2280 2391
 				'unapproved_topics' => 0,
2281 2392
 			);
2393
+		}
2282 2394
 
2283 2395
 		// If it's the first message then the topic state changes!
2284 2396
 		if ($row['id_msg'] == $row['id_first_msg'])
@@ -2299,14 +2411,13 @@  discard block
 block discarded – undo
2299 2411
 				'poster' => $row['id_member'],
2300 2412
 				'new_topic' => true,
2301 2413
 			);
2302
-		}
2303
-		else
2414
+		} else
2304 2415
 		{
2305 2416
 			$topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
2306 2417
 
2307 2418
 			// This will be a post... but don't notify unless it's not followed by approved ones.
2308
-			if ($row['id_msg'] > $row['id_last_msg'])
2309
-				$notification_posts[$row['id_topic']] = array(
2419
+			if ($row['id_msg'] > $row['id_last_msg']) {
2420
+							$notification_posts[$row['id_topic']] = array(
2310 2421
 					'id' => $row['id_msg'],
2311 2422
 					'body' => $row['body'],
2312 2423
 					'subject' => $row['subject'],
@@ -2317,28 +2428,33 @@  discard block
 block discarded – undo
2317 2428
 					'new_topic' => false,
2318 2429
 					'msg' => $row['id_msg'],
2319 2430
 				);
2431
+			}
2320 2432
 		}
2321 2433
 
2322 2434
 		// If this is being approved and id_msg is higher than the current id_last_msg then it changes.
2323
-		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
2324
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2435
+		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
2436
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2437
+		}
2325 2438
 		// If this is being unapproved, and it's equal to the id_last_msg we need to find a new one!
2326
-		elseif (!$approve)
2327
-			// Default to the first message and then we'll override in a bit ;)
2439
+		elseif (!$approve) {
2440
+					// Default to the first message and then we'll override in a bit ;)
2328 2441
 			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
2442
+		}
2329 2443
 
2330 2444
 		$topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
2331 2445
 		$board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
2332 2446
 		$board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
2333 2447
 
2334 2448
 		// Post count for the user?
2335
-		if ($row['id_member'] && empty($row['count_posts']))
2336
-			$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2449
+		if ($row['id_member'] && empty($row['count_posts'])) {
2450
+					$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2451
+		}
2337 2452
 	}
2338 2453
 	$smcFunc['db_free_result']($request);
2339 2454
 
2340
-	if (empty($msgs))
2341
-		return;
2455
+	if (empty($msgs)) {
2456
+			return;
2457
+	}
2342 2458
 
2343 2459
 	// Now we have the differences make the changes, first the easy one.
2344 2460
 	$smcFunc['db_query']('', '
@@ -2365,14 +2481,15 @@  discard block
 block discarded – undo
2365 2481
 				'approved' => 1,
2366 2482
 			)
2367 2483
 		);
2368
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2369
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2484
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2485
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2486
+		}
2370 2487
 		$smcFunc['db_free_result']($request);
2371 2488
 	}
2372 2489
 
2373 2490
 	// ... next the topics...
2374
-	foreach ($topic_changes as $id => $changes)
2375
-		$smcFunc['db_query']('', '
2491
+	foreach ($topic_changes as $id => $changes) {
2492
+			$smcFunc['db_query']('', '
2376 2493
 			UPDATE {db_prefix}topics
2377 2494
 			SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2378 2495
 				num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
@@ -2385,10 +2502,11 @@  discard block
 block discarded – undo
2385 2502
 				'id_topic' => $id,
2386 2503
 			)
2387 2504
 		);
2505
+	}
2388 2506
 
2389 2507
 	// ... finally the boards...
2390
-	foreach ($board_changes as $id => $changes)
2391
-		$smcFunc['db_query']('', '
2508
+	foreach ($board_changes as $id => $changes) {
2509
+			$smcFunc['db_query']('', '
2392 2510
 			UPDATE {db_prefix}boards
2393 2511
 			SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2394 2512
 				num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
@@ -2401,13 +2519,14 @@  discard block
 block discarded – undo
2401 2519
 				'id_board' => $id,
2402 2520
 			)
2403 2521
 		);
2522
+	}
2404 2523
 
2405 2524
 	// Finally, least importantly, notifications!
2406 2525
 	if ($approve)
2407 2526
 	{
2408 2527
 		$task_rows = array();
2409
-		foreach (array_merge($notification_topics, $notification_posts) as $topic)
2410
-			$task_rows[] = array(
2528
+		foreach (array_merge($notification_topics, $notification_posts) as $topic) {
2529
+					$task_rows[] = array(
2411 2530
 				'$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
2412 2531
 					'msgOptions' => array(
2413 2532
 						'id' => $topic['msg'],
@@ -2425,14 +2544,16 @@  discard block
 block discarded – undo
2425 2544
 					'type' => $topic['new_topic'] ? 'topic' : 'reply',
2426 2545
 				)), 0
2427 2546
 			);
2547
+		}
2428 2548
 
2429
-		if ($notify)
2430
-			$smcFunc['db_insert']('',
2549
+		if ($notify) {
2550
+					$smcFunc['db_insert']('',
2431 2551
 				'{db_prefix}background_tasks',
2432 2552
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2433 2553
 				$task_rows,
2434 2554
 				array('id_task')
2435 2555
 			);
2556
+		}
2436 2557
 
2437 2558
 		$smcFunc['db_query']('', '
2438 2559
 			DELETE FROM {db_prefix}approval_queue
@@ -2448,8 +2569,9 @@  discard block
 block discarded – undo
2448 2569
 	else
2449 2570
 	{
2450 2571
 		$msgInserts = array();
2451
-		foreach ($msgs as $msg)
2452
-			$msgInserts[] = array($msg);
2572
+		foreach ($msgs as $msg) {
2573
+					$msgInserts[] = array($msg);
2574
+		}
2453 2575
 
2454 2576
 		$smcFunc['db_insert']('ignore',
2455 2577
 			'{db_prefix}approval_queue',
@@ -2463,9 +2585,10 @@  discard block
 block discarded – undo
2463 2585
 	updateLastMessages(array_keys($board_changes));
2464 2586
 
2465 2587
 	// Post count for the members?
2466
-	if (!empty($member_post_changes))
2467
-		foreach ($member_post_changes as $id_member => $count_change)
2588
+	if (!empty($member_post_changes)) {
2589
+			foreach ($member_post_changes as $id_member => $count_change)
2468 2590
 			updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
2591
+	}
2469 2592
 
2470 2593
 	return true;
2471 2594
 }
@@ -2482,11 +2605,13 @@  discard block
 block discarded – undo
2482 2605
 {
2483 2606
 	global $smcFunc;
2484 2607
 
2485
-	if (!is_array($topics))
2486
-		$topics = array($topics);
2608
+	if (!is_array($topics)) {
2609
+			$topics = array($topics);
2610
+	}
2487 2611
 
2488
-	if (empty($topics))
2489
-		return false;
2612
+	if (empty($topics)) {
2613
+			return false;
2614
+	}
2490 2615
 
2491 2616
 	$approve_type = $approve ? 0 : 1;
2492 2617
 
@@ -2502,8 +2627,9 @@  discard block
 block discarded – undo
2502 2627
 		)
2503 2628
 	);
2504 2629
 	$msgs = array();
2505
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2506
-		$msgs[] = $row['id_msg'];
2630
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2631
+			$msgs[] = $row['id_msg'];
2632
+	}
2507 2633
 	$smcFunc['db_free_result']($request);
2508 2634
 
2509 2635
 	return approvePosts($msgs, $approve);
@@ -2526,11 +2652,13 @@  discard block
 block discarded – undo
2526 2652
 	global $board_info, $board, $smcFunc;
2527 2653
 
2528 2654
 	// Please - let's be sane.
2529
-	if (empty($setboards))
2530
-		return false;
2655
+	if (empty($setboards)) {
2656
+			return false;
2657
+	}
2531 2658
 
2532
-	if (!is_array($setboards))
2533
-		$setboards = array($setboards);
2659
+	if (!is_array($setboards)) {
2660
+			$setboards = array($setboards);
2661
+	}
2534 2662
 
2535 2663
 	// If we don't know the id_msg we need to find it.
2536 2664
 	if (!$id_msg)
@@ -2548,15 +2676,16 @@  discard block
 block discarded – undo
2548 2676
 			)
2549 2677
 		);
2550 2678
 		$lastMsg = array();
2551
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2552
-			$lastMsg[$row['id_board']] = $row['id_msg'];
2679
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2680
+					$lastMsg[$row['id_board']] = $row['id_msg'];
2681
+		}
2553 2682
 		$smcFunc['db_free_result']($request);
2554
-	}
2555
-	else
2683
+	} else
2556 2684
 	{
2557 2685
 		// Just to note - there should only be one board passed if we are doing this.
2558
-		foreach ($setboards as $id_board)
2559
-			$lastMsg[$id_board] = $id_msg;
2686
+		foreach ($setboards as $id_board) {
2687
+					$lastMsg[$id_board] = $id_msg;
2688
+		}
2560 2689
 	}
2561 2690
 
2562 2691
 	$parent_boards = array();
@@ -2571,10 +2700,11 @@  discard block
 block discarded – undo
2571 2700
 			$lastModified[$id_board] = 0;
2572 2701
 		}
2573 2702
 
2574
-		if (!empty($board) && $id_board == $board)
2575
-			$parents = $board_info['parent_boards'];
2576
-		else
2577
-			$parents = getBoardParents($id_board);
2703
+		if (!empty($board) && $id_board == $board) {
2704
+					$parents = $board_info['parent_boards'];
2705
+		} else {
2706
+					$parents = getBoardParents($id_board);
2707
+		}
2578 2708
 
2579 2709
 		// Ignore any parents on the top child level.
2580 2710
 		// @todo Why?
@@ -2583,10 +2713,11 @@  discard block
 block discarded – undo
2583 2713
 			if ($parent['level'] != 0)
2584 2714
 			{
2585 2715
 				// If we're already doing this one as a board, is this a higher last modified?
2586
-				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
2587
-					$lastModified[$id] = $lastModified[$id_board];
2588
-				elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
2589
-					$parent_boards[$id] = $lastModified[$id_board];
2716
+				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) {
2717
+									$lastModified[$id] = $lastModified[$id_board];
2718
+				} elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) {
2719
+									$parent_boards[$id] = $lastModified[$id_board];
2720
+				}
2590 2721
 			}
2591 2722
 		}
2592 2723
 	}
@@ -2599,23 +2730,24 @@  discard block
 block discarded – undo
2599 2730
 	// Finally, to save on queries make the changes...
2600 2731
 	foreach ($parent_boards as $id => $msg)
2601 2732
 	{
2602
-		if (!isset($parent_updates[$msg]))
2603
-			$parent_updates[$msg] = array($id);
2604
-		else
2605
-			$parent_updates[$msg][] = $id;
2733
+		if (!isset($parent_updates[$msg])) {
2734
+					$parent_updates[$msg] = array($id);
2735
+		} else {
2736
+					$parent_updates[$msg][] = $id;
2737
+		}
2606 2738
 	}
2607 2739
 
2608 2740
 	foreach ($lastMsg as $id => $msg)
2609 2741
 	{
2610
-		if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
2611
-			$board_updates[$msg . '-' . $lastModified[$id]] = array(
2742
+		if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) {
2743
+					$board_updates[$msg . '-' . $lastModified[$id]] = array(
2612 2744
 				'id' => $msg,
2613 2745
 				'updated' => $lastModified[$id],
2614 2746
 				'boards' => array($id)
2615 2747
 			);
2616
-
2617
-		else
2618
-			$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2748
+		} else {
2749
+					$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2750
+		}
2619 2751
 	}
2620 2752
 
2621 2753
 	// Now commit the changes!
@@ -2707,11 +2839,13 @@  discard block
 block discarded – undo
2707 2839
 	global $txt, $mbname, $scripturl, $settings;
2708 2840
 
2709 2841
 	// First things first, load up the email templates language file, if we need to.
2710
-	if ($loadLang)
2711
-		loadLanguage('EmailTemplates', $lang);
2842
+	if ($loadLang) {
2843
+			loadLanguage('EmailTemplates', $lang);
2844
+	}
2712 2845
 
2713
-	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
2714
-		fatal_lang_error('email_no_template', 'template', array($template));
2846
+	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) {
2847
+			fatal_lang_error('email_no_template', 'template', array($template));
2848
+	}
2715 2849
 
2716 2850
 	$ret = array(
2717 2851
 		'subject' => $txt[$template . '_subject'],
@@ -2761,17 +2895,18 @@  discard block
 block discarded – undo
2761 2895
 function user_info_callback($matches)
2762 2896
 {
2763 2897
 	global $user_info;
2764
-	if (empty($matches[1]))
2765
-		return '';
2898
+	if (empty($matches[1])) {
2899
+			return '';
2900
+	}
2766 2901
 
2767 2902
 	$use_ref = true;
2768 2903
 	$ref = &$user_info;
2769 2904
 
2770 2905
 	foreach (explode('.', $matches[1]) as $index)
2771 2906
 	{
2772
-		if ($use_ref && isset($ref[$index]))
2773
-			$ref = &$ref[$index];
2774
-		else
2907
+		if ($use_ref && isset($ref[$index])) {
2908
+					$ref = &$ref[$index];
2909
+		} else
2775 2910
 		{
2776 2911
 			$use_ref = false;
2777 2912
 			break;
@@ -2808,8 +2943,7 @@  discard block
 block discarded – undo
2808 2943
 		if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale))
2809 2944
 		{
2810 2945
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale);
2811
-		}
2812
-		elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2946
+		} elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2813 2947
 		{
2814 2948
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']);
2815 2949
 		}
@@ -2819,8 +2953,7 @@  discard block
 block discarded – undo
2819 2953
 		{
2820 2954
 			$context['provider'] = 'enchant';
2821 2955
 			return $enchant_link;
2822
-		}
2823
-		else
2956
+		} else
2824 2957
 		{
2825 2958
 			// Free up any resources used...
2826 2959
 			@enchant_broker_free($context['enchant_broker']);
@@ -2841,8 +2974,9 @@  discard block
 block discarded – undo
2841 2974
 		$pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
2842 2975
 
2843 2976
 		// Most people don't have anything but English installed... So we use English as a last resort.
2844
-		if (!$pspell_link)
2845
-			$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
2977
+		if (!$pspell_link) {
2978
+					$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
2979
+		}
2846 2980
 
2847 2981
 		error_reporting($old);
2848 2982
 		ob_end_clean();
@@ -2882,8 +3016,7 @@  discard block
 block discarded – undo
2882 3016
 			$word = iconv($txt['lang_character_set'], 'UTF-8', $word);
2883 3017
 		}
2884 3018
 		return enchant_dict_check($dict, $word);
2885
-	}
2886
-	elseif ($context['provider'] == 'pspell')
3019
+	} elseif ($context['provider'] == 'pspell')
2887 3020
 	{
2888 3021
 		return pspell_check($dict, $word);
2889 3022
 	}
@@ -2919,13 +3052,11 @@  discard block
 block discarded – undo
2919 3052
 			}
2920 3053
 
2921 3054
 			return $suggestions;
2922
-		}
2923
-		else
3055
+		} else
2924 3056
 		{
2925 3057
 			return enchant_dict_suggest($dict, $word);
2926 3058
 		}
2927
-	}
2928
-	elseif ($context['provider'] == 'pspell')
3059
+	} elseif ($context['provider'] == 'pspell')
2929 3060
 	{
2930 3061
 		return pspell_suggest($dict, $word);
2931 3062
 	}
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +795 added lines, -601 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,28 +48,36 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65 73
 		// We excpiclity do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded.
66
-		if (!is_array($modSettings['attachmentUploadDir']))
67
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
74
+		if (!is_array($modSettings['attachmentUploadDir'])) {
75
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
76
+		}
68 77
 
69
-		if (!empty($cache_enable))
70
-			cache_put_data('modSettings', $modSettings, 90);
78
+		if (!empty($cache_enable)) {
79
+					cache_put_data('modSettings', $modSettings, 90);
80
+		}
71 81
 	}
72 82
 
73 83
 	$modSettings['cache_enable'] = $cache_enable;
@@ -87,8 +97,9 @@  discard block
 block discarded – undo
87 97
 		};
88 98
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
89 99
 	{
90
-		if (!$utf8 || $smcFunc['db_mb4'])
91
-			return $string;
100
+		if (!$utf8 || $smcFunc['db_mb4']) {
101
+					return $string;
102
+		}
92 103
 
93 104
 		$i = 0;
94 105
 		$len = strlen($string);
@@ -100,18 +111,15 @@  discard block
 block discarded – undo
100 111
 			{
101 112
 				$new_string .= $string[$i];
102 113
 				$i++;
103
-			}
104
-			elseif ($ord < 224)
114
+			} elseif ($ord < 224)
105 115
 			{
106 116
 				$new_string .= $string[$i] . $string[$i + 1];
107 117
 				$i += 2;
108
-			}
109
-			elseif ($ord < 240)
118
+			} elseif ($ord < 240)
110 119
 			{
111 120
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
112 121
 				$i += 3;
113
-			}
114
-			elseif ($ord < 248)
122
+			} elseif ($ord < 248)
115 123
 			{
116 124
 				// Magic happens.
117 125
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -155,8 +163,7 @@  discard block
 block discarded – undo
155 163
 			{
156 164
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
157 165
 				return is_int($result) ? $result + $offset : false;
158
-			}
159
-			else
166
+			} else
160 167
 			{
161 168
 				$needle_arr = preg_split('~(' . $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
 
@@ -392,9 +409,9 @@  discard block
 block discarded – undo
392 409
 				break;
393 410
 			}
394 411
 		}
412
+	} else {
413
+			$id_member = 0;
395 414
 	}
396
-	else
397
-		$id_member = 0;
398 415
 
399 416
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
400 417
 	{
@@ -402,8 +419,9 @@  discard block
 block discarded – undo
402 419
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
403 420
 
404 421
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
405
-		if (empty($cookie_data))
406
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
422
+		if (empty($cookie_data)) {
423
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
424
+		}
407 425
 
408 426
 		list($id_member, $password, $login_span, $cookie_domain, $cookie_path) = array_pad((array) $cookie_data, 5, '');
409 427
 
@@ -411,16 +429,17 @@  discard block
 block discarded – undo
411 429
 
412 430
 		// Make sure the cookie is set to the correct domain and path
413 431
 		require_once($sourcedir . '/Subs-Auth.php');
414
-		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])))
415
-			setLoginCookie((int) $login_span - time(), $id_member);
416
-	}
417
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
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'])))
418 436
 	{
419 437
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
420 438
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename], true);
421 439
 
422
-		if (empty($cookie_data))
423
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
440
+		if (empty($cookie_data)) {
441
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
442
+		}
424 443
 
425 444
 		list($id_member, $password, $login_span) = array_pad((array) $cookie_data, 3, '');
426 445
 		$id_member = !empty($id_member) && strlen($password) == 128 && (int) $login_span > time() ? (int) $id_member : 0;
@@ -445,30 +464,34 @@  discard block
 block discarded – undo
445 464
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
446 465
 			$smcFunc['db_free_result']($request);
447 466
 
448
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
449
-				$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
467
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
468
+							$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
469
+			}
450 470
 
451
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
452
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
471
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
472
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
473
+			}
453 474
 		}
454 475
 
455 476
 		// Did we find 'im?  If not, junk it.
456 477
 		if (!empty($user_settings))
457 478
 		{
458 479
 			// As much as the password should be right, we can assume the integration set things up.
459
-			if (!empty($already_verified) && $already_verified === true)
460
-				$check = true;
480
+			if (!empty($already_verified) && $already_verified === true) {
481
+							$check = true;
482
+			}
461 483
 			// SHA-512 hash should be 128 characters long.
462
-			elseif (strlen($password) == 128)
463
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
464
-			else
465
-				$check = false;
484
+			elseif (strlen($password) == 128) {
485
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
486
+			} else {
487
+							$check = false;
488
+			}
466 489
 
467 490
 			// Wrong password or not activated - either way, you're going nowhere.
468 491
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
492
+		} else {
493
+					$id_member = 0;
469 494
 		}
470
-		else
471
-			$id_member = 0;
472 495
 
473 496
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
474 497
 		if (!$id_member)
@@ -497,8 +520,9 @@  discard block
 block discarded – undo
497 520
 
498 521
 					list ($tfamember, $tfasecret) = array_pad((array) $tfa_data, 2, '');
499 522
 
500
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
501
-						$tfasecret = null;
523
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
524
+											$tfasecret = null;
525
+					}
502 526
 				}
503 527
 
504 528
 				// They didn't finish logging in before coming here? Then they're no one to us.
@@ -520,10 +544,12 @@  discard block
 block discarded – undo
520 544
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
521 545
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
522 546
 		{
523
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
547
+			if ($modSettings['tfa_mode'] == 2) {
548
+				//only do this if we are just forcing SOME membergroups
524 549
 			{
525 550
 				//Build an array of ALL user membergroups.
526 551
 				$full_groups = array($user_settings['id_group']);
552
+			}
527 553
 				if (!empty($user_settings['additional_groups']))
528 554
 				{
529 555
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -543,15 +569,17 @@  discard block
 block discarded – undo
543 569
 				);
544 570
 				$row = $smcFunc['db_fetch_assoc']($request);
545 571
 				$smcFunc['db_free_result']($request);
572
+			} else {
573
+							$row['total'] = 1;
546 574
 			}
547
-			else
548
-				$row['total'] = 1; //simplifies logics in the next "if"
575
+			//simplifies logics in the next "if"
549 576
 
550 577
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
551 578
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
552 579
 
553
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
554
-				redirectexit('action=profile;area=tfasetup;forced');
580
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
581
+							redirectexit('action=profile;area=tfasetup;forced');
582
+			}
555 583
 		}
556 584
 	}
557 585
 
@@ -588,33 +616,37 @@  discard block
 block discarded – undo
588 616
 				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']));
589 617
 				$user_settings['last_login'] = time();
590 618
 
591
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
592
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
619
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
620
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
621
+				}
593 622
 
594
-				if (!empty($modSettings['cache_enable']))
595
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
623
+				if (!empty($modSettings['cache_enable'])) {
624
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
625
+				}
596 626
 			}
627
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
628
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
597 629
 		}
598
-		elseif (empty($_SESSION['id_msg_last_visit']))
599
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
600 630
 
601 631
 		$username = $user_settings['member_name'];
602 632
 
603
-		if (empty($user_settings['additional_groups']))
604
-			$user_info = array(
633
+		if (empty($user_settings['additional_groups'])) {
634
+					$user_info = array(
605 635
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
606 636
 			);
607
-		else
608
-			$user_info = array(
637
+		} else {
638
+					$user_info = array(
609 639
 				'groups' => array_merge(
610 640
 					array($user_settings['id_group'], $user_settings['id_post_group']),
611 641
 					explode(',', $user_settings['additional_groups'])
612 642
 				)
613 643
 			);
644
+		}
614 645
 
615 646
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
616
-		foreach ($user_info['groups'] as $k => $v)
617
-			$user_info['groups'][$k] = (int) $v;
647
+		foreach ($user_info['groups'] as $k => $v) {
648
+					$user_info['groups'][$k] = (int) $v;
649
+		}
618 650
 
619 651
 		// This is a logged in user, so definitely not a spider.
620 652
 		$user_info['possibly_robot'] = false;
@@ -628,8 +660,7 @@  discard block
 block discarded – undo
628 660
 			$time_system = new DateTime('now', $tz_system);
629 661
 			$time_user = new DateTime('now', $tz_user);
630 662
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
631
-		}
632
-		else
663
+		} else
633 664
 		{
634 665
 			// !!! Compatibility.
635 666
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -643,8 +674,9 @@  discard block
 block discarded – undo
643 674
 		$user_info = array('groups' => array(-1));
644 675
 		$user_settings = array();
645 676
 
646
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
647
-			$_COOKIE[$cookiename] = '';
677
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
678
+					$_COOKIE[$cookiename] = '';
679
+		}
648 680
 
649 681
 		// Expire the 2FA cookie
650 682
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -661,19 +693,20 @@  discard block
 block discarded – undo
661 693
 		}
662 694
 
663 695
 		// Create a login token if it doesn't exist yet.
664
-		if (!isset($_SESSION['token']['post-login']))
665
-			createToken('login');
666
-		else
667
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
696
+		if (!isset($_SESSION['token']['post-login'])) {
697
+					createToken('login');
698
+		} else {
699
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
700
+		}
668 701
 
669 702
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
670 703
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
671 704
 		{
672 705
 			require_once($sourcedir . '/ManageSearchEngines.php');
673 706
 			$user_info['possibly_robot'] = SpiderCheck();
707
+		} elseif (!empty($modSettings['spider_mode'])) {
708
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
674 709
 		}
675
-		elseif (!empty($modSettings['spider_mode']))
676
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
677 710
 		// If we haven't turned on proper spider hunts then have a guess!
678 711
 		else
679 712
 		{
@@ -721,8 +754,9 @@  discard block
 block discarded – undo
721 754
 	$user_info['groups'] = array_unique($user_info['groups']);
722 755
 
723 756
 	// 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.
724
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
725
-		unset($user_info['ignoreboards'][$tmp]);
757
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
758
+			unset($user_info['ignoreboards'][$tmp]);
759
+	}
726 760
 
727 761
 	// Allow the user to change their language.
728 762
 	if (!empty($modSettings['userLanguage']))
@@ -735,13 +769,14 @@  discard block
 block discarded – undo
735 769
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
736 770
 
737 771
 			// Make it permanent for members.
738
-			if (!empty($user_info['id']))
739
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
740
-			else
741
-				$_SESSION['language'] = $user_info['language'];
772
+			if (!empty($user_info['id'])) {
773
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
774
+			} else {
775
+							$_SESSION['language'] = $user_info['language'];
776
+			}
777
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
778
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
742 779
 		}
743
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
744
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
745 780
 	}
746 781
 
747 782
 	$temp = build_query_board($user_info['id']);
@@ -804,9 +839,9 @@  discard block
 block discarded – undo
804 839
 		}
805 840
 
806 841
 		// Remember redirection is the key to avoiding fallout from your bosses.
807
-		if (!empty($topic))
808
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
809
-		else
842
+		if (!empty($topic)) {
843
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
844
+		} else
810 845
 		{
811 846
 			loadPermissions();
812 847
 			loadTheme();
@@ -824,10 +859,11 @@  discard block
 block discarded – undo
824 859
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
825 860
 	{
826 861
 		// @todo SLOW?
827
-		if (!empty($topic))
828
-			$temp = cache_get_data('topic_board-' . $topic, 120);
829
-		else
830
-			$temp = cache_get_data('board-' . $board, 120);
862
+		if (!empty($topic)) {
863
+					$temp = cache_get_data('topic_board-' . $topic, 120);
864
+		} else {
865
+					$temp = cache_get_data('board-' . $board, 120);
866
+		}
831 867
 
832 868
 		if (!empty($temp))
833 869
 		{
@@ -865,8 +901,9 @@  discard block
 block discarded – undo
865 901
 			$row = $smcFunc['db_fetch_assoc']($request);
866 902
 
867 903
 			// Set the current board.
868
-			if (!empty($row['id_board']))
869
-				$board = $row['id_board'];
904
+			if (!empty($row['id_board'])) {
905
+							$board = $row['id_board'];
906
+			}
870 907
 
871 908
 			// Basic operating information. (globals... :/)
872 909
 			$board_info = array(
@@ -902,21 +939,23 @@  discard block
 block discarded – undo
902 939
 
903 940
 			do
904 941
 			{
905
-				if (!empty($row['id_moderator']))
906
-					$board_info['moderators'][$row['id_moderator']] = array(
942
+				if (!empty($row['id_moderator'])) {
943
+									$board_info['moderators'][$row['id_moderator']] = array(
907 944
 						'id' => $row['id_moderator'],
908 945
 						'name' => $row['real_name'],
909 946
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
910 947
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
911 948
 					);
949
+				}
912 950
 
913
-				if (!empty($row['id_moderator_group']))
914
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
951
+				if (!empty($row['id_moderator_group'])) {
952
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
915 953
 						'id' => $row['id_moderator_group'],
916 954
 						'name' => $row['group_name'],
917 955
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
918 956
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
919 957
 					);
958
+				}
920 959
 			}
921 960
 			while ($row = $smcFunc['db_fetch_assoc']($request));
922 961
 
@@ -948,12 +987,12 @@  discard block
 block discarded – undo
948 987
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
949 988
 			{
950 989
 				// @todo SLOW?
951
-				if (!empty($topic))
952
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
990
+				if (!empty($topic)) {
991
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
992
+				}
953 993
 				cache_put_data('board-' . $board, $board_info, 120);
954 994
 			}
955
-		}
956
-		else
995
+		} else
957 996
 		{
958 997
 			// Otherwise the topic is invalid, there are no moderators, etc.
959 998
 			$board_info = array(
@@ -967,8 +1006,9 @@  discard block
 block discarded – undo
967 1006
 		$smcFunc['db_free_result']($request);
968 1007
 	}
969 1008
 
970
-	if (!empty($topic))
971
-		$_GET['board'] = (int) $board;
1009
+	if (!empty($topic)) {
1010
+			$_GET['board'] = (int) $board;
1011
+	}
972 1012
 
973 1013
 	if (!empty($board))
974 1014
 	{
@@ -978,10 +1018,12 @@  discard block
 block discarded – undo
978 1018
 		// Now check if the user is a moderator.
979 1019
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
980 1020
 
981
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
982
-			$board_info['error'] = 'access';
983
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
984
-			$board_info['error'] = 'access';
1021
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1022
+					$board_info['error'] = 'access';
1023
+		}
1024
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1025
+					$board_info['error'] = 'access';
1026
+		}
985 1027
 
986 1028
 		// Build up the linktree.
987 1029
 		$context['linktree'] = array_merge(
@@ -1004,8 +1046,9 @@  discard block
 block discarded – undo
1004 1046
 	$context['current_board'] = $board;
1005 1047
 
1006 1048
 	// No posting in redirection boards!
1007
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1008
-		$board_info['error'] == 'post_in_redirect';
1049
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1050
+			$board_info['error'] == 'post_in_redirect';
1051
+	}
1009 1052
 
1010 1053
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1011 1054
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1031,24 +1074,23 @@  discard block
 block discarded – undo
1031 1074
 			ob_end_clean();
1032 1075
 			header('HTTP/1.1 403 Forbidden');
1033 1076
 			die;
1034
-		}
1035
-		elseif ($board_info['error'] == 'post_in_redirect')
1077
+		} elseif ($board_info['error'] == 'post_in_redirect')
1036 1078
 		{
1037 1079
 			// Slightly different error message here...
1038 1080
 			fatal_lang_error('cannot_post_redirect', false);
1039
-		}
1040
-		elseif ($user_info['is_guest'])
1081
+		} elseif ($user_info['is_guest'])
1041 1082
 		{
1042 1083
 			loadLanguage('Errors');
1043 1084
 			is_not_guest($txt['topic_gone']);
1085
+		} else {
1086
+					fatal_lang_error('topic_gone', false);
1044 1087
 		}
1045
-		else
1046
-			fatal_lang_error('topic_gone', false);
1047 1088
 	}
1048 1089
 
1049
-	if ($user_info['is_mod'])
1050
-		$user_info['groups'][] = 3;
1051
-}
1090
+	if ($user_info['is_mod']) {
1091
+			$user_info['groups'][] = 3;
1092
+	}
1093
+	}
1052 1094
 
1053 1095
 /**
1054 1096
  * Load this user's permissions.
@@ -1069,8 +1111,9 @@  discard block
 block discarded – undo
1069 1111
 		asort($cache_groups);
1070 1112
 		$cache_groups = implode(',', $cache_groups);
1071 1113
 		// If it's a spider then cache it different.
1072
-		if ($user_info['possibly_robot'])
1073
-			$cache_groups .= '-spider';
1114
+		if ($user_info['possibly_robot']) {
1115
+					$cache_groups .= '-spider';
1116
+		}
1074 1117
 
1075 1118
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1076 1119
 		{
@@ -1078,9 +1121,9 @@  discard block
 block discarded – undo
1078 1121
 			banPermissions();
1079 1122
 
1080 1123
 			return;
1124
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1125
+					list ($user_info['permissions'], $removals) = $temp;
1081 1126
 		}
1082
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1083
-			list ($user_info['permissions'], $removals) = $temp;
1084 1127
 	}
1085 1128
 
1086 1129
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1102,23 +1145,26 @@  discard block
 block discarded – undo
1102 1145
 		$removals = array();
1103 1146
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1104 1147
 		{
1105
-			if (empty($row['add_deny']))
1106
-				$removals[] = $row['permission'];
1107
-			else
1108
-				$user_info['permissions'][] = $row['permission'];
1148
+			if (empty($row['add_deny'])) {
1149
+							$removals[] = $row['permission'];
1150
+			} else {
1151
+							$user_info['permissions'][] = $row['permission'];
1152
+			}
1109 1153
 		}
1110 1154
 		$smcFunc['db_free_result']($request);
1111 1155
 
1112
-		if (isset($cache_groups))
1113
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1156
+		if (isset($cache_groups)) {
1157
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1158
+		}
1114 1159
 	}
1115 1160
 
1116 1161
 	// Get the board permissions.
1117 1162
 	if (!empty($board))
1118 1163
 	{
1119 1164
 		// Make sure the board (if any) has been loaded by loadBoard().
1120
-		if (!isset($board_info['profile']))
1121
-			fatal_lang_error('no_board');
1165
+		if (!isset($board_info['profile'])) {
1166
+					fatal_lang_error('no_board');
1167
+		}
1122 1168
 
1123 1169
 		$request = $smcFunc['db_query']('', '
1124 1170
 			SELECT permission, add_deny
@@ -1134,20 +1180,23 @@  discard block
 block discarded – undo
1134 1180
 		);
1135 1181
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1136 1182
 		{
1137
-			if (empty($row['add_deny']))
1138
-				$removals[] = $row['permission'];
1139
-			else
1140
-				$user_info['permissions'][] = $row['permission'];
1183
+			if (empty($row['add_deny'])) {
1184
+							$removals[] = $row['permission'];
1185
+			} else {
1186
+							$user_info['permissions'][] = $row['permission'];
1187
+			}
1141 1188
 		}
1142 1189
 		$smcFunc['db_free_result']($request);
1143 1190
 	}
1144 1191
 
1145 1192
 	// Remove all the permissions they shouldn't have ;).
1146
-	if (!empty($modSettings['permission_enable_deny']))
1147
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1193
+	if (!empty($modSettings['permission_enable_deny'])) {
1194
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1195
+	}
1148 1196
 
1149
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1150
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1197
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1198
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1199
+	}
1151 1200
 
1152 1201
 	// Banned?  Watch, don't touch..
1153 1202
 	banPermissions();
@@ -1159,17 +1208,18 @@  discard block
 block discarded – undo
1159 1208
 		{
1160 1209
 			require_once($sourcedir . '/Subs-Auth.php');
1161 1210
 			rebuildModCache();
1211
+		} else {
1212
+					$user_info['mod_cache'] = $_SESSION['mc'];
1162 1213
 		}
1163
-		else
1164
-			$user_info['mod_cache'] = $_SESSION['mc'];
1165 1214
 
1166 1215
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1167 1216
 		// For example this drastically simplifies certain changes to the profile area.
1168 1217
 		$user_info['permissions'][] = 'is_not_guest';
1169 1218
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1170 1219
 		$user_info['permissions'][] = 'profile_view_own';
1171
-		if (in_array('profile_view', $user_info['permissions']))
1172
-			$user_info['permissions'][] = 'profile_view_any';
1220
+		if (in_array('profile_view', $user_info['permissions'])) {
1221
+					$user_info['permissions'][] = 'profile_view_any';
1222
+		}
1173 1223
 	}
1174 1224
 }
1175 1225
 
@@ -1187,8 +1237,9 @@  discard block
 block discarded – undo
1187 1237
 	global $image_proxy_enabled, $boardurl, $user_info;
1188 1238
 
1189 1239
 	// Can't just look for no users :P.
1190
-	if (empty($users))
1191
-		return array();
1240
+	if (empty($users)) {
1241
+			return array();
1242
+	}
1192 1243
 
1193 1244
 	// Pass the set value
1194 1245
 	$context['loadMemberContext_set'] = $set;
@@ -1203,8 +1254,9 @@  discard block
 block discarded – undo
1203 1254
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1204 1255
 		{
1205 1256
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1206
-			if ($data == null)
1207
-				continue;
1257
+			if ($data == null) {
1258
+							continue;
1259
+			}
1208 1260
 
1209 1261
 			$loaded_ids[] = $data['id_member'];
1210 1262
 			$user_profile[$data['id_member']] = $data;
@@ -1271,16 +1323,19 @@  discard block
 block discarded – undo
1271 1323
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1272 1324
 
1273 1325
 			// Take care of proxying avatar if required, do this here for maximum reach
1274
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
1275
-				$row['avatar'] = get_proxied_url($row['avatar']);
1326
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
1327
+							$row['avatar'] = get_proxied_url($row['avatar']);
1328
+			}
1276 1329
 
1277 1330
 			// Keep track of the member's normal member group
1278 1331
 			$row['primary_group'] = $row['member_group'];
1279 1332
 
1280
-			if (isset($row['member_ip']))
1281
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1282
-			if (isset($row['member_ip2']))
1283
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1333
+			if (isset($row['member_ip'])) {
1334
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1335
+			}
1336
+			if (isset($row['member_ip2'])) {
1337
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1338
+			}
1284 1339
 			$new_loaded_ids[] = $row['id_member'];
1285 1340
 			$loaded_ids[] = $row['id_member'];
1286 1341
 			$row['options'] = array();
@@ -1299,8 +1354,9 @@  discard block
 block discarded – undo
1299 1354
 				'loaded_ids' => $new_loaded_ids,
1300 1355
 			)
1301 1356
 		);
1302
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1303
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1357
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1358
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1359
+		}
1304 1360
 		$smcFunc['db_free_result']($request);
1305 1361
 	}
1306 1362
 
@@ -1311,10 +1367,11 @@  discard block
 block discarded – undo
1311 1367
 	{
1312 1368
 		foreach ($loaded_ids as $a_member)
1313 1369
 		{
1314
-			if (!empty($user_profile[$a_member]['additional_groups']))
1315
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1316
-			else
1317
-				$groups = array($user_profile[$a_member]['id_group']);
1370
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1371
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1372
+			} else {
1373
+							$groups = array($user_profile[$a_member]['id_group']);
1374
+			}
1318 1375
 
1319 1376
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1320 1377
 
@@ -1327,8 +1384,9 @@  discard block
 block discarded – undo
1327 1384
 
1328 1385
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1329 1386
 	{
1330
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1331
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1387
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1388
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1389
+		}
1332 1390
 	}
1333 1391
 
1334 1392
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1354,14 +1412,17 @@  discard block
 block discarded – undo
1354 1412
 		foreach ($temp_mods as $id)
1355 1413
 		{
1356 1414
 			// By popular demand, don't show admins or global moderators as moderators.
1357
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1358
-				$user_profile[$id]['member_group'] = $row['member_group'];
1415
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1416
+							$user_profile[$id]['member_group'] = $row['member_group'];
1417
+			}
1359 1418
 
1360 1419
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1361
-			if (!empty($row['icons']))
1362
-				$user_profile[$id]['icons'] = $row['icons'];
1363
-			if (!empty($row['member_group_color']))
1364
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1420
+			if (!empty($row['icons'])) {
1421
+							$user_profile[$id]['icons'] = $row['icons'];
1422
+			}
1423
+			if (!empty($row['member_group_color'])) {
1424
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1425
+			}
1365 1426
 		}
1366 1427
 	}
1367 1428
 
@@ -1383,12 +1444,14 @@  discard block
 block discarded – undo
1383 1444
 	static $loadedLanguages = array();
1384 1445
 
1385 1446
 	// If this person's data is already loaded, skip it.
1386
-	if (isset($dataLoaded[$user]))
1387
-		return true;
1447
+	if (isset($dataLoaded[$user])) {
1448
+			return true;
1449
+	}
1388 1450
 
1389 1451
 	// We can't load guests or members not loaded by loadMemberData()!
1390
-	if ($user == 0)
1391
-		return false;
1452
+	if ($user == 0) {
1453
+			return false;
1454
+	}
1392 1455
 	if (!isset($user_profile[$user]))
1393 1456
 	{
1394 1457
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1414,12 +1477,16 @@  discard block
 block discarded – undo
1414 1477
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1415 1478
 
1416 1479
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1417
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1480
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1481
+		//icon is set and exists
1418 1482
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1419
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1483
+	} elseif (isset($profile['icons'][1])) {
1484
+		//icon is set and doesn't exist, fallback to default
1420 1485
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1421
-	else //not set, bye bye
1486
+	} else {
1487
+		//not set, bye bye
1422 1488
 		$group_icon_url = '';
1489
+	}
1423 1490
 
1424 1491
 	// These minimal values are always loaded
1425 1492
 	$memberContext[$user] = array(
@@ -1438,8 +1505,9 @@  discard block
 block discarded – undo
1438 1505
 	if ($context['loadMemberContext_set'] != 'minimal')
1439 1506
 	{
1440 1507
 		// Go the extra mile and load the user's native language name.
1441
-		if (empty($loadedLanguages))
1442
-			$loadedLanguages = getLanguages();
1508
+		if (empty($loadedLanguages)) {
1509
+					$loadedLanguages = getLanguages();
1510
+		}
1443 1511
 
1444 1512
 		$memberContext[$user] += array(
1445 1513
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1494,31 +1562,33 @@  discard block
 block discarded – undo
1494 1562
 	{
1495 1563
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1496 1564
 		{
1497
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1498
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1499
-			else
1500
-				$image = get_gravatar_url($profile['email_address']);
1501
-		}
1502
-		else
1565
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1566
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1567
+			} else {
1568
+							$image = get_gravatar_url($profile['email_address']);
1569
+			}
1570
+		} else
1503 1571
 		{
1504 1572
 			// So it's stored in the member table?
1505 1573
 			if (!empty($profile['avatar']))
1506 1574
 			{
1507 1575
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1576
+			} elseif (!empty($profile['filename'])) {
1577
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1508 1578
 			}
1509
-			elseif (!empty($profile['filename']))
1510
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1511 1579
 			// Right... no avatar...use the default one
1512
-			else
1513
-				$image = $modSettings['avatar_url'] . '/default.png';
1580
+			else {
1581
+							$image = $modSettings['avatar_url'] . '/default.png';
1582
+			}
1514 1583
 		}
1515
-		if (!empty($image))
1516
-			$memberContext[$user]['avatar'] = array(
1584
+		if (!empty($image)) {
1585
+					$memberContext[$user]['avatar'] = array(
1517 1586
 				'name' => $profile['avatar'],
1518 1587
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1519 1588
 				'href' => $image,
1520 1589
 				'url' => $image,
1521 1590
 			);
1591
+		}
1522 1592
 	}
1523 1593
 
1524 1594
 	// Are we also loading the members custom fields into context?
@@ -1526,13 +1596,15 @@  discard block
 block discarded – undo
1526 1596
 	{
1527 1597
 		$memberContext[$user]['custom_fields'] = array();
1528 1598
 
1529
-		if (!isset($context['display_fields']))
1530
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1599
+		if (!isset($context['display_fields'])) {
1600
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1601
+		}
1531 1602
 
1532 1603
 		foreach ($context['display_fields'] as $custom)
1533 1604
 		{
1534
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1535
-				continue;
1605
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1606
+							continue;
1607
+			}
1536 1608
 
1537 1609
 			$value = $profile['options'][$custom['col_name']];
1538 1610
 
@@ -1540,31 +1612,36 @@  discard block
 block discarded – undo
1540 1612
 			$currentKey = 0;
1541 1613
 
1542 1614
 			// Create a key => value array for multiple options fields
1543
-			if (!empty($custom['options']))
1544
-				foreach ($custom['options'] as $k => $v)
1615
+			if (!empty($custom['options'])) {
1616
+							foreach ($custom['options'] as $k => $v)
1545 1617
 				{
1546 1618
 					$fieldOptions[] = $v;
1547
-					if (empty($currentKey))
1548
-						$currentKey = $v == $value ? $k : 0;
1619
+			}
1620
+					if (empty($currentKey)) {
1621
+											$currentKey = $v == $value ? $k : 0;
1622
+					}
1549 1623
 				}
1550 1624
 
1551 1625
 			// BBC?
1552
-			if ($custom['bbc'])
1553
-				$value = parse_bbc($value);
1626
+			if ($custom['bbc']) {
1627
+							$value = parse_bbc($value);
1628
+			}
1554 1629
 
1555 1630
 			// ... or checkbox?
1556
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1557
-				$value = $value ? $txt['yes'] : $txt['no'];
1631
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1632
+							$value = $value ? $txt['yes'] : $txt['no'];
1633
+			}
1558 1634
 
1559 1635
 			// Enclosing the user input within some other text?
1560
-			if (!empty($custom['enclose']))
1561
-				$value = strtr($custom['enclose'], array(
1636
+			if (!empty($custom['enclose'])) {
1637
+							$value = strtr($custom['enclose'], array(
1562 1638
 					'{SCRIPTURL}' => $scripturl,
1563 1639
 					'{IMAGES_URL}' => $settings['images_url'],
1564 1640
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1565 1641
 					'{INPUT}' => $value,
1566 1642
 					'{KEY}' => $currentKey,
1567 1643
 				));
1644
+			}
1568 1645
 
1569 1646
 			$memberContext[$user]['custom_fields'][] = array(
1570 1647
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1591,8 +1668,9 @@  discard block
 block discarded – undo
1591 1668
 	global $smcFunc, $txt, $scripturl, $settings;
1592 1669
 
1593 1670
 	// Do not waste my time...
1594
-	if (empty($users) || empty($params))
1595
-		return false;
1671
+	if (empty($users) || empty($params)) {
1672
+			return false;
1673
+	}
1596 1674
 
1597 1675
 	// Make sure it's an array.
1598 1676
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1619,41 +1697,48 @@  discard block
 block discarded – undo
1619 1697
 		$currentKey = 0;
1620 1698
 
1621 1699
 		// Create a key => value array for multiple options fields
1622
-		if (!empty($row['field_options']))
1623
-			foreach (explode(',', $row['field_options']) as $k => $v)
1700
+		if (!empty($row['field_options'])) {
1701
+					foreach (explode(',', $row['field_options']) as $k => $v)
1624 1702
 			{
1625 1703
 				$fieldOptions[] = $v;
1626
-				if (empty($currentKey))
1627
-					$currentKey = $v == $row['value'] ? $k : 0;
1704
+		}
1705
+				if (empty($currentKey)) {
1706
+									$currentKey = $v == $row['value'] ? $k : 0;
1707
+				}
1628 1708
 			}
1629 1709
 
1630 1710
 		// BBC?
1631
-		if (!empty($row['bbc']))
1632
-			$row['value'] = parse_bbc($row['value']);
1711
+		if (!empty($row['bbc'])) {
1712
+					$row['value'] = parse_bbc($row['value']);
1713
+		}
1633 1714
 
1634 1715
 		// ... or checkbox?
1635
-		elseif (isset($row['type']) && $row['type'] == 'check')
1636
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1716
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1717
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1718
+		}
1637 1719
 
1638 1720
 		// Enclosing the user input within some other text?
1639
-		if (!empty($row['enclose']))
1640
-			$row['value'] = strtr($row['enclose'], array(
1721
+		if (!empty($row['enclose'])) {
1722
+					$row['value'] = strtr($row['enclose'], array(
1641 1723
 				'{SCRIPTURL}' => $scripturl,
1642 1724
 				'{IMAGES_URL}' => $settings['images_url'],
1643 1725
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1644 1726
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1645 1727
 				'{KEY}' => $currentKey,
1646 1728
 			));
1729
+		}
1647 1730
 
1648 1731
 		// Send a simple array if there is just 1 param
1649
-		if (count($params) == 1)
1650
-			$return[$row['id_member']] = $row;
1732
+		if (count($params) == 1) {
1733
+					$return[$row['id_member']] = $row;
1734
+		}
1651 1735
 
1652 1736
 		// More than 1? knock yourself out...
1653 1737
 		else
1654 1738
 		{
1655
-			if (!isset($return[$row['id_member']]))
1656
-				$return[$row['id_member']] = array();
1739
+			if (!isset($return[$row['id_member']])) {
1740
+							$return[$row['id_member']] = array();
1741
+			}
1657 1742
 
1658 1743
 			$return[$row['id_member']][$row['variable']] = $row;
1659 1744
 		}
@@ -1687,8 +1772,9 @@  discard block
 block discarded – undo
1687 1772
 	global $context;
1688 1773
 
1689 1774
 	// Don't know any browser!
1690
-	if (empty($context['browser']))
1691
-		detectBrowser();
1775
+	if (empty($context['browser'])) {
1776
+			detectBrowser();
1777
+	}
1692 1778
 
1693 1779
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1694 1780
 }
@@ -1706,8 +1792,9 @@  discard block
 block discarded – undo
1706 1792
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1707 1793
 
1708 1794
 	// The theme was specified by parameter.
1709
-	if (!empty($id_theme))
1710
-		$id_theme = (int) $id_theme;
1795
+	if (!empty($id_theme)) {
1796
+			$id_theme = (int) $id_theme;
1797
+	}
1711 1798
 	// The theme was specified by REQUEST.
1712 1799
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1713 1800
 	{
@@ -1715,54 +1802,61 @@  discard block
 block discarded – undo
1715 1802
 		$_SESSION['id_theme'] = $id_theme;
1716 1803
 	}
1717 1804
 	// The theme was specified by REQUEST... previously.
1718
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1719
-		$id_theme = (int) $_SESSION['id_theme'];
1805
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1806
+			$id_theme = (int) $_SESSION['id_theme'];
1807
+	}
1720 1808
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1721
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1722
-		$id_theme = $user_info['theme'];
1809
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1810
+			$id_theme = $user_info['theme'];
1811
+	}
1723 1812
 	// The theme was specified by the board.
1724
-	elseif (!empty($board_info['theme']))
1725
-		$id_theme = $board_info['theme'];
1813
+	elseif (!empty($board_info['theme'])) {
1814
+			$id_theme = $board_info['theme'];
1815
+	}
1726 1816
 	// The theme is the forum's default.
1727
-	else
1728
-		$id_theme = $modSettings['theme_guests'];
1817
+	else {
1818
+			$id_theme = $modSettings['theme_guests'];
1819
+	}
1729 1820
 
1730 1821
 	// We already load the basic stuff?
1731 1822
 	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme )
1732 1823
 	{
1733 1824
 		// Verify the id_theme... no foul play.
1734 1825
 		// Always allow the board specific theme, if they are overriding.
1735
-		if (!empty($board_info['theme']) && $board_info['override_theme'])
1736
-			$id_theme = $board_info['theme'];
1826
+		if (!empty($board_info['theme']) && $board_info['override_theme']) {
1827
+					$id_theme = $board_info['theme'];
1828
+		}
1737 1829
 		// If they have specified a particular theme to use with SSI allow it to be used.
1738
-		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1739
-			$id_theme = (int) $id_theme;
1740
-		elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1830
+		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1831
+					$id_theme = (int) $id_theme;
1832
+		} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1741 1833
 		{
1742 1834
 			$themes = explode(',', $modSettings['enableThemes']);
1743
-			if (!in_array($id_theme, $themes))
1744
-				$id_theme = $modSettings['theme_guests'];
1745
-			else
1746
-				$id_theme = (int) $id_theme;
1835
+			if (!in_array($id_theme, $themes)) {
1836
+							$id_theme = $modSettings['theme_guests'];
1837
+			} else {
1838
+							$id_theme = (int) $id_theme;
1839
+			}
1840
+		} else {
1841
+					$id_theme = (int) $id_theme;
1747 1842
 		}
1748
-		else
1749
-			$id_theme = (int) $id_theme;
1750 1843
 
1751 1844
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1752 1845
 
1753 1846
 		// Disable image proxy if we don't have SSL enabled
1754
-		if (empty($modSettings['force_ssl']))
1755
-			$image_proxy_enabled = false;
1847
+		if (empty($modSettings['force_ssl'])) {
1848
+					$image_proxy_enabled = false;
1849
+		}
1756 1850
 
1757 1851
 		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'])
1758 1852
 		{
1759 1853
 			$themeData = $temp;
1760 1854
 			$flag = true;
1855
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1856
+					$themeData = $temp + array($member => array());
1857
+		} else {
1858
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1761 1859
 		}
1762
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1763
-			$themeData = $temp + array($member => array());
1764
-		else
1765
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1766 1860
 
1767 1861
 		if (empty($flag))
1768 1862
 		{
@@ -1781,31 +1875,37 @@  discard block
 block discarded – undo
1781 1875
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1782 1876
 			{
1783 1877
 				// There are just things we shouldn't be able to change as members.
1784
-				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')))
1785
-					continue;
1878
+				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'))) {
1879
+									continue;
1880
+				}
1786 1881
 
1787 1882
 				// If this is the theme_dir of the default theme, store it.
1788
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1789
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1883
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1884
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1885
+				}
1790 1886
 
1791 1887
 				// If this isn't set yet, is a theme option, or is not the default theme..
1792
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1793
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1888
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1889
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1890
+				}
1794 1891
 			}
1795 1892
 			$smcFunc['db_free_result']($result);
1796 1893
 
1797
-			if (!empty($themeData[-1]))
1798
-				foreach ($themeData[-1] as $k => $v)
1894
+			if (!empty($themeData[-1])) {
1895
+							foreach ($themeData[-1] as $k => $v)
1799 1896
 				{
1800 1897
 					if (!isset($themeData[$member][$k]))
1801 1898
 						$themeData[$member][$k] = $v;
1899
+			}
1802 1900
 				}
1803 1901
 
1804
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1805
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1902
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1903
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1904
+			}
1806 1905
 			// Only if we didn't already load that part of the cache...
1807
-			elseif (!isset($temp))
1808
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1906
+			elseif (!isset($temp)) {
1907
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1908
+			}
1809 1909
 		}
1810 1910
 
1811 1911
 		$settings = $themeData[0];
@@ -1822,17 +1922,20 @@  discard block
 block discarded – undo
1822 1922
 		$settings['template_dirs'][] = $settings['theme_dir'];
1823 1923
 
1824 1924
 		// Based on theme (if there is one).
1825
-		if (!empty($settings['base_theme_dir']))
1826
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1925
+		if (!empty($settings['base_theme_dir'])) {
1926
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1927
+		}
1827 1928
 
1828 1929
 		// Lastly the default theme.
1829
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1830
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1930
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1931
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1932
+		}
1831 1933
 	}
1832 1934
 
1833 1935
 
1834
-	if (!$initialize)
1835
-		return;
1936
+	if (!$initialize) {
1937
+			return;
1938
+	}
1836 1939
 
1837 1940
 	// Check to see if we're forcing SSL
1838 1941
 	if (!empty($modSettings['force_ssl']) && empty($maintenance) &&
@@ -1853,8 +1956,9 @@  discard block
 block discarded – undo
1853 1956
 		$detected_url = httpsOn() ? 'https://' : 'http://';
1854 1957
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1855 1958
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1856
-		if ($temp != '/')
1857
-			$detected_url .= $temp;
1959
+		if ($temp != '/') {
1960
+					$detected_url .= $temp;
1961
+		}
1858 1962
 	}
1859 1963
 	if (isset($detected_url) && $detected_url != $boardurl)
1860 1964
 	{
@@ -1866,8 +1970,9 @@  discard block
 block discarded – undo
1866 1970
 			foreach ($aliases as $alias)
1867 1971
 			{
1868 1972
 				// Rip off all the boring parts, spaces, etc.
1869
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1870
-					$do_fix = true;
1973
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1974
+									$do_fix = true;
1975
+				}
1871 1976
 			}
1872 1977
 		}
1873 1978
 
@@ -1875,21 +1980,23 @@  discard block
 block discarded – undo
1875 1980
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1876 1981
 		{
1877 1982
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1878
-			if (empty($_GET))
1879
-				redirectexit('wwwRedirect');
1880
-			else
1983
+			if (empty($_GET)) {
1984
+							redirectexit('wwwRedirect');
1985
+			} else
1881 1986
 			{
1882 1987
 				$k = key($_GET);
1883 1988
 				$v = current($_GET);
1884 1989
 
1885
-				if ($k != 'wwwRedirect')
1886
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1990
+				if ($k != 'wwwRedirect') {
1991
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1992
+				}
1887 1993
 			}
1888 1994
 		}
1889 1995
 
1890 1996
 		// #3 is just a check for SSL...
1891
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1892
-			$do_fix = true;
1997
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1998
+					$do_fix = true;
1999
+		}
1893 2000
 
1894 2001
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1895 2002
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1924,8 +2031,9 @@  discard block
 block discarded – undo
1924 2031
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1925 2032
 				}
1926 2033
 			}
1927
-			foreach ($context['linktree'] as $k => $dummy)
1928
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2034
+			foreach ($context['linktree'] as $k => $dummy) {
2035
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2036
+			}
1929 2037
 		}
1930 2038
 	}
1931 2039
 	// Set up the contextual user array.
@@ -1944,16 +2052,16 @@  discard block
 block discarded – undo
1944 2052
 			'email' => $user_info['email'],
1945 2053
 			'ignoreusers' => $user_info['ignoreusers'],
1946 2054
 		);
1947
-		if (!$context['user']['is_guest'])
1948
-			$context['user']['name'] = $user_info['name'];
1949
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1950
-			$context['user']['name'] = $txt['guest_title'];
2055
+		if (!$context['user']['is_guest']) {
2056
+					$context['user']['name'] = $user_info['name'];
2057
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2058
+					$context['user']['name'] = $txt['guest_title'];
2059
+		}
1951 2060
 
1952 2061
 		// Determine the current smiley set.
1953 2062
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1954 2063
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1955
-	}
1956
-	else
2064
+	} else
1957 2065
 	{
1958 2066
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1959 2067
 		$context['user'] = array(
@@ -1987,18 +2095,24 @@  discard block
 block discarded – undo
1987 2095
 	}
1988 2096
 
1989 2097
 	// Some basic information...
1990
-	if (!isset($context['html_headers']))
1991
-		$context['html_headers'] = '';
1992
-	if (!isset($context['javascript_files']))
1993
-		$context['javascript_files'] = array();
1994
-	if (!isset($context['css_files']))
1995
-		$context['css_files'] = array();
1996
-	if (!isset($context['css_header']))
1997
-		$context['css_header'] = array();
1998
-	if (!isset($context['javascript_inline']))
1999
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2000
-	if (!isset($context['javascript_vars']))
2001
-		$context['javascript_vars'] = array();
2098
+	if (!isset($context['html_headers'])) {
2099
+			$context['html_headers'] = '';
2100
+	}
2101
+	if (!isset($context['javascript_files'])) {
2102
+			$context['javascript_files'] = array();
2103
+	}
2104
+	if (!isset($context['css_files'])) {
2105
+			$context['css_files'] = array();
2106
+	}
2107
+	if (!isset($context['css_header'])) {
2108
+			$context['css_header'] = array();
2109
+	}
2110
+	if (!isset($context['javascript_inline'])) {
2111
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2112
+	}
2113
+	if (!isset($context['javascript_vars'])) {
2114
+			$context['javascript_vars'] = array();
2115
+	}
2002 2116
 
2003 2117
 	$context['login_url'] =  $scripturl . '?action=login2';
2004 2118
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -2010,16 +2124,18 @@  discard block
 block discarded – undo
2010 2124
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
2011 2125
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
2012 2126
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
2013
-	if (isset($modSettings['load_average']))
2014
-		$context['load_average'] = $modSettings['load_average'];
2127
+	if (isset($modSettings['load_average'])) {
2128
+			$context['load_average'] = $modSettings['load_average'];
2129
+	}
2015 2130
 
2016 2131
 	// Detect the browser. This is separated out because it's also used in attachment downloads
2017 2132
 	detectBrowser();
2018 2133
 
2019 2134
 	// Set the top level linktree up.
2020 2135
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2021
-	if (empty($context['linktree']))
2022
-		$context['linktree'] = array();
2136
+	if (empty($context['linktree'])) {
2137
+			$context['linktree'] = array();
2138
+	}
2023 2139
 	array_unshift($context['linktree'], array(
2024 2140
 		'url' => $scripturl,
2025 2141
 		'name' => $context['forum_name_html_safe']
@@ -2028,8 +2144,9 @@  discard block
 block discarded – undo
2028 2144
 	// This allows sticking some HTML on the page output - useful for controls.
2029 2145
 	$context['insert_after_template'] = '';
2030 2146
 
2031
-	if (!isset($txt))
2032
-		$txt = array();
2147
+	if (!isset($txt)) {
2148
+			$txt = array();
2149
+	}
2033 2150
 
2034 2151
 	$simpleActions = array(
2035 2152
 		'findmember',
@@ -2075,9 +2192,10 @@  discard block
 block discarded – undo
2075 2192
 
2076 2193
 	// See if theres any extra param to check.
2077 2194
 	$requiresXML = false;
2078
-	foreach ($extraParams as $key => $extra)
2079
-		if (isset($_REQUEST[$extra]))
2195
+	foreach ($extraParams as $key => $extra) {
2196
+			if (isset($_REQUEST[$extra]))
2080 2197
 			$requiresXML = true;
2198
+	}
2081 2199
 
2082 2200
 	// Output is fully XML, so no need for the index template.
2083 2201
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2092,37 +2210,39 @@  discard block
 block discarded – undo
2092 2210
 	{
2093 2211
 		loadLanguage('index+Modifications');
2094 2212
 		$context['template_layers'] = array();
2095
-	}
2096
-
2097
-	else
2213
+	} else
2098 2214
 	{
2099 2215
 		// Custom templates to load, or just default?
2100
-		if (isset($settings['theme_templates']))
2101
-			$templates = explode(',', $settings['theme_templates']);
2102
-		else
2103
-			$templates = array('index');
2216
+		if (isset($settings['theme_templates'])) {
2217
+					$templates = explode(',', $settings['theme_templates']);
2218
+		} else {
2219
+					$templates = array('index');
2220
+		}
2104 2221
 
2105 2222
 		// Load each template...
2106
-		foreach ($templates as $template)
2107
-			loadTemplate($template);
2223
+		foreach ($templates as $template) {
2224
+					loadTemplate($template);
2225
+		}
2108 2226
 
2109 2227
 		// ...and attempt to load their associated language files.
2110 2228
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2111 2229
 		loadLanguage($required_files, '', false);
2112 2230
 
2113 2231
 		// Custom template layers?
2114
-		if (isset($settings['theme_layers']))
2115
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2116
-		else
2117
-			$context['template_layers'] = array('html', 'body');
2232
+		if (isset($settings['theme_layers'])) {
2233
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2234
+		} else {
2235
+					$context['template_layers'] = array('html', 'body');
2236
+		}
2118 2237
 	}
2119 2238
 
2120 2239
 	// Initialize the theme.
2121 2240
 	loadSubTemplate('init', 'ignore');
2122 2241
 
2123 2242
 	// Allow overriding the board wide time/number formats.
2124
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2125
-		$user_info['time_format'] = $txt['time_format'];
2243
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2244
+			$user_info['time_format'] = $txt['time_format'];
2245
+	}
2126 2246
 
2127 2247
 	// Set the character set from the template.
2128 2248
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2130,12 +2250,14 @@  discard block
 block discarded – undo
2130 2250
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2131 2251
 
2132 2252
 	// Guests may still need a name.
2133
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2134
-		$context['user']['name'] = $txt['guest_title'];
2253
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2254
+			$context['user']['name'] = $txt['guest_title'];
2255
+	}
2135 2256
 
2136 2257
 	// Any theme-related strings that need to be loaded?
2137
-	if (!empty($settings['require_theme_strings']))
2138
-		loadLanguage('ThemeStrings', '', false);
2258
+	if (!empty($settings['require_theme_strings'])) {
2259
+			loadLanguage('ThemeStrings', '', false);
2260
+	}
2139 2261
 
2140 2262
 	// Make a special URL for the language.
2141 2263
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2146,8 +2268,9 @@  discard block
 block discarded – undo
2146 2268
 	// Here is my luvly Responsive CSS
2147 2269
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive');
2148 2270
 
2149
-	if ($context['right_to_left'])
2150
-		loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2271
+	if ($context['right_to_left']) {
2272
+			loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2273
+	}
2151 2274
 
2152 2275
 	// We allow theme variants, because we're cool.
2153 2276
 	$context['theme_variant'] = '';
@@ -2155,14 +2278,17 @@  discard block
 block discarded – undo
2155 2278
 	if (!empty($settings['theme_variants']))
2156 2279
 	{
2157 2280
 		// Overriding - for previews and that ilk.
2158
-		if (!empty($_REQUEST['variant']))
2159
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2281
+		if (!empty($_REQUEST['variant'])) {
2282
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2283
+		}
2160 2284
 		// User selection?
2161
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2162
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2285
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2286
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2287
+		}
2163 2288
 		// If not a user variant, select the default.
2164
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2165
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2289
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2290
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2291
+		}
2166 2292
 
2167 2293
 		// Do this to keep things easier in the templates.
2168 2294
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2171,20 +2297,23 @@  discard block
 block discarded – undo
2171 2297
 		if (!empty($context['theme_variant']))
2172 2298
 		{
2173 2299
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']);
2174
-			if ($context['right_to_left'])
2175
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2300
+			if ($context['right_to_left']) {
2301
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2302
+			}
2176 2303
 		}
2177 2304
 	}
2178 2305
 
2179 2306
 	// Let's be compatible with old themes!
2180
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2181
-		$context['template_layers'] = array('main');
2307
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2308
+			$context['template_layers'] = array('main');
2309
+	}
2182 2310
 
2183 2311
 	$context['tabindex'] = 1;
2184 2312
 
2185 2313
 	// Compatibility.
2186
-	if (!isset($settings['theme_version']))
2187
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2314
+	if (!isset($settings['theme_version'])) {
2315
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2316
+	}
2188 2317
 
2189 2318
 	// Default JS variables for use in every theme
2190 2319
 	$context['javascript_vars'] = array(
@@ -2203,18 +2332,18 @@  discard block
 block discarded – undo
2203 2332
 	);
2204 2333
 
2205 2334
 	// Add the JQuery library to the list of files to load.
2206
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2207
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2208
-
2209
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2210
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2211
-
2212
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2213
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2335
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2336
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2337
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2338
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2339
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2340
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2341
+	}
2214 2342
 
2215 2343
 	// Auto loading? template_javascript() will take care of the local half of this.
2216
-	else
2217
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2344
+	else {
2345
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2346
+	}
2218 2347
 
2219 2348
 	// Queue our JQuery plugins!
2220 2349
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2237,12 +2366,12 @@  discard block
 block discarded – undo
2237 2366
 			require_once($sourcedir . '/ScheduledTasks.php');
2238 2367
 
2239 2368
 			// What to do, what to do?!
2240
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2241
-				AutoTask();
2242
-			else
2243
-				ReduceMailQueue();
2244
-		}
2245
-		else
2369
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2370
+							AutoTask();
2371
+			} else {
2372
+							ReduceMailQueue();
2373
+			}
2374
+		} else
2246 2375
 		{
2247 2376
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2248 2377
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2293,8 +2422,9 @@  discard block
 block discarded – undo
2293 2422
 		foreach ($theme_includes as $include)
2294 2423
 		{
2295 2424
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2296
-			if (file_exists($include))
2297
-				require_once($include);
2425
+			if (file_exists($include)) {
2426
+							require_once($include);
2427
+			}
2298 2428
 		}
2299 2429
 	}
2300 2430
 
@@ -2324,16 +2454,19 @@  discard block
 block discarded – undo
2324 2454
 	// Do any style sheets first, cause we're easy with those.
2325 2455
 	if (!empty($style_sheets))
2326 2456
 	{
2327
-		if (!is_array($style_sheets))
2328
-			$style_sheets = array($style_sheets);
2457
+		if (!is_array($style_sheets)) {
2458
+					$style_sheets = array($style_sheets);
2459
+		}
2329 2460
 
2330
-		foreach ($style_sheets as $sheet)
2331
-			loadCSSFile($sheet . '.css', array(), $sheet);
2461
+		foreach ($style_sheets as $sheet) {
2462
+					loadCSSFile($sheet . '.css', array(), $sheet);
2463
+		}
2332 2464
 	}
2333 2465
 
2334 2466
 	// No template to load?
2335
-	if ($template_name === false)
2336
-		return true;
2467
+	if ($template_name === false) {
2468
+			return true;
2469
+	}
2337 2470
 
2338 2471
 	$loaded = false;
2339 2472
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2348,12 +2481,14 @@  discard block
 block discarded – undo
2348 2481
 
2349 2482
 	if ($loaded)
2350 2483
 	{
2351
-		if ($db_show_debug === true)
2352
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2484
+		if ($db_show_debug === true) {
2485
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2486
+		}
2353 2487
 
2354 2488
 		// If they have specified an initialization function for this template, go ahead and call it now.
2355
-		if (function_exists('template_' . $template_name . '_init'))
2356
-			call_user_func('template_' . $template_name . '_init');
2489
+		if (function_exists('template_' . $template_name . '_init')) {
2490
+					call_user_func('template_' . $template_name . '_init');
2491
+		}
2357 2492
 	}
2358 2493
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2359 2494
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2373,13 +2508,14 @@  discard block
 block discarded – undo
2373 2508
 		loadTemplate($template_name);
2374 2509
 	}
2375 2510
 	// Cause an error otherwise.
2376
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2377
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2378
-	elseif ($fatal)
2379
-		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'));
2380
-	else
2381
-		return false;
2382
-}
2511
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2512
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2513
+	} elseif ($fatal) {
2514
+			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'));
2515
+	} else {
2516
+			return false;
2517
+	}
2518
+	}
2383 2519
 
2384 2520
 /**
2385 2521
  * Load a sub-template.
@@ -2397,17 +2533,19 @@  discard block
 block discarded – undo
2397 2533
 {
2398 2534
 	global $context, $txt, $db_show_debug;
2399 2535
 
2400
-	if ($db_show_debug === true)
2401
-		$context['debug']['sub_templates'][] = $sub_template_name;
2536
+	if ($db_show_debug === true) {
2537
+			$context['debug']['sub_templates'][] = $sub_template_name;
2538
+	}
2402 2539
 
2403 2540
 	// Figure out what the template function is named.
2404 2541
 	$theme_function = 'template_' . $sub_template_name;
2405
-	if (function_exists($theme_function))
2406
-		$theme_function();
2407
-	elseif ($fatal === false)
2408
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2409
-	elseif ($fatal !== 'ignore')
2410
-		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'));
2542
+	if (function_exists($theme_function)) {
2543
+			$theme_function();
2544
+	} elseif ($fatal === false) {
2545
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2546
+	} elseif ($fatal !== 'ignore') {
2547
+			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'));
2548
+	}
2411 2549
 
2412 2550
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2413 2551
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2437,8 +2575,9 @@  discard block
 block discarded – undo
2437 2575
 {
2438 2576
 	global $settings, $context, $modSettings;
2439 2577
 
2440
-	if (empty($context['css_files_order']))
2441
-		$context['css_files_order'] = array();
2578
+	if (empty($context['css_files_order'])) {
2579
+			$context['css_files_order'] = array();
2580
+	}
2442 2581
 
2443 2582
 	$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']) : '');
2444 2583
 	$params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false;
@@ -2449,8 +2588,9 @@  discard block
 block discarded – undo
2449 2588
 	$params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000;
2450 2589
 
2451 2590
 	// If this is an external file, automatically set this to false.
2452
-	if (!empty($params['external']))
2453
-		$params['minimize'] = false;
2591
+	if (!empty($params['external'])) {
2592
+			$params['minimize'] = false;
2593
+	}
2454 2594
 
2455 2595
 	// Account for shorthand like admin.css?alp21 filenames
2456 2596
 	$has_seed = strpos($fileName, '.css?');
@@ -2467,16 +2607,12 @@  discard block
 block discarded – undo
2467 2607
 			{
2468 2608
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2469 2609
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2470
-			}
2471
-
2472
-			else
2610
+			} else
2473 2611
 			{
2474 2612
 				$fileUrl = false;
2475 2613
 				$filePath = false;
2476 2614
 			}
2477
-		}
2478
-
2479
-		else
2615
+		} else
2480 2616
 		{
2481 2617
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2482 2618
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2494,16 +2630,18 @@  discard block
 block discarded – undo
2494 2630
 	if (!empty($fileName))
2495 2631
 	{
2496 2632
 		// find a free number/position
2497
-		while (isset($context['css_files_order'][$params['order_pos']]))
2498
-			$params['order_pos']++;
2633
+		while (isset($context['css_files_order'][$params['order_pos']])) {
2634
+					$params['order_pos']++;
2635
+		}
2499 2636
 		$context['css_files_order'][$params['order_pos']] = $id;
2500 2637
 
2501 2638
 		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2502 2639
 	}
2503 2640
 
2504
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2505
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2506
-}
2641
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2642
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2643
+	}
2644
+	}
2507 2645
 
2508 2646
 /**
2509 2647
  * Add a block of inline css code to be executed later
@@ -2520,8 +2658,9 @@  discard block
 block discarded – undo
2520 2658
 	global $context;
2521 2659
 
2522 2660
 	// Gotta add something...
2523
-	if (empty($css))
2524
-		return false;
2661
+	if (empty($css)) {
2662
+			return false;
2663
+	}
2525 2664
 
2526 2665
 	$context['css_header'][] = $css;
2527 2666
 }
@@ -2556,8 +2695,9 @@  discard block
 block discarded – undo
2556 2695
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2557 2696
 
2558 2697
 	// If this is an external file, automatically set this to false.
2559
-	if (!empty($params['external']))
2560
-		$params['minimize'] = false;
2698
+	if (!empty($params['external'])) {
2699
+			$params['minimize'] = false;
2700
+	}
2561 2701
 
2562 2702
 	// Account for shorthand like admin.js?alp21 filenames
2563 2703
 	$has_seed = strpos($fileName, '.js?');
@@ -2574,16 +2714,12 @@  discard block
 block discarded – undo
2574 2714
 			{
2575 2715
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2576 2716
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2577
-			}
2578
-
2579
-			else
2717
+			} else
2580 2718
 			{
2581 2719
 				$fileUrl = false;
2582 2720
 				$filePath = false;
2583 2721
 			}
2584
-		}
2585
-
2586
-		else
2722
+		} else
2587 2723
 		{
2588 2724
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2589 2725
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2598,9 +2734,10 @@  discard block
 block discarded – undo
2598 2734
 	}
2599 2735
 
2600 2736
 	// Add it to the array for use in the template
2601
-	if (!empty($fileName))
2602
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2603
-}
2737
+	if (!empty($fileName)) {
2738
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2739
+	}
2740
+	}
2604 2741
 
2605 2742
 /**
2606 2743
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2614,9 +2751,10 @@  discard block
 block discarded – undo
2614 2751
 {
2615 2752
 	global $context;
2616 2753
 
2617
-	if (!empty($key) && (!empty($value) || $value === '0'))
2618
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2619
-}
2754
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2755
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2756
+	}
2757
+	}
2620 2758
 
2621 2759
 /**
2622 2760
  * Add a block of inline Javascript code to be executed later
@@ -2633,8 +2771,9 @@  discard block
 block discarded – undo
2633 2771
 {
2634 2772
 	global $context;
2635 2773
 
2636
-	if (empty($javascript))
2637
-		return false;
2774
+	if (empty($javascript)) {
2775
+			return false;
2776
+	}
2638 2777
 
2639 2778
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2640 2779
 }
@@ -2655,15 +2794,18 @@  discard block
 block discarded – undo
2655 2794
 	static $already_loaded = array();
2656 2795
 
2657 2796
 	// Default to the user's language.
2658
-	if ($lang == '')
2659
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2797
+	if ($lang == '') {
2798
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2799
+	}
2660 2800
 
2661 2801
 	// Do we want the English version of language file as fallback?
2662
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2663
-		loadLanguage($template_name, 'english', false);
2802
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2803
+			loadLanguage($template_name, 'english', false);
2804
+	}
2664 2805
 
2665
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2666
-		return $lang;
2806
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2807
+			return $lang;
2808
+	}
2667 2809
 
2668 2810
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2669 2811
 	if (empty($settings['default_theme_dir']))
@@ -2674,8 +2816,9 @@  discard block
 block discarded – undo
2674 2816
 
2675 2817
 	// What theme are we in?
2676 2818
 	$theme_name = basename($settings['theme_url']);
2677
-	if (empty($theme_name))
2678
-		$theme_name = 'unknown';
2819
+	if (empty($theme_name)) {
2820
+			$theme_name = 'unknown';
2821
+	}
2679 2822
 
2680 2823
 	// For each file open it up and write it out!
2681 2824
 	foreach (explode('+', $template_name) as $template)
@@ -2717,8 +2860,9 @@  discard block
 block discarded – undo
2717 2860
 				$found = true;
2718 2861
 
2719 2862
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2720
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2721
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2863
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2864
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2865
+				}
2722 2866
 
2723 2867
 				break;
2724 2868
 			}
@@ -2758,8 +2902,9 @@  discard block
 block discarded – undo
2758 2902
 	}
2759 2903
 
2760 2904
 	// Keep track of what we're up to soldier.
2761
-	if ($db_show_debug === true)
2762
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2905
+	if ($db_show_debug === true) {
2906
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2907
+	}
2763 2908
 
2764 2909
 	// Remember what we have loaded, and in which language.
2765 2910
 	$already_loaded[$template_name] = $lang;
@@ -2805,8 +2950,9 @@  discard block
 block discarded – undo
2805 2950
 				)
2806 2951
 			);
2807 2952
 			// In the EXTREMELY unlikely event this happens, give an error message.
2808
-			if ($smcFunc['db_num_rows']($result) == 0)
2809
-				fatal_lang_error('parent_not_found', 'critical');
2953
+			if ($smcFunc['db_num_rows']($result) == 0) {
2954
+							fatal_lang_error('parent_not_found', 'critical');
2955
+			}
2810 2956
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2811 2957
 			{
2812 2958
 				if (!isset($boards[$row['id_board']]))
@@ -2823,8 +2969,8 @@  discard block
 block discarded – undo
2823 2969
 					);
2824 2970
 				}
2825 2971
 				// If a moderator exists for this board, add that moderator for all children too.
2826
-				if (!empty($row['id_moderator']))
2827
-					foreach ($boards as $id => $dummy)
2972
+				if (!empty($row['id_moderator'])) {
2973
+									foreach ($boards as $id => $dummy)
2828 2974
 					{
2829 2975
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2830 2976
 							'id' => $row['id_moderator'],
@@ -2832,11 +2978,12 @@  discard block
 block discarded – undo
2832 2978
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2833 2979
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2834 2980
 						);
2981
+				}
2835 2982
 					}
2836 2983
 
2837 2984
 				// If a moderator group exists for this board, add that moderator group for all children too
2838
-				if (!empty($row['id_moderator_group']))
2839
-					foreach ($boards as $id => $dummy)
2985
+				if (!empty($row['id_moderator_group'])) {
2986
+									foreach ($boards as $id => $dummy)
2840 2987
 					{
2841 2988
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2842 2989
 							'id' => $row['id_moderator_group'],
@@ -2844,6 +2991,7 @@  discard block
 block discarded – undo
2844 2991
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2845 2992
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2846 2993
 						);
2994
+				}
2847 2995
 					}
2848 2996
 			}
2849 2997
 			$smcFunc['db_free_result']($result);
@@ -2870,23 +3018,27 @@  discard block
 block discarded – undo
2870 3018
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2871 3019
 	{
2872 3020
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2873
-		if (empty($smcFunc['ucwords']))
2874
-			reloadSettings();
3021
+		if (empty($smcFunc['ucwords'])) {
3022
+					reloadSettings();
3023
+		}
2875 3024
 
2876 3025
 		// If we don't have our theme information yet, let's get it.
2877
-		if (empty($settings['default_theme_dir']))
2878
-			loadTheme(0, false);
3026
+		if (empty($settings['default_theme_dir'])) {
3027
+					loadTheme(0, false);
3028
+		}
2879 3029
 
2880 3030
 		// Default language directories to try.
2881 3031
 		$language_directories = array(
2882 3032
 			$settings['default_theme_dir'] . '/languages',
2883 3033
 		);
2884
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2885
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3034
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
3035
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3036
+		}
2886 3037
 
2887 3038
 		// We possibly have a base theme directory.
2888
-		if (!empty($settings['base_theme_dir']))
2889
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3039
+		if (!empty($settings['base_theme_dir'])) {
3040
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3041
+		}
2890 3042
 
2891 3043
 		// Remove any duplicates.
2892 3044
 		$language_directories = array_unique($language_directories);
@@ -2900,20 +3052,21 @@  discard block
 block discarded – undo
2900 3052
 		foreach ($language_directories as $language_dir)
2901 3053
 		{
2902 3054
 			// Can't look in here... doesn't exist!
2903
-			if (!file_exists($language_dir))
2904
-				continue;
3055
+			if (!file_exists($language_dir)) {
3056
+							continue;
3057
+			}
2905 3058
 
2906 3059
 			$dir = dir($language_dir);
2907 3060
 			while ($entry = $dir->read())
2908 3061
 			{
2909 3062
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2910
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2911
-					continue;
2912
-
2913
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2914
-					$langName = $langList[$matches[1]];
3063
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3064
+									continue;
3065
+				}
2915 3066
 
2916
-				else
3067
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3068
+									$langName = $langList[$matches[1]];
3069
+				} else
2917 3070
 				{
2918 3071
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2919 3072
 
@@ -2954,12 +3107,14 @@  discard block
 block discarded – undo
2954 3107
 		}
2955 3108
 
2956 3109
 		// Do we need to store the lang list?
2957
-		if (empty($langList))
2958
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3110
+		if (empty($langList)) {
3111
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3112
+		}
2959 3113
 
2960 3114
 		// Let's cash in on this deal.
2961
-		if (!empty($modSettings['cache_enable']))
2962
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3115
+		if (!empty($modSettings['cache_enable'])) {
3116
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3117
+		}
2963 3118
 	}
2964 3119
 
2965 3120
 	return $context['languages'];
@@ -2982,8 +3137,9 @@  discard block
 block discarded – undo
2982 3137
 	global $modSettings, $options, $txt;
2983 3138
 	static $censor_vulgar = null, $censor_proper;
2984 3139
 
2985
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2986
-		return $text;
3140
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3141
+			return $text;
3142
+	}
2987 3143
 
2988 3144
 	// If they haven't yet been loaded, load them.
2989 3145
 	if ($censor_vulgar == null)
@@ -3014,9 +3170,9 @@  discard block
 block discarded – undo
3014 3170
 	{
3015 3171
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
3016 3172
 		$text = $func($censor_vulgar, $censor_proper, $text);
3173
+	} else {
3174
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
3017 3175
 	}
3018
-	else
3019
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
3020 3176
 
3021 3177
 	return $text;
3022 3178
 }
@@ -3042,38 +3198,42 @@  discard block
 block discarded – undo
3042 3198
 	@ini_set('track_errors', '1');
3043 3199
 
3044 3200
 	// Don't include the file more than once, if $once is true.
3045
-	if ($once && in_array($filename, $templates))
3046
-		return;
3201
+	if ($once && in_array($filename, $templates)) {
3202
+			return;
3203
+	}
3047 3204
 	// Add this file to the include list, whether $once is true or not.
3048
-	else
3049
-		$templates[] = $filename;
3205
+	else {
3206
+			$templates[] = $filename;
3207
+	}
3050 3208
 
3051 3209
 	// Are we going to use eval?
3052 3210
 	if (empty($modSettings['disableTemplateEval']))
3053 3211
 	{
3054 3212
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
3055 3213
 		$settings['current_include_filename'] = $filename;
3056
-	}
3057
-	else
3214
+	} else
3058 3215
 	{
3059 3216
 		$file_found = file_exists($filename);
3060 3217
 
3061
-		if ($once && $file_found)
3062
-			require_once($filename);
3063
-		elseif ($file_found)
3064
-			require($filename);
3218
+		if ($once && $file_found) {
3219
+					require_once($filename);
3220
+		} elseif ($file_found) {
3221
+					require($filename);
3222
+		}
3065 3223
 	}
3066 3224
 
3067 3225
 	if ($file_found !== true)
3068 3226
 	{
3069 3227
 		ob_end_clean();
3070
-		if (!empty($modSettings['enableCompressedOutput']))
3071
-			@ob_start('ob_gzhandler');
3072
-		else
3073
-			ob_start();
3228
+		if (!empty($modSettings['enableCompressedOutput'])) {
3229
+					@ob_start('ob_gzhandler');
3230
+		} else {
3231
+					ob_start();
3232
+		}
3074 3233
 
3075
-		if (isset($_GET['debug']))
3076
-			header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3234
+		if (isset($_GET['debug'])) {
3235
+					header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3236
+		}
3077 3237
 
3078 3238
 		// Don't cache error pages!!
3079 3239
 		header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3092,12 +3252,13 @@  discard block
 block discarded – undo
3092 3252
 		echo '<!DOCTYPE html>
3093 3253
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3094 3254
 	<head>';
3095
-		if (isset($context['character_set']))
3096
-			echo '
3255
+		if (isset($context['character_set'])) {
3256
+					echo '
3097 3257
 		<meta charset="', $context['character_set'], '">';
3258
+		}
3098 3259
 
3099
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3100
-			echo '
3260
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3261
+					echo '
3101 3262
 		<title>', $mtitle, '</title>
3102 3263
 	</head>
3103 3264
 	<body>
@@ -3105,8 +3266,8 @@  discard block
 block discarded – undo
3105 3266
 		', $mmessage, '
3106 3267
 	</body>
3107 3268
 </html>';
3108
-		elseif (!allowedTo('admin_forum'))
3109
-			echo '
3269
+		} elseif (!allowedTo('admin_forum')) {
3270
+					echo '
3110 3271
 		<title>', $txt['template_parse_error'], '</title>
3111 3272
 	</head>
3112 3273
 	<body>
@@ -3114,14 +3275,16 @@  discard block
 block discarded – undo
3114 3275
 		', $txt['template_parse_error_message'], '
3115 3276
 	</body>
3116 3277
 </html>';
3117
-		else
3278
+		} else
3118 3279
 		{
3119 3280
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3120 3281
 			$error_array = error_get_last();
3121
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3122
-				$error = $error_array['message'];
3123
-			if (empty($error))
3124
-				$error = $txt['template_parse_errmsg'];
3282
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3283
+							$error = $error_array['message'];
3284
+			}
3285
+			if (empty($error)) {
3286
+							$error = $txt['template_parse_errmsg'];
3287
+			}
3125 3288
 
3126 3289
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3127 3290
 
@@ -3132,11 +3295,12 @@  discard block
 block discarded – undo
3132 3295
 		<h3>', $txt['template_parse_error'], '</h3>
3133 3296
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3134 3297
 
3135
-			if (!empty($error))
3136
-				echo '
3298
+			if (!empty($error)) {
3299
+							echo '
3137 3300
 		<hr>
3138 3301
 
3139 3302
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3303
+			}
3140 3304
 
3141 3305
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3142 3306
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3146,10 +3310,11 @@  discard block
 block discarded – undo
3146 3310
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3147 3311
 
3148 3312
 				// Fix the PHP code stuff...
3149
-				if (!isBrowser('gecko'))
3150
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3151
-				else
3152
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3313
+				if (!isBrowser('gecko')) {
3314
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3315
+				} else {
3316
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3317
+				}
3153 3318
 
3154 3319
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3155 3320
 				$j = -1;
@@ -3157,8 +3322,9 @@  discard block
 block discarded – undo
3157 3322
 				{
3158 3323
 					$j++;
3159 3324
 
3160
-					if (substr_count($line, '<br>') == 0)
3161
-						continue;
3325
+					if (substr_count($line, '<br>') == 0) {
3326
+											continue;
3327
+					}
3162 3328
 
3163 3329
 					$n = substr_count($line, '<br>');
3164 3330
 					for ($i = 0; $i < $n; $i++)
@@ -3177,38 +3343,42 @@  discard block
 block discarded – undo
3177 3343
 				// Figure out what the color coding was before...
3178 3344
 				$line = max($match[1] - 9, 1);
3179 3345
 				$last_line = '';
3180
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3181
-					if (strpos($data2[$line2], '<') !== false)
3346
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3347
+									if (strpos($data2[$line2], '<') !== false)
3182 3348
 					{
3183 3349
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3184 3350
 							$last_line = $color_match[1];
3351
+				}
3185 3352
 						break;
3186 3353
 					}
3187 3354
 
3188 3355
 				// Show the relevant lines...
3189 3356
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3190 3357
 				{
3191
-					if ($line == $match[1])
3192
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3358
+					if ($line == $match[1]) {
3359
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3360
+					}
3193 3361
 
3194 3362
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3195
-					if (isset($data2[$line]) && $data2[$line] != '')
3196
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3363
+					if (isset($data2[$line]) && $data2[$line] != '') {
3364
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3365
+					}
3197 3366
 
3198 3367
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3199 3368
 					{
3200 3369
 						$last_line = $color_match[1];
3201 3370
 						echo '</', substr($last_line, 1, 4), '>';
3371
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3372
+											$last_line = '';
3373
+					} elseif ($last_line != '' && $data2[$line] != '') {
3374
+											echo '</', substr($last_line, 1, 4), '>';
3202 3375
 					}
3203
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3204
-						$last_line = '';
3205
-					elseif ($last_line != '' && $data2[$line] != '')
3206
-						echo '</', substr($last_line, 1, 4), '>';
3207 3376
 
3208
-					if ($line == $match[1])
3209
-						echo '</pre></div><pre style="margin: 0;">';
3210
-					else
3211
-						echo "\n";
3377
+					if ($line == $match[1]) {
3378
+											echo '</pre></div><pre style="margin: 0;">';
3379
+					} else {
3380
+											echo "\n";
3381
+					}
3212 3382
 				}
3213 3383
 
3214 3384
 				echo '</pre></div>';
@@ -3232,8 +3402,9 @@  discard block
 block discarded – undo
3232 3402
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3233 3403
 
3234 3404
 	// Figure out what type of database we are using.
3235
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3236
-		$db_type = 'mysql';
3405
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3406
+			$db_type = 'mysql';
3407
+	}
3237 3408
 
3238 3409
 	// Load the file for the database.
3239 3410
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3241,8 +3412,9 @@  discard block
 block discarded – undo
3241 3412
 	$db_options = array();
3242 3413
 
3243 3414
 	// Add in the port if needed
3244
-	if (!empty($db_port))
3245
-		$db_options['port'] = $db_port;
3415
+	if (!empty($db_port)) {
3416
+			$db_options['port'] = $db_port;
3417
+	}
3246 3418
 
3247 3419
 	// 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.
3248 3420
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3261,13 +3433,15 @@  discard block
 block discarded – undo
3261 3433
 	}
3262 3434
 
3263 3435
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3264
-	if (!$db_connection)
3265
-		display_db_error();
3436
+	if (!$db_connection) {
3437
+			display_db_error();
3438
+	}
3266 3439
 
3267 3440
 	// If in SSI mode fix up the prefix.
3268
-	if (SMF == 'SSI')
3269
-		db_fix_prefix($db_prefix, $db_name);
3270
-}
3441
+	if (SMF == 'SSI') {
3442
+			db_fix_prefix($db_prefix, $db_name);
3443
+	}
3444
+	}
3271 3445
 
3272 3446
 /**
3273 3447
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3281,10 +3455,11 @@  discard block
 block discarded – undo
3281 3455
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3282 3456
 
3283 3457
 	// Not overriding this and we have a cacheAPI, send it back.
3284
-	if (empty($overrideCache) && is_object($cacheAPI))
3285
-		return $cacheAPI;
3286
-	elseif (is_null($cacheAPI))
3287
-		$cacheAPI = false;
3458
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3459
+			return $cacheAPI;
3460
+	} elseif (is_null($cacheAPI)) {
3461
+			$cacheAPI = false;
3462
+	}
3288 3463
 
3289 3464
 	// Make sure our class is in session.
3290 3465
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3305,8 +3480,9 @@  discard block
 block discarded – undo
3305 3480
 		if (!$testAPI->isSupported())
3306 3481
 		{
3307 3482
 			// Can we save ourselves?
3308
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3309
-				return loadCacheAccelerator(null, false);
3483
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3484
+							return loadCacheAccelerator(null, false);
3485
+			}
3310 3486
 			return false;
3311 3487
 		}
3312 3488
 
@@ -3318,9 +3494,9 @@  discard block
 block discarded – undo
3318 3494
 		{
3319 3495
 			$cacheAPI = $testAPI;
3320 3496
 			return $cacheAPI;
3497
+		} else {
3498
+					return $testAPI;
3321 3499
 		}
3322
-		else
3323
-			return $testAPI;
3324 3500
 	}
3325 3501
 }
3326 3502
 
@@ -3340,8 +3516,9 @@  discard block
 block discarded – undo
3340 3516
 
3341 3517
 	// @todo Why are we doing this if caching is disabled?
3342 3518
 
3343
-	if (function_exists('call_integration_hook'))
3344
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3519
+	if (function_exists('call_integration_hook')) {
3520
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3521
+	}
3345 3522
 
3346 3523
 	/* Refresh the cache if either:
3347 3524
 		1. Caching is disabled.
@@ -3355,16 +3532,19 @@  discard block
 block discarded – undo
3355 3532
 		require_once($sourcedir . '/' . $file);
3356 3533
 		$cache_block = call_user_func_array($function, $params);
3357 3534
 
3358
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3359
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3535
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3536
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3537
+		}
3360 3538
 	}
3361 3539
 
3362 3540
 	// Some cached data may need a freshening up after retrieval.
3363
-	if (!empty($cache_block['post_retri_eval']))
3364
-		eval($cache_block['post_retri_eval']);
3541
+	if (!empty($cache_block['post_retri_eval'])) {
3542
+			eval($cache_block['post_retri_eval']);
3543
+	}
3365 3544
 
3366
-	if (function_exists('call_integration_hook'))
3367
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3545
+	if (function_exists('call_integration_hook')) {
3546
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3547
+	}
3368 3548
 
3369 3549
 	return $cache_block['data'];
3370 3550
 }
@@ -3391,8 +3571,9 @@  discard block
 block discarded – undo
3391 3571
 	global $smcFunc, $cache_enable, $cacheAPI;
3392 3572
 	global $cache_hits, $cache_count, $db_show_debug;
3393 3573
 
3394
-	if (empty($cache_enable) || empty($cacheAPI))
3395
-		return;
3574
+	if (empty($cache_enable) || empty($cacheAPI)) {
3575
+			return;
3576
+	}
3396 3577
 
3397 3578
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3398 3579
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3405,12 +3586,14 @@  discard block
 block discarded – undo
3405 3586
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3406 3587
 	$cacheAPI->putData($key, $value, $ttl);
3407 3588
 
3408
-	if (function_exists('call_integration_hook'))
3409
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3589
+	if (function_exists('call_integration_hook')) {
3590
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3591
+	}
3410 3592
 
3411
-	if (isset($db_show_debug) && $db_show_debug === true)
3412
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3413
-}
3593
+	if (isset($db_show_debug) && $db_show_debug === true) {
3594
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3595
+	}
3596
+	}
3414 3597
 
3415 3598
 /**
3416 3599
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3426,8 +3609,9 @@  discard block
 block discarded – undo
3426 3609
 	global $smcFunc, $cache_enable, $cacheAPI;
3427 3610
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3428 3611
 
3429
-	if (empty($cache_enable) || empty($cacheAPI))
3430
-		return;
3612
+	if (empty($cache_enable) || empty($cacheAPI)) {
3613
+			return;
3614
+	}
3431 3615
 
3432 3616
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3433 3617
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3447,16 +3631,18 @@  discard block
 block discarded – undo
3447 3631
 
3448 3632
 		if (empty($value))
3449 3633
 		{
3450
-			if (!is_array($cache_misses))
3451
-				$cache_misses = array();
3634
+			if (!is_array($cache_misses)) {
3635
+							$cache_misses = array();
3636
+			}
3452 3637
 
3453 3638
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3454 3639
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3455 3640
 		}
3456 3641
 	}
3457 3642
 
3458
-	if (function_exists('call_integration_hook') && isset($value))
3459
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3643
+	if (function_exists('call_integration_hook') && isset($value)) {
3644
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3645
+	}
3460 3646
 
3461 3647
 	return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3462 3648
 }
@@ -3478,8 +3664,9 @@  discard block
 block discarded – undo
3478 3664
 	global $cacheAPI;
3479 3665
 
3480 3666
 	// If we can't get to the API, can't do this.
3481
-	if (empty($cacheAPI))
3482
-		return;
3667
+	if (empty($cacheAPI)) {
3668
+			return;
3669
+	}
3483 3670
 
3484 3671
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3485 3672
 	$cacheAPI->cleanCache($type);
@@ -3504,8 +3691,9 @@  discard block
 block discarded – undo
3504 3691
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $user_info;
3505 3692
 
3506 3693
 	// Come on!
3507
-	if (empty($data))
3508
-		return array();
3694
+	if (empty($data)) {
3695
+			return array();
3696
+	}
3509 3697
 
3510 3698
 	// Set a nice default var.
3511 3699
 	$image = '';
@@ -3513,11 +3701,11 @@  discard block
 block discarded – undo
3513 3701
 	// Gravatar has been set as mandatory!
3514 3702
 	if (!empty($modSettings['gravatarOverride']))
3515 3703
 	{
3516
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3517
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3518
-
3519
-		else if (!empty($data['email']))
3520
-			$image = get_gravatar_url($data['email']);
3704
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3705
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3706
+		} else if (!empty($data['email'])) {
3707
+					$image = get_gravatar_url($data['email']);
3708
+		}
3521 3709
 	}
3522 3710
 
3523 3711
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3529,54 +3717,60 @@  discard block
 block discarded – undo
3529 3717
 			// Gravatar.
3530 3718
 			if (stristr($data['avatar'], 'gravatar://'))
3531 3719
 			{
3532
-				if ($data['avatar'] == 'gravatar://')
3533
-					$image = get_gravatar_url($data['email']);
3534
-
3535
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3536
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3720
+				if ($data['avatar'] == 'gravatar://') {
3721
+									$image = get_gravatar_url($data['email']);
3722
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3723
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3724
+				}
3537 3725
 			}
3538 3726
 
3539 3727
 			// External url.
3540 3728
 			else
3541 3729
 			{
3542 3730
 				// Using ssl?
3543
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
3544
-					$image = get_proxied_url($data['avatar']);
3731
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
3732
+									$image = get_proxied_url($data['avatar']);
3733
+				}
3545 3734
 
3546 3735
 				// Just a plain external url.
3547
-				else
3548
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3736
+				else {
3737
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3738
+				}
3549 3739
 			}
3550 3740
 		}
3551 3741
 
3552 3742
 		// Perhaps this user has an attachment as avatar...
3553
-		else if (!empty($data['filename']))
3554
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3743
+		else if (!empty($data['filename'])) {
3744
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3745
+		}
3555 3746
 
3556 3747
 		// Right... no avatar... use our default image.
3557
-		else
3558
-			$image = $modSettings['avatar_url'] . '/default.png';
3748
+		else {
3749
+					$image = $modSettings['avatar_url'] . '/default.png';
3750
+		}
3559 3751
 	}
3560 3752
 
3561 3753
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3562 3754
 
3563 3755
 	// 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.
3564
-	if (!empty($image))
3565
-		return array(
3756
+	if (!empty($image)) {
3757
+			return array(
3566 3758
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3567 3759
 			'image' => '<img class="avatar" src="' . $image . '" />',
3568 3760
 			'href' => $image,
3569 3761
 			'url' => $image,
3570 3762
 		);
3763
+	}
3571 3764
 
3572 3765
 	// Fallback to make life easier for everyone...
3573
-	else
3574
-		return array(
3766
+	else {
3767
+			return array(
3575 3768
 			'name' => '',
3576 3769
 			'image' => '',
3577 3770
 			'href' => '',
3578 3771
 			'url' => '',
3579 3772
 		);
3580
-}
3773
+	}
3774
+	}
3581 3775
 
3582 3776
 ?>
3583 3777
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Profile-Modify.php 1 patch
Braces   +710 added lines, -533 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * This defines every profile field known to man.
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $sourcedir, $profile_vars;
30 31
 
31 32
 	// Don't load this twice!
32
-	if (!empty($profile_fields) && !$force_reload)
33
-		return;
33
+	if (!empty($profile_fields) && !$force_reload) {
34
+			return;
35
+	}
34 36
 
35 37
 	/* This horrific array defines all the profile fields in the whole world!
36 38
 		In general each "field" has one array - the key of which is the database column name associated with said field. Each item
@@ -103,13 +105,14 @@  discard block
 block discarded – undo
103 105
 				if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0)
104 106
 				{
105 107
 					// Set to blank?
106
-					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1)
107
-						$value = '1004-01-01';
108
-					else
109
-						$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01';
108
+					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) {
109
+											$value = '1004-01-01';
110
+					} else {
111
+											$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01';
112
+					}
113
+				} else {
114
+									$value = '1004-01-01';
110 115
 				}
111
-				else
112
-					$value = '1004-01-01';
113 116
 
114 117
 				$profile_vars['birthdate'] = $value;
115 118
 				$cur_profile['birthdate'] = $value;
@@ -127,8 +130,7 @@  discard block
 block discarded – undo
127 130
 				{
128 131
 					$value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf('%04d-%02d-%02d', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : '1004-01-01';
129 132
 					return true;
130
-				}
131
-				else
133
+				} else
132 134
 				{
133 135
 					$value = empty($cur_profile['birthdate']) ? '1004-01-01' : $cur_profile['birthdate'];
134 136
 					return false;
@@ -150,10 +152,11 @@  discard block
 block discarded – undo
150 152
 					return $txt['invalid_registration'] . ' ' . strftime('%d %b %Y ' . (strpos($user_info['time_format'], '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false));
151 153
 				}
152 154
 				// As long as it doesn't equal "N/A"...
153
-				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600)))
154
-					$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
155
-				else
156
-					$value = $cur_profile['date_registered'];
155
+				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) {
156
+									$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
157
+				} else {
158
+									$value = $cur_profile['date_registered'];
159
+				}
157 160
 
158 161
 				return true;
159 162
 			},
@@ -177,8 +180,9 @@  discard block
 block discarded – undo
177 180
 			{
178 181
 				global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
179 182
 
180
-				if (strtolower($value) == strtolower($old_profile['email_address']))
181
-					return false;
183
+				if (strtolower($value) == strtolower($old_profile['email_address'])) {
184
+									return false;
185
+				}
182 186
 
183 187
 				$isValid = profileValidateEmail($value, $context['id_member']);
184 188
 
@@ -254,11 +258,11 @@  discard block
 block discarded – undo
254 258
 
255 259
 				if (isset($context['profile_languages'][$value]))
256 260
 				{
257
-					if ($context['user']['is_owner'] && empty($context['password_auth_failed']))
258
-						$_SESSION['language'] = $value;
261
+					if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) {
262
+											$_SESSION['language'] = $value;
263
+					}
259 264
 					return true;
260
-				}
261
-				else
265
+				} else
262 266
 				{
263 267
 					$value = $cur_profile['lngfile'];
264 268
 					return false;
@@ -282,13 +286,14 @@  discard block
 block discarded – undo
282 286
 
283 287
 					// Maybe they are trying to change their password as well?
284 288
 					$resetPassword = true;
285
-					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null)
286
-						$resetPassword = false;
289
+					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) {
290
+											$resetPassword = false;
291
+					}
287 292
 
288 293
 					// Do the reset... this will send them an email too.
289
-					if ($resetPassword)
290
-						resetPassword($context['id_member'], $value);
291
-					elseif ($value !== null)
294
+					if ($resetPassword) {
295
+											resetPassword($context['id_member'], $value);
296
+					} elseif ($value !== null)
292 297
 					{
293 298
 						validateUsername($context['id_member'], trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value)));
294 299
 						updateMemberData($context['id_member'], array('member_name' => $value));
@@ -312,20 +317,23 @@  discard block
 block discarded – undo
312 317
 			'input_validate' => function(&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
313 318
 			{
314 319
 				// If we didn't try it then ignore it!
315
-				if ($value == '')
316
-					return false;
320
+				if ($value == '') {
321
+									return false;
322
+				}
317 323
 
318 324
 				// Do the two entries for the password even match?
319
-				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2'])
320
-					return 'bad_new_password';
325
+				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) {
326
+									return 'bad_new_password';
327
+				}
321 328
 
322 329
 				// Let's get the validation function into play...
323 330
 				require_once($sourcedir . '/Subs-Auth.php');
324 331
 				$passwordErrors = validatePassword($value, $cur_profile['member_name'], array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email']));
325 332
 
326 333
 				// Were there errors?
327
-				if ($passwordErrors != null)
328
-					return 'password_' . $passwordErrors;
334
+				if ($passwordErrors != null) {
335
+									return 'password_' . $passwordErrors;
336
+				}
329 337
 
330 338
 				// Set up the new password variable... ready for storage.
331 339
 				$value = hash_password($cur_profile['member_name'], un_htmlspecialchars($value));
@@ -350,8 +358,9 @@  discard block
 block discarded – undo
350 358
 			'permission' => 'profile_blurb',
351 359
 			'input_validate' => function(&$value) use ($smcFunc)
352 360
 			{
353
-				if ($smcFunc['strlen']($value) > 50)
354
-					return 'personal_text_too_long';
361
+				if ($smcFunc['strlen']($value) > 50) {
362
+									return 'personal_text_too_long';
363
+				}
355 364
 
356 365
 				return true;
357 366
 			},
@@ -386,10 +395,11 @@  discard block
 block discarded – undo
386 395
 			'permission' => 'moderate_forum',
387 396
 			'input_validate' => function(&$value)
388 397
 			{
389
-				if (!is_numeric($value))
390
-					return 'digits_only';
391
-				else
392
-					$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
398
+				if (!is_numeric($value)) {
399
+									return 'digits_only';
400
+				} else {
401
+									$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
402
+				}
393 403
 				return true;
394 404
 			},
395 405
 		),
@@ -405,15 +415,16 @@  discard block
 block discarded – undo
405 415
 			{
406 416
 				$value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value));
407 417
 
408
-				if (trim($value) == '')
409
-					return 'no_name';
410
-				elseif ($smcFunc['strlen']($value) > 60)
411
-					return 'name_too_long';
412
-				elseif ($cur_profile['real_name'] != $value)
418
+				if (trim($value) == '') {
419
+									return 'no_name';
420
+				} elseif ($smcFunc['strlen']($value) > 60) {
421
+									return 'name_too_long';
422
+				} elseif ($cur_profile['real_name'] != $value)
413 423
 				{
414 424
 					require_once($sourcedir . '/Subs-Members.php');
415
-					if (isReservedName($value, $context['id_member']))
416
-						return 'name_taken';
425
+					if (isReservedName($value, $context['id_member'])) {
426
+											return 'name_taken';
427
+					}
417 428
 				}
418 429
 				return true;
419 430
 			},
@@ -471,8 +482,9 @@  discard block
 block discarded – undo
471 482
 						'selected' => $set == $context['member']['smiley_set']['id']
472 483
 					);
473 484
 
474
-					if ($context['smiley_sets'][$i]['selected'])
475
-						$context['member']['smiley_set']['name'] = $set_names[$i];
485
+					if ($context['smiley_sets'][$i]['selected']) {
486
+											$context['member']['smiley_set']['name'] = $set_names[$i];
487
+					}
476 488
 				}
477 489
 				return true;
478 490
 			},
@@ -481,8 +493,9 @@  discard block
 block discarded – undo
481 493
 				global $modSettings;
482 494
 
483 495
 				$smiley_sets = explode(',', $modSettings['smiley_sets_known']);
484
-				if (!in_array($value, $smiley_sets) && $value != 'none')
485
-					$value = '';
496
+				if (!in_array($value, $smiley_sets) && $value != 'none') {
497
+									$value = '';
498
+				}
486 499
 				return true;
487 500
 			},
488 501
 		),
@@ -497,8 +510,9 @@  discard block
 block discarded – undo
497 510
 				loadLanguage('Settings');
498 511
 
499 512
 				$context['allow_no_censored'] = false;
500
-				if ($user_info['is_admin'] || $context['user']['is_owner'])
501
-					$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
513
+				if ($user_info['is_admin'] || $context['user']['is_owner']) {
514
+									$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
515
+				}
502 516
 
503 517
 				return true;
504 518
 			},
@@ -545,8 +559,9 @@  discard block
 block discarded – undo
545 559
 			'input_validate' => function($value)
546 560
 			{
547 561
 				$tz = smf_list_timezones();
548
-				if (!isset($tz[$value]))
549
-					return 'bad_timezone';
562
+				if (!isset($tz[$value])) {
563
+									return 'bad_timezone';
564
+				}
550 565
 
551 566
 				return true;
552 567
 			},
@@ -561,8 +576,9 @@  discard block
 block discarded – undo
561 576
 			'enabled' => !empty($modSettings['titlesEnable']),
562 577
 			'input_validate' => function(&$value) use ($smcFunc)
563 578
 			{
564
-				if ($smcFunc['strlen']($value) > 50)
565
-					return 'user_title_too_long';
579
+				if ($smcFunc['strlen']($value) > 50) {
580
+									return 'user_title_too_long';
581
+				}
566 582
 
567 583
 				return true;
568 584
 			},
@@ -584,10 +600,12 @@  discard block
 block discarded – undo
584 600
 			// Fix the URL...
585 601
 			'input_validate' => function(&$value)
586 602
 			{
587
-				if (strlen(trim($value)) > 0 && strpos($value, '://') === false)
588
-					$value = 'http://' . $value;
589
-				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://'))
590
-					$value = '';
603
+				if (strlen(trim($value)) > 0 && strpos($value, '://') === false) {
604
+									$value = 'http://' . $value;
605
+				}
606
+				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) {
607
+									$value = '';
608
+				}
591 609
 				return true;
592 610
 			},
593 611
 			'link_with' => 'website',
@@ -601,16 +619,19 @@  discard block
 block discarded – undo
601 619
 	foreach ($profile_fields as $key => $field)
602 620
 	{
603 621
 		// Do we have permission to do this?
604
-		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission']))
605
-			unset($profile_fields[$key]);
622
+		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) {
623
+					unset($profile_fields[$key]);
624
+		}
606 625
 
607 626
 		// Is it enabled?
608
-		if (isset($field['enabled']) && !$field['enabled'])
609
-			unset($profile_fields[$key]);
627
+		if (isset($field['enabled']) && !$field['enabled']) {
628
+					unset($profile_fields[$key]);
629
+		}
610 630
 
611 631
 		// Is it specifically disabled?
612
-		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields)))
613
-			unset($profile_fields[$key]);
632
+		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) {
633
+					unset($profile_fields[$key]);
634
+		}
614 635
 	}
615 636
 }
616 637
 
@@ -635,9 +656,10 @@  discard block
 block discarded – undo
635 656
 	loadProfileFields(true);
636 657
 
637 658
 	// First check for any linked sets.
638
-	foreach ($profile_fields as $key => $field)
639
-		if (isset($field['link_with']) && in_array($field['link_with'], $fields))
659
+	foreach ($profile_fields as $key => $field) {
660
+			if (isset($field['link_with']) && in_array($field['link_with'], $fields))
640 661
 			$fields[] = $key;
662
+	}
641 663
 
642 664
 	$i = 0;
643 665
 	$last_type = '';
@@ -649,38 +671,46 @@  discard block
 block discarded – undo
649 671
 			$cur_field = &$profile_fields[$field];
650 672
 
651 673
 			// Does it have a preload and does that preload succeed?
652
-			if (isset($cur_field['preload']) && !$cur_field['preload']())
653
-				continue;
674
+			if (isset($cur_field['preload']) && !$cur_field['preload']()) {
675
+							continue;
676
+			}
654 677
 
655 678
 			// If this is anything but complex we need to do more cleaning!
656 679
 			if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden')
657 680
 			{
658
-				if (!isset($cur_field['label']))
659
-					$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
681
+				if (!isset($cur_field['label'])) {
682
+									$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
683
+				}
660 684
 
661 685
 				// Everything has a value!
662
-				if (!isset($cur_field['value']))
663
-					$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
686
+				if (!isset($cur_field['value'])) {
687
+									$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
688
+				}
664 689
 
665 690
 				// Any input attributes?
666 691
 				$cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : '';
667 692
 			}
668 693
 
669 694
 			// Was there an error with this field on posting?
670
-			if (isset($context['profile_errors'][$field]))
671
-				$cur_field['is_error'] = true;
695
+			if (isset($context['profile_errors'][$field])) {
696
+							$cur_field['is_error'] = true;
697
+			}
672 698
 
673 699
 			// Any javascript stuff?
674
-			if (!empty($cur_field['js_submit']))
675
-				$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
676
-			if (!empty($cur_field['js']))
677
-				$context['profile_javascript'] .= $cur_field['js'];
700
+			if (!empty($cur_field['js_submit'])) {
701
+							$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
702
+			}
703
+			if (!empty($cur_field['js'])) {
704
+							$context['profile_javascript'] .= $cur_field['js'];
705
+			}
678 706
 
679 707
 			// Any template stuff?
680
-			if (!empty($cur_field['prehtml']))
681
-				$context['profile_prehtml'] .= $cur_field['prehtml'];
682
-			if (!empty($cur_field['posthtml']))
683
-				$context['profile_posthtml'] .= $cur_field['posthtml'];
708
+			if (!empty($cur_field['prehtml'])) {
709
+							$context['profile_prehtml'] .= $cur_field['prehtml'];
710
+			}
711
+			if (!empty($cur_field['posthtml'])) {
712
+							$context['profile_posthtml'] .= $cur_field['posthtml'];
713
+			}
684 714
 
685 715
 			// Finally put it into context?
686 716
 			if ($cur_field['type'] != 'hidden')
@@ -713,12 +743,14 @@  discard block
 block discarded – undo
713 743
 	}, false);' : ''), true);
714 744
 
715 745
 	// Any onsubmit javascript?
716
-	if (!empty($context['profile_onsubmit_javascript']))
717
-		addInlineJavaScript($context['profile_onsubmit_javascript'], true);
746
+	if (!empty($context['profile_onsubmit_javascript'])) {
747
+			addInlineJavaScript($context['profile_onsubmit_javascript'], true);
748
+	}
718 749
 
719 750
 	// Any totally custom stuff?
720
-	if (!empty($context['profile_javascript']))
721
-		addInlineJavaScript($context['profile_javascript'], true);
751
+	if (!empty($context['profile_javascript'])) {
752
+			addInlineJavaScript($context['profile_javascript'], true);
753
+	}
722 754
 
723 755
 	// Free up some memory.
724 756
 	unset($profile_fields);
@@ -739,8 +771,9 @@  discard block
 block discarded – undo
739 771
 
740 772
 	// This allows variables to call activities when they save - by default just to reload their settings
741 773
 	$context['profile_execute_on_save'] = array();
742
-	if ($context['user']['is_owner'])
743
-		$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
774
+	if ($context['user']['is_owner']) {
775
+			$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
776
+	}
744 777
 
745 778
 	// Assume we log nothing.
746 779
 	$context['log_changes'] = array();
@@ -748,8 +781,9 @@  discard block
 block discarded – undo
748 781
 	// Cycle through the profile fields working out what to do!
749 782
 	foreach ($profile_fields as $key => $field)
750 783
 	{
751
-		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature'))
752
-			continue;
784
+		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) {
785
+					continue;
786
+		}
753 787
 
754 788
 		// What gets updated?
755 789
 		$db_key = isset($field['save_key']) ? $field['save_key'] : $key;
@@ -777,12 +811,13 @@  discard block
 block discarded – undo
777 811
 		$field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type'];
778 812
 
779 813
 		// Finally, clean up certain types.
780
-		if ($field['cast_type'] == 'int')
781
-			$_POST[$key] = (int) $_POST[$key];
782
-		elseif ($field['cast_type'] == 'float')
783
-			$_POST[$key] = (float) $_POST[$key];
784
-		elseif ($field['cast_type'] == 'check')
785
-			$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
814
+		if ($field['cast_type'] == 'int') {
815
+					$_POST[$key] = (int) $_POST[$key];
816
+		} elseif ($field['cast_type'] == 'float') {
817
+					$_POST[$key] = (float) $_POST[$key];
818
+		} elseif ($field['cast_type'] == 'check') {
819
+					$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
820
+		}
786 821
 
787 822
 		// If we got here we're doing OK.
788 823
 		if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key]))
@@ -793,11 +828,12 @@  discard block
 block discarded – undo
793 828
 			$cur_profile[$key] = $_POST[$key];
794 829
 
795 830
 			// Are we logging it?
796
-			if (!empty($field['log_change']) && isset($old_profile[$key]))
797
-				$context['log_changes'][$key] = array(
831
+			if (!empty($field['log_change']) && isset($old_profile[$key])) {
832
+							$context['log_changes'][$key] = array(
798 833
 					'previous' => $old_profile[$key],
799 834
 					'new' => $_POST[$key],
800 835
 				);
836
+			}
801 837
 		}
802 838
 
803 839
 		// Logging group changes are a bit different...
@@ -830,10 +866,11 @@  discard block
 block discarded – undo
830 866
 				{
831 867
 					foreach ($groups as $id => $group)
832 868
 					{
833
-						if (isset($context['member_groups'][$group]))
834
-							$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
835
-						else
836
-							unset($additional_groups[$type][$id]);
869
+						if (isset($context['member_groups'][$group])) {
870
+													$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
871
+						} else {
872
+													unset($additional_groups[$type][$id]);
873
+						}
837 874
 					}
838 875
 					$additional_groups[$type] = implode(', ', $additional_groups[$type]);
839 876
 				}
@@ -844,10 +881,11 @@  discard block
 block discarded – undo
844 881
 	}
845 882
 
846 883
 	// @todo Temporary
847
-	if ($context['user']['is_owner'])
848
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
849
-	else
850
-		$changeOther = allowedTo('profile_extra_any');
884
+	if ($context['user']['is_owner']) {
885
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
886
+	} else {
887
+			$changeOther = allowedTo('profile_extra_any');
888
+	}
851 889
 	if ($changeOther && empty($post_errors))
852 890
 	{
853 891
 		makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
@@ -855,8 +893,9 @@  discard block
 block discarded – undo
855 893
 		{
856 894
 			$custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true);
857 895
 
858
-			if (!empty($custom_fields_errors))
859
-				$post_errors = array_merge($post_errors, $custom_fields_errors);
896
+			if (!empty($custom_fields_errors)) {
897
+							$post_errors = array_merge($post_errors, $custom_fields_errors);
898
+			}
860 899
 		}
861 900
 	}
862 901
 
@@ -882,9 +921,9 @@  discard block
 block discarded – undo
882 921
 	if ($context['user']['is_owner'])
883 922
 	{
884 923
 		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own'));
924
+	} else {
925
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
885 926
 	}
886
-	else
887
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
888 927
 
889 928
 	// Arrays of all the changes - makes things easier.
890 929
 	$profile_bools = array();
@@ -895,22 +934,25 @@  discard block
 block discarded – undo
895 934
 		'ignore_boards',
896 935
 	);
897 936
 
898
-	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
899
-		$_POST['ignore_brd'] = array();
937
+	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) {
938
+			$_POST['ignore_brd'] = array();
939
+	}
900 940
 
901 941
 	unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing.  Kinda like our minds.
902 942
 	if (isset($_POST['ignore_brd']))
903 943
 	{
904
-		if (!is_array($_POST['ignore_brd']))
905
-			$_POST['ignore_brd'] = array($_POST['ignore_brd']);
944
+		if (!is_array($_POST['ignore_brd'])) {
945
+					$_POST['ignore_brd'] = array($_POST['ignore_brd']);
946
+		}
906 947
 
907 948
 		foreach ($_POST['ignore_brd'] as $k => $d)
908 949
 		{
909 950
 			$d = (int) $d;
910
-			if ($d != 0)
911
-				$_POST['ignore_brd'][$k] = $d;
912
-			else
913
-				unset($_POST['ignore_brd'][$k]);
951
+			if ($d != 0) {
952
+							$_POST['ignore_brd'][$k] = $d;
953
+			} else {
954
+							unset($_POST['ignore_brd'][$k]);
955
+			}
914 956
 		}
915 957
 		$_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
916 958
 		unset($_POST['ignore_brd']);
@@ -923,21 +965,26 @@  discard block
 block discarded – undo
923 965
 		makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
924 966
 		//makeAvatarChanges($memID, $post_errors);
925 967
 
926
-		if (!empty($_REQUEST['sa']))
927
-			makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
968
+		if (!empty($_REQUEST['sa'])) {
969
+					makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
970
+		}
928 971
 
929
-		foreach ($profile_bools as $var)
930
-			if (isset($_POST[$var]))
972
+		foreach ($profile_bools as $var) {
973
+					if (isset($_POST[$var]))
931 974
 				$profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
932
-		foreach ($profile_ints as $var)
933
-			if (isset($_POST[$var]))
975
+		}
976
+		foreach ($profile_ints as $var) {
977
+					if (isset($_POST[$var]))
934 978
 				$profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
935
-		foreach ($profile_floats as $var)
936
-			if (isset($_POST[$var]))
979
+		}
980
+		foreach ($profile_floats as $var) {
981
+					if (isset($_POST[$var]))
937 982
 				$profile_vars[$var] = (float) $_POST[$var];
938
-		foreach ($profile_strings as $var)
939
-			if (isset($_POST[$var]))
983
+		}
984
+		foreach ($profile_strings as $var) {
985
+					if (isset($_POST[$var]))
940 986
 				$profile_vars[$var] = $_POST[$var];
987
+		}
941 988
 	}
942 989
 }
943 990
 
@@ -971,8 +1018,9 @@  discard block
 block discarded – undo
971 1018
 	);
972 1019
 
973 1020
 	// Can't change reserved vars.
974
-	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0))
975
-		fatal_lang_error('no_access', false);
1021
+	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) {
1022
+			fatal_lang_error('no_access', false);
1023
+	}
976 1024
 
977 1025
 	// Don't allow any overriding of custom fields with default or non-default options.
978 1026
 	$request = $smcFunc['db_query']('', '
@@ -984,8 +1032,9 @@  discard block
 block discarded – undo
984 1032
 		)
985 1033
 	);
986 1034
 	$custom_fields = array();
987
-	while ($row = $smcFunc['db_fetch_assoc']($request))
988
-		$custom_fields[] = $row['col_name'];
1035
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1036
+			$custom_fields[] = $row['col_name'];
1037
+	}
989 1038
 	$smcFunc['db_free_result']($request);
990 1039
 
991 1040
 	// These are the theme changes...
@@ -994,33 +1043,39 @@  discard block
 block discarded – undo
994 1043
 	{
995 1044
 		foreach ($_POST['options'] as $opt => $val)
996 1045
 		{
997
-			if (in_array($opt, $custom_fields))
998
-				continue;
1046
+			if (in_array($opt, $custom_fields)) {
1047
+							continue;
1048
+			}
999 1049
 
1000 1050
 			// These need to be controlled.
1001
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1002
-				$val = max(0, min($val, 50));
1051
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1052
+							$val = max(0, min($val, 50));
1053
+			}
1003 1054
 			// We don't set this per theme anymore.
1004
-			elseif ($opt == 'allow_no_censored')
1005
-				continue;
1055
+			elseif ($opt == 'allow_no_censored') {
1056
+							continue;
1057
+			}
1006 1058
 
1007 1059
 			$themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
1008 1060
 		}
1009 1061
 	}
1010 1062
 
1011 1063
 	$erase_options = array();
1012
-	if (isset($_POST['default_options']) && is_array($_POST['default_options']))
1013
-		foreach ($_POST['default_options'] as $opt => $val)
1064
+	if (isset($_POST['default_options']) && is_array($_POST['default_options'])) {
1065
+			foreach ($_POST['default_options'] as $opt => $val)
1014 1066
 		{
1015 1067
 			if (in_array($opt, $custom_fields))
1016 1068
 				continue;
1069
+	}
1017 1070
 
1018 1071
 			// These need to be controlled.
1019
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1020
-				$val = max(0, min($val, 50));
1072
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1073
+							$val = max(0, min($val, 50));
1074
+			}
1021 1075
 			// Only let admins and owners change the censor.
1022
-			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner'])
1023
-					continue;
1076
+			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) {
1077
+								continue;
1078
+			}
1024 1079
 
1025 1080
 			$themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
1026 1081
 			$erase_options[] = $opt;
@@ -1056,8 +1111,9 @@  discard block
 block discarded – undo
1056 1111
 
1057 1112
 		// Admins can choose any theme, even if it's not enabled...
1058 1113
 		$themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']);
1059
-		foreach ($themes as $t)
1060
-			cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1114
+		foreach ($themes as $t) {
1115
+					cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1116
+		}
1061 1117
 	}
1062 1118
 }
1063 1119
 
@@ -1076,8 +1132,9 @@  discard block
 block discarded – undo
1076 1132
 	if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
1077 1133
 	{
1078 1134
 		// Make sure only integers are deleted.
1079
-		foreach ($_POST['notify_boards'] as $index => $id)
1080
-			$_POST['notify_boards'][$index] = (int) $id;
1135
+		foreach ($_POST['notify_boards'] as $index => $id) {
1136
+					$_POST['notify_boards'][$index] = (int) $id;
1137
+		}
1081 1138
 
1082 1139
 		// id_board = 0 is reserved for topic notifications.
1083 1140
 		$_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
@@ -1096,8 +1153,9 @@  discard block
 block discarded – undo
1096 1153
 	// We are editing topic notifications......
1097 1154
 	elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
1098 1155
 	{
1099
-		foreach ($_POST['notify_topics'] as $index => $id)
1100
-			$_POST['notify_topics'][$index] = (int) $id;
1156
+		foreach ($_POST['notify_topics'] as $index => $id) {
1157
+					$_POST['notify_topics'][$index] = (int) $id;
1158
+		}
1101 1159
 
1102 1160
 		// Make sure there are no zeros left.
1103 1161
 		$_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
@@ -1111,16 +1169,18 @@  discard block
 block discarded – undo
1111 1169
 				'selected_member' => $memID,
1112 1170
 			)
1113 1171
 		);
1114
-		foreach ($_POST['notify_topics'] as $topic)
1115
-			setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1172
+		foreach ($_POST['notify_topics'] as $topic) {
1173
+					setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1174
+		}
1116 1175
 	}
1117 1176
 
1118 1177
 	// We are removing topic preferences
1119 1178
 	elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics']))
1120 1179
 	{
1121 1180
 		$prefs = array();
1122
-		foreach ($_POST['notify_topics'] as $topic)
1123
-			$prefs[] = 'topic_notify_' . $topic;
1181
+		foreach ($_POST['notify_topics'] as $topic) {
1182
+					$prefs[] = 'topic_notify_' . $topic;
1183
+		}
1124 1184
 		deleteNotifyPrefs($memID, $prefs);
1125 1185
 	}
1126 1186
 
@@ -1128,8 +1188,9 @@  discard block
 block discarded – undo
1128 1188
 	elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards']))
1129 1189
 	{
1130 1190
 		$prefs = array();
1131
-		foreach ($_POST['notify_boards'] as $board)
1132
-			$prefs[] = 'board_notify_' . $board;
1191
+		foreach ($_POST['notify_boards'] as $board) {
1192
+					$prefs[] = 'board_notify_' . $board;
1193
+		}
1133 1194
 		deleteNotifyPrefs($memID, $prefs);
1134 1195
 	}
1135 1196
 }
@@ -1150,8 +1211,9 @@  discard block
 block discarded – undo
1150 1211
 
1151 1212
 	$errors = array();
1152 1213
 
1153
-	if ($sanitize && isset($_POST['customfield']))
1154
-		$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1214
+	if ($sanitize && isset($_POST['customfield'])) {
1215
+			$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1216
+	}
1155 1217
 
1156 1218
 	$where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
1157 1219
 
@@ -1177,26 +1239,29 @@  discard block
 block discarded – undo
1177 1239
 			- The data is not invisible to users but editable by the owner (or if it is the user is not the owner)
1178 1240
 			- The area isn't registration, and if it is that the field is not supposed to be shown there.
1179 1241
 		*/
1180
-		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
1181
-			continue;
1242
+		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) {
1243
+					continue;
1244
+		}
1182 1245
 
1183 1246
 		// Validate the user data.
1184
-		if ($row['field_type'] == 'check')
1185
-			$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1186
-		elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1247
+		if ($row['field_type'] == 'check') {
1248
+					$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1249
+		} elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1187 1250
 		{
1188 1251
 			$value = $row['default_value'];
1189
-			foreach (explode(',', $row['field_options']) as $k => $v)
1190
-				if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1252
+			foreach (explode(',', $row['field_options']) as $k => $v) {
1253
+							if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1191 1254
 					$value = $v;
1255
+			}
1192 1256
 		}
1193 1257
 		// Otherwise some form of text!
1194 1258
 		else
1195 1259
 		{
1196 1260
 			$value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
1197 1261
 
1198
-			if ($row['field_length'])
1199
-				$value = $smcFunc['substr']($value, 0, $row['field_length']);
1262
+			if ($row['field_length']) {
1263
+							$value = $smcFunc['substr']($value, 0, $row['field_length']);
1264
+			}
1200 1265
 
1201 1266
 			// Any masks?
1202 1267
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
@@ -1205,36 +1270,34 @@  discard block
 block discarded – undo
1205 1270
 				$valueReference = un_htmlspecialchars($value);
1206 1271
 
1207 1272
 				// Try and avoid some checks. '0' could be a valid non-empty value.
1208
-				if (empty($value) && !is_numeric($value))
1209
-					$value = '';
1273
+				if (empty($value) && !is_numeric($value)) {
1274
+									$value = '';
1275
+				}
1210 1276
 
1211 1277
 				if ($row['mask'] == 'nohtml' && ($valueReference != strip_tags($valueReference) || $value != filter_var($value, FILTER_SANITIZE_STRING) || preg_match('/<(.+?)[\s]*\/?[\s]*>/si', $valueReference)))
1212 1278
 				{
1213
-					if ($returnErrors)
1214
-						$errors[] = 'custom_field_nohtml_fail';
1215
-
1216
-					else
1217
-						$value = '';
1218
-				}
1219
-				elseif ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1279
+					if ($returnErrors) {
1280
+											$errors[] = 'custom_field_nohtml_fail';
1281
+					} else {
1282
+											$value = '';
1283
+					}
1284
+				} elseif ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1220 1285
 				{
1221
-					if ($returnErrors)
1222
-						$errors[] = 'custom_field_mail_fail';
1223
-
1224
-					else
1225
-						$value = '';
1226
-				}
1227
-				elseif ($row['mask'] == 'number')
1286
+					if ($returnErrors) {
1287
+											$errors[] = 'custom_field_mail_fail';
1288
+					} else {
1289
+											$value = '';
1290
+					}
1291
+				} elseif ($row['mask'] == 'number')
1228 1292
 				{
1229 1293
 					$value = (int) $value;
1230
-				}
1231
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1294
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1232 1295
 				{
1233
-					if ($returnErrors)
1234
-						$errors[] = 'custom_field_regex_fail';
1235
-
1236
-					else
1237
-						$value = '';
1296
+					if ($returnErrors) {
1297
+											$errors[] = 'custom_field_regex_fail';
1298
+					} else {
1299
+											$value = '';
1300
+					}
1238 1301
 				}
1239 1302
 
1240 1303
 				unset($valueReference);
@@ -1258,8 +1321,7 @@  discard block
 block discarded – undo
1258 1321
 			{
1259 1322
 				$deletes = array('id_theme' => 1 , 'variable' => $row['col_name'], 'id_member' => $memID);
1260 1323
 				unset($user_profile[$memID]['options'][$row['col_name']]);
1261
-			}
1262
-			else
1324
+			} else
1263 1325
 			{
1264 1326
 				$changes[] = array(1, $row['col_name'], $value, $memID);
1265 1327
 				$user_profile[$memID]['options'][$row['col_name']] = $value;
@@ -1270,27 +1332,30 @@  discard block
 block discarded – undo
1270 1332
 
1271 1333
 	$hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize, &$deletes));
1272 1334
 
1273
-	if (!empty($hook_errors) && is_array($hook_errors))
1274
-		$errors = array_merge($errors, $hook_errors);
1335
+	if (!empty($hook_errors) && is_array($hook_errors)) {
1336
+			$errors = array_merge($errors, $hook_errors);
1337
+	}
1275 1338
 
1276 1339
 	// Make those changes!
1277 1340
 	if ((!empty($changes) || !empty($deletes)) && empty($context['password_auth_failed']) && empty($errors))
1278 1341
 	{
1279
-		if (!empty($changes))
1280
-			$smcFunc['db_insert']('replace',
1342
+		if (!empty($changes)) {
1343
+					$smcFunc['db_insert']('replace',
1281 1344
 				'{db_prefix}themes',
1282 1345
 				array('id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534', 'id_member' => 'int'),
1283 1346
 				$changes,
1284 1347
 				array('id_theme', 'variable', 'id_member')
1285 1348
 			);
1286
-		if (!empty($deletes))
1287
-			$smcFunc['db_query']('','
1349
+		}
1350
+		if (!empty($deletes)) {
1351
+					$smcFunc['db_query']('','
1288 1352
 				DELETE FROM {db_prefix}themes 
1289 1353
 				WHERE id_theme = {int:id_theme} AND 
1290 1354
 						variable = {string:variable} AND 
1291 1355
 						id_member = {int:id_member}',
1292 1356
 				$deletes
1293 1357
 				);
1358
+		}
1294 1359
 		if (!empty($log_changes) && !empty($modSettings['modlog_enabled']))
1295 1360
 		{
1296 1361
 			require_once($sourcedir . '/Logging.php');
@@ -1298,9 +1363,10 @@  discard block
 block discarded – undo
1298 1363
 		}
1299 1364
 	}
1300 1365
 
1301
-	if ($returnErrors)
1302
-		return $errors;
1303
-}
1366
+	if ($returnErrors) {
1367
+			return $errors;
1368
+	}
1369
+	}
1304 1370
 
1305 1371
 /**
1306 1372
  * Show all the users buddies, as well as a add/delete interface.
@@ -1312,8 +1378,9 @@  discard block
 block discarded – undo
1312 1378
 	global $context, $txt, $modSettings;
1313 1379
 
1314 1380
 	// Do a quick check to ensure people aren't getting here illegally!
1315
-	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
1316
-		fatal_lang_error('no_access', false);
1381
+	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) {
1382
+			fatal_lang_error('no_access', false);
1383
+	}
1317 1384
 
1318 1385
 	// Can we email the user direct?
1319 1386
 	$context['can_moderate_forum'] = allowedTo('moderate_forum');
@@ -1343,9 +1410,10 @@  discard block
 block discarded – undo
1343 1410
 	$context['sub_template'] = $subActions[$context['list_area']][0];
1344 1411
 	$call = call_helper($subActions[$context['list_area']][0], true);
1345 1412
 
1346
-	if (!empty($call))
1347
-		call_user_func($call, $memID);
1348
-}
1413
+	if (!empty($call)) {
1414
+			call_user_func($call, $memID);
1415
+	}
1416
+	}
1349 1417
 
1350 1418
 /**
1351 1419
  * Show all the users buddies, as well as a add/delete interface.
@@ -1359,9 +1427,10 @@  discard block
 block discarded – undo
1359 1427
 
1360 1428
 	// For making changes!
1361 1429
 	$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
1362
-	foreach ($buddiesArray as $k => $dummy)
1363
-		if ($dummy == '')
1430
+	foreach ($buddiesArray as $k => $dummy) {
1431
+			if ($dummy == '')
1364 1432
 			unset($buddiesArray[$k]);
1433
+	}
1365 1434
 
1366 1435
 	// Removing a buddy?
1367 1436
 	if (isset($_GET['remove']))
@@ -1373,10 +1442,11 @@  discard block
 block discarded – undo
1373 1442
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1374 1443
 
1375 1444
 		// Heh, I'm lazy, do it the easy way...
1376
-		foreach ($buddiesArray as $key => $buddy)
1377
-			if ($buddy == (int) $_GET['remove'])
1445
+		foreach ($buddiesArray as $key => $buddy) {
1446
+					if ($buddy == (int) $_GET['remove'])
1378 1447
 			{
1379 1448
 				unset($buddiesArray[$key]);
1449
+		}
1380 1450
 				$_SESSION['prf-save'] = true;
1381 1451
 			}
1382 1452
 
@@ -1386,8 +1456,7 @@  discard block
 block discarded – undo
1386 1456
 
1387 1457
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1388 1458
 		redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
1389
-	}
1390
-	elseif (isset($_POST['new_buddy']))
1459
+	} elseif (isset($_POST['new_buddy']))
1391 1460
 	{
1392 1461
 		checkSession();
1393 1462
 
@@ -1400,8 +1469,9 @@  discard block
 block discarded – undo
1400 1469
 		{
1401 1470
 			$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
1402 1471
 
1403
-			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1404
-				unset($new_buddies[$k]);
1472
+			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1473
+							unset($new_buddies[$k]);
1474
+			}
1405 1475
 		}
1406 1476
 
1407 1477
 		call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
@@ -1421,16 +1491,18 @@  discard block
 block discarded – undo
1421 1491
 				)
1422 1492
 			);
1423 1493
 
1424
-			if ($smcFunc['db_num_rows']($request) != 0)
1425
-				$_SESSION['prf-save'] = true;
1494
+			if ($smcFunc['db_num_rows']($request) != 0) {
1495
+							$_SESSION['prf-save'] = true;
1496
+			}
1426 1497
 
1427 1498
 			// Add the new member to the buddies array.
1428 1499
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1429 1500
 			{
1430
-				if (in_array($row['id_member'], $buddiesArray))
1431
-					continue;
1432
-				else
1433
-					$buddiesArray[] = (int) $row['id_member'];
1501
+				if (in_array($row['id_member'], $buddiesArray)) {
1502
+									continue;
1503
+				} else {
1504
+									$buddiesArray[] = (int) $row['id_member'];
1505
+				}
1434 1506
 			}
1435 1507
 			$smcFunc['db_free_result']($request);
1436 1508
 
@@ -1460,18 +1532,20 @@  discard block
 block discarded – undo
1460 1532
 
1461 1533
 	$context['custom_pf'] = array();
1462 1534
 	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
1463
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1464
-		if (!isset($disabled_fields[$row['col_name']]))
1535
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1536
+			if (!isset($disabled_fields[$row['col_name']]))
1465 1537
 			$context['custom_pf'][$row['col_name']] = array(
1466 1538
 				'label' => $row['field_name'],
1467 1539
 				'type' => $row['field_type'],
1468 1540
 				'bbc' => !empty($row['bbc']),
1469 1541
 				'enclose' => $row['enclose'],
1470 1542
 			);
1543
+	}
1471 1544
 
1472 1545
 	// Gotta disable the gender option.
1473
-	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'None')
1474
-		unset($context['custom_pf']['cust_gender']);
1546
+	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'None') {
1547
+			unset($context['custom_pf']['cust_gender']);
1548
+	}
1475 1549
 
1476 1550
 	$smcFunc['db_free_result']($request);
1477 1551
 
@@ -1488,8 +1562,9 @@  discard block
 block discarded – undo
1488 1562
 				'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
1489 1563
 			)
1490 1564
 		);
1491
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1492
-			$buddies[] = $row['id_member'];
1565
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1566
+					$buddies[] = $row['id_member'];
1567
+		}
1493 1568
 		$smcFunc['db_free_result']($result);
1494 1569
 	}
1495 1570
 
@@ -1517,30 +1592,32 @@  discard block
 block discarded – undo
1517 1592
 					continue;
1518 1593
 				}
1519 1594
 
1520
-				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key]))
1521
-					$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1522
-
1523
-				elseif ($column['type'] == 'check')
1524
-					$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1595
+				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) {
1596
+									$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1597
+				} elseif ($column['type'] == 'check') {
1598
+									$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1599
+				}
1525 1600
 
1526 1601
 				// Enclosing the user input within some other text?
1527
-				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key]))
1528
-					$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1602
+				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) {
1603
+									$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1529 1604
 						'{SCRIPTURL}' => $scripturl,
1530 1605
 						'{IMAGES_URL}' => $settings['images_url'],
1531 1606
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1532 1607
 						'{INPUT}' => $context['buddies'][$buddy]['options'][$key],
1533 1608
 					));
1609
+				}
1534 1610
 			}
1535 1611
 		}
1536 1612
 	}
1537 1613
 
1538 1614
 	if (isset($_SESSION['prf-save']))
1539 1615
 	{
1540
-		if ($_SESSION['prf-save'] === true)
1541
-			$context['saved_successful'] = true;
1542
-		else
1543
-			$context['saved_failed'] = $_SESSION['prf-save'];
1616
+		if ($_SESSION['prf-save'] === true) {
1617
+					$context['saved_successful'] = true;
1618
+		} else {
1619
+					$context['saved_failed'] = $_SESSION['prf-save'];
1620
+		}
1544 1621
 
1545 1622
 		unset($_SESSION['prf-save']);
1546 1623
 	}
@@ -1560,9 +1637,10 @@  discard block
 block discarded – undo
1560 1637
 
1561 1638
 	// For making changes!
1562 1639
 	$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
1563
-	foreach ($ignoreArray as $k => $dummy)
1564
-		if ($dummy == '')
1640
+	foreach ($ignoreArray as $k => $dummy) {
1641
+			if ($dummy == '')
1565 1642
 			unset($ignoreArray[$k]);
1643
+	}
1566 1644
 
1567 1645
 	// Removing a member from the ignore list?
1568 1646
 	if (isset($_GET['remove']))
@@ -1572,10 +1650,11 @@  discard block
 block discarded – undo
1572 1650
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1573 1651
 
1574 1652
 		// Heh, I'm lazy, do it the easy way...
1575
-		foreach ($ignoreArray as $key => $id_remove)
1576
-			if ($id_remove == (int) $_GET['remove'])
1653
+		foreach ($ignoreArray as $key => $id_remove) {
1654
+					if ($id_remove == (int) $_GET['remove'])
1577 1655
 			{
1578 1656
 				unset($ignoreArray[$key]);
1657
+		}
1579 1658
 				$_SESSION['prf-save'] = true;
1580 1659
 			}
1581 1660
 
@@ -1585,8 +1664,7 @@  discard block
 block discarded – undo
1585 1664
 
1586 1665
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1587 1666
 		redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
1588
-	}
1589
-	elseif (isset($_POST['new_ignore']))
1667
+	} elseif (isset($_POST['new_ignore']))
1590 1668
 	{
1591 1669
 		checkSession();
1592 1670
 		// Prepare the string for extraction...
@@ -1598,8 +1676,9 @@  discard block
 block discarded – undo
1598 1676
 		{
1599 1677
 			$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
1600 1678
 
1601
-			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1602
-				unset($new_entries[$k]);
1679
+			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1680
+							unset($new_entries[$k]);
1681
+			}
1603 1682
 		}
1604 1683
 
1605 1684
 		$_SESSION['prf-save'] = $txt['could_not_add_person'];
@@ -1617,16 +1696,18 @@  discard block
 block discarded – undo
1617 1696
 				)
1618 1697
 			);
1619 1698
 
1620
-			if ($smcFunc['db_num_rows']($request) != 0)
1621
-				$_SESSION['prf-save'] = true;
1699
+			if ($smcFunc['db_num_rows']($request) != 0) {
1700
+							$_SESSION['prf-save'] = true;
1701
+			}
1622 1702
 
1623 1703
 			// Add the new member to the buddies array.
1624 1704
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1625 1705
 			{
1626
-				if (in_array($row['id_member'], $ignoreArray))
1627
-					continue;
1628
-				else
1629
-					$ignoreArray[] = (int) $row['id_member'];
1706
+				if (in_array($row['id_member'], $ignoreArray)) {
1707
+									continue;
1708
+				} else {
1709
+									$ignoreArray[] = (int) $row['id_member'];
1710
+				}
1630 1711
 			}
1631 1712
 			$smcFunc['db_free_result']($request);
1632 1713
 
@@ -1655,8 +1736,9 @@  discard block
 block discarded – undo
1655 1736
 				'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
1656 1737
 			)
1657 1738
 		);
1658
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1659
-			$ignored[] = $row['id_member'];
1739
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1740
+					$ignored[] = $row['id_member'];
1741
+		}
1660 1742
 		$smcFunc['db_free_result']($result);
1661 1743
 	}
1662 1744
 
@@ -1675,10 +1757,11 @@  discard block
 block discarded – undo
1675 1757
 
1676 1758
 	if (isset($_SESSION['prf-save']))
1677 1759
 	{
1678
-		if ($_SESSION['prf-save'] === true)
1679
-			$context['saved_successful'] = true;
1680
-		else
1681
-			$context['saved_failed'] = $_SESSION['prf-save'];
1760
+		if ($_SESSION['prf-save'] === true) {
1761
+					$context['saved_successful'] = true;
1762
+		} else {
1763
+					$context['saved_failed'] = $_SESSION['prf-save'];
1764
+		}
1682 1765
 
1683 1766
 		unset($_SESSION['prf-save']);
1684 1767
 	}
@@ -1694,8 +1777,9 @@  discard block
 block discarded – undo
1694 1777
 	global $context, $txt;
1695 1778
 
1696 1779
 	loadThemeOptions($memID);
1697
-	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
1698
-		loadCustomFields($memID, 'account');
1780
+	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) {
1781
+			loadCustomFields($memID, 'account');
1782
+	}
1699 1783
 
1700 1784
 	$context['sub_template'] = 'edit_options';
1701 1785
 	$context['page_desc'] = $txt['account_info'];
@@ -1722,8 +1806,9 @@  discard block
 block discarded – undo
1722 1806
 	global $context, $txt;
1723 1807
 
1724 1808
 	loadThemeOptions($memID);
1725
-	if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
1726
-		loadCustomFields($memID, 'forumprofile');
1809
+	if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) {
1810
+			loadCustomFields($memID, 'forumprofile');
1811
+	}
1727 1812
 
1728 1813
 	$context['sub_template'] = 'edit_options';
1729 1814
 	$context['page_desc'] = $txt['forumProfile_info'];
@@ -1756,18 +1841,21 @@  discard block
 block discarded – undo
1756 1841
 	$dirs = array();
1757 1842
 	$files = array();
1758 1843
 
1759
-	if (!$dir)
1760
-		return array();
1844
+	if (!$dir) {
1845
+			return array();
1846
+	}
1761 1847
 
1762 1848
 	while ($line = $dir->read())
1763 1849
 	{
1764
-		if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
1765
-			continue;
1850
+		if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) {
1851
+					continue;
1852
+		}
1766 1853
 
1767
-		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
1768
-			$dirs[] = $line;
1769
-		else
1770
-			$files[] = $line;
1854
+		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) {
1855
+					$dirs[] = $line;
1856
+		} else {
1857
+					$files[] = $line;
1858
+		}
1771 1859
 	}
1772 1860
 	$dir->close();
1773 1861
 
@@ -1788,14 +1876,15 @@  discard block
 block discarded – undo
1788 1876
 	foreach ($dirs as $line)
1789 1877
 	{
1790 1878
 		$tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
1791
-		if (!empty($tmp))
1792
-			$result[] = array(
1879
+		if (!empty($tmp)) {
1880
+					$result[] = array(
1793 1881
 				'filename' => $smcFunc['htmlspecialchars']($line),
1794 1882
 				'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
1795 1883
 				'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
1796 1884
 				'is_dir' => true,
1797 1885
 				'files' => $tmp
1798 1886
 		);
1887
+		}
1799 1888
 		unset($tmp);
1800 1889
 	}
1801 1890
 
@@ -1805,8 +1894,9 @@  discard block
 block discarded – undo
1805 1894
 		$extension = substr(strrchr($line, '.'), 1);
1806 1895
 
1807 1896
 		// Make sure it is an image.
1808
-		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
1809
-			continue;
1897
+		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) {
1898
+					continue;
1899
+		}
1810 1900
 
1811 1901
 		$result[] = array(
1812 1902
 			'filename' => $smcFunc['htmlspecialchars']($line),
@@ -1814,8 +1904,9 @@  discard block
 block discarded – undo
1814 1904
 			'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
1815 1905
 			'is_dir' => false
1816 1906
 		);
1817
-		if ($level == 1)
1818
-			$context['avatar_list'][] = $directory . '/' . $line;
1907
+		if ($level == 1) {
1908
+					$context['avatar_list'][] = $directory . '/' . $line;
1909
+		}
1819 1910
 	}
1820 1911
 
1821 1912
 	return $result;
@@ -1837,8 +1928,9 @@  discard block
 block discarded – undo
1837 1928
 	call_integration_hook('integrate_theme_options');
1838 1929
 
1839 1930
 	loadThemeOptions($memID);
1840
-	if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
1841
-		loadCustomFields($memID, 'theme');
1931
+	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) {
1932
+			loadCustomFields($memID, 'theme');
1933
+	}
1842 1934
 
1843 1935
 	$context['sub_template'] = 'edit_options';
1844 1936
 	$context['page_desc'] = $txt['theme_info'];
@@ -1892,16 +1984,19 @@  discard block
 block discarded – undo
1892 1984
 {
1893 1985
 	global $txt, $context, $modSettings, $smcFunc, $sourcedir;
1894 1986
 
1895
-	if (!isset($context['token_check']))
1896
-		$context['token_check'] = 'profile-nt' . $memID;
1987
+	if (!isset($context['token_check'])) {
1988
+			$context['token_check'] = 'profile-nt' . $memID;
1989
+	}
1897 1990
 
1898 1991
 	is_not_guest();
1899
-	if (!$context['user']['is_owner'])
1900
-		isAllowedTo('profile_extra_any');
1992
+	if (!$context['user']['is_owner']) {
1993
+			isAllowedTo('profile_extra_any');
1994
+	}
1901 1995
 
1902 1996
 	// Set the post action if we're coming from the profile...
1903
-	if (!isset($context['action']))
1904
-		$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1997
+	if (!isset($context['action'])) {
1998
+			$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1999
+	}
1905 2000
 
1906 2001
 	// What options are set
1907 2002
 	loadThemeOptions($memID);
@@ -1988,28 +2083,34 @@  discard block
 block discarded – undo
1988 2083
 	);
1989 2084
 
1990 2085
 	// There are certain things that are disabled at the group level.
1991
-	if (empty($modSettings['cal_enabled']))
1992
-		unset($alert_types['calendar']);
2086
+	if (empty($modSettings['cal_enabled'])) {
2087
+			unset($alert_types['calendar']);
2088
+	}
1993 2089
 
1994 2090
 	// Disable paid subscriptions at group level if they're disabled
1995
-	if (empty($modSettings['paid_enabled']))
1996
-		unset($alert_types['paidsubs']);
2091
+	if (empty($modSettings['paid_enabled'])) {
2092
+			unset($alert_types['paidsubs']);
2093
+	}
1997 2094
 
1998 2095
 	// Disable membergroup requests at group level if they're disabled
1999
-	if (empty($modSettings['show_group_membership']))
2000
-		unset($alert_types['groupr'], $alert_types['members']['request_group']);
2096
+	if (empty($modSettings['show_group_membership'])) {
2097
+			unset($alert_types['groupr'], $alert_types['members']['request_group']);
2098
+	}
2001 2099
 
2002 2100
 	// Disable mentions if they're disabled
2003
-	if (empty($modSettings['enable_mentions']))
2004
-		unset($alert_types['msg']['msg_mention']);
2101
+	if (empty($modSettings['enable_mentions'])) {
2102
+			unset($alert_types['msg']['msg_mention']);
2103
+	}
2005 2104
 
2006 2105
 	// Disable likes if they're disabled
2007
-	if (empty($modSettings['enable_likes']))
2008
-		unset($alert_types['msg']['msg_like']);
2106
+	if (empty($modSettings['enable_likes'])) {
2107
+			unset($alert_types['msg']['msg_like']);
2108
+	}
2009 2109
 
2010 2110
 	// Disable buddy requests if they're disabled
2011
-	if (empty($modSettings['enable_buddylist']))
2012
-		unset($alert_types['members']['buddy_request']);
2111
+	if (empty($modSettings['enable_buddylist'])) {
2112
+			unset($alert_types['members']['buddy_request']);
2113
+	}
2013 2114
 
2014 2115
 	// Now, now, we could pass this through global but we should really get into the habit of
2015 2116
 	// passing content to hooks, not expecting hooks to splatter everything everywhere.
@@ -2037,15 +2138,17 @@  discard block
 block discarded – undo
2037 2138
 			$perms_cache['manage_membergroups'] = in_array($memID, $members);
2038 2139
 		}
2039 2140
 
2040
-		if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
2041
-			unset($alert_types['members']['request_group']);
2141
+		if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) {
2142
+					unset($alert_types['members']['request_group']);
2143
+		}
2042 2144
 
2043 2145
 		foreach ($alert_types as $group => $items)
2044 2146
 		{
2045 2147
 			foreach ($items as $alert_key => $alert_value)
2046 2148
 			{
2047
-				if (!isset($alert_value['permission']))
2048
-					continue;
2149
+				if (!isset($alert_value['permission'])) {
2150
+									continue;
2151
+				}
2049 2152
 				if (!isset($perms_cache[$alert_value['permission']['name']]))
2050 2153
 				{
2051 2154
 					$in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
@@ -2053,12 +2156,14 @@  discard block
 block discarded – undo
2053 2156
 					$perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
2054 2157
 				}
2055 2158
 
2056
-				if (!$perms_cache[$alert_value['permission']['name']])
2057
-					unset ($alert_types[$group][$alert_key]);
2159
+				if (!$perms_cache[$alert_value['permission']['name']]) {
2160
+									unset ($alert_types[$group][$alert_key]);
2161
+				}
2058 2162
 			}
2059 2163
 
2060
-			if (empty($alert_types[$group]))
2061
-				unset ($alert_types[$group]);
2164
+			if (empty($alert_types[$group])) {
2165
+							unset ($alert_types[$group]);
2166
+			}
2062 2167
 		}
2063 2168
 	}
2064 2169
 
@@ -2090,9 +2195,9 @@  discard block
 block discarded – undo
2090 2195
 						$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
2091 2196
 						break;
2092 2197
 					case 'select':
2093
-						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
2094
-							$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2095
-						else
2198
+						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) {
2199
+													$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2200
+						} else
2096 2201
 						{
2097 2202
 							// We didn't have a sane value. Let's grab the first item from the possibles.
2098 2203
 							$keys = array_keys($this_option['opts']);
@@ -2112,23 +2217,28 @@  discard block
 block discarded – undo
2112 2217
 				$this_value = 0;
2113 2218
 				foreach ($context['alert_bits'] as $type => $bitvalue)
2114 2219
 				{
2115
-					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always')
2116
-						$this_value |= $bitvalue;
2220
+					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') {
2221
+											$this_value |= $bitvalue;
2222
+					}
2223
+				}
2224
+				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) {
2225
+									$update_prefs[$item_key] = $this_value;
2117 2226
 				}
2118
-				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value)
2119
-					$update_prefs[$item_key] = $this_value;
2120 2227
 			}
2121 2228
 		}
2122 2229
 
2123
-		if (!empty($_POST['opt_alert_timeout']))
2124
-			$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2230
+		if (!empty($_POST['opt_alert_timeout'])) {
2231
+					$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2232
+		}
2125 2233
 
2126
-		if (!empty($_POST['notify_announcements']))
2127
-			$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2234
+		if (!empty($_POST['notify_announcements'])) {
2235
+					$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2236
+		}
2128 2237
 
2129 2238
 		setNotifyPrefs((int) $memID, $update_prefs);
2130
-		foreach ($update_prefs as $pref => $value)
2131
-			$context['alert_prefs'][$pref] = $value;
2239
+		foreach ($update_prefs as $pref => $value) {
2240
+					$context['alert_prefs'][$pref] = $value;
2241
+		}
2132 2242
 
2133 2243
 		makeNotificationChanges($memID);
2134 2244
 
@@ -2158,8 +2268,9 @@  discard block
 block discarded – undo
2158 2268
 
2159 2269
 	// Now we're all set up.
2160 2270
 	is_not_guest();
2161
-	if (!$context['user']['is_owner'])
2162
-		fatal_error('no_access');
2271
+	if (!$context['user']['is_owner']) {
2272
+			fatal_error('no_access');
2273
+	}
2163 2274
 
2164 2275
 	checkSession('get');
2165 2276
 
@@ -2191,8 +2302,9 @@  discard block
 block discarded – undo
2191 2302
 {
2192 2303
 	global $smcFunc;
2193 2304
 
2194
-	if (empty($toMark) || empty($memID))
2195
-		return false;
2305
+	if (empty($toMark) || empty($memID)) {
2306
+			return false;
2307
+	}
2196 2308
 
2197 2309
 	$toMark = (array) $toMark;
2198 2310
 
@@ -2226,8 +2338,9 @@  discard block
 block discarded – undo
2226 2338
 {
2227 2339
 	global $smcFunc;
2228 2340
 
2229
-	if (empty($toDelete))
2230
-		return false;
2341
+	if (empty($toDelete)) {
2342
+			return false;
2343
+	}
2231 2344
 
2232 2345
 	$toDelete = (array) $toDelete;
2233 2346
 
@@ -2262,8 +2375,9 @@  discard block
 block discarded – undo
2262 2375
 {
2263 2376
 	global $smcFunc;
2264 2377
 
2265
-	if (empty($memID))
2266
-		return false;
2378
+	if (empty($memID)) {
2379
+			return false;
2380
+	}
2267 2381
 
2268 2382
 	$request = $smcFunc['db_query']('', '
2269 2383
 		SELECT id_alert
@@ -2340,8 +2454,9 @@  discard block
 block discarded – undo
2340 2454
 					{
2341 2455
 						$link = $topic['link'];
2342 2456
 
2343
-						if ($topic['new'])
2344
-							$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2457
+						if ($topic['new']) {
2458
+													$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2459
+						}
2345 2460
 
2346 2461
 						$link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>';
2347 2462
 
@@ -2492,8 +2607,9 @@  discard block
 block discarded – undo
2492 2607
 					{
2493 2608
 						$link = $board['link'];
2494 2609
 
2495
-						if ($board['new'])
2496
-							$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2610
+						if ($board['new']) {
2611
+													$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2612
+						}
2497 2613
 
2498 2614
 						return $link;
2499 2615
 					},
@@ -2693,8 +2809,8 @@  discard block
 block discarded – undo
2693 2809
 		)
2694 2810
 	);
2695 2811
 	$notification_boards = array();
2696
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2697
-		$notification_boards[] = array(
2812
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2813
+			$notification_boards[] = array(
2698 2814
 			'id' => $row['id_board'],
2699 2815
 			'name' => $row['name'],
2700 2816
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
@@ -2702,6 +2818,7 @@  discard block
 block discarded – undo
2702 2818
 			'new' => $row['board_read'] < $row['id_msg_updated'],
2703 2819
 			'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0),
2704 2820
 		);
2821
+	}
2705 2822
 	$smcFunc['db_free_result']($request);
2706 2823
 
2707 2824
 	return $notification_boards;
@@ -2716,17 +2833,18 @@  discard block
 block discarded – undo
2716 2833
 {
2717 2834
 	global $context, $options, $cur_profile, $smcFunc;
2718 2835
 
2719
-	if (isset($_POST['default_options']))
2720
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2836
+	if (isset($_POST['default_options'])) {
2837
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2838
+	}
2721 2839
 
2722 2840
 	if ($context['user']['is_owner'])
2723 2841
 	{
2724 2842
 		$context['member']['options'] = $options;
2725
-		if (isset($_POST['options']) && is_array($_POST['options']))
2726
-			foreach ($_POST['options'] as $k => $v)
2843
+		if (isset($_POST['options']) && is_array($_POST['options'])) {
2844
+					foreach ($_POST['options'] as $k => $v)
2727 2845
 				$context['member']['options'][$k] = $v;
2728
-	}
2729
-	else
2846
+		}
2847
+	} else
2730 2848
 	{
2731 2849
 		$request = $smcFunc['db_query']('', '
2732 2850
 			SELECT id_member, variable, value
@@ -2747,8 +2865,9 @@  discard block
 block discarded – undo
2747 2865
 				continue;
2748 2866
 			}
2749 2867
 
2750
-			if (isset($_POST['options'][$row['variable']]))
2751
-				$row['value'] = $_POST['options'][$row['variable']];
2868
+			if (isset($_POST['options'][$row['variable']])) {
2869
+							$row['value'] = $_POST['options'][$row['variable']];
2870
+			}
2752 2871
 			$context['member']['options'][$row['variable']] = $row['value'];
2753 2872
 		}
2754 2873
 		$smcFunc['db_free_result']($request);
@@ -2756,8 +2875,9 @@  discard block
 block discarded – undo
2756 2875
 		// Load up the default theme options for any missing.
2757 2876
 		foreach ($temp as $k => $v)
2758 2877
 		{
2759
-			if (!isset($context['member']['options'][$k]))
2760
-				$context['member']['options'][$k] = $v;
2878
+			if (!isset($context['member']['options'][$k])) {
2879
+							$context['member']['options'][$k] = $v;
2880
+			}
2761 2881
 		}
2762 2882
 	}
2763 2883
 }
@@ -2772,8 +2892,9 @@  discard block
 block discarded – undo
2772 2892
 	global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir;
2773 2893
 
2774 2894
 	// Have the admins enabled this option?
2775
-	if (empty($modSettings['allow_ignore_boards']))
2776
-		fatal_lang_error('ignoreboards_disallowed', 'user');
2895
+	if (empty($modSettings['allow_ignore_boards'])) {
2896
+			fatal_lang_error('ignoreboards_disallowed', 'user');
2897
+	}
2777 2898
 
2778 2899
 	// Find all the boards this user is allowed to see.
2779 2900
 	$request = $smcFunc['db_query']('order_by_board_order', '
@@ -2793,12 +2914,13 @@  discard block
 block discarded – undo
2793 2914
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2794 2915
 	{
2795 2916
 		// This category hasn't been set up yet..
2796
-		if (!isset($context['categories'][$row['id_cat']]))
2797
-			$context['categories'][$row['id_cat']] = array(
2917
+		if (!isset($context['categories'][$row['id_cat']])) {
2918
+					$context['categories'][$row['id_cat']] = array(
2798 2919
 				'id' => $row['id_cat'],
2799 2920
 				'name' => $row['cat_name'],
2800 2921
 				'boards' => array()
2801 2922
 			);
2923
+		}
2802 2924
 
2803 2925
 		// Set this board up, and let the template know when it's a child.  (indent them..)
2804 2926
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -2828,18 +2950,20 @@  discard block
 block discarded – undo
2828 2950
 	}
2829 2951
 
2830 2952
 	$max_boards = ceil(count($temp_boards) / 2);
2831
-	if ($max_boards == 1)
2832
-		$max_boards = 2;
2953
+	if ($max_boards == 1) {
2954
+			$max_boards = 2;
2955
+	}
2833 2956
 
2834 2957
 	// Now, alternate them so they can be shown left and right ;).
2835 2958
 	$context['board_columns'] = array();
2836 2959
 	for ($i = 0; $i < $max_boards; $i++)
2837 2960
 	{
2838 2961
 		$context['board_columns'][] = $temp_boards[$i];
2839
-		if (isset($temp_boards[$i + $max_boards]))
2840
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
2841
-		else
2842
-			$context['board_columns'][] = array();
2962
+		if (isset($temp_boards[$i + $max_boards])) {
2963
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
2964
+		} else {
2965
+					$context['board_columns'][] = array();
2966
+		}
2843 2967
 	}
2844 2968
 
2845 2969
 	loadThemeOptions($memID);
@@ -2908,8 +3032,9 @@  discard block
 block discarded – undo
2908 3032
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2909 3033
 	{
2910 3034
 		// We should skip the administrator group if they don't have the admin_forum permission!
2911
-		if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
2912
-			continue;
3035
+		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) {
3036
+					continue;
3037
+		}
2913 3038
 
2914 3039
 		$context['member_groups'][$row['id_group']] = array(
2915 3040
 			'id' => $row['id_group'],
@@ -2955,16 +3080,17 @@  discard block
 block discarded – undo
2955 3080
 	$context['max_signature_length'] = $context['signature_limits']['max_length'];
2956 3081
 	// Warning message for signature image limits?
2957 3082
 	$context['signature_warning'] = '';
2958
-	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
2959
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
2960
-	elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
2961
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3083
+	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) {
3084
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
3085
+	} elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) {
3086
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3087
+	}
2962 3088
 
2963 3089
 	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
2964 3090
 
2965
-	if (empty($context['do_preview']))
2966
-		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
2967
-	else
3091
+	if (empty($context['do_preview'])) {
3092
+			$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
3093
+	} else
2968 3094
 	{
2969 3095
 		$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
2970 3096
 		$validation = profileValidateSignature($signature);
@@ -2974,8 +3100,9 @@  discard block
 block discarded – undo
2974 3100
 			$context['post_errors'] = array();
2975 3101
 		}
2976 3102
 		$context['post_errors'][] = 'signature_not_yet_saved';
2977
-		if ($validation !== true && $validation !== false)
2978
-			$context['post_errors'][] = $validation;
3103
+		if ($validation !== true && $validation !== false) {
3104
+					$context['post_errors'][] = $validation;
3105
+		}
2979 3106
 
2980 3107
 		censorText($context['member']['signature']);
2981 3108
 		$context['member']['current_signature'] = $context['member']['signature'];
@@ -2985,8 +3112,9 @@  discard block
 block discarded – undo
2985 3112
 	}
2986 3113
 
2987 3114
 	// Load the spell checker?
2988
-	if ($context['show_spellchecking'])
2989
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3115
+	if ($context['show_spellchecking']) {
3116
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3117
+	}
2990 3118
 
2991 3119
 	return true;
2992 3120
 }
@@ -3020,8 +3148,7 @@  discard block
 block discarded – undo
3020 3148
 			'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11)
3021 3149
 		);
3022 3150
 		$context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']);
3023
-	}
3024
-	elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3151
+	} elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3025 3152
 	{
3026 3153
 		$context['member']['avatar'] += array(
3027 3154
 			'choice' => 'upload',
@@ -3031,33 +3158,34 @@  discard block
 block discarded – undo
3031 3158
 		$context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename'];
3032 3159
 	}
3033 3160
 	// Use "avatar_original" here so we show what the user entered even if the image proxy is enabled
3034
-	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
3035
-		$context['member']['avatar'] += array(
3161
+	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) {
3162
+			$context['member']['avatar'] += array(
3036 3163
 			'choice' => 'external',
3037 3164
 			'server_pic' => 'blank.png',
3038 3165
 			'external' => $cur_profile['avatar_original']
3039 3166
 		);
3040
-	elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
3041
-		$context['member']['avatar'] += array(
3167
+	} elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) {
3168
+			$context['member']['avatar'] += array(
3042 3169
 			'choice' => 'server_stored',
3043 3170
 			'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
3044 3171
 			'external' => 'http://'
3045 3172
 		);
3046
-	else
3047
-		$context['member']['avatar'] += array(
3173
+	} else {
3174
+			$context['member']['avatar'] += array(
3048 3175
 			'choice' => 'none',
3049 3176
 			'server_pic' => 'blank.png',
3050 3177
 			'external' => 'http://'
3051 3178
 		);
3179
+	}
3052 3180
 
3053 3181
 	// Get a list of all the avatars.
3054 3182
 	if ($context['member']['avatar']['allow_server_stored'])
3055 3183
 	{
3056 3184
 		$context['avatar_list'] = array();
3057 3185
 		$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
3186
+	} else {
3187
+			$context['avatars'] = array();
3058 3188
 	}
3059
-	else
3060
-		$context['avatars'] = array();
3061 3189
 
3062 3190
 	// Second level selected avatar...
3063 3191
 	$context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
@@ -3086,19 +3214,22 @@  discard block
 block discarded – undo
3086 3214
 			)
3087 3215
 		);
3088 3216
 		$protected_groups = array(1);
3089
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3090
-			$protected_groups[] = $row['id_group'];
3217
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3218
+					$protected_groups[] = $row['id_group'];
3219
+		}
3091 3220
 		$smcFunc['db_free_result']($request);
3092 3221
 
3093 3222
 		$protected_groups = array_unique($protected_groups);
3094 3223
 	}
3095 3224
 
3096 3225
 	// The account page allows the change of your id_group - but not to a protected group!
3097
-	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
3098
-		$value = (int) $value;
3226
+	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) {
3227
+			$value = (int) $value;
3228
+	}
3099 3229
 	// ... otherwise it's the old group sir.
3100
-	else
3101
-		$value = $old_profile['id_group'];
3230
+	else {
3231
+			$value = $old_profile['id_group'];
3232
+	}
3102 3233
 
3103 3234
 	// Find the additional membergroups (if any)
3104 3235
 	if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
@@ -3107,16 +3238,18 @@  discard block
 block discarded – undo
3107 3238
 		foreach ($_POST['additional_groups'] as $group_id)
3108 3239
 		{
3109 3240
 			$group_id = (int) $group_id;
3110
-			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
3111
-				$additional_groups[] = $group_id;
3241
+			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) {
3242
+							$additional_groups[] = $group_id;
3243
+			}
3112 3244
 		}
3113 3245
 
3114 3246
 		// Put the protected groups back in there if you don't have permission to take them away.
3115 3247
 		$old_additional_groups = explode(',', $old_profile['additional_groups']);
3116 3248
 		foreach ($old_additional_groups as $group_id)
3117 3249
 		{
3118
-			if (!empty($protected_groups) && in_array($group_id, $protected_groups))
3119
-				$additional_groups[] = $group_id;
3250
+			if (!empty($protected_groups) && in_array($group_id, $protected_groups)) {
3251
+							$additional_groups[] = $group_id;
3252
+			}
3120 3253
 		}
3121 3254
 
3122 3255
 		if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
@@ -3148,18 +3281,20 @@  discard block
 block discarded – undo
3148 3281
 			list ($another) = $smcFunc['db_fetch_row']($request);
3149 3282
 			$smcFunc['db_free_result']($request);
3150 3283
 
3151
-			if (empty($another))
3152
-				fatal_lang_error('at_least_one_admin', 'critical');
3284
+			if (empty($another)) {
3285
+							fatal_lang_error('at_least_one_admin', 'critical');
3286
+			}
3153 3287
 		}
3154 3288
 	}
3155 3289
 
3156 3290
 	// If we are changing group status, update permission cache as necessary.
3157 3291
 	if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
3158 3292
 	{
3159
-		if ($context['user']['is_owner'])
3160
-			$_SESSION['mc']['time'] = 0;
3161
-		else
3162
-			updateSettings(array('settings_updated' => time()));
3293
+		if ($context['user']['is_owner']) {
3294
+					$_SESSION['mc']['time'] = 0;
3295
+		} else {
3296
+					updateSettings(array('settings_updated' => time()));
3297
+		}
3163 3298
 	}
3164 3299
 
3165 3300
 	// Announce to any hooks that we have changed groups, but don't allow them to change it.
@@ -3180,8 +3315,9 @@  discard block
 block discarded – undo
3180 3315
 	global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
3181 3316
 
3182 3317
 	$memID = $context['id_member'];
3183
-	if (empty($memID) && !empty($context['password_auth_failed']))
3184
-		return false;
3318
+	if (empty($memID) && !empty($context['password_auth_failed'])) {
3319
+			return false;
3320
+	}
3185 3321
 
3186 3322
 	require_once($sourcedir . '/ManageAttachments.php');
3187 3323
 
@@ -3192,8 +3328,9 @@  discard block
 block discarded – undo
3192 3328
 	$downloadedExternalAvatar = false;
3193 3329
 	if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external']))
3194 3330
 	{
3195
-		if (!is_writable($uploadDir))
3196
-			fatal_lang_error('attachments_no_write', 'critical');
3331
+		if (!is_writable($uploadDir)) {
3332
+					fatal_lang_error('attachments_no_write', 'critical');
3333
+		}
3197 3334
 
3198 3335
 		$url = parse_url($_POST['userpicpersonal']);
3199 3336
 		$contents = fetch_web_data($url['scheme'] . '://' . $url['host'] . (empty($url['port']) ? '' : ':' . $url['port']) . str_replace(' ', '%20', trim($url['path'])));
@@ -3235,19 +3372,18 @@  discard block
 block discarded – undo
3235 3372
 
3236 3373
 		// Get rid of their old avatar. (if uploaded.)
3237 3374
 		removeAttachments(array('id_member' => $memID));
3238
-	}
3239
-	elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3375
+	} elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3240 3376
 	{
3241 3377
 		// One wasn't specified, or it's not allowed to use extra email addresses, or it's not a valid one, reset to default Gravatar.
3242
-		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL))
3243
-			$profile_vars['avatar'] = 'gravatar://';
3244
-		else
3245
-			$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3378
+		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) {
3379
+					$profile_vars['avatar'] = 'gravatar://';
3380
+		} else {
3381
+					$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3382
+		}
3246 3383
 
3247 3384
 		// Get rid of their old avatar. (if uploaded.)
3248 3385
 		removeAttachments(array('id_member' => $memID));
3249
-	}
3250
-	elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3386
+	} elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3251 3387
 	{
3252 3388
 		// We need these clean...
3253 3389
 		$cur_profile['id_attach'] = 0;
@@ -3259,11 +3395,13 @@  discard block
 block discarded – undo
3259 3395
 
3260 3396
 		$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
3261 3397
 
3262
-		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
3263
-			$profile_vars['avatar'] = '';
3398
+		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') {
3399
+					$profile_vars['avatar'] = '';
3400
+		}
3264 3401
 		// Trying to make us do something we'll regret?
3265
-		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
3266
-			return 'bad_avatar_invalid_url';
3402
+		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') {
3403
+					return 'bad_avatar_invalid_url';
3404
+		}
3267 3405
 		// Should we check dimensions?
3268 3406
 		elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
3269 3407
 		{
@@ -3273,9 +3411,9 @@  discard block
 block discarded – undo
3273 3411
 			if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
3274 3412
 			{
3275 3413
 				// Houston, we have a problem. The avatar is too large!!
3276
-				if ($modSettings['avatar_action_too_large'] == 'option_refuse')
3277
-					return 'bad_avatar_too_large';
3278
-				elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3414
+				if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
3415
+									return 'bad_avatar_too_large';
3416
+				} elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3279 3417
 				{
3280 3418
 					// @todo remove this if appropriate
3281 3419
 					require_once($sourcedir . '/Subs-Graphics.php');
@@ -3285,26 +3423,27 @@  discard block
 block discarded – undo
3285 3423
 						$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
3286 3424
 						$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
3287 3425
 						$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
3426
+					} else {
3427
+											return 'bad_avatar';
3288 3428
 					}
3289
-					else
3290
-						return 'bad_avatar';
3291 3429
 				}
3292 3430
 			}
3293 3431
 		}
3294
-	}
3295
-	elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3432
+	} elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3296 3433
 	{
3297 3434
 		if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
3298 3435
 		{
3299 3436
 			// Get the dimensions of the image.
3300 3437
 			if (!$downloadedExternalAvatar)
3301 3438
 			{
3302
-				if (!is_writable($uploadDir))
3303
-					fatal_lang_error('attachments_no_write', 'critical');
3439
+				if (!is_writable($uploadDir)) {
3440
+									fatal_lang_error('attachments_no_write', 'critical');
3441
+				}
3304 3442
 
3305 3443
 				$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
3306
-				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
3307
-					fatal_lang_error('attach_timeout', 'critical');
3444
+				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) {
3445
+									fatal_lang_error('attach_timeout', 'critical');
3446
+				}
3308 3447
 
3309 3448
 				$_FILES['attachment']['tmp_name'] = $new_filename;
3310 3449
 			}
@@ -3417,17 +3556,19 @@  discard block
 block discarded – undo
3417 3556
 			$profile_vars['avatar'] = '';
3418 3557
 
3419 3558
 			// Delete any temporary file.
3420
-			if (file_exists($_FILES['attachment']['tmp_name']))
3421
-				@unlink($_FILES['attachment']['tmp_name']);
3559
+			if (file_exists($_FILES['attachment']['tmp_name'])) {
3560
+							@unlink($_FILES['attachment']['tmp_name']);
3561
+			}
3422 3562
 		}
3423 3563
 		// Selected the upload avatar option and had one already uploaded before or didn't upload one.
3424
-		else
3564
+		else {
3565
+					$profile_vars['avatar'] = '';
3566
+		}
3567
+	} elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) {
3568
+			$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3569
+	} else {
3425 3570
 			$profile_vars['avatar'] = '';
3426 3571
 	}
3427
-	elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar'))
3428
-		$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3429
-	else
3430
-		$profile_vars['avatar'] = '';
3431 3572
 
3432 3573
 	// Setup the profile variables so it shows things right on display!
3433 3574
 	$cur_profile['avatar'] = $profile_vars['avatar'];
@@ -3475,9 +3616,9 @@  discard block
 block discarded – undo
3475 3616
 		$smiley_parsed = $unparsed_signature;
3476 3617
 		parsesmileys($smiley_parsed);
3477 3618
 		$smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
3478
-		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
3479
-			return 'signature_allow_smileys';
3480
-		elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3619
+		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) {
3620
+					return 'signature_allow_smileys';
3621
+		} elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3481 3622
 		{
3482 3623
 			$txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
3483 3624
 			return 'signature_max_smileys';
@@ -3490,14 +3631,15 @@  discard block
 block discarded – undo
3490 3631
 			{
3491 3632
 				$limit_broke = 0;
3492 3633
 				// Attempt to allow all sizes of abuse, so to speak.
3493
-				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
3494
-					$limit_broke = $sig_limits[7] . 'px';
3495
-				elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
3496
-					$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3497
-				elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
3498
-					$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3499
-				elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
3500
-					$limit_broke = 'large';
3634
+				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
3635
+									$limit_broke = $sig_limits[7] . 'px';
3636
+				} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
3637
+									$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3638
+				} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
3639
+									$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3640
+				} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
3641
+									$limit_broke = 'large';
3642
+				}
3501 3643
 
3502 3644
 				if ($limit_broke)
3503 3645
 				{
@@ -3539,24 +3681,26 @@  discard block
 block discarded – undo
3539 3681
 					$width = -1; $height = -1;
3540 3682
 
3541 3683
 					// Does it have predefined restraints? Width first.
3542
-					if ($matches[6][$key])
3543
-						$matches[2][$key] = $matches[6][$key];
3684
+					if ($matches[6][$key]) {
3685
+											$matches[2][$key] = $matches[6][$key];
3686
+					}
3544 3687
 					if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
3545 3688
 					{
3546 3689
 						$width = $sig_limits[5];
3547 3690
 						$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
3691
+					} elseif ($matches[2][$key]) {
3692
+											$width = $matches[2][$key];
3548 3693
 					}
3549
-					elseif ($matches[2][$key])
3550
-						$width = $matches[2][$key];
3551 3694
 					// ... and height.
3552 3695
 					if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
3553 3696
 					{
3554 3697
 						$height = $sig_limits[6];
3555
-						if ($width != -1)
3556
-							$width = $width * ($height / $matches[4][$key]);
3698
+						if ($width != -1) {
3699
+													$width = $width * ($height / $matches[4][$key]);
3700
+						}
3701
+					} elseif ($matches[4][$key]) {
3702
+											$height = $matches[4][$key];
3557 3703
 					}
3558
-					elseif ($matches[4][$key])
3559
-						$height = $matches[4][$key];
3560 3704
 
3561 3705
 					// If the dimensions are still not fixed - we need to check the actual image.
3562 3706
 					if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -3574,21 +3718,24 @@  discard block
 block discarded – undo
3574 3718
 							if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
3575 3719
 							{
3576 3720
 								$height = $sig_limits[6];
3577
-								if ($width == -1)
3578
-									$width = $sizes[0];
3721
+								if ($width == -1) {
3722
+																	$width = $sizes[0];
3723
+								}
3579 3724
 								$width = $width * ($height / $sizes[1]);
3725
+							} elseif ($width != -1) {
3726
+															$height = $sizes[1];
3580 3727
 							}
3581
-							elseif ($width != -1)
3582
-								$height = $sizes[1];
3583 3728
 						}
3584 3729
 					}
3585 3730
 
3586 3731
 					// Did we come up with some changes? If so remake the string.
3587
-					if ($width != -1 || $height != -1)
3588
-						$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3732
+					if ($width != -1 || $height != -1) {
3733
+											$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3734
+					}
3735
+				}
3736
+				if (!empty($replaces)) {
3737
+									$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3589 3738
 				}
3590
-				if (!empty($replaces))
3591
-					$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3592 3739
 			}
3593 3740
 		}
3594 3741
 
@@ -3632,10 +3779,12 @@  discard block
 block discarded – undo
3632 3779
 	$email = strtr($email, array('&#039;' => '\''));
3633 3780
 
3634 3781
 	// Check the name and email for validity.
3635
-	if (trim($email) == '')
3636
-		return 'no_email';
3637
-	if (!filter_var($email, FILTER_VALIDATE_EMAIL))
3638
-		return 'bad_email';
3782
+	if (trim($email) == '') {
3783
+			return 'no_email';
3784
+	}
3785
+	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
3786
+			return 'bad_email';
3787
+	}
3639 3788
 
3640 3789
 	// Email addresses should be and stay unique.
3641 3790
 	$request = $smcFunc['db_query']('', '
@@ -3650,8 +3799,9 @@  discard block
 block discarded – undo
3650 3799
 		)
3651 3800
 	);
3652 3801
 
3653
-	if ($smcFunc['db_num_rows']($request) > 0)
3654
-		return 'email_taken';
3802
+	if ($smcFunc['db_num_rows']($request) > 0) {
3803
+			return 'email_taken';
3804
+	}
3655 3805
 	$smcFunc['db_free_result']($request);
3656 3806
 
3657 3807
 	return true;
@@ -3664,8 +3814,9 @@  discard block
 block discarded – undo
3664 3814
 {
3665 3815
 	global $modSettings, $context, $cur_profile;
3666 3816
 
3667
-	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
3668
-		setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3817
+	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') {
3818
+			setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3819
+	}
3669 3820
 
3670 3821
 	loadUserSettings();
3671 3822
 	writeLog();
@@ -3681,8 +3832,9 @@  discard block
 block discarded – undo
3681 3832
 	require_once($sourcedir . '/Subs-Post.php');
3682 3833
 
3683 3834
 	// Shouldn't happen but just in case.
3684
-	if (empty($profile_vars['email_address']))
3685
-		return;
3835
+	if (empty($profile_vars['email_address'])) {
3836
+			return;
3837
+	}
3686 3838
 
3687 3839
 	$replacements = array(
3688 3840
 		'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
@@ -3705,8 +3857,9 @@  discard block
 block discarded – undo
3705 3857
 	$_SESSION['log_time'] = 0;
3706 3858
 	$_SESSION['login_' . $cookiename] = $smcFunc['json_encode'](array(0, '', 0));
3707 3859
 
3708
-	if (isset($_COOKIE[$cookiename]))
3709
-		$_COOKIE[$cookiename] = '';
3860
+	if (isset($_COOKIE[$cookiename])) {
3861
+			$_COOKIE[$cookiename] = '';
3862
+	}
3710 3863
 
3711 3864
 	loadUserSettings();
3712 3865
 
@@ -3739,11 +3892,13 @@  discard block
 block discarded – undo
3739 3892
 	$groups[] = $curMember['id_group'];
3740 3893
 
3741 3894
 	// Ensure the query doesn't croak!
3742
-	if (empty($groups))
3743
-		$groups = array(0);
3895
+	if (empty($groups)) {
3896
+			$groups = array(0);
3897
+	}
3744 3898
 	// Just to be sure...
3745
-	foreach ($groups as $k => $v)
3746
-		$groups[$k] = (int) $v;
3899
+	foreach ($groups as $k => $v) {
3900
+			$groups[$k] = (int) $v;
3901
+	}
3747 3902
 
3748 3903
 	// Get all the membergroups they can join.
3749 3904
 	$request = $smcFunc['db_query']('', '
@@ -3773,12 +3928,14 @@  discard block
 block discarded – undo
3773 3928
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3774 3929
 	{
3775 3930
 		// Can they edit their primary group?
3776
-		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
3777
-			$context['can_edit_primary'] = true;
3931
+		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) {
3932
+					$context['can_edit_primary'] = true;
3933
+		}
3778 3934
 
3779 3935
 		// If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
3780
-		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
3781
-			continue;
3936
+		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) {
3937
+					continue;
3938
+		}
3782 3939
 
3783 3940
 		$context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
3784 3941
 			'id' => $row['id_group'],
@@ -3807,13 +3964,15 @@  discard block
 block discarded – undo
3807 3964
 	);
3808 3965
 
3809 3966
 	// No changing primary one unless you have enough groups!
3810
-	if (count($context['groups']['member']) < 2)
3811
-		$context['can_edit_primary'] = false;
3967
+	if (count($context['groups']['member']) < 2) {
3968
+			$context['can_edit_primary'] = false;
3969
+	}
3812 3970
 
3813 3971
 	// In the special case that someone is requesting membership of a group, setup some special context vars.
3814
-	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
3815
-		$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3816
-}
3972
+	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) {
3973
+			$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3974
+	}
3975
+	}
3817 3976
 
3818 3977
 /**
3819 3978
  * This function actually makes all the group changes
@@ -3828,10 +3987,12 @@  discard block
 block discarded – undo
3828 3987
 	global $user_info, $context, $user_profile, $modSettings, $smcFunc;
3829 3988
 
3830 3989
 	// Let's be extra cautious...
3831
-	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
3832
-		isAllowedTo('manage_membergroups');
3833
-	if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
3834
-		fatal_lang_error('no_access', false);
3990
+	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) {
3991
+			isAllowedTo('manage_membergroups');
3992
+	}
3993
+	if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) {
3994
+			fatal_lang_error('no_access', false);
3995
+	}
3835 3996
 
3836 3997
 	checkSession(isset($_GET['gid']) ? 'get' : 'post');
3837 3998
 
@@ -3850,8 +4011,9 @@  discard block
 block discarded – undo
3850 4011
 	$foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
3851 4012
 
3852 4013
 	// Sanity check!!
3853
-	if ($group_id == 1)
3854
-		isAllowedTo('admin_forum');
4014
+	if ($group_id == 1) {
4015
+			isAllowedTo('admin_forum');
4016
+	}
3855 4017
 	// Protected groups too!
3856 4018
 	else
3857 4019
 	{
@@ -3868,8 +4030,9 @@  discard block
 block discarded – undo
3868 4030
 		list ($is_protected) = $smcFunc['db_fetch_row']($request);
3869 4031
 		$smcFunc['db_free_result']($request);
3870 4032
 
3871
-		if ($is_protected == 1)
3872
-			isAllowedTo('admin_forum');
4033
+		if ($is_protected == 1) {
4034
+					isAllowedTo('admin_forum');
4035
+		}
3873 4036
 	}
3874 4037
 
3875 4038
 	// What ever we are doing, we need to determine if changing primary is possible!
@@ -3891,36 +4054,43 @@  discard block
 block discarded – undo
3891 4054
 			$group_name = $row['group_name'];
3892 4055
 
3893 4056
 			// Does the group type match what we're doing - are we trying to request a non-requestable group?
3894
-			if ($changeType == 'request' && $row['group_type'] != 2)
3895
-				fatal_lang_error('no_access', false);
4057
+			if ($changeType == 'request' && $row['group_type'] != 2) {
4058
+							fatal_lang_error('no_access', false);
4059
+			}
3896 4060
 			// What about leaving a requestable group we are not a member of?
3897
-			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
3898
-				fatal_lang_error('no_access', false);
3899
-			elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
3900
-				fatal_lang_error('no_access', false);
4061
+			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) {
4062
+							fatal_lang_error('no_access', false);
4063
+			} elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) {
4064
+							fatal_lang_error('no_access', false);
4065
+			}
3901 4066
 
3902 4067
 			// We can't change the primary group if this is hidden!
3903
-			if ($row['hidden'] == 2)
3904
-				$canChangePrimary = false;
4068
+			if ($row['hidden'] == 2) {
4069
+							$canChangePrimary = false;
4070
+			}
3905 4071
 		}
3906 4072
 
3907 4073
 		// If this is their old primary, can we change it?
3908
-		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
3909
-			$canChangePrimary = 1;
4074
+		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) {
4075
+					$canChangePrimary = 1;
4076
+		}
3910 4077
 
3911 4078
 		// If we are not doing a force primary move, don't do it automatically if current primary is not 0.
3912
-		if ($changeType != 'primary' && $old_profile['id_group'] != 0)
3913
-			$canChangePrimary = false;
4079
+		if ($changeType != 'primary' && $old_profile['id_group'] != 0) {
4080
+					$canChangePrimary = false;
4081
+		}
3914 4082
 
3915 4083
 		// If this is the one we are acting on, can we even act?
3916
-		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
3917
-			$canChangePrimary = false;
4084
+		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) {
4085
+					$canChangePrimary = false;
4086
+		}
3918 4087
 	}
3919 4088
 	$smcFunc['db_free_result']($request);
3920 4089
 
3921 4090
 	// Didn't find the target?
3922
-	if (!$foundTarget)
3923
-		fatal_lang_error('no_access', false);
4091
+	if (!$foundTarget) {
4092
+			fatal_lang_error('no_access', false);
4093
+	}
3924 4094
 
3925 4095
 	// Final security check, don't allow users to promote themselves to admin.
3926 4096
 	if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
@@ -3940,8 +4110,9 @@  discard block
 block discarded – undo
3940 4110
 		list ($disallow) = $smcFunc['db_fetch_row']($request);
3941 4111
 		$smcFunc['db_free_result']($request);
3942 4112
 
3943
-		if ($disallow)
3944
-			isAllowedTo('admin_forum');
4113
+		if ($disallow) {
4114
+					isAllowedTo('admin_forum');
4115
+		}
3945 4116
 	}
3946 4117
 
3947 4118
 	// If we're requesting, add the note then return.
@@ -3959,8 +4130,9 @@  discard block
 block discarded – undo
3959 4130
 				'status_open' => 0,
3960 4131
 			)
3961 4132
 		);
3962
-		if ($smcFunc['db_num_rows']($request) != 0)
3963
-			fatal_lang_error('profile_error_already_requested_group');
4133
+		if ($smcFunc['db_num_rows']($request) != 0) {
4134
+					fatal_lang_error('profile_error_already_requested_group');
4135
+		}
3964 4136
 		$smcFunc['db_free_result']($request);
3965 4137
 
3966 4138
 		// Log the request.
@@ -3994,10 +4166,11 @@  discard block
 block discarded – undo
3994 4166
 		// Are we leaving?
3995 4167
 		if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
3996 4168
 		{
3997
-			if ($old_profile['id_group'] == $group_id)
3998
-				$newPrimary = 0;
3999
-			else
4000
-				unset($addGroups[$group_id]);
4169
+			if ($old_profile['id_group'] == $group_id) {
4170
+							$newPrimary = 0;
4171
+			} else {
4172
+							unset($addGroups[$group_id]);
4173
+			}
4001 4174
 		}
4002 4175
 		// ... if not, must be joining.
4003 4176
 		else
@@ -4005,36 +4178,42 @@  discard block
 block discarded – undo
4005 4178
 			// Can we change the primary, and do we want to?
4006 4179
 			if ($canChangePrimary)
4007 4180
 			{
4008
-				if ($old_profile['id_group'] != 0)
4009
-					$addGroups[$old_profile['id_group']] = -1;
4181
+				if ($old_profile['id_group'] != 0) {
4182
+									$addGroups[$old_profile['id_group']] = -1;
4183
+				}
4010 4184
 				$newPrimary = $group_id;
4011 4185
 			}
4012 4186
 			// Otherwise it's an additional group...
4013
-			else
4014
-				$addGroups[$group_id] = -1;
4187
+			else {
4188
+							$addGroups[$group_id] = -1;
4189
+			}
4015 4190
 		}
4016 4191
 	}
4017 4192
 	// Finally, we must be setting the primary.
4018 4193
 	elseif ($canChangePrimary)
4019 4194
 	{
4020
-		if ($old_profile['id_group'] != 0)
4021
-			$addGroups[$old_profile['id_group']] = -1;
4022
-		if (isset($addGroups[$group_id]))
4023
-			unset($addGroups[$group_id]);
4195
+		if ($old_profile['id_group'] != 0) {
4196
+					$addGroups[$old_profile['id_group']] = -1;
4197
+		}
4198
+		if (isset($addGroups[$group_id])) {
4199
+					unset($addGroups[$group_id]);
4200
+		}
4024 4201
 		$newPrimary = $group_id;
4025 4202
 	}
4026 4203
 
4027 4204
 	// Finally, we can make the changes!
4028
-	foreach ($addGroups as $id => $dummy)
4029
-		if (empty($id))
4205
+	foreach ($addGroups as $id => $dummy) {
4206
+			if (empty($id))
4030 4207
 			unset($addGroups[$id]);
4208
+	}
4031 4209
 	$addGroups = implode(',', array_flip($addGroups));
4032 4210
 
4033 4211
 	// Ensure that we don't cache permissions if the group is changing.
4034
-	if ($context['user']['is_owner'])
4035
-		$_SESSION['mc']['time'] = 0;
4036
-	else
4037
-		updateSettings(array('settings_updated' => time()));
4212
+	if ($context['user']['is_owner']) {
4213
+			$_SESSION['mc']['time'] = 0;
4214
+	} else {
4215
+			updateSettings(array('settings_updated' => time()));
4216
+	}
4038 4217
 
4039 4218
 	updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
4040 4219
 
@@ -4057,8 +4236,9 @@  discard block
 block discarded – undo
4057 4236
 	if (empty($user_settings['tfa_secret']) && $context['user']['is_owner'])
4058 4237
 	{
4059 4238
 		// Check to ensure we're forcing SSL for authentication
4060
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
4061
-			fatal_lang_error('login_ssl_required');
4239
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
4240
+					fatal_lang_error('login_ssl_required');
4241
+		}
4062 4242
 
4063 4243
 		// In some cases (forced 2FA or backup code) they would be forced to be redirected here,
4064 4244
 		// we do not want too much AJAX to confuse them.
@@ -4095,8 +4275,7 @@  discard block
 block discarded – undo
4095 4275
 				$context['sub_template'] = 'tfasetup_backup';
4096 4276
 
4097 4277
 				return;
4098
-			}
4099
-			else
4278
+			} else
4100 4279
 			{
4101 4280
 				$context['tfa_secret'] = $_SESSION['tfa_secret'];
4102 4281
 				$context['tfa_error'] = !$valid_code;
@@ -4104,8 +4283,7 @@  discard block
 block discarded – undo
4104 4283
 				$context['tfa_pass_value'] = $_POST['passwd'];
4105 4284
 				$context['tfa_value'] = $_POST['tfa_code'];
4106 4285
 			}
4107
-		}
4108
-		else
4286
+		} else
4109 4287
 		{
4110 4288
 			$totp = new \TOTP\Auth();
4111 4289
 			$secret = $totp->generateCode();
@@ -4115,17 +4293,16 @@  discard block
 block discarded – undo
4115 4293
 		}
4116 4294
 
4117 4295
 		$context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']);
4118
-	}
4119
-	elseif (isset($_REQUEST['disable']))
4296
+	} elseif (isset($_REQUEST['disable']))
4120 4297
 	{
4121 4298
 		updateMemberData($memID, array(
4122 4299
 			'tfa_secret' => '',
4123 4300
 			'tfa_backup' => '',
4124 4301
 		));
4125 4302
 		redirectexit('action=profile;area=account;u=' . $memID);
4303
+	} else {
4304
+			redirectexit('action=profile;area=account;u=' . $memID);
4305
+	}
4126 4306
 	}
4127
-	else
4128
-		redirectexit('action=profile;area=account;u=' . $memID);
4129
-}
4130 4307
 
4131 4308
 ?>
4132 4309
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs.php 1 patch
Braces   +1434 added lines, -1064 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,23 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($var == 'alerts' && ($val === '+' || $val === '-'))
@@ -385,18 +394,17 @@  discard block
 block discarded – undo
385 394
 			if (is_array($members))
386 395
 			{
387 396
 				$val = 'CASE ';
388
-				foreach ($members as $k => $v)
389
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
397
+				foreach ($members as $k => $v) {
398
+									$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
399
+				}
390 400
 				$val = $val . ' END';
391 401
 				$type = 'raw';
392
-			}
393
-			else
402
+			} else
394 403
 			{
395 404
 				$blub = fetch_alerts($members, false, 0, array(), false);
396 405
 				$val = count($blub);
397 406
 			}
398
-		}
399
-		else if ($type == 'int' && ($val === '+' || $val === '-'))
407
+		} else if ($type == 'int' && ($val === '+' || $val === '-'))
400 408
 		{
401 409
 			$val = $var . ' ' . $val . ' 1';
402 410
 			$type = 'raw';
@@ -407,8 +415,9 @@  discard block
 block discarded – undo
407 415
 		{
408 416
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
409 417
 			{
410
-				if ($match[1] != '+ ')
411
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
418
+				if ($match[1] != '+ ') {
419
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
420
+				}
412 421
 				$type = 'raw';
413 422
 			}
414 423
 		}
@@ -429,8 +438,9 @@  discard block
 block discarded – undo
429 438
 	// Clear any caching?
430 439
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
431 440
 	{
432
-		if (!is_array($members))
433
-			$members = array($members);
441
+		if (!is_array($members)) {
442
+					$members = array($members);
443
+		}
434 444
 
435 445
 		foreach ($members as $member)
436 446
 		{
@@ -463,29 +473,32 @@  discard block
 block discarded – undo
463 473
 {
464 474
 	global $modSettings, $smcFunc;
465 475
 
466
-	if (empty($changeArray) || !is_array($changeArray))
467
-		return;
476
+	if (empty($changeArray) || !is_array($changeArray)) {
477
+			return;
478
+	}
468 479
 
469 480
 	$toRemove = array();
470 481
 
471 482
 	// Go check if there is any setting to be removed.
472
-	foreach ($changeArray as $k => $v)
473
-		if ($v === null)
483
+	foreach ($changeArray as $k => $v) {
484
+			if ($v === null)
474 485
 		{
475 486
 			// Found some, remove them from the original array and add them to ours.
476 487
 			unset($changeArray[$k]);
488
+	}
477 489
 			$toRemove[] = $k;
478 490
 		}
479 491
 
480 492
 	// Proceed with the deletion.
481
-	if (!empty($toRemove))
482
-		$smcFunc['db_query']('', '
493
+	if (!empty($toRemove)) {
494
+			$smcFunc['db_query']('', '
483 495
 			DELETE FROM {db_prefix}settings
484 496
 			WHERE variable IN ({array_string:remove})',
485 497
 			array(
486 498
 				'remove' => $toRemove,
487 499
 			)
488 500
 		);
501
+	}
489 502
 
490 503
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
491 504
 	if ($update)
@@ -514,19 +527,22 @@  discard block
 block discarded – undo
514 527
 	foreach ($changeArray as $variable => $value)
515 528
 	{
516 529
 		// Don't bother if it's already like that ;).
517
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
518
-			continue;
530
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
531
+					continue;
532
+		}
519 533
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
520
-		elseif (!isset($modSettings[$variable]) && empty($value))
521
-			continue;
534
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
535
+					continue;
536
+		}
522 537
 
523 538
 		$replaceArray[] = array($variable, $value);
524 539
 
525 540
 		$modSettings[$variable] = $value;
526 541
 	}
527 542
 
528
-	if (empty($replaceArray))
529
-		return;
543
+	if (empty($replaceArray)) {
544
+			return;
545
+	}
530 546
 
531 547
 	$smcFunc['db_insert']('replace',
532 548
 		'{db_prefix}settings',
@@ -572,14 +588,17 @@  discard block
 block discarded – undo
572 588
 	$start_invalid = $start < 0;
573 589
 
574 590
 	// Make sure $start is a proper variable - not less than 0.
575
-	if ($start_invalid)
576
-		$start = 0;
591
+	if ($start_invalid) {
592
+			$start = 0;
593
+	}
577 594
 	// Not greater than the upper bound.
578
-	elseif ($start >= $max_value)
579
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
595
+	elseif ($start >= $max_value) {
596
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
597
+	}
580 598
 	// And it has to be a multiple of $num_per_page!
581
-	else
582
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
599
+	else {
600
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
601
+	}
583 602
 
584 603
 	$context['current_page'] = $start / $num_per_page;
585 604
 
@@ -609,77 +628,87 @@  discard block
 block discarded – undo
609 628
 
610 629
 		// Show all the pages.
611 630
 		$display_page = 1;
612
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
613
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
631
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
632
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
633
+		}
614 634
 
615 635
 		// Show the right arrow.
616 636
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
617
-		if ($start != $counter - $max_value && !$start_invalid)
618
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
619
-	}
620
-	else
637
+		if ($start != $counter - $max_value && !$start_invalid) {
638
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
639
+		}
640
+	} else
621 641
 	{
622 642
 		// If they didn't enter an odd value, pretend they did.
623 643
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
624 644
 
625 645
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
626
-		if (!empty($start) && $show_prevnext)
627
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
628
-		else
629
-			$pageindex .= '';
646
+		if (!empty($start) && $show_prevnext) {
647
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
648
+		} else {
649
+					$pageindex .= '';
650
+		}
630 651
 
631 652
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
632
-		if ($start > $num_per_page * $PageContiguous)
633
-			$pageindex .= sprintf($base_link, 0, '1');
653
+		if ($start > $num_per_page * $PageContiguous) {
654
+					$pageindex .= sprintf($base_link, 0, '1');
655
+		}
634 656
 
635 657
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
636
-		if ($start > $num_per_page * ($PageContiguous + 1))
637
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
658
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
659
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
638 660
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
639 661
 				'{FIRST_PAGE}' => $num_per_page,
640 662
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
641 663
 				'{PER_PAGE}' => $num_per_page,
642 664
 			));
665
+		}
643 666
 
644 667
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
645
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
646
-			if ($start >= $num_per_page * $nCont)
668
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
669
+					if ($start >= $num_per_page * $nCont)
647 670
 			{
648 671
 				$tmpStart = $start - $num_per_page * $nCont;
672
+		}
649 673
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
650 674
 			}
651 675
 
652 676
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
653
-		if (!$start_invalid)
654
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
655
-		else
656
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
677
+		if (!$start_invalid) {
678
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
679
+		} else {
680
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
681
+		}
657 682
 
658 683
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
659 684
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
660
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
661
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
685
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
686
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
662 687
 			{
663 688
 				$tmpStart = $start + $num_per_page * $nCont;
689
+		}
664 690
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
665 691
 			}
666 692
 
667 693
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
668
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
669
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
694
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
695
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
670 696
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
671 697
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
672 698
 				'{LAST_PAGE}' => $tmpMaxPages,
673 699
 				'{PER_PAGE}' => $num_per_page,
674 700
 			));
701
+		}
675 702
 
676 703
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
677
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
678
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
704
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
705
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
706
+		}
679 707
 
680 708
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
681
-		if ($start != $tmpMaxPages && $show_prevnext)
682
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
709
+		if ($start != $tmpMaxPages && $show_prevnext) {
710
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
711
+		}
683 712
 	}
684 713
 	$pageindex .= $settings['page_index']['extra_after'];
685 714
 
@@ -705,8 +734,9 @@  discard block
 block discarded – undo
705 734
 	if ($decimal_separator === null)
706 735
 	{
707 736
 		// Not set for whatever reason?
708
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
709
-			return $number;
737
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
738
+					return $number;
739
+		}
710 740
 
711 741
 		// Cache these each load...
712 742
 		$thousands_separator = $matches[1];
@@ -740,17 +770,20 @@  discard block
 block discarded – undo
740 770
 	static $unsupportedFormats, $finalizedFormats;
741 771
 
742 772
 	// Offset the time.
743
-	if (!$offset_type)
744
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
773
+	if (!$offset_type) {
774
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
775
+	}
745 776
 	// Just the forum offset?
746
-	elseif ($offset_type == 'forum')
747
-		$time = $log_time + $modSettings['time_offset'] * 3600;
748
-	else
749
-		$time = $log_time;
777
+	elseif ($offset_type == 'forum') {
778
+			$time = $log_time + $modSettings['time_offset'] * 3600;
779
+	} else {
780
+			$time = $log_time;
781
+	}
750 782
 
751 783
 	// We can't have a negative date (on Windows, at least.)
752
-	if ($log_time < 0)
753
-		$log_time = 0;
784
+	if ($log_time < 0) {
785
+			$log_time = 0;
786
+	}
754 787
 
755 788
 	// Today and Yesterday?
756 789
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -767,24 +800,27 @@  discard block
 block discarded – undo
767 800
 		{
768 801
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
769 802
 			$today_fmt = $h . ':%M' . $s . ' %p';
803
+		} else {
804
+					$today_fmt = '%H:%M' . $s;
770 805
 		}
771
-		else
772
-			$today_fmt = '%H:%M' . $s;
773 806
 
774 807
 		// Same day of the year, same year.... Today!
775
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
776
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
808
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
809
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
810
+		}
777 811
 
778 812
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
779
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
780
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
813
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
814
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
815
+		}
781 816
 	}
782 817
 
783 818
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
784 819
 
785 820
 	// Use the cached formats if available
786
-	if (is_null($finalizedFormats))
787
-		$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
821
+	if (is_null($finalizedFormats)) {
822
+			$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
823
+	}
788 824
 
789 825
 	// Make a supported version for this format if we don't already have one
790 826
 	if (empty($finalizedFormats[$str]))
@@ -813,8 +849,9 @@  discard block
 block discarded – undo
813 849
 		);
814 850
 
815 851
 		// No need to do this part again if we already did it once
816
-		if (is_null($unsupportedFormats))
817
-			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
852
+		if (is_null($unsupportedFormats)) {
853
+					$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
854
+		}
818 855
 		if (empty($unsupportedFormats))
819 856
 		{
820 857
 			foreach($strftimeFormatSubstitutions as $format => $substitution)
@@ -823,20 +860,23 @@  discard block
 block discarded – undo
823 860
 
824 861
 				// Windows will return false for unsupported formats
825 862
 				// Other operating systems return the format string as a literal
826
-				if ($value === false || $value === $format)
827
-					$unsupportedFormats[] = $format;
863
+				if ($value === false || $value === $format) {
864
+									$unsupportedFormats[] = $format;
865
+				}
828 866
 			}
829 867
 			cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400);
830 868
 		}
831 869
 
832 870
 		// Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q'
833
-		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
834
-			$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
871
+		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
872
+					$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
873
+		}
835 874
 
836 875
 		// Substitute unsupported formats with supported ones
837
-		if (!empty($unsupportedFormats))
838
-			while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
876
+		if (!empty($unsupportedFormats)) {
877
+					while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
839 878
 				$timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat);
879
+		}
840 880
 
841 881
 		// Remember this so we don't need to do it again
842 882
 		$finalizedFormats[$str] = $timeformat;
@@ -845,33 +885,39 @@  discard block
 block discarded – undo
845 885
 
846 886
 	$str = $finalizedFormats[$str];
847 887
 
848
-	if (!isset($locale_cache))
849
-		$locale_cache = setlocale(LC_TIME, $txt['lang_locale']);
888
+	if (!isset($locale_cache)) {
889
+			$locale_cache = setlocale(LC_TIME, $txt['lang_locale']);
890
+	}
850 891
 
851 892
 	if ($locale_cache !== false)
852 893
 	{
853 894
 		// Check if another process changed the locale
854
-		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache)
855
-			setlocale(LC_TIME, $txt['lang_locale']);
895
+		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) {
896
+					setlocale(LC_TIME, $txt['lang_locale']);
897
+		}
856 898
 
857
-		if (!isset($non_twelve_hour))
858
-			$non_twelve_hour = trim(strftime('%p')) === '';
859
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
860
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
899
+		if (!isset($non_twelve_hour)) {
900
+					$non_twelve_hour = trim(strftime('%p')) === '';
901
+		}
902
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
903
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
904
+		}
861 905
 
862
-		foreach (array('%a', '%A', '%b', '%B') as $token)
863
-			if (strpos($str, $token) !== false)
906
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
907
+					if (strpos($str, $token) !== false)
864 908
 				$str = str_replace($token, strftime($token, $time), $str);
865
-	}
866
-	else
909
+		}
910
+	} else
867 911
 	{
868 912
 		// Do-it-yourself time localization.  Fun.
869
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
870
-			if (strpos($str, $token) !== false)
913
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
914
+					if (strpos($str, $token) !== false)
871 915
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
916
+		}
872 917
 
873
-		if (strpos($str, '%p') !== false)
874
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
918
+		if (strpos($str, '%p') !== false) {
919
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
920
+		}
875 921
 	}
876 922
 
877 923
 	// Format the time and then restore any literal percent characters
@@ -894,16 +940,19 @@  discard block
 block discarded – undo
894 940
 	static $translation = array();
895 941
 
896 942
 	// Determine the character set... Default to UTF-8
897
-	if (empty($context['character_set']))
898
-		$charset = 'UTF-8';
943
+	if (empty($context['character_set'])) {
944
+			$charset = 'UTF-8';
945
+	}
899 946
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
900
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
901
-		$charset = 'ISO-8859-1';
902
-	else
903
-		$charset = $context['character_set'];
947
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
948
+			$charset = 'ISO-8859-1';
949
+	} else {
950
+			$charset = $context['character_set'];
951
+	}
904 952
 
905
-	if (empty($translation))
906
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
953
+	if (empty($translation)) {
954
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
955
+	}
907 956
 
908 957
 	return strtr($string, $translation);
909 958
 }
@@ -925,8 +974,9 @@  discard block
 block discarded – undo
925 974
 	global $smcFunc;
926 975
 
927 976
 	// It was already short enough!
928
-	if ($smcFunc['strlen']($subject) <= $len)
929
-		return $subject;
977
+	if ($smcFunc['strlen']($subject) <= $len) {
978
+			return $subject;
979
+	}
930 980
 
931 981
 	// Shorten it by the length it was too long, and strip off junk from the end.
932 982
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -945,10 +995,11 @@  discard block
 block discarded – undo
945 995
 {
946 996
 	global $user_info, $modSettings;
947 997
 
948
-	if ($timestamp === null)
949
-		$timestamp = time();
950
-	elseif ($timestamp == 0)
951
-		return 0;
998
+	if ($timestamp === null) {
999
+			$timestamp = time();
1000
+	} elseif ($timestamp == 0) {
1001
+			return 0;
1002
+	}
952 1003
 
953 1004
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
954 1005
 }
@@ -977,8 +1028,9 @@  discard block
 block discarded – undo
977 1028
 		$array[$i] = $array[$j];
978 1029
 		$array[$j] = $temp;
979 1030
 
980
-		for ($i = 1; $p[$i] == 0; $i++)
981
-			$p[$i] = 1;
1031
+		for ($i = 1; $p[$i] == 0; $i++) {
1032
+					$p[$i] = 1;
1033
+		}
982 1034
 
983 1035
 		$orders[] = $array;
984 1036
 	}
@@ -1010,12 +1062,14 @@  discard block
 block discarded – undo
1010 1062
 	static $disabled;
1011 1063
 
1012 1064
 	// Don't waste cycles
1013
-	if ($message === '')
1014
-		return '';
1065
+	if ($message === '') {
1066
+			return '';
1067
+	}
1015 1068
 
1016 1069
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
1017
-	if (!isset($context['utf8']))
1018
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1070
+	if (!isset($context['utf8'])) {
1071
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1072
+	}
1019 1073
 
1020 1074
 	// Clean up any cut/paste issues we may have
1021 1075
 	$message = sanitizeMSCutPaste($message);
@@ -1027,13 +1081,15 @@  discard block
 block discarded – undo
1027 1081
 		return $message;
1028 1082
 	}
1029 1083
 
1030
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
1031
-		$smileys = (bool) $smileys;
1084
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1085
+			$smileys = (bool) $smileys;
1086
+	}
1032 1087
 
1033 1088
 	if (empty($modSettings['enableBBC']) && $message !== false)
1034 1089
 	{
1035
-		if ($smileys === true)
1036
-			parsesmileys($message);
1090
+		if ($smileys === true) {
1091
+					parsesmileys($message);
1092
+		}
1037 1093
 
1038 1094
 		return $message;
1039 1095
 	}
@@ -1046,8 +1102,9 @@  discard block
 block discarded – undo
1046 1102
 	}
1047 1103
 
1048 1104
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1049
-	if (!empty($modSettings['autoLinkUrls']))
1050
-		set_tld_regex();
1105
+	if (!empty($modSettings['autoLinkUrls'])) {
1106
+			set_tld_regex();
1107
+	}
1051 1108
 
1052 1109
 	// Allow mods access before entering the main parse_bbc loop
1053 1110
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1061,12 +1118,14 @@  discard block
 block discarded – undo
1061 1118
 
1062 1119
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1063 1120
 
1064
-			foreach ($temp as $tag)
1065
-				$disabled[trim($tag)] = true;
1121
+			foreach ($temp as $tag) {
1122
+							$disabled[trim($tag)] = true;
1123
+			}
1066 1124
 		}
1067 1125
 
1068
-		if (empty($modSettings['enableEmbeddedFlash']))
1069
-			$disabled['flash'] = true;
1126
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1127
+					$disabled['flash'] = true;
1128
+		}
1070 1129
 
1071 1130
 		/* The following bbc are formatted as an array, with keys as follows:
1072 1131
 
@@ -1187,8 +1246,9 @@  discard block
 block discarded – undo
1187 1246
 					$returnContext = '';
1188 1247
 
1189 1248
 					// BBC or the entire attachments feature is disabled
1190
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1191
-						return $data;
1249
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1250
+											return $data;
1251
+					}
1192 1252
 
1193 1253
 					// Save the attach ID.
1194 1254
 					$attachID = $data;
@@ -1199,8 +1259,9 @@  discard block
 block discarded – undo
1199 1259
 					$currentAttachment = parseAttachBBC($attachID);
1200 1260
 
1201 1261
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1202
-					if (is_string($currentAttachment))
1203
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1262
+					if (is_string($currentAttachment)) {
1263
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1264
+					}
1204 1265
 
1205 1266
 					if (!empty($currentAttachment['is_image']))
1206 1267
 					{
@@ -1216,15 +1277,17 @@  discard block
 block discarded – undo
1216 1277
 							$height = ' height="' . $currentAttachment['height'] . '"';
1217 1278
 						}
1218 1279
 
1219
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1220
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1221
-						else
1222
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1280
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1281
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1282
+						} else {
1283
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1284
+						}
1223 1285
 					}
1224 1286
 
1225 1287
 					// No image. Show a link.
1226
-					else
1227
-						$returnContext .= $currentAttachment['link'];
1288
+					else {
1289
+											$returnContext .= $currentAttachment['link'];
1290
+					}
1228 1291
 
1229 1292
 					// Gotta append what we just did.
1230 1293
 					$data = $returnContext;
@@ -1255,8 +1318,9 @@  discard block
 block discarded – undo
1255 1318
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1256 1319
 						{
1257 1320
 							// Do PHP code coloring?
1258
-							if ($php_parts[$php_i] != '&lt;?php')
1259
-								continue;
1321
+							if ($php_parts[$php_i] != '&lt;?php') {
1322
+															continue;
1323
+							}
1260 1324
 
1261 1325
 							$php_string = '';
1262 1326
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1272,8 +1336,9 @@  discard block
 block discarded – undo
1272 1336
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1273 1337
 
1274 1338
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1275
-						if ($context['browser']['is_opera'])
1276
-							$data .= '&nbsp;';
1339
+						if ($context['browser']['is_opera']) {
1340
+													$data .= '&nbsp;';
1341
+						}
1277 1342
 					}
1278 1343
 				},
1279 1344
 				'block_level' => true,
@@ -1292,8 +1357,9 @@  discard block
 block discarded – undo
1292 1357
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1293 1358
 						{
1294 1359
 							// Do PHP code coloring?
1295
-							if ($php_parts[$php_i] != '&lt;?php')
1296
-								continue;
1360
+							if ($php_parts[$php_i] != '&lt;?php') {
1361
+															continue;
1362
+							}
1297 1363
 
1298 1364
 							$php_string = '';
1299 1365
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1309,8 +1375,9 @@  discard block
 block discarded – undo
1309 1375
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1310 1376
 
1311 1377
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1312
-						if ($context['browser']['is_opera'])
1313
-							$data[0] .= '&nbsp;';
1378
+						if ($context['browser']['is_opera']) {
1379
+													$data[0] .= '&nbsp;';
1380
+						}
1314 1381
 					}
1315 1382
 				},
1316 1383
 				'block_level' => true,
@@ -1348,11 +1415,13 @@  discard block
 block discarded – undo
1348 1415
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1349 1416
 				'validate' => function (&$tag, &$data, $disabled)
1350 1417
 				{
1351
-					if (isset($disabled['url']))
1352
-						$tag['content'] = '$1';
1418
+					if (isset($disabled['url'])) {
1419
+											$tag['content'] = '$1';
1420
+					}
1353 1421
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1354
-					if (empty($scheme))
1355
-						$data[0] = '//' . ltrim($data[0], ':/');
1422
+					if (empty($scheme)) {
1423
+											$data[0] = '//' . ltrim($data[0], ':/');
1424
+					}
1356 1425
 				},
1357 1426
 				'disabled_content' => '<a href="$1" target="_blank" rel="noopener">$1</a>',
1358 1427
 			),
@@ -1366,10 +1435,11 @@  discard block
 block discarded – undo
1366 1435
 				{
1367 1436
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1368 1437
 
1369
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1370
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1371
-					else
1372
-						$css = '';
1438
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1439
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1440
+					} else {
1441
+											$css = '';
1442
+					}
1373 1443
 
1374 1444
 					$data = $class . $css;
1375 1445
 				},
@@ -1419,17 +1489,20 @@  discard block
 block discarded – undo
1419 1489
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1420 1490
 					if ($image_proxy_enabled)
1421 1491
 					{
1422
-						if (!empty($user_info['possibly_robot']))
1423
-							return;
1492
+						if (!empty($user_info['possibly_robot'])) {
1493
+													return;
1494
+						}
1424 1495
 
1425
-						if (empty($scheme))
1426
-							$data = 'http://' . ltrim($data, ':/');
1496
+						if (empty($scheme)) {
1497
+													$data = 'http://' . ltrim($data, ':/');
1498
+						}
1427 1499
 
1428
-						if ($scheme != 'https')
1429
-							$data = get_proxied_url($data);
1500
+						if ($scheme != 'https') {
1501
+													$data = get_proxied_url($data);
1502
+						}
1503
+					} elseif (empty($scheme)) {
1504
+											$data = '//' . ltrim($data, ':/');
1430 1505
 					}
1431
-					elseif (empty($scheme))
1432
-						$data = '//' . ltrim($data, ':/');
1433 1506
 				},
1434 1507
 				'disabled_content' => '($1)',
1435 1508
 			),
@@ -1445,17 +1518,20 @@  discard block
 block discarded – undo
1445 1518
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1446 1519
 					if ($image_proxy_enabled)
1447 1520
 					{
1448
-						if (!empty($user_info['possibly_robot']))
1449
-							return;
1521
+						if (!empty($user_info['possibly_robot'])) {
1522
+													return;
1523
+						}
1450 1524
 
1451
-						if (empty($scheme))
1452
-							$data = 'http://' . ltrim($data, ':/');
1525
+						if (empty($scheme)) {
1526
+													$data = 'http://' . ltrim($data, ':/');
1527
+						}
1453 1528
 
1454
-						if ($scheme != 'https')
1455
-							$data = get_proxied_url($data);
1529
+						if ($scheme != 'https') {
1530
+													$data = get_proxied_url($data);
1531
+						}
1532
+					} elseif (empty($scheme)) {
1533
+											$data = '//' . ltrim($data, ':/');
1456 1534
 					}
1457
-					elseif (empty($scheme))
1458
-						$data = '//' . ltrim($data, ':/');
1459 1535
 				},
1460 1536
 				'disabled_content' => '($1)',
1461 1537
 			),
@@ -1467,8 +1543,9 @@  discard block
 block discarded – undo
1467 1543
 				{
1468 1544
 					$data = strtr($data, array('<br>' => ''));
1469 1545
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1470
-					if (empty($scheme))
1471
-						$data = '//' . ltrim($data, ':/');
1546
+					if (empty($scheme)) {
1547
+											$data = '//' . ltrim($data, ':/');
1548
+					}
1472 1549
 				},
1473 1550
 			),
1474 1551
 			array(
@@ -1479,13 +1556,14 @@  discard block
 block discarded – undo
1479 1556
 				'after' => '</a>',
1480 1557
 				'validate' => function (&$tag, &$data, $disabled)
1481 1558
 				{
1482
-					if (substr($data, 0, 1) == '#')
1483
-						$data = '#post_' . substr($data, 1);
1484
-					else
1559
+					if (substr($data, 0, 1) == '#') {
1560
+											$data = '#post_' . substr($data, 1);
1561
+					} else
1485 1562
 					{
1486 1563
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1487
-						if (empty($scheme))
1488
-							$data = '//' . ltrim($data, ':/');
1564
+						if (empty($scheme)) {
1565
+													$data = '//' . ltrim($data, ':/');
1566
+						}
1489 1567
 					}
1490 1568
 				},
1491 1569
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1563,8 +1641,9 @@  discard block
 block discarded – undo
1563 1641
 					{
1564 1642
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1565 1643
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1566
-						if ($add_begin)
1567
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1644
+						if ($add_begin) {
1645
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1646
+						}
1568 1647
 					}
1569 1648
 				},
1570 1649
 				'block_level' => false,
@@ -1695,10 +1774,11 @@  discard block
 block discarded – undo
1695 1774
 				'content' => '$1',
1696 1775
 				'validate' => function (&$tag, &$data, $disabled)
1697 1776
 				{
1698
-					if (is_numeric($data))
1699
-						$data = timeformat($data);
1700
-					else
1701
-						$tag['content'] = '[time]$1[/time]';
1777
+					if (is_numeric($data)) {
1778
+											$data = timeformat($data);
1779
+					} else {
1780
+											$tag['content'] = '[time]$1[/time]';
1781
+					}
1702 1782
 				},
1703 1783
 			),
1704 1784
 			array(
@@ -1725,8 +1805,9 @@  discard block
 block discarded – undo
1725 1805
 				{
1726 1806
 					$data = strtr($data, array('<br>' => ''));
1727 1807
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1728
-					if (empty($scheme))
1729
-						$data = '//' . ltrim($data, ':/');
1808
+					if (empty($scheme)) {
1809
+											$data = '//' . ltrim($data, ':/');
1810
+					}
1730 1811
 				},
1731 1812
 			),
1732 1813
 			array(
@@ -1738,8 +1819,9 @@  discard block
 block discarded – undo
1738 1819
 				'validate' => function (&$tag, &$data, $disabled)
1739 1820
 				{
1740 1821
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1741
-					if (empty($scheme))
1742
-						$data = '//' . ltrim($data, ':/');
1822
+					if (empty($scheme)) {
1823
+											$data = '//' . ltrim($data, ':/');
1824
+					}
1743 1825
 				},
1744 1826
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1745 1827
 				'disabled_after' => ' ($1)',
@@ -1759,8 +1841,9 @@  discard block
 block discarded – undo
1759 1841
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1760 1842
 		if ($message === false)
1761 1843
 		{
1762
-			if (isset($temp_bbc))
1763
-				$bbc_codes = $temp_bbc;
1844
+			if (isset($temp_bbc)) {
1845
+							$bbc_codes = $temp_bbc;
1846
+			}
1764 1847
 			usort($codes, function ($a, $b) {
1765 1848
 				return strcmp($a['tag'], $b['tag']);
1766 1849
 			});
@@ -1780,8 +1863,9 @@  discard block
 block discarded – undo
1780 1863
 		);
1781 1864
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1782 1865
 		{
1783
-			foreach ($itemcodes as $c => $dummy)
1784
-				$bbc_codes[$c] = array();
1866
+			foreach ($itemcodes as $c => $dummy) {
1867
+							$bbc_codes[$c] = array();
1868
+			}
1785 1869
 		}
1786 1870
 
1787 1871
 		// Shhhh!
@@ -1802,12 +1886,14 @@  discard block
 block discarded – undo
1802 1886
 		foreach ($codes as $code)
1803 1887
 		{
1804 1888
 			// Make it easier to process parameters later
1805
-			if (!empty($code['parameters']))
1806
-				ksort($code['parameters'], SORT_STRING);
1889
+			if (!empty($code['parameters'])) {
1890
+							ksort($code['parameters'], SORT_STRING);
1891
+			}
1807 1892
 
1808 1893
 			// If we are not doing every tag only do ones we are interested in.
1809
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1810
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1894
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1895
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1896
+			}
1811 1897
 		}
1812 1898
 		$codes = null;
1813 1899
 	}
@@ -1818,8 +1904,9 @@  discard block
 block discarded – undo
1818 1904
 		// It's likely this will change if the message is modified.
1819 1905
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1820 1906
 
1821
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1822
-			return $temp;
1907
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1908
+					return $temp;
1909
+		}
1823 1910
 
1824 1911
 		$cache_t = microtime();
1825 1912
 	}
@@ -1851,8 +1938,9 @@  discard block
 block discarded – undo
1851 1938
 		$disabled['flash'] = true;
1852 1939
 
1853 1940
 		// @todo Change maybe?
1854
-		if (!isset($_GET['images']))
1855
-			$disabled['img'] = true;
1941
+		if (!isset($_GET['images'])) {
1942
+					$disabled['img'] = true;
1943
+		}
1856 1944
 
1857 1945
 		// @todo Interface/setting to add more?
1858 1946
 	}
@@ -1876,8 +1964,9 @@  discard block
 block discarded – undo
1876 1964
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1877 1965
 
1878 1966
 		// Failsafe.
1879
-		if ($pos === false || $last_pos > $pos)
1880
-			$pos = strlen($message) + 1;
1967
+		if ($pos === false || $last_pos > $pos) {
1968
+					$pos = strlen($message) + 1;
1969
+		}
1881 1970
 
1882 1971
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1883 1972
 		if ($last_pos < $pos - 1)
@@ -1895,8 +1984,9 @@  discard block
 block discarded – undo
1895 1984
 
1896 1985
 				// <br> should be empty.
1897 1986
 				$empty_tags = array('br', 'hr');
1898
-				foreach ($empty_tags as $tag)
1899
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
1987
+				foreach ($empty_tags as $tag) {
1988
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
1989
+				}
1900 1990
 
1901 1991
 				// b, u, i, s, pre... basic tags.
1902 1992
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong');
@@ -1905,8 +1995,9 @@  discard block
 block discarded – undo
1905 1995
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1906 1996
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1907 1997
 
1908
-					if ($diff > 0)
1909
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1998
+					if ($diff > 0) {
1999
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2000
+					}
1910 2001
 				}
1911 2002
 
1912 2003
 				// Do <img ...> - with security... action= -> action-.
@@ -1919,8 +2010,9 @@  discard block
 block discarded – undo
1919 2010
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1920 2011
 
1921 2012
 						// Remove action= from the URL - no funny business, now.
1922
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1923
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2013
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
2014
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2015
+						}
1924 2016
 
1925 2017
 						$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1926 2018
 					}
@@ -1935,16 +2027,18 @@  discard block
 block discarded – undo
1935 2027
 				$no_autolink_area = false;
1936 2028
 				if (!empty($open_tags))
1937 2029
 				{
1938
-					foreach ($open_tags as $open_tag)
1939
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2030
+					foreach ($open_tags as $open_tag) {
2031
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1940 2032
 							$no_autolink_area = true;
2033
+					}
1941 2034
 				}
1942 2035
 
1943 2036
 				// Don't go backwards.
1944 2037
 				// @todo Don't think is the real solution....
1945 2038
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1946
-				if ($pos < $lastAutoPos)
1947
-					$no_autolink_area = true;
2039
+				if ($pos < $lastAutoPos) {
2040
+									$no_autolink_area = true;
2041
+				}
1948 2042
 				$lastAutoPos = $pos;
1949 2043
 
1950 2044
 				if (!$no_autolink_area)
@@ -2053,17 +2147,19 @@  discard block
 block discarded – undo
2053 2147
 							if ($scheme == 'mailto')
2054 2148
 							{
2055 2149
 								$email_address = str_replace('mailto:', '', $url);
2056
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2057
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2058
-								else
2059
-									return $url;
2150
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2151
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2152
+								} else {
2153
+																	return $url;
2154
+								}
2060 2155
 							}
2061 2156
 
2062 2157
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2063
-							if (empty($scheme))
2064
-								$fullUrl = '//' . ltrim($url, ':/');
2065
-							else
2066
-								$fullUrl = $url;
2158
+							if (empty($scheme)) {
2159
+															$fullUrl = '//' . ltrim($url, ':/');
2160
+							} else {
2161
+															$fullUrl = $url;
2162
+							}
2067 2163
 
2068 2164
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2069 2165
 						}, $data);
@@ -2112,22 +2208,25 @@  discard block
 block discarded – undo
2112 2208
 		}
2113 2209
 
2114 2210
 		// Are we there yet?  Are we there yet?
2115
-		if ($pos >= strlen($message) - 1)
2116
-			break;
2211
+		if ($pos >= strlen($message) - 1) {
2212
+					break;
2213
+		}
2117 2214
 
2118 2215
 		$tags = strtolower($message[$pos + 1]);
2119 2216
 
2120 2217
 		if ($tags == '/' && !empty($open_tags))
2121 2218
 		{
2122 2219
 			$pos2 = strpos($message, ']', $pos + 1);
2123
-			if ($pos2 == $pos + 2)
2124
-				continue;
2220
+			if ($pos2 == $pos + 2) {
2221
+							continue;
2222
+			}
2125 2223
 
2126 2224
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2127 2225
 
2128 2226
 			// A closing tag that doesn't match any open tags? Skip it.
2129
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2130
-				continue;
2227
+			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) {
2228
+							continue;
2229
+			}
2131 2230
 
2132 2231
 			$to_close = array();
2133 2232
 			$block_level = null;
@@ -2135,8 +2234,9 @@  discard block
 block discarded – undo
2135 2234
 			do
2136 2235
 			{
2137 2236
 				$tag = array_pop($open_tags);
2138
-				if (!$tag)
2139
-					break;
2237
+				if (!$tag) {
2238
+									break;
2239
+				}
2140 2240
 
2141 2241
 				if (!empty($tag['block_level']))
2142 2242
 				{
@@ -2150,10 +2250,11 @@  discard block
 block discarded – undo
2150 2250
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2151 2251
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2152 2252
 					{
2153
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2154
-							if ($temp['tag'] == $look_for)
2253
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2254
+													if ($temp['tag'] == $look_for)
2155 2255
 							{
2156 2256
 								$block_level = !empty($temp['block_level']);
2257
+						}
2157 2258
 								break;
2158 2259
 							}
2159 2260
 					}
@@ -2175,15 +2276,15 @@  discard block
 block discarded – undo
2175 2276
 			{
2176 2277
 				$open_tags = $to_close;
2177 2278
 				continue;
2178
-			}
2179
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2279
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2180 2280
 			{
2181 2281
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2182 2282
 				{
2183
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2184
-						if ($temp['tag'] == $look_for)
2283
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2284
+											if ($temp['tag'] == $look_for)
2185 2285
 						{
2186 2286
 							$block_level = !empty($temp['block_level']);
2287
+					}
2187 2288
 							break;
2188 2289
 						}
2189 2290
 				}
@@ -2191,8 +2292,9 @@  discard block
 block discarded – undo
2191 2292
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2192 2293
 				if (!$block_level)
2193 2294
 				{
2194
-					foreach ($to_close as $tag)
2195
-						array_push($open_tags, $tag);
2295
+					foreach ($to_close as $tag) {
2296
+											array_push($open_tags, $tag);
2297
+					}
2196 2298
 					continue;
2197 2299
 				}
2198 2300
 			}
@@ -2205,14 +2307,17 @@  discard block
 block discarded – undo
2205 2307
 
2206 2308
 				// See the comment at the end of the big loop - just eating whitespace ;).
2207 2309
 				$whitespace_regex = '';
2208
-				if (!empty($tag['block_level']))
2209
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2310
+				if (!empty($tag['block_level'])) {
2311
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2312
+				}
2210 2313
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2211
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2212
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2314
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2315
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2316
+				}
2213 2317
 
2214
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2215
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2318
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2319
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2320
+				}
2216 2321
 			}
2217 2322
 
2218 2323
 			if (!empty($to_close))
@@ -2225,8 +2330,9 @@  discard block
 block discarded – undo
2225 2330
 		}
2226 2331
 
2227 2332
 		// No tags for this character, so just keep going (fastest possible course.)
2228
-		if (!isset($bbc_codes[$tags]))
2229
-			continue;
2333
+		if (!isset($bbc_codes[$tags])) {
2334
+					continue;
2335
+		}
2230 2336
 
2231 2337
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2232 2338
 		$tag = null;
@@ -2235,48 +2341,57 @@  discard block
 block discarded – undo
2235 2341
 			$pt_strlen = strlen($possible['tag']);
2236 2342
 
2237 2343
 			// Not a match?
2238
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2239
-				continue;
2344
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2345
+							continue;
2346
+			}
2240 2347
 
2241 2348
 			$next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : '';
2242 2349
 
2243 2350
 			// A tag is the last char maybe
2244
-			if ($next_c == '')
2245
-				break;
2351
+			if ($next_c == '') {
2352
+							break;
2353
+			}
2246 2354
 
2247 2355
 			// A test validation?
2248
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2249
-				continue;
2356
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2357
+							continue;
2358
+			}
2250 2359
 			// Do we want parameters?
2251 2360
 			elseif (!empty($possible['parameters']))
2252 2361
 			{
2253
-				if ($next_c != ' ')
2254
-					continue;
2255
-			}
2256
-			elseif (isset($possible['type']))
2362
+				if ($next_c != ' ') {
2363
+									continue;
2364
+				}
2365
+			} elseif (isset($possible['type']))
2257 2366
 			{
2258 2367
 				// Do we need an equal sign?
2259
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2260
-					continue;
2368
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2369
+									continue;
2370
+				}
2261 2371
 				// Maybe we just want a /...
2262
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2263
-					continue;
2372
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2373
+									continue;
2374
+				}
2264 2375
 				// An immediate ]?
2265
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2266
-					continue;
2376
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2377
+									continue;
2378
+				}
2267 2379
 			}
2268 2380
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2269
-			elseif ($next_c != ']')
2270
-				continue;
2381
+			elseif ($next_c != ']') {
2382
+							continue;
2383
+			}
2271 2384
 
2272 2385
 			// Check allowed tree?
2273
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2274
-				continue;
2275
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2276
-				continue;
2386
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2387
+							continue;
2388
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2389
+							continue;
2390
+			}
2277 2391
 			// If this is in the list of disallowed child tags, don't parse it.
2278
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2279
-				continue;
2392
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2393
+							continue;
2394
+			}
2280 2395
 
2281 2396
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2282 2397
 
@@ -2288,8 +2403,9 @@  discard block
 block discarded – undo
2288 2403
 				foreach ($open_tags as $open_quote)
2289 2404
 				{
2290 2405
 					// Every parent quote this quote has flips the styling
2291
-					if ($open_quote['tag'] == 'quote')
2292
-						$quote_alt = !$quote_alt;
2406
+					if ($open_quote['tag'] == 'quote') {
2407
+											$quote_alt = !$quote_alt;
2408
+					}
2293 2409
 				}
2294 2410
 				// Add a class to the quote to style alternating blockquotes
2295 2411
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2300,8 +2416,9 @@  discard block
 block discarded – undo
2300 2416
 			{
2301 2417
 				// Build a regular expression for each parameter for the current tag.
2302 2418
 				$preg = array();
2303
-				foreach ($possible['parameters'] as $p => $info)
2304
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2419
+				foreach ($possible['parameters'] as $p => $info) {
2420
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2421
+				}
2305 2422
 
2306 2423
 				// Extract the string that potentially holds our parameters.
2307 2424
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2321,24 +2438,27 @@  discard block
 block discarded – undo
2321 2438
 
2322 2439
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2323 2440
 
2324
-					if ($match)
2325
-						$blob_counter = count($blobs) + 1;
2441
+					if ($match) {
2442
+											$blob_counter = count($blobs) + 1;
2443
+					}
2326 2444
 				}
2327 2445
 
2328 2446
 				// Didn't match our parameter list, try the next possible.
2329
-				if (!$match)
2330
-					continue;
2447
+				if (!$match) {
2448
+									continue;
2449
+				}
2331 2450
 
2332 2451
 				$params = array();
2333 2452
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2334 2453
 				{
2335 2454
 					$key = strtok(ltrim($matches[$i]), '=');
2336
-					if (isset($possible['parameters'][$key]['value']))
2337
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2338
-					elseif (isset($possible['parameters'][$key]['validate']))
2339
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2340
-					else
2341
-						$params['{' . $key . '}'] = $matches[$i + 1];
2455
+					if (isset($possible['parameters'][$key]['value'])) {
2456
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2457
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2458
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2459
+					} else {
2460
+											$params['{' . $key . '}'] = $matches[$i + 1];
2461
+					}
2342 2462
 
2343 2463
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2344 2464
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2346,23 +2466,26 @@  discard block
 block discarded – undo
2346 2466
 
2347 2467
 				foreach ($possible['parameters'] as $p => $info)
2348 2468
 				{
2349
-					if (!isset($params['{' . $p . '}']))
2350
-						$params['{' . $p . '}'] = '';
2469
+					if (!isset($params['{' . $p . '}'])) {
2470
+											$params['{' . $p . '}'] = '';
2471
+					}
2351 2472
 				}
2352 2473
 
2353 2474
 				$tag = $possible;
2354 2475
 
2355 2476
 				// Put the parameters into the string.
2356
-				if (isset($tag['before']))
2357
-					$tag['before'] = strtr($tag['before'], $params);
2358
-				if (isset($tag['after']))
2359
-					$tag['after'] = strtr($tag['after'], $params);
2360
-				if (isset($tag['content']))
2361
-					$tag['content'] = strtr($tag['content'], $params);
2477
+				if (isset($tag['before'])) {
2478
+									$tag['before'] = strtr($tag['before'], $params);
2479
+				}
2480
+				if (isset($tag['after'])) {
2481
+									$tag['after'] = strtr($tag['after'], $params);
2482
+				}
2483
+				if (isset($tag['content'])) {
2484
+									$tag['content'] = strtr($tag['content'], $params);
2485
+				}
2362 2486
 
2363 2487
 				$pos1 += strlen($given_param_string);
2364
-			}
2365
-			else
2488
+			} else
2366 2489
 			{
2367 2490
 				$tag = $possible;
2368 2491
 				$params = array();
@@ -2373,8 +2496,9 @@  discard block
 block discarded – undo
2373 2496
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2374 2497
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2375 2498
 		{
2376
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2377
-				continue;
2499
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2500
+							continue;
2501
+			}
2378 2502
 
2379 2503
 			$tag = $itemcodes[$message[$pos + 1]];
2380 2504
 
@@ -2395,9 +2519,9 @@  discard block
 block discarded – undo
2395 2519
 			{
2396 2520
 				array_pop($open_tags);
2397 2521
 				$code = '</li>';
2522
+			} else {
2523
+							$code = '';
2398 2524
 			}
2399
-			else
2400
-				$code = '';
2401 2525
 
2402 2526
 			// Now we open a new tag.
2403 2527
 			$open_tags[] = array(
@@ -2444,12 +2568,14 @@  discard block
 block discarded – undo
2444 2568
 		}
2445 2569
 
2446 2570
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2447
-		if ($tag === null)
2448
-			continue;
2571
+		if ($tag === null) {
2572
+					continue;
2573
+		}
2449 2574
 
2450 2575
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2451
-		if (isset($inside['disallow_children']))
2452
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2576
+		if (isset($inside['disallow_children'])) {
2577
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2578
+		}
2453 2579
 
2454 2580
 		// Is this tag disabled?
2455 2581
 		if (isset($disabled[$tag['tag']]))
@@ -2459,14 +2585,13 @@  discard block
 block discarded – undo
2459 2585
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2460 2586
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2461 2587
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2462
-			}
2463
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2588
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2464 2589
 			{
2465 2590
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2466 2591
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2592
+			} else {
2593
+							$tag['content'] = $tag['disabled_content'];
2467 2594
 			}
2468
-			else
2469
-				$tag['content'] = $tag['disabled_content'];
2470 2595
 		}
2471 2596
 
2472 2597
 		// we use this a lot
@@ -2476,8 +2601,9 @@  discard block
 block discarded – undo
2476 2601
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2477 2602
 		{
2478 2603
 			$n = count($open_tags) - 1;
2479
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2480
-				$n--;
2604
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2605
+							$n--;
2606
+			}
2481 2607
 
2482 2608
 			// Close all the non block level tags so this tag isn't surrounded by them.
2483 2609
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2489,12 +2615,15 @@  discard block
 block discarded – undo
2489 2615
 
2490 2616
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2491 2617
 				$whitespace_regex = '';
2492
-				if (!empty($tag['block_level']))
2493
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2494
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2495
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2496
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2497
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2618
+				if (!empty($tag['block_level'])) {
2619
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2620
+				}
2621
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2622
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2623
+				}
2624
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2625
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2626
+				}
2498 2627
 
2499 2628
 				array_pop($open_tags);
2500 2629
 			}
@@ -2515,16 +2644,19 @@  discard block
 block discarded – undo
2515 2644
 		elseif ($tag['type'] == 'unparsed_content')
2516 2645
 		{
2517 2646
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2518
-			if ($pos2 === false)
2519
-				continue;
2647
+			if ($pos2 === false) {
2648
+							continue;
2649
+			}
2520 2650
 
2521 2651
 			$data = substr($message, $pos1, $pos2 - $pos1);
2522 2652
 
2523
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2524
-				$data = substr($data, 4);
2653
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2654
+							$data = substr($data, 4);
2655
+			}
2525 2656
 
2526
-			if (isset($tag['validate']))
2527
-				$tag['validate']($tag, $data, $disabled, $params);
2657
+			if (isset($tag['validate'])) {
2658
+							$tag['validate']($tag, $data, $disabled, $params);
2659
+			}
2528 2660
 
2529 2661
 			$code = strtr($tag['content'], array('$1' => $data));
2530 2662
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2540,34 +2672,40 @@  discard block
 block discarded – undo
2540 2672
 			if (isset($tag['quoted']))
2541 2673
 			{
2542 2674
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2543
-				if ($tag['quoted'] != 'optional' && !$quoted)
2544
-					continue;
2675
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2676
+									continue;
2677
+				}
2545 2678
 
2546
-				if ($quoted)
2547
-					$pos1 += 6;
2679
+				if ($quoted) {
2680
+									$pos1 += 6;
2681
+				}
2682
+			} else {
2683
+							$quoted = false;
2548 2684
 			}
2549
-			else
2550
-				$quoted = false;
2551 2685
 
2552 2686
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2553
-			if ($pos2 === false)
2554
-				continue;
2687
+			if ($pos2 === false) {
2688
+							continue;
2689
+			}
2555 2690
 
2556 2691
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2557
-			if ($pos3 === false)
2558
-				continue;
2692
+			if ($pos3 === false) {
2693
+							continue;
2694
+			}
2559 2695
 
2560 2696
 			$data = array(
2561 2697
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2562 2698
 				substr($message, $pos1, $pos2 - $pos1)
2563 2699
 			);
2564 2700
 
2565
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2566
-				$data[0] = substr($data[0], 4);
2701
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2702
+							$data[0] = substr($data[0], 4);
2703
+			}
2567 2704
 
2568 2705
 			// Validation for my parking, please!
2569
-			if (isset($tag['validate']))
2570
-				$tag['validate']($tag, $data, $disabled, $params);
2706
+			if (isset($tag['validate'])) {
2707
+							$tag['validate']($tag, $data, $disabled, $params);
2708
+			}
2571 2709
 
2572 2710
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2573 2711
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2584,23 +2722,27 @@  discard block
 block discarded – undo
2584 2722
 		elseif ($tag['type'] == 'unparsed_commas_content')
2585 2723
 		{
2586 2724
 			$pos2 = strpos($message, ']', $pos1);
2587
-			if ($pos2 === false)
2588
-				continue;
2725
+			if ($pos2 === false) {
2726
+							continue;
2727
+			}
2589 2728
 
2590 2729
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2591
-			if ($pos3 === false)
2592
-				continue;
2730
+			if ($pos3 === false) {
2731
+							continue;
2732
+			}
2593 2733
 
2594 2734
 			// We want $1 to be the content, and the rest to be csv.
2595 2735
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2596 2736
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2597 2737
 
2598
-			if (isset($tag['validate']))
2599
-				$tag['validate']($tag, $data, $disabled, $params);
2738
+			if (isset($tag['validate'])) {
2739
+							$tag['validate']($tag, $data, $disabled, $params);
2740
+			}
2600 2741
 
2601 2742
 			$code = $tag['content'];
2602
-			foreach ($data as $k => $d)
2603
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2743
+			foreach ($data as $k => $d) {
2744
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2745
+			}
2604 2746
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2605 2747
 			$pos += strlen($code) - 1 + 2;
2606 2748
 		}
@@ -2608,24 +2750,28 @@  discard block
 block discarded – undo
2608 2750
 		elseif ($tag['type'] == 'unparsed_commas')
2609 2751
 		{
2610 2752
 			$pos2 = strpos($message, ']', $pos1);
2611
-			if ($pos2 === false)
2612
-				continue;
2753
+			if ($pos2 === false) {
2754
+							continue;
2755
+			}
2613 2756
 
2614 2757
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2615 2758
 
2616
-			if (isset($tag['validate']))
2617
-				$tag['validate']($tag, $data, $disabled, $params);
2759
+			if (isset($tag['validate'])) {
2760
+							$tag['validate']($tag, $data, $disabled, $params);
2761
+			}
2618 2762
 
2619 2763
 			// Fix after, for disabled code mainly.
2620
-			foreach ($data as $k => $d)
2621
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2764
+			foreach ($data as $k => $d) {
2765
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2766
+			}
2622 2767
 
2623 2768
 			$open_tags[] = $tag;
2624 2769
 
2625 2770
 			// Replace them out, $1, $2, $3, $4, etc.
2626 2771
 			$code = $tag['before'];
2627
-			foreach ($data as $k => $d)
2628
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2772
+			foreach ($data as $k => $d) {
2773
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2774
+			}
2629 2775
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2630 2776
 			$pos += strlen($code) - 1 + 2;
2631 2777
 		}
@@ -2636,28 +2782,33 @@  discard block
 block discarded – undo
2636 2782
 			if (isset($tag['quoted']))
2637 2783
 			{
2638 2784
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2639
-				if ($tag['quoted'] != 'optional' && !$quoted)
2640
-					continue;
2785
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2786
+									continue;
2787
+				}
2641 2788
 
2642
-				if ($quoted)
2643
-					$pos1 += 6;
2789
+				if ($quoted) {
2790
+									$pos1 += 6;
2791
+				}
2792
+			} else {
2793
+							$quoted = false;
2644 2794
 			}
2645
-			else
2646
-				$quoted = false;
2647 2795
 
2648 2796
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2649
-			if ($pos2 === false)
2650
-				continue;
2797
+			if ($pos2 === false) {
2798
+							continue;
2799
+			}
2651 2800
 
2652 2801
 			$data = substr($message, $pos1, $pos2 - $pos1);
2653 2802
 
2654 2803
 			// Validation for my parking, please!
2655
-			if (isset($tag['validate']))
2656
-				$tag['validate']($tag, $data, $disabled, $params);
2804
+			if (isset($tag['validate'])) {
2805
+							$tag['validate']($tag, $data, $disabled, $params);
2806
+			}
2657 2807
 
2658 2808
 			// For parsed content, we must recurse to avoid security problems.
2659
-			if ($tag['type'] != 'unparsed_equals')
2660
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2809
+			if ($tag['type'] != 'unparsed_equals') {
2810
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2811
+			}
2661 2812
 
2662 2813
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2663 2814
 
@@ -2669,34 +2820,40 @@  discard block
 block discarded – undo
2669 2820
 		}
2670 2821
 
2671 2822
 		// If this is block level, eat any breaks after it.
2672
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2673
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2823
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2824
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2825
+		}
2674 2826
 
2675 2827
 		// Are we trimming outside this tag?
2676
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2677
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2828
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2829
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2830
+		}
2678 2831
 	}
2679 2832
 
2680 2833
 	// Close any remaining tags.
2681
-	while ($tag = array_pop($open_tags))
2682
-		$message .= "\n" . $tag['after'] . "\n";
2834
+	while ($tag = array_pop($open_tags)) {
2835
+			$message .= "\n" . $tag['after'] . "\n";
2836
+	}
2683 2837
 
2684 2838
 	// Parse the smileys within the parts where it can be done safely.
2685 2839
 	if ($smileys === true)
2686 2840
 	{
2687 2841
 		$message_parts = explode("\n", $message);
2688
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2689
-			parsesmileys($message_parts[$i]);
2842
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2843
+					parsesmileys($message_parts[$i]);
2844
+		}
2690 2845
 
2691 2846
 		$message = implode('', $message_parts);
2692 2847
 	}
2693 2848
 
2694 2849
 	// No smileys, just get rid of the markers.
2695
-	else
2696
-		$message = strtr($message, array("\n" => ''));
2850
+	else {
2851
+			$message = strtr($message, array("\n" => ''));
2852
+	}
2697 2853
 
2698
-	if ($message !== '' && $message[0] === ' ')
2699
-		$message = '&nbsp;' . substr($message, 1);
2854
+	if ($message !== '' && $message[0] === ' ') {
2855
+			$message = '&nbsp;' . substr($message, 1);
2856
+	}
2700 2857
 
2701 2858
 	// Cleanup whitespace.
2702 2859
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2705,15 +2862,16 @@  discard block
 block discarded – undo
2705 2862
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2706 2863
 
2707 2864
 	// Cache the output if it took some time...
2708
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2709
-		cache_put_data($cache_key, $message, 240);
2865
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2866
+			cache_put_data($cache_key, $message, 240);
2867
+	}
2710 2868
 
2711 2869
 	// If this was a force parse revert if needed.
2712 2870
 	if (!empty($parse_tags))
2713 2871
 	{
2714
-		if (empty($temp_bbc))
2715
-			$bbc_codes = array();
2716
-		else
2872
+		if (empty($temp_bbc)) {
2873
+					$bbc_codes = array();
2874
+		} else
2717 2875
 		{
2718 2876
 			$bbc_codes = $temp_bbc;
2719 2877
 			unset($temp_bbc);
@@ -2740,8 +2898,9 @@  discard block
 block discarded – undo
2740 2898
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2741 2899
 
2742 2900
 	// No smiley set at all?!
2743
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2744
-		return;
2901
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2902
+			return;
2903
+	}
2745 2904
 
2746 2905
 	// If smileyPregSearch hasn't been set, do it now.
2747 2906
 	if (empty($smileyPregSearch))
@@ -2752,8 +2911,7 @@  discard block
 block discarded – undo
2752 2911
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2753 2912
 			$smileysto = array('evil.png', 'cheesy.png', 'rolleyes.png', 'angry.png', 'laugh.png', 'smiley.png', 'wink.png', 'grin.png', 'sad.png', 'shocked.png', 'cool.png', 'tongue.png', 'huh.png', 'embarrassed.png', 'lipsrsealed.png', 'kiss.png', 'cry.png', 'undecided.png', 'azn.png', 'afro.png', 'police.png', 'angel.png');
2754 2913
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2755
-		}
2756
-		else
2914
+		} else
2757 2915
 		{
2758 2916
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2759 2917
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2777,9 +2935,9 @@  discard block
 block discarded – undo
2777 2935
 				$smcFunc['db_free_result']($result);
2778 2936
 
2779 2937
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2938
+			} else {
2939
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2780 2940
 			}
2781
-			else
2782
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2783 2941
 		}
2784 2942
 
2785 2943
 		// The non-breaking-space is a complex thing...
@@ -2857,12 +3015,14 @@  discard block
 block discarded – undo
2857 3015
 	global $boardurl, $image_proxy_enabled, $image_proxy_secret;
2858 3016
 
2859 3017
 	// Only use the proxy if enabled and necessary
2860
-	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https')
2861
-		return $url;
3018
+	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') {
3019
+			return $url;
3020
+	}
2862 3021
 
2863 3022
 	// We don't need to proxy our own resources
2864
-	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0)
2865
-		return strtr($url, array('http://' => 'https://'));
3023
+	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) {
3024
+			return strtr($url, array('http://' => 'https://'));
3025
+	}
2866 3026
 
2867 3027
 	// By default, use SMF's own image proxy script
2868 3028
 	$proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret);
@@ -2887,35 +3047,41 @@  discard block
 block discarded – undo
2887 3047
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2888 3048
 
2889 3049
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2890
-	if (!empty($context['flush_mail']))
2891
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3050
+	if (!empty($context['flush_mail'])) {
3051
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2892 3052
 		AddMailQueue(true);
3053
+	}
2893 3054
 
2894 3055
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2895 3056
 
2896
-	if ($add)
2897
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3057
+	if ($add) {
3058
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3059
+	}
2898 3060
 
2899 3061
 	// Put the session ID in.
2900
-	if (defined('SID') && SID != '')
2901
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3062
+	if (defined('SID') && SID != '') {
3063
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3064
+	}
2902 3065
 	// Keep that debug in their for template debugging!
2903
-	elseif (isset($_GET['debug']))
2904
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3066
+	elseif (isset($_GET['debug'])) {
3067
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3068
+	}
2905 3069
 
2906 3070
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
2907 3071
 	{
2908
-		if (defined('SID') && SID != '')
2909
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3072
+		if (defined('SID') && SID != '') {
3073
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2910 3074
 				function ($m) use ($scripturl)
2911 3075
 				{
2912 3076
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3077
+		}
2913 3078
 				}, $setLocation);
2914
-		else
2915
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3079
+		else {
3080
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2916 3081
 				function ($m) use ($scripturl)
2917 3082
 				{
2918 3083
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3084
+		}
2919 3085
 				}, $setLocation);
2920 3086
 	}
2921 3087
 
@@ -2926,8 +3092,9 @@  discard block
 block discarded – undo
2926 3092
 	header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2927 3093
 
2928 3094
 	// Debugging.
2929
-	if (isset($db_show_debug) && $db_show_debug === true)
2930
-		$_SESSION['debug_redirect'] = $db_cache;
3095
+	if (isset($db_show_debug) && $db_show_debug === true) {
3096
+			$_SESSION['debug_redirect'] = $db_cache;
3097
+	}
2931 3098
 
2932 3099
 	obExit(false);
2933 3100
 }
@@ -2946,51 +3113,60 @@  discard block
 block discarded – undo
2946 3113
 
2947 3114
 	// Attempt to prevent a recursive loop.
2948 3115
 	++$level;
2949
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2950
-		exit;
2951
-	if ($from_fatal_error)
2952
-		$has_fatal_error = true;
3116
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3117
+			exit;
3118
+	}
3119
+	if ($from_fatal_error) {
3120
+			$has_fatal_error = true;
3121
+	}
2953 3122
 
2954 3123
 	// Clear out the stat cache.
2955 3124
 	trackStats();
2956 3125
 
2957 3126
 	// If we have mail to send, send it.
2958
-	if (!empty($context['flush_mail']))
2959
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3127
+	if (!empty($context['flush_mail'])) {
3128
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2960 3129
 		AddMailQueue(true);
3130
+	}
2961 3131
 
2962 3132
 	$do_header = $header === null ? !$header_done : $header;
2963
-	if ($do_footer === null)
2964
-		$do_footer = $do_header;
3133
+	if ($do_footer === null) {
3134
+			$do_footer = $do_header;
3135
+	}
2965 3136
 
2966 3137
 	// Has the template/header been done yet?
2967 3138
 	if ($do_header)
2968 3139
 	{
2969 3140
 		// Was the page title set last minute? Also update the HTML safe one.
2970
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2971
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3141
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3142
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3143
+		}
2972 3144
 
2973 3145
 		// Start up the session URL fixer.
2974 3146
 		ob_start('ob_sessrewrite');
2975 3147
 
2976
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2977
-			$buffers = explode(',', $settings['output_buffers']);
2978
-		elseif (!empty($settings['output_buffers']))
2979
-			$buffers = $settings['output_buffers'];
2980
-		else
2981
-			$buffers = array();
3148
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3149
+					$buffers = explode(',', $settings['output_buffers']);
3150
+		} elseif (!empty($settings['output_buffers'])) {
3151
+					$buffers = $settings['output_buffers'];
3152
+		} else {
3153
+					$buffers = array();
3154
+		}
2982 3155
 
2983
-		if (isset($modSettings['integrate_buffer']))
2984
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3156
+		if (isset($modSettings['integrate_buffer'])) {
3157
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3158
+		}
2985 3159
 
2986
-		if (!empty($buffers))
2987
-			foreach ($buffers as $function)
3160
+		if (!empty($buffers)) {
3161
+					foreach ($buffers as $function)
2988 3162
 			{
2989 3163
 				$call = call_helper($function, true);
3164
+		}
2990 3165
 
2991 3166
 				// Is it valid?
2992
-				if (!empty($call))
2993
-					ob_start($call);
3167
+				if (!empty($call)) {
3168
+									ob_start($call);
3169
+				}
2994 3170
 			}
2995 3171
 
2996 3172
 		// Display the screen in the logical order.
@@ -3002,8 +3178,9 @@  discard block
 block discarded – undo
3002 3178
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
3003 3179
 
3004 3180
 		// Anything special to put out?
3005
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
3006
-			echo $context['insert_after_template'];
3181
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3182
+					echo $context['insert_after_template'];
3183
+		}
3007 3184
 
3008 3185
 		// Just so we don't get caught in an endless loop of errors from the footer...
3009 3186
 		if (!$footer_done)
@@ -3012,14 +3189,16 @@  discard block
 block discarded – undo
3012 3189
 			template_footer();
3013 3190
 
3014 3191
 			// (since this is just debugging... it's okay that it's after </html>.)
3015
-			if (!isset($_REQUEST['xml']))
3016
-				displayDebug();
3192
+			if (!isset($_REQUEST['xml'])) {
3193
+							displayDebug();
3194
+			}
3017 3195
 		}
3018 3196
 	}
3019 3197
 
3020 3198
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
3021
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
3022
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3199
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3200
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3201
+	}
3023 3202
 
3024 3203
 	// For session check verification.... don't switch browsers...
3025 3204
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -3028,9 +3207,10 @@  discard block
 block discarded – undo
3028 3207
 	call_integration_hook('integrate_exit', array($do_footer));
3029 3208
 
3030 3209
 	// Don't exit if we're coming from index.php; that will pass through normally.
3031
-	if (!$from_index)
3032
-		exit;
3033
-}
3210
+	if (!$from_index) {
3211
+			exit;
3212
+	}
3213
+	}
3034 3214
 
3035 3215
 /**
3036 3216
  * Get the size of a specified image with better error handling.
@@ -3049,8 +3229,9 @@  discard block
 block discarded – undo
3049 3229
 	$url = str_replace(' ', '%20', $url);
3050 3230
 
3051 3231
 	// Can we pull this from the cache... please please?
3052
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3053
-		return $temp;
3232
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3233
+			return $temp;
3234
+	}
3054 3235
 	$t = microtime();
3055 3236
 
3056 3237
 	// Get the host to pester...
@@ -3060,12 +3241,10 @@  discard block
 block discarded – undo
3060 3241
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3061 3242
 	{
3062 3243
 		return false;
3063
-	}
3064
-	elseif (!isset($match[1]))
3244
+	} elseif (!isset($match[1]))
3065 3245
 	{
3066 3246
 		$size = @getimagesize($url);
3067
-	}
3068
-	else
3247
+	} else
3069 3248
 	{
3070 3249
 		// Try to connect to the server... give it half a second.
3071 3250
 		$temp = 0;
@@ -3102,12 +3281,14 @@  discard block
 block discarded – undo
3102 3281
 	}
3103 3282
 
3104 3283
 	// If we didn't get it, we failed.
3105
-	if (!isset($size))
3106
-		$size = false;
3284
+	if (!isset($size)) {
3285
+			$size = false;
3286
+	}
3107 3287
 
3108 3288
 	// If this took a long time, we may never have to do it again, but then again we might...
3109
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3110
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3289
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3290
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3291
+	}
3111 3292
 
3112 3293
 	// Didn't work.
3113 3294
 	return $size;
@@ -3125,8 +3306,9 @@  discard block
 block discarded – undo
3125 3306
 
3126 3307
 	// Under SSI this function can be called more then once.  That can cause some problems.
3127 3308
 	//   So only run the function once unless we are forced to run it again.
3128
-	if ($loaded && !$forceload)
3129
-		return;
3309
+	if ($loaded && !$forceload) {
3310
+			return;
3311
+	}
3130 3312
 
3131 3313
 	$loaded = true;
3132 3314
 
@@ -3138,14 +3320,16 @@  discard block
 block discarded – undo
3138 3320
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3139 3321
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3140 3322
 	{
3141
-		if (trim($context['news_lines'][$i]) == '')
3142
-			continue;
3323
+		if (trim($context['news_lines'][$i]) == '') {
3324
+					continue;
3325
+		}
3143 3326
 
3144 3327
 		// Clean it up for presentation ;).
3145 3328
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3146 3329
 	}
3147
-	if (!empty($context['news_lines']))
3148
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3330
+	if (!empty($context['news_lines'])) {
3331
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3332
+	}
3149 3333
 
3150 3334
 	if (!$user_info['is_guest'])
3151 3335
 	{
@@ -3154,40 +3338,48 @@  discard block
 block discarded – undo
3154 3338
 		$context['user']['alerts'] = &$user_info['alerts'];
3155 3339
 
3156 3340
 		// Personal message popup...
3157
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3158
-			$context['user']['popup_messages'] = true;
3159
-		else
3160
-			$context['user']['popup_messages'] = false;
3341
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3342
+					$context['user']['popup_messages'] = true;
3343
+		} else {
3344
+					$context['user']['popup_messages'] = false;
3345
+		}
3161 3346
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3162 3347
 
3163
-		if (allowedTo('moderate_forum'))
3164
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3348
+		if (allowedTo('moderate_forum')) {
3349
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3350
+		}
3165 3351
 
3166 3352
 		$context['user']['avatar'] = array();
3167 3353
 
3168 3354
 		// Check for gravatar first since we might be forcing them...
3169 3355
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3170 3356
 		{
3171
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3172
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3173
-			else
3174
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3357
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3358
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3359
+			} else {
3360
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3361
+			}
3175 3362
 		}
3176 3363
 		// Uploaded?
3177
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3178
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3364
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3365
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3366
+		}
3179 3367
 		// Full URL?
3180
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3181
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3368
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3369
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3370
+		}
3182 3371
 		// Otherwise we assume it's server stored.
3183
-		elseif ($user_info['avatar']['url'] != '')
3184
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3372
+		elseif ($user_info['avatar']['url'] != '') {
3373
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3374
+		}
3185 3375
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3186
-		else
3187
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3376
+		else {
3377
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3378
+		}
3188 3379
 
3189
-		if (!empty($context['user']['avatar']))
3190
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3380
+		if (!empty($context['user']['avatar'])) {
3381
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3382
+		}
3191 3383
 
3192 3384
 		// Figure out how long they've been logged in.
3193 3385
 		$context['user']['total_time_logged_in'] = array(
@@ -3195,8 +3387,7 @@  discard block
 block discarded – undo
3195 3387
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3196 3388
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3197 3389
 		);
3198
-	}
3199
-	else
3390
+	} else
3200 3391
 	{
3201 3392
 		$context['user']['messages'] = 0;
3202 3393
 		$context['user']['unread_messages'] = 0;
@@ -3204,12 +3395,14 @@  discard block
 block discarded – undo
3204 3395
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3205 3396
 		$context['user']['popup_messages'] = false;
3206 3397
 
3207
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3208
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3398
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3399
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3400
+		}
3209 3401
 
3210 3402
 		// If we've upgraded recently, go easy on the passwords.
3211
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3212
-			$context['disable_login_hashing'] = true;
3403
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3404
+					$context['disable_login_hashing'] = true;
3405
+		}
3213 3406
 	}
3214 3407
 
3215 3408
 	// Setup the main menu items.
@@ -3222,8 +3415,8 @@  discard block
 block discarded – undo
3222 3415
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3223 3416
 
3224 3417
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3225
-	if ($context['show_pm_popup'])
3226
-		addInlineJavaScript('
3418
+	if ($context['show_pm_popup']) {
3419
+			addInlineJavaScript('
3227 3420
 		jQuery(document).ready(function($) {
3228 3421
 			new smc_Popup({
3229 3422
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3231,24 +3424,28 @@  discard block
 block discarded – undo
3231 3424
 				icon_class: \'generic_icons mail_new\'
3232 3425
 			});
3233 3426
 		});');
3427
+	}
3234 3428
 
3235 3429
 	// Add a generic "Are you sure?" confirmation message.
3236 3430
 	addInlineJavaScript('
3237 3431
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3238 3432
 
3239 3433
 	// Now add the capping code for avatars.
3240
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3241
-		addInlineCss('
3434
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3435
+			addInlineCss('
3242 3436
 	img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3437
+	}
3243 3438
 
3244 3439
 	// Add max image limits
3245
-	if (!empty($modSettings['max_image_width']))
3246
-		addInlineCss('
3440
+	if (!empty($modSettings['max_image_width'])) {
3441
+			addInlineCss('
3247 3442
 	.postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }');
3443
+	}
3248 3444
 
3249
-	if (!empty($modSettings['max_image_height']))
3250
-		addInlineCss('
3445
+	if (!empty($modSettings['max_image_height'])) {
3446
+			addInlineCss('
3251 3447
 	.postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }');
3448
+	}
3252 3449
 
3253 3450
 	// This looks weird, but it's because BoardIndex.php references the variable.
3254 3451
 	$context['common_stats']['latest_member'] = array(
@@ -3265,11 +3462,13 @@  discard block
 block discarded – undo
3265 3462
 	);
3266 3463
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3267 3464
 
3268
-	if (empty($settings['theme_version']))
3269
-		addJavaScriptVar('smf_scripturl', $scripturl);
3465
+	if (empty($settings['theme_version'])) {
3466
+			addJavaScriptVar('smf_scripturl', $scripturl);
3467
+	}
3270 3468
 
3271
-	if (!isset($context['page_title']))
3272
-		$context['page_title'] = '';
3469
+	if (!isset($context['page_title'])) {
3470
+			$context['page_title'] = '';
3471
+	}
3273 3472
 
3274 3473
 	// Set some specific vars.
3275 3474
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3279,21 +3478,23 @@  discard block
 block discarded – undo
3279 3478
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3280 3479
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3281 3480
 
3282
-	if (!empty($context['meta_keywords']))
3283
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3481
+	if (!empty($context['meta_keywords'])) {
3482
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3483
+	}
3284 3484
 
3285
-	if (!empty($context['canonical_url']))
3286
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3485
+	if (!empty($context['canonical_url'])) {
3486
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3487
+	}
3287 3488
 
3288
-	if (!empty($settings['og_image']))
3289
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3489
+	if (!empty($settings['og_image'])) {
3490
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3491
+	}
3290 3492
 
3291 3493
 	if (!empty($context['meta_description']))
3292 3494
 	{
3293 3495
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3294 3496
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3295
-	}
3296
-	else
3497
+	} else
3297 3498
 	{
3298 3499
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3299 3500
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3318,8 +3519,9 @@  discard block
 block discarded – undo
3318 3519
 	$memory_needed = memoryReturnBytes($needed);
3319 3520
 
3320 3521
 	// should we account for how much is currently being used?
3321
-	if ($in_use)
3322
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3522
+	if ($in_use) {
3523
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3524
+	}
3323 3525
 
3324 3526
 	// if more is needed, request it
3325 3527
 	if ($memory_current < $memory_needed)
@@ -3342,8 +3544,9 @@  discard block
 block discarded – undo
3342 3544
  */
3343 3545
 function memoryReturnBytes($val)
3344 3546
 {
3345
-	if (is_integer($val))
3346
-		return $val;
3547
+	if (is_integer($val)) {
3548
+			return $val;
3549
+	}
3347 3550
 
3348 3551
 	// Separate the number from the designator
3349 3552
 	$val = trim($val);
@@ -3379,10 +3582,11 @@  discard block
 block discarded – undo
3379 3582
 		header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3380 3583
 
3381 3584
 		// Are we debugging the template/html content?
3382
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3383
-			header('content-type: application/xhtml+xml');
3384
-		elseif (!isset($_REQUEST['xml']))
3385
-			header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3585
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3586
+					header('content-type: application/xhtml+xml');
3587
+		} elseif (!isset($_REQUEST['xml'])) {
3588
+					header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3589
+		}
3386 3590
 	}
3387 3591
 
3388 3592
 	header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3391,8 +3595,9 @@  discard block
 block discarded – undo
3391 3595
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3392 3596
 	{
3393 3597
 		$position = array_search('body', $context['template_layers']);
3394
-		if ($position === false)
3395
-			$position = array_search('main', $context['template_layers']);
3598
+		if ($position === false) {
3599
+					$position = array_search('main', $context['template_layers']);
3600
+		}
3396 3601
 
3397 3602
 		if ($position !== false)
3398 3603
 		{
@@ -3420,23 +3625,25 @@  discard block
 block discarded – undo
3420 3625
 
3421 3626
 			foreach ($securityFiles as $i => $securityFile)
3422 3627
 			{
3423
-				if (!file_exists($boarddir . '/' . $securityFile))
3424
-					unset($securityFiles[$i]);
3628
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3629
+									unset($securityFiles[$i]);
3630
+				}
3425 3631
 			}
3426 3632
 
3427 3633
 			// We are already checking so many files...just few more doesn't make any difference! :P
3428
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3429
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3430
-
3431
-			else
3432
-				$path = $modSettings['attachmentUploadDir'];
3634
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3635
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3636
+			} else {
3637
+							$path = $modSettings['attachmentUploadDir'];
3638
+			}
3433 3639
 
3434 3640
 			secureDirectory($path, true);
3435 3641
 			secureDirectory($cachedir);
3436 3642
 
3437 3643
 			// If agreement is enabled, at least the english version shall exists
3438
-			if ($modSettings['requireAgreement'])
3439
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3644
+			if ($modSettings['requireAgreement']) {
3645
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3646
+			}
3440 3647
 
3441 3648
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3442 3649
 			{
@@ -3451,18 +3658,21 @@  discard block
 block discarded – undo
3451 3658
 					echo '
3452 3659
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3453 3660
 
3454
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3455
-						echo '
3661
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3662
+											echo '
3456 3663
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3664
+					}
3457 3665
 				}
3458 3666
 
3459
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3460
-					echo '
3667
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3668
+									echo '
3461 3669
 				<strong>', $txt['cache_writable'], '</strong><br>';
3670
+				}
3462 3671
 
3463
-				if (!empty($agreement))
3464
-					echo '
3672
+				if (!empty($agreement)) {
3673
+									echo '
3465 3674
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3675
+				}
3466 3676
 
3467 3677
 				echo '
3468 3678
 			</p>
@@ -3477,16 +3687,18 @@  discard block
 block discarded – undo
3477 3687
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3478 3688
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3479 3689
 
3480
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3481
-				echo '
3690
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3691
+							echo '
3482 3692
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3693
+			}
3483 3694
 
3484
-			if (!empty($_SESSION['ban']['expire_time']))
3485
-				echo '
3695
+			if (!empty($_SESSION['ban']['expire_time'])) {
3696
+							echo '
3486 3697
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3487
-			else
3488
-				echo '
3698
+			} else {
3699
+							echo '
3489 3700
 					<div>', $txt['your_ban_expires_never'], '</div>';
3701
+			}
3490 3702
 
3491 3703
 			echo '
3492 3704
 				</div>';
@@ -3502,8 +3714,9 @@  discard block
 block discarded – undo
3502 3714
 	global $forum_copyright, $software_year, $forum_version;
3503 3715
 
3504 3716
 	// Don't display copyright for things like SSI.
3505
-	if (!isset($forum_version) || !isset($software_year))
3506
-		return;
3717
+	if (!isset($forum_version) || !isset($software_year)) {
3718
+			return;
3719
+	}
3507 3720
 
3508 3721
 	// Put in the version...
3509 3722
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3521,9 +3734,10 @@  discard block
 block discarded – undo
3521 3734
 	$context['load_time'] = round(microtime(true) - $time_start, 3);
3522 3735
 	$context['load_queries'] = $db_count;
3523 3736
 
3524
-	foreach (array_reverse($context['template_layers']) as $layer)
3525
-		loadSubTemplate($layer . '_below', true);
3526
-}
3737
+	foreach (array_reverse($context['template_layers']) as $layer) {
3738
+			loadSubTemplate($layer . '_below', true);
3739
+	}
3740
+	}
3527 3741
 
3528 3742
 /**
3529 3743
  * Output the Javascript files
@@ -3554,8 +3768,7 @@  discard block
 block discarded – undo
3554 3768
 			{
3555 3769
 				echo '
3556 3770
 		var ', $key, ';';
3557
-			}
3558
-			else
3771
+			} else
3559 3772
 			{
3560 3773
 				echo '
3561 3774
 		var ', $key, ' = ', $value, ';';
@@ -3570,26 +3783,27 @@  discard block
 block discarded – undo
3570 3783
 	foreach ($context['javascript_files'] as $id => $js_file)
3571 3784
 	{
3572 3785
 		// Last minute call! allow theme authors to disable single files.
3573
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3574
-			continue;
3786
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3787
+					continue;
3788
+		}
3575 3789
 
3576 3790
 		// By default all files don't get minimized unless the file explicitly says so!
3577 3791
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3578 3792
 		{
3579
-			if ($do_deferred && !empty($js_file['options']['defer']))
3580
-				$toMinifyDefer[] = $js_file;
3581
-
3582
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3583
-				$toMinify[] = $js_file;
3793
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3794
+							$toMinifyDefer[] = $js_file;
3795
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3796
+							$toMinify[] = $js_file;
3797
+			}
3584 3798
 
3585 3799
 			// Grab a random seed.
3586
-			if (!isset($minSeed) && isset($js_file['options']['seed']))
3587
-				$minSeed = $js_file['options']['seed'];
3588
-		}
3589
-
3590
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3591
-			echo '
3800
+			if (!isset($minSeed) && isset($js_file['options']['seed'])) {
3801
+							$minSeed = $js_file['options']['seed'];
3802
+			}
3803
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3804
+					echo '
3592 3805
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3806
+		}
3593 3807
 	}
3594 3808
 
3595 3809
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3598,9 +3812,10 @@  discard block
 block discarded – undo
3598 3812
 
3599 3813
 		$minSuccessful = array_keys($result) === array('smf_minified');
3600 3814
 
3601
-		foreach ($result as $minFile)
3602
-			echo '
3815
+		foreach ($result as $minFile) {
3816
+					echo '
3603 3817
 	<script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async="async"' : '', '></script>';
3818
+		}
3604 3819
 
3605 3820
 	}
3606 3821
 
@@ -3612,8 +3827,9 @@  discard block
 block discarded – undo
3612 3827
 			echo '
3613 3828
 <script>';
3614 3829
 
3615
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3616
-				echo $js_code;
3830
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3831
+							echo $js_code;
3832
+			}
3617 3833
 
3618 3834
 			echo '
3619 3835
 </script>';
@@ -3624,8 +3840,9 @@  discard block
 block discarded – undo
3624 3840
 			echo '
3625 3841
 	<script>';
3626 3842
 
3627
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3628
-				echo $js_code;
3843
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3844
+							echo $js_code;
3845
+			}
3629 3846
 
3630 3847
 			echo '
3631 3848
 	</script>';
@@ -3653,23 +3870,26 @@  discard block
 block discarded – undo
3653 3870
 	foreach ($context['css_files'] as $id => $file)
3654 3871
 	{
3655 3872
 		// Last minute call! allow theme authors to disable single files.
3656
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3657
-			continue;
3873
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3874
+					continue;
3875
+		}
3658 3876
 
3659 3877
 		// Files are minimized unless they explicitly opt out.
3660
-		if (!isset($file['options']['minimize']))
3661
-			$file['options']['minimize'] = true;
3878
+		if (!isset($file['options']['minimize'])) {
3879
+					$file['options']['minimize'] = true;
3880
+		}
3662 3881
 
3663 3882
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
3664 3883
 		{
3665 3884
 			$toMinify[] = $file;
3666 3885
 
3667 3886
 			// Grab a random seed.
3668
-			if (!isset($minSeed) && isset($file['options']['seed']))
3669
-				$minSeed = $file['options']['seed'];
3887
+			if (!isset($minSeed) && isset($file['options']['seed'])) {
3888
+							$minSeed = $file['options']['seed'];
3889
+			}
3890
+		} else {
3891
+					$normal[] = $file['fileUrl'];
3670 3892
 		}
3671
-		else
3672
-			$normal[] = $file['fileUrl'];
3673 3893
 	}
3674 3894
 
3675 3895
 	if (!empty($toMinify))
@@ -3678,23 +3898,26 @@  discard block
 block discarded – undo
3678 3898
 
3679 3899
 		$minSuccessful = array_keys($result) === array('smf_minified');
3680 3900
 
3681
-		foreach ($result as $minFile)
3682
-			echo '
3901
+		foreach ($result as $minFile) {
3902
+					echo '
3683 3903
 	<link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">';
3904
+		}
3684 3905
 	}
3685 3906
 
3686 3907
 	// Print the rest after the minified files.
3687
-	if (!empty($normal))
3688
-		foreach ($normal as $nf)
3908
+	if (!empty($normal)) {
3909
+			foreach ($normal as $nf)
3689 3910
 			echo '
3690 3911
 	<link rel="stylesheet" href="', $nf ,'">';
3912
+	}
3691 3913
 
3692 3914
 	if ($db_show_debug === true)
3693 3915
 	{
3694 3916
 		// Try to keep only what's useful.
3695 3917
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3696
-		foreach ($context['css_files'] as $file)
3697
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3918
+		foreach ($context['css_files'] as $file) {
3919
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3920
+		}
3698 3921
 	}
3699 3922
 
3700 3923
 	if (!empty($context['css_header']))
@@ -3702,9 +3925,10 @@  discard block
 block discarded – undo
3702 3925
 		echo '
3703 3926
 	<style>';
3704 3927
 
3705
-		foreach ($context['css_header'] as $css)
3706
-			echo $css .'
3928
+		foreach ($context['css_header'] as $css) {
3929
+					echo $css .'
3707 3930
 	';
3931
+		}
3708 3932
 
3709 3933
 		echo'
3710 3934
 	</style>';
@@ -3728,8 +3952,9 @@  discard block
 block discarded – undo
3728 3952
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3729 3953
 	$data = !empty($data) ? $data : false;
3730 3954
 
3731
-	if (empty($type) || empty($data))
3732
-		return false;
3955
+	if (empty($type) || empty($data)) {
3956
+			return false;
3957
+	}
3733 3958
 
3734 3959
 	// Different pages include different files, so we use a hash to label the different combinations
3735 3960
 	$hash = md5(implode(' ', array_keys($data)));
@@ -3738,8 +3963,9 @@  discard block
 block discarded – undo
3738 3963
 	$toCache = cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400);
3739 3964
 
3740 3965
 	// Already done?
3741
-	if (!empty($toCache))
3742
-		return true;
3966
+	if (!empty($toCache)) {
3967
+			return true;
3968
+	}
3743 3969
 
3744 3970
 	// No namespaces, sorry!
3745 3971
 	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
@@ -3771,8 +3997,9 @@  discard block
 block discarded – undo
3771 3997
 		$toAdd = file_exists($tempFile) ? $tempFile : false;
3772 3998
 
3773 3999
 		// A minified script should only be loaded asynchronously if all its components wanted to be.
3774
-		if (empty($file['options']['async']))
3775
-			$async = false;
4000
+		if (empty($file['options']['async'])) {
4001
+					$async = false;
4002
+		}
3776 4003
 
3777 4004
 		// The file couldn't be located so it won't be added. Log this error.
3778 4005
 		if (empty($toAdd))
@@ -3832,8 +4059,9 @@  discard block
 block discarded – undo
3832 4059
 	global $modSettings, $smcFunc;
3833 4060
 
3834 4061
 	// Just make up a nice hash...
3835
-	if ($new)
3836
-		return sha1(md5($filename . time()) . mt_rand());
4062
+	if ($new) {
4063
+			return sha1(md5($filename . time()) . mt_rand());
4064
+	}
3837 4065
 
3838 4066
 	// Just make sure that attachment id is only a int
3839 4067
 	$attachment_id = (int) $attachment_id;
@@ -3850,23 +4078,25 @@  discard block
 block discarded – undo
3850 4078
 				'id_attach' => $attachment_id,
3851 4079
 			));
3852 4080
 
3853
-		if ($smcFunc['db_num_rows']($request) === 0)
3854
-			return false;
4081
+		if ($smcFunc['db_num_rows']($request) === 0) {
4082
+					return false;
4083
+		}
3855 4084
 
3856 4085
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3857 4086
 		$smcFunc['db_free_result']($request);
3858 4087
 	}
3859 4088
 
3860 4089
 	// Still no hash? mmm...
3861
-	if (empty($file_hash))
3862
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
4090
+	if (empty($file_hash)) {
4091
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
4092
+	}
3863 4093
 
3864 4094
 	// Are we using multiple directories?
3865
-	if (is_array($modSettings['attachmentUploadDir']))
3866
-		$path = $modSettings['attachmentUploadDir'][$dir];
3867
-
3868
-	else
3869
-		$path = $modSettings['attachmentUploadDir'];
4095
+	if (is_array($modSettings['attachmentUploadDir'])) {
4096
+			$path = $modSettings['attachmentUploadDir'][$dir];
4097
+	} else {
4098
+			$path = $modSettings['attachmentUploadDir'];
4099
+	}
3870 4100
 
3871 4101
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3872 4102
 }
@@ -3881,8 +4111,9 @@  discard block
 block discarded – undo
3881 4111
 function ip2range($fullip)
3882 4112
 {
3883 4113
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3884
-	if ($fullip == 'unknown')
3885
-		$fullip = '255.255.255.255';
4114
+	if ($fullip == 'unknown') {
4115
+			$fullip = '255.255.255.255';
4116
+	}
3886 4117
 
3887 4118
 	$ip_parts = explode('-', $fullip);
3888 4119
 	$ip_array = array();
@@ -3906,10 +4137,11 @@  discard block
 block discarded – undo
3906 4137
 		$ip_array['low'] = $ip_parts[0];
3907 4138
 		$ip_array['high'] = $ip_parts[1];
3908 4139
 		return $ip_array;
3909
-	}
3910
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4140
+	} elseif (count($ip_parts) == 2) {
4141
+		// if ip 22.22.*-22.22.*
3911 4142
 	{
3912 4143
 		$valid_low = isValidIP($ip_parts[0]);
4144
+	}
3913 4145
 		$valid_high = isValidIP($ip_parts[1]);
3914 4146
 		$count = 0;
3915 4147
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3924,7 +4156,9 @@  discard block
 block discarded – undo
3924 4156
 				$ip_parts[0] .= $mode . $min;
3925 4157
 				$valid_low = isValidIP($ip_parts[0]);
3926 4158
 				$count++;
3927
-				if ($count > 9) break;
4159
+				if ($count > 9) {
4160
+					break;
4161
+				}
3928 4162
 			}
3929 4163
 		}
3930 4164
 
@@ -3938,7 +4172,9 @@  discard block
 block discarded – undo
3938 4172
 				$ip_parts[1] .= $mode . $max;
3939 4173
 				$valid_high = isValidIP($ip_parts[1]);
3940 4174
 				$count++;
3941
-				if ($count > 9) break;
4175
+				if ($count > 9) {
4176
+					break;
4177
+				}
3942 4178
 			}
3943 4179
 		}
3944 4180
 
@@ -3963,46 +4199,54 @@  discard block
 block discarded – undo
3963 4199
 {
3964 4200
 	global $modSettings;
3965 4201
 
3966
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3967
-		return $host;
4202
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4203
+			return $host;
4204
+	}
3968 4205
 	$t = microtime();
3969 4206
 
3970 4207
 	// Try the Linux host command, perhaps?
3971 4208
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3972 4209
 	{
3973
-		if (!isset($modSettings['host_to_dis']))
3974
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3975
-		else
3976
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4210
+		if (!isset($modSettings['host_to_dis'])) {
4211
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4212
+		} else {
4213
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4214
+		}
3977 4215
 
3978 4216
 		// Did host say it didn't find anything?
3979
-		if (strpos($test, 'not found') !== false)
3980
-			$host = '';
4217
+		if (strpos($test, 'not found') !== false) {
4218
+					$host = '';
4219
+		}
3981 4220
 		// Invalid server option?
3982
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3983
-			updateSettings(array('host_to_dis' => 1));
4221
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4222
+					updateSettings(array('host_to_dis' => 1));
4223
+		}
3984 4224
 		// Maybe it found something, after all?
3985
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3986
-			$host = $match[1];
4225
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4226
+					$host = $match[1];
4227
+		}
3987 4228
 	}
3988 4229
 
3989 4230
 	// This is nslookup; usually only Windows, but possibly some Unix?
3990 4231
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3991 4232
 	{
3992 4233
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3993
-		if (strpos($test, 'Non-existent domain') !== false)
3994
-			$host = '';
3995
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3996
-			$host = $match[1];
4234
+		if (strpos($test, 'Non-existent domain') !== false) {
4235
+					$host = '';
4236
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4237
+					$host = $match[1];
4238
+		}
3997 4239
 	}
3998 4240
 
3999 4241
 	// This is the last try :/.
4000
-	if (!isset($host) || $host === false)
4001
-		$host = @gethostbyaddr($ip);
4242
+	if (!isset($host) || $host === false) {
4243
+			$host = @gethostbyaddr($ip);
4244
+	}
4002 4245
 
4003 4246
 	// It took a long time, so let's cache it!
4004
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
4005
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4247
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4248
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4249
+	}
4006 4250
 
4007 4251
 	return $host;
4008 4252
 }
@@ -4038,20 +4282,21 @@  discard block
 block discarded – undo
4038 4282
 			{
4039 4283
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
4040 4284
 				$total = 0;
4041
-				for ($i = 0; $i < $max_chars; $i++)
4042
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4285
+				for ($i = 0; $i < $max_chars; $i++) {
4286
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4287
+				}
4043 4288
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
4044 4289
 			}
4045 4290
 		}
4046 4291
 		return array_unique($returned_ints);
4047
-	}
4048
-	else
4292
+	} else
4049 4293
 	{
4050 4294
 		// Trim characters before and after and add slashes for database insertion.
4051 4295
 		$returned_words = array();
4052
-		foreach ($words as $word)
4053
-			if (($word = trim($word, '-_\'')) !== '')
4296
+		foreach ($words as $word) {
4297
+					if (($word = trim($word, '-_\'')) !== '')
4054 4298
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4299
+		}
4055 4300
 
4056 4301
 		// Filter out all words that occur more than once.
4057 4302
 		return array_unique($returned_words);
@@ -4073,16 +4318,18 @@  discard block
 block discarded – undo
4073 4318
 	global $settings, $txt;
4074 4319
 
4075 4320
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4076
-	if (function_exists('template_create_button') && !$force_use)
4077
-		return template_create_button($name, $alt, $label = '', $custom = '');
4321
+	if (function_exists('template_create_button') && !$force_use) {
4322
+			return template_create_button($name, $alt, $label = '', $custom = '');
4323
+	}
4078 4324
 
4079
-	if (!$settings['use_image_buttons'])
4080
-		return $txt[$alt];
4081
-	elseif (!empty($settings['use_buttons']))
4082
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4083
-	else
4084
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4085
-}
4325
+	if (!$settings['use_image_buttons']) {
4326
+			return $txt[$alt];
4327
+	} elseif (!empty($settings['use_buttons'])) {
4328
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4329
+	} else {
4330
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4331
+	}
4332
+	}
4086 4333
 
4087 4334
 /**
4088 4335
  * Sets up all of the top menu buttons
@@ -4125,9 +4372,10 @@  discard block
 block discarded – undo
4125 4372
 	var user_menus = new smc_PopupMenu();
4126 4373
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4127 4374
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4128
-		if ($context['allow_pm'])
4129
-			addInlineJavaScript('
4375
+		if ($context['allow_pm']) {
4376
+					addInlineJavaScript('
4130 4377
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4378
+		}
4131 4379
 
4132 4380
 		if (!empty($modSettings['enable_ajax_alerts']))
4133 4381
 		{
@@ -4287,88 +4535,96 @@  discard block
 block discarded – undo
4287 4535
 
4288 4536
 		// Now we put the buttons in the context so the theme can use them.
4289 4537
 		$menu_buttons = array();
4290
-		foreach ($buttons as $act => $button)
4291
-			if (!empty($button['show']))
4538
+		foreach ($buttons as $act => $button) {
4539
+					if (!empty($button['show']))
4292 4540
 			{
4293 4541
 				$button['active_button'] = false;
4542
+		}
4294 4543
 
4295 4544
 				// This button needs some action.
4296
-				if (isset($button['action_hook']))
4297
-					$needs_action_hook = true;
4545
+				if (isset($button['action_hook'])) {
4546
+									$needs_action_hook = true;
4547
+				}
4298 4548
 
4299 4549
 				// Make sure the last button truly is the last button.
4300 4550
 				if (!empty($button['is_last']))
4301 4551
 				{
4302
-					if (isset($last_button))
4303
-						unset($menu_buttons[$last_button]['is_last']);
4552
+					if (isset($last_button)) {
4553
+											unset($menu_buttons[$last_button]['is_last']);
4554
+					}
4304 4555
 					$last_button = $act;
4305 4556
 				}
4306 4557
 
4307 4558
 				// Go through the sub buttons if there are any.
4308
-				if (!empty($button['sub_buttons']))
4309
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4559
+				if (!empty($button['sub_buttons'])) {
4560
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4310 4561
 					{
4311 4562
 						if (empty($subbutton['show']))
4312 4563
 							unset($button['sub_buttons'][$key]);
4564
+				}
4313 4565
 
4314 4566
 						// 2nd level sub buttons next...
4315 4567
 						if (!empty($subbutton['sub_buttons']))
4316 4568
 						{
4317 4569
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4318 4570
 							{
4319
-								if (empty($sub_button2['show']))
4320
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4571
+								if (empty($sub_button2['show'])) {
4572
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4573
+								}
4321 4574
 							}
4322 4575
 						}
4323 4576
 					}
4324 4577
 
4325 4578
 				// Does this button have its own icon?
4326
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4327
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4328
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4329
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4330
-				elseif (isset($button['icon']))
4331
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4332
-				else
4333
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4579
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4580
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4581
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4582
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4583
+				} elseif (isset($button['icon'])) {
4584
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4585
+				} else {
4586
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4587
+				}
4334 4588
 
4335 4589
 				$menu_buttons[$act] = $button;
4336 4590
 			}
4337 4591
 
4338
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4339
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4592
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4593
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4594
+		}
4340 4595
 	}
4341 4596
 
4342 4597
 	$context['menu_buttons'] = $menu_buttons;
4343 4598
 
4344 4599
 	// Logging out requires the session id in the url.
4345
-	if (isset($context['menu_buttons']['logout']))
4346
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4600
+	if (isset($context['menu_buttons']['logout'])) {
4601
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4602
+	}
4347 4603
 
4348 4604
 	// Figure out which action we are doing so we can set the active tab.
4349 4605
 	// Default to home.
4350 4606
 	$current_action = 'home';
4351 4607
 
4352
-	if (isset($context['menu_buttons'][$context['current_action']]))
4353
-		$current_action = $context['current_action'];
4354
-	elseif ($context['current_action'] == 'search2')
4355
-		$current_action = 'search';
4356
-	elseif ($context['current_action'] == 'theme')
4357
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4358
-	elseif ($context['current_action'] == 'register2')
4359
-		$current_action = 'register';
4360
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4361
-		$current_action = 'login';
4362
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4363
-		$current_action = 'moderate';
4608
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4609
+			$current_action = $context['current_action'];
4610
+	} elseif ($context['current_action'] == 'search2') {
4611
+			$current_action = 'search';
4612
+	} elseif ($context['current_action'] == 'theme') {
4613
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4614
+	} elseif ($context['current_action'] == 'register2') {
4615
+			$current_action = 'register';
4616
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4617
+			$current_action = 'login';
4618
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4619
+			$current_action = 'moderate';
4620
+	}
4364 4621
 
4365 4622
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4366 4623
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4367 4624
 	{
4368 4625
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4369 4626
 		$context[$current_action] = true;
4370
-	}
4371
-	elseif ($context['current_action'] == 'pm')
4627
+	} elseif ($context['current_action'] == 'pm')
4372 4628
 	{
4373 4629
 		$current_action = 'self_pm';
4374 4630
 		$context['self_pm'] = true;
@@ -4425,12 +4681,14 @@  discard block
 block discarded – undo
4425 4681
 	}
4426 4682
 
4427 4683
 	// Not all actions are simple.
4428
-	if (!empty($needs_action_hook))
4429
-		call_integration_hook('integrate_current_action', array(&$current_action));
4684
+	if (!empty($needs_action_hook)) {
4685
+			call_integration_hook('integrate_current_action', array(&$current_action));
4686
+	}
4430 4687
 
4431
-	if (isset($context['menu_buttons'][$current_action]))
4432
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4433
-}
4688
+	if (isset($context['menu_buttons'][$current_action])) {
4689
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4690
+	}
4691
+	}
4434 4692
 
4435 4693
 /**
4436 4694
  * Generate a random seed and ensure it's stored in settings.
@@ -4454,30 +4712,35 @@  discard block
 block discarded – undo
4454 4712
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4455 4713
 	global $context, $txt;
4456 4714
 
4457
-	if ($db_show_debug === true)
4458
-		$context['debug']['hooks'][] = $hook;
4715
+	if ($db_show_debug === true) {
4716
+			$context['debug']['hooks'][] = $hook;
4717
+	}
4459 4718
 
4460 4719
 	// Need to have some control.
4461
-	if (!isset($context['instances']))
4462
-		$context['instances'] = array();
4720
+	if (!isset($context['instances'])) {
4721
+			$context['instances'] = array();
4722
+	}
4463 4723
 
4464 4724
 	$results = array();
4465
-	if (empty($modSettings[$hook]))
4466
-		return $results;
4725
+	if (empty($modSettings[$hook])) {
4726
+			return $results;
4727
+	}
4467 4728
 
4468 4729
 	$functions = explode(',', $modSettings[$hook]);
4469 4730
 	// Loop through each function.
4470 4731
 	foreach ($functions as $function)
4471 4732
 	{
4472 4733
 		// Hook has been marked as "disabled". Skip it!
4473
-		if (strpos($function, '!') !== false)
4474
-			continue;
4734
+		if (strpos($function, '!') !== false) {
4735
+					continue;
4736
+		}
4475 4737
 
4476 4738
 		$call = call_helper($function, true);
4477 4739
 
4478 4740
 		// Is it valid?
4479
-		if (!empty($call))
4480
-			$results[$function] = call_user_func_array($call, $parameters);
4741
+		if (!empty($call)) {
4742
+					$results[$function] = call_user_func_array($call, $parameters);
4743
+		}
4481 4744
 
4482 4745
 		// Whatever it was suppose to call, it failed :(
4483 4746
 		elseif (!empty($function))
@@ -4493,8 +4756,9 @@  discard block
 block discarded – undo
4493 4756
 			}
4494 4757
 
4495 4758
 			// "Assume" the file resides on $boarddir somewhere...
4496
-			else
4497
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4759
+			else {
4760
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4761
+			}
4498 4762
 		}
4499 4763
 	}
4500 4764
 
@@ -4516,12 +4780,14 @@  discard block
 block discarded – undo
4516 4780
 	global $smcFunc, $modSettings;
4517 4781
 
4518 4782
 	// Any objects?
4519
-	if ($object)
4520
-		$function = $function . '#';
4783
+	if ($object) {
4784
+			$function = $function . '#';
4785
+	}
4521 4786
 
4522 4787
 	// Any files  to load?
4523
-	if (!empty($file) && is_string($file))
4524
-		$function = $file . (!empty($function) ? '|' . $function : '');
4788
+	if (!empty($file) && is_string($file)) {
4789
+			$function = $file . (!empty($function) ? '|' . $function : '');
4790
+	}
4525 4791
 
4526 4792
 	// Get the correct string.
4527 4793
 	$integration_call = $function;
@@ -4543,13 +4809,14 @@  discard block
 block discarded – undo
4543 4809
 		if (!empty($current_functions))
4544 4810
 		{
4545 4811
 			$current_functions = explode(',', $current_functions);
4546
-			if (in_array($integration_call, $current_functions))
4547
-				return;
4812
+			if (in_array($integration_call, $current_functions)) {
4813
+							return;
4814
+			}
4548 4815
 
4549 4816
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4817
+		} else {
4818
+					$permanent_functions = array($integration_call);
4550 4819
 		}
4551
-		else
4552
-			$permanent_functions = array($integration_call);
4553 4820
 
4554 4821
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4555 4822
 	}
@@ -4558,8 +4825,9 @@  discard block
 block discarded – undo
4558 4825
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4559 4826
 
4560 4827
 	// Do nothing, if it's already there.
4561
-	if (in_array($integration_call, $functions))
4562
-		return;
4828
+	if (in_array($integration_call, $functions)) {
4829
+			return;
4830
+	}
4563 4831
 
4564 4832
 	$functions[] = $integration_call;
4565 4833
 	$modSettings[$hook] = implode(',', $functions);
@@ -4582,12 +4850,14 @@  discard block
 block discarded – undo
4582 4850
 	global $smcFunc, $modSettings;
4583 4851
 
4584 4852
 	// Any objects?
4585
-	if ($object)
4586
-		$function = $function . '#';
4853
+	if ($object) {
4854
+			$function = $function . '#';
4855
+	}
4587 4856
 
4588 4857
 	// Any files  to load?
4589
-	if (!empty($file) && is_string($file))
4590
-		$function = $file . '|' . $function;
4858
+	if (!empty($file) && is_string($file)) {
4859
+			$function = $file . '|' . $function;
4860
+	}
4591 4861
 
4592 4862
 	// Get the correct string.
4593 4863
 	$integration_call = $function;
@@ -4608,16 +4878,18 @@  discard block
 block discarded – undo
4608 4878
 	{
4609 4879
 		$current_functions = explode(',', $current_functions);
4610 4880
 
4611
-		if (in_array($integration_call, $current_functions))
4612
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4881
+		if (in_array($integration_call, $current_functions)) {
4882
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4883
+		}
4613 4884
 	}
4614 4885
 
4615 4886
 	// Turn the function list into something usable.
4616 4887
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4617 4888
 
4618 4889
 	// You can only remove it if it's available.
4619
-	if (!in_array($integration_call, $functions))
4620
-		return;
4890
+	if (!in_array($integration_call, $functions)) {
4891
+			return;
4892
+	}
4621 4893
 
4622 4894
 	$functions = array_diff($functions, array($integration_call));
4623 4895
 	$modSettings[$hook] = implode(',', $functions);
@@ -4638,17 +4910,20 @@  discard block
 block discarded – undo
4638 4910
 	global $context, $smcFunc, $txt, $db_show_debug;
4639 4911
 
4640 4912
 	// Really?
4641
-	if (empty($string))
4642
-		return false;
4913
+	if (empty($string)) {
4914
+			return false;
4915
+	}
4643 4916
 
4644 4917
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4645 4918
 	// A closure? should be a callable one.
4646
-	if (is_array($string) || $string instanceof Closure)
4647
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4919
+	if (is_array($string) || $string instanceof Closure) {
4920
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4921
+	}
4648 4922
 
4649 4923
 	// No full objects, sorry! pass a method or a property instead!
4650
-	if (is_object($string))
4651
-		return false;
4924
+	if (is_object($string)) {
4925
+			return false;
4926
+	}
4652 4927
 
4653 4928
 	// Stay vitaminized my friends...
4654 4929
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4657,8 +4932,9 @@  discard block
 block discarded – undo
4657 4932
 	$string = load_file($string);
4658 4933
 
4659 4934
 	// Loaded file failed
4660
-	if (empty($string))
4661
-		return false;
4935
+	if (empty($string)) {
4936
+			return false;
4937
+	}
4662 4938
 
4663 4939
 	// Found a method.
4664 4940
 	if (strpos($string, '::') !== false)
@@ -4679,8 +4955,9 @@  discard block
 block discarded – undo
4679 4955
 				// Add another one to the list.
4680 4956
 				if ($db_show_debug === true)
4681 4957
 				{
4682
-					if (!isset($context['debug']['instances']))
4683
-						$context['debug']['instances'] = array();
4958
+					if (!isset($context['debug']['instances'])) {
4959
+											$context['debug']['instances'] = array();
4960
+					}
4684 4961
 
4685 4962
 					$context['debug']['instances'][$class] = $class;
4686 4963
 				}
@@ -4690,13 +4967,15 @@  discard block
 block discarded – undo
4690 4967
 		}
4691 4968
 
4692 4969
 		// Right then. This is a call to a static method.
4693
-		else
4694
-			$func = array($class, $method);
4970
+		else {
4971
+					$func = array($class, $method);
4972
+		}
4695 4973
 	}
4696 4974
 
4697 4975
 	// Nope! just a plain regular function.
4698
-	else
4699
-		$func = $string;
4976
+	else {
4977
+			$func = $string;
4978
+	}
4700 4979
 
4701 4980
 	// Right, we got what we need, time to do some checks.
4702 4981
 	if (!is_callable($func, false, $callable_name))
@@ -4712,17 +4991,18 @@  discard block
 block discarded – undo
4712 4991
 	else
4713 4992
 	{
4714 4993
 		// What are we gonna do about it?
4715
-		if ($return)
4716
-			return $func;
4994
+		if ($return) {
4995
+					return $func;
4996
+		}
4717 4997
 
4718 4998
 		// If this is a plain function, avoid the heat of calling call_user_func().
4719 4999
 		else
4720 5000
 		{
4721
-			if (is_array($func))
4722
-				call_user_func($func);
4723
-
4724
-			else
4725
-				$func();
5001
+			if (is_array($func)) {
5002
+							call_user_func($func);
5003
+			} else {
5004
+							$func();
5005
+			}
4726 5006
 		}
4727 5007
 	}
4728 5008
 }
@@ -4739,31 +5019,34 @@  discard block
 block discarded – undo
4739 5019
 {
4740 5020
 	global $sourcedir, $txt, $boarddir, $settings;
4741 5021
 
4742
-	if (empty($string))
4743
-		return false;
5022
+	if (empty($string)) {
5023
+			return false;
5024
+	}
4744 5025
 
4745 5026
 	if (strpos($string, '|') !== false)
4746 5027
 	{
4747 5028
 		list ($file, $string) = explode('|', $string);
4748 5029
 
4749 5030
 		// Match the wildcards to their regular vars.
4750
-		if (empty($settings['theme_dir']))
4751
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4752
-
4753
-		else
4754
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5031
+		if (empty($settings['theme_dir'])) {
5032
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5033
+		} else {
5034
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5035
+		}
4755 5036
 
4756 5037
 		// Load the file if it can be loaded.
4757
-		if (file_exists($absPath))
4758
-			require_once($absPath);
5038
+		if (file_exists($absPath)) {
5039
+					require_once($absPath);
5040
+		}
4759 5041
 
4760 5042
 		// No? try a fallback to $sourcedir
4761 5043
 		else
4762 5044
 		{
4763 5045
 			$absPath = $sourcedir .'/'. $file;
4764 5046
 
4765
-			if (file_exists($absPath))
4766
-				require_once($absPath);
5047
+			if (file_exists($absPath)) {
5048
+							require_once($absPath);
5049
+			}
4767 5050
 
4768 5051
 			// Sorry, can't do much for you at this point.
4769 5052
 			else
@@ -4802,8 +5085,9 @@  discard block
 block discarded – undo
4802 5085
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
4803 5086
 
4804 5087
 	// No scheme? No data for you!
4805
-	if (empty($match[1]))
4806
-		return false;
5088
+	if (empty($match[1])) {
5089
+			return false;
5090
+	}
4807 5091
 
4808 5092
 	// An FTP url. We should try connecting and RETRieving it...
4809 5093
 	elseif ($match[1] == 'ftp')
@@ -4813,23 +5097,26 @@  discard block
 block discarded – undo
4813 5097
 
4814 5098
 		// Establish a connection and attempt to enable passive mode.
4815 5099
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
4816
-		if ($ftp->error !== false || !$ftp->passive())
4817
-			return false;
5100
+		if ($ftp->error !== false || !$ftp->passive()) {
5101
+					return false;
5102
+		}
4818 5103
 
4819 5104
 		// I want that one *points*!
4820 5105
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
4821 5106
 
4822 5107
 		// Since passive mode worked (or we would have returned already!) open the connection.
4823 5108
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
4824
-		if (!$fp)
4825
-			return false;
5109
+		if (!$fp) {
5110
+					return false;
5111
+		}
4826 5112
 
4827 5113
 		// The server should now say something in acknowledgement.
4828 5114
 		$ftp->check_response(150);
4829 5115
 
4830 5116
 		$data = '';
4831
-		while (!feof($fp))
4832
-			$data .= fread($fp, 4096);
5117
+		while (!feof($fp)) {
5118
+					$data .= fread($fp, 4096);
5119
+		}
4833 5120
 		fclose($fp);
4834 5121
 
4835 5122
 		// All done, right?  Good.
@@ -4841,8 +5128,9 @@  discard block
 block discarded – undo
4841 5128
 	elseif (isset($match[1]) && $match[1] == 'http')
4842 5129
 	{
4843 5130
 		// First try to use fsockopen, because it is fastest.
4844
-		if ($keep_alive && $match[3] == $keep_alive_dom)
4845
-			$fp = $keep_alive_fp;
5131
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
5132
+					$fp = $keep_alive_fp;
5133
+		}
4846 5134
 		if (empty($fp))
4847 5135
 		{
4848 5136
 			// Open the socket on the port we want...
@@ -4862,20 +5150,21 @@  discard block
 block discarded – undo
4862 5150
 				fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
4863 5151
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
4864 5152
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
4865
-				if ($keep_alive)
4866
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
4867
-				else
4868
-					fwrite($fp, 'connection: close' . "\r\n\r\n");
4869
-			}
4870
-			else
5153
+				if ($keep_alive) {
5154
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5155
+				} else {
5156
+									fwrite($fp, 'connection: close' . "\r\n\r\n");
5157
+				}
5158
+			} else
4871 5159
 			{
4872 5160
 				fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
4873 5161
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
4874 5162
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
4875
-				if ($keep_alive)
4876
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n");
4877
-				else
4878
-					fwrite($fp, 'connection: close' . "\r\n");
5163
+				if ($keep_alive) {
5164
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5165
+				} else {
5166
+									fwrite($fp, 'connection: close' . "\r\n");
5167
+				}
4879 5168
 				fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n");
4880 5169
 				fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n");
4881 5170
 				fwrite($fp, $post_data);
@@ -4888,30 +5177,33 @@  discard block
 block discarded – undo
4888 5177
 			{
4889 5178
 				$header = '';
4890 5179
 				$location = '';
4891
-				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
4892
-					if (strpos($header, 'location:') !== false)
5180
+				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
5181
+									if (strpos($header, 'location:') !== false)
4893 5182
 						$location = trim(substr($header, strpos($header, ':') + 1));
5183
+				}
4894 5184
 
4895
-				if (empty($location))
4896
-					return false;
4897
-				else
5185
+				if (empty($location)) {
5186
+									return false;
5187
+				} else
4898 5188
 				{
4899
-					if (!$keep_alive)
4900
-						fclose($fp);
5189
+					if (!$keep_alive) {
5190
+											fclose($fp);
5191
+					}
4901 5192
 					return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
4902 5193
 				}
4903 5194
 			}
4904 5195
 
4905 5196
 			// Make sure we get a 200 OK.
4906
-			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
4907
-				return false;
5197
+			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
5198
+							return false;
5199
+			}
4908 5200
 
4909 5201
 			// Skip the headers...
4910 5202
 			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
4911 5203
 			{
4912
-				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
4913
-					$content_length = $match[1];
4914
-				elseif (preg_match('~connection:\s*close~i', $header) != 0)
5204
+				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
5205
+									$content_length = $match[1];
5206
+				} elseif (preg_match('~connection:\s*close~i', $header) != 0)
4915 5207
 				{
4916 5208
 					$keep_alive_dom = null;
4917 5209
 					$keep_alive = false;
@@ -4923,17 +5215,19 @@  discard block
 block discarded – undo
4923 5215
 			$data = '';
4924 5216
 			if (isset($content_length))
4925 5217
 			{
4926
-				while (!feof($fp) && strlen($data) < $content_length)
4927
-					$data .= fread($fp, $content_length - strlen($data));
4928
-			}
4929
-			else
5218
+				while (!feof($fp) && strlen($data) < $content_length) {
5219
+									$data .= fread($fp, $content_length - strlen($data));
5220
+				}
5221
+			} else
4930 5222
 			{
4931
-				while (!feof($fp))
4932
-					$data .= fread($fp, 4096);
5223
+				while (!feof($fp)) {
5224
+									$data .= fread($fp, 4096);
5225
+				}
4933 5226
 			}
4934 5227
 
4935
-			if (!$keep_alive)
4936
-				fclose($fp);
5228
+			if (!$keep_alive) {
5229
+							fclose($fp);
5230
+			}
4937 5231
 		}
4938 5232
 
4939 5233
 		// If using fsockopen didn't work, try to use cURL if available.
@@ -4946,17 +5240,18 @@  discard block
 block discarded – undo
4946 5240
 			$fetch_data->get_url_data($url, $post_data);
4947 5241
 
4948 5242
 			// no errors and a 200 result, then we have a good dataset, well we at least have data. ;)
4949
-			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
4950
-				$data = $fetch_data->result('body');
4951
-			else
4952
-				return false;
5243
+			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
5244
+							$data = $fetch_data->result('body');
5245
+			} else {
5246
+							return false;
5247
+			}
4953 5248
 		}
4954 5249
 
4955 5250
 		// Neither fsockopen nor curl are available. Well, phooey.
4956
-		else
4957
-			return false;
4958
-	}
4959
-	else
5251
+		else {
5252
+					return false;
5253
+		}
5254
+	} else
4960 5255
 	{
4961 5256
 		// Umm, this shouldn't happen?
4962 5257
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
@@ -4976,8 +5271,9 @@  discard block
 block discarded – undo
4976 5271
 	global $user_info, $smcFunc;
4977 5272
 
4978 5273
 	// Make sure we have something to work with.
4979
-	if (empty($topic))
4980
-		return array();
5274
+	if (empty($topic)) {
5275
+			return array();
5276
+	}
4981 5277
 
4982 5278
 
4983 5279
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -5000,8 +5296,9 @@  discard block
 block discarded – undo
5000 5296
 				'topic' => $topic,
5001 5297
 			)
5002 5298
 		);
5003
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5004
-			$temp[] = (int) $row['content_id'];
5299
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5300
+					$temp[] = (int) $row['content_id'];
5301
+		}
5005 5302
 
5006 5303
 		cache_put_data($cache_key, $temp, $ttl);
5007 5304
 	}
@@ -5022,8 +5319,9 @@  discard block
 block discarded – undo
5022 5319
 {
5023 5320
 	global $context;
5024 5321
 
5025
-	if (empty($string))
5026
-		return $string;
5322
+	if (empty($string)) {
5323
+			return $string;
5324
+	}
5027 5325
 
5028 5326
 	// UTF-8 occurences of MS special characters
5029 5327
 	$findchars_utf8 = array(
@@ -5064,10 +5362,11 @@  discard block
 block discarded – undo
5064 5362
 		'--',	// &mdash;
5065 5363
 	);
5066 5364
 
5067
-	if ($context['utf8'])
5068
-		$string = str_replace($findchars_utf8, $replacechars, $string);
5069
-	else
5070
-		$string = str_replace($findchars_iso, $replacechars, $string);
5365
+	if ($context['utf8']) {
5366
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5367
+	} else {
5368
+			$string = str_replace($findchars_iso, $replacechars, $string);
5369
+	}
5071 5370
 
5072 5371
 	return $string;
5073 5372
 }
@@ -5086,49 +5385,59 @@  discard block
 block discarded – undo
5086 5385
 {
5087 5386
 	global $context;
5088 5387
 
5089
-	if (!isset($matches[2]))
5090
-		return '';
5388
+	if (!isset($matches[2])) {
5389
+			return '';
5390
+	}
5091 5391
 
5092 5392
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5093 5393
 
5094 5394
 	// remove left to right / right to left overrides
5095
-	if ($num === 0x202D || $num === 0x202E)
5096
-		return '';
5395
+	if ($num === 0x202D || $num === 0x202E) {
5396
+			return '';
5397
+	}
5097 5398
 
5098 5399
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
5099
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
5100
-		return '&#' . $num . ';';
5400
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5401
+			return '&#' . $num . ';';
5402
+	}
5101 5403
 
5102 5404
 	if (empty($context['utf8']))
5103 5405
 	{
5104 5406
 		// no control characters
5105
-		if ($num < 0x20)
5106
-			return '';
5407
+		if ($num < 0x20) {
5408
+					return '';
5409
+		}
5107 5410
 		// text is text
5108
-		elseif ($num < 0x80)
5109
-			return chr($num);
5411
+		elseif ($num < 0x80) {
5412
+					return chr($num);
5413
+		}
5110 5414
 		// all others get html-ised
5111
-		else
5112
-			return '&#' . $matches[2] . ';';
5113
-	}
5114
-	else
5415
+		else {
5416
+					return '&#' . $matches[2] . ';';
5417
+		}
5418
+	} else
5115 5419
 	{
5116 5420
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
5117 5421
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
5118
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
5119
-			return '';
5422
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5423
+					return '';
5424
+		}
5120 5425
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5121
-		elseif ($num < 0x80)
5122
-			return chr($num);
5426
+		elseif ($num < 0x80) {
5427
+					return chr($num);
5428
+		}
5123 5429
 		// <0x800 (2048)
5124
-		elseif ($num < 0x800)
5125
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5430
+		elseif ($num < 0x800) {
5431
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5432
+		}
5126 5433
 		// < 0x10000 (65536)
5127
-		elseif ($num < 0x10000)
5128
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5434
+		elseif ($num < 0x10000) {
5435
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5436
+		}
5129 5437
 		// <= 0x10FFFF (1114111)
5130
-		else
5131
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5438
+		else {
5439
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5440
+		}
5132 5441
 	}
5133 5442
 }
5134 5443
 
@@ -5144,28 +5453,34 @@  discard block
 block discarded – undo
5144 5453
  */
5145 5454
 function fixchar__callback($matches)
5146 5455
 {
5147
-	if (!isset($matches[1]))
5148
-		return '';
5456
+	if (!isset($matches[1])) {
5457
+			return '';
5458
+	}
5149 5459
 
5150 5460
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
5151 5461
 
5152 5462
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
5153 5463
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
5154
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
5155
-		return '';
5464
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5465
+			return '';
5466
+	}
5156 5467
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5157
-	elseif ($num < 0x80)
5158
-		return chr($num);
5468
+	elseif ($num < 0x80) {
5469
+			return chr($num);
5470
+	}
5159 5471
 	// <0x800 (2048)
5160
-	elseif ($num < 0x800)
5161
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5472
+	elseif ($num < 0x800) {
5473
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5474
+	}
5162 5475
 	// < 0x10000 (65536)
5163
-	elseif ($num < 0x10000)
5164
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5476
+	elseif ($num < 0x10000) {
5477
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5478
+	}
5165 5479
 	// <= 0x10FFFF (1114111)
5166
-	else
5167
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5168
-}
5480
+	else {
5481
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5482
+	}
5483
+	}
5169 5484
 
5170 5485
 /**
5171 5486
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -5178,17 +5493,19 @@  discard block
 block discarded – undo
5178 5493
  */
5179 5494
 function entity_fix__callback($matches)
5180 5495
 {
5181
-	if (!isset($matches[2]))
5182
-		return '';
5496
+	if (!isset($matches[2])) {
5497
+			return '';
5498
+	}
5183 5499
 
5184 5500
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5185 5501
 
5186 5502
 	// we don't allow control characters, characters out of range, byte markers, etc
5187
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
5188
-		return '';
5189
-	else
5190
-		return '&#' . $num . ';';
5191
-}
5503
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5504
+			return '';
5505
+	} else {
5506
+			return '&#' . $num . ';';
5507
+	}
5508
+	}
5192 5509
 
5193 5510
 /**
5194 5511
  * Return a Gravatar URL based on
@@ -5212,18 +5529,23 @@  discard block
 block discarded – undo
5212 5529
 		$ratings = array('G', 'PG', 'R', 'X');
5213 5530
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
5214 5531
 		$url_params = array();
5215
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
5216
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5217
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
5218
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5219
-		if (!empty($modSettings['avatar_max_width_external']))
5220
-			$size_string = (int) $modSettings['avatar_max_width_external'];
5221
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
5222
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5532
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5533
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5534
+		}
5535
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5536
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5537
+		}
5538
+		if (!empty($modSettings['avatar_max_width_external'])) {
5539
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5540
+		}
5541
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5542
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5223 5543
 				$size_string = $modSettings['avatar_max_height_external'];
5544
+		}
5224 5545
 
5225
-		if (!empty($size_string))
5226
-			$url_params[] = 's=' . $size_string;
5546
+		if (!empty($size_string)) {
5547
+					$url_params[] = 's=' . $size_string;
5548
+		}
5227 5549
 	}
5228 5550
 	$http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www';
5229 5551
 
@@ -5242,22 +5564,26 @@  discard block
 block discarded – undo
5242 5564
 	static $timezones = null, $lastwhen = null;
5243 5565
 
5244 5566
 	// No point doing this over if we already did it once
5245
-	if (!empty($timezones) && $when == $lastwhen)
5246
-		return $timezones;
5247
-	else
5248
-		$lastwhen = $when;
5567
+	if (!empty($timezones) && $when == $lastwhen) {
5568
+			return $timezones;
5569
+	} else {
5570
+			$lastwhen = $when;
5571
+	}
5249 5572
 
5250 5573
 	// Parseable datetime string?
5251
-	if (is_int($timestamp = strtotime($when)))
5252
-		$when = $timestamp;
5574
+	if (is_int($timestamp = strtotime($when))) {
5575
+			$when = $timestamp;
5576
+	}
5253 5577
 
5254 5578
 	// A Unix timestamp?
5255
-	elseif (is_numeric($when))
5256
-		$when = intval($when);
5579
+	elseif (is_numeric($when)) {
5580
+			$when = intval($when);
5581
+	}
5257 5582
 
5258 5583
 	// Invalid value? Just get current Unix timestamp.
5259
-	else
5260
-		$when = time();
5584
+	else {
5585
+			$when = time();
5586
+	}
5261 5587
 
5262 5588
 	// We'll need these too
5263 5589
 	$date_when = date_create('@' . $when);
@@ -5321,8 +5647,9 @@  discard block
 block discarded – undo
5321 5647
 	foreach ($priority_countries as $country)
5322 5648
 	{
5323 5649
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5324
-		if (!empty($country_tzids))
5325
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5650
+		if (!empty($country_tzids)) {
5651
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5652
+		}
5326 5653
 	}
5327 5654
 
5328 5655
 	// Process the preferred timezones first, then the rest.
@@ -5332,8 +5659,9 @@  discard block
 block discarded – undo
5332 5659
 	foreach ($tzids as $tzid)
5333 5660
 	{
5334 5661
 		// We don't want UTC right now
5335
-		if ($tzid == 'UTC')
5336
-			continue;
5662
+		if ($tzid == 'UTC') {
5663
+					continue;
5664
+		}
5337 5665
 
5338 5666
 		$tz = timezone_open($tzid);
5339 5667
 
@@ -5354,8 +5682,9 @@  discard block
 block discarded – undo
5354 5682
 		}
5355 5683
 
5356 5684
 		// A time zone from a prioritized country?
5357
-		if (in_array($tzid, $priority_tzids))
5358
-			$priority_zones[$tzkey] = true;
5685
+		if (in_array($tzid, $priority_tzids)) {
5686
+					$priority_zones[$tzkey] = true;
5687
+		}
5359 5688
 
5360 5689
 		// Keep track of the location and offset for this tzid
5361 5690
 		$tzid_parts = explode('/', $tzid);
@@ -5374,15 +5703,17 @@  discard block
 block discarded – undo
5374 5703
 	{
5375 5704
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5376 5705
 
5377
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5378
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5379
-		else
5380
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5706
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5707
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5708
+		} else {
5709
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5710
+		}
5381 5711
 
5382
-		if (isset($priority_zones[$tzkey]))
5383
-			$priority_timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5384
-		else
5385
-			$timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5712
+		if (isset($priority_zones[$tzkey])) {
5713
+					$priority_timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5714
+		} else {
5715
+					$timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5716
+		}
5386 5717
 	}
5387 5718
 
5388 5719
 	$timezones = array_merge(
@@ -5436,9 +5767,9 @@  discard block
 block discarded – undo
5436 5767
 			'Indian/Kerguelen' => 'TFT',
5437 5768
 		);
5438 5769
 
5439
-		if (!empty($missing_tz_abbrs[$tzid]))
5440
-			$tz_abbrev = $missing_tz_abbrs[$tzid];
5441
-		else
5770
+		if (!empty($missing_tz_abbrs[$tzid])) {
5771
+					$tz_abbrev = $missing_tz_abbrs[$tzid];
5772
+		} else
5442 5773
 		{
5443 5774
 			// Russia likes to experiment with time zones often, and names them as offsets from Moscow
5444 5775
 			$tz_location = timezone_location_get(timezone_open($tzid));
@@ -5466,8 +5797,9 @@  discard block
 block discarded – undo
5466 5797
  */
5467 5798
 function inet_ptod($ip_address)
5468 5799
 {
5469
-	if (!isValidIP($ip_address))
5470
-		return $ip_address;
5800
+	if (!isValidIP($ip_address)) {
5801
+			return $ip_address;
5802
+	}
5471 5803
 
5472 5804
 	$bin = inet_pton($ip_address);
5473 5805
 	return $bin;
@@ -5479,13 +5811,15 @@  discard block
 block discarded – undo
5479 5811
  */
5480 5812
 function inet_dtop($bin)
5481 5813
 {
5482
-	if(empty($bin))
5483
-		return '';
5814
+	if(empty($bin)) {
5815
+			return '';
5816
+	}
5484 5817
 
5485 5818
 	global $db_type;
5486 5819
 
5487
-	if ($db_type == 'postgresql')
5488
-		return $bin;
5820
+	if ($db_type == 'postgresql') {
5821
+			return $bin;
5822
+	}
5489 5823
 
5490 5824
 	$ip_address = inet_ntop($bin);
5491 5825
 
@@ -5510,26 +5844,32 @@  discard block
 block discarded – undo
5510 5844
  */
5511 5845
 function _safe_serialize($value)
5512 5846
 {
5513
-	if(is_null($value))
5514
-		return 'N;';
5847
+	if(is_null($value)) {
5848
+			return 'N;';
5849
+	}
5515 5850
 
5516
-	if(is_bool($value))
5517
-		return 'b:'. (int) $value .';';
5851
+	if(is_bool($value)) {
5852
+			return 'b:'. (int) $value .';';
5853
+	}
5518 5854
 
5519
-	if(is_int($value))
5520
-		return 'i:'. $value .';';
5855
+	if(is_int($value)) {
5856
+			return 'i:'. $value .';';
5857
+	}
5521 5858
 
5522
-	if(is_float($value))
5523
-		return 'd:'. str_replace(',', '.', $value) .';';
5859
+	if(is_float($value)) {
5860
+			return 'd:'. str_replace(',', '.', $value) .';';
5861
+	}
5524 5862
 
5525
-	if(is_string($value))
5526
-		return 's:'. strlen($value) .':"'. $value .'";';
5863
+	if(is_string($value)) {
5864
+			return 's:'. strlen($value) .':"'. $value .'";';
5865
+	}
5527 5866
 
5528 5867
 	if(is_array($value))
5529 5868
 	{
5530 5869
 		$out = '';
5531
-		foreach($value as $k => $v)
5532
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5870
+		foreach($value as $k => $v) {
5871
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5872
+		}
5533 5873
 
5534 5874
 		return 'a:'. count($value) .':{'. $out .'}';
5535 5875
 	}
@@ -5555,8 +5895,9 @@  discard block
 block discarded – undo
5555 5895
 
5556 5896
 	$out = _safe_serialize($value);
5557 5897
 
5558
-	if (isset($mbIntEnc))
5559
-		mb_internal_encoding($mbIntEnc);
5898
+	if (isset($mbIntEnc)) {
5899
+			mb_internal_encoding($mbIntEnc);
5900
+	}
5560 5901
 
5561 5902
 	return $out;
5562 5903
 }
@@ -5573,8 +5914,9 @@  discard block
 block discarded – undo
5573 5914
 function _safe_unserialize($str)
5574 5915
 {
5575 5916
 	// Input  is not a string.
5576
-	if(empty($str) || !is_string($str))
5577
-		return false;
5917
+	if(empty($str) || !is_string($str)) {
5918
+			return false;
5919
+	}
5578 5920
 
5579 5921
 	$stack = array();
5580 5922
 	$expected = array();
@@ -5590,43 +5932,38 @@  discard block
 block discarded – undo
5590 5932
 	while($state != 1)
5591 5933
 	{
5592 5934
 		$type = isset($str[0]) ? $str[0] : '';
5593
-		if($type == '}')
5594
-			$str = substr($str, 1);
5595
-
5596
-		else if($type == 'N' && $str[1] == ';')
5935
+		if($type == '}') {
5936
+					$str = substr($str, 1);
5937
+		} else if($type == 'N' && $str[1] == ';')
5597 5938
 		{
5598 5939
 			$value = null;
5599 5940
 			$str = substr($str, 2);
5600
-		}
5601
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5941
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5602 5942
 		{
5603 5943
 			$value = $matches[1] == '1' ? true : false;
5604 5944
 			$str = substr($str, 4);
5605
-		}
5606
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5945
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5607 5946
 		{
5608 5947
 			$value = (int)$matches[1];
5609 5948
 			$str = $matches[2];
5610
-		}
5611
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5949
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5612 5950
 		{
5613 5951
 			$value = (float)$matches[1];
5614 5952
 			$str = $matches[3];
5615
-		}
5616
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5953
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5617 5954
 		{
5618 5955
 			$value = substr($matches[2], 0, (int)$matches[1]);
5619 5956
 			$str = substr($matches[2], (int)$matches[1] + 2);
5620
-		}
5621
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5957
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5622 5958
 		{
5623 5959
 			$expectedLength = (int)$matches[1];
5624 5960
 			$str = $matches[2];
5625 5961
 		}
5626 5962
 
5627 5963
 		// Object or unknown/malformed type.
5628
-		else
5629
-			return false;
5964
+		else {
5965
+					return false;
5966
+		}
5630 5967
 
5631 5968
 		switch($state)
5632 5969
 		{
@@ -5654,8 +5991,9 @@  discard block
 block discarded – undo
5654 5991
 				if($type == '}')
5655 5992
 				{
5656 5993
 					// Array size is less than expected.
5657
-					if(count($list) < end($expected))
5658
-						return false;
5994
+					if(count($list) < end($expected)) {
5995
+											return false;
5996
+					}
5659 5997
 
5660 5998
 					unset($list);
5661 5999
 					$list = &$stack[count($stack)-1];
@@ -5664,8 +6002,9 @@  discard block
 block discarded – undo
5664 6002
 					// Go to terminal state if we're at the end of the root array.
5665 6003
 					array_pop($expected);
5666 6004
 
5667
-					if(count($expected) == 0)
5668
-						$state = 1;
6005
+					if(count($expected) == 0) {
6006
+											$state = 1;
6007
+					}
5669 6008
 
5670 6009
 					break;
5671 6010
 				}
@@ -5673,8 +6012,9 @@  discard block
 block discarded – undo
5673 6012
 				if($type == 'i' || $type == 's')
5674 6013
 				{
5675 6014
 					// Array size exceeds expected length.
5676
-					if(count($list) >= end($expected))
5677
-						return false;
6015
+					if(count($list) >= end($expected)) {
6016
+											return false;
6017
+					}
5678 6018
 
5679 6019
 					$key = $value;
5680 6020
 					$state = 3;
@@ -5708,8 +6048,9 @@  discard block
 block discarded – undo
5708 6048
 	}
5709 6049
 
5710 6050
 	// Trailing data in input.
5711
-	if(!empty($str))
5712
-		return false;
6051
+	if(!empty($str)) {
6052
+			return false;
6053
+	}
5713 6054
 
5714 6055
 	return $data;
5715 6056
 }
@@ -5732,8 +6073,9 @@  discard block
 block discarded – undo
5732 6073
 
5733 6074
 	$out = _safe_unserialize($str);
5734 6075
 
5735
-	if (isset($mbIntEnc))
5736
-		mb_internal_encoding($mbIntEnc);
6076
+	if (isset($mbIntEnc)) {
6077
+			mb_internal_encoding($mbIntEnc);
6078
+	}
5737 6079
 
5738 6080
 	return $out;
5739 6081
 }
@@ -5748,12 +6090,14 @@  discard block
 block discarded – undo
5748 6090
 function smf_chmod($file, $value = 0)
5749 6091
 {
5750 6092
 	// No file? no checks!
5751
-	if (empty($file))
5752
-		return false;
6093
+	if (empty($file)) {
6094
+			return false;
6095
+	}
5753 6096
 
5754 6097
 	// Already writable?
5755
-	if (is_writable($file))
5756
-		return true;
6098
+	if (is_writable($file)) {
6099
+			return true;
6100
+	}
5757 6101
 
5758 6102
 	// Do we have a file or a dir?
5759 6103
 	$isDir = is_dir($file);
@@ -5769,10 +6113,9 @@  discard block
 block discarded – undo
5769 6113
 		{
5770 6114
 			$isWritable = true;
5771 6115
 			break;
6116
+		} else {
6117
+					@chmod($file, $val);
5772 6118
 		}
5773
-
5774
-		else
5775
-			@chmod($file, $val);
5776 6119
 	}
5777 6120
 
5778 6121
 	return $isWritable;
@@ -5791,8 +6134,9 @@  discard block
 block discarded – undo
5791 6134
 	global $txt;
5792 6135
 
5793 6136
 	// Come on...
5794
-	if (empty($json) || !is_string($json))
5795
-		return array();
6137
+	if (empty($json) || !is_string($json)) {
6138
+			return array();
6139
+	}
5796 6140
 
5797 6141
 	$returnArray = @json_decode($json, $returnAsArray);
5798 6142
 
@@ -5830,11 +6174,11 @@  discard block
 block discarded – undo
5830 6174
 		$jsonDebug = $jsonDebug[0];
5831 6175
 		loadLanguage('Errors');
5832 6176
 
5833
-		if (!empty($jsonDebug))
5834
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5835
-
5836
-		else
5837
-			log_error($txt['json_'. $jsonError], 'critical');
6177
+		if (!empty($jsonDebug)) {
6178
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6179
+		} else {
6180
+					log_error($txt['json_'. $jsonError], 'critical');
6181
+		}
5838 6182
 
5839 6183
 		// Everyone expects an array.
5840 6184
 		return array();
@@ -5868,8 +6212,9 @@  discard block
 block discarded – undo
5868 6212
 	global $db_show_debug, $modSettings;
5869 6213
 
5870 6214
 	// Defensive programming anyone?
5871
-	if (empty($data))
5872
-		return false;
6215
+	if (empty($data)) {
6216
+			return false;
6217
+	}
5873 6218
 
5874 6219
 	// Don't need extra stuff...
5875 6220
 	$db_show_debug = false;
@@ -5877,11 +6222,11 @@  discard block
 block discarded – undo
5877 6222
 	// Kill anything else.
5878 6223
 	ob_end_clean();
5879 6224
 
5880
-	if (!empty($modSettings['CompressedOutput']))
5881
-		@ob_start('ob_gzhandler');
5882
-
5883
-	else
5884
-		ob_start();
6225
+	if (!empty($modSettings['CompressedOutput'])) {
6226
+			@ob_start('ob_gzhandler');
6227
+	} else {
6228
+			ob_start();
6229
+	}
5885 6230
 
5886 6231
 	// Set the header.
5887 6232
 	header($type);
@@ -5913,8 +6258,9 @@  discard block
 block discarded – undo
5913 6258
 	static $done = false;
5914 6259
 
5915 6260
 	// If we don't need to do anything, don't
5916
-	if (!$update && $done)
5917
-		return;
6261
+	if (!$update && $done) {
6262
+			return;
6263
+	}
5918 6264
 
5919 6265
 	// Should we get a new copy of the official list of TLDs?
5920 6266
 	if ($update)
@@ -5922,8 +6268,9 @@  discard block
 block discarded – undo
5922 6268
 		$tlds = fetch_web_data('https://data.iana.org/TLD/tlds-alpha-by-domain.txt');
5923 6269
 
5924 6270
 		// If the Internet Assigned Numbers Authority can't be reached, the Internet is gone. We're probably running on a server hidden in a bunker deep underground to protect it from marauding bandits roaming on the surface. We don't want to waste precious electricity on pointlessly repeating background tasks, so we'll wait until the next regularly scheduled update to see if civilization has been restored.
5925
-		if ($tlds === false)
5926
-			$postapocalypticNightmare = true;
6271
+		if ($tlds === false) {
6272
+					$postapocalypticNightmare = true;
6273
+		}
5927 6274
 	}
5928 6275
 	// If we aren't updating and the regex is valid, we're done
5929 6276
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -5938,10 +6285,11 @@  discard block
 block discarded – undo
5938 6285
 		// Clean $tlds and convert it to an array
5939 6286
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5940 6287
 			$line = trim($line);
5941
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5942
-				return false;
5943
-			else
5944
-				return true;
6288
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6289
+							return false;
6290
+			} else {
6291
+							return true;
6292
+			}
5945 6293
 		});
5946 6294
 
5947 6295
 		// Convert Punycode to Unicode
@@ -5995,8 +6343,9 @@  discard block
 block discarded – undo
5995 6343
 						$idx += $digit * $w;
5996 6344
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5997 6345
 
5998
-						if ($digit < $t)
5999
-							break;
6346
+						if ($digit < $t) {
6347
+													break;
6348
+						}
6000 6349
 
6001 6350
 						$w = (int) ($w * ($base - $t));
6002 6351
 					}
@@ -6005,8 +6354,9 @@  discard block
 block discarded – undo
6005 6354
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
6006 6355
 					$delta += intval($delta / ($deco_len + 1));
6007 6356
 
6008
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
6009
-						$delta = intval($delta / ($base - $tmin));
6357
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
6358
+											$delta = intval($delta / ($base - $tmin));
6359
+					}
6010 6360
 
6011 6361
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
6012 6362
 					$is_first = false;
@@ -6015,8 +6365,9 @@  discard block
 block discarded – undo
6015 6365
 
6016 6366
 					if ($deco_len > 0)
6017 6367
 					{
6018
-						for ($i = $deco_len; $i > $idx; $i--)
6019
-							$decoded[$i] = $decoded[($i - 1)];
6368
+						for ($i = $deco_len; $i > $idx; $i--) {
6369
+													$decoded[$i] = $decoded[($i - 1)];
6370
+						}
6020 6371
 					}
6021 6372
 					$decoded[$idx++] = $char;
6022 6373
 				}
@@ -6024,24 +6375,29 @@  discard block
 block discarded – undo
6024 6375
 				foreach ($decoded as $k => $v)
6025 6376
 				{
6026 6377
 					// 7bit are transferred literally
6027
-					if ($v < 128)
6028
-						$output .= chr($v);
6378
+					if ($v < 128) {
6379
+											$output .= chr($v);
6380
+					}
6029 6381
 
6030 6382
 					// 2 bytes
6031
-					elseif ($v < (1 << 11))
6032
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6383
+					elseif ($v < (1 << 11)) {
6384
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6385
+					}
6033 6386
 
6034 6387
 					// 3 bytes
6035
-					elseif ($v < (1 << 16))
6036
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6388
+					elseif ($v < (1 << 16)) {
6389
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6390
+					}
6037 6391
 
6038 6392
 					// 4 bytes
6039
-					elseif ($v < (1 << 21))
6040
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6393
+					elseif ($v < (1 << 21)) {
6394
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6395
+					}
6041 6396
 
6042 6397
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
6043
-					else
6044
-						$output .= $safe_char;
6398
+					else {
6399
+											$output .= $safe_char;
6400
+					}
6045 6401
 				}
6046 6402
 
6047 6403
 				$output_parts[] = $output;
@@ -6134,8 +6490,7 @@  discard block
 block discarded – undo
6134 6490
 
6135 6491
 		$strlen = 'mb_strlen';
6136 6492
 		$substr = 'mb_substr';
6137
-	}
6138
-	else
6493
+	} else
6139 6494
 	{
6140 6495
 		$strlen = $smcFunc['strlen'];
6141 6496
 		$substr = $smcFunc['substr'];
@@ -6149,20 +6504,21 @@  discard block
 block discarded – undo
6149 6504
 
6150 6505
 		$first = $substr($string, 0, 1);
6151 6506
 
6152
-		if (empty($index[$first]))
6153
-			$index[$first] = array();
6507
+		if (empty($index[$first])) {
6508
+					$index[$first] = array();
6509
+		}
6154 6510
 
6155 6511
 		if ($strlen($string) > 1)
6156 6512
 		{
6157 6513
 			// Sanity check on recursion
6158
-			if ($depth > 99)
6159
-				$index[$first][$substr($string, 1)] = '';
6160
-
6161
-			else
6162
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6514
+			if ($depth > 99) {
6515
+							$index[$first][$substr($string, 1)] = '';
6516
+			} else {
6517
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6518
+			}
6519
+		} else {
6520
+					$index[$first][''] = '';
6163 6521
 		}
6164
-		else
6165
-			$index[$first][''] = '';
6166 6522
 
6167 6523
 		$depth--;
6168 6524
 		return $index;
@@ -6185,9 +6541,9 @@  discard block
 block discarded – undo
6185 6541
 			$key_regex = preg_quote($key, $delim);
6186 6542
 			$new_key = $key;
6187 6543
 
6188
-			if (empty($value))
6189
-				$sub_regex = '';
6190
-			else
6544
+			if (empty($value)) {
6545
+							$sub_regex = '';
6546
+			} else
6191 6547
 			{
6192 6548
 				$sub_regex = $index_to_regex($value, $delim);
6193 6549
 
@@ -6195,22 +6551,22 @@  discard block
 block discarded – undo
6195 6551
 				{
6196 6552
 					$new_key_array = explode('(?'.'>', $sub_regex);
6197 6553
 					$new_key .= $new_key_array[0];
6554
+				} else {
6555
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6198 6556
 				}
6199
-				else
6200
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6201 6557
 			}
6202 6558
 
6203
-			if ($depth > 1)
6204
-				$regex[$new_key] = $key_regex . $sub_regex;
6205
-			else
6559
+			if ($depth > 1) {
6560
+							$regex[$new_key] = $key_regex . $sub_regex;
6561
+			} else
6206 6562
 			{
6207 6563
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
6208 6564
 				{
6209 6565
 					$regex[$new_key] = $key_regex . $sub_regex;
6210 6566
 					unset($index[$key]);
6567
+				} else {
6568
+									break;
6211 6569
 				}
6212
-				else
6213
-					break;
6214 6570
 			}
6215 6571
 		}
6216 6572
 
@@ -6219,10 +6575,11 @@  discard block
 block discarded – undo
6219 6575
 			$l1 = $strlen($k1);
6220 6576
 			$l2 = $strlen($k2);
6221 6577
 
6222
-			if ($l1 == $l2)
6223
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
6224
-			else
6225
-				return $l1 > $l2 ? -1 : 1;
6578
+			if ($l1 == $l2) {
6579
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6580
+			} else {
6581
+							return $l1 > $l2 ? -1 : 1;
6582
+			}
6226 6583
 		});
6227 6584
 
6228 6585
 		$depth--;
@@ -6233,21 +6590,24 @@  discard block
 block discarded – undo
6233 6590
 	$index = array();
6234 6591
 	$regex = '';
6235 6592
 
6236
-	foreach ($strings as $string)
6237
-		$index = $add_string_to_index($string, $index);
6593
+	foreach ($strings as $string) {
6594
+			$index = $add_string_to_index($string, $index);
6595
+	}
6238 6596
 
6239 6597
 	if ($returnArray === true)
6240 6598
 	{
6241 6599
 		$regex = array();
6242
-		while (!empty($index))
6243
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6600
+		while (!empty($index)) {
6601
+					$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6602
+		}
6603
+	} else {
6604
+			$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6244 6605
 	}
6245
-	else
6246
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6247 6606
 
6248 6607
 	// Restore PHP's internal character encoding to whatever it was originally
6249
-	if (!empty($current_encoding))
6250
-		mb_internal_encoding($current_encoding);
6608
+	if (!empty($current_encoding)) {
6609
+			mb_internal_encoding($current_encoding);
6610
+	}
6251 6611
 
6252 6612
 	return $regex;
6253 6613
 }
@@ -6290,13 +6650,15 @@  discard block
 block discarded – undo
6290 6650
 	// Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't...
6291 6651
 	$url = str_ireplace('https://', 'http://', $url) . '/';
6292 6652
 	$headers = @get_headers($url);
6293
-	if ($headers === false)
6294
-		return false;
6653
+	if ($headers === false) {
6654
+			return false;
6655
+	}
6295 6656
 
6296 6657
 	// Now to see if it came back https...
6297 6658
 	// First check for a redirect status code in first row (301, 302, 307)
6298
-	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false)
6299
-		return false;
6659
+	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) {
6660
+			return false;
6661
+	}
6300 6662
 
6301 6663
 	// Search for the location entry to confirm https
6302 6664
 	$result = false;
@@ -6332,8 +6694,7 @@  discard block
 block discarded – undo
6332 6694
 		$is_admin = $user_info['is_admin'];
6333 6695
 		$mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null;
6334 6696
 		$ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null;
6335
-	}
6336
-	else
6697
+	} else
6337 6698
 	{
6338 6699
 		$request = $smcFunc['db_query']('', '
6339 6700
 				SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group
@@ -6347,17 +6708,19 @@  discard block
 block discarded – undo
6347 6708
 
6348 6709
 		$row = $smcFunc['db_fetch_assoc']($request);
6349 6710
 
6350
-		if (empty($row['additional_groups']))
6351
-			$groups = array($row['id_group'], $row['id_post_group']);
6352
-		else
6353
-			$groups = array_merge(
6711
+		if (empty($row['additional_groups'])) {
6712
+					$groups = array($row['id_group'], $row['id_post_group']);
6713
+		} else {
6714
+					$groups = array_merge(
6354 6715
 					array($row['id_group'], $row['id_post_group']),
6355 6716
 					explode(',', $row['additional_groups'])
6356 6717
 			);
6718
+		}
6357 6719
 
6358 6720
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
6359
-		foreach ($groups as $k => $v)
6360
-			$groups[$k] = (int) $v;
6721
+		foreach ($groups as $k => $v) {
6722
+					$groups[$k] = (int) $v;
6723
+		}
6361 6724
 
6362 6725
 		$is_admin = in_array(1, $groups);
6363 6726
 
@@ -6374,8 +6737,9 @@  discard block
 block discarded – undo
6374 6737
 				'current_member' => $userid,
6375 6738
 			)
6376 6739
 		);
6377
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6378
-			$boards_mod[] = $row['id_board'];
6740
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6741
+					$boards_mod[] = $row['id_board'];
6742
+		}
6379 6743
 		$smcFunc['db_free_result']($request);
6380 6744
 
6381 6745
 		// Can any of the groups they're in moderate any of the boards?
@@ -6387,8 +6751,9 @@  discard block
 block discarded – undo
6387 6751
 				'groups' => $groups,
6388 6752
 			)
6389 6753
 		);
6390
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6391
-			$boards_mod[] = $row['id_board'];
6754
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6755
+					$boards_mod[] = $row['id_board'];
6756
+		}
6392 6757
 		$smcFunc['db_free_result']($request);
6393 6758
 
6394 6759
 		// Just in case we've got duplicates here...
@@ -6398,21 +6763,25 @@  discard block
 block discarded – undo
6398 6763
 	}
6399 6764
 
6400 6765
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
6401
-	if ($is_admin)
6402
-		$query_part['query_see_board'] = '1=1';
6766
+	if ($is_admin) {
6767
+			$query_part['query_see_board'] = '1=1';
6768
+	}
6403 6769
 	// Otherwise just the groups in $user_info['groups'].
6404
-	else
6405
-		$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6770
+	else {
6771
+			$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6772
+	}
6406 6773
 
6407 6774
 	// Build the list of boards they WANT to see.
6408 6775
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
6409 6776
 
6410 6777
 	// If they aren't ignoring any boards then they want to see all the boards they can see
6411
-	if (empty($ignoreboards))
6412
-		$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6778
+	if (empty($ignoreboards)) {
6779
+			$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6780
+	}
6413 6781
 	// Ok I guess they don't want to see all the boards
6414
-	else
6415
-		$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6782
+	else {
6783
+			$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6784
+	}
6416 6785
 
6417 6786
 	return $query_part;
6418 6787
 }
@@ -6426,10 +6795,11 @@  discard block
 block discarded – undo
6426 6795
 {
6427 6796
 	$secure = false;
6428 6797
 
6429
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
6430
-		$secure = true;
6431
-	elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
6432
-		$secure = true;
6798
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
6799
+			$secure = true;
6800
+	} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
6801
+			$secure = true;
6802
+	}
6433 6803
 
6434 6804
 	return $secure;
6435 6805
 }
Please login to merge, or discard this patch.
Sources/ManageServer.php 1 patch
Braces   +315 added lines, -243 removed lines patch added patch discarded remove patch
@@ -59,8 +59,9 @@  discard block
 block discarded – undo
59 59
  * @version 2.1 Beta 4
60 60
  */
61 61
 
62
-if (!defined('SMF'))
62
+if (!defined('SMF')) {
63 63
 	die('No direct access...');
64
+}
64 65
 
65 66
 /**
66 67
  * This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects
@@ -111,10 +112,11 @@  discard block
 block discarded – undo
111 112
 	$settings_not_writable = !is_writable($boarddir . '/Settings.php');
112 113
 	$settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
113 114
 
114
-	if ($settings_not_writable)
115
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
116
-	elseif ($settings_backup_fail)
117
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
115
+	if ($settings_not_writable) {
116
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
117
+	} elseif ($settings_backup_fail) {
118
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
119
+	}
118 120
 
119 121
 	$context['settings_not_writable'] = $settings_not_writable;
120 122
 
@@ -142,10 +144,11 @@  discard block
 block discarded – undo
142 144
 
143 145
 	// If no cert, force_ssl must remain 0
144 146
 	require_once($sourcedir . '/Subs.php');
145
-	if (!ssl_cert_found($boardurl) && empty($modSettings['force_ssl']))
146
-		$disable_force_ssl = true;
147
-	else
148
-		$disable_force_ssl = false;
147
+	if (!ssl_cert_found($boardurl) && empty($modSettings['force_ssl'])) {
148
+			$disable_force_ssl = true;
149
+	} else {
150
+			$disable_force_ssl = false;
151
+	}
149 152
 
150 153
 	/* If you're writing a mod, it's a bad idea to add things here....
151 154
 	For each option:
@@ -175,8 +178,9 @@  discard block
 block discarded – undo
175 178
 
176 179
 	call_integration_hook('integrate_general_settings', array(&$config_vars));
177 180
 
178
-	if ($return_config)
179
-		return $config_vars;
181
+	if ($return_config) {
182
+			return $config_vars;
183
+	}
180 184
 
181 185
 	// Setup the template stuff.
182 186
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=general;save';
@@ -193,16 +197,18 @@  discard block
 block discarded – undo
193 197
 			$registerSMStats = registerSMStats();
194 198
 
195 199
 			// Failed to register, disable it again.
196
-			if (empty($registerSMStats))
197
-				$_POST['enable_sm_stats'] = 0;
200
+			if (empty($registerSMStats)) {
201
+							$_POST['enable_sm_stats'] = 0;
202
+			}
198 203
 		}
199 204
 
200 205
 		// Ensure all URLs are aligned with the new force_ssl setting
201 206
 		// Treat unset like 0
202
-		if (isset($_POST['force_ssl']))
203
-			AlignURLsWithSSLSetting($_POST['force_ssl']);
204
-		else
205
-			AlignURLsWithSSLSetting(0);
207
+		if (isset($_POST['force_ssl'])) {
208
+					AlignURLsWithSSLSetting($_POST['force_ssl']);
209
+		} else {
210
+					AlignURLsWithSSLSetting(0);
211
+		}
206 212
 
207 213
 		saveSettings($config_vars);
208 214
 		$_SESSION['adm-save'] = true;
@@ -255,10 +261,11 @@  discard block
 block discarded – undo
255 261
 	require_once($sourcedir . '/Subs-Admin.php');
256 262
 
257 263
 	// Check $boardurl
258
-	if (!empty($new_force_ssl))
259
-		$newval = strtr($boardurl, array('http://' => 'https://'));
260
-	else
261
-		$newval = strtr($boardurl, array('https://' => 'http://'));
264
+	if (!empty($new_force_ssl)) {
265
+			$newval = strtr($boardurl, array('http://' => 'https://'));
266
+	} else {
267
+			$newval = strtr($boardurl, array('https://' => 'http://'));
268
+	}
262 269
 	updateSettingsFile(array('boardurl' => '\'' . addslashes($newval) . '\''));
263 270
 
264 271
 	$new_settings = array();
@@ -266,20 +273,22 @@  discard block
 block discarded – undo
266 273
 	// Check $smileys_url, but only if it points to a subfolder of $boardurl
267 274
 	if (BoardurlMatch($modSettings['smileys_url']))
268 275
 	{
269
-		if (!empty($new_force_ssl))
270
-			$newval = strtr($modSettings['smileys_url'], array('http://' => 'https://'));
271
-		else
272
-			$newval = strtr($modSettings['smileys_url'], array('https://' => 'http://'));
276
+		if (!empty($new_force_ssl)) {
277
+					$newval = strtr($modSettings['smileys_url'], array('http://' => 'https://'));
278
+		} else {
279
+					$newval = strtr($modSettings['smileys_url'], array('https://' => 'http://'));
280
+		}
273 281
 		$new_settings['smileys_url'] = $newval;
274 282
 	}
275 283
 
276 284
 	// Check $avatar_url, but only if it points to a subfolder of $boardurl
277 285
 	if (BoardurlMatch($modSettings['avatar_url']))
278 286
 	{
279
-		if (!empty($new_force_ssl))
280
-			$newval = strtr($modSettings['avatar_url'], array('http://' => 'https://'));
281
-		else
282
-			$newval = strtr($modSettings['avatar_url'], array('https://' => 'http://'));
287
+		if (!empty($new_force_ssl)) {
288
+					$newval = strtr($modSettings['avatar_url'], array('http://' => 'https://'));
289
+		} else {
290
+					$newval = strtr($modSettings['avatar_url'], array('https://' => 'http://'));
291
+		}
283 292
 		$new_settings['avatar_url'] = $newval;
284 293
 	}
285 294
 
@@ -287,16 +296,18 @@  discard block
 block discarded – undo
287 296
 	// This one had been optional in the past, make sure it is set first
288 297
 	if (isset($modSettings['custom_avatar_url']) && BoardurlMatch($modSettings['custom_avatar_url']))
289 298
 	{
290
-		if (!empty($new_force_ssl))
291
-			$newval = strtr($modSettings['custom_avatar_url'], array('http://' => 'https://'));
292
-		else
293
-			$newval = strtr($modSettings['custom_avatar_url'], array('https://' => 'http://'));
299
+		if (!empty($new_force_ssl)) {
300
+					$newval = strtr($modSettings['custom_avatar_url'], array('http://' => 'https://'));
301
+		} else {
302
+					$newval = strtr($modSettings['custom_avatar_url'], array('https://' => 'http://'));
303
+		}
294 304
 		$new_settings['custom_avatar_url'] = $newval;
295 305
 	}
296 306
 
297 307
 	// Save updates to the settings table
298
-	if (!empty($new_settings))
299
-		updateSettings($new_settings, true);
308
+	if (!empty($new_settings)) {
309
+			updateSettings($new_settings, true);
310
+	}
300 311
 
301 312
 	// Now we move onto the themes.
302 313
 	// First, get a list of theme URLs...
@@ -317,10 +328,11 @@  discard block
 block discarded – undo
317 328
 		// First check to see if it points to a subfolder of $boardurl
318 329
 		if (BoardurlMatch($row['value']))
319 330
 		{
320
-			if (!empty($new_force_ssl))
321
-				$newval = strtr($row['value'], array('http://' => 'https://'));
322
-			else
323
-				$newval = strtr($row['value'], array('https://' => 'http://'));
331
+			if (!empty($new_force_ssl)) {
332
+							$newval = strtr($row['value'], array('http://' => 'https://'));
333
+			} else {
334
+							$newval = strtr($row['value'], array('https://' => 'http://'));
335
+			}
324 336
 			$smcFunc['db_query']('', '
325 337
 				UPDATE {db_prefix}themes
326 338
 				   SET value = {string:theme_val}
@@ -360,11 +372,12 @@  discard block
 block discarded – undo
360 372
 
361 373
 	// If leftmost portion of path matches boardurl, return true
362 374
 	$result = strpos($urlpath, $boardurlpath);
363
-	if ($result === false || $result != 0)
364
-		return false;
365
-	else
366
-		return true;
367
-}
375
+	if ($result === false || $result != 0) {
376
+			return false;
377
+	} else {
378
+			return true;
379
+	}
380
+	}
368 381
 
369 382
 /**
370 383
  * Basic database and paths settings - database name, host, etc.
@@ -403,8 +416,9 @@  discard block
 block discarded – undo
403 416
 		$request = $smcFunc['db_query']('', 'SELECT cfgname FROM pg_ts_config', array());
404 417
 		$fts_language = array();
405 418
 
406
-		while ($row = $smcFunc['db_fetch_assoc']($request))
407
-			$fts_language[$row['cfgname']] = $row['cfgname'];
419
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
420
+					$fts_language[$row['cfgname']] = $row['cfgname'];
421
+		}
408 422
 
409 423
 		$config_vars = array_merge ($config_vars, array(
410 424
 				'',
@@ -416,20 +430,22 @@  discard block
 block discarded – undo
416 430
 
417 431
 	call_integration_hook('integrate_database_settings', array(&$config_vars));
418 432
 
419
-	if ($return_config)
420
-		return $config_vars;
433
+	if ($return_config) {
434
+			return $config_vars;
435
+	}
421 436
 
422 437
 	// Setup the template stuff.
423 438
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save';
424 439
 	$context['settings_title'] = $txt['database_settings'];
425 440
 	$context['save_disabled'] = $context['settings_not_writable'];
426 441
 
427
-	if (!$smcFunc['db_allow_persistent']())
428
-		addInlineJavaScript('
442
+	if (!$smcFunc['db_allow_persistent']()) {
443
+			addInlineJavaScript('
429 444
 			$(function()
430 445
 			{
431 446
 				$("#db_persist").prop("disabled", true);
432 447
 			});', true);
448
+	}
433 449
 
434 450
 	// Saving settings?
435 451
 	if (isset($_REQUEST['save']))
@@ -499,13 +515,15 @@  discard block
 block discarded – undo
499 515
 		hideGlobalCookies();
500 516
 	});', true);
501 517
 
502
-	if (empty($user_settings['tfa_secret']))
503
-		addInlineJavaScript('');
518
+	if (empty($user_settings['tfa_secret'])) {
519
+			addInlineJavaScript('');
520
+	}
504 521
 
505 522
 	call_integration_hook('integrate_cookie_settings', array(&$config_vars));
506 523
 
507
-	if ($return_config)
508
-		return $config_vars;
524
+	if ($return_config) {
525
+			return $config_vars;
526
+	}
509 527
 
510 528
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save';
511 529
 	$context['settings_title'] = $txt['cookies_sessions_settings'];
@@ -516,14 +534,17 @@  discard block
 block discarded – undo
516 534
 		call_integration_hook('integrate_save_cookie_settings');
517 535
 
518 536
 		// Local and global do not play nicely together.
519
-		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies']))
520
-			unset ($_POST['globalCookies']);
537
+		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) {
538
+					unset ($_POST['globalCookies']);
539
+		}
521 540
 
522
-		if (empty($modSettings['localCookies']) != empty($_POST['localCookies']) || empty($modSettings['globalCookies']) != empty($_POST['globalCookies']))
523
-			$scope_changed = true;
541
+		if (empty($modSettings['localCookies']) != empty($_POST['localCookies']) || empty($modSettings['globalCookies']) != empty($_POST['globalCookies'])) {
542
+					$scope_changed = true;
543
+		}
524 544
 
525
-		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false)
526
-			fatal_lang_error('invalid_cookie_domain', false);
545
+		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) {
546
+					fatal_lang_error('invalid_cookie_domain', false);
547
+		}
527 548
 
528 549
 		saveSettings($config_vars);
529 550
 
@@ -606,8 +627,9 @@  discard block
 block discarded – undo
606 627
 
607 628
 	call_integration_hook('integrate_general_security_settings', array(&$config_vars));
608 629
 
609
-	if ($return_config)
610
-		return $config_vars;
630
+	if ($return_config) {
631
+			return $config_vars;
632
+	}
611 633
 
612 634
 	// Saving?
613 635
 	if (isset($_GET['save']))
@@ -646,8 +668,7 @@  discard block
 block discarded – undo
646 668
 		$txt['cache_settings_message'] = $txt['detected_no_caching'];
647 669
 		$cache_level = array($txt['cache_off']);
648 670
 		$detected['none'] = $txt['cache_off'];
649
-	}
650
-	else
671
+	} else
651 672
 	{
652 673
 		$txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected));
653 674
 		$cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']);
@@ -684,8 +705,9 @@  discard block
 block discarded – undo
684 705
 			}
685 706
 		}
686 707
 	}
687
-	if ($return_config)
688
-		return $config_vars;
708
+	if ($return_config) {
709
+			return $config_vars;
710
+	}
689 711
 
690 712
 	// Saving again?
691 713
 	if (isset($_GET['save']))
@@ -713,8 +735,9 @@  discard block
 block discarded – undo
713 735
 	$context['save_disabled'] = $context['settings_not_writable'];
714 736
 
715 737
 	// Decide what message to show.
716
-	if (!$context['save_disabled'])
717
-		$context['settings_message'] = $txt['caching_information'];
738
+	if (!$context['save_disabled']) {
739
+			$context['settings_message'] = $txt['caching_information'];
740
+	}
718 741
 
719 742
 	// Prepare the template.
720 743
 	prepareServerSettingsContext($config_vars);
@@ -737,24 +760,25 @@  discard block
 block discarded – undo
737 760
 	if (stripos(PHP_OS, 'win') === 0)
738 761
 	{
739 762
 		$context['settings_message'] = $txt['loadavg_disabled_windows'];
740
-		if (isset($_GET['save']))
741
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
742
-	}
743
-	elseif (stripos(PHP_OS, 'darwin') === 0)
763
+		if (isset($_GET['save'])) {
764
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
765
+		}
766
+	} elseif (stripos(PHP_OS, 'darwin') === 0)
744 767
 	{
745 768
 		$context['settings_message'] = $txt['loadavg_disabled_osx'];
746
-		if (isset($_GET['save']))
747
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
748
-	}
749
-	else
769
+		if (isset($_GET['save'])) {
770
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
771
+		}
772
+	} else
750 773
 	{
751 774
 		$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
752
-		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0)
753
-			$modSettings['load_average'] = (float) $matches[1];
754
-		elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0)
755
-			$modSettings['load_average'] = (float) $matches[1];
756
-		else
757
-			unset($modSettings['load_average']);
775
+		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) {
776
+					$modSettings['load_average'] = (float) $matches[1];
777
+		} elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) {
778
+					$modSettings['load_average'] = (float) $matches[1];
779
+		} else {
780
+					unset($modSettings['load_average']);
781
+		}
758 782
 
759 783
 		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
760 784
 		{
@@ -790,8 +814,9 @@  discard block
 block discarded – undo
790 814
 
791 815
 	call_integration_hook('integrate_loadavg_settings', array(&$config_vars));
792 816
 
793
-	if ($return_config)
794
-		return $config_vars;
817
+	if ($return_config) {
818
+			return $config_vars;
819
+	}
795 820
 
796 821
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save';
797 822
 	$context['settings_title'] = $txt['load_balancing_settings'];
@@ -802,24 +827,27 @@  discard block
 block discarded – undo
802 827
 		// Stupidity is not allowed.
803 828
 		foreach ($_POST as $key => $value)
804 829
 		{
805
-			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values)))
806
-				continue;
807
-			else
808
-				$_POST[$key] = (float) $value;
809
-
810
-			if ($key == 'loadavg_auto_opt' && $value <= 1)
811
-				$_POST['loadavg_auto_opt'] = 1.0;
812
-			elseif ($key == 'loadavg_forum' && $value < 10)
813
-				$_POST['loadavg_forum'] = 10.0;
814
-			elseif ($value < 2)
815
-				$_POST[$key] = 2.0;
830
+			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) {
831
+							continue;
832
+			} else {
833
+							$_POST[$key] = (float) $value;
834
+			}
835
+
836
+			if ($key == 'loadavg_auto_opt' && $value <= 1) {
837
+							$_POST['loadavg_auto_opt'] = 1.0;
838
+			} elseif ($key == 'loadavg_forum' && $value < 10) {
839
+							$_POST['loadavg_forum'] = 10.0;
840
+			} elseif ($value < 2) {
841
+							$_POST[$key] = 2.0;
842
+			}
816 843
 		}
817 844
 
818 845
 		call_integration_hook('integrate_save_loadavg_settings');
819 846
 
820 847
 		saveDBSettings($config_vars);
821
-		if (!isset($_SESSION['adm-save']))
822
-			$_SESSION['adm-save'] = true;
848
+		if (!isset($_SESSION['adm-save'])) {
849
+					$_SESSION['adm-save'] = true;
850
+		}
823 851
 		redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']);
824 852
 	}
825 853
 
@@ -855,10 +883,11 @@  discard block
 block discarded – undo
855 883
 
856 884
 	if (isset($_SESSION['adm-save']))
857 885
 	{
858
-		if ($_SESSION['adm-save'] === true)
859
-			$context['saved_successful'] = true;
860
-		else
861
-			$context['saved_failed'] = $_SESSION['adm-save'];
886
+		if ($_SESSION['adm-save'] === true) {
887
+					$context['saved_successful'] = true;
888
+		} else {
889
+					$context['saved_failed'] = $_SESSION['adm-save'];
890
+		}
862 891
 
863 892
 		unset($_SESSION['adm-save']);
864 893
 	}
@@ -866,9 +895,9 @@  discard block
 block discarded – undo
866 895
 	$context['config_vars'] = array();
867 896
 	foreach ($config_vars as $identifier => $config_var)
868 897
 	{
869
-		if (!is_array($config_var) || !isset($config_var[1]))
870
-			$context['config_vars'][] = $config_var;
871
-		else
898
+		if (!is_array($config_var) || !isset($config_var[1])) {
899
+					$context['config_vars'][] = $config_var;
900
+		} else
872 901
 		{
873 902
 			$varname = $config_var[0];
874 903
 			global $$varname;
@@ -903,16 +932,19 @@  discard block
 block discarded – undo
903 932
 			if ($config_var[3] == 'int' || $config_var[3] == 'float')
904 933
 			{
905 934
 				// Default to a min of 0 if one isn't set
906
-				if (isset($config_var['min']))
907
-					$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
908
-				else
909
-					$context['config_vars'][$config_var[0]]['min'] = 0;
935
+				if (isset($config_var['min'])) {
936
+									$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
937
+				} else {
938
+									$context['config_vars'][$config_var[0]]['min'] = 0;
939
+				}
910 940
 
911
-				if (isset($config_var['max']))
912
-					$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
941
+				if (isset($config_var['max'])) {
942
+									$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
943
+				}
913 944
 
914
-				if (isset($config_var['step']))
915
-					$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
945
+				if (isset($config_var['step'])) {
946
+									$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
947
+				}
916 948
 			}
917 949
 
918 950
 			// If this is a select box handle any data.
@@ -920,12 +952,13 @@  discard block
 block discarded – undo
920 952
 			{
921 953
 				// If it's associative
922 954
 				$config_values = array_values($config_var[4]);
923
-				if (isset($config_values[0]) && is_array($config_values[0]))
924
-					$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
925
-				else
955
+				if (isset($config_values[0]) && is_array($config_values[0])) {
956
+									$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
957
+				} else
926 958
 				{
927
-					foreach ($config_var[4] as $key => $item)
928
-						$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
959
+					foreach ($config_var[4] as $key => $item) {
960
+											$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
961
+					}
929 962
 				}
930 963
 			}
931 964
 		}
@@ -950,10 +983,11 @@  discard block
 block discarded – undo
950 983
 
951 984
 	if (isset($_SESSION['adm-save']))
952 985
 	{
953
-		if ($_SESSION['adm-save'] === true)
954
-			$context['saved_successful'] = true;
955
-		else
956
-			$context['saved_failed'] = $_SESSION['adm-save'];
986
+		if ($_SESSION['adm-save'] === true) {
987
+					$context['saved_successful'] = true;
988
+		} else {
989
+					$context['saved_failed'] = $_SESSION['adm-save'];
990
+		}
957 991
 
958 992
 		unset($_SESSION['adm-save']);
959 993
 	}
@@ -965,26 +999,30 @@  discard block
 block discarded – undo
965 999
 	foreach ($config_vars as $config_var)
966 1000
 	{
967 1001
 		// HR?
968
-		if (!is_array($config_var))
969
-			$context['config_vars'][] = $config_var;
970
-		else
1002
+		if (!is_array($config_var)) {
1003
+					$context['config_vars'][] = $config_var;
1004
+		} else
971 1005
 		{
972 1006
 			// If it has no name it doesn't have any purpose!
973
-			if (empty($config_var[1]))
974
-				continue;
1007
+			if (empty($config_var[1])) {
1008
+							continue;
1009
+			}
975 1010
 
976 1011
 			// Special case for inline permissions
977
-			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions'))
978
-				$inlinePermissions[] = $config_var[1];
979
-			elseif ($config_var[0] == 'permissions')
980
-				continue;
1012
+			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) {
1013
+							$inlinePermissions[] = $config_var[1];
1014
+			} elseif ($config_var[0] == 'permissions') {
1015
+							continue;
1016
+			}
981 1017
 
982
-			if ($config_var[0] == 'boards')
983
-				$board_list = true;
1018
+			if ($config_var[0] == 'boards') {
1019
+							$board_list = true;
1020
+			}
984 1021
 
985 1022
 			// Are we showing the BBC selection box?
986
-			if ($config_var[0] == 'bbc')
987
-				$bbcChoice[] = $config_var[1];
1023
+			if ($config_var[0] == 'bbc') {
1024
+							$bbcChoice[] = $config_var[1];
1025
+			}
988 1026
 
989 1027
 			// We need to do some parsing of the value before we pass it in.
990 1028
 			if (isset($modSettings[$config_var[1]]))
@@ -1003,8 +1041,7 @@  discard block
 block discarded – undo
1003 1041
 					default:
1004 1042
 						$value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]);
1005 1043
 				}
1006
-			}
1007
-			else
1044
+			} else
1008 1045
 			{
1009 1046
 				// Darn, it's empty. What type is expected?
1010 1047
 				switch ($config_var[0])
@@ -1044,16 +1081,19 @@  discard block
 block discarded – undo
1044 1081
 			if ($config_var[0] == 'int' || $config_var[0] == 'float')
1045 1082
 			{
1046 1083
 				// Default to a min of 0 if one isn't set
1047
-				if (isset($config_var['min']))
1048
-					$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
1049
-				else
1050
-					$context['config_vars'][$config_var[1]]['min'] = 0;
1084
+				if (isset($config_var['min'])) {
1085
+									$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
1086
+				} else {
1087
+									$context['config_vars'][$config_var[1]]['min'] = 0;
1088
+				}
1051 1089
 
1052
-				if (isset($config_var['max']))
1053
-					$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
1090
+				if (isset($config_var['max'])) {
1091
+									$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
1092
+				}
1054 1093
 
1055
-				if (isset($config_var['step']))
1056
-					$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
1094
+				if (isset($config_var['step'])) {
1095
+									$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
1096
+				}
1057 1097
 			}
1058 1098
 
1059 1099
 			// If this is a select box handle any data.
@@ -1067,12 +1107,13 @@  discard block
 block discarded – undo
1067 1107
 				}
1068 1108
 
1069 1109
 				// If it's associative
1070
-				if (isset($config_var[2][0]) && is_array($config_var[2][0]))
1071
-					$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
1072
-				else
1110
+				if (isset($config_var[2][0]) && is_array($config_var[2][0])) {
1111
+									$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
1112
+				} else
1073 1113
 				{
1074
-					foreach ($config_var[2] as $key => $item)
1075
-						$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
1114
+					foreach ($config_var[2] as $key => $item) {
1115
+											$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
1116
+					}
1076 1117
 				}
1077 1118
 			}
1078 1119
 
@@ -1081,17 +1122,19 @@  discard block
 block discarded – undo
1081 1122
 			{
1082 1123
 				if (!is_numeric($k))
1083 1124
 				{
1084
-					if (substr($k, 0, 2) == 'on')
1085
-						$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
1086
-					else
1087
-						$context['config_vars'][$config_var[1]][$k] = $v;
1125
+					if (substr($k, 0, 2) == 'on') {
1126
+											$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
1127
+					} else {
1128
+											$context['config_vars'][$config_var[1]][$k] = $v;
1129
+					}
1088 1130
 				}
1089 1131
 
1090 1132
 				// See if there are any other labels that might fit?
1091
-				if (isset($txt['setting_' . $config_var[1]]))
1092
-					$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
1093
-				elseif (isset($txt['groups_' . $config_var[1]]))
1094
-					$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
1133
+				if (isset($txt['setting_' . $config_var[1]])) {
1134
+									$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
1135
+				} elseif (isset($txt['groups_' . $config_var[1]])) {
1136
+									$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
1137
+				}
1095 1138
 			}
1096 1139
 
1097 1140
 			// Set the subtext in case it's part of the label.
@@ -1124,8 +1167,9 @@  discard block
 block discarded – undo
1124 1167
 		// What are the options, eh?
1125 1168
 		$temp = parse_bbc(false);
1126 1169
 		$bbcTags = array();
1127
-		foreach ($temp as $tag)
1128
-			$bbcTags[] = $tag['tag'];
1170
+		foreach ($temp as $tag) {
1171
+					$bbcTags[] = $tag['tag'];
1172
+		}
1129 1173
 
1130 1174
 		$bbcTags = array_unique($bbcTags);
1131 1175
 		$totalTags = count($bbcTags);
@@ -1140,8 +1184,9 @@  discard block
 block discarded – undo
1140 1184
 		$col = 0; $i = 0;
1141 1185
 		foreach ($bbcTags as $tag)
1142 1186
 		{
1143
-			if ($i % $tagsPerColumn == 0 && $i != 0)
1144
-				$col++;
1187
+			if ($i % $tagsPerColumn == 0 && $i != 0) {
1188
+							$col++;
1189
+			}
1145 1190
 
1146 1191
 			$context['bbc_columns'][$col][] = array(
1147 1192
 				'tag' => $tag,
@@ -1184,18 +1229,21 @@  discard block
 block discarded – undo
1184 1229
 	validateToken('admin-ssc');
1185 1230
 
1186 1231
 	// Fix the darn stupid cookiename! (more may not be allowed, but these for sure!)
1187
-	if (isset($_POST['cookiename']))
1188
-		$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1232
+	if (isset($_POST['cookiename'])) {
1233
+			$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1234
+	}
1189 1235
 
1190 1236
 	// Fix the forum's URL if necessary.
1191 1237
 	if (isset($_POST['boardurl']))
1192 1238
 	{
1193
-		if (substr($_POST['boardurl'], -10) == '/index.php')
1194
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1195
-		elseif (substr($_POST['boardurl'], -1) == '/')
1196
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1197
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
1198
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1239
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1240
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1241
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1242
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1243
+		}
1244
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1245
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1246
+		}
1199 1247
 	}
1200 1248
 
1201 1249
 	// Any passwords?
@@ -1230,21 +1278,21 @@  discard block
 block discarded – undo
1230 1278
 	// Figure out which config vars we're saving here...
1231 1279
 	foreach ($config_vars as $var)
1232 1280
 	{
1233
-		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]])))
1234
-			continue;
1281
+		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) {
1282
+					continue;
1283
+		}
1235 1284
 
1236 1285
 		$config_var = $var[0];
1237 1286
 
1238 1287
 		if (in_array($config_var, $config_passwords))
1239 1288
 		{
1240
-			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1])
1241
-				$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1242
-		}
1243
-		elseif (in_array($config_var, $config_strs))
1289
+			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) {
1290
+							$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1291
+			}
1292
+		} elseif (in_array($config_var, $config_strs))
1244 1293
 		{
1245 1294
 			$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var], '\'\\') . '\'';
1246
-		}
1247
-		elseif (in_array($config_var, $config_ints))
1295
+		} elseif (in_array($config_var, $config_ints))
1248 1296
 		{
1249 1297
 			$new_settings[$config_var] = (int) $_POST[$config_var];
1250 1298
 
@@ -1253,17 +1301,17 @@  discard block
 block discarded – undo
1253 1301
 			$new_settings[$config_var] = max($min, $new_settings[$config_var]);
1254 1302
 
1255 1303
 			// Is there a max value for this as well?
1256
-			if (isset($var['max']))
1257
-				$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1258
-		}
1259
-		elseif (in_array($config_var, $config_bools))
1304
+			if (isset($var['max'])) {
1305
+							$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1306
+			}
1307
+		} elseif (in_array($config_var, $config_bools))
1260 1308
 		{
1261
-			if (!empty($_POST[$config_var]))
1262
-				$new_settings[$config_var] = '1';
1263
-			else
1264
-				$new_settings[$config_var] = '0';
1265
-		}
1266
-		else
1309
+			if (!empty($_POST[$config_var])) {
1310
+							$new_settings[$config_var] = '1';
1311
+			} else {
1312
+							$new_settings[$config_var] = '0';
1313
+			}
1314
+		} else
1267 1315
 		{
1268 1316
 			// This shouldn't happen, but it might...
1269 1317
 			fatal_error('Unknown config_var \'' . $config_var . '\'');
@@ -1279,30 +1327,35 @@  discard block
 block discarded – undo
1279 1327
 	foreach ($config_vars as $config_var)
1280 1328
 	{
1281 1329
 		// We just saved the file-based settings, so skip their definitions.
1282
-		if (!is_array($config_var) || $config_var[2] == 'file')
1283
-			continue;
1330
+		if (!is_array($config_var) || $config_var[2] == 'file') {
1331
+					continue;
1332
+		}
1284 1333
 
1285 1334
 		$new_setting = array($config_var[3], $config_var[0]);
1286 1335
 
1287 1336
 		// Select options need carried over, too.
1288
-		if (isset($config_var[4]))
1289
-			$new_setting[] = $config_var[4];
1337
+		if (isset($config_var[4])) {
1338
+					$new_setting[] = $config_var[4];
1339
+		}
1290 1340
 
1291 1341
 		// Include min and max if necessary
1292
-		if (isset($config_var['min']))
1293
-			$new_setting['min'] = $config_var['min'];
1342
+		if (isset($config_var['min'])) {
1343
+					$new_setting['min'] = $config_var['min'];
1344
+		}
1294 1345
 
1295
-		if (isset($config_var['max']))
1296
-			$new_setting['max'] = $config_var['max'];
1346
+		if (isset($config_var['max'])) {
1347
+					$new_setting['max'] = $config_var['max'];
1348
+		}
1297 1349
 
1298 1350
 		// Rewrite the definition a bit.
1299 1351
 		$new_settings[] = $new_setting;
1300 1352
 	}
1301 1353
 
1302 1354
 	// Save the new database-based settings, if any.
1303
-	if (!empty($new_settings))
1304
-		saveDBSettings($new_settings);
1305
-}
1355
+	if (!empty($new_settings)) {
1356
+			saveDBSettings($new_settings);
1357
+	}
1358
+	}
1306 1359
 
1307 1360
 /**
1308 1361
  * Helper function for saving database settings.
@@ -1320,22 +1373,25 @@  discard block
 block discarded – undo
1320 1373
 	$inlinePermissions = array();
1321 1374
 	foreach ($config_vars as $var)
1322 1375
 	{
1323
-		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags']))))
1324
-			continue;
1376
+		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) {
1377
+					continue;
1378
+		}
1325 1379
 
1326 1380
 		// Checkboxes!
1327
-		elseif ($var[0] == 'check')
1328
-			$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1381
+		elseif ($var[0] == 'check') {
1382
+					$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1383
+		}
1329 1384
 		// Select boxes!
1330
-		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2])))
1331
-			$setArray[$var[1]] = $_POST[$var[1]];
1332
-		elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1385
+		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) {
1386
+					$setArray[$var[1]] = $_POST[$var[1]];
1387
+		} elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1333 1388
 		{
1334 1389
 			// For security purposes we validate this line by line.
1335 1390
 			$lOptions = array();
1336
-			foreach ($_POST[$var[1]] as $invar)
1337
-				if (in_array($invar, array_keys($var[2])))
1391
+			foreach ($_POST[$var[1]] as $invar) {
1392
+							if (in_array($invar, array_keys($var[2])))
1338 1393
 					$lOptions[] = $invar;
1394
+			}
1339 1395
 
1340 1396
 			$setArray[$var[1]] = $smcFunc['json_encode']($lOptions);
1341 1397
 		}
@@ -1349,18 +1405,20 @@  discard block
 block discarded – undo
1349 1405
 				$request = $smcFunc['db_query']('', '
1350 1406
 					SELECT id_board
1351 1407
 					FROM {db_prefix}boards');
1352
-				while ($row = $smcFunc['db_fetch_row']($request))
1353
-					$board_list[$row[0]] = true;
1408
+				while ($row = $smcFunc['db_fetch_row']($request)) {
1409
+									$board_list[$row[0]] = true;
1410
+				}
1354 1411
 
1355 1412
 				$smcFunc['db_free_result']($request);
1356 1413
 			}
1357 1414
 
1358 1415
 			$lOptions = array();
1359 1416
 
1360
-			if (!empty($_POST[$var[1]]))
1361
-				foreach ($_POST[$var[1]] as $invar => $dummy)
1417
+			if (!empty($_POST[$var[1]])) {
1418
+							foreach ($_POST[$var[1]] as $invar => $dummy)
1362 1419
 					if (isset($board_list[$invar]))
1363 1420
 						$lOptions[] = $invar;
1421
+			}
1364 1422
 
1365 1423
 			$setArray[$var[1]] = !empty($lOptions) ? implode(',', $lOptions) : '';
1366 1424
 		}
@@ -1374,8 +1432,9 @@  discard block
 block discarded – undo
1374 1432
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1375 1433
 
1376 1434
 			// Do we have a max value for this as well?
1377
-			if (isset($var['max']))
1378
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1435
+			if (isset($var['max'])) {
1436
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1437
+			}
1379 1438
 		}
1380 1439
 		// Floating point!
1381 1440
 		elseif ($var[0] == 'float')
@@ -1387,40 +1446,47 @@  discard block
 block discarded – undo
1387 1446
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1388 1447
 
1389 1448
 			// Do we have a max value for this as well?
1390
-			if (isset($var['max']))
1391
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1449
+			if (isset($var['max'])) {
1450
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1451
+			}
1392 1452
 		}
1393 1453
 		// Text!
1394
-		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time')))
1395
-			$setArray[$var[1]] = $_POST[$var[1]];
1454
+		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) {
1455
+					$setArray[$var[1]] = $_POST[$var[1]];
1456
+		}
1396 1457
 		// Passwords!
1397 1458
 		elseif ($var[0] == 'password')
1398 1459
 		{
1399
-			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1])
1400
-				$setArray[$var[1]] = $_POST[$var[1]][0];
1460
+			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) {
1461
+							$setArray[$var[1]] = $_POST[$var[1]][0];
1462
+			}
1401 1463
 		}
1402 1464
 		// BBC.
1403 1465
 		elseif ($var[0] == 'bbc')
1404 1466
 		{
1405 1467
 
1406 1468
 			$bbcTags = array();
1407
-			foreach (parse_bbc(false) as $tag)
1408
-				$bbcTags[] = $tag['tag'];
1469
+			foreach (parse_bbc(false) as $tag) {
1470
+							$bbcTags[] = $tag['tag'];
1471
+			}
1409 1472
 
1410
-			if (!isset($_POST[$var[1] . '_enabledTags']))
1411
-				$_POST[$var[1] . '_enabledTags'] = array();
1412
-			elseif (!is_array($_POST[$var[1] . '_enabledTags']))
1413
-				$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1473
+			if (!isset($_POST[$var[1] . '_enabledTags'])) {
1474
+							$_POST[$var[1] . '_enabledTags'] = array();
1475
+			} elseif (!is_array($_POST[$var[1] . '_enabledTags'])) {
1476
+							$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1477
+			}
1414 1478
 
1415 1479
 			$setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags']));
1416 1480
 		}
1417 1481
 		// Permissions?
1418
-		elseif ($var[0] == 'permissions')
1419
-			$inlinePermissions[] = $var[1];
1482
+		elseif ($var[0] == 'permissions') {
1483
+					$inlinePermissions[] = $var[1];
1484
+		}
1420 1485
 	}
1421 1486
 
1422
-	if (!empty($setArray))
1423
-		updateSettings($setArray);
1487
+	if (!empty($setArray)) {
1488
+			updateSettings($setArray);
1489
+	}
1424 1490
 
1425 1491
 	// If we have inline permissions we need to save them.
1426 1492
 	if (!empty($inlinePermissions) && allowedTo('manage_permissions'))
@@ -1457,18 +1523,21 @@  discard block
 block discarded – undo
1457 1523
 	// put all of it into an array
1458 1524
 	foreach ($info_lines as $line)
1459 1525
 	{
1460
-		if (preg_match('~(' . $remove . ')~', $line))
1461
-			continue;
1526
+		if (preg_match('~(' . $remove . ')~', $line)) {
1527
+					continue;
1528
+		}
1462 1529
 
1463 1530
 		// new category?
1464
-		if (strpos($line, '<h2>') !== false)
1465
-			$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1531
+		if (strpos($line, '<h2>') !== false) {
1532
+					$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1533
+		}
1466 1534
 
1467 1535
 		// load it as setting => value or the old setting local master
1468
-		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1469
-			$pinfo[$category][$val[1]] = $val[2];
1470
-		elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1471
-			$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1536
+		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1537
+					$pinfo[$category][$val[1]] = $val[2];
1538
+		} elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1539
+					$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1540
+		}
1472 1541
 	}
1473 1542
 
1474 1543
 	// load it in to context and display it
@@ -1503,8 +1572,9 @@  discard block
 block discarded – undo
1503 1572
 				$testAPI = new $cache_class_name();
1504 1573
 
1505 1574
 				// No Support?  NEXT!
1506
-				if (!$testAPI->isSupported(true))
1507
-					continue;
1575
+				if (!$testAPI->isSupported(true)) {
1576
+									continue;
1577
+				}
1508 1578
 
1509 1579
 				$apis[$tryCache] = isset($txt[$tryCache . '_cache']) ? $txt[$tryCache . '_cache'] : $tryCache;
1510 1580
 			}
@@ -1529,8 +1599,9 @@  discard block
 block discarded – undo
1529 1599
 	global $modSettings, $boardurl, $smcFunc;
1530 1600
 
1531 1601
 	// Already have a key?  Can't register again.
1532
-	if (!empty($modSettings['sm_stats_key']))
1533
-		return true;
1602
+	if (!empty($modSettings['sm_stats_key'])) {
1603
+			return true;
1604
+	}
1534 1605
 
1535 1606
 	$fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr);
1536 1607
 	if ($fp)
@@ -1541,8 +1612,9 @@  discard block
 block discarded – undo
1541 1612
 		fwrite($fp, $out);
1542 1613
 
1543 1614
 		$return_data = '';
1544
-		while (!feof($fp))
1545
-			$return_data .= fgets($fp, 128);
1615
+		while (!feof($fp)) {
1616
+					$return_data .= fgets($fp, 128);
1617
+		}
1546 1618
 
1547 1619
 		fclose($fp);
1548 1620
 
Please login to merge, or discard this patch.
Sources/DbExtra-mysql.php 1 patch
Braces   +72 added lines, -51 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Add the functions implemented in this file to the $smcFunc array.
@@ -23,8 +24,8 @@  discard block
 block discarded – undo
23 24
 {
24 25
 	global $smcFunc;
25 26
 
26
-	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table')
27
-		$smcFunc += array(
27
+	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') {
28
+			$smcFunc += array(
28 29
 			'db_backup_table' => 'smf_db_backup_table',
29 30
 			'db_optimize_table' => 'smf_db_optimize_table',
30 31
 			'db_table_sql' => 'smf_db_table_sql',
@@ -33,7 +34,8 @@  discard block
 block discarded – undo
33 34
 			'db_get_vendor' => 'smf_db_get_vendor',
34 35
 			'db_allow_persistent' => 'smf_db_allow_persistent',
35 36
 		);
36
-}
37
+	}
38
+	}
37 39
 
38 40
 /**
39 41
  * Backup $table to $backup_table.
@@ -75,8 +77,9 @@  discard block
 block discarded – undo
75 77
 			));
76 78
 
77 79
 		// Old school or no school?
78
-		if ($request)
79
-			return $request;
80
+		if ($request) {
81
+					return $request;
82
+		}
80 83
 	}
81 84
 
82 85
 	// At this point, the quick method failed.
@@ -100,8 +103,9 @@  discard block
 block discarded – undo
100 103
 	foreach ($create as $k => $l)
101 104
 	{
102 105
 		// Get the name of the auto_increment column.
103
-		if (strpos($l, 'auto_increment'))
104
-			$auto_inc = trim($l);
106
+		if (strpos($l, 'auto_increment')) {
107
+					$auto_inc = trim($l);
108
+		}
105 109
 
106 110
 		// For the engine type, see if we can work out what it is.
107 111
 		if (strpos($l, 'ENGINE') !== false || strpos($l, 'TYPE') !== false)
@@ -109,30 +113,36 @@  discard block
 block discarded – undo
109 113
 			// Extract the engine type.
110 114
 			preg_match('~(ENGINE|TYPE)=(\w+)(\sDEFAULT)?(\sCHARSET=(\w+))?(\sCOLLATE=(\w+))?~', $l, $match);
111 115
 
112
-			if (!empty($match[1]))
113
-				$engine = $match[1];
116
+			if (!empty($match[1])) {
117
+							$engine = $match[1];
118
+			}
114 119
 
115
-			if (!empty($match[2]))
116
-				$engine = $match[2];
120
+			if (!empty($match[2])) {
121
+							$engine = $match[2];
122
+			}
117 123
 
118
-			if (!empty($match[5]))
119
-				$charset = $match[5];
124
+			if (!empty($match[5])) {
125
+							$charset = $match[5];
126
+			}
120 127
 
121
-			if (!empty($match[7]))
122
-				$collate = $match[7];
128
+			if (!empty($match[7])) {
129
+							$collate = $match[7];
130
+			}
123 131
 		}
124 132
 
125 133
 		// Skip everything but keys...
126
-		if (strpos($l, 'KEY') === false)
127
-			unset($create[$k]);
134
+		if (strpos($l, 'KEY') === false) {
135
+					unset($create[$k]);
136
+		}
128 137
 	}
129 138
 
130
-	if (!empty($create))
131
-		$create = '(
139
+	if (!empty($create)) {
140
+			$create = '(
132 141
 			' . implode('
133 142
 			', $create) . ')';
134
-	else
135
-		$create = '';
143
+	} else {
144
+			$create = '';
145
+	}
136 146
 
137 147
 	$request = $smcFunc['db_query']('', '
138 148
 		CREATE TABLE {raw:backup_table} {raw:create}
@@ -151,8 +161,9 @@  discard block
 block discarded – undo
151 161
 
152 162
 	if ($auto_inc != '')
153 163
 	{
154
-		if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',')
155
-			$auto_inc = substr($auto_inc, 0, -1);
164
+		if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',') {
165
+					$auto_inc = substr($auto_inc, 0, -1);
166
+		}
156 167
 
157 168
 		$smcFunc['db_query']('', '
158 169
 			ALTER TABLE {raw:backup_table}
@@ -196,8 +207,9 @@  discard block
 block discarded – undo
196 207
 				'table' => $table,
197 208
 			)
198 209
 		);
199
-	if (!$request)
200
-		return -1;
210
+	if (!$request) {
211
+			return -1;
212
+	}
201 213
 
202 214
 	// How much left?
203 215
 	$request = $smcFunc['db_query']('', '
@@ -240,8 +252,9 @@  discard block
 block discarded – undo
240 252
 		)
241 253
 	);
242 254
 	$tables = array();
243
-	while ($row = $smcFunc['db_fetch_row']($request))
244
-		$tables[] = $row[0];
255
+	while ($row = $smcFunc['db_fetch_row']($request)) {
256
+			$tables[] = $row[0];
257
+	}
245 258
 	$smcFunc['db_free_result']($request);
246 259
 
247 260
 	return $tables;
@@ -285,8 +298,9 @@  discard block
 block discarded – undo
285 298
 		if (!empty($row['Default']) || $row['Null'] !== 'YES')
286 299
 		{
287 300
 			// Make a special case of auto-timestamp.
288
-			if ($row['Default'] == 'CURRENT_TIMESTAMP')
289
-				$schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */';
301
+			if ($row['Default'] == 'CURRENT_TIMESTAMP') {
302
+							$schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */';
303
+			}
290 304
 			// Text shouldn't have a default.
291 305
 			elseif ($row['Default'] !== null)
292 306
 			{
@@ -321,14 +335,16 @@  discard block
 block discarded – undo
321 335
 		$row['Key_name'] = $row['Key_name'] == 'PRIMARY' ? 'PRIMARY KEY' : (empty($row['Non_unique']) ? 'UNIQUE ' : ($row['Comment'] == 'FULLTEXT' || (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') ? 'FULLTEXT ' : 'KEY ')) . '`' . $row['Key_name'] . '`';
322 336
 
323 337
 		// Is this the first column in the index?
324
-		if (empty($indexes[$row['Key_name']]))
325
-			$indexes[$row['Key_name']] = array();
338
+		if (empty($indexes[$row['Key_name']])) {
339
+					$indexes[$row['Key_name']] = array();
340
+		}
326 341
 
327 342
 		// A sub part, like only indexing 15 characters of a varchar.
328
-		if (!empty($row['Sub_part']))
329
-			$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')';
330
-		else
331
-			$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`';
343
+		if (!empty($row['Sub_part'])) {
344
+					$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')';
345
+		} else {
346
+					$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`';
347
+		}
332 348
 	}
333 349
 	$smcFunc['db_free_result']($result);
334 350
 
@@ -366,8 +382,9 @@  discard block
 block discarded – undo
366 382
 {
367 383
 	static $ver;
368 384
 
369
-	if (!empty($ver))
370
-		return $ver;
385
+	if (!empty($ver)) {
386
+			return $ver;
387
+	}
371 388
 
372 389
 	global $smcFunc;
373 390
 
@@ -392,8 +409,9 @@  discard block
 block discarded – undo
392 409
 	global $smcFunc;
393 410
 	static $db_type;
394 411
 
395
-	if (!empty($db_type))
396
-		return $db_type;
412
+	if (!empty($db_type)) {
413
+			return $db_type;
414
+	}
397 415
 
398 416
 	$request = $smcFunc['db_query']('', 'SELECT @@version_comment');
399 417
 	list ($comment) = $smcFunc['db_fetch_row']($request);
@@ -402,13 +420,15 @@  discard block
 block discarded – undo
402 420
 	// Skip these if we don't have a comment.
403 421
 	if (!empty($comment))
404 422
 	{
405
-		if (stripos($comment, 'percona') !== false)
406
-			return 'Percona';
407
-		if (stripos($comment, 'mariadb') !== false)
408
-			return 'MariaDB';
423
+		if (stripos($comment, 'percona') !== false) {
424
+					return 'Percona';
425
+		}
426
+		if (stripos($comment, 'mariadb') !== false) {
427
+					return 'MariaDB';
428
+		}
429
+	} else {
430
+			return 'fail';
409 431
 	}
410
-	else
411
-		return 'fail';
412 432
 
413 433
 	return 'MySQL';
414 434
 }
@@ -421,10 +441,11 @@  discard block
 block discarded – undo
421 441
 function smf_db_allow_persistent()
422 442
 {
423 443
 	$value = ini_get('mysqli.allow_persistent');
424
-	if (strtolower($value) == 'on' || strtolower($value) == 'true' || $value == '1')
425
-		return true;
426
-	else
427
-		return false;
428
-}
444
+	if (strtolower($value) == 'on' || strtolower($value) == 'true' || $value == '1') {
445
+			return true;
446
+	} else {
447
+			return false;
448
+	}
449
+	}
429 450
 
430 451
 ?>
431 452
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/DbExtra-postgresql.php 1 patch
Braces   +43 added lines, -32 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Add the functions implemented in this file to the $smcFunc array.
@@ -23,8 +24,8 @@  discard block
 block discarded – undo
23 24
 {
24 25
 	global $smcFunc;
25 26
 
26
-	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table')
27
-		$smcFunc += array(
27
+	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') {
28
+			$smcFunc += array(
28 29
 			'db_backup_table' => 'smf_db_backup_table',
29 30
 			'db_optimize_table' => 'smf_db_optimize_table',
30 31
 			'db_table_sql' => 'smf_db_table_sql',
@@ -33,7 +34,8 @@  discard block
 block discarded – undo
33 34
 			'db_get_vendor' => 'smf_db_get_vendor',
34 35
 			'db_allow_persistent' => 'smf_db_allow_persistent',
35 36
 		);
36
-}
37
+	}
38
+	}
37 39
 
38 40
 /**
39 41
  * Backup $table to $backup_table.
@@ -49,13 +51,14 @@  discard block
 block discarded – undo
49 51
 
50 52
 	// Do we need to drop it first?
51 53
 	$tables = smf_db_list_tables(false, $backup_table);
52
-	if (!empty($tables))
53
-		$smcFunc['db_query']('', '
54
+	if (!empty($tables)) {
55
+			$smcFunc['db_query']('', '
54 56
 			DROP TABLE {raw:backup_table}',
55 57
 			array(
56 58
 				'backup_table' => $backup_table,
57 59
 			)
58 60
 		);
61
+	}
59 62
 
60 63
 	/**
61 64
 	 * @todo Should we create backups of sequences as well?
@@ -118,8 +121,9 @@  discard block
 block discarded – undo
118 121
 			)
119 122
 		);
120 123
 
121
-	if (!$request)
122
-		return -1;
124
+	if (!$request) {
125
+			return -1;
126
+	}
123 127
 
124 128
 	$request = $smcFunc['db_query']('', '
125 129
 		SELECT pg_relation_size(C.oid) AS "size"
@@ -137,11 +141,12 @@  discard block
 block discarded – undo
137 141
 	$row = $smcFunc['db_fetch_assoc']($request);
138 142
 	$smcFunc['db_free_result']($request);
139 143
 
140
-	if (isset($row['size']))
141
-			return ($old_size - $row['size']) / 1024;
142
-	else
143
-		return 0;
144
-}
144
+	if (isset($row['size'])) {
145
+				return ($old_size - $row['size']) / 1024;
146
+	} else {
147
+			return 0;
148
+	}
149
+	}
145 150
 
146 151
 /**
147 152
  * This function lists all tables in the database.
@@ -168,8 +173,9 @@  discard block
 block discarded – undo
168 173
 	);
169 174
 
170 175
 	$tables = array();
171
-	while ($row = $smcFunc['db_fetch_row']($request))
172
-		$tables[] = $row[0];
176
+	while ($row = $smcFunc['db_fetch_row']($request)) {
177
+			$tables[] = $row[0];
178
+	}
173 179
 	$smcFunc['db_free_result']($request);
174 180
 
175 181
 	return $tables;
@@ -210,12 +216,14 @@  discard block
 block discarded – undo
210 216
 	);
211 217
 	while ($row = $smcFunc['db_fetch_assoc']($result))
212 218
 	{
213
-		if ($row['data_type'] == 'character varying')
214
-			$row['data_type'] = 'varchar';
215
-		elseif ($row['data_type'] == 'character')
216
-			$row['data_type'] = 'char';
217
-		if ($row['character_maximum_length'])
218
-			$row['data_type'] .= '(' . $row['character_maximum_length'] . ')';
219
+		if ($row['data_type'] == 'character varying') {
220
+					$row['data_type'] = 'varchar';
221
+		} elseif ($row['data_type'] == 'character') {
222
+					$row['data_type'] = 'char';
223
+		}
224
+		if ($row['character_maximum_length']) {
225
+					$row['data_type'] .= '(' . $row['character_maximum_length'] . ')';
226
+		}
219 227
 
220 228
 		// Make the CREATE for this column.
221 229
 		$schema_create .= ' "' . $row['column_name'] . '" ' . $row['data_type'] . ($row['is_nullable'] != 'YES' ? ' NOT NULL' : '');
@@ -266,13 +274,14 @@  discard block
 block discarded – undo
266 274
 	{
267 275
 		if ($row['is_primary'])
268 276
 		{
269
-			if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0)
270
-				continue;
277
+			if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) {
278
+							continue;
279
+			}
271 280
 
272 281
 			$index_create .= $crlf . 'ALTER TABLE ' . $tableName . ' ADD PRIMARY KEY ("' . $matches[1] . '");';
282
+		} else {
283
+					$index_create .= $crlf . $row['inddef'] . ';';
273 284
 		}
274
-		else
275
-			$index_create .= $crlf . $row['inddef'] . ';';
276 285
 	}
277 286
 	$smcFunc['db_free_result']($result);
278 287
 
@@ -291,8 +300,9 @@  discard block
 block discarded – undo
291 300
 	global $db_connection;
292 301
 	static $ver;
293 302
 
294
-	if(!empty($ver))
295
-		return $ver;
303
+	if(!empty($ver)) {
304
+			return $ver;
305
+	}
296 306
 
297 307
 	$ver = pg_version($db_connection)['server'];
298 308
 
@@ -317,10 +327,11 @@  discard block
 block discarded – undo
317 327
 function smf_db_allow_persistent()
318 328
 {
319 329
 	$value = ini_get('pgsql.allow_persistent');
320
-	if (strtolower($value) == 'on' || strtolower($value) == 'true' || $value == '1')
321
-		return true;
322
-	else
323
-		return false;
324
-}
330
+	if (strtolower($value) == 'on' || strtolower($value) == 'true' || $value == '1') {
331
+			return true;
332
+	} else {
333
+			return false;
334
+	}
335
+	}
325 336
 
326 337
 ?>
327 338
\ No newline at end of file
Please login to merge, or discard this patch.
proxy.php 1 patch
Braces   +35 added lines, -23 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
 	define('SMF', 'proxy');
18
+}
18 19
 
19 20
 global $proxyhousekeeping;
20 21
 
@@ -68,30 +69,35 @@  discard block
 block discarded – undo
68 69
 	 */
69 70
 	public function checkRequest()
70 71
 	{
71
-		if (!$this->enabled)
72
-			return false;
72
+		if (!$this->enabled) {
73
+					return false;
74
+		}
73 75
 
74 76
 		// Try to create the image cache directory if it doesn't exist
75
-		if (!file_exists($this->cache))
76
-			if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php'))
77
+		if (!file_exists($this->cache)) {
78
+					if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php'))
77 79
 				return false;
80
+		}
78 81
 
79 82
 		// Basic sanity check
80 83
 		$_GET['request'] = filter_var($_GET['request'], FILTER_VALIDATE_URL);
81 84
 
82 85
 		// We aren't going anywhere without these
83
-		if (empty($_GET['hash']) || empty($_GET['request']))
84
-			return false;
86
+		if (empty($_GET['hash']) || empty($_GET['request'])) {
87
+					return false;
88
+		}
85 89
 
86 90
 		$hash = $_GET['hash'];
87 91
 		$request = $_GET['request'];
88 92
 
89
-		if (md5($request . $this->secret) != $hash)
90
-			return false;
93
+		if (md5($request . $this->secret) != $hash) {
94
+					return false;
95
+		}
91 96
 
92 97
 		// Attempt to cache the request if it doesn't exist
93
-		if (!$this->isCached($request))
94
-			return $this->cacheImage($request);
98
+		if (!$this->isCached($request)) {
99
+					return $this->cacheImage($request);
100
+		}
95 101
 
96 102
 		return true;
97 103
 	}
@@ -128,8 +134,9 @@  discard block
 block discarded – undo
128 134
 		if (!$cached || $time - $cached['time'] > ($this->maxDays * 86400))
129 135
 		{
130 136
 			@unlink($cached_file);
131
-			if ($this->checkRequest())
132
-				$this->serve();
137
+			if ($this->checkRequest()) {
138
+							$this->serve();
139
+			}
133 140
 			$this::redirectexit($request);
134 141
 		}
135 142
 
@@ -142,8 +149,9 @@  discard block
 block discarded – undo
142 149
 
143 150
 		// Make sure we're serving an image
144 151
 		$contentParts = explode('/', !empty($cached['content_type']) ? $cached['content_type'] : '');
145
-		if ($contentParts[0] != 'image')
146
-			exit;
152
+		if ($contentParts[0] != 'image') {
153
+					exit;
154
+		}
147 155
 
148 156
 		$max_age = $time - $cached['time'] + (5 * 86400);
149 157
 		header('content-type: ' . $cached['content_type']);
@@ -193,25 +201,29 @@  discard block
 block discarded – undo
193 201
 		$image = fetch_web_data($request);
194 202
 
195 203
 		// Looks like nobody was home
196
-		if (empty($image))
197
-			return -1;
204
+		if (empty($image)) {
205
+					return -1;
206
+		}
198 207
 
199 208
 		// What kind of file did they give us?
200 209
 		$finfo = finfo_open(FILEINFO_MIME_TYPE);
201 210
 		$mime_type = finfo_buffer($finfo, $image);
202 211
 
203 212
 		// SVG needs a little extra care
204
-		if ($ext == 'svg' && $mime_type == 'text/plain')
205
-			$mime_type = 'image/svg+xml';
213
+		if ($ext == 'svg' && $mime_type == 'text/plain') {
214
+					$mime_type = 'image/svg+xml';
215
+		}
206 216
 
207 217
 		// Make sure the url is returning an image
208
-		if (strpos($mime_type, 'image/') !== 0)
209
-			return -1;
218
+		if (strpos($mime_type, 'image/') !== 0) {
219
+					return -1;
220
+		}
210 221
 
211 222
 		// Validate the filesize
212 223
 		$size = strlen($image);
213
-		if ($size > ($this->maxSize * 1024))
214
-			return 0;
224
+		if ($size > ($this->maxSize * 1024)) {
225
+					return 0;
226
+		}
215 227
 
216 228
 		// Cache it for later
217 229
 		return file_put_contents($dest, json_encode(array(
Please login to merge, or discard this patch.