Completed
Pull Request — release-2.1 (#5028)
by 01
06:01
created
Themes/default/ManageScheduledTasks.template.php 1 patch
Braces   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -20,13 +20,12 @@  discard block
 block discarded – undo
20 20
 	// We completed some tasks?
21 21
 	if (!empty($context['tasks_were_run']))
22 22
 	{
23
-		if (empty($context['scheduled_errors']))
24
-			echo '
23
+		if (empty($context['scheduled_errors'])) {
24
+					echo '
25 25
 	<div class="infobox">
26 26
 		', $txt['scheduled_tasks_were_run'], '
27 27
 	</div>';
28
-
29
-		else
28
+		} else
30 29
 		{
31 30
 			echo '
32 31
 	<div class="errorbox" id="errors">
@@ -35,14 +34,15 @@  discard block
 block discarded – undo
35 34
 				<strong id="error_serious">', $txt['scheduled_tasks_were_run_errors'], '</strong>
36 35
 			</dt>';
37 36
 
38
-			foreach ($context['scheduled_errors'] as $task => $errors)
39
-				echo '
37
+			foreach ($context['scheduled_errors'] as $task => $errors) {
38
+							echo '
40 39
 			<dd class="error">
41 40
 				<strong>', isset($txt['scheduled_task_' . $task]) ? $txt['scheduled_task_' . $task] : $task, '</strong>
42 41
 				<ul>
43 42
 					<li>', implode('</li><li>', $errors), '</li>
44 43
 				</ul>
45 44
 			</dd>';
45
+			}
46 46
 
47 47
 			echo '
48 48
 		</dl>
Please login to merge, or discard this patch.
Themes/default/ReportToMod.template.php 1 patch
Braces   +6 added lines, -5 removed lines patch added patch discarded remove patch
@@ -62,16 +62,17 @@
 block discarded – undo
62 62
 				<div id="error_box" class="errorbox">
63 63
 					<ul id="error_list">';
64 64
 
65
-		foreach ($context['post_errors'] as $key => $error)
66
-			echo '
65
+		foreach ($context['post_errors'] as $key => $error) {
66
+					echo '
67 67
 						<li id="error_', $key, '" class="error">', $error, '</li>';
68
+		}
68 69
 
69 70
 		echo '
70 71
 					</ul>';
71
-	}
72
-	else
73
-		echo '
72
+	} else {
73
+			echo '
74 74
 				<div style="display:none" id="error_box" class="errorbox">';
75
+	}
75 76
 
76 77
 	echo '
77 78
 				</div>';
Please login to merge, or discard this patch.
Themes/default/Reports.template.php 1 patch
Braces   +32 added lines, -24 removed lines patch added patch discarded remove patch
@@ -29,9 +29,10 @@  discard block
 block discarded – undo
29 29
 	// Go through each type of report they can run.
30 30
 	foreach ($context['report_types'] as $type)
31 31
 	{
32
-		if (isset($type['description']))
33
-			echo '
32
+		if (isset($type['description'])) {
33
+					echo '
34 34
 					<dt>', $type['description'], '</dt>';
35
+		}
35 36
 
36 37
 		echo '
37 38
 					<dd>
@@ -62,8 +63,9 @@  discard block
 block discarded – undo
62 63
 		</div>
63 64
 		<div id="report_buttons">';
64 65
 
65
-	if (!empty($context['report_buttons']))
66
-		template_button_strip($context['report_buttons'], 'right');
66
+	if (!empty($context['report_buttons'])) {
67
+			template_button_strip($context['report_buttons'], 'right');
68
+	}
67 69
 
68 70
 	echo '
69 71
 		</div>';
@@ -74,25 +76,27 @@  discard block
 block discarded – undo
74 76
 		echo '
75 77
 		<table class="table_grid report_results">';
76 78
 
77
-		if (!empty($table['title']))
78
-			echo '
79
+		if (!empty($table['title'])) {
80
+					echo '
79 81
 			<thead>
80 82
 				<tr class="title_bar">
81 83
 					<th scope="col" colspan="', $table['column_count'], '">', $table['title'], '</th>
82 84
 				</tr>
83 85
 			</thead>
84 86
 			<tbody>';
87
+		}
85 88
 
86 89
 		// Now do each row!
87 90
 		$row_number = 0;
88 91
 		foreach ($table['data'] as $row)
89 92
 		{
90
-			if ($row_number == 0 && !empty($table['shading']['top']))
91
-				echo '
93
+			if ($row_number == 0 && !empty($table['shading']['top'])) {
94
+							echo '
92 95
 				<tr class="windowbg table_caption">';
93
-			else
94
-				echo '
96
+			} else {
97
+							echo '
95 98
 				<tr class="', !empty($row[0]['separator']) ? 'title_bar' : 'windowbg', '">';
99
+			}
96 100
 
97 101
 			// Now do each column.
98 102
 			$column_number = 0;
@@ -110,16 +114,17 @@  discard block
 block discarded – undo
110 114
 				}
111 115
 
112 116
 				// Shaded?
113
-				if ($column_number == 0 && !empty($table['shading']['left']))
114
-					echo '
117
+				if ($column_number == 0 && !empty($table['shading']['left'])) {
118
+									echo '
115 119
 					<td class="table_caption ', $table['align']['shaded'], 'text"', $table['width']['shaded'] != 'auto' ? ' width="' . $table['width']['shaded'] . '"' : '', '>
116 120
 						', $data['v'] == $table['default_value'] ? '' : ($data['v'] . (empty($data['v']) ? '' : ':')), '
117 121
 					</td>';
118
-				else
119
-					echo '
122
+				} else {
123
+									echo '
120 124
 					<td class="smalltext centertext" ', $table['width']['normal'] != 'auto' ? ' width="' . $table['width']['normal'] . '"' : '', !empty($data['style']) ? ' style="' . $data['style'] . '"' : '', '>
121 125
 						', $data['v'], '
122 126
 					</td>';
127
+				}
123 128
 
124 129
 				$column_number++;
125 130
 			}
@@ -168,24 +173,26 @@  discard block
 block discarded – undo
168 173
 		<div style="overflow: visible;', $table['max_width'] != 'auto' ? ' width: ' . $table['max_width'] . 'px;' : '', '">
169 174
 			<table class="bordercolor">';
170 175
 
171
-		if (!empty($table['title']))
172
-			echo '
176
+		if (!empty($table['title'])) {
177
+					echo '
173 178
 				<tr class="title_bar">
174 179
 					<td colspan="', $table['column_count'], '">
175 180
 						', $table['title'], '
176 181
 					</td>
177 182
 				</tr>';
183
+		}
178 184
 
179 185
 		// Now do each row!
180 186
 		$row_number = 0;
181 187
 		foreach ($table['data'] as $row)
182 188
 		{
183
-			if ($row_number == 0 && !empty($table['shading']['top']))
184
-				echo '
189
+			if ($row_number == 0 && !empty($table['shading']['top'])) {
190
+							echo '
185 191
 				<tr class="titlebg">';
186
-			else
187
-				echo '
192
+			} else {
193
+							echo '
188 194
 				<tr class="windowbg">';
195
+			}
189 196
 
190 197
 			// Now do each column!!
191 198
 			$column_number = 0;
@@ -202,16 +209,17 @@  discard block
 block discarded – undo
202 209
 				}
203 210
 
204 211
 				// Shaded?
205
-				if ($column_number == 0 && !empty($table['shading']['left']))
206
-					echo '
212
+				if ($column_number == 0 && !empty($table['shading']['left'])) {
213
+									echo '
207 214
 					<td class="titlebg ', $table['align']['shaded'], 'text"', $table['width']['shaded'] != 'auto' ? ' width="' . $table['width']['shaded'] . '"' : '', '>
208 215
 						', $data['v'] == $table['default_value'] ? '' : ($data['v'] . (empty($data['v']) ? '' : ':')), '
209 216
 					</td>';
210
-				else
211
-					echo '
217
+				} else {
218
+									echo '
212 219
 					<td class="centertext" ', $table['width']['normal'] != 'auto' ? ' width="' . $table['width']['normal'] . '"' : '', !empty($data['style']) ? ' style="' . $data['style'] . '"' : '', '>
213 220
 						', $data['v'], '
214 221
 					</td>';
222
+				}
215 223
 
216 224
 				$column_number++;
217 225
 			}
Please login to merge, or discard this patch.
Sources/ManageSearch.php 1 patch
Braces   +109 added lines, -90 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
  * Main entry point for the admin search settings screen.
@@ -107,11 +108,13 @@  discard block
 block discarded – undo
107 108
 	// Perhaps the search method wants to add some settings?
108 109
 	require_once($sourcedir . '/Search.php');
109 110
 	$searchAPI = findSearchAPI();
110
-	if (is_callable(array($searchAPI, 'searchSettings')))
111
-		call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars));
111
+	if (is_callable(array($searchAPI, 'searchSettings'))) {
112
+			call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars));
113
+	}
112 114
 
113
-	if ($return_config)
114
-		return $config_vars;
115
+	if ($return_config) {
116
+			return $config_vars;
117
+	}
115 118
 
116 119
 	$context['page_title'] = $txt['search_settings_title'];
117 120
 	$context['sub_template'] = 'show_settings';
@@ -126,8 +129,9 @@  discard block
 block discarded – undo
126 129
 
127 130
 		call_integration_hook('integrate_save_search_settings');
128 131
 
129
-		if (empty($_POST['search_results_per_page']))
130
-			$_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages'];
132
+		if (empty($_POST['search_results_per_page'])) {
133
+					$_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages'];
134
+		}
131 135
 		saveDBSettings($config_vars);
132 136
 		$_SESSION['adm-save'] = true;
133 137
 		redirectexit('action=admin;area=managesearch;sa=settings;' . $context['session_var'] . '=' . $context['session_id']);
@@ -177,17 +181,20 @@  discard block
 block discarded – undo
177 181
 		call_integration_hook('integrate_save_search_weights');
178 182
 
179 183
 		$changes = array();
180
-		foreach ($factors as $factor)
181
-			$changes[$factor] = (int) $_POST[$factor];
184
+		foreach ($factors as $factor) {
185
+					$changes[$factor] = (int) $_POST[$factor];
186
+		}
182 187
 		updateSettings($changes);
183 188
 	}
184 189
 
185 190
 	$context['relative_weights'] = array('total' => 0);
186
-	foreach ($factors as $factor)
187
-		$context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0;
191
+	foreach ($factors as $factor) {
192
+			$context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0;
193
+	}
188 194
 
189
-	foreach ($factors as $factor)
190
-		$context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1);
195
+	foreach ($factors as $factor) {
196
+			$context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1);
197
+	}
191 198
 
192 199
 	createToken('admin-msw');
193 200
 }
@@ -215,8 +222,9 @@  discard block
 block discarded – undo
215 222
 	$context['search_apis'] = loadSearchAPIs();
216 223
 
217 224
 	// Detect whether a fulltext index is set.
218
-	if ($context['supports_fulltext'])
219
-		detectFulltextIndex();
225
+	if ($context['supports_fulltext']) {
226
+			detectFulltextIndex();
227
+	}
220 228
 
221 229
 	if (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'createfulltext')
222 230
 	{
@@ -240,8 +248,7 @@  discard block
 block discarded – undo
240 248
 					'language' => $language_ftx
241 249
 				)
242 250
 			);
243
-		}
244
-		else
251
+		} else
245 252
 		{
246 253
 			// Make sure it's gone before creating it.
247 254
 			$smcFunc['db_query']('', '
@@ -259,8 +266,7 @@  discard block
 block discarded – undo
259 266
 				)
260 267
 			);
261 268
 		}
262
-	}
263
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
269
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
264 270
 	{
265 271
 		checkSession('get');
266 272
 		validateToken('admin-msm', 'get');
@@ -277,12 +283,12 @@  discard block
 block discarded – undo
277 283
 		$context['fulltext_index'] = array();
278 284
 
279 285
 		// Go back to the default search method.
280
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext')
281
-			updateSettings(array(
286
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') {
287
+					updateSettings(array(
282 288
 				'search_index' => '',
283 289
 			));
284
-	}
285
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
290
+		}
291
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
286 292
 	{
287 293
 		checkSession('get');
288 294
 		validateToken('admin-msm', 'get');
@@ -304,12 +310,12 @@  discard block
 block discarded – undo
304 310
 		));
305 311
 
306 312
 		// Go back to the default search method.
307
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
308
-			updateSettings(array(
313
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
314
+					updateSettings(array(
309 315
 				'search_index' => '',
310 316
 			));
311
-	}
312
-	elseif (isset($_POST['save']))
317
+		}
318
+	} elseif (isset($_POST['save']))
313 319
 	{
314 320
 		checkSession();
315 321
 		validateToken('admin-msmpost');
@@ -331,8 +337,8 @@  discard block
 block discarded – undo
331 337
 	// Get some info about the messages table, to show its size and index size.
332 338
 	if ($db_type == 'mysql')
333 339
 	{
334
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
335
-			$request = $smcFunc['db_query']('', '
340
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
341
+					$request = $smcFunc['db_query']('', '
336 342
 				SHOW TABLE STATUS
337 343
 				FROM {string:database_name}
338 344
 				LIKE {string:table_name}',
@@ -341,14 +347,15 @@  discard block
 block discarded – undo
341 347
 					'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
342 348
 				)
343 349
 			);
344
-		else
345
-			$request = $smcFunc['db_query']('', '
350
+		} else {
351
+					$request = $smcFunc['db_query']('', '
346 352
 				SHOW TABLE STATUS
347 353
 				LIKE {string:table_name}',
348 354
 				array(
349 355
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
350 356
 				)
351 357
 			);
358
+		}
352 359
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
353 360
 		{
354 361
 			// Only do this if the user has permission to execute this query.
@@ -360,8 +367,8 @@  discard block
 block discarded – undo
360 367
 		}
361 368
 
362 369
 		// Now check the custom index table, if it exists at all.
363
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
364
-			$request = $smcFunc['db_query']('', '
370
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
371
+					$request = $smcFunc['db_query']('', '
365 372
 				SHOW TABLE STATUS
366 373
 				FROM {string:database_name}
367 374
 				LIKE {string:table_name}',
@@ -370,14 +377,15 @@  discard block
 block discarded – undo
370 377
 					'table_name' => str_replace('_', '\_', $match[2]) . 'log_search_words',
371 378
 				)
372 379
 			);
373
-		else
374
-			$request = $smcFunc['db_query']('', '
380
+		} else {
381
+					$request = $smcFunc['db_query']('', '
375 382
 				SHOW TABLE STATUS
376 383
 				LIKE {string:table_name}',
377 384
 				array(
378 385
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'log_search_words',
379 386
 				)
380 387
 			);
388
+		}
381 389
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
382 390
 		{
383 391
 			// Only do this if the user has permission to execute this query.
@@ -386,8 +394,7 @@  discard block
 block discarded – undo
386 394
 			$context['table_info']['custom_index_length'] = $row['Data_length'] + $row['Index_length'];
387 395
 			$smcFunc['db_free_result']($request);
388 396
 		}
389
-	}
390
-	elseif ($db_type == 'postgresql')
397
+	} elseif ($db_type == 'postgresql')
391 398
 	{
392 399
 		// In order to report the sizes correctly we need to perform vacuum (optimize) on the tables we will be using.
393 400
 		//db_extend();
@@ -429,38 +436,38 @@  discard block
 block discarded – undo
429 436
 					$context['table_info']['data_length'] = (int) $row['table_size'];
430 437
 					$context['table_info']['index_length'] = (int) $row['index_size'];
431 438
 					$context['table_info']['fulltext_length'] = (int) $row['index_size'];
432
-				}
433
-				elseif ($row['indexname'] == $db_prefix . 'log_search_words')
439
+				} elseif ($row['indexname'] == $db_prefix . 'log_search_words')
434 440
 				{
435 441
 					$context['table_info']['index_length'] = (int) $row['index_size'];
436 442
 					$context['table_info']['custom_index_length'] = (int) $row['index_size'];
437 443
 				}
438 444
 			}
439 445
 			$smcFunc['db_free_result']($request);
440
-		}
441
-		else
442
-			// Didn't work for some reason...
446
+		} else {
447
+					// Didn't work for some reason...
443 448
 			$context['table_info'] = array(
444 449
 				'data_length' => $txt['not_applicable'],
445 450
 				'index_length' => $txt['not_applicable'],
446 451
 				'fulltext_length' => $txt['not_applicable'],
447 452
 				'custom_index_length' => $txt['not_applicable'],
448 453
 			);
449
-	}
450
-	else
451
-		$context['table_info'] = array(
454
+		}
455
+	} else {
456
+			$context['table_info'] = array(
452 457
 			'data_length' => $txt['not_applicable'],
453 458
 			'index_length' => $txt['not_applicable'],
454 459
 			'fulltext_length' => $txt['not_applicable'],
455 460
 			'custom_index_length' => $txt['not_applicable'],
456 461
 		);
462
+	}
457 463
 
458 464
 	// Format the data and index length in kilobytes.
459 465
 	foreach ($context['table_info'] as $type => $size)
460 466
 	{
461 467
 		// If it's not numeric then just break.  This database engine doesn't support size.
462
-		if (!is_numeric($size))
463
-			break;
468
+		if (!is_numeric($size)) {
469
+					break;
470
+		}
464 471
 
465 472
 		$context['table_info'][$type] = comma_format($context['table_info'][$type] / 1024) . ' ' . $txt['search_method_kilobytes'];
466 473
 	}
@@ -489,8 +496,9 @@  discard block
 block discarded – undo
489 496
 
490 497
 	// Scotty, we need more time...
491 498
 	@set_time_limit(600);
492
-	if (function_exists('apache_reset_timeout'))
493
-		@apache_reset_timeout();
499
+	if (function_exists('apache_reset_timeout')) {
500
+			@apache_reset_timeout();
501
+	}
494 502
 
495 503
 	$context[$context['admin_menu_name']]['current_subsection'] = 'method';
496 504
 	$context['page_title'] = $txt['search_index_custom'];
@@ -520,8 +528,7 @@  discard block
 block discarded – undo
520 528
 		$context['start'] = (int) $context['index_settings']['resume_at'];
521 529
 		unset($context['index_settings']['resume_at']);
522 530
 		$context['step'] = 1;
523
-	}
524
-	else
531
+	} else
525 532
 	{
526 533
 		$context['index_settings'] = array(
527 534
 			'bytes_per_word' => isset($_REQUEST['bytes_per_word']) && isset($index_properties[$_REQUEST['bytes_per_word']]) ? (int) $_REQUEST['bytes_per_word'] : 2,
@@ -530,12 +537,14 @@  discard block
 block discarded – undo
530 537
 		$context['step'] = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0;
531 538
 
532 539
 		// admin timeouts are painful when building these long indexes - but only if we actually have such things enabled
533
-		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1)
534
-			$_SESSION['admin_time'] = time();
540
+		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) {
541
+					$_SESSION['admin_time'] = time();
542
+		}
535 543
 	}
536 544
 
537
-	if ($context['step'] !== 0)
538
-		checkSession('request');
545
+	if ($context['step'] !== 0) {
546
+			checkSession('request');
547
+	}
539 548
 
540 549
 	// Step 0: let the user determine how they like their index.
541 550
 	if ($context['step'] === 0)
@@ -564,12 +573,14 @@  discard block
 block discarded – undo
564 573
 			$smcFunc['db_create_word_search']($index_properties[$context['index_settings']['bytes_per_word']]['column_definition']);
565 574
 
566 575
 			// Temporarily switch back to not using a search index.
567
-			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
568
-				updateSettings(array('search_index' => ''));
576
+			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
577
+							updateSettings(array('search_index' => ''));
578
+			}
569 579
 
570 580
 			// Don't let simultanious processes be updating the search index.
571
-			if (!empty($modSettings['search_custom_index_config']))
572
-				updateSettings(array('search_custom_index_config' => ''));
581
+			if (!empty($modSettings['search_custom_index_config'])) {
582
+							updateSettings(array('search_custom_index_config' => ''));
583
+			}
573 584
 		}
574 585
 
575 586
 		$num_messages = array(
@@ -585,16 +596,16 @@  discard block
 block discarded – undo
585 596
 				'starting_id' => $context['start'],
586 597
 			)
587 598
 		);
588
-		while ($row = $smcFunc['db_fetch_assoc']($request))
589
-			$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
599
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
600
+					$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
601
+		}
590 602
 
591 603
 		if (empty($num_messages['todo']))
592 604
 		{
593 605
 			$context['step'] = 2;
594 606
 			$context['percentage'] = 80;
595 607
 			$context['start'] = 0;
596
-		}
597
-		else
608
+		} else
598 609
 		{
599 610
 			// Number of seconds before the next step.
600 611
 			$stop = time() + 3;
@@ -635,21 +646,22 @@  discard block
 block discarded – undo
635 646
 
636 647
 				$context['start'] += $forced_break ? $number_processed : $messages_per_batch;
637 648
 
638
-				if (!empty($inserts))
639
-					$smcFunc['db_insert']('ignore',
649
+				if (!empty($inserts)) {
650
+									$smcFunc['db_insert']('ignore',
640 651
 						'{db_prefix}log_search_words',
641 652
 						array('id_word' => 'int', 'id_msg' => 'int'),
642 653
 						$inserts,
643 654
 						array('id_word', 'id_msg')
644 655
 					);
656
+				}
645 657
 				if ($num_messages['todo'] === 0)
646 658
 				{
647 659
 					$context['step'] = 2;
648 660
 					$context['start'] = 0;
649 661
 					break;
662
+				} else {
663
+									updateSettings(array('search_custom_index_resume' => $smcFunc['json_encode'](array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
650 664
 				}
651
-				else
652
-					updateSettings(array('search_custom_index_resume' => $smcFunc['json_encode'](array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
653 665
 			}
654 666
 
655 667
 			// Since there are still two steps to go, 80% is the maximum here.
@@ -660,9 +672,9 @@  discard block
 block discarded – undo
660 672
 	// Step 2: removing the words that occur too often and are of no use.
661 673
 	elseif ($context['step'] === 2)
662 674
 	{
663
-		if ($context['index_settings']['bytes_per_word'] < 4)
664
-			$context['step'] = 3;
665
-		else
675
+		if ($context['index_settings']['bytes_per_word'] < 4) {
676
+					$context['step'] = 3;
677
+		} else
666 678
 		{
667 679
 			$stop_words = $context['start'] === 0 || empty($modSettings['search_stopwords']) ? array() : explode(',', $modSettings['search_stopwords']);
668 680
 			$stop = time() + 3;
@@ -683,20 +695,22 @@  discard block
 block discarded – undo
683 695
 						'minimum_messages' => $max_messages,
684 696
 					)
685 697
 				);
686
-				while ($row = $smcFunc['db_fetch_assoc']($request))
687
-					$stop_words[] = $row['id_word'];
698
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
699
+									$stop_words[] = $row['id_word'];
700
+				}
688 701
 				$smcFunc['db_free_result']($request);
689 702
 
690 703
 				updateSettings(array('search_stopwords' => implode(',', $stop_words)));
691 704
 
692
-				if (!empty($stop_words))
693
-					$smcFunc['db_query']('', '
705
+				if (!empty($stop_words)) {
706
+									$smcFunc['db_query']('', '
694 707
 						DELETE FROM {db_prefix}log_search_words
695 708
 						WHERE id_word in ({array_int:stop_words})',
696 709
 						array(
697 710
 							'stop_words' => $stop_words,
698 711
 						)
699 712
 					);
713
+				}
700 714
 
701 715
 				$context['start'] += $index_properties[$context['index_settings']['bytes_per_word']]['step_size'];
702 716
 				if ($context['start'] > $index_properties[$context['index_settings']['bytes_per_word']]['max_size'])
@@ -757,8 +771,9 @@  discard block
 block discarded – undo
757 771
 					$searchAPI = new $search_class_name();
758 772
 
759 773
 					// No Support?  NEXT!
760
-					if (!$searchAPI->is_supported)
761
-						continue;
774
+					if (!$searchAPI->is_supported) {
775
+											continue;
776
+					}
762 777
 
763 778
 					$apis[$index_name] = array(
764 779
 						'filename' => $file,
@@ -805,10 +820,10 @@  discard block
 block discarded – undo
805 820
 				'messages_ftx' => $db_prefix . 'messages_ftx',
806 821
 			)
807 822
 		);
808
-		while ($row = $smcFunc['db_fetch_assoc']($request))
809
-			$context['fulltext_index'][] = $row['indexname'];
810
-	}
811
-	else
823
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
824
+					$context['fulltext_index'][] = $row['indexname'];
825
+		}
826
+	} else
812 827
 	{
813 828
 		$request = $smcFunc['db_query']('', '
814 829
 			SHOW INDEX
@@ -819,17 +834,19 @@  discard block
 block discarded – undo
819 834
 		$context['fulltext_index'] = array();
820 835
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
821 836
 		{
822
-			while ($row = $smcFunc['db_fetch_assoc']($request))
823
-			if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
837
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
838
+						if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
824 839
 				$context['fulltext_index'][] = $row['Key_name'];
840
+			}
825 841
 			$smcFunc['db_free_result']($request);
826 842
 
827
-			if (is_array($context['fulltext_index']))
828
-				$context['fulltext_index'] = array_unique($context['fulltext_index']);
843
+			if (is_array($context['fulltext_index'])) {
844
+							$context['fulltext_index'] = array_unique($context['fulltext_index']);
845
+			}
829 846
 		}
830 847
 
831
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
832
-			$request = $smcFunc['db_query']('', '
848
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
849
+					$request = $smcFunc['db_query']('', '
833 850
 			SHOW TABLE STATUS
834 851
 			FROM {string:database_name}
835 852
 			LIKE {string:table_name}',
@@ -838,20 +855,22 @@  discard block
 block discarded – undo
838 855
 				'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
839 856
 			)
840 857
 			);
841
-		else
842
-			$request = $smcFunc['db_query']('', '
858
+		} else {
859
+					$request = $smcFunc['db_query']('', '
843 860
 			SHOW TABLE STATUS
844 861
 			LIKE {string:table_name}',
845 862
 			array(
846 863
 				'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
847 864
 			)
848 865
 			);
866
+		}
849 867
 
850 868
 		if ($request !== false)
851 869
 		{
852
-			while ($row = $smcFunc['db_fetch_assoc']($request))
853
-			if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'](), '5.6.4', '>=')))
870
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
871
+						if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'](), '5.6.4', '>=')))
854 872
 				$context['cannot_create_fulltext'] = true;
873
+			}
855 874
 			$smcFunc['db_free_result']($request);
856 875
 		}
857 876
 	}
Please login to merge, or discard this patch.
Sources/ManageNews.php 1 patch
Braces   +140 added lines, -102 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The news dispatcher; doesn't do anything, just delegates.
@@ -67,8 +68,9 @@  discard block
 block discarded – undo
67 68
 	);
68 69
 
69 70
 	// Force the right area...
70
-	if (substr($_REQUEST['sa'], 0, 7) == 'mailing')
71
-		$context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers';
71
+	if (substr($_REQUEST['sa'], 0, 7) == 'mailing') {
72
+			$context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers';
73
+	}
72 74
 
73 75
 	call_helper($subActions[$_REQUEST['sa']][0]);
74 76
 }
@@ -99,9 +101,10 @@  discard block
 block discarded – undo
99 101
 		$temp_news = explode("\n", $modSettings['news']);
100 102
 
101 103
 		// Remove the items that were selected.
102
-		foreach ($temp_news as $i => $news)
103
-			if (in_array($i, $_POST['remove']))
104
+		foreach ($temp_news as $i => $news) {
105
+					if (in_array($i, $_POST['remove']))
104 106
 				unset($temp_news[$i]);
107
+		}
105 108
 
106 109
 		// Update the database.
107 110
 		updateSettings(array('news' => implode("\n", $temp_news)));
@@ -117,9 +120,9 @@  discard block
 block discarded – undo
117 120
 
118 121
 		foreach ($_POST['news'] as $i => $news)
119 122
 		{
120
-			if (trim($news) == '')
121
-				unset($_POST['news'][$i]);
122
-			else
123
+			if (trim($news) == '') {
124
+							unset($_POST['news'][$i]);
125
+			} else
123 126
 			{
124 127
 				$_POST['news'][$i] = $smcFunc['htmlspecialchars']($_POST['news'][$i], ENT_QUOTES);
125 128
 				preparsecode($_POST['news'][$i]);
@@ -155,12 +158,13 @@  discard block
 block discarded – undo
155 158
 				'data' => array(
156 159
 					'function' => function($news)
157 160
 					{
158
-						if (is_numeric($news['id']))
159
-							return '
161
+						if (is_numeric($news['id'])) {
162
+													return '
160 163
 								<textarea id="data_' . $news['id'] . '" rows="3" cols="50" name="news[]" class="padding block">' . $news['unparsed'] . '</textarea>
161 164
 								<div class="floatleft" id="preview_' . $news['id'] . '"></div>';
162
-						else
163
-							return $news['unparsed'];
165
+						} else {
166
+													return $news['unparsed'];
167
+						}
164 168
 					},
165 169
 					'class' => 'half_table',
166 170
 				),
@@ -186,10 +190,11 @@  discard block
 block discarded – undo
186 190
 				'data' => array(
187 191
 					'function' => function($news)
188 192
 					{
189
-						if (is_numeric($news['id']))
190
-							return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '">';
191
-						else
192
-							return '';
193
+						if (is_numeric($news['id'])) {
194
+													return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '">';
195
+						} else {
196
+													return '';
197
+						}
193 198
 					},
194 199
 					'class' => 'centercol icon',
195 200
 				),
@@ -283,12 +288,13 @@  discard block
 block discarded – undo
283 288
 
284 289
 	$admin_current_news = array();
285 290
 	// Ready the current news.
286
-	foreach (explode("\n", $modSettings['news']) as $id => $line)
287
-		$admin_current_news[$id] = array(
291
+	foreach (explode("\n", $modSettings['news']) as $id => $line) {
292
+			$admin_current_news[$id] = array(
288 293
 			'id' => $id,
289 294
 			'unparsed' => un_preparsecode($line),
290 295
 			'parsed' => preg_replace('~<([/]?)form[^>]*?[>]*>~i', '<em class="smalltext">&lt;$1form&gt;</em>', parse_bbc($line)),
291 296
 		);
297
+	}
292 298
 
293 299
 	$admin_current_news['last'] = array(
294 300
 		'id' => 'last',
@@ -355,10 +361,11 @@  discard block
 block discarded – undo
355 361
 			'member_count' => 0,
356 362
 		);
357 363
 
358
-		if ($row['min_posts'] == -1)
359
-			$normalGroups[$row['id_group']] = $row['id_group'];
360
-		else
361
-			$postGroups[$row['id_group']] = $row['id_group'];
364
+		if ($row['min_posts'] == -1) {
365
+					$normalGroups[$row['id_group']] = $row['id_group'];
366
+		} else {
367
+					$postGroups[$row['id_group']] = $row['id_group'];
368
+		}
362 369
 	}
363 370
 	$smcFunc['db_free_result']($request);
364 371
 
@@ -374,8 +381,9 @@  discard block
 block discarded – undo
374 381
 				'post_group_list' => $postGroups,
375 382
 			)
376 383
 		);
377
-		while ($row = $smcFunc['db_fetch_assoc']($query))
378
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
384
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
385
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
386
+		}
379 387
 		$smcFunc['db_free_result']($query);
380 388
 	}
381 389
 
@@ -391,8 +399,9 @@  discard block
 block discarded – undo
391 399
 				'normal_group_list' => $normalGroups,
392 400
 			)
393 401
 		);
394
-		while ($row = $smcFunc['db_fetch_assoc']($query))
395
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
402
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
403
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
404
+		}
396 405
 		$smcFunc['db_free_result']($query);
397 406
 
398 407
 		// Also do those who have it as an additional membergroup - this ones more yucky...
@@ -409,8 +418,9 @@  discard block
 block discarded – undo
409 418
 				'blank_string' => '',
410 419
 			)
411 420
 		);
412
-		while ($row = $smcFunc['db_fetch_assoc']($query))
413
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
421
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
422
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
423
+		}
414 424
 		$smcFunc['db_free_result']($query);
415 425
 	}
416 426
 
@@ -461,10 +471,11 @@  discard block
 block discarded – undo
461 471
 	{
462 472
 		$context[$key] = !empty($_REQUEST[$post]) ? $_REQUEST[$post] : '';
463 473
 
464
-		if (empty($context[$key]) && empty($_REQUEST['xml']))
465
-			$context['post_error']['messages'][] = $txt['error_no_' . $post];
466
-		elseif (!empty($_REQUEST['xml']))
467
-			continue;
474
+		if (empty($context[$key]) && empty($_REQUEST['xml'])) {
475
+					$context['post_error']['messages'][] = $txt['error_no_' . $post];
476
+		} elseif (!empty($_REQUEST['xml'])) {
477
+					continue;
478
+		}
468 479
 
469 480
 		preparsecode($context[$key]);
470 481
 		if ($html)
@@ -543,10 +554,12 @@  discard block
 block discarded – undo
543 554
 
544 555
 	// Start by finding any members!
545 556
 	$toClean = array();
546
-	if (!empty($_POST['members']))
547
-		$toClean[] = 'members';
548
-	if (!empty($_POST['exclude_members']))
549
-		$toClean[] = 'exclude_members';
557
+	if (!empty($_POST['members'])) {
558
+			$toClean[] = 'members';
559
+	}
560
+	if (!empty($_POST['exclude_members'])) {
561
+			$toClean[] = 'exclude_members';
562
+	}
550 563
 	if (!empty($toClean))
551 564
 	{
552 565
 		require_once($sourcedir . '/Subs-Auth.php');
@@ -558,11 +571,13 @@  discard block
 block discarded – undo
558 571
 			preg_match_all('~"([^"]+)"~', $_POST[$type], $matches);
559 572
 			$_POST[$type] = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST[$type]))));
560 573
 
561
-			foreach ($_POST[$type] as $index => $member)
562
-				if (strlen(trim($member)) > 0)
574
+			foreach ($_POST[$type] as $index => $member) {
575
+							if (strlen(trim($member)) > 0)
563 576
 					$_POST[$type][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($member)));
564
-				else
565
-					unset($_POST[$type][$index]);
577
+			}
578
+				else {
579
+									unset($_POST[$type][$index]);
580
+				}
566 581
 
567 582
 			// Find the members
568 583
 			$_POST[$type] = implode(',', array_keys(findMembers($_POST[$type])));
@@ -572,16 +587,18 @@  discard block
 block discarded – undo
572 587
 	if (isset($_POST['member_list']) && is_array($_POST['member_list']))
573 588
 	{
574 589
 		$members = array();
575
-		foreach ($_POST['member_list'] as $member_id)
576
-			$members[] = (int) $member_id;
590
+		foreach ($_POST['member_list'] as $member_id) {
591
+					$members[] = (int) $member_id;
592
+		}
577 593
 		$_POST['members'] = implode(',', $members);
578 594
 	}
579 595
 
580 596
 	if (isset($_POST['exclude_member_list']) && is_array($_POST['exclude_member_list']))
581 597
 	{
582 598
 		$members = array();
583
-		foreach ($_POST['exclude_member_list'] as $member_id)
584
-			$members[] = (int) $member_id;
599
+		foreach ($_POST['exclude_member_list'] as $member_id) {
600
+					$members[] = (int) $member_id;
601
+		}
585 602
 		$_POST['exclude_members'] = implode(',', $members);
586 603
 	}
587 604
 
@@ -605,8 +622,9 @@  discard block
 block discarded – undo
605 622
 			'current_time' => time(),
606 623
 		)
607 624
 	);
608
-	while ($row = $smcFunc['db_fetch_assoc']($request))
609
-		$context['recipients']['exclude_members'][] = $row['id_member'];
625
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
626
+			$context['recipients']['exclude_members'][] = $row['id_member'];
627
+	}
610 628
 	$smcFunc['db_free_result']($request);
611 629
 
612 630
 	$request = $smcFunc['db_query']('', '
@@ -641,8 +659,9 @@  discard block
 block discarded – undo
641 659
 			WHERE email_address IN(' . implode(', ', $condition_array) . ')',
642 660
 			$condition_array_params
643 661
 		);
644
-		while ($row = $smcFunc['db_fetch_assoc']($request))
645
-			$context['recipients']['exclude_members'][] = $row['id_member'];
662
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
663
+					$context['recipients']['exclude_members'][] = $row['id_member'];
664
+		}
646 665
 		$smcFunc['db_free_result']($request);
647 666
 	}
648 667
 
@@ -660,10 +679,11 @@  discard block
 block discarded – undo
660 679
 		);
661 680
 		while ($row = $smcFunc['db_fetch_assoc']($request))
662 681
 		{
663
-			if (in_array(3, $context['recipients']))
664
-				$context['recipients']['exclude_members'][] = $row['identifier'];
665
-			else
666
-				$context['recipients']['members'][] = $row['identifier'];
682
+			if (in_array(3, $context['recipients'])) {
683
+							$context['recipients']['exclude_members'][] = $row['identifier'];
684
+			} else {
685
+							$context['recipients']['members'][] = $row['identifier'];
686
+			}
667 687
 		}
668 688
 		$smcFunc['db_free_result']($request);
669 689
 	}
@@ -710,8 +730,9 @@  discard block
 block discarded – undo
710 730
 	$num_at_once = 1000;
711 731
 
712 732
 	// If by PM's I suggest we half the above number.
713
-	if (!empty($_POST['send_pm']))
714
-		$num_at_once /= 2;
733
+	if (!empty($_POST['send_pm'])) {
734
+			$num_at_once /= 2;
735
+	}
715 736
 
716 737
 	checkSession();
717 738
 
@@ -734,8 +755,7 @@  discard block
 block discarded – undo
734 755
 		);
735 756
 		list ($context['total_members']) = $smcFunc['db_fetch_row']($request);
736 757
 		$smcFunc['db_free_result']($request);
737
-	}
738
-	else
758
+	} else
739 759
 	{
740 760
 		$context['total_members'] = (int) $_REQUEST['total_members'];
741 761
 	}
@@ -753,32 +773,35 @@  discard block
 block discarded – undo
753 773
 	if (!empty($_POST['exclude_members']))
754 774
 	{
755 775
 		$members = explode(',', $_POST['exclude_members']);
756
-		foreach ($members as $member)
757
-			if ($member >= $context['start'])
776
+		foreach ($members as $member) {
777
+					if ($member >= $context['start'])
758 778
 				$context['recipients']['exclude_members'][] = (int) $member;
779
+		}
759 780
 	}
760 781
 
761 782
 	// What about members we *must* do?
762 783
 	if (!empty($_POST['members']))
763 784
 	{
764 785
 		$members = explode(',', $_POST['members']);
765
-		foreach ($members as $member)
766
-			if ($member >= $context['start'])
786
+		foreach ($members as $member) {
787
+					if ($member >= $context['start'])
767 788
 				$context['recipients']['members'][] = (int) $member;
789
+		}
768 790
 	}
769 791
 	// Cleaning groups is simple - although deal with both checkbox and commas.
770 792
 	if (isset($_POST['groups']))
771 793
 	{
772 794
 		if (is_array($_POST['groups']))
773 795
 		{
774
-			foreach ($_POST['groups'] as $group => $dummy)
775
-				$context['recipients']['groups'][] = (int) $group;
776
-		}
777
-		else
796
+			foreach ($_POST['groups'] as $group => $dummy) {
797
+							$context['recipients']['groups'][] = (int) $group;
798
+			}
799
+		} else
778 800
 		{
779 801
 			$groups = explode(',', $_POST['groups']);
780
-			foreach ($groups as $group)
781
-				$context['recipients']['groups'][] = (int) $group;
802
+			foreach ($groups as $group) {
803
+							$context['recipients']['groups'][] = (int) $group;
804
+			}
782 805
 		}
783 806
 	}
784 807
 	// Same for excluded groups
@@ -786,15 +809,17 @@  discard block
 block discarded – undo
786 809
 	{
787 810
 		if (is_array($_POST['exclude_groups']))
788 811
 		{
789
-			foreach ($_POST['exclude_groups'] as $group => $dummy)
790
-				$context['recipients']['exclude_groups'][] = (int) $group;
812
+			foreach ($_POST['exclude_groups'] as $group => $dummy) {
813
+							$context['recipients']['exclude_groups'][] = (int) $group;
814
+			}
791 815
 		}
792 816
 		// Ignore an empty string - we don't want to exclude "Regular Members" unless it's specifically selected
793 817
 		elseif ($_POST['exclude_groups'] != '')
794 818
 		{
795 819
 			$groups = explode(',', $_POST['exclude_groups']);
796
-			foreach ($groups as $group)
797
-				$context['recipients']['exclude_groups'][] = (int) $group;
820
+			foreach ($groups as $group) {
821
+							$context['recipients']['exclude_groups'][] = (int) $group;
822
+			}
798 823
 		}
799 824
 	}
800 825
 	// Finally - emails!
@@ -804,14 +829,16 @@  discard block
 block discarded – undo
804 829
 		foreach ($addressed as $curmem)
805 830
 		{
806 831
 			$curmem = trim($curmem);
807
-			if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL))
808
-				$context['recipients']['emails'][$curmem] = $curmem;
832
+			if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL)) {
833
+							$context['recipients']['emails'][$curmem] = $curmem;
834
+			}
809 835
 		}
810 836
 	}
811 837
 
812 838
 	// If we're only cleaning drop out here.
813
-	if ($clean_only)
814
-		return;
839
+	if ($clean_only) {
840
+			return;
841
+	}
815 842
 
816 843
 	require_once($sourcedir . '/Subs-Post.php');
817 844
 
@@ -827,16 +854,18 @@  discard block
 block discarded – undo
827 854
 	if (!$context['send_pm'] && !empty($_POST['send_html']))
828 855
 	{
829 856
 		// Prepare the message for HTML.
830
-		if (!empty($_POST['parse_html']))
831
-			$_POST['message'] = str_replace(array("\n", '  '), array('<br>' . "\n", '&nbsp; '), $_POST['message']);
857
+		if (!empty($_POST['parse_html'])) {
858
+					$_POST['message'] = str_replace(array("\n", '  '), array('<br>' . "\n", '&nbsp; '), $_POST['message']);
859
+		}
832 860
 
833 861
 		// This is here to prevent spam filters from tagging this as spam.
834 862
 		if (preg_match('~\<html~i', $_POST['message']) == 0)
835 863
 		{
836
-			if (preg_match('~\<body~i', $_POST['message']) == 0)
837
-				$_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>';
838
-			else
839
-				$_POST['message'] = '<html>' . $_POST['message'] . '</html>';
864
+			if (preg_match('~\<body~i', $_POST['message']) == 0) {
865
+							$_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>';
866
+			} else {
867
+							$_POST['message'] = '<html>' . $_POST['message'] . '</html>';
868
+			}
840 869
 		}
841 870
 	}
842 871
 
@@ -890,15 +919,17 @@  discard block
 block discarded – undo
890 919
 	foreach ($context['recipients']['emails'] as $k => $email)
891 920
 	{
892 921
 		// Done as many as we can?
893
-		if ($i >= $num_at_once)
894
-			break;
922
+		if ($i >= $num_at_once) {
923
+					break;
924
+		}
895 925
 
896 926
 		// Don't sent it twice!
897 927
 		unset($context['recipients']['emails'][$k]);
898 928
 
899 929
 		// Dammit - can't PM emails!
900
-		if ($context['send_pm'])
901
-			continue;
930
+		if ($context['send_pm']) {
931
+					continue;
932
+		}
902 933
 
903 934
 		$to_member = array(
904 935
 			$email,
@@ -932,8 +963,9 @@  discard block
 block discarded – undo
932 963
 					$queryBuild[] = 'mem.id_post_group = {int:group_' . $group . '}';
933 964
 				}
934 965
 			}
935
-			if (!empty($queryBuild))
936
-			$sendQuery .= implode(' OR ', $queryBuild);
966
+			if (!empty($queryBuild)) {
967
+						$sendQuery .= implode(' OR ', $queryBuild);
968
+			}
937 969
 		}
938 970
 		if (!empty($context['recipients']['members']))
939 971
 		{
@@ -952,8 +984,9 @@  discard block
 block discarded – undo
952 984
 		}
953 985
 
954 986
 		// Anything to exclude?
955
-		if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups']))
956
-			$sendQuery .= ' AND mem.id_group != {int:regular_group}';
987
+		if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups'])) {
988
+					$sendQuery .= ' AND mem.id_group != {int:regular_group}';
989
+		}
957 990
 		if (!empty($context['recipients']['exclude_members']))
958 991
 		{
959 992
 			$sendQuery .= ' AND mem.id_member NOT IN ({array_int:exclude_members})';
@@ -989,21 +1022,24 @@  discard block
 block discarded – undo
989 1022
 		foreach ($rows as $row)
990 1023
 		{
991 1024
 			// Force them to have it?
992
-			if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements']))
993
-				continue;
1025
+			if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements'])) {
1026
+							continue;
1027
+			}
994 1028
 
995 1029
 			// What groups are we looking at here?
996
-			if (empty($row['additional_groups']))
997
-				$groups = array($row['id_group'], $row['id_post_group']);
998
-			else
999
-				$groups = array_merge(
1030
+			if (empty($row['additional_groups'])) {
1031
+							$groups = array($row['id_group'], $row['id_post_group']);
1032
+			} else {
1033
+							$groups = array_merge(
1000 1034
 					array($row['id_group'], $row['id_post_group']),
1001 1035
 					explode(',', $row['additional_groups'])
1002 1036
 				);
1037
+			}
1003 1038
 
1004 1039
 			// Excluded groups?
1005
-			if (array_intersect($groups, $context['recipients']['exclude_groups']))
1006
-				continue;
1040
+			if (array_intersect($groups, $context['recipients']['exclude_groups'])) {
1041
+							continue;
1042
+			}
1007 1043
 
1008 1044
 			// We might need this
1009 1045
 			$cleanMemberName = empty($_POST['send_html']) || $context['send_pm'] ? un_htmlspecialchars($row['real_name']) : $row['real_name'];
@@ -1026,10 +1062,11 @@  discard block
 block discarded – undo
1026 1062
 				), $_POST['subject']);
1027 1063
 
1028 1064
 			// Send the actual email - or a PM!
1029
-			if (!$context['send_pm'])
1030
-				sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5);
1031
-			else
1032
-				sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message);
1065
+			if (!$context['send_pm']) {
1066
+							sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5);
1067
+			} else {
1068
+							sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message);
1069
+			}
1033 1070
 		}
1034 1071
 	}
1035 1072
 
@@ -1079,8 +1116,9 @@  discard block
 block discarded – undo
1079 1116
 
1080 1117
 	call_integration_hook('integrate_modify_news_settings', array(&$config_vars));
1081 1118
 
1082
-	if ($return_config)
1083
-		return $config_vars;
1119
+	if ($return_config) {
1120
+			return $config_vars;
1121
+	}
1084 1122
 
1085 1123
 	$context['page_title'] = $txt['admin_edit_news'] . ' - ' . $txt['settings'];
1086 1124
 	$context['sub_template'] = 'show_settings';
Please login to merge, or discard this patch.
Sources/Subs.php 4 patches
Indentation   +1 added lines, -3 removed lines patch added patch discarded remove patch
@@ -5495,7 +5495,6 @@  discard block
 block discarded – undo
5495 5495
 
5496 5496
 /**
5497 5497
  * Tries different modes to make file/dirs writable. Wrapper function for chmod()
5498
-
5499 5498
  * @param string $file The file/dir full path.
5500 5499
  * @param int $value Not needed, added for legacy reasons.
5501 5500
  * @return boolean  true if the file/dir is already writable or the function was able to make it writable, false if the function couldn't make the file/dir writable.
@@ -5535,7 +5534,6 @@  discard block
 block discarded – undo
5535 5534
 
5536 5535
 /**
5537 5536
  * Wrapper function for json_decode() with error handling.
5538
-
5539 5537
  * @param string $json The string to decode.
5540 5538
  * @param bool $returnAsArray To return the decoded string as an array or an object, SMF only uses Arrays but to keep on compatibility with json_decode its set to false as default.
5541 5539
  * @param bool $logIt To specify if the error will be logged if theres any.
@@ -6029,7 +6027,7 @@  discard block
 block discarded – undo
6029 6027
 		$params = stream_context_get_params($stream);
6030 6028
 		$result = isset($params["options"]["ssl"]["peer_certificate"]) ? true : false;
6031 6029
 	}
6032
-    return $result;
6030
+	return $result;
6033 6031
 }
6034 6032
 
6035 6033
 /**
Please login to merge, or discard this patch.
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
  * - caches the formatting data from the setting for optimization.
694 694
  *
695 695
  * @param float $number A number
696
- * @param bool|int $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
696
+ * @param integer $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
697 697
  * @return string A formatted number
698 698
  */
699 699
 function comma_format($number, $override_decimal_count = false)
@@ -5869,7 +5869,7 @@  discard block
 block discarded – undo
5869 5869
  * It assumes the data is already a string.
5870 5870
  * @param string $data The data to print
5871 5871
  * @param string $type The content type. Defaults to Json.
5872
- * @return void
5872
+ * @return false|null
5873 5873
  */
5874 5874
 function smf_serverResponse($data = '', $type = 'content-type: application/json')
5875 5875
 {
@@ -6351,7 +6351,7 @@  discard block
 block discarded – undo
6351 6351
  *
6352 6352
  * @param string $iri The IRI to test.
6353 6353
  * @param int $flags Optional flags to pass to filter_var()
6354
- * @return string|bool Either the original IRI, or false if the IRI was invalid.
6354
+ * @return string|false Either the original IRI, or false if the IRI was invalid.
6355 6355
  */
6356 6356
 function validate_iri($iri, $flags = null)
6357 6357
 {
Please login to merge, or discard this patch.
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 			{
392 392
 				$val = 'CASE ';
393 393
 				foreach ($members as $k => $v)
394
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
394
+					$val .= 'WHEN id_member = ' . $v . ' THEN ' . count(fetch_alerts($v, false, 0, array(), false)) . ' ';
395 395
 				$val = $val . ' END';
396 396
 				$type = 'raw';
397 397
 			}
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 	static $non_twelve_hour, $locale_cache;
745 745
 	static $unsupportedFormats, $finalizedFormats;
746 746
 
747
-	$unsupportedFormatsWindows = array('z','Z');
747
+	$unsupportedFormatsWindows = array('z', 'Z');
748 748
 
749 749
 	// Ensure required values are set
750 750
 	$user_info['time_offset'] = !empty($user_info['time_offset']) ? $user_info['time_offset'] : 0;
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
 			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
830 830
 		if (empty($unsupportedFormats))
831 831
 		{
832
-			foreach($strftimeFormatSubstitutions as $format => $substitution)
832
+			foreach ($strftimeFormatSubstitutions as $format => $substitution)
833 833
 			{
834 834
 				// Avoid a crashing bug with PHP 7 on certain versions of Windows
835 835
 				if ($context['server']['is_windows'] && in_array($format, $unsupportedFormatsWindows))
@@ -1210,7 +1210,7 @@  discard block
 block discarded – undo
1210 1210
 					'height' => array('optional' => true, 'match' => '(\d+)'),
1211 1211
 				),
1212 1212
 				'content' => '$1',
1213
-				'validate' => function (&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1213
+				'validate' => function(&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1214 1214
 				{
1215 1215
 					$returnContext = '';
1216 1216
 
@@ -1245,7 +1245,7 @@  discard block
 block discarded – undo
1245 1245
 						}
1246 1246
 
1247 1247
 						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1248
-							$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>';
1248
+							$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>';
1249 1249
 						else
1250 1250
 							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1251 1251
 					}
@@ -1297,7 +1297,7 @@  discard block
 block discarded – undo
1297 1297
 				'type' => 'unparsed_content',
1298 1298
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1299 1299
 				// @todo Maybe this can be simplified?
1300
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1300
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1301 1301
 				{
1302 1302
 					if (!isset($disabled['code']))
1303 1303
 					{
@@ -1334,7 +1334,7 @@  discard block
 block discarded – undo
1334 1334
 				'type' => 'unparsed_equals_content',
1335 1335
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> ($2) <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1336 1336
 				// @todo Maybe this can be simplified?
1337
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1337
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1338 1338
 				{
1339 1339
 					if (!isset($disabled['code']))
1340 1340
 					{
@@ -1378,7 +1378,7 @@  discard block
 block discarded – undo
1378 1378
 				'type' => 'unparsed_content',
1379 1379
 				'content' => '<a href="mailto:$1" class="bbc_email">$1</a>',
1380 1380
 				// @todo Should this respect guest_hideContacts?
1381
-				'validate' => function (&$tag, &$data, $disabled)
1381
+				'validate' => function(&$tag, &$data, $disabled)
1382 1382
 				{
1383 1383
 					$data = strtr($data, array('<br>' => ''));
1384 1384
 				},
@@ -1398,7 +1398,7 @@  discard block
 block discarded – undo
1398 1398
 				'test' => '(left|right)(\s+max=\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)?\]',
1399 1399
 				'before' => '<div $1>',
1400 1400
 				'after' => '</div>',
1401
-				'validate' => function (&$tag, &$data, $disabled)
1401
+				'validate' => function(&$tag, &$data, $disabled)
1402 1402
 				{
1403 1403
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1404 1404
 
@@ -1484,7 +1484,7 @@  discard block
 block discarded – undo
1484 1484
 					'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
1485 1485
 				),
1486 1486
 				'content' => '<img src="$1" alt="{alt}" title="{title}"{width}{height} class="bbc_img resized">',
1487
-				'validate' => function (&$tag, &$data, $disabled)
1487
+				'validate' => function(&$tag, &$data, $disabled)
1488 1488
 				{
1489 1489
 					global $image_proxy_enabled, $user_info;
1490 1490
 
@@ -1510,7 +1510,7 @@  discard block
 block discarded – undo
1510 1510
 				'tag' => 'img',
1511 1511
 				'type' => 'unparsed_content',
1512 1512
 				'content' => '<img src="$1" alt="" class="bbc_img">',
1513
-				'validate' => function (&$tag, &$data, $disabled)
1513
+				'validate' => function(&$tag, &$data, $disabled)
1514 1514
 				{
1515 1515
 					global $image_proxy_enabled, $user_info;
1516 1516
 
@@ -1536,7 +1536,7 @@  discard block
 block discarded – undo
1536 1536
 				'tag' => 'iurl',
1537 1537
 				'type' => 'unparsed_content',
1538 1538
 				'content' => '<a href="$1" class="bbc_link">$1</a>',
1539
-				'validate' => function (&$tag, &$data, $disabled)
1539
+				'validate' => function(&$tag, &$data, $disabled)
1540 1540
 				{
1541 1541
 					$data = strtr($data, array('<br>' => ''));
1542 1542
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1550,7 +1550,7 @@  discard block
 block discarded – undo
1550 1550
 				'quoted' => 'optional',
1551 1551
 				'before' => '<a href="$1" class="bbc_link">',
1552 1552
 				'after' => '</a>',
1553
-				'validate' => function (&$tag, &$data, $disabled)
1553
+				'validate' => function(&$tag, &$data, $disabled)
1554 1554
 				{
1555 1555
 					if (substr($data, 0, 1) == '#')
1556 1556
 						$data = '#post_' . substr($data, 1);
@@ -1643,7 +1643,7 @@  discard block
 block discarded – undo
1643 1643
 				'tag' => 'php',
1644 1644
 				'type' => 'unparsed_content',
1645 1645
 				'content' => '<span class="phpcode">$1</span>',
1646
-				'validate' => isset($disabled['php']) ? null : function (&$tag, &$data, $disabled)
1646
+				'validate' => isset($disabled['php']) ? null : function(&$tag, &$data, $disabled)
1647 1647
 				{
1648 1648
 					if (!isset($disabled['php']))
1649 1649
 					{
@@ -1792,7 +1792,7 @@  discard block
 block discarded – undo
1792 1792
 				'test' => '[1-7]\]',
1793 1793
 				'before' => '<span style="font-size: $1;" class="bbc_size">',
1794 1794
 				'after' => '</span>',
1795
-				'validate' => function (&$tag, &$data, $disabled)
1795
+				'validate' => function(&$tag, &$data, $disabled)
1796 1796
 				{
1797 1797
 					$sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95);
1798 1798
 					$data = $sizes[$data] . 'em';
@@ -1830,7 +1830,7 @@  discard block
 block discarded – undo
1830 1830
 				'tag' => 'time',
1831 1831
 				'type' => 'unparsed_content',
1832 1832
 				'content' => '$1',
1833
-				'validate' => function (&$tag, &$data, $disabled)
1833
+				'validate' => function(&$tag, &$data, $disabled)
1834 1834
 				{
1835 1835
 					if (is_numeric($data))
1836 1836
 						$data = timeformat($data);
@@ -1863,7 +1863,7 @@  discard block
 block discarded – undo
1863 1863
 				'tag' => 'url',
1864 1864
 				'type' => 'unparsed_content',
1865 1865
 				'content' => '<a href="$1" class="bbc_link" target="_blank" rel="noopener">$1</a>',
1866
-				'validate' => function (&$tag, &$data, $disabled)
1866
+				'validate' => function(&$tag, &$data, $disabled)
1867 1867
 				{
1868 1868
 					$data = strtr($data, array('<br>' => ''));
1869 1869
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1877,7 +1877,7 @@  discard block
 block discarded – undo
1877 1877
 				'quoted' => 'optional',
1878 1878
 				'before' => '<a href="$1" class="bbc_link" target="_blank" rel="noopener">',
1879 1879
 				'after' => '</a>',
1880
-				'validate' => function (&$tag, &$data, $disabled)
1880
+				'validate' => function(&$tag, &$data, $disabled)
1881 1881
 				{
1882 1882
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1883 1883
 					if (empty($scheme))
@@ -1923,7 +1923,7 @@  discard block
 block discarded – undo
1923 1923
 		{
1924 1924
 			if (isset($temp_bbc))
1925 1925
 				$bbc_codes = $temp_bbc;
1926
-			usort($codes, function ($a, $b) {
1926
+			usort($codes, function($a, $b) {
1927 1927
 				return strcmp($a['tag'], $b['tag']);
1928 1928
 			});
1929 1929
 			return $codes;
@@ -2139,7 +2139,7 @@  discard block
 block discarded – undo
2139 2139
 										# a run of Unicode domain name characters and a dot
2140 2140
 										[\p{L}\p{M}\p{N}\-.:@]+\.
2141 2141
 										# and then a TLD valid in the DNS or the reserved "local" TLD
2142
-										(?:'. $modSettings['tld_regex'] .'|local)
2142
+										(?:'. $modSettings['tld_regex'] . '|local)
2143 2143
 									)
2144 2144
 									# followed by a non-domain character or end of line
2145 2145
 									(?=[^\p{L}\p{N}\-.]|$)
@@ -2207,7 +2207,7 @@  discard block
 block discarded – undo
2207 2207
 						)?
2208 2208
 						';
2209 2209
 
2210
-						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function ($matches) {
2210
+						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function($matches) {
2211 2211
 							$url = array_shift($matches);
2212 2212
 
2213 2213
 							// If this isn't a clean URL, bail out
@@ -2232,7 +2232,7 @@  discard block
 block discarded – undo
2232 2232
 								$fullUrl = $url;
2233 2233
 
2234 2234
 							// Make sure that $fullUrl really is valid
2235
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2235
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '') . $fullUrl) === false)
2236 2236
 								return $url;
2237 2237
 
2238 2238
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
@@ -2296,7 +2296,7 @@  discard block
 block discarded – undo
2296 2296
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2297 2297
 
2298 2298
 			// A closing tag that doesn't match any open tags? Skip it.
2299
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2299
+			if (!in_array($look_for, array_map(function($code) {return $code['tag']; }, $open_tags)))
2300 2300
 				continue;
2301 2301
 
2302 2302
 			$to_close = array();
@@ -2969,7 +2969,7 @@  discard block
 block discarded – undo
2969 2969
 			{
2970 2970
 				$exts = array('svg', 'png', 'gif', 'jpg');
2971 2971
 				$fname = pathinfo($smileysto[$i], PATHINFO_FILENAME);
2972
-				$alt_images = glob($smileys_dir . $fname .  '.{' . (implode(',', $exts)) . '}', GLOB_BRACE);
2972
+				$alt_images = glob($smileys_dir . $fname . '.{' . (implode(',', $exts)) . '}', GLOB_BRACE);
2973 2973
 				if (!empty($alt_images))
2974 2974
 				{
2975 2975
 					foreach ($exts as $ext)
@@ -2985,7 +2985,7 @@  discard block
 block discarded – undo
2985 2985
 			}
2986 2986
 
2987 2987
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
2988
-			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')). '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2988
+			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2989 2989
 
2990 2990
 			$smileyPregReplacements[$smileysfrom[$i]] = $smileyCode;
2991 2991
 
@@ -3010,7 +3010,7 @@  discard block
 block discarded – undo
3010 3010
 
3011 3011
 	// Replace away!
3012 3012
 	$message = preg_replace_callback($smileyPregSearch,
3013
-		function ($matches) use ($smileyPregReplacements)
3013
+		function($matches) use ($smileyPregReplacements)
3014 3014
 		{
3015 3015
 			return $smileyPregReplacements[$matches[1]];
3016 3016
 		}, $message);
@@ -3107,13 +3107,13 @@  discard block
 block discarded – undo
3107 3107
 	{
3108 3108
 		if (defined('SID') && SID != '')
3109 3109
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3110
-				function ($m) use ($scripturl)
3110
+				function($m) use ($scripturl)
3111 3111
 				{
3112
-					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3112
+					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID . (isset($m[2]) ? "$m[2]" : "");
3113 3113
 				}, $setLocation);
3114 3114
 		else
3115 3115
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3116
-				function ($m) use ($scripturl)
3116
+				function($m) use ($scripturl)
3117 3117
 				{
3118 3118
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3119 3119
 				}, $setLocation);
@@ -3434,7 +3434,7 @@  discard block
 block discarded – undo
3434 3434
 
3435 3435
 	// Add a generic "Are you sure?" confirmation message.
3436 3436
 	addInlineJavaScript('
3437
-	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3437
+	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) . ';');
3438 3438
 
3439 3439
 	// Now add the capping code for avatars.
3440 3440
 	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')
@@ -3900,7 +3900,7 @@  discard block
 block discarded – undo
3900 3900
 	if (!empty($normal))
3901 3901
 		foreach ($normal as $nf)
3902 3902
 			echo '
3903
-	<link rel="stylesheet" href="', $nf ,'">';
3903
+	<link rel="stylesheet" href="', $nf, '">';
3904 3904
 
3905 3905
 	if ($db_show_debug === true)
3906 3906
 	{
@@ -3916,7 +3916,7 @@  discard block
 block discarded – undo
3916 3916
 	<style>';
3917 3917
 
3918 3918
 		foreach ($context['css_header'] as $css)
3919
-			echo $css .'
3919
+			echo $css . '
3920 3920
 	';
3921 3921
 
3922 3922
 		echo'
@@ -3960,7 +3960,7 @@  discard block
 block discarded – undo
3960 3960
 
3961 3961
 
3962 3962
 	// No namespaces, sorry!
3963
-	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
3963
+	$classType = 'MatthiasMullie\\Minify\\' . strtoupper($type);
3964 3964
 
3965 3965
 	// Temp path.
3966 3966
 	$cTempPath = $settings['theme_dir'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/';
@@ -4140,7 +4140,7 @@  discard block
 block discarded – undo
4140 4140
 	else
4141 4141
 		$path = $modSettings['attachmentUploadDir'];
4142 4142
 
4143
-	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
4143
+	return $path . '/' . $attachment_id . '_' . $file_hash . '.dat';
4144 4144
 }
4145 4145
 
4146 4146
 /**
@@ -4184,10 +4184,10 @@  discard block
 block discarded – undo
4184 4184
 		$valid_low = isValidIP($ip_parts[0]);
4185 4185
 		$valid_high = isValidIP($ip_parts[1]);
4186 4186
 		$count = 0;
4187
-		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
4187
+		$mode = (preg_match('/:/', $ip_parts[0]) > 0 ? ':' : '.');
4188 4188
 		$max = ($mode == ':' ? 'ffff' : '255');
4189 4189
 		$min = 0;
4190
-		if(!$valid_low)
4190
+		if (!$valid_low)
4191 4191
 		{
4192 4192
 			$ip_parts[0] = preg_replace('/\*/', '0', $ip_parts[0]);
4193 4193
 			$valid_low = isValidIP($ip_parts[0]);
@@ -4201,7 +4201,7 @@  discard block
 block discarded – undo
4201 4201
 		}
4202 4202
 
4203 4203
 		$count = 0;
4204
-		if(!$valid_high)
4204
+		if (!$valid_high)
4205 4205
 		{
4206 4206
 			$ip_parts[1] = preg_replace('/\*/', $max, $ip_parts[1]);
4207 4207
 			$valid_high = isValidIP($ip_parts[1]);
@@ -4214,7 +4214,7 @@  discard block
 block discarded – undo
4214 4214
 			}
4215 4215
 		}
4216 4216
 
4217
-		if($valid_high && $valid_low)
4217
+		if ($valid_high && $valid_low)
4218 4218
 		{
4219 4219
 			$ip_array['low'] = $ip_parts[0];
4220 4220
 			$ip_array['high'] = $ip_parts[1];
@@ -4395,7 +4395,7 @@  discard block
 block discarded – undo
4395 4395
 		addInlineJavaScript('
4396 4396
 	var user_menus = new smc_PopupMenu();
4397 4397
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4398
-	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4398
+	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u=' . $context['user']['id'] . '");', true);
4399 4399
 		if ($context['allow_pm'])
4400 4400
 			addInlineJavaScript('
4401 4401
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
@@ -4690,7 +4690,7 @@  discard block
 block discarded – undo
4690 4690
 		$context['total_admin_reports'] += $context['unapproved_members'];
4691 4691
 	}
4692 4692
 
4693
-	if($context['total_admin_reports'] > 0 && !empty($context['menu_buttons']['admin']))
4693
+	if ($context['total_admin_reports'] > 0 && !empty($context['menu_buttons']['admin']))
4694 4694
 	{
4695 4695
 		$context['menu_buttons']['admin']['amt'] = $context['total_admin_reports'];
4696 4696
 	}
@@ -5037,7 +5037,7 @@  discard block
 block discarded – undo
5037 5037
 		// No? try a fallback to $sourcedir
5038 5038
 		else
5039 5039
 		{
5040
-			$absPath = $sourcedir .'/'. $file;
5040
+			$absPath = $sourcedir . '/' . $file;
5041 5041
 
5042 5042
 			if (file_exists($absPath))
5043 5043
 				require_once($absPath);
@@ -5304,15 +5304,15 @@  discard block
 block discarded – undo
5304 5304
 
5305 5305
 	// UTF-8 occurences of MS special characters
5306 5306
 	$findchars_utf8 = array(
5307
-		"\xe2\x80\x9a",	// single low-9 quotation mark
5308
-		"\xe2\x80\x9e",	// double low-9 quotation mark
5309
-		"\xe2\x80\xa6",	// horizontal ellipsis
5310
-		"\xe2\x80\x98",	// left single curly quote
5311
-		"\xe2\x80\x99",	// right single curly quote
5312
-		"\xe2\x80\x9c",	// left double curly quote
5313
-		"\xe2\x80\x9d",	// right double curly quote
5314
-		"\xe2\x80\x93",	// en dash
5315
-		"\xe2\x80\x94",	// em dash
5307
+		"\xe2\x80\x9a", // single low-9 quotation mark
5308
+		"\xe2\x80\x9e", // double low-9 quotation mark
5309
+		"\xe2\x80\xa6", // horizontal ellipsis
5310
+		"\xe2\x80\x98", // left single curly quote
5311
+		"\xe2\x80\x99", // right single curly quote
5312
+		"\xe2\x80\x9c", // left double curly quote
5313
+		"\xe2\x80\x9d", // right double curly quote
5314
+		"\xe2\x80\x93", // en dash
5315
+		"\xe2\x80\x94", // em dash
5316 5316
 	);
5317 5317
 
5318 5318
 	// windows 1252 / iso equivalents
@@ -5330,15 +5330,15 @@  discard block
 block discarded – undo
5330 5330
 
5331 5331
 	// safe replacements
5332 5332
 	$replacechars = array(
5333
-		',',	// &sbquo;
5334
-		',,',	// &bdquo;
5335
-		'...',	// &hellip;
5336
-		"'",	// &lsquo;
5337
-		"'",	// &rsquo;
5338
-		'"',	// &ldquo;
5339
-		'"',	// &rdquo;
5340
-		'-',	// &ndash;
5341
-		'--',	// &mdash;
5333
+		',', // &sbquo;
5334
+		',,', // &bdquo;
5335
+		'...', // &hellip;
5336
+		"'", // &lsquo;
5337
+		"'", // &rsquo;
5338
+		'"', // &ldquo;
5339
+		'"', // &rdquo;
5340
+		'-', // &ndash;
5341
+		'--', // &mdash;
5342 5342
 	);
5343 5343
 
5344 5344
 	if ($context['utf8'])
@@ -5658,7 +5658,7 @@  discard block
 block discarded – undo
5658 5658
  */
5659 5659
 function inet_dtop($bin)
5660 5660
 {
5661
-	if(empty($bin))
5661
+	if (empty($bin))
5662 5662
 		return '';
5663 5663
 
5664 5664
 	global $db_type;
@@ -5689,28 +5689,28 @@  discard block
 block discarded – undo
5689 5689
  */
5690 5690
 function _safe_serialize($value)
5691 5691
 {
5692
-	if(is_null($value))
5692
+	if (is_null($value))
5693 5693
 		return 'N;';
5694 5694
 
5695
-	if(is_bool($value))
5696
-		return 'b:'. (int) $value .';';
5695
+	if (is_bool($value))
5696
+		return 'b:' . (int) $value . ';';
5697 5697
 
5698
-	if(is_int($value))
5699
-		return 'i:'. $value .';';
5698
+	if (is_int($value))
5699
+		return 'i:' . $value . ';';
5700 5700
 
5701
-	if(is_float($value))
5702
-		return 'd:'. str_replace(',', '.', $value) .';';
5701
+	if (is_float($value))
5702
+		return 'd:' . str_replace(',', '.', $value) . ';';
5703 5703
 
5704
-	if(is_string($value))
5705
-		return 's:'. strlen($value) .':"'. $value .'";';
5704
+	if (is_string($value))
5705
+		return 's:' . strlen($value) . ':"' . $value . '";';
5706 5706
 
5707
-	if(is_array($value))
5707
+	if (is_array($value))
5708 5708
 	{
5709 5709
 		$out = '';
5710
-		foreach($value as $k => $v)
5710
+		foreach ($value as $k => $v)
5711 5711
 			$out .= _safe_serialize($k) . _safe_serialize($v);
5712 5712
 
5713
-		return 'a:'. count($value) .':{'. $out .'}';
5713
+		return 'a:' . count($value) . ':{' . $out . '}';
5714 5714
 	}
5715 5715
 
5716 5716
 	// safe_serialize cannot serialize resources or objects.
@@ -5752,7 +5752,7 @@  discard block
 block discarded – undo
5752 5752
 function _safe_unserialize($str)
5753 5753
 {
5754 5754
 	// Input  is not a string.
5755
-	if(empty($str) || !is_string($str))
5755
+	if (empty($str) || !is_string($str))
5756 5756
 		return false;
5757 5757
 
5758 5758
 	$stack = array();
@@ -5766,40 +5766,40 @@  discard block
 block discarded – undo
5766 5766
 	 *   3 - in array, expecting value or another array
5767 5767
 	 */
5768 5768
 	$state = 0;
5769
-	while($state != 1)
5769
+	while ($state != 1)
5770 5770
 	{
5771 5771
 		$type = isset($str[0]) ? $str[0] : '';
5772
-		if($type == '}')
5772
+		if ($type == '}')
5773 5773
 			$str = substr($str, 1);
5774 5774
 
5775
-		else if($type == 'N' && $str[1] == ';')
5775
+		else if ($type == 'N' && $str[1] == ';')
5776 5776
 		{
5777 5777
 			$value = null;
5778 5778
 			$str = substr($str, 2);
5779 5779
 		}
5780
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5780
+		else if ($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5781 5781
 		{
5782 5782
 			$value = $matches[1] == '1' ? true : false;
5783 5783
 			$str = substr($str, 4);
5784 5784
 		}
5785
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5785
+		else if ($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5786 5786
 		{
5787
-			$value = (int)$matches[1];
5787
+			$value = (int) $matches[1];
5788 5788
 			$str = $matches[2];
5789 5789
 		}
5790
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5790
+		else if ($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5791 5791
 		{
5792
-			$value = (float)$matches[1];
5792
+			$value = (float) $matches[1];
5793 5793
 			$str = $matches[3];
5794 5794
 		}
5795
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5795
+		else if ($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int) $matches[1], 2) == '";')
5796 5796
 		{
5797
-			$value = substr($matches[2], 0, (int)$matches[1]);
5798
-			$str = substr($matches[2], (int)$matches[1] + 2);
5797
+			$value = substr($matches[2], 0, (int) $matches[1]);
5798
+			$str = substr($matches[2], (int) $matches[1] + 2);
5799 5799
 		}
5800
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5800
+		else if ($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5801 5801
 		{
5802
-			$expectedLength = (int)$matches[1];
5802
+			$expectedLength = (int) $matches[1];
5803 5803
 			$str = $matches[2];
5804 5804
 		}
5805 5805
 
@@ -5807,10 +5807,10 @@  discard block
 block discarded – undo
5807 5807
 		else
5808 5808
 			return false;
5809 5809
 
5810
-		switch($state)
5810
+		switch ($state)
5811 5811
 		{
5812 5812
 			case 3: // In array, expecting value or another array.
5813
-				if($type == 'a')
5813
+				if ($type == 'a')
5814 5814
 				{
5815 5815
 					$stack[] = &$list;
5816 5816
 					$list[$key] = array();
@@ -5819,7 +5819,7 @@  discard block
 block discarded – undo
5819 5819
 					$state = 2;
5820 5820
 					break;
5821 5821
 				}
5822
-				if($type != '}')
5822
+				if ($type != '}')
5823 5823
 				{
5824 5824
 					$list[$key] = $value;
5825 5825
 					$state = 2;
@@ -5830,29 +5830,29 @@  discard block
 block discarded – undo
5830 5830
 				return false;
5831 5831
 
5832 5832
 			case 2: // in array, expecting end of array or a key
5833
-				if($type == '}')
5833
+				if ($type == '}')
5834 5834
 				{
5835 5835
 					// Array size is less than expected.
5836
-					if(count($list) < end($expected))
5836
+					if (count($list) < end($expected))
5837 5837
 						return false;
5838 5838
 
5839 5839
 					unset($list);
5840
-					$list = &$stack[count($stack)-1];
5840
+					$list = &$stack[count($stack) - 1];
5841 5841
 					array_pop($stack);
5842 5842
 
5843 5843
 					// Go to terminal state if we're at the end of the root array.
5844 5844
 					array_pop($expected);
5845 5845
 
5846
-					if(count($expected) == 0)
5846
+					if (count($expected) == 0)
5847 5847
 						$state = 1;
5848 5848
 
5849 5849
 					break;
5850 5850
 				}
5851 5851
 
5852
-				if($type == 'i' || $type == 's')
5852
+				if ($type == 'i' || $type == 's')
5853 5853
 				{
5854 5854
 					// Array size exceeds expected length.
5855
-					if(count($list) >= end($expected))
5855
+					if (count($list) >= end($expected))
5856 5856
 						return false;
5857 5857
 
5858 5858
 					$key = $value;
@@ -5865,7 +5865,7 @@  discard block
 block discarded – undo
5865 5865
 
5866 5866
 			// Expecting array or value.
5867 5867
 			case 0:
5868
-				if($type == 'a')
5868
+				if ($type == 'a')
5869 5869
 				{
5870 5870
 					$data = array();
5871 5871
 					$list = &$data;
@@ -5874,7 +5874,7 @@  discard block
 block discarded – undo
5874 5874
 					break;
5875 5875
 				}
5876 5876
 
5877
-				if($type != '}')
5877
+				if ($type != '}')
5878 5878
 				{
5879 5879
 					$data = $value;
5880 5880
 					$state = 1;
@@ -5887,7 +5887,7 @@  discard block
 block discarded – undo
5887 5887
 	}
5888 5888
 
5889 5889
 	// Trailing data in input.
5890
-	if(!empty($str))
5890
+	if (!empty($str))
5891 5891
 		return false;
5892 5892
 
5893 5893
 	return $data;
@@ -5941,7 +5941,7 @@  discard block
 block discarded – undo
5941 5941
 	// Set different modes.
5942 5942
 	$chmodValues = $isDir ? array(0750, 0755, 0775, 0777) : array(0644, 0664, 0666);
5943 5943
 
5944
-	foreach($chmodValues as $val)
5944
+	foreach ($chmodValues as $val)
5945 5945
 	{
5946 5946
 		// If it's writable, break out of the loop.
5947 5947
 		if (is_writable($file))
@@ -5976,13 +5976,13 @@  discard block
 block discarded – undo
5976 5976
 	$returnArray = @json_decode($json, $returnAsArray);
5977 5977
 
5978 5978
 	// PHP 5.3 so no json_last_error_msg()
5979
-	switch(json_last_error())
5979
+	switch (json_last_error())
5980 5980
 	{
5981 5981
 		case JSON_ERROR_NONE:
5982 5982
 			$jsonError = false;
5983 5983
 			break;
5984 5984
 		case JSON_ERROR_DEPTH:
5985
-			$jsonError =  'JSON_ERROR_DEPTH';
5985
+			$jsonError = 'JSON_ERROR_DEPTH';
5986 5986
 			break;
5987 5987
 		case JSON_ERROR_STATE_MISMATCH:
5988 5988
 			$jsonError = 'JSON_ERROR_STATE_MISMATCH';
@@ -6010,10 +6010,10 @@  discard block
 block discarded – undo
6010 6010
 		loadLanguage('Errors');
6011 6011
 
6012 6012
 		if (!empty($jsonDebug))
6013
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6013
+			log_error($txt['json_' . $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6014 6014
 
6015 6015
 		else
6016
-			log_error($txt['json_'. $jsonError], 'critical');
6016
+			log_error($txt['json_' . $jsonError], 'critical');
6017 6017
 
6018 6018
 		// Everyone expects an array.
6019 6019
 		return array();
@@ -6130,7 +6130,7 @@  discard block
 block discarded – undo
6130 6130
 		// Convert Punycode to Unicode
6131 6131
 		require_once($sourcedir . '/Class-Punycode.php');
6132 6132
 		$Punycode = new Punycode();
6133
-		$tlds = array_map(function ($input) use ($Punycode) { return $Punycode->decode($input); }, $tlds);
6133
+		$tlds = array_map(function($input) use ($Punycode) { return $Punycode->decode($input); }, $tlds);
6134 6134
 	}
6135 6135
 	// Otherwise, use the 2012 list of gTLDs and ccTLDs for now and schedule a background update
6136 6136
 	else
@@ -6224,7 +6224,7 @@  discard block
 block discarded – undo
6224 6224
 	}
6225 6225
 
6226 6226
 	// This recursive function creates the index array from the strings
6227
-	$add_string_to_index = function ($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
6227
+	$add_string_to_index = function($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
6228 6228
 	{
6229 6229
 		static $depth = 0;
6230 6230
 		$depth++;
@@ -6251,7 +6251,7 @@  discard block
 block discarded – undo
6251 6251
 	};
6252 6252
 
6253 6253
 	// This recursive function turns the index array into a regular expression
6254
-	$index_to_regex = function (&$index, $delim) use (&$strlen, &$index_to_regex)
6254
+	$index_to_regex = function(&$index, $delim) use (&$strlen, &$index_to_regex)
6255 6255
 	{
6256 6256
 		static $depth = 0;
6257 6257
 		$depth++;
@@ -6275,11 +6275,11 @@  discard block
 block discarded – undo
6275 6275
 
6276 6276
 				if (count(array_keys($value)) == 1)
6277 6277
 				{
6278
-					$new_key_array = explode('(?'.'>', $sub_regex);
6278
+					$new_key_array = explode('(?' . '>', $sub_regex);
6279 6279
 					$new_key .= $new_key_array[0];
6280 6280
 				}
6281 6281
 				else
6282
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6282
+					$sub_regex = '(?' . '>' . $sub_regex . ')';
6283 6283
 			}
6284 6284
 
6285 6285
 			if ($depth > 1)
@@ -6322,10 +6322,10 @@  discard block
 block discarded – undo
6322 6322
 	{
6323 6323
 		$regex = array();
6324 6324
 		while (!empty($index))
6325
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6325
+			$regex[] = '(?' . '>' . $index_to_regex($index, $delim) . ')';
6326 6326
 	}
6327 6327
 	else
6328
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6328
+		$regex = '(?' . '>' . $index_to_regex($index, $delim) . ')';
6329 6329
 
6330 6330
 	// Restore PHP's internal character encoding to whatever it was originally
6331 6331
 	if (!empty($current_encoding))
@@ -6549,7 +6549,7 @@  discard block
 block discarded – undo
6549 6549
 function sanitize_iri($iri)
6550 6550
 {
6551 6551
 	// Encode any non-ASCII characters (but not space or control characters of any sort)
6552
-	$iri = preg_replace_callback('~[^\x00-\x7F\pZ\pC]~u', function ($matches) {
6552
+	$iri = preg_replace_callback('~[^\x00-\x7F\pZ\pC]~u', function($matches) {
6553 6553
 		return rawurlencode($matches[0]);
6554 6554
 	}, $iri);
6555 6555
 
@@ -6591,7 +6591,7 @@  discard block
 block discarded – undo
6591 6591
 	$unescaped = array(
6592 6592
 		'%21'=>'!', '%23'=>'#', '%24'=>'$', '%26'=>'&',
6593 6593
 		'%27'=>"'", '%28'=>'(', '%29'=>')', '%2A'=>'*',
6594
-		'%2B'=>'+', '%2C'=>',',	'%2F'=>'/', '%3A'=>':',
6594
+		'%2B'=>'+', '%2C'=>',', '%2F'=>'/', '%3A'=>':',
6595 6595
 		'%3B'=>';', '%3D'=>'=', '%3F'=>'?', '%40'=>'@',
6596 6596
 	);
6597 6597
 	$iri = strtr(rawurlencode($iri), $unescaped);
Please login to merge, or discard this patch.
Braces   +1477 added lines, -1105 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,24 +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
-
195
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
196 199
 			{
197 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
198 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -213,8 +216,9 @@  discard block
 block discarded – undo
213 216
 
214 217
 		case 'postgroups':
215 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
216
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
217
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
218 222
 
219 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
220 224
 			if ($postgroups == null || $parameter1 == null)
@@ -229,8 +233,9 @@  discard block
 block discarded – undo
229 233
 					)
230 234
 				);
231 235
 				$postgroups = array();
232
-				while ($row = $smcFunc['db_fetch_assoc']($request))
233
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
234 239
 
235 240
 				$smcFunc['db_free_result']($request);
236 241
 
@@ -241,8 +246,9 @@  discard block
 block discarded – undo
241 246
 			}
242 247
 
243 248
 			// Oh great, they've screwed their post groups.
244
-			if (empty($postgroups))
245
-				return;
249
+			if (empty($postgroups)) {
250
+							return;
251
+			}
246 252
 
247 253
 			// Set all membergroups from most posts to least posts.
248 254
 			$conditions = '';
@@ -301,12 +307,9 @@  discard block
 block discarded – undo
301 307
 	{
302 308
 		$condition = 'id_member IN ({array_int:members})';
303 309
 		$parameters['members'] = $members;
304
-	}
305
-
306
-	elseif ($members === null)
307
-		$condition = '1=1';
308
-
309
-	else
310
+	} elseif ($members === null) {
311
+			$condition = '1=1';
312
+	} else
310 313
 	{
311 314
 		$condition = 'id_member = {int:member}';
312 315
 		$parameters['member'] = $members;
@@ -346,9 +349,9 @@  discard block
 block discarded – undo
346 349
 		if (count($vars_to_integrate) != 0)
347 350
 		{
348 351
 			// Fetch a list of member_names if necessary
349
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
350
-				$member_names = array($user_info['username']);
351
-			else
352
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
353
+							$member_names = array($user_info['username']);
354
+			} else
352 355
 			{
353 356
 				$member_names = array();
354 357
 				$request = $smcFunc['db_query']('', '
@@ -357,14 +360,16 @@  discard block
 block discarded – undo
357 360
 					WHERE ' . $condition,
358 361
 					$parameters
359 362
 				);
360
-				while ($row = $smcFunc['db_fetch_assoc']($request))
361
-					$member_names[] = $row['member_name'];
363
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
364
+									$member_names[] = $row['member_name'];
365
+				}
362 366
 				$smcFunc['db_free_result']($request);
363 367
 			}
364 368
 
365
-			if (!empty($member_names))
366
-				foreach ($vars_to_integrate as $var)
369
+			if (!empty($member_names)) {
370
+							foreach ($vars_to_integrate as $var)
367 371
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
372
+			}
368 373
 		}
369 374
 	}
370 375
 
@@ -372,16 +377,17 @@  discard block
 block discarded – undo
372 377
 	foreach ($data as $var => $val)
373 378
 	{
374 379
 		$type = 'string';
375
-		if (in_array($var, $knownInts))
376
-			$type = 'int';
377
-		elseif (in_array($var, $knownFloats))
378
-			$type = 'float';
379
-		elseif ($var == 'birthdate')
380
-			$type = 'date';
381
-		elseif ($var == 'member_ip')
382
-			$type = 'inet';
383
-		elseif ($var == 'member_ip2')
384
-			$type = 'inet';
380
+		if (in_array($var, $knownInts)) {
381
+					$type = 'int';
382
+		} elseif (in_array($var, $knownFloats)) {
383
+					$type = 'float';
384
+		} elseif ($var == 'birthdate') {
385
+					$type = 'date';
386
+		} elseif ($var == 'member_ip') {
387
+					$type = 'inet';
388
+		} elseif ($var == 'member_ip2') {
389
+					$type = 'inet';
390
+		}
385 391
 
386 392
 		// Doing an increment?
387 393
 		if ($var == 'alerts' && ($val === '+' || $val === '-'))
@@ -390,18 +396,17 @@  discard block
 block discarded – undo
390 396
 			if (is_array($members))
391 397
 			{
392 398
 				$val = 'CASE ';
393
-				foreach ($members as $k => $v)
394
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
399
+				foreach ($members as $k => $v) {
400
+									$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
401
+				}
395 402
 				$val = $val . ' END';
396 403
 				$type = 'raw';
397
-			}
398
-			else
404
+			} else
399 405
 			{
400 406
 				$blub = fetch_alerts($members, false, 0, array(), false);
401 407
 				$val = count($blub);
402 408
 			}
403
-		}
404
-		else if ($type == 'int' && ($val === '+' || $val === '-'))
409
+		} else if ($type == 'int' && ($val === '+' || $val === '-'))
405 410
 		{
406 411
 			$val = $var . ' ' . $val . ' 1';
407 412
 			$type = 'raw';
@@ -412,8 +417,9 @@  discard block
 block discarded – undo
412 417
 		{
413 418
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
414 419
 			{
415
-				if ($match[1] != '+ ')
416
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
420
+				if ($match[1] != '+ ') {
421
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
422
+				}
417 423
 				$type = 'raw';
418 424
 			}
419 425
 		}
@@ -434,8 +440,9 @@  discard block
 block discarded – undo
434 440
 	// Clear any caching?
435 441
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
436 442
 	{
437
-		if (!is_array($members))
438
-			$members = array($members);
443
+		if (!is_array($members)) {
444
+					$members = array($members);
445
+		}
439 446
 
440 447
 		foreach ($members as $member)
441 448
 		{
@@ -468,29 +475,32 @@  discard block
 block discarded – undo
468 475
 {
469 476
 	global $modSettings, $smcFunc;
470 477
 
471
-	if (empty($changeArray) || !is_array($changeArray))
472
-		return;
478
+	if (empty($changeArray) || !is_array($changeArray)) {
479
+			return;
480
+	}
473 481
 
474 482
 	$toRemove = array();
475 483
 
476 484
 	// Go check if there is any setting to be removed.
477
-	foreach ($changeArray as $k => $v)
478
-		if ($v === null)
485
+	foreach ($changeArray as $k => $v) {
486
+			if ($v === null)
479 487
 		{
480 488
 			// Found some, remove them from the original array and add them to ours.
481 489
 			unset($changeArray[$k]);
490
+	}
482 491
 			$toRemove[] = $k;
483 492
 		}
484 493
 
485 494
 	// Proceed with the deletion.
486
-	if (!empty($toRemove))
487
-		$smcFunc['db_query']('', '
495
+	if (!empty($toRemove)) {
496
+			$smcFunc['db_query']('', '
488 497
 			DELETE FROM {db_prefix}settings
489 498
 			WHERE variable IN ({array_string:remove})',
490 499
 			array(
491 500
 				'remove' => $toRemove,
492 501
 			)
493 502
 		);
503
+	}
494 504
 
495 505
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
496 506
 	if ($update)
@@ -519,19 +529,22 @@  discard block
 block discarded – undo
519 529
 	foreach ($changeArray as $variable => $value)
520 530
 	{
521 531
 		// Don't bother if it's already like that ;).
522
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
523
-			continue;
532
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
533
+					continue;
534
+		}
524 535
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
525
-		elseif (!isset($modSettings[$variable]) && empty($value))
526
-			continue;
536
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
537
+					continue;
538
+		}
527 539
 
528 540
 		$replaceArray[] = array($variable, $value);
529 541
 
530 542
 		$modSettings[$variable] = $value;
531 543
 	}
532 544
 
533
-	if (empty($replaceArray))
534
-		return;
545
+	if (empty($replaceArray)) {
546
+			return;
547
+	}
535 548
 
536 549
 	$smcFunc['db_insert']('replace',
537 550
 		'{db_prefix}settings',
@@ -577,14 +590,17 @@  discard block
 block discarded – undo
577 590
 	$start_invalid = $start < 0;
578 591
 
579 592
 	// Make sure $start is a proper variable - not less than 0.
580
-	if ($start_invalid)
581
-		$start = 0;
593
+	if ($start_invalid) {
594
+			$start = 0;
595
+	}
582 596
 	// Not greater than the upper bound.
583
-	elseif ($start >= $max_value)
584
-		$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
+	elseif ($start >= $max_value) {
598
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
599
+	}
585 600
 	// And it has to be a multiple of $num_per_page!
586
-	else
587
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
601
+	else {
602
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
603
+	}
588 604
 
589 605
 	$context['current_page'] = $start / $num_per_page;
590 606
 
@@ -614,77 +630,87 @@  discard block
 block discarded – undo
614 630
 
615 631
 		// Show all the pages.
616 632
 		$display_page = 1;
617
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
618
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
633
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
634
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
635
+		}
619 636
 
620 637
 		// Show the right arrow.
621 638
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
622
-		if ($start != $counter - $max_value && !$start_invalid)
623
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
624
-	}
625
-	else
639
+		if ($start != $counter - $max_value && !$start_invalid) {
640
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
641
+		}
642
+	} else
626 643
 	{
627 644
 		// If they didn't enter an odd value, pretend they did.
628 645
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
629 646
 
630 647
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
631
-		if (!empty($start) && $show_prevnext)
632
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
633
-		else
634
-			$pageindex .= '';
648
+		if (!empty($start) && $show_prevnext) {
649
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
650
+		} else {
651
+					$pageindex .= '';
652
+		}
635 653
 
636 654
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
637
-		if ($start > $num_per_page * $PageContiguous)
638
-			$pageindex .= sprintf($base_link, 0, '1');
655
+		if ($start > $num_per_page * $PageContiguous) {
656
+					$pageindex .= sprintf($base_link, 0, '1');
657
+		}
639 658
 
640 659
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
641
-		if ($start > $num_per_page * ($PageContiguous + 1))
642
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
660
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
661
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
643 662
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
644 663
 				'{FIRST_PAGE}' => $num_per_page,
645 664
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
646 665
 				'{PER_PAGE}' => $num_per_page,
647 666
 			));
667
+		}
648 668
 
649 669
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
650
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
651
-			if ($start >= $num_per_page * $nCont)
670
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
671
+					if ($start >= $num_per_page * $nCont)
652 672
 			{
653 673
 				$tmpStart = $start - $num_per_page * $nCont;
674
+		}
654 675
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
655 676
 			}
656 677
 
657 678
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
658
-		if (!$start_invalid)
659
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
660
-		else
661
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
679
+		if (!$start_invalid) {
680
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
681
+		} else {
682
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
683
+		}
662 684
 
663 685
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
664 686
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
665
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
666
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
687
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
688
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
667 689
 			{
668 690
 				$tmpStart = $start + $num_per_page * $nCont;
691
+		}
669 692
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
670 693
 			}
671 694
 
672 695
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
673
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
674
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
696
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
697
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
675 698
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
676 699
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
677 700
 				'{LAST_PAGE}' => $tmpMaxPages,
678 701
 				'{PER_PAGE}' => $num_per_page,
679 702
 			));
703
+		}
680 704
 
681 705
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
682
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
683
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
706
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
707
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
708
+		}
684 709
 
685 710
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
686
-		if ($start != $tmpMaxPages && $show_prevnext)
687
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
711
+		if ($start != $tmpMaxPages && $show_prevnext) {
712
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
713
+		}
688 714
 	}
689 715
 	$pageindex .= $settings['page_index']['extra_after'];
690 716
 
@@ -710,8 +736,9 @@  discard block
 block discarded – undo
710 736
 	if ($decimal_separator === null)
711 737
 	{
712 738
 		// Not set for whatever reason?
713
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
714
-			return $number;
739
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
740
+					return $number;
741
+		}
715 742
 
716 743
 		// Cache these each load...
717 744
 		$thousands_separator = $matches[1];
@@ -752,17 +779,20 @@  discard block
 block discarded – undo
752 779
 	$user_info['time_format'] = !empty($user_info['time_format']) ? $user_info['time_format'] : (!empty($modSettings['time_format']) ? $modSettings['time_format'] : '%F %H:%M');
753 780
 
754 781
 	// Offset the time.
755
-	if (!$offset_type)
756
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
782
+	if (!$offset_type) {
783
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
784
+	}
757 785
 	// Just the forum offset?
758
-	elseif ($offset_type == 'forum')
759
-		$time = $log_time + $modSettings['time_offset'] * 3600;
760
-	else
761
-		$time = $log_time;
786
+	elseif ($offset_type == 'forum') {
787
+			$time = $log_time + $modSettings['time_offset'] * 3600;
788
+	} else {
789
+			$time = $log_time;
790
+	}
762 791
 
763 792
 	// We can't have a negative date (on Windows, at least.)
764
-	if ($log_time < 0)
765
-		$log_time = 0;
793
+	if ($log_time < 0) {
794
+			$log_time = 0;
795
+	}
766 796
 
767 797
 	// Today and Yesterday?
768 798
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -779,24 +809,27 @@  discard block
 block discarded – undo
779 809
 		{
780 810
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
781 811
 			$today_fmt = $h . ':%M' . $s . ' %p';
812
+		} else {
813
+					$today_fmt = '%H:%M' . $s;
782 814
 		}
783
-		else
784
-			$today_fmt = '%H:%M' . $s;
785 815
 
786 816
 		// Same day of the year, same year.... Today!
787
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
788
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
817
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
818
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
819
+		}
789 820
 
790 821
 		// 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...
791
-		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))
792
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
822
+		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)) {
823
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
824
+		}
793 825
 	}
794 826
 
795 827
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
796 828
 
797 829
 	// Use the cached formats if available
798
-	if (is_null($finalizedFormats))
799
-		$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
830
+	if (is_null($finalizedFormats)) {
831
+			$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
832
+	}
800 833
 
801 834
 	// Make a supported version for this format if we don't already have one
802 835
 	if (empty($finalizedFormats[$str]))
@@ -825,8 +858,9 @@  discard block
 block discarded – undo
825 858
 		);
826 859
 
827 860
 		// No need to do this part again if we already did it once
828
-		if (is_null($unsupportedFormats))
829
-			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
861
+		if (is_null($unsupportedFormats)) {
862
+					$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
863
+		}
830 864
 		if (empty($unsupportedFormats))
831 865
 		{
832 866
 			foreach($strftimeFormatSubstitutions as $format => $substitution)
@@ -842,20 +876,23 @@  discard block
 block discarded – undo
842 876
 
843 877
 				// Windows will return false for unsupported formats
844 878
 				// Other operating systems return the format string as a literal
845
-				if ($value === false || $value === $format)
846
-					$unsupportedFormats[] = $format;
879
+				if ($value === false || $value === $format) {
880
+									$unsupportedFormats[] = $format;
881
+				}
847 882
 			}
848 883
 			cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400);
849 884
 		}
850 885
 
851 886
 		// Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q'
852
-		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
853
-			$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
887
+		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
888
+					$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
889
+		}
854 890
 
855 891
 		// Substitute unsupported formats with supported ones
856
-		if (!empty($unsupportedFormats))
857
-			while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
892
+		if (!empty($unsupportedFormats)) {
893
+					while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
858 894
 				$timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat);
895
+		}
859 896
 
860 897
 		// Remember this so we don't need to do it again
861 898
 		$finalizedFormats[$str] = $timeformat;
@@ -864,33 +901,39 @@  discard block
 block discarded – undo
864 901
 
865 902
 	$str = $finalizedFormats[$str];
866 903
 
867
-	if (!isset($locale_cache))
868
-		$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
904
+	if (!isset($locale_cache)) {
905
+			$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
906
+	}
869 907
 
870 908
 	if ($locale_cache !== false)
871 909
 	{
872 910
 		// Check if another process changed the locale
873
-		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache)
874
-			setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
911
+		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) {
912
+					setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
913
+		}
875 914
 
876
-		if (!isset($non_twelve_hour))
877
-			$non_twelve_hour = trim(strftime('%p')) === '';
878
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
879
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
915
+		if (!isset($non_twelve_hour)) {
916
+					$non_twelve_hour = trim(strftime('%p')) === '';
917
+		}
918
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
919
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
920
+		}
880 921
 
881
-		foreach (array('%a', '%A', '%b', '%B') as $token)
882
-			if (strpos($str, $token) !== false)
922
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
923
+					if (strpos($str, $token) !== false)
883 924
 				$str = str_replace($token, strftime($token, $time), $str);
884
-	}
885
-	else
925
+		}
926
+	} else
886 927
 	{
887 928
 		// Do-it-yourself time localization.  Fun.
888
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
889
-			if (strpos($str, $token) !== false)
929
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
930
+					if (strpos($str, $token) !== false)
890 931
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
932
+		}
891 933
 
892
-		if (strpos($str, '%p') !== false)
893
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
934
+		if (strpos($str, '%p') !== false) {
935
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
936
+		}
894 937
 	}
895 938
 
896 939
 	// Format the time and then restore any literal percent characters
@@ -913,16 +956,19 @@  discard block
 block discarded – undo
913 956
 	static $translation = array();
914 957
 
915 958
 	// Determine the character set... Default to UTF-8
916
-	if (empty($context['character_set']))
917
-		$charset = 'UTF-8';
959
+	if (empty($context['character_set'])) {
960
+			$charset = 'UTF-8';
961
+	}
918 962
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
919
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
920
-		$charset = 'ISO-8859-1';
921
-	else
922
-		$charset = $context['character_set'];
963
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
964
+			$charset = 'ISO-8859-1';
965
+	} else {
966
+			$charset = $context['character_set'];
967
+	}
923 968
 
924
-	if (empty($translation))
925
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
969
+	if (empty($translation)) {
970
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
971
+	}
926 972
 
927 973
 	return strtr($string, $translation);
928 974
 }
@@ -944,8 +990,9 @@  discard block
 block discarded – undo
944 990
 	global $smcFunc;
945 991
 
946 992
 	// It was already short enough!
947
-	if ($smcFunc['strlen']($subject) <= $len)
948
-		return $subject;
993
+	if ($smcFunc['strlen']($subject) <= $len) {
994
+			return $subject;
995
+	}
949 996
 
950 997
 	// Shorten it by the length it was too long, and strip off junk from the end.
951 998
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -964,10 +1011,11 @@  discard block
 block discarded – undo
964 1011
 {
965 1012
 	global $user_info, $modSettings;
966 1013
 
967
-	if ($timestamp === null)
968
-		$timestamp = time();
969
-	elseif ($timestamp == 0)
970
-		return 0;
1014
+	if ($timestamp === null) {
1015
+			$timestamp = time();
1016
+	} elseif ($timestamp == 0) {
1017
+			return 0;
1018
+	}
971 1019
 
972 1020
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
973 1021
 }
@@ -996,8 +1044,9 @@  discard block
 block discarded – undo
996 1044
 		$array[$i] = $array[$j];
997 1045
 		$array[$j] = $temp;
998 1046
 
999
-		for ($i = 1; $p[$i] == 0; $i++)
1000
-			$p[$i] = 1;
1047
+		for ($i = 1; $p[$i] == 0; $i++) {
1048
+					$p[$i] = 1;
1049
+		}
1001 1050
 
1002 1051
 		$orders[] = $array;
1003 1052
 	}
@@ -1029,12 +1078,14 @@  discard block
 block discarded – undo
1029 1078
 	static $disabled;
1030 1079
 
1031 1080
 	// Don't waste cycles
1032
-	if ($message === '')
1033
-		return '';
1081
+	if ($message === '') {
1082
+			return '';
1083
+	}
1034 1084
 
1035 1085
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
1036
-	if (!isset($context['utf8']))
1037
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1086
+	if (!isset($context['utf8'])) {
1087
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1088
+	}
1038 1089
 
1039 1090
 	// Clean up any cut/paste issues we may have
1040 1091
 	$message = sanitizeMSCutPaste($message);
@@ -1046,13 +1097,15 @@  discard block
 block discarded – undo
1046 1097
 		return $message;
1047 1098
 	}
1048 1099
 
1049
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
1050
-		$smileys = (bool) $smileys;
1100
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1101
+			$smileys = (bool) $smileys;
1102
+	}
1051 1103
 
1052 1104
 	if (empty($modSettings['enableBBC']) && $message !== false)
1053 1105
 	{
1054
-		if ($smileys === true)
1055
-			parsesmileys($message);
1106
+		if ($smileys === true) {
1107
+					parsesmileys($message);
1108
+		}
1056 1109
 
1057 1110
 		return $message;
1058 1111
 	}
@@ -1065,8 +1118,9 @@  discard block
 block discarded – undo
1065 1118
 	}
1066 1119
 
1067 1120
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1068
-	if (!empty($modSettings['autoLinkUrls']))
1069
-		set_tld_regex();
1121
+	if (!empty($modSettings['autoLinkUrls'])) {
1122
+			set_tld_regex();
1123
+	}
1070 1124
 
1071 1125
 	// Allow mods access before entering the main parse_bbc loop
1072 1126
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1080,8 +1134,9 @@  discard block
 block discarded – undo
1080 1134
 
1081 1135
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1082 1136
 
1083
-			foreach ($temp as $tag)
1084
-				$disabled[trim($tag)] = true;
1137
+			foreach ($temp as $tag) {
1138
+							$disabled[trim($tag)] = true;
1139
+			}
1085 1140
 		}
1086 1141
 
1087 1142
 		// The YouTube bbc needs this for its origin parameter
@@ -1215,8 +1270,9 @@  discard block
 block discarded – undo
1215 1270
 					$returnContext = '';
1216 1271
 
1217 1272
 					// BBC or the entire attachments feature is disabled
1218
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1219
-						return $data;
1273
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1274
+											return $data;
1275
+					}
1220 1276
 
1221 1277
 					// Save the attach ID.
1222 1278
 					$attachID = $data;
@@ -1227,8 +1283,9 @@  discard block
 block discarded – undo
1227 1283
 					$currentAttachment = parseAttachBBC($attachID);
1228 1284
 
1229 1285
 					// parseAttachBBC will return a string ($txt key) rather than dying with a fatal_error. Up to you to decide what to do.
1230
-					if (is_string($currentAttachment))
1231
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1286
+					if (is_string($currentAttachment)) {
1287
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1288
+					}
1232 1289
 
1233 1290
 					if (!empty($currentAttachment['is_image']))
1234 1291
 					{
@@ -1244,15 +1301,17 @@  discard block
 block discarded – undo
1244 1301
 							$height = ' height="' . $currentAttachment['height'] . '"';
1245 1302
 						}
1246 1303
 
1247
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1248
-							$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>';
1249
-						else
1250
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1304
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1305
+													$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>';
1306
+						} else {
1307
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1308
+						}
1251 1309
 					}
1252 1310
 
1253 1311
 					// No image. Show a link.
1254
-					else
1255
-						$returnContext .= $currentAttachment['link'];
1312
+					else {
1313
+											$returnContext .= $currentAttachment['link'];
1314
+					}
1256 1315
 
1257 1316
 					// Gotta append what we just did.
1258 1317
 					$data = $returnContext;
@@ -1306,8 +1365,9 @@  discard block
 block discarded – undo
1306 1365
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1307 1366
 						{
1308 1367
 							// Do PHP code coloring?
1309
-							if ($php_parts[$php_i] != '&lt;?php')
1310
-								continue;
1368
+							if ($php_parts[$php_i] != '&lt;?php') {
1369
+															continue;
1370
+							}
1311 1371
 
1312 1372
 							$php_string = '';
1313 1373
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1323,8 +1383,9 @@  discard block
 block discarded – undo
1323 1383
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1324 1384
 
1325 1385
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1326
-						if (!empty($context['browser']['is_opera']))
1327
-							$data .= '&nbsp;';
1386
+						if (!empty($context['browser']['is_opera'])) {
1387
+													$data .= '&nbsp;';
1388
+						}
1328 1389
 					}
1329 1390
 				},
1330 1391
 				'block_level' => true,
@@ -1343,8 +1404,9 @@  discard block
 block discarded – undo
1343 1404
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1344 1405
 						{
1345 1406
 							// Do PHP code coloring?
1346
-							if ($php_parts[$php_i] != '&lt;?php')
1347
-								continue;
1407
+							if ($php_parts[$php_i] != '&lt;?php') {
1408
+															continue;
1409
+							}
1348 1410
 
1349 1411
 							$php_string = '';
1350 1412
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1360,8 +1422,9 @@  discard block
 block discarded – undo
1360 1422
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1361 1423
 
1362 1424
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1363
-						if (!empty($context['browser']['is_opera']))
1364
-							$data[0] .= '&nbsp;';
1425
+						if (!empty($context['browser']['is_opera'])) {
1426
+													$data[0] .= '&nbsp;';
1427
+						}
1365 1428
 					}
1366 1429
 				},
1367 1430
 				'block_level' => true,
@@ -1402,10 +1465,11 @@  discard block
 block discarded – undo
1402 1465
 				{
1403 1466
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1404 1467
 
1405
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1406
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1407
-					else
1408
-						$css = '';
1468
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1469
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1470
+					} else {
1471
+											$css = '';
1472
+					}
1409 1473
 
1410 1474
 					$data = $class . $css;
1411 1475
 				},
@@ -1420,8 +1484,9 @@  discard block
 block discarded – undo
1420 1484
 				{
1421 1485
 					$data = strtr($data, array('<br />' => ''));
1422 1486
 
1423
-					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0)
1424
-						$data = 'ftp://' . $data;
1487
+					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) {
1488
+											$data = 'ftp://' . $data;
1489
+					}
1425 1490
 				},
1426 1491
 			),
1427 1492
 			array(
@@ -1431,8 +1496,9 @@  discard block
 block discarded – undo
1431 1496
 				'after' => '</a>',
1432 1497
 				'validate' => function(&$tag, &$data, $disabled)
1433 1498
 				{
1434
-					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0)
1435
-						$data = 'ftp://' . $data;
1499
+					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) {
1500
+											$data = 'ftp://' . $data;
1501
+					}
1436 1502
 				},
1437 1503
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1438 1504
 				'disabled_after' => ' ($1)',
@@ -1492,17 +1558,20 @@  discard block
 block discarded – undo
1492 1558
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1493 1559
 					if ($image_proxy_enabled)
1494 1560
 					{
1495
-						if (!empty($user_info['possibly_robot']))
1496
-							return;
1561
+						if (!empty($user_info['possibly_robot'])) {
1562
+													return;
1563
+						}
1497 1564
 
1498
-						if (empty($scheme))
1499
-							$data = 'http://' . ltrim($data, ':/');
1565
+						if (empty($scheme)) {
1566
+													$data = 'http://' . ltrim($data, ':/');
1567
+						}
1500 1568
 
1501
-						if ($scheme != 'https')
1502
-							$data = get_proxied_url($data);
1569
+						if ($scheme != 'https') {
1570
+													$data = get_proxied_url($data);
1571
+						}
1572
+					} elseif (empty($scheme)) {
1573
+											$data = '//' . ltrim($data, ':/');
1503 1574
 					}
1504
-					elseif (empty($scheme))
1505
-						$data = '//' . ltrim($data, ':/');
1506 1575
 				},
1507 1576
 				'disabled_content' => '($1)',
1508 1577
 			),
@@ -1518,17 +1587,20 @@  discard block
 block discarded – undo
1518 1587
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1519 1588
 					if ($image_proxy_enabled)
1520 1589
 					{
1521
-						if (!empty($user_info['possibly_robot']))
1522
-							return;
1590
+						if (!empty($user_info['possibly_robot'])) {
1591
+													return;
1592
+						}
1523 1593
 
1524
-						if (empty($scheme))
1525
-							$data = 'http://' . ltrim($data, ':/');
1594
+						if (empty($scheme)) {
1595
+													$data = 'http://' . ltrim($data, ':/');
1596
+						}
1526 1597
 
1527
-						if ($scheme != 'https')
1528
-							$data = get_proxied_url($data);
1598
+						if ($scheme != 'https') {
1599
+													$data = get_proxied_url($data);
1600
+						}
1601
+					} elseif (empty($scheme)) {
1602
+											$data = '//' . ltrim($data, ':/');
1529 1603
 					}
1530
-					elseif (empty($scheme))
1531
-						$data = '//' . ltrim($data, ':/');
1532 1604
 				},
1533 1605
 				'disabled_content' => '($1)',
1534 1606
 			),
@@ -1540,8 +1612,9 @@  discard block
 block discarded – undo
1540 1612
 				{
1541 1613
 					$data = strtr($data, array('<br>' => ''));
1542 1614
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1543
-					if (empty($scheme))
1544
-						$data = '//' . ltrim($data, ':/');
1615
+					if (empty($scheme)) {
1616
+											$data = '//' . ltrim($data, ':/');
1617
+					}
1545 1618
 				},
1546 1619
 			),
1547 1620
 			array(
@@ -1552,13 +1625,14 @@  discard block
 block discarded – undo
1552 1625
 				'after' => '</a>',
1553 1626
 				'validate' => function (&$tag, &$data, $disabled)
1554 1627
 				{
1555
-					if (substr($data, 0, 1) == '#')
1556
-						$data = '#post_' . substr($data, 1);
1557
-					else
1628
+					if (substr($data, 0, 1) == '#') {
1629
+											$data = '#post_' . substr($data, 1);
1630
+					} else
1558 1631
 					{
1559 1632
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1560
-						if (empty($scheme))
1561
-							$data = '//' . ltrim($data, ':/');
1633
+						if (empty($scheme)) {
1634
+													$data = '//' . ltrim($data, ':/');
1635
+						}
1562 1636
 					}
1563 1637
 				},
1564 1638
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1649,8 +1723,9 @@  discard block
 block discarded – undo
1649 1723
 					{
1650 1724
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1651 1725
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1652
-						if ($add_begin)
1653
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1726
+						if ($add_begin) {
1727
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1728
+						}
1654 1729
 					}
1655 1730
 				},
1656 1731
 				'block_level' => false,
@@ -1742,20 +1817,17 @@  discard block
 block discarded – undo
1742 1817
 				'validate' => function(&$tag, &$data, $disabled)
1743 1818
 					{
1744 1819
 
1745
-						if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50))
1746
-							$data[1] = '0 -2px 1px';
1747
-
1748
-						elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100))
1749
-							$data[1] = '2px 0 1px';
1750
-
1751
-						elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190))
1752
-							$data[1] = '0 2px 1px';
1753
-
1754
-						elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280))
1755
-							$data[1] = '-2px 0 1px';
1756
-
1757
-						else
1758
-							$data[1] = '1px 1px 1px';
1820
+						if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50)) {
1821
+													$data[1] = '0 -2px 1px';
1822
+						} elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100)) {
1823
+													$data[1] = '2px 0 1px';
1824
+						} elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190)) {
1825
+													$data[1] = '0 2px 1px';
1826
+						} elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280)) {
1827
+													$data[1] = '-2px 0 1px';
1828
+						} else {
1829
+													$data[1] = '1px 1px 1px';
1830
+						}
1759 1831
 					},
1760 1832
 			),
1761 1833
 			array(
@@ -1811,10 +1883,11 @@  discard block
 block discarded – undo
1811 1883
 				'content' => '$1',
1812 1884
 				'validate' => function (&$tag, &$data, $disabled)
1813 1885
 				{
1814
-					if (is_numeric($data))
1815
-						$data = timeformat($data);
1816
-					else
1817
-						$tag['content'] = '[time]$1[/time]';
1886
+					if (is_numeric($data)) {
1887
+											$data = timeformat($data);
1888
+					} else {
1889
+											$tag['content'] = '[time]$1[/time]';
1890
+					}
1818 1891
 				},
1819 1892
 			),
1820 1893
 			array(
@@ -1846,8 +1919,9 @@  discard block
 block discarded – undo
1846 1919
 				{
1847 1920
 					$data = strtr($data, array('<br>' => ''));
1848 1921
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1849
-					if (empty($scheme))
1850
-						$data = '//' . ltrim($data, ':/');
1922
+					if (empty($scheme)) {
1923
+											$data = '//' . ltrim($data, ':/');
1924
+					}
1851 1925
 				},
1852 1926
 			),
1853 1927
 			array(
@@ -1859,8 +1933,9 @@  discard block
 block discarded – undo
1859 1933
 				'validate' => function (&$tag, &$data, $disabled)
1860 1934
 				{
1861 1935
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1862
-					if (empty($scheme))
1863
-						$data = '//' . ltrim($data, ':/');
1936
+					if (empty($scheme)) {
1937
+											$data = '//' . ltrim($data, ':/');
1938
+					}
1864 1939
 				},
1865 1940
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1866 1941
 				'disabled_after' => ' ($1)',
@@ -1887,12 +1962,13 @@  discard block
 block discarded – undo
1887 1962
 		);
1888 1963
 
1889 1964
 		// Handle legacy bbc codes.
1890
-		foreach ($context['legacy_bbc'] as $bbc)
1891
-			$codes[] = array(
1965
+		foreach ($context['legacy_bbc'] as $bbc) {
1966
+					$codes[] = array(
1892 1967
 				'tag' => $bbc,
1893 1968
 				'before' => '',
1894 1969
 				'after' => '',
1895 1970
 			);
1971
+		}
1896 1972
 
1897 1973
 		// Let mods add new BBC without hassle.
1898 1974
 		call_integration_hook('integrate_bbc_codes', array(&$codes, &$no_autolink_tags));
@@ -1900,8 +1976,9 @@  discard block
 block discarded – undo
1900 1976
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1901 1977
 		if ($message === false)
1902 1978
 		{
1903
-			if (isset($temp_bbc))
1904
-				$bbc_codes = $temp_bbc;
1979
+			if (isset($temp_bbc)) {
1980
+							$bbc_codes = $temp_bbc;
1981
+			}
1905 1982
 			usort($codes, function ($a, $b) {
1906 1983
 				return strcmp($a['tag'], $b['tag']);
1907 1984
 			});
@@ -1921,8 +1998,9 @@  discard block
 block discarded – undo
1921 1998
 		);
1922 1999
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1923 2000
 		{
1924
-			foreach ($itemcodes as $c => $dummy)
1925
-				$bbc_codes[$c] = array();
2001
+			foreach ($itemcodes as $c => $dummy) {
2002
+							$bbc_codes[$c] = array();
2003
+			}
1926 2004
 		}
1927 2005
 
1928 2006
 		// Shhhh!
@@ -1943,12 +2021,14 @@  discard block
 block discarded – undo
1943 2021
 		foreach ($codes as $code)
1944 2022
 		{
1945 2023
 			// Make it easier to process parameters later
1946
-			if (!empty($code['parameters']))
1947
-				ksort($code['parameters'], SORT_STRING);
2024
+			if (!empty($code['parameters'])) {
2025
+							ksort($code['parameters'], SORT_STRING);
2026
+			}
1948 2027
 
1949 2028
 			// If we are not doing every tag only do ones we are interested in.
1950
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1951
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2029
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
2030
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2031
+			}
1952 2032
 		}
1953 2033
 		$codes = null;
1954 2034
 	}
@@ -1959,8 +2039,9 @@  discard block
 block discarded – undo
1959 2039
 		// It's likely this will change if the message is modified.
1960 2040
 		$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']);
1961 2041
 
1962
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1963
-			return $temp;
2042
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
2043
+					return $temp;
2044
+		}
1964 2045
 
1965 2046
 		$cache_t = microtime();
1966 2047
 	}
@@ -1992,8 +2073,9 @@  discard block
 block discarded – undo
1992 2073
 		$disabled['flash'] = true;
1993 2074
 
1994 2075
 		// @todo Change maybe?
1995
-		if (!isset($_GET['images']))
1996
-			$disabled['img'] = true;
2076
+		if (!isset($_GET['images'])) {
2077
+					$disabled['img'] = true;
2078
+		}
1997 2079
 
1998 2080
 		// @todo Interface/setting to add more?
1999 2081
 	}
@@ -2004,8 +2086,9 @@  discard block
 block discarded – undo
2004 2086
 	$alltags = array();
2005 2087
 	foreach ($bbc_codes as $section)
2006 2088
 	{
2007
-		foreach ($section as $code)
2008
-			$alltags[] = $code['tag'];
2089
+		foreach ($section as $code) {
2090
+					$alltags[] = $code['tag'];
2091
+		}
2009 2092
 	}
2010 2093
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
2011 2094
 
@@ -2017,8 +2100,9 @@  discard block
 block discarded – undo
2017 2100
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
2018 2101
 
2019 2102
 		// Failsafe.
2020
-		if ($pos === false || $last_pos > $pos)
2021
-			$pos = strlen($message) + 1;
2103
+		if ($pos === false || $last_pos > $pos) {
2104
+					$pos = strlen($message) + 1;
2105
+		}
2022 2106
 
2023 2107
 		// Can't have a one letter smiley, URL, or email! (sorry.)
2024 2108
 		if ($last_pos < $pos - 1)
@@ -2036,8 +2120,9 @@  discard block
 block discarded – undo
2036 2120
 
2037 2121
 				// <br> should be empty.
2038 2122
 				$empty_tags = array('br', 'hr');
2039
-				foreach ($empty_tags as $tag)
2040
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2123
+				foreach ($empty_tags as $tag) {
2124
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2125
+				}
2041 2126
 
2042 2127
 				// b, u, i, s, pre... basic tags.
2043 2128
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong');
@@ -2046,8 +2131,9 @@  discard block
 block discarded – undo
2046 2131
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
2047 2132
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
2048 2133
 
2049
-					if ($diff > 0)
2050
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2134
+					if ($diff > 0) {
2135
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2136
+					}
2051 2137
 				}
2052 2138
 
2053 2139
 				// Do <img ...> - with security... action= -> action-.
@@ -2060,8 +2146,9 @@  discard block
 block discarded – undo
2060 2146
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
2061 2147
 
2062 2148
 						// Remove action= from the URL - no funny business, now.
2063
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
2064
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2149
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
2150
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2151
+						}
2065 2152
 
2066 2153
 						$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
2067 2154
 					}
@@ -2076,16 +2163,18 @@  discard block
 block discarded – undo
2076 2163
 				$no_autolink_area = false;
2077 2164
 				if (!empty($open_tags))
2078 2165
 				{
2079
-					foreach ($open_tags as $open_tag)
2080
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2166
+					foreach ($open_tags as $open_tag) {
2167
+											if (in_array($open_tag['tag'], $no_autolink_tags))
2081 2168
 							$no_autolink_area = true;
2169
+					}
2082 2170
 				}
2083 2171
 
2084 2172
 				// Don't go backwards.
2085 2173
 				// @todo Don't think is the real solution....
2086 2174
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
2087
-				if ($pos < $lastAutoPos)
2088
-					$no_autolink_area = true;
2175
+				if ($pos < $lastAutoPos) {
2176
+									$no_autolink_area = true;
2177
+				}
2089 2178
 				$lastAutoPos = $pos;
2090 2179
 
2091 2180
 				if (!$no_autolink_area)
@@ -2190,29 +2279,33 @@  discard block
 block discarded – undo
2190 2279
 							$url = array_shift($matches);
2191 2280
 
2192 2281
 							// If this isn't a clean URL, bail out
2193
-							if ($url != sanitize_iri($url))
2194
-								return $url;
2282
+							if ($url != sanitize_iri($url)) {
2283
+															return $url;
2284
+							}
2195 2285
 
2196 2286
 							$scheme = parse_url($url, PHP_URL_SCHEME);
2197 2287
 
2198 2288
 							if ($scheme == 'mailto')
2199 2289
 							{
2200 2290
 								$email_address = str_replace('mailto:', '', $url);
2201
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2202
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2203
-								else
2204
-									return $url;
2291
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2292
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2293
+								} else {
2294
+																	return $url;
2295
+								}
2205 2296
 							}
2206 2297
 
2207 2298
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2208
-							if (empty($scheme))
2209
-								$fullUrl = '//' . ltrim($url, ':/');
2210
-							else
2211
-								$fullUrl = $url;
2299
+							if (empty($scheme)) {
2300
+															$fullUrl = '//' . ltrim($url, ':/');
2301
+							} else {
2302
+															$fullUrl = $url;
2303
+							}
2212 2304
 
2213 2305
 							// Make sure that $fullUrl really is valid
2214
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2215
-								return $url;
2306
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) {
2307
+															return $url;
2308
+							}
2216 2309
 
2217 2310
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2218 2311
 						}, $data);
@@ -2261,22 +2354,25 @@  discard block
 block discarded – undo
2261 2354
 		}
2262 2355
 
2263 2356
 		// Are we there yet?  Are we there yet?
2264
-		if ($pos >= strlen($message) - 1)
2265
-			break;
2357
+		if ($pos >= strlen($message) - 1) {
2358
+					break;
2359
+		}
2266 2360
 
2267 2361
 		$tags = strtolower($message[$pos + 1]);
2268 2362
 
2269 2363
 		if ($tags == '/' && !empty($open_tags))
2270 2364
 		{
2271 2365
 			$pos2 = strpos($message, ']', $pos + 1);
2272
-			if ($pos2 == $pos + 2)
2273
-				continue;
2366
+			if ($pos2 == $pos + 2) {
2367
+							continue;
2368
+			}
2274 2369
 
2275 2370
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2276 2371
 
2277 2372
 			// A closing tag that doesn't match any open tags? Skip it.
2278
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2279
-				continue;
2373
+			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) {
2374
+							continue;
2375
+			}
2280 2376
 
2281 2377
 			$to_close = array();
2282 2378
 			$block_level = null;
@@ -2284,8 +2380,9 @@  discard block
 block discarded – undo
2284 2380
 			do
2285 2381
 			{
2286 2382
 				$tag = array_pop($open_tags);
2287
-				if (!$tag)
2288
-					break;
2383
+				if (!$tag) {
2384
+									break;
2385
+				}
2289 2386
 
2290 2387
 				if (!empty($tag['block_level']))
2291 2388
 				{
@@ -2299,10 +2396,11 @@  discard block
 block discarded – undo
2299 2396
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2300 2397
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2301 2398
 					{
2302
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2303
-							if ($temp['tag'] == $look_for)
2399
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2400
+													if ($temp['tag'] == $look_for)
2304 2401
 							{
2305 2402
 								$block_level = !empty($temp['block_level']);
2403
+						}
2306 2404
 								break;
2307 2405
 							}
2308 2406
 					}
@@ -2324,15 +2422,15 @@  discard block
 block discarded – undo
2324 2422
 			{
2325 2423
 				$open_tags = $to_close;
2326 2424
 				continue;
2327
-			}
2328
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2425
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2329 2426
 			{
2330 2427
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2331 2428
 				{
2332
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2333
-						if ($temp['tag'] == $look_for)
2429
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2430
+											if ($temp['tag'] == $look_for)
2334 2431
 						{
2335 2432
 							$block_level = !empty($temp['block_level']);
2433
+					}
2336 2434
 							break;
2337 2435
 						}
2338 2436
 				}
@@ -2340,8 +2438,9 @@  discard block
 block discarded – undo
2340 2438
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2341 2439
 				if (!$block_level)
2342 2440
 				{
2343
-					foreach ($to_close as $tag)
2344
-						array_push($open_tags, $tag);
2441
+					foreach ($to_close as $tag) {
2442
+											array_push($open_tags, $tag);
2443
+					}
2345 2444
 					continue;
2346 2445
 				}
2347 2446
 			}
@@ -2354,14 +2453,17 @@  discard block
 block discarded – undo
2354 2453
 
2355 2454
 				// See the comment at the end of the big loop - just eating whitespace ;).
2356 2455
 				$whitespace_regex = '';
2357
-				if (!empty($tag['block_level']))
2358
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2456
+				if (!empty($tag['block_level'])) {
2457
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2458
+				}
2359 2459
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2360
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2361
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2460
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2461
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2462
+				}
2362 2463
 
2363
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2364
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2464
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2465
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2466
+				}
2365 2467
 			}
2366 2468
 
2367 2469
 			if (!empty($to_close))
@@ -2374,8 +2476,9 @@  discard block
 block discarded – undo
2374 2476
 		}
2375 2477
 
2376 2478
 		// No tags for this character, so just keep going (fastest possible course.)
2377
-		if (!isset($bbc_codes[$tags]))
2378
-			continue;
2479
+		if (!isset($bbc_codes[$tags])) {
2480
+					continue;
2481
+		}
2379 2482
 
2380 2483
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2381 2484
 		$tag = null;
@@ -2384,48 +2487,57 @@  discard block
 block discarded – undo
2384 2487
 			$pt_strlen = strlen($possible['tag']);
2385 2488
 
2386 2489
 			// Not a match?
2387
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2388
-				continue;
2490
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2491
+							continue;
2492
+			}
2389 2493
 
2390 2494
 			$next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : '';
2391 2495
 
2392 2496
 			// A tag is the last char maybe
2393
-			if ($next_c == '')
2394
-				break;
2497
+			if ($next_c == '') {
2498
+							break;
2499
+			}
2395 2500
 
2396 2501
 			// A test validation?
2397
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2398
-				continue;
2502
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2503
+							continue;
2504
+			}
2399 2505
 			// Do we want parameters?
2400 2506
 			elseif (!empty($possible['parameters']))
2401 2507
 			{
2402
-				if ($next_c != ' ')
2403
-					continue;
2404
-			}
2405
-			elseif (isset($possible['type']))
2508
+				if ($next_c != ' ') {
2509
+									continue;
2510
+				}
2511
+			} elseif (isset($possible['type']))
2406 2512
 			{
2407 2513
 				// Do we need an equal sign?
2408
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2409
-					continue;
2514
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2515
+									continue;
2516
+				}
2410 2517
 				// Maybe we just want a /...
2411
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2412
-					continue;
2518
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2519
+									continue;
2520
+				}
2413 2521
 				// An immediate ]?
2414
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2415
-					continue;
2522
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2523
+									continue;
2524
+				}
2416 2525
 			}
2417 2526
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2418
-			elseif ($next_c != ']')
2419
-				continue;
2527
+			elseif ($next_c != ']') {
2528
+							continue;
2529
+			}
2420 2530
 
2421 2531
 			// Check allowed tree?
2422
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2423
-				continue;
2424
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2425
-				continue;
2532
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2533
+							continue;
2534
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2535
+							continue;
2536
+			}
2426 2537
 			// If this is in the list of disallowed child tags, don't parse it.
2427
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2428
-				continue;
2538
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2539
+							continue;
2540
+			}
2429 2541
 
2430 2542
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2431 2543
 
@@ -2437,8 +2549,9 @@  discard block
 block discarded – undo
2437 2549
 				foreach ($open_tags as $open_quote)
2438 2550
 				{
2439 2551
 					// Every parent quote this quote has flips the styling
2440
-					if ($open_quote['tag'] == 'quote')
2441
-						$quote_alt = !$quote_alt;
2552
+					if ($open_quote['tag'] == 'quote') {
2553
+											$quote_alt = !$quote_alt;
2554
+					}
2442 2555
 				}
2443 2556
 				// Add a class to the quote to style alternating blockquotes
2444 2557
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2449,8 +2562,9 @@  discard block
 block discarded – undo
2449 2562
 			{
2450 2563
 				// Build a regular expression for each parameter for the current tag.
2451 2564
 				$preg = array();
2452
-				foreach ($possible['parameters'] as $p => $info)
2453
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2565
+				foreach ($possible['parameters'] as $p => $info) {
2566
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2567
+				}
2454 2568
 
2455 2569
 				// Extract the string that potentially holds our parameters.
2456 2570
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2469,24 +2583,27 @@  discard block
 block discarded – undo
2469 2583
 
2470 2584
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2471 2585
 
2472
-					if ($match)
2473
-						$blob_counter = count($blobs) + 1;
2586
+					if ($match) {
2587
+											$blob_counter = count($blobs) + 1;
2588
+					}
2474 2589
 				}
2475 2590
 
2476 2591
 				// Didn't match our parameter list, try the next possible.
2477
-				if (!$match)
2478
-					continue;
2592
+				if (!$match) {
2593
+									continue;
2594
+				}
2479 2595
 
2480 2596
 				$params = array();
2481 2597
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2482 2598
 				{
2483 2599
 					$key = strtok(ltrim($matches[$i]), '=');
2484
-					if (isset($possible['parameters'][$key]['value']))
2485
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2486
-					elseif (isset($possible['parameters'][$key]['validate']))
2487
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2488
-					else
2489
-						$params['{' . $key . '}'] = $matches[$i + 1];
2600
+					if (isset($possible['parameters'][$key]['value'])) {
2601
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2602
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2603
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2604
+					} else {
2605
+											$params['{' . $key . '}'] = $matches[$i + 1];
2606
+					}
2490 2607
 
2491 2608
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2492 2609
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2494,23 +2611,26 @@  discard block
 block discarded – undo
2494 2611
 
2495 2612
 				foreach ($possible['parameters'] as $p => $info)
2496 2613
 				{
2497
-					if (!isset($params['{' . $p . '}']))
2498
-						$params['{' . $p . '}'] = '';
2614
+					if (!isset($params['{' . $p . '}'])) {
2615
+											$params['{' . $p . '}'] = '';
2616
+					}
2499 2617
 				}
2500 2618
 
2501 2619
 				$tag = $possible;
2502 2620
 
2503 2621
 				// Put the parameters into the string.
2504
-				if (isset($tag['before']))
2505
-					$tag['before'] = strtr($tag['before'], $params);
2506
-				if (isset($tag['after']))
2507
-					$tag['after'] = strtr($tag['after'], $params);
2508
-				if (isset($tag['content']))
2509
-					$tag['content'] = strtr($tag['content'], $params);
2622
+				if (isset($tag['before'])) {
2623
+									$tag['before'] = strtr($tag['before'], $params);
2624
+				}
2625
+				if (isset($tag['after'])) {
2626
+									$tag['after'] = strtr($tag['after'], $params);
2627
+				}
2628
+				if (isset($tag['content'])) {
2629
+									$tag['content'] = strtr($tag['content'], $params);
2630
+				}
2510 2631
 
2511 2632
 				$pos1 += strlen($given_param_string);
2512
-			}
2513
-			else
2633
+			} else
2514 2634
 			{
2515 2635
 				$tag = $possible;
2516 2636
 				$params = array();
@@ -2521,8 +2641,9 @@  discard block
 block discarded – undo
2521 2641
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2522 2642
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2523 2643
 		{
2524
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2525
-				continue;
2644
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2645
+							continue;
2646
+			}
2526 2647
 
2527 2648
 			$tag = $itemcodes[$message[$pos + 1]];
2528 2649
 
@@ -2543,9 +2664,9 @@  discard block
 block discarded – undo
2543 2664
 			{
2544 2665
 				array_pop($open_tags);
2545 2666
 				$code = '</li>';
2667
+			} else {
2668
+							$code = '';
2546 2669
 			}
2547
-			else
2548
-				$code = '';
2549 2670
 
2550 2671
 			// Now we open a new tag.
2551 2672
 			$open_tags[] = array(
@@ -2592,12 +2713,14 @@  discard block
 block discarded – undo
2592 2713
 		}
2593 2714
 
2594 2715
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2595
-		if ($tag === null)
2596
-			continue;
2716
+		if ($tag === null) {
2717
+					continue;
2718
+		}
2597 2719
 
2598 2720
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2599
-		if (isset($inside['disallow_children']))
2600
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2721
+		if (isset($inside['disallow_children'])) {
2722
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2723
+		}
2601 2724
 
2602 2725
 		// Is this tag disabled?
2603 2726
 		if (isset($disabled[$tag['tag']]))
@@ -2607,14 +2730,13 @@  discard block
 block discarded – undo
2607 2730
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2608 2731
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2609 2732
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2610
-			}
2611
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2733
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2612 2734
 			{
2613 2735
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2614 2736
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2737
+			} else {
2738
+							$tag['content'] = $tag['disabled_content'];
2615 2739
 			}
2616
-			else
2617
-				$tag['content'] = $tag['disabled_content'];
2618 2740
 		}
2619 2741
 
2620 2742
 		// we use this a lot
@@ -2624,8 +2746,9 @@  discard block
 block discarded – undo
2624 2746
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2625 2747
 		{
2626 2748
 			$n = count($open_tags) - 1;
2627
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2628
-				$n--;
2749
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2750
+							$n--;
2751
+			}
2629 2752
 
2630 2753
 			// Close all the non block level tags so this tag isn't surrounded by them.
2631 2754
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2637,12 +2760,15 @@  discard block
 block discarded – undo
2637 2760
 
2638 2761
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2639 2762
 				$whitespace_regex = '';
2640
-				if (!empty($tag['block_level']))
2641
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2642
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2643
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2644
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2645
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2763
+				if (!empty($tag['block_level'])) {
2764
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2765
+				}
2766
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2767
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2768
+				}
2769
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2770
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2771
+				}
2646 2772
 
2647 2773
 				array_pop($open_tags);
2648 2774
 			}
@@ -2663,16 +2789,19 @@  discard block
 block discarded – undo
2663 2789
 		elseif ($tag['type'] == 'unparsed_content')
2664 2790
 		{
2665 2791
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2666
-			if ($pos2 === false)
2667
-				continue;
2792
+			if ($pos2 === false) {
2793
+							continue;
2794
+			}
2668 2795
 
2669 2796
 			$data = substr($message, $pos1, $pos2 - $pos1);
2670 2797
 
2671
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2672
-				$data = substr($data, 4);
2798
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2799
+							$data = substr($data, 4);
2800
+			}
2673 2801
 
2674
-			if (isset($tag['validate']))
2675
-				$tag['validate']($tag, $data, $disabled, $params);
2802
+			if (isset($tag['validate'])) {
2803
+							$tag['validate']($tag, $data, $disabled, $params);
2804
+			}
2676 2805
 
2677 2806
 			$code = strtr($tag['content'], array('$1' => $data));
2678 2807
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2687,34 +2816,40 @@  discard block
 block discarded – undo
2687 2816
 			if (isset($tag['quoted']))
2688 2817
 			{
2689 2818
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2690
-				if ($tag['quoted'] != 'optional' && !$quoted)
2691
-					continue;
2819
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2820
+									continue;
2821
+				}
2692 2822
 
2693
-				if ($quoted)
2694
-					$pos1 += 6;
2823
+				if ($quoted) {
2824
+									$pos1 += 6;
2825
+				}
2826
+			} else {
2827
+							$quoted = false;
2695 2828
 			}
2696
-			else
2697
-				$quoted = false;
2698 2829
 
2699 2830
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2700
-			if ($pos2 === false)
2701
-				continue;
2831
+			if ($pos2 === false) {
2832
+							continue;
2833
+			}
2702 2834
 
2703 2835
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2704
-			if ($pos3 === false)
2705
-				continue;
2836
+			if ($pos3 === false) {
2837
+							continue;
2838
+			}
2706 2839
 
2707 2840
 			$data = array(
2708 2841
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2709 2842
 				substr($message, $pos1, $pos2 - $pos1)
2710 2843
 			);
2711 2844
 
2712
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2713
-				$data[0] = substr($data[0], 4);
2845
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2846
+							$data[0] = substr($data[0], 4);
2847
+			}
2714 2848
 
2715 2849
 			// Validation for my parking, please!
2716
-			if (isset($tag['validate']))
2717
-				$tag['validate']($tag, $data, $disabled, $params);
2850
+			if (isset($tag['validate'])) {
2851
+							$tag['validate']($tag, $data, $disabled, $params);
2852
+			}
2718 2853
 
2719 2854
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2720 2855
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2731,23 +2866,27 @@  discard block
 block discarded – undo
2731 2866
 		elseif ($tag['type'] == 'unparsed_commas_content')
2732 2867
 		{
2733 2868
 			$pos2 = strpos($message, ']', $pos1);
2734
-			if ($pos2 === false)
2735
-				continue;
2869
+			if ($pos2 === false) {
2870
+							continue;
2871
+			}
2736 2872
 
2737 2873
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2738
-			if ($pos3 === false)
2739
-				continue;
2874
+			if ($pos3 === false) {
2875
+							continue;
2876
+			}
2740 2877
 
2741 2878
 			// We want $1 to be the content, and the rest to be csv.
2742 2879
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2743 2880
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2744 2881
 
2745
-			if (isset($tag['validate']))
2746
-				$tag['validate']($tag, $data, $disabled, $params);
2882
+			if (isset($tag['validate'])) {
2883
+							$tag['validate']($tag, $data, $disabled, $params);
2884
+			}
2747 2885
 
2748 2886
 			$code = $tag['content'];
2749
-			foreach ($data as $k => $d)
2750
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2887
+			foreach ($data as $k => $d) {
2888
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2889
+			}
2751 2890
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2752 2891
 			$pos += strlen($code) - 1 + 2;
2753 2892
 		}
@@ -2755,24 +2894,28 @@  discard block
 block discarded – undo
2755 2894
 		elseif ($tag['type'] == 'unparsed_commas')
2756 2895
 		{
2757 2896
 			$pos2 = strpos($message, ']', $pos1);
2758
-			if ($pos2 === false)
2759
-				continue;
2897
+			if ($pos2 === false) {
2898
+							continue;
2899
+			}
2760 2900
 
2761 2901
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2762 2902
 
2763
-			if (isset($tag['validate']))
2764
-				$tag['validate']($tag, $data, $disabled, $params);
2903
+			if (isset($tag['validate'])) {
2904
+							$tag['validate']($tag, $data, $disabled, $params);
2905
+			}
2765 2906
 
2766 2907
 			// Fix after, for disabled code mainly.
2767
-			foreach ($data as $k => $d)
2768
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2908
+			foreach ($data as $k => $d) {
2909
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2910
+			}
2769 2911
 
2770 2912
 			$open_tags[] = $tag;
2771 2913
 
2772 2914
 			// Replace them out, $1, $2, $3, $4, etc.
2773 2915
 			$code = $tag['before'];
2774
-			foreach ($data as $k => $d)
2775
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2916
+			foreach ($data as $k => $d) {
2917
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2918
+			}
2776 2919
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2777 2920
 			$pos += strlen($code) - 1 + 2;
2778 2921
 		}
@@ -2783,28 +2926,33 @@  discard block
 block discarded – undo
2783 2926
 			if (isset($tag['quoted']))
2784 2927
 			{
2785 2928
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2786
-				if ($tag['quoted'] != 'optional' && !$quoted)
2787
-					continue;
2929
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2930
+									continue;
2931
+				}
2788 2932
 
2789
-				if ($quoted)
2790
-					$pos1 += 6;
2933
+				if ($quoted) {
2934
+									$pos1 += 6;
2935
+				}
2936
+			} else {
2937
+							$quoted = false;
2791 2938
 			}
2792
-			else
2793
-				$quoted = false;
2794 2939
 
2795 2940
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2796
-			if ($pos2 === false)
2797
-				continue;
2941
+			if ($pos2 === false) {
2942
+							continue;
2943
+			}
2798 2944
 
2799 2945
 			$data = substr($message, $pos1, $pos2 - $pos1);
2800 2946
 
2801 2947
 			// Validation for my parking, please!
2802
-			if (isset($tag['validate']))
2803
-				$tag['validate']($tag, $data, $disabled, $params);
2948
+			if (isset($tag['validate'])) {
2949
+							$tag['validate']($tag, $data, $disabled, $params);
2950
+			}
2804 2951
 
2805 2952
 			// For parsed content, we must recurse to avoid security problems.
2806
-			if ($tag['type'] != 'unparsed_equals')
2807
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2953
+			if ($tag['type'] != 'unparsed_equals') {
2954
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2955
+			}
2808 2956
 
2809 2957
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2810 2958
 
@@ -2816,34 +2964,40 @@  discard block
 block discarded – undo
2816 2964
 		}
2817 2965
 
2818 2966
 		// If this is block level, eat any breaks after it.
2819
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2820
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2967
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2968
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2969
+		}
2821 2970
 
2822 2971
 		// Are we trimming outside this tag?
2823
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2824
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2972
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2973
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2974
+		}
2825 2975
 	}
2826 2976
 
2827 2977
 	// Close any remaining tags.
2828
-	while ($tag = array_pop($open_tags))
2829
-		$message .= "\n" . $tag['after'] . "\n";
2978
+	while ($tag = array_pop($open_tags)) {
2979
+			$message .= "\n" . $tag['after'] . "\n";
2980
+	}
2830 2981
 
2831 2982
 	// Parse the smileys within the parts where it can be done safely.
2832 2983
 	if ($smileys === true)
2833 2984
 	{
2834 2985
 		$message_parts = explode("\n", $message);
2835
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2836
-			parsesmileys($message_parts[$i]);
2986
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2987
+					parsesmileys($message_parts[$i]);
2988
+		}
2837 2989
 
2838 2990
 		$message = implode('', $message_parts);
2839 2991
 	}
2840 2992
 
2841 2993
 	// No smileys, just get rid of the markers.
2842
-	else
2843
-		$message = strtr($message, array("\n" => ''));
2994
+	else {
2995
+			$message = strtr($message, array("\n" => ''));
2996
+	}
2844 2997
 
2845
-	if ($message !== '' && $message[0] === ' ')
2846
-		$message = '&nbsp;' . substr($message, 1);
2998
+	if ($message !== '' && $message[0] === ' ') {
2999
+			$message = '&nbsp;' . substr($message, 1);
3000
+	}
2847 3001
 
2848 3002
 	// Cleanup whitespace.
2849 3003
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2852,15 +3006,16 @@  discard block
 block discarded – undo
2852 3006
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2853 3007
 
2854 3008
 	// Cache the output if it took some time...
2855
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2856
-		cache_put_data($cache_key, $message, 240);
3009
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
3010
+			cache_put_data($cache_key, $message, 240);
3011
+	}
2857 3012
 
2858 3013
 	// If this was a force parse revert if needed.
2859 3014
 	if (!empty($parse_tags))
2860 3015
 	{
2861
-		if (empty($temp_bbc))
2862
-			$bbc_codes = array();
2863
-		else
3016
+		if (empty($temp_bbc)) {
3017
+					$bbc_codes = array();
3018
+		} else
2864 3019
 		{
2865 3020
 			$bbc_codes = $temp_bbc;
2866 3021
 			unset($temp_bbc);
@@ -2887,8 +3042,9 @@  discard block
 block discarded – undo
2887 3042
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2888 3043
 
2889 3044
 	// No smiley set at all?!
2890
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2891
-		return;
3045
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
3046
+			return;
3047
+	}
2892 3048
 
2893 3049
 	// Maybe a mod wants to implement an alternative method (e.g. emojis instead of images)
2894 3050
 	call_integration_hook('integrate_smileys', array(&$smileyPregSearch, &$smileyPregReplacements));
@@ -2902,8 +3058,7 @@  discard block
 block discarded – undo
2902 3058
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', 'O:-)');
2903 3059
 			$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');
2904 3060
 			$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'], '', '', '', '');
2905
-		}
2906
-		else
3061
+		} else
2907 3062
 		{
2908 3063
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2909 3064
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2927,9 +3082,9 @@  discard block
 block discarded – undo
2927 3082
 				$smcFunc['db_free_result']($result);
2928 3083
 
2929 3084
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
3085
+			} else {
3086
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2930 3087
 			}
2931
-			else
2932
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2933 3088
 		}
2934 3089
 
2935 3090
 		// The non-breaking-space is a complex thing...
@@ -2951,16 +3106,18 @@  discard block
 block discarded – undo
2951 3106
 				$alt_images = glob($smileys_dir . $fname .  '.{' . (implode(',', $exts)) . '}', GLOB_BRACE);
2952 3107
 				if (!empty($alt_images))
2953 3108
 				{
2954
-					foreach ($exts as $ext)
2955
-						if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
3109
+					foreach ($exts as $ext) {
3110
+											if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
2956 3111
 						{
2957 3112
 							$smileysto[$i] = $fname . '.' . $ext;
3113
+					}
2958 3114
 							break;
2959 3115
 						}
2960 3116
 				}
2961 3117
 				// If we have no image, just leave the text version in place
2962
-				else
2963
-					continue;
3118
+				else {
3119
+									continue;
3120
+				}
2964 3121
 			}
2965 3122
 
2966 3123
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
@@ -3036,12 +3193,14 @@  discard block
 block discarded – undo
3036 3193
 	global $boardurl, $image_proxy_enabled, $image_proxy_secret;
3037 3194
 
3038 3195
 	// Only use the proxy if enabled and necessary
3039
-	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https')
3040
-		return $url;
3196
+	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') {
3197
+			return $url;
3198
+	}
3041 3199
 
3042 3200
 	// We don't need to proxy our own resources
3043
-	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0)
3044
-		return strtr($url, array('http://' => 'https://'));
3201
+	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) {
3202
+			return strtr($url, array('http://' => 'https://'));
3203
+	}
3045 3204
 
3046 3205
 	// By default, use SMF's own image proxy script
3047 3206
 	$proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret);
@@ -3066,35 +3225,41 @@  discard block
 block discarded – undo
3066 3225
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
3067 3226
 
3068 3227
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
3069
-	if (!empty($context['flush_mail']))
3070
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3228
+	if (!empty($context['flush_mail'])) {
3229
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3071 3230
 		AddMailQueue(true);
3231
+	}
3072 3232
 
3073 3233
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
3074 3234
 
3075
-	if ($add)
3076
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3235
+	if ($add) {
3236
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3237
+	}
3077 3238
 
3078 3239
 	// Put the session ID in.
3079
-	if (defined('SID') && SID != '')
3080
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3240
+	if (defined('SID') && SID != '') {
3241
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3242
+	}
3081 3243
 	// Keep that debug in their for template debugging!
3082
-	elseif (isset($_GET['debug']))
3083
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3244
+	elseif (isset($_GET['debug'])) {
3245
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3246
+	}
3084 3247
 
3085 3248
 	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'])))
3086 3249
 	{
3087
-		if (defined('SID') && SID != '')
3088
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3250
+		if (defined('SID') && SID != '') {
3251
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3089 3252
 				function ($m) use ($scripturl)
3090 3253
 				{
3091 3254
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3255
+		}
3092 3256
 				}, $setLocation);
3093
-		else
3094
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3257
+		else {
3258
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3095 3259
 				function ($m) use ($scripturl)
3096 3260
 				{
3097 3261
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3262
+		}
3098 3263
 				}, $setLocation);
3099 3264
 	}
3100 3265
 
@@ -3105,8 +3270,9 @@  discard block
 block discarded – undo
3105 3270
 	header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
3106 3271
 
3107 3272
 	// Debugging.
3108
-	if (isset($db_show_debug) && $db_show_debug === true)
3109
-		$_SESSION['debug_redirect'] = $db_cache;
3273
+	if (isset($db_show_debug) && $db_show_debug === true) {
3274
+			$_SESSION['debug_redirect'] = $db_cache;
3275
+	}
3110 3276
 
3111 3277
 	obExit(false);
3112 3278
 }
@@ -3125,51 +3291,60 @@  discard block
 block discarded – undo
3125 3291
 
3126 3292
 	// Attempt to prevent a recursive loop.
3127 3293
 	++$level;
3128
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
3129
-		exit;
3130
-	if ($from_fatal_error)
3131
-		$has_fatal_error = true;
3294
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3295
+			exit;
3296
+	}
3297
+	if ($from_fatal_error) {
3298
+			$has_fatal_error = true;
3299
+	}
3132 3300
 
3133 3301
 	// Clear out the stat cache.
3134 3302
 	trackStats();
3135 3303
 
3136 3304
 	// If we have mail to send, send it.
3137
-	if (!empty($context['flush_mail']))
3138
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3305
+	if (!empty($context['flush_mail'])) {
3306
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3139 3307
 		AddMailQueue(true);
3308
+	}
3140 3309
 
3141 3310
 	$do_header = $header === null ? !$header_done : $header;
3142
-	if ($do_footer === null)
3143
-		$do_footer = $do_header;
3311
+	if ($do_footer === null) {
3312
+			$do_footer = $do_header;
3313
+	}
3144 3314
 
3145 3315
 	// Has the template/header been done yet?
3146 3316
 	if ($do_header)
3147 3317
 	{
3148 3318
 		// Was the page title set last minute? Also update the HTML safe one.
3149
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
3150
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3319
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3320
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3321
+		}
3151 3322
 
3152 3323
 		// Start up the session URL fixer.
3153 3324
 		ob_start('ob_sessrewrite');
3154 3325
 
3155
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
3156
-			$buffers = explode(',', $settings['output_buffers']);
3157
-		elseif (!empty($settings['output_buffers']))
3158
-			$buffers = $settings['output_buffers'];
3159
-		else
3160
-			$buffers = array();
3326
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3327
+					$buffers = explode(',', $settings['output_buffers']);
3328
+		} elseif (!empty($settings['output_buffers'])) {
3329
+					$buffers = $settings['output_buffers'];
3330
+		} else {
3331
+					$buffers = array();
3332
+		}
3161 3333
 
3162
-		if (isset($modSettings['integrate_buffer']))
3163
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3334
+		if (isset($modSettings['integrate_buffer'])) {
3335
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3336
+		}
3164 3337
 
3165
-		if (!empty($buffers))
3166
-			foreach ($buffers as $function)
3338
+		if (!empty($buffers)) {
3339
+					foreach ($buffers as $function)
3167 3340
 			{
3168 3341
 				$call = call_helper($function, true);
3342
+		}
3169 3343
 
3170 3344
 				// Is it valid?
3171
-				if (!empty($call))
3172
-					ob_start($call);
3345
+				if (!empty($call)) {
3346
+									ob_start($call);
3347
+				}
3173 3348
 			}
3174 3349
 
3175 3350
 		// Display the screen in the logical order.
@@ -3181,8 +3356,9 @@  discard block
 block discarded – undo
3181 3356
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
3182 3357
 
3183 3358
 		// Anything special to put out?
3184
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
3185
-			echo $context['insert_after_template'];
3359
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3360
+					echo $context['insert_after_template'];
3361
+		}
3186 3362
 
3187 3363
 		// Just so we don't get caught in an endless loop of errors from the footer...
3188 3364
 		if (!$footer_done)
@@ -3191,14 +3367,16 @@  discard block
 block discarded – undo
3191 3367
 			template_footer();
3192 3368
 
3193 3369
 			// (since this is just debugging... it's okay that it's after </html>.)
3194
-			if (!isset($_REQUEST['xml']))
3195
-				displayDebug();
3370
+			if (!isset($_REQUEST['xml'])) {
3371
+							displayDebug();
3372
+			}
3196 3373
 		}
3197 3374
 	}
3198 3375
 
3199 3376
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
3200
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
3201
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3377
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3378
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3379
+	}
3202 3380
 
3203 3381
 	// For session check verification.... don't switch browsers...
3204 3382
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -3207,9 +3385,10 @@  discard block
 block discarded – undo
3207 3385
 	call_integration_hook('integrate_exit', array($do_footer));
3208 3386
 
3209 3387
 	// Don't exit if we're coming from index.php; that will pass through normally.
3210
-	if (!$from_index)
3211
-		exit;
3212
-}
3388
+	if (!$from_index) {
3389
+			exit;
3390
+	}
3391
+	}
3213 3392
 
3214 3393
 /**
3215 3394
  * Get the size of a specified image with better error handling.
@@ -3228,8 +3407,9 @@  discard block
 block discarded – undo
3228 3407
 	$url = str_replace(' ', '%20', $url);
3229 3408
 
3230 3409
 	// Can we pull this from the cache... please please?
3231
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3232
-		return $temp;
3410
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3411
+			return $temp;
3412
+	}
3233 3413
 	$t = microtime();
3234 3414
 
3235 3415
 	// Get the host to pester...
@@ -3239,12 +3419,10 @@  discard block
 block discarded – undo
3239 3419
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3240 3420
 	{
3241 3421
 		return false;
3242
-	}
3243
-	elseif (!isset($match[1]))
3422
+	} elseif (!isset($match[1]))
3244 3423
 	{
3245 3424
 		$size = @getimagesize($url);
3246
-	}
3247
-	else
3425
+	} else
3248 3426
 	{
3249 3427
 		// Try to connect to the server... give it half a second.
3250 3428
 		$temp = 0;
@@ -3281,12 +3459,14 @@  discard block
 block discarded – undo
3281 3459
 	}
3282 3460
 
3283 3461
 	// If we didn't get it, we failed.
3284
-	if (!isset($size))
3285
-		$size = false;
3462
+	if (!isset($size)) {
3463
+			$size = false;
3464
+	}
3286 3465
 
3287 3466
 	// If this took a long time, we may never have to do it again, but then again we might...
3288
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3289
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3467
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3468
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3469
+	}
3290 3470
 
3291 3471
 	// Didn't work.
3292 3472
 	return $size;
@@ -3304,8 +3484,9 @@  discard block
 block discarded – undo
3304 3484
 
3305 3485
 	// Under SSI this function can be called more then once.  That can cause some problems.
3306 3486
 	//   So only run the function once unless we are forced to run it again.
3307
-	if ($loaded && !$forceload)
3308
-		return;
3487
+	if ($loaded && !$forceload) {
3488
+			return;
3489
+	}
3309 3490
 
3310 3491
 	$loaded = true;
3311 3492
 
@@ -3317,14 +3498,16 @@  discard block
 block discarded – undo
3317 3498
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3318 3499
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3319 3500
 	{
3320
-		if (trim($context['news_lines'][$i]) == '')
3321
-			continue;
3501
+		if (trim($context['news_lines'][$i]) == '') {
3502
+					continue;
3503
+		}
3322 3504
 
3323 3505
 		// Clean it up for presentation ;).
3324 3506
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3325 3507
 	}
3326
-	if (!empty($context['news_lines']))
3327
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3508
+	if (!empty($context['news_lines'])) {
3509
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3510
+	}
3328 3511
 
3329 3512
 	if (!$user_info['is_guest'])
3330 3513
 	{
@@ -3333,40 +3516,48 @@  discard block
 block discarded – undo
3333 3516
 		$context['user']['alerts'] = &$user_info['alerts'];
3334 3517
 
3335 3518
 		// Personal message popup...
3336
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3337
-			$context['user']['popup_messages'] = true;
3338
-		else
3339
-			$context['user']['popup_messages'] = false;
3519
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3520
+					$context['user']['popup_messages'] = true;
3521
+		} else {
3522
+					$context['user']['popup_messages'] = false;
3523
+		}
3340 3524
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3341 3525
 
3342
-		if (allowedTo('moderate_forum'))
3343
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3526
+		if (allowedTo('moderate_forum')) {
3527
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3528
+		}
3344 3529
 
3345 3530
 		$context['user']['avatar'] = array();
3346 3531
 
3347 3532
 		// Check for gravatar first since we might be forcing them...
3348 3533
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3349 3534
 		{
3350
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3351
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3352
-			else
3353
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3535
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3536
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3537
+			} else {
3538
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3539
+			}
3354 3540
 		}
3355 3541
 		// Uploaded?
3356
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3357
-			$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';
3542
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3543
+					$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';
3544
+		}
3358 3545
 		// Full URL?
3359
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3360
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3546
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3547
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3548
+		}
3361 3549
 		// Otherwise we assume it's server stored.
3362
-		elseif ($user_info['avatar']['url'] != '')
3363
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3550
+		elseif ($user_info['avatar']['url'] != '') {
3551
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3552
+		}
3364 3553
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3365
-		else
3366
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3554
+		else {
3555
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3556
+		}
3367 3557
 
3368
-		if (!empty($context['user']['avatar']))
3369
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3558
+		if (!empty($context['user']['avatar'])) {
3559
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3560
+		}
3370 3561
 
3371 3562
 		// Figure out how long they've been logged in.
3372 3563
 		$context['user']['total_time_logged_in'] = array(
@@ -3374,8 +3565,7 @@  discard block
 block discarded – undo
3374 3565
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3375 3566
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3376 3567
 		);
3377
-	}
3378
-	else
3568
+	} else
3379 3569
 	{
3380 3570
 		$context['user']['messages'] = 0;
3381 3571
 		$context['user']['unread_messages'] = 0;
@@ -3383,12 +3573,14 @@  discard block
 block discarded – undo
3383 3573
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3384 3574
 		$context['user']['popup_messages'] = false;
3385 3575
 
3386
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3387
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3576
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3577
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3578
+		}
3388 3579
 
3389 3580
 		// If we've upgraded recently, go easy on the passwords.
3390
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3391
-			$context['disable_login_hashing'] = true;
3581
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3582
+					$context['disable_login_hashing'] = true;
3583
+		}
3392 3584
 	}
3393 3585
 
3394 3586
 	// Setup the main menu items.
@@ -3401,8 +3593,8 @@  discard block
 block discarded – undo
3401 3593
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3402 3594
 
3403 3595
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3404
-	if ($context['show_pm_popup'])
3405
-		addInlineJavaScript('
3596
+	if ($context['show_pm_popup']) {
3597
+			addInlineJavaScript('
3406 3598
 		jQuery(document).ready(function($) {
3407 3599
 			new smc_Popup({
3408 3600
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3410,24 +3602,28 @@  discard block
 block discarded – undo
3410 3602
 				icon_class: \'generic_icons mail_new\'
3411 3603
 			});
3412 3604
 		});');
3605
+	}
3413 3606
 
3414 3607
 	// Add a generic "Are you sure?" confirmation message.
3415 3608
 	addInlineJavaScript('
3416 3609
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3417 3610
 
3418 3611
 	// Now add the capping code for avatars.
3419
-	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')
3420
-		addInlineCss('
3612
+	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') {
3613
+			addInlineCss('
3421 3614
 	img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3615
+	}
3422 3616
 
3423 3617
 	// Add max image limits
3424
-	if (!empty($modSettings['max_image_width']))
3425
-		addInlineCss('
3618
+	if (!empty($modSettings['max_image_width'])) {
3619
+			addInlineCss('
3426 3620
 	.postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }');
3621
+	}
3427 3622
 
3428
-	if (!empty($modSettings['max_image_height']))
3429
-		addInlineCss('
3623
+	if (!empty($modSettings['max_image_height'])) {
3624
+			addInlineCss('
3430 3625
 	.postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }');
3626
+	}
3431 3627
 
3432 3628
 	// This looks weird, but it's because BoardIndex.php references the variable.
3433 3629
 	$context['common_stats']['latest_member'] = array(
@@ -3444,11 +3640,13 @@  discard block
 block discarded – undo
3444 3640
 	);
3445 3641
 	$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']);
3446 3642
 
3447
-	if (empty($settings['theme_version']))
3448
-		addJavaScriptVar('smf_scripturl', $scripturl);
3643
+	if (empty($settings['theme_version'])) {
3644
+			addJavaScriptVar('smf_scripturl', $scripturl);
3645
+	}
3449 3646
 
3450
-	if (!isset($context['page_title']))
3451
-		$context['page_title'] = '';
3647
+	if (!isset($context['page_title'])) {
3648
+			$context['page_title'] = '';
3649
+	}
3452 3650
 
3453 3651
 	// Set some specific vars.
3454 3652
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3458,21 +3656,23 @@  discard block
 block discarded – undo
3458 3656
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3459 3657
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3460 3658
 
3461
-	if (!empty($context['meta_keywords']))
3462
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3659
+	if (!empty($context['meta_keywords'])) {
3660
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3661
+	}
3463 3662
 
3464
-	if (!empty($context['canonical_url']))
3465
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3663
+	if (!empty($context['canonical_url'])) {
3664
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3665
+	}
3466 3666
 
3467
-	if (!empty($settings['og_image']))
3468
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3667
+	if (!empty($settings['og_image'])) {
3668
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3669
+	}
3469 3670
 
3470 3671
 	if (!empty($context['meta_description']))
3471 3672
 	{
3472 3673
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3473 3674
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3474
-	}
3475
-	else
3675
+	} else
3476 3676
 	{
3477 3677
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3478 3678
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3497,8 +3697,9 @@  discard block
 block discarded – undo
3497 3697
 	$memory_needed = memoryReturnBytes($needed);
3498 3698
 
3499 3699
 	// should we account for how much is currently being used?
3500
-	if ($in_use)
3501
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3700
+	if ($in_use) {
3701
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3702
+	}
3502 3703
 
3503 3704
 	// if more is needed, request it
3504 3705
 	if ($memory_current < $memory_needed)
@@ -3521,8 +3722,9 @@  discard block
 block discarded – undo
3521 3722
  */
3522 3723
 function memoryReturnBytes($val)
3523 3724
 {
3524
-	if (is_integer($val))
3525
-		return $val;
3725
+	if (is_integer($val)) {
3726
+			return $val;
3727
+	}
3526 3728
 
3527 3729
 	// Separate the number from the designator
3528 3730
 	$val = trim($val);
@@ -3558,10 +3760,11 @@  discard block
 block discarded – undo
3558 3760
 		header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3559 3761
 
3560 3762
 		// Are we debugging the template/html content?
3561
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3562
-			header('content-type: application/xhtml+xml');
3563
-		elseif (!isset($_REQUEST['xml']))
3564
-			header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3763
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3764
+					header('content-type: application/xhtml+xml');
3765
+		} elseif (!isset($_REQUEST['xml'])) {
3766
+					header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3767
+		}
3565 3768
 	}
3566 3769
 
3567 3770
 	header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3570,8 +3773,9 @@  discard block
 block discarded – undo
3570 3773
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3571 3774
 	{
3572 3775
 		$position = array_search('body', $context['template_layers']);
3573
-		if ($position === false)
3574
-			$position = array_search('main', $context['template_layers']);
3776
+		if ($position === false) {
3777
+					$position = array_search('main', $context['template_layers']);
3778
+		}
3575 3779
 
3576 3780
 		if ($position !== false)
3577 3781
 		{
@@ -3599,23 +3803,25 @@  discard block
 block discarded – undo
3599 3803
 
3600 3804
 			foreach ($securityFiles as $i => $securityFile)
3601 3805
 			{
3602
-				if (!file_exists($boarddir . '/' . $securityFile))
3603
-					unset($securityFiles[$i]);
3806
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3807
+									unset($securityFiles[$i]);
3808
+				}
3604 3809
 			}
3605 3810
 
3606 3811
 			// We are already checking so many files...just few more doesn't make any difference! :P
3607
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3608
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3609
-
3610
-			else
3611
-				$path = $modSettings['attachmentUploadDir'];
3812
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3813
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3814
+			} else {
3815
+							$path = $modSettings['attachmentUploadDir'];
3816
+			}
3612 3817
 
3613 3818
 			secureDirectory($path, true);
3614 3819
 			secureDirectory($cachedir);
3615 3820
 
3616 3821
 			// If agreement is enabled, at least the english version shall exists
3617
-			if ($modSettings['requireAgreement'])
3618
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3822
+			if ($modSettings['requireAgreement']) {
3823
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3824
+			}
3619 3825
 
3620 3826
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3621 3827
 			{
@@ -3630,18 +3836,21 @@  discard block
 block discarded – undo
3630 3836
 					echo '
3631 3837
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3632 3838
 
3633
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3634
-						echo '
3839
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3840
+											echo '
3635 3841
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3842
+					}
3636 3843
 				}
3637 3844
 
3638
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3639
-					echo '
3845
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3846
+									echo '
3640 3847
 				<strong>', $txt['cache_writable'], '</strong><br>';
3848
+				}
3641 3849
 
3642
-				if (!empty($agreement))
3643
-					echo '
3850
+				if (!empty($agreement)) {
3851
+									echo '
3644 3852
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3853
+				}
3645 3854
 
3646 3855
 				echo '
3647 3856
 			</p>
@@ -3656,16 +3865,18 @@  discard block
 block discarded – undo
3656 3865
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3657 3866
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3658 3867
 
3659
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3660
-				echo '
3868
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3869
+							echo '
3661 3870
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3871
+			}
3662 3872
 
3663
-			if (!empty($_SESSION['ban']['expire_time']))
3664
-				echo '
3873
+			if (!empty($_SESSION['ban']['expire_time'])) {
3874
+							echo '
3665 3875
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3666
-			else
3667
-				echo '
3876
+			} else {
3877
+							echo '
3668 3878
 					<div>', $txt['your_ban_expires_never'], '</div>';
3879
+			}
3669 3880
 
3670 3881
 			echo '
3671 3882
 				</div>';
@@ -3681,8 +3892,9 @@  discard block
 block discarded – undo
3681 3892
 	global $forum_copyright, $software_year, $forum_version;
3682 3893
 
3683 3894
 	// Don't display copyright for things like SSI.
3684
-	if (!isset($forum_version) || !isset($software_year))
3685
-		return;
3895
+	if (!isset($forum_version) || !isset($software_year)) {
3896
+			return;
3897
+	}
3686 3898
 
3687 3899
 	// Put in the version...
3688 3900
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3700,9 +3912,10 @@  discard block
 block discarded – undo
3700 3912
 	$context['load_time'] = round(microtime(true) - $time_start, 3);
3701 3913
 	$context['load_queries'] = $db_count;
3702 3914
 
3703
-	foreach (array_reverse($context['template_layers']) as $layer)
3704
-		loadSubTemplate($layer . '_below', true);
3705
-}
3915
+	foreach (array_reverse($context['template_layers']) as $layer) {
3916
+			loadSubTemplate($layer . '_below', true);
3917
+	}
3918
+	}
3706 3919
 
3707 3920
 /**
3708 3921
  * Output the Javascript files
@@ -3736,8 +3949,7 @@  discard block
 block discarded – undo
3736 3949
 			{
3737 3950
 				echo '
3738 3951
 		var ', $key, ';';
3739
-			}
3740
-			else
3952
+			} else
3741 3953
 			{
3742 3954
 				echo '
3743 3955
 		var ', $key, ' = ', $value, ';';
@@ -3756,27 +3968,29 @@  discard block
 block discarded – undo
3756 3968
 		foreach ($context['javascript_files'] as $id => $js_file)
3757 3969
 		{
3758 3970
 			// Last minute call! allow theme authors to disable single files.
3759
-			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3760
-				continue;
3971
+			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3972
+							continue;
3973
+			}
3761 3974
 
3762 3975
 			// By default files don't get minimized unless the file explicitly says so!
3763 3976
 			if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3764 3977
 			{
3765
-				if (!empty($js_file['options']['async']))
3766
-					$toMinify['async'][] = $js_file;
3767
-				elseif (!empty($js_file['options']['defer']))
3768
-					$toMinify['defer'][] = $js_file;
3769
-				else
3770
-					$toMinify['standard'][] = $js_file;
3978
+				if (!empty($js_file['options']['async'])) {
3979
+									$toMinify['async'][] = $js_file;
3980
+				} elseif (!empty($js_file['options']['defer'])) {
3981
+									$toMinify['defer'][] = $js_file;
3982
+				} else {
3983
+									$toMinify['standard'][] = $js_file;
3984
+				}
3771 3985
 
3772 3986
 				// Grab a random seed.
3773
-				if (!isset($minSeed) && isset($js_file['options']['seed']))
3774
-					$minSeed = $js_file['options']['seed'];
3775
-			}
3776
-
3777
-			else
3778
-				echo '
3987
+				if (!isset($minSeed) && isset($js_file['options']['seed'])) {
3988
+									$minSeed = $js_file['options']['seed'];
3989
+				}
3990
+			} else {
3991
+							echo '
3779 3992
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async' : '', !empty($js_file['options']['defer']) ? ' defer' : '', '></script>';
3993
+			}
3780 3994
 		}
3781 3995
 
3782 3996
 		foreach ($toMinify as $js_files)
@@ -3787,9 +4001,10 @@  discard block
 block discarded – undo
3787 4001
 
3788 4002
 				$minSuccessful = array_keys($result) === array('smf_minified');
3789 4003
 
3790
-				foreach ($result as $minFile)
3791
-					echo '
4004
+				foreach ($result as $minFile) {
4005
+									echo '
3792 4006
 	<script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async' : '', !empty($minFile['options']['defer']) ? ' defer' : '', '></script>';
4007
+				}
3793 4008
 			}
3794 4009
 		}
3795 4010
 	}
@@ -3803,8 +4018,9 @@  discard block
 block discarded – undo
3803 4018
 <script>
3804 4019
 window.addEventListener("DOMContentLoaded", function() {';
3805 4020
 
3806
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3807
-				echo $js_code;
4021
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
4022
+							echo $js_code;
4023
+			}
3808 4024
 
3809 4025
 			echo '
3810 4026
 });
@@ -3816,8 +4032,9 @@  discard block
 block discarded – undo
3816 4032
 			echo '
3817 4033
 	<script>';
3818 4034
 
3819
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3820
-				echo $js_code;
4035
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
4036
+							echo $js_code;
4037
+			}
3821 4038
 
3822 4039
 			echo '
3823 4040
 	</script>';
@@ -3845,23 +4062,26 @@  discard block
 block discarded – undo
3845 4062
 	foreach ($context['css_files'] as $id => $file)
3846 4063
 	{
3847 4064
 		// Last minute call! allow theme authors to disable single files.
3848
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3849
-			continue;
4065
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
4066
+					continue;
4067
+		}
3850 4068
 
3851 4069
 		// Files are minimized unless they explicitly opt out.
3852
-		if (!isset($file['options']['minimize']))
3853
-			$file['options']['minimize'] = true;
4070
+		if (!isset($file['options']['minimize'])) {
4071
+					$file['options']['minimize'] = true;
4072
+		}
3854 4073
 
3855 4074
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']) && !isset($_REQUEST['normalcss']))
3856 4075
 		{
3857 4076
 			$toMinify[] = $file;
3858 4077
 
3859 4078
 			// Grab a random seed.
3860
-			if (!isset($minSeed) && isset($file['options']['seed']))
3861
-				$minSeed = $file['options']['seed'];
4079
+			if (!isset($minSeed) && isset($file['options']['seed'])) {
4080
+							$minSeed = $file['options']['seed'];
4081
+			}
4082
+		} else {
4083
+					$normal[] = $file['fileUrl'];
3862 4084
 		}
3863
-		else
3864
-			$normal[] = $file['fileUrl'];
3865 4085
 	}
3866 4086
 
3867 4087
 	if (!empty($toMinify))
@@ -3870,23 +4090,26 @@  discard block
 block discarded – undo
3870 4090
 
3871 4091
 		$minSuccessful = array_keys($result) === array('smf_minified');
3872 4092
 
3873
-		foreach ($result as $minFile)
3874
-			echo '
4093
+		foreach ($result as $minFile) {
4094
+					echo '
3875 4095
 	<link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">';
4096
+		}
3876 4097
 	}
3877 4098
 
3878 4099
 	// Print the rest after the minified files.
3879
-	if (!empty($normal))
3880
-		foreach ($normal as $nf)
4100
+	if (!empty($normal)) {
4101
+			foreach ($normal as $nf)
3881 4102
 			echo '
3882 4103
 	<link rel="stylesheet" href="', $nf ,'">';
4104
+	}
3883 4105
 
3884 4106
 	if ($db_show_debug === true)
3885 4107
 	{
3886 4108
 		// Try to keep only what's useful.
3887 4109
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3888
-		foreach ($context['css_files'] as $file)
3889
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4110
+		foreach ($context['css_files'] as $file) {
4111
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4112
+		}
3890 4113
 	}
3891 4114
 
3892 4115
 	if (!empty($context['css_header']))
@@ -3894,9 +4117,10 @@  discard block
 block discarded – undo
3894 4117
 		echo '
3895 4118
 	<style>';
3896 4119
 
3897
-		foreach ($context['css_header'] as $css)
3898
-			echo $css .'
4120
+		foreach ($context['css_header'] as $css) {
4121
+					echo $css .'
3899 4122
 	';
4123
+		}
3900 4124
 
3901 4125
 		echo'
3902 4126
 	</style>';
@@ -3919,8 +4143,9 @@  discard block
 block discarded – undo
3919 4143
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3920 4144
 	$data = is_array($data) ? $data : array();
3921 4145
 
3922
-	if (empty($type) || empty($data))
3923
-		return $data;
4146
+	if (empty($type) || empty($data)) {
4147
+			return $data;
4148
+	}
3924 4149
 
3925 4150
 	// Different pages include different files, so we use a hash to label the different combinations
3926 4151
 	$hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . (int) @filesize($file['filePath']) . (int) @filemtime($file['filePath']); }, $data)));
@@ -3929,13 +4154,14 @@  discard block
 block discarded – undo
3929 4154
 	list($toCache, $async, $defer) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 3, null);
3930 4155
 
3931 4156
 	// Already done?
3932
-	if (!empty($toCache))
3933
-		return array('smf_minified' => array(
4157
+	if (!empty($toCache)) {
4158
+			return array('smf_minified' => array(
3934 4159
 			'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache),
3935 4160
 			'filePath' => $toCache,
3936 4161
 			'fileName' => basename($toCache),
3937 4162
 			'options' => array('async' => !empty($async), 'defer' => !empty($defer)),
3938 4163
 		));
4164
+	}
3939 4165
 
3940 4166
 
3941 4167
 	// No namespaces, sorry!
@@ -3965,9 +4191,9 @@  discard block
 block discarded – undo
3965 4191
 
3966 4192
 	foreach ($data as $id => $file)
3967 4193
 	{
3968
-		if (empty($file['filePath']))
3969
-			$toAdd = false;
3970
-		else
4194
+		if (empty($file['filePath'])) {
4195
+					$toAdd = false;
4196
+		} else
3971 4197
 		{
3972 4198
 			$seed = isset($file['options']['seed']) ? $file['options']['seed'] : '';
3973 4199
 			$tempFile = str_replace($seed, '', $file['filePath']);
@@ -3975,12 +4201,14 @@  discard block
 block discarded – undo
3975 4201
 		}
3976 4202
 
3977 4203
 		// A minified script should only be loaded asynchronously if all its components wanted to be.
3978
-		if (empty($file['options']['async']))
3979
-			$async = false;
4204
+		if (empty($file['options']['async'])) {
4205
+					$async = false;
4206
+		}
3980 4207
 
3981 4208
 		// A minified script should only be deferred if all its components wanted to be.
3982
-		if (empty($file['options']['defer']))
3983
-			$defer = false;
4209
+		if (empty($file['options']['defer'])) {
4210
+					$defer = false;
4211
+		}
3984 4212
 
3985 4213
 		// The file couldn't be located so it won't be added. Log this error.
3986 4214
 		if (empty($toAdd))
@@ -4046,12 +4274,14 @@  discard block
 block discarded – undo
4046 4274
 			foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename)
4047 4275
 			{
4048 4276
 				// Remove the cache entry
4049
-				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches))
4050
-					cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4277
+				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) {
4278
+									cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4279
+				}
4051 4280
 
4052 4281
 				// Try to delete the file. Add it to our error list if it fails.
4053
-				if (!@unlink($filename))
4054
-					$not_deleted[] = $filename;
4282
+				if (!@unlink($filename)) {
4283
+									$not_deleted[] = $filename;
4284
+				}
4055 4285
 			}
4056 4286
 		}
4057 4287
 	}
@@ -4083,8 +4313,9 @@  discard block
 block discarded – undo
4083 4313
 	global $modSettings, $smcFunc;
4084 4314
 
4085 4315
 	// Just make up a nice hash...
4086
-	if ($new)
4087
-		return sha1(md5($filename . time()) . mt_rand());
4316
+	if ($new) {
4317
+			return sha1(md5($filename . time()) . mt_rand());
4318
+	}
4088 4319
 
4089 4320
 	// Just make sure that attachment id is only a int
4090 4321
 	$attachment_id = (int) $attachment_id;
@@ -4101,23 +4332,25 @@  discard block
 block discarded – undo
4101 4332
 				'id_attach' => $attachment_id,
4102 4333
 			));
4103 4334
 
4104
-		if ($smcFunc['db_num_rows']($request) === 0)
4105
-			return false;
4335
+		if ($smcFunc['db_num_rows']($request) === 0) {
4336
+					return false;
4337
+		}
4106 4338
 
4107 4339
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
4108 4340
 		$smcFunc['db_free_result']($request);
4109 4341
 	}
4110 4342
 
4111 4343
 	// Still no hash? mmm...
4112
-	if (empty($file_hash))
4113
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
4344
+	if (empty($file_hash)) {
4345
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
4346
+	}
4114 4347
 
4115 4348
 	// Are we using multiple directories?
4116
-	if (is_array($modSettings['attachmentUploadDir']))
4117
-		$path = $modSettings['attachmentUploadDir'][$dir];
4118
-
4119
-	else
4120
-		$path = $modSettings['attachmentUploadDir'];
4349
+	if (is_array($modSettings['attachmentUploadDir'])) {
4350
+			$path = $modSettings['attachmentUploadDir'][$dir];
4351
+	} else {
4352
+			$path = $modSettings['attachmentUploadDir'];
4353
+	}
4121 4354
 
4122 4355
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
4123 4356
 }
@@ -4132,8 +4365,9 @@  discard block
 block discarded – undo
4132 4365
 function ip2range($fullip)
4133 4366
 {
4134 4367
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
4135
-	if ($fullip == 'unknown')
4136
-		$fullip = '255.255.255.255';
4368
+	if ($fullip == 'unknown') {
4369
+			$fullip = '255.255.255.255';
4370
+	}
4137 4371
 
4138 4372
 	$ip_parts = explode('-', $fullip);
4139 4373
 	$ip_array = array();
@@ -4157,10 +4391,11 @@  discard block
 block discarded – undo
4157 4391
 		$ip_array['low'] = $ip_parts[0];
4158 4392
 		$ip_array['high'] = $ip_parts[1];
4159 4393
 		return $ip_array;
4160
-	}
4161
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4394
+	} elseif (count($ip_parts) == 2) {
4395
+		// if ip 22.22.*-22.22.*
4162 4396
 	{
4163 4397
 		$valid_low = isValidIP($ip_parts[0]);
4398
+	}
4164 4399
 		$valid_high = isValidIP($ip_parts[1]);
4165 4400
 		$count = 0;
4166 4401
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -4175,7 +4410,9 @@  discard block
 block discarded – undo
4175 4410
 				$ip_parts[0] .= $mode . $min;
4176 4411
 				$valid_low = isValidIP($ip_parts[0]);
4177 4412
 				$count++;
4178
-				if ($count > 9) break;
4413
+				if ($count > 9) {
4414
+					break;
4415
+				}
4179 4416
 			}
4180 4417
 		}
4181 4418
 
@@ -4189,7 +4426,9 @@  discard block
 block discarded – undo
4189 4426
 				$ip_parts[1] .= $mode . $max;
4190 4427
 				$valid_high = isValidIP($ip_parts[1]);
4191 4428
 				$count++;
4192
-				if ($count > 9) break;
4429
+				if ($count > 9) {
4430
+					break;
4431
+				}
4193 4432
 			}
4194 4433
 		}
4195 4434
 
@@ -4213,46 +4452,54 @@  discard block
 block discarded – undo
4213 4452
 {
4214 4453
 	global $modSettings;
4215 4454
 
4216
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
4217
-		return $host;
4455
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4456
+			return $host;
4457
+	}
4218 4458
 	$t = microtime();
4219 4459
 
4220 4460
 	// Try the Linux host command, perhaps?
4221 4461
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
4222 4462
 	{
4223
-		if (!isset($modSettings['host_to_dis']))
4224
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4225
-		else
4226
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4463
+		if (!isset($modSettings['host_to_dis'])) {
4464
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4465
+		} else {
4466
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4467
+		}
4227 4468
 
4228 4469
 		// Did host say it didn't find anything?
4229
-		if (strpos($test, 'not found') !== false)
4230
-			$host = '';
4470
+		if (strpos($test, 'not found') !== false) {
4471
+					$host = '';
4472
+		}
4231 4473
 		// Invalid server option?
4232
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
4233
-			updateSettings(array('host_to_dis' => 1));
4474
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4475
+					updateSettings(array('host_to_dis' => 1));
4476
+		}
4234 4477
 		// Maybe it found something, after all?
4235
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
4236
-			$host = $match[1];
4478
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4479
+					$host = $match[1];
4480
+		}
4237 4481
 	}
4238 4482
 
4239 4483
 	// This is nslookup; usually only Windows, but possibly some Unix?
4240 4484
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
4241 4485
 	{
4242 4486
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
4243
-		if (strpos($test, 'Non-existent domain') !== false)
4244
-			$host = '';
4245
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
4246
-			$host = $match[1];
4487
+		if (strpos($test, 'Non-existent domain') !== false) {
4488
+					$host = '';
4489
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4490
+					$host = $match[1];
4491
+		}
4247 4492
 	}
4248 4493
 
4249 4494
 	// This is the last try :/.
4250
-	if (!isset($host) || $host === false)
4251
-		$host = @gethostbyaddr($ip);
4495
+	if (!isset($host) || $host === false) {
4496
+			$host = @gethostbyaddr($ip);
4497
+	}
4252 4498
 
4253 4499
 	// It took a long time, so let's cache it!
4254
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
4255
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4500
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4501
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4502
+	}
4256 4503
 
4257 4504
 	return $host;
4258 4505
 }
@@ -4288,20 +4535,21 @@  discard block
 block discarded – undo
4288 4535
 			{
4289 4536
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
4290 4537
 				$total = 0;
4291
-				for ($i = 0; $i < $max_chars; $i++)
4292
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4538
+				for ($i = 0; $i < $max_chars; $i++) {
4539
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4540
+				}
4293 4541
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
4294 4542
 			}
4295 4543
 		}
4296 4544
 		return array_unique($returned_ints);
4297
-	}
4298
-	else
4545
+	} else
4299 4546
 	{
4300 4547
 		// Trim characters before and after and add slashes for database insertion.
4301 4548
 		$returned_words = array();
4302
-		foreach ($words as $word)
4303
-			if (($word = trim($word, '-_\'')) !== '')
4549
+		foreach ($words as $word) {
4550
+					if (($word = trim($word, '-_\'')) !== '')
4304 4551
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4552
+		}
4305 4553
 
4306 4554
 		// Filter out all words that occur more than once.
4307 4555
 		return array_unique($returned_words);
@@ -4323,16 +4571,18 @@  discard block
 block discarded – undo
4323 4571
 	global $settings, $txt;
4324 4572
 
4325 4573
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4326
-	if (function_exists('template_create_button') && !$force_use)
4327
-		return template_create_button($name, $alt, $label = '', $custom = '');
4574
+	if (function_exists('template_create_button') && !$force_use) {
4575
+			return template_create_button($name, $alt, $label = '', $custom = '');
4576
+	}
4328 4577
 
4329
-	if (!$settings['use_image_buttons'])
4330
-		return $txt[$alt];
4331
-	elseif (!empty($settings['use_buttons']))
4332
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4333
-	else
4334
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4335
-}
4578
+	if (!$settings['use_image_buttons']) {
4579
+			return $txt[$alt];
4580
+	} elseif (!empty($settings['use_buttons'])) {
4581
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4582
+	} else {
4583
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4584
+	}
4585
+	}
4336 4586
 
4337 4587
 /**
4338 4588
  * Sets up all of the top menu buttons
@@ -4375,9 +4625,10 @@  discard block
 block discarded – undo
4375 4625
 	var user_menus = new smc_PopupMenu();
4376 4626
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4377 4627
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4378
-		if ($context['allow_pm'])
4379
-			addInlineJavaScript('
4628
+		if ($context['allow_pm']) {
4629
+					addInlineJavaScript('
4380 4630
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4631
+		}
4381 4632
 
4382 4633
 		if (!empty($modSettings['enable_ajax_alerts']))
4383 4634
 		{
@@ -4537,88 +4788,96 @@  discard block
 block discarded – undo
4537 4788
 
4538 4789
 		// Now we put the buttons in the context so the theme can use them.
4539 4790
 		$menu_buttons = array();
4540
-		foreach ($buttons as $act => $button)
4541
-			if (!empty($button['show']))
4791
+		foreach ($buttons as $act => $button) {
4792
+					if (!empty($button['show']))
4542 4793
 			{
4543 4794
 				$button['active_button'] = false;
4795
+		}
4544 4796
 
4545 4797
 				// This button needs some action.
4546
-				if (isset($button['action_hook']))
4547
-					$needs_action_hook = true;
4798
+				if (isset($button['action_hook'])) {
4799
+									$needs_action_hook = true;
4800
+				}
4548 4801
 
4549 4802
 				// Make sure the last button truly is the last button.
4550 4803
 				if (!empty($button['is_last']))
4551 4804
 				{
4552
-					if (isset($last_button))
4553
-						unset($menu_buttons[$last_button]['is_last']);
4805
+					if (isset($last_button)) {
4806
+											unset($menu_buttons[$last_button]['is_last']);
4807
+					}
4554 4808
 					$last_button = $act;
4555 4809
 				}
4556 4810
 
4557 4811
 				// Go through the sub buttons if there are any.
4558
-				if (!empty($button['sub_buttons']))
4559
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4812
+				if (!empty($button['sub_buttons'])) {
4813
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4560 4814
 					{
4561 4815
 						if (empty($subbutton['show']))
4562 4816
 							unset($button['sub_buttons'][$key]);
4817
+				}
4563 4818
 
4564 4819
 						// 2nd level sub buttons next...
4565 4820
 						if (!empty($subbutton['sub_buttons']))
4566 4821
 						{
4567 4822
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4568 4823
 							{
4569
-								if (empty($sub_button2['show']))
4570
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4824
+								if (empty($sub_button2['show'])) {
4825
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4826
+								}
4571 4827
 							}
4572 4828
 						}
4573 4829
 					}
4574 4830
 
4575 4831
 				// Does this button have its own icon?
4576
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4577
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4578
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4579
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4580
-				elseif (isset($button['icon']))
4581
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4582
-				else
4583
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4832
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4833
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4834
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4835
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4836
+				} elseif (isset($button['icon'])) {
4837
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4838
+				} else {
4839
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4840
+				}
4584 4841
 
4585 4842
 				$menu_buttons[$act] = $button;
4586 4843
 			}
4587 4844
 
4588
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4589
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4845
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4846
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4847
+		}
4590 4848
 	}
4591 4849
 
4592 4850
 	$context['menu_buttons'] = $menu_buttons;
4593 4851
 
4594 4852
 	// Logging out requires the session id in the url.
4595
-	if (isset($context['menu_buttons']['logout']))
4596
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4853
+	if (isset($context['menu_buttons']['logout'])) {
4854
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4855
+	}
4597 4856
 
4598 4857
 	// Figure out which action we are doing so we can set the active tab.
4599 4858
 	// Default to home.
4600 4859
 	$current_action = 'home';
4601 4860
 
4602
-	if (isset($context['menu_buttons'][$context['current_action']]))
4603
-		$current_action = $context['current_action'];
4604
-	elseif ($context['current_action'] == 'search2')
4605
-		$current_action = 'search';
4606
-	elseif ($context['current_action'] == 'theme')
4607
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4608
-	elseif ($context['current_action'] == 'register2')
4609
-		$current_action = 'register';
4610
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4611
-		$current_action = 'login';
4612
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4613
-		$current_action = 'moderate';
4861
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4862
+			$current_action = $context['current_action'];
4863
+	} elseif ($context['current_action'] == 'search2') {
4864
+			$current_action = 'search';
4865
+	} elseif ($context['current_action'] == 'theme') {
4866
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4867
+	} elseif ($context['current_action'] == 'register2') {
4868
+			$current_action = 'register';
4869
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4870
+			$current_action = 'login';
4871
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4872
+			$current_action = 'moderate';
4873
+	}
4614 4874
 
4615 4875
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4616 4876
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4617 4877
 	{
4618 4878
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4619 4879
 		$context[$current_action] = true;
4620
-	}
4621
-	elseif ($context['current_action'] == 'pm')
4880
+	} elseif ($context['current_action'] == 'pm')
4622 4881
 	{
4623 4882
 		$current_action = 'self_pm';
4624 4883
 		$context['self_pm'] = true;
@@ -4681,12 +4940,14 @@  discard block
 block discarded – undo
4681 4940
 	}
4682 4941
 
4683 4942
 	// Not all actions are simple.
4684
-	if (!empty($needs_action_hook))
4685
-		call_integration_hook('integrate_current_action', array(&$current_action));
4943
+	if (!empty($needs_action_hook)) {
4944
+			call_integration_hook('integrate_current_action', array(&$current_action));
4945
+	}
4686 4946
 
4687
-	if (isset($context['menu_buttons'][$current_action]))
4688
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4689
-}
4947
+	if (isset($context['menu_buttons'][$current_action])) {
4948
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4949
+	}
4950
+	}
4690 4951
 
4691 4952
 /**
4692 4953
  * Generate a random seed and ensure it's stored in settings.
@@ -4710,30 +4971,35 @@  discard block
 block discarded – undo
4710 4971
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4711 4972
 	global $context, $txt;
4712 4973
 
4713
-	if ($db_show_debug === true)
4714
-		$context['debug']['hooks'][] = $hook;
4974
+	if ($db_show_debug === true) {
4975
+			$context['debug']['hooks'][] = $hook;
4976
+	}
4715 4977
 
4716 4978
 	// Need to have some control.
4717
-	if (!isset($context['instances']))
4718
-		$context['instances'] = array();
4979
+	if (!isset($context['instances'])) {
4980
+			$context['instances'] = array();
4981
+	}
4719 4982
 
4720 4983
 	$results = array();
4721
-	if (empty($modSettings[$hook]))
4722
-		return $results;
4984
+	if (empty($modSettings[$hook])) {
4985
+			return $results;
4986
+	}
4723 4987
 
4724 4988
 	$functions = explode(',', $modSettings[$hook]);
4725 4989
 	// Loop through each function.
4726 4990
 	foreach ($functions as $function)
4727 4991
 	{
4728 4992
 		// Hook has been marked as "disabled". Skip it!
4729
-		if (strpos($function, '!') !== false)
4730
-			continue;
4993
+		if (strpos($function, '!') !== false) {
4994
+					continue;
4995
+		}
4731 4996
 
4732 4997
 		$call = call_helper($function, true);
4733 4998
 
4734 4999
 		// Is it valid?
4735
-		if (!empty($call))
4736
-			$results[$function] = call_user_func_array($call, $parameters);
5000
+		if (!empty($call)) {
5001
+					$results[$function] = call_user_func_array($call, $parameters);
5002
+		}
4737 5003
 
4738 5004
 		// Whatever it was suppose to call, it failed :(
4739 5005
 		elseif (!empty($function))
@@ -4749,8 +5015,9 @@  discard block
 block discarded – undo
4749 5015
 			}
4750 5016
 
4751 5017
 			// "Assume" the file resides on $boarddir somewhere...
4752
-			else
4753
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5018
+			else {
5019
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5020
+			}
4754 5021
 		}
4755 5022
 	}
4756 5023
 
@@ -4772,12 +5039,14 @@  discard block
 block discarded – undo
4772 5039
 	global $smcFunc, $modSettings;
4773 5040
 
4774 5041
 	// Any objects?
4775
-	if ($object)
4776
-		$function = $function . '#';
5042
+	if ($object) {
5043
+			$function = $function . '#';
5044
+	}
4777 5045
 
4778 5046
 	// Any files  to load?
4779
-	if (!empty($file) && is_string($file))
4780
-		$function = $file . (!empty($function) ? '|' . $function : '');
5047
+	if (!empty($file) && is_string($file)) {
5048
+			$function = $file . (!empty($function) ? '|' . $function : '');
5049
+	}
4781 5050
 
4782 5051
 	// Get the correct string.
4783 5052
 	$integration_call = $function;
@@ -4799,13 +5068,14 @@  discard block
 block discarded – undo
4799 5068
 		if (!empty($current_functions))
4800 5069
 		{
4801 5070
 			$current_functions = explode(',', $current_functions);
4802
-			if (in_array($integration_call, $current_functions))
4803
-				return;
5071
+			if (in_array($integration_call, $current_functions)) {
5072
+							return;
5073
+			}
4804 5074
 
4805 5075
 			$permanent_functions = array_merge($current_functions, array($integration_call));
5076
+		} else {
5077
+					$permanent_functions = array($integration_call);
4806 5078
 		}
4807
-		else
4808
-			$permanent_functions = array($integration_call);
4809 5079
 
4810 5080
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4811 5081
 	}
@@ -4814,8 +5084,9 @@  discard block
 block discarded – undo
4814 5084
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4815 5085
 
4816 5086
 	// Do nothing, if it's already there.
4817
-	if (in_array($integration_call, $functions))
4818
-		return;
5087
+	if (in_array($integration_call, $functions)) {
5088
+			return;
5089
+	}
4819 5090
 
4820 5091
 	$functions[] = $integration_call;
4821 5092
 	$modSettings[$hook] = implode(',', $functions);
@@ -4838,12 +5109,14 @@  discard block
 block discarded – undo
4838 5109
 	global $smcFunc, $modSettings;
4839 5110
 
4840 5111
 	// Any objects?
4841
-	if ($object)
4842
-		$function = $function . '#';
5112
+	if ($object) {
5113
+			$function = $function . '#';
5114
+	}
4843 5115
 
4844 5116
 	// Any files  to load?
4845
-	if (!empty($file) && is_string($file))
4846
-		$function = $file . '|' . $function;
5117
+	if (!empty($file) && is_string($file)) {
5118
+			$function = $file . '|' . $function;
5119
+	}
4847 5120
 
4848 5121
 	// Get the correct string.
4849 5122
 	$integration_call = $function;
@@ -4864,16 +5137,18 @@  discard block
 block discarded – undo
4864 5137
 	{
4865 5138
 		$current_functions = explode(',', $current_functions);
4866 5139
 
4867
-		if (in_array($integration_call, $current_functions))
4868
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5140
+		if (in_array($integration_call, $current_functions)) {
5141
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5142
+		}
4869 5143
 	}
4870 5144
 
4871 5145
 	// Turn the function list into something usable.
4872 5146
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4873 5147
 
4874 5148
 	// You can only remove it if it's available.
4875
-	if (!in_array($integration_call, $functions))
4876
-		return;
5149
+	if (!in_array($integration_call, $functions)) {
5150
+			return;
5151
+	}
4877 5152
 
4878 5153
 	$functions = array_diff($functions, array($integration_call));
4879 5154
 	$modSettings[$hook] = implode(',', $functions);
@@ -4894,17 +5169,20 @@  discard block
 block discarded – undo
4894 5169
 	global $context, $smcFunc, $txt, $db_show_debug;
4895 5170
 
4896 5171
 	// Really?
4897
-	if (empty($string))
4898
-		return false;
5172
+	if (empty($string)) {
5173
+			return false;
5174
+	}
4899 5175
 
4900 5176
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4901 5177
 	// A closure? should be a callable one.
4902
-	if (is_array($string) || $string instanceof Closure)
4903
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5178
+	if (is_array($string) || $string instanceof Closure) {
5179
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5180
+	}
4904 5181
 
4905 5182
 	// No full objects, sorry! pass a method or a property instead!
4906
-	if (is_object($string))
4907
-		return false;
5183
+	if (is_object($string)) {
5184
+			return false;
5185
+	}
4908 5186
 
4909 5187
 	// Stay vitaminized my friends...
4910 5188
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4913,8 +5191,9 @@  discard block
 block discarded – undo
4913 5191
 	$string = load_file($string);
4914 5192
 
4915 5193
 	// Loaded file failed
4916
-	if (empty($string))
4917
-		return false;
5194
+	if (empty($string)) {
5195
+			return false;
5196
+	}
4918 5197
 
4919 5198
 	// Found a method.
4920 5199
 	if (strpos($string, '::') !== false)
@@ -4935,8 +5214,9 @@  discard block
 block discarded – undo
4935 5214
 				// Add another one to the list.
4936 5215
 				if ($db_show_debug === true)
4937 5216
 				{
4938
-					if (!isset($context['debug']['instances']))
4939
-						$context['debug']['instances'] = array();
5217
+					if (!isset($context['debug']['instances'])) {
5218
+											$context['debug']['instances'] = array();
5219
+					}
4940 5220
 
4941 5221
 					$context['debug']['instances'][$class] = $class;
4942 5222
 				}
@@ -4946,13 +5226,15 @@  discard block
 block discarded – undo
4946 5226
 		}
4947 5227
 
4948 5228
 		// Right then. This is a call to a static method.
4949
-		else
4950
-			$func = array($class, $method);
5229
+		else {
5230
+					$func = array($class, $method);
5231
+		}
4951 5232
 	}
4952 5233
 
4953 5234
 	// Nope! just a plain regular function.
4954
-	else
4955
-		$func = $string;
5235
+	else {
5236
+			$func = $string;
5237
+	}
4956 5238
 
4957 5239
 	// Right, we got what we need, time to do some checks.
4958 5240
 	if (!is_callable($func, false, $callable_name))
@@ -4968,17 +5250,18 @@  discard block
 block discarded – undo
4968 5250
 	else
4969 5251
 	{
4970 5252
 		// What are we gonna do about it?
4971
-		if ($return)
4972
-			return $func;
5253
+		if ($return) {
5254
+					return $func;
5255
+		}
4973 5256
 
4974 5257
 		// If this is a plain function, avoid the heat of calling call_user_func().
4975 5258
 		else
4976 5259
 		{
4977
-			if (is_array($func))
4978
-				call_user_func($func);
4979
-
4980
-			else
4981
-				$func();
5260
+			if (is_array($func)) {
5261
+							call_user_func($func);
5262
+			} else {
5263
+							$func();
5264
+			}
4982 5265
 		}
4983 5266
 	}
4984 5267
 }
@@ -4995,31 +5278,34 @@  discard block
 block discarded – undo
4995 5278
 {
4996 5279
 	global $sourcedir, $txt, $boarddir, $settings;
4997 5280
 
4998
-	if (empty($string))
4999
-		return false;
5281
+	if (empty($string)) {
5282
+			return false;
5283
+	}
5000 5284
 
5001 5285
 	if (strpos($string, '|') !== false)
5002 5286
 	{
5003 5287
 		list ($file, $string) = explode('|', $string);
5004 5288
 
5005 5289
 		// Match the wildcards to their regular vars.
5006
-		if (empty($settings['theme_dir']))
5007
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5008
-
5009
-		else
5010
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5290
+		if (empty($settings['theme_dir'])) {
5291
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5292
+		} else {
5293
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5294
+		}
5011 5295
 
5012 5296
 		// Load the file if it can be loaded.
5013
-		if (file_exists($absPath))
5014
-			require_once($absPath);
5297
+		if (file_exists($absPath)) {
5298
+					require_once($absPath);
5299
+		}
5015 5300
 
5016 5301
 		// No? try a fallback to $sourcedir
5017 5302
 		else
5018 5303
 		{
5019 5304
 			$absPath = $sourcedir .'/'. $file;
5020 5305
 
5021
-			if (file_exists($absPath))
5022
-				require_once($absPath);
5306
+			if (file_exists($absPath)) {
5307
+							require_once($absPath);
5308
+			}
5023 5309
 
5024 5310
 			// Sorry, can't do much for you at this point.
5025 5311
 			else
@@ -5058,8 +5344,9 @@  discard block
 block discarded – undo
5058 5344
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
5059 5345
 
5060 5346
 	// No scheme? No data for you!
5061
-	if (empty($match[1]))
5062
-		return false;
5347
+	if (empty($match[1])) {
5348
+			return false;
5349
+	}
5063 5350
 
5064 5351
 	// An FTP url. We should try connecting and RETRieving it...
5065 5352
 	elseif ($match[1] == 'ftp')
@@ -5069,23 +5356,26 @@  discard block
 block discarded – undo
5069 5356
 
5070 5357
 		// Establish a connection and attempt to enable passive mode.
5071 5358
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
5072
-		if ($ftp->error !== false || !$ftp->passive())
5073
-			return false;
5359
+		if ($ftp->error !== false || !$ftp->passive()) {
5360
+					return false;
5361
+		}
5074 5362
 
5075 5363
 		// I want that one *points*!
5076 5364
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
5077 5365
 
5078 5366
 		// Since passive mode worked (or we would have returned already!) open the connection.
5079 5367
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
5080
-		if (!$fp)
5081
-			return false;
5368
+		if (!$fp) {
5369
+					return false;
5370
+		}
5082 5371
 
5083 5372
 		// The server should now say something in acknowledgement.
5084 5373
 		$ftp->check_response(150);
5085 5374
 
5086 5375
 		$data = '';
5087
-		while (!feof($fp))
5088
-			$data .= fread($fp, 4096);
5376
+		while (!feof($fp)) {
5377
+					$data .= fread($fp, 4096);
5378
+		}
5089 5379
 		fclose($fp);
5090 5380
 
5091 5381
 		// All done, right?  Good.
@@ -5097,8 +5387,9 @@  discard block
 block discarded – undo
5097 5387
 	elseif (isset($match[1]) && $match[1] == 'http')
5098 5388
 	{
5099 5389
 		// First try to use fsockopen, because it is fastest.
5100
-		if ($keep_alive && $match[3] == $keep_alive_dom)
5101
-			$fp = $keep_alive_fp;
5390
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
5391
+					$fp = $keep_alive_fp;
5392
+		}
5102 5393
 		if (empty($fp))
5103 5394
 		{
5104 5395
 			// Open the socket on the port we want...
@@ -5118,20 +5409,21 @@  discard block
 block discarded – undo
5118 5409
 				fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
5119 5410
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5120 5411
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5121
-				if ($keep_alive)
5122
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5123
-				else
5124
-					fwrite($fp, 'connection: close' . "\r\n\r\n");
5125
-			}
5126
-			else
5412
+				if ($keep_alive) {
5413
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5414
+				} else {
5415
+									fwrite($fp, 'connection: close' . "\r\n\r\n");
5416
+				}
5417
+			} else
5127 5418
 			{
5128 5419
 				fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
5129 5420
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5130 5421
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5131
-				if ($keep_alive)
5132
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5133
-				else
5134
-					fwrite($fp, 'connection: close' . "\r\n");
5422
+				if ($keep_alive) {
5423
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5424
+				} else {
5425
+									fwrite($fp, 'connection: close' . "\r\n");
5426
+				}
5135 5427
 				fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n");
5136 5428
 				fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n");
5137 5429
 				fwrite($fp, $post_data);
@@ -5144,30 +5436,33 @@  discard block
 block discarded – undo
5144 5436
 			{
5145 5437
 				$header = '';
5146 5438
 				$location = '';
5147
-				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5148
-					if (strpos($header, 'location:') !== false)
5439
+				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
5440
+									if (strpos($header, 'location:') !== false)
5149 5441
 						$location = trim(substr($header, strpos($header, ':') + 1));
5442
+				}
5150 5443
 
5151
-				if (empty($location))
5152
-					return false;
5153
-				else
5444
+				if (empty($location)) {
5445
+									return false;
5446
+				} else
5154 5447
 				{
5155
-					if (!$keep_alive)
5156
-						fclose($fp);
5448
+					if (!$keep_alive) {
5449
+											fclose($fp);
5450
+					}
5157 5451
 					return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
5158 5452
 				}
5159 5453
 			}
5160 5454
 
5161 5455
 			// Make sure we get a 200 OK.
5162
-			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
5163
-				return false;
5456
+			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
5457
+							return false;
5458
+			}
5164 5459
 
5165 5460
 			// Skip the headers...
5166 5461
 			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5167 5462
 			{
5168
-				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
5169
-					$content_length = $match[1];
5170
-				elseif (preg_match('~connection:\s*close~i', $header) != 0)
5463
+				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
5464
+									$content_length = $match[1];
5465
+				} elseif (preg_match('~connection:\s*close~i', $header) != 0)
5171 5466
 				{
5172 5467
 					$keep_alive_dom = null;
5173 5468
 					$keep_alive = false;
@@ -5179,17 +5474,19 @@  discard block
 block discarded – undo
5179 5474
 			$data = '';
5180 5475
 			if (isset($content_length))
5181 5476
 			{
5182
-				while (!feof($fp) && strlen($data) < $content_length)
5183
-					$data .= fread($fp, $content_length - strlen($data));
5184
-			}
5185
-			else
5477
+				while (!feof($fp) && strlen($data) < $content_length) {
5478
+									$data .= fread($fp, $content_length - strlen($data));
5479
+				}
5480
+			} else
5186 5481
 			{
5187
-				while (!feof($fp))
5188
-					$data .= fread($fp, 4096);
5482
+				while (!feof($fp)) {
5483
+									$data .= fread($fp, 4096);
5484
+				}
5189 5485
 			}
5190 5486
 
5191
-			if (!$keep_alive)
5192
-				fclose($fp);
5487
+			if (!$keep_alive) {
5488
+							fclose($fp);
5489
+			}
5193 5490
 		}
5194 5491
 
5195 5492
 		// If using fsockopen didn't work, try to use cURL if available.
@@ -5202,17 +5499,18 @@  discard block
 block discarded – undo
5202 5499
 			$fetch_data->get_url_data($url, $post_data);
5203 5500
 
5204 5501
 			// no errors and a 200 result, then we have a good dataset, well we at least have data. ;)
5205
-			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
5206
-				$data = $fetch_data->result('body');
5207
-			else
5208
-				return false;
5502
+			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
5503
+							$data = $fetch_data->result('body');
5504
+			} else {
5505
+							return false;
5506
+			}
5209 5507
 		}
5210 5508
 
5211 5509
 		// Neither fsockopen nor curl are available. Well, phooey.
5212
-		else
5213
-			return false;
5214
-	}
5215
-	else
5510
+		else {
5511
+					return false;
5512
+		}
5513
+	} else
5216 5514
 	{
5217 5515
 		// Umm, this shouldn't happen?
5218 5516
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
@@ -5232,8 +5530,9 @@  discard block
 block discarded – undo
5232 5530
 	global $user_info, $smcFunc;
5233 5531
 
5234 5532
 	// Make sure we have something to work with.
5235
-	if (empty($topic))
5236
-		return array();
5533
+	if (empty($topic)) {
5534
+			return array();
5535
+	}
5237 5536
 
5238 5537
 
5239 5538
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -5256,8 +5555,9 @@  discard block
 block discarded – undo
5256 5555
 				'topic' => $topic,
5257 5556
 			)
5258 5557
 		);
5259
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5260
-			$temp[] = (int) $row['content_id'];
5558
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5559
+					$temp[] = (int) $row['content_id'];
5560
+		}
5261 5561
 
5262 5562
 		cache_put_data($cache_key, $temp, $ttl);
5263 5563
 	}
@@ -5278,8 +5578,9 @@  discard block
 block discarded – undo
5278 5578
 {
5279 5579
 	global $context;
5280 5580
 
5281
-	if (empty($string))
5282
-		return $string;
5581
+	if (empty($string)) {
5582
+			return $string;
5583
+	}
5283 5584
 
5284 5585
 	// UTF-8 occurences of MS special characters
5285 5586
 	$findchars_utf8 = array(
@@ -5320,10 +5621,11 @@  discard block
 block discarded – undo
5320 5621
 		'--',	// &mdash;
5321 5622
 	);
5322 5623
 
5323
-	if ($context['utf8'])
5324
-		$string = str_replace($findchars_utf8, $replacechars, $string);
5325
-	else
5326
-		$string = str_replace($findchars_iso, $replacechars, $string);
5624
+	if ($context['utf8']) {
5625
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5626
+	} else {
5627
+			$string = str_replace($findchars_iso, $replacechars, $string);
5628
+	}
5327 5629
 
5328 5630
 	return $string;
5329 5631
 }
@@ -5342,49 +5644,59 @@  discard block
 block discarded – undo
5342 5644
 {
5343 5645
 	global $context;
5344 5646
 
5345
-	if (!isset($matches[2]))
5346
-		return '';
5647
+	if (!isset($matches[2])) {
5648
+			return '';
5649
+	}
5347 5650
 
5348 5651
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5349 5652
 
5350 5653
 	// remove left to right / right to left overrides
5351
-	if ($num === 0x202D || $num === 0x202E)
5352
-		return '';
5654
+	if ($num === 0x202D || $num === 0x202E) {
5655
+			return '';
5656
+	}
5353 5657
 
5354 5658
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
5355
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
5356
-		return '&#' . $num . ';';
5659
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5660
+			return '&#' . $num . ';';
5661
+	}
5357 5662
 
5358 5663
 	if (empty($context['utf8']))
5359 5664
 	{
5360 5665
 		// no control characters
5361
-		if ($num < 0x20)
5362
-			return '';
5666
+		if ($num < 0x20) {
5667
+					return '';
5668
+		}
5363 5669
 		// text is text
5364
-		elseif ($num < 0x80)
5365
-			return chr($num);
5670
+		elseif ($num < 0x80) {
5671
+					return chr($num);
5672
+		}
5366 5673
 		// all others get html-ised
5367
-		else
5368
-			return '&#' . $matches[2] . ';';
5369
-	}
5370
-	else
5674
+		else {
5675
+					return '&#' . $matches[2] . ';';
5676
+		}
5677
+	} else
5371 5678
 	{
5372 5679
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
5373 5680
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
5374
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
5375
-			return '';
5681
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5682
+					return '';
5683
+		}
5376 5684
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5377
-		elseif ($num < 0x80)
5378
-			return chr($num);
5685
+		elseif ($num < 0x80) {
5686
+					return chr($num);
5687
+		}
5379 5688
 		// <0x800 (2048)
5380
-		elseif ($num < 0x800)
5381
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5689
+		elseif ($num < 0x800) {
5690
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5691
+		}
5382 5692
 		// < 0x10000 (65536)
5383
-		elseif ($num < 0x10000)
5384
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5693
+		elseif ($num < 0x10000) {
5694
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5695
+		}
5385 5696
 		// <= 0x10FFFF (1114111)
5386
-		else
5387
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5697
+		else {
5698
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5699
+		}
5388 5700
 	}
5389 5701
 }
5390 5702
 
@@ -5400,28 +5712,34 @@  discard block
 block discarded – undo
5400 5712
  */
5401 5713
 function fixchar__callback($matches)
5402 5714
 {
5403
-	if (!isset($matches[1]))
5404
-		return '';
5715
+	if (!isset($matches[1])) {
5716
+			return '';
5717
+	}
5405 5718
 
5406 5719
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
5407 5720
 
5408 5721
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
5409 5722
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
5410
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
5411
-		return '';
5723
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5724
+			return '';
5725
+	}
5412 5726
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5413
-	elseif ($num < 0x80)
5414
-		return chr($num);
5727
+	elseif ($num < 0x80) {
5728
+			return chr($num);
5729
+	}
5415 5730
 	// <0x800 (2048)
5416
-	elseif ($num < 0x800)
5417
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5731
+	elseif ($num < 0x800) {
5732
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5733
+	}
5418 5734
 	// < 0x10000 (65536)
5419
-	elseif ($num < 0x10000)
5420
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5735
+	elseif ($num < 0x10000) {
5736
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5737
+	}
5421 5738
 	// <= 0x10FFFF (1114111)
5422
-	else
5423
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5424
-}
5739
+	else {
5740
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5741
+	}
5742
+	}
5425 5743
 
5426 5744
 /**
5427 5745
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -5434,17 +5752,19 @@  discard block
 block discarded – undo
5434 5752
  */
5435 5753
 function entity_fix__callback($matches)
5436 5754
 {
5437
-	if (!isset($matches[2]))
5438
-		return '';
5755
+	if (!isset($matches[2])) {
5756
+			return '';
5757
+	}
5439 5758
 
5440 5759
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5441 5760
 
5442 5761
 	// we don't allow control characters, characters out of range, byte markers, etc
5443
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
5444
-		return '';
5445
-	else
5446
-		return '&#' . $num . ';';
5447
-}
5762
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5763
+			return '';
5764
+	} else {
5765
+			return '&#' . $num . ';';
5766
+	}
5767
+	}
5448 5768
 
5449 5769
 /**
5450 5770
  * Return a Gravatar URL based on
@@ -5468,18 +5788,23 @@  discard block
 block discarded – undo
5468 5788
 		$ratings = array('G', 'PG', 'R', 'X');
5469 5789
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
5470 5790
 		$url_params = array();
5471
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
5472
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5473
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
5474
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5475
-		if (!empty($modSettings['avatar_max_width_external']))
5476
-			$size_string = (int) $modSettings['avatar_max_width_external'];
5477
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
5478
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5791
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5792
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5793
+		}
5794
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5795
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5796
+		}
5797
+		if (!empty($modSettings['avatar_max_width_external'])) {
5798
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5799
+		}
5800
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5801
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5479 5802
 				$size_string = $modSettings['avatar_max_height_external'];
5803
+		}
5480 5804
 
5481
-		if (!empty($size_string))
5482
-			$url_params[] = 's=' . $size_string;
5805
+		if (!empty($size_string)) {
5806
+					$url_params[] = 's=' . $size_string;
5807
+		}
5483 5808
 	}
5484 5809
 	$http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www';
5485 5810
 
@@ -5498,22 +5823,26 @@  discard block
 block discarded – undo
5498 5823
 	static $timezones = null, $lastwhen = null;
5499 5824
 
5500 5825
 	// No point doing this over if we already did it once
5501
-	if (!empty($timezones) && $when == $lastwhen)
5502
-		return $timezones;
5503
-	else
5504
-		$lastwhen = $when;
5826
+	if (!empty($timezones) && $when == $lastwhen) {
5827
+			return $timezones;
5828
+	} else {
5829
+			$lastwhen = $when;
5830
+	}
5505 5831
 
5506 5832
 	// Parseable datetime string?
5507
-	if (is_int($timestamp = strtotime($when)))
5508
-		$when = $timestamp;
5833
+	if (is_int($timestamp = strtotime($when))) {
5834
+			$when = $timestamp;
5835
+	}
5509 5836
 
5510 5837
 	// A Unix timestamp?
5511
-	elseif (is_numeric($when))
5512
-		$when = intval($when);
5838
+	elseif (is_numeric($when)) {
5839
+			$when = intval($when);
5840
+	}
5513 5841
 
5514 5842
 	// Invalid value? Just get current Unix timestamp.
5515
-	else
5516
-		$when = time();
5843
+	else {
5844
+			$when = time();
5845
+	}
5517 5846
 
5518 5847
 	// We'll need these too
5519 5848
 	$date_when = date_create('@' . $when);
@@ -5528,8 +5857,9 @@  discard block
 block discarded – undo
5528 5857
 	foreach ($priority_countries as $country)
5529 5858
 	{
5530 5859
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5531
-		if (!empty($country_tzids))
5532
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5860
+		if (!empty($country_tzids)) {
5861
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5862
+		}
5533 5863
 	}
5534 5864
 
5535 5865
 	// Antarctic research stations should be listed last, unless you're running a penguin forum
@@ -5543,8 +5873,9 @@  discard block
 block discarded – undo
5543 5873
 	foreach ($tzids as $tzid)
5544 5874
 	{
5545 5875
 		// We don't want UTC right now
5546
-		if ($tzid == 'UTC')
5547
-			continue;
5876
+		if ($tzid == 'UTC') {
5877
+					continue;
5878
+		}
5548 5879
 
5549 5880
 		$tz = timezone_open($tzid);
5550 5881
 
@@ -5565,13 +5896,14 @@  discard block
 block discarded – undo
5565 5896
 		}
5566 5897
 
5567 5898
 		// A time zone from a prioritized country?
5568
-		if (in_array($tzid, $priority_tzids))
5569
-			$priority_zones[$tzkey] = true;
5899
+		if (in_array($tzid, $priority_tzids)) {
5900
+					$priority_zones[$tzkey] = true;
5901
+		}
5570 5902
 
5571 5903
 		// Keep track of the location and offset for this tzid
5572
-		if (!empty($txt[$tzid]))
5573
-			$zones[$tzkey]['locations'][] = $txt[$tzid];
5574
-		else
5904
+		if (!empty($txt[$tzid])) {
5905
+					$zones[$tzkey]['locations'][] = $txt[$tzid];
5906
+		} else
5575 5907
 		{
5576 5908
 			$tzid_parts = explode('/', $tzid);
5577 5909
 			$zones[$tzkey]['locations'][] = str_replace(array('St_', '_'), array('St. ', ' '), array_pop($tzid_parts));
@@ -5591,23 +5923,27 @@  discard block
 block discarded – undo
5591 5923
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5592 5924
 
5593 5925
 		// Use the custom description, if there is one
5594
-		if (!empty($tztxt[$tzvalue['tzid']]))
5595
-			$desc = $tztxt[$tzvalue['tzid']];
5926
+		if (!empty($tztxt[$tzvalue['tzid']])) {
5927
+					$desc = $tztxt[$tzvalue['tzid']];
5928
+		}
5596 5929
 		// Otherwise, use the list of locations (max 5, so things don't get silly)
5597
-		else
5598
-			$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5930
+		else {
5931
+					$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5932
+		}
5599 5933
 
5600 5934
 		// Show the UTC offset and the abbreviation, if it's something like 'MST' and not '-06'
5601 5935
 		$desc = '[UTC' . date_format($date_when, 'P') . '] - ' . (!strspn($tzvalue['abbr'], '+-') ? $tzvalue['abbr'] . ' - ' : '') . $desc;
5602 5936
 
5603
-		if (isset($priority_zones[$tzkey]))
5604
-			$priority_timezones[$tzvalue['tzid']] = $desc;
5605
-		else
5606
-			$timezones[$tzvalue['tzid']] = $desc;
5937
+		if (isset($priority_zones[$tzkey])) {
5938
+					$priority_timezones[$tzvalue['tzid']] = $desc;
5939
+		} else {
5940
+					$timezones[$tzvalue['tzid']] = $desc;
5941
+		}
5607 5942
 	}
5608 5943
 
5609
-	if (!empty($priority_timezones))
5610
-		$priority_timezones[] = '-----';
5944
+	if (!empty($priority_timezones)) {
5945
+			$priority_timezones[] = '-----';
5946
+	}
5611 5947
 
5612 5948
 	$timezones = array_merge(
5613 5949
 		$priority_timezones,
@@ -5624,8 +5960,9 @@  discard block
 block discarded – undo
5624 5960
  */
5625 5961
 function inet_ptod($ip_address)
5626 5962
 {
5627
-	if (!isValidIP($ip_address))
5628
-		return $ip_address;
5963
+	if (!isValidIP($ip_address)) {
5964
+			return $ip_address;
5965
+	}
5629 5966
 
5630 5967
 	$bin = inet_pton($ip_address);
5631 5968
 	return $bin;
@@ -5637,13 +5974,15 @@  discard block
 block discarded – undo
5637 5974
  */
5638 5975
 function inet_dtop($bin)
5639 5976
 {
5640
-	if(empty($bin))
5641
-		return '';
5977
+	if(empty($bin)) {
5978
+			return '';
5979
+	}
5642 5980
 
5643 5981
 	global $db_type;
5644 5982
 
5645
-	if ($db_type == 'postgresql')
5646
-		return $bin;
5983
+	if ($db_type == 'postgresql') {
5984
+			return $bin;
5985
+	}
5647 5986
 
5648 5987
 	$ip_address = inet_ntop($bin);
5649 5988
 
@@ -5668,26 +6007,32 @@  discard block
 block discarded – undo
5668 6007
  */
5669 6008
 function _safe_serialize($value)
5670 6009
 {
5671
-	if(is_null($value))
5672
-		return 'N;';
6010
+	if(is_null($value)) {
6011
+			return 'N;';
6012
+	}
5673 6013
 
5674
-	if(is_bool($value))
5675
-		return 'b:'. (int) $value .';';
6014
+	if(is_bool($value)) {
6015
+			return 'b:'. (int) $value .';';
6016
+	}
5676 6017
 
5677
-	if(is_int($value))
5678
-		return 'i:'. $value .';';
6018
+	if(is_int($value)) {
6019
+			return 'i:'. $value .';';
6020
+	}
5679 6021
 
5680
-	if(is_float($value))
5681
-		return 'd:'. str_replace(',', '.', $value) .';';
6022
+	if(is_float($value)) {
6023
+			return 'd:'. str_replace(',', '.', $value) .';';
6024
+	}
5682 6025
 
5683
-	if(is_string($value))
5684
-		return 's:'. strlen($value) .':"'. $value .'";';
6026
+	if(is_string($value)) {
6027
+			return 's:'. strlen($value) .':"'. $value .'";';
6028
+	}
5685 6029
 
5686 6030
 	if(is_array($value))
5687 6031
 	{
5688 6032
 		$out = '';
5689
-		foreach($value as $k => $v)
5690
-			$out .= _safe_serialize($k) . _safe_serialize($v);
6033
+		foreach($value as $k => $v) {
6034
+					$out .= _safe_serialize($k) . _safe_serialize($v);
6035
+		}
5691 6036
 
5692 6037
 		return 'a:'. count($value) .':{'. $out .'}';
5693 6038
 	}
@@ -5713,8 +6058,9 @@  discard block
 block discarded – undo
5713 6058
 
5714 6059
 	$out = _safe_serialize($value);
5715 6060
 
5716
-	if (isset($mbIntEnc))
5717
-		mb_internal_encoding($mbIntEnc);
6061
+	if (isset($mbIntEnc)) {
6062
+			mb_internal_encoding($mbIntEnc);
6063
+	}
5718 6064
 
5719 6065
 	return $out;
5720 6066
 }
@@ -5731,8 +6077,9 @@  discard block
 block discarded – undo
5731 6077
 function _safe_unserialize($str)
5732 6078
 {
5733 6079
 	// Input  is not a string.
5734
-	if(empty($str) || !is_string($str))
5735
-		return false;
6080
+	if(empty($str) || !is_string($str)) {
6081
+			return false;
6082
+	}
5736 6083
 
5737 6084
 	$stack = array();
5738 6085
 	$expected = array();
@@ -5748,43 +6095,38 @@  discard block
 block discarded – undo
5748 6095
 	while($state != 1)
5749 6096
 	{
5750 6097
 		$type = isset($str[0]) ? $str[0] : '';
5751
-		if($type == '}')
5752
-			$str = substr($str, 1);
5753
-
5754
-		else if($type == 'N' && $str[1] == ';')
6098
+		if($type == '}') {
6099
+					$str = substr($str, 1);
6100
+		} else if($type == 'N' && $str[1] == ';')
5755 6101
 		{
5756 6102
 			$value = null;
5757 6103
 			$str = substr($str, 2);
5758
-		}
5759
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
6104
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5760 6105
 		{
5761 6106
 			$value = $matches[1] == '1' ? true : false;
5762 6107
 			$str = substr($str, 4);
5763
-		}
5764
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
6108
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5765 6109
 		{
5766 6110
 			$value = (int)$matches[1];
5767 6111
 			$str = $matches[2];
5768
-		}
5769
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
6112
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5770 6113
 		{
5771 6114
 			$value = (float)$matches[1];
5772 6115
 			$str = $matches[3];
5773
-		}
5774
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
6116
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5775 6117
 		{
5776 6118
 			$value = substr($matches[2], 0, (int)$matches[1]);
5777 6119
 			$str = substr($matches[2], (int)$matches[1] + 2);
5778
-		}
5779
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
6120
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5780 6121
 		{
5781 6122
 			$expectedLength = (int)$matches[1];
5782 6123
 			$str = $matches[2];
5783 6124
 		}
5784 6125
 
5785 6126
 		// Object or unknown/malformed type.
5786
-		else
5787
-			return false;
6127
+		else {
6128
+					return false;
6129
+		}
5788 6130
 
5789 6131
 		switch($state)
5790 6132
 		{
@@ -5812,8 +6154,9 @@  discard block
 block discarded – undo
5812 6154
 				if($type == '}')
5813 6155
 				{
5814 6156
 					// Array size is less than expected.
5815
-					if(count($list) < end($expected))
5816
-						return false;
6157
+					if(count($list) < end($expected)) {
6158
+											return false;
6159
+					}
5817 6160
 
5818 6161
 					unset($list);
5819 6162
 					$list = &$stack[count($stack)-1];
@@ -5822,8 +6165,9 @@  discard block
 block discarded – undo
5822 6165
 					// Go to terminal state if we're at the end of the root array.
5823 6166
 					array_pop($expected);
5824 6167
 
5825
-					if(count($expected) == 0)
5826
-						$state = 1;
6168
+					if(count($expected) == 0) {
6169
+											$state = 1;
6170
+					}
5827 6171
 
5828 6172
 					break;
5829 6173
 				}
@@ -5831,8 +6175,9 @@  discard block
 block discarded – undo
5831 6175
 				if($type == 'i' || $type == 's')
5832 6176
 				{
5833 6177
 					// Array size exceeds expected length.
5834
-					if(count($list) >= end($expected))
5835
-						return false;
6178
+					if(count($list) >= end($expected)) {
6179
+											return false;
6180
+					}
5836 6181
 
5837 6182
 					$key = $value;
5838 6183
 					$state = 3;
@@ -5866,8 +6211,9 @@  discard block
 block discarded – undo
5866 6211
 	}
5867 6212
 
5868 6213
 	// Trailing data in input.
5869
-	if(!empty($str))
5870
-		return false;
6214
+	if(!empty($str)) {
6215
+			return false;
6216
+	}
5871 6217
 
5872 6218
 	return $data;
5873 6219
 }
@@ -5890,8 +6236,9 @@  discard block
 block discarded – undo
5890 6236
 
5891 6237
 	$out = _safe_unserialize($str);
5892 6238
 
5893
-	if (isset($mbIntEnc))
5894
-		mb_internal_encoding($mbIntEnc);
6239
+	if (isset($mbIntEnc)) {
6240
+			mb_internal_encoding($mbIntEnc);
6241
+	}
5895 6242
 
5896 6243
 	return $out;
5897 6244
 }
@@ -5906,12 +6253,14 @@  discard block
 block discarded – undo
5906 6253
 function smf_chmod($file, $value = 0)
5907 6254
 {
5908 6255
 	// No file? no checks!
5909
-	if (empty($file))
5910
-		return false;
6256
+	if (empty($file)) {
6257
+			return false;
6258
+	}
5911 6259
 
5912 6260
 	// Already writable?
5913
-	if (is_writable($file))
5914
-		return true;
6261
+	if (is_writable($file)) {
6262
+			return true;
6263
+	}
5915 6264
 
5916 6265
 	// Do we have a file or a dir?
5917 6266
 	$isDir = is_dir($file);
@@ -5927,10 +6276,9 @@  discard block
 block discarded – undo
5927 6276
 		{
5928 6277
 			$isWritable = true;
5929 6278
 			break;
6279
+		} else {
6280
+					@chmod($file, $val);
5930 6281
 		}
5931
-
5932
-		else
5933
-			@chmod($file, $val);
5934 6282
 	}
5935 6283
 
5936 6284
 	return $isWritable;
@@ -5949,8 +6297,9 @@  discard block
 block discarded – undo
5949 6297
 	global $txt;
5950 6298
 
5951 6299
 	// Come on...
5952
-	if (empty($json) || !is_string($json))
5953
-		return array();
6300
+	if (empty($json) || !is_string($json)) {
6301
+			return array();
6302
+	}
5954 6303
 
5955 6304
 	$returnArray = @json_decode($json, $returnAsArray);
5956 6305
 
@@ -5988,11 +6337,11 @@  discard block
 block discarded – undo
5988 6337
 		$jsonDebug = $jsonDebug[0];
5989 6338
 		loadLanguage('Errors');
5990 6339
 
5991
-		if (!empty($jsonDebug))
5992
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5993
-
5994
-		else
5995
-			log_error($txt['json_'. $jsonError], 'critical');
6340
+		if (!empty($jsonDebug)) {
6341
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6342
+		} else {
6343
+					log_error($txt['json_'. $jsonError], 'critical');
6344
+		}
5996 6345
 
5997 6346
 		// Everyone expects an array.
5998 6347
 		return array();
@@ -6026,8 +6375,9 @@  discard block
 block discarded – undo
6026 6375
 	global $db_show_debug, $modSettings;
6027 6376
 
6028 6377
 	// Defensive programming anyone?
6029
-	if (empty($data))
6030
-		return false;
6378
+	if (empty($data)) {
6379
+			return false;
6380
+	}
6031 6381
 
6032 6382
 	// Don't need extra stuff...
6033 6383
 	$db_show_debug = false;
@@ -6035,11 +6385,11 @@  discard block
 block discarded – undo
6035 6385
 	// Kill anything else.
6036 6386
 	ob_end_clean();
6037 6387
 
6038
-	if (!empty($modSettings['CompressedOutput']))
6039
-		@ob_start('ob_gzhandler');
6040
-
6041
-	else
6042
-		ob_start();
6388
+	if (!empty($modSettings['CompressedOutput'])) {
6389
+			@ob_start('ob_gzhandler');
6390
+	} else {
6391
+			ob_start();
6392
+	}
6043 6393
 
6044 6394
 	// Set the header.
6045 6395
 	header($type);
@@ -6071,8 +6421,9 @@  discard block
 block discarded – undo
6071 6421
 	static $done = false;
6072 6422
 
6073 6423
 	// If we don't need to do anything, don't
6074
-	if (!$update && $done)
6075
-		return;
6424
+	if (!$update && $done) {
6425
+			return;
6426
+	}
6076 6427
 
6077 6428
 	// Should we get a new copy of the official list of TLDs?
6078 6429
 	if ($update)
@@ -6084,8 +6435,9 @@  discard block
 block discarded – undo
6084 6435
 		// marauding bandits roaming on the surface. We don't want to waste precious electricity on
6085 6436
 		// pointlessly repeating background tasks, so we'll wait until the next regularly scheduled
6086 6437
 		// update to see if civilization has been restored.
6087
-		if ($tlds === false)
6088
-			$postapocalypticNightmare = true;
6438
+		if ($tlds === false) {
6439
+					$postapocalypticNightmare = true;
6440
+		}
6089 6441
 	}
6090 6442
 	// If we aren't updating and the regex is valid, we're done
6091 6443
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -6100,10 +6452,11 @@  discard block
 block discarded – undo
6100 6452
 		// Clean $tlds and convert it to an array
6101 6453
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
6102 6454
 			$line = trim($line);
6103
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
6104
-				return false;
6105
-			else
6106
-				return true;
6455
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6456
+							return false;
6457
+			} else {
6458
+							return true;
6459
+			}
6107 6460
 		});
6108 6461
 
6109 6462
 		// Convert Punycode to Unicode
@@ -6195,8 +6548,7 @@  discard block
 block discarded – undo
6195 6548
 
6196 6549
 		$strlen = 'mb_strlen';
6197 6550
 		$substr = 'mb_substr';
6198
-	}
6199
-	else
6551
+	} else
6200 6552
 	{
6201 6553
 		$strlen = $smcFunc['strlen'];
6202 6554
 		$substr = $smcFunc['substr'];
@@ -6210,20 +6562,21 @@  discard block
 block discarded – undo
6210 6562
 
6211 6563
 		$first = $substr($string, 0, 1);
6212 6564
 
6213
-		if (empty($index[$first]))
6214
-			$index[$first] = array();
6565
+		if (empty($index[$first])) {
6566
+					$index[$first] = array();
6567
+		}
6215 6568
 
6216 6569
 		if ($strlen($string) > 1)
6217 6570
 		{
6218 6571
 			// Sanity check on recursion
6219
-			if ($depth > 99)
6220
-				$index[$first][$substr($string, 1)] = '';
6221
-
6222
-			else
6223
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6572
+			if ($depth > 99) {
6573
+							$index[$first][$substr($string, 1)] = '';
6574
+			} else {
6575
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6576
+			}
6577
+		} else {
6578
+					$index[$first][''] = '';
6224 6579
 		}
6225
-		else
6226
-			$index[$first][''] = '';
6227 6580
 
6228 6581
 		$depth--;
6229 6582
 		return $index;
@@ -6246,9 +6599,9 @@  discard block
 block discarded – undo
6246 6599
 			$key_regex = preg_quote($key, $delim);
6247 6600
 			$new_key = $key;
6248 6601
 
6249
-			if (empty($value))
6250
-				$sub_regex = '';
6251
-			else
6602
+			if (empty($value)) {
6603
+							$sub_regex = '';
6604
+			} else
6252 6605
 			{
6253 6606
 				$sub_regex = $index_to_regex($value, $delim);
6254 6607
 
@@ -6256,22 +6609,22 @@  discard block
 block discarded – undo
6256 6609
 				{
6257 6610
 					$new_key_array = explode('(?'.'>', $sub_regex);
6258 6611
 					$new_key .= $new_key_array[0];
6612
+				} else {
6613
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6259 6614
 				}
6260
-				else
6261
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6262 6615
 			}
6263 6616
 
6264
-			if ($depth > 1)
6265
-				$regex[$new_key] = $key_regex . $sub_regex;
6266
-			else
6617
+			if ($depth > 1) {
6618
+							$regex[$new_key] = $key_regex . $sub_regex;
6619
+			} else
6267 6620
 			{
6268 6621
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
6269 6622
 				{
6270 6623
 					$regex[$new_key] = $key_regex . $sub_regex;
6271 6624
 					unset($index[$key]);
6625
+				} else {
6626
+									break;
6272 6627
 				}
6273
-				else
6274
-					break;
6275 6628
 			}
6276 6629
 		}
6277 6630
 
@@ -6280,10 +6633,11 @@  discard block
 block discarded – undo
6280 6633
 			$l1 = $strlen($k1);
6281 6634
 			$l2 = $strlen($k2);
6282 6635
 
6283
-			if ($l1 == $l2)
6284
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
6285
-			else
6286
-				return $l1 > $l2 ? -1 : 1;
6636
+			if ($l1 == $l2) {
6637
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6638
+			} else {
6639
+							return $l1 > $l2 ? -1 : 1;
6640
+			}
6287 6641
 		});
6288 6642
 
6289 6643
 		$depth--;
@@ -6294,21 +6648,24 @@  discard block
 block discarded – undo
6294 6648
 	$index = array();
6295 6649
 	$regex = '';
6296 6650
 
6297
-	foreach ($strings as $string)
6298
-		$index = $add_string_to_index($string, $index);
6651
+	foreach ($strings as $string) {
6652
+			$index = $add_string_to_index($string, $index);
6653
+	}
6299 6654
 
6300 6655
 	if ($returnArray === true)
6301 6656
 	{
6302 6657
 		$regex = array();
6303
-		while (!empty($index))
6304
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6658
+		while (!empty($index)) {
6659
+					$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6660
+		}
6661
+	} else {
6662
+			$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6305 6663
 	}
6306
-	else
6307
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6308 6664
 
6309 6665
 	// Restore PHP's internal character encoding to whatever it was originally
6310
-	if (!empty($current_encoding))
6311
-		mb_internal_encoding($current_encoding);
6666
+	if (!empty($current_encoding)) {
6667
+			mb_internal_encoding($current_encoding);
6668
+	}
6312 6669
 
6313 6670
 	return $regex;
6314 6671
 }
@@ -6351,13 +6708,15 @@  discard block
 block discarded – undo
6351 6708
 	// Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't...
6352 6709
 	$url = str_ireplace('https://', 'http://', $url) . '/';
6353 6710
 	$headers = @get_headers($url);
6354
-	if ($headers === false)
6355
-		return false;
6711
+	if ($headers === false) {
6712
+			return false;
6713
+	}
6356 6714
 
6357 6715
 	// Now to see if it came back https...
6358 6716
 	// First check for a redirect status code in first row (301, 302, 307)
6359
-	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false)
6360
-		return false;
6717
+	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) {
6718
+			return false;
6719
+	}
6361 6720
 
6362 6721
 	// Search for the location entry to confirm https
6363 6722
 	$result = false;
@@ -6395,8 +6754,7 @@  discard block
 block discarded – undo
6395 6754
 		$is_admin = $user_info['is_admin'];
6396 6755
 		$mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null;
6397 6756
 		$ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null;
6398
-	}
6399
-	else
6757
+	} else
6400 6758
 	{
6401 6759
 		$request = $smcFunc['db_query']('', '
6402 6760
 				SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group
@@ -6410,17 +6768,19 @@  discard block
 block discarded – undo
6410 6768
 
6411 6769
 		$row = $smcFunc['db_fetch_assoc']($request);
6412 6770
 
6413
-		if (empty($row['additional_groups']))
6414
-			$groups = array($row['id_group'], $row['id_post_group']);
6415
-		else
6416
-			$groups = array_merge(
6771
+		if (empty($row['additional_groups'])) {
6772
+					$groups = array($row['id_group'], $row['id_post_group']);
6773
+		} else {
6774
+					$groups = array_merge(
6417 6775
 					array($row['id_group'], $row['id_post_group']),
6418 6776
 					explode(',', $row['additional_groups'])
6419 6777
 			);
6778
+		}
6420 6779
 
6421 6780
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
6422
-		foreach ($groups as $k => $v)
6423
-			$groups[$k] = (int) $v;
6781
+		foreach ($groups as $k => $v) {
6782
+					$groups[$k] = (int) $v;
6783
+		}
6424 6784
 
6425 6785
 		$is_admin = in_array(1, $groups);
6426 6786
 
@@ -6437,8 +6797,9 @@  discard block
 block discarded – undo
6437 6797
 				'current_member' => $userid,
6438 6798
 			)
6439 6799
 		);
6440
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6441
-			$boards_mod[] = $row['id_board'];
6800
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6801
+					$boards_mod[] = $row['id_board'];
6802
+		}
6442 6803
 		$smcFunc['db_free_result']($request);
6443 6804
 
6444 6805
 		// Can any of the groups they're in moderate any of the boards?
@@ -6450,8 +6811,9 @@  discard block
 block discarded – undo
6450 6811
 				'groups' => $groups,
6451 6812
 			)
6452 6813
 		);
6453
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6454
-			$boards_mod[] = $row['id_board'];
6814
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6815
+					$boards_mod[] = $row['id_board'];
6816
+		}
6455 6817
 		$smcFunc['db_free_result']($request);
6456 6818
 
6457 6819
 		// Just in case we've got duplicates here...
@@ -6461,21 +6823,25 @@  discard block
 block discarded – undo
6461 6823
 	}
6462 6824
 
6463 6825
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
6464
-	if ($is_admin)
6465
-		$query_part['query_see_board'] = '1=1';
6826
+	if ($is_admin) {
6827
+			$query_part['query_see_board'] = '1=1';
6828
+	}
6466 6829
 	// Otherwise just the groups in $user_info['groups'].
6467
-	else
6468
-		$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'] : '') . ')';
6830
+	else {
6831
+			$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'] : '') . ')';
6832
+	}
6469 6833
 
6470 6834
 	// Build the list of boards they WANT to see.
6471 6835
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
6472 6836
 
6473 6837
 	// If they aren't ignoring any boards then they want to see all the boards they can see
6474
-	if (empty($ignoreboards))
6475
-		$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6838
+	if (empty($ignoreboards)) {
6839
+			$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6840
+	}
6476 6841
 	// Ok I guess they don't want to see all the boards
6477
-	else
6478
-		$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6842
+	else {
6843
+			$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6844
+	}
6479 6845
 
6480 6846
 	return $query_part;
6481 6847
 }
@@ -6489,10 +6855,11 @@  discard block
 block discarded – undo
6489 6855
 {
6490 6856
 	$secure = false;
6491 6857
 
6492
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
6493
-		$secure = true;
6494
-	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')
6495
-		$secure = true;
6858
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
6859
+			$secure = true;
6860
+	} 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') {
6861
+			$secure = true;
6862
+	}
6496 6863
 
6497 6864
 	return $secure;
6498 6865
 }
@@ -6509,11 +6876,12 @@  discard block
 block discarded – undo
6509 6876
 {
6510 6877
 	$url = iri_to_url($iri);
6511 6878
 
6512
-	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false)
6513
-		return $iri;
6514
-	else
6515
-		return false;
6516
-}
6879
+	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) {
6880
+			return $iri;
6881
+	} else {
6882
+			return false;
6883
+	}
6884
+	}
6517 6885
 
6518 6886
 /**
6519 6887
  * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs
@@ -6556,8 +6924,9 @@  discard block
 block discarded – undo
6556 6924
 
6557 6925
 	$host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST);
6558 6926
 
6559
-	if (empty($host))
6560
-		return $iri;
6927
+	if (empty($host)) {
6928
+			return $iri;
6929
+	}
6561 6930
 
6562 6931
 	// Convert the domain using the Punycode algorithm
6563 6932
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6593,8 +6962,9 @@  discard block
 block discarded – undo
6593 6962
 
6594 6963
 	$host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST);
6595 6964
 
6596
-	if (empty($host))
6597
-		return $url;
6965
+	if (empty($host)) {
6966
+			return $url;
6967
+	}
6598 6968
 
6599 6969
 	// Decode the domain from Punycode
6600 6970
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6620,8 +6990,9 @@  discard block
 block discarded – undo
6620 6990
 {
6621 6991
 	global $user_info, $modSettings, $smcFunc, $txt;
6622 6992
 
6623
-	if (empty($modSettings['cron_last_checked']))
6624
-		$modSettings['cron_last_checked'] = 0;
6993
+	if (empty($modSettings['cron_last_checked'])) {
6994
+			$modSettings['cron_last_checked'] = 0;
6995
+	}
6625 6996
 
6626 6997
 	if (!empty($modSettings['cron_is_real_cron']) && time() - $modSettings['cron_last_checked'] > 84600)
6627 6998
 	{
@@ -6641,9 +7012,9 @@  discard block
 block discarded – undo
6641 7012
 			loadLanguage('ManageScheduledTasks');
6642 7013
 			log_error($txt['cron_not_working']);
6643 7014
 			updateSettings(array('cron_is_real_cron' => 0));
7015
+		} else {
7016
+					updateSettings(array('cron_last_checked' => time()));
6644 7017
 		}
6645
-		else
6646
-			updateSettings(array('cron_last_checked' => time()));
6647 7018
 	}
6648 7019
 }
6649 7020
 
@@ -6667,10 +7038,11 @@  discard block
 block discarded – undo
6667 7038
 
6668 7039
 	$protocol = preg_match('~^\s*(HTTP/[12]\.\d)\s*$~i', $_SERVER['SERVER_PROTOCOL'], $matches) ? $matches[1] : 'HTTP/1.0';
6669 7040
 
6670
-	if (!isset($statuses[$code]) && empty($status))
6671
-		header($protocol . ' 500 Internal Server Error');
6672
-	else
6673
-		header($protocol . ' ' . $code . ' ' . (!empty($status) ? $status : $statuses[$code]));
6674
-}
7041
+	if (!isset($statuses[$code]) && empty($status)) {
7042
+			header($protocol . ' 500 Internal Server Error');
7043
+	} else {
7044
+			header($protocol . ' ' . $code . ' ' . (!empty($status) ? $status : $statuses[$code]));
7045
+	}
7046
+	}
6675 7047
 
6676 7048
 ?>
6677 7049
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/CacheAPI-postgres.php 2 patches
Braces   +28 added lines, -19 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * PostgreSQL Cache API class
@@ -49,8 +50,9 @@  discard block
 block discarded – undo
49 50
 
50 51
 		$result = pg_execute($db_connection, '', array('public', $db_prefix . 'cache'));
51 52
 
52
-		if (pg_affected_rows($result) === 0)
53
-			pg_query($db_connection, 'CREATE UNLOGGED TABLE ' . $db_prefix . 'cache (key text, value text, ttl bigint, PRIMARY KEY (key))');			
53
+		if (pg_affected_rows($result) === 0) {
54
+					pg_query($db_connection, 'CREATE UNLOGGED TABLE ' . $db_prefix . 'cache (key text, value text, ttl bigint, PRIMARY KEY (key))');
55
+		}
54 56
 	}
55 57
 
56 58
 	/**
@@ -60,14 +62,16 @@  discard block
 block discarded – undo
60 62
 	{
61 63
 		global $smcFunc, $db_connection;
62 64
 
63
-		if ($smcFunc['db_title'] !== 'PostgreSQL')
64
-			return false;
65
+		if ($smcFunc['db_title'] !== 'PostgreSQL') {
66
+					return false;
67
+		}
65 68
 
66 69
 		$result = pg_query($db_connection, 'SHOW server_version_num');
67 70
 		$res = pg_fetch_assoc($result);
68 71
 		
69
-		if ($res['server_version_num'] < 90500)
70
-			return false;
72
+		if ($res['server_version_num'] < 90500) {
73
+					return false;
74
+		}
71 75
 		
72 76
 		return $test ? true : parent::isSupported();
73 77
 	}
@@ -81,13 +85,15 @@  discard block
 block discarded – undo
81 85
 
82 86
 		$ttl = time() - $ttl;
83 87
 		
84
-		if (empty($this->pg_get_data_prep))
85
-			$this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1');
88
+		if (empty($this->pg_get_data_prep)) {
89
+					$this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1');
90
+		}
86 91
 			
87 92
 		$result = pg_execute($db_connection, 'smf_cache_get_data', array($key, $ttl));
88 93
 		
89
-		if (pg_affected_rows($result) === 0)
90
-			return null;
94
+		if (pg_affected_rows($result) === 0) {
95
+					return null;
96
+		}
91 97
 
92 98
 		$res = pg_fetch_assoc($result);
93 99
 
@@ -101,23 +107,26 @@  discard block
 block discarded – undo
101 107
 	{
102 108
 		global  $db_prefix, $db_connection;
103 109
 
104
-		if (!isset($value))
105
-			$value = '';
110
+		if (!isset($value)) {
111
+					$value = '';
112
+		}
106 113
 
107 114
 		$ttl = time() + $ttl;
108 115
 
109
-		if (empty($this->pg_put_data_prep))
110
-			$this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data',
116
+		if (empty($this->pg_put_data_prep)) {
117
+					$this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data',
111 118
 				'INSERT INTO ' . $db_prefix . 'cache(key,value,ttl) VALUES($1,$2,$3)
112 119
 				ON CONFLICT(key) DO UPDATE SET value = excluded.value, ttl = excluded.ttl'
113 120
 			);
121
+		}
114 122
 
115 123
 		$result = pg_execute($db_connection, 'smf_cache_put_data', array($key, $value, $ttl));
116 124
 
117
-		if (pg_affected_rows($result) > 0)
118
-			return true;
119
-		else
120
-			return false;
125
+		if (pg_affected_rows($result) > 0) {
126
+					return true;
127
+		} else {
128
+					return false;
129
+		}
121 130
 	}
122 131
 
123 132
 	/**
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	{
166 166
 		global $db_connection, $db_prefix;
167 167
 		
168
-		pg_query($db_connection, 'CREATE LOCAL TEMP TABLE IF NOT EXISTS ' . $db_prefix . 'cache_tmp AS SELECT * FROM ' . $db_prefix . 'cache WHERE ttl >= ' . time() );
168
+		pg_query($db_connection, 'CREATE LOCAL TEMP TABLE IF NOT EXISTS ' . $db_prefix . 'cache_tmp AS SELECT * FROM ' . $db_prefix . 'cache WHERE ttl >= ' . time());
169 169
 	}
170 170
 	
171 171
 	/**
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	{
190 190
 		global $db_connection, $db_prefix;
191 191
 		
192
-		pg_query($db_connection, 'INSERT INTO ' . $db_prefix . 'cache SELECT * FROM '. $db_prefix . 'cache_tmp ON CONFLICT DO NOTHING');
192
+		pg_query($db_connection, 'INSERT INTO ' . $db_prefix . 'cache SELECT * FROM ' . $db_prefix . 'cache_tmp ON CONFLICT DO NOTHING');
193 193
 	}
194 194
 }
195 195
 
Please login to merge, or discard this patch.
Sources/Profile-Actions.php 1 patch
Braces   +117 added lines, -86 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
  * Activate an account.
@@ -48,8 +49,9 @@  discard block
 block discarded – undo
48 49
 		logAction('approve_member', array('member' => $memID), 'admin');
49 50
 
50 51
 		// If we are doing approval, update the stats for the member just in case.
51
-		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15)))
52
-			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
52
+		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15))) {
53
+					updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
54
+		}
53 55
 
54 56
 		// Make sure we update the stats too.
55 57
 		updateStats('member', false);
@@ -76,8 +78,9 @@  discard block
 block discarded – undo
76 78
 	$issueErrors = array();
77 79
 
78 80
 	// Doesn't hurt to be overly cautious.
79
-	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning'))
80
-		fatal_lang_error('no_access', false);
81
+	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning')) {
82
+			fatal_lang_error('no_access', false);
83
+	}
81 84
 
82 85
 	// Get the base (errors related) stuff done.
83 86
 	loadLanguage('Errors');
@@ -135,16 +138,18 @@  discard block
 block discarded – undo
135 138
 
136 139
 		// This cannot be empty!
137 140
 		$_POST['warn_reason'] = isset($_POST['warn_reason']) ? trim($_POST['warn_reason']) : '';
138
-		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner'])
139
-			$issueErrors[] = 'warning_no_reason';
141
+		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner']) {
142
+					$issueErrors[] = 'warning_no_reason';
143
+		}
140 144
 		$_POST['warn_reason'] = $smcFunc['htmlspecialchars']($_POST['warn_reason']);
141 145
 
142 146
 		$_POST['warning_level'] = (int) $_POST['warning_level'];
143 147
 		$_POST['warning_level'] = max(0, min(100, $_POST['warning_level']));
144
-		if ($_POST['warning_level'] < $context['min_allowed'])
145
-			$_POST['warning_level'] = $context['min_allowed'];
146
-		elseif ($_POST['warning_level'] > $context['max_allowed'])
147
-			$_POST['warning_level'] = $context['max_allowed'];
148
+		if ($_POST['warning_level'] < $context['min_allowed']) {
149
+					$_POST['warning_level'] = $context['min_allowed'];
150
+		} elseif ($_POST['warning_level'] > $context['max_allowed']) {
151
+					$_POST['warning_level'] = $context['max_allowed'];
152
+		}
148 153
 
149 154
 		// Do we actually have to issue them with a PM?
150 155
 		$id_notice = 0;
@@ -152,8 +157,9 @@  discard block
 block discarded – undo
152 157
 		{
153 158
 			$_POST['warn_sub'] = trim($_POST['warn_sub']);
154 159
 			$_POST['warn_body'] = trim($_POST['warn_body']);
155
-			if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
156
-				$issueErrors[] = 'warning_notify_blank';
160
+			if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
161
+							$issueErrors[] = 'warning_notify_blank';
162
+			}
157 163
 			// Send the PM?
158 164
 			else
159 165
 			{
@@ -190,8 +196,8 @@  discard block
 block discarded – undo
190 196
 		if (empty($issueErrors))
191 197
 		{
192 198
 			// Log what we've done!
193
-			if (!$context['user']['is_owner'])
194
-				$smcFunc['db_insert']('',
199
+			if (!$context['user']['is_owner']) {
200
+							$smcFunc['db_insert']('',
195 201
 					'{db_prefix}log_comments',
196 202
 					array(
197 203
 						'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int', 'recipient_name' => 'string-255',
@@ -203,14 +209,14 @@  discard block
 block discarded – undo
203 209
 					),
204 210
 					array('id_comment')
205 211
 				);
212
+			}
206 213
 
207 214
 			// Make the change.
208 215
 			updateMemberData($memID, array('warning' => $_POST['warning_level']));
209 216
 
210 217
 			// Leave a lovely message.
211 218
 			$context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : $txt['profile_warning_success'];
212
-		}
213
-		else
219
+		} else
214 220
 		{
215 221
 			// Try to remember some bits.
216 222
 			$context['warning_data'] = array(
@@ -229,8 +235,9 @@  discard block
 block discarded – undo
229 235
 	{
230 236
 		$warning_body = !empty($_POST['warn_body']) ? trim(censorText($_POST['warn_body'])) : '';
231 237
 		$context['preview_subject'] = !empty($_POST['warn_sub']) ? trim($smcFunc['htmlspecialchars']($_POST['warn_sub'])) : '';
232
-		if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
233
-			$issueErrors[] = 'warning_notify_blank';
238
+		if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
239
+					$issueErrors[] = 'warning_notify_blank';
240
+		}
234 241
 
235 242
 		if (!empty($_POST['warn_body']))
236 243
 		{
@@ -254,8 +261,9 @@  discard block
 block discarded – undo
254 261
 	{
255 262
 		// Fill in the suite of errors.
256 263
 		$context['post_errors'] = array();
257
-		foreach ($issueErrors as $error)
258
-			$context['post_errors'][] = $txt[$error];
264
+		foreach ($issueErrors as $error) {
265
+					$context['post_errors'][] = $txt[$error];
266
+		}
259 267
 	}
260 268
 
261 269
 
@@ -272,9 +280,10 @@  discard block
 block discarded – undo
272 280
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_mute'],
273 281
 	);
274 282
 	$context['current_level'] = 0;
275
-	foreach ($context['level_effects'] as $limit => $dummy)
276
-		if ($context['member']['warning'] >= $limit)
283
+	foreach ($context['level_effects'] as $limit => $dummy) {
284
+			if ($context['member']['warning'] >= $limit)
277 285
 			$context['current_level'] = $limit;
286
+	}
278 287
 
279 288
 	$listOptions = array(
280 289
 		'id' => 'view_warnings',
@@ -337,11 +346,12 @@  discard block
 block discarded – undo
337 346
 							' . $warning['reason'] . '
338 347
 						</div>';
339 348
 
340
-						if (!empty($warning['id_notice']))
341
-							$ret .= '
349
+						if (!empty($warning['id_notice'])) {
350
+													$ret .= '
342 351
 						<div class="floatright">
343 352
 							<a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $warning['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" rel="noopener" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a>
344 353
 						</div>';
354
+						}
345 355
 
346 356
 						return $ret;
347 357
 					},
@@ -413,8 +423,9 @@  discard block
 block discarded – undo
413 423
 	while ($row = $smcFunc['db_fetch_assoc']($request))
414 424
 	{
415 425
 		// If we're not warning for a message skip any that are.
416
-		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false)
417
-			continue;
426
+		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false) {
427
+					continue;
428
+		}
418 429
 
419 430
 		$context['notification_templates'][] = array(
420 431
 			'title' => $row['template_title'],
@@ -424,16 +435,18 @@  discard block
 block discarded – undo
424 435
 	$smcFunc['db_free_result']($request);
425 436
 
426 437
 	// Setup the "default" templates.
427
-	foreach (array('spamming', 'offence', 'insulting') as $type)
428
-		$context['notification_templates'][] = array(
438
+	foreach (array('spamming', 'offence', 'insulting') as $type) {
439
+			$context['notification_templates'][] = array(
429 440
 			'title' => $txt['profile_warning_notify_title_' . $type],
430 441
 			'body' => sprintf($txt['profile_warning_notify_template_outline' . (!empty($context['warning_for_message']) ? '_post' : '')], $txt['profile_warning_notify_for_' . $type]),
431 442
 		);
443
+	}
432 444
 
433 445
 	// Replace all the common variables in the templates.
434
-	foreach ($context['notification_templates'] as $k => $name)
435
-		$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
436
-}
446
+	foreach ($context['notification_templates'] as $k => $name) {
447
+			$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
448
+	}
449
+	}
437 450
 
438 451
 /**
439 452
  * Get the number of warnings a user has. Callback for $listOptions['get_count'] in issueWarning()
@@ -517,10 +530,11 @@  discard block
 block discarded – undo
517 530
 {
518 531
 	global $txt, $context, $modSettings, $cur_profile;
519 532
 
520
-	if (!$context['user']['is_owner'])
521
-		isAllowedTo('profile_remove_any');
522
-	elseif (!allowedTo('profile_remove_any'))
523
-		isAllowedTo('profile_remove_own');
533
+	if (!$context['user']['is_owner']) {
534
+			isAllowedTo('profile_remove_any');
535
+	} elseif (!allowedTo('profile_remove_any')) {
536
+			isAllowedTo('profile_remove_own');
537
+	}
524 538
 
525 539
 	// Permissions for removing stuff...
526 540
 	$context['can_delete_posts'] = !$context['user']['is_owner'] && allowedTo('moderate_forum');
@@ -547,10 +561,11 @@  discard block
 block discarded – undo
547 561
 
548 562
 	// @todo Add a way to delete pms as well?
549 563
 
550
-	if (!$context['user']['is_owner'])
551
-		isAllowedTo('profile_remove_any');
552
-	elseif (!allowedTo('profile_remove_any'))
553
-		isAllowedTo('profile_remove_own');
564
+	if (!$context['user']['is_owner']) {
565
+			isAllowedTo('profile_remove_any');
566
+	} elseif (!allowedTo('profile_remove_any')) {
567
+			isAllowedTo('profile_remove_own');
568
+	}
554 569
 
555 570
 	checkSession();
556 571
 
@@ -576,8 +591,9 @@  discard block
 block discarded – undo
576 591
 		list ($another) = $smcFunc['db_fetch_row']($request);
577 592
 		$smcFunc['db_free_result']($request);
578 593
 
579
-		if (empty($another))
580
-			fatal_lang_error('at_least_one_admin', 'critical');
594
+		if (empty($another)) {
595
+					fatal_lang_error('at_least_one_admin', 'critical');
596
+		}
581 597
 	}
582 598
 
583 599
 	// This file is needed for the deleteMembers function.
@@ -656,8 +672,9 @@  discard block
 block discarded – undo
656 672
 					)
657 673
 				);
658 674
 				$topicIDs = array();
659
-				while ($row = $smcFunc['db_fetch_assoc']($request))
660
-					$topicIDs[] = $row['id_topic'];
675
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
676
+									$topicIDs[] = $row['id_topic'];
677
+				}
661 678
 				$smcFunc['db_free_result']($request);
662 679
 
663 680
 				// Actually remove the topics. Ignore recycling if we want to perma-delete things...
@@ -680,8 +697,9 @@  discard block
 block discarded – undo
680 697
 			// This could take a while... but ya know it's gonna be worth it in the end.
681 698
 			while ($row = $smcFunc['db_fetch_assoc']($request))
682 699
 			{
683
-				if (function_exists('apache_reset_timeout'))
684
-					@apache_reset_timeout();
700
+				if (function_exists('apache_reset_timeout')) {
701
+									@apache_reset_timeout();
702
+				}
685 703
 
686 704
 				removeMessage($row['id_msg']);
687 705
 			}
@@ -689,8 +707,9 @@  discard block
 block discarded – undo
689 707
 		}
690 708
 
691 709
 		// Only delete this poor members account if they are actually being booted out of camp.
692
-		if (isset($_POST['deleteAccount']))
693
-			deleteMembers($memID);
710
+		if (isset($_POST['deleteAccount'])) {
711
+					deleteMembers($memID);
712
+		}
694 713
 	}
695 714
 	// Do they need approval to delete?
696 715
 	elseif (!empty($modSettings['approveAccountDeletion']) && !allowedTo('moderate_forum'))
@@ -741,18 +760,18 @@  discard block
 block discarded – undo
741 760
 		{
742 761
 			foreach ($costs as $duration => $cost)
743 762
 			{
744
-				if ($cost != 0)
745
-					$cost_array[$duration] = $cost;
763
+				if ($cost != 0) {
764
+									$cost_array[$duration] = $cost;
765
+				}
746 766
 			}
747
-		}
748
-		else
767
+		} else
749 768
 		{
750 769
 			$cost_array['fixed'] = $costs['fixed'];
751 770
 		}
752 771
 
753
-		if (empty($cost_array))
754
-			unset($context['subscriptions'][$id]);
755
-		else
772
+		if (empty($cost_array)) {
773
+					unset($context['subscriptions'][$id]);
774
+		} else
756 775
 		{
757 776
 			$context['subscriptions'][$id]['member'] = 0;
758 777
 			$context['subscriptions'][$id]['subscribed'] = false;
@@ -765,13 +784,15 @@  discard block
 block discarded – undo
765 784
 	foreach ($gateways as $id => $gateway)
766 785
 	{
767 786
 		$gateways[$id] = new $gateway['display_class']();
768
-		if (!$gateways[$id]->gatewayEnabled())
769
-			unset($gateways[$id]);
787
+		if (!$gateways[$id]->gatewayEnabled()) {
788
+					unset($gateways[$id]);
789
+		}
770 790
 	}
771 791
 
772 792
 	// No gateways yet?
773
-	if (empty($gateways))
774
-		fatal_error($txt['paid_admin_not_setup_gateway']);
793
+	if (empty($gateways)) {
794
+			fatal_error($txt['paid_admin_not_setup_gateway']);
795
+	}
775 796
 
776 797
 	// Get the current subscriptions.
777 798
 	$request = $smcFunc['db_query']('', '
@@ -786,8 +807,9 @@  discard block
 block discarded – undo
786 807
 	while ($row = $smcFunc['db_fetch_assoc']($request))
787 808
 	{
788 809
 		// The subscription must exist!
789
-		if (!isset($context['subscriptions'][$row['id_subscribe']]))
790
-			continue;
810
+		if (!isset($context['subscriptions'][$row['id_subscribe']])) {
811
+					continue;
812
+		}
791 813
 
792 814
 		$context['current'][$row['id_subscribe']] = array(
793 815
 			'id' => $row['id_sublog'],
@@ -801,8 +823,9 @@  discard block
 block discarded – undo
801 823
 			'status_text' => $row['status'] == 0 ? ($row['payments_pending'] ? $txt['paid_pending'] : $txt['paid_finished']) : $txt['paid_active'],
802 824
 		);
803 825
 
804
-		if ($row['status'] == 1)
805
-			$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
826
+		if ($row['status'] == 1) {
827
+					$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
828
+		}
806 829
 	}
807 830
 	$smcFunc['db_free_result']($request);
808 831
 
@@ -853,21 +876,25 @@  discard block
 block discarded – undo
853 876
 	if (isset($_GET['confirm']) && isset($_POST['sub_id']) && is_array($_POST['sub_id']))
854 877
 	{
855 878
 		// Hopefully just one.
856
-		foreach ($_POST['sub_id'] as $k => $v)
857
-			$ID_SUB = (int) $k;
879
+		foreach ($_POST['sub_id'] as $k => $v) {
880
+					$ID_SUB = (int) $k;
881
+		}
858 882
 
859
-		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0)
860
-			fatal_lang_error('paid_sub_not_active');
883
+		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0) {
884
+					fatal_lang_error('paid_sub_not_active');
885
+		}
861 886
 
862 887
 		// Simplify...
863 888
 		$context['sub'] = $context['subscriptions'][$ID_SUB];
864 889
 		$period = 'xx';
865
-		if ($context['sub']['flexible'])
866
-			$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
890
+		if ($context['sub']['flexible']) {
891
+					$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
892
+		}
867 893
 
868 894
 		// Check we have a valid cost.
869
-		if ($context['sub']['flexible'] && $period == 'xx')
870
-			fatal_lang_error('paid_sub_not_active');
895
+		if ($context['sub']['flexible'] && $period == 'xx') {
896
+					fatal_lang_error('paid_sub_not_active');
897
+		}
871 898
 
872 899
 		// Sort out the cost/currency.
873 900
 		$context['currency'] = $modSettings['paid_currency_code'];
@@ -880,8 +907,7 @@  discard block
 block discarded – undo
880 907
 			$context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']) . '/' . $txt[$_POST['cur'][$ID_SUB]];
881 908
 			// The period value for paypal.
882 909
 			$context['paypal_period'] = strtoupper(substr($_POST['cur'][$ID_SUB], 0, 1));
883
-		}
884
-		else
910
+		} else
885 911
 		{
886 912
 			// Real cost...
887 913
 			$context['value'] = $context['sub']['costs']['fixed'];
@@ -898,13 +924,15 @@  discard block
 block discarded – undo
898 924
 		foreach ($gateways as $id => $gateway)
899 925
 		{
900 926
 			$fields = $gateways[$id]->fetchGatewayFields($context['sub']['id'] . '+' . $memID, $context['sub'], $context['value'], $period, $scripturl . '?action=profile;u=' . $memID . ';area=subscriptions;sub_id=' . $context['sub']['id'] . ';done');
901
-			if (!empty($fields['form']))
902
-				$context['gateways'][] = $fields;
927
+			if (!empty($fields['form'])) {
928
+							$context['gateways'][] = $fields;
929
+			}
903 930
 		}
904 931
 
905 932
 		// Bugger?!
906
-		if (empty($context['gateways']))
907
-			fatal_error($txt['paid_admin_not_setup_gateway']);
933
+		if (empty($context['gateways'])) {
934
+					fatal_error($txt['paid_admin_not_setup_gateway']);
935
+		}
908 936
 
909 937
 		// Now we are going to assume they want to take this out ;)
910 938
 		$new_data = array($context['sub']['id'], $context['value'], $period, 'prepay');
@@ -912,16 +940,19 @@  discard block
 block discarded – undo
912 940
 		{
913 941
 			// What are the details like?
914 942
 			$current_pending = array();
915
-			if ($context['current'][$context['sub']['id']]['pending_details'] != '')
916
-				$current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true);
943
+			if ($context['current'][$context['sub']['id']]['pending_details'] != '') {
944
+							$current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true);
945
+			}
917 946
 			// Don't get silly.
918
-			if (count($current_pending) > 9)
919
-				$current_pending = array();
947
+			if (count($current_pending) > 9) {
948
+							$current_pending = array();
949
+			}
920 950
 			$pending_count = 0;
921 951
 			// Only record real pending payments as will otherwise confuse the admin!
922
-			foreach ($current_pending as $pending)
923
-				if ($pending[3] == 'payback')
952
+			foreach ($current_pending as $pending) {
953
+							if ($pending[3] == 'payback')
924 954
 					$pending_count++;
955
+			}
925 956
 
926 957
 			if (!in_array($new_data, $current_pending))
927 958
 			{
@@ -966,9 +997,9 @@  discard block
 block discarded – undo
966 997
 
967 998
 		// Quit.
968 999
 		return;
1000
+	} else {
1001
+			$context['sub_template'] = 'user_subscription';
1002
+	}
969 1003
 	}
970
-	else
971
-		$context['sub_template'] = 'user_subscription';
972
-}
973 1004
 
974 1005
 ?>
975 1006
\ No newline at end of file
Please login to merge, or discard this patch.
other/install.php 2 patches
Spacing   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1697,8 +1697,7 @@  discard block
 block discarded – undo
1697 1697
 	updateStats('topic');
1698 1698
 
1699 1699
 	// This function is needed to do the updateStats('subject') call.
1700
-	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1701
-		function($string){
1700
+	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1702 1701
 			global $sourcedir;
1703 1702
 			if (function_exists('mb_strtolower'))
1704 1703
 				return mb_strtolower($string, 'UTF-8');
@@ -1767,7 +1766,7 @@  discard block
 block discarded – undo
1767 1766
 		if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}')
1768 1767
 		{
1769 1768
 			// Set the ten lines to nothing.
1770
-			for ($j=0; $j < 10; $j++)
1769
+			for ($j = 0; $j < 10; $j++)
1771 1770
 				$settingsArray[$i++] = '';
1772 1771
 
1773 1772
 			continue;
Please login to merge, or discard this patch.
Braces   +472 added lines, -350 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -63,10 +64,11 @@  discard block
 block discarded – undo
63 64
 
64 65
 			list ($charcode) = pg_fetch_row($request);
65 66
 
66
-			if ($charcode == 'UTF8')
67
-				return true;
68
-			else
69
-				return false;
67
+			if ($charcode == 'UTF8') {
68
+							return true;
69
+			} else {
70
+							return false;
71
+			}
70 72
 		},
71 73
 		'utf8_version' => '8.0',
72 74
 		'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
@@ -76,12 +78,14 @@  discard block
 block discarded – undo
76 78
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
77 79
 
78 80
 			// Is it reserved?
79
-			if ($value == 'pg_')
80
-				return $txt['error_db_prefix_reserved'];
81
+			if ($value == 'pg_') {
82
+							return $txt['error_db_prefix_reserved'];
83
+			}
81 84
 
82 85
 			// Is the prefix numeric?
83
-			if (preg_match('~^\d~', $value))
84
-				return $txt['error_db_prefix_numeric'];
86
+			if (preg_match('~^\d~', $value)) {
87
+							return $txt['error_db_prefix_numeric'];
88
+			}
85 89
 
86 90
 			return true;
87 91
 		},
@@ -128,10 +132,11 @@  discard block
 block discarded – undo
128 132
 		$incontext['skip'] = false;
129 133
 
130 134
 		// Call the step and if it returns false that means pause!
131
-		if (function_exists($step[2]) && $step[2]() === false)
132
-			break;
133
-		elseif (function_exists($step[2]))
134
-			$incontext['current_step']++;
135
+		if (function_exists($step[2]) && $step[2]() === false) {
136
+					break;
137
+		} elseif (function_exists($step[2])) {
138
+					$incontext['current_step']++;
139
+		}
135 140
 
136 141
 		// No warnings pass on.
137 142
 		$incontext['warning'] = '';
@@ -147,8 +152,9 @@  discard block
 block discarded – undo
147 152
 	global $databases;
148 153
 
149 154
 	// Just so people using older versions of PHP aren't left in the cold.
150
-	if (!isset($_SERVER['PHP_SELF']))
151
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
155
+	if (!isset($_SERVER['PHP_SELF'])) {
156
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
157
+	}
152 158
 
153 159
 	// Enable error reporting for fatal errors.
154 160
 	error_reporting(E_ERROR | E_PARSE);
@@ -164,21 +170,23 @@  discard block
 block discarded – undo
164 170
 	{
165 171
 		ob_start();
166 172
 
167
-		if (ini_get('session.save_handler') == 'user')
168
-			@ini_set('session.save_handler', 'files');
169
-		if (function_exists('session_start'))
170
-			@session_start();
171
-	}
172
-	else
173
+		if (ini_get('session.save_handler') == 'user') {
174
+					@ini_set('session.save_handler', 'files');
175
+		}
176
+		if (function_exists('session_start')) {
177
+					@session_start();
178
+		}
179
+	} else
173 180
 	{
174 181
 		ob_start('ob_gzhandler');
175 182
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
183
+		if (ini_get('session.save_handler') == 'user') {
184
+					@ini_set('session.save_handler', 'files');
185
+		}
178 186
 		session_start();
179 187
 
180
-		if (!headers_sent())
181
-			echo '<!DOCTYPE html>
188
+		if (!headers_sent()) {
189
+					echo '<!DOCTYPE html>
182 190
 <html>
183 191
 	<head>
184 192
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -187,14 +195,16 @@  discard block
 block discarded – undo
187 195
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
188 196
 	</body>
189 197
 </html>';
198
+		}
190 199
 		exit;
191 200
 	}
192 201
 
193 202
 	// Add slashes, as long as they aren't already being added.
194
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
195
-		foreach ($_POST as $k => $v)
203
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
204
+			foreach ($_POST as $k => $v)
196 205
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
197 206
 				$_POST[$k] = addslashes($v);
207
+	}
198 208
 
199 209
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
200 210
 	if (isset($_GET['delete']))
@@ -215,8 +225,7 @@  discard block
 block discarded – undo
215 225
 			$ftp->close();
216 226
 
217 227
 			unset($_SESSION['installer_temp_ftp']);
218
-		}
219
-		else
228
+		} else
220 229
 		{
221 230
 			@unlink(__FILE__);
222 231
 
@@ -230,10 +239,11 @@  discard block
 block discarded – undo
230 239
 		// Now just redirect to a blank.png...
231 240
 		$secure = false;
232 241
 
233
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
234
-			$secure = true;
235
-		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')
236
-			$secure = true;
242
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
243
+					$secure = true;
244
+		} 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') {
245
+					$secure = true;
246
+		}
237 247
 
238 248
 		header('location: http' . ($secure ? 's' : '') . '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png');
239 249
 		exit;
@@ -244,10 +254,11 @@  discard block
 block discarded – undo
244 254
 	{
245 255
 		// Get PHP's default timezone, if set
246 256
 		$ini_tz = ini_get('date.timezone');
247
-		if (!empty($ini_tz))
248
-			$timezone_id = $ini_tz;
249
-		else
250
-			$timezone_id = '';
257
+		if (!empty($ini_tz)) {
258
+					$timezone_id = $ini_tz;
259
+		} else {
260
+					$timezone_id = '';
261
+		}
251 262
 
252 263
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
253 264
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -277,8 +288,9 @@  discard block
 block discarded – undo
277 288
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
278 289
 		while ($entry = $dir->read())
279 290
 		{
280
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
281
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
291
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
292
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
293
+			}
282 294
 		}
283 295
 		$dir->close();
284 296
 	}
@@ -325,10 +337,11 @@  discard block
 block discarded – undo
325 337
 	}
326 338
 
327 339
 	// Override the language file?
328
-	if (isset($_GET['lang_file']))
329
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
330
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
331
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
340
+	if (isset($_GET['lang_file'])) {
341
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
342
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
343
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
344
+	}
332 345
 
333 346
 	// Make sure it exists, if it doesn't reset it.
334 347
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -337,8 +350,9 @@  discard block
 block discarded – undo
337 350
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
338 351
 
339 352
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
340
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
341
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
353
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
354
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
355
+		}
342 356
 	}
343 357
 
344 358
 	// And now include the actual language file itself.
@@ -355,15 +369,18 @@  discard block
 block discarded – undo
355 369
 	global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings, $db_port;
356 370
 	global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist, $db_mb4;
357 371
 
358
-	if (empty($sourcedir))
359
-		$sourcedir = dirname(__FILE__) . '/Sources';
372
+	if (empty($sourcedir)) {
373
+			$sourcedir = dirname(__FILE__) . '/Sources';
374
+	}
360 375
 
361 376
 	// Need this to check whether we need the database password.
362 377
 	require(dirname(__FILE__) . '/Settings.php');
363
-	if (!defined('SMF'))
364
-		define('SMF', 1);
365
-	if (empty($smcFunc))
366
-		$smcFunc = array();
378
+	if (!defined('SMF')) {
379
+			define('SMF', 1);
380
+	}
381
+	if (empty($smcFunc)) {
382
+			$smcFunc = array();
383
+	}
367 384
 
368 385
 	$modSettings['disableQueryCheck'] = true;
369 386
 
@@ -374,14 +391,17 @@  discard block
 block discarded – undo
374 391
 
375 392
 		$options = array('persist' => $db_persist);
376 393
 
377
-		if (!empty($db_port))
378
-			$options['port'] = $db_port;
394
+		if (!empty($db_port)) {
395
+					$options['port'] = $db_port;
396
+		}
379 397
 
380
-		if (!empty($db_mb4))
381
-			$options['db_mb4'] = $db_mb4;
398
+		if (!empty($db_mb4)) {
399
+					$options['db_mb4'] = $db_mb4;
400
+		}
382 401
 
383
-		if (!$db_connection)
384
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
402
+		if (!$db_connection) {
403
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
404
+		}
385 405
 	}
386 406
 }
387 407
 
@@ -409,8 +429,9 @@  discard block
 block discarded – undo
409 429
 		// @todo REMOVE THIS!!
410 430
 		else
411 431
 		{
412
-			if (function_exists('doStep' . $_GET['step']))
413
-				call_user_func('doStep' . $_GET['step']);
432
+			if (function_exists('doStep' . $_GET['step'])) {
433
+							call_user_func('doStep' . $_GET['step']);
434
+			}
414 435
 		}
415 436
 		// Show the footer.
416 437
 		template_install_below();
@@ -428,8 +449,9 @@  discard block
 block discarded – undo
428 449
 	$incontext['sub_template'] = 'welcome_message';
429 450
 
430 451
 	// Done the submission?
431
-	if (isset($_POST['contbutt']))
432
-		return true;
452
+	if (isset($_POST['contbutt'])) {
453
+			return true;
454
+	}
433 455
 
434 456
 	// See if we think they have already installed it?
435 457
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -437,14 +459,17 @@  discard block
 block discarded – undo
437 459
 		$probably_installed = 0;
438 460
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
439 461
 		{
440
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
441
-				$probably_installed++;
442
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
443
-				$probably_installed++;
462
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
463
+							$probably_installed++;
464
+			}
465
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
466
+							$probably_installed++;
467
+			}
444 468
 		}
445 469
 
446
-		if ($probably_installed == 2)
447
-			$incontext['warning'] = $txt['error_already_installed'];
470
+		if ($probably_installed == 2) {
471
+					$incontext['warning'] = $txt['error_already_installed'];
472
+		}
448 473
 	}
449 474
 
450 475
 	// Is some database support even compiled in?
@@ -459,45 +484,54 @@  discard block
 block discarded – undo
459 484
 				$databases[$key]['supported'] = false;
460 485
 				$notFoundSQLFile = true;
461 486
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
487
+			} else {
488
+							$incontext['supported_databases'][] = $db;
462 489
 			}
463
-			else
464
-				$incontext['supported_databases'][] = $db;
465 490
 		}
466 491
 	}
467 492
 
468 493
 	// Check the PHP version.
469
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>=')))
470
-		$error = 'error_php_too_low';
494
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) {
495
+			$error = 'error_php_too_low';
496
+	}
471 497
 	// Make sure we have a supported database
472
-	elseif (empty($incontext['supported_databases']))
473
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
498
+	elseif (empty($incontext['supported_databases'])) {
499
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
500
+	}
474 501
 	// How about session support?  Some crazy sysadmin remove it?
475
-	elseif (!function_exists('session_start'))
476
-		$error = 'error_session_missing';
502
+	elseif (!function_exists('session_start')) {
503
+			$error = 'error_session_missing';
504
+	}
477 505
 	// Make sure they uploaded all the files.
478
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
479
-		$error = 'error_missing_files';
506
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
507
+			$error = 'error_missing_files';
508
+	}
480 509
 	// Very simple check on the session.save_path for Windows.
481 510
 	// @todo Move this down later if they don't use database-driven sessions?
482
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
483
-		$error = 'error_session_save_path';
511
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
512
+			$error = 'error_session_save_path';
513
+	}
484 514
 
485 515
 	// Since each of the three messages would look the same, anyway...
486
-	if (isset($error))
487
-		$incontext['error'] = $txt[$error];
516
+	if (isset($error)) {
517
+			$incontext['error'] = $txt[$error];
518
+	}
488 519
 
489 520
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
490
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
491
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
521
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
522
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
523
+	}
492 524
 
493 525
 	// Confirm mbstring is loaded...
494
-	if (!extension_loaded('mbstring'))
495
-		$incontext['error'] = $txt['install_no_mbstring'];
526
+	if (!extension_loaded('mbstring')) {
527
+			$incontext['error'] = $txt['install_no_mbstring'];
528
+	}
496 529
 
497 530
 	// Check for https stream support.
498 531
 	$supported_streams = stream_get_wrappers();
499
-	if (!in_array('https', $supported_streams))
500
-		$incontext['warning'] = $txt['install_no_https'];
532
+	if (!in_array('https', $supported_streams)) {
533
+			$incontext['warning'] = $txt['install_no_https'];
534
+	}
501 535
 
502 536
 	return false;
503 537
 }
@@ -522,12 +556,14 @@  discard block
 block discarded – undo
522 556
 		'Settings_bak.php',
523 557
 	);
524 558
 
525
-	foreach ($incontext['detected_languages'] as $lang => $temp)
526
-		$extra_files[] = 'Themes/default/languages/' . $lang;
559
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
560
+			$extra_files[] = 'Themes/default/languages/' . $lang;
561
+	}
527 562
 
528 563
 	// With mod_security installed, we could attempt to fix it with .htaccess.
529
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
530
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
564
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
565
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
566
+	}
531 567
 
532 568
 	$failed_files = array();
533 569
 
@@ -539,20 +575,23 @@  discard block
 block discarded – undo
539 575
 		foreach ($writable_files as $file)
540 576
 		{
541 577
 			// Some files won't exist, try to address up front
542
-			if (!file_exists(dirname(__FILE__) . '/' . $file))
543
-				@touch(dirname(__FILE__) . '/' . $file);
578
+			if (!file_exists(dirname(__FILE__) . '/' . $file)) {
579
+							@touch(dirname(__FILE__) . '/' . $file);
580
+			}
544 581
 			// NOW do the writable check...
545 582
 			if (!is_writable(dirname(__FILE__) . '/' . $file))
546 583
 			{
547 584
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
548 585
 
549 586
 				// Well, 755 hopefully worked... if not, try 777.
550
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
551
-					$failed_files[] = $file;
587
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
588
+									$failed_files[] = $file;
589
+				}
552 590
 			}
553 591
 		}
554
-		foreach ($extra_files as $file)
555
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
592
+		foreach ($extra_files as $file) {
593
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
594
+		}
556 595
 	}
557 596
 	// Windows is trickier.  Let's try opening for r+...
558 597
 	else
@@ -562,30 +601,35 @@  discard block
 block discarded – undo
562 601
 		foreach ($writable_files as $file)
563 602
 		{
564 603
 			// Folders can't be opened for write... but the index.php in them can ;)
565
-			if (is_dir(dirname(__FILE__) . '/' . $file))
566
-				$file .= '/index.php';
604
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
605
+							$file .= '/index.php';
606
+			}
567 607
 
568 608
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
569 609
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
570 610
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
571 611
 
572 612
 			// Hmm, okay, try just for write in that case...
573
-			if (!is_resource($fp))
574
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
613
+			if (!is_resource($fp)) {
614
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
615
+			}
575 616
 
576
-			if (!is_resource($fp))
577
-				$failed_files[] = $file;
617
+			if (!is_resource($fp)) {
618
+							$failed_files[] = $file;
619
+			}
578 620
 
579 621
 			@fclose($fp);
580 622
 		}
581
-		foreach ($extra_files as $file)
582
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
623
+		foreach ($extra_files as $file) {
624
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
625
+		}
583 626
 	}
584 627
 
585 628
 	$failure = count($failed_files) >= 1;
586 629
 
587
-	if (!isset($_SERVER))
588
-		return !$failure;
630
+	if (!isset($_SERVER)) {
631
+			return !$failure;
632
+	}
589 633
 
590 634
 	// Put the list into context.
591 635
 	$incontext['failed_files'] = $failed_files;
@@ -633,19 +677,23 @@  discard block
 block discarded – undo
633 677
 
634 678
 		if (!isset($ftp) || $ftp->error !== false)
635 679
 		{
636
-			if (!isset($ftp))
637
-				$ftp = new ftp_connection(null);
680
+			if (!isset($ftp)) {
681
+							$ftp = new ftp_connection(null);
682
+			}
638 683
 			// Save the error so we can mess with listing...
639
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
640
-				$incontext['ftp_errors'][] = $ftp->last_message;
684
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
685
+							$incontext['ftp_errors'][] = $ftp->last_message;
686
+			}
641 687
 
642 688
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
643 689
 
644
-			if (empty($_POST['ftp_path']) && $found_path)
645
-				$_POST['ftp_path'] = $detect_path;
690
+			if (empty($_POST['ftp_path']) && $found_path) {
691
+							$_POST['ftp_path'] = $detect_path;
692
+			}
646 693
 
647
-			if (!isset($_POST['ftp_username']))
648
-				$_POST['ftp_username'] = $username;
694
+			if (!isset($_POST['ftp_username'])) {
695
+							$_POST['ftp_username'] = $username;
696
+			}
649 697
 
650 698
 			// Set the username etc, into context.
651 699
 			$incontext['ftp'] = array(
@@ -657,8 +705,7 @@  discard block
 block discarded – undo
657 705
 			);
658 706
 
659 707
 			return false;
660
-		}
661
-		else
708
+		} else
662 709
 		{
663 710
 			$_SESSION['installer_temp_ftp'] = array(
664 711
 				'server' => $_POST['ftp_server'],
@@ -672,10 +719,12 @@  discard block
 block discarded – undo
672 719
 
673 720
 			foreach ($failed_files as $file)
674 721
 			{
675
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
676
-					$ftp->chmod($file, 0755);
677
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
678
-					$ftp->chmod($file, 0777);
722
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
723
+									$ftp->chmod($file, 0755);
724
+				}
725
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
726
+									$ftp->chmod($file, 0777);
727
+				}
679 728
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
680 729
 				{
681 730
 					$failed_files_updated[] = $file;
@@ -731,15 +780,17 @@  discard block
 block discarded – undo
731 780
 
732 781
 			if (!$foundOne)
733 782
 			{
734
-				if (isset($db['default_host']))
735
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
783
+				if (isset($db['default_host'])) {
784
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
785
+				}
736 786
 				if (isset($db['default_user']))
737 787
 				{
738 788
 					$incontext['db']['user'] = ini_get($db['default_user']);
739 789
 					$incontext['db']['name'] = ini_get($db['default_user']);
740 790
 				}
741
-				if (isset($db['default_password']))
742
-					$incontext['db']['pass'] = ini_get($db['default_password']);
791
+				if (isset($db['default_password'])) {
792
+									$incontext['db']['pass'] = ini_get($db['default_password']);
793
+				}
743 794
 
744 795
 				// For simplicity and less confusion, leave the port blank by default
745 796
 				$incontext['db']['port'] = '';
@@ -758,10 +809,10 @@  discard block
 block discarded – undo
758 809
 		$incontext['db']['server'] = $_POST['db_server'];
759 810
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
760 811
 
761
-		if (!empty($_POST['db_port']))
762
-			$incontext['db']['port'] = $_POST['db_port'];
763
-	}
764
-	else
812
+		if (!empty($_POST['db_port'])) {
813
+					$incontext['db']['port'] = $_POST['db_port'];
814
+		}
815
+	} else
765 816
 	{
766 817
 		$incontext['db']['prefix'] = 'smf_';
767 818
 	}
@@ -797,10 +848,11 @@  discard block
 block discarded – undo
797 848
 		if (!empty($_POST['db_port']))
798 849
 		{
799 850
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
800
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
801
-				$vars['db_port'] = (int) $_POST['db_port'];
802
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
803
-				$vars['db_port'] = (int) $_POST['db_port'];
851
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
852
+							$vars['db_port'] = (int) $_POST['db_port'];
853
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
854
+							$vars['db_port'] = (int) $_POST['db_port'];
855
+			}
804 856
 		}
805 857
 
806 858
 		// God I hope it saved!
@@ -813,8 +865,9 @@  discard block
 block discarded – undo
813 865
 		// Make sure it works.
814 866
 		require(dirname(__FILE__) . '/Settings.php');
815 867
 
816
-		if (empty($sourcedir))
817
-			$sourcedir = dirname(__FILE__) . '/Sources';
868
+		if (empty($sourcedir)) {
869
+					$sourcedir = dirname(__FILE__) . '/Sources';
870
+		}
818 871
 
819 872
 		// Better find the database file!
820 873
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -824,12 +877,14 @@  discard block
 block discarded – undo
824 877
 		}
825 878
 
826 879
 		// Now include it for database functions!
827
-		if (!defined('SMF'))
828
-			define('SMF', 1);
880
+		if (!defined('SMF')) {
881
+					define('SMF', 1);
882
+		}
829 883
 
830 884
 		$modSettings['disableQueryCheck'] = true;
831
-		if (empty($smcFunc))
832
-			$smcFunc = array();
885
+		if (empty($smcFunc)) {
886
+					$smcFunc = array();
887
+		}
833 888
 
834 889
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
835 890
 
@@ -838,11 +893,13 @@  discard block
 block discarded – undo
838 893
 
839 894
 		$options = array('non_fatal' => true, 'dont_select_db' => !$needsDB);
840 895
 		// Add in the port if needed
841
-		if (!empty($db_port))
842
-			$options['port'] = $db_port;
896
+		if (!empty($db_port)) {
897
+					$options['port'] = $db_port;
898
+		}
843 899
 		
844
-		if (!empty($db_mb4))
845
-			$options['db_mb4'] = $db_mb4;
900
+		if (!empty($db_mb4)) {
901
+					$options['db_mb4'] = $db_mb4;
902
+		}
846 903
 
847 904
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
848 905
 
@@ -928,12 +985,14 @@  discard block
 block discarded – undo
928 985
 	$incontext['page_title'] = $txt['install_settings'];
929 986
 
930 987
 	// Let's see if we got the database type correct.
931
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
932
-		$db_type = $_POST['db_type'];
988
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
989
+			$db_type = $_POST['db_type'];
990
+	}
933 991
 
934 992
 	// Else we'd better be able to get the connection.
935
-	else
936
-		load_database();
993
+	else {
994
+			load_database();
995
+	}
937 996
 
938 997
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
939 998
 
@@ -942,10 +1001,11 @@  discard block
 block discarded – undo
942 1001
 
943 1002
 		$secure = false;
944 1003
 
945
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
946
-			$secure = true;
947
-		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')
948
-			$secure = true;
1004
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
1005
+					$secure = true;
1006
+		} 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') {
1007
+					$secure = true;
1008
+		}
949 1009
 
950 1010
 	// Now, to put what we've learned together... and add a path.
951 1011
 	$incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
@@ -977,18 +1037,21 @@  discard block
 block discarded – undo
977 1037
 	// Submitting?
978 1038
 	if (isset($_POST['boardurl']))
979 1039
 	{
980
-		if (substr($_POST['boardurl'], -10) == '/index.php')
981
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
982
-		elseif (substr($_POST['boardurl'], -1) == '/')
983
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
984
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
985
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1040
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1041
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1042
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1043
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1044
+		}
1045
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1046
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1047
+		}
986 1048
 
987 1049
 		//Make sure boardurl is aligned with ssl setting
988
-		if (empty($_POST['force_ssl']))
989
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
990
-		else
991
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1050
+		if (empty($_POST['force_ssl'])) {
1051
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
1052
+		} else {
1053
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1054
+		}
992 1055
 
993 1056
 		// Save these variables.
994 1057
 		$vars = array(
@@ -1027,10 +1090,10 @@  discard block
 block discarded – undo
1027 1090
 			{
1028 1091
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
1029 1092
 				return false;
1030
-			}
1031
-			else
1032
-				// Set the character set here.
1093
+			} else {
1094
+							// Set the character set here.
1033 1095
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1096
+			}
1034 1097
 		}
1035 1098
 
1036 1099
 		// Good, skip on.
@@ -1050,8 +1113,9 @@  discard block
 block discarded – undo
1050 1113
 	$incontext['continue'] = 1;
1051 1114
 
1052 1115
 	// Already done?
1053
-	if (isset($_POST['pop_done']))
1054
-		return true;
1116
+	if (isset($_POST['pop_done'])) {
1117
+			return true;
1118
+	}
1055 1119
 
1056 1120
 	// Reload settings.
1057 1121
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1069,8 +1133,9 @@  discard block
 block discarded – undo
1069 1133
 	$modSettings = array();
1070 1134
 	if ($result !== false)
1071 1135
 	{
1072
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1073
-			$modSettings[$row['variable']] = $row['value'];
1136
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1137
+					$modSettings[$row['variable']] = $row['value'];
1138
+		}
1074 1139
 		$smcFunc['db_free_result']($result);
1075 1140
 
1076 1141
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1083,20 +1148,22 @@  discard block
 block discarded – undo
1083 1148
 	$modSettings['disableQueryCheck'] = true;
1084 1149
 
1085 1150
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1086
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1087
-		$smcFunc['db_query']('', '
1151
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1152
+			$smcFunc['db_query']('', '
1088 1153
 			SET NAMES {string:utf8}',
1089 1154
 			array(
1090 1155
 				'db_error_skip' => true,
1091 1156
 				'utf8' => 'utf8',
1092 1157
 			)
1093 1158
 		);
1159
+	}
1094 1160
 
1095 1161
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1096
-	if (substr(__DIR__, -1) == '\\')
1097
-		$attachdir = __DIR__ . 'attachments';
1098
-	else
1099
-		$attachdir = __DIR__ . '/attachments';
1162
+	if (substr(__DIR__, -1) == '\\') {
1163
+			$attachdir = __DIR__ . 'attachments';
1164
+	} else {
1165
+			$attachdir = __DIR__ . '/attachments';
1166
+	}
1100 1167
 
1101 1168
 	$replaces = array(
1102 1169
 		'{$db_prefix}' => $db_prefix,
@@ -1113,8 +1180,9 @@  discard block
 block discarded – undo
1113 1180
 
1114 1181
 	foreach ($txt as $key => $value)
1115 1182
 	{
1116
-		if (substr($key, 0, 8) == 'default_')
1117
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1183
+		if (substr($key, 0, 8) == 'default_') {
1184
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1185
+		}
1118 1186
 	}
1119 1187
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1120 1188
 
@@ -1129,8 +1197,9 @@  discard block
 block discarded – undo
1129 1197
 
1130 1198
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1131 1199
 		{
1132
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1133
-				$engines[] = $row['Engine'];
1200
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1201
+							$engines[] = $row['Engine'];
1202
+			}
1134 1203
 		}
1135 1204
 
1136 1205
 		// Done with this now
@@ -1154,8 +1223,7 @@  discard block
 block discarded – undo
1154 1223
 			$replaces['START TRANSACTION;'] = '';
1155 1224
 			$replaces['COMMIT;'] = '';
1156 1225
 		}
1157
-	}
1158
-	else
1226
+	} else
1159 1227
 	{
1160 1228
 		$has_innodb = false;
1161 1229
 	}
@@ -1177,21 +1245,24 @@  discard block
 block discarded – undo
1177 1245
 	foreach ($sql_lines as $count => $line)
1178 1246
 	{
1179 1247
 		// No comments allowed!
1180
-		if (substr(trim($line), 0, 1) != '#')
1181
-			$current_statement .= "\n" . rtrim($line);
1248
+		if (substr(trim($line), 0, 1) != '#') {
1249
+					$current_statement .= "\n" . rtrim($line);
1250
+		}
1182 1251
 
1183 1252
 		// Is this the end of the query string?
1184
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1185
-			continue;
1253
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1254
+					continue;
1255
+		}
1186 1256
 
1187 1257
 		// Does this table already exist?  If so, don't insert more data into it!
1188 1258
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1189 1259
 		{
1190 1260
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1191
-			if (!empty($matches[0]))
1192
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1193
-			else
1194
-				$incontext['sql_results']['insert_dups']++;
1261
+			if (!empty($matches[0])) {
1262
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1263
+			} else {
1264
+							$incontext['sql_results']['insert_dups']++;
1265
+			}
1195 1266
 
1196 1267
 			$current_statement = '';
1197 1268
 			continue;
@@ -1200,8 +1271,9 @@  discard block
 block discarded – undo
1200 1271
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1201 1272
 		{
1202 1273
 			// Use the appropriate function based on the DB type
1203
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1204
-				$db_errorno = $db_type . '_errno';
1274
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1275
+							$db_errorno = $db_type . '_errno';
1276
+			}
1205 1277
 
1206 1278
 			// Error 1050: Table already exists!
1207 1279
 			// @todo Needs to be made better!
@@ -1216,18 +1288,18 @@  discard block
 block discarded – undo
1216 1288
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1217 1289
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1218 1290
 			}
1219
-		}
1220
-		else
1291
+		} else
1221 1292
 		{
1222
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1223
-				$incontext['sql_results']['tables']++;
1224
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1293
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1294
+							$incontext['sql_results']['tables']++;
1295
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1225 1296
 			{
1226 1297
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1227
-				if (!empty($matches[0]))
1228
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1229
-				else
1230
-					$incontext['sql_results']['inserts']++;
1298
+				if (!empty($matches[0])) {
1299
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1300
+				} else {
1301
+									$incontext['sql_results']['inserts']++;
1302
+				}
1231 1303
 			}
1232 1304
 		}
1233 1305
 
@@ -1240,15 +1312,17 @@  discard block
 block discarded – undo
1240 1312
 	// Sort out the context for the SQL.
1241 1313
 	foreach ($incontext['sql_results'] as $key => $number)
1242 1314
 	{
1243
-		if ($number == 0)
1244
-			unset($incontext['sql_results'][$key]);
1245
-		else
1246
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1315
+		if ($number == 0) {
1316
+					unset($incontext['sql_results'][$key]);
1317
+		} else {
1318
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1319
+		}
1247 1320
 	}
1248 1321
 
1249 1322
 	// Make sure UTF will be used globally.
1250
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1251
-		$newSettings[] = array('global_character_set', 'UTF-8');
1323
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1324
+			$newSettings[] = array('global_character_set', 'UTF-8');
1325
+	}
1252 1326
 
1253 1327
 	// Auto-detect local & global cookie settings
1254 1328
 	$url_parts = parse_url($boardurl);
@@ -1277,15 +1351,19 @@  discard block
 block discarded – undo
1277 1351
 
1278 1352
 		// Look for subfolder, if found, set localCookie
1279 1353
 		// Checking for len > 1 ensures you don't have just a slash...
1280
-		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1)
1281
-			$localCookies = '1';
1354
+		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) {
1355
+					$localCookies = '1';
1356
+		}
1282 1357
 
1283
-		if (isset($globalCookies))
1284
-			$newSettings[] = array('globalCookies', $globalCookies);
1285
-		if (isset($globalCookiesDomain))
1286
-			$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1287
-		if (isset($localCookies))
1288
-			$newSettings[] = array('localCookies', $localCookies);
1358
+		if (isset($globalCookies)) {
1359
+					$newSettings[] = array('globalCookies', $globalCookies);
1360
+		}
1361
+		if (isset($globalCookiesDomain)) {
1362
+					$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1363
+		}
1364
+		if (isset($localCookies)) {
1365
+					$newSettings[] = array('localCookies', $localCookies);
1366
+		}
1289 1367
 	}
1290 1368
 
1291 1369
 	// Are we allowing stat collection?
@@ -1303,16 +1381,17 @@  discard block
 block discarded – undo
1303 1381
 			fwrite($fp, $out);
1304 1382
 
1305 1383
 			$return_data = '';
1306
-			while (!feof($fp))
1307
-				$return_data .= fgets($fp, 128);
1384
+			while (!feof($fp)) {
1385
+							$return_data .= fgets($fp, 128);
1386
+			}
1308 1387
 
1309 1388
 			fclose($fp);
1310 1389
 
1311 1390
 			// Get the unique site ID.
1312 1391
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1313 1392
 
1314
-			if (!empty($ID[1]))
1315
-				$smcFunc['db_insert']('replace',
1393
+			if (!empty($ID[1])) {
1394
+							$smcFunc['db_insert']('replace',
1316 1395
 					$db_prefix . 'settings',
1317 1396
 					array('variable' => 'string', 'value' => 'string'),
1318 1397
 					array(
@@ -1321,11 +1400,12 @@  discard block
 block discarded – undo
1321 1400
 					),
1322 1401
 					array('variable')
1323 1402
 				);
1403
+			}
1324 1404
 		}
1325 1405
 	}
1326 1406
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1327
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1328
-		$smcFunc['db_query']('', '
1407
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1408
+			$smcFunc['db_query']('', '
1329 1409
 			DELETE FROM {db_prefix}settings
1330 1410
 			WHERE variable = {string:enable_sm_stats}',
1331 1411
 			array(
@@ -1333,20 +1413,23 @@  discard block
 block discarded – undo
1333 1413
 				'db_error_skip' => true,
1334 1414
 			)
1335 1415
 		);
1416
+	}
1336 1417
 
1337 1418
 	// Are we enabling SSL?
1338
-	if (!empty($_POST['force_ssl']))
1339
-		$newSettings[] = array('force_ssl', 1);
1419
+	if (!empty($_POST['force_ssl'])) {
1420
+			$newSettings[] = array('force_ssl', 1);
1421
+	}
1340 1422
 
1341 1423
 	// Setting a timezone is required.
1342 1424
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1343 1425
 	{
1344 1426
 		// Get PHP's default timezone, if set
1345 1427
 		$ini_tz = ini_get('date.timezone');
1346
-		if (!empty($ini_tz))
1347
-			$timezone_id = $ini_tz;
1348
-		else
1349
-			$timezone_id = '';
1428
+		if (!empty($ini_tz)) {
1429
+					$timezone_id = $ini_tz;
1430
+		} else {
1431
+					$timezone_id = '';
1432
+		}
1350 1433
 
1351 1434
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1352 1435
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1355,8 +1438,9 @@  discard block
 block discarded – undo
1355 1438
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1356 1439
 		}
1357 1440
 
1358
-		if (date_default_timezone_set($timezone_id))
1359
-			$newSettings[] = array('default_timezone', $timezone_id);
1441
+		if (date_default_timezone_set($timezone_id)) {
1442
+					$newSettings[] = array('default_timezone', $timezone_id);
1443
+		}
1360 1444
 	}
1361 1445
 
1362 1446
 	if (!empty($newSettings))
@@ -1387,16 +1471,18 @@  discard block
 block discarded – undo
1387 1471
 	}
1388 1472
 
1389 1473
 	// MySQL specific stuff
1390
-	if (substr($db_type, 0, 5) != 'mysql')
1391
-		return false;
1474
+	if (substr($db_type, 0, 5) != 'mysql') {
1475
+			return false;
1476
+	}
1392 1477
 
1393 1478
 	// Find database user privileges.
1394 1479
 	$privs = array();
1395 1480
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1396 1481
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1397 1482
 	{
1398
-		if ($row['Privilege'] == 'Alter')
1399
-			$privs[] = $row['Privilege'];
1483
+		if ($row['Privilege'] == 'Alter') {
1484
+					$privs[] = $row['Privilege'];
1485
+		}
1400 1486
 	}
1401 1487
 	$smcFunc['db_free_result']($get_privs);
1402 1488
 
@@ -1426,8 +1512,9 @@  discard block
 block discarded – undo
1426 1512
 	$incontext['continue'] = 1;
1427 1513
 
1428 1514
 	// Skipping?
1429
-	if (!empty($_POST['skip']))
1430
-		return true;
1515
+	if (!empty($_POST['skip'])) {
1516
+			return true;
1517
+	}
1431 1518
 
1432 1519
 	// Need this to check whether we need the database password.
1433 1520
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1444,18 +1531,22 @@  discard block
 block discarded – undo
1444 1531
 	// We need this to properly hash the password for Admin
1445 1532
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1446 1533
 			global $sourcedir;
1447
-			if (function_exists('mb_strtolower'))
1448
-				return mb_strtolower($string, 'UTF-8');
1534
+			if (function_exists('mb_strtolower')) {
1535
+							return mb_strtolower($string, 'UTF-8');
1536
+			}
1449 1537
 			require_once($sourcedir . '/Subs-Charset.php');
1450 1538
 			return utf8_strtolower($string);
1451 1539
 		};
1452 1540
 
1453
-	if (!isset($_POST['username']))
1454
-		$_POST['username'] = '';
1455
-	if (!isset($_POST['email']))
1456
-		$_POST['email'] = '';
1457
-	if (!isset($_POST['server_email']))
1458
-		$_POST['server_email'] = '';
1541
+	if (!isset($_POST['username'])) {
1542
+			$_POST['username'] = '';
1543
+	}
1544
+	if (!isset($_POST['email'])) {
1545
+			$_POST['email'] = '';
1546
+	}
1547
+	if (!isset($_POST['server_email'])) {
1548
+			$_POST['server_email'] = '';
1549
+	}
1459 1550
 
1460 1551
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1461 1552
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1474,8 +1565,9 @@  discard block
 block discarded – undo
1474 1565
 			'admin_group' => 1,
1475 1566
 		)
1476 1567
 	);
1477
-	if ($smcFunc['db_num_rows']($request) != 0)
1478
-		$incontext['skip'] = 1;
1568
+	if ($smcFunc['db_num_rows']($request) != 0) {
1569
+			$incontext['skip'] = 1;
1570
+	}
1479 1571
 	$smcFunc['db_free_result']($request);
1480 1572
 
1481 1573
 	// Trying to create an account?
@@ -1506,8 +1598,9 @@  discard block
 block discarded – undo
1506 1598
 		}
1507 1599
 
1508 1600
 		// Update the webmaster's email?
1509
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1510
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1601
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1602
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1603
+		}
1511 1604
 
1512 1605
 		// Work out whether we're going to have dodgy characters and remove them.
1513 1606
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1530,32 +1623,27 @@  discard block
 block discarded – undo
1530 1623
 			$smcFunc['db_free_result']($result);
1531 1624
 
1532 1625
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1533
-		}
1534
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1626
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1535 1627
 		{
1536 1628
 			// Try the previous step again.
1537 1629
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1538 1630
 			return false;
1539
-		}
1540
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1631
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1541 1632
 		{
1542 1633
 			// Try the previous step again.
1543 1634
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1544 1635
 			return false;
1545
-		}
1546
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1636
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1547 1637
 		{
1548 1638
 			// One step back, this time fill out a proper admin email address.
1549 1639
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1550 1640
 			return false;
1551
-		}
1552
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1641
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1553 1642
 		{
1554 1643
 			// One step back, this time fill out a proper admin email address.
1555 1644
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1556 1645
 			return false;
1557
-		}
1558
-		elseif ($_POST['username'] != '')
1646
+		} elseif ($_POST['username'] != '')
1559 1647
 		{
1560 1648
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1561 1649
 
@@ -1623,17 +1711,19 @@  discard block
 block discarded – undo
1623 1711
 	reloadSettings();
1624 1712
 
1625 1713
 	// Bring a warning over.
1626
-	if (!empty($incontext['account_existed']))
1627
-		$incontext['warning'] = $incontext['account_existed'];
1714
+	if (!empty($incontext['account_existed'])) {
1715
+			$incontext['warning'] = $incontext['account_existed'];
1716
+	}
1628 1717
 
1629
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1630
-		$smcFunc['db_query']('', '
1718
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1719
+			$smcFunc['db_query']('', '
1631 1720
 			SET NAMES {string:db_character_set}',
1632 1721
 			array(
1633 1722
 				'db_character_set' => $db_character_set,
1634 1723
 				'db_error_skip' => true,
1635 1724
 			)
1636 1725
 		);
1726
+	}
1637 1727
 
1638 1728
 	// As track stats is by default enabled let's add some activity.
1639 1729
 	$smcFunc['db_insert']('ignore',
@@ -1654,14 +1744,16 @@  discard block
 block discarded – undo
1654 1744
 	// Only proceed if we can load the data.
1655 1745
 	if ($request)
1656 1746
 	{
1657
-		while ($row = $smcFunc['db_fetch_row']($request))
1658
-			$modSettings[$row[0]] = $row[1];
1747
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1748
+					$modSettings[$row[0]] = $row[1];
1749
+		}
1659 1750
 		$smcFunc['db_free_result']($request);
1660 1751
 	}
1661 1752
 
1662 1753
 	// Automatically log them in ;)
1663
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1664
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1754
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1755
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1756
+	}
1665 1757
 
1666 1758
 	$result = $smcFunc['db_query']('', '
1667 1759
 		SELECT value
@@ -1672,13 +1764,14 @@  discard block
 block discarded – undo
1672 1764
 			'db_error_skip' => true,
1673 1765
 		)
1674 1766
 	);
1675
-	if ($smcFunc['db_num_rows']($result) != 0)
1676
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1767
+	if ($smcFunc['db_num_rows']($result) != 0) {
1768
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1769
+	}
1677 1770
 	$smcFunc['db_free_result']($result);
1678 1771
 
1679
-	if (empty($db_sessions))
1680
-		$_SESSION['admin_time'] = time();
1681
-	else
1772
+	if (empty($db_sessions)) {
1773
+			$_SESSION['admin_time'] = time();
1774
+	} else
1682 1775
 	{
1683 1776
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1684 1777
 
@@ -1702,8 +1795,9 @@  discard block
 block discarded – undo
1702 1795
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1703 1796
 		function($string){
1704 1797
 			global $sourcedir;
1705
-			if (function_exists('mb_strtolower'))
1706
-				return mb_strtolower($string, 'UTF-8');
1798
+			if (function_exists('mb_strtolower')) {
1799
+							return mb_strtolower($string, 'UTF-8');
1800
+			}
1707 1801
 			require_once($sourcedir . '/Subs-Charset.php');
1708 1802
 			return utf8_strtolower($string);
1709 1803
 		};
@@ -1719,8 +1813,9 @@  discard block
 block discarded – undo
1719 1813
 		)
1720 1814
 	);
1721 1815
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1722
-	if ($smcFunc['db_num_rows']($request) > 0)
1723
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1816
+	if ($smcFunc['db_num_rows']($request) > 0) {
1817
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1818
+	}
1724 1819
 	$smcFunc['db_free_result']($request);
1725 1820
 
1726 1821
 	// Now is the perfect time to fetch the SM files.
@@ -1739,8 +1834,9 @@  discard block
 block discarded – undo
1739 1834
 
1740 1835
 	// Check if we need some stupid MySQL fix.
1741 1836
 	$server_version = $smcFunc['db_server_info']();
1742
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1743
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1837
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1838
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1839
+	}
1744 1840
 
1745 1841
 	// Some final context for the template.
1746 1842
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1760,8 +1856,9 @@  discard block
 block discarded – undo
1760 1856
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1761 1857
 
1762 1858
 	// @todo Do we just want to read the file in clean, and split it this way always?
1763
-	if (count($settingsArray) == 1)
1764
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1859
+	if (count($settingsArray) == 1) {
1860
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1861
+	}
1765 1862
 
1766 1863
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1767 1864
 	{
@@ -1769,25 +1866,29 @@  discard block
 block discarded – undo
1769 1866
 		if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}')
1770 1867
 		{
1771 1868
 			// Set the ten lines to nothing.
1772
-			for ($j=0; $j < 10; $j++)
1773
-				$settingsArray[$i++] = '';
1869
+			for ($j=0; $j < 10; $j++) {
1870
+							$settingsArray[$i++] = '';
1871
+			}
1774 1872
 
1775 1873
 			continue;
1776 1874
 		}
1777 1875
 
1778
-		if (trim($settingsArray[$i]) == '?' . '>')
1779
-			$settingsArray[$i] = '';
1876
+		if (trim($settingsArray[$i]) == '?' . '>') {
1877
+					$settingsArray[$i] = '';
1878
+		}
1780 1879
 
1781 1880
 		// Don't trim or bother with it if it's not a variable.
1782
-		if (substr($settingsArray[$i], 0, 1) != '$')
1783
-			continue;
1881
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1882
+					continue;
1883
+		}
1784 1884
 
1785 1885
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1786 1886
 
1787
-		foreach ($vars as $var => $val)
1788
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1887
+		foreach ($vars as $var => $val) {
1888
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1789 1889
 			{
1790 1890
 				$comment = strstr($settingsArray[$i], '#');
1891
+		}
1791 1892
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1792 1893
 				unset($vars[$var]);
1793 1894
 			}
@@ -1797,36 +1898,41 @@  discard block
 block discarded – undo
1797 1898
 	if (!empty($vars))
1798 1899
 	{
1799 1900
 		$settingsArray[$i++] = '';
1800
-		foreach ($vars as $var => $val)
1801
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1901
+		foreach ($vars as $var => $val) {
1902
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1903
+		}
1802 1904
 	}
1803 1905
 
1804 1906
 	// Blank out the file - done to fix a oddity with some servers.
1805 1907
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1806
-	if (!$fp)
1807
-		return false;
1908
+	if (!$fp) {
1909
+			return false;
1910
+	}
1808 1911
 	fclose($fp);
1809 1912
 
1810 1913
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1811 1914
 
1812 1915
 	// Gotta have one of these ;)
1813
-	if (trim($settingsArray[0]) != '<?php')
1814
-		fwrite($fp, "<?php\n");
1916
+	if (trim($settingsArray[0]) != '<?php') {
1917
+			fwrite($fp, "<?php\n");
1918
+	}
1815 1919
 
1816 1920
 	$lines = count($settingsArray);
1817 1921
 	for ($i = 0; $i < $lines - 1; $i++)
1818 1922
 	{
1819 1923
 		// Don't just write a bunch of blank lines.
1820
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1821
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1924
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1925
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1926
+		}
1822 1927
 	}
1823 1928
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1824 1929
 	fclose($fp);
1825 1930
 
1826 1931
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1827 1932
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1828
-	if (function_exists('opcache_invalidate'))
1829
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1933
+	if (function_exists('opcache_invalidate')) {
1934
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1935
+	}
1830 1936
 
1831 1937
 	return true;
1832 1938
 }
@@ -1836,10 +1942,11 @@  discard block
 block discarded – undo
1836 1942
 	global $cachedir;
1837 1943
 
1838 1944
 	// Write out the db_last_error file with the error timestamp
1839
-	if (!empty($cachedir) && is_writable($cachedir))
1840
-		file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1841
-	else
1842
-		file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1945
+	if (!empty($cachedir) && is_writable($cachedir)) {
1946
+			file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1947
+	} else {
1948
+			file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1949
+	}
1843 1950
 
1844 1951
 	return true;
1845 1952
 }
@@ -1856,9 +1963,9 @@  discard block
 block discarded – undo
1856 1963
 	SecFilterScanPOST Off
1857 1964
 </IfModule>';
1858 1965
 
1859
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1860
-		return true;
1861
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1966
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1967
+			return true;
1968
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1862 1969
 	{
1863 1970
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1864 1971
 
@@ -1870,29 +1977,28 @@  discard block
 block discarded – undo
1870 1977
 				fwrite($ht_handle, $htaccess_addition);
1871 1978
 				fclose($ht_handle);
1872 1979
 				return true;
1980
+			} else {
1981
+							return false;
1873 1982
 			}
1874
-			else
1875
-				return false;
1983
+		} else {
1984
+					return true;
1876 1985
 		}
1877
-		else
1878
-			return true;
1879
-	}
1880
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1881
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1882
-	elseif (is_writable(dirname(__FILE__)))
1986
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1987
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1988
+	} elseif (is_writable(dirname(__FILE__)))
1883 1989
 	{
1884 1990
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1885 1991
 		{
1886 1992
 			fwrite($ht_handle, $htaccess_addition);
1887 1993
 			fclose($ht_handle);
1888 1994
 			return true;
1995
+		} else {
1996
+					return false;
1889 1997
 		}
1890
-		else
1998
+	} else {
1891 1999
 			return false;
1892 2000
 	}
1893
-	else
1894
-		return false;
1895
-}
2001
+	}
1896 2002
 
1897 2003
 function template_install_above()
1898 2004
 {
@@ -1931,9 +2037,10 @@  discard block
 block discarded – undo
1931 2037
 							<label for="installer_language">', $txt['installer_language'], ':</label>
1932 2038
 							<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1933 2039
 
1934
-		foreach ($incontext['detected_languages'] as $lang => $name)
1935
-			echo '
2040
+		foreach ($incontext['detected_languages'] as $lang => $name) {
2041
+					echo '
1936 2042
 								<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
2043
+		}
1937 2044
 
1938 2045
 		echo '
1939 2046
 							</select>
@@ -1953,9 +2060,10 @@  discard block
 block discarded – undo
1953 2060
 					<h2>', $txt['upgrade_progress'], '</h2>
1954 2061
 					<ul>';
1955 2062
 
1956
-	foreach ($incontext['steps'] as $num => $step)
1957
-		echo '
2063
+	foreach ($incontext['steps'] as $num => $step) {
2064
+			echo '
1958 2065
 						<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
2066
+	}
1959 2067
 
1960 2068
 	echo '
1961 2069
 					</ul>
@@ -1981,20 +2089,23 @@  discard block
 block discarded – undo
1981 2089
 		echo '
1982 2090
 							<div class="floatright">';
1983 2091
 
1984
-		if (!empty($incontext['continue']))
1985
-			echo '
2092
+		if (!empty($incontext['continue'])) {
2093
+					echo '
1986 2094
 								<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button">';
1987
-		if (!empty($incontext['skip']))
1988
-			echo '
2095
+		}
2096
+		if (!empty($incontext['skip'])) {
2097
+					echo '
1989 2098
 								<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button">';
2099
+		}
1990 2100
 		echo '
1991 2101
 							</div>';
1992 2102
 	}
1993 2103
 
1994 2104
 	// Show the closing form tag and other data only if not in the last step
1995
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1996
-		echo '
2105
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2106
+			echo '
1997 2107
 						</form>';
2108
+	}
1998 2109
 
1999 2110
 	echo '
2000 2111
 					</div><!-- .panel -->
@@ -2027,13 +2138,15 @@  discard block
 block discarded – undo
2027 2138
 		</div>';
2028 2139
 
2029 2140
 	// Show the warnings, or not.
2030
-	if (template_warning_divs())
2031
-		echo '
2141
+	if (template_warning_divs()) {
2142
+			echo '
2032 2143
 		<h3>', $txt['install_all_lovely'], '</h3>';
2144
+	}
2033 2145
 
2034 2146
 	// Say we want the continue button!
2035
-	if (empty($incontext['error']))
2036
-		$incontext['continue'] = 1;
2147
+	if (empty($incontext['error'])) {
2148
+			$incontext['continue'] = 1;
2149
+	}
2037 2150
 
2038 2151
 	// For the latest version stuff.
2039 2152
 	echo '
@@ -2067,19 +2180,21 @@  discard block
 block discarded – undo
2067 2180
 	global $txt, $incontext;
2068 2181
 
2069 2182
 	// Errors are very serious..
2070
-	if (!empty($incontext['error']))
2071
-		echo '
2183
+	if (!empty($incontext['error'])) {
2184
+			echo '
2072 2185
 		<div class="errorbox">
2073 2186
 			<h3>', $txt['upgrade_critical_error'], '</h3>
2074 2187
 			', $incontext['error'], '
2075 2188
 		</div>';
2189
+	}
2076 2190
 	// A warning message?
2077
-	elseif (!empty($incontext['warning']))
2078
-		echo '
2191
+	elseif (!empty($incontext['warning'])) {
2192
+			echo '
2079 2193
 		<div class="errorbox">
2080 2194
 			<h3>', $txt['upgrade_warning'], '</h3>
2081 2195
 			', $incontext['warning'], '
2082 2196
 		</div>';
2197
+	}
2083 2198
 
2084 2199
 	return empty($incontext['error']) && empty($incontext['warning']);
2085 2200
 }
@@ -2095,26 +2210,29 @@  discard block
 block discarded – undo
2095 2210
 			<li>', $incontext['failed_files']), '</li>
2096 2211
 		</ul>';
2097 2212
 
2098
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2099
-		echo '
2213
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2214
+			echo '
2100 2215
 		<hr>
2101 2216
 		<p>', $txt['chmod_linux_info'], '</p>
2102 2217
 		<samp># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</samp>';
2218
+	}
2103 2219
 
2104 2220
 	// This is serious!
2105
-	if (!template_warning_divs())
2106
-		return;
2221
+	if (!template_warning_divs()) {
2222
+			return;
2223
+	}
2107 2224
 
2108 2225
 	echo '
2109 2226
 		<hr>
2110 2227
 		<p>', $txt['ftp_setup_info'], '</p>';
2111 2228
 
2112
-	if (!empty($incontext['ftp_errors']))
2113
-		echo '
2229
+	if (!empty($incontext['ftp_errors'])) {
2230
+			echo '
2114 2231
 		<div class="error_message">
2115 2232
 			', $txt['error_ftp_no_connect'], '<br><br>
2116 2233
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2117 2234
 		</div>';
2235
+	}
2118 2236
 
2119 2237
 	echo '
2120 2238
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2183,16 +2301,16 @@  discard block
 block discarded – undo
2183 2301
 			<dd>
2184 2302
 				<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2185 2303
 
2186
-	foreach ($incontext['supported_databases'] as $key => $db)
2187
-			echo '
2304
+	foreach ($incontext['supported_databases'] as $key => $db) {
2305
+				echo '
2188 2306
 					<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2307
+	}
2189 2308
 
2190 2309
 	echo '
2191 2310
 				</select>
2192 2311
 				<div class="smalltext">', $txt['db_settings_type_info'], '</div>
2193 2312
 			</dd>';
2194
-	}
2195
-	else
2313
+	} else
2196 2314
 	{
2197 2315
 		echo '
2198 2316
 			<dd>
@@ -2360,9 +2478,10 @@  discard block
 block discarded – undo
2360 2478
 		<div class="red">', $txt['error_db_queries'], '</div>
2361 2479
 		<ul>';
2362 2480
 
2363
-		foreach ($incontext['failures'] as $line => $fail)
2364
-			echo '
2481
+		foreach ($incontext['failures'] as $line => $fail) {
2482
+					echo '
2365 2483
 			<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2484
+		}
2366 2485
 
2367 2486
 		echo '
2368 2487
 		</ul>';
@@ -2427,15 +2546,16 @@  discard block
 block discarded – undo
2427 2546
 			</dd>
2428 2547
 		</dl>';
2429 2548
 
2430
-	if ($incontext['require_db_confirm'])
2431
-		echo '
2549
+	if ($incontext['require_db_confirm']) {
2550
+			echo '
2432 2551
 		<h2>', $txt['user_settings_database'], '</h2>
2433 2552
 		<p>', $txt['user_settings_database_info'], '</p>
2434 2553
 
2435 2554
 		<div class="lefttext">
2436 2555
 			<input type="password" name="password3" size="30">
2437 2556
 		</div>';
2438
-}
2557
+	}
2558
+	}
2439 2559
 
2440 2560
 // Tell them it's done, and to delete.
2441 2561
 function template_delete_install()
@@ -2448,13 +2568,14 @@  discard block
 block discarded – undo
2448 2568
 	template_warning_divs();
2449 2569
 
2450 2570
 	// Install directory still writable?
2451
-	if ($incontext['dir_still_writable'])
2452
-		echo '
2571
+	if ($incontext['dir_still_writable']) {
2572
+			echo '
2453 2573
 		<p><em>', $txt['still_writable'], '</em></p>';
2574
+	}
2454 2575
 
2455 2576
 	// Don't show the box if it's like 99% sure it won't work :P.
2456
-	if ($incontext['probably_delete_install'])
2457
-		echo '
2577
+	if ($incontext['probably_delete_install']) {
2578
+			echo '
2458 2579
 		<label>
2459 2580
 			<input type="checkbox" id="delete_self" onclick="doTheDelete();">
2460 2581
 			<strong>', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</strong>
@@ -2470,6 +2591,7 @@  discard block
 block discarded – undo
2470 2591
 				theCheck.disabled = true;
2471 2592
 			}
2472 2593
 		</script>';
2594
+	}
2473 2595
 
2474 2596
 	echo '
2475 2597
 		<p>', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '</p>
Please login to merge, or discard this patch.