Completed
Push — release-2.1 ( 4c82a0...64d581 )
by Rick
09:29
created
Sources/Calendar.php 1 patch
Braces   +94 added lines, -71 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
  * Show the calendar.
@@ -47,12 +48,14 @@  discard block
 block discarded – undo
47 48
 		'post' => 'CalendarPost',
48 49
 	);
49 50
 
50
-	if (isset($_GET['sa']) && isset($subActions[$_GET['sa']]))
51
-		return call_helper($subActions[$_GET['sa']]);
51
+	if (isset($_GET['sa']) && isset($subActions[$_GET['sa']])) {
52
+			return call_helper($subActions[$_GET['sa']]);
53
+	}
52 54
 
53 55
 	// You can't do anything if the calendar is off.
54
-	if (empty($modSettings['cal_enabled']))
55
-		fatal_lang_error('calendar_off', false);
56
+	if (empty($modSettings['cal_enabled'])) {
57
+			fatal_lang_error('calendar_off', false);
58
+	}
56 59
 
57 60
 	// This is gonna be needed...
58 61
 	loadTemplate('Calendar');
@@ -97,8 +100,9 @@  discard block
 block discarded – undo
97 100
 	$context['view_week'] = isset($_GET['viewweek']);
98 101
 
99 102
 	// Don't let search engines index weekly calendar pages.
100
-	if ($context['view_week'])
101
-		$context['robot_no_index'] = true;
103
+	if ($context['view_week']) {
104
+			$context['robot_no_index'] = true;
105
+	}
102 106
 
103 107
 	// Get the current day of month...
104 108
 	require_once($sourcedir . '/Subs-Calendar.php');
@@ -112,17 +116,20 @@  discard block
 block discarded – undo
112 116
 	);
113 117
 
114 118
 	// Make sure the year and month are in valid ranges.
115
-	if ($curPage['month'] < 1 || $curPage['month'] > 12)
116
-		fatal_lang_error('invalid_month', false);
117
-	if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear'])
118
-		fatal_lang_error('invalid_year', false);
119
+	if ($curPage['month'] < 1 || $curPage['month'] > 12) {
120
+			fatal_lang_error('invalid_month', false);
121
+	}
122
+	if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear']) {
123
+			fatal_lang_error('invalid_year', false);
124
+	}
119 125
 	// If we have a day clean that too.
120 126
 	if ($context['view_week'])
121 127
 	{
122 128
 		// Note $isValid is -1 < PHP 5.1
123 129
 		$isValid = mktime(0, 0, 0, $curPage['month'], $curPage['day'], $curPage['year']);
124
-		if ($curPage['day'] > 31 || !$isValid || $isValid == -1)
125
-			fatal_lang_error('invalid_day', false);
130
+		if ($curPage['day'] > 31 || !$isValid || $isValid == -1) {
131
+					fatal_lang_error('invalid_day', false);
132
+		}
126 133
 	}
127 134
 
128 135
 	// Load all the context information needed to show the calendar grid.
@@ -144,21 +151,24 @@  discard block
 block discarded – undo
144 151
 	);
145 152
 
146 153
 	// Load up the main view.
147
-	if ($context['view_week'])
148
-		$context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
149
-	else
150
-		$context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
154
+	if ($context['view_week']) {
155
+			$context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
156
+	} else {
157
+			$context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
158
+	}
151 159
 
152 160
 	// Load up the previous and next months.
153 161
 	$context['calendar_grid_current'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
154 162
 
155 163
 	// Only show previous month if it isn't pre-January of the min-year
156
-	if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1)
157
-		$context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
164
+	if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1) {
165
+			$context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
166
+	}
158 167
 
159 168
 	// Only show next month if it isn't post-December of the max-year
160
-	if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12)
161
-		$context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
169
+	if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12) {
170
+			$context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
171
+	}
162 172
 
163 173
 	// Basic template stuff.
164 174
 	$context['allow_calendar_event'] = allowedTo('calendar_post');
@@ -191,17 +201,19 @@  discard block
 block discarded – undo
191 201
 		'name' => $txt['months'][$context['current_month']] . ' ' . $context['current_year']
192 202
 	);
193 203
 	// If applicable, add the current week to the linktree.
194
-	if ($context['view_week'])
195
-		$context['linktree'][] = array(
204
+	if ($context['view_week']) {
205
+			$context['linktree'][] = array(
196 206
 			'url' => $scripturl . '?action=calendar;viewweek;year=' . $context['current_year'] . ';month=' . $context['current_month'] . ';day=' . $context['current_day'],
197 207
 			'name' => $context['calendar_grid_main']['week_title'],
198 208
 		);
209
+	}
199 210
 
200 211
 	// Build the calendar button array.
201 212
 	$context['calendar_buttons'] = array();
202 213
 
203
-	if ($context['can_post'])
204
-		$context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']);
214
+	if ($context['can_post']) {
215
+			$context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']);
216
+	}
205 217
 
206 218
 	// Allow mods to add additional buttons here
207 219
 	call_integration_hook('integrate_calendar_buttons');
@@ -229,8 +241,9 @@  discard block
 block discarded – undo
229 241
 	require_once($sourcedir . '/Subs-Calendar.php');
230 242
 
231 243
 	// Cast this for safety...
232
-	if (isset($_REQUEST['eventid']))
233
-		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
244
+	if (isset($_REQUEST['eventid'])) {
245
+			$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
246
+	}
234 247
 
235 248
 	// Submitting?
236 249
 	if (isset($_POST[$context['session_var']], $_REQUEST['eventid']))
@@ -238,12 +251,14 @@  discard block
 block discarded – undo
238 251
 		checkSession();
239 252
 
240 253
 		// Validate the post...
241
-		if (!isset($_POST['link_to_board']))
242
-			validateEventPost();
254
+		if (!isset($_POST['link_to_board'])) {
255
+					validateEventPost();
256
+		}
243 257
 
244 258
 		// If you're not allowed to edit any events, you have to be the poster.
245
-		if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any'))
246
-			isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
259
+		if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any')) {
260
+					isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
261
+		}
247 262
 
248 263
 		// New - and directing?
249 264
 		if (isset($_POST['link_to_board']) || empty($modSettings['cal_allow_unlinked']))
@@ -267,8 +282,9 @@  discard block
 block discarded – undo
267 282
 		}
268 283
 
269 284
 		// Deleting...
270
-		elseif (isset($_REQUEST['deleteevent']))
271
-			removeEvent($_REQUEST['eventid']);
285
+		elseif (isset($_REQUEST['deleteevent'])) {
286
+					removeEvent($_REQUEST['eventid']);
287
+		}
272 288
 
273 289
 		// ... or just update it?
274 290
 		else
@@ -315,13 +331,13 @@  discard block
 block discarded – undo
315 331
 			'span' => 1,
316 332
 		);
317 333
 		$context['event']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year']));
318
-	}
319
-	else
334
+	} else
320 335
 	{
321 336
 		$context['event'] = getEventProperties($_REQUEST['eventid']);
322 337
 
323
-		if ($context['event'] === false)
324
-			fatal_lang_error('no_access', false);
338
+		if ($context['event'] === false) {
339
+					fatal_lang_error('no_access', false);
340
+		}
325 341
 
326 342
 		// If it has a board, then they should be editing it within the topic.
327 343
 		if (!empty($context['event']['topic']['id']) && !empty($context['event']['topic']['first_msg']))
@@ -332,10 +348,11 @@  discard block
 block discarded – undo
332 348
 		}
333 349
 
334 350
 		// Make sure the user is allowed to edit this event.
335
-		if ($context['event']['member'] != $user_info['id'])
336
-			isAllowedTo('calendar_edit_any');
337
-		elseif (!allowedTo('calendar_edit_any'))
338
-			isAllowedTo('calendar_edit_own');
351
+		if ($context['event']['member'] != $user_info['id']) {
352
+					isAllowedTo('calendar_edit_any');
353
+		} elseif (!allowedTo('calendar_edit_any')) {
354
+					isAllowedTo('calendar_edit_own');
355
+		}
339 356
 	}
340 357
 
341 358
 	// Get list of boards that can be posted in.
@@ -344,8 +361,7 @@  discard block
 block discarded – undo
344 361
 	{
345 362
 		// You can post new events but can't link them to anything...
346 363
 		$context['event']['categories'] = array();
347
-	}
348
-	else
364
+	} else
349 365
 	{
350 366
 		// Load the list of boards and categories in the context.
351 367
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -383,12 +399,14 @@  discard block
 block discarded – undo
383 399
 	global $smcFunc, $sourcedir, $forum_version, $modSettings, $webmaster_email, $mbname;
384 400
 
385 401
 	// You can't export if the calendar export feature is off.
386
-	if (empty($modSettings['cal_export']))
387
-		fatal_lang_error('calendar_export_off', false);
402
+	if (empty($modSettings['cal_export'])) {
403
+			fatal_lang_error('calendar_export_off', false);
404
+	}
388 405
 
389 406
 	// Goes without saying that this is required.
390
-	if (!isset($_REQUEST['eventid']))
391
-		fatal_lang_error('no_access', false);
407
+	if (!isset($_REQUEST['eventid'])) {
408
+			fatal_lang_error('no_access', false);
409
+	}
392 410
 
393 411
 	// This is kinda wanted.
394 412
 	require_once($sourcedir . '/Subs-Calendar.php');
@@ -396,15 +414,17 @@  discard block
 block discarded – undo
396 414
 	// Load up the event in question and check it exists.
397 415
 	$event = getEventProperties($_REQUEST['eventid']);
398 416
 
399
-	if ($event === false)
400
-		fatal_lang_error('no_access', false);
417
+	if ($event === false) {
418
+			fatal_lang_error('no_access', false);
419
+	}
401 420
 
402 421
 	// Check the title isn't too long - iCal requires some formatting if so.
403 422
 	$title = str_split($event['title'], 30);
404 423
 	foreach ($title as $id => $line)
405 424
 	{
406
-		if ($id != 0)
407
-			$title[$id] = ' ' . $title[$id];
425
+		if ($id != 0) {
426
+					$title[$id] = ' ' . $title[$id];
427
+		}
408 428
 		$title[$id] .= "\n";
409 429
 	}
410 430
 
@@ -433,12 +453,14 @@  discard block
 block discarded – undo
433 453
 	$filecontents .= 'DTSTART;VALUE=DATE:' . $datestart . "\n";
434 454
 
435 455
 	// more than one day
436
-	if ($event['span'] > 1)
437
-		$filecontents .= 'DTEND;VALUE=DATE:' . $dateend . "\n";
456
+	if ($event['span'] > 1) {
457
+			$filecontents .= 'DTEND;VALUE=DATE:' . $dateend . "\n";
458
+	}
438 459
 
439 460
 	// event has changed? advance the sequence for this UID
440
-	if ($event['sequence'] > 0)
441
-		$filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
461
+	if ($event['sequence'] > 0) {
462
+			$filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
463
+	}
442 464
 
443 465
 	$filecontents .= 'SUMMARY:' . implode('', $title);
444 466
 	$filecontents .= 'UID:' . $event['eventid'] . '@' . str_replace(' ', '-', $mbname) . "\n";
@@ -447,23 +469,26 @@  discard block
 block discarded – undo
447 469
 
448 470
 	// Send some standard headers.
449 471
 	ob_end_clean();
450
-	if (!empty($modSettings['enableCompressedOutput']))
451
-		@ob_start('ob_gzhandler');
452
-	else
453
-		ob_start();
472
+	if (!empty($modSettings['enableCompressedOutput'])) {
473
+			@ob_start('ob_gzhandler');
474
+	} else {
475
+			ob_start();
476
+	}
454 477
 
455 478
 	// Send the file headers
456 479
 	header('Pragma: ');
457 480
 	header('Cache-Control: no-cache');
458
-	if (!isBrowser('gecko'))
459
-		header('Content-Transfer-Encoding: binary');
481
+	if (!isBrowser('gecko')) {
482
+			header('Content-Transfer-Encoding: binary');
483
+	}
460 484
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
461 485
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . 'GMT');
462 486
 	header('Accept-Ranges: bytes');
463 487
 	header('Connection: close');
464 488
 	header('Content-Disposition: attachment; filename="' . $event['title'] . '.ics"');
465
-	if (empty($modSettings['enableCompressedOutput']))
466
-		header('Content-Length: ' . $smcFunc['strlen']($filecontents));
489
+	if (empty($modSettings['enableCompressedOutput'])) {
490
+			header('Content-Length: ' . $smcFunc['strlen']($filecontents));
491
+	}
467 492
 
468 493
 	// This is a calendar item!
469 494
 	header('Content-Type: text/calendar');
@@ -502,20 +527,17 @@  discard block
 block discarded – undo
502 527
 		$context['sub_template'] = 'bcd';
503 528
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock;bcd', 'name' => 'BCD');
504 529
 		$context['clockicons'] = safe_unserialize(base64_decode('YTo2OntzOjI6ImgxIjthOjI6e2k6MDtpOjI7aToxO2k6MTt9czoyOiJoMiI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjI6Im0xIjthOjM6e2k6MDtpOjQ7aToxO2k6MjtpOjI7aToxO31zOjI6Im0yIjthOjQ6e2k6MDtpOjg7aToxO2k6NDtpOjI7aToyO2k6MztpOjE7fXM6MjoiczEiO2E6Mzp7aTowO2k6NDtpOjE7aToyO2k6MjtpOjE7fXM6MjoiczIiO2E6NDp7aTowO2k6ODtpOjE7aTo0O2k6MjtpOjI7aTozO2k6MTt9fQ=='));
505
-	}
506
-	elseif (!$omfg && !isset($_REQUEST['time']))
530
+	} elseif (!$omfg && !isset($_REQUEST['time']))
507 531
 	{
508 532
 		$context['sub_template'] = 'hms';
509 533
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock', 'name' => 'Binary');
510 534
 		$context['clockicons'] = safe_unserialize(base64_decode('YTozOntzOjE6ImgiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czoxOiJtIjthOjY6e2k6MDtpOjMyO2k6MTtpOjE2O2k6MjtpOjg7aTozO2k6NDtpOjQ7aToyO2k6NTtpOjE7fXM6MToicyI7YTo2OntpOjA7aTozMjtpOjE7aToxNjtpOjI7aTo4O2k6MztpOjQ7aTo0O2k6MjtpOjU7aToxO319'));
511
-	}
512
-	elseif ($omfg)
535
+	} elseif ($omfg)
513 536
 	{
514 537
 		$context['sub_template'] = 'omfg';
515 538
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock;omfg', 'name' => 'OMFG');
516 539
 		$context['clockicons'] = safe_unserialize(base64_decode('YTo2OntzOjQ6InllYXIiO2E6Nzp7aTowO2k6NjQ7aToxO2k6MzI7aToyO2k6MTY7aTozO2k6ODtpOjQ7aTo0O2k6NTtpOjI7aTo2O2k6MTt9czo1OiJtb250aCI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjM6ImRheSI7YTo1OntpOjA7aToxNjtpOjE7aTo4O2k6MjtpOjQ7aTozO2k6MjtpOjQ7aToxO31zOjQ6ImhvdXIiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czozOiJtaW4iO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9czozOiJzZWMiO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9fQ=='));
517
-	}
518
-	elseif (isset($_REQUEST['time']))
540
+	} elseif (isset($_REQUEST['time']))
519 541
 	{
520 542
 		$context['sub_template'] = 'thetime';
521 543
 		$time = getdate($_REQUEST['time'] == 'now' ? time() : (int) $_REQUEST['time']);
@@ -575,12 +597,13 @@  discard block
 block discarded – undo
575 597
 			),
576 598
 		);
577 599
 
578
-		foreach ($context['clockicons'] as $t => $vs)
579
-			foreach ($vs as $v => $dumb)
600
+		foreach ($context['clockicons'] as $t => $vs) {
601
+					foreach ($vs as $v => $dumb)
580 602
 			{
581 603
 				if ($$t >= $v)
582 604
 				{
583 605
 					$$t -= $v;
606
+		}
584 607
 					$context['clockicons'][$t][$v] = true;
585 608
 				}
586 609
 			}
Please login to merge, or discard this patch.
Sources/Reports.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	// Build the reports button array.
113 113
 	$context['report_buttons'] = array(
114 114
 		'generate_reports' => array('text' => 'generate_reports', 'image' => 'print.png', 'url' => $scripturl . '?action=admin;area=reports', 'active' => true),
115
-		'print' => array('text' => 'print', 'image' => 'print.png', 'url' => $scripturl . '?action=admin;area=reports;rt=' . $context['report_type']. ';st=print', 'custom' => 'target="_blank"'),
115
+		'print' => array('text' => 'print', 'image' => 'print.png', 'url' => $scripturl . '?action=admin;area=reports;rt=' . $context['report_type'] . ';st=print', 'custom' => 'target="_blank"'),
116 116
 	);
117 117
 
118 118
 	// Allow mods to add additional buttons here
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 	$request = $smcFunc['db_query']('', '
345 345
 		SELECT id_board, id_group
346 346
 		FROM {db_prefix}moderator_groups
347
-		WHERE ' . $board_clause .' AND ' . $group_clause,
347
+		WHERE ' . $board_clause . ' AND ' . $group_clause,
348 348
 		array(
349 349
 		)
350 350
 	);
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/DbPackages-mysql.php 1 patch
Braces   +127 added lines, -101 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
  * Add the file functions to the $smcFunc array.
@@ -52,8 +53,9 @@  discard block
 block discarded – undo
52 53
 		'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages',
53 54
 		'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys',
54 55
 		'themes', 'topics');
55
-	foreach ($reservedTables as $k => $table_name)
56
-		$reservedTables[$k] = strtolower($db_prefix . $table_name);
56
+	foreach ($reservedTables as $k => $table_name) {
57
+			$reservedTables[$k] = strtolower($db_prefix . $table_name);
58
+	}
57 59
 
58 60
 	// We in turn may need the extra stuff.
59 61
 	db_extend('extra');
@@ -105,8 +107,9 @@  discard block
 block discarded – undo
105 107
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
106 108
 
107 109
 	// First - no way do we touch SMF tables.
108
-	if (in_array(strtolower($table_name), $reservedTables))
109
-		return false;
110
+	if (in_array(strtolower($table_name), $reservedTables)) {
111
+			return false;
112
+	}
110 113
 
111 114
 	// Log that we'll want to remove this on uninstall.
112 115
 	$db_package_log[] = array('remove_table', $table_name);
@@ -116,16 +119,18 @@  discard block
 block discarded – undo
116 119
 	if (in_array($full_table_name, $tables))
117 120
 	{
118 121
 		// This is a sad day... drop the table? If not, return false (error) by default.
119
-		if ($if_exists == 'overwrite')
120
-			$smcFunc['db_drop_table']($table_name);
121
-		else
122
-			return $if_exists == 'ignore';
122
+		if ($if_exists == 'overwrite') {
123
+					$smcFunc['db_drop_table']($table_name);
124
+		} else {
125
+					return $if_exists == 'ignore';
126
+		}
123 127
 	}
124 128
 
125 129
 	// Righty - let's do the damn thing!
126 130
 	$table_query = 'CREATE TABLE ' . $table_name . "\n" . '(';
127
-	foreach ($columns as $column)
128
-		$table_query .= "\n\t" . smf_db_create_query_column($column)  . ',';
131
+	foreach ($columns as $column) {
132
+			$table_query .= "\n\t" . smf_db_create_query_column($column)  . ',';
133
+	}
129 134
 
130 135
 	// Loop through the indexes next...
131 136
 	foreach ($indexes as $index)
@@ -133,19 +138,21 @@  discard block
 block discarded – undo
133 138
 		$columns = implode(',', $index['columns']);
134 139
 
135 140
 		// Is it the primary?
136
-		if (isset($index['type']) && $index['type'] == 'primary')
137
-			$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
138
-		else
141
+		if (isset($index['type']) && $index['type'] == 'primary') {
142
+					$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
143
+		} else
139 144
 		{
140
-			if (empty($index['name']))
141
-				$index['name'] = implode('_', $index['columns']);
145
+			if (empty($index['name'])) {
146
+							$index['name'] = implode('_', $index['columns']);
147
+			}
142 148
 			$table_query .= "\n\t" . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : 'KEY') . ' ' . $index['name'] . ' (' . $columns . '),';
143 149
 		}
144 150
 	}
145 151
 
146 152
 	// No trailing commas!
147
-	if (substr($table_query, -1) == ',')
148
-		$table_query = substr($table_query, 0, -1);
153
+	if (substr($table_query, -1) == ',') {
154
+			$table_query = substr($table_query, 0, -1);
155
+	}
149 156
 
150 157
 	// Which engine do we want here?
151 158
 	if (empty($engines))
@@ -155,8 +162,9 @@  discard block
 block discarded – undo
155 162
 
156 163
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
157 164
 		{
158
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
159
-				$engines[] = $row['Engine'];
165
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
166
+							$engines[] = $row['Engine'];
167
+			}
160 168
 		}
161 169
 
162 170
 		$smcFunc['db_free_result']($get_engines);
@@ -170,8 +178,9 @@  discard block
 block discarded – undo
170 178
 	}
171 179
 
172 180
 	$table_query .= ') ENGINE=' . $parameters['engine'];
173
-	if (!empty($db_character_set) && $db_character_set == 'utf8')
174
-		$table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
181
+	if (!empty($db_character_set) && $db_character_set == 'utf8') {
182
+			$table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
183
+	}
175 184
 
176 185
 	// Create the table!
177 186
 	$smcFunc['db_query']('', $table_query,
@@ -203,8 +212,9 @@  discard block
 block discarded – undo
203 212
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
204 213
 
205 214
 	// God no - dropping one of these = bad.
206
-	if (in_array(strtolower($table_name), $reservedTables))
207
-		return false;
215
+	if (in_array(strtolower($table_name), $reservedTables)) {
216
+			return false;
217
+	}
208 218
 
209 219
 	// Does it exist?
210 220
 	if (in_array($full_table_name, $smcFunc['db_list_tables']()))
@@ -245,14 +255,16 @@  discard block
 block discarded – undo
245 255
 
246 256
 	// Does it exist - if so don't add it again!
247 257
 	$columns = $smcFunc['db_list_columns']($table_name, false);
248
-	foreach ($columns as $column)
249
-		if ($column == $column_info['name'])
258
+	foreach ($columns as $column) {
259
+			if ($column == $column_info['name'])
250 260
 		{
251 261
 			// If we're going to overwrite then use change column.
252 262
 			if ($if_exists == 'update')
253 263
 				return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
254
-			else
255
-				return false;
264
+	}
265
+			else {
266
+							return false;
267
+			}
256 268
 		}
257 269
 
258 270
 	// Get the specifics...
@@ -262,8 +274,9 @@  discard block
 block discarded – undo
262 274
 	// Allow unsigned integers (mysql only)
263 275
 	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : '';
264 276
 
265
-	if ($size !== null)
266
-		$type = $type . '(' . $size . ')';
277
+	if ($size !== null) {
278
+			$type = $type . '(' . $size . ')';
279
+	}
267 280
 
268 281
 	// Now add the thing!
269 282
 	$query = '
@@ -295,8 +308,8 @@  discard block
 block discarded – undo
295 308
 
296 309
 	// Does it exist?
297 310
 	$columns = $smcFunc['db_list_columns']($table_name, true);
298
-	foreach ($columns as $column)
299
-		if ($column['name'] == $column_name)
311
+	foreach ($columns as $column) {
312
+			if ($column['name'] == $column_name)
300 313
 		{
301 314
 			$smcFunc['db_query']('', '
302 315
 				ALTER TABLE ' . $table_name . '
@@ -305,6 +318,7 @@  discard block
 block discarded – undo
305 318
 					'security_override' => true,
306 319
 				)
307 320
 			);
321
+	}
308 322
 
309 323
 			return true;
310 324
 		}
@@ -331,37 +345,47 @@  discard block
 block discarded – undo
331 345
 	// Check it does exist!
332 346
 	$columns = $smcFunc['db_list_columns']($table_name, true);
333 347
 	$old_info = null;
334
-	foreach ($columns as $column)
335
-		if ($column['name'] == $old_column)
348
+	foreach ($columns as $column) {
349
+			if ($column['name'] == $old_column)
336 350
 			$old_info = $column;
351
+	}
337 352
 
338 353
 	// Nothing?
339
-	if ($old_info == null)
340
-		return false;
354
+	if ($old_info == null) {
355
+			return false;
356
+	}
341 357
 
342 358
 	// Get the right bits.
343
-	if (!isset($column_info['name']))
344
-		$column_info['name'] = $old_column;
345
-	if (!isset($column_info['default']))
346
-		$column_info['default'] = $old_info['default'];
347
-	if (!isset($column_info['null']))
348
-		$column_info['null'] = $old_info['null'];
349
-	if (!isset($column_info['auto']))
350
-		$column_info['auto'] = $old_info['auto'];
351
-	if (!isset($column_info['type']))
352
-		$column_info['type'] = $old_info['type'];
353
-	if (!isset($column_info['size']) || !is_numeric($column_info['size']))
354
-		$column_info['size'] = $old_info['size'];
355
-	if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')))
356
-		$column_info['unsigned'] = '';
359
+	if (!isset($column_info['name'])) {
360
+			$column_info['name'] = $old_column;
361
+	}
362
+	if (!isset($column_info['default'])) {
363
+			$column_info['default'] = $old_info['default'];
364
+	}
365
+	if (!isset($column_info['null'])) {
366
+			$column_info['null'] = $old_info['null'];
367
+	}
368
+	if (!isset($column_info['auto'])) {
369
+			$column_info['auto'] = $old_info['auto'];
370
+	}
371
+	if (!isset($column_info['type'])) {
372
+			$column_info['type'] = $old_info['type'];
373
+	}
374
+	if (!isset($column_info['size']) || !is_numeric($column_info['size'])) {
375
+			$column_info['size'] = $old_info['size'];
376
+	}
377
+	if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) {
378
+			$column_info['unsigned'] = '';
379
+	}
357 380
 
358 381
 	list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']);
359 382
 
360 383
 	// Allow for unsigned integers (mysql only)
361 384
 	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : '';
362 385
 
363
-	if ($size !== null)
364
-		$type = $type . '(' . $size . ')';
386
+	if ($size !== null) {
387
+			$type = $type . '(' . $size . ')';
388
+	}
365 389
 
366 390
 	$smcFunc['db_query']('', '
367 391
 		ALTER TABLE ' . $table_name . '
@@ -391,21 +415,23 @@  discard block
 block discarded – undo
391 415
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
392 416
 
393 417
 	// No columns = no index.
394
-	if (empty($index_info['columns']))
395
-		return false;
418
+	if (empty($index_info['columns'])) {
419
+			return false;
420
+	}
396 421
 	$columns = implode(',', $index_info['columns']);
397 422
 
398 423
 	// No name - make it up!
399 424
 	if (empty($index_info['name']))
400 425
 	{
401 426
 		// No need for primary.
402
-		if (isset($index_info['type']) && $index_info['type'] == 'primary')
403
-			$index_info['name'] = '';
404
-		else
405
-			$index_info['name'] = implode('_', $index_info['columns']);
427
+		if (isset($index_info['type']) && $index_info['type'] == 'primary') {
428
+					$index_info['name'] = '';
429
+		} else {
430
+					$index_info['name'] = implode('_', $index_info['columns']);
431
+		}
432
+	} else {
433
+			$index_info['name'] = $index_info['name'];
406 434
 	}
407
-	else
408
-		$index_info['name'] = $index_info['name'];
409 435
 
410 436
 	// Log that we are going to want to remove this!
411 437
 	$db_package_log[] = array('remove_index', $table_name, $index_info['name']);
@@ -418,10 +444,11 @@  discard block
 block discarded – undo
418 444
 		if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary'))
419 445
 		{
420 446
 			// If we want to overwrite simply remove the current one then continue.
421
-			if ($if_exists != 'update' || $index['type'] == 'primary')
422
-				return false;
423
-			else
424
-				$smcFunc['db_remove_index']($table_name, $index_info['name']);
447
+			if ($if_exists != 'update' || $index['type'] == 'primary') {
448
+							return false;
449
+			} else {
450
+							$smcFunc['db_remove_index']($table_name, $index_info['name']);
451
+			}
425 452
 		}
426 453
 	}
427 454
 
@@ -435,8 +462,7 @@  discard block
 block discarded – undo
435 462
 				'security_override' => true,
436 463
 			)
437 464
 		);
438
-	}
439
-	else
465
+	} else
440 466
 	{
441 467
 		$smcFunc['db_query']('', '
442 468
 			ALTER TABLE ' . $table_name . '
@@ -520,8 +546,7 @@  discard block
 block discarded – undo
520 546
 		$types = array(
521 547
 			'inet' => 'varbinary',
522 548
 		);
523
-	}
524
-	else
549
+	} else
525 550
 	{
526 551
 		$types = array(
527 552
 			'varbinary' => 'inet',
@@ -535,16 +560,15 @@  discard block
 block discarded – undo
535 560
 		{
536 561
 			$type_size = 16;
537 562
 			$type_name = 'varbinary';
538
-		}
539
-		elseif ($type_name == 'varbinary' && $reverse && $type_size == 16)
563
+		} elseif ($type_name == 'varbinary' && $reverse && $type_size == 16)
540 564
 		{
541 565
 			$type_name = 'inet';
542 566
 			$type_size = null;
567
+		} elseif ($type_name == 'varbinary') {
568
+					$type_name = 'varbinary';
569
+		} else {
570
+					$type_name = $types[$type_name];
543 571
 		}
544
-		elseif ($type_name == 'varbinary')
545
-			$type_name = 'varbinary';
546
-		else
547
-			$type_name = $types[$type_name];
548 572
 	}
549 573
 
550 574
 	return array($type_name, $type_size);
@@ -612,8 +636,7 @@  discard block
 block discarded – undo
612 636
 		if (!$detail)
613 637
 		{
614 638
 			$columns[] = $row['Field'];
615
-		}
616
-		else
639
+		} else
617 640
 		{
618 641
 			// Is there an auto_increment?
619 642
 			$auto = strpos($row['Extra'], 'auto_increment') !== false ? true : false;
@@ -623,10 +646,10 @@  discard block
 block discarded – undo
623 646
 			{
624 647
 				$type = $matches[1];
625 648
 				$size = $matches[2];
626
-				if (!empty($matches[3]) && $matches[3] == 'unsigned')
627
-					$unsigned = true;
628
-			}
629
-			else
649
+				if (!empty($matches[3]) && $matches[3] == 'unsigned') {
650
+									$unsigned = true;
651
+				}
652
+			} else
630 653
 			{
631 654
 				$type = $row['Type'];
632 655
 				$size = null;
@@ -677,19 +700,20 @@  discard block
 block discarded – undo
677 700
 	$indexes = array();
678 701
 	while ($row = $smcFunc['db_fetch_assoc']($result))
679 702
 	{
680
-		if (!$detail)
681
-			$indexes[] = $row['Key_name'];
682
-		else
703
+		if (!$detail) {
704
+					$indexes[] = $row['Key_name'];
705
+		} else
683 706
 		{
684 707
 			// What is the type?
685
-			if ($row['Key_name'] == 'PRIMARY')
686
-				$type = 'primary';
687
-			elseif (empty($row['Non_unique']))
688
-				$type = 'unique';
689
-			elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT')
690
-				$type = 'fulltext';
691
-			else
692
-				$type = 'index';
708
+			if ($row['Key_name'] == 'PRIMARY') {
709
+							$type = 'primary';
710
+			} elseif (empty($row['Non_unique'])) {
711
+							$type = 'unique';
712
+			} elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') {
713
+							$type = 'fulltext';
714
+			} else {
715
+							$type = 'index';
716
+			}
693 717
 
694 718
 			// This is the first column we've seen?
695 719
 			if (empty($indexes[$row['Key_name']]))
@@ -702,10 +726,11 @@  discard block
 block discarded – undo
702 726
 			}
703 727
 
704 728
 			// Is it a partial index?
705
-			if (!empty($row['Sub_part']))
706
-				$indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')';
707
-			else
708
-				$indexes[$row['Key_name']]['columns'][] = $row['Column_name'];
729
+			if (!empty($row['Sub_part'])) {
730
+							$indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')';
731
+			} else {
732
+							$indexes[$row['Key_name']]['columns'][] = $row['Column_name'];
733
+			}
709 734
 		}
710 735
 	}
711 736
 	$smcFunc['db_free_result']($result);
@@ -727,11 +752,11 @@  discard block
 block discarded – undo
727 752
 	if (!empty($column['auto']))
728 753
 	{
729 754
 		$default = 'auto_increment';
755
+	} elseif (isset($column['default']) && $column['default'] !== null) {
756
+			$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
757
+	} else {
758
+			$default = '';
730 759
 	}
731
-	elseif (isset($column['default']) && $column['default'] !== null)
732
-		$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
733
-	else
734
-		$default = '';
735 760
 
736 761
 	// Sort out the size... and stuff...
737 762
 	$column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null;
@@ -740,8 +765,9 @@  discard block
 block discarded – undo
740 765
 	// Allow unsigned integers (mysql only)
741 766
 	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column['unsigned']) ? 'unsigned ' : '';
742 767
 
743
-	if ($size !== null)
744
-		$type = $type . '(' . $size . ')';
768
+	if ($size !== null) {
769
+			$type = $type . '(' . $size . ')';
770
+	}
745 771
 
746 772
 	// Now just put it together!
747 773
 	return '`' .$column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default;
Please login to merge, or discard this patch.
Sources/ShowAttachments.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
 	}
72 72
 
73 73
 	// Use cache when possible.
74
-	if (($cache = cache_get_data('attachment_lookup_id-'. $attachId)) != null)
74
+	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null)
75 75
 		list($file, $thumbFile) = $cache;
76 76
 
77 77
 	// Get the info from the DB.
78
-	if(empty($file) || empty($thumbFile) && !empty($file['id_thumb']))
78
+	if (empty($file) || empty($thumbFile) && !empty($file['id_thumb']))
79 79
 	{
80 80
 		// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
81 81
 		$attachRequest = null;
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
 		$file['filePath'] = getAttachmentFilename($file['filename'], $attachId, $file['id_folder'], false, $file['file_hash']);
145 145
 		// ensure variant attachment compatibility
146 146
 		$filePath = pathinfo($file['filePath']);
147
-		$file['filePath'] = !file_exists($file['filePath']) ? substr($file['filePath'], 0, -(strlen($filePath['extension'])+1)) : $file['filePath'];
148
-		$file['etag'] = '"'. md5_file($file['filePath']) .'"';
147
+		$file['filePath'] = !file_exists($file['filePath']) ? substr($file['filePath'], 0, -(strlen($filePath['extension']) + 1)) : $file['filePath'];
148
+		$file['etag'] = '"' . md5_file($file['filePath']) . '"';
149 149
 
150 150
 		// now get the thumbfile!
151 151
 		$thumbFile = array();
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
 
172 172
 				// set filePath and ETag time
173 173
 				$thumbFile['filePath'] = getAttachmentFilename($thumbFile['filename'], $attachId, $thumbFile['id_folder'], false, $thumbFile['file_hash']);
174
-				$thumbFile['etag'] = '"'. md5_file($thumbFile['filePath']) .'"';
174
+				$thumbFile['etag'] = '"' . md5_file($thumbFile['filePath']) . '"';
175 175
 			}
176 176
 		}
177 177
 
178 178
 		// Cache it.
179
-		if(!empty($file) || !empty($thumbFile))
180
-			cache_put_data('attachment_lookup_id-'. $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
179
+		if (!empty($file) || !empty($thumbFile))
180
+			cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
181 181
 	}
182 182
 
183 183
 	// Update the download counter (unless it's a thumbnail).
@@ -289,17 +289,17 @@  discard block
 block discarded – undo
289 289
 	if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file['fileext'], array('txt', 'css', 'htm', 'html', 'php', 'xml')))
290 290
 	{
291 291
 		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false)
292
-			$callback = function ($buffer)
292
+			$callback = function($buffer)
293 293
 			{
294 294
 				return preg_replace('~[\r]?\n~', "\r\n", $buffer);
295 295
 			};
296 296
 		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false)
297
-			$callback = function ($buffer)
297
+			$callback = function($buffer)
298 298
 			{
299 299
 				return preg_replace('~[\r]?\n~', "\r", $buffer);
300 300
 			};
301 301
 		else
302
-			$callback = function ($buffer)
302
+			$callback = function($buffer)
303 303
 			{
304 304
 				return preg_replace('~[\r]?\n~', "\n", $buffer);
305 305
 			};
Please login to merge, or discard this patch.
Sources/ManageMembergroups.php 1 patch
Braces   +131 added lines, -90 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 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
 /**
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 	$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_membergroups') ? 'index' : 'settings');
45 46
 
46 47
 	// Is it elsewhere?
47
-	if (isset($subActions[$_REQUEST['sa']][2]))
48
-		require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]);
48
+	if (isset($subActions[$_REQUEST['sa']][2])) {
49
+			require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]);
50
+	}
49 51
 
50 52
 	// Do the permission check, you might not be allowed her.
51 53
 	isAllowedTo($subActions[$_REQUEST['sa']][1]);
@@ -104,19 +106,20 @@  discard block
 block discarded – undo
104 106
 					'function' => function ($rowData) use ($scripturl)
105 107
 					{
106 108
 						// Since the moderator group has no explicit members, no link is needed.
107
-						if ($rowData['id_group'] == 3)
108
-							$group_name = $rowData['group_name'];
109
-						else
109
+						if ($rowData['id_group'] == 3) {
110
+													$group_name = $rowData['group_name'];
111
+						} else
110 112
 						{
111 113
 							$color_style = empty($rowData['online_color']) ? '' : sprintf(' style="color: %1$s;"', $rowData['online_color']);
112 114
 							$group_name = sprintf('<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']);
113 115
 						}
114 116
 
115 117
 						// Add a help option for moderator and administrator.
116
-						if ($rowData['id_group'] == 1)
117
-							$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
118
-						elseif ($rowData['id_group'] == 3)
119
-							$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
118
+						if ($rowData['id_group'] == 1) {
119
+													$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
120
+						} elseif ($rowData['id_group'] == 3) {
121
+													$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
122
+						}
120 123
 
121 124
 						return $group_name;
122 125
 					},
@@ -330,12 +333,14 @@  discard block
 block discarded – undo
330 333
 		call_integration_hook('integrate_add_membergroup', array($id_group, $postCountBasedGroup));
331 334
 
332 335
 		// Update the post groups now, if this is a post group!
333
-		if (isset($_POST['min_posts']))
334
-			updateStats('postgroups');
336
+		if (isset($_POST['min_posts'])) {
337
+					updateStats('postgroups');
338
+		}
335 339
 
336 340
 		// You cannot set permissions for post groups if they are disabled.
337
-		if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups']))
338
-			$_POST['perm_type'] = '';
341
+		if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) {
342
+					$_POST['perm_type'] = '';
343
+		}
339 344
 
340 345
 		if ($_POST['perm_type'] == 'predefined')
341 346
 		{
@@ -365,8 +370,9 @@  discard block
 block discarded – undo
365 370
 				$smcFunc['db_free_result']($request);
366 371
 
367 372
 				// Protected groups are... well, protected!
368
-				if ($copy_type == 1)
369
-					fatal_lang_error('membergroup_does_not_exist');
373
+				if ($copy_type == 1) {
374
+									fatal_lang_error('membergroup_does_not_exist');
375
+				}
370 376
 			}
371 377
 
372 378
 			// Don't allow copying of a real priviledged person!
@@ -384,18 +390,20 @@  discard block
 block discarded – undo
384 390
 			$inserts = array();
385 391
 			while ($row = $smcFunc['db_fetch_assoc']($request))
386 392
 			{
387
-				if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions']))
388
-					$inserts[] = array($id_group, $row['permission'], $row['add_deny']);
393
+				if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions'])) {
394
+									$inserts[] = array($id_group, $row['permission'], $row['add_deny']);
395
+				}
389 396
 			}
390 397
 			$smcFunc['db_free_result']($request);
391 398
 
392
-			if (!empty($inserts))
393
-				$smcFunc['db_insert']('insert',
399
+			if (!empty($inserts)) {
400
+							$smcFunc['db_insert']('insert',
394 401
 					'{db_prefix}permissions',
395 402
 					array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
396 403
 					$inserts,
397 404
 					array('id_group', 'permission')
398 405
 				);
406
+			}
399 407
 
400 408
 			$request = $smcFunc['db_query']('', '
401 409
 				SELECT id_profile, permission, add_deny
@@ -406,17 +414,19 @@  discard block
 block discarded – undo
406 414
 				)
407 415
 			);
408 416
 			$inserts = array();
409
-			while ($row = $smcFunc['db_fetch_assoc']($request))
410
-				$inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']);
417
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
418
+							$inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']);
419
+			}
411 420
 			$smcFunc['db_free_result']($request);
412 421
 
413
-			if (!empty($inserts))
414
-				$smcFunc['db_insert']('insert',
422
+			if (!empty($inserts)) {
423
+							$smcFunc['db_insert']('insert',
415 424
 					'{db_prefix}board_permissions',
416 425
 					array('id_group' => 'int', 'id_profile' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
417 426
 					$inserts,
418 427
 					array('id_group', 'id_profile', 'permission')
419 428
 				);
429
+			}
420 430
 
421 431
 			// Also get some membergroup information if we're copying and not copying from guests...
422 432
 			if ($copy_id > 0 && $_POST['perm_type'] == 'copy')
@@ -469,14 +479,15 @@  discard block
 block discarded – undo
469 479
 		$changed_boards['allow'] = array();
470 480
 		$changed_boards['deny'] = array();
471 481
 		$changed_boards['ignore'] = array();
472
-		foreach ($accesses as $group_id => $action)
473
-			$changed_boards[$action][] = (int) $group_id;
482
+		foreach ($accesses as $group_id => $action) {
483
+					$changed_boards[$action][] = (int) $group_id;
484
+		}
474 485
 
475 486
 		foreach (array('allow', 'deny') as $board_action)
476 487
 		{
477 488
 			// Only do this if they have special access requirements.
478
-			if (!empty($changed_boards[$board_action]))
479
-				$smcFunc['db_query']('', '
489
+			if (!empty($changed_boards[$board_action])) {
490
+							$smcFunc['db_query']('', '
480 491
 					UPDATE {db_prefix}boards
481 492
 					SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END
482 493
 					WHERE id_board IN ({array_int:board_list})',
@@ -488,11 +499,13 @@  discard block
 block discarded – undo
488 499
 						'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
489 500
 					)
490 501
 				);
502
+			}
491 503
 		}
492 504
 
493 505
 		// If this is joinable then set it to show group membership in people's profiles.
494
-		if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1)
495
-			updateSettings(array('show_group_membership' => 1));
506
+		if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) {
507
+					updateSettings(array('show_group_membership' => 1));
508
+		}
496 509
 
497 510
 		// Rebuild the group cache.
498 511
 		updateSettings(array(
@@ -513,8 +526,9 @@  discard block
 block discarded – undo
513 526
 	$context['undefined_group'] = !isset($_REQUEST['postgroup']) && !isset($_REQUEST['generalgroup']);
514 527
 	$context['allow_protected'] = allowedTo('admin_forum');
515 528
 
516
-	if (!empty($modSettings['deny_boards_access']))
517
-		loadLanguage('ManagePermissions');
529
+	if (!empty($modSettings['deny_boards_access'])) {
530
+			loadLanguage('ManagePermissions');
531
+	}
518 532
 
519 533
 	$result = $smcFunc['db_query']('', '
520 534
 		SELECT id_group, group_name
@@ -531,11 +545,12 @@  discard block
 block discarded – undo
531 545
 		)
532 546
 	);
533 547
 	$context['groups'] = array();
534
-	while ($row = $smcFunc['db_fetch_assoc']($result))
535
-		$context['groups'][] = array(
548
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
549
+			$context['groups'][] = array(
536 550
 			'id' => $row['id_group'],
537 551
 			'name' => $row['group_name']
538 552
 		);
553
+	}
539 554
 	$smcFunc['db_free_result']($result);
540 555
 
541 556
 	$request = $smcFunc['db_query']('', '
@@ -552,12 +567,13 @@  discard block
 block discarded – undo
552 567
 	while ($row = $smcFunc['db_fetch_assoc']($request))
553 568
 	{
554 569
 		// This category hasn't been set up yet..
555
-		if (!isset($context['categories'][$row['id_cat']]))
556
-			$context['categories'][$row['id_cat']] = array(
570
+		if (!isset($context['categories'][$row['id_cat']])) {
571
+					$context['categories'][$row['id_cat']] = array(
557 572
 				'id' => $row['id_cat'],
558 573
 				'name' => $row['cat_name'],
559 574
 				'boards' => array()
560 575
 			);
576
+		}
561 577
 
562 578
 		// Set this board up, and let the template know when it's a child.  (indent them..)
563 579
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -605,8 +621,9 @@  discard block
 block discarded – undo
605 621
 	require_once($sourcedir . '/Subs-Membergroups.php');
606 622
 	$result = deleteMembergroups((int) $_REQUEST['group']);
607 623
 	// Need to throw a warning if it went wrong, but this is the only one we have a message for...
608
-	if ($result === 'group_cannot_delete_sub')
609
-		fatal_lang_error('membergroups_cannot_delete_paid', false);
624
+	if ($result === 'group_cannot_delete_sub') {
625
+			fatal_lang_error('membergroups_cannot_delete_paid', false);
626
+	}
610 627
 
611 628
 	// Go back to the membergroup index.
612 629
 	redirectexit('action=admin;area=membergroups;');
@@ -628,8 +645,9 @@  discard block
 block discarded – undo
628 645
 
629 646
 	$_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0;
630 647
 
631
-	if (!empty($modSettings['deny_boards_access']))
632
-		loadLanguage('ManagePermissions');
648
+	if (!empty($modSettings['deny_boards_access'])) {
649
+			loadLanguage('ManagePermissions');
650
+	}
633 651
 
634 652
 	// Make sure this group is editable.
635 653
 	if (!empty($_REQUEST['group']))
@@ -651,8 +669,9 @@  discard block
 block discarded – undo
651 669
 	}
652 670
 
653 671
 	// Now, do we have a valid id?
654
-	if (empty($_REQUEST['group']))
655
-		fatal_lang_error('membergroup_does_not_exist', false);
672
+	if (empty($_REQUEST['group'])) {
673
+			fatal_lang_error('membergroup_does_not_exist', false);
674
+	}
656 675
 
657 676
 	// People who can manage boards are a bit special.
658 677
 	require_once($sourcedir . '/Subs-Members.php');
@@ -683,8 +702,9 @@  discard block
 block discarded – undo
683 702
 		require_once($sourcedir . '/Subs-Membergroups.php');
684 703
 		$result = deleteMembergroups($_REQUEST['group']);
685 704
 		// Need to throw a warning if it went wrong, but this is the only one we have a message for...
686
-		if ($result === 'group_cannot_delete_sub')
687
-			fatal_lang_error('membergroups_cannot_delete_paid', false);
705
+		if ($result === 'group_cannot_delete_sub') {
706
+					fatal_lang_error('membergroups_cannot_delete_paid', false);
707
+		}
688 708
 
689 709
 		redirectexit('action=admin;area=membergroups;');
690 710
 	}
@@ -761,16 +781,18 @@  discard block
 block discarded – undo
761 781
 				$request = $smcFunc['db_query']('', '
762 782
 					SELECT id_board
763 783
 					FROM {db_prefix}boards');
764
-				while ($row = $smcFunc['db_fetch_assoc']($request))
765
-					$accesses[(int) $row['id_board']] = 'allow';
784
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
785
+									$accesses[(int) $row['id_board']] = 'allow';
786
+				}
766 787
 				$smcFunc['db_free_result']($request);
767 788
 			}
768 789
 
769 790
 			$changed_boards['allow'] = array();
770 791
 			$changed_boards['deny'] = array();
771 792
 			$changed_boards['ignore'] = array();
772
-			foreach ($accesses as $group_id => $action)
773
-				$changed_boards[$action][] = (int) $group_id;
793
+			foreach ($accesses as $group_id => $action) {
794
+							$changed_boards[$action][] = (int) $group_id;
795
+			}
774 796
 
775 797
 			foreach (array('allow', 'deny') as $board_action)
776 798
 			{
@@ -786,8 +808,8 @@  discard block
 block discarded – undo
786 808
 						'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
787 809
 					)
788 810
 				);
789
-				while ($row = $smcFunc['db_fetch_assoc']($request))
790
-					$smcFunc['db_query']('', '
811
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
812
+									$smcFunc['db_query']('', '
791 813
 						UPDATE {db_prefix}boards
792 814
 						SET {raw:column} = {string:member_group_access}
793 815
 						WHERE id_board = {int:current_board}',
@@ -797,11 +819,12 @@  discard block
 block discarded – undo
797 819
 							'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
798 820
 						)
799 821
 					);
822
+				}
800 823
 				$smcFunc['db_free_result']($request);
801 824
 
802 825
 				// Add the membergroup to all boards that hadn't been set yet.
803
-				if (!empty($changed_boards[$board_action]))
804
-					$smcFunc['db_query']('', '
826
+				if (!empty($changed_boards[$board_action])) {
827
+									$smcFunc['db_query']('', '
805 828
 						UPDATE {db_prefix}boards
806 829
 						SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END
807 830
 						WHERE id_board IN ({array_int:board_list})
@@ -815,6 +838,7 @@  discard block
 block discarded – undo
815 838
 							'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
816 839
 						)
817 840
 					);
841
+				}
818 842
 			}
819 843
 		}
820 844
 
@@ -840,12 +864,14 @@  discard block
 block discarded – undo
840 864
 				)
841 865
 			);
842 866
 			$updates = array();
843
-			while ($row = $smcFunc['db_fetch_assoc']($request))
844
-				$updates[$row['additional_groups']][] = $row['id_member'];
867
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
868
+							$updates[$row['additional_groups']][] = $row['id_member'];
869
+			}
845 870
 			$smcFunc['db_free_result']($request);
846 871
 
847
-			foreach ($updates as $additional_groups => $memberArray)
848
-				updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
872
+			foreach ($updates as $additional_groups => $memberArray) {
873
+							updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
874
+			}
849 875
 
850 876
 			// Sorry, but post groups can't moderate boards
851 877
 			$request = $smcFunc['db_query']('', '
@@ -855,8 +881,7 @@  discard block
 block discarded – undo
855 881
 					'current_group' => (int) $_REQUEST['group'],
856 882
 				)
857 883
 			);
858
-		}
859
-		elseif ($_REQUEST['group'] != 3)
884
+		} elseif ($_REQUEST['group'] != 3)
860 885
 		{
861 886
 			// Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional).
862 887
 			if ($_POST['group_hidden'] == 2)
@@ -871,8 +896,9 @@  discard block
 block discarded – undo
871 896
 					)
872 897
 				);
873 898
 				$updates = array();
874
-				while ($row = $smcFunc['db_fetch_assoc']($request))
875
-					$updates[$row['additional_groups']][] = $row['id_member'];
899
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
900
+									$updates[$row['additional_groups']][] = $row['id_member'];
901
+				}
876 902
 				$smcFunc['db_free_result']($request);
877 903
 
878 904
 				foreach ($updates as $additional_groups => $memberArray)
@@ -914,8 +940,9 @@  discard block
 block discarded – undo
914 940
 			$smcFunc['db_free_result']($request);
915 941
 
916 942
 			// Do we need to update the setting?
917
-			if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable))
918
-				updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0));
943
+			if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) {
944
+							updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0));
945
+			}
919 946
 		}
920 947
 
921 948
 		// Do we need to set inherited permissions?
@@ -948,8 +975,9 @@  discard block
 block discarded – undo
948 975
 				{
949 976
 					$moderators[$k] = trim($moderators[$k]);
950 977
 
951
-					if (strlen($moderators[$k]) == 0)
952
-						unset($moderators[$k]);
978
+					if (strlen($moderators[$k]) == 0) {
979
+											unset($moderators[$k]);
980
+					}
953 981
 				}
954 982
 
955 983
 				// Find all the id_member's for the member_name's in the list.
@@ -965,8 +993,9 @@  discard block
 block discarded – undo
965 993
 							'count' => count($moderators),
966 994
 						)
967 995
 					);
968
-					while ($row = $smcFunc['db_fetch_assoc']($request))
969
-						$group_moderators[] = $row['id_member'];
996
+					while ($row = $smcFunc['db_fetch_assoc']($request)) {
997
+											$group_moderators[] = $row['id_member'];
998
+					}
970 999
 					$smcFunc['db_free_result']($request);
971 1000
 				}
972 1001
 			}
@@ -974,8 +1003,9 @@  discard block
 block discarded – undo
974 1003
 			if (!empty($_POST['moderator_list']))
975 1004
 			{
976 1005
 				$moderators = array();
977
-				foreach ($_POST['moderator_list'] as $moderator)
978
-					$moderators[] = (int) $moderator;
1006
+				foreach ($_POST['moderator_list'] as $moderator) {
1007
+									$moderators[] = (int) $moderator;
1008
+				}
979 1009
 
980 1010
 				if (!empty($moderators))
981 1011
 				{
@@ -989,8 +1019,9 @@  discard block
 block discarded – undo
989 1019
 							'num_moderators' => count($moderators),
990 1020
 						)
991 1021
 					);
992
-					while ($row = $smcFunc['db_fetch_assoc']($request))
993
-						$group_moderators[] = $row['id_member'];
1022
+					while ($row = $smcFunc['db_fetch_assoc']($request)) {
1023
+											$group_moderators[] = $row['id_member'];
1024
+					}
994 1025
 					$smcFunc['db_free_result']($request);
995 1026
 				}
996 1027
 			}
@@ -1002,8 +1033,9 @@  discard block
 block discarded – undo
1002 1033
 			if (!empty($group_moderators))
1003 1034
 			{
1004 1035
 				$mod_insert = array();
1005
-				foreach ($group_moderators as $moderator)
1006
-					$mod_insert[] = array($_REQUEST['group'], $moderator);
1036
+				foreach ($group_moderators as $moderator) {
1037
+									$mod_insert[] = array($_REQUEST['group'], $moderator);
1038
+				}
1007 1039
 
1008 1040
 				$smcFunc['db_insert']('insert',
1009 1041
 					'{db_prefix}group_moderators',
@@ -1037,8 +1069,9 @@  discard block
 block discarded – undo
1037 1069
 			'current_group' => (int) $_REQUEST['group'],
1038 1070
 		)
1039 1071
 	);
1040
-	if ($smcFunc['db_num_rows']($request) == 0)
1041
-		fatal_lang_error('membergroup_does_not_exist', false);
1072
+	if ($smcFunc['db_num_rows']($request) == 0) {
1073
+			fatal_lang_error('membergroup_does_not_exist', false);
1074
+	}
1042 1075
 	$row = $smcFunc['db_fetch_assoc']($request);
1043 1076
 	$smcFunc['db_free_result']($request);
1044 1077
 
@@ -1075,14 +1108,16 @@  discard block
 block discarded – undo
1075 1108
 		)
1076 1109
 	);
1077 1110
 	$context['group']['moderators'] = array();
1078
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1079
-		$context['group']['moderators'][$row['id_member']] = $row['real_name'];
1111
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1112
+			$context['group']['moderators'][$row['id_member']] = $row['real_name'];
1113
+	}
1080 1114
 	$smcFunc['db_free_result']($request);
1081 1115
 
1082 1116
 	$context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '&quot;' . implode('&quot;, &quot;', $context['group']['moderators']) . '&quot;';
1083 1117
 
1084
-	if (!empty($context['group']['moderators']))
1085
-		list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1);
1118
+	if (!empty($context['group']['moderators'])) {
1119
+			list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1);
1120
+	}
1086 1121
 
1087 1122
 	// Get a list of boards this membergroup is allowed to see.
1088 1123
 	$context['boards'] = array();
@@ -1102,12 +1137,13 @@  discard block
 block discarded – undo
1102 1137
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1103 1138
 		{
1104 1139
 			// This category hasn't been set up yet..
1105
-			if (!isset($context['categories'][$row['id_cat']]))
1106
-				$context['categories'][$row['id_cat']] = array(
1140
+			if (!isset($context['categories'][$row['id_cat']])) {
1141
+							$context['categories'][$row['id_cat']] = array(
1107 1142
 					'id' => $row['id_cat'],
1108 1143
 					'name' => $row['cat_name'],
1109 1144
 					'boards' => array()
1110 1145
 				);
1146
+			}
1111 1147
 
1112 1148
 			// Set this board up, and let the template know when it's a child.  (indent them..)
1113 1149
 			$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -1135,8 +1171,9 @@  discard block
 block discarded – undo
1135 1171
 		}
1136 1172
 
1137 1173
 		$max_boards = ceil(count($temp_boards) / 2);
1138
-		if ($max_boards == 1)
1139
-			$max_boards = 2;
1174
+		if ($max_boards == 1) {
1175
+					$max_boards = 2;
1176
+		}
1140 1177
 	}
1141 1178
 
1142 1179
 	// Get a list of all the image formats we can select.
@@ -1159,19 +1196,22 @@  discard block
 block discarded – undo
1159 1196
 				$image_info = getimagesize($settings['default_theme_dir'] . '/images/membericons/' . $value);
1160 1197
 
1161 1198
 				// If this is bigger than 128 in width or 32 in height, skip this one.
1162
-				if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32)
1163
-					continue;
1199
+				if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32) {
1200
+									continue;
1201
+				}
1164 1202
 
1165 1203
 				// Else it's valid. Add it in.
1166
-				else
1167
-					$context['possible_icons'][] = $value;
1204
+				else {
1205
+									$context['possible_icons'][] = $value;
1206
+				}
1168 1207
 			}
1169 1208
 		}
1170 1209
 	}
1171 1210
 
1172 1211
 	// Insert our JS, if we have possible icons.
1173
-	if (!empty($context['possible_icons']))
1174
-		loadJavaScriptFile('icondropdown.js', array('validate' => true), 'smf_icondropdown');
1212
+	if (!empty($context['possible_icons'])) {
1213
+			loadJavaScriptFile('icondropdown.js', array('validate' => true), 'smf_icondropdown');
1214
+	}
1175 1215
 
1176 1216
 		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
1177 1217
 
@@ -1193,8 +1233,9 @@  discard block
 block discarded – undo
1193 1233
 		)
1194 1234
 	);
1195 1235
 	$context['inheritable_groups'] = array();
1196
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1197
-		$context['inheritable_groups'][$row['id_group']] = $row['group_name'];
1236
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1237
+			$context['inheritable_groups'][$row['id_group']] = $row['group_name'];
1238
+	}
1198 1239
 	$smcFunc['db_free_result']($request);
1199 1240
 
1200 1241
 	call_integration_hook('integrate_view_membergroup');
Please login to merge, or discard this patch.
Sources/Attachments.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 		// Just send a generic message.
77 77
 		else
78 78
 			$this->setResponse(array(
79
-				'text' => $this->_sa == 'add' ? 'attach_error_title' :   'attached_file_deleted_error',
79
+				'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error',
80 80
 				'type' => 'error',
81 81
 				'data' => false,
82 82
 			));
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 			// Gotta urlencode the filename.
405 405
 			if ($this->_attachResults)
406 406
 				foreach ($this->_attachResults as $k => $v)
407
-					$this->_attachResults[$k]['name'] =  urlencode($this->_attachResults[$k]['name']);
407
+					$this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']);
408 408
 
409 409
 			$this->_response = array(
410 410
 				'files' => $this->_attachResults ? $this->_attachResults : false,
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 			ob_start();
432 432
 
433 433
 		// Set the header.
434
-		header('Content-Type: application/json; charset='. $context['character_set'] .'');
434
+		header('Content-Type: application/json; charset=' . $context['character_set'] . '');
435 435
 
436 436
 		echo json_encode($this->_response ? $this->_response : array());
437 437
 
Please login to merge, or discard this patch.
Braces   +102 added lines, -76 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
 class Attachments
20 21
 {
@@ -70,16 +71,18 @@  discard block
 block discarded – undo
70 71
 
71 72
 		$this->_sa = !empty($_REQUEST['sa']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_REQUEST['sa'])) : false;
72 73
 
73
-		if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions))
74
-			$this->{$this->_sa}();
74
+		if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) {
75
+					$this->{$this->_sa}();
76
+		}
75 77
 
76 78
 		// Just send a generic message.
77
-		else
78
-			$this->setResponse(array(
79
+		else {
80
+					$this->setResponse(array(
79 81
 				'text' => $this->_sa == 'add' ? 'attach_error_title' :   'attached_file_deleted_error',
80 82
 				'type' => 'error',
81 83
 				'data' => false,
82 84
 			));
85
+		}
83 86
 
84 87
 		// Back to the future, oh, to the browser!
85 88
 		$this->sendResponse();
@@ -95,12 +98,13 @@  discard block
 block discarded – undo
95 98
 		$attachID = !empty($_REQUEST['attach']) && is_numeric($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : 0;
96 99
 
97 100
 		// Need something to work with.
98
-		if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID])))
99
-			return $this->setResponse(array(
101
+		if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) {
102
+					return $this->setResponse(array(
100 103
 				'text' => 'attached_file_deleted_error',
101 104
 				'type' => 'error',
102 105
 				'data' => false,
103 106
 			));
107
+		}
104 108
 
105 109
 		// Lets pass some params and see what happens :P
106 110
 		$affectedMessage = removeAttachments(array('id_attach' => $attachID), '', true, true);
@@ -121,19 +125,21 @@  discard block
 block discarded – undo
121 125
 		$result = array();
122 126
 
123 127
 		// You gotta be able to post attachments.
124
-		if (!$this->_canPostAttachment)
125
-			return $this->setResponse(array(
128
+		if (!$this->_canPostAttachment) {
129
+					return $this->setResponse(array(
126 130
 				'text' => 'attached_file_cannot',
127 131
 				'type' => 'error',
128 132
 				'data' => false,
129 133
 			));
134
+		}
130 135
 
131 136
 		// Process them at once!
132 137
 		$this->processAttachments();
133 138
 
134 139
 		// The attachments was created and moved the the right folder, time to update the DB.
135
-		if (!empty($_SESSION['temp_attachments']))
136
-			$this->createAtttach();
140
+		if (!empty($_SESSION['temp_attachments'])) {
141
+					$this->createAtttach();
142
+		}
137 143
 
138 144
 		// Set the response.
139 145
 		$this->setResponse();
@@ -146,8 +152,9 @@  discard block
 block discarded – undo
146 152
 	{
147 153
 		global $context, $modSettings, $smcFunc, $user_info, $txt;
148 154
 
149
-		if (!isset($_FILES['attachment']['name']))
150
-			$_FILES['attachment']['tmp_name'] = array();
155
+		if (!isset($_FILES['attachment']['name'])) {
156
+					$_FILES['attachment']['tmp_name'] = array();
157
+		}
151 158
 
152 159
 		// If there are attachments, calculate the total size and how many.
153 160
 		$context['attachments']['total_size'] = 0;
@@ -157,25 +164,30 @@  discard block
 block discarded – undo
157 164
 		if (isset($_REQUEST['msg']))
158 165
 		{
159 166
 			$context['attachments']['quantity'] = count($context['current_attachments']);
160
-			foreach ($context['current_attachments'] as $attachment)
161
-				$context['attachments']['total_size'] += $attachment['size'];
167
+			foreach ($context['current_attachments'] as $attachment) {
168
+							$context['attachments']['total_size'] += $attachment['size'];
169
+			}
162 170
 		}
163 171
 
164 172
 		// A bit of house keeping first.
165
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
166
-			unset($_SESSION['temp_attachments']);
173
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
174
+					unset($_SESSION['temp_attachments']);
175
+		}
167 176
 
168 177
 		// Our infamous SESSION var, we are gonna have soo much fun with it!
169
-		if (!isset($_SESSION['temp_attachments']))
170
-			$_SESSION['temp_attachments'] = array();
178
+		if (!isset($_SESSION['temp_attachments'])) {
179
+					$_SESSION['temp_attachments'] = array();
180
+		}
171 181
 
172 182
 		// Make sure we're uploading to the right place.
173
-		if (!empty($modSettings['automanage_attachments']))
174
-			automanage_attachments_check_directory();
183
+		if (!empty($modSettings['automanage_attachments'])) {
184
+					automanage_attachments_check_directory();
185
+		}
175 186
 
176 187
 		// Is the attachments folder actually there?
177
-		if (!empty($context['dir_creation_error']))
178
-			$this->_generalErrors[] = $context['dir_creation_error'];
188
+		if (!empty($context['dir_creation_error'])) {
189
+					$this->_generalErrors[] = $context['dir_creation_error'];
190
+		}
179 191
 
180 192
 		// The current attach folder ha some issues...
181 193
 		elseif (!is_dir($this->_attchDir))
@@ -200,13 +212,12 @@  discard block
 block discarded – undo
200 212
 			);
201 213
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
202 214
 			$smcFunc['db_free_result']($request);
203
-		}
204
-
205
-		else
206
-			$context['attachments'] = array(
215
+		} else {
216
+					$context['attachments'] = array(
207 217
 				'quantity' => 0,
208 218
 				'total_size' => 0,
209 219
 			);
220
+		}
210 221
 
211 222
 		// Check for other general errors here.
212 223
 
@@ -214,9 +225,10 @@  discard block
 block discarded – undo
214 225
 		if (!empty($this->_generalErrors))
215 226
 		{
216 227
 			// And delete the files 'cos they ain't going nowhere.
217
-			foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
218
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
228
+			foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
229
+							if (file_exists($_FILES['attachment']['tmp_name'][$n]))
219 230
 					unlink($_FILES['attachment']['tmp_name'][$n]);
231
+			}
220 232
 
221 233
 			$_FILES['attachment']['tmp_name'] = array();
222 234
 
@@ -227,26 +239,29 @@  discard block
 block discarded – undo
227 239
 		// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
228 240
 		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
229 241
 		{
230
-			if ($_FILES['attachment']['name'][$n] == '')
231
-				continue;
242
+			if ($_FILES['attachment']['name'][$n] == '') {
243
+							continue;
244
+			}
232 245
 
233 246
 			// First, let's first check for PHP upload errors.
234 247
 			$errors = array();
235 248
 			if (!empty($_FILES['attachment']['error'][$n]))
236 249
 			{
237
-				if ($_FILES['attachment']['error'][$n] == 2)
238
-					$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
239
-
240
-				else
241
-					log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
250
+				if ($_FILES['attachment']['error'][$n] == 2) {
251
+									$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
252
+				} else {
253
+									log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
254
+				}
242 255
 
243 256
 				// Log this one, because...
244
-				if ($_FILES['attachment']['error'][$n] == 6)
245
-					log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
257
+				if ($_FILES['attachment']['error'][$n] == 6) {
258
+									log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
259
+				}
246 260
 
247 261
 				// Weird, no errors were cached, still fill out a generic one.
248
-				if (empty($errors))
249
-					$errors[] = 'attach_php_error';
262
+				if (empty($errors)) {
263
+									$errors[] = 'attach_php_error';
264
+				}
250 265
 			}
251 266
 
252 267
 			// Try to move and rename the file before doing any more checks on it.
@@ -266,16 +281,18 @@  discard block
 block discarded – undo
266 281
 				);
267 282
 
268 283
 				// Move the file to the attachments folder with a temp name for now.
269
-				if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
270
-					smf_chmod($destName, 0644);
284
+				if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
285
+									smf_chmod($destName, 0644);
286
+				}
271 287
 
272 288
 				// This is madness!!
273 289
 				else
274 290
 				{
275 291
 					// File couldn't be moved.
276 292
 					$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
277
-					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
278
-						unlink($_FILES['attachment']['tmp_name'][$n]);
293
+					if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
294
+											unlink($_FILES['attachment']['tmp_name'][$n]);
295
+					}
279 296
 				}
280 297
 			}
281 298
 
@@ -288,13 +305,15 @@  discard block
 block discarded – undo
288 305
 					'errors' => $errors,
289 306
 				);
290 307
 
291
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
292
-					unlink($_FILES['attachment']['tmp_name'][$n]);
308
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
309
+									unlink($_FILES['attachment']['tmp_name'][$n]);
310
+				}
293 311
 			}
294 312
 
295 313
 			// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
296
-			if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
297
-				attachmentChecks($attachID);
314
+			if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
315
+							attachmentChecks($attachID);
316
+			}
298 317
 		}
299 318
 
300 319
 		// Mod authors, finally a hook to hang an alternate attachment upload system upon
@@ -333,23 +352,24 @@  discard block
 block discarded – undo
333 352
 				'errors' => $attachment['errors'],
334 353
 			);
335 354
 
336
-			if (empty($attachment['errors']))
337
-				if (createAttachment($attachmentOptions))
355
+			if (empty($attachment['errors'])) {
356
+							if (createAttachment($attachmentOptions))
338 357
 				{
339 358
 					// Avoid JS getting confused.
340 359
 					$attachmentOptions['attachID'] = $attachmentOptions['id'];
360
+			}
341 361
 					unset($attachmentOptions['id']);
342 362
 
343 363
 					$_SESSION['already_attached'][$attachmentOptions['attachID']] = $attachmentOptions['attachID'];
344 364
 
345
-					if (!empty($attachmentOptions['thumb']))
346
-						$_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb'];
347
-
348
-					if ($this->_msg)
349
-						assignAttachments($_SESSION['already_attached'], $this->_msg);
350
-				}
365
+					if (!empty($attachmentOptions['thumb'])) {
366
+											$_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb'];
367
+					}
351 368
 
352
-			elseif (!empty($attachmentOptions['errors']))
369
+					if ($this->_msg) {
370
+											assignAttachments($_SESSION['already_attached'], $this->_msg);
371
+					}
372
+				} elseif (!empty($attachmentOptions['errors']))
353 373
 			{
354 374
 				// Sort out the errors for display and delete any associated files.
355 375
 				$log_these = array('attachments_no_create', 'attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file');
@@ -361,14 +381,16 @@  discard block
 block discarded – undo
361 381
 					if (!is_array($error))
362 382
 					{
363 383
 						$attachmentOptions['errors'][] = $txt[$error];
364
-						if (in_array($error, $log_these))
365
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
384
+						if (in_array($error, $log_these)) {
385
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
386
+						}
387
+					} else {
388
+											$attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]);
366 389
 					}
367
-					else
368
-						$attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]);
369 390
 				}
370
-				if (file_exists($attachment['tmp_name']))
371
-					unlink($attachment['tmp_name']);
391
+				if (file_exists($attachment['tmp_name'])) {
392
+									unlink($attachment['tmp_name']);
393
+				}
372 394
 			}
373 395
 
374 396
 			// Regardless of errors, pass the results.
@@ -376,8 +398,9 @@  discard block
 block discarded – undo
376 398
 		}
377 399
 
378 400
 		// Temp save this on the db.
379
-		if (!empty($_SESSION['already_attached']))
380
-			$this->_attachSuccess = $_SESSION['already_attached'];
401
+		if (!empty($_SESSION['already_attached'])) {
402
+					$this->_attachSuccess = $_SESSION['already_attached'];
403
+		}
381 404
 
382 405
 		unset($_SESSION['temp_attachments']);
383 406
 	}
@@ -397,14 +420,16 @@  discard block
 block discarded – undo
397 420
 		if ($this->_sa == 'add')
398 421
 		{
399 422
 			// Is there any generic errors? made some sense out of them!
400
-			if ($this->_generalErrors)
401
-				foreach ($this->_generalErrors as $k => $v)
423
+			if ($this->_generalErrors) {
424
+							foreach ($this->_generalErrors as $k => $v)
402 425
 					$this->_generalErrors[$k] = (is_array($v) ? vsprintf($txt[$v[0]], $v[1]) : $txt[$v]);
426
+			}
403 427
 
404 428
 			// Gotta urlencode the filename.
405
-			if ($this->_attachResults)
406
-				foreach ($this->_attachResults as $k => $v)
429
+			if ($this->_attachResults) {
430
+							foreach ($this->_attachResults as $k => $v)
407 431
 					$this->_attachResults[$k]['name'] =  urlencode($this->_attachResults[$k]['name']);
432
+			}
408 433
 
409 434
 			$this->_response = array(
410 435
 				'files' => $this->_attachResults ? $this->_attachResults : false,
@@ -413,9 +438,10 @@  discard block
 block discarded – undo
413 438
 		}
414 439
 
415 440
 		// Rest of us mere mortals gets no special treatment...
416
-		elseif (!empty($data))
417
-			if (!empty($data['text']) && !empty($txt[$data['text']]))
441
+		elseif (!empty($data)) {
442
+					if (!empty($data['text']) && !empty($txt[$data['text']]))
418 443
 				$this->_response['text'] = $txt[$data['text']];
444
+		}
419 445
 	}
420 446
 
421 447
 	protected function sendResponse()
@@ -424,11 +450,11 @@  discard block
 block discarded – undo
424 450
 
425 451
 		ob_end_clean();
426 452
 
427
-		if (!empty($modSettings['CompressedOutput']))
428
-			@ob_start('ob_gzhandler');
429
-
430
-		else
431
-			ob_start();
453
+		if (!empty($modSettings['CompressedOutput'])) {
454
+					@ob_start('ob_gzhandler');
455
+		} else {
456
+					ob_start();
457
+		}
432 458
 
433 459
 		// Set the header.
434 460
 		header('Content-Type: application/json; charset='. $context['character_set'] .'');
Please login to merge, or discard this patch.
Sources/ManageServer.php 1 patch
Braces   +268 added lines, -206 removed lines patch added patch discarded remove patch
@@ -59,8 +59,9 @@  discard block
 block discarded – undo
59 59
  * @version 2.1 Beta 3
60 60
  */
61 61
 
62
-if (!defined('SMF'))
62
+if (!defined('SMF')) {
63 63
 	die('No direct access...');
64
+}
64 65
 
65 66
 /**
66 67
  * This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects
@@ -111,10 +112,11 @@  discard block
 block discarded – undo
111 112
 	$settings_not_writable = !is_writable($boarddir . '/Settings.php');
112 113
 	$settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
113 114
 
114
-	if ($settings_not_writable)
115
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
116
-	elseif ($settings_backup_fail)
117
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
115
+	if ($settings_not_writable) {
116
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
117
+	} elseif ($settings_backup_fail) {
118
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
119
+	}
118 120
 
119 121
 	$context['settings_not_writable'] = $settings_not_writable;
120 122
 
@@ -166,8 +168,9 @@  discard block
 block discarded – undo
166 168
 
167 169
 	call_integration_hook('integrate_general_settings', array(&$config_vars));
168 170
 
169
-	if ($return_config)
170
-		return $config_vars;
171
+	if ($return_config) {
172
+			return $config_vars;
173
+	}
171 174
 
172 175
 	// Setup the template stuff.
173 176
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=general;save';
@@ -232,8 +235,9 @@  discard block
 block discarded – undo
232 235
 
233 236
 	call_integration_hook('integrate_database_settings', array(&$config_vars));
234 237
 
235
-	if ($return_config)
236
-		return $config_vars;
238
+	if ($return_config) {
239
+			return $config_vars;
240
+	}
237 241
 
238 242
 	// Setup the template stuff.
239 243
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save';
@@ -308,13 +312,15 @@  discard block
 block discarded – undo
308 312
 		hideGlobalCookies();
309 313
 	});', true);
310 314
 
311
-	if (empty($user_settings['tfa_secret']))
312
-		addInlineJavaScript('');
315
+	if (empty($user_settings['tfa_secret'])) {
316
+			addInlineJavaScript('');
317
+	}
313 318
 
314 319
 	call_integration_hook('integrate_cookie_settings', array(&$config_vars));
315 320
 
316
-	if ($return_config)
317
-		return $config_vars;
321
+	if ($return_config) {
322
+			return $config_vars;
323
+	}
318 324
 
319 325
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save';
320 326
 	$context['settings_title'] = $txt['cookies_sessions_settings'];
@@ -325,11 +331,13 @@  discard block
 block discarded – undo
325 331
 		call_integration_hook('integrate_save_cookie_settings');
326 332
 
327 333
 		// Local and global do not play nicely together.
328
-		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies']))
329
-			unset ($_POST['globalCookies']);
334
+		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) {
335
+					unset ($_POST['globalCookies']);
336
+		}
330 337
 
331
-		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false)
332
-			fatal_lang_error('invalid_cookie_domain', false);
338
+		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) {
339
+					fatal_lang_error('invalid_cookie_domain', false);
340
+		}
333 341
 
334 342
 		saveSettings($config_vars);
335 343
 
@@ -412,8 +420,9 @@  discard block
 block discarded – undo
412 420
 
413 421
 	call_integration_hook('integrate_general_security_settings', array(&$config_vars));
414 422
 
415
-	if ($return_config)
416
-		return $config_vars;
423
+	if ($return_config) {
424
+			return $config_vars;
425
+	}
417 426
 
418 427
 	// Saving?
419 428
 	if (isset($_GET['save']))
@@ -445,18 +454,24 @@  discard block
 block discarded – undo
445 454
 
446 455
 	// Detect all available optimizers
447 456
 	$detected = array();
448
-	if (function_exists('apc_store'))
449
-		$detected['apc'] = $txt['apc_cache'];
450
-	if (function_exists('apcu_store'))
451
-		$detected['apcu'] = $txt['apcu_cache'];
452
-	if (function_exists('output_cache_put') || function_exists('zend_shm_cache_store'))
453
-		$detected['zend'] = $txt['zend_cache'];
454
-	if (function_exists('memcache_set') || function_exists('memcached_set'))
455
-		$detected['memcached'] = $txt['memcached_cache'];
456
-	if (function_exists('xcache_set'))
457
-		$detected['xcache'] = $txt['xcache_cache'];
458
-	if (function_exists('file_put_contents'))
459
-		$detected['smf'] = $txt['default_cache'];
457
+	if (function_exists('apc_store')) {
458
+			$detected['apc'] = $txt['apc_cache'];
459
+	}
460
+	if (function_exists('apcu_store')) {
461
+			$detected['apcu'] = $txt['apcu_cache'];
462
+	}
463
+	if (function_exists('output_cache_put') || function_exists('zend_shm_cache_store')) {
464
+			$detected['zend'] = $txt['zend_cache'];
465
+	}
466
+	if (function_exists('memcache_set') || function_exists('memcached_set')) {
467
+			$detected['memcached'] = $txt['memcached_cache'];
468
+	}
469
+	if (function_exists('xcache_set')) {
470
+			$detected['xcache'] = $txt['xcache_cache'];
471
+	}
472
+	if (function_exists('file_put_contents')) {
473
+			$detected['smf'] = $txt['default_cache'];
474
+	}
460 475
 
461 476
 	// set our values to show what, if anything, we found
462 477
 	if (empty($detected))
@@ -464,8 +479,7 @@  discard block
 block discarded – undo
464 479
 		$txt['cache_settings_message'] = $txt['detected_no_caching'];
465 480
 		$cache_level = array($txt['cache_off']);
466 481
 		$detected['none'] = $txt['cache_off'];
467
-	}
468
-	else
482
+	} else
469 483
 	{
470 484
 		$txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected));
471 485
 		$cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']);
@@ -490,8 +504,9 @@  discard block
 block discarded – undo
490 504
 
491 505
 	call_integration_hook('integrate_modify_cache_settings', array(&$config_vars));
492 506
 
493
-	if ($return_config)
494
-		return $config_vars;
507
+	if ($return_config) {
508
+			return $config_vars;
509
+	}
495 510
 
496 511
 	// Saving again?
497 512
 	if (isset($_GET['save']))
@@ -519,8 +534,9 @@  discard block
 block discarded – undo
519 534
 	$context['save_disabled'] = $context['settings_not_writable'];
520 535
 
521 536
 	// Decide what message to show.
522
-	if (!$context['save_disabled'])
523
-		$context['settings_message'] = $txt['caching_information'];
537
+	if (!$context['save_disabled']) {
538
+			$context['settings_message'] = $txt['caching_information'];
539
+	}
524 540
 
525 541
 	// Prepare the template.
526 542
 	prepareServerSettingsContext($config_vars);
@@ -543,24 +559,25 @@  discard block
 block discarded – undo
543 559
 	if (stripos(PHP_OS, 'win') === 0)
544 560
 	{
545 561
 		$context['settings_message'] = $txt['loadavg_disabled_windows'];
546
-		if (isset($_GET['save']))
547
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
548
-	}
549
-	elseif (stripos(PHP_OS, 'darwin') === 0)
562
+		if (isset($_GET['save'])) {
563
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
564
+		}
565
+	} elseif (stripos(PHP_OS, 'darwin') === 0)
550 566
 	{
551 567
 		$context['settings_message'] = $txt['loadavg_disabled_osx'];
552
-		if (isset($_GET['save']))
553
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
554
-	}
555
-	else
568
+		if (isset($_GET['save'])) {
569
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
570
+		}
571
+	} else
556 572
 	{
557 573
 		$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
558
-		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0)
559
-			$modSettings['load_average'] = (float) $matches[1];
560
-		elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0)
561
-			$modSettings['load_average'] = (float) $matches[1];
562
-		else
563
-			unset($modSettings['load_average']);
574
+		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) {
575
+					$modSettings['load_average'] = (float) $matches[1];
576
+		} elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) {
577
+					$modSettings['load_average'] = (float) $matches[1];
578
+		} else {
579
+					unset($modSettings['load_average']);
580
+		}
564 581
 
565 582
 		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
566 583
 		{
@@ -596,8 +613,9 @@  discard block
 block discarded – undo
596 613
 
597 614
 	call_integration_hook('integrate_loadavg_settings', array(&$config_vars));
598 615
 
599
-	if ($return_config)
600
-		return $config_vars;
616
+	if ($return_config) {
617
+			return $config_vars;
618
+	}
601 619
 
602 620
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save';
603 621
 	$context['settings_title'] = $txt['load_balancing_settings'];
@@ -608,24 +626,27 @@  discard block
 block discarded – undo
608 626
 		// Stupidity is not allowed.
609 627
 		foreach ($_POST as $key => $value)
610 628
 		{
611
-			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values)))
612
-				continue;
613
-			else
614
-				$_POST[$key] = (float) $value;
615
-
616
-			if ($key == 'loadavg_auto_opt' && $value <= 1)
617
-				$_POST['loadavg_auto_opt'] = 1.0;
618
-			elseif ($key == 'loadavg_forum' && $value < 10)
619
-				$_POST['loadavg_forum'] = 10.0;
620
-			elseif ($value < 2)
621
-				$_POST[$key] = 2.0;
629
+			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) {
630
+							continue;
631
+			} else {
632
+							$_POST[$key] = (float) $value;
633
+			}
634
+
635
+			if ($key == 'loadavg_auto_opt' && $value <= 1) {
636
+							$_POST['loadavg_auto_opt'] = 1.0;
637
+			} elseif ($key == 'loadavg_forum' && $value < 10) {
638
+							$_POST['loadavg_forum'] = 10.0;
639
+			} elseif ($value < 2) {
640
+							$_POST[$key] = 2.0;
641
+			}
622 642
 		}
623 643
 
624 644
 		call_integration_hook('integrate_save_loadavg_settings');
625 645
 
626 646
 		saveDBSettings($config_vars);
627
-		if (!isset($_SESSION['adm-save']))
628
-			$_SESSION['adm-save'] = true;
647
+		if (!isset($_SESSION['adm-save'])) {
648
+					$_SESSION['adm-save'] = true;
649
+		}
629 650
 		redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']);
630 651
 	}
631 652
 
@@ -662,10 +683,11 @@  discard block
 block discarded – undo
662 683
 
663 684
 	if (isset($_SESSION['adm-save']))
664 685
 	{
665
-		if ($_SESSION['adm-save'] === true)
666
-			$context['saved_successful'] = true;
667
-		else
668
-			$context['saved_failed'] = $_SESSION['adm-save'];
686
+		if ($_SESSION['adm-save'] === true) {
687
+					$context['saved_successful'] = true;
688
+		} else {
689
+					$context['saved_failed'] = $_SESSION['adm-save'];
690
+		}
669 691
 
670 692
 		unset($_SESSION['adm-save']);
671 693
 	}
@@ -673,9 +695,9 @@  discard block
 block discarded – undo
673 695
 	$context['config_vars'] = array();
674 696
 	foreach ($config_vars as $identifier => $config_var)
675 697
 	{
676
-		if (!is_array($config_var) || !isset($config_var[1]))
677
-			$context['config_vars'][] = $config_var;
678
-		else
698
+		if (!is_array($config_var) || !isset($config_var[1])) {
699
+					$context['config_vars'][] = $config_var;
700
+		} else
679 701
 		{
680 702
 			$varname = $config_var[0];
681 703
 			global $$varname;
@@ -710,16 +732,19 @@  discard block
 block discarded – undo
710 732
 			if ($config_var[3] == 'int' || $config_var[3] == 'float')
711 733
 			{
712 734
 				// Default to a min of 0 if one isn't set
713
-				if (isset($config_var['min']))
714
-					$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
715
-				else
716
-					$context['config_vars'][$config_var[0]]['min'] = 0;
735
+				if (isset($config_var['min'])) {
736
+									$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
737
+				} else {
738
+									$context['config_vars'][$config_var[0]]['min'] = 0;
739
+				}
717 740
 
718
-				if (isset($config_var['max']))
719
-					$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
741
+				if (isset($config_var['max'])) {
742
+									$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
743
+				}
720 744
 
721
-				if (isset($config_var['step']))
722
-					$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
745
+				if (isset($config_var['step'])) {
746
+									$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
747
+				}
723 748
 			}
724 749
 
725 750
 			// If this is a select box handle any data.
@@ -727,12 +752,13 @@  discard block
 block discarded – undo
727 752
 			{
728 753
 				// If it's associative
729 754
 				$config_values = array_values($config_var[4]);
730
-				if (isset($config_values[0]) && is_array($config_values[0]))
731
-					$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
732
-				else
755
+				if (isset($config_values[0]) && is_array($config_values[0])) {
756
+									$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
757
+				} else
733 758
 				{
734
-					foreach ($config_var[4] as $key => $item)
735
-						$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
759
+					foreach ($config_var[4] as $key => $item) {
760
+											$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
761
+					}
736 762
 				}
737 763
 			}
738 764
 		}
@@ -757,10 +783,11 @@  discard block
 block discarded – undo
757 783
 
758 784
 	if (isset($_SESSION['adm-save']))
759 785
 	{
760
-		if ($_SESSION['adm-save'] === true)
761
-			$context['saved_successful'] = true;
762
-		else
763
-			$context['saved_failed'] = $_SESSION['adm-save'];
786
+		if ($_SESSION['adm-save'] === true) {
787
+					$context['saved_successful'] = true;
788
+		} else {
789
+					$context['saved_failed'] = $_SESSION['adm-save'];
790
+		}
764 791
 
765 792
 		unset($_SESSION['adm-save']);
766 793
 	}
@@ -772,26 +799,30 @@  discard block
 block discarded – undo
772 799
 	foreach ($config_vars as $config_var)
773 800
 	{
774 801
 		// HR?
775
-		if (!is_array($config_var))
776
-			$context['config_vars'][] = $config_var;
777
-		else
802
+		if (!is_array($config_var)) {
803
+					$context['config_vars'][] = $config_var;
804
+		} else
778 805
 		{
779 806
 			// If it has no name it doesn't have any purpose!
780
-			if (empty($config_var[1]))
781
-				continue;
807
+			if (empty($config_var[1])) {
808
+							continue;
809
+			}
782 810
 
783 811
 			// Special case for inline permissions
784
-			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions'))
785
-				$inlinePermissions[] = $config_var[1];
786
-			elseif ($config_var[0] == 'permissions')
787
-				continue;
812
+			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) {
813
+							$inlinePermissions[] = $config_var[1];
814
+			} elseif ($config_var[0] == 'permissions') {
815
+							continue;
816
+			}
788 817
 
789
-			if ($config_var[0] == 'boards')
790
-				$board_list = true;
818
+			if ($config_var[0] == 'boards') {
819
+							$board_list = true;
820
+			}
791 821
 
792 822
 			// Are we showing the BBC selection box?
793
-			if ($config_var[0] == 'bbc')
794
-				$bbcChoice[] = $config_var[1];
823
+			if ($config_var[0] == 'bbc') {
824
+							$bbcChoice[] = $config_var[1];
825
+			}
795 826
 
796 827
 			// We need to do some parsing of the value before we pass it in.
797 828
 			if (isset($modSettings[$config_var[1]]))
@@ -810,8 +841,7 @@  discard block
 block discarded – undo
810 841
 					default:
811 842
 						$value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]);
812 843
 				}
813
-			}
814
-			else
844
+			} else
815 845
 			{
816 846
 				// Darn, it's empty. What type is expected?
817 847
 				switch ($config_var[0])
@@ -851,16 +881,19 @@  discard block
 block discarded – undo
851 881
 			if ($config_var[0] == 'int' || $config_var[0] == 'float')
852 882
 			{
853 883
 				// Default to a min of 0 if one isn't set
854
-				if (isset($config_var['min']))
855
-					$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
856
-				else
857
-					$context['config_vars'][$config_var[1]]['min'] = 0;
884
+				if (isset($config_var['min'])) {
885
+									$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
886
+				} else {
887
+									$context['config_vars'][$config_var[1]]['min'] = 0;
888
+				}
858 889
 
859
-				if (isset($config_var['max']))
860
-					$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
890
+				if (isset($config_var['max'])) {
891
+									$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
892
+				}
861 893
 
862
-				if (isset($config_var['step']))
863
-					$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
894
+				if (isset($config_var['step'])) {
895
+									$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
896
+				}
864 897
 			}
865 898
 
866 899
 			// If this is a select box handle any data.
@@ -874,12 +907,13 @@  discard block
 block discarded – undo
874 907
 				}
875 908
 
876 909
 				// If it's associative
877
-				if (isset($config_var[2][0]) && is_array($config_var[2][0]))
878
-					$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
879
-				else
910
+				if (isset($config_var[2][0]) && is_array($config_var[2][0])) {
911
+									$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
912
+				} else
880 913
 				{
881
-					foreach ($config_var[2] as $key => $item)
882
-						$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
914
+					foreach ($config_var[2] as $key => $item) {
915
+											$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
916
+					}
883 917
 				}
884 918
 			}
885 919
 
@@ -888,17 +922,19 @@  discard block
 block discarded – undo
888 922
 			{
889 923
 				if (!is_numeric($k))
890 924
 				{
891
-					if (substr($k, 0, 2) == 'on')
892
-						$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
893
-					else
894
-						$context['config_vars'][$config_var[1]][$k] = $v;
925
+					if (substr($k, 0, 2) == 'on') {
926
+											$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
927
+					} else {
928
+											$context['config_vars'][$config_var[1]][$k] = $v;
929
+					}
895 930
 				}
896 931
 
897 932
 				// See if there are any other labels that might fit?
898
-				if (isset($txt['setting_' . $config_var[1]]))
899
-					$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
900
-				elseif (isset($txt['groups_' . $config_var[1]]))
901
-					$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
933
+				if (isset($txt['setting_' . $config_var[1]])) {
934
+									$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
935
+				} elseif (isset($txt['groups_' . $config_var[1]])) {
936
+									$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
937
+				}
902 938
 			}
903 939
 
904 940
 			// Set the subtext in case it's part of the label.
@@ -931,8 +967,9 @@  discard block
 block discarded – undo
931 967
 		// What are the options, eh?
932 968
 		$temp = parse_bbc(false);
933 969
 		$bbcTags = array();
934
-		foreach ($temp as $tag)
935
-			$bbcTags[] = $tag['tag'];
970
+		foreach ($temp as $tag) {
971
+					$bbcTags[] = $tag['tag'];
972
+		}
936 973
 
937 974
 		$bbcTags = array_unique($bbcTags);
938 975
 		$totalTags = count($bbcTags);
@@ -947,8 +984,9 @@  discard block
 block discarded – undo
947 984
 		$col = 0; $i = 0;
948 985
 		foreach ($bbcTags as $tag)
949 986
 		{
950
-			if ($i % $tagsPerColumn == 0 && $i != 0)
951
-				$col++;
987
+			if ($i % $tagsPerColumn == 0 && $i != 0) {
988
+							$col++;
989
+			}
952 990
 
953 991
 			$context['bbc_columns'][$col][] = array(
954 992
 				'tag' => $tag,
@@ -991,18 +1029,21 @@  discard block
 block discarded – undo
991 1029
 	validateToken('admin-ssc');
992 1030
 
993 1031
 	// Fix the darn stupid cookiename! (more may not be allowed, but these for sure!)
994
-	if (isset($_POST['cookiename']))
995
-		$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1032
+	if (isset($_POST['cookiename'])) {
1033
+			$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1034
+	}
996 1035
 
997 1036
 	// Fix the forum's URL if necessary.
998 1037
 	if (isset($_POST['boardurl']))
999 1038
 	{
1000
-		if (substr($_POST['boardurl'], -10) == '/index.php')
1001
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1002
-		elseif (substr($_POST['boardurl'], -1) == '/')
1003
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1004
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
1005
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1039
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1040
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1041
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1042
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1043
+		}
1044
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1045
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1046
+		}
1006 1047
 	}
1007 1048
 
1008 1049
 	// Any passwords?
@@ -1037,21 +1078,21 @@  discard block
 block discarded – undo
1037 1078
 	// Figure out which config vars we're saving here...
1038 1079
 	foreach ($config_vars as $var)
1039 1080
 	{
1040
-		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]])))
1041
-			continue;
1081
+		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) {
1082
+					continue;
1083
+		}
1042 1084
 
1043 1085
 		$config_var = $var[0];
1044 1086
 
1045 1087
 		if (in_array($config_var, $config_passwords))
1046 1088
 		{
1047
-			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1])
1048
-				$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1049
-		}
1050
-		elseif (in_array($config_var, $config_strs))
1089
+			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) {
1090
+							$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1091
+			}
1092
+		} elseif (in_array($config_var, $config_strs))
1051 1093
 		{
1052 1094
 			$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var], '\'\\') . '\'';
1053
-		}
1054
-		elseif (in_array($config_var, $config_ints))
1095
+		} elseif (in_array($config_var, $config_ints))
1055 1096
 		{
1056 1097
 			$new_settings[$config_var] = (int) $_POST[$config_var];
1057 1098
 
@@ -1060,17 +1101,17 @@  discard block
 block discarded – undo
1060 1101
 			$new_settings[$config_var] = max($min, $new_settings[$config_var]);
1061 1102
 
1062 1103
 			// Is there a max value for this as well?
1063
-			if (isset($var['max']))
1064
-				$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1065
-		}
1066
-		elseif (in_array($config_var, $config_bools))
1104
+			if (isset($var['max'])) {
1105
+							$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1106
+			}
1107
+		} elseif (in_array($config_var, $config_bools))
1067 1108
 		{
1068
-			if (!empty($_POST[$config_var]))
1069
-				$new_settings[$config_var] = '1';
1070
-			else
1071
-				$new_settings[$config_var] = '0';
1072
-		}
1073
-		else
1109
+			if (!empty($_POST[$config_var])) {
1110
+							$new_settings[$config_var] = '1';
1111
+			} else {
1112
+							$new_settings[$config_var] = '0';
1113
+			}
1114
+		} else
1074 1115
 		{
1075 1116
 			// This shouldn't happen, but it might...
1076 1117
 			fatal_error('Unknown config_var \'' . $config_var . '\'');
@@ -1086,30 +1127,35 @@  discard block
 block discarded – undo
1086 1127
 	foreach ($config_vars as $config_var)
1087 1128
 	{
1088 1129
 		// We just saved the file-based settings, so skip their definitions.
1089
-		if (!is_array($config_var) || $config_var[2] == 'file')
1090
-			continue;
1130
+		if (!is_array($config_var) || $config_var[2] == 'file') {
1131
+					continue;
1132
+		}
1091 1133
 
1092 1134
 		$new_setting = array($config_var[3], $config_var[0]);
1093 1135
 
1094 1136
 		// Select options need carried over, too.
1095
-		if (isset($config_var[4]))
1096
-			$new_setting[] = $config_var[4];
1137
+		if (isset($config_var[4])) {
1138
+					$new_setting[] = $config_var[4];
1139
+		}
1097 1140
 
1098 1141
 		// Include min and max if necessary
1099
-		if (isset($config_var['min']))
1100
-			$new_setting['min'] = $config_var['min'];
1142
+		if (isset($config_var['min'])) {
1143
+					$new_setting['min'] = $config_var['min'];
1144
+		}
1101 1145
 
1102
-		if (isset($config_var['max']))
1103
-			$new_setting['max'] = $config_var['max'];
1146
+		if (isset($config_var['max'])) {
1147
+					$new_setting['max'] = $config_var['max'];
1148
+		}
1104 1149
 
1105 1150
 		// Rewrite the definition a bit.
1106 1151
 		$new_settings[] = $new_setting;
1107 1152
 	}
1108 1153
 
1109 1154
 	// Save the new database-based settings, if any.
1110
-	if (!empty($new_settings))
1111
-		saveDBSettings($new_settings);
1112
-}
1155
+	if (!empty($new_settings)) {
1156
+			saveDBSettings($new_settings);
1157
+	}
1158
+	}
1113 1159
 
1114 1160
 /**
1115 1161
  * Helper function for saving database settings.
@@ -1127,22 +1173,25 @@  discard block
 block discarded – undo
1127 1173
 	$inlinePermissions = array();
1128 1174
 	foreach ($config_vars as $var)
1129 1175
 	{
1130
-		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags']))))
1131
-			continue;
1176
+		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) {
1177
+					continue;
1178
+		}
1132 1179
 
1133 1180
 		// Checkboxes!
1134
-		elseif ($var[0] == 'check')
1135
-			$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1181
+		elseif ($var[0] == 'check') {
1182
+					$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1183
+		}
1136 1184
 		// Select boxes!
1137
-		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2])))
1138
-			$setArray[$var[1]] = $_POST[$var[1]];
1139
-		elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1185
+		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) {
1186
+					$setArray[$var[1]] = $_POST[$var[1]];
1187
+		} elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1140 1188
 		{
1141 1189
 			// For security purposes we validate this line by line.
1142 1190
 			$lOptions = array();
1143
-			foreach ($_POST[$var[1]] as $invar)
1144
-				if (in_array($invar, array_keys($var[2])))
1191
+			foreach ($_POST[$var[1]] as $invar) {
1192
+							if (in_array($invar, array_keys($var[2])))
1145 1193
 					$lOptions[] = $invar;
1194
+			}
1146 1195
 
1147 1196
 			$setArray[$var[1]] = json_encode($lOptions);
1148 1197
 		}
@@ -1156,18 +1205,20 @@  discard block
 block discarded – undo
1156 1205
 				$request = $smcFunc['db_query']('', '
1157 1206
 					SELECT id_board
1158 1207
 					FROM {db_prefix}boards');
1159
-				while ($row = $smcFunc['db_fetch_row']($request))
1160
-					$board_list[$row[0]] = true;
1208
+				while ($row = $smcFunc['db_fetch_row']($request)) {
1209
+									$board_list[$row[0]] = true;
1210
+				}
1161 1211
 
1162 1212
 				$smcFunc['db_free_result']($request);
1163 1213
 			}
1164 1214
 
1165 1215
 			$lOptions = array();
1166 1216
 
1167
-			if (!empty($_POST[$var[1]]))
1168
-				foreach ($_POST[$var[1]] as $invar => $dummy)
1217
+			if (!empty($_POST[$var[1]])) {
1218
+							foreach ($_POST[$var[1]] as $invar => $dummy)
1169 1219
 					if (isset($board_list[$invar]))
1170 1220
 						$lOptions[] = $invar;
1221
+			}
1171 1222
 
1172 1223
 			$setArray[$var[1]] = !empty($lOptions) ? implode(',', $lOptions) : '';
1173 1224
 		}
@@ -1181,8 +1232,9 @@  discard block
 block discarded – undo
1181 1232
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1182 1233
 
1183 1234
 			// Do we have a max value for this as well?
1184
-			if (isset($var['max']))
1185
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1235
+			if (isset($var['max'])) {
1236
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1237
+			}
1186 1238
 		}
1187 1239
 		// Floating point!
1188 1240
 		elseif ($var[0] == 'float')
@@ -1194,40 +1246,47 @@  discard block
 block discarded – undo
1194 1246
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1195 1247
 
1196 1248
 			// Do we have a max value for this as well?
1197
-			if (isset($var['max']))
1198
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1249
+			if (isset($var['max'])) {
1250
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1251
+			}
1199 1252
 		}
1200 1253
 		// Text!
1201
-		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time')))
1202
-			$setArray[$var[1]] = $_POST[$var[1]];
1254
+		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) {
1255
+					$setArray[$var[1]] = $_POST[$var[1]];
1256
+		}
1203 1257
 		// Passwords!
1204 1258
 		elseif ($var[0] == 'password')
1205 1259
 		{
1206
-			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1])
1207
-				$setArray[$var[1]] = $_POST[$var[1]][0];
1260
+			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) {
1261
+							$setArray[$var[1]] = $_POST[$var[1]][0];
1262
+			}
1208 1263
 		}
1209 1264
 		// BBC.
1210 1265
 		elseif ($var[0] == 'bbc')
1211 1266
 		{
1212 1267
 
1213 1268
 			$bbcTags = array();
1214
-			foreach (parse_bbc(false) as $tag)
1215
-				$bbcTags[] = $tag['tag'];
1269
+			foreach (parse_bbc(false) as $tag) {
1270
+							$bbcTags[] = $tag['tag'];
1271
+			}
1216 1272
 
1217
-			if (!isset($_POST[$var[1] . '_enabledTags']))
1218
-				$_POST[$var[1] . '_enabledTags'] = array();
1219
-			elseif (!is_array($_POST[$var[1] . '_enabledTags']))
1220
-				$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1273
+			if (!isset($_POST[$var[1] . '_enabledTags'])) {
1274
+							$_POST[$var[1] . '_enabledTags'] = array();
1275
+			} elseif (!is_array($_POST[$var[1] . '_enabledTags'])) {
1276
+							$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1277
+			}
1221 1278
 
1222 1279
 			$setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags']));
1223 1280
 		}
1224 1281
 		// Permissions?
1225
-		elseif ($var[0] == 'permissions')
1226
-			$inlinePermissions[] = $var[1];
1282
+		elseif ($var[0] == 'permissions') {
1283
+					$inlinePermissions[] = $var[1];
1284
+		}
1227 1285
 	}
1228 1286
 
1229
-	if (!empty($setArray))
1230
-		updateSettings($setArray);
1287
+	if (!empty($setArray)) {
1288
+			updateSettings($setArray);
1289
+	}
1231 1290
 
1232 1291
 	// If we have inline permissions we need to save them.
1233 1292
 	if (!empty($inlinePermissions) && allowedTo('manage_permissions'))
@@ -1265,18 +1324,21 @@  discard block
 block discarded – undo
1265 1324
 	// put all of it into an array
1266 1325
 	foreach ($info_lines as $line)
1267 1326
 	{
1268
-		if (preg_match('~(' . $remove . ')~', $line))
1269
-			continue;
1327
+		if (preg_match('~(' . $remove . ')~', $line)) {
1328
+					continue;
1329
+		}
1270 1330
 
1271 1331
 		// new category?
1272
-		if (strpos($line, '<h2>') !== false)
1273
-			$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1332
+		if (strpos($line, '<h2>') !== false) {
1333
+					$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1334
+		}
1274 1335
 
1275 1336
 		// load it as setting => value or the old setting local master
1276
-		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1277
-			$pinfo[$category][$val[1]] = $val[2];
1278
-		elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1279
-			$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1337
+		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1338
+					$pinfo[$category][$val[1]] = $val[2];
1339
+		} elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1340
+					$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1341
+		}
1280 1342
 	}
1281 1343
 
1282 1344
 	// load it in to context and display it
Please login to merge, or discard this patch.
Sources/Drafts.php 1 patch
Braces   +81 added lines, -57 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
 loadLanguage('Drafts');
21 22
 
@@ -33,8 +34,9 @@  discard block
 block discarded – undo
33 34
 	global $context, $user_info, $smcFunc, $modSettings, $board;
34 35
 
35 36
 	// can you be, should you be ... here?
36
-	if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft']))
37
-		return false;
37
+	if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) {
38
+			return false;
39
+	}
38 40
 
39 41
 	// read in what they sent us, if anything
40 42
 	$id_draft = (int) $_POST['id_draft'];
@@ -46,14 +48,16 @@  discard block
 block discarded – undo
46 48
 		$context['draft_saved_on'] = $draft_info['poster_time'];
47 49
 
48 50
 		// since we were called from the autosave function, send something back
49
-		if (!empty($id_draft))
50
-			XmlDraft($id_draft);
51
+		if (!empty($id_draft)) {
52
+					XmlDraft($id_draft);
53
+		}
51 54
 
52 55
 		return true;
53 56
 	}
54 57
 
55
-	if (!isset($_POST['message']))
56
-		$_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : '';
58
+	if (!isset($_POST['message'])) {
59
+			$_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : '';
60
+	}
57 61
 
58 62
 	// prepare any data from the form
59 63
 	$topic_id = empty($_REQUEST['topic']) ? 0 : (int) $_REQUEST['topic'];
@@ -66,8 +70,9 @@  discard block
 block discarded – undo
66 70
 
67 71
 	// message and subject still need a bit more work
68 72
 	preparsecode($draft['body']);
69
-	if ($smcFunc['strlen']($draft['subject']) > 100)
70
-		$draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100);
73
+	if ($smcFunc['strlen']($draft['subject']) > 100) {
74
+			$draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100);
75
+	}
71 76
 
72 77
 	// Modifying an existing draft, like hitting the save draft button or autosave enabled?
73 78
 	if (!empty($id_draft) && !empty($draft_info) && $draft_info['id_member'] == $user_info['id'])
@@ -150,9 +155,9 @@  discard block
 block discarded – undo
150 155
 		{
151 156
 			$context['draft_saved'] = true;
152 157
 			$context['id_draft'] = $id_draft;
158
+		} else {
159
+					$post_errors[] = 'draft_not_saved';
153 160
 		}
154
-		else
155
-			$post_errors[] = 'draft_not_saved';
156 161
 
157 162
 		// cleanup
158 163
 		unset($_POST['save_draft']);
@@ -182,8 +187,9 @@  discard block
 block discarded – undo
182 187
 	global $context, $user_info, $smcFunc, $modSettings;
183 188
 
184 189
 	// PM survey says ... can you stay or must you go
185
-	if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft']))
186
-		return false;
190
+	if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) {
191
+			return false;
192
+	}
187 193
 
188 194
 	// read in what you sent us
189 195
 	$id_pm_draft = (int) $_POST['id_pm_draft'];
@@ -195,8 +201,9 @@  discard block
 block discarded – undo
195 201
 		$context['draft_saved_on'] = $draft_info['poster_time'];
196 202
 
197 203
 		// Send something back to the javascript caller
198
-		if (!empty($id_draft))
199
-			XmlDraft($id_draft);
204
+		if (!empty($id_draft)) {
205
+					XmlDraft($id_draft);
206
+		}
200 207
 
201 208
 		return true;
202 209
 	}
@@ -206,9 +213,9 @@  discard block
 block discarded – undo
206 213
 	{
207 214
 		$recipientList['to'] = isset($_POST['recipient_to']) ? explode(',', $_POST['recipient_to']) : array();
208 215
 		$recipientList['bcc'] = isset($_POST['recipient_bcc']) ? explode(',', $_POST['recipient_bcc']) : array();
216
+	} elseif (!empty($draft_info['to_list']) && empty($recipientList)) {
217
+			$recipientList = smf_json_decode($draft_info['to_list'], true);
209 218
 	}
210
-	elseif (!empty($draft_info['to_list']) && empty($recipientList))
211
-		$recipientList = smf_json_decode($draft_info['to_list'], true);
212 219
 
213 220
 	// prepare the data we got from the form
214 221
 	$reply_id = empty($_POST['replied_to']) ? 0 : (int) $_POST['replied_to'];
@@ -217,8 +224,9 @@  discard block
 block discarded – undo
217 224
 
218 225
 	// message and subject always need a bit more work
219 226
 	preparsecode($draft['body']);
220
-	if ($smcFunc['strlen']($draft['subject']) > 100)
221
-		$draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100);
227
+	if ($smcFunc['strlen']($draft['subject']) > 100) {
228
+			$draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100);
229
+	}
222 230
 
223 231
 	// Modifying an existing PM draft?
224 232
 	if (!empty($id_pm_draft) && !empty($draft_info) && $draft_info['id_member'] == $user_info['id'])
@@ -284,9 +292,9 @@  discard block
 block discarded – undo
284 292
 		{
285 293
 			$context['draft_saved'] = true;
286 294
 			$context['id_pm_draft'] = $id_pm_draft;
295
+		} else {
296
+					$post_errors[] = 'draft_not_saved';
287 297
 		}
288
-		else
289
-			$post_errors[] = 'draft_not_saved';
290 298
 	}
291 299
 
292 300
 	// if we were called from the autosave function, send something back
@@ -319,8 +327,9 @@  discard block
 block discarded – undo
319 327
 	$type = (int) $type;
320 328
 
321 329
 	// nothing to read, nothing to do
322
-	if (empty($id_draft))
323
-		return false;
330
+	if (empty($id_draft)) {
331
+			return false;
332
+	}
324 333
 
325 334
 	// load in this draft from the DB
326 335
 	$request = $smcFunc['db_query']('', '
@@ -340,8 +349,9 @@  discard block
 block discarded – undo
340 349
 	);
341 350
 
342 351
 	// no results?
343
-	if (!$smcFunc['db_num_rows']($request))
344
-		return false;
352
+	if (!$smcFunc['db_num_rows']($request)) {
353
+			return false;
354
+	}
345 355
 
346 356
 	// load up the data
347 357
 	$draft_info = $smcFunc['db_fetch_assoc']($request);
@@ -362,8 +372,7 @@  discard block
 block discarded – undo
362 372
 			$context['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : '';
363 373
 			$context['board'] = !empty($draft_info['board_id']) ? $draft_info['id_board'] : '';
364 374
 			$context['id_draft'] = !empty($draft_info['id_draft']) ? $draft_info['id_draft'] : 0;
365
-		}
366
-		elseif ($type === 1)
375
+		} elseif ($type === 1)
367 376
 		{
368 377
 			// one of those pm drafts? then set it up like we have an error
369 378
 			$_REQUEST['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : '';
@@ -399,12 +408,14 @@  discard block
 block discarded – undo
399 408
 	global $user_info, $smcFunc;
400 409
 
401 410
 	// Only a single draft.
402
-	if (is_numeric($id_draft))
403
-		$id_draft = array($id_draft);
411
+	if (is_numeric($id_draft)) {
412
+			$id_draft = array($id_draft);
413
+	}
404 414
 
405 415
 	// can't delete nothing
406
-	if (empty($id_draft) || ($check && empty($user_info['id'])))
407
-		return false;
416
+	if (empty($id_draft) || ($check && empty($user_info['id']))) {
417
+			return false;
418
+	}
408 419
 
409 420
 	$smcFunc['db_query']('', '
410 421
 		DELETE FROM {db_prefix}user_drafts
@@ -433,14 +444,16 @@  discard block
 block discarded – undo
433 444
 	global $smcFunc, $scripturl, $context, $txt, $modSettings;
434 445
 
435 446
 	// Permissions
436
-	if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id))
437
-		return false;
447
+	if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) {
448
+			return false;
449
+	}
438 450
 
439 451
 	$context['drafts'] = array();
440 452
 
441 453
 	// has a specific draft has been selected?  Load it up if there is not a message already in the editor
442
-	if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message']))
443
-		ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true);
454
+	if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) {
455
+			ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true);
456
+	}
444 457
 
445 458
 	// load the drafts this user has available
446 459
 	$request = $smcFunc['db_query']('', '
@@ -463,23 +476,26 @@  discard block
 block discarded – undo
463 476
 	// add them to the draft array for display
464 477
 	while ($row = $smcFunc['db_fetch_assoc']($request))
465 478
 	{
466
-		if (empty($row['subject']))
467
-			$row['subject'] = $txt['no_subject'];
479
+		if (empty($row['subject'])) {
480
+					$row['subject'] = $txt['no_subject'];
481
+		}
468 482
 
469 483
 		// Post drafts
470
-		if ($draft_type === 0)
471
-			$context['drafts'][] = array(
484
+		if ($draft_type === 0) {
485
+					$context['drafts'][] = array(
472 486
 				'subject' => censorText(shorten_subject(stripslashes($row['subject']), 24)),
473 487
 				'poster_time' => timeformat($row['poster_time']),
474 488
 				'link' => '<a href="' . $scripturl . '?action=post;board=' . $row['id_board'] . ';' . (!empty($row['id_topic']) ? 'topic='. $row['id_topic'] .'.0;' : '') . 'id_draft=' . $row['id_draft'] . '">' . $row['subject'] . '</a>',
475 489
 			);
490
+		}
476 491
 		// PM drafts
477
-		elseif ($draft_type === 1)
478
-			$context['drafts'][] = array(
492
+		elseif ($draft_type === 1) {
493
+					$context['drafts'][] = array(
479 494
 				'subject' => censorText(shorten_subject(stripslashes($row['subject']), 24)),
480 495
 				'poster_time' => timeformat($row['poster_time']),
481 496
 				'link' => '<a href="' . $scripturl . '?action=pm;sa=send;id_draft=' . $row['id_draft'] . '">' . (!empty($row['subject']) ? $row['subject'] : $txt['drafts_none']) . '</a>',
482 497
 			);
498
+		}
483 499
 	}
484 500
 	$smcFunc['db_free_result']($request);
485 501
 }
@@ -543,8 +559,9 @@  discard block
 block discarded – undo
543 559
 	}
544 560
 
545 561
 	// Default to 10.
546
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
547
-		$_REQUEST['viewscount'] = 10;
562
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
563
+			$_REQUEST['viewscount'] = 10;
564
+	}
548 565
 
549 566
 	// Get the count of applicable drafts on the boards they can (still) see ...
550 567
 	// @todo .. should we just let them see their drafts even if they have lost board access ?
@@ -609,12 +626,14 @@  discard block
 block discarded – undo
609 626
 	while ($row = $smcFunc['db_fetch_assoc']($request))
610 627
 	{
611 628
 		// Censor....
612
-		if (empty($row['body']))
613
-			$row['body'] = '';
629
+		if (empty($row['body'])) {
630
+					$row['body'] = '';
631
+		}
614 632
 
615 633
 		$row['subject'] = $smcFunc['htmltrim']($row['subject']);
616
-		if (empty($row['subject']))
617
-			$row['subject'] = $txt['no_subject'];
634
+		if (empty($row['subject'])) {
635
+					$row['subject'] = $txt['no_subject'];
636
+		}
618 637
 
619 638
 		censorText($row['body']);
620 639
 		censorText($row['subject']);
@@ -646,8 +665,9 @@  discard block
 block discarded – undo
646 665
 	$smcFunc['db_free_result']($request);
647 666
 
648 667
 	// If the drafts were retrieved in reverse order, get them right again.
649
-	if ($reverse)
650
-		$context['drafts'] = array_reverse($context['drafts'], true);
668
+	if ($reverse) {
669
+			$context['drafts'] = array_reverse($context['drafts'], true);
670
+	}
651 671
 
652 672
 	// Menu tab
653 673
 	$context[$context['profile_menu_name']]['tab_data'] = array(
@@ -705,8 +725,9 @@  discard block
 block discarded – undo
705 725
 	}
706 726
 
707 727
 	// Default to 10.
708
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
709
-		$_REQUEST['viewscount'] = 10;
728
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
729
+			$_REQUEST['viewscount'] = 10;
730
+	}
710 731
 
711 732
 	// Get the count of applicable drafts
712 733
 	$request = $smcFunc['db_query']('', '
@@ -765,12 +786,14 @@  discard block
 block discarded – undo
765 786
 	while ($row = $smcFunc['db_fetch_assoc']($request))
766 787
 	{
767 788
 		// Censor....
768
-		if (empty($row['body']))
769
-			$row['body'] = '';
789
+		if (empty($row['body'])) {
790
+					$row['body'] = '';
791
+		}
770 792
 
771 793
 		$row['subject'] = $smcFunc['htmltrim']($row['subject']);
772
-		if (empty($row['subject']))
773
-			$row['subject'] = $txt['no_subject'];
794
+		if (empty($row['subject'])) {
795
+					$row['subject'] = $txt['no_subject'];
796
+		}
774 797
 
775 798
 		censorText($row['body']);
776 799
 		censorText($row['subject']);
@@ -825,8 +848,9 @@  discard block
 block discarded – undo
825 848
 	$smcFunc['db_free_result']($request);
826 849
 
827 850
 	// if the drafts were retrieved in reverse order, then put them in the right order again.
828
-	if ($reverse)
829
-		$context['drafts'] = array_reverse($context['drafts'], true);
851
+	if ($reverse) {
852
+			$context['drafts'] = array_reverse($context['drafts'], true);
853
+	}
830 854
 
831 855
 	// off to the template we go
832 856
 	$context['page_title'] = $txt['drafts'];
Please login to merge, or discard this patch.