Completed
Pull Request — release-2.1 (#3836)
by Michael
10:56
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/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/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.
Sources/Themes.php 1 patch
Braces   +345 added lines, -269 removed lines patch added patch discarded remove patch
@@ -30,8 +30,9 @@  discard block
 block discarded – undo
30 30
  * @version 2.1 Beta 3
31 31
  */
32 32
 
33
-if (!defined('SMF'))
33
+if (!defined('SMF')) {
34 34
 	die('No direct access...');
35
+}
35 36
 
36 37
 /**
37 38
  * Subaction handler - manages the action and delegates control to the proper
@@ -103,12 +104,12 @@  discard block
 block discarded – undo
103 104
 	cache_put_data('minimized_css', null);
104 105
 
105 106
 	// Follow the sa or just go to administration.
106
-	if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']]))
107
-		call_helper($subActions[$_GET['sa']]);
108
-
109
-	else
110
-		call_helper($subActions['admin']);
111
-}
107
+	if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']])) {
108
+			call_helper($subActions[$_GET['sa']]);
109
+	} else {
110
+			call_helper($subActions['admin']);
111
+	}
112
+	}
112 113
 
113 114
 /**
114 115
  * This function allows administration of themes and their settings,
@@ -130,15 +131,16 @@  discard block
 block discarded – undo
130 131
 		checkSession();
131 132
 		validateToken('admin-tm');
132 133
 
133
-		if (isset($_POST['options']['known_themes']))
134
-			foreach ($_POST['options']['known_themes'] as $key => $id)
134
+		if (isset($_POST['options']['known_themes'])) {
135
+					foreach ($_POST['options']['known_themes'] as $key => $id)
135 136
 				$_POST['options']['known_themes'][$key] = (int) $id;
137
+		} else {
138
+					fatal_lang_error('themes_none_selectable', false);
139
+		}
136 140
 
137
-		else
138
-			fatal_lang_error('themes_none_selectable', false);
139
-
140
-		if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes']))
141
-			fatal_lang_error('themes_default_selectable', false);
141
+		if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes'])) {
142
+					fatal_lang_error('themes_default_selectable', false);
143
+		}
142 144
 
143 145
 		// Commit the new settings.
144 146
 		updateSettings(array(
@@ -146,8 +148,9 @@  discard block
 block discarded – undo
146 148
 			'theme_guests' => $_POST['options']['theme_guests'],
147 149
 			'knownThemes' => implode(',', $_POST['options']['known_themes']),
148 150
 		));
149
-		if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes']))
150
-			updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset']));
151
+		if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes'])) {
152
+					updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset']));
153
+		}
151 154
 
152 155
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=admin');
153 156
 	}
@@ -166,8 +169,9 @@  discard block
 block discarded – undo
166 169
 	// Look for a non existent theme directory. (ie theme87.)
167 170
 	$theme_dir = $boarddir . '/Themes/theme';
168 171
 	$i = 1;
169
-	while (file_exists($theme_dir . $i))
170
-		$i++;
172
+	while (file_exists($theme_dir . $i)) {
173
+			$i++;
174
+	}
171 175
 
172 176
 	$context['new_theme_name'] = 'theme' . $i;
173 177
 
@@ -189,8 +193,9 @@  discard block
 block discarded – undo
189 193
 	loadLanguage('Admin');
190 194
 	isAllowedTo('admin_forum');
191 195
 
192
-	if (isset($_REQUEST['th']))
193
-		return SetThemeSettings();
196
+	if (isset($_REQUEST['th'])) {
197
+			return SetThemeSettings();
198
+	}
194 199
 
195 200
 	if (isset($_POST['save']))
196 201
 	{
@@ -274,12 +279,13 @@  discard block
 block discarded – undo
274 279
 		$context['themes'] = array();
275 280
 		while ($row = $smcFunc['db_fetch_assoc']($request))
276 281
 		{
277
-			if (!isset($context['themes'][$row['id_theme']]))
278
-				$context['themes'][$row['id_theme']] = array(
282
+			if (!isset($context['themes'][$row['id_theme']])) {
283
+							$context['themes'][$row['id_theme']] = array(
279 284
 					'id' => $row['id_theme'],
280 285
 					'num_default_options' => 0,
281 286
 					'num_members' => 0,
282 287
 				);
288
+			}
283 289
 			$context['themes'][$row['id_theme']][$row['variable']] = $row['value'];
284 290
 		}
285 291
 		$smcFunc['db_free_result']($request);
@@ -293,8 +299,9 @@  discard block
 block discarded – undo
293 299
 				'guest_member' => -1,
294 300
 			)
295 301
 		);
296
-		while ($row = $smcFunc['db_fetch_assoc']($request))
297
-			$context['themes'][$row['id_theme']]['num_default_options'] = $row['value'];
302
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
303
+					$context['themes'][$row['id_theme']]['num_default_options'] = $row['value'];
304
+		}
298 305
 		$smcFunc['db_free_result']($request);
299 306
 
300 307
 		// Need to make sure we don't do custom fields.
@@ -305,8 +312,9 @@  discard block
 block discarded – undo
305 312
 			)
306 313
 		);
307 314
 		$customFields = array();
308
-		while ($row = $smcFunc['db_fetch_assoc']($request))
309
-			$customFields[] = $row['col_name'];
315
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
316
+					$customFields[] = $row['col_name'];
317
+		}
310 318
 		$smcFunc['db_free_result']($request);
311 319
 		$customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})');
312 320
 
@@ -321,14 +329,16 @@  discard block
 block discarded – undo
321 329
 				'custom_fields' => empty($customFields) ? array() : $customFields,
322 330
 			)
323 331
 		);
324
-		while ($row = $smcFunc['db_fetch_assoc']($request))
325
-			$context['themes'][$row['id_theme']]['num_members'] = $row['value'];
332
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
333
+					$context['themes'][$row['id_theme']]['num_members'] = $row['value'];
334
+		}
326 335
 		$smcFunc['db_free_result']($request);
327 336
 
328 337
 		// There has to be a Settings template!
329
-		foreach ($context['themes'] as $k => $v)
330
-			if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members'])))
338
+		foreach ($context['themes'] as $k => $v) {
339
+					if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members'])))
331 340
 				unset($context['themes'][$k]);
341
+		}
332 342
 
333 343
 		loadTemplate('Themes');
334 344
 		$context['sub_template'] = 'reset_list';
@@ -343,16 +353,19 @@  discard block
 block discarded – undo
343 353
 		checkSession();
344 354
 		validateToken('admin-sto');
345 355
 
346
-		if (empty($_POST['options']))
347
-			$_POST['options'] = array();
348
-		if (empty($_POST['default_options']))
349
-			$_POST['default_options'] = array();
356
+		if (empty($_POST['options'])) {
357
+					$_POST['options'] = array();
358
+		}
359
+		if (empty($_POST['default_options'])) {
360
+					$_POST['default_options'] = array();
361
+		}
350 362
 
351 363
 		// Set up the sql query.
352 364
 		$setValues = array();
353 365
 
354
-		foreach ($_POST['options'] as $opt => $val)
355
-			$setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
366
+		foreach ($_POST['options'] as $opt => $val) {
367
+					$setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
368
+		}
356 369
 
357 370
 		$old_settings = array();
358 371
 		foreach ($_POST['default_options'] as $opt => $val)
@@ -366,8 +379,8 @@  discard block
 block discarded – undo
366 379
 		if (!empty($setValues))
367 380
 		{
368 381
 			// Are there options in non-default themes set that should be cleared?
369
-			if (!empty($old_settings))
370
-				$smcFunc['db_query']('', '
382
+			if (!empty($old_settings)) {
383
+							$smcFunc['db_query']('', '
371 384
 					DELETE FROM {db_prefix}themes
372 385
 					WHERE id_theme != {int:default_theme}
373 386
 						AND id_member = {int:guest_member}
@@ -378,6 +391,7 @@  discard block
 block discarded – undo
378 391
 						'old_settings' => $old_settings,
379 392
 					)
380 393
 				);
394
+			}
381 395
 
382 396
 			$smcFunc['db_insert']('replace',
383 397
 				'{db_prefix}themes',
@@ -391,8 +405,7 @@  discard block
 block discarded – undo
391 405
 		cache_put_data('theme_settings-1', null, 90);
392 406
 
393 407
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
394
-	}
395
-	elseif (isset($_POST['submit']) && $_POST['who'] == 1)
408
+	} elseif (isset($_POST['submit']) && $_POST['who'] == 1)
396 409
 	{
397 410
 		checkSession();
398 411
 		validateToken('admin-sto');
@@ -405,9 +418,9 @@  discard block
 block discarded – undo
405 418
 		$old_settings = array();
406 419
 		foreach ($_POST['default_options'] as $opt => $val)
407 420
 		{
408
-			if ($_POST['default_options_master'][$opt] == 0)
409
-				continue;
410
-			elseif ($_POST['default_options_master'][$opt] == 1)
421
+			if ($_POST['default_options_master'][$opt] == 0) {
422
+							continue;
423
+			} elseif ($_POST['default_options_master'][$opt] == 1)
411 424
 			{
412 425
 				// Delete then insert for ease of database compatibility!
413 426
 				$smcFunc['db_query']('substring', '
@@ -433,8 +446,7 @@  discard block
 block discarded – undo
433 446
 				);
434 447
 
435 448
 				$old_settings[] = $opt;
436
-			}
437
-			elseif ($_POST['default_options_master'][$opt] == 2)
449
+			} elseif ($_POST['default_options_master'][$opt] == 2)
438 450
 			{
439 451
 				$smcFunc['db_query']('', '
440 452
 					DELETE FROM {db_prefix}themes
@@ -449,8 +461,8 @@  discard block
 block discarded – undo
449 461
 		}
450 462
 
451 463
 		// Delete options from other themes.
452
-		if (!empty($old_settings))
453
-			$smcFunc['db_query']('', '
464
+		if (!empty($old_settings)) {
465
+					$smcFunc['db_query']('', '
454 466
 				DELETE FROM {db_prefix}themes
455 467
 				WHERE id_theme != {int:default_theme}
456 468
 					AND id_member > {int:no_member}
@@ -461,12 +473,13 @@  discard block
 block discarded – undo
461 473
 					'old_settings' => $old_settings,
462 474
 				)
463 475
 			);
476
+		}
464 477
 
465 478
 		foreach ($_POST['options'] as $opt => $val)
466 479
 		{
467
-			if ($_POST['options_master'][$opt] == 0)
468
-				continue;
469
-			elseif ($_POST['options_master'][$opt] == 1)
480
+			if ($_POST['options_master'][$opt] == 0) {
481
+							continue;
482
+			} elseif ($_POST['options_master'][$opt] == 1)
470 483
 			{
471 484
 				// Delete then insert for ease of database compatibility - again!
472 485
 				$smcFunc['db_query']('substring', '
@@ -491,8 +504,7 @@  discard block
 block discarded – undo
491 504
 						'value' => (is_array($val) ? implode(',', $val) : $val),
492 505
 					)
493 506
 				);
494
-			}
495
-			elseif ($_POST['options_master'][$opt] == 2)
507
+			} elseif ($_POST['options_master'][$opt] == 2)
496 508
 			{
497 509
 				$smcFunc['db_query']('', '
498 510
 					DELETE FROM {db_prefix}themes
@@ -509,8 +521,7 @@  discard block
 block discarded – undo
509 521
 		}
510 522
 
511 523
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
512
-	}
513
-	elseif (!empty($_GET['who']) && $_GET['who'] == 2)
524
+	} elseif (!empty($_GET['who']) && $_GET['who'] == 2)
514 525
 	{
515 526
 		checkSession('get');
516 527
 		validateToken('admin-stor', 'request');
@@ -525,8 +536,9 @@  discard block
 block discarded – undo
525 536
 				)
526 537
 			);
527 538
 			$customFields = array();
528
-			while ($row = $smcFunc['db_fetch_assoc']($request))
529
-				$customFields[] = $row['col_name'];
539
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
540
+							$customFields[] = $row['col_name'];
541
+			}
530 542
 			$smcFunc['db_free_result']($request);
531 543
 		}
532 544
 		$customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})');
@@ -578,13 +590,13 @@  discard block
 block discarded – undo
578 590
 			)
579 591
 		);
580 592
 		$context['theme_options'] = array();
581
-		while ($row = $smcFunc['db_fetch_assoc']($request))
582
-			$context['theme_options'][$row['variable']] = $row['value'];
593
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
594
+					$context['theme_options'][$row['variable']] = $row['value'];
595
+		}
583 596
 		$smcFunc['db_free_result']($request);
584 597
 
585 598
 		$context['theme_options_reset'] = false;
586
-	}
587
-	else
599
+	} else
588 600
 	{
589 601
 		$context['theme_options'] = array();
590 602
 		$context['theme_options_reset'] = true;
@@ -597,22 +609,23 @@  discard block
 block discarded – undo
597 609
 		{
598 610
 			unset($context['options'][$i]);
599 611
 			continue;
600
-		}
601
-		elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
612
+		} elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
602 613
 		{
603 614
 			unset($context['options'][$i]);
604 615
 			continue;
605 616
 		}
606 617
 
607
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
608
-			$context['options'][$i]['type'] = 'checkbox';
609
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
610
-			$context['options'][$i]['type'] = 'number';
611
-		elseif ($setting['type'] == 'string')
612
-			$context['options'][$i]['type'] = 'text';
618
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
619
+					$context['options'][$i]['type'] = 'checkbox';
620
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
621
+					$context['options'][$i]['type'] = 'number';
622
+		} elseif ($setting['type'] == 'string') {
623
+					$context['options'][$i]['type'] = 'text';
624
+		}
613 625
 
614
-		if (isset($setting['options']))
615
-			$context['options'][$i]['type'] = 'list';
626
+		if (isset($setting['options'])) {
627
+					$context['options'][$i]['type'] = 'list';
628
+		}
616 629
 
617 630
 		$context['options'][$i]['value'] = !isset($context['theme_options'][$setting['id']]) ? '' : $context['theme_options'][$setting['id']];
618 631
 	}
@@ -637,8 +650,9 @@  discard block
 block discarded – undo
637 650
 {
638 651
 	global $txt, $context, $settings, $modSettings, $smcFunc;
639 652
 
640
-	if (empty($_GET['th']) && empty($_GET['id']))
641
-		return ThemeAdmin();
653
+	if (empty($_GET['th']) && empty($_GET['id'])) {
654
+			return ThemeAdmin();
655
+	}
642 656
 
643 657
 	$_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
644 658
 
@@ -649,8 +663,9 @@  discard block
 block discarded – undo
649 663
 	isAllowedTo('admin_forum');
650 664
 
651 665
 	// Validate inputs/user.
652
-	if (empty($_GET['th']))
653
-		fatal_lang_error('no_theme', false);
666
+	if (empty($_GET['th'])) {
667
+			fatal_lang_error('no_theme', false);
668
+	}
654 669
 
655 670
 	// Fetch the smiley sets...
656 671
 	$sets = explode(',', 'none,' . $modSettings['smiley_sets_known']);
@@ -658,8 +673,9 @@  discard block
 block discarded – undo
658 673
 	$context['smiley_sets'] = array(
659 674
 		'' => $txt['smileys_no_default']
660 675
 	);
661
-	foreach ($sets as $i => $set)
662
-		$context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]);
676
+	foreach ($sets as $i => $set) {
677
+			$context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]);
678
+	}
663 679
 
664 680
 	$old_id = $settings['theme_id'];
665 681
 	$old_settings = $settings;
@@ -684,8 +700,9 @@  discard block
 block discarded – undo
684 700
 	if (file_exists($settings['theme_dir'] . '/index.template.php'))
685 701
 	{
686 702
 		$file_contents = implode('', file($settings['theme_dir'] . '/index.template.php'));
687
-		if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches))
688
-				eval('global $settings;' . $matches[0]);
703
+		if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches)) {
704
+						eval('global $settings;' . $matches[0]);
705
+		}
689 706
 	}
690 707
 
691 708
 	// Submitting!
@@ -694,37 +711,45 @@  discard block
 block discarded – undo
694 711
 		checkSession();
695 712
 		validateToken('admin-sts');
696 713
 
697
-		if (empty($_POST['options']))
698
-			$_POST['options'] = array();
699
-		if (empty($_POST['default_options']))
700
-			$_POST['default_options'] = array();
714
+		if (empty($_POST['options'])) {
715
+					$_POST['options'] = array();
716
+		}
717
+		if (empty($_POST['default_options'])) {
718
+					$_POST['default_options'] = array();
719
+		}
701 720
 
702 721
 		// Make sure items are cast correctly.
703 722
 		foreach ($context['theme_settings'] as $item)
704 723
 		{
705 724
 			// Disregard this item if this is just a separator.
706
-			if (!is_array($item))
707
-				continue;
725
+			if (!is_array($item)) {
726
+							continue;
727
+			}
708 728
 
709 729
 			foreach (array('options', 'default_options') as $option)
710 730
 			{
711
-				if (!isset($_POST[$option][$item['id']]))
712
-					continue;
731
+				if (!isset($_POST[$option][$item['id']])) {
732
+									continue;
733
+				}
713 734
 				// Checkbox.
714
-				elseif (empty($item['type']))
715
-					$_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
735
+				elseif (empty($item['type'])) {
736
+									$_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
737
+				}
716 738
 				// Number
717
-				elseif ($item['type'] == 'number')
718
-					$_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
739
+				elseif ($item['type'] == 'number') {
740
+									$_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
741
+				}
719 742
 			}
720 743
 		}
721 744
 
722 745
 		// Set up the sql query.
723 746
 		$inserts = array();
724
-		foreach ($_POST['options'] as $opt => $val)
725
-			$inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
726
-		foreach ($_POST['default_options'] as $opt => $val)
727
-			$inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val);
747
+		foreach ($_POST['options'] as $opt => $val) {
748
+					$inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
749
+		}
750
+		foreach ($_POST['default_options'] as $opt => $val) {
751
+					$inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val);
752
+		}
728 753
 		// If we're actually inserting something..
729 754
 		if (!empty($inserts))
730 755
 		{
@@ -750,8 +775,9 @@  discard block
 block discarded – undo
750 775
 
751 776
 	foreach ($settings as $setting => $dummy)
752 777
 	{
753
-		if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs')))
754
-			$settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
778
+		if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) {
779
+					$settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
780
+		}
755 781
 	}
756 782
 
757 783
 	$context['settings'] = $context['theme_settings'];
@@ -760,18 +786,21 @@  discard block
 block discarded – undo
760 786
 	foreach ($context['settings'] as $i => $setting)
761 787
 	{
762 788
 		// Separators are dummies, so leave them alone.
763
-		if (!is_array($setting))
764
-			continue;
789
+		if (!is_array($setting)) {
790
+					continue;
791
+		}
765 792
 
766
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
767
-			$context['settings'][$i]['type'] = 'checkbox';
768
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
769
-			$context['settings'][$i]['type'] = 'number';
770
-		elseif ($setting['type'] == 'string')
771
-			$context['settings'][$i]['type'] = 'text';
793
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
794
+					$context['settings'][$i]['type'] = 'checkbox';
795
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
796
+					$context['settings'][$i]['type'] = 'number';
797
+		} elseif ($setting['type'] == 'string') {
798
+					$context['settings'][$i]['type'] = 'text';
799
+		}
772 800
 
773
-		if (isset($setting['options']))
774
-			$context['settings'][$i]['type'] = 'list';
801
+		if (isset($setting['options'])) {
802
+					$context['settings'][$i]['type'] = 'list';
803
+		}
775 804
 
776 805
 		$context['settings'][$i]['value'] = !isset($settings[$setting['id']]) ? '' : $settings[$setting['id']];
777 806
 	}
@@ -824,8 +853,9 @@  discard block
 block discarded – undo
824 853
 	$themeID = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
825 854
 
826 855
 	// You can't delete the default theme!
827
-	if ($themeID == 1)
828
-		fatal_lang_error('no_access', false);
856
+	if ($themeID == 1) {
857
+			fatal_lang_error('no_access', false);
858
+	}
829 859
 
830 860
 	$theme_info = get_single_theme($themeID);
831 861
 
@@ -833,8 +863,9 @@  discard block
 block discarded – undo
833 863
 	remove_theme($themeID);
834 864
 
835 865
 	// And remove all its files and folders too.
836
-	if (!empty($theme_info) && !empty($theme_info['theme_dir']))
837
-		remove_dir($theme_info['theme_dir']);
866
+	if (!empty($theme_info) && !empty($theme_info['theme_dir'])) {
867
+			remove_dir($theme_info['theme_dir']);
868
+	}
838 869
 
839 870
 	// Go back to the list page.
840 871
 	redirectexit('action=admin;area=theme;sa=list;' . $context['session_var'] . '=' . $context['session_id'] . ';done=removing');
@@ -859,12 +890,14 @@  discard block
 block discarded – undo
859 890
 	$enableThemes = explode(',', $modSettings['enableThemes']);
860 891
 
861 892
 	// Are we disabling it?
862
-	if (isset($_GET['disabled']))
863
-		$enableThemes = array_diff($enableThemes, array($themeID));
893
+	if (isset($_GET['disabled'])) {
894
+			$enableThemes = array_diff($enableThemes, array($themeID));
895
+	}
864 896
 
865 897
 	// Nope? then enable it!
866
-	else
867
-		$enableThemes[] = (string) $themeID;
898
+	else {
899
+			$enableThemes[] = (string) $themeID;
900
+	}
868 901
 
869 902
 	// Update the setting.
870 903
 	$enableThemes = strtr(implode(',', $enableThemes), array(',,' => ','));
@@ -899,18 +932,21 @@  discard block
 block discarded – undo
899 932
 
900 933
 	$_SESSION['id_theme'] = 0;
901 934
 
902
-	if (isset($_GET['id']))
903
-		$_GET['th'] = $_GET['id'];
935
+	if (isset($_GET['id'])) {
936
+			$_GET['th'] = $_GET['id'];
937
+	}
904 938
 
905 939
 	// Saving a variant cause JS doesn't work - pretend it did ;)
906 940
 	if (isset($_POST['save']))
907 941
 	{
908 942
 		// Which theme?
909
-		foreach ($_POST['save'] as $k => $v)
910
-			$_GET['th'] = (int) $k;
943
+		foreach ($_POST['save'] as $k => $v) {
944
+					$_GET['th'] = (int) $k;
945
+		}
911 946
 
912
-		if (isset($_POST['vrt'][$k]))
913
-			$_GET['vrt'] = $_POST['vrt'][$k];
947
+		if (isset($_POST['vrt'][$k])) {
948
+					$_GET['vrt'] = $_POST['vrt'][$k];
949
+		}
914 950
 	}
915 951
 
916 952
 	// Have we made a decision, or are we just browsing?
@@ -988,8 +1024,9 @@  discard block
 block discarded – undo
988 1024
 		else
989 1025
 		{
990 1026
 			// The forum's default theme is always 0 and we
991
-			if (isset($_GET['th']) && $_GET['th'] == 0)
992
-					$_GET['th'] = $modSettings['theme_guests'];
1027
+			if (isset($_GET['th']) && $_GET['th'] == 0) {
1028
+								$_GET['th'] = $modSettings['theme_guests'];
1029
+			}
993 1030
 
994 1031
 			updateMemberData((int) $_REQUEST['u'], array('id_theme' => (int) $_GET['th']));
995 1032
 
@@ -1003,8 +1040,9 @@  discard block
 block discarded – undo
1003 1040
 				);
1004 1041
 				cache_put_data('theme_settings-' . $_GET['th'] . ':' . (int) $_REQUEST['u'], null, 90);
1005 1042
 
1006
-				if ($user_info['id'] == $_REQUEST['u'])
1007
-					$_SESSION['id_variant'] = 0;
1043
+				if ($user_info['id'] == $_REQUEST['u']) {
1044
+									$_SESSION['id_variant'] = 0;
1045
+				}
1008 1046
 			}
1009 1047
 
1010 1048
 			redirectexit('action=profile;u=' . (int) $_REQUEST['u'] . ';area=theme');
@@ -1073,12 +1111,13 @@  discard block
 block discarded – undo
1073 1111
 		);
1074 1112
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1075 1113
 		{
1076
-			if (!isset($context['available_themes'][$row['id_theme']]))
1077
-				$context['available_themes'][$row['id_theme']] = array(
1114
+			if (!isset($context['available_themes'][$row['id_theme']])) {
1115
+							$context['available_themes'][$row['id_theme']] = array(
1078 1116
 					'id' => $row['id_theme'],
1079 1117
 					'selected' => $context['current_theme'] == $row['id_theme'],
1080 1118
 					'num_users' => 0
1081 1119
 				);
1120
+			}
1082 1121
 			$context['available_themes'][$row['id_theme']][$row['variable']] = $row['value'];
1083 1122
 		}
1084 1123
 		$smcFunc['db_free_result']($request);
@@ -1091,9 +1130,9 @@  discard block
 block discarded – undo
1091 1130
 			'num_users' => 0
1092 1131
 		);
1093 1132
 		$guest_theme = 0;
1133
+	} else {
1134
+			$guest_theme = $modSettings['theme_guests'];
1094 1135
 	}
1095
-	else
1096
-		$guest_theme = $modSettings['theme_guests'];
1097 1136
 
1098 1137
 	$request = $smcFunc['db_query']('', '
1099 1138
 		SELECT id_theme, COUNT(*) AS the_count
@@ -1106,15 +1145,17 @@  discard block
 block discarded – undo
1106 1145
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1107 1146
 	{
1108 1147
 		// Figure out which theme it is they are REALLY using.
1109
-		if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes'])))
1110
-			$row['id_theme'] = $guest_theme;
1111
-		elseif (empty($modSettings['theme_allow']))
1112
-			$row['id_theme'] = $guest_theme;
1148
+		if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes']))) {
1149
+					$row['id_theme'] = $guest_theme;
1150
+		} elseif (empty($modSettings['theme_allow'])) {
1151
+					$row['id_theme'] = $guest_theme;
1152
+		}
1113 1153
 
1114
-		if (isset($context['available_themes'][$row['id_theme']]))
1115
-			$context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count'];
1116
-		else
1117
-			$context['available_themes'][$guest_theme]['num_users'] += $row['the_count'];
1154
+		if (isset($context['available_themes'][$row['id_theme']])) {
1155
+					$context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count'];
1156
+		} else {
1157
+					$context['available_themes'][$guest_theme]['num_users'] += $row['the_count'];
1158
+		}
1118 1159
 	}
1119 1160
 	$smcFunc['db_free_result']($request);
1120 1161
 
@@ -1133,8 +1174,9 @@  discard block
 block discarded – undo
1133 1174
 				'id_member' => isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? array(-1, $context['current_member']) : array(-1),
1134 1175
 			)
1135 1176
 		);
1136
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1137
-			$variant_preferences[$row['id_theme']] = $row['value'];
1177
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1178
+					$variant_preferences[$row['id_theme']] = $row['value'];
1179
+		}
1138 1180
 		$smcFunc['db_free_result']($request);
1139 1181
 	}
1140 1182
 
@@ -1145,17 +1187,18 @@  discard block
 block discarded – undo
1145 1187
 	foreach ($context['available_themes'] as $id_theme => $theme_data)
1146 1188
 	{
1147 1189
 		// Don't try to load the forum or board default theme's data... it doesn't have any!
1148
-		if ($id_theme == 0)
1149
-			continue;
1190
+		if ($id_theme == 0) {
1191
+					continue;
1192
+		}
1150 1193
 
1151 1194
 		// The thumbnail needs the correct path.
1152 1195
 		$settings['images_url'] = &$theme_data['images_url'];
1153 1196
 
1154
-		if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'))
1155
-			include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
1156
-		elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php'))
1157
-			include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php');
1158
-		else
1197
+		if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php')) {
1198
+					include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
1199
+		} elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php')) {
1200
+					include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php');
1201
+		} else
1159 1202
 		{
1160 1203
 			$txt['theme_thumbnail_href'] = $theme_data['images_url'] . '/thumbnail.png';
1161 1204
 			$txt['theme_description'] = '';
@@ -1180,15 +1223,17 @@  discard block
 block discarded – undo
1180 1223
 					loadLanguage('Settings');
1181 1224
 
1182 1225
 					$context['available_themes'][$id_theme]['variants'] = array();
1183
-					foreach ($settings['theme_variants'] as $variant)
1184
-						$context['available_themes'][$id_theme]['variants'][$variant] = array(
1226
+					foreach ($settings['theme_variants'] as $variant) {
1227
+											$context['available_themes'][$id_theme]['variants'][$variant] = array(
1185 1228
 							'label' => isset($txt['variant_' . $variant]) ? $txt['variant_' . $variant] : $variant,
1186 1229
 							'thumbnail' => !file_exists($theme_data['theme_dir'] . '/images/thumbnail.png') || file_exists($theme_data['theme_dir'] . '/images/thumbnail_' . $variant . '.png') ? $theme_data['images_url'] . '/thumbnail_' . $variant . '.png' : ($theme_data['images_url'] . '/thumbnail.png'),
1187 1230
 						);
1231
+					}
1188 1232
 
1189 1233
 					$context['available_themes'][$id_theme]['selected_variant'] = isset($_GET['vrt']) ? $_GET['vrt'] : (!empty($variant_preferences[$id_theme]) ? $variant_preferences[$id_theme] : (!empty($settings['default_variant']) ? $settings['default_variant'] : $settings['theme_variants'][0]));
1190
-					if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail']))
1191
-						$context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0];
1234
+					if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'])) {
1235
+											$context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0];
1236
+					}
1192 1237
 
1193 1238
 					$context['available_themes'][$id_theme]['thumbnail_href'] = $context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'];
1194 1239
 					// Allow themes to override the text.
@@ -1204,8 +1249,9 @@  discard block
 block discarded – undo
1204 1249
 	// As long as we're not doing the default theme...
1205 1250
 	if (!isset($_REQUEST['u']) || $_REQUEST['u'] >= 0)
1206 1251
 	{
1207
-		if ($guest_theme != 0)
1208
-			$context['available_themes'][0] = $context['available_themes'][$guest_theme];
1252
+		if ($guest_theme != 0) {
1253
+					$context['available_themes'][0] = $context['available_themes'][$guest_theme];
1254
+		}
1209 1255
 
1210 1256
 		$context['available_themes'][0]['id'] = 0;
1211 1257
 		$context['available_themes'][0]['name'] = $txt['theme_forum_default'];
@@ -1254,14 +1300,16 @@  discard block
 block discarded – undo
1254 1300
 		$action = $smcFunc['htmlspecialchars'](trim($_GET['do']));
1255 1301
 
1256 1302
 		// Got any info from the specific form?
1257
-		if (!isset($_POST['save_' . $action]))
1258
-			fatal_lang_error('theme_install_no_action', false);
1303
+		if (!isset($_POST['save_' . $action])) {
1304
+					fatal_lang_error('theme_install_no_action', false);
1305
+		}
1259 1306
 
1260 1307
 		validateToken('admin-t-' . $action);
1261 1308
 
1262 1309
 		// Hopefully the themes directory is writable, or we might have a problem.
1263
-		if (!is_writable($themedir))
1264
-			fatal_lang_error('theme_install_write_error', 'critical');
1310
+		if (!is_writable($themedir)) {
1311
+					fatal_lang_error('theme_install_write_error', 'critical');
1312
+		}
1265 1313
 
1266 1314
 		// Call the function and handle the result.
1267 1315
 		$result = $subActions[$action]();
@@ -1276,9 +1324,10 @@  discard block
 block discarded – undo
1276 1324
 	}
1277 1325
 
1278 1326
 	// Nope, show a nice error.
1279
-	else
1280
-		fatal_lang_error('theme_install_no_action', false);
1281
-}
1327
+	else {
1328
+			fatal_lang_error('theme_install_no_action', false);
1329
+	}
1330
+	}
1282 1331
 
1283 1332
 /**
1284 1333
  * Installs a theme from a theme package.
@@ -1294,8 +1343,9 @@  discard block
 block discarded – undo
1294 1343
 	$dirtemp = $themedir . '/temp';
1295 1344
 
1296 1345
 	// Make sure the temp dir doesn't already exist
1297
-	if (file_exists($dirtemp))
1298
-		remove_dir($dirtemp);
1346
+	if (file_exists($dirtemp)) {
1347
+			remove_dir($dirtemp);
1348
+	}
1299 1349
 
1300 1350
 	// Create the temp dir.
1301 1351
 	mkdir($dirtemp, 0777);
@@ -1307,17 +1357,20 @@  discard block
 block discarded – undo
1307 1357
 		smf_chmod($dirtemp, '0755');
1308 1358
 
1309 1359
 		// How about now?
1310
-		if (!is_writable($dirtemp))
1311
-			fatal_lang_error('theme_install_write_error', 'critical');
1360
+		if (!is_writable($dirtemp)) {
1361
+					fatal_lang_error('theme_install_write_error', 'critical');
1362
+		}
1312 1363
 	}
1313 1364
 
1314 1365
 	// This happens when the admin session is gone and the user has to login again.
1315
-	if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz']))
1316
-		redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
1366
+	if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz'])) {
1367
+			redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
1368
+	}
1317 1369
 
1318 1370
 	// Another error check layer, something went wrong with the upload.
1319
-	if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0)
1320
-		fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false);
1371
+	if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0) {
1372
+			fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false);
1373
+	}
1321 1374
 
1322 1375
 	// Get the theme's name.
1323 1376
 	$name = pathinfo($_FILES['theme_gz']['name'], PATHINFO_FILENAME);
@@ -1348,11 +1401,10 @@  discard block
 block discarded – undo
1348 1401
 
1349 1402
 		// return all the info.
1350 1403
 		return $context['to_install'];
1404
+	} else {
1405
+			fatal_lang_error('theme_install_error_title', false);
1406
+	}
1351 1407
 	}
1352
-
1353
-	else
1354
-		fatal_lang_error('theme_install_error_title', false);
1355
-}
1356 1408
 
1357 1409
 /**
1358 1410
  * Makes a copy from the default theme, assigns a name for it and installs it.
@@ -1366,15 +1418,17 @@  discard block
 block discarded – undo
1366 1418
 	global $forum_version;
1367 1419
 
1368 1420
 	// There's gotta be something to work with.
1369
-	if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy']))
1370
-		fatal_lang_error('theme_install_error_title', false);
1421
+	if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy'])) {
1422
+			fatal_lang_error('theme_install_error_title', false);
1423
+	}
1371 1424
 
1372 1425
 	// Get a cleaner version.
1373 1426
 	$name = preg_replace('~[^A-Za-z0-9_\- ]~', '', $_REQUEST['copy']);
1374 1427
 
1375 1428
 	// Is there a theme already named like this?
1376
-	if (file_exists($themedir . '/' . $name))
1377
-		fatal_lang_error('theme_install_already_dir', false);
1429
+	if (file_exists($themedir . '/' . $name)) {
1430
+			fatal_lang_error('theme_install_already_dir', false);
1431
+	}
1378 1432
 
1379 1433
 	// This is a brand new theme so set all possible values.
1380 1434
 	$context['to_install'] = array(
@@ -1394,8 +1448,9 @@  discard block
 block discarded – undo
1394 1448
 
1395 1449
 	// Buy some time.
1396 1450
 	@set_time_limit(600);
1397
-	if (function_exists('apache_reset_timeout'))
1398
-		@apache_reset_timeout();
1451
+	if (function_exists('apache_reset_timeout')) {
1452
+			@apache_reset_timeout();
1453
+	}
1399 1454
 
1400 1455
 	// Create subdirectories for css and javascript files.
1401 1456
 	mkdir($context['to_install']['theme_dir'] . '/css', 0777);
@@ -1431,12 +1486,13 @@  discard block
 block discarded – undo
1431 1486
 
1432 1487
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1433 1488
 	{
1434
-		if ($row['variable'] == 'theme_templates')
1435
-			$theme_templates = $row['value'];
1436
-		elseif ($row['variable'] == 'theme_layers')
1437
-			$theme_layers = $row['value'];
1438
-		else
1439
-			continue;
1489
+		if ($row['variable'] == 'theme_templates') {
1490
+					$theme_templates = $row['value'];
1491
+		} elseif ($row['variable'] == 'theme_layers') {
1492
+					$theme_layers = $row['value'];
1493
+		} else {
1494
+					continue;
1495
+		}
1440 1496
 	}
1441 1497
 
1442 1498
 	$smcFunc['db_free_result']($request);
@@ -1495,12 +1551,14 @@  discard block
 block discarded – undo
1495 1551
 	global $themedir, $themeurl, $context;
1496 1552
 
1497 1553
 	// Cannot use the theme dir as a theme dir.
1498
-	if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir))
1499
-		fatal_lang_error('theme_install_invalid_dir', false);
1554
+	if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir)) {
1555
+			fatal_lang_error('theme_install_invalid_dir', false);
1556
+	}
1500 1557
 
1501 1558
 	// Check is there is "something" on the dir.
1502
-	elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml'))
1503
-		fatal_lang_error('theme_install_error', false);
1559
+	elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml')) {
1560
+			fatal_lang_error('theme_install_error', false);
1561
+	}
1504 1562
 
1505 1563
 	$name = basename($_REQUEST['theme_dir']);
1506 1564
 	$name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $name);
@@ -1544,24 +1602,27 @@  discard block
 block discarded – undo
1544 1602
 	}
1545 1603
 
1546 1604
 	// Any special layers?
1547
-	if (isset($settings['catch_action']['layers']))
1548
-		$context['template_layers'] = $settings['catch_action']['layers'];
1605
+	if (isset($settings['catch_action']['layers'])) {
1606
+			$context['template_layers'] = $settings['catch_action']['layers'];
1607
+	}
1549 1608
 
1550 1609
 	// Any function to call?
1551 1610
 	if (isset($settings['catch_action']['function']))
1552 1611
 	{
1553 1612
 		$hook = $settings['catch_action']['function'];
1554 1613
 
1555
-		if (!isset($settings['catch_action']['filename']))
1556
-			$settings['catch_action']['filename'] = '';
1614
+		if (!isset($settings['catch_action']['filename'])) {
1615
+					$settings['catch_action']['filename'] = '';
1616
+		}
1557 1617
 
1558 1618
 		add_integration_function('integrate_wrap_action', $hook, false, $settings['catch_action']['filename'], false);
1559 1619
 		call_integration_hook('integrate_wrap_action');
1560 1620
 	}
1561 1621
 	// And finally, the main sub template ;).
1562
-	if (isset($settings['catch_action']['sub_template']))
1563
-		$context['sub_template'] = $settings['catch_action']['sub_template'];
1564
-}
1622
+	if (isset($settings['catch_action']['sub_template'])) {
1623
+			$context['sub_template'] = $settings['catch_action']['sub_template'];
1624
+	}
1625
+	}
1565 1626
 
1566 1627
 /**
1567 1628
  * Set an option via javascript.
@@ -1580,12 +1641,14 @@  discard block
 block discarded – undo
1580 1641
 	checkSession('get');
1581 1642
 
1582 1643
 	// This good-for-nothing pixel is being used to keep the session alive.
1583
-	if (empty($_GET['var']) || !isset($_GET['val']))
1584
-		redirectexit($settings['images_url'] . '/blank.png');
1644
+	if (empty($_GET['var']) || !isset($_GET['val'])) {
1645
+			redirectexit($settings['images_url'] . '/blank.png');
1646
+	}
1585 1647
 
1586 1648
 	// Sorry, guests can't go any further than this.
1587
-	if ($user_info['is_guest'] || $user_info['id'] == 0)
1588
-		obExit(false);
1649
+	if ($user_info['is_guest'] || $user_info['id'] == 0) {
1650
+			obExit(false);
1651
+	}
1589 1652
 
1590 1653
 	$reservedVars = array(
1591 1654
 		'actual_theme_url',
@@ -1608,8 +1671,9 @@  discard block
 block discarded – undo
1608 1671
 	);
1609 1672
 
1610 1673
 	// Can't change reserved vars.
1611
-	if (in_array(strtolower($_GET['var']), $reservedVars))
1612
-		redirectexit($settings['images_url'] . '/blank.png');
1674
+	if (in_array(strtolower($_GET['var']), $reservedVars)) {
1675
+			redirectexit($settings['images_url'] . '/blank.png');
1676
+	}
1613 1677
 
1614 1678
 	// Use a specific theme?
1615 1679
 	if (isset($_GET['th']) || isset($_GET['id']))
@@ -1625,8 +1689,9 @@  discard block
 block discarded – undo
1625 1689
 	{
1626 1690
 		$options['admin_preferences'] = !empty($options['admin_preferences']) ? smf_json_decode($options['admin_preferences'], true) : array();
1627 1691
 		// New thingy...
1628
-		if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5)
1629
-			$options['admin_preferences'][$_GET['admin_key']] = $_GET['val'];
1692
+		if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5) {
1693
+					$options['admin_preferences'][$_GET['admin_key']] = $_GET['val'];
1694
+		}
1630 1695
 
1631 1696
 		// Change the value to be something nice,
1632 1697
 		$_GET['val'] = json_encode($options['admin_preferences']);
@@ -1656,8 +1721,9 @@  discard block
 block discarded – undo
1656 1721
 	global $context, $scripturl, $boarddir, $smcFunc, $txt;
1657 1722
 
1658 1723
 	// @todo Should this be removed?
1659
-	if (isset($_REQUEST['preview']))
1660
-		die('die() with fire');
1724
+	if (isset($_REQUEST['preview'])) {
1725
+			die('die() with fire');
1726
+	}
1661 1727
 
1662 1728
 	isAllowedTo('admin_forum');
1663 1729
 	loadTemplate('Themes');
@@ -1671,11 +1737,11 @@  discard block
 block discarded – undo
1671 1737
 		foreach ($context['themes'] as $key => $theme)
1672 1738
 		{
1673 1739
 			// There has to be a Settings template!
1674
-			if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css'))
1675
-				unset($context['themes'][$key]);
1676
-
1677
-			else
1678
-				$context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css');
1740
+			if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css')) {
1741
+							unset($context['themes'][$key]);
1742
+			} else {
1743
+							$context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css');
1744
+			}
1679 1745
 		}
1680 1746
 
1681 1747
 		$context['sub_template'] = 'edit_list';
@@ -1690,22 +1756,24 @@  discard block
 block discarded – undo
1690 1756
 	$context['theme_id'] = $currentTheme['id'];
1691 1757
 	$context['browse_title'] = sprintf($txt['themeadmin_browsing_theme'], $currentTheme['name']);
1692 1758
 
1693
-	if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css'))
1694
-		fatal_lang_error('theme_edit_missing', false);
1759
+	if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css')) {
1760
+			fatal_lang_error('theme_edit_missing', false);
1761
+	}
1695 1762
 
1696 1763
 	if (!isset($_REQUEST['filename']))
1697 1764
 	{
1698 1765
 		if (isset($_GET['directory']))
1699 1766
 		{
1700
-			if (substr($_GET['directory'], 0, 1) == '.')
1701
-				$_GET['directory'] = '';
1702
-			else
1767
+			if (substr($_GET['directory'], 0, 1) == '.') {
1768
+							$_GET['directory'] = '';
1769
+			} else
1703 1770
 			{
1704 1771
 				$_GET['directory'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_GET['directory']);
1705 1772
 
1706 1773
 				$temp = realpath($currentTheme['theme_dir'] . '/' . $_GET['directory']);
1707
-				if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir']))
1708
-					$_GET['directory'] = '';
1774
+				if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) {
1775
+									$_GET['directory'] = '';
1776
+				}
1709 1777
 			}
1710 1778
 		}
1711 1779
 
@@ -1724,37 +1792,39 @@  discard block
 block discarded – undo
1724 1792
 				'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $temp,
1725 1793
 				'size' => '',
1726 1794
 			));
1795
+		} else {
1796
+					$context['theme_files'] = get_file_listing($currentTheme['theme_dir'], '');
1727 1797
 		}
1728
-		else
1729
-			$context['theme_files'] = get_file_listing($currentTheme['theme_dir'], '');
1730 1798
 
1731 1799
 		$context['sub_template'] = 'edit_browse';
1732 1800
 
1733 1801
 		return;
1734
-	}
1735
-	else
1802
+	} else
1736 1803
 	{
1737
-		if (substr($_REQUEST['filename'], 0, 1) == '.')
1738
-			$_REQUEST['filename'] = '';
1739
-		else
1804
+		if (substr($_REQUEST['filename'], 0, 1) == '.') {
1805
+					$_REQUEST['filename'] = '';
1806
+		} else
1740 1807
 		{
1741 1808
 			$_REQUEST['filename'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_REQUEST['filename']);
1742 1809
 
1743 1810
 			$temp = realpath($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1744
-			if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir']))
1745
-				$_REQUEST['filename'] = '';
1811
+			if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) {
1812
+							$_REQUEST['filename'] = '';
1813
+			}
1746 1814
 		}
1747 1815
 
1748
-		if (empty($_REQUEST['filename']))
1749
-			fatal_lang_error('theme_edit_missing', false);
1816
+		if (empty($_REQUEST['filename'])) {
1817
+					fatal_lang_error('theme_edit_missing', false);
1818
+		}
1750 1819
 	}
1751 1820
 
1752 1821
 	if (isset($_POST['save']))
1753 1822
 	{
1754 1823
 		if (checkSession('post', '', false) == '' && validateToken('admin-te-' . md5($_GET['th'] . '-' . $_REQUEST['filename']), 'post', false) == true)
1755 1824
 		{
1756
-			if (is_array($_POST['entire_file']))
1757
-				$_POST['entire_file'] = implode("\n", $_POST['entire_file']);
1825
+			if (is_array($_POST['entire_file'])) {
1826
+							$_POST['entire_file'] = implode("\n", $_POST['entire_file']);
1827
+			}
1758 1828
 
1759 1829
 			$_POST['entire_file'] = rtrim(strtr($_POST['entire_file'], array("\r" => '', '   ' => "\t")));
1760 1830
 
@@ -1766,10 +1836,11 @@  discard block
 block discarded – undo
1766 1836
 				fclose($fp);
1767 1837
 
1768 1838
 				$error = @file_get_contents($currentTheme['theme_url'] . '/tmp_' . session_id() . '.php');
1769
-				if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0)
1770
-					$error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php';
1771
-				else
1772
-					unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php');
1839
+				if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0) {
1840
+									$error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php';
1841
+				} else {
1842
+									unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php');
1843
+				}
1773 1844
 			}
1774 1845
 
1775 1846
 			if (!isset($error_file))
@@ -1790,10 +1861,11 @@  discard block
 block discarded – undo
1790 1861
 			$context['sub_template'] = 'edit_file';
1791 1862
 
1792 1863
 			// Recycle the submitted data.
1793
-			if (is_array($_POST['entire_file']))
1794
-				$context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file']));
1795
-			else
1796
-				$context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']);
1864
+			if (is_array($_POST['entire_file'])) {
1865
+							$context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file']));
1866
+			} else {
1867
+							$context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']);
1868
+			}
1797 1869
 
1798 1870
 			$context['edit_filename'] = $smcFunc['htmlspecialchars']($_POST['filename']);
1799 1871
 
@@ -1816,17 +1888,17 @@  discard block
 block discarded – undo
1816 1888
 		$context['sub_template'] = 'edit_style';
1817 1889
 
1818 1890
 		$context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(file_get_contents($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']), array("\t" => '   ')));
1819
-	}
1820
-	elseif (substr($_REQUEST['filename'], -13) == '.template.php')
1891
+	} elseif (substr($_REQUEST['filename'], -13) == '.template.php')
1821 1892
 	{
1822 1893
 		$context['sub_template'] = 'edit_template';
1823 1894
 
1824
-		if (!isset($error_file))
1825
-			$file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1826
-		else
1895
+		if (!isset($error_file)) {
1896
+					$file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1897
+		} else
1827 1898
 		{
1828
-			if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0)
1829
-				$context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2];
1899
+			if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0) {
1900
+							$context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2];
1901
+			}
1830 1902
 			$file_data = file($error_file);
1831 1903
 			unlink($error_file);
1832 1904
 		}
@@ -1840,8 +1912,9 @@  discard block
 block discarded – undo
1840 1912
 				// Try to format the functions a little nicer...
1841 1913
 				$context['file_parts'][$j]['data'] = trim($context['file_parts'][$j]['data']) . "\n";
1842 1914
 
1843
-				if (empty($context['file_parts'][$j]['lines']))
1844
-					unset($context['file_parts'][$j]);
1915
+				if (empty($context['file_parts'][$j]['lines'])) {
1916
+									unset($context['file_parts'][$j]);
1917
+				}
1845 1918
 				$context['file_parts'][++$j] = array('lines' => 0, 'line' => $i + 1, 'data' => '');
1846 1919
 			}
1847 1920
 
@@ -1850,8 +1923,7 @@  discard block
 block discarded – undo
1850 1923
 		}
1851 1924
 
1852 1925
 		$context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(implode('', $file_data), array("\t" => '   ')));
1853
-	}
1854
-	else
1926
+	} else
1855 1927
 	{
1856 1928
 		$context['sub_template'] = 'edit_file';
1857 1929
 
@@ -1877,8 +1949,9 @@  discard block
 block discarded – undo
1877 1949
 
1878 1950
 	$_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
1879 1951
 
1880
-	if (empty($_GET['th']))
1881
-		fatal_lang_error('theme_install_invalid_id');
1952
+	if (empty($_GET['th'])) {
1953
+			fatal_lang_error('theme_install_invalid_id');
1954
+	}
1882 1955
 
1883 1956
 	// Get the theme info.
1884 1957
 	$theme = get_single_theme($_GET['th']);
@@ -1886,25 +1959,24 @@  discard block
 block discarded – undo
1886 1959
 
1887 1960
 	if (isset($_REQUEST['template']) && preg_match('~[\./\\\\:\0]~', $_REQUEST['template']) == 0)
1888 1961
 	{
1889
-		if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php'))
1890
-			$filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php';
1891
-
1892
-		else
1893
-			fatal_lang_error('no_access', false);
1962
+		if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php')) {
1963
+					$filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php';
1964
+		} else {
1965
+					fatal_lang_error('no_access', false);
1966
+		}
1894 1967
 
1895 1968
 		$fp = fopen($theme['theme_dir'] . '/' . $_REQUEST['template'] . '.template.php', 'w');
1896 1969
 		fwrite($fp, file_get_contents($filename));
1897 1970
 		fclose($fp);
1898 1971
 
1899 1972
 		redirectexit('action=admin;area=theme;th=' . $context['theme_id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=copy');
1900
-	}
1901
-	elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0)
1973
+	} elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0)
1902 1974
 	{
1903
-		if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php'))
1904
-			$filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php';
1905
-
1906
-		else
1907
-			fatal_lang_error('no_access', false);
1975
+		if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php')) {
1976
+					$filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php';
1977
+		} else {
1978
+					fatal_lang_error('no_access', false);
1979
+		}
1908 1980
 
1909 1981
 		$fp = fopen($theme['theme_dir'] . '/languages/' . $_REQUEST['lang_file'] . '.php', 'w');
1910 1982
 		fwrite($fp, file_get_contents($filename));
@@ -1919,16 +1991,18 @@  discard block
 block discarded – undo
1919 1991
 	$dir = dir($settings['default_theme_dir']);
1920 1992
 	while ($entry = $dir->read())
1921 1993
 	{
1922
-		if (substr($entry, -13) == '.template.php')
1923
-			$templates[] = substr($entry, 0, -13);
1994
+		if (substr($entry, -13) == '.template.php') {
1995
+					$templates[] = substr($entry, 0, -13);
1996
+		}
1924 1997
 	}
1925 1998
 	$dir->close();
1926 1999
 
1927 2000
 	$dir = dir($settings['default_theme_dir'] . '/languages');
1928 2001
 	while ($entry = $dir->read())
1929 2002
 	{
1930
-		if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches))
1931
-			$lang_files[] = $matches[1];
2003
+		if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches)) {
2004
+					$lang_files[] = $matches[1];
2005
+		}
1932 2006
 	}
1933 2007
 	$dir->close();
1934 2008
 
@@ -1936,21 +2010,23 @@  discard block
 block discarded – undo
1936 2010
 	natcasesort($lang_files);
1937 2011
 
1938 2012
 	$context['available_templates'] = array();
1939
-	foreach ($templates as $template)
1940
-		$context['available_templates'][$template] = array(
2013
+	foreach ($templates as $template) {
2014
+			$context['available_templates'][$template] = array(
1941 2015
 			'filename' => $template . '.template.php',
1942 2016
 			'value' => $template,
1943 2017
 			'already_exists' => false,
1944 2018
 			'can_copy' => is_writable($theme['theme_dir']),
1945 2019
 		);
2020
+	}
1946 2021
 	$context['available_language_files'] = array();
1947
-	foreach ($lang_files as $file)
1948
-		$context['available_language_files'][$file] = array(
2022
+	foreach ($lang_files as $file) {
2023
+			$context['available_language_files'][$file] = array(
1949 2024
 			'filename' => $file . '.php',
1950 2025
 			'value' => $file,
1951 2026
 			'already_exists' => false,
1952 2027
 			'can_copy' => file_exists($theme['theme_dir'] . '/languages') ? is_writable($theme['theme_dir'] . '/languages') : is_writable($theme['theme_dir']),
1953 2028
 		);
2029
+	}
1954 2030
 
1955 2031
 	$dir = dir($theme['theme_dir']);
1956 2032
 	while ($entry = $dir->read())
Please login to merge, or discard this patch.
Sources/Class-Graphics.php 1 patch
Braces   +90 added lines, -62 removed lines patch added patch discarded remove patch
@@ -19,8 +19,9 @@  discard block
 block discarded – undo
19 19
  * @version 2.1 Beta 3
20 20
  */
21 21
 
22
-if (!defined('SMF'))
22
+if (!defined('SMF')) {
23 23
 	die('No direct access...');
24
+}
24 25
 
25 26
 /**
26 27
  * Class gif_lzw_compression
@@ -52,13 +53,15 @@  discard block
 block discarded – undo
52 53
 
53 54
 		$this->LZWCommand($data, true);
54 55
 
55
-		while (($iIndex = $this->LZWCommand($data, false)) >= 0)
56
-			$ret .= chr($iIndex);
56
+		while (($iIndex = $this->LZWCommand($data, false)) >= 0) {
57
+					$ret .= chr($iIndex);
58
+		}
57 59
 
58 60
 		$datLen = $stLen - strlen($data);
59 61
 
60
-		if ($iIndex != -2)
61
-			return false;
62
+		if ($iIndex != -2) {
63
+					return false;
64
+		}
62 65
 
63 66
 		return $ret;
64 67
 	}
@@ -140,8 +143,9 @@  discard block
 block discarded – undo
140 143
 				return $this->FirstCode;
141 144
 			}
142 145
 
143
-			if ($Code == $this->EndCode)
144
-				return -2;
146
+			if ($Code == $this->EndCode) {
147
+							return -2;
148
+			}
145 149
 
146 150
 			$InCode = $Code;
147 151
 			if ($Code >= $this->MaxCode)
@@ -156,8 +160,10 @@  discard block
 block discarded – undo
156 160
 				$this->Stack[$this->sp] = $this->Vals[$Code];
157 161
 				$this->sp++;
158 162
 
159
-				if ($Code == $this->Next[$Code]) // Circular table entry, big GIF Error!
163
+				if ($Code == $this->Next[$Code]) {
164
+					// Circular table entry, big GIF Error!
160 165
 					return -1;
166
+				}
161 167
 
162 168
 				$Code = $this->Next[$Code];
163 169
 			}
@@ -207,8 +213,9 @@  discard block
 block discarded – undo
207 213
 			if ($this->Done)
208 214
 			{
209 215
 				// Ran off the end of my bits...
210
-				if ($this->CurBit >= $this->LastBit)
211
-					return 0;
216
+				if ($this->CurBit >= $this->LastBit) {
217
+									return 0;
218
+				}
212 219
 
213 220
 				return -1;
214 221
 			}
@@ -221,13 +228,14 @@  discard block
 block discarded – undo
221 228
 
222 229
 			if ($count)
223 230
 			{
224
-				for ($i = 0; $i < $count; $i++)
225
-					$this->Buf[2 + $i] = ord($data{$i});
231
+				for ($i = 0; $i < $count; $i++) {
232
+									$this->Buf[2 + $i] = ord($data{$i});
233
+				}
226 234
 
227 235
 				$data = substr($data, $count);
236
+			} else {
237
+							$this->Done = 1;
228 238
 			}
229
-			else
230
-				$this->Done = 1;
231 239
 
232 240
 			$this->LastByte = 2 + $count;
233 241
 			$this->CurBit = ($this->CurBit - $this->LastBit) + 16;
@@ -235,8 +243,9 @@  discard block
 block discarded – undo
235 243
 		}
236 244
 
237 245
 		$iRet = 0;
238
-		for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++)
239
-			$iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j;
246
+		for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) {
247
+					$iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j;
248
+		}
240 249
 
241 250
 		$this->CurBit += $this->CodeSize;
242 251
 		return $iRet;
@@ -261,8 +270,9 @@  discard block
 block discarded – undo
261 270
 		for ($i = 0; $i < $num; $i++)
262 271
 		{
263 272
 			$rgb = substr($lpData, $i * 3, 3);
264
-			if (strlen($rgb) < 3)
265
-				return false;
273
+			if (strlen($rgb) < 3) {
274
+							return false;
275
+			}
266 276
 
267 277
 			$this->m_arColors[] = (ord($rgb[2]) << 16) + (ord($rgb[1]) << 8) + ord($rgb[0]);
268 278
 			$this->m_nColors++;
@@ -329,13 +339,15 @@  discard block
 block discarded – undo
329 339
 		$hdrLen = 0;
330 340
 
331 341
 		$this->m_lpVer = substr($lpData, 0, 6);
332
-		if (($this->m_lpVer != 'GIF87a') && ($this->m_lpVer != 'GIF89a'))
333
-			return false;
342
+		if (($this->m_lpVer != 'GIF87a') && ($this->m_lpVer != 'GIF89a')) {
343
+					return false;
344
+		}
334 345
 
335 346
 		list ($this->m_nWidth, $this->m_nHeight) = array_values(unpack('v2', substr($lpData, 6, 4)));
336 347
 
337
-		if (!$this->m_nWidth || !$this->m_nHeight)
338
-			return false;
348
+		if (!$this->m_nWidth || !$this->m_nHeight) {
349
+					return false;
350
+		}
339 351
 
340 352
 		$b = ord(substr($lpData, 10, 1));
341 353
 		$this->m_bGlobalClr  = ($b & 0x80) ? true : false;
@@ -349,8 +361,9 @@  discard block
 block discarded – undo
349 361
 		if ($this->m_bGlobalClr)
350 362
 		{
351 363
 			$this->m_colorTable = new gif_color_table();
352
-			if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize))
353
-				return false;
364
+			if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) {
365
+							return false;
366
+			}
354 367
 
355 368
 			$hdrLen += 3 * $this->m_nTableSize;
356 369
 		}
@@ -377,8 +390,9 @@  discard block
 block discarded – undo
377 390
 		// Get the width/height/etc. from the header.
378 391
 		list ($this->m_nLeft, $this->m_nTop, $this->m_nWidth, $this->m_nHeight) = array_values(unpack('v4', substr($lpData, 0, 8)));
379 392
 
380
-		if (!$this->m_nWidth || !$this->m_nHeight)
381
-			return false;
393
+		if (!$this->m_nWidth || !$this->m_nHeight) {
394
+					return false;
395
+		}
382 396
 
383 397
 		$b = ord($lpData[8]);
384 398
 		$this->m_bLocalClr  = ($b & 0x80) ? true : false;
@@ -390,8 +404,9 @@  discard block
 block discarded – undo
390 404
 		if ($this->m_bLocalClr)
391 405
 		{
392 406
 			$this->m_colorTable = new gif_color_table();
393
-			if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize))
394
-				return false;
407
+			if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) {
408
+							return false;
409
+			}
395 410
 
396 411
 			$hdrLen += 3 * $this->m_nTableSize;
397 412
 		}
@@ -427,8 +442,9 @@  discard block
 block discarded – undo
427 442
 			// Extension...
428 443
 				case 0x21:
429 444
 					$len = 0;
430
-					if (!$this->skipExt($data, $len))
431
-						return false;
445
+					if (!$this->skipExt($data, $len)) {
446
+											return false;
447
+					}
432 448
 
433 449
 					$datLen += $len;
434 450
 					break;
@@ -437,22 +453,25 @@  discard block
 block discarded – undo
437 453
 				case 0x2C:
438 454
 					// Load the header and color table.
439 455
 					$len = 0;
440
-					if (!$this->m_gih->load($data, $len))
441
-						return false;
456
+					if (!$this->m_gih->load($data, $len)) {
457
+											return false;
458
+					}
442 459
 
443 460
 					$data = substr($data, $len);
444 461
 					$datLen += $len;
445 462
 
446 463
 					// Decompress the data, and ride on home ;).
447 464
 					$len = 0;
448
-					if (!($this->m_data = $this->m_lzw->decompress($data, $len)))
449
-						return false;
465
+					if (!($this->m_data = $this->m_lzw->decompress($data, $len))) {
466
+											return false;
467
+					}
450 468
 
451 469
 					$data = substr($data, $len);
452 470
 					$datLen += $len;
453 471
 
454
-					if ($this->m_gih->m_bInterlace)
455
-						$this->deInterlace();
472
+					if ($this->m_gih->m_bInterlace) {
473
+											$this->deInterlace();
474
+					}
456 475
 
457 476
 					return true;
458 477
 
@@ -572,17 +591,20 @@  discard block
 block discarded – undo
572 591
 
573 592
 	public function loadFile($filename, $iIndex)
574 593
 	{
575
-		if ($iIndex < 0)
576
-			return false;
594
+		if ($iIndex < 0) {
595
+					return false;
596
+		}
577 597
 
578 598
 		$this->data = @file_get_contents($filename);
579
-		if ($this->data === false)
580
-			return false;
599
+		if ($this->data === false) {
600
+					return false;
601
+		}
581 602
 
582 603
 		// Tell the header to load up....
583 604
 		$len = 0;
584
-		if (!$this->header->load($this->data, $len))
585
-			return false;
605
+		if (!$this->header->load($this->data, $len)) {
606
+					return false;
607
+		}
586 608
 
587 609
 		$this->data = substr($this->data, $len);
588 610
 
@@ -590,8 +612,9 @@  discard block
 block discarded – undo
590 612
 		for ($j = 0; $j <= $iIndex; $j++)
591 613
 		{
592 614
 			$imgLen = 0;
593
-			if (!$this->image->load($this->data, $imgLen))
594
-				return false;
615
+			if (!$this->image->load($this->data, $imgLen)) {
616
+							return false;
617
+			}
595 618
 
596 619
 			$this->data = substr($this->data, $imgLen);
597 620
 		}
@@ -602,8 +625,9 @@  discard block
 block discarded – undo
602 625
 
603 626
 	public function get_png_data($background_color)
604 627
 	{
605
-		if (!$this->loaded)
606
-			return false;
628
+		if (!$this->loaded) {
629
+					return false;
630
+		}
607 631
 
608 632
 		// Prepare the color table.
609 633
 		if ($this->image->m_gih->m_bLocalClr)
@@ -611,25 +635,26 @@  discard block
 block discarded – undo
611 635
 			$colors = $this->image->m_gih->m_nTableSize;
612 636
 			$pal = $this->image->m_gih->m_colorTable->toString();
613 637
 
614
-			if ($background_color != -1)
615
-				$background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color);
616
-		}
617
-		elseif ($this->header->m_bGlobalClr)
638
+			if ($background_color != -1) {
639
+							$background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color);
640
+			}
641
+		} elseif ($this->header->m_bGlobalClr)
618 642
 		{
619 643
 			$colors = $this->header->m_nTableSize;
620 644
 			$pal = $this->header->m_colorTable->toString();
621 645
 
622
-			if ($background_color != -1)
623
-				$background_color = $this->header->m_colorTable->colorIndex($background_color);
624
-		}
625
-		else
646
+			if ($background_color != -1) {
647
+							$background_color = $this->header->m_colorTable->colorIndex($background_color);
648
+			}
649
+		} else
626 650
 		{
627 651
 			$colors = 0;
628 652
 			$background_color = -1;
629 653
 		}
630 654
 
631
-		if ($background_color == -1)
632
-			$background_color = $this->header->m_nBgColor;
655
+		if ($background_color == -1) {
656
+					$background_color = $this->header->m_nBgColor;
657
+		}
633 658
 
634 659
 		$data = &$this->image->m_data;
635 660
 		$header = &$this->image->m_gih;
@@ -645,11 +670,13 @@  discard block
 block discarded – undo
645 670
 			for ($x = 0; $x < $this->header->m_nWidth; $x++, $i++)
646 671
 			{
647 672
 				// Is this in the proper range?  If so, get the specific pixel data...
648
-				if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight))
649
-					$bmp .= $data{$i};
673
+				if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight)) {
674
+									$bmp .= $data{$i};
675
+				}
650 676
 				// Otherwise, this is background...
651
-				else
652
-					$bmp .= chr($background_color);
677
+				else {
678
+									$bmp .= chr($background_color);
679
+				}
653 680
 			}
654 681
 		}
655 682
 
@@ -678,8 +705,9 @@  discard block
 block discarded – undo
678 705
 			$tmp = 'tRNS';
679 706
 
680 707
 			// Stick each color on - full transparency or none.
681
-			for ($i = 0; $i < $colors; $i++)
682
-				$tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF";
708
+			for ($i = 0; $i < $colors; $i++) {
709
+							$tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF";
710
+			}
683 711
 
684 712
 			$out .= $tmp . pack('N', smf_crc32($tmp));
685 713
 		}
Please login to merge, or discard this patch.
Sources/ModerationCenter.php 1 patch
Braces   +139 added lines, -102 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 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
  * Entry point for the moderation center.
@@ -26,8 +27,9 @@  discard block
 block discarded – undo
26 27
 	global $txt, $context, $scripturl, $modSettings, $user_info, $sourcedir, $options;
27 28
 
28 29
 	// Don't run this twice... and don't conflict with the admin bar.
29
-	if (isset($context['admin_area']))
30
-		return;
30
+	if (isset($context['admin_area'])) {
31
+			return;
32
+	}
31 33
 
32 34
 	$context['can_moderate_boards'] = $user_info['mod_cache']['bq'] != '0=1';
33 35
 	$context['can_moderate_groups'] = $user_info['mod_cache']['gq'] != '0=1';
@@ -35,8 +37,9 @@  discard block
 block discarded – undo
35 37
 	$context['can_moderate_users'] = allowedTo('moderate_forum');
36 38
 
37 39
 	// Everyone using this area must be allowed here!
38
-	if (!$context['can_moderate_boards'] && !$context['can_moderate_groups'] && !$context['can_moderate_approvals'] && !$context['can_moderate_users'])
39
-		isAllowedTo('access_mod_center');
40
+	if (!$context['can_moderate_boards'] && !$context['can_moderate_groups'] && !$context['can_moderate_approvals'] && !$context['can_moderate_users']) {
41
+			isAllowedTo('access_mod_center');
42
+	}
40 43
 
41 44
 	// We're gonna want a menu of some kind.
42 45
 	require_once($sourcedir . '/Subs-Menu.php');
@@ -195,8 +198,9 @@  discard block
 block discarded – undo
195 198
 	unset($moderation_areas);
196 199
 
197 200
 	// We got something - didn't we? DIDN'T WE!
198
-	if ($mod_include_data == false)
199
-		fatal_lang_error('no_access', false);
201
+	if ($mod_include_data == false) {
202
+			fatal_lang_error('no_access', false);
203
+	}
200 204
 
201 205
 	// Retain the ID information in case required by a subaction.
202 206
 	$context['moderation_menu_id'] = $context['max_menu_id'];
@@ -219,22 +223,25 @@  discard block
 block discarded – undo
219 223
 		'url' => $scripturl . '?action=moderate',
220 224
 		'name' => $txt['moderation_center'],
221 225
 	);
222
-	if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index')
223
-		$context['linktree'][] = array(
226
+	if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index') {
227
+			$context['linktree'][] = array(
224 228
 			'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'],
225 229
 			'name' => $mod_include_data['label'],
226 230
 		);
227
-	if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label'])
228
-		$context['linktree'][] = array(
231
+	}
232
+	if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label']) {
233
+			$context['linktree'][] = array(
229 234
 			'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'] . ';sa=' . $mod_include_data['current_subsection'],
230 235
 			'name' => $mod_include_data['subsections'][$mod_include_data['current_subsection']][0],
231 236
 		);
237
+	}
232 238
 
233 239
 	// Now - finally - the bit before the encore - the main performance of course!
234 240
 	if (!$dont_call)
235 241
 	{
236
-		if (isset($mod_include_data['file']))
237
-			require_once($sourcedir . '/' . $mod_include_data['file']);
242
+		if (isset($mod_include_data['file'])) {
243
+					require_once($sourcedir . '/' . $mod_include_data['file']);
244
+		}
238 245
 
239 246
 		call_helper($mod_include_data['function']);
240 247
 	}
@@ -259,8 +266,9 @@  discard block
 block discarded – undo
259 266
 	// Load what blocks the user actually can see...
260 267
 	$valid_blocks = array();
261 268
 
262
-	if ($context['can_moderate_groups'])
263
-		$valid_blocks['g'] = 'GroupRequests';
269
+	if ($context['can_moderate_groups']) {
270
+			$valid_blocks['g'] = 'GroupRequests';
271
+	}
264 272
 	if ($context['can_moderate_boards'])
265 273
 	{
266 274
 		$valid_blocks['r'] = 'ReportedPosts';
@@ -269,8 +277,9 @@  discard block
 block discarded – undo
269 277
 	if ($context['can_moderate_users'])
270 278
 	{
271 279
 		// This falls under the category of moderating users as well...
272
-		if (!$context['can_moderate_boards'])
273
-			$valid_blocks['w'] = 'WatchedUsers';
280
+		if (!$context['can_moderate_boards']) {
281
+					$valid_blocks['w'] = 'WatchedUsers';
282
+		}
274 283
 
275 284
 		$valid_blocks['rm'] = 'ReportedMembers';
276 285
 	}
@@ -281,8 +290,9 @@  discard block
 block discarded – undo
281 290
 	foreach ($valid_blocks as $k => $block)
282 291
 	{
283 292
 		$block = 'ModBlock' . $block;
284
-		if (function_exists($block))
285
-			$context['mod_blocks'][] = $block();
293
+		if (function_exists($block)) {
294
+					$context['mod_blocks'][] = $block();
295
+		}
286 296
 	}
287 297
 
288 298
 	$context['admin_prefs'] = !empty($options['admin_preferences']) ? smf_json_decode($options['admin_preferences'], true) : array();
@@ -309,8 +319,9 @@  discard block
 block discarded – undo
309 319
 			)
310 320
 		);
311 321
 		$watched_users = array();
312
-		while ($row = $smcFunc['db_fetch_assoc']($request))
313
-			$watched_users[] = $row;
322
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
323
+					$watched_users[] = $row;
324
+		}
314 325
 		$smcFunc['db_free_result']($request);
315 326
 
316 327
 		cache_put_data('recent_user_watches', $watched_users, 240);
@@ -402,8 +413,9 @@  discard block
 block discarded – undo
402 413
 			$note_owner = $smcFunc['db_num_rows']($get_owner);
403 414
 			$smcFunc['db_free_result']($get_owner);
404 415
 
405
-			if (empty($note_owner))
406
-				fatal_lang_error('mc_notes_delete_own', false);
416
+			if (empty($note_owner)) {
417
+							fatal_lang_error('mc_notes_delete_own', false);
418
+			}
407 419
 		}
408 420
 
409 421
 		// Lets delete it.
@@ -460,12 +472,14 @@  discard block
 block discarded – undo
460 472
 			)
461 473
 		);
462 474
 		$moderator_notes = array();
463
-		while ($row = $smcFunc['db_fetch_assoc']($request))
464
-			$moderator_notes[] = $row;
475
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
476
+					$moderator_notes[] = $row;
477
+		}
465 478
 		$smcFunc['db_free_result']($request);
466 479
 
467
-		if ($offset == 0)
468
-			cache_put_data('moderator_notes', $moderator_notes, 240);
480
+		if ($offset == 0) {
481
+					cache_put_data('moderator_notes', $moderator_notes, 240);
482
+		}
469 483
 	}
470 484
 
471 485
 	// Lets construct a page index.
@@ -504,8 +518,9 @@  discard block
 block discarded – undo
504 518
 	// Got the info already?
505 519
 	$cachekey = md5(json_encode($user_info['mod_cache']['bq']));
506 520
 	$context['reported_posts'] = array();
507
-	if ($user_info['mod_cache']['bq'] == '0=1')
508
-		return 'reported_posts_block';
521
+	if ($user_info['mod_cache']['bq'] == '0=1') {
522
+			return 'reported_posts_block';
523
+	}
509 524
 
510 525
 	if (($reported_posts = cache_get_data('reported_posts_' . $cachekey, 90)) === null)
511 526
 	{
@@ -529,8 +544,9 @@  discard block
 block discarded – undo
529 544
 			)
530 545
 		);
531 546
 		$reported_posts = array();
532
-		while ($row = $smcFunc['db_fetch_assoc']($request))
533
-			$reported_posts[] = $row;
547
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
548
+					$reported_posts[] = $row;
549
+		}
534 550
 		$smcFunc['db_free_result']($request);
535 551
 
536 552
 		// Cache it.
@@ -568,8 +584,9 @@  discard block
 block discarded – undo
568 584
 
569 585
 	$context['group_requests'] = array();
570 586
 	// Make sure they can even moderate someone!
571
-	if ($user_info['mod_cache']['gq'] == '0=1')
572
-		return 'group_requests_block';
587
+	if ($user_info['mod_cache']['gq'] == '0=1') {
588
+			return 'group_requests_block';
589
+	}
573 590
 
574 591
 	// What requests are outstanding?
575 592
 	$request = $smcFunc['db_query']('', '
@@ -618,8 +635,9 @@  discard block
 block discarded – undo
618 635
 	// Got the info already?
619 636
 	$cachekey = md5(json_encode((int) allowedTo('moderate_forum')));
620 637
 	$context['reported_users'] = array();
621
-	if (!allowedTo('moderate_forum'))
622
-		return 'reported_users_block';
638
+	if (!allowedTo('moderate_forum')) {
639
+			return 'reported_users_block';
640
+	}
623 641
 
624 642
 	if (($reported_users = cache_get_data('reported_users_' . $cachekey, 90)) === null)
625 643
 	{
@@ -642,8 +660,9 @@  discard block
 block discarded – undo
642 660
 			)
643 661
 		);
644 662
 		$reported_users = array();
645
-		while ($row = $smcFunc['db_fetch_assoc']($request))
646
-			$reported_users[] = $row;
663
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
664
+					$reported_users[] = $row;
665
+		}
647 666
 		$smcFunc['db_free_result']($request);
648 667
 
649 668
 		// Cache it.
@@ -691,8 +710,9 @@  discard block
 block discarded – undo
691 710
 	isAllowedTo('moderate_forum');
692 711
 
693 712
 	// Are they wanting to view a particular report?
694
-	if (!empty($_REQUEST['report']))
695
-		return MemberReport();
713
+	if (!empty($_REQUEST['report'])) {
714
+			return MemberReport();
715
+	}
696 716
 
697 717
 	// Set up the comforting bits...
698 718
 	$context['page_title'] = $txt['mc_reported_members'];
@@ -746,15 +766,15 @@  discard block
 block discarded – undo
746 766
 		// Time to update.
747 767
 		updateSettings(array('last_mod_report_action' => time()));
748 768
 		recountOpenReports('members');
749
-	}
750
-	elseif (isset($_POST['close']) && isset($_POST['close_selected']))
769
+	} elseif (isset($_POST['close']) && isset($_POST['close_selected']))
751 770
 	{
752 771
 		checkSession();
753 772
 
754 773
 		// All the ones to update...
755 774
 		$toClose = array();
756
-		foreach ($_POST['close'] as $rid)
757
-			$toClose[] = (int) $rid;
775
+		foreach ($_POST['close'] as $rid) {
776
+					$toClose[] = (int) $rid;
777
+		}
758 778
 
759 779
 		if (!empty($toClose))
760 780
 		{
@@ -907,8 +927,9 @@  discard block
 block discarded – undo
907 927
 	global $context, $user_info;
908 928
 
909 929
 	// You need to be allowed to moderate groups...
910
-	if ($user_info['mod_cache']['gq'] == '0=1')
911
-		isAllowedTo('manage_membergroups');
930
+	if ($user_info['mod_cache']['gq'] == '0=1') {
931
+			isAllowedTo('manage_membergroups');
932
+	}
912 933
 
913 934
 	// Load the group templates.
914 935
 	loadTemplate('ModerationCenter');
@@ -919,8 +940,9 @@  discard block
 block discarded – undo
919 940
 		'view' => 'ViewGroups',
920 941
 	);
921 942
 
922
-	if (!isset($_GET['sa']) || !isset($subActions[$_GET['sa']]))
923
-		$_GET['sa'] = 'view';
943
+	if (!isset($_GET['sa']) || !isset($subActions[$_GET['sa']])) {
944
+			$_GET['sa'] = 'view';
945
+	}
924 946
 	$context['sub_action'] = $_GET['sa'];
925 947
 
926 948
 	// Call the relevant function.
@@ -950,8 +972,9 @@  discard block
 block discarded – undo
950 972
 			'id_notice' => $id_notice,
951 973
 		)
952 974
 	);
953
-	if ($smcFunc['db_num_rows']($request) == 0)
954
-		fatal_lang_error('no_access', false);
975
+	if ($smcFunc['db_num_rows']($request) == 0) {
976
+			fatal_lang_error('no_access', false);
977
+	}
955 978
 	list ($context['notice_body'], $context['notice_subject']) = $smcFunc['db_fetch_row']($request);
956 979
 	$smcFunc['db_free_result']($request);
957 980
 
@@ -988,18 +1011,20 @@  discard block
 block discarded – undo
988 1011
 		checkSession(!is_array($_REQUEST['delete']) ? 'get' : 'post');
989 1012
 
990 1013
 		$toDelete = array();
991
-		if (!is_array($_REQUEST['delete']))
992
-			$toDelete[] = (int) $_REQUEST['delete'];
993
-		else
994
-			foreach ($_REQUEST['delete'] as $did)
1014
+		if (!is_array($_REQUEST['delete'])) {
1015
+					$toDelete[] = (int) $_REQUEST['delete'];
1016
+		} else {
1017
+					foreach ($_REQUEST['delete'] as $did)
995 1018
 				$toDelete[] = (int) $did;
1019
+		}
996 1020
 
997 1021
 		if (!empty($toDelete))
998 1022
 		{
999 1023
 			require_once($sourcedir . '/RemoveTopic.php');
1000 1024
 			// If they don't have permission we'll let it error - either way no chance of a security slip here!
1001
-			foreach ($toDelete as $did)
1002
-				removeMessage($did);
1025
+			foreach ($toDelete as $did) {
1026
+							removeMessage($did);
1027
+			}
1003 1028
 		}
1004 1029
 	}
1005 1030
 
@@ -1008,20 +1033,21 @@  discard block
 block discarded – undo
1008 1033
 	{
1009 1034
 		$approve_query = '';
1010 1035
 		$delete_boards = array();
1011
-	}
1012
-	else
1036
+	} else
1013 1037
 	{
1014 1038
 		// Still obey permissions!
1015 1039
 		$approve_boards = boardsAllowedTo('approve_posts');
1016 1040
 		$delete_boards = boardsAllowedTo('delete_any');
1017 1041
 
1018
-		if ($approve_boards == array(0))
1019
-			$approve_query = '';
1020
-		elseif (!empty($approve_boards))
1021
-			$approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
1042
+		if ($approve_boards == array(0)) {
1043
+					$approve_query = '';
1044
+		} elseif (!empty($approve_boards)) {
1045
+					$approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
1046
+		}
1022 1047
 		// Nada, zip, etc...
1023
-		else
1024
-			$approve_query = ' AND 1=0';
1048
+		else {
1049
+					$approve_query = ' AND 1=0';
1050
+		}
1025 1051
 	}
1026 1052
 
1027 1053
 	require_once($sourcedir . '/Subs-List.php');
@@ -1120,10 +1146,11 @@  discard block
 block discarded – undo
1120 1146
 				'data' => array(
1121 1147
 					'function' => function($member) use ($scripturl)
1122 1148
 					{
1123
-						if ($member['last_post_id'])
1124
-							return '<a href="' . $scripturl . '?msg=' . $member['last_post_id'] . '">' . $member['last_post'] . '</a>';
1125
-						else
1126
-							return $member['last_post'];
1149
+						if ($member['last_post_id']) {
1150
+													return '<a href="' . $scripturl . '?msg=' . $member['last_post_id'] . '">' . $member['last_post'] . '</a>';
1151
+						} else {
1152
+													return $member['last_post'];
1153
+						}
1127 1154
 					},
1128 1155
 				),
1129 1156
 			),
@@ -1251,8 +1278,9 @@  discard block
 block discarded – undo
1251 1278
 			)
1252 1279
 		);
1253 1280
 		$latest_posts = array();
1254
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1255
-			$latest_posts[$row['id_member']] = $row['last_post_id'];
1281
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1282
+					$latest_posts[$row['id_member']] = $row['last_post_id'];
1283
+		}
1256 1284
 
1257 1285
 		if (!empty($latest_posts))
1258 1286
 		{
@@ -1443,15 +1471,17 @@  discard block
 block discarded – undo
1443 1471
 	// Setup the direction stuff...
1444 1472
 	$context['order'] = isset($_REQUEST['sort']) && isset($sort_types[$_REQUEST['sort']]) ? $_REQUEST['sort'] : 'member';
1445 1473
 
1446
-	if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search']))
1447
-		$search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
1448
-	else
1449
-		$search_params_string = $search_params['string'];
1474
+	if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) {
1475
+			$search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
1476
+	} else {
1477
+			$search_params_string = $search_params['string'];
1478
+	}
1450 1479
 
1451
-	if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']]))
1452
-		$search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
1453
-	else
1454
-		$search_params_type = $search_params['type'];
1480
+	if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) {
1481
+			$search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
1482
+	} else {
1483
+			$search_params_type = $search_params['type'];
1484
+	}
1455 1485
 
1456 1486
 	$search_params_column = $searchTypes[$search_params_type]['sql'];
1457 1487
 	$search_params = array(
@@ -1535,9 +1565,10 @@  discard block
 block discarded – undo
1535 1565
 								' . $rowData['reason'] . '
1536 1566
 							</div>';
1537 1567
 
1538
-						if (!empty($rowData['id_notice']))
1539
-							$output .= '
1568
+						if (!empty($rowData['id_notice'])) {
1569
+													$output .= '
1540 1570
 								&nbsp;<a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $rowData['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" class="new_win" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a>';
1571
+						}
1541 1572
 						return $output;
1542 1573
 					},
1543 1574
 				),
@@ -1655,9 +1686,9 @@  discard block
 block discarded – undo
1655 1686
 	global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir, $user_info;
1656 1687
 
1657 1688
 	// Submitting a new one?
1658
-	if (isset($_POST['add']))
1659
-		return ModifyWarningTemplate();
1660
-	elseif (isset($_POST['delete']) && !empty($_POST['deltpl']))
1689
+	if (isset($_POST['add'])) {
1690
+			return ModifyWarningTemplate();
1691
+	} elseif (isset($_POST['delete']) && !empty($_POST['deltpl']))
1661 1692
 	{
1662 1693
 		checkSession();
1663 1694
 		validateToken('mod-wt');
@@ -1676,8 +1707,9 @@  discard block
 block discarded – undo
1676 1707
 				'current_member' => $user_info['id'],
1677 1708
 			)
1678 1709
 		);
1679
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1680
-			logAction('delete_warn_template', array('template' => $row['recipient_name']));
1710
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1711
+					logAction('delete_warn_template', array('template' => $row['recipient_name']));
1712
+		}
1681 1713
 		$smcFunc['db_free_result']($request);
1682 1714
 
1683 1715
 		// Do the deletes.
@@ -1968,16 +2000,18 @@  discard block
 block discarded – undo
1968 2000
 				);
1969 2001
 
1970 2002
 				// If it wasn't visible and now is they've effectively added it.
1971
-				if ($context['template_data']['personal'] && !$recipient_id)
1972
-					logAction('add_warn_template', array('template' => $_POST['template_title']));
2003
+				if ($context['template_data']['personal'] && !$recipient_id) {
2004
+									logAction('add_warn_template', array('template' => $_POST['template_title']));
2005
+				}
1973 2006
 				// Conversely if they made it personal it's a delete.
1974
-				elseif (!$context['template_data']['personal'] && $recipient_id)
1975
-					logAction('delete_warn_template', array('template' => $_POST['template_title']));
2007
+				elseif (!$context['template_data']['personal'] && $recipient_id) {
2008
+									logAction('delete_warn_template', array('template' => $_POST['template_title']));
2009
+				}
1976 2010
 				// Otherwise just an edit.
1977
-				else
1978
-					logAction('modify_warn_template', array('template' => $_POST['template_title']));
1979
-			}
1980
-			else
2011
+				else {
2012
+									logAction('modify_warn_template', array('template' => $_POST['template_title']));
2013
+				}
2014
+			} else
1981 2015
 			{
1982 2016
 				$smcFunc['db_insert']('',
1983 2017
 					'{db_prefix}log_comments',
@@ -1997,17 +2031,18 @@  discard block
 block discarded – undo
1997 2031
 
1998 2032
 			// Get out of town...
1999 2033
 			redirectexit('action=moderate;area=warnings;sa=templates');
2000
-		}
2001
-		else
2034
+		} else
2002 2035
 		{
2003 2036
 			$context['warning_errors'] = array();
2004 2037
 			$context['template_data']['title'] = !empty($_POST['template_title']) ? $_POST['template_title'] : '';
2005 2038
 			$context['template_data']['body'] = !empty($_POST['template_body']) ? $_POST['template_body'] : $txt['mc_warning_template_body_default'];
2006 2039
 			$context['template_data']['personal'] = !empty($_POST['make_personal']);
2007
-			if (empty($_POST['template_title']))
2008
-				$context['warning_errors'][] = $txt['mc_warning_template_error_no_title'];
2009
-			if (empty($_POST['template_body']))
2010
-				$context['warning_errors'][] = $txt['mc_warning_template_error_no_body'];
2040
+			if (empty($_POST['template_title'])) {
2041
+							$context['warning_errors'][] = $txt['mc_warning_template_error_no_title'];
2042
+			}
2043
+			if (empty($_POST['template_body'])) {
2044
+							$context['warning_errors'][] = $txt['mc_warning_template_error_no_body'];
2045
+			}
2011 2046
 		}
2012 2047
 	}
2013 2048
 
@@ -2054,8 +2089,9 @@  discard block
 block discarded – undo
2054 2089
 		// Now check other options!
2055 2090
 		$pref_binary = 0;
2056 2091
 
2057
-		if ($context['can_moderate_approvals'] && !empty($_POST['mod_notify_approval']))
2058
-			$pref_binary |= 4;
2092
+		if ($context['can_moderate_approvals'] && !empty($_POST['mod_notify_approval'])) {
2093
+					$pref_binary |= 4;
2094
+		}
2059 2095
 
2060 2096
 		// Put it all together.
2061 2097
 		$mod_prefs = '0||' . $pref_binary;
@@ -2079,9 +2115,10 @@  discard block
 block discarded – undo
2079 2115
 	unset($_SESSION['moderate_time']);
2080 2116
 
2081 2117
 	// Clean any moderator tokens as well.
2082
-	foreach ($_SESSION['token'] as $key => $token)
2083
-		if (strpos($key, '-mod') !== false)
2118
+	foreach ($_SESSION['token'] as $key => $token) {
2119
+			if (strpos($key, '-mod') !== false)
2084 2120
 			unset($_SESSION['token'][$key]);
2121
+	}
2085 2122
 
2086 2123
 	redirectexit();
2087 2124
 }
Please login to merge, or discard this patch.