Completed
Pull Request — release-2.1 (#3761)
by Rick
14:55 queued 08:11
created
Sources/ReportedContent.php 1 patch
Braces   +61 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Sets and call a function based on the given subaction. Acts as a dispatcher function.
@@ -54,8 +55,9 @@  discard block
 block discarded – undo
54 55
 	);
55 56
 
56 57
 	// This comes under the umbrella of moderating posts.
57
-	if ($context['report_type'] == 'members' || $user_info['mod_cache']['bq'] == '0=1')
58
-		isAllowedTo('moderate_forum');
58
+	if ($context['report_type'] == 'members' || $user_info['mod_cache']['bq'] == '0=1') {
59
+			isAllowedTo('moderate_forum');
60
+	}
59 61
 
60 62
 	$subActions = array(
61 63
 		'show' => 'ShowReports',
@@ -70,11 +72,11 @@  discard block
 block discarded – undo
70 72
 	call_integration_hook('integrate_reported_' . $context['report_type'], array(&$subActions));
71 73
 
72 74
 	// By default we call the open sub-action.
73
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
74
-		$context['sub_action'] = $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_REQUEST['sa']), ENT_QUOTES);
75
-
76
-	else
77
-		$context['sub_action'] = 'show';
75
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
76
+			$context['sub_action'] = $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_REQUEST['sa']), ENT_QUOTES);
77
+	} else {
78
+			$context['sub_action'] = 'show';
79
+	}
78 80
 
79 81
 	// Hi Ho Silver Away!
80 82
 	call_helper($subActions[$context['sub_action']]);
@@ -116,11 +118,13 @@  discard block
 block discarded – undo
116 118
 
117 119
 		// All the ones to update...
118 120
 		$toClose = array();
119
-		foreach ($_POST['close'] as $rid)
120
-			$toClose[] = (int) $rid;
121
+		foreach ($_POST['close'] as $rid) {
122
+					$toClose[] = (int) $rid;
123
+		}
121 124
 
122
-		if (!empty($toClose))
123
-			updateReport('closed', 1, $toClose);
125
+		if (!empty($toClose)) {
126
+					updateReport('closed', 1, $toClose);
127
+		}
124 128
 
125 129
 		// Set the confirmation message.
126 130
 		$_SESSION['rc_confirmation'] = 'close_all';
@@ -178,8 +182,9 @@  discard block
 block discarded – undo
178 182
 	$reportComments = array();
179 183
 
180 184
 	// Have to at least give us something to work with.
181
-	if (empty($_REQUEST['rid']))
182
-		fatal_lang_error('mc_reportedp_none_found');
185
+	if (empty($_REQUEST['rid'])) {
186
+			fatal_lang_error('mc_reportedp_none_found');
187
+	}
183 188
 
184 189
 	// Integers only please
185 190
 	$report_id = (int) $_REQUEST['rid'];
@@ -187,8 +192,9 @@  discard block
 block discarded – undo
187 192
 	// Get the report details.
188 193
 	$report = getReportDetails($report_id);
189 194
 
190
-	if (!$report)
191
-		fatal_lang_error('mc_no_modreport_found');
195
+	if (!$report) {
196
+			fatal_lang_error('mc_no_modreport_found');
197
+	}
192 198
 
193 199
 	// Build the report data - basic details first, then extra stuff based on the type
194 200
 	$context['report'] = array(
@@ -214,8 +220,7 @@  discard block
 block discarded – undo
214 220
 				'href' => $scripturl . '?action=profile;u=' . $report['id_user'],
215 221
 			),
216 222
 		);
217
-	}
218
-	else
223
+	} else
219 224
 	{
220 225
 		$extraDetails = array(
221 226
 			'topic_id' => $report['id_topic'],
@@ -238,8 +243,9 @@  discard block
 block discarded – undo
238 243
 
239 244
 	$reportComments = getReportComments($report_id);
240 245
 
241
-	if (!empty($reportComments))
242
-		$context['report'] = array_merge($context['report'], $reportComments);
246
+	if (!empty($reportComments)) {
247
+			$context['report'] = array_merge($context['report'], $reportComments);
248
+	}
243 249
 
244 250
 	// What have the other moderators done to this message?
245 251
 	require_once($sourcedir . '/Modlog.php');
@@ -260,8 +266,7 @@  discard block
 block discarded – undo
260 266
 			1,
261 267
 			true,
262 268
 		);
263
-	}
264
-	else
269
+	} else
265 270
 	{
266 271
 		$params = array(
267 272
 			'lm.id_topic = {int:id_topic}
@@ -361,16 +366,16 @@  discard block
 block discarded – undo
361 366
 	createList($listOptions);
362 367
 
363 368
 	// Make sure to get the correct tab selected.
364
-	if ($context['report']['closed'])
365
-		$context[$context['moderation_menu_name']]['current_subsection'] = 'closed';
369
+	if ($context['report']['closed']) {
370
+			$context[$context['moderation_menu_name']]['current_subsection'] = 'closed';
371
+	}
366 372
 
367 373
 	// Finally we are done :P
368 374
 	if ($context['report_type'] == 'members')
369 375
 	{
370 376
 		$context['page_title'] = sprintf($txt['mc_viewmemberreport'], $context['report']['user']['name']);
371 377
 		$context['sub_template'] = 'viewmemberreport';
372
-	}
373
-	else
378
+	} else
374 379
 	{
375 380
 		$context['page_title'] = sprintf($txt['mc_viewmodreport'], $context['report']['subject'], $context['report']['author']['name']);
376 381
 		$context['sub_template'] = 'viewmodreport';
@@ -395,8 +400,9 @@  discard block
 block discarded – undo
395 400
 	$comment = array();
396 401
 
397 402
 	// The report ID is a must.
398
-	if (empty($_REQUEST['rid']))
399
-		fatal_lang_error('mc_reportedp_none_found');
403
+	if (empty($_REQUEST['rid'])) {
404
+			fatal_lang_error('mc_reportedp_none_found');
405
+	}
400 406
 
401 407
 	// Integers only please.
402 408
 	$report_id = (int) $_REQUEST['rid'];
@@ -421,8 +427,9 @@  discard block
 block discarded – undo
421 427
 		checkSession('get');
422 428
 		validateToken('mod-reportC-delete', 'get');
423 429
 
424
-		if (empty($_REQUEST['mid']))
425
-			fatal_lang_error('mc_reportedp_comment_none_found');
430
+		if (empty($_REQUEST['mid'])) {
431
+					fatal_lang_error('mc_reportedp_comment_none_found');
432
+		}
426 433
 
427 434
 		$comment_id = (int) $_REQUEST['mid'];
428 435
 
@@ -430,15 +437,17 @@  discard block
 block discarded – undo
430 437
 		$comment = getCommentModDetails($comment_id);
431 438
 
432 439
 		// Perhaps somebody else already deleted this fine gem...
433
-		if (empty($comment))
434
-			fatal_lang_error('report_action_message_delete_issue');
440
+		if (empty($comment)) {
441
+					fatal_lang_error('report_action_message_delete_issue');
442
+		}
435 443
 
436 444
 		// Can you actually do this?
437 445
 		$comment_owner = $user_info['id'] == $comment['id_member'];
438 446
 
439 447
 		// Nope! sorry.
440
-		if (!allowedTo('admin_forum') && !$comment_owner)
441
-			fatal_lang_error('report_action_message_delete_cannot');
448
+		if (!allowedTo('admin_forum') && !$comment_owner) {
449
+					fatal_lang_error('report_action_message_delete_cannot');
450
+		}
442 451
 
443 452
 		// All good!
444 453
 		deleteModComment($comment_id);
@@ -465,11 +474,13 @@  discard block
 block discarded – undo
465 474
 	checkSession(isset($_REQUEST['save']) ? 'post' : 'get');
466 475
 
467 476
 	// The report ID is a must.
468
-	if (empty($_REQUEST['rid']))
469
-		fatal_lang_error('mc_reportedp_none_found');
477
+	if (empty($_REQUEST['rid'])) {
478
+			fatal_lang_error('mc_reportedp_none_found');
479
+	}
470 480
 
471
-	if (empty($_REQUEST['mid']))
472
-		fatal_lang_error('mc_reportedp_comment_none_found');
481
+	if (empty($_REQUEST['mid'])) {
482
+			fatal_lang_error('mc_reportedp_comment_none_found');
483
+	}
473 484
 
474 485
 	// Integers only please.
475 486
 	$context['report_id'] = (int) $_REQUEST['rid'];
@@ -477,8 +488,9 @@  discard block
 block discarded – undo
477 488
 
478 489
 	$context['comment'] = getCommentModDetails($context['comment_id']);
479 490
 
480
-	if (empty($context['comment']))
481
-		fatal_lang_error('mc_reportedp_comment_none_found');
491
+	if (empty($context['comment'])) {
492
+			fatal_lang_error('mc_reportedp_comment_none_found');
493
+	}
482 494
 
483 495
 	// Set up the comforting bits...
484 496
 	$context['page_title'] = $txt['mc_reported_posts'];
@@ -489,15 +501,17 @@  discard block
 block discarded – undo
489 501
 		validateToken('mod-reportC-edit');
490 502
 
491 503
 		// Make sure there is some data to edit on the DB.
492
-		if (empty($context['comment']))
493
-			fatal_lang_error('report_action_message_edit_issue');
504
+		if (empty($context['comment'])) {
505
+					fatal_lang_error('report_action_message_edit_issue');
506
+		}
494 507
 
495 508
 		// Still there, good, now lets see if you can actually edit it...
496 509
 		$comment_owner = $user_info['id'] == $context['comment']['id_member'];
497 510
 
498 511
 		// So, you aren't neither an admin or the comment owner huh? that's too bad.
499
-		if (!allowedTo('admin_forum') && !$comment_owner)
500
-			fatal_lang_error('report_action_message_edit_cannot');
512
+		if (!allowedTo('admin_forum') && !$comment_owner) {
513
+					fatal_lang_error('report_action_message_edit_cannot');
514
+		}
501 515
 
502 516
 		// All good!
503 517
 		$edited_comment = trim($smcFunc['htmlspecialchars']($_POST['mod_comment']));
@@ -523,8 +537,9 @@  discard block
 block discarded – undo
523 537
 	checkSession('get');
524 538
 
525 539
 	// We need to do something!
526
-	if (empty($_GET['rid']) && (!isset($_GET['ignore']) || !isset($_GET['closed'])))
527
-		fatal_lang_error('mc_reportedp_none_found');
540
+	if (empty($_GET['rid']) && (!isset($_GET['ignore']) || !isset($_GET['closed']))) {
541
+			fatal_lang_error('mc_reportedp_none_found');
542
+	}
528 543
 
529 544
 	// What are we gonna do?
530 545
 	$action = isset($_GET['ignore']) ? 'ignore' : 'closed';
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +798 added lines, -602 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,27 +48,35 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65
-		if (!is_array($modSettings['attachmentUploadDir']))
66
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
73
+		if (!is_array($modSettings['attachmentUploadDir'])) {
74
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
75
+		}
67 76
 
68
-		if (!empty($cache_enable))
69
-			cache_put_data('modSettings', $modSettings, 90);
77
+		if (!empty($cache_enable)) {
78
+					cache_put_data('modSettings', $modSettings, 90);
79
+		}
70 80
 	}
71 81
 
72 82
 	$modSettings['cache_enable'] = $cache_enable;
@@ -86,8 +96,9 @@  discard block
 block discarded – undo
86 96
 		};
87 97
 	$fix_utf8mb4 = function($string) use ($utf8)
88 98
 	{
89
-		if (!$utf8)
90
-			return $string;
99
+		if (!$utf8) {
100
+					return $string;
101
+		}
91 102
 
92 103
 		$i = 0;
93 104
 		$len = strlen($string);
@@ -99,18 +110,15 @@  discard block
 block discarded – undo
99 110
 			{
100 111
 				$new_string .= $string[$i];
101 112
 				$i++;
102
-			}
103
-			elseif ($ord < 224)
113
+			} elseif ($ord < 224)
104 114
 			{
105 115
 				$new_string .= $string[$i] . $string[$i + 1];
106 116
 				$i += 2;
107
-			}
108
-			elseif ($ord < 240)
117
+			} elseif ($ord < 240)
109 118
 			{
110 119
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
111 120
 				$i += 3;
112
-			}
113
-			elseif ($ord < 248)
121
+			} elseif ($ord < 248)
114 122
 			{
115 123
 				// Magic happens.
116 124
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -154,8 +162,7 @@  discard block
 block discarded – undo
154 162
 			{
155 163
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
156 164
 				return is_int($result) ? $result + $offset : false;
157
-			}
158
-			else
165
+			} else
159 166
 			{
160 167
 				$needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
161 168
 				$needle_size = count($needle_arr);
@@ -164,8 +171,9 @@  discard block
 block discarded – undo
164 171
 				while ((int) $result === $result)
165 172
 				{
166 173
 					$offset += $result;
167
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
168
-						return $offset;
174
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
175
+											return $offset;
176
+					}
169 177
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
170 178
 				}
171 179
 				return false;
@@ -203,8 +211,9 @@  discard block
 block discarded – undo
203 211
 			$string = $ent_check($string);
204 212
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
205 213
 			$string = $matches[0];
206
-			while (strlen($string) > $length)
207
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
214
+			while (strlen($string) > $length) {
215
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
216
+			}
208 217
 			return $string;
209 218
 		},
210 219
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -214,23 +223,25 @@  discard block
 block discarded – undo
214 223
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
215 224
 		{
216 225
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
217
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
218
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
226
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
227
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
228
+			}
219 229
 			return implode('', $words);
220 230
 		} : 'ucwords',
221 231
 	);
222 232
 
223 233
 	// Setting the timezone is a requirement for some functions.
224
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
225
-		date_default_timezone_set($modSettings['default_timezone']);
226
-	else
234
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
235
+			date_default_timezone_set($modSettings['default_timezone']);
236
+	} else
227 237
 	{
228 238
 		// Get PHP's default timezone, if set
229 239
 		$ini_tz = ini_get('date.timezone');
230
-		if (!empty($ini_tz))
231
-			$modSettings['default_timezone'] = $ini_tz;
232
-		else
233
-			$modSettings['default_timezone'] = '';
240
+		if (!empty($ini_tz)) {
241
+					$modSettings['default_timezone'] = $ini_tz;
242
+		} else {
243
+					$modSettings['default_timezone'] = '';
244
+		}
234 245
 
235 246
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
236 247
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -248,22 +259,26 @@  discard block
 block discarded – undo
248 259
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
249 260
 		{
250 261
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
251
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
252
-				$modSettings['load_average'] = (float) $matches[1];
253
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
254
-				$modSettings['load_average'] = (float) $matches[1];
255
-			else
256
-				unset($modSettings['load_average']);
262
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
263
+							$modSettings['load_average'] = (float) $matches[1];
264
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
265
+							$modSettings['load_average'] = (float) $matches[1];
266
+			} else {
267
+							unset($modSettings['load_average']);
268
+			}
257 269
 
258
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
259
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
270
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
271
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
272
+			}
260 273
 		}
261 274
 
262
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
263
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
275
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
276
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
277
+		}
264 278
 
265
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
266
-			display_loadavg_error();
279
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
280
+					display_loadavg_error();
281
+		}
267 282
 	}
268 283
 
269 284
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -284,8 +299,9 @@  discard block
 block discarded – undo
284 299
 	if (defined('SMF_INTEGRATION_SETTINGS'))
285 300
 	{
286 301
 		$integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true);
287
-		foreach ($integration_settings as $hook => $function)
288
-			add_integration_function($hook, $function, '', false);
302
+		foreach ($integration_settings as $hook => $function) {
303
+					add_integration_function($hook, $function, '', false);
304
+		}
289 305
 	}
290 306
 
291 307
 	// Any files to pre include?
@@ -295,8 +311,9 @@  discard block
 block discarded – undo
295 311
 		foreach ($pre_includes as $include)
296 312
 		{
297 313
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
298
-			if (file_exists($include))
299
-				require_once($include);
314
+			if (file_exists($include)) {
315
+							require_once($include);
316
+			}
300 317
 		}
301 318
 	}
302 319
 
@@ -400,27 +417,28 @@  discard block
 block discarded – undo
400 417
 				break;
401 418
 			}
402 419
 		}
420
+	} else {
421
+			$id_member = 0;
403 422
 	}
404
-	else
405
-		$id_member = 0;
406 423
 
407 424
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
408 425
 	{
409 426
 		$cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false);
410 427
 
411
-		if (empty($cookie_data))
412
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
428
+		if (empty($cookie_data)) {
429
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
430
+		}
413 431
 
414 432
 		list ($id_member, $password) = $cookie_data;
415 433
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
416
-	}
417
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
434
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
418 435
 	{
419 436
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
420 437
 		$cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]);
421 438
 
422
-		if (empty($cookie_data))
423
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
439
+		if (empty($cookie_data)) {
440
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
441
+		}
424 442
 
425 443
 		list ($id_member, $password, $login_span) = $cookie_data;
426 444
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -445,30 +463,34 @@  discard block
 block discarded – undo
445 463
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
446 464
 			$smcFunc['db_free_result']($request);
447 465
 
448
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
449
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
466
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
467
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
468
+			}
450 469
 
451
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
452
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
470
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
471
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
472
+			}
453 473
 		}
454 474
 
455 475
 		// Did we find 'im?  If not, junk it.
456 476
 		if (!empty($user_settings))
457 477
 		{
458 478
 			// As much as the password should be right, we can assume the integration set things up.
459
-			if (!empty($already_verified) && $already_verified === true)
460
-				$check = true;
479
+			if (!empty($already_verified) && $already_verified === true) {
480
+							$check = true;
481
+			}
461 482
 			// SHA-512 hash should be 128 characters long.
462
-			elseif (strlen($password) == 128)
463
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
464
-			else
465
-				$check = false;
483
+			elseif (strlen($password) == 128) {
484
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
485
+			} else {
486
+							$check = false;
487
+			}
466 488
 
467 489
 			// Wrong password or not activated - either way, you're going nowhere.
468 490
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
491
+		} else {
492
+					$id_member = 0;
469 493
 		}
470
-		else
471
-			$id_member = 0;
472 494
 
473 495
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
474 496
 		if (!$id_member)
@@ -490,13 +512,15 @@  discard block
 block discarded – undo
490 512
 				{
491 513
 					$tfa_data = smf_json_decode($_COOKIE[$tfacookie]);
492 514
 
493
-					if (is_null($tfa_data))
494
-						$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
515
+					if (is_null($tfa_data)) {
516
+											$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
517
+					}
495 518
 
496 519
 					list ($tfamember, $tfasecret) = $tfa_data;
497 520
 
498
-					if ((int) $tfamember != $id_member)
499
-						$tfasecret = null;
521
+					if ((int) $tfamember != $id_member) {
522
+											$tfasecret = null;
523
+					}
500 524
 				}
501 525
 
502 526
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -516,10 +540,12 @@  discard block
 block discarded – undo
516 540
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
517 541
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
518 542
 		{
519
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
543
+			if ($modSettings['tfa_mode'] == 2) {
544
+				//only do this if we are just forcing SOME membergroups
520 545
 			{
521 546
 				//Build an array of ALL user membergroups.
522 547
 				$full_groups = array($user_settings['id_group']);
548
+			}
523 549
 				if (!empty($user_settings['additional_groups']))
524 550
 				{
525 551
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -539,15 +565,17 @@  discard block
 block discarded – undo
539 565
 				);
540 566
 				$row = $smcFunc['db_fetch_assoc']($request);
541 567
 				$smcFunc['db_free_result']($request);
568
+			} else {
569
+							$row['total'] = 1;
542 570
 			}
543
-			else
544
-				$row['total'] = 1; //simplifies logics in the next "if"
571
+			//simplifies logics in the next "if"
545 572
 
546 573
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
547 574
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
548 575
 
549
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
550
-				redirectexit('action=profile;area=tfasetup;forced');
576
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
577
+							redirectexit('action=profile;area=tfasetup;forced');
578
+			}
551 579
 		}
552 580
 	}
553 581
 
@@ -584,33 +612,37 @@  discard block
 block discarded – undo
584 612
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
585 613
 				$user_settings['last_login'] = time();
586 614
 
587
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
588
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
615
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
616
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
617
+				}
589 618
 
590
-				if (!empty($modSettings['cache_enable']))
591
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
619
+				if (!empty($modSettings['cache_enable'])) {
620
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
621
+				}
592 622
 			}
623
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
624
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
593 625
 		}
594
-		elseif (empty($_SESSION['id_msg_last_visit']))
595
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
596 626
 
597 627
 		$username = $user_settings['member_name'];
598 628
 
599
-		if (empty($user_settings['additional_groups']))
600
-			$user_info = array(
629
+		if (empty($user_settings['additional_groups'])) {
630
+					$user_info = array(
601 631
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
602 632
 			);
603
-		else
604
-			$user_info = array(
633
+		} else {
634
+					$user_info = array(
605 635
 				'groups' => array_merge(
606 636
 					array($user_settings['id_group'], $user_settings['id_post_group']),
607 637
 					explode(',', $user_settings['additional_groups'])
608 638
 				)
609 639
 			);
640
+		}
610 641
 
611 642
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
612
-		foreach ($user_info['groups'] as $k => $v)
613
-			$user_info['groups'][$k] = (int) $v;
643
+		foreach ($user_info['groups'] as $k => $v) {
644
+					$user_info['groups'][$k] = (int) $v;
645
+		}
614 646
 
615 647
 		// This is a logged in user, so definitely not a spider.
616 648
 		$user_info['possibly_robot'] = false;
@@ -624,8 +656,7 @@  discard block
 block discarded – undo
624 656
 			$time_system = new DateTime('now', $tz_system);
625 657
 			$time_user = new DateTime('now', $tz_user);
626 658
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
627
-		}
628
-		else
659
+		} else
629 660
 		{
630 661
 			// !!! Compatibility.
631 662
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -639,16 +670,18 @@  discard block
 block discarded – undo
639 670
 		$user_info = array('groups' => array(-1));
640 671
 		$user_settings = array();
641 672
 
642
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
643
-			$_COOKIE[$cookiename] = '';
673
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
674
+					$_COOKIE[$cookiename] = '';
675
+		}
644 676
 
645 677
 		// Expire the 2FA cookie
646 678
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
647 679
 		{
648 680
 			$tfa_data = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
649 681
 
650
-			if (is_null($tfa_data))
651
-				$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
682
+			if (is_null($tfa_data)) {
683
+							$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
684
+			}
652 685
 
653 686
 			list ($id, $user, $exp, $state, $preserve) = $tfa_data;
654 687
 
@@ -660,19 +693,20 @@  discard block
 block discarded – undo
660 693
 		}
661 694
 
662 695
 		// Create a login token if it doesn't exist yet.
663
-		if (!isset($_SESSION['token']['post-login']))
664
-			createToken('login');
665
-		else
666
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
696
+		if (!isset($_SESSION['token']['post-login'])) {
697
+					createToken('login');
698
+		} else {
699
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
700
+		}
667 701
 
668 702
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
669 703
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
670 704
 		{
671 705
 			require_once($sourcedir . '/ManageSearchEngines.php');
672 706
 			$user_info['possibly_robot'] = SpiderCheck();
707
+		} elseif (!empty($modSettings['spider_mode'])) {
708
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
673 709
 		}
674
-		elseif (!empty($modSettings['spider_mode']))
675
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
676 710
 		// If we haven't turned on proper spider hunts then have a guess!
677 711
 		else
678 712
 		{
@@ -720,8 +754,9 @@  discard block
 block discarded – undo
720 754
 	$user_info['groups'] = array_unique($user_info['groups']);
721 755
 
722 756
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
723
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
724
-		unset($user_info['ignoreboards'][$tmp]);
757
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
758
+			unset($user_info['ignoreboards'][$tmp]);
759
+	}
725 760
 
726 761
 	// Allow the user to change their language.
727 762
 	if (!empty($modSettings['userLanguage']))
@@ -734,31 +769,36 @@  discard block
 block discarded – undo
734 769
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
735 770
 
736 771
 			// Make it permanent for members.
737
-			if (!empty($user_info['id']))
738
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
739
-			else
740
-				$_SESSION['language'] = $user_info['language'];
772
+			if (!empty($user_info['id'])) {
773
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
774
+			} else {
775
+							$_SESSION['language'] = $user_info['language'];
776
+			}
777
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
778
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
741 779
 		}
742
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
743
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
744 780
 	}
745 781
 
746 782
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
747
-	if ($user_info['is_admin'])
748
-		$user_info['query_see_board'] = '1=1';
783
+	if ($user_info['is_admin']) {
784
+			$user_info['query_see_board'] = '1=1';
785
+	}
749 786
 	// Otherwise just the groups in $user_info['groups'].
750
-	else
751
-		$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
787
+	else {
788
+			$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
789
+	}
752 790
 
753 791
 	// Build the list of boards they WANT to see.
754 792
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
755 793
 
756 794
 	// If they aren't ignoring any boards then they want to see all the boards they can see
757
-	if (empty($user_info['ignoreboards']))
758
-		$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
795
+	if (empty($user_info['ignoreboards'])) {
796
+			$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
797
+	}
759 798
 	// Ok I guess they don't want to see all the boards
760
-	else
761
-		$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
799
+	else {
800
+			$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
801
+	}
762 802
 
763 803
 	call_integration_hook('integrate_user_info');
764 804
 }
@@ -816,9 +856,9 @@  discard block
 block discarded – undo
816 856
 		}
817 857
 
818 858
 		// Remember redirection is the key to avoiding fallout from your bosses.
819
-		if (!empty($topic))
820
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
821
-		else
859
+		if (!empty($topic)) {
860
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
861
+		} else
822 862
 		{
823 863
 			loadPermissions();
824 864
 			loadTheme();
@@ -836,10 +876,11 @@  discard block
 block discarded – undo
836 876
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
837 877
 	{
838 878
 		// @todo SLOW?
839
-		if (!empty($topic))
840
-			$temp = cache_get_data('topic_board-' . $topic, 120);
841
-		else
842
-			$temp = cache_get_data('board-' . $board, 120);
879
+		if (!empty($topic)) {
880
+					$temp = cache_get_data('topic_board-' . $topic, 120);
881
+		} else {
882
+					$temp = cache_get_data('board-' . $board, 120);
883
+		}
843 884
 
844 885
 		if (!empty($temp))
845 886
 		{
@@ -877,8 +918,9 @@  discard block
 block discarded – undo
877 918
 			$row = $smcFunc['db_fetch_assoc']($request);
878 919
 
879 920
 			// Set the current board.
880
-			if (!empty($row['id_board']))
881
-				$board = $row['id_board'];
921
+			if (!empty($row['id_board'])) {
922
+							$board = $row['id_board'];
923
+			}
882 924
 
883 925
 			// Basic operating information. (globals... :/)
884 926
 			$board_info = array(
@@ -914,21 +956,23 @@  discard block
 block discarded – undo
914 956
 
915 957
 			do
916 958
 			{
917
-				if (!empty($row['id_moderator']))
918
-					$board_info['moderators'][$row['id_moderator']] = array(
959
+				if (!empty($row['id_moderator'])) {
960
+									$board_info['moderators'][$row['id_moderator']] = array(
919 961
 						'id' => $row['id_moderator'],
920 962
 						'name' => $row['real_name'],
921 963
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
922 964
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
923 965
 					);
966
+				}
924 967
 
925
-				if (!empty($row['id_moderator_group']))
926
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
968
+				if (!empty($row['id_moderator_group'])) {
969
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
927 970
 						'id' => $row['id_moderator_group'],
928 971
 						'name' => $row['group_name'],
929 972
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
930 973
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
931 974
 					);
975
+				}
932 976
 			}
933 977
 			while ($row = $smcFunc['db_fetch_assoc']($request));
934 978
 
@@ -960,12 +1004,12 @@  discard block
 block discarded – undo
960 1004
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
961 1005
 			{
962 1006
 				// @todo SLOW?
963
-				if (!empty($topic))
964
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
1007
+				if (!empty($topic)) {
1008
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1009
+				}
965 1010
 				cache_put_data('board-' . $board, $board_info, 120);
966 1011
 			}
967
-		}
968
-		else
1012
+		} else
969 1013
 		{
970 1014
 			// Otherwise the topic is invalid, there are no moderators, etc.
971 1015
 			$board_info = array(
@@ -979,8 +1023,9 @@  discard block
 block discarded – undo
979 1023
 		$smcFunc['db_free_result']($request);
980 1024
 	}
981 1025
 
982
-	if (!empty($topic))
983
-		$_GET['board'] = (int) $board;
1026
+	if (!empty($topic)) {
1027
+			$_GET['board'] = (int) $board;
1028
+	}
984 1029
 
985 1030
 	if (!empty($board))
986 1031
 	{
@@ -990,10 +1035,12 @@  discard block
 block discarded – undo
990 1035
 		// Now check if the user is a moderator.
991 1036
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
992 1037
 
993
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
994
-			$board_info['error'] = 'access';
995
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
996
-			$board_info['error'] = 'access';
1038
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1039
+					$board_info['error'] = 'access';
1040
+		}
1041
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1042
+					$board_info['error'] = 'access';
1043
+		}
997 1044
 
998 1045
 		// Build up the linktree.
999 1046
 		$context['linktree'] = array_merge(
@@ -1016,8 +1063,9 @@  discard block
 block discarded – undo
1016 1063
 	$context['current_board'] = $board;
1017 1064
 
1018 1065
 	// No posting in redirection boards!
1019
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1020
-		$board_info['error'] == 'post_in_redirect';
1066
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1067
+			$board_info['error'] == 'post_in_redirect';
1068
+	}
1021 1069
 
1022 1070
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1023 1071
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1043,24 +1091,23 @@  discard block
 block discarded – undo
1043 1091
 			ob_end_clean();
1044 1092
 			header('HTTP/1.1 403 Forbidden');
1045 1093
 			die;
1046
-		}
1047
-		elseif ($board_info['error'] == 'post_in_redirect')
1094
+		} elseif ($board_info['error'] == 'post_in_redirect')
1048 1095
 		{
1049 1096
 			// Slightly different error message here...
1050 1097
 			fatal_lang_error('cannot_post_redirect', false);
1051
-		}
1052
-		elseif ($user_info['is_guest'])
1098
+		} elseif ($user_info['is_guest'])
1053 1099
 		{
1054 1100
 			loadLanguage('Errors');
1055 1101
 			is_not_guest($txt['topic_gone']);
1102
+		} else {
1103
+					fatal_lang_error('topic_gone', false);
1056 1104
 		}
1057
-		else
1058
-			fatal_lang_error('topic_gone', false);
1059 1105
 	}
1060 1106
 
1061
-	if ($user_info['is_mod'])
1062
-		$user_info['groups'][] = 3;
1063
-}
1107
+	if ($user_info['is_mod']) {
1108
+			$user_info['groups'][] = 3;
1109
+	}
1110
+	}
1064 1111
 
1065 1112
 /**
1066 1113
  * Load this user's permissions.
@@ -1081,8 +1128,9 @@  discard block
 block discarded – undo
1081 1128
 		asort($cache_groups);
1082 1129
 		$cache_groups = implode(',', $cache_groups);
1083 1130
 		// If it's a spider then cache it different.
1084
-		if ($user_info['possibly_robot'])
1085
-			$cache_groups .= '-spider';
1131
+		if ($user_info['possibly_robot']) {
1132
+					$cache_groups .= '-spider';
1133
+		}
1086 1134
 
1087 1135
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1088 1136
 		{
@@ -1090,9 +1138,9 @@  discard block
 block discarded – undo
1090 1138
 			banPermissions();
1091 1139
 
1092 1140
 			return;
1141
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1142
+					list ($user_info['permissions'], $removals) = $temp;
1093 1143
 		}
1094
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1095
-			list ($user_info['permissions'], $removals) = $temp;
1096 1144
 	}
1097 1145
 
1098 1146
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1114,23 +1162,26 @@  discard block
 block discarded – undo
1114 1162
 		$removals = array();
1115 1163
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1116 1164
 		{
1117
-			if (empty($row['add_deny']))
1118
-				$removals[] = $row['permission'];
1119
-			else
1120
-				$user_info['permissions'][] = $row['permission'];
1165
+			if (empty($row['add_deny'])) {
1166
+							$removals[] = $row['permission'];
1167
+			} else {
1168
+							$user_info['permissions'][] = $row['permission'];
1169
+			}
1121 1170
 		}
1122 1171
 		$smcFunc['db_free_result']($request);
1123 1172
 
1124
-		if (isset($cache_groups))
1125
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1173
+		if (isset($cache_groups)) {
1174
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1175
+		}
1126 1176
 	}
1127 1177
 
1128 1178
 	// Get the board permissions.
1129 1179
 	if (!empty($board))
1130 1180
 	{
1131 1181
 		// Make sure the board (if any) has been loaded by loadBoard().
1132
-		if (!isset($board_info['profile']))
1133
-			fatal_lang_error('no_board');
1182
+		if (!isset($board_info['profile'])) {
1183
+					fatal_lang_error('no_board');
1184
+		}
1134 1185
 
1135 1186
 		$request = $smcFunc['db_query']('', '
1136 1187
 			SELECT permission, add_deny
@@ -1146,20 +1197,23 @@  discard block
 block discarded – undo
1146 1197
 		);
1147 1198
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1148 1199
 		{
1149
-			if (empty($row['add_deny']))
1150
-				$removals[] = $row['permission'];
1151
-			else
1152
-				$user_info['permissions'][] = $row['permission'];
1200
+			if (empty($row['add_deny'])) {
1201
+							$removals[] = $row['permission'];
1202
+			} else {
1203
+							$user_info['permissions'][] = $row['permission'];
1204
+			}
1153 1205
 		}
1154 1206
 		$smcFunc['db_free_result']($request);
1155 1207
 	}
1156 1208
 
1157 1209
 	// Remove all the permissions they shouldn't have ;).
1158
-	if (!empty($modSettings['permission_enable_deny']))
1159
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1210
+	if (!empty($modSettings['permission_enable_deny'])) {
1211
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1212
+	}
1160 1213
 
1161
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1162
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1214
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1215
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1216
+	}
1163 1217
 
1164 1218
 	// Banned?  Watch, don't touch..
1165 1219
 	banPermissions();
@@ -1171,17 +1225,18 @@  discard block
 block discarded – undo
1171 1225
 		{
1172 1226
 			require_once($sourcedir . '/Subs-Auth.php');
1173 1227
 			rebuildModCache();
1228
+		} else {
1229
+					$user_info['mod_cache'] = $_SESSION['mc'];
1174 1230
 		}
1175
-		else
1176
-			$user_info['mod_cache'] = $_SESSION['mc'];
1177 1231
 
1178 1232
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1179 1233
 		// For example this drastically simplifies certain changes to the profile area.
1180 1234
 		$user_info['permissions'][] = 'is_not_guest';
1181 1235
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1182 1236
 		$user_info['permissions'][] = 'profile_view_own';
1183
-		if (in_array('profile_view', $user_info['permissions']))
1184
-			$user_info['permissions'][] = 'profile_view_any';
1237
+		if (in_array('profile_view', $user_info['permissions'])) {
1238
+					$user_info['permissions'][] = 'profile_view_any';
1239
+		}
1185 1240
 	}
1186 1241
 }
1187 1242
 
@@ -1199,8 +1254,9 @@  discard block
 block discarded – undo
1199 1254
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1200 1255
 
1201 1256
 	// Can't just look for no users :P.
1202
-	if (empty($users))
1203
-		return array();
1257
+	if (empty($users)) {
1258
+			return array();
1259
+	}
1204 1260
 
1205 1261
 	// Pass the set value
1206 1262
 	$context['loadMemberContext_set'] = $set;
@@ -1215,8 +1271,9 @@  discard block
 block discarded – undo
1215 1271
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1216 1272
 		{
1217 1273
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1218
-			if ($data == null)
1219
-				continue;
1274
+			if ($data == null) {
1275
+							continue;
1276
+			}
1220 1277
 
1221 1278
 			$loaded_ids[] = $data['id_member'];
1222 1279
 			$user_profile[$data['id_member']] = $data;
@@ -1280,13 +1337,16 @@  discard block
 block discarded – undo
1280 1337
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1281 1338
 		{
1282 1339
 			// Take care of proxying avatar if required, do this here for maximum reach
1283
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1284
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1340
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1341
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1342
+			}
1285 1343
 
1286
-			if (isset($row['member_ip']))
1287
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1288
-			if (isset($row['member_ip2']))
1289
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1344
+			if (isset($row['member_ip'])) {
1345
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1346
+			}
1347
+			if (isset($row['member_ip2'])) {
1348
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1349
+			}
1290 1350
 			$new_loaded_ids[] = $row['id_member'];
1291 1351
 			$loaded_ids[] = $row['id_member'];
1292 1352
 			$row['options'] = array();
@@ -1305,8 +1365,9 @@  discard block
 block discarded – undo
1305 1365
 				'loaded_ids' => $new_loaded_ids,
1306 1366
 			)
1307 1367
 		);
1308
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1309
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1368
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1369
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1370
+		}
1310 1371
 		$smcFunc['db_free_result']($request);
1311 1372
 	}
1312 1373
 
@@ -1317,10 +1378,11 @@  discard block
 block discarded – undo
1317 1378
 	{
1318 1379
 		foreach ($loaded_ids as $a_member)
1319 1380
 		{
1320
-			if (!empty($user_profile[$a_member]['additional_groups']))
1321
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1322
-			else
1323
-				$groups = array($user_profile[$a_member]['id_group']);
1381
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1382
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1383
+			} else {
1384
+							$groups = array($user_profile[$a_member]['id_group']);
1385
+			}
1324 1386
 
1325 1387
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1326 1388
 
@@ -1333,8 +1395,9 @@  discard block
 block discarded – undo
1333 1395
 
1334 1396
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1335 1397
 	{
1336
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1337
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1398
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1399
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1400
+		}
1338 1401
 	}
1339 1402
 
1340 1403
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1360,14 +1423,17 @@  discard block
 block discarded – undo
1360 1423
 		foreach ($temp_mods as $id)
1361 1424
 		{
1362 1425
 			// By popular demand, don't show admins or global moderators as moderators.
1363
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1364
-				$user_profile[$id]['member_group'] = $row['member_group'];
1426
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1427
+							$user_profile[$id]['member_group'] = $row['member_group'];
1428
+			}
1365 1429
 
1366 1430
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1367
-			if (!empty($row['icons']))
1368
-				$user_profile[$id]['icons'] = $row['icons'];
1369
-			if (!empty($row['member_group_color']))
1370
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1431
+			if (!empty($row['icons'])) {
1432
+							$user_profile[$id]['icons'] = $row['icons'];
1433
+			}
1434
+			if (!empty($row['member_group_color'])) {
1435
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1436
+			}
1371 1437
 		}
1372 1438
 	}
1373 1439
 
@@ -1389,12 +1455,14 @@  discard block
 block discarded – undo
1389 1455
 	static $loadedLanguages = array();
1390 1456
 
1391 1457
 	// If this person's data is already loaded, skip it.
1392
-	if (isset($dataLoaded[$user]))
1393
-		return true;
1458
+	if (isset($dataLoaded[$user])) {
1459
+			return true;
1460
+	}
1394 1461
 
1395 1462
 	// We can't load guests or members not loaded by loadMemberData()!
1396
-	if ($user == 0)
1397
-		return false;
1463
+	if ($user == 0) {
1464
+			return false;
1465
+	}
1398 1466
 	if (!isset($user_profile[$user]))
1399 1467
 	{
1400 1468
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1420,12 +1488,16 @@  discard block
 block discarded – undo
1420 1488
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1421 1489
 
1422 1490
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1423
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1491
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1492
+		//icon is set and exists
1424 1493
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1425
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1494
+	} elseif (isset($profile['icons'][1])) {
1495
+		//icon is set and doesn't exist, fallback to default
1426 1496
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1427
-	else //not set, bye bye
1497
+	} else {
1498
+		//not set, bye bye
1428 1499
 		$group_icon_url = '';
1500
+	}
1429 1501
 
1430 1502
 	// These minimal values are always loaded
1431 1503
 	$memberContext[$user] = array(
@@ -1444,8 +1516,9 @@  discard block
 block discarded – undo
1444 1516
 	if ($context['loadMemberContext_set'] != 'minimal')
1445 1517
 	{
1446 1518
 		// Go the extra mile and load the user's native language name.
1447
-		if (empty($loadedLanguages))
1448
-			$loadedLanguages = getLanguages();
1519
+		if (empty($loadedLanguages)) {
1520
+					$loadedLanguages = getLanguages();
1521
+		}
1449 1522
 
1450 1523
 		$memberContext[$user] += array(
1451 1524
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1499,31 +1572,33 @@  discard block
 block discarded – undo
1499 1572
 	{
1500 1573
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1501 1574
 		{
1502
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1503
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1504
-			else
1505
-				$image = get_gravatar_url($profile['email_address']);
1506
-		}
1507
-		else
1575
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1576
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1577
+			} else {
1578
+							$image = get_gravatar_url($profile['email_address']);
1579
+			}
1580
+		} else
1508 1581
 		{
1509 1582
 			// So it's stored in the member table?
1510 1583
 			if (!empty($profile['avatar']))
1511 1584
 			{
1512 1585
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1586
+			} elseif (!empty($profile['filename'])) {
1587
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1513 1588
 			}
1514
-			elseif (!empty($profile['filename']))
1515
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1516 1589
 			// Right... no avatar...use the default one
1517
-			else
1518
-				$image = $modSettings['avatar_url'] . '/default.png';
1590
+			else {
1591
+							$image = $modSettings['avatar_url'] . '/default.png';
1592
+			}
1519 1593
 		}
1520
-		if (!empty($image))
1521
-			$memberContext[$user]['avatar'] = array(
1594
+		if (!empty($image)) {
1595
+					$memberContext[$user]['avatar'] = array(
1522 1596
 				'name' => $profile['avatar'],
1523 1597
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1524 1598
 				'href' => $image,
1525 1599
 				'url' => $image,
1526 1600
 			);
1601
+		}
1527 1602
 	}
1528 1603
 
1529 1604
 	// Are we also loading the members custom fields into context?
@@ -1531,35 +1606,41 @@  discard block
 block discarded – undo
1531 1606
 	{
1532 1607
 		$memberContext[$user]['custom_fields'] = array();
1533 1608
 
1534
-		if (!isset($context['display_fields']))
1535
-			$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1609
+		if (!isset($context['display_fields'])) {
1610
+					$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1611
+		}
1536 1612
 
1537 1613
 		foreach ($context['display_fields'] as $custom)
1538 1614
 		{
1539
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1540
-				continue;
1615
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1616
+							continue;
1617
+			}
1541 1618
 
1542 1619
 			$value = $profile['options'][$custom['col_name']];
1543 1620
 
1544 1621
 			// Don't show the "disabled" option for the "gender" field.
1545
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1546
-				continue;
1622
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1623
+							continue;
1624
+			}
1547 1625
 
1548 1626
 			// BBC?
1549
-			if ($custom['bbc'])
1550
-				$value = parse_bbc($value);
1627
+			if ($custom['bbc']) {
1628
+							$value = parse_bbc($value);
1629
+			}
1551 1630
 			// ... or checkbox?
1552
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1553
-				$value = $value ? $txt['yes'] : $txt['no'];
1631
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1632
+							$value = $value ? $txt['yes'] : $txt['no'];
1633
+			}
1554 1634
 
1555 1635
 			// Enclosing the user input within some other text?
1556
-			if (!empty($custom['enclose']))
1557
-				$value = strtr($custom['enclose'], array(
1636
+			if (!empty($custom['enclose'])) {
1637
+							$value = strtr($custom['enclose'], array(
1558 1638
 					'{SCRIPTURL}' => $scripturl,
1559 1639
 					'{IMAGES_URL}' => $settings['images_url'],
1560 1640
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1561 1641
 					'{INPUT}' => $value,
1562 1642
 				));
1643
+			}
1563 1644
 
1564 1645
 			$memberContext[$user]['custom_fields'][] = array(
1565 1646
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1586,8 +1667,9 @@  discard block
 block discarded – undo
1586 1667
 	global $smcFunc, $txt, $scripturl, $settings;
1587 1668
 
1588 1669
 	// Do not waste my time...
1589
-	if (empty($users) || empty($params))
1590
-		return false;
1670
+	if (empty($users) || empty($params)) {
1671
+			return false;
1672
+	}
1591 1673
 
1592 1674
 	// Make sure it's an array.
1593 1675
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1611,31 +1693,36 @@  discard block
 block discarded – undo
1611 1693
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1612 1694
 	{
1613 1695
 		// BBC?
1614
-		if (!empty($row['bbc']))
1615
-			$row['value'] = parse_bbc($row['value']);
1696
+		if (!empty($row['bbc'])) {
1697
+					$row['value'] = parse_bbc($row['value']);
1698
+		}
1616 1699
 
1617 1700
 		// ... or checkbox?
1618
-		elseif (isset($row['type']) && $row['type'] == 'check')
1619
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1701
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1702
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1703
+		}
1620 1704
 
1621 1705
 		// Enclosing the user input within some other text?
1622
-		if (!empty($row['enclose']))
1623
-			$row['value'] = strtr($row['enclose'], array(
1706
+		if (!empty($row['enclose'])) {
1707
+					$row['value'] = strtr($row['enclose'], array(
1624 1708
 				'{SCRIPTURL}' => $scripturl,
1625 1709
 				'{IMAGES_URL}' => $settings['images_url'],
1626 1710
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1627 1711
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1628 1712
 			));
1713
+		}
1629 1714
 
1630 1715
 		// Send a simple array if there is just 1 param
1631
-		if (count($params) == 1)
1632
-			$return[$row['id_member']] = $row;
1716
+		if (count($params) == 1) {
1717
+					$return[$row['id_member']] = $row;
1718
+		}
1633 1719
 
1634 1720
 		// More than 1? knock yourself out...
1635 1721
 		else
1636 1722
 		{
1637
-			if (!isset($return[$row['id_member']]))
1638
-				$return[$row['id_member']] = array();
1723
+			if (!isset($return[$row['id_member']])) {
1724
+							$return[$row['id_member']] = array();
1725
+			}
1639 1726
 
1640 1727
 			$return[$row['id_member']][$row['variable']] = $row;
1641 1728
 		}
@@ -1669,8 +1756,9 @@  discard block
 block discarded – undo
1669 1756
 	global $context;
1670 1757
 
1671 1758
 	// Don't know any browser!
1672
-	if (empty($context['browser']))
1673
-		detectBrowser();
1759
+	if (empty($context['browser'])) {
1760
+			detectBrowser();
1761
+	}
1674 1762
 
1675 1763
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1676 1764
 }
@@ -1688,8 +1776,9 @@  discard block
 block discarded – undo
1688 1776
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1689 1777
 
1690 1778
 	// The theme was specified by parameter.
1691
-	if (!empty($id_theme))
1692
-		$id_theme = (int) $id_theme;
1779
+	if (!empty($id_theme)) {
1780
+			$id_theme = (int) $id_theme;
1781
+	}
1693 1782
 	// The theme was specified by REQUEST.
1694 1783
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1695 1784
 	{
@@ -1697,51 +1786,58 @@  discard block
 block discarded – undo
1697 1786
 		$_SESSION['id_theme'] = $id_theme;
1698 1787
 	}
1699 1788
 	// The theme was specified by REQUEST... previously.
1700
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1701
-		$id_theme = (int) $_SESSION['id_theme'];
1789
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1790
+			$id_theme = (int) $_SESSION['id_theme'];
1791
+	}
1702 1792
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1703
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1704
-		$id_theme = $user_info['theme'];
1793
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1794
+			$id_theme = $user_info['theme'];
1795
+	}
1705 1796
 	// The theme was specified by the board.
1706
-	elseif (!empty($board_info['theme']))
1707
-		$id_theme = $board_info['theme'];
1797
+	elseif (!empty($board_info['theme'])) {
1798
+			$id_theme = $board_info['theme'];
1799
+	}
1708 1800
 	// The theme is the forum's default.
1709
-	else
1710
-		$id_theme = $modSettings['theme_guests'];
1801
+	else {
1802
+			$id_theme = $modSettings['theme_guests'];
1803
+	}
1711 1804
 
1712 1805
 	// Verify the id_theme... no foul play.
1713 1806
 	// Always allow the board specific theme, if they are overriding.
1714
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1715
-		$id_theme = $board_info['theme'];
1807
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1808
+			$id_theme = $board_info['theme'];
1809
+	}
1716 1810
 	// If they have specified a particular theme to use with SSI allow it to be used.
1717
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1718
-		$id_theme = (int) $id_theme;
1719
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1811
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1812
+			$id_theme = (int) $id_theme;
1813
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1720 1814
 	{
1721 1815
 		$themes = explode(',', $modSettings['enableThemes']);
1722
-		if (!in_array($id_theme, $themes))
1723
-			$id_theme = $modSettings['theme_guests'];
1724
-		else
1816
+		if (!in_array($id_theme, $themes)) {
1817
+					$id_theme = $modSettings['theme_guests'];
1818
+		} else {
1819
+					$id_theme = (int) $id_theme;
1820
+		}
1821
+	} else {
1725 1822
 			$id_theme = (int) $id_theme;
1726 1823
 	}
1727
-	else
1728
-		$id_theme = (int) $id_theme;
1729 1824
 
1730 1825
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1731 1826
 
1732 1827
 	// Disable image proxy if we don't have SSL enabled
1733
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1734
-		$image_proxy_enabled = false;
1828
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1829
+			$image_proxy_enabled = false;
1830
+	}
1735 1831
 
1736 1832
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1737 1833
 	{
1738 1834
 		$themeData = $temp;
1739 1835
 		$flag = true;
1836
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1837
+			$themeData = $temp + array($member => array());
1838
+	} else {
1839
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1740 1840
 	}
1741
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1742
-		$themeData = $temp + array($member => array());
1743
-	else
1744
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1745 1841
 
1746 1842
 	if (empty($flag))
1747 1843
 	{
@@ -1760,31 +1856,37 @@  discard block
 block discarded – undo
1760 1856
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1761 1857
 		{
1762 1858
 			// There are just things we shouldn't be able to change as members.
1763
-			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1764
-				continue;
1859
+			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1860
+							continue;
1861
+			}
1765 1862
 
1766 1863
 			// If this is the theme_dir of the default theme, store it.
1767
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1768
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1864
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1865
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1866
+			}
1769 1867
 
1770 1868
 			// If this isn't set yet, is a theme option, or is not the default theme..
1771
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1772
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1869
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1870
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1871
+			}
1773 1872
 		}
1774 1873
 		$smcFunc['db_free_result']($result);
1775 1874
 
1776
-		if (!empty($themeData[-1]))
1777
-			foreach ($themeData[-1] as $k => $v)
1875
+		if (!empty($themeData[-1])) {
1876
+					foreach ($themeData[-1] as $k => $v)
1778 1877
 			{
1779 1878
 				if (!isset($themeData[$member][$k]))
1780 1879
 					$themeData[$member][$k] = $v;
1880
+		}
1781 1881
 			}
1782 1882
 
1783
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1784
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1883
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1884
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1885
+		}
1785 1886
 		// Only if we didn't already load that part of the cache...
1786
-		elseif (!isset($temp))
1787
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1887
+		elseif (!isset($temp)) {
1888
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1889
+		}
1788 1890
 	}
1789 1891
 
1790 1892
 	$settings = $themeData[0];
@@ -1801,20 +1903,24 @@  discard block
 block discarded – undo
1801 1903
 	$settings['template_dirs'][] = $settings['theme_dir'];
1802 1904
 
1803 1905
 	// Based on theme (if there is one).
1804
-	if (!empty($settings['base_theme_dir']))
1805
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1906
+	if (!empty($settings['base_theme_dir'])) {
1907
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1908
+	}
1806 1909
 
1807 1910
 	// Lastly the default theme.
1808
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1809
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1911
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1912
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1913
+	}
1810 1914
 
1811
-	if (!$initialize)
1812
-		return;
1915
+	if (!$initialize) {
1916
+			return;
1917
+	}
1813 1918
 
1814 1919
 	// Check to see if we're forcing SSL
1815 1920
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1816
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1817
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1921
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1922
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1923
+	}
1818 1924
 
1819 1925
 	// Check to see if they're accessing it from the wrong place.
1820 1926
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1822,8 +1928,9 @@  discard block
 block discarded – undo
1822 1928
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1823 1929
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1824 1930
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1825
-		if ($temp != '/')
1826
-			$detected_url .= $temp;
1931
+		if ($temp != '/') {
1932
+					$detected_url .= $temp;
1933
+		}
1827 1934
 	}
1828 1935
 	if (isset($detected_url) && $detected_url != $boardurl)
1829 1936
 	{
@@ -1835,8 +1942,9 @@  discard block
 block discarded – undo
1835 1942
 			foreach ($aliases as $alias)
1836 1943
 			{
1837 1944
 				// Rip off all the boring parts, spaces, etc.
1838
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1839
-					$do_fix = true;
1945
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1946
+									$do_fix = true;
1947
+				}
1840 1948
 			}
1841 1949
 		}
1842 1950
 
@@ -1844,20 +1952,22 @@  discard block
 block discarded – undo
1844 1952
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1845 1953
 		{
1846 1954
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1847
-			if (empty($_GET))
1848
-				redirectexit('wwwRedirect');
1849
-			else
1955
+			if (empty($_GET)) {
1956
+							redirectexit('wwwRedirect');
1957
+			} else
1850 1958
 			{
1851 1959
 				list ($k, $v) = each($_GET);
1852 1960
 
1853
-				if ($k != 'wwwRedirect')
1854
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1961
+				if ($k != 'wwwRedirect') {
1962
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1963
+				}
1855 1964
 			}
1856 1965
 		}
1857 1966
 
1858 1967
 		// #3 is just a check for SSL...
1859
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1860
-			$do_fix = true;
1968
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1969
+					$do_fix = true;
1970
+		}
1861 1971
 
1862 1972
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1863 1973
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1891,8 +2001,9 @@  discard block
 block discarded – undo
1891 2001
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1892 2002
 				}
1893 2003
 			}
1894
-			foreach ($context['linktree'] as $k => $dummy)
1895
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2004
+			foreach ($context['linktree'] as $k => $dummy) {
2005
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2006
+			}
1896 2007
 		}
1897 2008
 	}
1898 2009
 	// Set up the contextual user array.
@@ -1911,16 +2022,16 @@  discard block
 block discarded – undo
1911 2022
 			'email' => $user_info['email'],
1912 2023
 			'ignoreusers' => $user_info['ignoreusers'],
1913 2024
 		);
1914
-		if (!$context['user']['is_guest'])
1915
-			$context['user']['name'] = $user_info['name'];
1916
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1917
-			$context['user']['name'] = $txt['guest_title'];
2025
+		if (!$context['user']['is_guest']) {
2026
+					$context['user']['name'] = $user_info['name'];
2027
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2028
+					$context['user']['name'] = $txt['guest_title'];
2029
+		}
1918 2030
 
1919 2031
 		// Determine the current smiley set.
1920 2032
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1921 2033
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1922
-	}
1923
-	else
2034
+	} else
1924 2035
 	{
1925 2036
 		$context['user'] = array(
1926 2037
 			'id' => -1,
@@ -1936,18 +2047,24 @@  discard block
 block discarded – undo
1936 2047
 	}
1937 2048
 
1938 2049
 	// Some basic information...
1939
-	if (!isset($context['html_headers']))
1940
-		$context['html_headers'] = '';
1941
-	if (!isset($context['javascript_files']))
1942
-		$context['javascript_files'] = array();
1943
-	if (!isset($context['css_files']))
1944
-		$context['css_files'] = array();
1945
-	if (!isset($context['css_header']))
1946
-		$context['css_header'] = array();
1947
-	if (!isset($context['javascript_inline']))
1948
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1949
-	if (!isset($context['javascript_vars']))
1950
-		$context['javascript_vars'] = array();
2050
+	if (!isset($context['html_headers'])) {
2051
+			$context['html_headers'] = '';
2052
+	}
2053
+	if (!isset($context['javascript_files'])) {
2054
+			$context['javascript_files'] = array();
2055
+	}
2056
+	if (!isset($context['css_files'])) {
2057
+			$context['css_files'] = array();
2058
+	}
2059
+	if (!isset($context['css_header'])) {
2060
+			$context['css_header'] = array();
2061
+	}
2062
+	if (!isset($context['javascript_inline'])) {
2063
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2064
+	}
2065
+	if (!isset($context['javascript_vars'])) {
2066
+			$context['javascript_vars'] = array();
2067
+	}
1951 2068
 
1952 2069
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1953 2070
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1959,8 +2076,9 @@  discard block
 block discarded – undo
1959 2076
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1960 2077
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1961 2078
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1962
-	if (isset($modSettings['load_average']))
1963
-		$context['load_average'] = $modSettings['load_average'];
2079
+	if (isset($modSettings['load_average'])) {
2080
+			$context['load_average'] = $modSettings['load_average'];
2081
+	}
1964 2082
 
1965 2083
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1966 2084
 	detectBrowser();
@@ -1974,8 +2092,9 @@  discard block
 block discarded – undo
1974 2092
 	// This allows sticking some HTML on the page output - useful for controls.
1975 2093
 	$context['insert_after_template'] = '';
1976 2094
 
1977
-	if (!isset($txt))
1978
-		$txt = array();
2095
+	if (!isset($txt)) {
2096
+			$txt = array();
2097
+	}
1979 2098
 
1980 2099
 	$simpleActions = array(
1981 2100
 		'findmember',
@@ -2021,9 +2140,10 @@  discard block
 block discarded – undo
2021 2140
 
2022 2141
 	// See if theres any extra param to check.
2023 2142
 	$requiresXML = false;
2024
-	foreach ($extraParams as $key => $extra)
2025
-		if (isset($_REQUEST[$extra]))
2143
+	foreach ($extraParams as $key => $extra) {
2144
+			if (isset($_REQUEST[$extra]))
2026 2145
 			$requiresXML = true;
2146
+	}
2027 2147
 
2028 2148
 	// Output is fully XML, so no need for the index template.
2029 2149
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2038,37 +2158,39 @@  discard block
 block discarded – undo
2038 2158
 	{
2039 2159
 		loadLanguage('index+Modifications');
2040 2160
 		$context['template_layers'] = array();
2041
-	}
2042
-
2043
-	else
2161
+	} else
2044 2162
 	{
2045 2163
 		// Custom templates to load, or just default?
2046
-		if (isset($settings['theme_templates']))
2047
-			$templates = explode(',', $settings['theme_templates']);
2048
-		else
2049
-			$templates = array('index');
2164
+		if (isset($settings['theme_templates'])) {
2165
+					$templates = explode(',', $settings['theme_templates']);
2166
+		} else {
2167
+					$templates = array('index');
2168
+		}
2050 2169
 
2051 2170
 		// Load each template...
2052
-		foreach ($templates as $template)
2053
-			loadTemplate($template);
2171
+		foreach ($templates as $template) {
2172
+					loadTemplate($template);
2173
+		}
2054 2174
 
2055 2175
 		// ...and attempt to load their associated language files.
2056 2176
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2057 2177
 		loadLanguage($required_files, '', false);
2058 2178
 
2059 2179
 		// Custom template layers?
2060
-		if (isset($settings['theme_layers']))
2061
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2062
-		else
2063
-			$context['template_layers'] = array('html', 'body');
2180
+		if (isset($settings['theme_layers'])) {
2181
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2182
+		} else {
2183
+					$context['template_layers'] = array('html', 'body');
2184
+		}
2064 2185
 	}
2065 2186
 
2066 2187
 	// Initialize the theme.
2067 2188
 	loadSubTemplate('init', 'ignore');
2068 2189
 
2069 2190
 	// Allow overriding the board wide time/number formats.
2070
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2071
-		$user_info['time_format'] = $txt['time_format'];
2191
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2192
+			$user_info['time_format'] = $txt['time_format'];
2193
+	}
2072 2194
 
2073 2195
 	// Set the character set from the template.
2074 2196
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2076,12 +2198,14 @@  discard block
 block discarded – undo
2076 2198
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2077 2199
 
2078 2200
 	// Guests may still need a name.
2079
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2080
-		$context['user']['name'] = $txt['guest_title'];
2201
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2202
+			$context['user']['name'] = $txt['guest_title'];
2203
+	}
2081 2204
 
2082 2205
 	// Any theme-related strings that need to be loaded?
2083
-	if (!empty($settings['require_theme_strings']))
2084
-		loadLanguage('ThemeStrings', '', false);
2206
+	if (!empty($settings['require_theme_strings'])) {
2207
+			loadLanguage('ThemeStrings', '', false);
2208
+	}
2085 2209
 
2086 2210
 	// Make a special URL for the language.
2087 2211
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2092,8 +2216,9 @@  discard block
 block discarded – undo
2092 2216
 	// Here is my luvly Responsive CSS
2093 2217
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2094 2218
 
2095
-	if ($context['right_to_left'])
2096
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2219
+	if ($context['right_to_left']) {
2220
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2221
+	}
2097 2222
 
2098 2223
 	// We allow theme variants, because we're cool.
2099 2224
 	$context['theme_variant'] = '';
@@ -2101,14 +2226,17 @@  discard block
 block discarded – undo
2101 2226
 	if (!empty($settings['theme_variants']))
2102 2227
 	{
2103 2228
 		// Overriding - for previews and that ilk.
2104
-		if (!empty($_REQUEST['variant']))
2105
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2229
+		if (!empty($_REQUEST['variant'])) {
2230
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2231
+		}
2106 2232
 		// User selection?
2107
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2108
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2233
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2234
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2235
+		}
2109 2236
 		// If not a user variant, select the default.
2110
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2111
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2237
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2238
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2239
+		}
2112 2240
 
2113 2241
 		// Do this to keep things easier in the templates.
2114 2242
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2117,20 +2245,23 @@  discard block
 block discarded – undo
2117 2245
 		if (!empty($context['theme_variant']))
2118 2246
 		{
2119 2247
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2120
-			if ($context['right_to_left'])
2121
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2248
+			if ($context['right_to_left']) {
2249
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2250
+			}
2122 2251
 		}
2123 2252
 	}
2124 2253
 
2125 2254
 	// Let's be compatible with old themes!
2126
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2127
-		$context['template_layers'] = array('main');
2255
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2256
+			$context['template_layers'] = array('main');
2257
+	}
2128 2258
 
2129 2259
 	$context['tabindex'] = 1;
2130 2260
 
2131 2261
 	// Compatibility.
2132
-	if (!isset($settings['theme_version']))
2133
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2262
+	if (!isset($settings['theme_version'])) {
2263
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2264
+	}
2134 2265
 
2135 2266
 	// Default JS variables for use in every theme
2136 2267
 	$context['javascript_vars'] = array(
@@ -2149,18 +2280,18 @@  discard block
 block discarded – undo
2149 2280
 	);
2150 2281
 
2151 2282
 	// Add the JQuery library to the list of files to load.
2152
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2153
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2154
-
2155
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2156
-		loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2157
-
2158
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2159
-		loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2283
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2284
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2285
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2286
+			loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2287
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2288
+			loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2289
+	}
2160 2290
 
2161 2291
 	// Auto loading? template_javascript() will take care of the local half of this.
2162
-	else
2163
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2292
+	else {
2293
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2294
+	}
2164 2295
 
2165 2296
 	// Queue our JQuery plugins!
2166 2297
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2183,12 +2314,12 @@  discard block
 block discarded – undo
2183 2314
 			require_once($sourcedir . '/ScheduledTasks.php');
2184 2315
 
2185 2316
 			// What to do, what to do?!
2186
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2187
-				AutoTask();
2188
-			else
2189
-				ReduceMailQueue();
2190
-		}
2191
-		else
2317
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2318
+							AutoTask();
2319
+			} else {
2320
+							ReduceMailQueue();
2321
+			}
2322
+		} else
2192 2323
 		{
2193 2324
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2194 2325
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2239,8 +2370,9 @@  discard block
 block discarded – undo
2239 2370
 		foreach ($theme_includes as $include)
2240 2371
 		{
2241 2372
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2242
-			if (file_exists($include))
2243
-				require_once($include);
2373
+			if (file_exists($include)) {
2374
+							require_once($include);
2375
+			}
2244 2376
 		}
2245 2377
 	}
2246 2378
 
@@ -2270,16 +2402,19 @@  discard block
 block discarded – undo
2270 2402
 	// Do any style sheets first, cause we're easy with those.
2271 2403
 	if (!empty($style_sheets))
2272 2404
 	{
2273
-		if (!is_array($style_sheets))
2274
-			$style_sheets = array($style_sheets);
2405
+		if (!is_array($style_sheets)) {
2406
+					$style_sheets = array($style_sheets);
2407
+		}
2275 2408
 
2276
-		foreach ($style_sheets as $sheet)
2277
-			loadCSSFile($sheet . '.css', array(), $sheet);
2409
+		foreach ($style_sheets as $sheet) {
2410
+					loadCSSFile($sheet . '.css', array(), $sheet);
2411
+		}
2278 2412
 	}
2279 2413
 
2280 2414
 	// No template to load?
2281
-	if ($template_name === false)
2282
-		return true;
2415
+	if ($template_name === false) {
2416
+			return true;
2417
+	}
2283 2418
 
2284 2419
 	$loaded = false;
2285 2420
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2294,12 +2429,14 @@  discard block
 block discarded – undo
2294 2429
 
2295 2430
 	if ($loaded)
2296 2431
 	{
2297
-		if ($db_show_debug === true)
2298
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2432
+		if ($db_show_debug === true) {
2433
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2434
+		}
2299 2435
 
2300 2436
 		// If they have specified an initialization function for this template, go ahead and call it now.
2301
-		if (function_exists('template_' . $template_name . '_init'))
2302
-			call_user_func('template_' . $template_name . '_init');
2437
+		if (function_exists('template_' . $template_name . '_init')) {
2438
+					call_user_func('template_' . $template_name . '_init');
2439
+		}
2303 2440
 	}
2304 2441
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2305 2442
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2319,13 +2456,14 @@  discard block
 block discarded – undo
2319 2456
 		loadTemplate($template_name);
2320 2457
 	}
2321 2458
 	// Cause an error otherwise.
2322
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2323
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2324
-	elseif ($fatal)
2325
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2326
-	else
2327
-		return false;
2328
-}
2459
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2460
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2461
+	} elseif ($fatal) {
2462
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2463
+	} else {
2464
+			return false;
2465
+	}
2466
+	}
2329 2467
 
2330 2468
 /**
2331 2469
  * Load a sub-template.
@@ -2343,17 +2481,19 @@  discard block
 block discarded – undo
2343 2481
 {
2344 2482
 	global $context, $txt, $db_show_debug;
2345 2483
 
2346
-	if ($db_show_debug === true)
2347
-		$context['debug']['sub_templates'][] = $sub_template_name;
2484
+	if ($db_show_debug === true) {
2485
+			$context['debug']['sub_templates'][] = $sub_template_name;
2486
+	}
2348 2487
 
2349 2488
 	// Figure out what the template function is named.
2350 2489
 	$theme_function = 'template_' . $sub_template_name;
2351
-	if (function_exists($theme_function))
2352
-		$theme_function();
2353
-	elseif ($fatal === false)
2354
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2355
-	elseif ($fatal !== 'ignore')
2356
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2490
+	if (function_exists($theme_function)) {
2491
+			$theme_function();
2492
+	} elseif ($fatal === false) {
2493
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2494
+	} elseif ($fatal !== 'ignore') {
2495
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2496
+	}
2357 2497
 
2358 2498
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2359 2499
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2390,8 +2530,9 @@  discard block
 block discarded – undo
2390 2530
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2391 2531
 
2392 2532
 	// If this is an external file, automatically set this to false.
2393
-	if (!empty($params['external']))
2394
-		$params['minimize'] = false;
2533
+	if (!empty($params['external'])) {
2534
+			$params['minimize'] = false;
2535
+	}
2395 2536
 
2396 2537
 	// Account for shorthand like admin.css?alp21 filenames
2397 2538
 	$has_seed = strpos($fileName, '.css?');
@@ -2408,13 +2549,10 @@  discard block
 block discarded – undo
2408 2549
 			{
2409 2550
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2410 2551
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2552
+			} else {
2553
+							$fileUrl = false;
2411 2554
 			}
2412
-
2413
-			else
2414
-				$fileUrl = false;
2415
-		}
2416
-
2417
-		else
2555
+		} else
2418 2556
 		{
2419 2557
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2420 2558
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2429,12 +2567,14 @@  discard block
 block discarded – undo
2429 2567
 	}
2430 2568
 
2431 2569
 	// Add it to the array for use in the template
2432
-	if (!empty($fileName))
2433
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2570
+	if (!empty($fileName)) {
2571
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2572
+	}
2434 2573
 
2435
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2436
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2437
-}
2574
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2575
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2576
+	}
2577
+	}
2438 2578
 
2439 2579
 /**
2440 2580
  * Add a block of inline css code to be executed later
@@ -2451,8 +2591,9 @@  discard block
 block discarded – undo
2451 2591
 	global $context;
2452 2592
 
2453 2593
 	// Gotta add something...
2454
-	if (empty($css))
2455
-		return false;
2594
+	if (empty($css)) {
2595
+			return false;
2596
+	}
2456 2597
 
2457 2598
 	$context['css_header'][] = $css;
2458 2599
 }
@@ -2487,8 +2628,9 @@  discard block
 block discarded – undo
2487 2628
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2488 2629
 
2489 2630
 	// If this is an external file, automatically set this to false.
2490
-	if (!empty($params['external']))
2491
-		$params['minimize'] = false;
2631
+	if (!empty($params['external'])) {
2632
+			$params['minimize'] = false;
2633
+	}
2492 2634
 
2493 2635
 	// Account for shorthand like admin.js?alp21 filenames
2494 2636
 	$has_seed = strpos($fileName, '.js?');
@@ -2505,16 +2647,12 @@  discard block
 block discarded – undo
2505 2647
 			{
2506 2648
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2507 2649
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2508
-			}
2509
-
2510
-			else
2650
+			} else
2511 2651
 			{
2512 2652
 				$fileUrl = false;
2513 2653
 				$filePath = false;
2514 2654
 			}
2515
-		}
2516
-
2517
-		else
2655
+		} else
2518 2656
 		{
2519 2657
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2520 2658
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2529,9 +2667,10 @@  discard block
 block discarded – undo
2529 2667
 	}
2530 2668
 
2531 2669
 	// Add it to the array for use in the template
2532
-	if (!empty($fileName))
2533
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2534
-}
2670
+	if (!empty($fileName)) {
2671
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2672
+	}
2673
+	}
2535 2674
 
2536 2675
 /**
2537 2676
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2545,9 +2684,10 @@  discard block
 block discarded – undo
2545 2684
 {
2546 2685
 	global $context;
2547 2686
 
2548
-	if (!empty($key) && (!empty($value) || $value === '0'))
2549
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2550
-}
2687
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2688
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2689
+	}
2690
+	}
2551 2691
 
2552 2692
 /**
2553 2693
  * Add a block of inline Javascript code to be executed later
@@ -2564,8 +2704,9 @@  discard block
 block discarded – undo
2564 2704
 {
2565 2705
 	global $context;
2566 2706
 
2567
-	if (empty($javascript))
2568
-		return false;
2707
+	if (empty($javascript)) {
2708
+			return false;
2709
+	}
2569 2710
 
2570 2711
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2571 2712
 }
@@ -2586,15 +2727,18 @@  discard block
 block discarded – undo
2586 2727
 	static $already_loaded = array();
2587 2728
 
2588 2729
 	// Default to the user's language.
2589
-	if ($lang == '')
2590
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2730
+	if ($lang == '') {
2731
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2732
+	}
2591 2733
 
2592 2734
 	// Do we want the English version of language file as fallback?
2593
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2594
-		loadLanguage($template_name, 'english', false);
2735
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2736
+			loadLanguage($template_name, 'english', false);
2737
+	}
2595 2738
 
2596
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2597
-		return $lang;
2739
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2740
+			return $lang;
2741
+	}
2598 2742
 
2599 2743
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2600 2744
 	if (empty($settings['default_theme_dir']))
@@ -2605,8 +2749,9 @@  discard block
 block discarded – undo
2605 2749
 
2606 2750
 	// What theme are we in?
2607 2751
 	$theme_name = basename($settings['theme_url']);
2608
-	if (empty($theme_name))
2609
-		$theme_name = 'unknown';
2752
+	if (empty($theme_name)) {
2753
+			$theme_name = 'unknown';
2754
+	}
2610 2755
 
2611 2756
 	// For each file open it up and write it out!
2612 2757
 	foreach (explode('+', $template_name) as $template)
@@ -2685,8 +2830,9 @@  discard block
 block discarded – undo
2685 2830
 	}
2686 2831
 
2687 2832
 	// Keep track of what we're up to soldier.
2688
-	if ($db_show_debug === true)
2689
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2833
+	if ($db_show_debug === true) {
2834
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2835
+	}
2690 2836
 
2691 2837
 	// Remember what we have loaded, and in which language.
2692 2838
 	$already_loaded[$template_name] = $lang;
@@ -2732,8 +2878,9 @@  discard block
 block discarded – undo
2732 2878
 				)
2733 2879
 			);
2734 2880
 			// In the EXTREMELY unlikely event this happens, give an error message.
2735
-			if ($smcFunc['db_num_rows']($result) == 0)
2736
-				fatal_lang_error('parent_not_found', 'critical');
2881
+			if ($smcFunc['db_num_rows']($result) == 0) {
2882
+							fatal_lang_error('parent_not_found', 'critical');
2883
+			}
2737 2884
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2738 2885
 			{
2739 2886
 				if (!isset($boards[$row['id_board']]))
@@ -2750,8 +2897,8 @@  discard block
 block discarded – undo
2750 2897
 					);
2751 2898
 				}
2752 2899
 				// If a moderator exists for this board, add that moderator for all children too.
2753
-				if (!empty($row['id_moderator']))
2754
-					foreach ($boards as $id => $dummy)
2900
+				if (!empty($row['id_moderator'])) {
2901
+									foreach ($boards as $id => $dummy)
2755 2902
 					{
2756 2903
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2757 2904
 							'id' => $row['id_moderator'],
@@ -2759,11 +2906,12 @@  discard block
 block discarded – undo
2759 2906
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2760 2907
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2761 2908
 						);
2909
+				}
2762 2910
 					}
2763 2911
 
2764 2912
 				// If a moderator group exists for this board, add that moderator group for all children too
2765
-				if (!empty($row['id_moderator_group']))
2766
-					foreach ($boards as $id => $dummy)
2913
+				if (!empty($row['id_moderator_group'])) {
2914
+									foreach ($boards as $id => $dummy)
2767 2915
 					{
2768 2916
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2769 2917
 							'id' => $row['id_moderator_group'],
@@ -2771,6 +2919,7 @@  discard block
 block discarded – undo
2771 2919
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2772 2920
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2773 2921
 						);
2922
+				}
2774 2923
 					}
2775 2924
 			}
2776 2925
 			$smcFunc['db_free_result']($result);
@@ -2798,23 +2947,27 @@  discard block
 block discarded – undo
2798 2947
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages' . ($favor_utf8 ? '' : '_all'), !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2799 2948
 	{
2800 2949
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2801
-		if (empty($smcFunc['ucwords']))
2802
-			reloadSettings();
2950
+		if (empty($smcFunc['ucwords'])) {
2951
+					reloadSettings();
2952
+		}
2803 2953
 
2804 2954
 		// If we don't have our theme information yet, let's get it.
2805
-		if (empty($settings['default_theme_dir']))
2806
-			loadTheme(0, false);
2955
+		if (empty($settings['default_theme_dir'])) {
2956
+					loadTheme(0, false);
2957
+		}
2807 2958
 
2808 2959
 		// Default language directories to try.
2809 2960
 		$language_directories = array(
2810 2961
 			$settings['default_theme_dir'] . '/languages',
2811 2962
 		);
2812
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2813
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2963
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2964
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2965
+		}
2814 2966
 
2815 2967
 		// We possibly have a base theme directory.
2816
-		if (!empty($settings['base_theme_dir']))
2817
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2968
+		if (!empty($settings['base_theme_dir'])) {
2969
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2970
+		}
2818 2971
 
2819 2972
 		// Remove any duplicates.
2820 2973
 		$language_directories = array_unique($language_directories);
@@ -2828,20 +2981,21 @@  discard block
 block discarded – undo
2828 2981
 		foreach ($language_directories as $language_dir)
2829 2982
 		{
2830 2983
 			// Can't look in here... doesn't exist!
2831
-			if (!file_exists($language_dir))
2832
-				continue;
2984
+			if (!file_exists($language_dir)) {
2985
+							continue;
2986
+			}
2833 2987
 
2834 2988
 			$dir = dir($language_dir);
2835 2989
 			while ($entry = $dir->read())
2836 2990
 			{
2837 2991
 				// Look for the index language file....
2838
-				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches))
2839
-					continue;
2840
-
2841
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2842
-					$langName = $langList[$matches[1]];
2992
+				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches)) {
2993
+									continue;
2994
+				}
2843 2995
 
2844
-				else
2996
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
2997
+									$langName = $langList[$matches[1]];
2998
+				} else
2845 2999
 				{
2846 3000
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2847 3001
 
@@ -2884,20 +3038,23 @@  discard block
 block discarded – undo
2884 3038
 		}
2885 3039
 
2886 3040
 		// Do we need to store the lang list?
2887
-		if (empty($langList))
2888
-			updateSettings(array('langList' => json_encode($catchLang)));
3041
+		if (empty($langList)) {
3042
+					updateSettings(array('langList' => json_encode($catchLang)));
3043
+		}
2889 3044
 
2890 3045
 		// Favoring UTF8? Then prevent us from selecting non-UTF8 versions.
2891 3046
 		if ($favor_utf8)
2892 3047
 		{
2893
-			foreach ($context['languages'] as $lang)
2894
-				if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
3048
+			foreach ($context['languages'] as $lang) {
3049
+							if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
2895 3050
 					unset($context['languages'][$lang['filename']]);
3051
+			}
2896 3052
 		}
2897 3053
 
2898 3054
 		// Let's cash in on this deal.
2899
-		if (!empty($modSettings['cache_enable']))
2900
-			cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3055
+		if (!empty($modSettings['cache_enable'])) {
3056
+					cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3057
+		}
2901 3058
 	}
2902 3059
 
2903 3060
 	return $context['languages'];
@@ -2920,8 +3077,9 @@  discard block
 block discarded – undo
2920 3077
 	global $modSettings, $options, $txt;
2921 3078
 	static $censor_vulgar = null, $censor_proper;
2922 3079
 
2923
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2924
-		return $text;
3080
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3081
+			return $text;
3082
+	}
2925 3083
 
2926 3084
 	// If they haven't yet been loaded, load them.
2927 3085
 	if ($censor_vulgar == null)
@@ -2949,9 +3107,9 @@  discard block
 block discarded – undo
2949 3107
 	{
2950 3108
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2951 3109
 		$text = $func($censor_vulgar, $censor_proper, $text);
3110
+	} else {
3111
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2952 3112
 	}
2953
-	else
2954
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2955 3113
 
2956 3114
 	return $text;
2957 3115
 }
@@ -2977,38 +3135,42 @@  discard block
 block discarded – undo
2977 3135
 	@ini_set('track_errors', '1');
2978 3136
 
2979 3137
 	// Don't include the file more than once, if $once is true.
2980
-	if ($once && in_array($filename, $templates))
2981
-		return;
3138
+	if ($once && in_array($filename, $templates)) {
3139
+			return;
3140
+	}
2982 3141
 	// Add this file to the include list, whether $once is true or not.
2983
-	else
2984
-		$templates[] = $filename;
3142
+	else {
3143
+			$templates[] = $filename;
3144
+	}
2985 3145
 
2986 3146
 	// Are we going to use eval?
2987 3147
 	if (empty($modSettings['disableTemplateEval']))
2988 3148
 	{
2989 3149
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2990 3150
 		$settings['current_include_filename'] = $filename;
2991
-	}
2992
-	else
3151
+	} else
2993 3152
 	{
2994 3153
 		$file_found = file_exists($filename);
2995 3154
 
2996
-		if ($once && $file_found)
2997
-			require_once($filename);
2998
-		elseif ($file_found)
2999
-			require($filename);
3155
+		if ($once && $file_found) {
3156
+					require_once($filename);
3157
+		} elseif ($file_found) {
3158
+					require($filename);
3159
+		}
3000 3160
 	}
3001 3161
 
3002 3162
 	if ($file_found !== true)
3003 3163
 	{
3004 3164
 		ob_end_clean();
3005
-		if (!empty($modSettings['enableCompressedOutput']))
3006
-			@ob_start('ob_gzhandler');
3007
-		else
3008
-			ob_start();
3165
+		if (!empty($modSettings['enableCompressedOutput'])) {
3166
+					@ob_start('ob_gzhandler');
3167
+		} else {
3168
+					ob_start();
3169
+		}
3009 3170
 
3010
-		if (isset($_GET['debug']))
3011
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3171
+		if (isset($_GET['debug'])) {
3172
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3173
+		}
3012 3174
 
3013 3175
 		// Don't cache error pages!!
3014 3176
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3027,12 +3189,13 @@  discard block
 block discarded – undo
3027 3189
 		echo '<!DOCTYPE html>
3028 3190
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3029 3191
 	<head>';
3030
-		if (isset($context['character_set']))
3031
-			echo '
3192
+		if (isset($context['character_set'])) {
3193
+					echo '
3032 3194
 		<meta charset="', $context['character_set'], '">';
3195
+		}
3033 3196
 
3034
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3035
-			echo '
3197
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3198
+					echo '
3036 3199
 		<title>', $mtitle, '</title>
3037 3200
 	</head>
3038 3201
 	<body>
@@ -3040,8 +3203,8 @@  discard block
 block discarded – undo
3040 3203
 		', $mmessage, '
3041 3204
 	</body>
3042 3205
 </html>';
3043
-		elseif (!allowedTo('admin_forum'))
3044
-			echo '
3206
+		} elseif (!allowedTo('admin_forum')) {
3207
+					echo '
3045 3208
 		<title>', $txt['template_parse_error'], '</title>
3046 3209
 	</head>
3047 3210
 	<body>
@@ -3049,15 +3212,17 @@  discard block
 block discarded – undo
3049 3212
 		', $txt['template_parse_error_message'], '
3050 3213
 	</body>
3051 3214
 </html>';
3052
-		else
3215
+		} else
3053 3216
 		{
3054 3217
 			require_once($sourcedir . '/Subs-Package.php');
3055 3218
 
3056 3219
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3057
-			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg))
3058
-				$error = $php_errormsg;
3059
-			if (empty($error))
3060
-				$error = $txt['template_parse_errmsg'];
3220
+			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) {
3221
+							$error = $php_errormsg;
3222
+			}
3223
+			if (empty($error)) {
3224
+							$error = $txt['template_parse_errmsg'];
3225
+			}
3061 3226
 
3062 3227
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3063 3228
 
@@ -3068,11 +3233,12 @@  discard block
 block discarded – undo
3068 3233
 		<h3>', $txt['template_parse_error'], '</h3>
3069 3234
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3070 3235
 
3071
-			if (!empty($error))
3072
-				echo '
3236
+			if (!empty($error)) {
3237
+							echo '
3073 3238
 		<hr>
3074 3239
 
3075 3240
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3241
+			}
3076 3242
 
3077 3243
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3078 3244
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3082,10 +3248,11 @@  discard block
 block discarded – undo
3082 3248
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3083 3249
 
3084 3250
 				// Fix the PHP code stuff...
3085
-				if (!isBrowser('gecko'))
3086
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3087
-				else
3088
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3251
+				if (!isBrowser('gecko')) {
3252
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3253
+				} else {
3254
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3255
+				}
3089 3256
 
3090 3257
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3091 3258
 				$j = -1;
@@ -3093,8 +3260,9 @@  discard block
 block discarded – undo
3093 3260
 				{
3094 3261
 					$j++;
3095 3262
 
3096
-					if (substr_count($line, '<br>') == 0)
3097
-						continue;
3263
+					if (substr_count($line, '<br>') == 0) {
3264
+											continue;
3265
+					}
3098 3266
 
3099 3267
 					$n = substr_count($line, '<br>');
3100 3268
 					for ($i = 0; $i < $n; $i++)
@@ -3113,38 +3281,42 @@  discard block
 block discarded – undo
3113 3281
 				// Figure out what the color coding was before...
3114 3282
 				$line = max($match[1] - 9, 1);
3115 3283
 				$last_line = '';
3116
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3117
-					if (strpos($data2[$line2], '<') !== false)
3284
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3285
+									if (strpos($data2[$line2], '<') !== false)
3118 3286
 					{
3119 3287
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3120 3288
 							$last_line = $color_match[1];
3289
+				}
3121 3290
 						break;
3122 3291
 					}
3123 3292
 
3124 3293
 				// Show the relevant lines...
3125 3294
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3126 3295
 				{
3127
-					if ($line == $match[1])
3128
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3296
+					if ($line == $match[1]) {
3297
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3298
+					}
3129 3299
 
3130 3300
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3131
-					if (isset($data2[$line]) && $data2[$line] != '')
3132
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3301
+					if (isset($data2[$line]) && $data2[$line] != '') {
3302
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3303
+					}
3133 3304
 
3134 3305
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3135 3306
 					{
3136 3307
 						$last_line = $color_match[1];
3137 3308
 						echo '</', substr($last_line, 1, 4), '>';
3309
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3310
+											$last_line = '';
3311
+					} elseif ($last_line != '' && $data2[$line] != '') {
3312
+											echo '</', substr($last_line, 1, 4), '>';
3138 3313
 					}
3139
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3140
-						$last_line = '';
3141
-					elseif ($last_line != '' && $data2[$line] != '')
3142
-						echo '</', substr($last_line, 1, 4), '>';
3143 3314
 
3144
-					if ($line == $match[1])
3145
-						echo '</pre></div><pre style="margin: 0;">';
3146
-					else
3147
-						echo "\n";
3315
+					if ($line == $match[1]) {
3316
+											echo '</pre></div><pre style="margin: 0;">';
3317
+					} else {
3318
+											echo "\n";
3319
+					}
3148 3320
 				}
3149 3321
 
3150 3322
 				echo '</pre></div>';
@@ -3168,8 +3340,9 @@  discard block
 block discarded – undo
3168 3340
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3169 3341
 
3170 3342
 	// Figure out what type of database we are using.
3171
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3172
-		$db_type = 'mysql';
3343
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3344
+			$db_type = 'mysql';
3345
+	}
3173 3346
 
3174 3347
 	// Load the file for the database.
3175 3348
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3177,8 +3350,9 @@  discard block
 block discarded – undo
3177 3350
 	$db_options = array();
3178 3351
 
3179 3352
 	// Add in the port if needed
3180
-	if (!empty($db_port))
3181
-		$db_options['port'] = $db_port;
3353
+	if (!empty($db_port)) {
3354
+			$db_options['port'] = $db_port;
3355
+	}
3182 3356
 
3183 3357
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3184 3358
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3197,13 +3371,15 @@  discard block
 block discarded – undo
3197 3371
 	}
3198 3372
 
3199 3373
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3200
-	if (!$db_connection)
3201
-		display_db_error();
3374
+	if (!$db_connection) {
3375
+			display_db_error();
3376
+	}
3202 3377
 
3203 3378
 	// If in SSI mode fix up the prefix.
3204
-	if (SMF == 'SSI')
3205
-		db_fix_prefix($db_prefix, $db_name);
3206
-}
3379
+	if (SMF == 'SSI') {
3380
+			db_fix_prefix($db_prefix, $db_name);
3381
+	}
3382
+	}
3207 3383
 
3208 3384
 /**
3209 3385
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3217,10 +3393,11 @@  discard block
 block discarded – undo
3217 3393
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3218 3394
 
3219 3395
 	// Not overriding this and we have a cacheAPI, send it back.
3220
-	if (empty($overrideCache) && is_object($cacheAPI))
3221
-		return $cacheAPI;
3222
-	elseif (is_null($cacheAPI))
3223
-		$cacheAPI = false;
3396
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3397
+			return $cacheAPI;
3398
+	} elseif (is_null($cacheAPI)) {
3399
+			$cacheAPI = false;
3400
+	}
3224 3401
 
3225 3402
 	// Make sure our class is in session.
3226 3403
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3241,8 +3418,9 @@  discard block
 block discarded – undo
3241 3418
 		if (!$testAPI->isSupported())
3242 3419
 		{
3243 3420
 			// Can we save ourselves?
3244
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3245
-				return loadCacheAccelerator(null, false);
3421
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3422
+							return loadCacheAccelerator(null, false);
3423
+			}
3246 3424
 			return false;
3247 3425
 		}
3248 3426
 
@@ -3254,9 +3432,9 @@  discard block
 block discarded – undo
3254 3432
 		{
3255 3433
 			$cacheAPI = $testAPI;
3256 3434
 			return $cacheAPI;
3435
+		} else {
3436
+					return $testAPI;
3257 3437
 		}
3258
-		else
3259
-			return $testAPI;
3260 3438
 	}
3261 3439
 }
3262 3440
 
@@ -3276,8 +3454,9 @@  discard block
 block discarded – undo
3276 3454
 
3277 3455
 	// @todo Why are we doing this if caching is disabled?
3278 3456
 
3279
-	if (function_exists('call_integration_hook'))
3280
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3457
+	if (function_exists('call_integration_hook')) {
3458
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3459
+	}
3281 3460
 
3282 3461
 	/* Refresh the cache if either:
3283 3462
 		1. Caching is disabled.
@@ -3291,16 +3470,19 @@  discard block
 block discarded – undo
3291 3470
 		require_once($sourcedir . '/' . $file);
3292 3471
 		$cache_block = call_user_func_array($function, $params);
3293 3472
 
3294
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3295
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3473
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3474
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3475
+		}
3296 3476
 	}
3297 3477
 
3298 3478
 	// Some cached data may need a freshening up after retrieval.
3299
-	if (!empty($cache_block['post_retri_eval']))
3300
-		eval($cache_block['post_retri_eval']);
3479
+	if (!empty($cache_block['post_retri_eval'])) {
3480
+			eval($cache_block['post_retri_eval']);
3481
+	}
3301 3482
 
3302
-	if (function_exists('call_integration_hook'))
3303
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3483
+	if (function_exists('call_integration_hook')) {
3484
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3485
+	}
3304 3486
 
3305 3487
 	return $cache_block['data'];
3306 3488
 }
@@ -3327,8 +3509,9 @@  discard block
 block discarded – undo
3327 3509
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3328 3510
 	global $cache_hits, $cache_count, $db_show_debug;
3329 3511
 
3330
-	if (empty($cache_enable) || empty($cacheAPI))
3331
-		return;
3512
+	if (empty($cache_enable) || empty($cacheAPI)) {
3513
+			return;
3514
+	}
3332 3515
 
3333 3516
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3334 3517
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3341,12 +3524,14 @@  discard block
 block discarded – undo
3341 3524
 	$value = $value === null ? null : json_encode($value);
3342 3525
 	$cacheAPI->putData($key, $value, $ttl);
3343 3526
 
3344
-	if (function_exists('call_integration_hook'))
3345
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3527
+	if (function_exists('call_integration_hook')) {
3528
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3529
+	}
3346 3530
 
3347
-	if (isset($db_show_debug) && $db_show_debug === true)
3348
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3349
-}
3531
+	if (isset($db_show_debug) && $db_show_debug === true) {
3532
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3533
+	}
3534
+	}
3350 3535
 
3351 3536
 /**
3352 3537
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3362,8 +3547,9 @@  discard block
 block discarded – undo
3362 3547
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3363 3548
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3364 3549
 
3365
-	if (empty($cache_enable) || empty($cacheAPI))
3366
-		return;
3550
+	if (empty($cache_enable) || empty($cacheAPI)) {
3551
+			return;
3552
+	}
3367 3553
 
3368 3554
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3369 3555
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3383,16 +3569,18 @@  discard block
 block discarded – undo
3383 3569
 
3384 3570
 		if (empty($value))
3385 3571
 		{
3386
-			if (!is_array($cache_misses))
3387
-				$cache_misses = array();
3572
+			if (!is_array($cache_misses)) {
3573
+							$cache_misses = array();
3574
+			}
3388 3575
 
3389 3576
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3390 3577
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3391 3578
 		}
3392 3579
 	}
3393 3580
 
3394
-	if (function_exists('call_integration_hook') && isset($value))
3395
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3581
+	if (function_exists('call_integration_hook') && isset($value)) {
3582
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3583
+	}
3396 3584
 
3397 3585
 	return empty($value) ? null : smf_json_decode($value, true);
3398 3586
 }
@@ -3414,8 +3602,9 @@  discard block
 block discarded – undo
3414 3602
 	global $cachedir, $sourcedir, $modSettings, $cacheAPI;
3415 3603
 
3416 3604
 	// If we can't get to the API, can't do this.
3417
-	if (empty($cacheAPI))
3418
-		return false;
3605
+	if (empty($cacheAPI)) {
3606
+			return false;
3607
+	}
3419 3608
 
3420 3609
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3421 3610
 	$value = $cacheAPI->cleanCache($type);
@@ -3440,8 +3629,9 @@  discard block
 block discarded – undo
3440 3629
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3441 3630
 
3442 3631
 	// Come on!
3443
-	if (empty($data))
3444
-		return array();
3632
+	if (empty($data)) {
3633
+			return array();
3634
+	}
3445 3635
 
3446 3636
 	// Set a nice default var.
3447 3637
 	$image = '';
@@ -3449,11 +3639,11 @@  discard block
 block discarded – undo
3449 3639
 	// Gravatar has been set as mandatory!
3450 3640
 	if (!empty($modSettings['gravatarOverride']))
3451 3641
 	{
3452
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3453
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3454
-
3455
-		else if (!empty($data['email']))
3456
-			$image = get_gravatar_url($data['email']);
3642
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3643
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3644
+		} else if (!empty($data['email'])) {
3645
+					$image = get_gravatar_url($data['email']);
3646
+		}
3457 3647
 	}
3458 3648
 
3459 3649
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3465,54 +3655,60 @@  discard block
 block discarded – undo
3465 3655
 			// Gravatar.
3466 3656
 			if (stristr($data['avatar'], 'gravatar://'))
3467 3657
 			{
3468
-				if ($data['avatar'] == 'gravatar://')
3469
-					$image = get_gravatar_url($data['email']);
3470
-
3471
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3472
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3658
+				if ($data['avatar'] == 'gravatar://') {
3659
+									$image = get_gravatar_url($data['email']);
3660
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3661
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3662
+				}
3473 3663
 			}
3474 3664
 
3475 3665
 			// External url.
3476 3666
 			else
3477 3667
 			{
3478 3668
 				// Using ssl?
3479
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3480
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3669
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3670
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3671
+				}
3481 3672
 
3482 3673
 				// Just a plain external url.
3483
-				else
3484
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3674
+				else {
3675
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3676
+				}
3485 3677
 			}
3486 3678
 		}
3487 3679
 
3488 3680
 		// Perhaps this user has an attachment as avatar...
3489
-		else if (!empty($data['filename']))
3490
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3681
+		else if (!empty($data['filename'])) {
3682
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3683
+		}
3491 3684
 
3492 3685
 		// Right... no avatar... use our default image.
3493
-		else
3494
-			$image = $modSettings['avatar_url'] . '/default.png';
3686
+		else {
3687
+					$image = $modSettings['avatar_url'] . '/default.png';
3688
+		}
3495 3689
 	}
3496 3690
 
3497 3691
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3498 3692
 
3499 3693
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3500
-	if (!empty($image))
3501
-		return array(
3694
+	if (!empty($image)) {
3695
+			return array(
3502 3696
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3503 3697
 			'image' => '<img class="avatar" src="' . $image . '" />',
3504 3698
 			'href' => $image,
3505 3699
 			'url' => $image,
3506 3700
 		);
3701
+	}
3507 3702
 
3508 3703
 	// Fallback to make life easier for everyone...
3509
-	else
3510
-		return array(
3704
+	else {
3705
+			return array(
3511 3706
 			'name' => '',
3512 3707
 			'image' => '',
3513 3708
 			'href' => '',
3514 3709
 			'url' => '',
3515 3710
 		);
3516
-}
3711
+	}
3712
+	}
3517 3713
 
3518 3714
 ?>
3519 3715
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Attachments.php 1 patch
Braces   +294 added lines, -222 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Check if the current directory is still valid or not.
@@ -28,22 +29,24 @@  discard block
 block discarded – undo
28 29
 	global $boarddir, $modSettings, $context;
29 30
 
30 31
 	// Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found.
31
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin')
32
-		$doit = true;
33
-	elseif (empty($modSettings['automanage_attachments']))
34
-		return;
35
-	elseif (!isset($_FILES))
36
-		return;
37
-	elseif (isset($_FILES['attachment']))
38
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
32
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') {
33
+			$doit = true;
34
+	} elseif (empty($modSettings['automanage_attachments'])) {
35
+			return;
36
+	} elseif (!isset($_FILES)) {
37
+			return;
38
+	} elseif (isset($_FILES['attachment'])) {
39
+			foreach ($_FILES['attachment']['tmp_name'] as $dummy)
39 40
 			if (!empty($dummy))
40 41
 			{
41 42
 				$doit = true;
43
+	}
42 44
 				break;
43 45
 			}
44 46
 
45
-	if (!isset($doit))
46
-		return;
47
+	if (!isset($doit)) {
48
+			return;
49
+	}
47 50
 
48 51
 	$year = date('Y');
49 52
 	$month = date('m');
@@ -55,21 +58,25 @@  discard block
 block discarded – undo
55 58
 
56 59
 	if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments']))
57 60
 	{
58
-			if (!is_array($modSettings['attachment_basedirectories']))
59
-				$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
61
+			if (!is_array($modSettings['attachment_basedirectories'])) {
62
+							$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
63
+			}
60 64
 			$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
65
+	} else {
66
+			$base_dir = 0;
61 67
 	}
62
-	else
63
-		$base_dir = 0;
64 68
 
65 69
 	if ($modSettings['automanage_attachments'] == 1)
66 70
 	{
67
-		if (!isset($modSettings['last_attachments_directory']))
68
-			$modSettings['last_attachments_directory'] = array();
69
-		if (!is_array($modSettings['last_attachments_directory']))
70
-			$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
71
-		if (!isset($modSettings['last_attachments_directory'][$base_dir]))
72
-			$modSettings['last_attachments_directory'][$base_dir] = 0;
71
+		if (!isset($modSettings['last_attachments_directory'])) {
72
+					$modSettings['last_attachments_directory'] = array();
73
+		}
74
+		if (!is_array($modSettings['last_attachments_directory'])) {
75
+					$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
76
+		}
77
+		if (!isset($modSettings['last_attachments_directory'][$base_dir])) {
78
+					$modSettings['last_attachments_directory'][$base_dir] = 0;
79
+		}
73 80
 	}
74 81
 
75 82
 	$basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
@@ -98,12 +105,14 @@  discard block
 block discarded – undo
98 105
 			$updir = '';
99 106
 	}
100 107
 
101
-	if (!is_array($modSettings['attachmentUploadDir']))
102
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
103
-	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir))
104
-		$outputCreation = automanage_attachments_create_directory($updir);
105
-	elseif (in_array($updir, $modSettings['attachmentUploadDir']))
106
-		$outputCreation = true;
108
+	if (!is_array($modSettings['attachmentUploadDir'])) {
109
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
110
+	}
111
+	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) {
112
+			$outputCreation = automanage_attachments_create_directory($updir);
113
+	} elseif (in_array($updir, $modSettings['attachmentUploadDir'])) {
114
+			$outputCreation = true;
115
+	}
107 116
 
108 117
 	if ($outputCreation)
109 118
 	{
@@ -140,8 +149,9 @@  discard block
 block discarded – undo
140 149
 		$count = count($tree);
141 150
 
142 151
 		$directory = attachments_init_dir($tree, $count);
143
-		if ($directory === false)
144
-			return false;
152
+		if ($directory === false) {
153
+					return false;
154
+		}
145 155
 	}
146 156
 
147 157
 	$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
@@ -169,8 +179,9 @@  discard block
 block discarded – undo
169 179
 	}
170 180
 
171 181
 	// Everything seems fine...let's create the .htaccess
172
-	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess'))
173
-		secureDirectory($updir, true);
182
+	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) {
183
+			secureDirectory($updir, true);
184
+	}
174 185
 
175 186
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
176 187
 	$updir = rtrim($updir, $sep);
@@ -202,8 +213,9 @@  discard block
 block discarded – undo
202 213
 {
203 214
 	global $modSettings, $boarddir;
204 215
 
205
-	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1))
206
-		return;
216
+	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) {
217
+			return;
218
+	}
207 219
 
208 220
 	$basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir;
209 221
 	// Just to be sure: I don't want directory separators at the end
@@ -215,13 +227,14 @@  discard block
 block discarded – undo
215 227
 	{
216 228
 		$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
217 229
 		$base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0;
230
+	} else {
231
+			$base_dir = 0;
218 232
 	}
219
-	else
220
-		$base_dir = 0;
221 233
 
222 234
 	// Get the last attachment directory for that base directory
223
-	if (empty($modSettings['last_attachments_directory'][$base_dir]))
224
-		$modSettings['last_attachments_directory'][$base_dir] = 0;
235
+	if (empty($modSettings['last_attachments_directory'][$base_dir])) {
236
+			$modSettings['last_attachments_directory'][$base_dir] = 0;
237
+	}
225 238
 	// And increment it.
226 239
 	$modSettings['last_attachments_directory'][$base_dir]++;
227 240
 
@@ -236,10 +249,10 @@  discard block
 block discarded – undo
236 249
 		$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
237 250
 
238 251
 		return true;
252
+	} else {
253
+			return false;
254
+	}
239 255
 	}
240
-	else
241
-		return false;
242
-}
243 256
 
244 257
 /**
245 258
  * Split a path into a list of all directories and subdirectories
@@ -257,12 +270,13 @@  discard block
 block discarded – undo
257 270
 			* in Windows we need to explode for both \ and /
258 271
 			* while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR)
259 272
 	*/
260
-	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
261
-		$tree = preg_split('#[\\\/]#', $directory);
262
-	else
273
+	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
274
+			$tree = preg_split('#[\\\/]#', $directory);
275
+	} else
263 276
 	{
264
-		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR)
265
-			return false;
277
+		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) {
278
+					return false;
279
+		}
266 280
 
267 281
 		$tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR));
268 282
 	}
@@ -286,10 +300,11 @@  discard block
 block discarded – undo
286 300
 		 //Better be sure that the first part of the path is actually a drive letter...
287 301
 		 //...even if, I should check this in the admin page...isn't it?
288 302
 		 //...NHAAA Let's leave space for users' complains! :P
289
-		if (preg_match('/^[a-z]:$/i', $tree[0]))
290
-			$directory = array_shift($tree);
291
-		else
292
-			return false;
303
+		if (preg_match('/^[a-z]:$/i', $tree[0])) {
304
+					$directory = array_shift($tree);
305
+		} else {
306
+					return false;
307
+		}
293 308
 
294 309
 		$count--;
295 310
 	}
@@ -304,18 +319,20 @@  discard block
 block discarded – undo
304 319
 	global $context, $modSettings, $smcFunc, $txt, $user_info;
305 320
 
306 321
 	// Make sure we're uploading to the right place.
307
-	if (!empty($modSettings['automanage_attachments']))
308
-		automanage_attachments_check_directory();
322
+	if (!empty($modSettings['automanage_attachments'])) {
323
+			automanage_attachments_check_directory();
324
+	}
309 325
 
310
-	if (!is_array($modSettings['attachmentUploadDir']))
311
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
326
+	if (!is_array($modSettings['attachmentUploadDir'])) {
327
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
328
+	}
312 329
 
313 330
 	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
314 331
 
315 332
 	// Is the attachments folder actualy there?
316
-	if (!empty($context['dir_creation_error']))
317
-		$initial_error = $context['dir_creation_error'];
318
-	elseif (!is_dir($context['attach_dir']))
333
+	if (!empty($context['dir_creation_error'])) {
334
+			$initial_error = $context['dir_creation_error'];
335
+	} elseif (!is_dir($context['attach_dir']))
319 336
 	{
320 337
 		$initial_error = 'attach_folder_warning';
321 338
 		log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical');
@@ -338,12 +355,12 @@  discard block
 block discarded – undo
338 355
 			);
339 356
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
340 357
 			$smcFunc['db_free_result']($request);
341
-		}
342
-		else
343
-			$context['attachments'] = array(
358
+		} else {
359
+					$context['attachments'] = array(
344 360
 				'quantity' => 0,
345 361
 				'total_size' => 0,
346 362
 			);
363
+		}
347 364
 	}
348 365
 
349 366
 	// Hmm. There are still files in session.
@@ -353,39 +370,44 @@  discard block
 block discarded – undo
353 370
 		// Let's try to keep them. But...
354 371
 		$ignore_temp = true;
355 372
 		// If new files are being added. We can't ignore those
356
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
357
-			if (!empty($dummy))
373
+		foreach ($_FILES['attachment']['tmp_name'] as $dummy) {
374
+					if (!empty($dummy))
358 375
 			{
359 376
 				$ignore_temp = false;
377
+		}
360 378
 				break;
361 379
 			}
362 380
 
363 381
 		// Need to make space for the new files. So, bye bye.
364 382
 		if (!$ignore_temp)
365 383
 		{
366
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
367
-				if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
384
+			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
385
+							if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
368 386
 					unlink($attachment['tmp_name']);
387
+			}
369 388
 
370 389
 			$context['we_are_history'] = $txt['error_temp_attachments_flushed'];
371 390
 			$_SESSION['temp_attachments'] = array();
372 391
 		}
373 392
 	}
374 393
 
375
-	if (!isset($_FILES['attachment']['name']))
376
-		$_FILES['attachment']['tmp_name'] = array();
394
+	if (!isset($_FILES['attachment']['name'])) {
395
+			$_FILES['attachment']['tmp_name'] = array();
396
+	}
377 397
 
378
-	if (!isset($_SESSION['temp_attachments']))
379
-		$_SESSION['temp_attachments'] = array();
398
+	if (!isset($_SESSION['temp_attachments'])) {
399
+			$_SESSION['temp_attachments'] = array();
400
+	}
380 401
 
381 402
 	// Remember where we are at. If it's anywhere at all.
382
-	if (!$ignore_temp)
383
-		$_SESSION['temp_attachments']['post'] = array(
403
+	if (!$ignore_temp) {
404
+			$_SESSION['temp_attachments']['post'] = array(
384 405
 			'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0,
385 406
 			'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0,
386 407
 			'topic' => !empty($topic) ? $topic : 0,
387 408
 			'board' => !empty($board) ? $board : 0,
388 409
 		);
410
+	}
389 411
 
390 412
 	// If we have an initial error, lets just display it.
391 413
 	if (!empty($initial_error))
@@ -393,9 +415,10 @@  discard block
 block discarded – undo
393 415
 		$_SESSION['temp_attachments']['initial_error'] = $initial_error;
394 416
 
395 417
 		// And delete the files 'cos they ain't going nowhere.
396
-		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
397
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
418
+		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
419
+					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
398 420
 				unlink($_FILES['attachment']['tmp_name'][$n]);
421
+		}
399 422
 
400 423
 		$_FILES['attachment']['tmp_name'] = array();
401 424
 	}
@@ -403,21 +426,24 @@  discard block
 block discarded – undo
403 426
 	// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
404 427
 	foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
405 428
 	{
406
-		if ($_FILES['attachment']['name'][$n] == '')
407
-			continue;
429
+		if ($_FILES['attachment']['name'][$n] == '') {
430
+					continue;
431
+		}
408 432
 
409 433
 		// First, let's first check for PHP upload errors.
410 434
 		$errors = array();
411 435
 		if (!empty($_FILES['attachment']['error'][$n]))
412 436
 		{
413
-			if ($_FILES['attachment']['error'][$n] == 2)
414
-				$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
415
-			elseif ($_FILES['attachment']['error'][$n] == 6)
416
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
417
-			else
418
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
419
-			if (empty($errors))
420
-				$errors[] = 'attach_php_error';
437
+			if ($_FILES['attachment']['error'][$n] == 2) {
438
+							$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
439
+			} elseif ($_FILES['attachment']['error'][$n] == 6) {
440
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
441
+			} else {
442
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
443
+			}
444
+			if (empty($errors)) {
445
+							$errors[] = 'attach_php_error';
446
+			}
421 447
 		}
422 448
 
423 449
 		// Try to move and rename the file before doing any more checks on it.
@@ -435,16 +461,16 @@  discard block
 block discarded – undo
435 461
 			);
436 462
 
437 463
 			// Move the file to the attachments folder with a temp name for now.
438
-			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
439
-				smf_chmod($destName, 0644);
440
-			else
464
+			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
465
+							smf_chmod($destName, 0644);
466
+			} else
441 467
 			{
442 468
 				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
443
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
444
-					unlink($_FILES['attachment']['tmp_name'][$n]);
469
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
470
+									unlink($_FILES['attachment']['tmp_name'][$n]);
471
+				}
445 472
 			}
446
-		}
447
-		else
473
+		} else
448 474
 		{
449 475
 			$_SESSION['temp_attachments'][$attachID] = array(
450 476
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -452,12 +478,14 @@  discard block
 block discarded – undo
452 478
 				'errors' => $errors,
453 479
 			);
454 480
 
455
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
456
-				unlink($_FILES['attachment']['tmp_name'][$n]);
481
+			if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
482
+							unlink($_FILES['attachment']['tmp_name'][$n]);
483
+			}
457 484
 		}
458 485
 		// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
459
-		if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
460
-			attachmentChecks($attachID);
486
+		if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
487
+					attachmentChecks($attachID);
488
+		}
461 489
 	}
462 490
 	// Mod authors, finally a hook to hang an alternate attachment upload system upon
463 491
 	// Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand())
@@ -484,21 +512,20 @@  discard block
 block discarded – undo
484 512
 	global $modSettings, $context, $sourcedir, $smcFunc;
485 513
 
486 514
 	// No data or missing data .... Not necessarily needed, but in case a mod author missed something.
487
-	if (empty($_SESSION['temp_attachments'][$attachID]))
488
-		$error = '$_SESSION[\'temp_attachments\'][$attachID]';
489
-
490
-	elseif (empty($attachID))
491
-		$error = '$attachID';
492
-
493
-	elseif (empty($context['attachments']))
494
-		$error = '$context[\'attachments\']';
495
-
496
-	elseif (empty($context['attach_dir']))
497
-		$error = '$context[\'attach_dir\']';
515
+	if (empty($_SESSION['temp_attachments'][$attachID])) {
516
+			$error = '$_SESSION[\'temp_attachments\'][$attachID]';
517
+	} elseif (empty($attachID)) {
518
+			$error = '$attachID';
519
+	} elseif (empty($context['attachments'])) {
520
+			$error = '$context[\'attachments\']';
521
+	} elseif (empty($context['attach_dir'])) {
522
+			$error = '$context[\'attach_dir\']';
523
+	}
498 524
 
499 525
 	// Let's get their attention.
500
-	if (!empty($error))
501
-		fatal_lang_error('attach_check_nag', 'debug', array($error));
526
+	if (!empty($error)) {
527
+			fatal_lang_error('attach_check_nag', 'debug', array($error));
528
+	}
502 529
 
503 530
 	// Just in case this slipped by the first checks, we stop it here and now
504 531
 	if ($_SESSION['temp_attachments'][$attachID]['size'] == 0)
@@ -527,8 +554,9 @@  discard block
 block discarded – undo
527 554
 			$size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']);
528 555
 			if (!(empty($size)) && ($size[2] != $old_format))
529 556
 			{
530
-				if (isset($context['validImageTypes'][$size[2]]))
531
-					$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
557
+				if (isset($context['validImageTypes'][$size[2]])) {
558
+									$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
559
+				}
532 560
 			}
533 561
 		}
534 562
 	}
@@ -582,42 +610,48 @@  discard block
 block discarded – undo
582 610
 				// Or, let the user know that it ain't gonna happen.
583 611
 				else
584 612
 				{
585
-					if (isset($context['dir_creation_error']))
586
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
587
-					else
588
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
613
+					if (isset($context['dir_creation_error'])) {
614
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
615
+					} else {
616
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
617
+					}
589 618
 				}
619
+			} else {
620
+							$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
590 621
 			}
591
-			else
592
-				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
593 622
 		}
594 623
 	}
595 624
 
596 625
 	// Is the file too big?
597 626
 	$context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size'];
598
-	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024)
599
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
627
+	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
628
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
629
+	}
600 630
 
601 631
 	// Check the total upload size for this post...
602
-	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024)
603
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
632
+	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) {
633
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
634
+	}
604 635
 
605 636
 	// Have we reached the maximum number of files we are allowed?
606 637
 	$context['attachments']['quantity']++;
607 638
 
608 639
 	// Set a max limit if none exists
609
-	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50)
610
-		$modSettings['attachmentNumPerPostLimit'] = 50;
640
+	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) {
641
+			$modSettings['attachmentNumPerPostLimit'] = 50;
642
+	}
611 643
 
612
-	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit'])
613
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
644
+	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) {
645
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
646
+	}
614 647
 
615 648
 	// File extension check
616 649
 	if (!empty($modSettings['attachmentCheckExtensions']))
617 650
 	{
618 651
 		$allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
619
-		foreach ($allowed as $k => $dummy)
620
-			$allowed[$k] = trim($dummy);
652
+		foreach ($allowed as $k => $dummy) {
653
+					$allowed[$k] = trim($dummy);
654
+		}
621 655
 
622 656
 		if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed))
623 657
 		{
@@ -629,10 +663,12 @@  discard block
 block discarded – undo
629 663
 	// Undo the math if there's an error
630 664
 	if (!empty($_SESSION['temp_attachments'][$attachID]['errors']))
631 665
 	{
632
-		if (isset($context['dir_size']))
633
-			$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
634
-		if (isset($context['dir_files']))
635
-			$context['dir_files']--;
666
+		if (isset($context['dir_size'])) {
667
+					$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
668
+		}
669
+		if (isset($context['dir_files'])) {
670
+					$context['dir_files']--;
671
+		}
636 672
 		$context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
637 673
 		$context['attachments']['quantity']--;
638 674
 		return false;
@@ -664,12 +700,14 @@  discard block
 block discarded – undo
664 700
 	if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
665 701
 	{
666 702
 		// Got a proper mime type?
667
-		if (!empty($size['mime']))
668
-			$attachmentOptions['mime_type'] = $size['mime'];
703
+		if (!empty($size['mime'])) {
704
+					$attachmentOptions['mime_type'] = $size['mime'];
705
+		}
669 706
 
670 707
 		// Otherwise a valid one?
671
-		elseif (isset($context['validImageTypes'][$size[2]]))
672
-			$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
708
+		elseif (isset($context['validImageTypes'][$size[2]])) {
709
+					$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
710
+		}
673 711
 	}
674 712
 
675 713
 	// It is possible we might have a MIME type that isn't actually an image but still have a size.
@@ -681,15 +719,17 @@  discard block
 block discarded – undo
681 719
 	}
682 720
 
683 721
 	// Get the hash if no hash has been given yet.
684
-	if (empty($attachmentOptions['file_hash']))
685
-		$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
722
+	if (empty($attachmentOptions['file_hash'])) {
723
+			$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
724
+	}
686 725
 
687 726
 	// Assuming no-one set the extension let's take a look at it.
688 727
 	if (empty($attachmentOptions['fileext']))
689 728
 	{
690 729
 		$attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
691
-		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name'])
692
-			$attachmentOptions['fileext'] = '';
730
+		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) {
731
+					$attachmentOptions['fileext'] = '';
732
+		}
693 733
 	}
694 734
 
695 735
 	// Last chance to change stuff!
@@ -698,8 +738,9 @@  discard block
 block discarded – undo
698 738
 	// Make sure the folder is valid...
699 739
 	$tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : smf_json_decode($modSettings['attachmentUploadDir'], true);
700 740
 	$folders = array_keys($tmp);
701
-	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders))
702
-		$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
741
+	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) {
742
+			$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
743
+	}
703 744
 
704 745
 	$smcFunc['db_insert']('',
705 746
 		'{db_prefix}attachments',
@@ -730,8 +771,8 @@  discard block
 block discarded – undo
730 771
 	rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
731 772
 
732 773
 	// If it's not approved then add to the approval queue.
733
-	if (!$attachmentOptions['approved'])
734
-		$smcFunc['db_insert']('',
774
+	if (!$attachmentOptions['approved']) {
775
+			$smcFunc['db_insert']('',
735 776
 			'{db_prefix}approval_queue',
736 777
 			array(
737 778
 				'id_attach' => 'int', 'id_msg' => 'int',
@@ -741,9 +782,11 @@  discard block
 block discarded – undo
741 782
 			),
742 783
 			array()
743 784
 		);
785
+	}
744 786
 
745
-	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height'])))
746
-		return true;
787
+	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) {
788
+			return true;
789
+	}
747 790
 
748 791
 	// Like thumbnails, do we?
749 792
 	if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight']))
@@ -754,13 +797,15 @@  discard block
 block discarded – undo
754 797
 			$size = @getimagesize($attachmentOptions['destination'] . '_thumb');
755 798
 			list ($thumb_width, $thumb_height) = $size;
756 799
 
757
-			if (!empty($size['mime']))
758
-				$thumb_mime = $size['mime'];
759
-			elseif (isset($context['validImageTypes'][$size[2]]))
760
-				$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
800
+			if (!empty($size['mime'])) {
801
+							$thumb_mime = $size['mime'];
802
+			} elseif (isset($context['validImageTypes'][$size[2]])) {
803
+							$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
804
+			}
761 805
 			// Lord only knows how this happened...
762
-			else
763
-				$thumb_mime = '';
806
+			else {
807
+							$thumb_mime = '';
808
+			}
764 809
 
765 810
 			$thumb_filename = $attachmentOptions['name'] . '_thumb';
766 811
 			$thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
@@ -840,15 +885,17 @@  discard block
 block discarded – undo
840 885
 	global $smcFunc;
841 886
 
842 887
 	// Oh, come on!
843
-	if (empty($attachIDs) || empty($msgID))
844
-		return false;
888
+	if (empty($attachIDs) || empty($msgID)) {
889
+			return false;
890
+	}
845 891
 
846 892
 	// "I see what is right and approve, but I do what is wrong."
847 893
 	call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID));
848 894
 
849 895
 	// One last check
850
-	if (empty($attachIDs))
851
-		return false;
896
+	if (empty($attachIDs)) {
897
+			return false;
898
+	}
852 899
 
853 900
 	// Perform.
854 901
 	$smcFunc['db_query']('', '
@@ -880,8 +927,9 @@  discard block
 block discarded – undo
880 927
 	$externalParse = false;
881 928
 
882 929
 	// Meh...
883
-	if (empty($attachID))
884
-		return 'attachments_no_data_loaded';
930
+	if (empty($attachID)) {
931
+			return 'attachments_no_data_loaded';
932
+	}
885 933
 
886 934
 	// Make it easy.
887 935
 	$msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
@@ -890,20 +938,23 @@  discard block
 block discarded – undo
890 938
 	$externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID));
891 939
 
892 940
 	// "I am innocent of the blood of this just person: see ye to it."
893
-	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse)))
894
-		return $externalParse;
941
+	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) {
942
+			return $externalParse;
943
+	}
895 944
 
896 945
 	//Are attachments enable?
897
-	if (empty($modSettings['attachmentEnable']))
898
-		return 'attachments_not_enable';
946
+	if (empty($modSettings['attachmentEnable'])) {
947
+			return 'attachments_not_enable';
948
+	}
899 949
 
900 950
 	// Previewing much? no msg ID has been set yet.
901 951
 	if (!empty($context['preview_message']))
902 952
 	{
903 953
 		$allAttachments = getAttachsByMsg(0);
904 954
 
905
-		if (empty($allAttachments[0][$attachID]))
906
-			return 'attachments_no_data_loaded';
955
+		if (empty($allAttachments[0][$attachID])) {
956
+					return 'attachments_no_data_loaded';
957
+		}
907 958
 
908 959
 		$attachContext = $allAttachments[0][$attachID];
909 960
 		$attachLoaded = loadAttachmentContext(0, $allAttachments);
@@ -916,57 +967,66 @@  discard block
 block discarded – undo
916 967
 		$attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>';
917 968
 
918 969
 		// Fix the thumbnail too, if the image has one.
919
-		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb']))
920
-			$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
970
+		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) {
971
+					$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
972
+		}
921 973
 
922 974
 		return $attachContext;
923 975
 	}
924 976
 
925 977
 	// There is always the chance someone else has already done our dirty work...
926 978
 	// If so, all pertinent checks were already done. Hopefully...
927
-	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID]))
928
-		return $context['current_attachments'][$attachID];
979
+	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) {
980
+			return $context['current_attachments'][$attachID];
981
+	}
929 982
 
930 983
 	// If we are lucky enough to be in $board's scope then check it!
931
-	if (!empty($board) && !allowedTo('view_attachments', $board))
932
-		return 'attachments_not_allowed_to_see';
984
+	if (!empty($board) && !allowedTo('view_attachments', $board)) {
985
+			return 'attachments_not_allowed_to_see';
986
+	}
933 987
 
934 988
 	// Get the message info associated with this particular attach ID.
935 989
 	$attachInfo = getAttachMsgInfo($attachID);
936 990
 
937 991
 	// There is always the chance this attachment no longer exists or isn't associated to a message anymore...
938
-	if (empty($attachInfo) || empty($attachInfo['msg']))
939
-		return 'attachments_no_msg_associated';
992
+	if (empty($attachInfo) || empty($attachInfo['msg'])) {
993
+			return 'attachments_no_msg_associated';
994
+	}
940 995
 
941 996
 	// Hold it! got the info now check if you can see this attachment.
942
-	if (!allowedTo('view_attachments', $attachInfo['board']))
943
-		return 'attachments_not_allowed_to_see';
997
+	if (!allowedTo('view_attachments', $attachInfo['board'])) {
998
+			return 'attachments_not_allowed_to_see';
999
+	}
944 1000
 
945 1001
 	$allAttachments = getAttachsByMsg($attachInfo['msg']);
946 1002
 	$attachContext = $allAttachments[$attachInfo['msg']][$attachID];
947 1003
 
948 1004
 	// No point in keep going further.
949
-	if (!allowedTo('view_attachments', $attachContext['board']))
950
-		return 'attachments_not_allowed_to_see';
1005
+	if (!allowedTo('view_attachments', $attachContext['board'])) {
1006
+			return 'attachments_not_allowed_to_see';
1007
+	}
951 1008
 
952 1009
 	// Load this particular attach's context.
953
-	if (!empty($attachContext))
954
-		$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1010
+	if (!empty($attachContext)) {
1011
+			$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1012
+	}
955 1013
 
956 1014
 	// One last check, you know, gotta be paranoid...
957
-	else
958
-		return 'attachments_no_data_loaded';
1015
+	else {
1016
+			return 'attachments_no_data_loaded';
1017
+	}
959 1018
 
960 1019
 	// This is the last "if" I promise!
961
-	if (empty($attachLoaded))
962
-		return 'attachments_no_data_loaded';
963
-
964
-	else
965
-		$attachContext = $attachLoaded[$attachID];
1020
+	if (empty($attachLoaded)) {
1021
+			return 'attachments_no_data_loaded';
1022
+	} else {
1023
+			$attachContext = $attachLoaded[$attachID];
1024
+	}
966 1025
 
967 1026
 	// You may or may not want to show this under the post.
968
-	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID]))
969
-		$context['show_attach_under_post'][$attachID] = $attachID;
1027
+	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) {
1028
+			$context['show_attach_under_post'][$attachID] = $attachID;
1029
+	}
970 1030
 
971 1031
 	// Last minute changes?
972 1032
 	call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext));
@@ -986,8 +1046,9 @@  discard block
 block discarded – undo
986 1046
 {
987 1047
 	global $smcFunc, $modSettings;
988 1048
 
989
-	if (empty($attachIDs))
990
-		return array();
1049
+	if (empty($attachIDs)) {
1050
+			return array();
1051
+	}
991 1052
 
992 1053
 	$return = array();
993 1054
 
@@ -1003,11 +1064,12 @@  discard block
 block discarded – undo
1003 1064
 		)
1004 1065
 	);
1005 1066
 
1006
-	if ($smcFunc['db_num_rows']($request) != 1)
1007
-		return array();
1067
+	if ($smcFunc['db_num_rows']($request) != 1) {
1068
+			return array();
1069
+	}
1008 1070
 
1009
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1010
-		$return[$row['id_attach']] = array(
1071
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1072
+			$return[$row['id_attach']] = array(
1011 1073
 			'name' => $smcFunc['htmlspecialchars']($row['filename']),
1012 1074
 			'size' => $row['size'],
1013 1075
 			'attachID' => $row['id_attach'],
@@ -1016,6 +1078,7 @@  discard block
 block discarded – undo
1016 1078
 			'mime_type' => $row['mime_type'],
1017 1079
 			'thumb' => $row['id_thumb'],
1018 1080
 		);
1081
+	}
1019 1082
 	$smcFunc['db_free_result']($request);
1020 1083
 
1021 1084
 	return $return;
@@ -1032,8 +1095,9 @@  discard block
 block discarded – undo
1032 1095
 {
1033 1096
 	global $smcFunc;
1034 1097
 
1035
-	if (empty($attachID))
1036
-		return array();
1098
+	if (empty($attachID)) {
1099
+			return array();
1100
+	}
1037 1101
 
1038 1102
 	$request = $smcFunc['db_query']('', '
1039 1103
 		SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board
@@ -1046,8 +1110,9 @@  discard block
 block discarded – undo
1046 1110
 		)
1047 1111
 	);
1048 1112
 
1049
-	if ($smcFunc['db_num_rows']($request) != 1)
1050
-		return array();
1113
+	if ($smcFunc['db_num_rows']($request) != 1) {
1114
+			return array();
1115
+	}
1051 1116
 
1052 1117
 	$row = $smcFunc['db_fetch_assoc']($request);
1053 1118
 	$smcFunc['db_free_result']($request);
@@ -1088,8 +1153,9 @@  discard block
 block discarded – undo
1088 1153
 		$temp = array();
1089 1154
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1090 1155
 		{
1091
-			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1092
-				continue;
1156
+			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1157
+							continue;
1158
+			}
1093 1159
 
1094 1160
 			$temp[$row['id_attach']] = $row;
1095 1161
 		}
@@ -1118,8 +1184,9 @@  discard block
 block discarded – undo
1118 1184
 {
1119 1185
 	global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc;
1120 1186
 
1121
-	if (empty($attachments) || empty($attachments[$id_msg]))
1122
-		return array();
1187
+	if (empty($attachments) || empty($attachments[$id_msg])) {
1188
+			return array();
1189
+	}
1123 1190
 
1124 1191
 	// Set up the attachment info - based on code by Meriadoc.
1125 1192
 	$attachmentData = array();
@@ -1143,11 +1210,13 @@  discard block
 block discarded – undo
1143 1210
 			);
1144 1211
 
1145 1212
 			// If something is unapproved we'll note it so we can sort them.
1146
-			if (!$attachment['approved'])
1147
-				$have_unapproved = true;
1213
+			if (!$attachment['approved']) {
1214
+							$have_unapproved = true;
1215
+			}
1148 1216
 
1149
-			if (!$attachmentData[$i]['is_image'])
1150
-				continue;
1217
+			if (!$attachmentData[$i]['is_image']) {
1218
+							continue;
1219
+			}
1151 1220
 
1152 1221
 			$attachmentData[$i]['real_width'] = $attachment['width'];
1153 1222
 			$attachmentData[$i]['width'] = $attachment['width'];
@@ -1168,12 +1237,12 @@  discard block
 block discarded – undo
1168 1237
 						// So what folder are we putting this image in?
1169 1238
 						if (!empty($modSettings['currentAttachmentUploadDir']))
1170 1239
 						{
1171
-							if (!is_array($modSettings['attachmentUploadDir']))
1172
-								$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1240
+							if (!is_array($modSettings['attachmentUploadDir'])) {
1241
+															$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1242
+							}
1173 1243
 							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
1174 1244
 							$id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
1175
-						}
1176
-						else
1245
+						} else
1177 1246
 						{
1178 1247
 							$path = $modSettings['attachmentUploadDir'];
1179 1248
 							$id_folder_thumb = 1;
@@ -1188,10 +1257,11 @@  discard block
 block discarded – undo
1188 1257
 						$thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : '';
1189 1258
 
1190 1259
 						// Figure out the mime type.
1191
-						if (!empty($size['mime']))
1192
-							$thumb_mime = $size['mime'];
1193
-						else
1194
-							$thumb_mime = 'image/' . $thumb_ext;
1260
+						if (!empty($size['mime'])) {
1261
+													$thumb_mime = $size['mime'];
1262
+						} else {
1263
+													$thumb_mime = 'image/' . $thumb_ext;
1264
+						}
1195 1265
 
1196 1266
 						$thumb_filename = $attachment['filename'] . '_thumb';
1197 1267
 						$thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
@@ -1238,11 +1308,12 @@  discard block
 block discarded – undo
1238 1308
 				}
1239 1309
 			}
1240 1310
 
1241
-			if (!empty($attachment['id_thumb']))
1242
-				$attachmentData[$i]['thumbnail'] = array(
1311
+			if (!empty($attachment['id_thumb'])) {
1312
+							$attachmentData[$i]['thumbnail'] = array(
1243 1313
 					'id' => $attachment['id_thumb'],
1244 1314
 					'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image',
1245 1315
 				);
1316
+			}
1246 1317
 			$attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
1247 1318
 
1248 1319
 			// If thumbnails are disabled, check the maximum size of the image.
@@ -1252,30 +1323,31 @@  discard block
 block discarded – undo
1252 1323
 				{
1253 1324
 					$attachmentData[$i]['width'] = $modSettings['max_image_width'];
1254 1325
 					$attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
1255
-				}
1256
-				elseif (!empty($modSettings['max_image_width']))
1326
+				} elseif (!empty($modSettings['max_image_width']))
1257 1327
 				{
1258 1328
 					$attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
1259 1329
 					$attachmentData[$i]['height'] = $modSettings['max_image_height'];
1260 1330
 				}
1261
-			}
1262
-			elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1331
+			} elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1263 1332
 			{
1264 1333
 				// If the image is too large to show inline, make it a popup.
1265
-				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height'])))
1266
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1267
-				else
1268
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1334
+				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) {
1335
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1336
+				} else {
1337
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1338
+				}
1269 1339
 			}
1270 1340
 
1271
-			if (!$attachmentData[$i]['thumbnail']['has_thumb'])
1272
-				$attachmentData[$i]['downloads']++;
1341
+			if (!$attachmentData[$i]['thumbnail']['has_thumb']) {
1342
+							$attachmentData[$i]['downloads']++;
1343
+			}
1273 1344
 		}
1274 1345
 	}
1275 1346
 
1276 1347
 	// Do we need to instigate a sort?
1277
-	if ($have_unapproved)
1278
-		usort($attachmentData, 'approved_attach_sort');
1348
+	if ($have_unapproved) {
1349
+			usort($attachmentData, 'approved_attach_sort');
1350
+	}
1279 1351
 
1280 1352
 	return $attachmentData;
1281 1353
 }
Please login to merge, or discard this patch.
Sources/QueryString.php 1 patch
Braces   +184 added lines, -130 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Clean the request variables - add html entities to GET and slashes if magic_quotes_gpc is Off.
@@ -44,22 +45,26 @@  discard block
 block discarded – undo
44 45
 	unset($GLOBALS['HTTP_POST_FILES'], $GLOBALS['HTTP_POST_FILES']);
45 46
 
46 47
 	// These keys shouldn't be set...ever.
47
-	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
48
-		die('Invalid request variable.');
48
+	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
49
+			die('Invalid request variable.');
50
+	}
49 51
 
50 52
 	// Same goes for numeric keys.
51
-	foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key)
52
-		if (is_numeric($key))
53
+	foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key) {
54
+			if (is_numeric($key))
53 55
 			die('Numeric request keys are invalid.');
56
+	}
54 57
 
55 58
 	// Numeric keys in cookies are less of a problem. Just unset those.
56
-	foreach ($_COOKIE as $key => $value)
57
-		if (is_numeric($key))
59
+	foreach ($_COOKIE as $key => $value) {
60
+			if (is_numeric($key))
58 61
 			unset($_COOKIE[$key]);
62
+	}
59 63
 
60 64
 	// Get the correct query string.  It may be in an environment variable...
61
-	if (!isset($_SERVER['QUERY_STRING']))
62
-		$_SERVER['QUERY_STRING'] = getenv('QUERY_STRING');
65
+	if (!isset($_SERVER['QUERY_STRING'])) {
66
+			$_SERVER['QUERY_STRING'] = getenv('QUERY_STRING');
67
+	}
63 68
 
64 69
 	// It seems that sticking a URL after the query string is mighty common, well, it's evil - don't.
65 70
 	if (strpos($_SERVER['QUERY_STRING'], 'http') === 0)
@@ -83,13 +88,14 @@  discard block
 block discarded – undo
83 88
 		parse_str(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr($_SERVER['QUERY_STRING'], array(';?' => '&', ';' => '&', '%00' => '', "\0" => ''))), $_GET);
84 89
 
85 90
 		// Magic quotes still applies with parse_str - so clean it up.
86
-		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
87
-			$_GET = $removeMagicQuoteFunction($_GET);
88
-	}
89
-	elseif (strpos(ini_get('arg_separator.input'), ';') !== false)
91
+		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
92
+					$_GET = $removeMagicQuoteFunction($_GET);
93
+		}
94
+	} elseif (strpos(ini_get('arg_separator.input'), ';') !== false)
90 95
 	{
91
-		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
92
-			$_GET = $removeMagicQuoteFunction($_GET);
96
+		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
97
+					$_GET = $removeMagicQuoteFunction($_GET);
98
+		}
93 99
 
94 100
 		// Search engines will send action=profile%3Bu=1, which confuses PHP.
95 101
 		foreach ($_GET as $k => $v)
@@ -102,8 +108,9 @@  discard block
 block discarded – undo
102 108
 				for ($i = 1, $n = count($temp); $i < $n; $i++)
103 109
 				{
104 110
 					@list ($key, $val) = @explode('=', $temp[$i], 2);
105
-					if (!isset($_GET[$key]))
106
-						$_GET[$key] = $val;
111
+					if (!isset($_GET[$key])) {
112
+											$_GET[$key] = $val;
113
+					}
107 114
 				}
108 115
 			}
109 116
 
@@ -120,18 +127,20 @@  discard block
 block discarded – undo
120 127
 	if (!empty($_SERVER['REQUEST_URI']))
121 128
 	{
122 129
 		// Remove the .html, assuming there is one.
123
-		if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm')
124
-			$request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.'));
125
-		else
126
-			$request = $_SERVER['REQUEST_URI'];
130
+		if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm') {
131
+					$request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.'));
132
+		} else {
133
+					$request = $_SERVER['REQUEST_URI'];
134
+		}
127 135
 
128 136
 		// @todo smflib.
129 137
 		// Replace 'index.php/a,b,c/d/e,f' with 'a=b,c&d=&e=f' and parse it into $_GET.
130 138
 		if (strpos($request, basename($scripturl) . '/') !== false)
131 139
 		{
132 140
 			parse_str(substr(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr(preg_replace('~/([^,/]+),~', '/$1=', substr($request, strpos($request, basename($scripturl)) + strlen(basename($scripturl)))), '/', '&')), 1), $temp);
133
-			if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
134
-				$temp = $removeMagicQuoteFunction($temp);
141
+			if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
142
+							$temp = $removeMagicQuoteFunction($temp);
143
+			}
135 144
 			$_GET += $temp;
136 145
 		}
137 146
 	}
@@ -142,9 +151,10 @@  discard block
 block discarded – undo
142 151
 		$_ENV = $removeMagicQuoteFunction($_ENV);
143 152
 		$_POST = $removeMagicQuoteFunction($_POST);
144 153
 		$_COOKIE = $removeMagicQuoteFunction($_COOKIE);
145
-		foreach ($_FILES as $k => $dummy)
146
-			if (isset($_FILES[$k]['name']))
154
+		foreach ($_FILES as $k => $dummy) {
155
+					if (isset($_FILES[$k]['name']))
147 156
 				$_FILES[$k]['name'] = $removeMagicQuoteFunction($_FILES[$k]['name']);
157
+		}
148 158
 	}
149 159
 
150 160
 	// Add entities to GET.  This is kinda like the slashes on everything else.
@@ -160,11 +170,13 @@  discard block
 block discarded – undo
160 170
 		$_REQUEST['board'] = (string) $_REQUEST['board'];
161 171
 
162 172
 		// If there's a slash in it, we've got a start value! (old, compatible links.)
163
-		if (strpos($_REQUEST['board'], '/') !== false)
164
-			list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']);
173
+		if (strpos($_REQUEST['board'], '/') !== false) {
174
+					list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']);
175
+		}
165 176
 		// Same idea, but dots.  This is the currently used format - ?board=1.0...
166
-		elseif (strpos($_REQUEST['board'], '.') !== false)
167
-			list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']);
177
+		elseif (strpos($_REQUEST['board'], '.') !== false) {
178
+					list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']);
179
+		}
168 180
 		// Now make absolutely sure it's a number.
169 181
 		$board = (int) $_REQUEST['board'];
170 182
 		$_REQUEST['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
@@ -173,12 +185,14 @@  discard block
 block discarded – undo
173 185
 		$_GET['board'] = $board;
174 186
 	}
175 187
 	// Well, $board is going to be a number no matter what.
176
-	else
177
-		$board = 0;
188
+	else {
189
+			$board = 0;
190
+	}
178 191
 
179 192
 	// If there's a threadid, it's probably an old YaBB SE link.  Flow with it.
180
-	if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic']))
181
-		$_REQUEST['topic'] = $_REQUEST['threadid'];
193
+	if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic'])) {
194
+			$_REQUEST['topic'] = $_REQUEST['threadid'];
195
+	}
182 196
 
183 197
 	// We've got topic!
184 198
 	if (isset($_REQUEST['topic']))
@@ -187,29 +201,34 @@  discard block
 block discarded – undo
187 201
 		$_REQUEST['topic'] = (string) $_REQUEST['topic'];
188 202
 
189 203
 		// Slash means old, beta style, formatting.  That's okay though, the link should still work.
190
-		if (strpos($_REQUEST['topic'], '/') !== false)
191
-			list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']);
204
+		if (strpos($_REQUEST['topic'], '/') !== false) {
205
+					list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']);
206
+		}
192 207
 		// Dots are useful and fun ;).  This is ?topic=1.15.
193
-		elseif (strpos($_REQUEST['topic'], '.') !== false)
194
-			list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']);
208
+		elseif (strpos($_REQUEST['topic'], '.') !== false) {
209
+					list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']);
210
+		}
195 211
 
196 212
 		$topic = (int) $_REQUEST['topic'];
197 213
 
198 214
 		// Now make sure the online log gets the right number.
199 215
 		$_GET['topic'] = $topic;
216
+	} else {
217
+			$topic = 0;
200 218
 	}
201
-	else
202
-		$topic = 0;
203 219
 
204 220
 	// There should be a $_REQUEST['start'], some at least.  If you need to default to other than 0, use $_GET['start'].
205
-	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647)
206
-		$_REQUEST['start'] = 0;
221
+	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) {
222
+			$_REQUEST['start'] = 0;
223
+	}
207 224
 
208 225
 	// The action needs to be a string and not an array or anything else
209
-	if (isset($_REQUEST['action']))
210
-		$_REQUEST['action'] = (string) $_REQUEST['action'];
211
-	if (isset($_GET['action']))
212
-		$_GET['action'] = (string) $_GET['action'];
226
+	if (isset($_REQUEST['action'])) {
227
+			$_REQUEST['action'] = (string) $_REQUEST['action'];
228
+	}
229
+	if (isset($_GET['action'])) {
230
+			$_GET['action'] = (string) $_GET['action'];
231
+	}
213 232
 
214 233
 	// Some mail providers like to encode semicolons in activation URLs...
215 234
 	if (!empty($_REQUEST['action']) && substr($_SERVER['QUERY_STRING'], 0, 18) == 'action=activate%3b')
@@ -235,29 +254,33 @@  discard block
 block discarded – undo
235 254
 	$_SERVER['BAN_CHECK_IP'] = $_SERVER['REMOTE_ADDR'];
236 255
 
237 256
 	// If we haven't specified how to handle Reverse Proxy IP headers, lets do what we always used to do.
238
-	if (!isset($modSettings['proxy_ip_header']))
239
-		$modSettings['proxy_ip_header'] = 'autodetect';
257
+	if (!isset($modSettings['proxy_ip_header'])) {
258
+			$modSettings['proxy_ip_header'] = 'autodetect';
259
+	}
240 260
 
241 261
 	// Which headers are we going to check for Reverse Proxy IP headers?
242
-	if ($modSettings['proxy_ip_header'] == 'disabled')
243
-		$reverseIPheaders = array();
244
-	elseif ($modSettings['proxy_ip_header'] == 'autodetect')
245
-		$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
246
-	else
247
-		$reverseIPheaders = array($modSettings['proxy_ip_header']);
262
+	if ($modSettings['proxy_ip_header'] == 'disabled') {
263
+			$reverseIPheaders = array();
264
+	} elseif ($modSettings['proxy_ip_header'] == 'autodetect') {
265
+			$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
266
+	} else {
267
+			$reverseIPheaders = array($modSettings['proxy_ip_header']);
268
+	}
248 269
 
249 270
 	// Find the user's IP address. (but don't let it give you 'unknown'!)
250 271
 	foreach ($reverseIPheaders as $proxyIPheader)
251 272
 	{
252 273
 		// Ignore if this is not set.
253
-		if (!isset($_SERVER[$proxyIPheader]))
254
-			continue;
274
+		if (!isset($_SERVER[$proxyIPheader])) {
275
+					continue;
276
+		}
255 277
 
256 278
 		if (!empty($modSettings['proxy_ip_servers']))
257 279
 		{
258
-			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy)
259
-				if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
280
+			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) {
281
+							if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
260 282
 					continue;
283
+			}
261 284
 		}
262 285
 
263 286
 		// If there are commas, get the last one.. probably.
@@ -277,8 +300,9 @@  discard block
 block discarded – undo
277 300
 
278 301
 						// Just incase we have a legacy IPv4 address.
279 302
 						// @ TODO: Convert to IPv6.
280
-						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
281
-							continue;
303
+						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
304
+													continue;
305
+						}
282 306
 					}
283 307
 
284 308
 					continue;
@@ -290,36 +314,40 @@  discard block
 block discarded – undo
290 314
 			}
291 315
 		}
292 316
 		// Otherwise just use the only one.
293
-		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0)
294
-			$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
295
-		elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
317
+		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) {
318
+					$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
319
+		} elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
296 320
 		{
297 321
 			$_SERVER[$proxyIPheader] = preg_replace('~^::ffff:(\d+\.\d+\.\d+\.\d+)~', '\1', $_SERVER[$proxyIPheader]);
298 322
 
299 323
 			// Just incase we have a legacy IPv4 address.
300 324
 			// @ TODO: Convert to IPv6.
301
-			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
302
-				continue;
325
+			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
326
+							continue;
327
+			}
303 328
 		}
304 329
 	}
305 330
 
306 331
 	// Make sure we know the URL of the current request.
307
-	if (empty($_SERVER['REQUEST_URI']))
308
-		$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
309
-	elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1)
310
-		$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
311
-	else
312
-		$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
332
+	if (empty($_SERVER['REQUEST_URI'])) {
333
+			$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
334
+	} elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) {
335
+			$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
336
+	} else {
337
+			$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
338
+	}
313 339
 
314 340
 	// And make sure HTTP_USER_AGENT is set.
315 341
 	$_SERVER['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES) : htmlspecialchars($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES)) : '';
316 342
 
317 343
 	// Some final checking.
318
-	if (!isValidIP($_SERVER['BAN_CHECK_IP']))
319
-		$_SERVER['BAN_CHECK_IP'] = '';
320
-	if ($_SERVER['REMOTE_ADDR'] == 'unknown')
321
-		$_SERVER['REMOTE_ADDR'] = '';
322
-}
344
+	if (!isValidIP($_SERVER['BAN_CHECK_IP'])) {
345
+			$_SERVER['BAN_CHECK_IP'] = '';
346
+	}
347
+	if ($_SERVER['REMOTE_ADDR'] == 'unknown') {
348
+			$_SERVER['REMOTE_ADDR'] = '';
349
+	}
350
+	}
323 351
 
324 352
 /**
325 353
  * Validates a IPv6 address. returns true if it is ipv6.
@@ -330,8 +358,9 @@  discard block
 block discarded – undo
330 358
 function isValidIPv6($ip)
331 359
 {
332 360
 	//looking for :
333
-	if (strpos($ip, ':') === false)
334
-		return false;
361
+	if (strpos($ip, ':') === false) {
362
+			return false;
363
+	}
335 364
 
336 365
 	//check valid address
337 366
 	return inet_pton($ip);
@@ -348,15 +377,17 @@  discard block
 block discarded – undo
348 377
 	static $expanded = array();
349 378
 
350 379
 	// Check if we have done this already.
351
-	if (isset($expanded[$ip]))
352
-		return $expanded[$ip];
380
+	if (isset($expanded[$ip])) {
381
+			return $expanded[$ip];
382
+	}
353 383
 
354 384
 	// Expand the IP out.
355 385
 	$expanded_ip = explode(':', expandIPv6($ip));
356 386
 
357 387
 	$new_ip = array();
358
-	foreach ($expanded_ip as $int)
359
-		$new_ip[] = hexdec($int);
388
+	foreach ($expanded_ip as $int) {
389
+			$new_ip[] = hexdec($int);
390
+	}
360 391
 
361 392
 	// Save this incase of repeated use.
362 393
 	$expanded[$ip] = $new_ip;
@@ -376,8 +407,9 @@  discard block
 block discarded – undo
376 407
 	static $converted = array();
377 408
 
378 409
 	// Check if we have done this already.
379
-	if (isset($converted[$addr]))
380
-		return $converted[$addr];
410
+	if (isset($converted[$addr])) {
411
+			return $converted[$addr];
412
+	}
381 413
 
382 414
 	// Check if there are segments missing, insert if necessary.
383 415
 	if (strpos($addr, '::') !== false)
@@ -387,18 +419,20 @@  discard block
 block discarded – undo
387 419
 		$part[1] = explode(':', $part[1]);
388 420
 		$missing = array();
389 421
 
390
-		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++)
391
-			array_push($missing, '0000');
422
+		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) {
423
+					array_push($missing, '0000');
424
+		}
392 425
 
393 426
 		$part = array_merge($part[0], $missing, $part[1]);
427
+	} else {
428
+			$part = explode(':', $addr);
394 429
 	}
395
-	else
396
-		$part = explode(':', $addr);
397 430
 
398 431
 	// Pad each segment until it has 4 digits.
399
-	foreach ($part as &$p)
400
-		while (strlen($p) < 4)
432
+	foreach ($part as &$p) {
433
+			while (strlen($p) < 4)
401 434
 			$p = '0' . $p;
435
+	}
402 436
 
403 437
 	unset($p);
404 438
 
@@ -409,11 +443,12 @@  discard block
 block discarded – undo
409 443
 	$converted[$addr] = $result;
410 444
 
411 445
 	// Quick check to make sure the length is as expected.
412
-	if (!$strict_check || strlen($result) == 39)
413
-		return $result;
414
-	else
415
-		return false;
416
-}
446
+	if (!$strict_check || strlen($result) == 39) {
447
+			return $result;
448
+	} else {
449
+			return false;
450
+	}
451
+	}
417 452
 
418 453
 
419 454
 /**
@@ -444,15 +479,17 @@  discard block
 block discarded – undo
444 479
 {
445 480
 	global $smcFunc;
446 481
 
447
-	if (!is_array($var))
448
-		return $smcFunc['db_escape_string']($var);
482
+	if (!is_array($var)) {
483
+			return $smcFunc['db_escape_string']($var);
484
+	}
449 485
 
450 486
 	// Reindex the array with slashes.
451 487
 	$new_var = array();
452 488
 
453 489
 	// Add slashes to every element, even the indexes!
454
-	foreach ($var as $k => $v)
455
-		$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
490
+	foreach ($var as $k => $v) {
491
+			$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
492
+	}
456 493
 
457 494
 	return $new_var;
458 495
 }
@@ -472,12 +509,14 @@  discard block
 block discarded – undo
472 509
 {
473 510
 	global $smcFunc;
474 511
 
475
-	if (!is_array($var))
476
-		return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
512
+	if (!is_array($var)) {
513
+			return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
514
+	}
477 515
 
478 516
 	// Add the htmlspecialchars to every element.
479
-	foreach ($var as $k => $v)
480
-		$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
517
+	foreach ($var as $k => $v) {
518
+			$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
519
+	}
481 520
 
482 521
 	return $var;
483 522
 }
@@ -495,15 +534,17 @@  discard block
 block discarded – undo
495 534
  */
496 535
 function urldecode__recursive($var, $level = 0)
497 536
 {
498
-	if (!is_array($var))
499
-		return urldecode($var);
537
+	if (!is_array($var)) {
538
+			return urldecode($var);
539
+	}
500 540
 
501 541
 	// Reindex the array...
502 542
 	$new_var = array();
503 543
 
504 544
 	// Add the htmlspecialchars to every element.
505
-	foreach ($var as $k => $v)
506
-		$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
545
+	foreach ($var as $k => $v) {
546
+			$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
547
+	}
507 548
 
508 549
 	return $new_var;
509 550
 }
@@ -521,15 +562,17 @@  discard block
 block discarded – undo
521 562
 {
522 563
 	global $smcFunc;
523 564
 
524
-	if (!is_array($var))
525
-		return $smcFunc['db_unescape_string']($var);
565
+	if (!is_array($var)) {
566
+			return $smcFunc['db_unescape_string']($var);
567
+	}
526 568
 
527 569
 	// Reindex the array without slashes, this time.
528 570
 	$new_var = array();
529 571
 
530 572
 	// Strip the slashes from every element.
531
-	foreach ($var as $k => $v)
532
-		$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
573
+	foreach ($var as $k => $v) {
574
+			$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
575
+	}
533 576
 
534 577
 	return $new_var;
535 578
 }
@@ -547,15 +590,17 @@  discard block
 block discarded – undo
547 590
  */
548 591
 function stripslashes__recursive($var, $level = 0)
549 592
 {
550
-	if (!is_array($var))
551
-		return stripslashes($var);
593
+	if (!is_array($var)) {
594
+			return stripslashes($var);
595
+	}
552 596
 
553 597
 	// Reindex the array without slashes, this time.
554 598
 	$new_var = array();
555 599
 
556 600
 	// Strip the slashes from every element.
557
-	foreach ($var as $k => $v)
558
-		$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
601
+	foreach ($var as $k => $v) {
602
+			$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
603
+	}
559 604
 
560 605
 	return $new_var;
561 606
 }
@@ -576,12 +621,14 @@  discard block
 block discarded – undo
576 621
 	global $smcFunc;
577 622
 
578 623
 	// Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160)
579
-	if (!is_array($var))
580
-		return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
624
+	if (!is_array($var)) {
625
+			return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
626
+	}
581 627
 
582 628
 	// Go through all the elements and remove the whitespace.
583
-	foreach ($var as $k => $v)
584
-		$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
629
+	foreach ($var as $k => $v) {
630
+			$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
631
+	}
585 632
 
586 633
 	return $var;
587 634
 }
@@ -646,30 +693,37 @@  discard block
 block discarded – undo
646 693
 	global $scripturl, $modSettings, $context;
647 694
 
648 695
 	// If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit.
649
-	if ($scripturl == '' || !defined('SID'))
650
-		return $buffer;
696
+	if ($scripturl == '' || !defined('SID')) {
697
+			return $buffer;
698
+	}
651 699
 
652 700
 	// Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit().  This doesn't work below PHP 4.3.0, because it makes the output buffer bigger.
653 701
 	// @todo smflib
654
-	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot'))
655
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
702
+	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) {
703
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
704
+	}
656 705
 	// Debugging templates, are we?
657
-	elseif (isset($_GET['debug']))
658
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
706
+	elseif (isset($_GET['debug'])) {
707
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
708
+	}
659 709
 
660 710
 	// This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo.
661 711
 	if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd'] || $context['server']['is_litespeed']))
662 712
 	{
663 713
 		// Let's do something special for session ids!
664
-		if (defined('SID') && SID != '')
665
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
714
+		if (defined('SID') && SID != '') {
715
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
666 716
 			{
667
-				global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
717
+				global $scripturl;
718
+		}
719
+		return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
668 720
 			}, $buffer);
669
-		else
670
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
721
+		else {
722
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
671 723
 			{
672
-				global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
724
+				global $scripturl;
725
+		}
726
+		return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
673 727
 			}, $buffer);
674 728
 	}
675 729
 
Please login to merge, or discard this patch.
Sources/Display.php 1 patch
Braces   +333 added lines, -249 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * The central part of the board - topic display.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	global $attachments, $messages_request, $language, $smcFunc;
35 36
 
36 37
 	// What are you gonna display if these are empty?!
37
-	if (empty($topic))
38
-		fatal_lang_error('no_board', false);
38
+	if (empty($topic)) {
39
+			fatal_lang_error('no_board', false);
40
+	}
39 41
 
40 42
 	// Load the proper template.
41 43
 	loadTemplate('Display');
@@ -52,15 +54,17 @@  discard block
 block discarded – undo
52 54
 	$context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
53 55
 
54 56
 	// Let's do some work on what to search index.
55
-	if (count($_GET) > 2)
56
-		foreach ($_GET as $k => $v)
57
+	if (count($_GET) > 2) {
58
+			foreach ($_GET as $k => $v)
57 59
 		{
58 60
 			if (!in_array($k, array('topic', 'board', 'start', session_name())))
59 61
 				$context['robot_no_index'] = true;
62
+	}
60 63
 		}
61 64
 
62
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
63
-		$context['robot_no_index'] = true;
65
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
66
+			$context['robot_no_index'] = true;
67
+	}
64 68
 
65 69
 	// Find the previous or next topic.  Make a fuss if there are no more.
66 70
 	if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next'))
@@ -172,8 +176,9 @@  discard block
 block discarded – undo
172 176
 			$topic_parameters
173 177
 	);
174 178
 
175
-	if ($smcFunc['db_num_rows']($request) == 0)
176
-		fatal_lang_error('not_a_topic', false, 404);
179
+	if ($smcFunc['db_num_rows']($request) == 0) {
180
+			fatal_lang_error('not_a_topic', false, 404);
181
+	}
177 182
 	$context['topicinfo'] = $smcFunc['db_fetch_assoc']($request);
178 183
 	$smcFunc['db_free_result']($request);
179 184
 
@@ -210,8 +215,9 @@  discard block
 block discarded – undo
210 215
 	$context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0;
211 216
 
212 217
 	// Add up unapproved replies to get real number of replies...
213
-	if ($modSettings['postmod_active'] && $approve_posts)
214
-		$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
218
+	if ($modSettings['postmod_active'] && $approve_posts) {
219
+			$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
220
+	}
215 221
 
216 222
 	// If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing.
217 223
 	if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts)
@@ -231,11 +237,11 @@  discard block
 block discarded – undo
231 237
 		$smcFunc['db_free_result']($request);
232 238
 
233 239
 		$context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0);
240
+	} elseif ($user_info['is_guest']) {
241
+			$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
242
+	} else {
243
+			$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
234 244
 	}
235
-	elseif ($user_info['is_guest'])
236
-		$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
237
-	else
238
-		$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
239 245
 
240 246
 	// The start isn't a number; it's information about what to do, where to go.
241 247
 	if (!is_numeric($_REQUEST['start']))
@@ -248,8 +254,7 @@  discard block
 block discarded – undo
248 254
 			{
249 255
 				$context['start_from'] = $context['total_visible_posts'] - 1;
250 256
 				$_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0;
251
-			}
252
-			else
257
+			} else
253 258
 			{
254 259
 				// Find the earliest unread message in the topic. (the use of topics here is just for both tables.)
255 260
 				$request = $smcFunc['db_query']('', '
@@ -277,9 +282,9 @@  discard block
 block discarded – undo
277 282
 		if (substr($_REQUEST['start'], 0, 4) == 'from')
278 283
 		{
279 284
 			$timestamp = (int) substr($_REQUEST['start'], 4);
280
-			if ($timestamp === 0)
281
-				$_REQUEST['start'] = 0;
282
-			else
285
+			if ($timestamp === 0) {
286
+							$_REQUEST['start'] = 0;
287
+			} else
283 288
 			{
284 289
 				// Find the number of messages posted before said time...
285 290
 				$request = $smcFunc['db_query']('', '
@@ -307,11 +312,11 @@  discard block
 block discarded – undo
307 312
 		elseif (substr($_REQUEST['start'], 0, 3) == 'msg')
308 313
 		{
309 314
 			$virtual_msg = (int) substr($_REQUEST['start'], 3);
310
-			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg'])
311
-				$context['start_from'] = $context['total_visible_posts'] - 1;
312
-			elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg'])
313
-				$context['start_from'] = 0;
314
-			else
315
+			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) {
316
+							$context['start_from'] = $context['total_visible_posts'] - 1;
317
+			} elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) {
318
+							$context['start_from'] = 0;
319
+			} else
315 320
 			{
316 321
 				// Find the start value for that message......
317 322
 				$request = $smcFunc['db_query']('', '
@@ -394,21 +399,25 @@  discard block
 block discarded – undo
394 399
 		);
395 400
 		while ($row = $smcFunc['db_fetch_assoc']($request))
396 401
 		{
397
-			if (empty($row['id_member']))
398
-				continue;
402
+			if (empty($row['id_member'])) {
403
+							continue;
404
+			}
399 405
 
400
-			if (!empty($row['online_color']))
401
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
402
-			else
403
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
406
+			if (!empty($row['online_color'])) {
407
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
408
+			} else {
409
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
410
+			}
404 411
 
405 412
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
406
-			if ($is_buddy)
407
-				$link = '<strong>' . $link . '</strong>';
413
+			if ($is_buddy) {
414
+							$link = '<strong>' . $link . '</strong>';
415
+			}
408 416
 
409 417
 			// Add them both to the list and to the more detailed list.
410
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
411
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
418
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
419
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
420
+			}
412 421
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
413 422
 				'id' => $row['id_member'],
414 423
 				'username' => $row['member_name'],
@@ -420,8 +429,9 @@  discard block
 block discarded – undo
420 429
 				'hidden' => empty($row['show_online']),
421 430
 			);
422 431
 
423
-			if (empty($row['show_online']))
424
-				$context['view_num_hidden']++;
432
+			if (empty($row['show_online'])) {
433
+							$context['view_num_hidden']++;
434
+			}
425 435
 		}
426 436
 
427 437
 		// The number of guests is equal to the rows minus the ones we actually used ;).
@@ -435,11 +445,13 @@  discard block
 block discarded – undo
435 445
 
436 446
 	// If all is set, but not allowed... just unset it.
437 447
 	$can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages'];
438
-	if (isset($_REQUEST['all']) && !$can_show_all)
439
-		unset($_REQUEST['all']);
448
+	if (isset($_REQUEST['all']) && !$can_show_all) {
449
+			unset($_REQUEST['all']);
450
+	}
440 451
 	// Otherwise, it must be allowed... so pretend start was -1.
441
-	elseif (isset($_REQUEST['all']))
442
-		$_REQUEST['start'] = -1;
452
+	elseif (isset($_REQUEST['all'])) {
453
+			$_REQUEST['start'] = -1;
454
+	}
443 455
 
444 456
 	// Construct the page index, allowing for the .START method...
445 457
 	$context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true);
@@ -476,8 +488,9 @@  discard block
 block discarded – undo
476 488
 			$_REQUEST['start'] = 0;
477 489
 		}
478 490
 		// They aren't using it, but the *option* is there, at least.
479
-		else
480
-			$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
491
+		else {
492
+					$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
493
+		}
481 494
 	}
482 495
 
483 496
 	// Build the link tree.
@@ -493,14 +506,16 @@  discard block
 block discarded – undo
493 506
 	if (!empty($board_info['moderators']))
494 507
 	{
495 508
 		// Add a link for each moderator...
496
-		foreach ($board_info['moderators'] as $mod)
497
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
509
+		foreach ($board_info['moderators'] as $mod) {
510
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
511
+		}
498 512
 	}
499 513
 	if (!empty($board_info['moderator_groups']))
500 514
 	{
501 515
 		// Add a link for each moderator group as well...
502
-		foreach ($board_info['moderator_groups'] as $mod_group)
503
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
516
+		foreach ($board_info['moderator_groups'] as $mod_group) {
517
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
518
+		}
504 519
 	}
505 520
 
506 521
 	if (!empty($context['link_moderators']))
@@ -531,9 +546,9 @@  discard block
 block discarded – undo
531 546
 	// For quick reply we need a response prefix in the default forum language.
532 547
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600)))
533 548
 	{
534
-		if ($language === $user_info['language'])
535
-			$context['response_prefix'] = $txt['response_prefix'];
536
-		else
549
+		if ($language === $user_info['language']) {
550
+					$context['response_prefix'] = $txt['response_prefix'];
551
+		} else
537 552
 		{
538 553
 			loadLanguage('index', $language, false);
539 554
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -565,8 +580,9 @@  discard block
 block discarded – undo
565 580
 			list($start, $end, $allday, $span, $tz_abbrev) = buildEventDatetimes($row);
566 581
 
567 582
 			// Sanity check
568
-			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
569
-				continue;
583
+			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
584
+							continue;
585
+			}
570 586
 
571 587
 			$linked_calendar_event = array(
572 588
 				'id' => $row['id_event'],
@@ -615,8 +631,9 @@  discard block
 block discarded – undo
615 631
 		}
616 632
 		$smcFunc['db_free_result']($request);
617 633
 
618
-		if (!empty($context['linked_calendar_events']))
619
-			$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
634
+		if (!empty($context['linked_calendar_events'])) {
635
+					$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
636
+		}
620 637
 	}
621 638
 
622 639
 	// Create the poll info if it exists.
@@ -689,20 +706,21 @@  discard block
 block discarded – undo
689 706
 				foreach ($guestinfo as $i => $guestvoted)
690 707
 				{
691 708
 					$guestvoted = explode(',', $guestvoted);
692
-					if ($guestvoted[0] == $context['topicinfo']['id_poll'])
693
-						break;
709
+					if ($guestvoted[0] == $context['topicinfo']['id_poll']) {
710
+											break;
711
+					}
694 712
 				}
695 713
 				// Has the poll been reset since guest voted?
696 714
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
697 715
 				{
698 716
 					// Remove the poll info from the cookie to allow guest to vote again
699 717
 					unset($guestinfo[$i]);
700
-					if (!empty($guestinfo))
701
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
702
-					else
703
-						unset($_COOKIE['guest_poll_vote']);
704
-				}
705
-				else
718
+					if (!empty($guestinfo)) {
719
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
720
+					} else {
721
+											unset($_COOKIE['guest_poll_vote']);
722
+					}
723
+				} else
706 724
 				{
707 725
 					// What did they vote for?
708 726
 					unset($guestvoted[0], $guestvoted[1]);
@@ -816,23 +834,29 @@  discard block
 block discarded – undo
816 834
 		// Build the poll moderation button array.
817 835
 		$context['poll_buttons'] = array();
818 836
 
819
-		if ($context['allow_return_vote'])
820
-			$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
837
+		if ($context['allow_return_vote']) {
838
+					$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
839
+		}
821 840
 
822
-		if ($context['show_view_results_button'])
823
-			$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
841
+		if ($context['show_view_results_button']) {
842
+					$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
843
+		}
824 844
 
825
-		if ($context['allow_change_vote'])
826
-			$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
845
+		if ($context['allow_change_vote']) {
846
+					$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
847
+		}
827 848
 
828
-		if ($context['allow_lock_poll'])
829
-			$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
849
+		if ($context['allow_lock_poll']) {
850
+					$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
851
+		}
830 852
 
831
-		if ($context['allow_edit_poll'])
832
-			$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
853
+		if ($context['allow_edit_poll']) {
854
+					$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
855
+		}
833 856
 
834
-		if ($context['can_remove_poll'])
835
-			$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
857
+		if ($context['can_remove_poll']) {
858
+					$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
859
+		}
836 860
 
837 861
 		// Allow mods to add additional buttons here
838 862
 		call_integration_hook('integrate_poll_buttons');
@@ -873,8 +897,9 @@  discard block
 block discarded – undo
873 897
 	$all_posters = array();
874 898
 	while ($row = $smcFunc['db_fetch_assoc']($request))
875 899
 	{
876
-		if (!empty($row['id_member']))
877
-			$all_posters[$row['id_msg']] = $row['id_member'];
900
+		if (!empty($row['id_member'])) {
901
+					$all_posters[$row['id_msg']] = $row['id_member'];
902
+		}
878 903
 		$messages[] = $row['id_msg'];
879 904
 	}
880 905
 	$smcFunc['db_free_result']($request);
@@ -886,8 +911,9 @@  discard block
 block discarded – undo
886 911
 	if (!$user_info['is_guest'] && !empty($messages))
887 912
 	{
888 913
 		$mark_at_msg = max($messages);
889
-		if ($mark_at_msg >= $context['topicinfo']['id_last_msg'])
890
-			$mark_at_msg = $modSettings['maxMsgID'];
914
+		if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) {
915
+					$mark_at_msg = $modSettings['maxMsgID'];
916
+		}
891 917
 		if ($mark_at_msg >= $context['topicinfo']['new_from'])
892 918
 		{
893 919
 			$smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace',
@@ -919,8 +945,9 @@  discard block
 block discarded – undo
919 945
 		while ($row = $smcFunc['db_fetch_assoc']($request))
920 946
 		{
921 947
 			// Find if this topic is marked for notification...
922
-			if (!empty($row['id_topic']))
923
-				$context['is_marked_notify'] = true;
948
+			if (!empty($row['id_topic'])) {
949
+							$context['is_marked_notify'] = true;
950
+			}
924 951
 
925 952
 			// Only do this once, but mark the notifications as "not sent yet" for next time.
926 953
 			if (!empty($row['sent']) && $do_once)
@@ -942,8 +969,9 @@  discard block
 block discarded – undo
942 969
 		}
943 970
 
944 971
 		// Have we recently cached the number of new topics in this board, and it's still a lot?
945
-		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5)
946
-			$_SESSION['topicseen_cache'][$board]--;
972
+		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) {
973
+					$_SESSION['topicseen_cache'][$board]--;
974
+		}
947 975
 		// Mark board as seen if this is the only new topic.
948 976
 		elseif (isset($_REQUEST['topicseen']))
949 977
 		{
@@ -967,14 +995,16 @@  discard block
 block discarded – undo
967 995
 			$smcFunc['db_free_result']($request);
968 996
 
969 997
 			// If there're no real new topics in this board, mark the board as seen.
970
-			if (empty($numNewTopics))
971
-				$_REQUEST['boardseen'] = true;
972
-			else
973
-				$_SESSION['topicseen_cache'][$board] = $numNewTopics;
998
+			if (empty($numNewTopics)) {
999
+							$_REQUEST['boardseen'] = true;
1000
+			} else {
1001
+							$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1002
+			}
974 1003
 		}
975 1004
 		// Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often.
976
-		elseif (isset($_SESSION['topicseen_cache'][$board]))
977
-			$_SESSION['topicseen_cache'][$board]--;
1005
+		elseif (isset($_SESSION['topicseen_cache'][$board])) {
1006
+					$_SESSION['topicseen_cache'][$board]--;
1007
+		}
978 1008
 
979 1009
 		// Mark board as seen if we came using last post link from BoardIndex. (or other places...)
980 1010
 		if (isset($_REQUEST['boardseen']))
@@ -1031,23 +1061,26 @@  discard block
 block discarded – undo
1031 1061
 			$temp = array();
1032 1062
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1033 1063
 			{
1034
-				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1035
-					continue;
1064
+				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1065
+									continue;
1066
+				}
1036 1067
 
1037 1068
 				$temp[$row['id_attach']] = $row;
1038 1069
 				$temp[$row['id_attach']]['topic'] = $topic;
1039 1070
 				$temp[$row['id_attach']]['board'] = $board;
1040 1071
 
1041
-				if (!isset($context['loaded_attachments'][$row['id_msg']]))
1042
-					$context['loaded_attachments'][$row['id_msg']] = array();
1072
+				if (!isset($context['loaded_attachments'][$row['id_msg']])) {
1073
+									$context['loaded_attachments'][$row['id_msg']] = array();
1074
+				}
1043 1075
 			}
1044 1076
 			$smcFunc['db_free_result']($request);
1045 1077
 
1046 1078
 			// This is better than sorting it with the query...
1047 1079
 			ksort($temp);
1048 1080
 
1049
-			foreach ($temp as $row)
1050
-				$context['loaded_attachments'][$row['id_msg']][] = $row;
1081
+			foreach ($temp as $row) {
1082
+							$context['loaded_attachments'][$row['id_msg']][] = $row;
1083
+			}
1051 1084
 		}
1052 1085
 
1053 1086
 		$msg_parameters = array(
@@ -1074,21 +1107,23 @@  discard block
 block discarded – undo
1074 1107
 		);
1075 1108
 
1076 1109
 		// And the likes
1077
-		if (!empty($modSettings['enable_likes']))
1078
-			$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1110
+		if (!empty($modSettings['enable_likes'])) {
1111
+					$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1112
+		}
1079 1113
 
1080 1114
 		// Go to the last message if the given time is beyond the time of the last message.
1081
-		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies'])
1082
-			$context['start_from'] = $context['topicinfo']['num_replies'];
1115
+		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) {
1116
+					$context['start_from'] = $context['topicinfo']['num_replies'];
1117
+		}
1083 1118
 
1084 1119
 		// Since the anchor information is needed on the top of the page we load these variables beforehand.
1085 1120
 		$context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
1086
-		if (empty($options['view_newest_first']))
1087
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1088
-		else
1089
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1090
-	}
1091
-	else
1121
+		if (empty($options['view_newest_first'])) {
1122
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1123
+		} else {
1124
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1125
+		}
1126
+	} else
1092 1127
 	{
1093 1128
 		$messages_request = false;
1094 1129
 		$context['first_message'] = 0;
@@ -1124,8 +1159,9 @@  discard block
 block discarded – undo
1124 1159
 		'can_see_likes' => 'likes_view',
1125 1160
 		'can_like' => 'likes_like',
1126 1161
 	);
1127
-	foreach ($common_permissions as $contextual => $perm)
1128
-		$context[$contextual] = allowedTo($perm);
1162
+	foreach ($common_permissions as $contextual => $perm) {
1163
+			$context[$contextual] = allowedTo($perm);
1164
+	}
1129 1165
 
1130 1166
 	// Permissions with _any/_own versions.  $context[YYY] => ZZZ_any/_own.
1131 1167
 	$anyown_permissions = array(
@@ -1138,8 +1174,9 @@  discard block
 block discarded – undo
1138 1174
 		'can_reply_unapproved' => 'post_unapproved_replies',
1139 1175
 		'can_view_warning' => 'profile_warning',
1140 1176
 	);
1141
-	foreach ($anyown_permissions as $contextual => $perm)
1142
-		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1177
+	foreach ($anyown_permissions as $contextual => $perm) {
1178
+			$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1179
+	}
1143 1180
 
1144 1181
 	if (!$user_info['is_admin'] && !$modSettings['topic_move_any'])
1145 1182
 	{
@@ -1185,8 +1222,9 @@  discard block
 block discarded – undo
1185 1222
 	// Check if the draft functions are enabled and that they have permission to use them (for quick reply.)
1186 1223
 	$context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply'];
1187 1224
 	$context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']);
1188
-	if (!empty($context['drafts_save']))
1189
-		loadLanguage('Drafts');
1225
+	if (!empty($context['drafts_save'])) {
1226
+			loadLanguage('Drafts');
1227
+	}
1190 1228
 
1191 1229
 	// When was the last time this topic was replied to?  Should we warn them about it?
1192 1230
 	if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky']))
@@ -1247,26 +1285,31 @@  discard block
 block discarded – undo
1247 1285
 	// Message icons - customized icons are off?
1248 1286
 	$context['icons'] = getMessageIcons($board);
1249 1287
 
1250
-	if (!empty($context['icons']))
1251
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1288
+	if (!empty($context['icons'])) {
1289
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1290
+	}
1252 1291
 
1253 1292
 	// Build the normal button array.
1254 1293
 	$context['normal_buttons'] = array();
1255 1294
 
1256
-	if ($context['can_reply'])
1257
-		$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1295
+	if ($context['can_reply']) {
1296
+			$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1297
+	}
1258 1298
 
1259
-	if ($context['can_add_poll'])
1260
-		$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1299
+	if ($context['can_add_poll']) {
1300
+			$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1301
+	}
1261 1302
 
1262
-	if ($context['can_mark_unread'])
1263
-		$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1303
+	if ($context['can_mark_unread']) {
1304
+			$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1305
+	}
1264 1306
 
1265
-	if ($context['can_print'])
1266
-		$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1307
+	if ($context['can_print']) {
1308
+			$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1309
+	}
1267 1310
 
1268
-	if ($context['can_set_notify'])
1269
-		$context['normal_buttons']['notify'] = array(
1311
+	if ($context['can_set_notify']) {
1312
+			$context['normal_buttons']['notify'] = array(
1270 1313
 			'text' => 'notify_topic_' . $context['topic_notification_mode'],
1271 1314
 			'sub_buttons' => array(
1272 1315
 				array(
@@ -1288,38 +1331,47 @@  discard block
 block discarded – undo
1288 1331
 				),
1289 1332
 			),
1290 1333
 		);
1334
+	}
1291 1335
 
1292 1336
 	// Build the mod button array
1293 1337
 	$context['mod_buttons'] = array();
1294 1338
 
1295
-	if ($context['can_move'])
1296
-		$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1339
+	if ($context['can_move']) {
1340
+			$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1341
+	}
1297 1342
 
1298
-	if ($context['can_delete'])
1299
-		$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1343
+	if ($context['can_delete']) {
1344
+			$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1345
+	}
1300 1346
 
1301
-	if ($context['can_lock'])
1302
-		$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1347
+	if ($context['can_lock']) {
1348
+			$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1349
+	}
1303 1350
 
1304
-	if ($context['can_sticky'])
1305
-		$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1351
+	if ($context['can_sticky']) {
1352
+			$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1353
+	}
1306 1354
 
1307
-	if ($context['can_merge'])
1308
-		$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1355
+	if ($context['can_merge']) {
1356
+			$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1357
+	}
1309 1358
 
1310
-	if ($context['calendar_post'])
1311
-		$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1359
+	if ($context['calendar_post']) {
1360
+			$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1361
+	}
1312 1362
 
1313 1363
 	// Restore topic. eh?  No monkey business.
1314
-	if ($context['can_restore_topic'])
1315
-		$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1364
+	if ($context['can_restore_topic']) {
1365
+			$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1366
+	}
1316 1367
 
1317 1368
 	// Show a message in case a recently posted message became unapproved.
1318 1369
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
1319 1370
 
1320 1371
 	// Don't want to show this forever...
1321
-	if ($context['becomesUnapproved'])
1322
-		unset($_SESSION['becomesUnapproved']);
1372
+	if ($context['becomesUnapproved']) {
1373
+			unset($_SESSION['becomesUnapproved']);
1374
+	}
1323 1375
 
1324 1376
 	// Allow adding new mod buttons easily.
1325 1377
 	// Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used
@@ -1328,12 +1380,14 @@  discard block
 block discarded – undo
1328 1380
 	call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons']));
1329 1381
 
1330 1382
 	// Load the drafts js file
1331
-	if ($context['drafts_autosave'])
1332
-		loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1383
+	if ($context['drafts_autosave']) {
1384
+			loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1385
+	}
1333 1386
 
1334 1387
 	// Spellcheck
1335
-	if ($context['show_spellchecking'])
1336
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1388
+	if ($context['show_spellchecking']) {
1389
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1390
+	}
1337 1391
 
1338 1392
 	// topic.js
1339 1393
 	loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic');
@@ -1367,16 +1421,19 @@  discard block
 block discarded – undo
1367 1421
 	static $counter = null;
1368 1422
 
1369 1423
 	// If the query returned false, bail.
1370
-	if ($messages_request == false)
1371
-		return false;
1424
+	if ($messages_request == false) {
1425
+			return false;
1426
+	}
1372 1427
 
1373 1428
 	// Remember which message this is.  (ie. reply #83)
1374
-	if ($counter === null || $reset)
1375
-		$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1429
+	if ($counter === null || $reset) {
1430
+			$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1431
+	}
1376 1432
 
1377 1433
 	// Start from the beginning...
1378
-	if ($reset)
1379
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1434
+	if ($reset) {
1435
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1436
+	}
1380 1437
 
1381 1438
 	// Attempt to get the next message.
1382 1439
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
@@ -1390,19 +1447,21 @@  discard block
 block discarded – undo
1390 1447
 	if (empty($context['icon_sources']))
1391 1448
 	{
1392 1449
 		$context['icon_sources'] = array();
1393
-		foreach ($context['stable_icons'] as $icon)
1394
-			$context['icon_sources'][$icon] = 'images_url';
1450
+		foreach ($context['stable_icons'] as $icon) {
1451
+					$context['icon_sources'][$icon] = 'images_url';
1452
+		}
1395 1453
 	}
1396 1454
 
1397 1455
 	// Message Icon Management... check the images exist.
1398 1456
 	if (empty($modSettings['messageIconChecks_disable']))
1399 1457
 	{
1400 1458
 		// If the current icon isn't known, then we need to do something...
1401
-		if (!isset($context['icon_sources'][$message['icon']]))
1402
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1459
+		if (!isset($context['icon_sources'][$message['icon']])) {
1460
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1461
+		}
1462
+	} elseif (!isset($context['icon_sources'][$message['icon']])) {
1463
+			$context['icon_sources'][$message['icon']] = 'images_url';
1403 1464
 	}
1404
-	elseif (!isset($context['icon_sources'][$message['icon']]))
1405
-		$context['icon_sources'][$message['icon']] = 'images_url';
1406 1465
 
1407 1466
 	// If you're a lazy bum, you probably didn't give a subject...
1408 1467
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1427,8 +1486,7 @@  discard block
 block discarded – undo
1427 1486
 		$memberContext[$message['id_member']]['email'] = $message['poster_email'];
1428 1487
 		$memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum');
1429 1488
 		$memberContext[$message['id_member']]['is_guest'] = true;
1430
-	}
1431
-	else
1489
+	} else
1432 1490
 	{
1433 1491
 		// Define this here to make things a bit more readable
1434 1492
 		$can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own'));
@@ -1451,8 +1509,9 @@  discard block
 block discarded – undo
1451 1509
 	$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
1452 1510
 
1453 1511
 	// If it's in the recycle bin we need to override whatever icon we did have.
1454
-	if (!empty($board_info['recycle']))
1455
-		$message['icon'] = 'recycled';
1512
+	if (!empty($board_info['recycle'])) {
1513
+			$message['icon'] = 'recycled';
1514
+	}
1456 1515
 
1457 1516
 	require_once($sourcedir . '/Subs-Attachments.php');
1458 1517
 
@@ -1496,32 +1555,36 @@  discard block
 block discarded – undo
1496 1555
 	}
1497 1556
 
1498 1557
 	// Are likes enable?
1499
-	if (!empty($modSettings['enable_likes']))
1500
-		$output['likes'] = array(
1558
+	if (!empty($modSettings['enable_likes'])) {
1559
+			$output['likes'] = array(
1501 1560
 			'count' => $message['likes'],
1502 1561
 			'you' => in_array($message['id_msg'], $context['my_likes']),
1503 1562
 			'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']),
1504 1563
 		);
1564
+	}
1505 1565
 
1506 1566
 	// Is this user the message author?
1507 1567
 	$output['is_message_author'] = $message['id_member'] == $user_info['id'];
1508
-	if (!empty($output['modified']['name']))
1509
-		$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1568
+	if (!empty($output['modified']['name'])) {
1569
+			$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1570
+	}
1510 1571
 
1511 1572
 	// Did they give a reason for editing?
1512
-	if (!empty($output['modified']['name']) && !empty($output['modified']['reason']))
1513
-		$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1573
+	if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) {
1574
+			$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1575
+	}
1514 1576
 
1515 1577
 	// Any custom profile fields?
1516
-	if (!empty($memberContext[$message['id_member']]['custom_fields']))
1517
-		foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1578
+	if (!empty($memberContext[$message['id_member']]['custom_fields'])) {
1579
+			foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1518 1580
 			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1581
+	}
1519 1582
 
1520
-	if (empty($options['view_newest_first']))
1521
-		$counter++;
1522
-
1523
-	else
1524
-		$counter--;
1583
+	if (empty($options['view_newest_first'])) {
1584
+			$counter++;
1585
+	} else {
1586
+			$counter--;
1587
+	}
1525 1588
 
1526 1589
 	call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter));
1527 1590
 
@@ -1547,21 +1610,23 @@  discard block
 block discarded – undo
1547 1610
 	$context['no_last_modified'] = true;
1548 1611
 
1549 1612
 	// Prevent a preview image from being displayed twice.
1550
-	if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview'))
1551
-		return;
1613
+	if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) {
1614
+			return;
1615
+	}
1552 1616
 
1553 1617
 	// Make sure some attachment was requested!
1554
-	if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id']))
1555
-		fatal_lang_error('no_access', false);
1618
+	if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) {
1619
+			fatal_lang_error('no_access', false);
1620
+	}
1556 1621
 
1557 1622
 	$_REQUEST['attach'] = isset($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : (int) $_REQUEST['id'];
1558 1623
 
1559 1624
 	// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
1560 1625
 	$attachRequest = null;
1561 1626
 	call_integration_hook('integrate_download_request', array(&$attachRequest));
1562
-	if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest))
1563
-		$request = $attachRequest;
1564
-	else
1627
+	if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) {
1628
+			$request = $attachRequest;
1629
+	} else
1565 1630
 	{
1566 1631
 		// This checks only the current board for $board/$topic's permissions.
1567 1632
 		isAllowedTo('view_attachments');
@@ -1582,19 +1647,21 @@  discard block
 block discarded – undo
1582 1647
 		);
1583 1648
 	}
1584 1649
 
1585
-	if ($smcFunc['db_num_rows']($request) == 0)
1586
-		fatal_lang_error('no_access', false);
1650
+	if ($smcFunc['db_num_rows']($request) == 0) {
1651
+			fatal_lang_error('no_access', false);
1652
+	}
1587 1653
 
1588 1654
 	list ($id_folder, $real_filename, $file_hash, $file_ext, $id_attach, $attachment_type, $mime_type, $is_approved, $id_member) = $smcFunc['db_fetch_row']($request);
1589 1655
 	$smcFunc['db_free_result']($request);
1590 1656
 
1591 1657
 	// If it isn't yet approved, do they have permission to view it?
1592
-	if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3))
1593
-		isAllowedTo('approve_posts');
1658
+	if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) {
1659
+			isAllowedTo('approve_posts');
1660
+	}
1594 1661
 
1595 1662
 	// Update the download counter (unless it's a thumbnail).
1596
-	if ($attachment_type != 3)
1597
-		$smcFunc['db_query']('attach_download_increase', '
1663
+	if ($attachment_type != 3) {
1664
+			$smcFunc['db_query']('attach_download_increase', '
1598 1665
 			UPDATE LOW_PRIORITY {db_prefix}attachments
1599 1666
 			SET downloads = downloads + 1
1600 1667
 			WHERE id_attach = {int:id_attach}',
@@ -1602,15 +1669,15 @@  discard block
 block discarded – undo
1602 1669
 				'id_attach' => $id_attach,
1603 1670
 			)
1604 1671
 		);
1672
+	}
1605 1673
 
1606 1674
 	$filename = getAttachmentFilename($real_filename, $_REQUEST['attach'], $id_folder, false, $file_hash);
1607 1675
 
1608 1676
 	// This is done to clear any output that was made before now.
1609 1677
 	ob_end_clean();
1610
-	if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java')))
1611
-		@ob_start('ob_gzhandler');
1612
-
1613
-	else
1678
+	if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) {
1679
+			@ob_start('ob_gzhandler');
1680
+	} else
1614 1681
 	{
1615 1682
 		ob_start();
1616 1683
 		header('Content-Encoding: none');
@@ -1653,8 +1720,9 @@  discard block
 block discarded – undo
1653 1720
 	// Send the attachment headers.
1654 1721
 	header('Pragma: ');
1655 1722
 
1656
-	if (!isBrowser('gecko'))
1657
-		header('Content-Transfer-Encoding: binary');
1723
+	if (!isBrowser('gecko')) {
1724
+			header('Content-Transfer-Encoding: binary');
1725
+	}
1658 1726
 
1659 1727
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
1660 1728
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT');
@@ -1663,18 +1731,19 @@  discard block
 block discarded – undo
1663 1731
 	header('ETag: ' . $eTag);
1664 1732
 
1665 1733
 	// Make sure the mime type warrants an inline display.
1666
-	if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0)
1667
-		unset($_REQUEST['image']);
1734
+	if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) {
1735
+			unset($_REQUEST['image']);
1736
+	}
1668 1737
 
1669 1738
 	// Does this have a mime type?
1670
-	elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff'))))
1671
-		header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp')));
1672
-
1673
-	else
1739
+	elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) {
1740
+			header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp')));
1741
+	} else
1674 1742
 	{
1675 1743
 		header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
1676
-		if (isset($_REQUEST['image']))
1677
-			unset($_REQUEST['image']);
1744
+		if (isset($_REQUEST['image'])) {
1745
+					unset($_REQUEST['image']);
1746
+		}
1678 1747
 	}
1679 1748
 
1680 1749
 	// Convert the file to UTF-8, cuz most browsers dig that.
@@ -1682,23 +1751,22 @@  discard block
 block discarded – undo
1682 1751
 	$disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline';
1683 1752
 
1684 1753
 	// Different browsers like different standards...
1685
-	if (isBrowser('firefox'))
1686
-		header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
1687
-
1688
-	elseif (isBrowser('opera'))
1689
-		header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
1690
-
1691
-	elseif (isBrowser('ie'))
1692
-		header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
1693
-
1694
-	else
1695
-		header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
1754
+	if (isBrowser('firefox')) {
1755
+			header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
1756
+	} elseif (isBrowser('opera')) {
1757
+			header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
1758
+	} elseif (isBrowser('ie')) {
1759
+			header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
1760
+	} else {
1761
+			header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
1762
+	}
1696 1763
 
1697 1764
 	// If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE.
1698
-	if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff')))
1699
-		header('Cache-Control: no-cache');
1700
-	else
1701
-		header('Cache-Control: max-age=' . (525600 * 60) . ', private');
1765
+	if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) {
1766
+			header('Cache-Control: no-cache');
1767
+	} else {
1768
+			header('Cache-Control: max-age=' . (525600 * 60) . ', private');
1769
+	}
1702 1770
 
1703 1771
 	header('Content-Length: ' . filesize($filename));
1704 1772
 
@@ -1708,20 +1776,23 @@  discard block
 block discarded – undo
1708 1776
 	// Recode line endings for text files, if enabled.
1709 1777
 	if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file_ext, array('txt', 'css', 'htm', 'html', 'php', 'xml')))
1710 1778
 	{
1711
-		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false)
1712
-			$callback = function($buffer)
1779
+		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) {
1780
+					$callback = function($buffer)
1713 1781
 			{
1714 1782
 				return preg_replace('~[\r]?\n~', "\r\n", $buffer);
1783
+		}
1715 1784
 			};
1716
-		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false)
1717
-			$callback = function($buffer)
1785
+		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) {
1786
+					$callback = function($buffer)
1718 1787
 			{
1719 1788
 				return preg_replace('~[\r]?\n~', "\r", $buffer);
1789
+		}
1720 1790
 			};
1721
-		else
1722
-			$callback = function($buffer)
1791
+		else {
1792
+					$callback = function($buffer)
1723 1793
 			{
1724 1794
 				return preg_replace('~[\r]?\n~', "\n", $buffer);
1795
+		}
1725 1796
 			};
1726 1797
 	}
1727 1798
 
@@ -1729,23 +1800,26 @@  discard block
 block discarded – undo
1729 1800
 	if (filesize($filename) > 4194304)
1730 1801
 	{
1731 1802
 		// Forcibly end any output buffering going on.
1732
-		while (@ob_get_level() > 0)
1733
-			@ob_end_clean();
1803
+		while (@ob_get_level() > 0) {
1804
+					@ob_end_clean();
1805
+		}
1734 1806
 
1735 1807
 		$fp = fopen($filename, 'rb');
1736 1808
 		while (!feof($fp))
1737 1809
 		{
1738
-			if (isset($callback))
1739
-				echo $callback(fread($fp, 8192));
1740
-			else
1741
-				echo fread($fp, 8192);
1810
+			if (isset($callback)) {
1811
+							echo $callback(fread($fp, 8192));
1812
+			} else {
1813
+							echo fread($fp, 8192);
1814
+			}
1742 1815
 			flush();
1743 1816
 		}
1744 1817
 		fclose($fp);
1745 1818
 	}
1746 1819
 	// On some of the less-bright hosts, readfile() is disabled.  It's just a faster, more byte safe, version of what's in the if.
1747
-	elseif (isset($callback) || @readfile($filename) === null)
1748
-		echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename);
1820
+	elseif (isset($callback) || @readfile($filename) === null) {
1821
+			echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename);
1822
+	}
1749 1823
 
1750 1824
 	obExit(false);
1751 1825
 }
@@ -1758,8 +1832,9 @@  discard block
 block discarded – undo
1758 1832
  */
1759 1833
 function approved_attach_sort($a, $b)
1760 1834
 {
1761
-	if ($a['is_approved'] == $b['is_approved'])
1762
-		return 0;
1835
+	if ($a['is_approved'] == $b['is_approved']) {
1836
+			return 0;
1837
+	}
1763 1838
 
1764 1839
 	return $a['is_approved'] > $b['is_approved'] ? -1 : 1;
1765 1840
 }
@@ -1776,16 +1851,19 @@  discard block
 block discarded – undo
1776 1851
 
1777 1852
 	require_once($sourcedir . '/RemoveTopic.php');
1778 1853
 
1779
-	if (empty($_REQUEST['msgs']))
1780
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1854
+	if (empty($_REQUEST['msgs'])) {
1855
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1856
+	}
1781 1857
 
1782 1858
 	$messages = array();
1783
-	foreach ($_REQUEST['msgs'] as $dummy)
1784
-		$messages[] = (int) $dummy;
1859
+	foreach ($_REQUEST['msgs'] as $dummy) {
1860
+			$messages[] = (int) $dummy;
1861
+	}
1785 1862
 
1786 1863
 	// We are restoring messages. We handle this in another place.
1787
-	if (isset($_REQUEST['restore_selected']))
1788
-		redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1864
+	if (isset($_REQUEST['restore_selected'])) {
1865
+			redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1866
+	}
1789 1867
 	if (isset($_REQUEST['split_selection']))
1790 1868
 	{
1791 1869
 		$request = $smcFunc['db_query']('', '
@@ -1804,8 +1882,9 @@  discard block
 block discarded – undo
1804 1882
 	}
1805 1883
 
1806 1884
 	// Allowed to delete any message?
1807
-	if (allowedTo('delete_any'))
1808
-		$allowed_all = true;
1885
+	if (allowedTo('delete_any')) {
1886
+			$allowed_all = true;
1887
+	}
1809 1888
 	// Allowed to delete replies to their messages?
1810 1889
 	elseif (allowedTo('delete_replies'))
1811 1890
 	{
@@ -1822,13 +1901,14 @@  discard block
 block discarded – undo
1822 1901
 		$smcFunc['db_free_result']($request);
1823 1902
 
1824 1903
 		$allowed_all = $starter == $user_info['id'];
1904
+	} else {
1905
+			$allowed_all = false;
1825 1906
 	}
1826
-	else
1827
-		$allowed_all = false;
1828 1907
 
1829 1908
 	// Make sure they're allowed to delete their own messages, if not any.
1830
-	if (!$allowed_all)
1831
-		isAllowedTo('delete_own');
1909
+	if (!$allowed_all) {
1910
+			isAllowedTo('delete_own');
1911
+	}
1832 1912
 
1833 1913
 	// Allowed to remove which messages?
1834 1914
 	$request = $smcFunc['db_query']('', '
@@ -1848,8 +1928,9 @@  discard block
 block discarded – undo
1848 1928
 	$messages = array();
1849 1929
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1850 1930
 	{
1851
-		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
1852
-			continue;
1931
+		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
1932
+					continue;
1933
+		}
1853 1934
 
1854 1935
 		$messages[$row['id_msg']] = array($row['subject'], $row['id_member']);
1855 1936
 	}
@@ -1872,17 +1953,20 @@  discard block
 block discarded – undo
1872 1953
 	foreach ($messages as $message => $info)
1873 1954
 	{
1874 1955
 		// Just skip the first message - if it's not the last.
1875
-		if ($message == $first_message && $message != $last_message)
1876
-			continue;
1956
+		if ($message == $first_message && $message != $last_message) {
1957
+					continue;
1958
+		}
1877 1959
 		// If the first message is going then don't bother going back to the topic as we're effectively deleting it.
1878
-		elseif ($message == $first_message)
1879
-			$topicGone = true;
1960
+		elseif ($message == $first_message) {
1961
+					$topicGone = true;
1962
+		}
1880 1963
 
1881 1964
 		removeMessage($message);
1882 1965
 
1883 1966
 		// Log this moderation action ;).
1884
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
1885
-			logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1967
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
1968
+					logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1969
+		}
1886 1970
 	}
1887 1971
 
1888 1972
 	redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']);
Please login to merge, or discard this patch.
Sources/ManageMembers.php 1 patch
Braces   +158 added lines, -116 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main entrance point for the Manage Members screen.
@@ -62,16 +63,18 @@  discard block
 block discarded – undo
62 63
 	$context['activation_numbers'] = array();
63 64
 	$context['awaiting_activation'] = 0;
64 65
 	$context['awaiting_approval'] = 0;
65
-	while ($row = $smcFunc['db_fetch_assoc']($request))
66
-		$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
66
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
67
+			$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
68
+	}
67 69
 	$smcFunc['db_free_result']($request);
68 70
 
69 71
 	foreach ($context['activation_numbers'] as $activation_type => $total_members)
70 72
 	{
71
-		if (in_array($activation_type, array(0, 2)))
72
-			$context['awaiting_activation'] += $total_members;
73
-		elseif (in_array($activation_type, array(3, 4, 5)))
74
-			$context['awaiting_approval'] += $total_members;
73
+		if (in_array($activation_type, array(0, 2))) {
74
+					$context['awaiting_activation'] += $total_members;
75
+		} elseif (in_array($activation_type, array(3, 4, 5))) {
76
+					$context['awaiting_approval'] += $total_members;
77
+		}
75 78
 	}
76 79
 
77 80
 	// For the page header... do we show activation?
@@ -124,8 +127,9 @@  discard block
 block discarded – undo
124 127
 	}
125 128
 	if (!$context['show_approve'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'approve'))
126 129
 	{
127
-		if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate'))
128
-			$context['tabs']['search']['is_last'] = true;
130
+		if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate')) {
131
+					$context['tabs']['search']['is_last'] = true;
132
+		}
129 133
 		unset($context['tabs']['approve']);
130 134
 	}
131 135
 
@@ -157,8 +161,9 @@  discard block
 block discarded – undo
157 161
 		foreach ($_POST['delete'] as $key => $value)
158 162
 		{
159 163
 			// Don't delete yourself, idiot.
160
-			if ($value != $user_info['id'])
161
-				$delete[$key] = (int) $value;
164
+			if ($value != $user_info['id']) {
165
+							$delete[$key] = (int) $value;
166
+			}
162 167
 		}
163 168
 
164 169
 		if (!empty($delete))
@@ -194,17 +199,18 @@  discard block
 block discarded – undo
194 199
 		);
195 200
 		while ($row = $smcFunc['db_fetch_assoc']($request))
196 201
 		{
197
-			if ($row['min_posts'] == -1)
198
-				$context['membergroups'][] = array(
202
+			if ($row['min_posts'] == -1) {
203
+							$context['membergroups'][] = array(
199 204
 					'id' => $row['id_group'],
200 205
 					'name' => $row['group_name'],
201 206
 					'can_be_additional' => true
202 207
 				);
203
-			else
204
-				$context['postgroups'][] = array(
208
+			} else {
209
+							$context['postgroups'][] = array(
205 210
 					'id' => $row['id_group'],
206 211
 					'name' => $row['group_name']
207 212
 				);
213
+			}
208 214
 		}
209 215
 		$smcFunc['db_free_result']($request);
210 216
 
@@ -268,14 +274,15 @@  discard block
 block discarded – undo
268 274
 		call_integration_hook('integrate_view_members_params', array(&$params));
269 275
 
270 276
 		$search_params = array();
271
-		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types']))
272
-			$search_params = smf_json_decode(base64_decode($_REQUEST['params']), true);
273
-		elseif (!empty($_POST))
277
+		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) {
278
+					$search_params = smf_json_decode(base64_decode($_REQUEST['params']), true);
279
+		} elseif (!empty($_POST))
274 280
 		{
275 281
 			$search_params['types'] = $_POST['types'];
276
-			foreach ($params as $param_name => $param_info)
277
-				if (isset($_POST[$param_name]))
282
+			foreach ($params as $param_name => $param_info) {
283
+							if (isset($_POST[$param_name]))
278 284
 					$search_params[$param_name] = $_POST[$param_name];
285
+			}
279 286
 		}
280 287
 
281 288
 		$search_url_params = isset($search_params) ? base64_encode(json_encode($search_params)) : null;
@@ -288,18 +295,21 @@  discard block
 block discarded – undo
288 295
 		foreach ($params as $param_name => $param_info)
289 296
 		{
290 297
 			// Not filled in?
291
-			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '')
292
-				continue;
298
+			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') {
299
+							continue;
300
+			}
293 301
 
294 302
 			// Make sure numeric values are really numeric.
295
-			if (in_array($param_info['type'], array('int', 'age')))
296
-				$search_params[$param_name] = (int) $search_params[$param_name];
303
+			if (in_array($param_info['type'], array('int', 'age'))) {
304
+							$search_params[$param_name] = (int) $search_params[$param_name];
305
+			}
297 306
 			// Date values have to match the specified format.
298 307
 			elseif ($param_info['type'] == 'date')
299 308
 			{
300 309
 				// Check if this date format is valid.
301
-				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0)
302
-					continue;
310
+				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) {
311
+									continue;
312
+				}
303 313
 
304 314
 				$search_params[$param_name] = strtotime($search_params[$param_name]);
305 315
 			}
@@ -308,8 +318,9 @@  discard block
 block discarded – undo
308 318
 			if (!empty($param_info['range']))
309 319
 			{
310 320
 				// Default to '=', just in case...
311
-				if (empty($range_trans[$search_params['types'][$param_name]]))
312
-					$search_params['types'][$param_name] = '=';
321
+				if (empty($range_trans[$search_params['types'][$param_name]])) {
322
+									$search_params['types'][$param_name] = '=';
323
+				}
313 324
 
314 325
 				// Handle special case 'age'.
315 326
 				if ($param_info['type'] == 'age')
@@ -337,29 +348,30 @@  discard block
 block discarded – undo
337 348
 				elseif ($param_info['type'] == 'date' && $search_params['types'][$param_name] == '=')
338 349
 				{
339 350
 					$query_parts[] = $param_info['db_fields'][0] . ' > ' . $search_params[$param_name] . ' AND ' . $param_info['db_fields'][0] . ' < ' . ($search_params[$param_name] + 86400);
351
+				} else {
352
+									$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
340 353
 				}
341
-				else
342
-					$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
343 354
 			}
344 355
 			// Checkboxes.
345 356
 			elseif ($param_info['type'] == 'checkbox')
346 357
 			{
347 358
 				// Each checkbox or no checkbox at all is checked -> ignore.
348
-				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values']))
349
-					continue;
359
+				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) {
360
+									continue;
361
+				}
350 362
 
351 363
 				$query_parts[] = ($param_info['db_fields'][0]) . ' IN ({array_string:' . $param_name . '_check})';
352 364
 				$where_params[$param_name . '_check'] = $search_params[$param_name];
353
-			}
354
-			else
365
+			} else
355 366
 			{
356 367
 				// Replace the wildcard characters ('*' and '?') into MySQL ones.
357 368
 				$parameter = strtolower(strtr($smcFunc['htmlspecialchars']($search_params[$param_name], ENT_QUOTES), array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')));
358 369
 
359
-				if ($smcFunc['db_case_sensitive'])
360
-					$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
361
-				else
362
-					$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
370
+				if ($smcFunc['db_case_sensitive']) {
371
+									$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
372
+				} else {
373
+									$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
374
+				}
363 375
 				$where_params[$param_name . '_normal'] = '%' . $parameter . '%';
364 376
 			}
365 377
 		}
@@ -375,16 +387,18 @@  discard block
 block discarded – undo
375 387
 		}
376 388
 
377 389
 		// Additional membergroups (these are only relevant if not all primary groups where selected!).
378
-		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1])))
379
-			foreach ($search_params['membergroups'][2] as $mg)
390
+		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) {
391
+					foreach ($search_params['membergroups'][2] as $mg)
380 392
 			{
381 393
 				$mg_query_parts[] = 'FIND_IN_SET({int:add_group_' . $mg . '}, mem.additional_groups) != 0';
394
+		}
382 395
 				$where_params['add_group_' . $mg] = $mg;
383 396
 			}
384 397
 
385 398
 		// Combine the one or two membergroup parts into one query part linked with an OR.
386
-		if (!empty($mg_query_parts))
387
-			$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
399
+		if (!empty($mg_query_parts)) {
400
+					$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
401
+		}
388 402
 
389 403
 		// Get all selected post count related membergroups.
390 404
 		if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($context['postgroups']))
@@ -396,9 +410,9 @@  discard block
 block discarded – undo
396 410
 		// Construct the where part of the query.
397 411
 		$where = empty($query_parts) ? '1=1' : implode('
398 412
 			AND ', $query_parts);
413
+	} else {
414
+			$search_url_params = null;
399 415
 	}
400
-	else
401
-		$search_url_params = null;
402 416
 
403 417
 	// Construct the additional URL part with the query info in it.
404 418
 	$context['params_url'] = $context['sub_action'] == 'query' ? ';sa=query;params=' . $search_url_params : '';
@@ -521,28 +535,32 @@  discard block
 block discarded – undo
521 535
 					'function' => function($rowData) use ($txt)
522 536
 					{
523 537
 						// Calculate number of days since last online.
524
-						if (empty($rowData['last_login']))
525
-							$difference = $txt['never'];
526
-						else
538
+						if (empty($rowData['last_login'])) {
539
+													$difference = $txt['never'];
540
+						} else
527 541
 						{
528 542
 							$num_days_difference = jeffsdatediff($rowData['last_login']);
529 543
 
530 544
 							// Today.
531
-							if (empty($num_days_difference))
532
-								$difference = $txt['viewmembers_today'];
545
+							if (empty($num_days_difference)) {
546
+															$difference = $txt['viewmembers_today'];
547
+							}
533 548
 
534 549
 							// Yesterday.
535
-							elseif ($num_days_difference == 1)
536
-								$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
550
+							elseif ($num_days_difference == 1) {
551
+															$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
552
+							}
537 553
 
538 554
 							// X days ago.
539
-							else
540
-								$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
555
+							else {
556
+															$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
557
+							}
541 558
 						}
542 559
 
543 560
 						// Show it in italics if they're not activated...
544
-						if ($rowData['is_activated'] % 10 != 1)
545
-							$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
561
+						if ($rowData['is_activated'] % 10 != 1) {
562
+													$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
563
+						}
546 564
 
547 565
 						return $difference;
548 566
 					},
@@ -594,8 +612,9 @@  discard block
 block discarded – undo
594 612
 	);
595 613
 
596 614
 	// Without enough permissions, don't show 'delete members' checkboxes.
597
-	if (!allowedTo('profile_remove_any'))
598
-		unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
615
+	if (!allowedTo('profile_remove_any')) {
616
+			unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
617
+	}
599 618
 
600 619
 	require_once($sourcedir . '/Subs-List.php');
601 620
 	createList($listOptions);
@@ -638,17 +657,18 @@  discard block
 block discarded – undo
638 657
 	);
639 658
 	while ($row = $smcFunc['db_fetch_assoc']($request))
640 659
 	{
641
-		if ($row['min_posts'] == -1)
642
-			$context['membergroups'][] = array(
660
+		if ($row['min_posts'] == -1) {
661
+					$context['membergroups'][] = array(
643 662
 				'id' => $row['id_group'],
644 663
 				'name' => $row['group_name'],
645 664
 				'can_be_additional' => true
646 665
 			);
647
-		else
648
-			$context['postgroups'][] = array(
666
+		} else {
667
+					$context['postgroups'][] = array(
649 668
 				'id' => $row['id_group'],
650 669
 				'name' => $row['group_name']
651 670
 			);
671
+		}
652 672
 	}
653 673
 	$smcFunc['db_free_result']($request);
654 674
 
@@ -675,8 +695,9 @@  discard block
 block discarded – undo
675 695
 	$context['page_title'] = $txt['admin_members'];
676 696
 	$context['sub_template'] = 'admin_browse';
677 697
 	$context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve');
678
-	if (isset($context['tabs'][$context['browse_type']]))
679
-		$context['tabs'][$context['browse_type']]['is_selected'] = true;
698
+	if (isset($context['tabs'][$context['browse_type']])) {
699
+			$context['tabs'][$context['browse_type']]['is_selected'] = true;
700
+	}
680 701
 
681 702
 	// Allowed filters are those we can have, in theory.
682 703
 	$context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2);
@@ -687,18 +708,20 @@  discard block
 block discarded – undo
687 708
 	foreach ($context['activation_numbers'] as $type => $amount)
688 709
 	{
689 710
 		// We have some of these...
690
-		if (in_array($type, $context['allowed_filters']) && $amount > 0)
691
-			$context['available_filters'][] = array(
711
+		if (in_array($type, $context['allowed_filters']) && $amount > 0) {
712
+					$context['available_filters'][] = array(
692 713
 				'type' => $type,
693 714
 				'amount' => $amount,
694 715
 				'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?',
695 716
 				'selected' => $type == $context['current_filter']
696 717
 			);
718
+		}
697 719
 	}
698 720
 
699 721
 	// If the filter was not sent, set it to whatever has people in it!
700
-	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount']))
701
-		$context['current_filter'] = $context['available_filters'][0]['type'];
722
+	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) {
723
+			$context['current_filter'] = $context['available_filters'][0]['type'];
724
+	}
702 725
 
703 726
 	// This little variable is used to determine if we should flag where we are looking.
704 727
 	$context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1;
@@ -713,44 +736,47 @@  discard block
 block discarded – undo
713 736
 	);
714 737
 
715 738
 	// Are we showing duplicate information?
716
-	if (isset($_GET['showdupes']))
717
-		$_SESSION['showdupes'] = (int) $_GET['showdupes'];
739
+	if (isset($_GET['showdupes'])) {
740
+			$_SESSION['showdupes'] = (int) $_GET['showdupes'];
741
+	}
718 742
 	$context['show_duplicates'] = !empty($_SESSION['showdupes']);
719 743
 
720 744
 	// Determine which actions we should allow on this page.
721 745
 	if ($context['browse_type'] == 'approve')
722 746
 	{
723 747
 		// If we are approving deleted accounts we have a slightly different list... actually a mirror ;)
724
-		if ($context['current_filter'] == 4)
725
-			$context['allowed_actions'] = array(
748
+		if ($context['current_filter'] == 4) {
749
+					$context['allowed_actions'] = array(
726 750
 				'reject' => $txt['admin_browse_w_approve_deletion'],
727 751
 				'ok' => $txt['admin_browse_w_reject'],
728 752
 			);
729
-		else
730
-			$context['allowed_actions'] = array(
753
+		} else {
754
+					$context['allowed_actions'] = array(
731 755
 				'ok' => $txt['admin_browse_w_approve'],
732 756
 				'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'],
733 757
 				'require_activation' => $txt['admin_browse_w_approve_require_activate'],
734 758
 				'reject' => $txt['admin_browse_w_reject'],
735 759
 				'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'],
736 760
 			);
737
-	}
738
-	elseif ($context['browse_type'] == 'activate')
739
-		$context['allowed_actions'] = array(
761
+		}
762
+	} elseif ($context['browse_type'] == 'activate') {
763
+			$context['allowed_actions'] = array(
740 764
 			'ok' => $txt['admin_browse_w_activate'],
741 765
 			'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'],
742 766
 			'delete' => $txt['admin_browse_w_delete'],
743 767
 			'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'],
744 768
 			'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'],
745 769
 		);
770
+	}
746 771
 
747 772
 	// Create an option list for actions allowed to be done with selected members.
748 773
 	$allowed_actions = '
749 774
 			<option selected value="">' . $txt['admin_browse_with_selected'] . ':</option>
750 775
 			<option value="" disabled>-----------------------------</option>';
751
-	foreach ($context['allowed_actions'] as $key => $desc)
752
-		$allowed_actions .= '
776
+	foreach ($context['allowed_actions'] as $key => $desc) {
777
+			$allowed_actions .= '
753 778
 			<option value="' . $key . '">' . $desc . '</option>';
779
+	}
754 780
 
755 781
 	// Setup the Javascript function for selecting an action for the list.
756 782
 	$javascript = '
@@ -762,15 +788,16 @@  discard block
 block discarded – undo
762 788
 			var message = "";';
763 789
 
764 790
 	// We have special messages for approving deletion of accounts - it's surprisingly logical - honest.
765
-	if ($context['current_filter'] == 4)
766
-		$javascript .= '
791
+	if ($context['current_filter'] == 4) {
792
+			$javascript .= '
767 793
 			if (document.forms.postForm.todo.value.indexOf("reject") != -1)
768 794
 				message = "' . $txt['admin_browse_w_delete'] . '";
769 795
 			else
770 796
 				message = "' . $txt['admin_browse_w_reject'] . '";';
797
+	}
771 798
 	// Otherwise a nice standard message.
772
-	else
773
-		$javascript .= '
799
+	else {
800
+			$javascript .= '
774 801
 			if (document.forms.postForm.todo.value.indexOf("delete") != -1)
775 802
 				message = "' . $txt['admin_browse_w_delete'] . '";
776 803
 			else if (document.forms.postForm.todo.value.indexOf("reject") != -1)
@@ -779,6 +806,7 @@  discard block
 block discarded – undo
779 806
 				message = "' . $txt['admin_browse_w_remind'] . '";
780 807
 			else
781 808
 				message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";';
809
+	}
782 810
 	$javascript .= '
783 811
 			if (confirm(message + " ' . $txt['admin_browse_warn'] . '"))
784 812
 				document.forms.postForm.submit();
@@ -911,10 +939,11 @@  discard block
 block discarded – undo
911 939
 						$member_links = array();
912 940
 						foreach ($rowData['duplicate_members'] as $member)
913 941
 						{
914
-							if ($member['id'])
915
-								$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
916
-							else
917
-								$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
942
+							if ($member['id']) {
943
+															$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
944
+							} else {
945
+															$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
946
+							}
918 947
 						}
919 948
 						return implode(', ', $member_links);
920 949
 					},
@@ -963,14 +992,16 @@  discard block
 block discarded – undo
963 992
 	);
964 993
 
965 994
 	// Pick what column to actually include if we're showing duplicates.
966
-	if ($context['show_duplicates'])
967
-		unset($listOptions['columns']['email']);
968
-	else
969
-		unset($listOptions['columns']['duplicates']);
995
+	if ($context['show_duplicates']) {
996
+			unset($listOptions['columns']['email']);
997
+	} else {
998
+			unset($listOptions['columns']['duplicates']);
999
+	}
970 1000
 
971 1001
 	// Only show hostname on duplicates as it takes a lot of time.
972
-	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup']))
973
-		unset($listOptions['columns']['hostname']);
1002
+	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) {
1003
+			unset($listOptions['columns']['hostname']);
1004
+	}
974 1005
 
975 1006
 	// Is there any need to show filters?
976 1007
 	if (isset($context['available_filters']) && count($context['available_filters']) > 1)
@@ -978,9 +1009,10 @@  discard block
 block discarded – undo
978 1009
 		$filterOptions = '
979 1010
 			<strong>' . $txt['admin_browse_filter_by'] . ':</strong>
980 1011
 			<select name="filter" onchange="this.form.submit();">';
981
-		foreach ($context['available_filters'] as $filter)
982
-			$filterOptions .= '
1012
+		foreach ($context['available_filters'] as $filter) {
1013
+					$filterOptions .= '
983 1014
 				<option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>';
1015
+		}
984 1016
 		$filterOptions .= '
985 1017
 			</select>
986 1018
 			<noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button_submit"></noscript>';
@@ -992,12 +1024,13 @@  discard block
 block discarded – undo
992 1024
 	}
993 1025
 
994 1026
 	// What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at.
995
-	if (!empty($context['show_filter']) && !empty($context['available_filters']))
996
-		$listOptions['additional_rows'][] = array(
1027
+	if (!empty($context['show_filter']) && !empty($context['available_filters'])) {
1028
+			$listOptions['additional_rows'][] = array(
997 1029
 			'position' => 'above_column_headers',
998 1030
 			'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . $context['available_filters'][0]['desc'],
999 1031
 			'class' => 'smalltext floatright',
1000 1032
 		);
1033
+	}
1001 1034
 
1002 1035
 	// Now that we have all the options, create the list.
1003 1036
 	require_once($sourcedir . '/Subs-List.php');
@@ -1028,12 +1061,14 @@  discard block
 block discarded – undo
1028 1061
 	$current_filter = (int) $_REQUEST['orig_filter'];
1029 1062
 
1030 1063
 	// If we are applying a filter do just that - then redirect.
1031
-	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter'])
1032
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1064
+	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) {
1065
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1066
+	}
1033 1067
 
1034 1068
 	// Nothing to do?
1035
-	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed']))
1036
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1069
+	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) {
1070
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1071
+	}
1037 1072
 
1038 1073
 	// Are we dealing with members who have been waiting for > set amount of time?
1039 1074
 	if (isset($_POST['time_passed']))
@@ -1046,8 +1081,9 @@  discard block
 block discarded – undo
1046 1081
 	else
1047 1082
 	{
1048 1083
 		$members = array();
1049
-		foreach ($_POST['todoAction'] as $id)
1050
-			$members[] = (int) $id;
1084
+		foreach ($_POST['todoAction'] as $id) {
1085
+					$members[] = (int) $id;
1086
+		}
1051 1087
 		$condition = '
1052 1088
 			AND id_member IN ({array_int:members})';
1053 1089
 	}
@@ -1068,8 +1104,9 @@  discard block
 block discarded – undo
1068 1104
 	$member_count = $smcFunc['db_num_rows']($request);
1069 1105
 
1070 1106
 	// If no results then just return!
1071
-	if ($member_count == 0)
1072
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1107
+	if ($member_count == 0) {
1108
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1109
+	}
1073 1110
 
1074 1111
 	$member_info = array();
1075 1112
 	$members = array();
@@ -1108,8 +1145,9 @@  discard block
 block discarded – undo
1108 1145
 		// Do we have to let the integration code know about the activations?
1109 1146
 		if (!empty($modSettings['integrate_activate']))
1110 1147
 		{
1111
-			foreach ($member_info as $member)
1112
-				call_integration_hook('integrate_activate', array($member['username']));
1148
+			foreach ($member_info as $member) {
1149
+							call_integration_hook('integrate_activate', array($member['username']));
1150
+			}
1113 1151
 		}
1114 1152
 
1115 1153
 		// Check for email.
@@ -1240,20 +1278,23 @@  discard block
 block discarded – undo
1240 1278
 		$log_inserts = array();
1241 1279
 
1242 1280
 		require_once($sourcedir . '/Logging.php');
1243
-		foreach ($member_info as $member)
1244
-			logAction($log_action, array('member' => $member['id']), 'admin');
1281
+		foreach ($member_info as $member) {
1282
+					logAction($log_action, array('member' => $member['id']), 'admin');
1283
+		}
1245 1284
 	}
1246 1285
 
1247 1286
 	// Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers).
1248
-	if (in_array($current_filter, array(3, 4, 5)))
1249
-		updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1287
+	if (in_array($current_filter, array(3, 4, 5))) {
1288
+			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1289
+	}
1250 1290
 
1251 1291
 	// Update the member's stats. (but, we know the member didn't change their name.)
1252 1292
 	updateStats('member', false);
1253 1293
 
1254 1294
 	// If they haven't been deleted, update the post group statistics on them...
1255
-	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind')))
1256
-		updateStats('postgroups', $members);
1295
+	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) {
1296
+			updateStats('postgroups', $members);
1297
+	}
1257 1298
 
1258 1299
 	redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1259 1300
 }
@@ -1278,10 +1319,11 @@  discard block
 block discarded – undo
1278 1319
 	$dis = time() - $old;
1279 1320
 
1280 1321
 	// Before midnight?
1281
-	if ($dis < $sinceMidnight)
1282
-		return 0;
1283
-	else
1284
-		$dis -= $sinceMidnight;
1322
+	if ($dis < $sinceMidnight) {
1323
+			return 0;
1324
+	} else {
1325
+			$dis -= $sinceMidnight;
1326
+	}
1285 1327
 
1286 1328
 	// Divide out the seconds in a day to get the number of days.
1287 1329
 	return ceil($dis / (24 * 60 * 60));
Please login to merge, or discard this patch.
Sources/Profile-Modify.php 1 patch
Braces   +693 added lines, -519 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * This defines every profile field known to man.
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $sourcedir, $profile_vars;
30 31
 
31 32
 	// Don't load this twice!
32
-	if (!empty($profile_fields) && !$force_reload)
33
-		return;
33
+	if (!empty($profile_fields) && !$force_reload) {
34
+			return;
35
+	}
34 36
 
35 37
 	/* This horrific array defines all the profile fields in the whole world!
36 38
 		In general each "field" has one array - the key of which is the database column name associated with said field. Each item
@@ -103,13 +105,14 @@  discard block
 block discarded – undo
103 105
 				if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0)
104 106
 				{
105 107
 					// Set to blank?
106
-					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1)
107
-						$value = '0001-01-01';
108
-					else
109
-						$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01';
108
+					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) {
109
+											$value = '0001-01-01';
110
+					} else {
111
+											$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01';
112
+					}
113
+				} else {
114
+									$value = '0001-01-01';
110 115
 				}
111
-				else
112
-					$value = '0001-01-01';
113 116
 
114 117
 				$profile_vars['birthdate'] = $value;
115 118
 				$cur_profile['birthdate'] = $value;
@@ -127,8 +130,7 @@  discard block
 block discarded – undo
127 130
 				{
128 131
 					$value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf('%04d-%02d-%02d', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : '0001-01-01';
129 132
 					return true;
130
-				}
131
-				else
133
+				} else
132 134
 				{
133 135
 					$value = empty($cur_profile['birthdate']) ? '0001-01-01' : $cur_profile['birthdate'];
134 136
 					return false;
@@ -150,10 +152,11 @@  discard block
 block discarded – undo
150 152
 					return $txt['invalid_registration'] . ' ' . strftime('%d %b %Y ' . (strpos($user_info['time_format'], '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false));
151 153
 				}
152 154
 				// As long as it doesn't equal "N/A"...
153
-				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600)))
154
-					$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
155
-				else
156
-					$value = $cur_profile['date_registered'];
155
+				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) {
156
+									$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
157
+				} else {
158
+									$value = $cur_profile['date_registered'];
159
+				}
157 160
 
158 161
 				return true;
159 162
 			},
@@ -177,8 +180,9 @@  discard block
 block discarded – undo
177 180
 			{
178 181
 				global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
179 182
 
180
-				if (strtolower($value) == strtolower($old_profile['email_address']))
181
-					return false;
183
+				if (strtolower($value) == strtolower($old_profile['email_address'])) {
184
+									return false;
185
+				}
182 186
 
183 187
 				$isValid = profileValidateEmail($value, $context['id_member']);
184 188
 
@@ -254,11 +258,11 @@  discard block
 block discarded – undo
254 258
 
255 259
 				if (isset($context['profile_languages'][$value]))
256 260
 				{
257
-					if ($context['user']['is_owner'] && empty($context['password_auth_failed']))
258
-						$_SESSION['language'] = $value;
261
+					if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) {
262
+											$_SESSION['language'] = $value;
263
+					}
259 264
 					return true;
260
-				}
261
-				else
265
+				} else
262 266
 				{
263 267
 					$value = $cur_profile['lngfile'];
264 268
 					return false;
@@ -282,13 +286,14 @@  discard block
 block discarded – undo
282 286
 
283 287
 					// Maybe they are trying to change their password as well?
284 288
 					$resetPassword = true;
285
-					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null)
286
-						$resetPassword = false;
289
+					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) {
290
+											$resetPassword = false;
291
+					}
287 292
 
288 293
 					// Do the reset... this will send them an email too.
289
-					if ($resetPassword)
290
-						resetPassword($context['id_member'], $value);
291
-					elseif ($value !== null)
294
+					if ($resetPassword) {
295
+											resetPassword($context['id_member'], $value);
296
+					} elseif ($value !== null)
292 297
 					{
293 298
 						validateUsername($context['id_member'], trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value)));
294 299
 						updateMemberData($context['id_member'], array('member_name' => $value));
@@ -312,20 +317,23 @@  discard block
 block discarded – undo
312 317
 			'input_validate' => function(&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
313 318
 			{
314 319
 				// If we didn't try it then ignore it!
315
-				if ($value == '')
316
-					return false;
320
+				if ($value == '') {
321
+									return false;
322
+				}
317 323
 
318 324
 				// Do the two entries for the password even match?
319
-				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2'])
320
-					return 'bad_new_password';
325
+				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) {
326
+									return 'bad_new_password';
327
+				}
321 328
 
322 329
 				// Let's get the validation function into play...
323 330
 				require_once($sourcedir . '/Subs-Auth.php');
324 331
 				$passwordErrors = validatePassword($value, $cur_profile['member_name'], array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email']));
325 332
 
326 333
 				// Were there errors?
327
-				if ($passwordErrors != null)
328
-					return 'password_' . $passwordErrors;
334
+				if ($passwordErrors != null) {
335
+									return 'password_' . $passwordErrors;
336
+				}
329 337
 
330 338
 				// Set up the new password variable... ready for storage.
331 339
 				$value = hash_password($cur_profile['member_name'], un_htmlspecialchars($value));
@@ -350,8 +358,9 @@  discard block
 block discarded – undo
350 358
 			'permission' => 'profile_blurb',
351 359
 			'input_validate' => function(&$value) use ($smcFunc)
352 360
 			{
353
-				if ($smcFunc['strlen']($value) > 50)
354
-					return 'personal_text_too_long';
361
+				if ($smcFunc['strlen']($value) > 50) {
362
+									return 'personal_text_too_long';
363
+				}
355 364
 
356 365
 				return true;
357 366
 			},
@@ -386,10 +395,11 @@  discard block
 block discarded – undo
386 395
 			'permission' => 'moderate_forum',
387 396
 			'input_validate' => function(&$value)
388 397
 			{
389
-				if (!is_numeric($value))
390
-					return 'digits_only';
391
-				else
392
-					$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
398
+				if (!is_numeric($value)) {
399
+									return 'digits_only';
400
+				} else {
401
+									$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
402
+				}
393 403
 				return true;
394 404
 			},
395 405
 		),
@@ -405,15 +415,16 @@  discard block
 block discarded – undo
405 415
 			{
406 416
 				$value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value));
407 417
 
408
-				if (trim($value) == '')
409
-					return 'no_name';
410
-				elseif ($smcFunc['strlen']($value) > 60)
411
-					return 'name_too_long';
412
-				elseif ($cur_profile['real_name'] != $value)
418
+				if (trim($value) == '') {
419
+									return 'no_name';
420
+				} elseif ($smcFunc['strlen']($value) > 60) {
421
+									return 'name_too_long';
422
+				} elseif ($cur_profile['real_name'] != $value)
413 423
 				{
414 424
 					require_once($sourcedir . '/Subs-Members.php');
415
-					if (isReservedName($value, $context['id_member']))
416
-						return 'name_taken';
425
+					if (isReservedName($value, $context['id_member'])) {
426
+											return 'name_taken';
427
+					}
417 428
 				}
418 429
 				return true;
419 430
 			},
@@ -471,8 +482,9 @@  discard block
 block discarded – undo
471 482
 						'selected' => $set == $context['member']['smiley_set']['id']
472 483
 					);
473 484
 
474
-					if ($context['smiley_sets'][$i]['selected'])
475
-						$context['member']['smiley_set']['name'] = $set_names[$i];
485
+					if ($context['smiley_sets'][$i]['selected']) {
486
+											$context['member']['smiley_set']['name'] = $set_names[$i];
487
+					}
476 488
 				}
477 489
 				return true;
478 490
 			},
@@ -481,8 +493,9 @@  discard block
 block discarded – undo
481 493
 				global $modSettings;
482 494
 
483 495
 				$smiley_sets = explode(',', $modSettings['smiley_sets_known']);
484
-				if (!in_array($value, $smiley_sets) && $value != 'none')
485
-					$value = '';
496
+				if (!in_array($value, $smiley_sets) && $value != 'none') {
497
+									$value = '';
498
+				}
486 499
 				return true;
487 500
 			},
488 501
 		),
@@ -497,8 +510,9 @@  discard block
 block discarded – undo
497 510
 				loadLanguage('Settings');
498 511
 
499 512
 				$context['allow_no_censored'] = false;
500
-				if ($user_info['is_admin'] || $context['user']['is_owner'])
501
-					$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
513
+				if ($user_info['is_admin'] || $context['user']['is_owner']) {
514
+									$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
515
+				}
502 516
 
503 517
 				return true;
504 518
 			},
@@ -545,8 +559,9 @@  discard block
 block discarded – undo
545 559
 			'input_validate' => function($value)
546 560
 			{
547 561
 				$tz = smf_list_timezones();
548
-				if (!isset($tz[$value]))
549
-					return 'bad_timezone';
562
+				if (!isset($tz[$value])) {
563
+									return 'bad_timezone';
564
+				}
550 565
 
551 566
 				return true;
552 567
 			},
@@ -561,8 +576,9 @@  discard block
 block discarded – undo
561 576
 			'enabled' => !empty($modSettings['titlesEnable']),
562 577
 			'input_validate' => function(&$value) use ($smcFunc)
563 578
 			{
564
-				if ($smcFunc['strlen']($value) > 50)
565
-					return 'user_title_too_long';
579
+				if ($smcFunc['strlen']($value) > 50) {
580
+									return 'user_title_too_long';
581
+				}
566 582
 
567 583
 				return true;
568 584
 			},
@@ -584,10 +600,12 @@  discard block
 block discarded – undo
584 600
 			// Fix the URL...
585 601
 			'input_validate' => function(&$value)
586 602
 			{
587
-				if (strlen(trim($value)) > 0 && strpos($value, '://') === false)
588
-					$value = 'http://' . $value;
589
-				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://'))
590
-					$value = '';
603
+				if (strlen(trim($value)) > 0 && strpos($value, '://') === false) {
604
+									$value = 'http://' . $value;
605
+				}
606
+				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) {
607
+									$value = '';
608
+				}
591 609
 				return true;
592 610
 			},
593 611
 			'link_with' => 'website',
@@ -601,16 +619,19 @@  discard block
 block discarded – undo
601 619
 	foreach ($profile_fields as $key => $field)
602 620
 	{
603 621
 		// Do we have permission to do this?
604
-		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission']))
605
-			unset($profile_fields[$key]);
622
+		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) {
623
+					unset($profile_fields[$key]);
624
+		}
606 625
 
607 626
 		// Is it enabled?
608
-		if (isset($field['enabled']) && !$field['enabled'])
609
-			unset($profile_fields[$key]);
627
+		if (isset($field['enabled']) && !$field['enabled']) {
628
+					unset($profile_fields[$key]);
629
+		}
610 630
 
611 631
 		// Is it specifically disabled?
612
-		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields)))
613
-			unset($profile_fields[$key]);
632
+		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) {
633
+					unset($profile_fields[$key]);
634
+		}
614 635
 	}
615 636
 }
616 637
 
@@ -635,9 +656,10 @@  discard block
 block discarded – undo
635 656
 	loadProfileFields(true);
636 657
 
637 658
 	// First check for any linked sets.
638
-	foreach ($profile_fields as $key => $field)
639
-		if (isset($field['link_with']) && in_array($field['link_with'], $fields))
659
+	foreach ($profile_fields as $key => $field) {
660
+			if (isset($field['link_with']) && in_array($field['link_with'], $fields))
640 661
 			$fields[] = $key;
662
+	}
641 663
 
642 664
 	$i = 0;
643 665
 	$last_type = '';
@@ -649,38 +671,46 @@  discard block
 block discarded – undo
649 671
 			$cur_field = &$profile_fields[$field];
650 672
 
651 673
 			// Does it have a preload and does that preload succeed?
652
-			if (isset($cur_field['preload']) && !$cur_field['preload']())
653
-				continue;
674
+			if (isset($cur_field['preload']) && !$cur_field['preload']()) {
675
+							continue;
676
+			}
654 677
 
655 678
 			// If this is anything but complex we need to do more cleaning!
656 679
 			if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden')
657 680
 			{
658
-				if (!isset($cur_field['label']))
659
-					$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
681
+				if (!isset($cur_field['label'])) {
682
+									$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
683
+				}
660 684
 
661 685
 				// Everything has a value!
662
-				if (!isset($cur_field['value']))
663
-					$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
686
+				if (!isset($cur_field['value'])) {
687
+									$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
688
+				}
664 689
 
665 690
 				// Any input attributes?
666 691
 				$cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : '';
667 692
 			}
668 693
 
669 694
 			// Was there an error with this field on posting?
670
-			if (isset($context['profile_errors'][$field]))
671
-				$cur_field['is_error'] = true;
695
+			if (isset($context['profile_errors'][$field])) {
696
+							$cur_field['is_error'] = true;
697
+			}
672 698
 
673 699
 			// Any javascript stuff?
674
-			if (!empty($cur_field['js_submit']))
675
-				$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
676
-			if (!empty($cur_field['js']))
677
-				$context['profile_javascript'] .= $cur_field['js'];
700
+			if (!empty($cur_field['js_submit'])) {
701
+							$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
702
+			}
703
+			if (!empty($cur_field['js'])) {
704
+							$context['profile_javascript'] .= $cur_field['js'];
705
+			}
678 706
 
679 707
 			// Any template stuff?
680
-			if (!empty($cur_field['prehtml']))
681
-				$context['profile_prehtml'] .= $cur_field['prehtml'];
682
-			if (!empty($cur_field['posthtml']))
683
-				$context['profile_posthtml'] .= $cur_field['posthtml'];
708
+			if (!empty($cur_field['prehtml'])) {
709
+							$context['profile_prehtml'] .= $cur_field['prehtml'];
710
+			}
711
+			if (!empty($cur_field['posthtml'])) {
712
+							$context['profile_posthtml'] .= $cur_field['posthtml'];
713
+			}
684 714
 
685 715
 			// Finally put it into context?
686 716
 			if ($cur_field['type'] != 'hidden')
@@ -713,12 +743,14 @@  discard block
 block discarded – undo
713 743
 	}, false);' : ''), true);
714 744
 
715 745
 	// Any onsubmit javascript?
716
-	if (!empty($context['profile_onsubmit_javascript']))
717
-		addInlineJavaScript($context['profile_onsubmit_javascript'], true);
746
+	if (!empty($context['profile_onsubmit_javascript'])) {
747
+			addInlineJavaScript($context['profile_onsubmit_javascript'], true);
748
+	}
718 749
 
719 750
 	// Any totally custom stuff?
720
-	if (!empty($context['profile_javascript']))
721
-		addInlineJavaScript($context['profile_javascript'], true);
751
+	if (!empty($context['profile_javascript'])) {
752
+			addInlineJavaScript($context['profile_javascript'], true);
753
+	}
722 754
 
723 755
 	// Free up some memory.
724 756
 	unset($profile_fields);
@@ -739,8 +771,9 @@  discard block
 block discarded – undo
739 771
 
740 772
 	// This allows variables to call activities when they save - by default just to reload their settings
741 773
 	$context['profile_execute_on_save'] = array();
742
-	if ($context['user']['is_owner'])
743
-		$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
774
+	if ($context['user']['is_owner']) {
775
+			$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
776
+	}
744 777
 
745 778
 	// Assume we log nothing.
746 779
 	$context['log_changes'] = array();
@@ -748,8 +781,9 @@  discard block
 block discarded – undo
748 781
 	// Cycle through the profile fields working out what to do!
749 782
 	foreach ($profile_fields as $key => $field)
750 783
 	{
751
-		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature'))
752
-			continue;
784
+		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) {
785
+					continue;
786
+		}
753 787
 
754 788
 		// What gets updated?
755 789
 		$db_key = isset($field['save_key']) ? $field['save_key'] : $key;
@@ -777,12 +811,13 @@  discard block
 block discarded – undo
777 811
 		$field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type'];
778 812
 
779 813
 		// Finally, clean up certain types.
780
-		if ($field['cast_type'] == 'int')
781
-			$_POST[$key] = (int) $_POST[$key];
782
-		elseif ($field['cast_type'] == 'float')
783
-			$_POST[$key] = (float) $_POST[$key];
784
-		elseif ($field['cast_type'] == 'check')
785
-			$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
814
+		if ($field['cast_type'] == 'int') {
815
+					$_POST[$key] = (int) $_POST[$key];
816
+		} elseif ($field['cast_type'] == 'float') {
817
+					$_POST[$key] = (float) $_POST[$key];
818
+		} elseif ($field['cast_type'] == 'check') {
819
+					$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
820
+		}
786 821
 
787 822
 		// If we got here we're doing OK.
788 823
 		if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key]))
@@ -793,11 +828,12 @@  discard block
 block discarded – undo
793 828
 			$cur_profile[$key] = $_POST[$key];
794 829
 
795 830
 			// Are we logging it?
796
-			if (!empty($field['log_change']) && isset($old_profile[$key]))
797
-				$context['log_changes'][$key] = array(
831
+			if (!empty($field['log_change']) && isset($old_profile[$key])) {
832
+							$context['log_changes'][$key] = array(
798 833
 					'previous' => $old_profile[$key],
799 834
 					'new' => $_POST[$key],
800 835
 				);
836
+			}
801 837
 		}
802 838
 
803 839
 		// Logging group changes are a bit different...
@@ -830,10 +866,11 @@  discard block
 block discarded – undo
830 866
 				{
831 867
 					foreach ($groups as $id => $group)
832 868
 					{
833
-						if (isset($context['member_groups'][$group]))
834
-							$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
835
-						else
836
-							unset($additional_groups[$type][$id]);
869
+						if (isset($context['member_groups'][$group])) {
870
+													$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
871
+						} else {
872
+													unset($additional_groups[$type][$id]);
873
+						}
837 874
 					}
838 875
 					$additional_groups[$type] = implode(', ', $additional_groups[$type]);
839 876
 				}
@@ -844,10 +881,11 @@  discard block
 block discarded – undo
844 881
 	}
845 882
 
846 883
 	// @todo Temporary
847
-	if ($context['user']['is_owner'])
848
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
849
-	else
850
-		$changeOther = allowedTo('profile_extra_any');
884
+	if ($context['user']['is_owner']) {
885
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
886
+	} else {
887
+			$changeOther = allowedTo('profile_extra_any');
888
+	}
851 889
 	if ($changeOther && empty($post_errors))
852 890
 	{
853 891
 		makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
@@ -855,8 +893,9 @@  discard block
 block discarded – undo
855 893
 		{
856 894
 			$custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true);
857 895
 
858
-			if (!empty($custom_fields_errors))
859
-				$post_errors = array_merge($post_errors, $custom_fields_errors);
896
+			if (!empty($custom_fields_errors)) {
897
+							$post_errors = array_merge($post_errors, $custom_fields_errors);
898
+			}
860 899
 		}
861 900
 	}
862 901
 
@@ -883,8 +922,7 @@  discard block
 block discarded – undo
883 922
 	{
884 923
 		$changeIdentity = allowedTo(array('profile_identity_any', 'profile_identity_own', 'profile_password_any', 'profile_password_own'));
885 924
 		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own'));
886
-	}
887
-	else
925
+	} else
888 926
 	{
889 927
 		$changeIdentity = allowedTo('profile_identity_any', 'profile_signature_any');
890 928
 		$changeOther = allowedTo('profile_extra_any', 'profile_website_any', 'profile_signature_any');
@@ -899,22 +937,25 @@  discard block
 block discarded – undo
899 937
 		'ignore_boards',
900 938
 	);
901 939
 
902
-	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
903
-		$_POST['ignore_brd'] = array();
940
+	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) {
941
+			$_POST['ignore_brd'] = array();
942
+	}
904 943
 
905 944
 	unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing.  Kinda like our minds.
906 945
 	if (isset($_POST['ignore_brd']))
907 946
 	{
908
-		if (!is_array($_POST['ignore_brd']))
909
-			$_POST['ignore_brd'] = array($_POST['ignore_brd']);
947
+		if (!is_array($_POST['ignore_brd'])) {
948
+					$_POST['ignore_brd'] = array($_POST['ignore_brd']);
949
+		}
910 950
 
911 951
 		foreach ($_POST['ignore_brd'] as $k => $d)
912 952
 		{
913 953
 			$d = (int) $d;
914
-			if ($d != 0)
915
-				$_POST['ignore_brd'][$k] = $d;
916
-			else
917
-				unset($_POST['ignore_brd'][$k]);
954
+			if ($d != 0) {
955
+							$_POST['ignore_brd'][$k] = $d;
956
+			} else {
957
+							unset($_POST['ignore_brd'][$k]);
958
+			}
918 959
 		}
919 960
 		$_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
920 961
 		unset($_POST['ignore_brd']);
@@ -927,21 +968,26 @@  discard block
 block discarded – undo
927 968
 		makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
928 969
 		//makeAvatarChanges($memID, $post_errors);
929 970
 
930
-		if (!empty($_REQUEST['sa']))
931
-			makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
971
+		if (!empty($_REQUEST['sa'])) {
972
+					makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
973
+		}
932 974
 
933
-		foreach ($profile_bools as $var)
934
-			if (isset($_POST[$var]))
975
+		foreach ($profile_bools as $var) {
976
+					if (isset($_POST[$var]))
935 977
 				$profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
936
-		foreach ($profile_ints as $var)
937
-			if (isset($_POST[$var]))
978
+		}
979
+		foreach ($profile_ints as $var) {
980
+					if (isset($_POST[$var]))
938 981
 				$profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
939
-		foreach ($profile_floats as $var)
940
-			if (isset($_POST[$var]))
982
+		}
983
+		foreach ($profile_floats as $var) {
984
+					if (isset($_POST[$var]))
941 985
 				$profile_vars[$var] = (float) $_POST[$var];
942
-		foreach ($profile_strings as $var)
943
-			if (isset($_POST[$var]))
986
+		}
987
+		foreach ($profile_strings as $var) {
988
+					if (isset($_POST[$var]))
944 989
 				$profile_vars[$var] = $_POST[$var];
990
+		}
945 991
 	}
946 992
 }
947 993
 
@@ -975,8 +1021,9 @@  discard block
 block discarded – undo
975 1021
 	);
976 1022
 
977 1023
 	// Can't change reserved vars.
978
-	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0))
979
-		fatal_lang_error('no_access', false);
1024
+	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) {
1025
+			fatal_lang_error('no_access', false);
1026
+	}
980 1027
 
981 1028
 	// Don't allow any overriding of custom fields with default or non-default options.
982 1029
 	$request = $smcFunc['db_query']('', '
@@ -988,8 +1035,9 @@  discard block
 block discarded – undo
988 1035
 		)
989 1036
 	);
990 1037
 	$custom_fields = array();
991
-	while ($row = $smcFunc['db_fetch_assoc']($request))
992
-		$custom_fields[] = $row['col_name'];
1038
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1039
+			$custom_fields[] = $row['col_name'];
1040
+	}
993 1041
 	$smcFunc['db_free_result']($request);
994 1042
 
995 1043
 	// These are the theme changes...
@@ -998,33 +1046,39 @@  discard block
 block discarded – undo
998 1046
 	{
999 1047
 		foreach ($_POST['options'] as $opt => $val)
1000 1048
 		{
1001
-			if (in_array($opt, $custom_fields))
1002
-				continue;
1049
+			if (in_array($opt, $custom_fields)) {
1050
+							continue;
1051
+			}
1003 1052
 
1004 1053
 			// These need to be controlled.
1005
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1006
-				$val = max(0, min($val, 50));
1054
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1055
+							$val = max(0, min($val, 50));
1056
+			}
1007 1057
 			// We don't set this per theme anymore.
1008
-			elseif ($opt == 'allow_no_censored')
1009
-				continue;
1058
+			elseif ($opt == 'allow_no_censored') {
1059
+							continue;
1060
+			}
1010 1061
 
1011 1062
 			$themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
1012 1063
 		}
1013 1064
 	}
1014 1065
 
1015 1066
 	$erase_options = array();
1016
-	if (isset($_POST['default_options']) && is_array($_POST['default_options']))
1017
-		foreach ($_POST['default_options'] as $opt => $val)
1067
+	if (isset($_POST['default_options']) && is_array($_POST['default_options'])) {
1068
+			foreach ($_POST['default_options'] as $opt => $val)
1018 1069
 		{
1019 1070
 			if (in_array($opt, $custom_fields))
1020 1071
 				continue;
1072
+	}
1021 1073
 
1022 1074
 			// These need to be controlled.
1023
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1024
-				$val = max(0, min($val, 50));
1075
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1076
+							$val = max(0, min($val, 50));
1077
+			}
1025 1078
 			// Only let admins and owners change the censor.
1026
-			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner'])
1027
-					continue;
1079
+			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) {
1080
+								continue;
1081
+			}
1028 1082
 
1029 1083
 			$themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
1030 1084
 			$erase_options[] = $opt;
@@ -1060,8 +1114,9 @@  discard block
 block discarded – undo
1060 1114
 
1061 1115
 		// Admins can choose any theme, even if it's not enabled...
1062 1116
 		$themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']);
1063
-		foreach ($themes as $t)
1064
-			cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1117
+		foreach ($themes as $t) {
1118
+					cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1119
+		}
1065 1120
 	}
1066 1121
 }
1067 1122
 
@@ -1080,8 +1135,9 @@  discard block
 block discarded – undo
1080 1135
 	if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
1081 1136
 	{
1082 1137
 		// Make sure only integers are deleted.
1083
-		foreach ($_POST['notify_boards'] as $index => $id)
1084
-			$_POST['notify_boards'][$index] = (int) $id;
1138
+		foreach ($_POST['notify_boards'] as $index => $id) {
1139
+					$_POST['notify_boards'][$index] = (int) $id;
1140
+		}
1085 1141
 
1086 1142
 		// id_board = 0 is reserved for topic notifications.
1087 1143
 		$_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
@@ -1100,8 +1156,9 @@  discard block
 block discarded – undo
1100 1156
 	// We are editing topic notifications......
1101 1157
 	elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
1102 1158
 	{
1103
-		foreach ($_POST['notify_topics'] as $index => $id)
1104
-			$_POST['notify_topics'][$index] = (int) $id;
1159
+		foreach ($_POST['notify_topics'] as $index => $id) {
1160
+					$_POST['notify_topics'][$index] = (int) $id;
1161
+		}
1105 1162
 
1106 1163
 		// Make sure there are no zeros left.
1107 1164
 		$_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
@@ -1115,16 +1172,18 @@  discard block
 block discarded – undo
1115 1172
 				'selected_member' => $memID,
1116 1173
 			)
1117 1174
 		);
1118
-		foreach ($_POST['notify_topics'] as $topic)
1119
-			setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1175
+		foreach ($_POST['notify_topics'] as $topic) {
1176
+					setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1177
+		}
1120 1178
 	}
1121 1179
 
1122 1180
 	// We are removing topic preferences
1123 1181
 	elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics']))
1124 1182
 	{
1125 1183
 		$prefs = array();
1126
-		foreach ($_POST['notify_topics'] as $topic)
1127
-			$prefs[] = 'topic_notify_' . $topic;
1184
+		foreach ($_POST['notify_topics'] as $topic) {
1185
+					$prefs[] = 'topic_notify_' . $topic;
1186
+		}
1128 1187
 		deleteNotifyPrefs($memID, $prefs);
1129 1188
 	}
1130 1189
 
@@ -1132,8 +1191,9 @@  discard block
 block discarded – undo
1132 1191
 	elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards']))
1133 1192
 	{
1134 1193
 		$prefs = array();
1135
-		foreach ($_POST['notify_boards'] as $board)
1136
-			$prefs[] = 'board_notify_' . $board;
1194
+		foreach ($_POST['notify_boards'] as $board) {
1195
+					$prefs[] = 'board_notify_' . $board;
1196
+		}
1137 1197
 		deleteNotifyPrefs($memID, $prefs);
1138 1198
 	}
1139 1199
 }
@@ -1154,8 +1214,9 @@  discard block
 block discarded – undo
1154 1214
 
1155 1215
 	$errors = array();
1156 1216
 
1157
-	if ($sanitize && isset($_POST['customfield']))
1158
-		$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1217
+	if ($sanitize && isset($_POST['customfield'])) {
1218
+			$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1219
+	}
1159 1220
 
1160 1221
 	$where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
1161 1222
 
@@ -1180,48 +1241,49 @@  discard block
 block discarded – undo
1180 1241
 			- The data is not invisible to users but editable by the owner (or if it is the user is not the owner)
1181 1242
 			- The area isn't registration, and if it is that the field is not supposed to be shown there.
1182 1243
 		*/
1183
-		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
1184
-			continue;
1244
+		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) {
1245
+					continue;
1246
+		}
1185 1247
 
1186 1248
 		// Validate the user data.
1187
-		if ($row['field_type'] == 'check')
1188
-			$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1189
-		elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1249
+		if ($row['field_type'] == 'check') {
1250
+					$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1251
+		} elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1190 1252
 		{
1191 1253
 			$value = $row['default_value'];
1192
-			foreach (explode(',', $row['field_options']) as $k => $v)
1193
-				if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1254
+			foreach (explode(',', $row['field_options']) as $k => $v) {
1255
+							if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1194 1256
 					$value = $v;
1257
+			}
1195 1258
 		}
1196 1259
 		// Otherwise some form of text!
1197 1260
 		else
1198 1261
 		{
1199 1262
 			$value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
1200
-			if ($row['field_length'])
1201
-				$value = $smcFunc['substr']($value, 0, $row['field_length']);
1263
+			if ($row['field_length']) {
1264
+							$value = $smcFunc['substr']($value, 0, $row['field_length']);
1265
+			}
1202 1266
 
1203 1267
 			// Any masks?
1204 1268
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
1205 1269
 			{
1206 1270
 				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1207 1271
 				{
1208
-					if ($returnErrors)
1209
-						$errors[] = 'custom_field_mail_fail';
1210
-
1211
-					else
1212
-						$value = '';
1213
-				}
1214
-				elseif ($row['mask'] == 'number')
1272
+					if ($returnErrors) {
1273
+											$errors[] = 'custom_field_mail_fail';
1274
+					} else {
1275
+											$value = '';
1276
+					}
1277
+				} elseif ($row['mask'] == 'number')
1215 1278
 				{
1216 1279
 					$value = (int) $value;
1217
-				}
1218
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1280
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1219 1281
 				{
1220
-					if ($returnErrors)
1221
-						$errors[] = 'custom_field_regex_fail';
1222
-
1223
-					else
1224
-						$value = '';
1282
+					if ($returnErrors) {
1283
+											$errors[] = 'custom_field_regex_fail';
1284
+					} else {
1285
+											$value = '';
1286
+					}
1225 1287
 				}
1226 1288
 			}
1227 1289
 		}
@@ -1248,8 +1310,9 @@  discard block
 block discarded – undo
1248 1310
 	$hook_errors = array();
1249 1311
 	$hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize));
1250 1312
 
1251
-	if (!empty($hook_errors) && is_array($hook_errors))
1252
-		$errors = array_merge($errors, $hook_errors);
1313
+	if (!empty($hook_errors) && is_array($hook_errors)) {
1314
+			$errors = array_merge($errors, $hook_errors);
1315
+	}
1253 1316
 
1254 1317
 	// Make those changes!
1255 1318
 	if (!empty($changes) && empty($context['password_auth_failed']) && empty($errors))
@@ -1267,9 +1330,10 @@  discard block
 block discarded – undo
1267 1330
 		}
1268 1331
 	}
1269 1332
 
1270
-	if ($returnErrors)
1271
-		return $errors;
1272
-}
1333
+	if ($returnErrors) {
1334
+			return $errors;
1335
+	}
1336
+	}
1273 1337
 
1274 1338
 /**
1275 1339
  * Show all the users buddies, as well as a add/delete interface.
@@ -1281,8 +1345,9 @@  discard block
 block discarded – undo
1281 1345
 	global $context, $txt, $modSettings;
1282 1346
 
1283 1347
 	// Do a quick check to ensure people aren't getting here illegally!
1284
-	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
1285
-		fatal_lang_error('no_access', false);
1348
+	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) {
1349
+			fatal_lang_error('no_access', false);
1350
+	}
1286 1351
 
1287 1352
 	// Can we email the user direct?
1288 1353
 	$context['can_moderate_forum'] = allowedTo('moderate_forum');
@@ -1312,9 +1377,10 @@  discard block
 block discarded – undo
1312 1377
 	$context['sub_template'] = $subActions[$context['list_area']][0];
1313 1378
 	$call = call_helper($subActions[$context['list_area']][0], true);
1314 1379
 
1315
-	if (!empty($call))
1316
-		call_user_func($call, $memID);
1317
-}
1380
+	if (!empty($call)) {
1381
+			call_user_func($call, $memID);
1382
+	}
1383
+	}
1318 1384
 
1319 1385
 /**
1320 1386
  * Show all the users buddies, as well as a add/delete interface.
@@ -1328,9 +1394,10 @@  discard block
 block discarded – undo
1328 1394
 
1329 1395
 	// For making changes!
1330 1396
 	$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
1331
-	foreach ($buddiesArray as $k => $dummy)
1332
-		if ($dummy == '')
1397
+	foreach ($buddiesArray as $k => $dummy) {
1398
+			if ($dummy == '')
1333 1399
 			unset($buddiesArray[$k]);
1400
+	}
1334 1401
 
1335 1402
 	// Removing a buddy?
1336 1403
 	if (isset($_GET['remove']))
@@ -1342,10 +1409,11 @@  discard block
 block discarded – undo
1342 1409
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1343 1410
 
1344 1411
 		// Heh, I'm lazy, do it the easy way...
1345
-		foreach ($buddiesArray as $key => $buddy)
1346
-			if ($buddy == (int) $_GET['remove'])
1412
+		foreach ($buddiesArray as $key => $buddy) {
1413
+					if ($buddy == (int) $_GET['remove'])
1347 1414
 			{
1348 1415
 				unset($buddiesArray[$key]);
1416
+		}
1349 1417
 				$_SESSION['prf-save'] = true;
1350 1418
 			}
1351 1419
 
@@ -1355,8 +1423,7 @@  discard block
 block discarded – undo
1355 1423
 
1356 1424
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1357 1425
 		redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
1358
-	}
1359
-	elseif (isset($_POST['new_buddy']))
1426
+	} elseif (isset($_POST['new_buddy']))
1360 1427
 	{
1361 1428
 		checkSession();
1362 1429
 
@@ -1369,8 +1436,9 @@  discard block
 block discarded – undo
1369 1436
 		{
1370 1437
 			$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
1371 1438
 
1372
-			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1373
-				unset($new_buddies[$k]);
1439
+			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1440
+							unset($new_buddies[$k]);
1441
+			}
1374 1442
 		}
1375 1443
 
1376 1444
 		call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
@@ -1390,16 +1458,18 @@  discard block
 block discarded – undo
1390 1458
 				)
1391 1459
 			);
1392 1460
 
1393
-			if ($smcFunc['db_num_rows']($request) != 0)
1394
-				$_SESSION['prf-save'] = true;
1461
+			if ($smcFunc['db_num_rows']($request) != 0) {
1462
+							$_SESSION['prf-save'] = true;
1463
+			}
1395 1464
 
1396 1465
 			// Add the new member to the buddies array.
1397 1466
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1398 1467
 			{
1399
-				if (in_array($row['id_member'], $buddiesArray))
1400
-					continue;
1401
-				else
1402
-					$buddiesArray[] = (int) $row['id_member'];
1468
+				if (in_array($row['id_member'], $buddiesArray)) {
1469
+									continue;
1470
+				} else {
1471
+									$buddiesArray[] = (int) $row['id_member'];
1472
+				}
1403 1473
 			}
1404 1474
 			$smcFunc['db_free_result']($request);
1405 1475
 
@@ -1429,18 +1499,20 @@  discard block
 block discarded – undo
1429 1499
 
1430 1500
 	$context['custom_pf'] = array();
1431 1501
 	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
1432
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1433
-		if (!isset($disabled_fields[$row['col_name']]))
1502
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1503
+			if (!isset($disabled_fields[$row['col_name']]))
1434 1504
 			$context['custom_pf'][$row['col_name']] = array(
1435 1505
 				'label' => $row['field_name'],
1436 1506
 				'type' => $row['field_type'],
1437 1507
 				'bbc' => !empty($row['bbc']),
1438 1508
 				'enclose' => $row['enclose'],
1439 1509
 			);
1510
+	}
1440 1511
 
1441 1512
 	// Gotta disable the gender option.
1442
-	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled')
1443
-		unset($context['custom_pf']['cust_gender']);
1513
+	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled') {
1514
+			unset($context['custom_pf']['cust_gender']);
1515
+	}
1444 1516
 
1445 1517
 	$smcFunc['db_free_result']($request);
1446 1518
 
@@ -1457,8 +1529,9 @@  discard block
 block discarded – undo
1457 1529
 				'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
1458 1530
 			)
1459 1531
 		);
1460
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1461
-			$buddies[] = $row['id_member'];
1532
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1533
+					$buddies[] = $row['id_member'];
1534
+		}
1462 1535
 		$smcFunc['db_free_result']($result);
1463 1536
 	}
1464 1537
 
@@ -1486,30 +1559,32 @@  discard block
 block discarded – undo
1486 1559
 					continue;
1487 1560
 				}
1488 1561
 
1489
-				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key]))
1490
-					$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1491
-
1492
-				elseif ($column['type'] == 'check')
1493
-					$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1562
+				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) {
1563
+									$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1564
+				} elseif ($column['type'] == 'check') {
1565
+									$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1566
+				}
1494 1567
 
1495 1568
 				// Enclosing the user input within some other text?
1496
-				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key]))
1497
-					$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1569
+				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) {
1570
+									$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1498 1571
 						'{SCRIPTURL}' => $scripturl,
1499 1572
 						'{IMAGES_URL}' => $settings['images_url'],
1500 1573
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1501 1574
 						'{INPUT}' => $context['buddies'][$buddy]['options'][$key],
1502 1575
 					));
1576
+				}
1503 1577
 			}
1504 1578
 		}
1505 1579
 	}
1506 1580
 
1507 1581
 	if (isset($_SESSION['prf-save']))
1508 1582
 	{
1509
-		if ($_SESSION['prf-save'] === true)
1510
-			$context['saved_successful'] = true;
1511
-		else
1512
-			$context['saved_failed'] = $_SESSION['prf-save'];
1583
+		if ($_SESSION['prf-save'] === true) {
1584
+					$context['saved_successful'] = true;
1585
+		} else {
1586
+					$context['saved_failed'] = $_SESSION['prf-save'];
1587
+		}
1513 1588
 
1514 1589
 		unset($_SESSION['prf-save']);
1515 1590
 	}
@@ -1529,9 +1604,10 @@  discard block
 block discarded – undo
1529 1604
 
1530 1605
 	// For making changes!
1531 1606
 	$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
1532
-	foreach ($ignoreArray as $k => $dummy)
1533
-		if ($dummy == '')
1607
+	foreach ($ignoreArray as $k => $dummy) {
1608
+			if ($dummy == '')
1534 1609
 			unset($ignoreArray[$k]);
1610
+	}
1535 1611
 
1536 1612
 	// Removing a member from the ignore list?
1537 1613
 	if (isset($_GET['remove']))
@@ -1541,10 +1617,11 @@  discard block
 block discarded – undo
1541 1617
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1542 1618
 
1543 1619
 		// Heh, I'm lazy, do it the easy way...
1544
-		foreach ($ignoreArray as $key => $id_remove)
1545
-			if ($id_remove == (int) $_GET['remove'])
1620
+		foreach ($ignoreArray as $key => $id_remove) {
1621
+					if ($id_remove == (int) $_GET['remove'])
1546 1622
 			{
1547 1623
 				unset($ignoreArray[$key]);
1624
+		}
1548 1625
 				$_SESSION['prf-save'] = true;
1549 1626
 			}
1550 1627
 
@@ -1554,8 +1631,7 @@  discard block
 block discarded – undo
1554 1631
 
1555 1632
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1556 1633
 		redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
1557
-	}
1558
-	elseif (isset($_POST['new_ignore']))
1634
+	} elseif (isset($_POST['new_ignore']))
1559 1635
 	{
1560 1636
 		checkSession();
1561 1637
 		// Prepare the string for extraction...
@@ -1567,8 +1643,9 @@  discard block
 block discarded – undo
1567 1643
 		{
1568 1644
 			$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
1569 1645
 
1570
-			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1571
-				unset($new_entries[$k]);
1646
+			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1647
+							unset($new_entries[$k]);
1648
+			}
1572 1649
 		}
1573 1650
 
1574 1651
 		$_SESSION['prf-save'] = $txt['could_not_add_person'];
@@ -1586,16 +1663,18 @@  discard block
 block discarded – undo
1586 1663
 				)
1587 1664
 			);
1588 1665
 
1589
-			if ($smcFunc['db_num_rows']($request) != 0)
1590
-				$_SESSION['prf-save'] = true;
1666
+			if ($smcFunc['db_num_rows']($request) != 0) {
1667
+							$_SESSION['prf-save'] = true;
1668
+			}
1591 1669
 
1592 1670
 			// Add the new member to the buddies array.
1593 1671
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1594 1672
 			{
1595
-				if (in_array($row['id_member'], $ignoreArray))
1596
-					continue;
1597
-				else
1598
-					$ignoreArray[] = (int) $row['id_member'];
1673
+				if (in_array($row['id_member'], $ignoreArray)) {
1674
+									continue;
1675
+				} else {
1676
+									$ignoreArray[] = (int) $row['id_member'];
1677
+				}
1599 1678
 			}
1600 1679
 			$smcFunc['db_free_result']($request);
1601 1680
 
@@ -1624,8 +1703,9 @@  discard block
 block discarded – undo
1624 1703
 				'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
1625 1704
 			)
1626 1705
 		);
1627
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1628
-			$ignored[] = $row['id_member'];
1706
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1707
+					$ignored[] = $row['id_member'];
1708
+		}
1629 1709
 		$smcFunc['db_free_result']($result);
1630 1710
 	}
1631 1711
 
@@ -1644,10 +1724,11 @@  discard block
 block discarded – undo
1644 1724
 
1645 1725
 	if (isset($_SESSION['prf-save']))
1646 1726
 	{
1647
-		if ($_SESSION['prf-save'] === true)
1648
-			$context['saved_successful'] = true;
1649
-		else
1650
-			$context['saved_failed'] = $_SESSION['prf-save'];
1727
+		if ($_SESSION['prf-save'] === true) {
1728
+					$context['saved_successful'] = true;
1729
+		} else {
1730
+					$context['saved_failed'] = $_SESSION['prf-save'];
1731
+		}
1651 1732
 
1652 1733
 		unset($_SESSION['prf-save']);
1653 1734
 	}
@@ -1663,8 +1744,9 @@  discard block
 block discarded – undo
1663 1744
 	global $context, $txt;
1664 1745
 
1665 1746
 	loadThemeOptions($memID);
1666
-	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
1667
-		loadCustomFields($memID, 'account');
1747
+	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) {
1748
+			loadCustomFields($memID, 'account');
1749
+	}
1668 1750
 
1669 1751
 	$context['sub_template'] = 'edit_options';
1670 1752
 	$context['page_desc'] = $txt['account_info'];
@@ -1691,8 +1773,9 @@  discard block
 block discarded – undo
1691 1773
 	global $context, $txt;
1692 1774
 
1693 1775
 	loadThemeOptions($memID);
1694
-	if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
1695
-		loadCustomFields($memID, 'forumprofile');
1776
+	if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) {
1777
+			loadCustomFields($memID, 'forumprofile');
1778
+	}
1696 1779
 
1697 1780
 	$context['sub_template'] = 'edit_options';
1698 1781
 	$context['page_desc'] = $txt['forumProfile_info'];
@@ -1725,18 +1808,21 @@  discard block
 block discarded – undo
1725 1808
 	$dirs = array();
1726 1809
 	$files = array();
1727 1810
 
1728
-	if (!$dir)
1729
-		return array();
1811
+	if (!$dir) {
1812
+			return array();
1813
+	}
1730 1814
 
1731 1815
 	while ($line = $dir->read())
1732 1816
 	{
1733
-		if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
1734
-			continue;
1817
+		if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) {
1818
+					continue;
1819
+		}
1735 1820
 
1736
-		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
1737
-			$dirs[] = $line;
1738
-		else
1739
-			$files[] = $line;
1821
+		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) {
1822
+					$dirs[] = $line;
1823
+		} else {
1824
+					$files[] = $line;
1825
+		}
1740 1826
 	}
1741 1827
 	$dir->close();
1742 1828
 
@@ -1757,14 +1843,15 @@  discard block
 block discarded – undo
1757 1843
 	foreach ($dirs as $line)
1758 1844
 	{
1759 1845
 		$tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
1760
-		if (!empty($tmp))
1761
-			$result[] = array(
1846
+		if (!empty($tmp)) {
1847
+					$result[] = array(
1762 1848
 				'filename' => $smcFunc['htmlspecialchars']($line),
1763 1849
 				'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
1764 1850
 				'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
1765 1851
 				'is_dir' => true,
1766 1852
 				'files' => $tmp
1767 1853
 		);
1854
+		}
1768 1855
 		unset($tmp);
1769 1856
 	}
1770 1857
 
@@ -1774,8 +1861,9 @@  discard block
 block discarded – undo
1774 1861
 		$extension = substr(strrchr($line, '.'), 1);
1775 1862
 
1776 1863
 		// Make sure it is an image.
1777
-		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
1778
-			continue;
1864
+		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) {
1865
+					continue;
1866
+		}
1779 1867
 
1780 1868
 		$result[] = array(
1781 1869
 			'filename' => $smcFunc['htmlspecialchars']($line),
@@ -1783,8 +1871,9 @@  discard block
 block discarded – undo
1783 1871
 			'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
1784 1872
 			'is_dir' => false
1785 1873
 		);
1786
-		if ($level == 1)
1787
-			$context['avatar_list'][] = $directory . '/' . $line;
1874
+		if ($level == 1) {
1875
+					$context['avatar_list'][] = $directory . '/' . $line;
1876
+		}
1788 1877
 	}
1789 1878
 
1790 1879
 	return $result;
@@ -1800,8 +1889,9 @@  discard block
 block discarded – undo
1800 1889
 	global $txt, $context;
1801 1890
 
1802 1891
 	loadThemeOptions($memID);
1803
-	if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
1804
-		loadCustomFields($memID, 'theme');
1892
+	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) {
1893
+			loadCustomFields($memID, 'theme');
1894
+	}
1805 1895
 
1806 1896
 	$context['sub_template'] = 'edit_options';
1807 1897
 	$context['page_desc'] = $txt['theme_info'];
@@ -1855,16 +1945,19 @@  discard block
 block discarded – undo
1855 1945
 {
1856 1946
 	global $txt, $user_profile, $context, $modSettings, $smcFunc, $sourcedir;
1857 1947
 
1858
-	if (!isset($context['token_check']))
1859
-		$context['token_check'] = 'profile-nt' . $memID;
1948
+	if (!isset($context['token_check'])) {
1949
+			$context['token_check'] = 'profile-nt' . $memID;
1950
+	}
1860 1951
 
1861 1952
 	is_not_guest();
1862
-	if (!$context['user']['is_owner'])
1863
-		isAllowedTo('profile_extra_any');
1953
+	if (!$context['user']['is_owner']) {
1954
+			isAllowedTo('profile_extra_any');
1955
+	}
1864 1956
 
1865 1957
 	// Set the post action if we're coming from the profile...
1866
-	if (!isset($context['action']))
1867
-		$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1958
+	if (!isset($context['action'])) {
1959
+			$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1960
+	}
1868 1961
 
1869 1962
 	// What options are set
1870 1963
 	loadThemeOptions($memID);
@@ -1951,28 +2044,34 @@  discard block
 block discarded – undo
1951 2044
 	);
1952 2045
 
1953 2046
 	// There are certain things that are disabled at the group level.
1954
-	if (empty($modSettings['cal_enabled']))
1955
-		unset($alert_types['calendar']);
2047
+	if (empty($modSettings['cal_enabled'])) {
2048
+			unset($alert_types['calendar']);
2049
+	}
1956 2050
 
1957 2051
 	// Disable paid subscriptions at group level if they're disabled
1958
-	if (empty($modSettings['paid_enabled']))
1959
-		unset($alert_types['paidsubs']);
2052
+	if (empty($modSettings['paid_enabled'])) {
2053
+			unset($alert_types['paidsubs']);
2054
+	}
1960 2055
 
1961 2056
 	// Disable membergroup requests at group level if they're disabled
1962
-	if (empty($modSettings['show_group_membership']))
1963
-		unset($alert_types['groupr'], $alert_types['members']['request_group']);
2057
+	if (empty($modSettings['show_group_membership'])) {
2058
+			unset($alert_types['groupr'], $alert_types['members']['request_group']);
2059
+	}
1964 2060
 
1965 2061
 	// Disable mentions if they're disabled
1966
-	if (empty($modSettings['enable_mentions']))
1967
-		unset($alert_types['msg']['msg_mention']);
2062
+	if (empty($modSettings['enable_mentions'])) {
2063
+			unset($alert_types['msg']['msg_mention']);
2064
+	}
1968 2065
 
1969 2066
 	// Disable likes if they're disabled
1970
-	if (empty($modSettings['enable_likes']))
1971
-		unset($alert_types['msg']['msg_like']);
2067
+	if (empty($modSettings['enable_likes'])) {
2068
+			unset($alert_types['msg']['msg_like']);
2069
+	}
1972 2070
 
1973 2071
 	// Disable buddy requests if they're disabled
1974
-	if (empty($modSettings['enable_buddylist']))
1975
-		unset($alert_types['members']['buddy_request']);
2072
+	if (empty($modSettings['enable_buddylist'])) {
2073
+			unset($alert_types['members']['buddy_request']);
2074
+	}
1976 2075
 
1977 2076
 	// Now, now, we could pass this through global but we should really get into the habit of
1978 2077
 	// passing content to hooks, not expecting hooks to splatter everything everywhere.
@@ -2000,15 +2099,17 @@  discard block
 block discarded – undo
2000 2099
 			$perms_cache['manage_membergroups'] = in_array($memID, $members);
2001 2100
 		}
2002 2101
 
2003
-		if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
2004
-			unset($alert_types['members']['request_group']);
2102
+		if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) {
2103
+					unset($alert_types['members']['request_group']);
2104
+		}
2005 2105
 
2006 2106
 		foreach ($alert_types as $group => $items)
2007 2107
 		{
2008 2108
 			foreach ($items as $alert_key => $alert_value)
2009 2109
 			{
2010
-				if (!isset($alert_value['permission']))
2011
-					continue;
2110
+				if (!isset($alert_value['permission'])) {
2111
+									continue;
2112
+				}
2012 2113
 				if (!isset($perms_cache[$alert_value['permission']['name']]))
2013 2114
 				{
2014 2115
 					$in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
@@ -2016,12 +2117,14 @@  discard block
 block discarded – undo
2016 2117
 					$perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
2017 2118
 				}
2018 2119
 
2019
-				if (!$perms_cache[$alert_value['permission']['name']])
2020
-					unset ($alert_types[$group][$alert_key]);
2120
+				if (!$perms_cache[$alert_value['permission']['name']]) {
2121
+									unset ($alert_types[$group][$alert_key]);
2122
+				}
2021 2123
 			}
2022 2124
 
2023
-			if (empty($alert_types[$group]))
2024
-				unset ($alert_types[$group]);
2125
+			if (empty($alert_types[$group])) {
2126
+							unset ($alert_types[$group]);
2127
+			}
2025 2128
 		}
2026 2129
 	}
2027 2130
 
@@ -2053,9 +2156,9 @@  discard block
 block discarded – undo
2053 2156
 						$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
2054 2157
 						break;
2055 2158
 					case 'select':
2056
-						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
2057
-							$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2058
-						else
2159
+						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) {
2160
+													$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2161
+						} else
2059 2162
 						{
2060 2163
 							// We didn't have a sane value. Let's grab the first item from the possibles.
2061 2164
 							$keys = array_keys($this_option['opts']);
@@ -2075,23 +2178,28 @@  discard block
 block discarded – undo
2075 2178
 				$this_value = 0;
2076 2179
 				foreach ($context['alert_bits'] as $type => $bitvalue)
2077 2180
 				{
2078
-					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always')
2079
-						$this_value |= $bitvalue;
2181
+					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') {
2182
+											$this_value |= $bitvalue;
2183
+					}
2184
+				}
2185
+				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) {
2186
+									$update_prefs[$item_key] = $this_value;
2080 2187
 				}
2081
-				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value)
2082
-					$update_prefs[$item_key] = $this_value;
2083 2188
 			}
2084 2189
 		}
2085 2190
 
2086
-		if (!empty($_POST['opt_alert_timeout']))
2087
-			$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2191
+		if (!empty($_POST['opt_alert_timeout'])) {
2192
+					$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2193
+		}
2088 2194
 
2089
-		if (!empty($_POST['notify_announcements']))
2090
-			$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2195
+		if (!empty($_POST['notify_announcements'])) {
2196
+					$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2197
+		}
2091 2198
 
2092 2199
 		setNotifyPrefs((int) $memID, $update_prefs);
2093
-		foreach ($update_prefs as $pref => $value)
2094
-			$context['alert_prefs'][$pref] = $value;
2200
+		foreach ($update_prefs as $pref => $value) {
2201
+					$context['alert_prefs'][$pref] = $value;
2202
+		}
2095 2203
 
2096 2204
 		makeNotificationChanges($memID);
2097 2205
 
@@ -2121,8 +2229,9 @@  discard block
 block discarded – undo
2121 2229
 
2122 2230
 	// Now we're all set up.
2123 2231
 	is_not_guest();
2124
-	if (!$context['user']['is_owner'])
2125
-		fatal_error('no_access');
2232
+	if (!$context['user']['is_owner']) {
2233
+			fatal_error('no_access');
2234
+	}
2126 2235
 
2127 2236
 	checkSession('get');
2128 2237
 
@@ -2154,8 +2263,9 @@  discard block
 block discarded – undo
2154 2263
 {
2155 2264
 	global $smcFunc;
2156 2265
 
2157
-	if (empty($toMark) || empty($memID))
2158
-		return false;
2266
+	if (empty($toMark) || empty($memID)) {
2267
+			return false;
2268
+	}
2159 2269
 
2160 2270
 	$toMark = (array) $toMark;
2161 2271
 	$count = 0;
@@ -2190,8 +2300,9 @@  discard block
 block discarded – undo
2190 2300
 {
2191 2301
 	global $smcFunc;
2192 2302
 
2193
-	if (empty($toDelete))
2194
-		return false;
2303
+	if (empty($toDelete)) {
2304
+			return false;
2305
+	}
2195 2306
 
2196 2307
 	$toDelete = (array) $toDelete;
2197 2308
 
@@ -2226,8 +2337,9 @@  discard block
 block discarded – undo
2226 2337
 {
2227 2338
 	global $smcFunc;
2228 2339
 
2229
-	if (empty($memID))
2230
-		return false;
2340
+	if (empty($memID)) {
2341
+			return false;
2342
+	}
2231 2343
 
2232 2344
 	$count = 0;
2233 2345
 
@@ -2306,8 +2418,9 @@  discard block
 block discarded – undo
2306 2418
 					{
2307 2419
 						$link = $topic['link'];
2308 2420
 
2309
-						if ($topic['new'])
2310
-							$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2421
+						if ($topic['new']) {
2422
+													$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2423
+						}
2311 2424
 
2312 2425
 						$link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>';
2313 2426
 
@@ -2458,8 +2571,9 @@  discard block
 block discarded – undo
2458 2571
 					{
2459 2572
 						$link = $board['link'];
2460 2573
 
2461
-						if ($board['new'])
2462
-							$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2574
+						if ($board['new']) {
2575
+													$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2576
+						}
2463 2577
 
2464 2578
 						return $link;
2465 2579
 					},
@@ -2659,8 +2773,8 @@  discard block
 block discarded – undo
2659 2773
 		)
2660 2774
 	);
2661 2775
 	$notification_boards = array();
2662
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2663
-		$notification_boards[] = array(
2776
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2777
+			$notification_boards[] = array(
2664 2778
 			'id' => $row['id_board'],
2665 2779
 			'name' => $row['name'],
2666 2780
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
@@ -2668,6 +2782,7 @@  discard block
 block discarded – undo
2668 2782
 			'new' => $row['board_read'] < $row['id_msg_updated'],
2669 2783
 			'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0),
2670 2784
 		);
2785
+	}
2671 2786
 	$smcFunc['db_free_result']($request);
2672 2787
 
2673 2788
 	return $notification_boards;
@@ -2682,17 +2797,18 @@  discard block
 block discarded – undo
2682 2797
 {
2683 2798
 	global $context, $options, $cur_profile, $smcFunc;
2684 2799
 
2685
-	if (isset($_POST['default_options']))
2686
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2800
+	if (isset($_POST['default_options'])) {
2801
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2802
+	}
2687 2803
 
2688 2804
 	if ($context['user']['is_owner'])
2689 2805
 	{
2690 2806
 		$context['member']['options'] = $options;
2691
-		if (isset($_POST['options']) && is_array($_POST['options']))
2692
-			foreach ($_POST['options'] as $k => $v)
2807
+		if (isset($_POST['options']) && is_array($_POST['options'])) {
2808
+					foreach ($_POST['options'] as $k => $v)
2693 2809
 				$context['member']['options'][$k] = $v;
2694
-	}
2695
-	else
2810
+		}
2811
+	} else
2696 2812
 	{
2697 2813
 		$request = $smcFunc['db_query']('', '
2698 2814
 			SELECT id_member, variable, value
@@ -2713,8 +2829,9 @@  discard block
 block discarded – undo
2713 2829
 				continue;
2714 2830
 			}
2715 2831
 
2716
-			if (isset($_POST['options'][$row['variable']]))
2717
-				$row['value'] = $_POST['options'][$row['variable']];
2832
+			if (isset($_POST['options'][$row['variable']])) {
2833
+							$row['value'] = $_POST['options'][$row['variable']];
2834
+			}
2718 2835
 			$context['member']['options'][$row['variable']] = $row['value'];
2719 2836
 		}
2720 2837
 		$smcFunc['db_free_result']($request);
@@ -2722,8 +2839,9 @@  discard block
 block discarded – undo
2722 2839
 		// Load up the default theme options for any missing.
2723 2840
 		foreach ($temp as $k => $v)
2724 2841
 		{
2725
-			if (!isset($context['member']['options'][$k]))
2726
-				$context['member']['options'][$k] = $v;
2842
+			if (!isset($context['member']['options'][$k])) {
2843
+							$context['member']['options'][$k] = $v;
2844
+			}
2727 2845
 		}
2728 2846
 	}
2729 2847
 }
@@ -2738,8 +2856,9 @@  discard block
 block discarded – undo
2738 2856
 	global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir;
2739 2857
 
2740 2858
 	// Have the admins enabled this option?
2741
-	if (empty($modSettings['allow_ignore_boards']))
2742
-		fatal_lang_error('ignoreboards_disallowed', 'user');
2859
+	if (empty($modSettings['allow_ignore_boards'])) {
2860
+			fatal_lang_error('ignoreboards_disallowed', 'user');
2861
+	}
2743 2862
 
2744 2863
 	// Find all the boards this user is allowed to see.
2745 2864
 	$request = $smcFunc['db_query']('order_by_board_order', '
@@ -2759,12 +2878,13 @@  discard block
 block discarded – undo
2759 2878
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2760 2879
 	{
2761 2880
 		// This category hasn't been set up yet..
2762
-		if (!isset($context['categories'][$row['id_cat']]))
2763
-			$context['categories'][$row['id_cat']] = array(
2881
+		if (!isset($context['categories'][$row['id_cat']])) {
2882
+					$context['categories'][$row['id_cat']] = array(
2764 2883
 				'id' => $row['id_cat'],
2765 2884
 				'name' => $row['cat_name'],
2766 2885
 				'boards' => array()
2767 2886
 			);
2887
+		}
2768 2888
 
2769 2889
 		// Set this board up, and let the template know when it's a child.  (indent them..)
2770 2890
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -2794,18 +2914,20 @@  discard block
 block discarded – undo
2794 2914
 	}
2795 2915
 
2796 2916
 	$max_boards = ceil(count($temp_boards) / 2);
2797
-	if ($max_boards == 1)
2798
-		$max_boards = 2;
2917
+	if ($max_boards == 1) {
2918
+			$max_boards = 2;
2919
+	}
2799 2920
 
2800 2921
 	// Now, alternate them so they can be shown left and right ;).
2801 2922
 	$context['board_columns'] = array();
2802 2923
 	for ($i = 0; $i < $max_boards; $i++)
2803 2924
 	{
2804 2925
 		$context['board_columns'][] = $temp_boards[$i];
2805
-		if (isset($temp_boards[$i + $max_boards]))
2806
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
2807
-		else
2808
-			$context['board_columns'][] = array();
2926
+		if (isset($temp_boards[$i + $max_boards])) {
2927
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
2928
+		} else {
2929
+					$context['board_columns'][] = array();
2930
+		}
2809 2931
 	}
2810 2932
 
2811 2933
 	loadThemeOptions($memID);
@@ -2874,8 +2996,9 @@  discard block
 block discarded – undo
2874 2996
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2875 2997
 	{
2876 2998
 		// We should skip the administrator group if they don't have the admin_forum permission!
2877
-		if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
2878
-			continue;
2999
+		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) {
3000
+					continue;
3001
+		}
2879 3002
 
2880 3003
 		$context['member_groups'][$row['id_group']] = array(
2881 3004
 			'id' => $row['id_group'],
@@ -2921,16 +3044,17 @@  discard block
 block discarded – undo
2921 3044
 	$context['max_signature_length'] = $context['signature_limits']['max_length'];
2922 3045
 	// Warning message for signature image limits?
2923 3046
 	$context['signature_warning'] = '';
2924
-	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
2925
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
2926
-	elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
2927
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3047
+	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) {
3048
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
3049
+	} elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) {
3050
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3051
+	}
2928 3052
 
2929 3053
 	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
2930 3054
 
2931
-	if (empty($context['do_preview']))
2932
-		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
2933
-	else
3055
+	if (empty($context['do_preview'])) {
3056
+			$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
3057
+	} else
2934 3058
 	{
2935 3059
 		$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
2936 3060
 		$validation = profileValidateSignature($signature);
@@ -2940,8 +3064,9 @@  discard block
 block discarded – undo
2940 3064
 			$context['post_errors'] = array();
2941 3065
 		}
2942 3066
 		$context['post_errors'][] = 'signature_not_yet_saved';
2943
-		if ($validation !== true && $validation !== false)
2944
-			$context['post_errors'][] = $validation;
3067
+		if ($validation !== true && $validation !== false) {
3068
+					$context['post_errors'][] = $validation;
3069
+		}
2945 3070
 
2946 3071
 		censorText($context['member']['signature']);
2947 3072
 		$context['member']['current_signature'] = $context['member']['signature'];
@@ -2951,8 +3076,9 @@  discard block
 block discarded – undo
2951 3076
 	}
2952 3077
 
2953 3078
 	// Load the spell checker?
2954
-	if ($context['show_spellchecking'])
2955
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3079
+	if ($context['show_spellchecking']) {
3080
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3081
+	}
2956 3082
 
2957 3083
 	return true;
2958 3084
 }
@@ -2986,8 +3112,7 @@  discard block
 block discarded – undo
2986 3112
 			'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11)
2987 3113
 		);
2988 3114
 		$context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']);
2989
-	}
2990
-	elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3115
+	} elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
2991 3116
 	{
2992 3117
 		$context['member']['avatar'] += array(
2993 3118
 			'choice' => 'upload',
@@ -2995,34 +3120,34 @@  discard block
 block discarded – undo
2995 3120
 			'external' => 'http://'
2996 3121
 		);
2997 3122
 		$context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename'];
2998
-	}
2999
-	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
3000
-		$context['member']['avatar'] += array(
3123
+	} elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) {
3124
+			$context['member']['avatar'] += array(
3001 3125
 			'choice' => 'external',
3002 3126
 			'server_pic' => 'blank.png',
3003 3127
 			'external' => $cur_profile['avatar']
3004 3128
 		);
3005
-	elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
3006
-		$context['member']['avatar'] += array(
3129
+	} elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) {
3130
+			$context['member']['avatar'] += array(
3007 3131
 			'choice' => 'server_stored',
3008 3132
 			'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
3009 3133
 			'external' => 'http://'
3010 3134
 		);
3011
-	else
3012
-		$context['member']['avatar'] += array(
3135
+	} else {
3136
+			$context['member']['avatar'] += array(
3013 3137
 			'choice' => 'none',
3014 3138
 			'server_pic' => 'blank.png',
3015 3139
 			'external' => 'http://'
3016 3140
 		);
3141
+	}
3017 3142
 
3018 3143
 	// Get a list of all the avatars.
3019 3144
 	if ($context['member']['avatar']['allow_server_stored'])
3020 3145
 	{
3021 3146
 		$context['avatar_list'] = array();
3022 3147
 		$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
3148
+	} else {
3149
+			$context['avatars'] = array();
3023 3150
 	}
3024
-	else
3025
-		$context['avatars'] = array();
3026 3151
 
3027 3152
 	// Second level selected avatar...
3028 3153
 	$context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
@@ -3051,19 +3176,22 @@  discard block
 block discarded – undo
3051 3176
 			)
3052 3177
 		);
3053 3178
 		$protected_groups = array(1);
3054
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3055
-			$protected_groups[] = $row['id_group'];
3179
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3180
+					$protected_groups[] = $row['id_group'];
3181
+		}
3056 3182
 		$smcFunc['db_free_result']($request);
3057 3183
 
3058 3184
 		$protected_groups = array_unique($protected_groups);
3059 3185
 	}
3060 3186
 
3061 3187
 	// The account page allows the change of your id_group - but not to a protected group!
3062
-	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
3063
-		$value = (int) $value;
3188
+	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) {
3189
+			$value = (int) $value;
3190
+	}
3064 3191
 	// ... otherwise it's the old group sir.
3065
-	else
3066
-		$value = $old_profile['id_group'];
3192
+	else {
3193
+			$value = $old_profile['id_group'];
3194
+	}
3067 3195
 
3068 3196
 	// Find the additional membergroups (if any)
3069 3197
 	if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
@@ -3072,16 +3200,18 @@  discard block
 block discarded – undo
3072 3200
 		foreach ($_POST['additional_groups'] as $group_id)
3073 3201
 		{
3074 3202
 			$group_id = (int) $group_id;
3075
-			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
3076
-				$additional_groups[] = $group_id;
3203
+			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) {
3204
+							$additional_groups[] = $group_id;
3205
+			}
3077 3206
 		}
3078 3207
 
3079 3208
 		// Put the protected groups back in there if you don't have permission to take them away.
3080 3209
 		$old_additional_groups = explode(',', $old_profile['additional_groups']);
3081 3210
 		foreach ($old_additional_groups as $group_id)
3082 3211
 		{
3083
-			if (!empty($protected_groups) && in_array($group_id, $protected_groups))
3084
-				$additional_groups[] = $group_id;
3212
+			if (!empty($protected_groups) && in_array($group_id, $protected_groups)) {
3213
+							$additional_groups[] = $group_id;
3214
+			}
3085 3215
 		}
3086 3216
 
3087 3217
 		if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
@@ -3113,18 +3243,20 @@  discard block
 block discarded – undo
3113 3243
 			list ($another) = $smcFunc['db_fetch_row']($request);
3114 3244
 			$smcFunc['db_free_result']($request);
3115 3245
 
3116
-			if (empty($another))
3117
-				fatal_lang_error('at_least_one_admin', 'critical');
3246
+			if (empty($another)) {
3247
+							fatal_lang_error('at_least_one_admin', 'critical');
3248
+			}
3118 3249
 		}
3119 3250
 	}
3120 3251
 
3121 3252
 	// If we are changing group status, update permission cache as necessary.
3122 3253
 	if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
3123 3254
 	{
3124
-		if ($context['user']['is_owner'])
3125
-			$_SESSION['mc']['time'] = 0;
3126
-		else
3127
-			updateSettings(array('settings_updated' => time()));
3255
+		if ($context['user']['is_owner']) {
3256
+					$_SESSION['mc']['time'] = 0;
3257
+		} else {
3258
+					updateSettings(array('settings_updated' => time()));
3259
+		}
3128 3260
 	}
3129 3261
 
3130 3262
 	// Announce to any hooks that we have changed groups, but don't allow them to change it.
@@ -3145,8 +3277,9 @@  discard block
 block discarded – undo
3145 3277
 	global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
3146 3278
 
3147 3279
 	$memID = $context['id_member'];
3148
-	if (empty($memID) && !empty($context['password_auth_failed']))
3149
-		return false;
3280
+	if (empty($memID) && !empty($context['password_auth_failed'])) {
3281
+			return false;
3282
+	}
3150 3283
 
3151 3284
 	require_once($sourcedir . '/ManageAttachments.php');
3152 3285
 
@@ -3157,8 +3290,9 @@  discard block
 block discarded – undo
3157 3290
 	$downloadedExternalAvatar = false;
3158 3291
 	if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external']))
3159 3292
 	{
3160
-		if (!is_writable($uploadDir))
3161
-			fatal_lang_error('attachments_no_write', 'critical');
3293
+		if (!is_writable($uploadDir)) {
3294
+					fatal_lang_error('attachments_no_write', 'critical');
3295
+		}
3162 3296
 
3163 3297
 		require_once($sourcedir . '/Subs-Package.php');
3164 3298
 
@@ -3202,19 +3336,18 @@  discard block
 block discarded – undo
3202 3336
 
3203 3337
 		// Get rid of their old avatar. (if uploaded.)
3204 3338
 		removeAttachments(array('id_member' => $memID));
3205
-	}
3206
-	elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3339
+	} elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3207 3340
 	{
3208 3341
 		// One wasn't specified, or it's not allowed to use extra email addresses, or it's not a valid one, reset to default Gravatar.
3209
-		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL))
3210
-			$profile_vars['avatar'] = 'gravatar://';
3211
-		else
3212
-			$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3342
+		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) {
3343
+					$profile_vars['avatar'] = 'gravatar://';
3344
+		} else {
3345
+					$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3346
+		}
3213 3347
 
3214 3348
 		// Get rid of their old avatar. (if uploaded.)
3215 3349
 		removeAttachments(array('id_member' => $memID));
3216
-	}
3217
-	elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3350
+	} elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3218 3351
 	{
3219 3352
 		// We need these clean...
3220 3353
 		$cur_profile['id_attach'] = 0;
@@ -3226,11 +3359,13 @@  discard block
 block discarded – undo
3226 3359
 
3227 3360
 		$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
3228 3361
 
3229
-		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
3230
-			$profile_vars['avatar'] = '';
3362
+		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') {
3363
+					$profile_vars['avatar'] = '';
3364
+		}
3231 3365
 		// Trying to make us do something we'll regret?
3232
-		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
3233
-			return 'bad_avatar_invalid_url';
3366
+		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') {
3367
+					return 'bad_avatar_invalid_url';
3368
+		}
3234 3369
 		// Should we check dimensions?
3235 3370
 		elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
3236 3371
 		{
@@ -3240,9 +3375,9 @@  discard block
 block discarded – undo
3240 3375
 			if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
3241 3376
 			{
3242 3377
 				// Houston, we have a problem. The avatar is too large!!
3243
-				if ($modSettings['avatar_action_too_large'] == 'option_refuse')
3244
-					return 'bad_avatar_too_large';
3245
-				elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3378
+				if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
3379
+									return 'bad_avatar_too_large';
3380
+				} elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3246 3381
 				{
3247 3382
 					// @todo remove this if appropriate
3248 3383
 					require_once($sourcedir . '/Subs-Graphics.php');
@@ -3252,26 +3387,27 @@  discard block
 block discarded – undo
3252 3387
 						$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
3253 3388
 						$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
3254 3389
 						$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
3390
+					} else {
3391
+											return 'bad_avatar';
3255 3392
 					}
3256
-					else
3257
-						return 'bad_avatar';
3258 3393
 				}
3259 3394
 			}
3260 3395
 		}
3261
-	}
3262
-	elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3396
+	} elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3263 3397
 	{
3264 3398
 		if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
3265 3399
 		{
3266 3400
 			// Get the dimensions of the image.
3267 3401
 			if (!$downloadedExternalAvatar)
3268 3402
 			{
3269
-				if (!is_writable($uploadDir))
3270
-					fatal_lang_error('attachments_no_write', 'critical');
3403
+				if (!is_writable($uploadDir)) {
3404
+									fatal_lang_error('attachments_no_write', 'critical');
3405
+				}
3271 3406
 
3272 3407
 				$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
3273
-				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
3274
-					fatal_lang_error('attach_timeout', 'critical');
3408
+				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) {
3409
+									fatal_lang_error('attach_timeout', 'critical');
3410
+				}
3275 3411
 
3276 3412
 				$_FILES['attachment']['tmp_name'] = $new_filename;
3277 3413
 			}
@@ -3384,17 +3520,19 @@  discard block
 block discarded – undo
3384 3520
 			$profile_vars['avatar'] = '';
3385 3521
 
3386 3522
 			// Delete any temporary file.
3387
-			if (file_exists($_FILES['attachment']['tmp_name']))
3388
-				@unlink($_FILES['attachment']['tmp_name']);
3523
+			if (file_exists($_FILES['attachment']['tmp_name'])) {
3524
+							@unlink($_FILES['attachment']['tmp_name']);
3525
+			}
3389 3526
 		}
3390 3527
 		// Selected the upload avatar option and had one already uploaded before or didn't upload one.
3391
-		else
3528
+		else {
3529
+					$profile_vars['avatar'] = '';
3530
+		}
3531
+	} elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) {
3532
+			$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3533
+	} else {
3392 3534
 			$profile_vars['avatar'] = '';
3393 3535
 	}
3394
-	elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar'))
3395
-		$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3396
-	else
3397
-		$profile_vars['avatar'] = '';
3398 3536
 
3399 3537
 	// Setup the profile variables so it shows things right on display!
3400 3538
 	$cur_profile['avatar'] = $profile_vars['avatar'];
@@ -3442,9 +3580,9 @@  discard block
 block discarded – undo
3442 3580
 		$smiley_parsed = $unparsed_signature;
3443 3581
 		parsesmileys($smiley_parsed);
3444 3582
 		$smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
3445
-		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
3446
-			return 'signature_allow_smileys';
3447
-		elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3583
+		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) {
3584
+					return 'signature_allow_smileys';
3585
+		} elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3448 3586
 		{
3449 3587
 			$txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
3450 3588
 			return 'signature_max_smileys';
@@ -3457,14 +3595,15 @@  discard block
 block discarded – undo
3457 3595
 			{
3458 3596
 				$limit_broke = 0;
3459 3597
 				// Attempt to allow all sizes of abuse, so to speak.
3460
-				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
3461
-					$limit_broke = $sig_limits[7] . 'px';
3462
-				elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
3463
-					$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3464
-				elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
3465
-					$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3466
-				elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
3467
-					$limit_broke = 'large';
3598
+				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
3599
+									$limit_broke = $sig_limits[7] . 'px';
3600
+				} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
3601
+									$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3602
+				} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
3603
+									$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3604
+				} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
3605
+									$limit_broke = 'large';
3606
+				}
3468 3607
 
3469 3608
 				if ($limit_broke)
3470 3609
 				{
@@ -3506,24 +3645,26 @@  discard block
 block discarded – undo
3506 3645
 					$width = -1; $height = -1;
3507 3646
 
3508 3647
 					// Does it have predefined restraints? Width first.
3509
-					if ($matches[6][$key])
3510
-						$matches[2][$key] = $matches[6][$key];
3648
+					if ($matches[6][$key]) {
3649
+											$matches[2][$key] = $matches[6][$key];
3650
+					}
3511 3651
 					if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
3512 3652
 					{
3513 3653
 						$width = $sig_limits[5];
3514 3654
 						$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
3655
+					} elseif ($matches[2][$key]) {
3656
+											$width = $matches[2][$key];
3515 3657
 					}
3516
-					elseif ($matches[2][$key])
3517
-						$width = $matches[2][$key];
3518 3658
 					// ... and height.
3519 3659
 					if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
3520 3660
 					{
3521 3661
 						$height = $sig_limits[6];
3522
-						if ($width != -1)
3523
-							$width = $width * ($height / $matches[4][$key]);
3662
+						if ($width != -1) {
3663
+													$width = $width * ($height / $matches[4][$key]);
3664
+						}
3665
+					} elseif ($matches[4][$key]) {
3666
+											$height = $matches[4][$key];
3524 3667
 					}
3525
-					elseif ($matches[4][$key])
3526
-						$height = $matches[4][$key];
3527 3668
 
3528 3669
 					// If the dimensions are still not fixed - we need to check the actual image.
3529 3670
 					if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -3541,21 +3682,24 @@  discard block
 block discarded – undo
3541 3682
 							if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
3542 3683
 							{
3543 3684
 								$height = $sig_limits[6];
3544
-								if ($width == -1)
3545
-									$width = $sizes[0];
3685
+								if ($width == -1) {
3686
+																	$width = $sizes[0];
3687
+								}
3546 3688
 								$width = $width * ($height / $sizes[1]);
3689
+							} elseif ($width != -1) {
3690
+															$height = $sizes[1];
3547 3691
 							}
3548
-							elseif ($width != -1)
3549
-								$height = $sizes[1];
3550 3692
 						}
3551 3693
 					}
3552 3694
 
3553 3695
 					// Did we come up with some changes? If so remake the string.
3554
-					if ($width != -1 || $height != -1)
3555
-						$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3696
+					if ($width != -1 || $height != -1) {
3697
+											$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3698
+					}
3699
+				}
3700
+				if (!empty($replaces)) {
3701
+									$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3556 3702
 				}
3557
-				if (!empty($replaces))
3558
-					$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3559 3703
 			}
3560 3704
 		}
3561 3705
 
@@ -3599,10 +3743,12 @@  discard block
 block discarded – undo
3599 3743
 	$email = strtr($email, array('&#039;' => '\''));
3600 3744
 
3601 3745
 	// Check the name and email for validity.
3602
-	if (trim($email) == '')
3603
-		return 'no_email';
3604
-	if (!filter_var($email, FILTER_VALIDATE_EMAIL))
3605
-		return 'bad_email';
3746
+	if (trim($email) == '') {
3747
+			return 'no_email';
3748
+	}
3749
+	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
3750
+			return 'bad_email';
3751
+	}
3606 3752
 
3607 3753
 	// Email addresses should be and stay unique.
3608 3754
 	$request = $smcFunc['db_query']('', '
@@ -3617,8 +3763,9 @@  discard block
 block discarded – undo
3617 3763
 		)
3618 3764
 	);
3619 3765
 
3620
-	if ($smcFunc['db_num_rows']($request) > 0)
3621
-		return 'email_taken';
3766
+	if ($smcFunc['db_num_rows']($request) > 0) {
3767
+			return 'email_taken';
3768
+	}
3622 3769
 	$smcFunc['db_free_result']($request);
3623 3770
 
3624 3771
 	return true;
@@ -3631,8 +3778,9 @@  discard block
 block discarded – undo
3631 3778
 {
3632 3779
 	global $modSettings, $context, $cur_profile;
3633 3780
 
3634
-	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
3635
-		setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3781
+	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') {
3782
+			setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3783
+	}
3636 3784
 
3637 3785
 	loadUserSettings();
3638 3786
 	writeLog();
@@ -3648,8 +3796,9 @@  discard block
 block discarded – undo
3648 3796
 	require_once($sourcedir . '/Subs-Post.php');
3649 3797
 
3650 3798
 	// Shouldn't happen but just in case.
3651
-	if (empty($profile_vars['email_address']))
3652
-		return;
3799
+	if (empty($profile_vars['email_address'])) {
3800
+			return;
3801
+	}
3653 3802
 
3654 3803
 	$replacements = array(
3655 3804
 		'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
@@ -3672,8 +3821,9 @@  discard block
 block discarded – undo
3672 3821
 	$_SESSION['log_time'] = 0;
3673 3822
 	$_SESSION['login_' . $cookiename] = json_encode(array(0, '', 0));
3674 3823
 
3675
-	if (isset($_COOKIE[$cookiename]))
3676
-		$_COOKIE[$cookiename] = '';
3824
+	if (isset($_COOKIE[$cookiename])) {
3825
+			$_COOKIE[$cookiename] = '';
3826
+	}
3677 3827
 
3678 3828
 	loadUserSettings();
3679 3829
 
@@ -3706,11 +3856,13 @@  discard block
 block discarded – undo
3706 3856
 	$groups[] = $curMember['id_group'];
3707 3857
 
3708 3858
 	// Ensure the query doesn't croak!
3709
-	if (empty($groups))
3710
-		$groups = array(0);
3859
+	if (empty($groups)) {
3860
+			$groups = array(0);
3861
+	}
3711 3862
 	// Just to be sure...
3712
-	foreach ($groups as $k => $v)
3713
-		$groups[$k] = (int) $v;
3863
+	foreach ($groups as $k => $v) {
3864
+			$groups[$k] = (int) $v;
3865
+	}
3714 3866
 
3715 3867
 	// Get all the membergroups they can join.
3716 3868
 	$request = $smcFunc['db_query']('', '
@@ -3740,12 +3892,14 @@  discard block
 block discarded – undo
3740 3892
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3741 3893
 	{
3742 3894
 		// Can they edit their primary group?
3743
-		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
3744
-			$context['can_edit_primary'] = true;
3895
+		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) {
3896
+					$context['can_edit_primary'] = true;
3897
+		}
3745 3898
 
3746 3899
 		// If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
3747
-		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
3748
-			continue;
3900
+		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) {
3901
+					continue;
3902
+		}
3749 3903
 
3750 3904
 		$context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
3751 3905
 			'id' => $row['id_group'],
@@ -3774,13 +3928,15 @@  discard block
 block discarded – undo
3774 3928
 	);
3775 3929
 
3776 3930
 	// No changing primary one unless you have enough groups!
3777
-	if (count($context['groups']['member']) < 2)
3778
-		$context['can_edit_primary'] = false;
3931
+	if (count($context['groups']['member']) < 2) {
3932
+			$context['can_edit_primary'] = false;
3933
+	}
3779 3934
 
3780 3935
 	// In the special case that someone is requesting membership of a group, setup some special context vars.
3781
-	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
3782
-		$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3783
-}
3936
+	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) {
3937
+			$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3938
+	}
3939
+	}
3784 3940
 
3785 3941
 /**
3786 3942
  * This function actually makes all the group changes
@@ -3795,10 +3951,12 @@  discard block
 block discarded – undo
3795 3951
 	global $user_info, $context, $user_profile, $modSettings, $smcFunc;
3796 3952
 
3797 3953
 	// Let's be extra cautious...
3798
-	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
3799
-		isAllowedTo('manage_membergroups');
3800
-	if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
3801
-		fatal_lang_error('no_access', false);
3954
+	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) {
3955
+			isAllowedTo('manage_membergroups');
3956
+	}
3957
+	if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) {
3958
+			fatal_lang_error('no_access', false);
3959
+	}
3802 3960
 
3803 3961
 	checkSession(isset($_GET['gid']) ? 'get' : 'post');
3804 3962
 
@@ -3817,8 +3975,9 @@  discard block
 block discarded – undo
3817 3975
 	$foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
3818 3976
 
3819 3977
 	// Sanity check!!
3820
-	if ($group_id == 1)
3821
-		isAllowedTo('admin_forum');
3978
+	if ($group_id == 1) {
3979
+			isAllowedTo('admin_forum');
3980
+	}
3822 3981
 	// Protected groups too!
3823 3982
 	else
3824 3983
 	{
@@ -3835,8 +3994,9 @@  discard block
 block discarded – undo
3835 3994
 		list ($is_protected) = $smcFunc['db_fetch_row']($request);
3836 3995
 		$smcFunc['db_free_result']($request);
3837 3996
 
3838
-		if ($is_protected == 1)
3839
-			isAllowedTo('admin_forum');
3997
+		if ($is_protected == 1) {
3998
+					isAllowedTo('admin_forum');
3999
+		}
3840 4000
 	}
3841 4001
 
3842 4002
 	// What ever we are doing, we need to determine if changing primary is possible!
@@ -3858,36 +4018,43 @@  discard block
 block discarded – undo
3858 4018
 			$group_name = $row['group_name'];
3859 4019
 
3860 4020
 			// Does the group type match what we're doing - are we trying to request a non-requestable group?
3861
-			if ($changeType == 'request' && $row['group_type'] != 2)
3862
-				fatal_lang_error('no_access', false);
4021
+			if ($changeType == 'request' && $row['group_type'] != 2) {
4022
+							fatal_lang_error('no_access', false);
4023
+			}
3863 4024
 			// What about leaving a requestable group we are not a member of?
3864
-			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
3865
-				fatal_lang_error('no_access', false);
3866
-			elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
3867
-				fatal_lang_error('no_access', false);
4025
+			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) {
4026
+							fatal_lang_error('no_access', false);
4027
+			} elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) {
4028
+							fatal_lang_error('no_access', false);
4029
+			}
3868 4030
 
3869 4031
 			// We can't change the primary group if this is hidden!
3870
-			if ($row['hidden'] == 2)
3871
-				$canChangePrimary = false;
4032
+			if ($row['hidden'] == 2) {
4033
+							$canChangePrimary = false;
4034
+			}
3872 4035
 		}
3873 4036
 
3874 4037
 		// If this is their old primary, can we change it?
3875
-		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
3876
-			$canChangePrimary = 1;
4038
+		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) {
4039
+					$canChangePrimary = 1;
4040
+		}
3877 4041
 
3878 4042
 		// If we are not doing a force primary move, don't do it automatically if current primary is not 0.
3879
-		if ($changeType != 'primary' && $old_profile['id_group'] != 0)
3880
-			$canChangePrimary = false;
4043
+		if ($changeType != 'primary' && $old_profile['id_group'] != 0) {
4044
+					$canChangePrimary = false;
4045
+		}
3881 4046
 
3882 4047
 		// If this is the one we are acting on, can we even act?
3883
-		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
3884
-			$canChangePrimary = false;
4048
+		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) {
4049
+					$canChangePrimary = false;
4050
+		}
3885 4051
 	}
3886 4052
 	$smcFunc['db_free_result']($request);
3887 4053
 
3888 4054
 	// Didn't find the target?
3889
-	if (!$foundTarget)
3890
-		fatal_lang_error('no_access', false);
4055
+	if (!$foundTarget) {
4056
+			fatal_lang_error('no_access', false);
4057
+	}
3891 4058
 
3892 4059
 	// Final security check, don't allow users to promote themselves to admin.
3893 4060
 	if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
@@ -3907,8 +4074,9 @@  discard block
 block discarded – undo
3907 4074
 		list ($disallow) = $smcFunc['db_fetch_row']($request);
3908 4075
 		$smcFunc['db_free_result']($request);
3909 4076
 
3910
-		if ($disallow)
3911
-			isAllowedTo('admin_forum');
4077
+		if ($disallow) {
4078
+					isAllowedTo('admin_forum');
4079
+		}
3912 4080
 	}
3913 4081
 
3914 4082
 	// If we're requesting, add the note then return.
@@ -3926,8 +4094,9 @@  discard block
 block discarded – undo
3926 4094
 				'status_open' => 0,
3927 4095
 			)
3928 4096
 		);
3929
-		if ($smcFunc['db_num_rows']($request) != 0)
3930
-			fatal_lang_error('profile_error_already_requested_group');
4097
+		if ($smcFunc['db_num_rows']($request) != 0) {
4098
+					fatal_lang_error('profile_error_already_requested_group');
4099
+		}
3931 4100
 		$smcFunc['db_free_result']($request);
3932 4101
 
3933 4102
 		// Log the request.
@@ -3961,10 +4130,11 @@  discard block
 block discarded – undo
3961 4130
 		// Are we leaving?
3962 4131
 		if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
3963 4132
 		{
3964
-			if ($old_profile['id_group'] == $group_id)
3965
-				$newPrimary = 0;
3966
-			else
3967
-				unset($addGroups[$group_id]);
4133
+			if ($old_profile['id_group'] == $group_id) {
4134
+							$newPrimary = 0;
4135
+			} else {
4136
+							unset($addGroups[$group_id]);
4137
+			}
3968 4138
 		}
3969 4139
 		// ... if not, must be joining.
3970 4140
 		else
@@ -3972,36 +4142,42 @@  discard block
 block discarded – undo
3972 4142
 			// Can we change the primary, and do we want to?
3973 4143
 			if ($canChangePrimary)
3974 4144
 			{
3975
-				if ($old_profile['id_group'] != 0)
3976
-					$addGroups[$old_profile['id_group']] = -1;
4145
+				if ($old_profile['id_group'] != 0) {
4146
+									$addGroups[$old_profile['id_group']] = -1;
4147
+				}
3977 4148
 				$newPrimary = $group_id;
3978 4149
 			}
3979 4150
 			// Otherwise it's an additional group...
3980
-			else
3981
-				$addGroups[$group_id] = -1;
4151
+			else {
4152
+							$addGroups[$group_id] = -1;
4153
+			}
3982 4154
 		}
3983 4155
 	}
3984 4156
 	// Finally, we must be setting the primary.
3985 4157
 	elseif ($canChangePrimary)
3986 4158
 	{
3987
-		if ($old_profile['id_group'] != 0)
3988
-			$addGroups[$old_profile['id_group']] = -1;
3989
-		if (isset($addGroups[$group_id]))
3990
-			unset($addGroups[$group_id]);
4159
+		if ($old_profile['id_group'] != 0) {
4160
+					$addGroups[$old_profile['id_group']] = -1;
4161
+		}
4162
+		if (isset($addGroups[$group_id])) {
4163
+					unset($addGroups[$group_id]);
4164
+		}
3991 4165
 		$newPrimary = $group_id;
3992 4166
 	}
3993 4167
 
3994 4168
 	// Finally, we can make the changes!
3995
-	foreach ($addGroups as $id => $dummy)
3996
-		if (empty($id))
4169
+	foreach ($addGroups as $id => $dummy) {
4170
+			if (empty($id))
3997 4171
 			unset($addGroups[$id]);
4172
+	}
3998 4173
 	$addGroups = implode(',', array_flip($addGroups));
3999 4174
 
4000 4175
 	// Ensure that we don't cache permissions if the group is changing.
4001
-	if ($context['user']['is_owner'])
4002
-		$_SESSION['mc']['time'] = 0;
4003
-	else
4004
-		updateSettings(array('settings_updated' => time()));
4176
+	if ($context['user']['is_owner']) {
4177
+			$_SESSION['mc']['time'] = 0;
4178
+	} else {
4179
+			updateSettings(array('settings_updated' => time()));
4180
+	}
4005 4181
 
4006 4182
 	updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
4007 4183
 
@@ -4024,8 +4200,9 @@  discard block
 block discarded – undo
4024 4200
 	if (empty($user_settings['tfa_secret']) && $context['user']['is_owner'])
4025 4201
 	{
4026 4202
 		// Check to ensure we're forcing SSL for authentication
4027
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
4028
-			fatal_lang_error('login_ssl_required');
4203
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
4204
+					fatal_lang_error('login_ssl_required');
4205
+		}
4029 4206
 
4030 4207
 		// In some cases (forced 2FA or backup code) they would be forced to be redirected here,
4031 4208
 		// we do not want too much AJAX to confuse them.
@@ -4062,8 +4239,7 @@  discard block
 block discarded – undo
4062 4239
 				$context['sub_template'] = 'tfasetup_backup';
4063 4240
 
4064 4241
 				return;
4065
-			}
4066
-			else
4242
+			} else
4067 4243
 			{
4068 4244
 				$context['tfa_secret'] = $_SESSION['tfa_secret'];
4069 4245
 				$context['tfa_error'] = !$valid_code;
@@ -4071,8 +4247,7 @@  discard block
 block discarded – undo
4071 4247
 				$context['tfa_pass_value'] = $_POST['passwd'];
4072 4248
 				$context['tfa_value'] = $_POST['tfa_code'];
4073 4249
 			}
4074
-		}
4075
-		else
4250
+		} else
4076 4251
 		{
4077 4252
 			$totp = new \TOTP\Auth();
4078 4253
 			$secret = $totp->generateCode();
@@ -4082,17 +4257,16 @@  discard block
 block discarded – undo
4082 4257
 		}
4083 4258
 
4084 4259
 		$context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']);
4085
-	}
4086
-	elseif (isset($_REQUEST['disable']))
4260
+	} elseif (isset($_REQUEST['disable']))
4087 4261
 	{
4088 4262
 		updateMemberData($memID, array(
4089 4263
 			'tfa_secret' => '',
4090 4264
 			'tfa_backup' => '',
4091 4265
 		));
4092 4266
 		redirectexit('action=profile;area=account;u=' . $memID);
4267
+	} else {
4268
+			redirectexit('action=profile;area=account;u=' . $memID);
4269
+	}
4093 4270
 	}
4094
-	else
4095
-		redirectexit('action=profile;area=account;u=' . $memID);
4096
-}
4097 4271
 
4098 4272
 ?>
4099 4273
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 1 patch
Braces   +211 added lines, -156 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Maps the implementations in this file (smf_db_function_name)
@@ -34,8 +35,8 @@  discard block
 block discarded – undo
34 35
 	global $smcFunc;
35 36
 
36 37
 	// Map some database specific functions, only do this once.
37
-	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc')
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc') {
39
+			$smcFunc += array(
39 40
 			'db_query' => 'smf_db_query',
40 41
 			'db_quote' => 'smf_db_quote',
41 42
 			'db_insert' => 'smf_db_insert',
@@ -59,11 +60,13 @@  discard block
 block discarded – undo
59 60
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
60 61
 			'db_is_resource' => 'is_resource',
61 62
 		);
63
+	}
62 64
 
63
-	if (!empty($db_options['persist']))
64
-		$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
65
-	else
66
-		$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
65
+	if (!empty($db_options['persist'])) {
66
+			$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
67
+	} else {
68
+			$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
69
+	}
67 70
 
68 71
 	// Something's wrong, show an error if its fatal (which we assume it is)
69 72
 	if (!$connection)
@@ -71,8 +74,7 @@  discard block
 block discarded – undo
71 74
 		if (!empty($db_options['non_fatal']))
72 75
 		{
73 76
 			return null;
74
-		}
75
-		else
77
+		} else
76 78
 		{
77 79
 			display_db_error();
78 80
 		}
@@ -123,34 +125,42 @@  discard block
 block discarded – undo
123 125
 
124 126
 	list ($values, $connection) = $db_callback;
125 127
 
126
-	if ($matches[1] === 'db_prefix')
127
-		return $db_prefix;
128
+	if ($matches[1] === 'db_prefix') {
129
+			return $db_prefix;
130
+	}
128 131
 
129
-	if ($matches[1] === 'query_see_board')
130
-		return $user_info['query_see_board'];
132
+	if ($matches[1] === 'query_see_board') {
133
+			return $user_info['query_see_board'];
134
+	}
131 135
 
132
-	if ($matches[1] === 'query_wanna_see_board')
133
-		return $user_info['query_wanna_see_board'];
136
+	if ($matches[1] === 'query_wanna_see_board') {
137
+			return $user_info['query_wanna_see_board'];
138
+	}
134 139
 
135
-	if ($matches[1] === 'empty')
136
-		return '\'\'';
140
+	if ($matches[1] === 'empty') {
141
+			return '\'\'';
142
+	}
137 143
 
138
-	if (!isset($matches[2]))
139
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
144
+	if (!isset($matches[2])) {
145
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
146
+	}
140 147
 
141
-	if ($matches[1] === 'literal')
142
-		return '\'' . pg_escape_string($matches[2]) . '\'';
148
+	if ($matches[1] === 'literal') {
149
+			return '\'' . pg_escape_string($matches[2]) . '\'';
150
+	}
143 151
 
144
-	if (!isset($values[$matches[2]]))
145
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
152
+	if (!isset($values[$matches[2]])) {
153
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
154
+	}
146 155
 
147 156
 	$replacement = $values[$matches[2]];
148 157
 
149 158
 	switch ($matches[1])
150 159
 	{
151 160
 		case 'int':
152
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
153
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
161
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
162
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
163
+			}
154 164
 			return (string) (int) $replacement;
155 165
 		break;
156 166
 
@@ -162,56 +172,63 @@  discard block
 block discarded – undo
162 172
 		case 'array_int':
163 173
 			if (is_array($replacement))
164 174
 			{
165
-				if (empty($replacement))
166
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
175
+				if (empty($replacement)) {
176
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
177
+				}
167 178
 
168 179
 				foreach ($replacement as $key => $value)
169 180
 				{
170
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
171
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
182
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183
+					}
172 184
 
173 185
 					$replacement[$key] = (string) (int) $value;
174 186
 				}
175 187
 
176 188
 				return implode(', ', $replacement);
189
+			} else {
190
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
177 191
 			}
178
-			else
179
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
180 192
 
181 193
 		break;
182 194
 
183 195
 		case 'array_string':
184 196
 			if (is_array($replacement))
185 197
 			{
186
-				if (empty($replacement))
187
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
198
+				if (empty($replacement)) {
199
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
200
+				}
188 201
 
189
-				foreach ($replacement as $key => $value)
190
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
202
+				foreach ($replacement as $key => $value) {
203
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
204
+				}
191 205
 
192 206
 				return implode(', ', $replacement);
207
+			} else {
208
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
193 209
 			}
194
-			else
195
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
196 210
 		break;
197 211
 
198 212
 		case 'date':
199
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
200
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
201
-			else
202
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
214
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
215
+			} else {
216
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
217
+			}
203 218
 		break;
204 219
 
205 220
 		case 'time':
206
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
207
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
208
-			else
209
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
222
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
223
+			} else {
224
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+			}
210 226
 		break;
211 227
 
212 228
 		case 'float':
213
-			if (!is_numeric($replacement))
214
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
229
+			if (!is_numeric($replacement)) {
230
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+			}
215 232
 			return (string) (float) $replacement;
216 233
 		break;
217 234
 
@@ -224,31 +241,36 @@  discard block
 block discarded – undo
224 241
 		break;
225 242
 
226 243
 		case 'inet':
227
-			if ($replacement == 'null' || $replacement == '')
228
-				return 'null';
229
-			if (inet_pton($replacement) === false)
230
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
244
+			if ($replacement == 'null' || $replacement == '') {
245
+							return 'null';
246
+			}
247
+			if (inet_pton($replacement) === false) {
248
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249
+			}
231 250
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
232 251
 
233 252
 		case 'array_inet':
234 253
 			if (is_array($replacement))
235 254
 			{
236
-				if (empty($replacement))
237
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
255
+				if (empty($replacement)) {
256
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
257
+				}
238 258
 
239 259
 				foreach ($replacement as $key => $value)
240 260
 				{
241
-					if ($replacement == 'null' || $replacement == '')
242
-						$replacement[$key] = 'null';
243
-					if (!isValidIP($value))
244
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
261
+					if ($replacement == 'null' || $replacement == '') {
262
+											$replacement[$key] = 'null';
263
+					}
264
+					if (!isValidIP($value)) {
265
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+					}
245 267
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
246 268
 				}
247 269
 
248 270
 				return implode(', ', $replacement);
271
+			} else {
272
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249 273
 			}
250
-			else
251
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
252 274
 		break;
253 275
 
254 276
 		default:
@@ -335,14 +357,16 @@  discard block
 block discarded – undo
335 357
 		),
336 358
 	);
337 359
 
338
-	if (isset($replacements[$identifier]))
339
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
360
+	if (isset($replacements[$identifier])) {
361
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
362
+	}
340 363
 
341 364
 	// Limits need to be a little different.
342 365
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
343 366
 
344
-	if (trim($db_string) == '')
345
-		return false;
367
+	if (trim($db_string) == '') {
368
+			return false;
369
+	}
346 370
 
347 371
 	// Comments that are allowed in a query are preg_removed.
348 372
 	static $allowed_comments_from = array(
@@ -362,8 +386,9 @@  discard block
 block discarded – undo
362 386
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
363 387
 	$db_replace_result = 0;
364 388
 
365
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
366
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
389
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
390
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
391
+	}
367 392
 
368 393
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
369 394
 	{
@@ -384,8 +409,9 @@  discard block
 block discarded – undo
384 409
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
385 410
 
386 411
 		// Initialize $db_cache if not already initialized.
387
-		if (!isset($db_cache))
388
-			$db_cache = array();
412
+		if (!isset($db_cache)) {
413
+					$db_cache = array();
414
+		}
389 415
 
390 416
 		if (!empty($_SESSION['debug_redirect']))
391 417
 		{
@@ -411,17 +437,18 @@  discard block
 block discarded – undo
411 437
 		while (true)
412 438
 		{
413 439
 			$pos = strpos($db_string, '\'', $pos + 1);
414
-			if ($pos === false)
415
-				break;
440
+			if ($pos === false) {
441
+							break;
442
+			}
416 443
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
417 444
 
418 445
 			while (true)
419 446
 			{
420 447
 				$pos1 = strpos($db_string, '\'', $pos + 1);
421 448
 				$pos2 = strpos($db_string, '\\', $pos + 1);
422
-				if ($pos1 === false)
423
-					break;
424
-				elseif ($pos2 === false || $pos2 > $pos1)
449
+				if ($pos1 === false) {
450
+									break;
451
+				} elseif ($pos2 === false || $pos2 > $pos1)
425 452
 				{
426 453
 					$pos = $pos1;
427 454
 					break;
@@ -437,26 +464,31 @@  discard block
 block discarded – undo
437 464
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
438 465
 
439 466
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
440
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
441
-			$fail = true;
467
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
468
+					$fail = true;
469
+		}
442 470
 		// Trying to change passwords, slow us down, or something?
443
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
444
-			$fail = true;
445
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
446
-			$fail = true;
471
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
472
+					$fail = true;
473
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
474
+					$fail = true;
475
+		}
447 476
 
448
-		if (!empty($fail) && function_exists('log_error'))
449
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
477
+		if (!empty($fail) && function_exists('log_error')) {
478
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
479
+		}
450 480
 	}
451 481
 
452 482
 	$db_last_result = @pg_query($connection, $db_string);
453 483
 
454
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
455
-		$db_last_result = smf_db_error($db_string, $connection);
484
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
485
+			$db_last_result = smf_db_error($db_string, $connection);
486
+	}
456 487
 
457 488
 	// Debugging.
458
-	if (isset($db_show_debug) && $db_show_debug === true)
459
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
489
+	if (isset($db_show_debug) && $db_show_debug === true) {
490
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
491
+	}
460 492
 
461 493
 	return $db_last_result;
462 494
 }
@@ -469,10 +501,11 @@  discard block
 block discarded – undo
469 501
 {
470 502
 	global $db_last_result, $db_replace_result;
471 503
 
472
-	if ($db_replace_result)
473
-		return $db_replace_result;
474
-	elseif ($result === null && !$db_last_result)
475
-		return 0;
504
+	if ($db_replace_result) {
505
+			return $db_replace_result;
506
+	} elseif ($result === null && !$db_last_result) {
507
+			return 0;
508
+	}
476 509
 
477 510
 	return pg_affected_rows($result === null ? $db_last_result : $result);
478 511
 }
@@ -491,16 +524,18 @@  discard block
 block discarded – undo
491 524
 
492 525
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
493 526
 
494
-	if ($connection === false)
495
-		$connection = $db_connection;
527
+	if ($connection === false) {
528
+			$connection = $db_connection;
529
+	}
496 530
 
497 531
 	// Try get the last ID for the auto increment field.
498 532
 	$request = $smcFunc['db_query']('', 'SELECT CURRVAL(\'' . $table . '_seq\') AS insertID',
499 533
 		array(
500 534
 		)
501 535
 	);
502
-	if (!$request)
503
-		return false;
536
+	if (!$request) {
537
+			return false;
538
+	}
504 539
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
505 540
 	$smcFunc['db_free_result']($request);
506 541
 
@@ -521,12 +556,13 @@  discard block
 block discarded – undo
521 556
 	// Decide which connection to use
522 557
 	$connection = $connection === null ? $db_connection : $connection;
523 558
 
524
-	if ($type == 'begin')
525
-		return @pg_query($connection, 'BEGIN');
526
-	elseif ($type == 'rollback')
527
-		return @pg_query($connection, 'ROLLBACK');
528
-	elseif ($type == 'commit')
529
-		return @pg_query($connection, 'COMMIT');
559
+	if ($type == 'begin') {
560
+			return @pg_query($connection, 'BEGIN');
561
+	} elseif ($type == 'rollback') {
562
+			return @pg_query($connection, 'ROLLBACK');
563
+	} elseif ($type == 'commit') {
564
+			return @pg_query($connection, 'COMMIT');
565
+	}
530 566
 
531 567
 	return false;
532 568
 }
@@ -554,19 +590,22 @@  discard block
 block discarded – undo
554 590
 	$query_error = @pg_last_error($connection);
555 591
 
556 592
 	// Log the error.
557
-	if (function_exists('log_error'))
558
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
593
+	if (function_exists('log_error')) {
594
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
595
+	}
559 596
 
560 597
 	// Nothing's defined yet... just die with it.
561
-	if (empty($context) || empty($txt))
562
-		die($query_error);
598
+	if (empty($context) || empty($txt)) {
599
+			die($query_error);
600
+	}
563 601
 
564 602
 	// Show an error message, if possible.
565 603
 	$context['error_title'] = $txt['database_error'];
566
-	if (allowedTo('admin_forum'))
567
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
568
-	else
569
-		$context['error_message'] = $txt['try_again'];
604
+	if (allowedTo('admin_forum')) {
605
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
606
+	} else {
607
+			$context['error_message'] = $txt['try_again'];
608
+	}
570 609
 
571 610
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
572 611
 	{
@@ -588,12 +627,14 @@  discard block
 block discarded – undo
588 627
 {
589 628
 	global $db_row_count;
590 629
 
591
-	if ($counter !== false)
592
-		return pg_fetch_row($request, $counter);
630
+	if ($counter !== false) {
631
+			return pg_fetch_row($request, $counter);
632
+	}
593 633
 
594 634
 	// Reset the row counter...
595
-	if (!isset($db_row_count[(int) $request]))
596
-		$db_row_count[(int) $request] = 0;
635
+	if (!isset($db_row_count[(int) $request])) {
636
+			$db_row_count[(int) $request] = 0;
637
+	}
597 638
 
598 639
 	// Return the right row.
599 640
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -610,12 +651,14 @@  discard block
 block discarded – undo
610 651
 {
611 652
 	global $db_row_count;
612 653
 
613
-	if ($counter !== false)
614
-		return pg_fetch_assoc($request, $counter);
654
+	if ($counter !== false) {
655
+			return pg_fetch_assoc($request, $counter);
656
+	}
615 657
 
616 658
 	// Reset the row counter...
617
-	if (!isset($db_row_count[(int) $request]))
618
-		$db_row_count[(int) $request] = 0;
659
+	if (!isset($db_row_count[(int) $request])) {
660
+			$db_row_count[(int) $request] = 0;
661
+	}
619 662
 
620 663
 	// Return the right row.
621 664
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -667,11 +710,13 @@  discard block
 block discarded – undo
667 710
 
668 711
 	$replace = '';
669 712
 
670
-	if (empty($data))
671
-		return;
713
+	if (empty($data)) {
714
+			return;
715
+	}
672 716
 
673
-	if (!is_array($data[array_rand($data)]))
674
-		$data = array($data);
717
+	if (!is_array($data[array_rand($data)])) {
718
+			$data = array($data);
719
+	}
675 720
 
676 721
 	// Replace the prefix holder with the actual prefix.
677 722
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -697,11 +742,13 @@  discard block
 block discarded – undo
697 742
 			//pg 9.5 got replace support
698 743
 			$pg_version = $smcFunc['db_get_version']();
699 744
 			// if we got a Beta Version
700
-			if (stripos($pg_version, 'beta') !== false)
701
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
745
+			if (stripos($pg_version, 'beta') !== false) {
746
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
747
+			}
702 748
 			// or RC
703
-			if (stripos($pg_version, 'rc') !== false)
704
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
749
+			if (stripos($pg_version, 'rc') !== false) {
750
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
751
+			}
705 752
 
706 753
 			$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
707 754
 		}
@@ -720,8 +767,7 @@  discard block
 block discarded – undo
720 767
 					$key_str .= ($count_pk > 0 ? ',' : '');
721 768
 					$key_str .= $columnName;
722 769
 					$count_pk++;
723
-				}
724
-				else //normal field
770
+				} else //normal field
725 771
 				{
726 772
 					$col_str .= ($count > 0 ? ',' : '');
727 773
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
@@ -729,20 +775,21 @@  discard block
 block discarded – undo
729 775
 				}
730 776
 			}
731 777
 			$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
732
-		}
733
-		else
778
+		} else
734 779
 		{
735 780
 			foreach ($columns as $columnName => $type)
736 781
 			{
737 782
 				// Are we restricting the length?
738
-				if (strpos($type, 'string-') !== false)
739
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
740
-				else
741
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
783
+				if (strpos($type, 'string-') !== false) {
784
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
785
+				} else {
786
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
787
+				}
742 788
 
743 789
 				// A key? That's what we were looking for.
744
-				if (in_array($columnName, $keys))
745
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
790
+				if (in_array($columnName, $keys)) {
791
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
792
+				}
746 793
 				$count++;
747 794
 			}
748 795
 
@@ -768,10 +815,11 @@  discard block
 block discarded – undo
768 815
 		foreach ($columns as $columnName => $type)
769 816
 		{
770 817
 			// Are we restricting the length?
771
-			if (strpos($type, 'string-') !== false)
772
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
773
-			else
774
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
818
+			if (strpos($type, 'string-') !== false) {
819
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
820
+			} else {
821
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
822
+			}
775 823
 		}
776 824
 		$insertData = substr($insertData, 0, -2) . ')';
777 825
 
@@ -780,11 +828,12 @@  discard block
 block discarded – undo
780 828
 
781 829
 		// Here's where the variables are injected to the query.
782 830
 		$insertRows = array();
783
-		foreach ($data as $dataRow)
784
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
831
+		foreach ($data as $dataRow) {
832
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
833
+		}
785 834
 
786
-		foreach ($insertRows as $entry)
787
-			// Do the insert.
835
+		foreach ($insertRows as $entry) {
836
+					// Do the insert.
788 837
 			$smcFunc['db_query']('', '
789 838
 				INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '")
790 839
 				VALUES
@@ -795,11 +844,13 @@  discard block
 block discarded – undo
795 844
 				),
796 845
 				$connection
797 846
 			);
847
+		}
798 848
 	}
799 849
 
800
-	if ($priv_trans)
801
-		$smcFunc['db_transaction']('commit', $connection);
802
-}
850
+	if ($priv_trans) {
851
+			$smcFunc['db_transaction']('commit', $connection);
852
+	}
853
+	}
803 854
 
804 855
 /**
805 856
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -836,8 +887,9 @@  discard block
 block discarded – undo
836 887
  */
837 888
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
838 889
 {
839
-	if (empty($log_message))
840
-		$log_message = $error_message;
890
+	if (empty($log_message)) {
891
+			$log_message = $error_message;
892
+	}
841 893
 
842 894
 	foreach (debug_backtrace() as $step)
843 895
 	{
@@ -856,12 +908,14 @@  discard block
 block discarded – undo
856 908
 	}
857 909
 
858 910
 	// A special case - we want the file and line numbers for debugging.
859
-	if ($error_type == 'return')
860
-		return array($file, $line);
911
+	if ($error_type == 'return') {
912
+			return array($file, $line);
913
+	}
861 914
 
862 915
 	// Is always a critical error.
863
-	if (function_exists('log_error'))
864
-		log_error($log_message, 'critical', $file, $line);
916
+	if (function_exists('log_error')) {
917
+			log_error($log_message, 'critical', $file, $line);
918
+	}
865 919
 
866 920
 	if (function_exists('fatal_error'))
867 921
 	{
@@ -869,12 +923,12 @@  discard block
 block discarded – undo
869 923
 
870 924
 		// Cannot continue...
871 925
 		exit;
926
+	} elseif ($error_type) {
927
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
928
+	} else {
929
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
930
+	}
872 931
 	}
873
-	elseif ($error_type)
874
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
875
-	else
876
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
877
-}
878 932
 
879 933
 /**
880 934
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -891,10 +945,11 @@  discard block
 block discarded – undo
891 945
 		'\\' => '\\\\',
892 946
 	);
893 947
 
894
-	if ($translate_human_wildcards)
895
-		$replacements += array(
948
+	if ($translate_human_wildcards) {
949
+			$replacements += array(
896 950
 			'*' => '%',
897 951
 		);
952
+	}
898 953
 
899 954
 	return strtr($string, $replacements);
900 955
 }
Please login to merge, or discard this patch.
Sources/Likes.php 1 patch
Braces   +106 added lines, -77 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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
  * Class Likes
@@ -108,8 +109,9 @@  discard block
 block discarded – undo
108 109
 		$this->_extra = isset($_GET['extra']) ? $_GET['extra'] : false;
109 110
 
110 111
 		// We do not want to output debug information here.
111
-		if ($this->_js)
112
-			$db_show_debug = false;
112
+		if ($this->_js) {
113
+					$db_show_debug = false;
114
+		}
113 115
 	}
114 116
 
115 117
 	/**
@@ -143,8 +145,9 @@  discard block
 block discarded – undo
143 145
 			$call = $this->_sa;
144 146
 
145 147
 			// Guest can only view likes.
146
-			if ($call != 'view')
147
-				is_not_guest();
148
+			if ($call != 'view') {
149
+							is_not_guest();
150
+			}
148 151
 
149 152
 			checkSession('get');
150 153
 
@@ -182,15 +185,17 @@  discard block
 block discarded – undo
182 185
 		global $smcFunc, $modSettings;
183 186
 
184 187
 		// This feature is currently disable.
185
-		if (empty($modSettings['enable_likes']))
186
-			return $this->_error = 'like_disable';
188
+		if (empty($modSettings['enable_likes'])) {
189
+					return $this->_error = 'like_disable';
190
+		}
187 191
 
188 192
 		// Zerothly, they did indicate some kind of content to like, right?
189 193
 		preg_match('~^([a-z0-9\-\_]{1,6})~i', $this->_type, $matches);
190 194
 		$this->_type = isset($matches[1]) ? $matches[1] : '';
191 195
 
192
-		if ($this->_type == '' || $this->_content <= 0)
193
-			return $this->_error = 'cannot_';
196
+		if ($this->_type == '' || $this->_content <= 0) {
197
+					return $this->_error = 'cannot_';
198
+		}
194 199
 
195 200
 		// First we need to verify if the user can see the type of content or not. This is set up to be extensible,
196 201
 		// so we'll check for the one type we do know about, and if it's not that, we'll defer to any hooks.
@@ -209,12 +214,14 @@  discard block
 block discarded – undo
209 214
 					'msg' => $this->_content,
210 215
 				)
211 216
 			);
212
-			if ($smcFunc['db_num_rows']($request) == 1)
213
-				list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request);
217
+			if ($smcFunc['db_num_rows']($request) == 1) {
218
+							list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request);
219
+			}
214 220
 
215 221
 			$smcFunc['db_free_result']($request);
216
-			if (empty($this->_idTopic))
217
-				return $this->_error = 'cannot_';
222
+			if (empty($this->_idTopic)) {
223
+							return $this->_error = 'cannot_';
224
+			}
218 225
 
219 226
 			// So we know what topic it's in and more importantly we know the user can see it.
220 227
 			// If we're not viewing, we need some info set up.
@@ -224,9 +231,7 @@  discard block
 block discarded – undo
224 231
 			$this->_validLikes['can_see'] = allowedTo('likes_view') ? true : 'cannot_view_likes';
225 232
 
226 233
 			$this->_validLikes['can_like'] = ($this->_user['id'] == $topicOwner ? 'cannot_like_content' : (allowedTo('likes_like') ? true : 'cannot_like_content'));
227
-		}
228
-
229
-		else
234
+		} else
230 235
 		{
231 236
 			// Modders: This will give you whatever the user offers up in terms of liking, e.g. $this->_type=msg, $this->_content=1
232 237
 			// When you hook this, check $this->_type first. If it is not something your mod worries about, return false.
@@ -244,8 +249,9 @@  discard block
 block discarded – undo
244 249
 					if ($result !== false)
245 250
 					{
246 251
 						// Match the type with what we already have.
247
-						if (!isset($result['type']) || $result['type'] != $this->_type)
248
-							return $this->_error = 'not_valid_like_type';
252
+						if (!isset($result['type']) || $result['type'] != $this->_type) {
253
+													return $this->_error = 'not_valid_like_type';
254
+						}
249 255
 
250 256
 						// Fill out the rest.
251 257
 						$this->_type = $result['type'];
@@ -256,17 +262,20 @@  discard block
 block discarded – undo
256 262
 				}
257 263
 			}
258 264
 
259
-			if (!$found)
260
-				return $this->_error = 'cannot_';
265
+			if (!$found) {
266
+							return $this->_error = 'cannot_';
267
+			}
261 268
 		}
262 269
 
263 270
 		// Does the user can see this?
264
-		if (isset($this->_validLikes['can_see']) && is_string($this->_validLikes['can_see']))
265
-			return $this->_error = $this->_validLikes['can_see'];
271
+		if (isset($this->_validLikes['can_see']) && is_string($this->_validLikes['can_see'])) {
272
+					return $this->_error = $this->_validLikes['can_see'];
273
+		}
266 274
 
267 275
 		// Does the user can like this? Viewing a list of likes doesn't require this permission.
268
-			if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like']))
269
-				return $this->_error = $this->_validLikes['can_like'];
276
+			if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like'])) {
277
+							return $this->_error = $this->_validLikes['can_like'];
278
+			}
270 279
 	}
271 280
 
272 281
 	/**
@@ -291,8 +300,9 @@  discard block
 block discarded – undo
291 300
 		);
292 301
 
293 302
 		// Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name.
294
-		if ($this->_sa == __FUNCTION__)
295
-			$this->_data = __FUNCTION__;
303
+		if ($this->_sa == __FUNCTION__) {
304
+					$this->_data = __FUNCTION__;
305
+		}
296 306
 	}
297 307
 
298 308
 	/**
@@ -322,8 +332,8 @@  discard block
 block discarded – undo
322 332
 
323 333
 		// Add a background task to process sending alerts.
324 334
 		// Mod author, you can add your own background task for your own custom like event using the "integrate_issue_like" hook or your callback, both are immediately called after this.
325
-		if ($this->_type == 'msg')
326
-			$smcFunc['db_insert']('insert',
335
+		if ($this->_type == 'msg') {
336
+					$smcFunc['db_insert']('insert',
327 337
 				'{db_prefix}background_tasks',
328 338
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
329 339
 				array('$sourcedir/tasks/Likes-Notify.php', 'Likes_Notify_Background', json_encode(array(
@@ -335,10 +345,12 @@  discard block
 block discarded – undo
335 345
 				)), 0),
336 346
 				array('id_task')
337 347
 			);
348
+		}
338 349
 
339 350
 		// Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name.
340
-		if ($this->_sa == __FUNCTION__)
341
-			$this->_data = __FUNCTION__;
351
+		if ($this->_sa == __FUNCTION__) {
352
+					$this->_data = __FUNCTION__;
353
+		}
342 354
 	}
343 355
 
344 356
 	/**
@@ -364,8 +376,9 @@  discard block
 block discarded – undo
364 376
 		$smcFunc['db_free_result']($request);
365 377
 
366 378
 		// If you want to call this directly, fill out _data property too.
367
-		if ($this->_sa == __FUNCTION__)
368
-			$this->_data = $this->_numLikes;
379
+		if ($this->_sa == __FUNCTION__) {
380
+					$this->_data = $this->_numLikes;
381
+		}
369 382
 	}
370 383
 
371 384
 	/**
@@ -378,8 +391,9 @@  discard block
 block discarded – undo
378 391
 		global $smcFunc;
379 392
 
380 393
 		// Safety first!
381
-		if (empty($this->_type) || empty($this->_content))
382
-			return $this->_error = 'cannot_';
394
+		if (empty($this->_type) || empty($this->_content)) {
395
+					return $this->_error = 'cannot_';
396
+		}
383 397
 
384 398
 		// Do we already like this?
385 399
 		$request = $smcFunc['db_query']('', '
@@ -397,26 +411,28 @@  discard block
 block discarded – undo
397 411
 		$this->_alreadyLiked = (bool) $smcFunc['db_num_rows']($request) != 0;
398 412
 		$smcFunc['db_free_result']($request);
399 413
 
400
-		if ($this->_alreadyLiked)
401
-			$this->delete();
402
-
403
-		else
404
-			$this->insert();
414
+		if ($this->_alreadyLiked) {
415
+					$this->delete();
416
+		} else {
417
+					$this->insert();
418
+		}
405 419
 
406 420
 		// Now, how many people like this content now? We *could* just +1 / -1 the relevant container but that has proven to become unstable.
407 421
 		$this->_count();
408 422
 
409 423
 		// Update the likes count for messages.
410
-		if ($this->_type == 'msg')
411
-			$this->msgIssueLike();
424
+		if ($this->_type == 'msg') {
425
+					$this->msgIssueLike();
426
+		}
412 427
 
413 428
 		// Any callbacks?
414 429
 		elseif (!empty($this->_validLikes['callback']))
415 430
 		{
416 431
 			$call = call_helper($this->_validLikes['callback'], true);
417 432
 
418
-			if (!empty($call))
419
-				call_user_func_array($call, array($this));
433
+			if (!empty($call)) {
434
+							call_user_func_array($call, array($this));
435
+			}
420 436
 		}
421 437
 
422 438
 		// Sometimes there might be other things that need updating after we do this like.
@@ -425,8 +441,9 @@  discard block
 block discarded – undo
425 441
 		// Now some clean up. This is provided here for any like handlers that want to do any cache flushing.
426 442
 		// This way a like handler doesn't need to explicitly declare anything in integrate_issue_like, but do so
427 443
 		// in integrate_valid_likes where it absolutely has to exist.
428
-		if (!empty($this->_validLikes['flush_cache']))
429
-			cache_put_data($this->_validLikes['flush_cache'], null);
444
+		if (!empty($this->_validLikes['flush_cache'])) {
445
+					cache_put_data($this->_validLikes['flush_cache'], null);
446
+		}
430 447
 
431 448
 		// All done, start building the data to pass as response.
432 449
 		$this->_data = array(
@@ -450,8 +467,9 @@  discard block
 block discarded – undo
450 467
 	{
451 468
 		global $smcFunc;
452 469
 
453
-		if ($this->_type !== 'msg')
454
-			return;
470
+		if ($this->_type !== 'msg') {
471
+					return;
472
+		}
455 473
 
456 474
 		$smcFunc['db_query']('', '
457 475
 			UPDATE {db_prefix}messages
@@ -492,8 +510,9 @@  discard block
 block discarded – undo
492 510
 				'like_type' => $this->_type,
493 511
 			)
494 512
 		);
495
-		while ($row = $smcFunc['db_fetch_assoc']($request))
496
-			$context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']);
513
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
514
+					$context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']);
515
+		}
497 516
 
498 517
 		// Now to get member data, including avatars and so on.
499 518
 		$members = array_keys($context['likers']);
@@ -501,8 +520,9 @@  discard block
 block discarded – undo
501 520
 		if (count($loaded) != count($members))
502 521
 		{
503 522
 			$members = array_diff($members, $loaded);
504
-			foreach ($members as $not_loaded)
505
-				unset ($context['likers'][$not_loaded]);
523
+			foreach ($members as $not_loaded) {
524
+							unset ($context['likers'][$not_loaded]);
525
+			}
506 526
 		}
507 527
 
508 528
 		foreach ($context['likers'] as $liker => $dummy)
@@ -544,12 +564,14 @@  discard block
 block discarded – undo
544 564
 		global $context, $txt;
545 565
 
546 566
 		// Don't do anything if someone else has already take care of the response.
547
-		if (!$this->_setResponse)
548
-			return;
567
+		if (!$this->_setResponse) {
568
+					return;
569
+		}
549 570
 
550 571
 		// Want a json response huh?
551
-		if ($this->_validLikes['json'])
552
-			return $this->jsonResponse();
572
+		if ($this->_validLikes['json']) {
573
+					return $this->jsonResponse();
574
+		}
553 575
 
554 576
 		// Set everything up for display.
555 577
 		loadTemplate('Likes');
@@ -559,8 +581,9 @@  discard block
 block discarded – undo
559 581
 		if ($this->_error)
560 582
 		{
561 583
 			// If this is a generic error, set it up good.
562
-			if ($this->_error == 'cannot_')
563
-				$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
584
+			if ($this->_error == 'cannot_') {
585
+							$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
586
+			}
564 587
 
565 588
 			// Is this request coming from an ajax call?
566 589
 			if ($this->_js)
@@ -570,8 +593,9 @@  discard block
 block discarded – undo
570 593
 			}
571 594
 
572 595
 			// Nope?  then just do a redirect to whatever URL was provided.
573
-			else
574
-				redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : '');
596
+			else {
597
+							redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : '');
598
+			}
575 599
 
576 600
 			return;
577 601
 		}
@@ -580,8 +604,9 @@  discard block
 block discarded – undo
580 604
 		else
581 605
 		{
582 606
 			// Not an ajax request so send the user back to the previous location or the main page.
583
-			if (!$this->_js)
584
-				redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : '');
607
+			if (!$this->_js) {
608
+							redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : '');
609
+			}
585 610
 
586 611
 			// These fine gentlemen all share the same template.
587 612
 			$generic = array('delete', 'insert', '_count');
@@ -612,8 +637,9 @@  discard block
 block discarded – undo
612 637
 		// If there is an error, send it.
613 638
 		if ($this->_error)
614 639
 		{
615
-			if ($this->_error == 'cannot_')
616
-				$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
640
+			if ($this->_error == 'cannot_') {
641
+							$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
642
+			}
617 643
 
618 644
 			$print['error'] = $this->_error;
619 645
 		}
@@ -649,33 +675,36 @@  discard block
 block discarded – undo
649 675
 	<body style="background-color: #444455; color: white; font-style: italic; font-family: serif;">
650 676
 		<div style="margin-top: 12%; font-size: 1.1em; line-height: 1.4; text-align: center;">';
651 677
 
652
-	if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2'))
653
-		$_GET['verse'] = '4:16';
678
+	if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2')) {
679
+			$_GET['verse'] = '4:16';
680
+	}
654 681
 
655
-	if ($_GET['verse'] == '2:18')
656
-		echo '
682
+	if ($_GET['verse'] == '2:18') {
683
+			echo '
657 684
 			Woe, it was that his name wasn\'t <em>known</em>, that he came in mystery, and was recognized by none.&nbsp;And it became to be in those days <em>something</em>.&nbsp; Something not yet <em id="unknown" name="[Unknown]">unknown</em> to mankind.&nbsp; And thus what was to be known the <em>secret project</em> began into its existence.&nbsp; Henceforth the opposition was only <em>weary</em> and <em>fearful</em>, for now their match was at arms against them.';
658
-	elseif ($_GET['verse'] == '4:16')
659
-		echo '
685
+	} elseif ($_GET['verse'] == '4:16') {
686
+			echo '
660 687
 			And it came to pass that the <em>unbelievers</em> dwindled in number and saw rise of many <em>proselytizers</em>, and the opposition found fear in the face of the <em>x</em> and the <em>j</em> while those who stood with the <em>something</em> grew stronger and came together.&nbsp; Still, this was only the <em>beginning</em>, and what lay in the future was <em id="unknown" name="[Unknown]">unknown</em> to all, even those on the right side.';
661
-	elseif ($_GET['verse'] == '22:1-2')
662
-		echo '
688
+	} elseif ($_GET['verse'] == '22:1-2') {
689
+			echo '
663 690
 			<p>Now <em>behold</em>, that which was once the secret project was <em id="unknown" name="[Unknown]">unknown</em> no longer.&nbsp; Alas, it needed more than <em>only one</em>, but yet even thought otherwise.&nbsp; It became that the opposition <em>rumored</em> and lied, but still to no avail.&nbsp; Their match, though not <em>perfect</em>, had them outdone.</p>
664 691
 			<p style="margin: 2ex 1ex 0 1ex; font-size: 1.05em; line-height: 1.5; text-align: center;">Let it continue.&nbsp; <em>The end</em>.</p>';
692
+	}
665 693
 
666 694
 	echo '
667 695
 		</div>
668 696
 		<div style="margin-top: 2ex; font-size: 2em; text-align: right;">';
669 697
 
670
-	if ($_GET['verse'] == '2:18')
671
-		echo '
698
+	if ($_GET['verse'] == '2:18') {
699
+			echo '
672 700
 			from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=4:16" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 2:18</span>';
673
-	elseif ($_GET['verse'] == '4:16')
674
-		echo '
701
+	} elseif ($_GET['verse'] == '4:16') {
702
+			echo '
675 703
 			from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=22:1-2" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 4:16</span>';
676
-	elseif ($_GET['verse'] == '22:1-2')
677
-		echo '
704
+	} elseif ($_GET['verse'] == '22:1-2') {
705
+			echo '
678 706
 			from <span style="font-family: Georgia, serif;"><strong>The Book of Unknown</strong>, 22:1-2</span>';
707
+	}
679 708
 
680 709
 	echo '
681 710
 		</div>
Please login to merge, or discard this patch.