Completed
Push — release-2.1 ( af8dd6...5b3c87 )
by Michael
20:47 queued 10:04
created
Sources/Calendar.php 1 patch
Braces   +122 added lines, -97 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
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');
@@ -88,22 +91,25 @@  discard block
 block discarded – undo
88 91
 	$context['page_title'] = $txt['calendar'];
89 92
 
90 93
 	// Ensure a default view is defined
91
-	if (empty($modSettings['calendar_default_view']))
92
-		$modSettings['calendar_default_view'] = 'viewlist';
94
+	if (empty($modSettings['calendar_default_view'])) {
95
+			$modSettings['calendar_default_view'] = 'viewlist';
96
+	}
93 97
 
94 98
 	// What view do we want?
95
-	if (isset($_GET['viewweek']))
96
-		$context['calendar_view'] = 'viewweek';
97
-	elseif (isset($_GET['viewmonth']))
98
-		$context['calendar_view'] = 'viewmonth';
99
-	elseif (isset($_GET['viewlist']))
100
-		$context['calendar_view'] = 'viewlist';
101
-	else
102
-		$context['calendar_view'] = $modSettings['calendar_default_view'];
99
+	if (isset($_GET['viewweek'])) {
100
+			$context['calendar_view'] = 'viewweek';
101
+	} elseif (isset($_GET['viewmonth'])) {
102
+			$context['calendar_view'] = 'viewmonth';
103
+	} elseif (isset($_GET['viewlist'])) {
104
+			$context['calendar_view'] = 'viewlist';
105
+	} else {
106
+			$context['calendar_view'] = $modSettings['calendar_default_view'];
107
+	}
103 108
 
104 109
 	// Don't let search engines index the non-default calendar pages
105
-	if ($context['calendar_view'] !== $modSettings['calendar_default_view'])
106
-		$context['robot_no_index'] = true;
110
+	if ($context['calendar_view'] !== $modSettings['calendar_default_view']) {
111
+			$context['robot_no_index'] = true;
112
+	}
107 113
 
108 114
 	// Get the current day of month...
109 115
 	require_once($sourcedir . '/Subs-Calendar.php');
@@ -164,16 +170,19 @@  discard block
 block discarded – undo
164 170
 	);
165 171
 
166 172
 	// Make sure the year and month are in valid ranges.
167
-	if ($curPage['month'] < 1 || $curPage['month'] > 12)
168
-		fatal_lang_error('invalid_month', false);
169
-	if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear'])
170
-		fatal_lang_error('invalid_year', false);
173
+	if ($curPage['month'] < 1 || $curPage['month'] > 12) {
174
+			fatal_lang_error('invalid_month', false);
175
+	}
176
+	if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear']) {
177
+			fatal_lang_error('invalid_year', false);
178
+	}
171 179
 	// If we have a day clean that too.
172 180
 	if ($context['calendar_view'] != 'viewmonth')
173 181
 	{
174 182
 		$isValid = checkdate($curPage['month'], $curPage['day'], $curPage['year']);
175
-		if (!$isValid)
176
-			fatal_lang_error('invalid_day', false);
183
+		if (!$isValid) {
184
+					fatal_lang_error('invalid_day', false);
185
+		}
177 186
 	}
178 187
 
179 188
 	// Load all the context information needed to show the calendar grid.
@@ -195,23 +204,26 @@  discard block
 block discarded – undo
195 204
 	);
196 205
 
197 206
 	// Load up the main view.
198
-	if ($context['calendar_view'] == 'viewlist')
199
-		$context['calendar_grid_main'] = getCalendarList($curPage['start_date'], $curPage['end_date'], $calendarOptions);
200
-	elseif ($context['calendar_view'] == 'viewweek')
201
-		$context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
202
-	else
203
-		$context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
207
+	if ($context['calendar_view'] == 'viewlist') {
208
+			$context['calendar_grid_main'] = getCalendarList($curPage['start_date'], $curPage['end_date'], $calendarOptions);
209
+	} elseif ($context['calendar_view'] == 'viewweek') {
210
+			$context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
211
+	} else {
212
+			$context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
213
+	}
204 214
 
205 215
 	// Load up the previous and next months.
206 216
 	$context['calendar_grid_current'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
207 217
 
208 218
 	// Only show previous month if it isn't pre-January of the min-year
209
-	if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1)
210
-		$context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
219
+	if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1) {
220
+			$context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
221
+	}
211 222
 
212 223
 	// Only show next month if it isn't post-December of the max-year
213
-	if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12)
214
-		$context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
224
+	if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12) {
225
+			$context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
226
+	}
215 227
 
216 228
 	// Basic template stuff.
217 229
 	$context['allow_calendar_event'] = allowedTo('calendar_post');
@@ -231,8 +243,9 @@  discard block
 block discarded – undo
231 243
 	$context['blocks_disabled'] = !empty($modSettings['cal_disable_prev_next']) ? 1 : 0;
232 244
 
233 245
 	// Set the page title to mention the month or week, too
234
-	if ($context['calendar_view'] != 'viewlist')
235
-		$context['page_title'] .= ' - ' . ($context['calendar_view'] == 'viewweek' ? $context['calendar_grid_main']['week_title'] : $txt['months'][$context['current_month']] . ' ' . $context['current_year']);
246
+	if ($context['calendar_view'] != 'viewlist') {
247
+			$context['page_title'] .= ' - ' . ($context['calendar_view'] == 'viewweek' ? $context['calendar_grid_main']['week_title'] : $txt['months'][$context['current_month']] . ' ' . $context['current_year']);
248
+	}
236 249
 
237 250
 	// Load up the linktree!
238 251
 	$context['linktree'][] = array(
@@ -245,17 +258,19 @@  discard block
 block discarded – undo
245 258
 		'name' => $txt['months'][$context['current_month']] . ' ' . $context['current_year']
246 259
 	);
247 260
 	// If applicable, add the current week to the linktree.
248
-	if ($context['calendar_view'] == 'viewweek')
249
-		$context['linktree'][] = array(
261
+	if ($context['calendar_view'] == 'viewweek') {
262
+			$context['linktree'][] = array(
250 263
 			'url' => $scripturl . '?action=calendar;viewweek;year=' . $context['current_year'] . ';month=' . $context['current_month'] . ';day=' . $context['current_day'],
251 264
 			'name' => $context['calendar_grid_main']['week_title'],
252 265
 		);
266
+	}
253 267
 
254 268
 	// Build the calendar button array.
255 269
 	$context['calendar_buttons'] = array();
256 270
 
257
-	if ($context['can_post'])
258
-		$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']);
271
+	if ($context['can_post']) {
272
+			$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']);
273
+	}
259 274
 
260 275
 	// Allow mods to add additional buttons here
261 276
 	call_integration_hook('integrate_calendar_buttons');
@@ -284,14 +299,16 @@  discard block
 block discarded – undo
284 299
 	require_once($sourcedir . '/Subs.php');
285 300
 
286 301
 	// Cast this for safety...
287
-	if (isset($_REQUEST['eventid']))
288
-		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
302
+	if (isset($_REQUEST['eventid'])) {
303
+			$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
304
+	}
289 305
 
290 306
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
291
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
292
-		$time_string = '%k:%M';
293
-	else
294
-		$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
307
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
308
+			$time_string = '%k:%M';
309
+	} else {
310
+			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
311
+	}
295 312
 
296 313
 	$js_time_string = str_replace(
297 314
 		array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -305,12 +322,14 @@  discard block
 block discarded – undo
305 322
 		checkSession();
306 323
 
307 324
 		// Validate the post...
308
-		if (!isset($_POST['link_to_board']))
309
-			validateEventPost();
325
+		if (!isset($_POST['link_to_board'])) {
326
+					validateEventPost();
327
+		}
310 328
 
311 329
 		// If you're not allowed to edit any events, you have to be the poster.
312
-		if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any'))
313
-			isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
330
+		if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any')) {
331
+					isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
332
+		}
314 333
 
315 334
 		// New - and directing?
316 335
 		if (isset($_POST['link_to_board']) || empty($modSettings['cal_allow_unlinked']))
@@ -333,8 +352,9 @@  discard block
 block discarded – undo
333 352
 		}
334 353
 
335 354
 		// Deleting...
336
-		elseif (isset($_REQUEST['deleteevent']))
337
-			removeEvent($_REQUEST['eventid']);
355
+		elseif (isset($_REQUEST['deleteevent'])) {
356
+					removeEvent($_REQUEST['eventid']);
357
+		}
338 358
 
339 359
 		// ... or just update it?
340 360
 		else
@@ -357,15 +377,13 @@  discard block
 block discarded – undo
357 377
 			$year = $d['year'];
358 378
 			$month = $d['month'];
359 379
 			$day = $d['day'];
360
-		}
361
-		elseif (isset($_POST['start_datetime']))
380
+		} elseif (isset($_POST['start_datetime']))
362 381
 		{
363 382
 			$d = date_parse($_POST['start_datetime']);
364 383
 			$year = $d['year'];
365 384
 			$month = $d['month'];
366 385
 			$day = $d['day'];
367
-		}
368
-		else
386
+		} else
369 387
 		{
370 388
 			$today = getdate();
371 389
 			$year = isset($_POST['year']) ? $_POST['year'] : $today['year'];
@@ -399,13 +417,13 @@  discard block
 block discarded – undo
399 417
 		$context['event'] = array_merge($context['event'], $eventDatetimes);
400 418
 
401 419
 		$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']));
402
-	}
403
-	else
420
+	} else
404 421
 	{
405 422
 		$context['event'] = getEventProperties($_REQUEST['eventid']);
406 423
 
407
-		if ($context['event'] === false)
408
-			fatal_lang_error('no_access', false);
424
+		if ($context['event'] === false) {
425
+					fatal_lang_error('no_access', false);
426
+		}
409 427
 
410 428
 		// If it has a board, then they should be editing it within the topic.
411 429
 		if (!empty($context['event']['topic']['id']) && !empty($context['event']['topic']['first_msg']))
@@ -416,10 +434,11 @@  discard block
 block discarded – undo
416 434
 		}
417 435
 
418 436
 		// Make sure the user is allowed to edit this event.
419
-		if ($context['event']['member'] != $user_info['id'])
420
-			isAllowedTo('calendar_edit_any');
421
-		elseif (!allowedTo('calendar_edit_any'))
422
-			isAllowedTo('calendar_edit_own');
437
+		if ($context['event']['member'] != $user_info['id']) {
438
+					isAllowedTo('calendar_edit_any');
439
+		} elseif (!allowedTo('calendar_edit_any')) {
440
+					isAllowedTo('calendar_edit_own');
441
+		}
423 442
 	}
424 443
 
425 444
 	// An all day event? Set up some nice defaults in case the user wants to change that
@@ -453,8 +472,7 @@  discard block
 block discarded – undo
453 472
 	{
454 473
 		// You can post new events but can't link them to anything...
455 474
 		$context['event']['categories'] = array();
456
-	}
457
-	else
475
+	} else
458 476
 	{
459 477
 		// Load the list of boards and categories in the context.
460 478
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -541,12 +559,14 @@  discard block
 block discarded – undo
541 559
 	global $smcFunc, $sourcedir, $forum_version, $modSettings, $webmaster_email, $mbname;
542 560
 
543 561
 	// You can't export if the calendar export feature is off.
544
-	if (empty($modSettings['cal_export']))
545
-		fatal_lang_error('calendar_export_off', false);
562
+	if (empty($modSettings['cal_export'])) {
563
+			fatal_lang_error('calendar_export_off', false);
564
+	}
546 565
 
547 566
 	// Goes without saying that this is required.
548
-	if (!isset($_REQUEST['eventid']))
549
-		fatal_lang_error('no_access', false);
567
+	if (!isset($_REQUEST['eventid'])) {
568
+			fatal_lang_error('no_access', false);
569
+	}
550 570
 
551 571
 	// This is kinda wanted.
552 572
 	require_once($sourcedir . '/Subs-Calendar.php');
@@ -554,15 +574,17 @@  discard block
 block discarded – undo
554 574
 	// Load up the event in question and check it exists.
555 575
 	$event = getEventProperties($_REQUEST['eventid']);
556 576
 
557
-	if ($event === false)
558
-		fatal_lang_error('no_access', false);
577
+	if ($event === false) {
578
+			fatal_lang_error('no_access', false);
579
+	}
559 580
 
560 581
 	// Check the title isn't too long - iCal requires some formatting if so.
561 582
 	$title = str_split($event['title'], 30);
562 583
 	foreach ($title as $id => $line)
563 584
 	{
564
-		if ($id != 0)
565
-			$title[$id] = ' ' . $title[$id];
585
+		if ($id != 0) {
586
+					$title[$id] = ' ' . $title[$id];
587
+		}
566 588
 		$title[$id] .= "\n";
567 589
 	}
568 590
 
@@ -575,8 +597,7 @@  discard block
 block discarded – undo
575 597
 	{
576 598
 		$datestart = date_format($start_date, 'Ymd\THis');
577 599
 		$dateend = date_format($end_date, 'Ymd\THis');
578
-	}
579
-	else
600
+	} else
580 601
 	{
581 602
 		$datestart = date_format($start_date, 'Ymd');
582 603
 
@@ -597,15 +618,18 @@  discard block
 block discarded – undo
597 618
 	$filecontents .= 'DTSTART' . (!empty($event['start_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $datestart . "\n";
598 619
 
599 620
 	// event has a duration
600
-	if ($event['start_iso_gmdate'] != $event['end_iso_gmdate'])
601
-		$filecontents .= 'DTEND' . (!empty($event['end_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $dateend . "\n";
621
+	if ($event['start_iso_gmdate'] != $event['end_iso_gmdate']) {
622
+			$filecontents .= 'DTEND' . (!empty($event['end_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $dateend . "\n";
623
+	}
602 624
 
603 625
 	// event has changed? advance the sequence for this UID
604
-	if ($event['sequence'] > 0)
605
-		$filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
626
+	if ($event['sequence'] > 0) {
627
+			$filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
628
+	}
606 629
 
607
-	if (!empty($event['location']))
608
-		$filecontents .= 'LOCATION:' . str_replace(',', '\,', $event['location']) . "\n";
630
+	if (!empty($event['location'])) {
631
+			$filecontents .= 'LOCATION:' . str_replace(',', '\,', $event['location']) . "\n";
632
+	}
609 633
 
610 634
 	$filecontents .= 'SUMMARY:' . implode('', $title);
611 635
 	$filecontents .= 'UID:' . $event['eventid'] . '@' . str_replace(' ', '-', $mbname) . "\n";
@@ -614,23 +638,26 @@  discard block
 block discarded – undo
614 638
 
615 639
 	// Send some standard headers.
616 640
 	ob_end_clean();
617
-	if (!empty($modSettings['enableCompressedOutput']))
618
-		@ob_start('ob_gzhandler');
619
-	else
620
-		ob_start();
641
+	if (!empty($modSettings['enableCompressedOutput'])) {
642
+			@ob_start('ob_gzhandler');
643
+	} else {
644
+			ob_start();
645
+	}
621 646
 
622 647
 	// Send the file headers
623 648
 	header('Pragma: ');
624 649
 	header('Cache-Control: no-cache');
625
-	if (!isBrowser('gecko'))
626
-		header('Content-Transfer-Encoding: binary');
650
+	if (!isBrowser('gecko')) {
651
+			header('Content-Transfer-Encoding: binary');
652
+	}
627 653
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
628 654
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . 'GMT');
629 655
 	header('Accept-Ranges: bytes');
630 656
 	header('Connection: close');
631 657
 	header('Content-Disposition: attachment; filename="' . $event['title'] . '.ics"');
632
-	if (empty($modSettings['enableCompressedOutput']))
633
-		header('Content-Length: ' . $smcFunc['strlen']($filecontents));
658
+	if (empty($modSettings['enableCompressedOutput'])) {
659
+			header('Content-Length: ' . $smcFunc['strlen']($filecontents));
660
+	}
634 661
 
635 662
 	// This is a calendar item!
636 663
 	header('Content-Type: text/calendar');
@@ -669,20 +696,17 @@  discard block
 block discarded – undo
669 696
 		$context['sub_template'] = 'bcd';
670 697
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock;bcd', 'name' => 'BCD');
671 698
 		$context['clockicons'] = $smcFunc['json_decode'](base64_decode('eyJoMSI6WzIsMV0sImgyIjpbOCw0LDIsMV0sIm0xIjpbNCwyLDFdLCJtMiI6WzgsNCwyLDFdLCJzMSI6WzQsMiwxXSwiczIiOls4LDQsMiwxXX0='), true);
672
-	}
673
-	elseif (!$omfg && !isset($_REQUEST['time']))
699
+	} elseif (!$omfg && !isset($_REQUEST['time']))
674 700
 	{
675 701
 		$context['sub_template'] = 'hms';
676 702
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock', 'name' => 'Binary');
677 703
 		$context['clockicons'] = $smcFunc['json_decode'](base64_decode('eyJoIjpbMTYsOCw0LDIsMV0sIm0iOlszMiwxNiw4LDQsMiwxXSwicyI6WzMyLDE2LDgsNCwyLDFdfQ'), true);
678
-	}
679
-	elseif ($omfg)
704
+	} elseif ($omfg)
680 705
 	{
681 706
 		$context['sub_template'] = 'omfg';
682 707
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock;omfg', 'name' => 'OMFG');
683 708
 		$context['clockicons'] = $smcFunc['json_decode'](base64_decode('eyJ5ZWFyIjpbNjQsMzIsMTYsOCw0LDIsMV0sIm1vbnRoIjpbOCw0LDIsMV0sImRheSI6WzE2LDgsNCwyLDFdLCJob3VyIjpbMTYsOCw0LDIsMV0sIm1pbiI6WzMyLDE2LDgsNCwyLDFdLCJzZWMiOlszMiwxNiw4LDQsMiwxXX0='), true);
684
-	}
685
-	elseif (isset($_REQUEST['time']))
709
+	} elseif (isset($_REQUEST['time']))
686 710
 	{
687 711
 		$context['sub_template'] = 'thetime';
688 712
 		$time = getdate($_REQUEST['time'] == 'now' ? time() : (int) $_REQUEST['time']);
@@ -736,12 +760,13 @@  discard block
 block discarded – undo
736 760
 			),
737 761
 		);
738 762
 
739
-		foreach ($context['clockicons'] as $t => $vs)
740
-			foreach ($vs as $v => $dumb)
763
+		foreach ($context['clockicons'] as $t => $vs) {
764
+					foreach ($vs as $v => $dumb)
741 765
 			{
742 766
 				if ($$t >= $v)
743 767
 				{
744 768
 					$$t -= $v;
769
+		}
745 770
 					$context['clockicons'][$t][$v] = true;
746 771
 				}
747 772
 			}
Please login to merge, or discard this patch.
subscriptions.php 1 patch
Braces   +38 added lines, -28 removed lines patch added patch discarded remove patch
@@ -16,8 +16,9 @@  discard block
 block discarded – undo
16 16
 
17 17
 // Start things rolling by getting SMF alive...
18 18
 $ssi_guest_access = true;
19
-if (!file_exists(dirname(__FILE__) . '/SSI.php'))
19
+if (!file_exists(dirname(__FILE__) . '/SSI.php')) {
20 20
 	die('Cannot find SSI.php');
21
+}
21 22
 
22 23
 require_once(dirname(__FILE__) . '/SSI.php');
23 24
 require_once($sourcedir . '/ManagePaid.php');
@@ -35,20 +36,22 @@  discard block
 block discarded – undo
35 36
 }
36 37
 
37 38
 // I assume we're even active?
38
-if (empty($modSettings['paid_enabled']))
39
+if (empty($modSettings['paid_enabled'])) {
39 40
 	exit;
41
+}
40 42
 
41 43
 // If we have some custom people who find out about problems load them here.
42 44
 $notify_users = array();
43 45
 if (!empty($modSettings['paid_email_to']))
44 46
 {
45
-	foreach (explode(',', $modSettings['paid_email_to']) as $email)
46
-		$notify_users[] = array(
47
+	foreach (explode(',', $modSettings['paid_email_to']) as $email) {
48
+			$notify_users[] = array(
47 49
 			'email' => $email,
48 50
 			'name' => $txt['who_member'],
49 51
 			'id' => 0,
50 52
 		);
51
-}
53
+	}
54
+	}
52 55
 
53 56
 // We need to see whether we can find the correct payment gateway,
54 57
 // we'll going to go through all our gateway scripts and find out
@@ -65,8 +68,9 @@  discard block
 block discarded – undo
65 68
 	}
66 69
 }
67 70
 
68
-if (empty($txnType))
71
+if (empty($txnType)) {
69 72
 	generateSubscriptionError($txt['paid_unknown_transaction_type']);
73
+}
70 74
 
71 75
 // Get the subscription and member ID amoungst others...
72 76
 @list($subscription_id, $member_id) = $gatewayClass->precheck();
@@ -76,8 +80,9 @@  discard block
 block discarded – undo
76 80
 $member_id = (int) $member_id;
77 81
 
78 82
 // This would be bad...
79
-if (empty($member_id))
83
+if (empty($member_id)) {
80 84
 	generateSubscriptionError($txt['paid_empty_member']);
85
+}
81 86
 
82 87
 // Verify the member.
83 88
 $request = $smcFunc['db_query']('', '
@@ -89,8 +94,9 @@  discard block
 block discarded – undo
89 94
 	)
90 95
 );
91 96
 // Didn't find them?
92
-if ($smcFunc['db_num_rows']($request) === 0)
97
+if ($smcFunc['db_num_rows']($request) === 0) {
93 98
 	generateSubscriptionError(sprintf($txt['paid_could_not_find_member'], $member_id));
99
+}
94 100
 $member_info = $smcFunc['db_fetch_assoc']($request);
95 101
 $smcFunc['db_free_result']($request);
96 102
 
@@ -105,8 +111,9 @@  discard block
 block discarded – undo
105 111
 );
106 112
 
107 113
 // Didn't find it?
108
-if ($smcFunc['db_num_rows']($request) === 0)
114
+if ($smcFunc['db_num_rows']($request) === 0) {
109 115
 	generateSubscriptionError(sprintf($txt['paid_count_not_find_subscription'], $member_id, $subscription_id));
116
+}
110 117
 
111 118
 $subscription_info = $smcFunc['db_fetch_assoc']($request);
112 119
 $smcFunc['db_free_result']($request);
@@ -123,8 +130,9 @@  discard block
 block discarded – undo
123 130
 		'current_member' => $member_id,
124 131
 	)
125 132
 );
126
-if ($smcFunc['db_num_rows']($request) === 0)
133
+if ($smcFunc['db_num_rows']($request) === 0) {
127 134
 	generateSubscriptionError(sprintf($txt['paid_count_not_find_subscription_log'], $member_id, $subscription_id));
135
+}
128 136
 $subscription_info += $smcFunc['db_fetch_assoc']($request);
129 137
 $smcFunc['db_free_result']($request);
130 138
 
@@ -139,8 +147,7 @@  discard block
 block discarded – undo
139 147
 		removeSubscription($subscription_id, $member_id);
140 148
 		$subscription_act = time();
141 149
 		$status = 0;
142
-	}
143
-	else
150
+	} else
144 151
 	{
145 152
 		loadSubscriptions();
146 153
 		$subscription_act = $subscription_info['end_time'] - $context['subscriptions'][$subscription_id]['num_length'];
@@ -188,16 +195,18 @@  discard block
 block discarded – undo
188 195
 	if (!$gatewayClass->isSubscription())
189 196
 	{
190 197
 		$real_details = $smcFunc['json_decode']($subscription_info['pending_details'], true);
191
-		if (empty($real_details))
192
-			generateSubscriptionError(sprintf($txt['paid_count_not_find_outstanding_payment'], $member_id, $subscription_id));
198
+		if (empty($real_details)) {
199
+					generateSubscriptionError(sprintf($txt['paid_count_not_find_outstanding_payment'], $member_id, $subscription_id));
200
+		}
193 201
 
194 202
 		// Now we just try to find anything pending.
195 203
 		// We don't really care which it is as security happens later.
196 204
 		foreach ($real_details as $id => $detail)
197 205
 		{
198 206
 			unset($real_details[$id]);
199
-			if ($detail[3] == 'payback' && $subscription_info['payments_pending'])
200
-				$subscription_info['payments_pending']--;
207
+			if ($detail[3] == 'payback' && $subscription_info['payments_pending']) {
208
+							$subscription_info['payments_pending']--;
209
+			}
201 210
 			break;
202 211
 		}
203 212
 
@@ -223,10 +232,11 @@  discard block
 block discarded – undo
223 232
 		// This is a little harder, can we find the right duration?
224 233
 		foreach ($cost as $duration => $value)
225 234
 		{
226
-			if ($duration == 'fixed')
227
-				continue;
228
-			elseif ((float) $value == (float) $total_cost)
229
-				$found_duration = strtoupper(substr($duration, 0, 1));
235
+			if ($duration == 'fixed') {
236
+							continue;
237
+			} elseif ((float) $value == (float) $total_cost) {
238
+							$found_duration = strtoupper(substr($duration, 0, 1));
239
+			}
230 240
 		}
231 241
 
232 242
 		// If we have the duration then we're done.
@@ -235,8 +245,7 @@  discard block
 block discarded – undo
235 245
 			$notify = true;
236 246
 			addSubscription($subscription_id, $member_id, $found_duration);
237 247
 		}
238
-	}
239
-	else
248
+	} else
240 249
 	{
241 250
 		$actual_cost = $cost['fixed'];
242 251
 
@@ -268,10 +277,10 @@  discard block
 block discarded – undo
268 277
 // Maybe they're cancelling. Some subscriptions may require actively doing something, but PayPal doesn't, for example.
269 278
 elseif ($gatewayClass->isCancellation())
270 279
 {
271
-	if (method_exists($gatewayClass, 'performCancel'))
272
-		$gatewayClass->performCancel($subscription_id, $member_id, $subscription_info);
273
-}
274
-else
280
+	if (method_exists($gatewayClass, 'performCancel')) {
281
+			$gatewayClass->performCancel($subscription_id, $member_id, $subscription_info);
282
+	}
283
+	} else
275 284
 {
276 285
 	// Some other "valid" transaction such as:
277 286
 	//
@@ -308,8 +317,9 @@  discard block
 block discarded – undo
308 317
 	// Maybe we can try to give them the post data?
309 318
 	if (!empty($_POST))
310 319
 	{
311
-		foreach ($_POST as $key => $val)
312
-			$text .= '<br>' . $smcFunc['htmlspecialchars']($key) . ': ' . $smcFunc['htmlspecialchars']($val);
320
+		foreach ($_POST as $key => $val) {
321
+					$text .= '<br>' . $smcFunc['htmlspecialchars']($key) . ': ' . $smcFunc['htmlspecialchars']($val);
322
+		}
313 323
 	}
314 324
 
315 325
 	// Then just log and die.
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +878 added lines, -645 removed lines patch added patch discarded remove patch
@@ -75,8 +75,9 @@  discard block
 block discarded – undo
75 75
 $upcontext['inactive_timeout'] = 10;
76 76
 
77 77
 // The helper is crucial. Include it first thing.
78
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
78
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
79 79
     die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
80
+}
80 81
 
81 82
 require_once($upgrade_path . '/upgrade-helper.php');
82 83
 
@@ -100,11 +101,14 @@  discard block
 block discarded – undo
100 101
 	ini_set('default_socket_timeout', 900);
101 102
 }
102 103
 // Clean the upgrade path if this is from the client.
103
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
104
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
104
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
105
+	for ($i = 1;
106
+}
107
+$i < $_SERVER['argc']; $i++)
105 108
 	{
106
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
107
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
109
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
110
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
111
+		}
108 112
 	}
109 113
 
110 114
 // Are we from the client?
@@ -112,16 +116,17 @@  discard block
 block discarded – undo
112 116
 {
113 117
 	$command_line = true;
114 118
 	$disable_security = true;
115
-}
116
-else
119
+} else {
117 120
 	$command_line = false;
121
+}
118 122
 
119 123
 // Load this now just because we can.
120 124
 require_once($upgrade_path . '/Settings.php');
121 125
 
122 126
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
123
-if (isset($language))
127
+if (isset($language)) {
124 128
 	$language = str_ireplace('-utf8', '', $language);
129
+}
125 130
 
126 131
 // Are we logged in?
127 132
 if (isset($upgradeData))
@@ -129,10 +134,12 @@  discard block
 block discarded – undo
129 134
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
130 135
 
131 136
 	// Check for sensible values.
132
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
133
-		$upcontext['user']['started'] = time();
134
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
135
-		$upcontext['user']['updated'] = 0;
137
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
138
+			$upcontext['user']['started'] = time();
139
+	}
140
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
141
+			$upcontext['user']['updated'] = 0;
142
+	}
136 143
 
137 144
 	$upcontext['started'] = $upcontext['user']['started'];
138 145
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -190,8 +197,9 @@  discard block
 block discarded – undo
190 197
 			'db_error_skip' => true,
191 198
 		)
192 199
 	);
193
-	while ($row = $smcFunc['db_fetch_assoc']($request))
194
-		$modSettings[$row['variable']] = $row['value'];
200
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
201
+			$modSettings[$row['variable']] = $row['value'];
202
+	}
195 203
 	$smcFunc['db_free_result']($request);
196 204
 }
197 205
 
@@ -201,10 +209,12 @@  discard block
 block discarded – undo
201 209
 	$modSettings['theme_url'] = 'Themes/default';
202 210
 	$modSettings['images_url'] = 'Themes/default/images';
203 211
 }
204
-if (!isset($settings['default_theme_url']))
212
+if (!isset($settings['default_theme_url'])) {
205 213
 	$settings['default_theme_url'] = $modSettings['theme_url'];
206
-if (!isset($settings['default_theme_dir']))
214
+}
215
+if (!isset($settings['default_theme_dir'])) {
207 216
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
217
+}
208 218
 
209 219
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
210 220
 // Default title...
@@ -222,13 +232,15 @@  discard block
 block discarded – undo
222 232
 	$support_js = $upcontext['upgrade_status']['js'];
223 233
 
224 234
 	// Only set this if the upgrader status says so.
225
-	if (empty($is_debug))
226
-		$is_debug = $upcontext['upgrade_status']['debug'];
235
+	if (empty($is_debug)) {
236
+			$is_debug = $upcontext['upgrade_status']['debug'];
237
+	}
227 238
 
228 239
 	// Load the language.
229
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
230
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
231
-}
240
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
241
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
242
+	}
243
+	}
232 244
 // Set the defaults.
233 245
 else
234 246
 {
@@ -246,15 +258,18 @@  discard block
 block discarded – undo
246 258
 }
247 259
 
248 260
 // If this isn't the first stage see whether they are logging in and resuming.
249
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
261
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
250 262
 	checkLogin();
263
+}
251 264
 
252
-if ($command_line)
265
+if ($command_line) {
253 266
 	cmdStep0();
267
+}
254 268
 
255 269
 // Don't error if we're using xml.
256
-if (isset($_GET['xml']))
270
+if (isset($_GET['xml'])) {
257 271
 	$upcontext['return_error'] = true;
272
+}
258 273
 
259 274
 // Loop through all the steps doing each one as required.
260 275
 $upcontext['overall_percent'] = 0;
@@ -275,9 +290,9 @@  discard block
 block discarded – undo
275 290
 		}
276 291
 
277 292
 		// Call the step and if it returns false that means pause!
278
-		if (function_exists($step[2]) && $step[2]() === false)
279
-			break;
280
-		elseif (function_exists($step[2])) {
293
+		if (function_exists($step[2]) && $step[2]() === false) {
294
+					break;
295
+		} elseif (function_exists($step[2])) {
281 296
 			//Start each new step with this unset, so the 'normal' template is called first
282 297
 			unset($_GET['xml']);
283 298
 			//Clear out warnings at the start of each step
@@ -323,17 +338,18 @@  discard block
 block discarded – undo
323 338
 		// This should not happen my dear... HELP ME DEVELOPERS!!
324 339
 		if (!empty($command_line))
325 340
 		{
326
-			if (function_exists('debug_print_backtrace'))
327
-				debug_print_backtrace();
341
+			if (function_exists('debug_print_backtrace')) {
342
+							debug_print_backtrace();
343
+			}
328 344
 
329 345
 			echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
330 346
 			flush();
331 347
 			die();
332 348
 		}
333 349
 
334
-		if (!isset($_GET['xml']))
335
-			template_upgrade_above();
336
-		else
350
+		if (!isset($_GET['xml'])) {
351
+					template_upgrade_above();
352
+		} else
337 353
 		{
338 354
 			header('Content-Type: text/xml; charset=UTF-8');
339 355
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -355,25 +371,29 @@  discard block
 block discarded – undo
355 371
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
356 372
 
357 373
 			// Custom stuff to pass back?
358
-			if (!empty($upcontext['query_string']))
359
-				$upcontext['form_url'] .= $upcontext['query_string'];
374
+			if (!empty($upcontext['query_string'])) {
375
+							$upcontext['form_url'] .= $upcontext['query_string'];
376
+			}
360 377
 
361 378
 			// Call the appropriate subtemplate
362
-			if (is_callable('template_' . $upcontext['sub_template']))
363
-				call_user_func('template_' . $upcontext['sub_template']);
364
-			else
365
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
379
+			if (is_callable('template_' . $upcontext['sub_template'])) {
380
+							call_user_func('template_' . $upcontext['sub_template']);
381
+			} else {
382
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
383
+			}
366 384
 		}
367 385
 
368 386
 		// Was there an error?
369
-		if (!empty($upcontext['forced_error_message']))
370
-			echo $upcontext['forced_error_message'];
387
+		if (!empty($upcontext['forced_error_message'])) {
388
+					echo $upcontext['forced_error_message'];
389
+		}
371 390
 
372 391
 		// Show the footer.
373
-		if (!isset($_GET['xml']))
374
-			template_upgrade_below();
375
-		else
376
-			template_xml_below();
392
+		if (!isset($_GET['xml'])) {
393
+					template_upgrade_below();
394
+		} else {
395
+					template_xml_below();
396
+		}
377 397
 	}
378 398
 
379 399
 
@@ -385,15 +405,19 @@  discard block
 block discarded – undo
385 405
 		$seconds = intval($active % 60);
386 406
 
387 407
 		$totalTime = '';
388
-		if ($hours > 0)
389
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
390
-		if ($minutes > 0)
391
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
392
-		if ($seconds > 0)
393
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
408
+		if ($hours > 0) {
409
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
410
+		}
411
+		if ($minutes > 0) {
412
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
413
+		}
414
+		if ($seconds > 0) {
415
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
416
+		}
394 417
 
395
-		if (!empty($totalTime))
396
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
418
+		if (!empty($totalTime)) {
419
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
420
+		}
397 421
 	}
398 422
 
399 423
 	// Bang - gone!
@@ -406,8 +430,9 @@  discard block
 block discarded – undo
406 430
 	global $upgradeurl, $upcontext, $command_line;
407 431
 
408 432
 	// Command line users can't be redirected.
409
-	if ($command_line)
410
-		upgradeExit(true);
433
+	if ($command_line) {
434
+			upgradeExit(true);
435
+	}
411 436
 
412 437
 	// Are we providing the core info?
413 438
 	if ($addForm)
@@ -433,12 +458,14 @@  discard block
 block discarded – undo
433 458
 	define('SMF', 1);
434 459
 
435 460
 	// Start the session.
436
-	if (@ini_get('session.save_handler') == 'user')
437
-		@ini_set('session.save_handler', 'files');
461
+	if (@ini_get('session.save_handler') == 'user') {
462
+			@ini_set('session.save_handler', 'files');
463
+	}
438 464
 	@session_start();
439 465
 
440
-	if (empty($smcFunc))
441
-		$smcFunc = array();
466
+	if (empty($smcFunc)) {
467
+			$smcFunc = array();
468
+	}
442 469
 
443 470
 	// We need this for authentication and some upgrade code
444 471
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -465,24 +492,27 @@  discard block
 block discarded – undo
465 492
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
466 493
 
467 494
 		// Make the connection...
468
-		if (empty($db_connection))
469
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
470
-		else
471
-			// If we've returned here, ping/reconnect to be safe
495
+		if (empty($db_connection)) {
496
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
497
+		} else {
498
+					// If we've returned here, ping/reconnect to be safe
472 499
 			$smcFunc['db_ping']($db_connection);
500
+		}
473 501
 
474 502
 		// Oh dear god!!
475
-		if ($db_connection === null)
476
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
503
+		if ($db_connection === null) {
504
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
505
+		}
477 506
 
478
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
479
-			$smcFunc['db_query']('', '
507
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
508
+					$smcFunc['db_query']('', '
480 509
 			SET NAMES {string:db_character_set}',
481 510
 			array(
482 511
 				'db_error_skip' => true,
483 512
 				'db_character_set' => $db_character_set,
484 513
 			)
485 514
 		);
515
+		}
486 516
 
487 517
 		// Load the modSettings data...
488 518
 		$request = $smcFunc['db_query']('', '
@@ -493,11 +523,11 @@  discard block
 block discarded – undo
493 523
 			)
494 524
 		);
495 525
 		$modSettings = array();
496
-		while ($row = $smcFunc['db_fetch_assoc']($request))
497
-			$modSettings[$row['variable']] = $row['value'];
526
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
527
+					$modSettings[$row['variable']] = $row['value'];
528
+		}
498 529
 		$smcFunc['db_free_result']($request);
499
-	}
500
-	else
530
+	} else
501 531
 	{
502 532
 		return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.');
503 533
 	}
@@ -511,9 +541,10 @@  discard block
 block discarded – undo
511 541
 		cleanRequest();
512 542
 	}
513 543
 
514
-	if (!isset($_GET['substep']))
515
-		$_GET['substep'] = 0;
516
-}
544
+	if (!isset($_GET['substep'])) {
545
+			$_GET['substep'] = 0;
546
+	}
547
+	}
517 548
 
518 549
 function initialize_inputs()
519 550
 {
@@ -543,8 +574,9 @@  discard block
 block discarded – undo
543 574
 		$dh = opendir(dirname(__FILE__));
544 575
 		while ($file = readdir($dh))
545 576
 		{
546
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
547
-				@unlink(dirname(__FILE__) . '/' . $file);
577
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
578
+							@unlink(dirname(__FILE__) . '/' . $file);
579
+			}
548 580
 		}
549 581
 		closedir($dh);
550 582
 
@@ -573,8 +605,9 @@  discard block
 block discarded – undo
573 605
 	$temp = 'upgrade_php?step';
574 606
 	while (strlen($temp) > 4)
575 607
 	{
576
-		if (isset($_GET[$temp]))
577
-			unset($_GET[$temp]);
608
+		if (isset($_GET[$temp])) {
609
+					unset($_GET[$temp]);
610
+		}
578 611
 		$temp = substr($temp, 1);
579 612
 	}
580 613
 
@@ -601,32 +634,39 @@  discard block
 block discarded – undo
601 634
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
602 635
 
603 636
 	// Need legacy scripts?
604
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
605
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
606
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
607
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
608
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
609
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
637
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
638
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
639
+	}
640
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
641
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
642
+	}
643
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
644
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
645
+	}
610 646
 
611 647
 	// We don't need "-utf8" files anymore...
612 648
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
613 649
 
614 650
 	// This needs to exist!
615
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
616
-		return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
617
-	else
618
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
651
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
652
+			return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
653
+	} else {
654
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
655
+	}
619 656
 
620
-	if (!$check)
621
-		// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
657
+	if (!$check) {
658
+			// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
622 659
 		return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.');
660
+	}
623 661
 
624 662
 	// Do they meet the install requirements?
625
-	if (!php_version_check())
626
-		return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
663
+	if (!php_version_check()) {
664
+			return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
665
+	}
627 666
 
628
-	if (!db_version_check())
629
-		return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
667
+	if (!db_version_check()) {
668
+			return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
669
+	}
630 670
 
631 671
 	// Do some checks to make sure they have proper privileges
632 672
 	db_extend('packages');
@@ -641,14 +681,16 @@  discard block
 block discarded – undo
641 681
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
642 682
 
643 683
 	// Sorry... we need CREATE, ALTER and DROP
644
-	if (!$create || !$alter || !$drop)
645
-		return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
684
+	if (!$create || !$alter || !$drop) {
685
+			return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
686
+	}
646 687
 
647 688
 	// Do a quick version spot check.
648 689
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
649 690
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
650
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
651
-		return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
691
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
692
+			return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
693
+	}
652 694
 
653 695
 	// What absolutely needs to be writable?
654 696
 	$writable_files = array(
@@ -670,12 +712,13 @@  discard block
 block discarded – undo
670 712
 	quickFileWritable($custom_av_dir);
671 713
 
672 714
 	// Are we good now?
673
-	if (!is_writable($custom_av_dir))
674
-		return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
675
-	elseif ($need_settings_update)
715
+	if (!is_writable($custom_av_dir)) {
716
+			return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
717
+	} elseif ($need_settings_update)
676 718
 	{
677
-		if (!function_exists('cache_put_data'))
678
-			require_once($sourcedir . '/Load.php');
719
+		if (!function_exists('cache_put_data')) {
720
+					require_once($sourcedir . '/Load.php');
721
+		}
679 722
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
680 723
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
681 724
 	}
@@ -684,28 +727,33 @@  discard block
 block discarded – undo
684 727
 
685 728
 	// Check the cache directory.
686 729
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
687
-	if (!file_exists($cachedir_temp))
688
-		@mkdir($cachedir_temp);
689
-	if (!file_exists($cachedir_temp))
690
-		return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
691
-
692
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
693
-		return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
694
-	elseif (!isset($_GET['skiplang']))
730
+	if (!file_exists($cachedir_temp)) {
731
+			@mkdir($cachedir_temp);
732
+	}
733
+	if (!file_exists($cachedir_temp)) {
734
+			return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
735
+	}
736
+
737
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
738
+			return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
739
+	} elseif (!isset($_GET['skiplang']))
695 740
 	{
696 741
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
697 742
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
698 743
 
699
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
700
-			return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
744
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
745
+					return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
746
+		}
701 747
 	}
702 748
 
703
-	if (!makeFilesWritable($writable_files))
704
-		return false;
749
+	if (!makeFilesWritable($writable_files)) {
750
+			return false;
751
+	}
705 752
 
706 753
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
707
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
708
-		return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
754
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
755
+			return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
756
+	}
709 757
 
710 758
 	// Upgrade the agreement.
711 759
 	elseif (isset($modSettings['agreement']))
@@ -716,8 +764,8 @@  discard block
 block discarded – undo
716 764
 	}
717 765
 
718 766
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
719
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
720
-		$upcontext['warning'] = '
767
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
768
+			$upcontext['warning'] = '
721 769
 			It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to &quot;' . $boarddir . '&quot; but should probably be &quot;' . dirname(__FILE__) . '&quot;. Settings.php currently lists your paths as:<br>
722 770
 			<ul>
723 771
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -725,19 +773,23 @@  discard block
 block discarded – undo
725 773
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
726 774
 			</ul>
727 775
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
776
+	}
728 777
 
729 778
 	// Confirm mbstring is loaded...
730
-	if (!extension_loaded('mbstring'))
731
-		return throw_error($txt['install_no_mbstring']);
779
+	if (!extension_loaded('mbstring')) {
780
+			return throw_error($txt['install_no_mbstring']);
781
+	}
732 782
 
733 783
 	// Check for https stream support.
734 784
 	$supported_streams = stream_get_wrappers();
735
-	if (!in_array('https', $supported_streams))
736
-		$upcontext['custom_warning'] = $txt['install_no_https'];
785
+	if (!in_array('https', $supported_streams)) {
786
+			$upcontext['custom_warning'] = $txt['install_no_https'];
787
+	}
737 788
 
738 789
 	// Either we're logged in or we're going to present the login.
739
-	if (checkLogin())
740
-		return true;
790
+	if (checkLogin()) {
791
+			return true;
792
+	}
741 793
 
742 794
 	$upcontext += createToken('login');
743 795
 
@@ -751,15 +803,17 @@  discard block
 block discarded – undo
751 803
 	global $smcFunc, $db_type, $support_js;
752 804
 
753 805
 	// Don't bother if the security is disabled.
754
-	if ($disable_security)
755
-		return true;
806
+	if ($disable_security) {
807
+			return true;
808
+	}
756 809
 
757 810
 	// Are we trying to login?
758 811
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
759 812
 	{
760 813
 		// If we've disabled security pick a suitable name!
761
-		if (empty($_POST['user']))
762
-			$_POST['user'] = 'Administrator';
814
+		if (empty($_POST['user'])) {
815
+					$_POST['user'] = 'Administrator';
816
+		}
763 817
 
764 818
 		// Before 2.0 these column names were different!
765 819
 		$oldDB = false;
@@ -774,16 +828,17 @@  discard block
 block discarded – undo
774 828
 					'db_error_skip' => true,
775 829
 				)
776 830
 			);
777
-			if ($smcFunc['db_num_rows']($request) != 0)
778
-				$oldDB = true;
831
+			if ($smcFunc['db_num_rows']($request) != 0) {
832
+							$oldDB = true;
833
+			}
779 834
 			$smcFunc['db_free_result']($request);
780 835
 		}
781 836
 
782 837
 		// Get what we believe to be their details.
783 838
 		if (!$disable_security)
784 839
 		{
785
-			if ($oldDB)
786
-				$request = $smcFunc['db_query']('', '
840
+			if ($oldDB) {
841
+							$request = $smcFunc['db_query']('', '
787 842
 					SELECT id_member, memberName AS member_name, passwd, id_group,
788 843
 					additionalGroups AS additional_groups, lngfile
789 844
 					FROM {db_prefix}members
@@ -793,8 +848,8 @@  discard block
 block discarded – undo
793 848
 						'db_error_skip' => true,
794 849
 					)
795 850
 				);
796
-			else
797
-				$request = $smcFunc['db_query']('', '
851
+			} else {
852
+							$request = $smcFunc['db_query']('', '
798 853
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
799 854
 					FROM {db_prefix}members
800 855
 					WHERE member_name = {string:member_name}',
@@ -803,6 +858,7 @@  discard block
 block discarded – undo
803 858
 						'db_error_skip' => true,
804 859
 					)
805 860
 				);
861
+			}
806 862
 			if ($smcFunc['db_num_rows']($request) != 0)
807 863
 			{
808 864
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -810,16 +866,17 @@  discard block
 block discarded – undo
810 866
 				$groups = explode(',', $addGroups);
811 867
 				$groups[] = $id_group;
812 868
 
813
-				foreach ($groups as $k => $v)
814
-					$groups[$k] = (int) $v;
869
+				foreach ($groups as $k => $v) {
870
+									$groups[$k] = (int) $v;
871
+				}
815 872
 
816 873
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
817 874
 
818 875
 				// We don't use "-utf8" anymore...
819 876
 				$user_language = str_ireplace('-utf8', '', $user_language);
877
+			} else {
878
+							$upcontext['username_incorrect'] = true;
820 879
 			}
821
-			else
822
-				$upcontext['username_incorrect'] = true;
823 880
 			$smcFunc['db_free_result']($request);
824 881
 		}
825 882
 		$upcontext['username'] = $_POST['user'];
@@ -829,13 +886,14 @@  discard block
 block discarded – undo
829 886
 		{
830 887
 			$upcontext['upgrade_status']['js'] = 1;
831 888
 			$support_js = 1;
889
+		} else {
890
+					$support_js = 0;
832 891
 		}
833
-		else
834
-			$support_js = 0;
835 892
 
836 893
 		// Note down the version we are coming from.
837
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
838
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
894
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
895
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
896
+		}
839 897
 
840 898
 		// Didn't get anywhere?
841 899
 		if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect']))
@@ -869,15 +927,15 @@  discard block
 block discarded – undo
869 927
 							'db_error_skip' => true,
870 928
 						)
871 929
 					);
872
-					if ($smcFunc['db_num_rows']($request) == 0)
873
-						return throw_error('You need to be an admin to perform an upgrade!');
930
+					if ($smcFunc['db_num_rows']($request) == 0) {
931
+											return throw_error('You need to be an admin to perform an upgrade!');
932
+					}
874 933
 					$smcFunc['db_free_result']($request);
875 934
 				}
876 935
 
877 936
 				$upcontext['user']['id'] = $id_member;
878 937
 				$upcontext['user']['name'] = $name;
879
-			}
880
-			else
938
+			} else
881 939
 			{
882 940
 				$upcontext['user']['id'] = 1;
883 941
 				$upcontext['user']['name'] = 'Administrator';
@@ -893,11 +951,11 @@  discard block
 block discarded – undo
893 951
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
894 952
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
895 953
 
896
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
897
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
898
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
899
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
900
-				else
954
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
955
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
956
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
957
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
958
+				} else
901 959
 				{
902 960
 					// Set this as the new language.
903 961
 					$upcontext['language'] = $user_language;
@@ -941,8 +999,9 @@  discard block
 block discarded – undo
941 999
 	unset($member_columns);
942 1000
 
943 1001
 	// If we've not submitted then we're done.
944
-	if (empty($_POST['upcont']))
945
-		return false;
1002
+	if (empty($_POST['upcont'])) {
1003
+			return false;
1004
+	}
946 1005
 
947 1006
 	// Firstly, if they're enabling SM stat collection just do it.
948 1007
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -962,16 +1021,17 @@  discard block
 block discarded – undo
962 1021
 				fwrite($fp, $out);
963 1022
 
964 1023
 				$return_data = '';
965
-				while (!feof($fp))
966
-					$return_data .= fgets($fp, 128);
1024
+				while (!feof($fp)) {
1025
+									$return_data .= fgets($fp, 128);
1026
+				}
967 1027
 
968 1028
 				fclose($fp);
969 1029
 
970 1030
 				// Get the unique site ID.
971 1031
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
972 1032
 
973
-				if (!empty($ID[1]))
974
-					$smcFunc['db_insert']('replace',
1033
+				if (!empty($ID[1])) {
1034
+									$smcFunc['db_insert']('replace',
975 1035
 						$db_prefix . 'settings',
976 1036
 						array('variable' => 'string', 'value' => 'string'),
977 1037
 						array(
@@ -980,9 +1040,9 @@  discard block
 block discarded – undo
980 1040
 						),
981 1041
 						array('variable')
982 1042
 					);
1043
+				}
983 1044
 			}
984
-		}
985
-		else
1045
+		} else
986 1046
 		{
987 1047
 			$smcFunc['db_insert']('replace',
988 1048
 				$db_prefix . 'settings',
@@ -993,8 +1053,8 @@  discard block
 block discarded – undo
993 1053
 		}
994 1054
 	}
995 1055
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
996
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
997
-		$smcFunc['db_query']('', '
1056
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1057
+			$smcFunc['db_query']('', '
998 1058
 			DELETE FROM {db_prefix}settings
999 1059
 			WHERE variable = {string:enable_sm_stats}',
1000 1060
 			array(
@@ -1002,6 +1062,7 @@  discard block
 block discarded – undo
1002 1062
 				'db_error_skip' => true,
1003 1063
 			)
1004 1064
 		);
1065
+	}
1005 1066
 
1006 1067
 	// Deleting old karma stuff?
1007 1068
 	if (!empty($_POST['delete_karma']))
@@ -1016,20 +1077,22 @@  discard block
 block discarded – undo
1016 1077
 		);
1017 1078
 
1018 1079
 		// Cleaning up old karma member settings.
1019
-		if ($upcontext['karma_installed']['good'])
1020
-			$smcFunc['db_query']('', '
1080
+		if ($upcontext['karma_installed']['good']) {
1081
+					$smcFunc['db_query']('', '
1021 1082
 				ALTER TABLE {db_prefix}members
1022 1083
 				DROP karma_good',
1023 1084
 				array()
1024 1085
 			);
1086
+		}
1025 1087
 
1026 1088
 		// Does karma bad was enable?
1027
-		if ($upcontext['karma_installed']['bad'])
1028
-			$smcFunc['db_query']('', '
1089
+		if ($upcontext['karma_installed']['bad']) {
1090
+					$smcFunc['db_query']('', '
1029 1091
 				ALTER TABLE {db_prefix}members
1030 1092
 				DROP karma_bad',
1031 1093
 				array()
1032 1094
 			);
1095
+		}
1033 1096
 
1034 1097
 		// Cleaning up old karma permissions.
1035 1098
 		$smcFunc['db_query']('', '
@@ -1042,26 +1105,29 @@  discard block
 block discarded – undo
1042 1105
 	}
1043 1106
 
1044 1107
 	// Emptying the error log?
1045
-	if (!empty($_POST['empty_error']))
1046
-		$smcFunc['db_query']('truncate_table', '
1108
+	if (!empty($_POST['empty_error'])) {
1109
+			$smcFunc['db_query']('truncate_table', '
1047 1110
 			TRUNCATE {db_prefix}log_errors',
1048 1111
 			array(
1049 1112
 			)
1050 1113
 		);
1114
+	}
1051 1115
 
1052 1116
 	$changes = array();
1053 1117
 
1054 1118
 	// Add proxy settings.
1055
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1056
-		$changes += array(
1119
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1120
+			$changes += array(
1057 1121
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1058 1122
 			'image_proxy_maxsize' => 5190,
1059 1123
 			'image_proxy_enabled' => 0,
1060 1124
 		);
1125
+	}
1061 1126
 
1062 1127
 	// If we're overriding the language follow it through.
1063
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1064
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1128
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1129
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1130
+	}
1065 1131
 
1066 1132
 	if (!empty($_POST['maint']))
1067 1133
 	{
@@ -1073,26 +1139,29 @@  discard block
 block discarded – undo
1073 1139
 		{
1074 1140
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1075 1141
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1076
-		}
1077
-		else
1142
+		} else
1078 1143
 		{
1079 1144
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1080 1145
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1081 1146
 		}
1082 1147
 	}
1083 1148
 
1084
-	if ($command_line)
1085
-		echo ' * Updating Settings.php...';
1149
+	if ($command_line) {
1150
+			echo ' * Updating Settings.php...';
1151
+	}
1086 1152
 
1087 1153
 	// Fix some old paths.
1088
-	if (substr($boarddir, 0, 1) == '.')
1089
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1154
+	if (substr($boarddir, 0, 1) == '.') {
1155
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1156
+	}
1090 1157
 
1091
-	if (substr($sourcedir, 0, 1) == '.')
1092
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1158
+	if (substr($sourcedir, 0, 1) == '.') {
1159
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1160
+	}
1093 1161
 
1094
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1095
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1162
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1163
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1164
+	}
1096 1165
 
1097 1166
 	// If they have a "host:port" setup for the host, split that into separate values
1098 1167
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1103,32 +1172,36 @@  discard block
 block discarded – undo
1103 1172
 		$changes['db_server'] = '\'' . $db_server . '\'';
1104 1173
 
1105 1174
 		// Only set this if we're not using the default port
1106
-		if ($db_port != ini_get('mysqli.default_port'))
1107
-			$changes['db_port'] = (int) $db_port;
1108
-	}
1109
-	elseif (!empty($db_port))
1175
+		if ($db_port != ini_get('mysqli.default_port')) {
1176
+					$changes['db_port'] = (int) $db_port;
1177
+		}
1178
+	} elseif (!empty($db_port))
1110 1179
 	{
1111 1180
 		// If db_port is set and is the same as the default, set it to ''
1112 1181
 		if ($db_type == 'mysql')
1113 1182
 		{
1114
-			if ($db_port == ini_get('mysqli.default_port'))
1115
-				$changes['db_port'] = '\'\'';
1116
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1117
-				$changes['db_port'] = '\'\'';
1183
+			if ($db_port == ini_get('mysqli.default_port')) {
1184
+							$changes['db_port'] = '\'\'';
1185
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1186
+							$changes['db_port'] = '\'\'';
1187
+			}
1118 1188
 		}
1119 1189
 	}
1120 1190
 
1121 1191
 	// Maybe we haven't had this option yet?
1122
-	if (empty($packagesdir))
1123
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1192
+	if (empty($packagesdir)) {
1193
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1194
+	}
1124 1195
 
1125 1196
 	// Add support for $tasksdir var.
1126
-	if (empty($tasksdir))
1127
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1197
+	if (empty($tasksdir)) {
1198
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1199
+	}
1128 1200
 
1129 1201
 	// Make sure we fix the language as well.
1130
-	if (stristr($language, '-utf8'))
1131
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1202
+	if (stristr($language, '-utf8')) {
1203
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1204
+	}
1132 1205
 
1133 1206
 	// @todo Maybe change the cookie name if going to 1.1, too?
1134 1207
 
@@ -1136,8 +1209,9 @@  discard block
 block discarded – undo
1136 1209
 	require_once($sourcedir . '/Subs-Admin.php');
1137 1210
 	updateSettingsFile($changes);
1138 1211
 
1139
-	if ($command_line)
1140
-		echo ' Successful.' . "\n";
1212
+	if ($command_line) {
1213
+			echo ' Successful.' . "\n";
1214
+	}
1141 1215
 
1142 1216
 	// Are we doing debug?
1143 1217
 	if (isset($_POST['debug']))
@@ -1147,8 +1221,9 @@  discard block
 block discarded – undo
1147 1221
 	}
1148 1222
 
1149 1223
 	// If we're not backing up then jump one.
1150
-	if (empty($_POST['backup']))
1151
-		$upcontext['current_step']++;
1224
+	if (empty($_POST['backup'])) {
1225
+			$upcontext['current_step']++;
1226
+	}
1152 1227
 
1153 1228
 	// If we've got here then let's proceed to the next step!
1154 1229
 	return true;
@@ -1163,8 +1238,9 @@  discard block
 block discarded – undo
1163 1238
 	$upcontext['page_title'] = 'Backup Database';
1164 1239
 
1165 1240
 	// Done it already - js wise?
1166
-	if (!empty($_POST['backup_done']))
1167
-		return true;
1241
+	if (!empty($_POST['backup_done'])) {
1242
+			return true;
1243
+	}
1168 1244
 
1169 1245
 	// Some useful stuff here.
1170 1246
 	db_extend();
@@ -1178,9 +1254,10 @@  discard block
 block discarded – undo
1178 1254
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1179 1255
 
1180 1256
 	$table_names = array();
1181
-	foreach ($tables as $table)
1182
-		if (substr($table, 0, 7) !== 'backup_')
1257
+	foreach ($tables as $table) {
1258
+			if (substr($table, 0, 7) !== 'backup_')
1183 1259
 			$table_names[] = $table;
1260
+	}
1184 1261
 
1185 1262
 	$upcontext['table_count'] = count($table_names);
1186 1263
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1190,12 +1267,14 @@  discard block
 block discarded – undo
1190 1267
 	$file_steps = $upcontext['table_count'];
1191 1268
 
1192 1269
 	// What ones have we already done?
1193
-	foreach ($table_names as $id => $table)
1194
-		if ($id < $_GET['substep'])
1270
+	foreach ($table_names as $id => $table) {
1271
+			if ($id < $_GET['substep'])
1195 1272
 			$upcontext['previous_tables'][] = $table;
1273
+	}
1196 1274
 
1197
-	if ($command_line)
1198
-		echo 'Backing Up Tables.';
1275
+	if ($command_line) {
1276
+			echo 'Backing Up Tables.';
1277
+	}
1199 1278
 
1200 1279
 	// If we don't support javascript we backup here.
1201 1280
 	if (!$support_js || isset($_GET['xml']))
@@ -1214,8 +1293,9 @@  discard block
 block discarded – undo
1214 1293
 			backupTable($table_names[$substep]);
1215 1294
 
1216 1295
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1217
-			if (isset($_GET['xml']))
1218
-				return upgradeExit();
1296
+			if (isset($_GET['xml'])) {
1297
+							return upgradeExit();
1298
+			}
1219 1299
 		}
1220 1300
 
1221 1301
 		if ($command_line)
@@ -1248,9 +1328,10 @@  discard block
 block discarded – undo
1248 1328
 
1249 1329
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1250 1330
 
1251
-	if ($command_line)
1252
-		echo ' done.';
1253
-}
1331
+	if ($command_line) {
1332
+			echo ' done.';
1333
+	}
1334
+	}
1254 1335
 
1255 1336
 // Step 2: Everything.
1256 1337
 function DatabaseChanges()
@@ -1259,8 +1340,9 @@  discard block
 block discarded – undo
1259 1340
 	global $upcontext, $support_js, $db_type;
1260 1341
 
1261 1342
 	// Have we just completed this?
1262
-	if (!empty($_POST['database_done']))
1263
-		return true;
1343
+	if (!empty($_POST['database_done'])) {
1344
+			return true;
1345
+	}
1264 1346
 
1265 1347
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1266 1348
 	$upcontext['page_title'] = 'Database Changes';
@@ -1275,15 +1357,16 @@  discard block
 block discarded – undo
1275 1357
 	);
1276 1358
 
1277 1359
 	// How many files are there in total?
1278
-	if (isset($_GET['filecount']))
1279
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1280
-	else
1360
+	if (isset($_GET['filecount'])) {
1361
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1362
+	} else
1281 1363
 	{
1282 1364
 		$upcontext['file_count'] = 0;
1283 1365
 		foreach ($files as $file)
1284 1366
 		{
1285
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1286
-				$upcontext['file_count']++;
1367
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1368
+							$upcontext['file_count']++;
1369
+			}
1287 1370
 		}
1288 1371
 	}
1289 1372
 
@@ -1293,9 +1376,9 @@  discard block
 block discarded – undo
1293 1376
 	$upcontext['cur_file_num'] = 0;
1294 1377
 	foreach ($files as $file)
1295 1378
 	{
1296
-		if ($did_not_do)
1297
-			$did_not_do--;
1298
-		else
1379
+		if ($did_not_do) {
1380
+					$did_not_do--;
1381
+		} else
1299 1382
 		{
1300 1383
 			$upcontext['cur_file_num']++;
1301 1384
 			$upcontext['cur_file_name'] = $file[0];
@@ -1322,12 +1405,13 @@  discard block
 block discarded – undo
1322 1405
 					// Flag to move on to the next.
1323 1406
 					$upcontext['completed_step'] = true;
1324 1407
 					// Did we complete the whole file?
1325
-					if ($nextFile)
1326
-						$upcontext['current_debug_item_num'] = -1;
1408
+					if ($nextFile) {
1409
+											$upcontext['current_debug_item_num'] = -1;
1410
+					}
1327 1411
 					return upgradeExit();
1412
+				} elseif ($support_js) {
1413
+									break;
1328 1414
 				}
1329
-				elseif ($support_js)
1330
-					break;
1331 1415
 			}
1332 1416
 			// Set the progress bar to be right as if we had - even if we hadn't...
1333 1417
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1352,8 +1436,9 @@  discard block
 block discarded – undo
1352 1436
 	global $command_line, $language, $upcontext, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1353 1437
 
1354 1438
 	// Now it's nice to have some of the basic SMF source files.
1355
-	if (!isset($_GET['ssi']) && !$command_line)
1356
-		redirectLocation('&ssi=1');
1439
+	if (!isset($_GET['ssi']) && !$command_line) {
1440
+			redirectLocation('&ssi=1');
1441
+	}
1357 1442
 
1358 1443
 	$upcontext['sub_template'] = 'upgrade_complete';
1359 1444
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1369,14 +1454,16 @@  discard block
 block discarded – undo
1369 1454
 	// Are we in maintenance mode?
1370 1455
 	if (isset($upcontext['user']['main']))
1371 1456
 	{
1372
-		if ($command_line)
1373
-			echo ' * ';
1457
+		if ($command_line) {
1458
+					echo ' * ';
1459
+		}
1374 1460
 		$upcontext['removed_maintenance'] = true;
1375 1461
 		$changes['maintenance'] = $upcontext['user']['main'];
1376 1462
 	}
1377 1463
 	// Otherwise if somehow we are in 2 let's go to 1.
1378
-	elseif (!empty($maintenance) && $maintenance == 2)
1379
-		$changes['maintenance'] = 1;
1464
+	elseif (!empty($maintenance) && $maintenance == 2) {
1465
+			$changes['maintenance'] = 1;
1466
+	}
1380 1467
 
1381 1468
 	// Wipe this out...
1382 1469
 	$upcontext['user'] = array();
@@ -1391,9 +1478,9 @@  discard block
 block discarded – undo
1391 1478
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1392 1479
 
1393 1480
 	// Now is the perfect time to fetch the SM files.
1394
-	if ($command_line)
1395
-		cli_scheduled_fetchSMfiles();
1396
-	else
1481
+	if ($command_line) {
1482
+			cli_scheduled_fetchSMfiles();
1483
+	} else
1397 1484
 	{
1398 1485
 		require_once($sourcedir . '/ScheduledTasks.php');
1399 1486
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1401,8 +1488,9 @@  discard block
 block discarded – undo
1401 1488
 	}
1402 1489
 
1403 1490
 	// Log what we've done.
1404
-	if (empty($user_info['id']))
1405
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1491
+	if (empty($user_info['id'])) {
1492
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1493
+	}
1406 1494
 
1407 1495
 	// Log the action manually, so CLI still works.
1408 1496
 	$smcFunc['db_insert']('',
@@ -1421,8 +1509,9 @@  discard block
 block discarded – undo
1421 1509
 
1422 1510
 	// Save the current database version.
1423 1511
 	$server_version = $smcFunc['db_server_info']();
1424
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1425
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1512
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1513
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1514
+	}
1426 1515
 
1427 1516
 	if ($command_line)
1428 1517
 	{
@@ -1434,8 +1523,9 @@  discard block
 block discarded – undo
1434 1523
 
1435 1524
 	// Make sure it says we're done.
1436 1525
 	$upcontext['overall_percent'] = 100;
1437
-	if (isset($upcontext['step_progress']))
1438
-		unset($upcontext['step_progress']);
1526
+	if (isset($upcontext['step_progress'])) {
1527
+			unset($upcontext['step_progress']);
1528
+	}
1439 1529
 
1440 1530
 	$_GET['substep'] = 0;
1441 1531
 	return false;
@@ -1446,8 +1536,9 @@  discard block
 block discarded – undo
1446 1536
 {
1447 1537
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1448 1538
 
1449
-	if (empty($modSettings['time_format']))
1450
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1539
+	if (empty($modSettings['time_format'])) {
1540
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1541
+	}
1451 1542
 
1452 1543
 	// What files do we want to get
1453 1544
 	$request = $smcFunc['db_query']('', '
@@ -1481,8 +1572,9 @@  discard block
 block discarded – undo
1481 1572
 		$file_data = fetch_web_data($url);
1482 1573
 
1483 1574
 		// If we got an error - give up - the site might be down.
1484
-		if ($file_data === false)
1485
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1575
+		if ($file_data === false) {
1576
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1577
+		}
1486 1578
 
1487 1579
 		// Save the file to the database.
1488 1580
 		$smcFunc['db_query']('substring', '
@@ -1524,8 +1616,9 @@  discard block
 block discarded – undo
1524 1616
 	$themeData = array();
1525 1617
 	foreach ($values as $variable => $value)
1526 1618
 	{
1527
-		if (!isset($value) || $value === null)
1528
-			$value = 0;
1619
+		if (!isset($value) || $value === null) {
1620
+					$value = 0;
1621
+		}
1529 1622
 
1530 1623
 		$themeData[] = array(0, 1, $variable, $value);
1531 1624
 	}
@@ -1554,8 +1647,9 @@  discard block
 block discarded – undo
1554 1647
 
1555 1648
 	foreach ($values as $variable => $value)
1556 1649
 	{
1557
-		if (empty($modSettings[$value[0]]))
1558
-			continue;
1650
+		if (empty($modSettings[$value[0]])) {
1651
+					continue;
1652
+		}
1559 1653
 
1560 1654
 		$smcFunc['db_query']('', '
1561 1655
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1641,19 +1735,21 @@  discard block
 block discarded – undo
1641 1735
 	set_error_handler(
1642 1736
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1643 1737
 		{
1644
-			if ($support_js)
1645
-				return true;
1646
-			else
1647
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1738
+			if ($support_js) {
1739
+							return true;
1740
+			} else {
1741
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1742
+			}
1648 1743
 		}
1649 1744
 	);
1650 1745
 
1651 1746
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1652 1747
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1653
-	if ($db_type == 'mysql')
1654
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1655
-	else
1656
-		$db_collation = '';
1748
+	if ($db_type == 'mysql') {
1749
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1750
+	} else {
1751
+			$db_collation = '';
1752
+	}
1657 1753
 
1658 1754
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1659 1755
 
@@ -1665,8 +1761,9 @@  discard block
 block discarded – undo
1665 1761
 	$last_step = '';
1666 1762
 
1667 1763
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1668
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1669
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1764
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1765
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1766
+	}
1670 1767
 
1671 1768
 	// Count the total number of steps within this file - for progress.
1672 1769
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1686,15 +1783,18 @@  discard block
 block discarded – undo
1686 1783
 		$do_current = $substep >= $_GET['substep'];
1687 1784
 
1688 1785
 		// Get rid of any comments in the beginning of the line...
1689
-		if (substr(trim($line), 0, 2) === '/*')
1690
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1786
+		if (substr(trim($line), 0, 2) === '/*') {
1787
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1788
+		}
1691 1789
 
1692 1790
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1693
-		if ($is_debug && !$support_js && $command_line)
1694
-			flush();
1791
+		if ($is_debug && !$support_js && $command_line) {
1792
+					flush();
1793
+		}
1695 1794
 
1696
-		if (trim($line) === '')
1697
-			continue;
1795
+		if (trim($line) === '') {
1796
+					continue;
1797
+		}
1698 1798
 
1699 1799
 		if (trim(substr($line, 0, 3)) === '---')
1700 1800
 		{
@@ -1704,8 +1804,9 @@  discard block
 block discarded – undo
1704 1804
 			if (trim($current_data) != '' && $type !== '}')
1705 1805
 			{
1706 1806
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1707
-				if ($command_line)
1708
-					echo $upcontext['error_message'];
1807
+				if ($command_line) {
1808
+									echo $upcontext['error_message'];
1809
+				}
1709 1810
 			}
1710 1811
 
1711 1812
 			if ($type == ' ')
@@ -1723,17 +1824,18 @@  discard block
 block discarded – undo
1723 1824
 				if ($do_current)
1724 1825
 				{
1725 1826
 					$upcontext['actioned_items'][] = $last_step;
1726
-					if ($command_line)
1727
-						echo ' * ';
1827
+					if ($command_line) {
1828
+											echo ' * ';
1829
+					}
1728 1830
 				}
1729
-			}
1730
-			elseif ($type == '#')
1831
+			} elseif ($type == '#')
1731 1832
 			{
1732 1833
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1733 1834
 
1734 1835
 				$upcontext['current_debug_item_num']++;
1735
-				if (trim($line) != '---#')
1736
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1836
+				if (trim($line) != '---#') {
1837
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1838
+				}
1737 1839
 
1738 1840
 				// Have we already done something?
1739 1841
 				if (isset($_GET['xml']) && $done_something)
@@ -1744,34 +1846,36 @@  discard block
 block discarded – undo
1744 1846
 
1745 1847
 				if ($do_current)
1746 1848
 				{
1747
-					if (trim($line) == '---#' && $command_line)
1748
-						echo ' done.', $endl;
1749
-					elseif ($command_line)
1750
-						echo ' +++ ', rtrim(substr($line, 4));
1751
-					elseif (trim($line) != '---#')
1849
+					if (trim($line) == '---#' && $command_line) {
1850
+											echo ' done.', $endl;
1851
+					} elseif ($command_line) {
1852
+											echo ' +++ ', rtrim(substr($line, 4));
1853
+					} elseif (trim($line) != '---#')
1752 1854
 					{
1753
-						if ($is_debug)
1754
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1855
+						if ($is_debug) {
1856
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1857
+						}
1755 1858
 					}
1756 1859
 				}
1757 1860
 
1758 1861
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1759 1862
 				{
1760
-					if ($command_line)
1761
-						echo ' * ';
1762
-					else
1763
-						$upcontext['actioned_items'][] = $last_step;
1863
+					if ($command_line) {
1864
+											echo ' * ';
1865
+					} else {
1866
+											$upcontext['actioned_items'][] = $last_step;
1867
+					}
1764 1868
 				}
1765 1869
 
1766 1870
 				// Small step - only if we're actually doing stuff.
1767
-				if ($do_current)
1768
-					nextSubstep(++$substep);
1769
-				else
1770
-					$substep++;
1771
-			}
1772
-			elseif ($type == '{')
1773
-				$current_type = 'code';
1774
-			elseif ($type == '}')
1871
+				if ($do_current) {
1872
+									nextSubstep(++$substep);
1873
+				} else {
1874
+									$substep++;
1875
+				}
1876
+			} elseif ($type == '{') {
1877
+							$current_type = 'code';
1878
+			} elseif ($type == '}')
1775 1879
 			{
1776 1880
 				$current_type = 'sql';
1777 1881
 
@@ -1784,8 +1888,9 @@  discard block
 block discarded – undo
1784 1888
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1785 1889
 				{
1786 1890
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1787
-					if ($command_line)
1788
-						echo $upcontext['error_message'];
1891
+					if ($command_line) {
1892
+											echo $upcontext['error_message'];
1893
+					}
1789 1894
 				}
1790 1895
 
1791 1896
 				// Done with code!
@@ -1865,8 +1970,9 @@  discard block
 block discarded – undo
1865 1970
 	$db_unbuffered = false;
1866 1971
 
1867 1972
 	// Failure?!
1868
-	if ($result !== false)
1869
-		return $result;
1973
+	if ($result !== false) {
1974
+			return $result;
1975
+	}
1870 1976
 
1871 1977
 	$db_error_message = $smcFunc['db_error']($db_connection);
1872 1978
 	// If MySQL we do something more clever.
@@ -1894,54 +2000,61 @@  discard block
 block discarded – undo
1894 2000
 			{
1895 2001
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1896 2002
 				$result = mysqli_query($db_connection, $string);
1897
-				if ($result !== false)
1898
-					return $result;
2003
+				if ($result !== false) {
2004
+									return $result;
2005
+				}
1899 2006
 			}
1900
-		}
1901
-		elseif ($mysqli_errno == 2013)
2007
+		} elseif ($mysqli_errno == 2013)
1902 2008
 		{
1903 2009
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1904 2010
 			mysqli_select_db($db_connection, $db_name);
1905 2011
 			if ($db_connection)
1906 2012
 			{
1907 2013
 				$result = mysqli_query($db_connection, $string);
1908
-				if ($result !== false)
1909
-					return $result;
2014
+				if ($result !== false) {
2015
+									return $result;
2016
+				}
1910 2017
 			}
1911 2018
 		}
1912 2019
 		// Duplicate column name... should be okay ;).
1913
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1914
-			return false;
2020
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2021
+					return false;
2022
+		}
1915 2023
 		// Duplicate insert... make sure it's the proper type of query ;).
1916
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1917
-			return false;
2024
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2025
+					return false;
2026
+		}
1918 2027
 		// Creating an index on a non-existent column.
1919
-		elseif ($mysqli_errno == 1072)
1920
-			return false;
1921
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1922
-			return false;
2028
+		elseif ($mysqli_errno == 1072) {
2029
+					return false;
2030
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2031
+					return false;
2032
+		}
1923 2033
 	}
1924 2034
 	// If a table already exists don't go potty.
1925 2035
 	else
1926 2036
 	{
1927 2037
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1928 2038
 		{
1929
-			if (strpos($db_error_message, 'exist') !== false)
1930
-				return true;
1931
-		}
1932
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2039
+			if (strpos($db_error_message, 'exist') !== false) {
2040
+							return true;
2041
+			}
2042
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1933 2043
 		{
1934
-			if (strpos($db_error_message, 'duplicate') !== false)
1935
-				return true;
2044
+			if (strpos($db_error_message, 'duplicate') !== false) {
2045
+							return true;
2046
+			}
1936 2047
 		}
1937 2048
 	}
1938 2049
 
1939 2050
 	// Get the query string so we pass everything.
1940 2051
 	$query_string = '';
1941
-	foreach ($_GET as $k => $v)
1942
-		$query_string .= ';' . $k . '=' . $v;
1943
-	if (strlen($query_string) != 0)
1944
-		$query_string = '?' . substr($query_string, 1);
2052
+	foreach ($_GET as $k => $v) {
2053
+			$query_string .= ';' . $k . '=' . $v;
2054
+	}
2055
+	if (strlen($query_string) != 0) {
2056
+			$query_string = '?' . substr($query_string, 1);
2057
+	}
1945 2058
 
1946 2059
 	if ($command_line)
1947 2060
 	{
@@ -1996,16 +2109,18 @@  discard block
 block discarded – undo
1996 2109
 			{
1997 2110
 				$found |= 1;
1998 2111
 				// Do some checks on the data if we have it set.
1999
-				if (isset($change['col_type']))
2000
-					$found &= $change['col_type'] === $column['type'];
2001
-				if (isset($change['null_allowed']))
2002
-					$found &= $column['null'] == $change['null_allowed'];
2003
-				if (isset($change['default']))
2004
-					$found &= $change['default'] === $column['default'];
2112
+				if (isset($change['col_type'])) {
2113
+									$found &= $change['col_type'] === $column['type'];
2114
+				}
2115
+				if (isset($change['null_allowed'])) {
2116
+									$found &= $column['null'] == $change['null_allowed'];
2117
+				}
2118
+				if (isset($change['default'])) {
2119
+									$found &= $change['default'] === $column['default'];
2120
+				}
2005 2121
 			}
2006 2122
 		}
2007
-	}
2008
-	elseif ($change['type'] === 'index')
2123
+	} elseif ($change['type'] === 'index')
2009 2124
 	{
2010 2125
 		$request = upgrade_query('
2011 2126
 			SHOW INDEX
@@ -2014,9 +2129,10 @@  discard block
 block discarded – undo
2014 2129
 		{
2015 2130
 			$cur_index = array();
2016 2131
 
2017
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2018
-				if ($row['Key_name'] === $change['name'])
2132
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2133
+							if ($row['Key_name'] === $change['name'])
2019 2134
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2135
+			}
2020 2136
 
2021 2137
 			ksort($cur_index, SORT_NUMERIC);
2022 2138
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2026,14 +2142,17 @@  discard block
 block discarded – undo
2026 2142
 	}
2027 2143
 
2028 2144
 	// If we're trying to add and it's added, we're done.
2029
-	if ($found && in_array($change['method'], array('add', 'change')))
2030
-		return true;
2145
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2146
+			return true;
2147
+	}
2031 2148
 	// Otherwise if we're removing and it wasn't found we're also done.
2032
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2033
-		return true;
2149
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2150
+			return true;
2151
+	}
2034 2152
 	// Otherwise is it just a test?
2035
-	elseif ($is_test)
2036
-		return false;
2153
+	elseif ($is_test) {
2154
+			return false;
2155
+	}
2037 2156
 
2038 2157
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2039 2158
 	$running = false;
@@ -2044,8 +2163,9 @@  discard block
 block discarded – undo
2044 2163
 			SHOW FULL PROCESSLIST');
2045 2164
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2046 2165
 		{
2047
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2048
-				$found = true;
2166
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2167
+							$found = true;
2168
+			}
2049 2169
 		}
2050 2170
 
2051 2171
 		// Can't find it? Then we need to run it fools!
@@ -2057,8 +2177,9 @@  discard block
 block discarded – undo
2057 2177
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2058 2178
 				' . $change['text'], true) !== false;
2059 2179
 
2060
-			if (!$success)
2061
-				return false;
2180
+			if (!$success) {
2181
+							return false;
2182
+			}
2062 2183
 
2063 2184
 			// Return
2064 2185
 			$running = true;
@@ -2100,8 +2221,9 @@  discard block
 block discarded – undo
2100 2221
 			'db_error_skip' => true,
2101 2222
 		)
2102 2223
 	);
2103
-	if ($smcFunc['db_num_rows']($request) === 0)
2104
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2224
+	if ($smcFunc['db_num_rows']($request) === 0) {
2225
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2226
+	}
2105 2227
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2106 2228
 	$smcFunc['db_free_result']($request);
2107 2229
 
@@ -2123,18 +2245,19 @@  discard block
 block discarded – undo
2123 2245
 			)
2124 2246
 		);
2125 2247
 		// No results? Just forget it all together.
2126
-		if ($smcFunc['db_num_rows']($request) === 0)
2127
-			unset($table_row['Collation']);
2128
-		else
2129
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2248
+		if ($smcFunc['db_num_rows']($request) === 0) {
2249
+					unset($table_row['Collation']);
2250
+		} else {
2251
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2252
+		}
2130 2253
 		$smcFunc['db_free_result']($request);
2131 2254
 	}
2132 2255
 
2133 2256
 	if ($column_fix)
2134 2257
 	{
2135 2258
 		// Make sure there are no NULL's left.
2136
-		if ($null_fix)
2137
-			$smcFunc['db_query']('', '
2259
+		if ($null_fix) {
2260
+					$smcFunc['db_query']('', '
2138 2261
 				UPDATE {db_prefix}' . $change['table'] . '
2139 2262
 				SET ' . $change['column'] . ' = {string:default}
2140 2263
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2143,6 +2266,7 @@  discard block
 block discarded – undo
2143 2266
 					'db_error_skip' => true,
2144 2267
 				)
2145 2268
 			);
2269
+		}
2146 2270
 
2147 2271
 		// Do the actual alteration.
2148 2272
 		$smcFunc['db_query']('', '
@@ -2171,8 +2295,9 @@  discard block
 block discarded – undo
2171 2295
 	}
2172 2296
 
2173 2297
 	// Not a column we need to check on?
2174
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2175
-		return;
2298
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2299
+			return;
2300
+	}
2176 2301
 
2177 2302
 	// Break it up you (six|seven).
2178 2303
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2191,13 +2316,13 @@  discard block
 block discarded – undo
2191 2316
 				'new_name' => $temp[2],
2192 2317
 		));
2193 2318
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2194
-		if ($smcFunc['db_num_rows'] != 1)
2195
-			return;
2319
+		if ($smcFunc['db_num_rows'] != 1) {
2320
+					return;
2321
+		}
2196 2322
 
2197 2323
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2198 2324
 		$smcFunc['db_free_result']($request);
2199
-	}
2200
-	else
2325
+	} else
2201 2326
 	{
2202 2327
 		// Do this the old fashion, sure method way.
2203 2328
 		$request = $smcFunc['db_query']('', '
@@ -2208,21 +2333,24 @@  discard block
 block discarded – undo
2208 2333
 		));
2209 2334
 		// Mayday!
2210 2335
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2211
-		if ($smcFunc['db_num_rows'] == 0)
2212
-			return;
2336
+		if ($smcFunc['db_num_rows'] == 0) {
2337
+					return;
2338
+		}
2213 2339
 
2214 2340
 		// Oh where, oh where has my little field gone. Oh where can it be...
2215
-		while ($row = $smcFunc['db_query']($request))
2216
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2341
+		while ($row = $smcFunc['db_query']($request)) {
2342
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2217 2343
 			{
2218 2344
 				$current_type = $row['Type'];
2345
+		}
2219 2346
 				break;
2220 2347
 			}
2221 2348
 	}
2222 2349
 
2223 2350
 	// If this doesn't match, the column may of been altered for a reason.
2224
-	if (trim($current_type) != trim($temp[3]))
2225
-		$temp[3] = $current_type;
2351
+	if (trim($current_type) != trim($temp[3])) {
2352
+			$temp[3] = $current_type;
2353
+	}
2226 2354
 
2227 2355
 	// Piece this back together.
2228 2356
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2234,8 +2362,9 @@  discard block
 block discarded – undo
2234 2362
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2235 2363
 	global $step_progress, $is_debug, $upcontext;
2236 2364
 
2237
-	if ($_GET['substep'] < $substep)
2238
-		$_GET['substep'] = $substep;
2365
+	if ($_GET['substep'] < $substep) {
2366
+			$_GET['substep'] = $substep;
2367
+	}
2239 2368
 
2240 2369
 	if ($command_line)
2241 2370
 	{
@@ -2248,29 +2377,33 @@  discard block
 block discarded – undo
2248 2377
 	}
2249 2378
 
2250 2379
 	@set_time_limit(300);
2251
-	if (function_exists('apache_reset_timeout'))
2252
-		@apache_reset_timeout();
2380
+	if (function_exists('apache_reset_timeout')) {
2381
+			@apache_reset_timeout();
2382
+	}
2253 2383
 
2254
-	if (time() - $start_time <= $timeLimitThreshold)
2255
-		return;
2384
+	if (time() - $start_time <= $timeLimitThreshold) {
2385
+			return;
2386
+	}
2256 2387
 
2257 2388
 	// Do we have some custom step progress stuff?
2258 2389
 	if (!empty($step_progress))
2259 2390
 	{
2260 2391
 		$upcontext['substep_progress'] = 0;
2261 2392
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2262
-		if ($step_progress['current'] > $step_progress['total'])
2263
-			$upcontext['substep_progress'] = 99.9;
2264
-		else
2265
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2393
+		if ($step_progress['current'] > $step_progress['total']) {
2394
+					$upcontext['substep_progress'] = 99.9;
2395
+		} else {
2396
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2397
+		}
2266 2398
 
2267 2399
 		// Make it nicely rounded.
2268 2400
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2269 2401
 	}
2270 2402
 
2271 2403
 	// If this is XML we just exit right away!
2272
-	if (isset($_GET['xml']))
2273
-		return upgradeExit();
2404
+	if (isset($_GET['xml'])) {
2405
+			return upgradeExit();
2406
+	}
2274 2407
 
2275 2408
 	// We're going to pause after this!
2276 2409
 	$upcontext['pause'] = true;
@@ -2278,13 +2411,15 @@  discard block
 block discarded – undo
2278 2411
 	$upcontext['query_string'] = '';
2279 2412
 	foreach ($_GET as $k => $v)
2280 2413
 	{
2281
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2282
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2414
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2415
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2416
+		}
2283 2417
 	}
2284 2418
 
2285 2419
 	// Custom warning?
2286
-	if (!empty($custom_warning))
2287
-		$upcontext['custom_warning'] = $custom_warning;
2420
+	if (!empty($custom_warning)) {
2421
+			$upcontext['custom_warning'] = $custom_warning;
2422
+	}
2288 2423
 
2289 2424
 	upgradeExit();
2290 2425
 }
@@ -2299,25 +2434,26 @@  discard block
 block discarded – undo
2299 2434
 	ob_implicit_flush(true);
2300 2435
 	@set_time_limit(600);
2301 2436
 
2302
-	if (!isset($_SERVER['argv']))
2303
-		$_SERVER['argv'] = array();
2437
+	if (!isset($_SERVER['argv'])) {
2438
+			$_SERVER['argv'] = array();
2439
+	}
2304 2440
 	$_GET['maint'] = 1;
2305 2441
 
2306 2442
 	foreach ($_SERVER['argv'] as $i => $arg)
2307 2443
 	{
2308
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2309
-			$_GET['lang'] = $match[1];
2310
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2311
-			continue;
2312
-		elseif ($arg == '--no-maintenance')
2313
-			$_GET['maint'] = 0;
2314
-		elseif ($arg == '--debug')
2315
-			$is_debug = true;
2316
-		elseif ($arg == '--backup')
2317
-			$_POST['backup'] = 1;
2318
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2319
-			$_GET['conv'] = 1;
2320
-		elseif ($i != 0)
2444
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2445
+					$_GET['lang'] = $match[1];
2446
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2447
+					continue;
2448
+		} elseif ($arg == '--no-maintenance') {
2449
+					$_GET['maint'] = 0;
2450
+		} elseif ($arg == '--debug') {
2451
+					$is_debug = true;
2452
+		} elseif ($arg == '--backup') {
2453
+					$_POST['backup'] = 1;
2454
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2455
+					$_GET['conv'] = 1;
2456
+		} elseif ($i != 0)
2321 2457
 		{
2322 2458
 			echo 'SMF Command-line Upgrader
2323 2459
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2331,10 +2467,12 @@  discard block
 block discarded – undo
2331 2467
 		}
2332 2468
 	}
2333 2469
 
2334
-	if (!php_version_check())
2335
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2336
-	if (!db_version_check())
2337
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2470
+	if (!php_version_check()) {
2471
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2472
+	}
2473
+	if (!db_version_check()) {
2474
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2475
+	}
2338 2476
 
2339 2477
 	// Do some checks to make sure they have proper privileges
2340 2478
 	db_extend('packages');
@@ -2349,39 +2487,45 @@  discard block
 block discarded – undo
2349 2487
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2350 2488
 
2351 2489
 	// Sorry... we need CREATE, ALTER and DROP
2352
-	if (!$create || !$alter || !$drop)
2353
-		print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2490
+	if (!$create || !$alter || !$drop) {
2491
+			print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2492
+	}
2354 2493
 
2355 2494
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2356 2495
 		&& @file_exists($sourcedir . '/QueryString.php')
2357 2496
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2358
-	if (!$check && !isset($modSettings['smfVersion']))
2359
-		print_error('Error: Some files are missing or out-of-date.', true);
2497
+	if (!$check && !isset($modSettings['smfVersion'])) {
2498
+			print_error('Error: Some files are missing or out-of-date.', true);
2499
+	}
2360 2500
 
2361 2501
 	// Do a quick version spot check.
2362 2502
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2363 2503
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2364
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2365
-		print_error('Error: Some files have not yet been updated properly.');
2504
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2505
+			print_error('Error: Some files have not yet been updated properly.');
2506
+	}
2366 2507
 
2367 2508
 	// Make sure Settings.php is writable.
2368 2509
 	quickFileWritable($boarddir . '/Settings.php');
2369
-	if (!is_writable($boarddir . '/Settings.php'))
2370
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2510
+	if (!is_writable($boarddir . '/Settings.php')) {
2511
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2512
+	}
2371 2513
 
2372 2514
 	// Make sure Settings_bak.php is writable.
2373 2515
 	quickFileWritable($boarddir . '/Settings_bak.php');
2374
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2375
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2516
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2517
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2518
+	}
2376 2519
 
2377 2520
 	// Make sure db_last_error.php is writable.
2378 2521
 	quickFileWritable($boarddir . '/db_last_error.php');
2379
-	if (!is_writable($boarddir . '/db_last_error.php'))
2380
-		print_error('Error: Unable to obtain write access to "db_last_error.php".');
2522
+	if (!is_writable($boarddir . '/db_last_error.php')) {
2523
+			print_error('Error: Unable to obtain write access to "db_last_error.php".');
2524
+	}
2381 2525
 
2382
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2383
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2384
-	elseif (isset($modSettings['agreement']))
2526
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2527
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2528
+	} elseif (isset($modSettings['agreement']))
2385 2529
 	{
2386 2530
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2387 2531
 		fwrite($fp, $modSettings['agreement']);
@@ -2391,31 +2535,36 @@  discard block
 block discarded – undo
2391 2535
 	// Make sure Themes is writable.
2392 2536
 	quickFileWritable($modSettings['theme_dir']);
2393 2537
 
2394
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2395
-		print_error('Error: Unable to obtain write access to "Themes".');
2538
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2539
+			print_error('Error: Unable to obtain write access to "Themes".');
2540
+	}
2396 2541
 
2397 2542
 	// Make sure cache directory exists and is writable!
2398 2543
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2399
-	if (!file_exists($cachedir_temp))
2400
-		@mkdir($cachedir_temp);
2544
+	if (!file_exists($cachedir_temp)) {
2545
+			@mkdir($cachedir_temp);
2546
+	}
2401 2547
 
2402 2548
 	// Make sure the cache temp dir is writable.
2403 2549
 	quickFileWritable($cachedir_temp);
2404 2550
 
2405
-	if (!is_writable($cachedir_temp))
2406
-		print_error('Error: Unable to obtain write access to "cache".', true);
2551
+	if (!is_writable($cachedir_temp)) {
2552
+			print_error('Error: Unable to obtain write access to "cache".', true);
2553
+	}
2407 2554
 
2408
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2409
-		print_error('Error: Unable to find language files!', true);
2410
-	else
2555
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2556
+			print_error('Error: Unable to find language files!', true);
2557
+	} else
2411 2558
 	{
2412 2559
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2413 2560
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2414 2561
 
2415
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2416
-			print_error('Error: Language files out of date.', true);
2417
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2418
-			print_error('Error: Install language is missing for selected language.', true);
2562
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2563
+					print_error('Error: Language files out of date.', true);
2564
+		}
2565
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2566
+					print_error('Error: Install language is missing for selected language.', true);
2567
+		}
2419 2568
 
2420 2569
 		// Otherwise include it!
2421 2570
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2434,8 +2583,9 @@  discard block
 block discarded – undo
2434 2583
 	global $upcontext, $db_character_set, $sourcedir, $smcFunc, $modSettings, $language, $db_prefix, $db_type, $command_line, $support_js;
2435 2584
 
2436 2585
 	// Done it already?
2437
-	if (!empty($_POST['utf8_done']))
2438
-		return true;
2586
+	if (!empty($_POST['utf8_done'])) {
2587
+			return true;
2588
+	}
2439 2589
 
2440 2590
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2441 2591
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2448,8 +2598,7 @@  discard block
 block discarded – undo
2448 2598
 		);
2449 2599
 
2450 2600
 		return true;
2451
-	}
2452
-	else
2601
+	} else
2453 2602
 	{
2454 2603
 		$upcontext['page_title'] = 'Converting to UTF8';
2455 2604
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2493,8 +2642,9 @@  discard block
 block discarded – undo
2493 2642
 			)
2494 2643
 		);
2495 2644
 		$db_charsets = array();
2496
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2497
-			$db_charsets[] = $row['Charset'];
2645
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2646
+					$db_charsets[] = $row['Charset'];
2647
+		}
2498 2648
 
2499 2649
 		$smcFunc['db_free_result']($request);
2500 2650
 
@@ -2530,13 +2680,15 @@  discard block
 block discarded – undo
2530 2680
 		// If there's a fulltext index, we need to drop it first...
2531 2681
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2532 2682
 		{
2533
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2534
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2683
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2684
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2535 2685
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2686
+			}
2536 2687
 			$smcFunc['db_free_result']($request);
2537 2688
 
2538
-			if (isset($upcontext['fulltext_index']))
2539
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2689
+			if (isset($upcontext['fulltext_index'])) {
2690
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2691
+			}
2540 2692
 		}
2541 2693
 
2542 2694
 		// Drop it and make a note...
@@ -2726,8 +2878,9 @@  discard block
 block discarded – undo
2726 2878
 			$replace = '%field%';
2727 2879
 
2728 2880
 			// Build a huge REPLACE statement...
2729
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2730
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2881
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2882
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2883
+			}
2731 2884
 		}
2732 2885
 
2733 2886
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2737,9 +2890,10 @@  discard block
 block discarded – undo
2737 2890
 		$upcontext['table_count'] = count($queryTables);
2738 2891
 
2739 2892
 		// What ones have we already done?
2740
-		foreach ($queryTables as $id => $table)
2741
-			if ($id < $_GET['substep'])
2893
+		foreach ($queryTables as $id => $table) {
2894
+					if ($id < $_GET['substep'])
2742 2895
 				$upcontext['previous_tables'][] = $table;
2896
+		}
2743 2897
 
2744 2898
 		$upcontext['cur_table_num'] = $_GET['substep'];
2745 2899
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2776,8 +2930,9 @@  discard block
 block discarded – undo
2776 2930
 			nextSubstep($substep);
2777 2931
 
2778 2932
 			// Just to make sure it doesn't time out.
2779
-			if (function_exists('apache_reset_timeout'))
2780
-				@apache_reset_timeout();
2933
+			if (function_exists('apache_reset_timeout')) {
2934
+							@apache_reset_timeout();
2935
+			}
2781 2936
 
2782 2937
 			$table_charsets = array();
2783 2938
 
@@ -2800,8 +2955,9 @@  discard block
 block discarded – undo
2800 2955
 
2801 2956
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2802 2957
 						if ($charset != 'utf8') {
2803
-							if (!isset($table_charsets[$charset]))
2804
-								$table_charsets[$charset] = array();
2958
+							if (!isset($table_charsets[$charset])) {
2959
+															$table_charsets[$charset] = array();
2960
+							}
2805 2961
 
2806 2962
 							$table_charsets[$charset][] = $column_info;
2807 2963
 						}
@@ -2842,10 +2998,11 @@  discard block
 block discarded – undo
2842 2998
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2843 2999
 				{
2844 3000
 					$update = '';
2845
-					foreach ($table_charsets as $charset => $columns)
2846
-						foreach ($columns as $column)
3001
+					foreach ($table_charsets as $charset => $columns) {
3002
+											foreach ($columns as $column)
2847 3003
 							$update .= '
2848 3004
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3005
+					}
2849 3006
 
2850 3007
 					$smcFunc['db_query']('', '
2851 3008
 						UPDATE {raw:table_name}
@@ -2870,8 +3027,9 @@  discard block
 block discarded – undo
2870 3027
 			// Now do the actual conversion (if still needed).
2871 3028
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2872 3029
 			{
2873
-				if ($command_line)
2874
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3030
+				if ($command_line) {
3031
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3032
+				}
2875 3033
 
2876 3034
 				$smcFunc['db_query']('', '
2877 3035
 					ALTER TABLE {raw:table_name}
@@ -2881,12 +3039,14 @@  discard block
 block discarded – undo
2881 3039
 					)
2882 3040
 				);
2883 3041
 
2884
-				if ($command_line)
2885
-					echo " done.\n";
3042
+				if ($command_line) {
3043
+									echo " done.\n";
3044
+				}
2886 3045
 			}
2887 3046
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2888
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
2889
-				return upgradeExit();
3047
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3048
+							return upgradeExit();
3049
+			}
2890 3050
 		}
2891 3051
 
2892 3052
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -2915,8 +3075,8 @@  discard block
 block discarded – undo
2915 3075
 		);
2916 3076
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2917 3077
 		{
2918
-			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1)
2919
-				$smcFunc['db_query']('', '
3078
+			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) {
3079
+							$smcFunc['db_query']('', '
2920 3080
 					UPDATE {db_prefix}log_actions
2921 3081
 					SET extra = {string:extra}
2922 3082
 					WHERE id_action = {int:current_action}',
@@ -2925,6 +3085,7 @@  discard block
 block discarded – undo
2925 3085
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2926 3086
 					)
2927 3087
 				);
3088
+			}
2928 3089
 		}
2929 3090
 		$smcFunc['db_free_result']($request);
2930 3091
 
@@ -2946,15 +3107,17 @@  discard block
 block discarded – undo
2946 3107
 	// First thing's first - did we already do this?
2947 3108
 	if (!empty($modSettings['json_done']))
2948 3109
 	{
2949
-		if ($command_line)
2950
-			return DeleteUpgrade();
2951
-		else
2952
-			return true;
3110
+		if ($command_line) {
3111
+					return DeleteUpgrade();
3112
+		} else {
3113
+					return true;
3114
+		}
2953 3115
 	}
2954 3116
 
2955 3117
 	// Done it already - js wise?
2956
-	if (!empty($_POST['json_done']))
2957
-		return true;
3118
+	if (!empty($_POST['json_done'])) {
3119
+			return true;
3120
+	}
2958 3121
 
2959 3122
 	// List of tables affected by this function
2960 3123
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2986,12 +3149,14 @@  discard block
 block discarded – undo
2986 3149
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2987 3150
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2988 3151
 
2989
-	foreach ($keys as $id => $table)
2990
-		if ($id < $_GET['substep'])
3152
+	foreach ($keys as $id => $table) {
3153
+			if ($id < $_GET['substep'])
2991 3154
 			$upcontext['previous_tables'][] = $table;
3155
+	}
2992 3156
 
2993
-	if ($command_line)
2994
-		echo 'Converting data from serialize() to json_encode().';
3157
+	if ($command_line) {
3158
+			echo 'Converting data from serialize() to json_encode().';
3159
+	}
2995 3160
 
2996 3161
 	if (!$support_js || isset($_GET['xml']))
2997 3162
 	{
@@ -3031,8 +3196,9 @@  discard block
 block discarded – undo
3031 3196
 
3032 3197
 				// Loop through and fix these...
3033 3198
 				$new_settings = array();
3034
-				if ($command_line)
3035
-					echo "\n" . 'Fixing some settings...';
3199
+				if ($command_line) {
3200
+									echo "\n" . 'Fixing some settings...';
3201
+				}
3036 3202
 
3037 3203
 				foreach ($serialized_settings as $var)
3038 3204
 				{
@@ -3040,22 +3206,24 @@  discard block
 block discarded – undo
3040 3206
 					{
3041 3207
 						// Attempt to unserialize the setting
3042 3208
 						$temp = @safe_unserialize($modSettings[$var]);
3043
-						if (!$temp && $command_line)
3044
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3045
-						elseif ($temp !== false)
3046
-							$new_settings[$var] = json_encode($temp);
3209
+						if (!$temp && $command_line) {
3210
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3211
+						} elseif ($temp !== false) {
3212
+													$new_settings[$var] = json_encode($temp);
3213
+						}
3047 3214
 					}
3048 3215
 				}
3049 3216
 
3050 3217
 				// Update everything at once
3051
-				if (!function_exists('cache_put_data'))
3052
-					require_once($sourcedir . '/Load.php');
3218
+				if (!function_exists('cache_put_data')) {
3219
+									require_once($sourcedir . '/Load.php');
3220
+				}
3053 3221
 				updateSettings($new_settings, true);
3054 3222
 
3055
-				if ($command_line)
3056
-					echo ' done.';
3057
-			}
3058
-			elseif ($table == 'themes')
3223
+				if ($command_line) {
3224
+									echo ' done.';
3225
+				}
3226
+			} elseif ($table == 'themes')
3059 3227
 			{
3060 3228
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3061 3229
 				$query = $smcFunc['db_query']('', '
@@ -3074,10 +3242,11 @@  discard block
 block discarded – undo
3074 3242
 
3075 3243
 						if ($command_line)
3076 3244
 						{
3077
-							if ($temp === false)
3078
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3079
-							else
3080
-								echo "\n" . 'Fixing admin preferences...';
3245
+							if ($temp === false) {
3246
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3247
+							} else {
3248
+															echo "\n" . 'Fixing admin preferences...';
3249
+							}
3081 3250
 						}
3082 3251
 
3083 3252
 						if ($temp !== false)
@@ -3099,15 +3268,15 @@  discard block
 block discarded – undo
3099 3268
 								)
3100 3269
 							);
3101 3270
 
3102
-							if ($command_line)
3103
-								echo ' done.';
3271
+							if ($command_line) {
3272
+															echo ' done.';
3273
+							}
3104 3274
 						}
3105 3275
 					}
3106 3276
 
3107 3277
 					$smcFunc['db_free_result']($query);
3108 3278
 				}
3109
-			}
3110
-			else
3279
+			} else
3111 3280
 			{
3112 3281
 				// First item is always the key...
3113 3282
 				$key = $info[0];
@@ -3118,8 +3287,7 @@  discard block
 block discarded – undo
3118 3287
 				{
3119 3288
 					$col_select = $info[1];
3120 3289
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3121
-				}
3122
-				else
3290
+				} else
3123 3291
 				{
3124 3292
 					$col_select = implode(', ', $info);
3125 3293
 				}
@@ -3152,8 +3320,7 @@  discard block
 block discarded – undo
3152 3320
 								if ($temp === false && $command_line)
3153 3321
 								{
3154 3322
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3155
-								}
3156
-								else
3323
+								} else
3157 3324
 								{
3158 3325
 									$row[$col] = json_encode($temp);
3159 3326
 
@@ -3178,16 +3345,18 @@  discard block
 block discarded – undo
3178 3345
 						}
3179 3346
 					}
3180 3347
 
3181
-					if ($command_line)
3182
-						echo ' done.';
3348
+					if ($command_line) {
3349
+											echo ' done.';
3350
+					}
3183 3351
 
3184 3352
 					// Free up some memory...
3185 3353
 					$smcFunc['db_free_result']($query);
3186 3354
 				}
3187 3355
 			}
3188 3356
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3189
-			if (isset($_GET['xml']))
3190
-				return upgradeExit();
3357
+			if (isset($_GET['xml'])) {
3358
+							return upgradeExit();
3359
+			}
3191 3360
 		}
3192 3361
 
3193 3362
 		if ($command_line)
@@ -3202,8 +3371,9 @@  discard block
 block discarded – undo
3202 3371
 
3203 3372
 		$_GET['substep'] = 0;
3204 3373
 		// Make sure we move on!
3205
-		if ($command_line)
3206
-			return DeleteUpgrade();
3374
+		if ($command_line) {
3375
+					return DeleteUpgrade();
3376
+		}
3207 3377
 
3208 3378
 		return true;
3209 3379
 	}
@@ -3223,14 +3393,16 @@  discard block
 block discarded – undo
3223 3393
 	global $upcontext, $txt, $settings;
3224 3394
 
3225 3395
 	// Don't call me twice!
3226
-	if (!empty($upcontext['chmod_called']))
3227
-		return;
3396
+	if (!empty($upcontext['chmod_called'])) {
3397
+			return;
3398
+	}
3228 3399
 
3229 3400
 	$upcontext['chmod_called'] = true;
3230 3401
 
3231 3402
 	// Nothing?
3232
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3233
-		return;
3403
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3404
+			return;
3405
+	}
3234 3406
 
3235 3407
 	// Was it a problem with Windows?
3236 3408
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3262,11 +3434,12 @@  discard block
 block discarded – undo
3262 3434
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>The following files needs to be made writable to continue:</h4>\n\t\t\t\');
3263 3435
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3264 3436
 
3265
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3266
-		echo '
3437
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3438
+			echo '
3267 3439
 					content.write(\'<hr>\n\t\t\t\');
3268 3440
 					content.write(\'<p>If you have a shell account, the convenient below command can automatically correct permissions on these files</p>\n\t\t\t\');
3269 3441
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3442
+	}
3270 3443
 
3271 3444
 	echo '
3272 3445
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3274,17 +3447,19 @@  discard block
 block discarded – undo
3274 3447
 				}
3275 3448
 			</script>';
3276 3449
 
3277
-	if (!empty($upcontext['chmod']['ftp_error']))
3278
-		echo '
3450
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3451
+			echo '
3279 3452
 			<div class="error_message red">
3280 3453
 				The following error was encountered when trying to connect:<br><br>
3281 3454
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3282 3455
 			</div>
3283 3456
 			<br>';
3457
+	}
3284 3458
 
3285
-	if (empty($upcontext['chmod_in_form']))
3286
-		echo '
3459
+	if (empty($upcontext['chmod_in_form'])) {
3460
+			echo '
3287 3461
 	<form action="', $upcontext['form_url'], '" method="post">';
3462
+	}
3288 3463
 
3289 3464
 	echo '
3290 3465
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3319,10 +3494,11 @@  discard block
 block discarded – undo
3319 3494
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3320 3495
 	</div>';
3321 3496
 
3322
-	if (empty($upcontext['chmod_in_form']))
3323
-		echo '
3497
+	if (empty($upcontext['chmod_in_form'])) {
3498
+			echo '
3324 3499
 	</form>';
3325
-}
3500
+	}
3501
+	}
3326 3502
 
3327 3503
 function template_upgrade_above()
3328 3504
 {
@@ -3382,9 +3558,10 @@  discard block
 block discarded – undo
3382 3558
 				<h2>', $txt['upgrade_progress'], '</h2>
3383 3559
 				<ul>';
3384 3560
 
3385
-	foreach ($upcontext['steps'] as $num => $step)
3386
-		echo '
3561
+	foreach ($upcontext['steps'] as $num => $step) {
3562
+			echo '
3387 3563
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3564
+	}
3388 3565
 
3389 3566
 	echo '
3390 3567
 					</ul>
@@ -3397,8 +3574,8 @@  discard block
 block discarded – undo
3397 3574
 				</div>
3398 3575
 			</div>';
3399 3576
 
3400
-	if (isset($upcontext['step_progress']))
3401
-		echo '
3577
+	if (isset($upcontext['step_progress'])) {
3578
+			echo '
3402 3579
 				<br>
3403 3580
 				<br>
3404 3581
 				<div id="progress_bar_step">
@@ -3407,6 +3584,7 @@  discard block
 block discarded – undo
3407 3584
 						<span>', $txt['upgrade_step_progress'], '</span>
3408 3585
 					</div>
3409 3586
 				</div>';
3587
+	}
3410 3588
 
3411 3589
 	echo '
3412 3590
 				<div id="substep_bar_div" class="smalltext" style="float: left;width: 50%;margin-top: 0.6em;display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div>
@@ -3437,32 +3615,36 @@  discard block
 block discarded – undo
3437 3615
 {
3438 3616
 	global $upcontext, $txt;
3439 3617
 
3440
-	if (!empty($upcontext['pause']))
3441
-		echo '
3618
+	if (!empty($upcontext['pause'])) {
3619
+			echo '
3442 3620
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3443 3621
 
3444 3622
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3445 3623
 								<h3>
3446 3624
 									', $txt['upgrade_paused_overload'], '
3447 3625
 								</h3>';
3626
+	}
3448 3627
 
3449
-	if (!empty($upcontext['custom_warning']))
3450
-		echo '
3628
+	if (!empty($upcontext['custom_warning'])) {
3629
+			echo '
3451 3630
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3452 3631
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3453 3632
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3454 3633
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3455 3634
 								</div>';
3635
+	}
3456 3636
 
3457 3637
 	echo '
3458 3638
 								<div class="righttext" style="margin: 1ex;">';
3459 3639
 
3460
-	if (!empty($upcontext['continue']))
3461
-		echo '
3640
+	if (!empty($upcontext['continue'])) {
3641
+			echo '
3462 3642
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3463
-	if (!empty($upcontext['skip']))
3464
-		echo '
3643
+	}
3644
+	if (!empty($upcontext['skip'])) {
3645
+			echo '
3465 3646
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3647
+	}
3466 3648
 
3467 3649
 	echo '
3468 3650
 								</div>
@@ -3512,11 +3694,12 @@  discard block
 block discarded – undo
3512 3694
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3513 3695
 	<smf>';
3514 3696
 
3515
-	if (!empty($upcontext['get_data']))
3516
-		foreach ($upcontext['get_data'] as $k => $v)
3697
+	if (!empty($upcontext['get_data'])) {
3698
+			foreach ($upcontext['get_data'] as $k => $v)
3517 3699
 			echo '
3518 3700
 		<get key="', $k, '">', $v, '</get>';
3519
-}
3701
+	}
3702
+	}
3520 3703
 
3521 3704
 function template_xml_below()
3522 3705
 {
@@ -3557,8 +3740,8 @@  discard block
 block discarded – undo
3557 3740
 	template_chmod();
3558 3741
 
3559 3742
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3560
-	if ($upcontext['is_large_forum'])
3561
-		echo '
3743
+	if ($upcontext['is_large_forum']) {
3744
+			echo '
3562 3745
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3563 3746
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3564 3747
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3566,10 +3749,11 @@  discard block
 block discarded – undo
3566 3749
 				', $txt['upgrade_warning_lots_data'], '
3567 3750
 			</div>
3568 3751
 		</div>';
3752
+	}
3569 3753
 
3570 3754
 	// A warning message?
3571
-	if (!empty($upcontext['warning']))
3572
-		echo '
3755
+	if (!empty($upcontext['warning'])) {
3756
+			echo '
3573 3757
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3574 3758
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3575 3759
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3577,6 +3761,7 @@  discard block
 block discarded – undo
3577 3761
 				', $upcontext['warning'], '
3578 3762
 			</div>
3579 3763
 		</div>';
3764
+	}
3580 3765
 
3581 3766
 	// Paths are incorrect?
3582 3767
 	echo '
@@ -3592,20 +3777,22 @@  discard block
 block discarded – undo
3592 3777
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3593 3778
 	{
3594 3779
 		$ago = time() - $upcontext['started'];
3595
-		if ($ago < 60)
3596
-			$ago = $ago . ' seconds';
3597
-		elseif ($ago < 3600)
3598
-			$ago = (int) ($ago / 60) . ' minutes';
3599
-		else
3600
-			$ago = (int) ($ago / 3600) . ' hours';
3780
+		if ($ago < 60) {
3781
+					$ago = $ago . ' seconds';
3782
+		} elseif ($ago < 3600) {
3783
+					$ago = (int) ($ago / 60) . ' minutes';
3784
+		} else {
3785
+					$ago = (int) ($ago / 3600) . ' hours';
3786
+		}
3601 3787
 
3602 3788
 		$active = time() - $upcontext['updated'];
3603
-		if ($active < 60)
3604
-			$updated = $active . ' seconds';
3605
-		elseif ($active < 3600)
3606
-			$updated = (int) ($active / 60) . ' minutes';
3607
-		else
3608
-			$updated = (int) ($active / 3600) . ' hours';
3789
+		if ($active < 60) {
3790
+					$updated = $active . ' seconds';
3791
+		} elseif ($active < 3600) {
3792
+					$updated = (int) ($active / 60) . ' minutes';
3793
+		} else {
3794
+					$updated = (int) ($active / 3600) . ' hours';
3795
+		}
3609 3796
 
3610 3797
 		echo '
3611 3798
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3614,16 +3801,18 @@  discard block
 block discarded – undo
3614 3801
 			<div style="padding-left: 6ex;">
3615 3802
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3616 3803
 
3617
-		if ($active < 600)
3618
-			echo '
3804
+		if ($active < 600) {
3805
+					echo '
3619 3806
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3807
+		}
3620 3808
 
3621
-		if ($active > $upcontext['inactive_timeout'])
3622
-			echo '
3809
+		if ($active > $upcontext['inactive_timeout']) {
3810
+					echo '
3623 3811
 				<br><br>You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.';
3624
-		else
3625
-			echo '
3812
+		} else {
3813
+					echo '
3626 3814
 				<br><br>This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3815
+		}
3627 3816
 
3628 3817
 		echo '
3629 3818
 			</div>
@@ -3639,9 +3828,10 @@  discard block
 block discarded – undo
3639 3828
 					<td>
3640 3829
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3641 3830
 
3642
-	if (!empty($upcontext['username_incorrect']))
3643
-		echo '
3831
+	if (!empty($upcontext['username_incorrect'])) {
3832
+			echo '
3644 3833
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3834
+	}
3645 3835
 
3646 3836
 	echo '
3647 3837
 					</td>
@@ -3652,9 +3842,10 @@  discard block
 block discarded – undo
3652 3842
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3653 3843
 						<input type="hidden" name="hash_passwrd" value="">';
3654 3844
 
3655
-	if (!empty($upcontext['password_failed']))
3656
-		echo '
3845
+	if (!empty($upcontext['password_failed'])) {
3846
+			echo '
3657 3847
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3848
+	}
3658 3849
 
3659 3850
 	echo '
3660 3851
 					</td>
@@ -3725,8 +3916,8 @@  discard block
 block discarded – undo
3725 3916
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3726 3917
 
3727 3918
 	// Warning message?
3728
-	if (!empty($upcontext['upgrade_options_warning']))
3729
-		echo '
3919
+	if (!empty($upcontext['upgrade_options_warning'])) {
3920
+			echo '
3730 3921
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3731 3922
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3732 3923
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3734,6 +3925,7 @@  discard block
 block discarded – undo
3734 3925
 				', $upcontext['upgrade_options_warning'], '
3735 3926
 			</div>
3736 3927
 		</div>';
3928
+	}
3737 3929
 
3738 3930
 	echo '
3739 3931
 				<table>
@@ -3776,8 +3968,8 @@  discard block
 block discarded – undo
3776 3968
 						</td>
3777 3969
 					</tr>';
3778 3970
 
3779
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3780
-		echo '
3971
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3972
+			echo '
3781 3973
 					<tr valign="top">
3782 3974
 						<td width="2%">
3783 3975
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3786,6 +3978,7 @@  discard block
 block discarded – undo
3786 3978
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3787 3979
 						</td>
3788 3980
 					</tr>';
3981
+	}
3789 3982
 
3790 3983
 	echo '
3791 3984
 					<tr valign="top">
@@ -3823,10 +4016,11 @@  discard block
 block discarded – undo
3823 4016
 			</div>';
3824 4017
 
3825 4018
 	// Dont any tables so far?
3826
-	if (!empty($upcontext['previous_tables']))
3827
-		foreach ($upcontext['previous_tables'] as $table)
4019
+	if (!empty($upcontext['previous_tables'])) {
4020
+			foreach ($upcontext['previous_tables'] as $table)
3828 4021
 			echo '
3829 4022
 			<br>Completed Table: &quot;', $table, '&quot;.';
4023
+	}
3830 4024
 
3831 4025
 	echo '
3832 4026
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3863,12 +4057,13 @@  discard block
 block discarded – undo
3863 4057
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3864 4058
 
3865 4059
 		// If debug flood the screen.
3866
-		if ($is_debug)
3867
-			echo '
4060
+		if ($is_debug) {
4061
+					echo '
3868 4062
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3869 4063
 
3870 4064
 				if (document.getElementById(\'debug_section\').scrollHeight)
3871 4065
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4066
+		}
3872 4067
 
3873 4068
 		echo '
3874 4069
 				// Get the next update...
@@ -3901,8 +4096,9 @@  discard block
 block discarded – undo
3901 4096
 {
3902 4097
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3903 4098
 
3904
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3905
-		$is_debug = true;
4099
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4100
+			$is_debug = true;
4101
+	}
3906 4102
 
3907 4103
 	echo '
3908 4104
 		<h3>Executing database changes</h3>
@@ -3917,8 +4113,9 @@  discard block
 block discarded – undo
3917 4113
 	{
3918 4114
 		foreach ($upcontext['actioned_items'] as $num => $item)
3919 4115
 		{
3920
-			if ($num != 0)
3921
-				echo ' Successful!';
4116
+			if ($num != 0) {
4117
+							echo ' Successful!';
4118
+			}
3922 4119
 			echo '<br>' . $item;
3923 4120
 		}
3924 4121
 		if (!empty($upcontext['changes_complete']))
@@ -3931,28 +4128,32 @@  discard block
 block discarded – undo
3931 4128
 				$seconds = intval($active % 60);
3932 4129
 
3933 4130
 				$totalTime = '';
3934
-				if ($hours > 0)
3935
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3936
-				if ($minutes > 0)
3937
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3938
-				if ($seconds > 0)
3939
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4131
+				if ($hours > 0) {
4132
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4133
+				}
4134
+				if ($minutes > 0) {
4135
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4136
+				}
4137
+				if ($seconds > 0) {
4138
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4139
+				}
3940 4140
 			}
3941 4141
 
3942
-			if ($is_debug && !empty($totalTime))
3943
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3944
-			else
3945
-				echo ' Successful!<br><br>';
4142
+			if ($is_debug && !empty($totalTime)) {
4143
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4144
+			} else {
4145
+							echo ' Successful!<br><br>';
4146
+			}
3946 4147
 
3947 4148
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3948 4149
 		}
3949
-	}
3950
-	else
4150
+	} else
3951 4151
 	{
3952 4152
 		// Tell them how many files we have in total.
3953
-		if ($upcontext['file_count'] > 1)
3954
-			echo '
4153
+		if ($upcontext['file_count'] > 1) {
4154
+					echo '
3955 4155
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4156
+		}
3956 4157
 
3957 4158
 		echo '
3958 4159
 		<h3 id="info2"><strong>Executing:</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> of <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -3968,19 +4169,23 @@  discard block
 block discarded – undo
3968 4169
 				$seconds = intval($active % 60);
3969 4170
 
3970 4171
 				$totalTime = '';
3971
-				if ($hours > 0)
3972
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3973
-				if ($minutes > 0)
3974
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3975
-				if ($seconds > 0)
3976
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4172
+				if ($hours > 0) {
4173
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4174
+				}
4175
+				if ($minutes > 0) {
4176
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4177
+				}
4178
+				if ($seconds > 0) {
4179
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4180
+				}
3977 4181
 			}
3978 4182
 
3979 4183
 			echo '
3980 4184
 			<br><span id="upgradeCompleted">';
3981 4185
 
3982
-			if (!empty($totalTime))
3983
-				echo 'Completed in ', $totalTime, '<br>';
4186
+			if (!empty($totalTime)) {
4187
+							echo 'Completed in ', $totalTime, '<br>';
4188
+			}
3984 4189
 
3985 4190
 			echo '</span>
3986 4191
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -4017,9 +4222,10 @@  discard block
 block discarded – undo
4017 4222
 			var getData = "";
4018 4223
 			var debugItems = ', $upcontext['debug_items'], ';';
4019 4224
 
4020
-		if ($is_debug)
4021
-			echo '
4225
+		if ($is_debug) {
4226
+					echo '
4022 4227
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4228
+		}
4023 4229
 
4024 4230
 		echo '
4025 4231
 			function getNextItem()
@@ -4059,9 +4265,10 @@  discard block
 block discarded – undo
4059 4265
 						document.getElementById("error_block").style.display = "";
4060 4266
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4061 4267
 
4062
-	if ($is_debug)
4063
-		echo '
4268
+	if ($is_debug) {
4269
+			echo '
4064 4270
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4271
+	}
4065 4272
 
4066 4273
 	echo '
4067 4274
 					}
@@ -4082,9 +4289,10 @@  discard block
 block discarded – undo
4082 4289
 						document.getElementById("error_block").style.display = "";
4083 4290
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4084 4291
 
4085
-	if ($is_debug)
4086
-		echo '
4292
+	if ($is_debug) {
4293
+			echo '
4087 4294
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4295
+	}
4088 4296
 
4089 4297
 	echo '
4090 4298
 					}
@@ -4143,8 +4351,8 @@  discard block
 block discarded – undo
4143 4351
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4144 4352
 				{';
4145 4353
 
4146
-		if ($is_debug)
4147
-			echo '
4354
+		if ($is_debug) {
4355
+					echo '
4148 4356
 					document.getElementById(\'debug_section\').style.display = "none";
4149 4357
 
4150 4358
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4162,6 +4370,7 @@  discard block
 block discarded – undo
4162 4370
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4163 4371
 
4164 4372
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4373
+		}
4165 4374
 
4166 4375
 		echo '
4167 4376
 
@@ -4169,9 +4378,10 @@  discard block
 block discarded – undo
4169 4378
 					document.getElementById(\'contbutt\').disabled = 0;
4170 4379
 					document.getElementById(\'database_done\').value = 1;';
4171 4380
 
4172
-		if ($upcontext['file_count'] > 1)
4173
-			echo '
4381
+		if ($upcontext['file_count'] > 1) {
4382
+					echo '
4174 4383
 					document.getElementById(\'info1\').style.display = "none";';
4384
+		}
4175 4385
 
4176 4386
 		echo '
4177 4387
 					document.getElementById(\'info2\').style.display = "none";
@@ -4184,9 +4394,10 @@  discard block
 block discarded – undo
4184 4394
 					lastItem = 0;
4185 4395
 					prevFile = curFile;';
4186 4396
 
4187
-		if ($is_debug)
4188
-			echo '
4397
+		if ($is_debug) {
4398
+					echo '
4189 4399
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4400
+		}
4190 4401
 
4191 4402
 		echo '
4192 4403
 					getNextItem();
@@ -4194,8 +4405,8 @@  discard block
 block discarded – undo
4194 4405
 				}';
4195 4406
 
4196 4407
 		// If debug scroll the screen.
4197
-		if ($is_debug)
4198
-			echo '
4408
+		if ($is_debug) {
4409
+					echo '
4199 4410
 				if (iLastSubStepProgress == -1)
4200 4411
 				{
4201 4412
 					// Give it consistent dots.
@@ -4214,6 +4425,7 @@  discard block
 block discarded – undo
4214 4425
 
4215 4426
 				if (document.getElementById(\'debug_section\').scrollHeight)
4216 4427
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4428
+		}
4217 4429
 
4218 4430
 		echo '
4219 4431
 				// Update the page.
@@ -4274,9 +4486,10 @@  discard block
 block discarded – undo
4274 4486
 			}';
4275 4487
 
4276 4488
 		// Start things off assuming we've not errored.
4277
-		if (empty($upcontext['error_message']))
4278
-			echo '
4489
+		if (empty($upcontext['error_message'])) {
4490
+					echo '
4279 4491
 			getNextItem();';
4492
+		}
4280 4493
 
4281 4494
 		echo '
4282 4495
 		//# sourceURL=dynamicScript-dbch.js
@@ -4294,18 +4507,21 @@  discard block
 block discarded – undo
4294 4507
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4295 4508
 	<debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>';
4296 4509
 
4297
-	if (!empty($upcontext['error_message']))
4298
-		echo '
4510
+	if (!empty($upcontext['error_message'])) {
4511
+			echo '
4299 4512
 	<error>', $upcontext['error_message'], '</error>';
4513
+	}
4300 4514
 
4301
-	if (!empty($upcontext['error_string']))
4302
-		echo '
4515
+	if (!empty($upcontext['error_string'])) {
4516
+			echo '
4303 4517
 	<sql>', $upcontext['error_string'], '</sql>';
4518
+	}
4304 4519
 
4305
-	if ($is_debug)
4306
-		echo '
4520
+	if ($is_debug) {
4521
+			echo '
4307 4522
 	<curtime>', time(), '</curtime>';
4308
-}
4523
+	}
4524
+	}
4309 4525
 
4310 4526
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4311 4527
 function template_convert_utf8()
@@ -4324,18 +4540,20 @@  discard block
 block discarded – undo
4324 4540
 			</div>';
4325 4541
 
4326 4542
 	// Done any tables so far?
4327
-	if (!empty($upcontext['previous_tables']))
4328
-		foreach ($upcontext['previous_tables'] as $table)
4543
+	if (!empty($upcontext['previous_tables'])) {
4544
+			foreach ($upcontext['previous_tables'] as $table)
4329 4545
 			echo '
4330 4546
 			<br>Completed Table: &quot;', $table, '&quot;.';
4547
+	}
4331 4548
 
4332 4549
 	echo '
4333 4550
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4334 4551
 
4335 4552
 	// If we dropped their index, let's let them know
4336
-	if ($upcontext['dropping_index'])
4337
-		echo '
4553
+	if ($upcontext['dropping_index']) {
4554
+			echo '
4338 4555
 				<br><span id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated in the admin area after the upgrade is complete.</span>';
4556
+	}
4339 4557
 
4340 4558
 	// Completion notification
4341 4559
 	echo '
@@ -4372,12 +4590,13 @@  discard block
 block discarded – undo
4372 4590
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4373 4591
 
4374 4592
 		// If debug flood the screen.
4375
-		if ($is_debug)
4376
-			echo '
4593
+		if ($is_debug) {
4594
+					echo '
4377 4595
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4378 4596
 
4379 4597
 				if (document.getElementById(\'debug_section\').scrollHeight)
4380 4598
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4599
+		}
4381 4600
 
4382 4601
 		echo '
4383 4602
 				// Get the next update...
@@ -4425,19 +4644,21 @@  discard block
 block discarded – undo
4425 4644
 			</div>';
4426 4645
 
4427 4646
 	// Dont any tables so far?
4428
-	if (!empty($upcontext['previous_tables']))
4429
-		foreach ($upcontext['previous_tables'] as $table)
4647
+	if (!empty($upcontext['previous_tables'])) {
4648
+			foreach ($upcontext['previous_tables'] as $table)
4430 4649
 			echo '
4431 4650
 			<br>Completed Table: &quot;', $table, '&quot;.';
4651
+	}
4432 4652
 
4433 4653
 	echo '
4434 4654
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4435 4655
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Convert to JSON Complete! Click Continue to Proceed.</span>';
4436 4656
 
4437 4657
 	// Try to make sure substep was reset.
4438
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4439
-		echo '
4658
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4659
+			echo '
4440 4660
 			<input type="hidden" name="substep" id="substep" value="0">';
4661
+	}
4441 4662
 
4442 4663
 	// Continue please!
4443 4664
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4470,12 +4691,13 @@  discard block
 block discarded – undo
4470 4691
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4471 4692
 
4472 4693
 		// If debug flood the screen.
4473
-		if ($is_debug)
4474
-			echo '
4694
+		if ($is_debug) {
4695
+					echo '
4475 4696
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4476 4697
 
4477 4698
 				if (document.getElementById(\'debug_section\').scrollHeight)
4478 4699
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4700
+		}
4479 4701
 
4480 4702
 		echo '
4481 4703
 				// Get the next update...
@@ -4511,8 +4733,8 @@  discard block
 block discarded – undo
4511 4733
 	<h3>That wasn\'t so hard, was it?  Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>.  Hope you like it!</h3>
4512 4734
 	<form action="', $boardurl, '/index.php">';
4513 4735
 
4514
-	if (!empty($upcontext['can_delete_script']))
4515
-		echo '
4736
+	if (!empty($upcontext['can_delete_script'])) {
4737
+			echo '
4516 4738
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em>
4517 4739
 			<script>
4518 4740
 				function doTheDelete(theCheck)
@@ -4524,6 +4746,7 @@  discard block
 block discarded – undo
4524 4746
 				}
4525 4747
 			</script>
4526 4748
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4749
+	}
4527 4750
 
4528 4751
 	$active = time() - $upcontext['started'];
4529 4752
 	$hours = floor($active / 3600);
@@ -4533,16 +4756,20 @@  discard block
 block discarded – undo
4533 4756
 	if ($is_debug)
4534 4757
 	{
4535 4758
 		$totalTime = '';
4536
-		if ($hours > 0)
4537
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4538
-		if ($minutes > 0)
4539
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4540
-		if ($seconds > 0)
4541
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4759
+		if ($hours > 0) {
4760
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4761
+		}
4762
+		if ($minutes > 0) {
4763
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4764
+		}
4765
+		if ($seconds > 0) {
4766
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4767
+		}
4542 4768
 	}
4543 4769
 
4544
-	if ($is_debug && !empty($totalTime))
4545
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4770
+	if ($is_debug && !empty($totalTime)) {
4771
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4772
+	}
4546 4773
 
4547 4774
 	echo '<br>
4548 4775
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="https://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -4569,8 +4796,9 @@  discard block
 block discarded – undo
4569 4796
 
4570 4797
 	$current_substep = $_GET['substep'];
4571 4798
 
4572
-	if (empty($_GET['a']))
4573
-		$_GET['a'] = 0;
4799
+	if (empty($_GET['a'])) {
4800
+			$_GET['a'] = 0;
4801
+	}
4574 4802
 	$step_progress['name'] = 'Converting ips';
4575 4803
 	$step_progress['current'] = $_GET['a'];
4576 4804
 
@@ -4613,16 +4841,19 @@  discard block
 block discarded – undo
4613 4841
 				'empty' => '',
4614 4842
 				'limit' => $limit,
4615 4843
 		));
4616
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4617
-			$arIp[] = $row[$oldCol];
4844
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4845
+					$arIp[] = $row[$oldCol];
4846
+		}
4618 4847
 		$smcFunc['db_free_result']($request);
4619 4848
 
4620 4849
 		// Special case, null ip could keep us in a loop.
4621
-		if (is_null($arIp[0]))
4622
-			unset($arIp[0]);
4850
+		if (is_null($arIp[0])) {
4851
+					unset($arIp[0]);
4852
+		}
4623 4853
 
4624
-		if (empty($arIp))
4625
-			$is_done = true;
4854
+		if (empty($arIp)) {
4855
+					$is_done = true;
4856
+		}
4626 4857
 
4627 4858
 		$updates = array();
4628 4859
 		$cases = array();
@@ -4631,16 +4862,18 @@  discard block
 block discarded – undo
4631 4862
 		{
4632 4863
 			$arIp[$i] = trim($arIp[$i]);
4633 4864
 
4634
-			if (empty($arIp[$i]))
4635
-				continue;
4865
+			if (empty($arIp[$i])) {
4866
+							continue;
4867
+			}
4636 4868
 
4637 4869
 			$updates['ip' . $i] = $arIp[$i];
4638 4870
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4639 4871
 
4640 4872
 			if ($setSize > 0 && $i % $setSize === 0)
4641 4873
 			{
4642
-				if (count($updates) == 1)
4643
-					continue;
4874
+				if (count($updates) == 1) {
4875
+									continue;
4876
+				}
4644 4877
 
4645 4878
 				$updates['whereSet'] = array_values($updates);
4646 4879
 				$smcFunc['db_query']('', '
@@ -4674,8 +4907,7 @@  discard block
 block discarded – undo
4674 4907
 							'ip' => $ip
4675 4908
 					));
4676 4909
 				}
4677
-			}
4678
-			else
4910
+			} else
4679 4911
 			{
4680 4912
 				$updates['whereSet'] = array_values($updates);
4681 4913
 				$smcFunc['db_query']('', '
@@ -4689,9 +4921,9 @@  discard block
 block discarded – undo
4689 4921
 					$updates
4690 4922
 				);
4691 4923
 			}
4924
+		} else {
4925
+					$is_done = true;
4692 4926
 		}
4693
-		else
4694
-			$is_done = true;
4695 4927
 
4696 4928
 		$_GET['a'] += $limit;
4697 4929
 		$step_progress['current'] = $_GET['a'];
@@ -4717,10 +4949,11 @@  discard block
 block discarded – undo
4717 4949
 
4718 4950
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4719 4951
 
4720
-	if (isset($columns[$column]))
4721
-		return $columns[$column];
4722
-	else
4723
-		return null;
4724
-}
4952
+	if (isset($columns[$column])) {
4953
+			return $columns[$column];
4954
+	} else {
4955
+			return null;
4956
+	}
4957
+	}
4725 4958
 
4726 4959
 ?>
4727 4960
\ No newline at end of file
Please login to merge, or discard this patch.
other/upgrade-helper.php 1 patch
Braces   +96 added lines, -68 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * This file contains helper functions for upgrade.php
14 14
  */
15 15
 
16
-if (!defined('SMF_VERSION'))
16
+if (!defined('SMF_VERSION')) {
17 17
 	die('No direct access!');
18
+}
18 19
 
19 20
 /**
20 21
  * Clean the cache using the SMF 2.1 CacheAPI.
@@ -45,8 +46,9 @@  discard block
 block discarded – undo
45 46
 	global $smcFunc;
46 47
 	static $member_groups = array();
47 48
 
48
-	if (!empty($member_groups))
49
-		return $member_groups;
49
+	if (!empty($member_groups)) {
50
+			return $member_groups;
51
+	}
50 52
 
51 53
 	$request = $smcFunc['db_query']('', '
52 54
 		SELECT group_name, id_group
@@ -71,8 +73,9 @@  discard block
 block discarded – undo
71 73
 			)
72 74
 		);
73 75
 	}
74
-	while ($row = $smcFunc['db_fetch_row']($request))
75
-		$member_groups[trim($row[0])] = $row[1];
76
+	while ($row = $smcFunc['db_fetch_row']($request)) {
77
+			$member_groups[trim($row[0])] = $row[1];
78
+	}
76 79
 	$smcFunc['db_free_result']($request);
77 80
 
78 81
 	return $member_groups;
@@ -88,8 +91,9 @@  discard block
 block discarded – undo
88 91
 {
89 92
 	global $upcontext, $boarddir, $sourcedir;
90 93
 
91
-	if (empty($files))
92
-		return true;
94
+	if (empty($files)) {
95
+			return true;
96
+	}
93 97
 
94 98
 	$failure = false;
95 99
 	// On linux, it's easy - just use is_writable!
@@ -100,22 +104,25 @@  discard block
 block discarded – undo
100 104
 		foreach ($files as $k => $file)
101 105
 		{
102 106
 			// Some files won't exist, try to address up front
103
-			if (!file_exists($file))
104
-				@touch($file);
107
+			if (!file_exists($file)) {
108
+							@touch($file);
109
+			}
105 110
 			// NOW do the writable check...
106 111
 			if (!is_writable($file))
107 112
 			{
108 113
 				@chmod($file, 0755);
109 114
 
110 115
 				// Well, 755 hopefully worked... if not, try 777.
111
-				if (!is_writable($file) && !@chmod($file, 0777))
112
-					$failure = true;
116
+				if (!is_writable($file) && !@chmod($file, 0777)) {
117
+									$failure = true;
118
+				}
113 119
 				// Otherwise remove it as it's good!
114
-				else
115
-					unset($files[$k]);
120
+				else {
121
+									unset($files[$k]);
122
+				}
123
+			} else {
124
+							unset($files[$k]);
116 125
 			}
117
-			else
118
-				unset($files[$k]);
119 126
 		}
120 127
 	}
121 128
 	// Windows is trickier.  Let's try opening for r+...
@@ -126,30 +133,35 @@  discard block
 block discarded – undo
126 133
 		foreach ($files as $k => $file)
127 134
 		{
128 135
 			// Folders can't be opened for write... but the index.php in them can ;).
129
-			if (is_dir($file))
130
-				$file .= '/index.php';
136
+			if (is_dir($file)) {
137
+							$file .= '/index.php';
138
+			}
131 139
 
132 140
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
133 141
 			@chmod($file, 0777);
134 142
 			$fp = @fopen($file, 'r+');
135 143
 
136 144
 			// Hmm, okay, try just for write in that case...
137
-			if (!$fp)
138
-				$fp = @fopen($file, 'w');
145
+			if (!$fp) {
146
+							$fp = @fopen($file, 'w');
147
+			}
139 148
 
140
-			if (!$fp)
141
-				$failure = true;
142
-			else
143
-				unset($files[$k]);
149
+			if (!$fp) {
150
+							$failure = true;
151
+			} else {
152
+							unset($files[$k]);
153
+			}
144 154
 			@fclose($fp);
145 155
 		}
146 156
 	}
147 157
 
148
-	if (empty($files))
149
-		return true;
158
+	if (empty($files)) {
159
+			return true;
160
+	}
150 161
 
151
-	if (!isset($_SERVER))
152
-		return !$failure;
162
+	if (!isset($_SERVER)) {
163
+			return !$failure;
164
+	}
153 165
 
154 166
 	// What still needs to be done?
155 167
 	$upcontext['chmod']['files'] = $files;
@@ -201,36 +213,40 @@  discard block
 block discarded – undo
201 213
 
202 214
 		if (!isset($ftp) || $ftp->error !== false)
203 215
 		{
204
-			if (!isset($ftp))
205
-				$ftp = new ftp_connection(null);
216
+			if (!isset($ftp)) {
217
+							$ftp = new ftp_connection(null);
218
+			}
206 219
 			// Save the error so we can mess with listing...
207
-			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error']))
208
-				$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
220
+			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) {
221
+							$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
222
+			}
209 223
 
210 224
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
211 225
 
212
-			if ($found_path || !isset($upcontext['chmod']['path']))
213
-				$upcontext['chmod']['path'] = $detect_path;
226
+			if ($found_path || !isset($upcontext['chmod']['path'])) {
227
+							$upcontext['chmod']['path'] = $detect_path;
228
+			}
214 229
 
215
-			if (!isset($upcontext['chmod']['username']))
216
-				$upcontext['chmod']['username'] = $username;
230
+			if (!isset($upcontext['chmod']['username'])) {
231
+							$upcontext['chmod']['username'] = $username;
232
+			}
217 233
 
218 234
 			// Don't forget the login token.
219 235
 			$upcontext += createToken('login');
220 236
 
221 237
 			return false;
222
-		}
223
-		else
238
+		} else
224 239
 		{
225 240
 			// We want to do a relative path for FTP.
226 241
 			if (!in_array($upcontext['chmod']['path'], array('', '/')))
227 242
 			{
228 243
 				$ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => ''));
229
-				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/'))
230
-					$ftp_root = substr($ftp_root, 0, -1);
244
+				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) {
245
+									$ftp_root = substr($ftp_root, 0, -1);
246
+				}
247
+			} else {
248
+							$ftp_root = $boarddir;
231 249
 			}
232
-			else
233
-				$ftp_root = $boarddir;
234 250
 
235 251
 			// Save the info for next time!
236 252
 			$_SESSION['installer_temp_ftp'] = array(
@@ -244,10 +260,12 @@  discard block
 block discarded – undo
244 260
 
245 261
 			foreach ($files as $k => $file)
246 262
 			{
247
-				if (!is_writable($file))
248
-					$ftp->chmod($file, 0755);
249
-				if (!is_writable($file))
250
-					$ftp->chmod($file, 0777);
263
+				if (!is_writable($file)) {
264
+									$ftp->chmod($file, 0755);
265
+				}
266
+				if (!is_writable($file)) {
267
+									$ftp->chmod($file, 0777);
268
+				}
251 269
 
252 270
 				// Assuming that didn't work calculate the path without the boarddir.
253 271
 				if (!is_writable($file))
@@ -256,19 +274,23 @@  discard block
 block discarded – undo
256 274
 					{
257 275
 						$ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => ''));
258 276
 						$ftp->chmod($ftp_file, 0755);
259
-						if (!is_writable($file))
260
-							$ftp->chmod($ftp_file, 0777);
277
+						if (!is_writable($file)) {
278
+													$ftp->chmod($ftp_file, 0777);
279
+						}
261 280
 						// Sometimes an extra slash can help...
262 281
 						$ftp_file = '/' . $ftp_file;
263
-						if (!is_writable($file))
264
-							$ftp->chmod($ftp_file, 0755);
265
-						if (!is_writable($file))
266
-							$ftp->chmod($ftp_file, 0777);
282
+						if (!is_writable($file)) {
283
+													$ftp->chmod($ftp_file, 0755);
284
+						}
285
+						if (!is_writable($file)) {
286
+													$ftp->chmod($ftp_file, 0777);
287
+						}
267 288
 					}
268 289
 				}
269 290
 
270
-				if (is_writable($file))
271
-					unset($files[$k]);
291
+				if (is_writable($file)) {
292
+									unset($files[$k]);
293
+				}
272 294
 			}
273 295
 
274 296
 			$ftp->close();
@@ -278,8 +300,9 @@  discard block
 block discarded – undo
278 300
 	// What remains?
279 301
 	$upcontext['chmod']['files'] = $files;
280 302
 
281
-	if (empty($files))
282
-		return true;
303
+	if (empty($files)) {
304
+			return true;
305
+	}
283 306
 
284 307
 	return false;
285 308
 }
@@ -294,12 +317,14 @@  discard block
 block discarded – undo
294 317
 {
295 318
 
296 319
 	// Some files won't exist, try to address up front
297
-	if (!file_exists($file))
298
-		@touch($file);
320
+	if (!file_exists($file)) {
321
+			@touch($file);
322
+	}
299 323
 
300 324
 	// NOW do the writable check...
301
-	if (is_writable($file))
302
-		return true;
325
+	if (is_writable($file)) {
326
+			return true;
327
+	}
303 328
 
304 329
 	@chmod($file, 0755);
305 330
 
@@ -309,10 +334,11 @@  discard block
 block discarded – undo
309 334
 	foreach ($chmod_values as $val)
310 335
 	{
311 336
 		// If it's writable, break out of the loop
312
-		if (is_writable($file))
313
-			break;
314
-		else
315
-			@chmod($file, $val);
337
+		if (is_writable($file)) {
338
+					break;
339
+		} else {
340
+					@chmod($file, $val);
341
+		}
316 342
 	}
317 343
 
318 344
 	return is_writable($file);
@@ -339,14 +365,16 @@  discard block
 block discarded – undo
339 365
 {
340 366
 	static $fp = null;
341 367
 
342
-	if ($fp === null)
343
-		$fp = fopen('php://stderr', 'wb');
368
+	if ($fp === null) {
369
+			$fp = fopen('php://stderr', 'wb');
370
+	}
344 371
 
345 372
 	fwrite($fp, $message . "\n");
346 373
 
347
-	if ($fatal)
348
-		exit;
349
-}
374
+	if ($fatal) {
375
+			exit;
376
+	}
377
+	}
350 378
 
351 379
 /**
352 380
  * Throws a graphical error message.
Please login to merge, or discard this patch.
Themes/default/BoardIndex.template.php 1 patch
Braces   +57 added lines, -39 removed lines patch added patch discarded remove patch
@@ -67,8 +67,9 @@  discard block
 block discarded – undo
67 67
 	foreach ($context['categories'] as $category)
68 68
 	{
69 69
 		// If theres no parent boards we can see, avoid showing an empty category (unless its collapsed)
70
-		if (empty($category['boards']) && !$category['is_collapsed'])
71
-			continue;
70
+		if (empty($category['boards']) && !$category['is_collapsed']) {
71
+					continue;
72
+		}
72 73
 
73 74
 		echo '
74 75
 		<div class="main_container">
@@ -76,9 +77,10 @@  discard block
 block discarded – undo
76 77
 				<h3 class="catbg">';
77 78
 
78 79
 		// If this category even can collapse, show a link to collapse it.
79
-		if ($category['can_collapse'])
80
-			echo '
80
+		if ($category['can_collapse']) {
81
+					echo '
81 82
 					<span id="category_', $category['id'], '_upshrink" class="', $category['is_collapsed'] ? 'toggle_down' : 'toggle_up', ' floatright" data-collapsed="', (int) $category['is_collapsed'], '" title="', !$category['is_collapsed'] ? $txt['hide_category'] : $txt['show_category'], '" style="display: none;"></span>';
83
+		}
82 84
 
83 85
 		echo '
84 86
 					', $category['link'], '
@@ -105,17 +107,19 @@  discard block
 block discarded – undo
105 107
 						</a>';
106 108
 
107 109
 				// Has it outstanding posts for approval?
108
-				if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics']))
109
-					echo '
110
+				if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics'])) {
111
+									echo '
110 112
 						<a href="', $scripturl, '?action=moderate;area=postmod;sa=', ($board['unapproved_topics'] > 0 ? 'topics' : 'posts'), ';brd=', $board['id'], ';', $context['session_var'], '=', $context['session_id'], '" title="', sprintf($txt['unapproved_posts'], $board['unapproved_topics'], $board['unapproved_posts']), '" class="moderation_link">(!)</a>';
113
+				}
111 114
 
112 115
 				echo '
113 116
 						<p class="board_description">', $board['description'], '</p>';
114 117
 
115 118
 				// Show the "Moderators: ". Each has name, href, link, and id. (but we're gonna use link_moderators.)
116
-				if (!empty($board['link_moderators']))
117
-					echo '
119
+				if (!empty($board['link_moderators'])) {
120
+									echo '
118 121
 						<p class="moderators">', count($board['link_moderators']) == 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $board['link_moderators']), '</p>';
122
+				}
119 123
 
120 124
 				// Show some basic information about the number of posts, etc.
121 125
 					echo '
@@ -127,9 +131,10 @@  discard block
 block discarded – undo
127 131
 					</div>
128 132
 					<div class="lastpost ',!empty($board['last_post']['id']) ? 'lpr_border' : 'hidden', '">';
129 133
 
130
-				if (!empty($board['last_post']['id']))
131
-					echo '
134
+				if (!empty($board['last_post']['id'])) {
135
+									echo '
132 136
 						<p>', $board['last_post']['last_post_message'], '</p>';
137
+				}
133 138
 				echo '
134 139
 					</div>';
135 140
 				// Show the "Child Boards: ". (there's a link_children but we're going to bold the new ones...)
@@ -141,14 +146,16 @@  discard block
 block discarded – undo
141 146
 							id, name, description, new (is it new?), topics (#), posts (#), href, link, and last_post. */
142 147
 					foreach ($board['children'] as $child)
143 148
 					{
144
-						if (!$child['is_redirect'])
145
-							$child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>';
146
-						else
147
-							$child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . ' - ' . $child['short_description'] . '">' . $child['name'] . '</a>';
149
+						if (!$child['is_redirect']) {
150
+													$child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>';
151
+						} else {
152
+													$child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . ' - ' . $child['short_description'] . '">' . $child['name'] . '</a>';
153
+						}
148 154
 
149 155
 						// Has it posts awaiting approval?
150
-						if ($child['can_approve_posts'] && ($child['unapproved_posts'] || $child['unapproved_topics']))
151
-							$child['link'] .= ' <a href="' . $scripturl . '?action=moderate;area=postmod;sa=' . ($child['unapproved_topics'] > 0 ? 'topics' : 'posts') . ';brd=' . $child['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" title="' . sprintf($txt['unapproved_posts'], $child['unapproved_topics'], $child['unapproved_posts']) . '" class="moderation_link">(!)</a>';
156
+						if ($child['can_approve_posts'] && ($child['unapproved_posts'] || $child['unapproved_topics'])) {
157
+													$child['link'] .= ' <a href="' . $scripturl . '?action=moderate;area=postmod;sa=' . ($child['unapproved_topics'] > 0 ? 'topics' : 'posts') . ';brd=' . $child['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" title="' . sprintf($txt['unapproved_posts'], $child['unapproved_topics'], $child['unapproved_posts']) . '" class="moderation_link">(!)</a>';
158
+						}
152 159
 
153 160
 						$children[] = $child['new'] ? '<span class="strong">' . $child['link'] . '</span>' : '<span>' . $child['link'] . '</span>';
154 161
 					}
@@ -172,10 +179,11 @@  discard block
 block discarded – undo
172 179
 	</div>';
173 180
 
174 181
 	// Show the mark all as read button?
175
-	if ($context['user']['is_logged'] && !empty($context['categories']))
176
-		echo '
182
+	if ($context['user']['is_logged'] && !empty($context['categories'])) {
183
+			echo '
177 184
 		<div class="mark_read">', template_button_strip($context['mark_read_button'], 'right'), '</div>';
178
-}
185
+	}
186
+	}
179 187
 
180 188
 /**
181 189
  * The lower part of the outer layer of the board index
@@ -192,8 +200,9 @@  discard block
 block discarded – undo
192 200
 {
193 201
 	global $context, $options, $txt;
194 202
 
195
-	if (empty($context['info_center']))
196
-		return;
203
+	if (empty($context['info_center'])) {
204
+			return;
205
+	}
197 206
 
198 207
 	// Here's where the "Info Center" starts...
199 208
 	echo '
@@ -293,14 +302,15 @@  discard block
 block discarded – undo
293 302
 		/* Each post in latest_posts has:
294 303
 				board (with an id, name, and link.), topic (the topic's id.), poster (with id, name, and link.),
295 304
 				subject, short_subject (shortened with...), time, link, and href. */
296
-		foreach ($context['latest_posts'] as $post)
297
-			echo '
305
+		foreach ($context['latest_posts'] as $post) {
306
+					echo '
298 307
 					<tr class="windowbg">
299 308
 						<td class="recentpost"><strong>', $post['link'], '</strong></td>
300 309
 						<td class="recentposter">', $post['poster']['link'], '</td>
301 310
 						<td class="recentboard">', $post['board']['link'], '</td>
302 311
 						<td class="recenttime">', $post['time'], '</td>
303 312
 					</tr>';
313
+		}
304 314
 		echo '
305 315
 				</table>';
306 316
 	}
@@ -324,9 +334,10 @@  discard block
 block discarded – undo
324 334
 			</div>';
325 335
 
326 336
 	// Holidays like "Christmas", "Chanukah", and "We Love [Unknown] Day" :P.
327
-	if (!empty($context['calendar_holidays']))
328
-		echo '
337
+	if (!empty($context['calendar_holidays'])) {
338
+			echo '
329 339
 				<p class="inline holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $context['calendar_holidays']), '</p>';
340
+	}
330 341
 
331 342
 	// People's birthdays. Like mine. And yours, I guess. Kidding.
332 343
 	if (!empty($context['calendar_birthdays']))
@@ -335,9 +346,10 @@  discard block
 block discarded – undo
335 346
 				<p class="inline">
336 347
 					<span class="birthday">', $context['calendar_only_today'] ? $txt['birthdays'] : $txt['birthdays_upcoming'], '</span>';
337 348
 		// Each member in calendar_birthdays has: id, name (person), age (if they have one set?), is_last. (last in list?), and is_today (birthday is today?)
338
-		foreach ($context['calendar_birthdays'] as $member)
339
-			echo '
349
+		foreach ($context['calendar_birthdays'] as $member) {
350
+					echo '
340 351
 					<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['is_today'] ? '<strong class="fix_rtl_names">' : '', $member['name'], $member['is_today'] ? '</strong>' : '', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] ? '' : ', ';
352
+		}
341 353
 		echo '
342 354
 				</p>';
343 355
 	}
@@ -351,9 +363,10 @@  discard block
 block discarded – undo
351 363
 
352 364
 		// Each event in calendar_events should have:
353 365
 		//		title, href, is_last, can_edit (are they allowed?), modify_href, and is_today.
354
-		foreach ($context['calendar_events'] as $event)
355
-			echo '
366
+		foreach ($context['calendar_events'] as $event) {
367
+					echo '
356 368
 					', $event['can_edit'] ? '<a href="' . $event['modify_href'] . '" title="' . $txt['calendar_edit'] . '"><span class="generic_icons calendar_modify"></span></a> ' : '', $event['href'] == '' ? '' : '<a href="' . $event['href'] . '">', $event['is_today'] ? '<strong>' . $event['title'] . '</strong>' : $event['title'], $event['href'] == '' ? '' : '</a>', $event['is_last'] ? '<br>' : ', ';
369
+		}
357 370
 		echo '
358 371
 				</p>';
359 372
 	}
@@ -398,15 +411,19 @@  discard block
 block discarded – undo
398 411
 
399 412
 	// Handle hidden users and buddies.
400 413
 	$bracketList = array();
401
-	if ($context['show_buddies'])
402
-		$bracketList[] = comma_format($context['num_buddies']) . ' ' . ($context['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
403
-	if (!empty($context['num_spiders']))
404
-		$bracketList[] = comma_format($context['num_spiders']) . ' ' . ($context['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
405
-	if (!empty($context['num_users_hidden']))
406
-		$bracketList[] = comma_format($context['num_users_hidden']) . ' ' . ($context['num_spiders'] == 1 ? $txt['hidden'] : $txt['hidden_s']);
414
+	if ($context['show_buddies']) {
415
+			$bracketList[] = comma_format($context['num_buddies']) . ' ' . ($context['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
416
+	}
417
+	if (!empty($context['num_spiders'])) {
418
+			$bracketList[] = comma_format($context['num_spiders']) . ' ' . ($context['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
419
+	}
420
+	if (!empty($context['num_users_hidden'])) {
421
+			$bracketList[] = comma_format($context['num_users_hidden']) . ' ' . ($context['num_spiders'] == 1 ? $txt['hidden'] : $txt['hidden_s']);
422
+	}
407 423
 
408
-	if (!empty($bracketList))
409
-		echo ' (' . implode(', ', $bracketList) . ')';
424
+	if (!empty($bracketList)) {
425
+			echo ' (' . implode(', ', $bracketList) . ')';
426
+	}
410 427
 
411 428
 	echo $context['show_who'] ? '</a>' : '', '
412 429
 
@@ -420,9 +437,10 @@  discard block
 block discarded – undo
420 437
 				', sprintf($txt['users_active'], $modSettings['lastActive']), ': ', implode(', ', $context['list_users_online']);
421 438
 
422 439
 		// Showing membergroups?
423
-		if (!empty($settings['show_group_key']) && !empty($context['membergroups']))
424
-			echo '
440
+		if (!empty($settings['show_group_key']) && !empty($context['membergroups'])) {
441
+					echo '
425 442
 				<span class="membergroups">' . implode(',&nbsp;', $context['membergroups']) . '</span>';
443
+		}
426 444
 	}
427 445
 
428 446
 	echo '
Please login to merge, or discard this patch.
Themes/default/MessageIndex.template.php 1 patch
Braces   +94 added lines, -65 removed lines patch added patch discarded remove patch
@@ -48,17 +48,19 @@  discard block
 block discarded – undo
48 48
 						</a>';
49 49
 
50 50
 			// Has it outstanding posts for approval?
51
-			if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics']))
52
-				echo '
51
+			if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics'])) {
52
+							echo '
53 53
 						<a href="', $scripturl, '?action=moderate;area=postmod;sa=', ($board['unapproved_topics'] > 0 ? 'topics' : 'posts'), ';brd=', $board['id'], ';', $context['session_var'], '=', $context['session_id'], '" title="', sprintf($txt['unapproved_posts'], $board['unapproved_topics'], $board['unapproved_posts']), '" class="moderation_link">(!)</a>';
54
+			}
54 55
 
55 56
 			echo '
56 57
 						<p class="board_description">', $board['description'], '</p>';
57 58
 
58 59
 			// Show the "Moderators: ". Each has name, href, link, and id. (but we're gonna use link_moderators.)
59
-			if (!empty($board['moderators']) || !empty($board['moderator_groups']))
60
-				echo '
60
+			if (!empty($board['moderators']) || !empty($board['moderator_groups'])) {
61
+							echo '
61 62
 						<p class="moderators">', count($board['link_moderators']) === 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $board['link_moderators']), '</p>';
63
+			}
62 64
 
63 65
 			// Show some basic information about the number of posts, etc.
64 66
 			echo '
@@ -70,9 +72,10 @@  discard block
 block discarded – undo
70 72
 					</div>
71 73
 					<div class="lastpost lpr_border">';
72 74
 
73
-			if (!empty($board['last_post']['id']))
74
-				echo '
75
+			if (!empty($board['last_post']['id'])) {
76
+							echo '
75 77
 						<p>', $board['last_post']['last_post_message'], '</p>';
78
+			}
76 79
 			echo '
77 80
 					</div>';
78 81
 
@@ -85,14 +88,16 @@  discard block
 block discarded – undo
85 88
 						id, name, description, new (is it new?), topics (#), posts (#), href, link, and last_post. */
86 89
 				foreach ($board['children'] as $child)
87 90
 				{
88
-					if (!$child['is_redirect'])
89
-						$child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>';
90
-					else
91
-						$child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . '">' . $child['name'] . '</a>';
91
+					if (!$child['is_redirect']) {
92
+											$child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>';
93
+					} else {
94
+											$child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . '">' . $child['name'] . '</a>';
95
+					}
92 96
 
93 97
 					// Has it posts awaiting approval?
94
-					if ($child['can_approve_posts'] && ($child['unapproved_posts'] | $child['unapproved_topics']))
95
-						$child['link'] .= ' <a href="' . $scripturl . '?action=moderate;area=postmod;sa=' . ($child['unapproved_topics'] > 0 ? 'topics' : 'posts') . ';brd=' . $child['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" title="' . sprintf($txt['unapproved_posts'], $child['unapproved_topics'], $child['unapproved_posts']) . '" class="moderation_link">(!)</a>';
98
+					if ($child['can_approve_posts'] && ($child['unapproved_posts'] | $child['unapproved_topics'])) {
99
+											$child['link'] .= ' <a href="' . $scripturl . '?action=moderate;area=postmod;sa=' . ($child['unapproved_topics'] > 0 ? 'topics' : 'posts') . ';brd=' . $child['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" title="' . sprintf($txt['unapproved_posts'], $child['unapproved_topics'], $child['unapproved_posts']) . '" class="moderation_link">(!)</a>';
100
+					}
96 101
 
97 102
 					$children[] = $child['new'] ? '<span class="strong">' . $child['link'] . '</span>' : '<span>' . $child['link'] . '</span>';
98 103
 				}
@@ -111,8 +116,9 @@  discard block
 block discarded – undo
111 116
 	}
112 117
 
113 118
 	// They can only mark read if they are logged in and it's enabled!
114
-	if (!$context['user']['is_logged'])
115
-		unset($context['normal_buttons']['markread']);
119
+	if (!$context['user']['is_logged']) {
120
+			unset($context['normal_buttons']['markread']);
121
+	}
116 122
 
117 123
 	if (!$context['no_topic_listing'])
118 124
 	{
@@ -135,13 +141,15 @@  discard block
 block discarded – undo
135 141
 	<div id="description_board" class="generic_list_wrapper">
136 142
 		<h3>', $context['name'], '</h3>
137 143
 		<p>';
138
-	if ($context['description'] != '')
139
-	echo '
144
+	if ($context['description'] != '') {
145
+		echo '
140 146
 		', $context['description'], '&nbsp;';
147
+	}
141 148
 
142
-	if (!empty($context['moderators']))
143
-	echo '
149
+	if (!empty($context['moderators'])) {
150
+		echo '
144 151
 		', count($context['moderators']) === 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $context['link_moderators']), '.';
152
+	}
145 153
 
146 154
 	echo '
147 155
 		</p>
@@ -149,9 +157,10 @@  discard block
 block discarded – undo
149 157
 		}
150 158
 
151 159
 		// If Quick Moderation is enabled start the form.
152
-		if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics']))
153
-			echo '
160
+		if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics'])) {
161
+					echo '
154 162
 	<form action="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], '" method="post" accept-charset="', $context['character_set'], '" class="clear" name="quickModForm" id="quickModForm">';
163
+		}
155 164
 
156 165
 		echo '
157 166
 		<div id="messageindex">';
@@ -159,10 +168,11 @@  discard block
 block discarded – undo
159 168
 		{
160 169
 		echo '
161 170
 			<div class="information">';
162
-			if ($settings['display_who_viewing'] == 1)
163
-				echo count($context['view_members']), ' ', count($context['view_members']) === 1 ? $txt['who_member'] : $txt['members'];
164
-		else
165
-				echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . (empty($context['view_num_hidden']) || $context['can_moderate_forum'] ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
171
+			if ($settings['display_who_viewing'] == 1) {
172
+							echo count($context['view_members']), ' ', count($context['view_members']) === 1 ? $txt['who_member'] : $txt['members'];
173
+			} else {
174
+						echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . (empty($context['view_num_hidden']) || $context['can_moderate_forum'] ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
175
+		}
166 176
 			echo $txt['who_and'], $context['view_num_guests'], ' ', $context['view_num_guests'] == 1 ? $txt['guest'] : $txt['guests'], $txt['who_viewing_board'];
167 177
 
168 178
 		echo '
@@ -181,19 +191,22 @@  discard block
 block discarded – undo
181 191
 					<div class="lastpost">', $context['topics_headers']['last_post'], '</div>';
182 192
 
183 193
 			// Show a "select all" box for quick moderation?
184
-			if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1)
185
-				echo '
194
+			if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1) {
195
+							echo '
186 196
 					<div class="moderation"><input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');" class="input_check"></div>';
197
+			}
187 198
 
188 199
 			// If it's on in "image" mode, don't show anything but the column.
189
-			elseif (!empty($context['can_quick_mod']))
190
-				echo '
200
+			elseif (!empty($context['can_quick_mod'])) {
201
+							echo '
191 202
 					<div class="moderation">&nbsp;</div>';
203
+			}
192 204
 		}
193 205
 		// No topics.... just say, "sorry bub".
194
-		else
195
-			echo '
206
+		else {
207
+					echo '
196 208
 					<h3 class="titlebg">', $txt['topic_alert_none'], '</h3>';
209
+		}
197 210
 
198 211
 		echo '
199 212
 		</div>';
@@ -225,21 +238,26 @@  discard block
 block discarded – undo
225 238
 			// Now we handle the icons
226 239
 			echo '
227 240
 							<div class="icons floatright">';
228
-			if ($topic['is_watched'])
229
-				echo '
241
+			if ($topic['is_watched']) {
242
+							echo '
230 243
 								<span class="generic_icons watch" title="', $txt['watching_this_topic'], '"></span>';
231
-			if ($topic['is_locked'])
232
-				echo '
244
+			}
245
+			if ($topic['is_locked']) {
246
+							echo '
233 247
 								<span class="generic_icons lock"></span>';
234
-			if ($topic['is_sticky'])
235
-				echo '
248
+			}
249
+			if ($topic['is_sticky']) {
250
+							echo '
236 251
 								<span class="generic_icons sticky"></span>';
237
-			if ($topic['is_redirect'])
238
-				echo '
252
+			}
253
+			if ($topic['is_redirect']) {
254
+							echo '
239 255
 								<span class="generic_icons move"></span>';
240
-			if ($topic['is_poll'])
241
-				echo '
256
+			}
257
+			if ($topic['is_poll']) {
258
+							echo '
242 259
 								<span class="generic_icons poll"></span>';
260
+			}
243 261
 			echo '
244 262
 							</div>';
245 263
 
@@ -265,26 +283,31 @@  discard block
 block discarded – undo
265 283
 			{
266 284
 				echo '
267 285
 					<div class="moderation">';
268
-				if ($options['display_quick_mod'] == 1)
269
-					echo '
286
+				if ($options['display_quick_mod'] == 1) {
287
+									echo '
270 288
 						<input type="checkbox" name="topics[]" value="', $topic['id'], '" class="input_check">';
271
-				else
289
+				} else
272 290
 				{
273 291
 					// Check permissions on each and show only the ones they are allowed to use.
274
-					if ($topic['quick_mod']['remove'])
275
-						echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=remove;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons delete" title="', $txt['remove_topic'], '"></span></a>';
292
+					if ($topic['quick_mod']['remove']) {
293
+											echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=remove;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons delete" title="', $txt['remove_topic'], '"></span></a>';
294
+					}
276 295
 
277
-					if ($topic['quick_mod']['lock'])
278
-						echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=lock;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons lock" title="', $topic['is_locked'] ? $txt['set_unlock'] : $txt['set_lock'], '"></span></a>';
296
+					if ($topic['quick_mod']['lock']) {
297
+											echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=lock;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons lock" title="', $topic['is_locked'] ? $txt['set_unlock'] : $txt['set_lock'], '"></span></a>';
298
+					}
279 299
 
280
-					if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove'])
281
-						echo '<br>';
300
+					if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove']) {
301
+											echo '<br>';
302
+					}
282 303
 
283
-					if ($topic['quick_mod']['sticky'])
284
-						echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=sticky;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons sticky" title="', $topic['is_sticky'] ? $txt['set_nonsticky'] : $txt['set_sticky'], '"></span></a>';
304
+					if ($topic['quick_mod']['sticky']) {
305
+											echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=sticky;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons sticky" title="', $topic['is_sticky'] ? $txt['set_nonsticky'] : $txt['set_sticky'], '"></span></a>';
306
+					}
285 307
 
286
-					if ($topic['quick_mod']['move'])
287
-						echo '<a href="', $scripturl, '?action=movetopic;current_board=', $context['current_board'], ';board=', $context['current_board'], '.', $context['start'], ';topic=', $topic['id'], '.0"><span class="generic_icons move" title="', $txt['move_topic'], '"></span></a>';
308
+					if ($topic['quick_mod']['move']) {
309
+											echo '<a href="', $scripturl, '?action=movetopic;current_board=', $context['current_board'], ';board=', $context['current_board'], '.', $context['start'], ';topic=', $topic['id'], '.0"><span class="generic_icons move" title="', $txt['move_topic'], '"></span></a>';
310
+					}
288 311
 				}
289 312
 				echo '
290 313
 					</div>';
@@ -302,18 +325,20 @@  discard block
 block discarded – undo
302 325
 					<select class="qaction" name="qaction"', $context['can_move'] ? ' onchange="this.form.move_to.disabled = (this.options[this.selectedIndex].value != \'move\');"' : '', '>
303 326
 						<option value="">--------</option>';
304 327
 
305
-			foreach ($context['qmod_actions'] as $qmod_action)
306
-				if ($context['can_' . $qmod_action])
328
+			foreach ($context['qmod_actions'] as $qmod_action) {
329
+							if ($context['can_' . $qmod_action])
307 330
 					echo '
308 331
 						<option value="' . $qmod_action . '">' . $txt['quick_mod_' . $qmod_action] . '</option>';
332
+			}
309 333
 
310 334
 			echo '
311 335
 					</select>';
312 336
 
313 337
 			// Show a list of boards they can move the topic to.
314
-			if ($context['can_move'])
315
-				echo '
338
+			if ($context['can_move']) {
339
+							echo '
316 340
 			<span id="quick_mod_jump_to">&nbsp;</span>';
341
+			}
317 342
 
318 343
 			echo '
319 344
 					<input type="submit" value="', $txt['quick_mod_go'], '" onclick="return document.forms.quickModForm.qaction.value != \'\' &amp;&amp; confirm(\'', $txt['quickmod_confirm'], '\');" class="button_submit qaction">
@@ -324,10 +349,11 @@  discard block
 block discarded – undo
324 349
 	</div>';
325 350
 
326 351
 		// Finish off the form - again.
327
-		if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics']))
328
-			echo '
352
+		if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics'])) {
353
+					echo '
329 354
 	<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '">
330 355
 	</form>';
356
+		}
331 357
 
332 358
 	// Mobile action buttons (bottom)
333 359
 	echo '
@@ -346,8 +372,8 @@  discard block
 block discarded – undo
346 372
 	// Show breadcrumbs at the bottom too.
347 373
 	theme_linktree();
348 374
 
349
-	if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']) && $context['can_move'])
350
-		echo '
375
+	if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']) && $context['can_move']) {
376
+			echo '
351 377
 			<script>
352 378
 				if (typeof(window.XMLHttpRequest) != "undefined")
353 379
 					aJumpTo[aJumpTo.length] = new JumpTo({
@@ -366,6 +392,7 @@  discard block
 block discarded – undo
366 392
 						sCustomName: "move_to"
367 393
 					});
368 394
 			</script>';
395
+	}
369 396
 
370 397
 	// Javascript for inline editing.
371 398
 	echo '
@@ -401,8 +428,8 @@  discard block
 block discarded – undo
401 428
 		<div class="information">
402 429
 			<p class="floatright" id="message_index_jump_to">&nbsp;</p>';
403 430
 
404
-	if (empty($context['no_topic_listing']))
405
-		echo '
431
+	if (empty($context['no_topic_listing'])) {
432
+			echo '
406 433
 			<p class="floatleft">', !empty($modSettings['enableParticipation']) && $context['user']['is_logged'] ? '
407 434
 				<img src="' . $settings['images_url'] . '/icons/profile_sm.png" alt="" class="centericon"> ' . $txt['participation_caption'] . '<br>' : '', '
408 435
 				'. ($modSettings['pollMode'] == '1' ? '<span class="generic_icons poll centericon"></span> ' . $txt['poll'] : '') . '<br>
@@ -412,9 +439,10 @@  discard block
 block discarded – undo
412 439
 				<span class="generic_icons lock centericon"></span> ' . $txt['locked_topic'] . '<br>
413 440
 				<span class="generic_icons sticky centericon"></span> ' . $txt['sticky_topic'] . '<br>
414 441
 			</p>';
442
+	}
415 443
 
416
-	if (!empty($context['jump_to']))
417
-		echo '
444
+	if (!empty($context['jump_to'])) {
445
+			echo '
418 446
 			<script>
419 447
 				if (typeof(window.XMLHttpRequest) != "undefined")
420 448
 					aJumpTo[aJumpTo.length] = new JumpTo({
@@ -430,6 +458,7 @@  discard block
 block discarded – undo
430 458
 						sGoButtonLabel: "', $txt['quick_mod_go'], '"
431 459
 					});
432 460
 			</script>';
461
+	}
433 462
 
434 463
 	echo '
435 464
 			<br class="clear">
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +792 added lines, -598 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,28 +48,36 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65 73
 		// We excpiclity do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded.
66
-		if (!is_array($modSettings['attachmentUploadDir']))
67
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
74
+		if (!is_array($modSettings['attachmentUploadDir'])) {
75
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
76
+		}
68 77
 
69
-		if (!empty($cache_enable))
70
-			cache_put_data('modSettings', $modSettings, 90);
78
+		if (!empty($cache_enable)) {
79
+					cache_put_data('modSettings', $modSettings, 90);
80
+		}
71 81
 	}
72 82
 
73 83
 	$modSettings['cache_enable'] = $cache_enable;
@@ -87,8 +97,9 @@  discard block
 block discarded – undo
87 97
 		};
88 98
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
89 99
 	{
90
-		if (!$utf8 || $smcFunc['db_mb4'])
91
-			return $string;
100
+		if (!$utf8 || $smcFunc['db_mb4']) {
101
+					return $string;
102
+		}
92 103
 
93 104
 		$i = 0;
94 105
 		$len = strlen($string);
@@ -100,18 +111,15 @@  discard block
 block discarded – undo
100 111
 			{
101 112
 				$new_string .= $string[$i];
102 113
 				$i++;
103
-			}
104
-			elseif ($ord < 224)
114
+			} elseif ($ord < 224)
105 115
 			{
106 116
 				$new_string .= $string[$i] . $string[$i + 1];
107 117
 				$i += 2;
108
-			}
109
-			elseif ($ord < 240)
118
+			} elseif ($ord < 240)
110 119
 			{
111 120
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
112 121
 				$i += 3;
113
-			}
114
-			elseif ($ord < 248)
122
+			} elseif ($ord < 248)
115 123
 			{
116 124
 				// Magic happens.
117 125
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -155,8 +163,7 @@  discard block
 block discarded – undo
155 163
 			{
156 164
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
157 165
 				return is_int($result) ? $result + $offset : false;
158
-			}
159
-			else
166
+			} else
160 167
 			{
161 168
 				$needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
162 169
 				$needle_size = count($needle_arr);
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 				while ((int) $result === $result)
166 173
 				{
167 174
 					$offset += $result;
168
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
169
-						return $offset;
175
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
176
+											return $offset;
177
+					}
170 178
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
171 179
 				}
172 180
 				return false;
@@ -204,8 +212,9 @@  discard block
 block discarded – undo
204 212
 			$string = $ent_check($string);
205 213
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
206 214
 			$string = $matches[0];
207
-			while (strlen($string) > $length)
208
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
215
+			while (strlen($string) > $length) {
216
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
217
+			}
209 218
 			return $string;
210 219
 		},
211 220
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -215,8 +224,9 @@  discard block
 block discarded – undo
215 224
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
216 225
 		{
217 226
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
218
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
219
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
227
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
228
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
229
+			}
220 230
 			return implode('', $words);
221 231
 		} : 'ucwords',
222 232
 		'json_decode' => 'smf_json_decode',
@@ -224,16 +234,17 @@  discard block
 block discarded – undo
224 234
 	);
225 235
 
226 236
 	// Setting the timezone is a requirement for some functions.
227
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
228
-		date_default_timezone_set($modSettings['default_timezone']);
229
-	else
237
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
238
+			date_default_timezone_set($modSettings['default_timezone']);
239
+	} else
230 240
 	{
231 241
 		// Get PHP's default timezone, if set
232 242
 		$ini_tz = ini_get('date.timezone');
233
-		if (!empty($ini_tz))
234
-			$modSettings['default_timezone'] = $ini_tz;
235
-		else
236
-			$modSettings['default_timezone'] = '';
243
+		if (!empty($ini_tz)) {
244
+					$modSettings['default_timezone'] = $ini_tz;
245
+		} else {
246
+					$modSettings['default_timezone'] = '';
247
+		}
237 248
 
238 249
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
239 250
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -251,22 +262,26 @@  discard block
 block discarded – undo
251 262
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
252 263
 		{
253 264
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
254
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
255
-				$modSettings['load_average'] = (float) $matches[1];
256
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
257
-				$modSettings['load_average'] = (float) $matches[1];
258
-			else
259
-				unset($modSettings['load_average']);
265
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
266
+							$modSettings['load_average'] = (float) $matches[1];
267
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
268
+							$modSettings['load_average'] = (float) $matches[1];
269
+			} else {
270
+							unset($modSettings['load_average']);
271
+			}
260 272
 
261
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
262
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
273
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
274
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
275
+			}
263 276
 		}
264 277
 
265
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
266
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
278
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
279
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
280
+		}
267 281
 
268
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
269
-			display_loadavg_error();
282
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
283
+					display_loadavg_error();
284
+		}
270 285
 	}
271 286
 
272 287
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -287,8 +302,9 @@  discard block
 block discarded – undo
287 302
 	if (defined('SMF_INTEGRATION_SETTINGS'))
288 303
 	{
289 304
 		$integration_settings = $smcFUnc['json_decode'](SMF_INTEGRATION_SETTINGS, true);
290
-		foreach ($integration_settings as $hook => $function)
291
-			add_integration_function($hook, $function, '', false);
305
+		foreach ($integration_settings as $hook => $function) {
306
+					add_integration_function($hook, $function, '', false);
307
+		}
292 308
 	}
293 309
 
294 310
 	// Any files to pre include?
@@ -298,8 +314,9 @@  discard block
 block discarded – undo
298 314
 		foreach ($pre_includes as $include)
299 315
 		{
300 316
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
301
-			if (file_exists($include))
302
-				require_once($include);
317
+			if (file_exists($include)) {
318
+							require_once($include);
319
+			}
303 320
 		}
304 321
 	}
305 322
 
@@ -403,27 +420,28 @@  discard block
 block discarded – undo
403 420
 				break;
404 421
 			}
405 422
 		}
423
+	} else {
424
+			$id_member = 0;
406 425
 	}
407
-	else
408
-		$id_member = 0;
409 426
 
410 427
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
411 428
 	{
412 429
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
413 430
 
414
-		if (empty($cookie_data))
415
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
431
+		if (empty($cookie_data)) {
432
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
433
+		}
416 434
 
417 435
 		list ($id_member, $password) = $cookie_data;
418 436
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
419
-	}
420
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
437
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
421 438
 	{
422 439
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
423 440
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
424 441
 
425
-		if (empty($cookie_data))
426
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
442
+		if (empty($cookie_data)) {
443
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
444
+		}
427 445
 
428 446
 		list ($id_member, $password, $login_span) = $cookie_data;
429 447
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -448,30 +466,34 @@  discard block
 block discarded – undo
448 466
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
449 467
 			$smcFunc['db_free_result']($request);
450 468
 
451
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
452
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
469
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
470
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
471
+			}
453 472
 
454
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
455
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
473
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
474
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
475
+			}
456 476
 		}
457 477
 
458 478
 		// Did we find 'im?  If not, junk it.
459 479
 		if (!empty($user_settings))
460 480
 		{
461 481
 			// As much as the password should be right, we can assume the integration set things up.
462
-			if (!empty($already_verified) && $already_verified === true)
463
-				$check = true;
482
+			if (!empty($already_verified) && $already_verified === true) {
483
+							$check = true;
484
+			}
464 485
 			// SHA-512 hash should be 128 characters long.
465
-			elseif (strlen($password) == 128)
466
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
467
-			else
468
-				$check = false;
486
+			elseif (strlen($password) == 128) {
487
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
488
+			} else {
489
+							$check = false;
490
+			}
469 491
 
470 492
 			// Wrong password or not activated - either way, you're going nowhere.
471 493
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
494
+		} else {
495
+					$id_member = 0;
472 496
 		}
473
-		else
474
-			$id_member = 0;
475 497
 
476 498
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
477 499
 		if (!$id_member)
@@ -495,8 +517,9 @@  discard block
 block discarded – undo
495 517
 
496 518
 					list ($tfamember, $tfasecret) = $tfa_data;
497 519
 
498
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
499
-						$tfasecret = null;
520
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
521
+											$tfasecret = null;
522
+					}
500 523
 				}
501 524
 
502 525
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -516,10 +539,12 @@  discard block
 block discarded – undo
516 539
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
517 540
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
518 541
 		{
519
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
542
+			if ($modSettings['tfa_mode'] == 2) {
543
+				//only do this if we are just forcing SOME membergroups
520 544
 			{
521 545
 				//Build an array of ALL user membergroups.
522 546
 				$full_groups = array($user_settings['id_group']);
547
+			}
523 548
 				if (!empty($user_settings['additional_groups']))
524 549
 				{
525 550
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -539,15 +564,17 @@  discard block
 block discarded – undo
539 564
 				);
540 565
 				$row = $smcFunc['db_fetch_assoc']($request);
541 566
 				$smcFunc['db_free_result']($request);
567
+			} else {
568
+							$row['total'] = 1;
542 569
 			}
543
-			else
544
-				$row['total'] = 1; //simplifies logics in the next "if"
570
+			//simplifies logics in the next "if"
545 571
 
546 572
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
547 573
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
548 574
 
549
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
550
-				redirectexit('action=profile;area=tfasetup;forced');
575
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
576
+							redirectexit('action=profile;area=tfasetup;forced');
577
+			}
551 578
 		}
552 579
 	}
553 580
 
@@ -584,33 +611,37 @@  discard block
 block discarded – undo
584 611
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
585 612
 				$user_settings['last_login'] = time();
586 613
 
587
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
588
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
614
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
615
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
616
+				}
589 617
 
590
-				if (!empty($modSettings['cache_enable']))
591
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
618
+				if (!empty($modSettings['cache_enable'])) {
619
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
620
+				}
592 621
 			}
622
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
623
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
593 624
 		}
594
-		elseif (empty($_SESSION['id_msg_last_visit']))
595
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
596 625
 
597 626
 		$username = $user_settings['member_name'];
598 627
 
599
-		if (empty($user_settings['additional_groups']))
600
-			$user_info = array(
628
+		if (empty($user_settings['additional_groups'])) {
629
+					$user_info = array(
601 630
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
602 631
 			);
603
-		else
604
-			$user_info = array(
632
+		} else {
633
+					$user_info = array(
605 634
 				'groups' => array_merge(
606 635
 					array($user_settings['id_group'], $user_settings['id_post_group']),
607 636
 					explode(',', $user_settings['additional_groups'])
608 637
 				)
609 638
 			);
639
+		}
610 640
 
611 641
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
612
-		foreach ($user_info['groups'] as $k => $v)
613
-			$user_info['groups'][$k] = (int) $v;
642
+		foreach ($user_info['groups'] as $k => $v) {
643
+					$user_info['groups'][$k] = (int) $v;
644
+		}
614 645
 
615 646
 		// This is a logged in user, so definitely not a spider.
616 647
 		$user_info['possibly_robot'] = false;
@@ -624,8 +655,7 @@  discard block
 block discarded – undo
624 655
 			$time_system = new DateTime('now', $tz_system);
625 656
 			$time_user = new DateTime('now', $tz_user);
626 657
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
627
-		}
628
-		else
658
+		} else
629 659
 		{
630 660
 			// !!! Compatibility.
631 661
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -639,8 +669,9 @@  discard block
 block discarded – undo
639 669
 		$user_info = array('groups' => array(-1));
640 670
 		$user_settings = array();
641 671
 
642
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
643
-			$_COOKIE[$cookiename] = '';
672
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
673
+					$_COOKIE[$cookiename] = '';
674
+		}
644 675
 
645 676
 		// Expire the 2FA cookie
646 677
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -657,19 +688,20 @@  discard block
 block discarded – undo
657 688
 		}
658 689
 
659 690
 		// Create a login token if it doesn't exist yet.
660
-		if (!isset($_SESSION['token']['post-login']))
661
-			createToken('login');
662
-		else
663
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
691
+		if (!isset($_SESSION['token']['post-login'])) {
692
+					createToken('login');
693
+		} else {
694
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
695
+		}
664 696
 
665 697
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
666 698
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
667 699
 		{
668 700
 			require_once($sourcedir . '/ManageSearchEngines.php');
669 701
 			$user_info['possibly_robot'] = SpiderCheck();
702
+		} elseif (!empty($modSettings['spider_mode'])) {
703
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
670 704
 		}
671
-		elseif (!empty($modSettings['spider_mode']))
672
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
673 705
 		// If we haven't turned on proper spider hunts then have a guess!
674 706
 		else
675 707
 		{
@@ -717,8 +749,9 @@  discard block
 block discarded – undo
717 749
 	$user_info['groups'] = array_unique($user_info['groups']);
718 750
 
719 751
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
720
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
721
-		unset($user_info['ignoreboards'][$tmp]);
752
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
753
+			unset($user_info['ignoreboards'][$tmp]);
754
+	}
722 755
 
723 756
 	// Allow the user to change their language.
724 757
 	if (!empty($modSettings['userLanguage']))
@@ -731,31 +764,36 @@  discard block
 block discarded – undo
731 764
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
732 765
 
733 766
 			// Make it permanent for members.
734
-			if (!empty($user_info['id']))
735
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
736
-			else
737
-				$_SESSION['language'] = $user_info['language'];
767
+			if (!empty($user_info['id'])) {
768
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
769
+			} else {
770
+							$_SESSION['language'] = $user_info['language'];
771
+			}
772
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
773
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
738 774
 		}
739
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
740
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
741 775
 	}
742 776
 
743 777
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
744
-	if ($user_info['is_admin'])
745
-		$user_info['query_see_board'] = '1=1';
778
+	if ($user_info['is_admin']) {
779
+			$user_info['query_see_board'] = '1=1';
780
+	}
746 781
 	// Otherwise just the groups in $user_info['groups'].
747
-	else
748
-		$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
782
+	else {
783
+			$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
784
+	}
749 785
 
750 786
 	// Build the list of boards they WANT to see.
751 787
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
752 788
 
753 789
 	// If they aren't ignoring any boards then they want to see all the boards they can see
754
-	if (empty($user_info['ignoreboards']))
755
-		$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
790
+	if (empty($user_info['ignoreboards'])) {
791
+			$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
792
+	}
756 793
 	// Ok I guess they don't want to see all the boards
757
-	else
758
-		$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
794
+	else {
795
+			$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
796
+	}
759 797
 
760 798
 	call_integration_hook('integrate_user_info');
761 799
 }
@@ -813,9 +851,9 @@  discard block
 block discarded – undo
813 851
 		}
814 852
 
815 853
 		// Remember redirection is the key to avoiding fallout from your bosses.
816
-		if (!empty($topic))
817
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
818
-		else
854
+		if (!empty($topic)) {
855
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
856
+		} else
819 857
 		{
820 858
 			loadPermissions();
821 859
 			loadTheme();
@@ -833,10 +871,11 @@  discard block
 block discarded – undo
833 871
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
834 872
 	{
835 873
 		// @todo SLOW?
836
-		if (!empty($topic))
837
-			$temp = cache_get_data('topic_board-' . $topic, 120);
838
-		else
839
-			$temp = cache_get_data('board-' . $board, 120);
874
+		if (!empty($topic)) {
875
+					$temp = cache_get_data('topic_board-' . $topic, 120);
876
+		} else {
877
+					$temp = cache_get_data('board-' . $board, 120);
878
+		}
840 879
 
841 880
 		if (!empty($temp))
842 881
 		{
@@ -874,8 +913,9 @@  discard block
 block discarded – undo
874 913
 			$row = $smcFunc['db_fetch_assoc']($request);
875 914
 
876 915
 			// Set the current board.
877
-			if (!empty($row['id_board']))
878
-				$board = $row['id_board'];
916
+			if (!empty($row['id_board'])) {
917
+							$board = $row['id_board'];
918
+			}
879 919
 
880 920
 			// Basic operating information. (globals... :/)
881 921
 			$board_info = array(
@@ -911,21 +951,23 @@  discard block
 block discarded – undo
911 951
 
912 952
 			do
913 953
 			{
914
-				if (!empty($row['id_moderator']))
915
-					$board_info['moderators'][$row['id_moderator']] = array(
954
+				if (!empty($row['id_moderator'])) {
955
+									$board_info['moderators'][$row['id_moderator']] = array(
916 956
 						'id' => $row['id_moderator'],
917 957
 						'name' => $row['real_name'],
918 958
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
919 959
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
920 960
 					);
961
+				}
921 962
 
922
-				if (!empty($row['id_moderator_group']))
923
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
963
+				if (!empty($row['id_moderator_group'])) {
964
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
924 965
 						'id' => $row['id_moderator_group'],
925 966
 						'name' => $row['group_name'],
926 967
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
927 968
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
928 969
 					);
970
+				}
929 971
 			}
930 972
 			while ($row = $smcFunc['db_fetch_assoc']($request));
931 973
 
@@ -957,12 +999,12 @@  discard block
 block discarded – undo
957 999
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
958 1000
 			{
959 1001
 				// @todo SLOW?
960
-				if (!empty($topic))
961
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
1002
+				if (!empty($topic)) {
1003
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1004
+				}
962 1005
 				cache_put_data('board-' . $board, $board_info, 120);
963 1006
 			}
964
-		}
965
-		else
1007
+		} else
966 1008
 		{
967 1009
 			// Otherwise the topic is invalid, there are no moderators, etc.
968 1010
 			$board_info = array(
@@ -976,8 +1018,9 @@  discard block
 block discarded – undo
976 1018
 		$smcFunc['db_free_result']($request);
977 1019
 	}
978 1020
 
979
-	if (!empty($topic))
980
-		$_GET['board'] = (int) $board;
1021
+	if (!empty($topic)) {
1022
+			$_GET['board'] = (int) $board;
1023
+	}
981 1024
 
982 1025
 	if (!empty($board))
983 1026
 	{
@@ -987,10 +1030,12 @@  discard block
 block discarded – undo
987 1030
 		// Now check if the user is a moderator.
988 1031
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
989 1032
 
990
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
991
-			$board_info['error'] = 'access';
992
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
993
-			$board_info['error'] = 'access';
1033
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1034
+					$board_info['error'] = 'access';
1035
+		}
1036
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1037
+					$board_info['error'] = 'access';
1038
+		}
994 1039
 
995 1040
 		// Build up the linktree.
996 1041
 		$context['linktree'] = array_merge(
@@ -1013,8 +1058,9 @@  discard block
 block discarded – undo
1013 1058
 	$context['current_board'] = $board;
1014 1059
 
1015 1060
 	// No posting in redirection boards!
1016
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1017
-		$board_info['error'] == 'post_in_redirect';
1061
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1062
+			$board_info['error'] == 'post_in_redirect';
1063
+	}
1018 1064
 
1019 1065
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1020 1066
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1040,24 +1086,23 @@  discard block
 block discarded – undo
1040 1086
 			ob_end_clean();
1041 1087
 			header('HTTP/1.1 403 Forbidden');
1042 1088
 			die;
1043
-		}
1044
-		elseif ($board_info['error'] == 'post_in_redirect')
1089
+		} elseif ($board_info['error'] == 'post_in_redirect')
1045 1090
 		{
1046 1091
 			// Slightly different error message here...
1047 1092
 			fatal_lang_error('cannot_post_redirect', false);
1048
-		}
1049
-		elseif ($user_info['is_guest'])
1093
+		} elseif ($user_info['is_guest'])
1050 1094
 		{
1051 1095
 			loadLanguage('Errors');
1052 1096
 			is_not_guest($txt['topic_gone']);
1097
+		} else {
1098
+					fatal_lang_error('topic_gone', false);
1053 1099
 		}
1054
-		else
1055
-			fatal_lang_error('topic_gone', false);
1056 1100
 	}
1057 1101
 
1058
-	if ($user_info['is_mod'])
1059
-		$user_info['groups'][] = 3;
1060
-}
1102
+	if ($user_info['is_mod']) {
1103
+			$user_info['groups'][] = 3;
1104
+	}
1105
+	}
1061 1106
 
1062 1107
 /**
1063 1108
  * Load this user's permissions.
@@ -1078,8 +1123,9 @@  discard block
 block discarded – undo
1078 1123
 		asort($cache_groups);
1079 1124
 		$cache_groups = implode(',', $cache_groups);
1080 1125
 		// If it's a spider then cache it different.
1081
-		if ($user_info['possibly_robot'])
1082
-			$cache_groups .= '-spider';
1126
+		if ($user_info['possibly_robot']) {
1127
+					$cache_groups .= '-spider';
1128
+		}
1083 1129
 
1084 1130
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1085 1131
 		{
@@ -1087,9 +1133,9 @@  discard block
 block discarded – undo
1087 1133
 			banPermissions();
1088 1134
 
1089 1135
 			return;
1136
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1137
+					list ($user_info['permissions'], $removals) = $temp;
1090 1138
 		}
1091
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1092
-			list ($user_info['permissions'], $removals) = $temp;
1093 1139
 	}
1094 1140
 
1095 1141
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1111,23 +1157,26 @@  discard block
 block discarded – undo
1111 1157
 		$removals = array();
1112 1158
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1113 1159
 		{
1114
-			if (empty($row['add_deny']))
1115
-				$removals[] = $row['permission'];
1116
-			else
1117
-				$user_info['permissions'][] = $row['permission'];
1160
+			if (empty($row['add_deny'])) {
1161
+							$removals[] = $row['permission'];
1162
+			} else {
1163
+							$user_info['permissions'][] = $row['permission'];
1164
+			}
1118 1165
 		}
1119 1166
 		$smcFunc['db_free_result']($request);
1120 1167
 
1121
-		if (isset($cache_groups))
1122
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1168
+		if (isset($cache_groups)) {
1169
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1170
+		}
1123 1171
 	}
1124 1172
 
1125 1173
 	// Get the board permissions.
1126 1174
 	if (!empty($board))
1127 1175
 	{
1128 1176
 		// Make sure the board (if any) has been loaded by loadBoard().
1129
-		if (!isset($board_info['profile']))
1130
-			fatal_lang_error('no_board');
1177
+		if (!isset($board_info['profile'])) {
1178
+					fatal_lang_error('no_board');
1179
+		}
1131 1180
 
1132 1181
 		$request = $smcFunc['db_query']('', '
1133 1182
 			SELECT permission, add_deny
@@ -1143,20 +1192,23 @@  discard block
 block discarded – undo
1143 1192
 		);
1144 1193
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1145 1194
 		{
1146
-			if (empty($row['add_deny']))
1147
-				$removals[] = $row['permission'];
1148
-			else
1149
-				$user_info['permissions'][] = $row['permission'];
1195
+			if (empty($row['add_deny'])) {
1196
+							$removals[] = $row['permission'];
1197
+			} else {
1198
+							$user_info['permissions'][] = $row['permission'];
1199
+			}
1150 1200
 		}
1151 1201
 		$smcFunc['db_free_result']($request);
1152 1202
 	}
1153 1203
 
1154 1204
 	// Remove all the permissions they shouldn't have ;).
1155
-	if (!empty($modSettings['permission_enable_deny']))
1156
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1205
+	if (!empty($modSettings['permission_enable_deny'])) {
1206
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1207
+	}
1157 1208
 
1158
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1159
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1209
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1210
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1211
+	}
1160 1212
 
1161 1213
 	// Banned?  Watch, don't touch..
1162 1214
 	banPermissions();
@@ -1168,17 +1220,18 @@  discard block
 block discarded – undo
1168 1220
 		{
1169 1221
 			require_once($sourcedir . '/Subs-Auth.php');
1170 1222
 			rebuildModCache();
1223
+		} else {
1224
+					$user_info['mod_cache'] = $_SESSION['mc'];
1171 1225
 		}
1172
-		else
1173
-			$user_info['mod_cache'] = $_SESSION['mc'];
1174 1226
 
1175 1227
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1176 1228
 		// For example this drastically simplifies certain changes to the profile area.
1177 1229
 		$user_info['permissions'][] = 'is_not_guest';
1178 1230
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1179 1231
 		$user_info['permissions'][] = 'profile_view_own';
1180
-		if (in_array('profile_view', $user_info['permissions']))
1181
-			$user_info['permissions'][] = 'profile_view_any';
1232
+		if (in_array('profile_view', $user_info['permissions'])) {
1233
+					$user_info['permissions'][] = 'profile_view_any';
1234
+		}
1182 1235
 	}
1183 1236
 }
1184 1237
 
@@ -1196,8 +1249,9 @@  discard block
 block discarded – undo
1196 1249
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1197 1250
 
1198 1251
 	// Can't just look for no users :P.
1199
-	if (empty($users))
1200
-		return array();
1252
+	if (empty($users)) {
1253
+			return array();
1254
+	}
1201 1255
 
1202 1256
 	// Pass the set value
1203 1257
 	$context['loadMemberContext_set'] = $set;
@@ -1212,8 +1266,9 @@  discard block
 block discarded – undo
1212 1266
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1213 1267
 		{
1214 1268
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1215
-			if ($data == null)
1216
-				continue;
1269
+			if ($data == null) {
1270
+							continue;
1271
+			}
1217 1272
 
1218 1273
 			$loaded_ids[] = $data['id_member'];
1219 1274
 			$user_profile[$data['id_member']] = $data;
@@ -1280,13 +1335,16 @@  discard block
 block discarded – undo
1280 1335
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1281 1336
 
1282 1337
 			// Take care of proxying avatar if required, do this here for maximum reach
1283
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1284
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1338
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1339
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1340
+			}
1285 1341
 
1286
-			if (isset($row['member_ip']))
1287
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1288
-			if (isset($row['member_ip2']))
1289
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1342
+			if (isset($row['member_ip'])) {
1343
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1344
+			}
1345
+			if (isset($row['member_ip2'])) {
1346
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1347
+			}
1290 1348
 			$new_loaded_ids[] = $row['id_member'];
1291 1349
 			$loaded_ids[] = $row['id_member'];
1292 1350
 			$row['options'] = array();
@@ -1305,8 +1363,9 @@  discard block
 block discarded – undo
1305 1363
 				'loaded_ids' => $new_loaded_ids,
1306 1364
 			)
1307 1365
 		);
1308
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1309
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1366
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1367
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1368
+		}
1310 1369
 		$smcFunc['db_free_result']($request);
1311 1370
 	}
1312 1371
 
@@ -1317,10 +1376,11 @@  discard block
 block discarded – undo
1317 1376
 	{
1318 1377
 		foreach ($loaded_ids as $a_member)
1319 1378
 		{
1320
-			if (!empty($user_profile[$a_member]['additional_groups']))
1321
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1322
-			else
1323
-				$groups = array($user_profile[$a_member]['id_group']);
1379
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1380
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1381
+			} else {
1382
+							$groups = array($user_profile[$a_member]['id_group']);
1383
+			}
1324 1384
 
1325 1385
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1326 1386
 
@@ -1333,8 +1393,9 @@  discard block
 block discarded – undo
1333 1393
 
1334 1394
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1335 1395
 	{
1336
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1337
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1396
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1397
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1398
+		}
1338 1399
 	}
1339 1400
 
1340 1401
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1360,14 +1421,17 @@  discard block
 block discarded – undo
1360 1421
 		foreach ($temp_mods as $id)
1361 1422
 		{
1362 1423
 			// By popular demand, don't show admins or global moderators as moderators.
1363
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1364
-				$user_profile[$id]['member_group'] = $row['member_group'];
1424
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1425
+							$user_profile[$id]['member_group'] = $row['member_group'];
1426
+			}
1365 1427
 
1366 1428
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1367
-			if (!empty($row['icons']))
1368
-				$user_profile[$id]['icons'] = $row['icons'];
1369
-			if (!empty($row['member_group_color']))
1370
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1429
+			if (!empty($row['icons'])) {
1430
+							$user_profile[$id]['icons'] = $row['icons'];
1431
+			}
1432
+			if (!empty($row['member_group_color'])) {
1433
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1434
+			}
1371 1435
 		}
1372 1436
 	}
1373 1437
 
@@ -1389,12 +1453,14 @@  discard block
 block discarded – undo
1389 1453
 	static $loadedLanguages = array();
1390 1454
 
1391 1455
 	// If this person's data is already loaded, skip it.
1392
-	if (isset($dataLoaded[$user]))
1393
-		return true;
1456
+	if (isset($dataLoaded[$user])) {
1457
+			return true;
1458
+	}
1394 1459
 
1395 1460
 	// We can't load guests or members not loaded by loadMemberData()!
1396
-	if ($user == 0)
1397
-		return false;
1461
+	if ($user == 0) {
1462
+			return false;
1463
+	}
1398 1464
 	if (!isset($user_profile[$user]))
1399 1465
 	{
1400 1466
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1420,12 +1486,16 @@  discard block
 block discarded – undo
1420 1486
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1421 1487
 
1422 1488
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1423
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1489
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1490
+		//icon is set and exists
1424 1491
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1425
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1492
+	} elseif (isset($profile['icons'][1])) {
1493
+		//icon is set and doesn't exist, fallback to default
1426 1494
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1427
-	else //not set, bye bye
1495
+	} else {
1496
+		//not set, bye bye
1428 1497
 		$group_icon_url = '';
1498
+	}
1429 1499
 
1430 1500
 	// These minimal values are always loaded
1431 1501
 	$memberContext[$user] = array(
@@ -1444,8 +1514,9 @@  discard block
 block discarded – undo
1444 1514
 	if ($context['loadMemberContext_set'] != 'minimal')
1445 1515
 	{
1446 1516
 		// Go the extra mile and load the user's native language name.
1447
-		if (empty($loadedLanguages))
1448
-			$loadedLanguages = getLanguages();
1517
+		if (empty($loadedLanguages)) {
1518
+					$loadedLanguages = getLanguages();
1519
+		}
1449 1520
 
1450 1521
 		$memberContext[$user] += array(
1451 1522
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1499,31 +1570,33 @@  discard block
 block discarded – undo
1499 1570
 	{
1500 1571
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1501 1572
 		{
1502
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1503
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1504
-			else
1505
-				$image = get_gravatar_url($profile['email_address']);
1506
-		}
1507
-		else
1573
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1574
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1575
+			} else {
1576
+							$image = get_gravatar_url($profile['email_address']);
1577
+			}
1578
+		} else
1508 1579
 		{
1509 1580
 			// So it's stored in the member table?
1510 1581
 			if (!empty($profile['avatar']))
1511 1582
 			{
1512 1583
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1584
+			} elseif (!empty($profile['filename'])) {
1585
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1513 1586
 			}
1514
-			elseif (!empty($profile['filename']))
1515
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1516 1587
 			// Right... no avatar...use the default one
1517
-			else
1518
-				$image = $modSettings['avatar_url'] . '/default.png';
1588
+			else {
1589
+							$image = $modSettings['avatar_url'] . '/default.png';
1590
+			}
1519 1591
 		}
1520
-		if (!empty($image))
1521
-			$memberContext[$user]['avatar'] = array(
1592
+		if (!empty($image)) {
1593
+					$memberContext[$user]['avatar'] = array(
1522 1594
 				'name' => $profile['avatar'],
1523 1595
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1524 1596
 				'href' => $image,
1525 1597
 				'url' => $image,
1526 1598
 			);
1599
+		}
1527 1600
 	}
1528 1601
 
1529 1602
 	// Are we also loading the members custom fields into context?
@@ -1531,35 +1604,41 @@  discard block
 block discarded – undo
1531 1604
 	{
1532 1605
 		$memberContext[$user]['custom_fields'] = array();
1533 1606
 
1534
-		if (!isset($context['display_fields']))
1535
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1607
+		if (!isset($context['display_fields'])) {
1608
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1609
+		}
1536 1610
 
1537 1611
 		foreach ($context['display_fields'] as $custom)
1538 1612
 		{
1539
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1540
-				continue;
1613
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1614
+							continue;
1615
+			}
1541 1616
 
1542 1617
 			$value = $profile['options'][$custom['col_name']];
1543 1618
 
1544 1619
 			// Don't show the "disabled" option for the "gender" field.
1545
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1546
-				continue;
1620
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1621
+							continue;
1622
+			}
1547 1623
 
1548 1624
 			// BBC?
1549
-			if ($custom['bbc'])
1550
-				$value = parse_bbc($value);
1625
+			if ($custom['bbc']) {
1626
+							$value = parse_bbc($value);
1627
+			}
1551 1628
 			// ... or checkbox?
1552
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1553
-				$value = $value ? $txt['yes'] : $txt['no'];
1629
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1630
+							$value = $value ? $txt['yes'] : $txt['no'];
1631
+			}
1554 1632
 
1555 1633
 			// Enclosing the user input within some other text?
1556
-			if (!empty($custom['enclose']))
1557
-				$value = strtr($custom['enclose'], array(
1634
+			if (!empty($custom['enclose'])) {
1635
+							$value = strtr($custom['enclose'], array(
1558 1636
 					'{SCRIPTURL}' => $scripturl,
1559 1637
 					'{IMAGES_URL}' => $settings['images_url'],
1560 1638
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1561 1639
 					'{INPUT}' => $value,
1562 1640
 				));
1641
+			}
1563 1642
 
1564 1643
 			$memberContext[$user]['custom_fields'][] = array(
1565 1644
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1586,8 +1665,9 @@  discard block
 block discarded – undo
1586 1665
 	global $smcFunc, $txt, $scripturl, $settings;
1587 1666
 
1588 1667
 	// Do not waste my time...
1589
-	if (empty($users) || empty($params))
1590
-		return false;
1668
+	if (empty($users) || empty($params)) {
1669
+			return false;
1670
+	}
1591 1671
 
1592 1672
 	// Make sure it's an array.
1593 1673
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1611,31 +1691,36 @@  discard block
 block discarded – undo
1611 1691
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1612 1692
 	{
1613 1693
 		// BBC?
1614
-		if (!empty($row['bbc']))
1615
-			$row['value'] = parse_bbc($row['value']);
1694
+		if (!empty($row['bbc'])) {
1695
+					$row['value'] = parse_bbc($row['value']);
1696
+		}
1616 1697
 
1617 1698
 		// ... or checkbox?
1618
-		elseif (isset($row['type']) && $row['type'] == 'check')
1619
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1699
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1700
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1701
+		}
1620 1702
 
1621 1703
 		// Enclosing the user input within some other text?
1622
-		if (!empty($row['enclose']))
1623
-			$row['value'] = strtr($row['enclose'], array(
1704
+		if (!empty($row['enclose'])) {
1705
+					$row['value'] = strtr($row['enclose'], array(
1624 1706
 				'{SCRIPTURL}' => $scripturl,
1625 1707
 				'{IMAGES_URL}' => $settings['images_url'],
1626 1708
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1627 1709
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1628 1710
 			));
1711
+		}
1629 1712
 
1630 1713
 		// Send a simple array if there is just 1 param
1631
-		if (count($params) == 1)
1632
-			$return[$row['id_member']] = $row;
1714
+		if (count($params) == 1) {
1715
+					$return[$row['id_member']] = $row;
1716
+		}
1633 1717
 
1634 1718
 		// More than 1? knock yourself out...
1635 1719
 		else
1636 1720
 		{
1637
-			if (!isset($return[$row['id_member']]))
1638
-				$return[$row['id_member']] = array();
1721
+			if (!isset($return[$row['id_member']])) {
1722
+							$return[$row['id_member']] = array();
1723
+			}
1639 1724
 
1640 1725
 			$return[$row['id_member']][$row['variable']] = $row;
1641 1726
 		}
@@ -1669,8 +1754,9 @@  discard block
 block discarded – undo
1669 1754
 	global $context;
1670 1755
 
1671 1756
 	// Don't know any browser!
1672
-	if (empty($context['browser']))
1673
-		detectBrowser();
1757
+	if (empty($context['browser'])) {
1758
+			detectBrowser();
1759
+	}
1674 1760
 
1675 1761
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1676 1762
 }
@@ -1688,8 +1774,9 @@  discard block
 block discarded – undo
1688 1774
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1689 1775
 
1690 1776
 	// The theme was specified by parameter.
1691
-	if (!empty($id_theme))
1692
-		$id_theme = (int) $id_theme;
1777
+	if (!empty($id_theme)) {
1778
+			$id_theme = (int) $id_theme;
1779
+	}
1693 1780
 	// The theme was specified by REQUEST.
1694 1781
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1695 1782
 	{
@@ -1697,51 +1784,58 @@  discard block
 block discarded – undo
1697 1784
 		$_SESSION['id_theme'] = $id_theme;
1698 1785
 	}
1699 1786
 	// The theme was specified by REQUEST... previously.
1700
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1701
-		$id_theme = (int) $_SESSION['id_theme'];
1787
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1788
+			$id_theme = (int) $_SESSION['id_theme'];
1789
+	}
1702 1790
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1703
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1704
-		$id_theme = $user_info['theme'];
1791
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1792
+			$id_theme = $user_info['theme'];
1793
+	}
1705 1794
 	// The theme was specified by the board.
1706
-	elseif (!empty($board_info['theme']))
1707
-		$id_theme = $board_info['theme'];
1795
+	elseif (!empty($board_info['theme'])) {
1796
+			$id_theme = $board_info['theme'];
1797
+	}
1708 1798
 	// The theme is the forum's default.
1709
-	else
1710
-		$id_theme = $modSettings['theme_guests'];
1799
+	else {
1800
+			$id_theme = $modSettings['theme_guests'];
1801
+	}
1711 1802
 
1712 1803
 	// Verify the id_theme... no foul play.
1713 1804
 	// Always allow the board specific theme, if they are overriding.
1714
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1715
-		$id_theme = $board_info['theme'];
1805
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1806
+			$id_theme = $board_info['theme'];
1807
+	}
1716 1808
 	// If they have specified a particular theme to use with SSI allow it to be used.
1717
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1718
-		$id_theme = (int) $id_theme;
1719
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1809
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1810
+			$id_theme = (int) $id_theme;
1811
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1720 1812
 	{
1721 1813
 		$themes = explode(',', $modSettings['enableThemes']);
1722
-		if (!in_array($id_theme, $themes))
1723
-			$id_theme = $modSettings['theme_guests'];
1724
-		else
1814
+		if (!in_array($id_theme, $themes)) {
1815
+					$id_theme = $modSettings['theme_guests'];
1816
+		} else {
1817
+					$id_theme = (int) $id_theme;
1818
+		}
1819
+	} else {
1725 1820
 			$id_theme = (int) $id_theme;
1726 1821
 	}
1727
-	else
1728
-		$id_theme = (int) $id_theme;
1729 1822
 
1730 1823
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1731 1824
 
1732 1825
 	// Disable image proxy if we don't have SSL enabled
1733
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1734
-		$image_proxy_enabled = false;
1826
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1827
+			$image_proxy_enabled = false;
1828
+	}
1735 1829
 
1736 1830
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1737 1831
 	{
1738 1832
 		$themeData = $temp;
1739 1833
 		$flag = true;
1834
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1835
+			$themeData = $temp + array($member => array());
1836
+	} else {
1837
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1740 1838
 	}
1741
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1742
-		$themeData = $temp + array($member => array());
1743
-	else
1744
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1745 1839
 
1746 1840
 	if (empty($flag))
1747 1841
 	{
@@ -1760,31 +1854,37 @@  discard block
 block discarded – undo
1760 1854
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1761 1855
 		{
1762 1856
 			// There are just things we shouldn't be able to change as members.
1763
-			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1764
-				continue;
1857
+			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1858
+							continue;
1859
+			}
1765 1860
 
1766 1861
 			// If this is the theme_dir of the default theme, store it.
1767
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1768
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1862
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1863
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1864
+			}
1769 1865
 
1770 1866
 			// If this isn't set yet, is a theme option, or is not the default theme..
1771
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1772
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1867
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1868
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1869
+			}
1773 1870
 		}
1774 1871
 		$smcFunc['db_free_result']($result);
1775 1872
 
1776
-		if (!empty($themeData[-1]))
1777
-			foreach ($themeData[-1] as $k => $v)
1873
+		if (!empty($themeData[-1])) {
1874
+					foreach ($themeData[-1] as $k => $v)
1778 1875
 			{
1779 1876
 				if (!isset($themeData[$member][$k]))
1780 1877
 					$themeData[$member][$k] = $v;
1878
+		}
1781 1879
 			}
1782 1880
 
1783
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1784
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1881
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1882
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1883
+		}
1785 1884
 		// Only if we didn't already load that part of the cache...
1786
-		elseif (!isset($temp))
1787
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1885
+		elseif (!isset($temp)) {
1886
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1887
+		}
1788 1888
 	}
1789 1889
 
1790 1890
 	$settings = $themeData[0];
@@ -1801,20 +1901,24 @@  discard block
 block discarded – undo
1801 1901
 	$settings['template_dirs'][] = $settings['theme_dir'];
1802 1902
 
1803 1903
 	// Based on theme (if there is one).
1804
-	if (!empty($settings['base_theme_dir']))
1805
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1904
+	if (!empty($settings['base_theme_dir'])) {
1905
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1906
+	}
1806 1907
 
1807 1908
 	// Lastly the default theme.
1808
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1809
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1909
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1910
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1911
+	}
1810 1912
 
1811
-	if (!$initialize)
1812
-		return;
1913
+	if (!$initialize) {
1914
+			return;
1915
+	}
1813 1916
 
1814 1917
 	// Check to see if we're forcing SSL
1815 1918
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1816
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1817
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1919
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1920
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1921
+	}
1818 1922
 
1819 1923
 	// Check to see if they're accessing it from the wrong place.
1820 1924
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1822,8 +1926,9 @@  discard block
 block discarded – undo
1822 1926
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1823 1927
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1824 1928
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1825
-		if ($temp != '/')
1826
-			$detected_url .= $temp;
1929
+		if ($temp != '/') {
1930
+					$detected_url .= $temp;
1931
+		}
1827 1932
 	}
1828 1933
 	if (isset($detected_url) && $detected_url != $boardurl)
1829 1934
 	{
@@ -1835,8 +1940,9 @@  discard block
 block discarded – undo
1835 1940
 			foreach ($aliases as $alias)
1836 1941
 			{
1837 1942
 				// Rip off all the boring parts, spaces, etc.
1838
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1839
-					$do_fix = true;
1943
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1944
+									$do_fix = true;
1945
+				}
1840 1946
 			}
1841 1947
 		}
1842 1948
 
@@ -1844,20 +1950,22 @@  discard block
 block discarded – undo
1844 1950
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1845 1951
 		{
1846 1952
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1847
-			if (empty($_GET))
1848
-				redirectexit('wwwRedirect');
1849
-			else
1953
+			if (empty($_GET)) {
1954
+							redirectexit('wwwRedirect');
1955
+			} else
1850 1956
 			{
1851 1957
 				list ($k, $v) = each($_GET);
1852 1958
 
1853
-				if ($k != 'wwwRedirect')
1854
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1959
+				if ($k != 'wwwRedirect') {
1960
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1961
+				}
1855 1962
 			}
1856 1963
 		}
1857 1964
 
1858 1965
 		// #3 is just a check for SSL...
1859
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1860
-			$do_fix = true;
1966
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1967
+					$do_fix = true;
1968
+		}
1861 1969
 
1862 1970
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1863 1971
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1891,8 +1999,9 @@  discard block
 block discarded – undo
1891 1999
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1892 2000
 				}
1893 2001
 			}
1894
-			foreach ($context['linktree'] as $k => $dummy)
1895
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2002
+			foreach ($context['linktree'] as $k => $dummy) {
2003
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2004
+			}
1896 2005
 		}
1897 2006
 	}
1898 2007
 	// Set up the contextual user array.
@@ -1911,16 +2020,16 @@  discard block
 block discarded – undo
1911 2020
 			'email' => $user_info['email'],
1912 2021
 			'ignoreusers' => $user_info['ignoreusers'],
1913 2022
 		);
1914
-		if (!$context['user']['is_guest'])
1915
-			$context['user']['name'] = $user_info['name'];
1916
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1917
-			$context['user']['name'] = $txt['guest_title'];
2023
+		if (!$context['user']['is_guest']) {
2024
+					$context['user']['name'] = $user_info['name'];
2025
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2026
+					$context['user']['name'] = $txt['guest_title'];
2027
+		}
1918 2028
 
1919 2029
 		// Determine the current smiley set.
1920 2030
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1921 2031
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1922
-	}
1923
-	else
2032
+	} else
1924 2033
 	{
1925 2034
 		$context['user'] = array(
1926 2035
 			'id' => -1,
@@ -1936,18 +2045,24 @@  discard block
 block discarded – undo
1936 2045
 	}
1937 2046
 
1938 2047
 	// Some basic information...
1939
-	if (!isset($context['html_headers']))
1940
-		$context['html_headers'] = '';
1941
-	if (!isset($context['javascript_files']))
1942
-		$context['javascript_files'] = array();
1943
-	if (!isset($context['css_files']))
1944
-		$context['css_files'] = array();
1945
-	if (!isset($context['css_header']))
1946
-		$context['css_header'] = array();
1947
-	if (!isset($context['javascript_inline']))
1948
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1949
-	if (!isset($context['javascript_vars']))
1950
-		$context['javascript_vars'] = array();
2048
+	if (!isset($context['html_headers'])) {
2049
+			$context['html_headers'] = '';
2050
+	}
2051
+	if (!isset($context['javascript_files'])) {
2052
+			$context['javascript_files'] = array();
2053
+	}
2054
+	if (!isset($context['css_files'])) {
2055
+			$context['css_files'] = array();
2056
+	}
2057
+	if (!isset($context['css_header'])) {
2058
+			$context['css_header'] = array();
2059
+	}
2060
+	if (!isset($context['javascript_inline'])) {
2061
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2062
+	}
2063
+	if (!isset($context['javascript_vars'])) {
2064
+			$context['javascript_vars'] = array();
2065
+	}
1951 2066
 
1952 2067
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1953 2068
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1959,8 +2074,9 @@  discard block
 block discarded – undo
1959 2074
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1960 2075
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1961 2076
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1962
-	if (isset($modSettings['load_average']))
1963
-		$context['load_average'] = $modSettings['load_average'];
2077
+	if (isset($modSettings['load_average'])) {
2078
+			$context['load_average'] = $modSettings['load_average'];
2079
+	}
1964 2080
 
1965 2081
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1966 2082
 	detectBrowser();
@@ -1974,8 +2090,9 @@  discard block
 block discarded – undo
1974 2090
 	// This allows sticking some HTML on the page output - useful for controls.
1975 2091
 	$context['insert_after_template'] = '';
1976 2092
 
1977
-	if (!isset($txt))
1978
-		$txt = array();
2093
+	if (!isset($txt)) {
2094
+			$txt = array();
2095
+	}
1979 2096
 
1980 2097
 	$simpleActions = array(
1981 2098
 		'findmember',
@@ -2021,9 +2138,10 @@  discard block
 block discarded – undo
2021 2138
 
2022 2139
 	// See if theres any extra param to check.
2023 2140
 	$requiresXML = false;
2024
-	foreach ($extraParams as $key => $extra)
2025
-		if (isset($_REQUEST[$extra]))
2141
+	foreach ($extraParams as $key => $extra) {
2142
+			if (isset($_REQUEST[$extra]))
2026 2143
 			$requiresXML = true;
2144
+	}
2027 2145
 
2028 2146
 	// Output is fully XML, so no need for the index template.
2029 2147
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2038,37 +2156,39 @@  discard block
 block discarded – undo
2038 2156
 	{
2039 2157
 		loadLanguage('index+Modifications');
2040 2158
 		$context['template_layers'] = array();
2041
-	}
2042
-
2043
-	else
2159
+	} else
2044 2160
 	{
2045 2161
 		// Custom templates to load, or just default?
2046
-		if (isset($settings['theme_templates']))
2047
-			$templates = explode(',', $settings['theme_templates']);
2048
-		else
2049
-			$templates = array('index');
2162
+		if (isset($settings['theme_templates'])) {
2163
+					$templates = explode(',', $settings['theme_templates']);
2164
+		} else {
2165
+					$templates = array('index');
2166
+		}
2050 2167
 
2051 2168
 		// Load each template...
2052
-		foreach ($templates as $template)
2053
-			loadTemplate($template);
2169
+		foreach ($templates as $template) {
2170
+					loadTemplate($template);
2171
+		}
2054 2172
 
2055 2173
 		// ...and attempt to load their associated language files.
2056 2174
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2057 2175
 		loadLanguage($required_files, '', false);
2058 2176
 
2059 2177
 		// Custom template layers?
2060
-		if (isset($settings['theme_layers']))
2061
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2062
-		else
2063
-			$context['template_layers'] = array('html', 'body');
2178
+		if (isset($settings['theme_layers'])) {
2179
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2180
+		} else {
2181
+					$context['template_layers'] = array('html', 'body');
2182
+		}
2064 2183
 	}
2065 2184
 
2066 2185
 	// Initialize the theme.
2067 2186
 	loadSubTemplate('init', 'ignore');
2068 2187
 
2069 2188
 	// Allow overriding the board wide time/number formats.
2070
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2071
-		$user_info['time_format'] = $txt['time_format'];
2189
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2190
+			$user_info['time_format'] = $txt['time_format'];
2191
+	}
2072 2192
 
2073 2193
 	// Set the character set from the template.
2074 2194
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2076,12 +2196,14 @@  discard block
 block discarded – undo
2076 2196
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2077 2197
 
2078 2198
 	// Guests may still need a name.
2079
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2080
-		$context['user']['name'] = $txt['guest_title'];
2199
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2200
+			$context['user']['name'] = $txt['guest_title'];
2201
+	}
2081 2202
 
2082 2203
 	// Any theme-related strings that need to be loaded?
2083
-	if (!empty($settings['require_theme_strings']))
2084
-		loadLanguage('ThemeStrings', '', false);
2204
+	if (!empty($settings['require_theme_strings'])) {
2205
+			loadLanguage('ThemeStrings', '', false);
2206
+	}
2085 2207
 
2086 2208
 	// Make a special URL for the language.
2087 2209
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2092,8 +2214,9 @@  discard block
 block discarded – undo
2092 2214
 	// Here is my luvly Responsive CSS
2093 2215
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2094 2216
 
2095
-	if ($context['right_to_left'])
2096
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2217
+	if ($context['right_to_left']) {
2218
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2219
+	}
2097 2220
 
2098 2221
 	// We allow theme variants, because we're cool.
2099 2222
 	$context['theme_variant'] = '';
@@ -2101,14 +2224,17 @@  discard block
 block discarded – undo
2101 2224
 	if (!empty($settings['theme_variants']))
2102 2225
 	{
2103 2226
 		// Overriding - for previews and that ilk.
2104
-		if (!empty($_REQUEST['variant']))
2105
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2227
+		if (!empty($_REQUEST['variant'])) {
2228
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2229
+		}
2106 2230
 		// User selection?
2107
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2108
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2231
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2232
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2233
+		}
2109 2234
 		// If not a user variant, select the default.
2110
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2111
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2235
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2236
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2237
+		}
2112 2238
 
2113 2239
 		// Do this to keep things easier in the templates.
2114 2240
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2117,20 +2243,23 @@  discard block
 block discarded – undo
2117 2243
 		if (!empty($context['theme_variant']))
2118 2244
 		{
2119 2245
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2120
-			if ($context['right_to_left'])
2121
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2246
+			if ($context['right_to_left']) {
2247
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2248
+			}
2122 2249
 		}
2123 2250
 	}
2124 2251
 
2125 2252
 	// Let's be compatible with old themes!
2126
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2127
-		$context['template_layers'] = array('main');
2253
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2254
+			$context['template_layers'] = array('main');
2255
+	}
2128 2256
 
2129 2257
 	$context['tabindex'] = 1;
2130 2258
 
2131 2259
 	// Compatibility.
2132
-	if (!isset($settings['theme_version']))
2133
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2260
+	if (!isset($settings['theme_version'])) {
2261
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2262
+	}
2134 2263
 
2135 2264
 	// Default JS variables for use in every theme
2136 2265
 	$context['javascript_vars'] = array(
@@ -2149,18 +2278,18 @@  discard block
 block discarded – undo
2149 2278
 	);
2150 2279
 
2151 2280
 	// Add the JQuery library to the list of files to load.
2152
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2153
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2154
-
2155
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2156
-		loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2157
-
2158
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2159
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2281
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2282
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2283
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2284
+			loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2285
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2286
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2287
+	}
2160 2288
 
2161 2289
 	// Auto loading? template_javascript() will take care of the local half of this.
2162
-	else
2163
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2290
+	else {
2291
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2292
+	}
2164 2293
 
2165 2294
 	// Queue our JQuery plugins!
2166 2295
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2183,12 +2312,12 @@  discard block
 block discarded – undo
2183 2312
 			require_once($sourcedir . '/ScheduledTasks.php');
2184 2313
 
2185 2314
 			// What to do, what to do?!
2186
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2187
-				AutoTask();
2188
-			else
2189
-				ReduceMailQueue();
2190
-		}
2191
-		else
2315
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2316
+							AutoTask();
2317
+			} else {
2318
+							ReduceMailQueue();
2319
+			}
2320
+		} else
2192 2321
 		{
2193 2322
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2194 2323
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2239,8 +2368,9 @@  discard block
 block discarded – undo
2239 2368
 		foreach ($theme_includes as $include)
2240 2369
 		{
2241 2370
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2242
-			if (file_exists($include))
2243
-				require_once($include);
2371
+			if (file_exists($include)) {
2372
+							require_once($include);
2373
+			}
2244 2374
 		}
2245 2375
 	}
2246 2376
 
@@ -2270,16 +2400,19 @@  discard block
 block discarded – undo
2270 2400
 	// Do any style sheets first, cause we're easy with those.
2271 2401
 	if (!empty($style_sheets))
2272 2402
 	{
2273
-		if (!is_array($style_sheets))
2274
-			$style_sheets = array($style_sheets);
2403
+		if (!is_array($style_sheets)) {
2404
+					$style_sheets = array($style_sheets);
2405
+		}
2275 2406
 
2276
-		foreach ($style_sheets as $sheet)
2277
-			loadCSSFile($sheet . '.css', array(), $sheet);
2407
+		foreach ($style_sheets as $sheet) {
2408
+					loadCSSFile($sheet . '.css', array(), $sheet);
2409
+		}
2278 2410
 	}
2279 2411
 
2280 2412
 	// No template to load?
2281
-	if ($template_name === false)
2282
-		return true;
2413
+	if ($template_name === false) {
2414
+			return true;
2415
+	}
2283 2416
 
2284 2417
 	$loaded = false;
2285 2418
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2294,12 +2427,14 @@  discard block
 block discarded – undo
2294 2427
 
2295 2428
 	if ($loaded)
2296 2429
 	{
2297
-		if ($db_show_debug === true)
2298
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2430
+		if ($db_show_debug === true) {
2431
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2432
+		}
2299 2433
 
2300 2434
 		// If they have specified an initialization function for this template, go ahead and call it now.
2301
-		if (function_exists('template_' . $template_name . '_init'))
2302
-			call_user_func('template_' . $template_name . '_init');
2435
+		if (function_exists('template_' . $template_name . '_init')) {
2436
+					call_user_func('template_' . $template_name . '_init');
2437
+		}
2303 2438
 	}
2304 2439
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2305 2440
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2319,13 +2454,14 @@  discard block
 block discarded – undo
2319 2454
 		loadTemplate($template_name);
2320 2455
 	}
2321 2456
 	// Cause an error otherwise.
2322
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2323
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2324
-	elseif ($fatal)
2325
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2326
-	else
2327
-		return false;
2328
-}
2457
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2458
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2459
+	} elseif ($fatal) {
2460
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2461
+	} else {
2462
+			return false;
2463
+	}
2464
+	}
2329 2465
 
2330 2466
 /**
2331 2467
  * Load a sub-template.
@@ -2343,17 +2479,19 @@  discard block
 block discarded – undo
2343 2479
 {
2344 2480
 	global $context, $txt, $db_show_debug;
2345 2481
 
2346
-	if ($db_show_debug === true)
2347
-		$context['debug']['sub_templates'][] = $sub_template_name;
2482
+	if ($db_show_debug === true) {
2483
+			$context['debug']['sub_templates'][] = $sub_template_name;
2484
+	}
2348 2485
 
2349 2486
 	// Figure out what the template function is named.
2350 2487
 	$theme_function = 'template_' . $sub_template_name;
2351
-	if (function_exists($theme_function))
2352
-		$theme_function();
2353
-	elseif ($fatal === false)
2354
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2355
-	elseif ($fatal !== 'ignore')
2356
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2488
+	if (function_exists($theme_function)) {
2489
+			$theme_function();
2490
+	} elseif ($fatal === false) {
2491
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2492
+	} elseif ($fatal !== 'ignore') {
2493
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2494
+	}
2357 2495
 
2358 2496
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2359 2497
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2390,8 +2528,9 @@  discard block
 block discarded – undo
2390 2528
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2391 2529
 
2392 2530
 	// If this is an external file, automatically set this to false.
2393
-	if (!empty($params['external']))
2394
-		$params['minimize'] = false;
2531
+	if (!empty($params['external'])) {
2532
+			$params['minimize'] = false;
2533
+	}
2395 2534
 
2396 2535
 	// Account for shorthand like admin.css?alp21 filenames
2397 2536
 	$has_seed = strpos($fileName, '.css?');
@@ -2408,13 +2547,10 @@  discard block
 block discarded – undo
2408 2547
 			{
2409 2548
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2410 2549
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2550
+			} else {
2551
+							$fileUrl = false;
2411 2552
 			}
2412
-
2413
-			else
2414
-				$fileUrl = false;
2415
-		}
2416
-
2417
-		else
2553
+		} else
2418 2554
 		{
2419 2555
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2420 2556
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2429,12 +2565,14 @@  discard block
 block discarded – undo
2429 2565
 	}
2430 2566
 
2431 2567
 	// Add it to the array for use in the template
2432
-	if (!empty($fileName))
2433
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2568
+	if (!empty($fileName)) {
2569
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2570
+	}
2434 2571
 
2435
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2436
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2437
-}
2572
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2573
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2574
+	}
2575
+	}
2438 2576
 
2439 2577
 /**
2440 2578
  * Add a block of inline css code to be executed later
@@ -2451,8 +2589,9 @@  discard block
 block discarded – undo
2451 2589
 	global $context;
2452 2590
 
2453 2591
 	// Gotta add something...
2454
-	if (empty($css))
2455
-		return false;
2592
+	if (empty($css)) {
2593
+			return false;
2594
+	}
2456 2595
 
2457 2596
 	$context['css_header'][] = $css;
2458 2597
 }
@@ -2487,8 +2626,9 @@  discard block
 block discarded – undo
2487 2626
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2488 2627
 
2489 2628
 	// If this is an external file, automatically set this to false.
2490
-	if (!empty($params['external']))
2491
-		$params['minimize'] = false;
2629
+	if (!empty($params['external'])) {
2630
+			$params['minimize'] = false;
2631
+	}
2492 2632
 
2493 2633
 	// Account for shorthand like admin.js?alp21 filenames
2494 2634
 	$has_seed = strpos($fileName, '.js?');
@@ -2505,16 +2645,12 @@  discard block
 block discarded – undo
2505 2645
 			{
2506 2646
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2507 2647
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2508
-			}
2509
-
2510
-			else
2648
+			} else
2511 2649
 			{
2512 2650
 				$fileUrl = false;
2513 2651
 				$filePath = false;
2514 2652
 			}
2515
-		}
2516
-
2517
-		else
2653
+		} else
2518 2654
 		{
2519 2655
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2520 2656
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2529,9 +2665,10 @@  discard block
 block discarded – undo
2529 2665
 	}
2530 2666
 
2531 2667
 	// Add it to the array for use in the template
2532
-	if (!empty($fileName))
2533
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2534
-}
2668
+	if (!empty($fileName)) {
2669
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2670
+	}
2671
+	}
2535 2672
 
2536 2673
 /**
2537 2674
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2545,9 +2682,10 @@  discard block
 block discarded – undo
2545 2682
 {
2546 2683
 	global $context;
2547 2684
 
2548
-	if (!empty($key) && (!empty($value) || $value === '0'))
2549
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2550
-}
2685
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2686
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2687
+	}
2688
+	}
2551 2689
 
2552 2690
 /**
2553 2691
  * Add a block of inline Javascript code to be executed later
@@ -2564,8 +2702,9 @@  discard block
 block discarded – undo
2564 2702
 {
2565 2703
 	global $context;
2566 2704
 
2567
-	if (empty($javascript))
2568
-		return false;
2705
+	if (empty($javascript)) {
2706
+			return false;
2707
+	}
2569 2708
 
2570 2709
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2571 2710
 }
@@ -2586,15 +2725,18 @@  discard block
 block discarded – undo
2586 2725
 	static $already_loaded = array();
2587 2726
 
2588 2727
 	// Default to the user's language.
2589
-	if ($lang == '')
2590
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2728
+	if ($lang == '') {
2729
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2730
+	}
2591 2731
 
2592 2732
 	// Do we want the English version of language file as fallback?
2593
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2594
-		loadLanguage($template_name, 'english', false);
2733
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2734
+			loadLanguage($template_name, 'english', false);
2735
+	}
2595 2736
 
2596
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2597
-		return $lang;
2737
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2738
+			return $lang;
2739
+	}
2598 2740
 
2599 2741
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2600 2742
 	if (empty($settings['default_theme_dir']))
@@ -2605,8 +2747,9 @@  discard block
 block discarded – undo
2605 2747
 
2606 2748
 	// What theme are we in?
2607 2749
 	$theme_name = basename($settings['theme_url']);
2608
-	if (empty($theme_name))
2609
-		$theme_name = 'unknown';
2750
+	if (empty($theme_name)) {
2751
+			$theme_name = 'unknown';
2752
+	}
2610 2753
 
2611 2754
 	// For each file open it up and write it out!
2612 2755
 	foreach (explode('+', $template_name) as $template)
@@ -2648,8 +2791,9 @@  discard block
 block discarded – undo
2648 2791
 				$found = true;
2649 2792
 
2650 2793
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2651
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2652
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2794
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2795
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2796
+				}
2653 2797
 
2654 2798
 				break;
2655 2799
 			}
@@ -2689,8 +2833,9 @@  discard block
 block discarded – undo
2689 2833
 	}
2690 2834
 
2691 2835
 	// Keep track of what we're up to soldier.
2692
-	if ($db_show_debug === true)
2693
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2836
+	if ($db_show_debug === true) {
2837
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2838
+	}
2694 2839
 
2695 2840
 	// Remember what we have loaded, and in which language.
2696 2841
 	$already_loaded[$template_name] = $lang;
@@ -2736,8 +2881,9 @@  discard block
 block discarded – undo
2736 2881
 				)
2737 2882
 			);
2738 2883
 			// In the EXTREMELY unlikely event this happens, give an error message.
2739
-			if ($smcFunc['db_num_rows']($result) == 0)
2740
-				fatal_lang_error('parent_not_found', 'critical');
2884
+			if ($smcFunc['db_num_rows']($result) == 0) {
2885
+							fatal_lang_error('parent_not_found', 'critical');
2886
+			}
2741 2887
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2742 2888
 			{
2743 2889
 				if (!isset($boards[$row['id_board']]))
@@ -2754,8 +2900,8 @@  discard block
 block discarded – undo
2754 2900
 					);
2755 2901
 				}
2756 2902
 				// If a moderator exists for this board, add that moderator for all children too.
2757
-				if (!empty($row['id_moderator']))
2758
-					foreach ($boards as $id => $dummy)
2903
+				if (!empty($row['id_moderator'])) {
2904
+									foreach ($boards as $id => $dummy)
2759 2905
 					{
2760 2906
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2761 2907
 							'id' => $row['id_moderator'],
@@ -2763,11 +2909,12 @@  discard block
 block discarded – undo
2763 2909
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2764 2910
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2765 2911
 						);
2912
+				}
2766 2913
 					}
2767 2914
 
2768 2915
 				// If a moderator group exists for this board, add that moderator group for all children too
2769
-				if (!empty($row['id_moderator_group']))
2770
-					foreach ($boards as $id => $dummy)
2916
+				if (!empty($row['id_moderator_group'])) {
2917
+									foreach ($boards as $id => $dummy)
2771 2918
 					{
2772 2919
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2773 2920
 							'id' => $row['id_moderator_group'],
@@ -2775,6 +2922,7 @@  discard block
 block discarded – undo
2775 2922
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2776 2923
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2777 2924
 						);
2925
+				}
2778 2926
 					}
2779 2927
 			}
2780 2928
 			$smcFunc['db_free_result']($result);
@@ -2801,23 +2949,27 @@  discard block
 block discarded – undo
2801 2949
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2802 2950
 	{
2803 2951
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2804
-		if (empty($smcFunc['ucwords']))
2805
-			reloadSettings();
2952
+		if (empty($smcFunc['ucwords'])) {
2953
+					reloadSettings();
2954
+		}
2806 2955
 
2807 2956
 		// If we don't have our theme information yet, let's get it.
2808
-		if (empty($settings['default_theme_dir']))
2809
-			loadTheme(0, false);
2957
+		if (empty($settings['default_theme_dir'])) {
2958
+					loadTheme(0, false);
2959
+		}
2810 2960
 
2811 2961
 		// Default language directories to try.
2812 2962
 		$language_directories = array(
2813 2963
 			$settings['default_theme_dir'] . '/languages',
2814 2964
 		);
2815
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2816
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2965
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2966
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2967
+		}
2817 2968
 
2818 2969
 		// We possibly have a base theme directory.
2819
-		if (!empty($settings['base_theme_dir']))
2820
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2970
+		if (!empty($settings['base_theme_dir'])) {
2971
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2972
+		}
2821 2973
 
2822 2974
 		// Remove any duplicates.
2823 2975
 		$language_directories = array_unique($language_directories);
@@ -2831,20 +2983,21 @@  discard block
 block discarded – undo
2831 2983
 		foreach ($language_directories as $language_dir)
2832 2984
 		{
2833 2985
 			// Can't look in here... doesn't exist!
2834
-			if (!file_exists($language_dir))
2835
-				continue;
2986
+			if (!file_exists($language_dir)) {
2987
+							continue;
2988
+			}
2836 2989
 
2837 2990
 			$dir = dir($language_dir);
2838 2991
 			while ($entry = $dir->read())
2839 2992
 			{
2840 2993
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2841
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2842
-					continue;
2843
-
2844
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2845
-					$langName = $langList[$matches[1]];
2994
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
2995
+									continue;
2996
+				}
2846 2997
 
2847
-				else
2998
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
2999
+									$langName = $langList[$matches[1]];
3000
+				} else
2848 3001
 				{
2849 3002
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2850 3003
 
@@ -2885,12 +3038,14 @@  discard block
 block discarded – undo
2885 3038
 		}
2886 3039
 
2887 3040
 		// Do we need to store the lang list?
2888
-		if (empty($langList))
2889
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3041
+		if (empty($langList)) {
3042
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3043
+		}
2890 3044
 
2891 3045
 		// Let's cash in on this deal.
2892
-		if (!empty($modSettings['cache_enable']))
2893
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3046
+		if (!empty($modSettings['cache_enable'])) {
3047
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3048
+		}
2894 3049
 	}
2895 3050
 
2896 3051
 	return $context['languages'];
@@ -2913,8 +3068,9 @@  discard block
 block discarded – undo
2913 3068
 	global $modSettings, $options, $txt;
2914 3069
 	static $censor_vulgar = null, $censor_proper;
2915 3070
 
2916
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2917
-		return $text;
3071
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3072
+			return $text;
3073
+	}
2918 3074
 
2919 3075
 	// If they haven't yet been loaded, load them.
2920 3076
 	if ($censor_vulgar == null)
@@ -2942,9 +3098,9 @@  discard block
 block discarded – undo
2942 3098
 	{
2943 3099
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2944 3100
 		$text = $func($censor_vulgar, $censor_proper, $text);
3101
+	} else {
3102
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2945 3103
 	}
2946
-	else
2947
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2948 3104
 
2949 3105
 	return $text;
2950 3106
 }
@@ -2970,38 +3126,42 @@  discard block
 block discarded – undo
2970 3126
 	@ini_set('track_errors', '1');
2971 3127
 
2972 3128
 	// Don't include the file more than once, if $once is true.
2973
-	if ($once && in_array($filename, $templates))
2974
-		return;
3129
+	if ($once && in_array($filename, $templates)) {
3130
+			return;
3131
+	}
2975 3132
 	// Add this file to the include list, whether $once is true or not.
2976
-	else
2977
-		$templates[] = $filename;
3133
+	else {
3134
+			$templates[] = $filename;
3135
+	}
2978 3136
 
2979 3137
 	// Are we going to use eval?
2980 3138
 	if (empty($modSettings['disableTemplateEval']))
2981 3139
 	{
2982 3140
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2983 3141
 		$settings['current_include_filename'] = $filename;
2984
-	}
2985
-	else
3142
+	} else
2986 3143
 	{
2987 3144
 		$file_found = file_exists($filename);
2988 3145
 
2989
-		if ($once && $file_found)
2990
-			require_once($filename);
2991
-		elseif ($file_found)
2992
-			require($filename);
3146
+		if ($once && $file_found) {
3147
+					require_once($filename);
3148
+		} elseif ($file_found) {
3149
+					require($filename);
3150
+		}
2993 3151
 	}
2994 3152
 
2995 3153
 	if ($file_found !== true)
2996 3154
 	{
2997 3155
 		ob_end_clean();
2998
-		if (!empty($modSettings['enableCompressedOutput']))
2999
-			@ob_start('ob_gzhandler');
3000
-		else
3001
-			ob_start();
3156
+		if (!empty($modSettings['enableCompressedOutput'])) {
3157
+					@ob_start('ob_gzhandler');
3158
+		} else {
3159
+					ob_start();
3160
+		}
3002 3161
 
3003
-		if (isset($_GET['debug']))
3004
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3162
+		if (isset($_GET['debug'])) {
3163
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3164
+		}
3005 3165
 
3006 3166
 		// Don't cache error pages!!
3007 3167
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3020,12 +3180,13 @@  discard block
 block discarded – undo
3020 3180
 		echo '<!DOCTYPE html>
3021 3181
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3022 3182
 	<head>';
3023
-		if (isset($context['character_set']))
3024
-			echo '
3183
+		if (isset($context['character_set'])) {
3184
+					echo '
3025 3185
 		<meta charset="', $context['character_set'], '">';
3186
+		}
3026 3187
 
3027
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3028
-			echo '
3188
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3189
+					echo '
3029 3190
 		<title>', $mtitle, '</title>
3030 3191
 	</head>
3031 3192
 	<body>
@@ -3033,8 +3194,8 @@  discard block
 block discarded – undo
3033 3194
 		', $mmessage, '
3034 3195
 	</body>
3035 3196
 </html>';
3036
-		elseif (!allowedTo('admin_forum'))
3037
-			echo '
3197
+		} elseif (!allowedTo('admin_forum')) {
3198
+					echo '
3038 3199
 		<title>', $txt['template_parse_error'], '</title>
3039 3200
 	</head>
3040 3201
 	<body>
@@ -3042,16 +3203,18 @@  discard block
 block discarded – undo
3042 3203
 		', $txt['template_parse_error_message'], '
3043 3204
 	</body>
3044 3205
 </html>';
3045
-		else
3206
+		} else
3046 3207
 		{
3047 3208
 			require_once($sourcedir . '/Subs-Package.php');
3048 3209
 
3049 3210
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3050 3211
 			$error_array = error_get_last();
3051
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3052
-				$error = $error_array['message'];
3053
-			if (empty($error))
3054
-				$error = $txt['template_parse_errmsg'];
3212
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3213
+							$error = $error_array['message'];
3214
+			}
3215
+			if (empty($error)) {
3216
+							$error = $txt['template_parse_errmsg'];
3217
+			}
3055 3218
 
3056 3219
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3057 3220
 
@@ -3062,11 +3225,12 @@  discard block
 block discarded – undo
3062 3225
 		<h3>', $txt['template_parse_error'], '</h3>
3063 3226
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3064 3227
 
3065
-			if (!empty($error))
3066
-				echo '
3228
+			if (!empty($error)) {
3229
+							echo '
3067 3230
 		<hr>
3068 3231
 
3069 3232
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3233
+			}
3070 3234
 
3071 3235
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3072 3236
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3076,10 +3240,11 @@  discard block
 block discarded – undo
3076 3240
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3077 3241
 
3078 3242
 				// Fix the PHP code stuff...
3079
-				if (!isBrowser('gecko'))
3080
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3081
-				else
3082
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3243
+				if (!isBrowser('gecko')) {
3244
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3245
+				} else {
3246
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3247
+				}
3083 3248
 
3084 3249
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3085 3250
 				$j = -1;
@@ -3087,8 +3252,9 @@  discard block
 block discarded – undo
3087 3252
 				{
3088 3253
 					$j++;
3089 3254
 
3090
-					if (substr_count($line, '<br>') == 0)
3091
-						continue;
3255
+					if (substr_count($line, '<br>') == 0) {
3256
+											continue;
3257
+					}
3092 3258
 
3093 3259
 					$n = substr_count($line, '<br>');
3094 3260
 					for ($i = 0; $i < $n; $i++)
@@ -3107,38 +3273,42 @@  discard block
 block discarded – undo
3107 3273
 				// Figure out what the color coding was before...
3108 3274
 				$line = max($match[1] - 9, 1);
3109 3275
 				$last_line = '';
3110
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3111
-					if (strpos($data2[$line2], '<') !== false)
3276
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3277
+									if (strpos($data2[$line2], '<') !== false)
3112 3278
 					{
3113 3279
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3114 3280
 							$last_line = $color_match[1];
3281
+				}
3115 3282
 						break;
3116 3283
 					}
3117 3284
 
3118 3285
 				// Show the relevant lines...
3119 3286
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3120 3287
 				{
3121
-					if ($line == $match[1])
3122
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3288
+					if ($line == $match[1]) {
3289
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3290
+					}
3123 3291
 
3124 3292
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3125
-					if (isset($data2[$line]) && $data2[$line] != '')
3126
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3293
+					if (isset($data2[$line]) && $data2[$line] != '') {
3294
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3295
+					}
3127 3296
 
3128 3297
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3129 3298
 					{
3130 3299
 						$last_line = $color_match[1];
3131 3300
 						echo '</', substr($last_line, 1, 4), '>';
3301
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3302
+											$last_line = '';
3303
+					} elseif ($last_line != '' && $data2[$line] != '') {
3304
+											echo '</', substr($last_line, 1, 4), '>';
3132 3305
 					}
3133
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3134
-						$last_line = '';
3135
-					elseif ($last_line != '' && $data2[$line] != '')
3136
-						echo '</', substr($last_line, 1, 4), '>';
3137 3306
 
3138
-					if ($line == $match[1])
3139
-						echo '</pre></div><pre style="margin: 0;">';
3140
-					else
3141
-						echo "\n";
3307
+					if ($line == $match[1]) {
3308
+											echo '</pre></div><pre style="margin: 0;">';
3309
+					} else {
3310
+											echo "\n";
3311
+					}
3142 3312
 				}
3143 3313
 
3144 3314
 				echo '</pre></div>';
@@ -3162,8 +3332,9 @@  discard block
 block discarded – undo
3162 3332
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3163 3333
 
3164 3334
 	// Figure out what type of database we are using.
3165
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3166
-		$db_type = 'mysql';
3335
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3336
+			$db_type = 'mysql';
3337
+	}
3167 3338
 
3168 3339
 	// Load the file for the database.
3169 3340
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3171,8 +3342,9 @@  discard block
 block discarded – undo
3171 3342
 	$db_options = array();
3172 3343
 
3173 3344
 	// Add in the port if needed
3174
-	if (!empty($db_port))
3175
-		$db_options['port'] = $db_port;
3345
+	if (!empty($db_port)) {
3346
+			$db_options['port'] = $db_port;
3347
+	}
3176 3348
 
3177 3349
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3178 3350
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3191,13 +3363,15 @@  discard block
 block discarded – undo
3191 3363
 	}
3192 3364
 
3193 3365
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3194
-	if (!$db_connection)
3195
-		display_db_error();
3366
+	if (!$db_connection) {
3367
+			display_db_error();
3368
+	}
3196 3369
 
3197 3370
 	// If in SSI mode fix up the prefix.
3198
-	if (SMF == 'SSI')
3199
-		db_fix_prefix($db_prefix, $db_name);
3200
-}
3371
+	if (SMF == 'SSI') {
3372
+			db_fix_prefix($db_prefix, $db_name);
3373
+	}
3374
+	}
3201 3375
 
3202 3376
 /**
3203 3377
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3211,10 +3385,11 @@  discard block
 block discarded – undo
3211 3385
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3212 3386
 
3213 3387
 	// Not overriding this and we have a cacheAPI, send it back.
3214
-	if (empty($overrideCache) && is_object($cacheAPI))
3215
-		return $cacheAPI;
3216
-	elseif (is_null($cacheAPI))
3217
-		$cacheAPI = false;
3388
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3389
+			return $cacheAPI;
3390
+	} elseif (is_null($cacheAPI)) {
3391
+			$cacheAPI = false;
3392
+	}
3218 3393
 
3219 3394
 	// Make sure our class is in session.
3220 3395
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3235,8 +3410,9 @@  discard block
 block discarded – undo
3235 3410
 		if (!$testAPI->isSupported())
3236 3411
 		{
3237 3412
 			// Can we save ourselves?
3238
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3239
-				return loadCacheAccelerator(null, false);
3413
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3414
+							return loadCacheAccelerator(null, false);
3415
+			}
3240 3416
 			return false;
3241 3417
 		}
3242 3418
 
@@ -3248,9 +3424,9 @@  discard block
 block discarded – undo
3248 3424
 		{
3249 3425
 			$cacheAPI = $testAPI;
3250 3426
 			return $cacheAPI;
3427
+		} else {
3428
+					return $testAPI;
3251 3429
 		}
3252
-		else
3253
-			return $testAPI;
3254 3430
 	}
3255 3431
 }
3256 3432
 
@@ -3270,8 +3446,9 @@  discard block
 block discarded – undo
3270 3446
 
3271 3447
 	// @todo Why are we doing this if caching is disabled?
3272 3448
 
3273
-	if (function_exists('call_integration_hook'))
3274
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3449
+	if (function_exists('call_integration_hook')) {
3450
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3451
+	}
3275 3452
 
3276 3453
 	/* Refresh the cache if either:
3277 3454
 		1. Caching is disabled.
@@ -3285,16 +3462,19 @@  discard block
 block discarded – undo
3285 3462
 		require_once($sourcedir . '/' . $file);
3286 3463
 		$cache_block = call_user_func_array($function, $params);
3287 3464
 
3288
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3289
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3465
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3466
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3467
+		}
3290 3468
 	}
3291 3469
 
3292 3470
 	// Some cached data may need a freshening up after retrieval.
3293
-	if (!empty($cache_block['post_retri_eval']))
3294
-		eval($cache_block['post_retri_eval']);
3471
+	if (!empty($cache_block['post_retri_eval'])) {
3472
+			eval($cache_block['post_retri_eval']);
3473
+	}
3295 3474
 
3296
-	if (function_exists('call_integration_hook'))
3297
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3475
+	if (function_exists('call_integration_hook')) {
3476
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3477
+	}
3298 3478
 
3299 3479
 	return $cache_block['data'];
3300 3480
 }
@@ -3321,8 +3501,9 @@  discard block
 block discarded – undo
3321 3501
 	global $smcFunc, $cache_enable, $cacheAPI;
3322 3502
 	global $cache_hits, $cache_count, $db_show_debug;
3323 3503
 
3324
-	if (empty($cache_enable) || empty($cacheAPI))
3325
-		return;
3504
+	if (empty($cache_enable) || empty($cacheAPI)) {
3505
+			return;
3506
+	}
3326 3507
 
3327 3508
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3328 3509
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3335,12 +3516,14 @@  discard block
 block discarded – undo
3335 3516
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3336 3517
 	$cacheAPI->putData($key, $value, $ttl);
3337 3518
 
3338
-	if (function_exists('call_integration_hook'))
3339
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3519
+	if (function_exists('call_integration_hook')) {
3520
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3521
+	}
3340 3522
 
3341
-	if (isset($db_show_debug) && $db_show_debug === true)
3342
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3343
-}
3523
+	if (isset($db_show_debug) && $db_show_debug === true) {
3524
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3525
+	}
3526
+	}
3344 3527
 
3345 3528
 /**
3346 3529
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3356,8 +3539,9 @@  discard block
 block discarded – undo
3356 3539
 	global $smcFunc, $cache_enable, $cacheAPI;
3357 3540
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3358 3541
 
3359
-	if (empty($cache_enable) || empty($cacheAPI))
3360
-		return;
3542
+	if (empty($cache_enable) || empty($cacheAPI)) {
3543
+			return;
3544
+	}
3361 3545
 
3362 3546
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3363 3547
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3377,16 +3561,18 @@  discard block
 block discarded – undo
3377 3561
 
3378 3562
 		if (empty($value))
3379 3563
 		{
3380
-			if (!is_array($cache_misses))
3381
-				$cache_misses = array();
3564
+			if (!is_array($cache_misses)) {
3565
+							$cache_misses = array();
3566
+			}
3382 3567
 
3383 3568
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3384 3569
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3385 3570
 		}
3386 3571
 	}
3387 3572
 
3388
-	if (function_exists('call_integration_hook') && isset($value))
3389
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3573
+	if (function_exists('call_integration_hook') && isset($value)) {
3574
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3575
+	}
3390 3576
 
3391 3577
 	return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3392 3578
 }
@@ -3408,8 +3594,9 @@  discard block
 block discarded – undo
3408 3594
 	global $cacheAPI;
3409 3595
 
3410 3596
 	// If we can't get to the API, can't do this.
3411
-	if (empty($cacheAPI))
3412
-		return;
3597
+	if (empty($cacheAPI)) {
3598
+			return;
3599
+	}
3413 3600
 
3414 3601
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3415 3602
 	$cacheAPI->cleanCache($type);
@@ -3434,8 +3621,9 @@  discard block
 block discarded – undo
3434 3621
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3435 3622
 
3436 3623
 	// Come on!
3437
-	if (empty($data))
3438
-		return array();
3624
+	if (empty($data)) {
3625
+			return array();
3626
+	}
3439 3627
 
3440 3628
 	// Set a nice default var.
3441 3629
 	$image = '';
@@ -3443,11 +3631,11 @@  discard block
 block discarded – undo
3443 3631
 	// Gravatar has been set as mandatory!
3444 3632
 	if (!empty($modSettings['gravatarOverride']))
3445 3633
 	{
3446
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3447
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3448
-
3449
-		else if (!empty($data['email']))
3450
-			$image = get_gravatar_url($data['email']);
3634
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3635
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3636
+		} else if (!empty($data['email'])) {
3637
+					$image = get_gravatar_url($data['email']);
3638
+		}
3451 3639
 	}
3452 3640
 
3453 3641
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3459,54 +3647,60 @@  discard block
 block discarded – undo
3459 3647
 			// Gravatar.
3460 3648
 			if (stristr($data['avatar'], 'gravatar://'))
3461 3649
 			{
3462
-				if ($data['avatar'] == 'gravatar://')
3463
-					$image = get_gravatar_url($data['email']);
3464
-
3465
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3466
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3650
+				if ($data['avatar'] == 'gravatar://') {
3651
+									$image = get_gravatar_url($data['email']);
3652
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3653
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3654
+				}
3467 3655
 			}
3468 3656
 
3469 3657
 			// External url.
3470 3658
 			else
3471 3659
 			{
3472 3660
 				// Using ssl?
3473
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3474
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3661
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3662
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3663
+				}
3475 3664
 
3476 3665
 				// Just a plain external url.
3477
-				else
3478
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3666
+				else {
3667
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3668
+				}
3479 3669
 			}
3480 3670
 		}
3481 3671
 
3482 3672
 		// Perhaps this user has an attachment as avatar...
3483
-		else if (!empty($data['filename']))
3484
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3673
+		else if (!empty($data['filename'])) {
3674
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3675
+		}
3485 3676
 
3486 3677
 		// Right... no avatar... use our default image.
3487
-		else
3488
-			$image = $modSettings['avatar_url'] . '/default.png';
3678
+		else {
3679
+					$image = $modSettings['avatar_url'] . '/default.png';
3680
+		}
3489 3681
 	}
3490 3682
 
3491 3683
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3492 3684
 
3493 3685
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3494
-	if (!empty($image))
3495
-		return array(
3686
+	if (!empty($image)) {
3687
+			return array(
3496 3688
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3497 3689
 			'image' => '<img class="avatar" src="' . $image . '" />',
3498 3690
 			'href' => $image,
3499 3691
 			'url' => $image,
3500 3692
 		);
3693
+	}
3501 3694
 
3502 3695
 	// Fallback to make life easier for everyone...
3503
-	else
3504
-		return array(
3696
+	else {
3697
+			return array(
3505 3698
 			'name' => '',
3506 3699
 			'image' => '',
3507 3700
 			'href' => '',
3508 3701
 			'url' => '',
3509 3702
 		);
3510
-}
3703
+	}
3704
+	}
3511 3705
 
3512 3706
 ?>
3513 3707
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/ManageBoards.php 1 patch
Braces   +147 added lines, -114 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main dispatcher; doesn't do anything, just delegates.
@@ -92,18 +93,19 @@  discard block
 block discarded – undo
92 93
 		checkSession('get');
93 94
 		validateToken('admin-bm-' . (int) $_REQUEST['src_board'], 'request');
94 95
 
95
-		if ($_REQUEST['move_to'] === 'top')
96
-			$boardOptions = array(
96
+		if ($_REQUEST['move_to'] === 'top') {
97
+					$boardOptions = array(
97 98
 				'move_to' => $_REQUEST['move_to'],
98 99
 				'target_category' => (int) $_REQUEST['target_cat'],
99 100
 				'move_first_child' => true,
100 101
 			);
101
-		else
102
-			$boardOptions = array(
102
+		} else {
103
+					$boardOptions = array(
103 104
 				'move_to' => $_REQUEST['move_to'],
104 105
 				'target_board' => (int) $_REQUEST['target_board'],
105 106
 				'move_first_child' => true,
106 107
 			);
108
+		}
107 109
 		modifyBoard((int) $_REQUEST['src_board'], $boardOptions);
108 110
 	}
109 111
 
@@ -148,15 +150,16 @@  discard block
 block discarded – undo
148 150
 			$security = $context['session_var'] . '=' . $context['session_id'] . ';' . $context['admin-bm-' . $context['move_board'] . '_token_var'] . '=' . $context['admin-bm-' . $context['move_board'] . '_token'];
149 151
 			foreach ($boardList[$catid] as $boardid)
150 152
 			{
151
-				if (!isset($context['categories'][$catid]['move_link']))
152
-					$context['categories'][$catid]['move_link'] = array(
153
+				if (!isset($context['categories'][$catid]['move_link'])) {
154
+									$context['categories'][$catid]['move_link'] = array(
153 155
 						'child_level' => 0,
154 156
 						'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'',
155 157
 						'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_board=' . $boardid . ';move_to=before;' . $security,
156 158
 					);
159
+				}
157 160
 
158
-				if (!$context['categories'][$catid]['boards'][$boardid]['move'])
159
-				$context['categories'][$catid]['boards'][$boardid]['move_links'] = array(
161
+				if (!$context['categories'][$catid]['boards'][$boardid]['move']) {
162
+								$context['categories'][$catid]['boards'][$boardid]['move_links'] = array(
160 163
 					array(
161 164
 						'child_level' => $boards[$boardid]['level'],
162 165
 						'label' => $txt['mboards_order_after'] . '\'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'',
@@ -170,34 +173,39 @@  discard block
 block discarded – undo
170 173
 						'class' => 'here',
171 174
 					),
172 175
 				);
176
+				}
173 177
 
174 178
 				$difference = $boards[$boardid]['level'] - $prev_child_level;
175
-				if ($difference == 1)
176
-					array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null);
177
-				elseif ($difference < 0)
179
+				if ($difference == 1) {
180
+									array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null);
181
+				} elseif ($difference < 0)
178 182
 				{
179
-					if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links']))
180
-						$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array();
181
-					for ($i = 0; $i < -$difference; $i++)
182
-						if (($temp = array_pop($stack)) != null)
183
+					if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) {
184
+											$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array();
185
+					}
186
+					for ($i = 0; $i < -$difference; $i++) {
187
+											if (($temp = array_pop($stack)) != null)
183 188
 							array_unshift($context['categories'][$catid]['boards'][$prev_board]['move_links'], $temp);
189
+					}
184 190
 				}
185 191
 
186 192
 				$prev_board = $boardid;
187 193
 				$prev_child_level = $boards[$boardid]['level'];
188 194
 
189 195
 			}
190
-			if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']))
191
-				$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']);
192
-			elseif (!empty($stack))
193
-				$context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack;
196
+			if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) {
197
+							$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']);
198
+			} elseif (!empty($stack)) {
199
+							$context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack;
200
+			}
194 201
 
195
-			if (empty($boardList[$catid]))
196
-				$context['categories'][$catid]['move_link'] = array(
202
+			if (empty($boardList[$catid])) {
203
+							$context['categories'][$catid]['move_link'] = array(
197 204
 					'child_level' => 0,
198 205
 					'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($tree['node']['name']) . '\'',
199 206
 					'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_cat=' . $catid . ';move_to=top;' . $security,
200 207
 				);
208
+			}
201 209
 		}
202 210
 	}
203 211
 
@@ -253,9 +261,9 @@  discard block
 block discarded – undo
253 261
 		);
254 262
 	}
255 263
 	// Category doesn't exist, man... sorry.
256
-	elseif (!isset($cat_tree[$_REQUEST['cat']]))
257
-		redirectexit('action=admin;area=manageboards');
258
-	else
264
+	elseif (!isset($cat_tree[$_REQUEST['cat']])) {
265
+			redirectexit('action=admin;area=manageboards');
266
+	} else
259 267
 	{
260 268
 		$context['category'] = array(
261 269
 			'id' => $_REQUEST['cat'],
@@ -267,30 +275,31 @@  discard block
 block discarded – undo
267 275
 			'is_empty' => empty($cat_tree[$_REQUEST['cat']]['children'])
268 276
 		);
269 277
 
270
-		foreach ($boardList[$_REQUEST['cat']] as $child_board)
271
-			$context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name'];
278
+		foreach ($boardList[$_REQUEST['cat']] as $child_board) {
279
+					$context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name'];
280
+		}
272 281
 	}
273 282
 
274 283
 	$prevCat = 0;
275 284
 	foreach ($cat_tree as $catid => $tree)
276 285
 	{
277
-		if ($catid == $_REQUEST['cat'] && $prevCat > 0)
278
-			$context['category_order'][$prevCat]['selected'] = true;
279
-		elseif ($catid != $_REQUEST['cat'])
280
-			$context['category_order'][$catid] = array(
286
+		if ($catid == $_REQUEST['cat'] && $prevCat > 0) {
287
+					$context['category_order'][$prevCat]['selected'] = true;
288
+		} elseif ($catid != $_REQUEST['cat']) {
289
+					$context['category_order'][$catid] = array(
281 290
 				'id' => $catid,
282 291
 				'name' => $txt['mboards_order_after'] . $tree['node']['name'],
283 292
 				'selected' => false,
284 293
 				'true_name' => $tree['node']['name']
285 294
 			);
295
+		}
286 296
 		$prevCat = $catid;
287 297
 	}
288 298
 	if (!isset($_REQUEST['delete']))
289 299
 	{
290 300
 		$context['sub_template'] = 'modify_category';
291 301
 		$context['page_title'] = $_REQUEST['sa'] == 'newcat' ? $txt['mboards_new_cat_name'] : $txt['catEdit'];
292
-	}
293
-	else
302
+	} else
294 303
 	{
295 304
 		$context['sub_template'] = 'confirm_category_delete';
296 305
 		$context['page_title'] = $txt['mboards_delete_cat'];
@@ -327,8 +336,9 @@  discard block
 block discarded – undo
327 336
 	{
328 337
 		$catOptions = array();
329 338
 
330
-		if (isset($_POST['cat_order']))
331
-			$catOptions['move_after'] = (int) $_POST['cat_order'];
339
+		if (isset($_POST['cat_order'])) {
340
+					$catOptions['move_after'] = (int) $_POST['cat_order'];
341
+		}
332 342
 
333 343
 		// Change "This & That" to "This &amp; That" but don't change "&cent" to "&amp;cent;"...
334 344
 		$catOptions['cat_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['cat_name']), false, '', $context['description_allowed_tags']);
@@ -336,10 +346,11 @@  discard block
 block discarded – undo
336 346
 
337 347
 		$catOptions['is_collapsible'] = isset($_POST['collapse']);
338 348
 
339
-		if (isset($_POST['add']))
340
-			createCategory($catOptions);
341
-		else
342
-			modifyCategory($_POST['cat'], $catOptions);
349
+		if (isset($_POST['add'])) {
350
+					createCategory($catOptions);
351
+		} else {
352
+					modifyCategory($_POST['cat'], $catOptions);
353
+		}
343 354
 	}
344 355
 	// If they want to delete - first give them confirmation.
345 356
 	elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['empty']))
@@ -353,13 +364,14 @@  discard block
 block discarded – undo
353 364
 		// First off - check if we are moving all the current boards first - before we start deleting!
354 365
 		if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1)
355 366
 		{
356
-			if (empty($_POST['cat_to']))
357
-				fatal_lang_error('mboards_delete_error');
367
+			if (empty($_POST['cat_to'])) {
368
+							fatal_lang_error('mboards_delete_error');
369
+			}
358 370
 
359 371
 			deleteCategories(array($_POST['cat']), (int) $_POST['cat_to']);
372
+		} else {
373
+					deleteCategories(array($_POST['cat']));
360 374
 		}
361
-		else
362
-			deleteCategories(array($_POST['cat']));
363 375
 	}
364 376
 
365 377
 	redirectexit('action=admin;area=manageboards');
@@ -404,8 +416,9 @@  discard block
 block discarded – undo
404 416
 	if ($_REQUEST['sa'] == 'newboard')
405 417
 	{
406 418
 		// Category doesn't exist, man... sorry.
407
-		if (empty($_REQUEST['cat']))
408
-			redirectexit('action=admin;area=manageboards');
419
+		if (empty($_REQUEST['cat'])) {
420
+					redirectexit('action=admin;area=manageboards');
421
+		}
409 422
 
410 423
 		// Some things that need to be setup for a new board.
411 424
 		$curBoard = array(
@@ -429,8 +442,7 @@  discard block
 block discarded – undo
429 442
 			'category' => (int) $_REQUEST['cat'],
430 443
 			'no_children' => true,
431 444
 		);
432
-	}
433
-	else
445
+	} else
434 446
 	{
435 447
 		// Just some easy shortcuts.
436 448
 		$curBoard = &$boards[$_REQUEST['boardid']];
@@ -478,8 +490,9 @@  discard block
 block discarded – undo
478 490
 	);
479 491
 	while ($row = $smcFunc['db_fetch_assoc']($request))
480 492
 	{
481
-		if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1)
482
-			$curBoard['member_groups'][] = $row['id_group'];
493
+		if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) {
494
+					$curBoard['member_groups'][] = $row['id_group'];
495
+		}
483 496
 
484 497
 		$context['groups'][(int) $row['id_group']] = array(
485 498
 			'id' => $row['id_group'],
@@ -492,8 +505,9 @@  discard block
 block discarded – undo
492 505
 	$smcFunc['db_free_result']($request);
493 506
 
494 507
 	// Category doesn't exist, man... sorry.
495
-	if (!isset($boardList[$curBoard['category']]))
496
-		redirectexit('action=admin;area=manageboards');
508
+	if (!isset($boardList[$curBoard['category']])) {
509
+			redirectexit('action=admin;area=manageboards');
510
+	}
497 511
 
498 512
 	foreach ($boardList[$curBoard['category']] as $boardid)
499 513
 	{
@@ -507,8 +521,7 @@  discard block
 block discarded – undo
507 521
 				'is_child' => false,
508 522
 				'selected' => true
509 523
 			);
510
-		}
511
-		else
524
+		} else
512 525
 		{
513 526
 			$context['board_order'][] = array(
514 527
 				'id' => $boardid,
@@ -525,19 +538,21 @@  discard block
 block discarded – undo
525 538
 		$context['can_move_children'] = false;
526 539
 		$context['children'] = $boards[$_REQUEST['boardid']]['tree']['children'];
527 540
 
528
-		foreach ($context['board_order'] as $lBoard)
529
-			if ($lBoard['is_child'] == false && $lBoard['selected'] == false)
541
+		foreach ($context['board_order'] as $lBoard) {
542
+					if ($lBoard['is_child'] == false && $lBoard['selected'] == false)
530 543
 				$context['can_move_children'] = true;
544
+		}
531 545
 	}
532 546
 
533 547
 	// Get other available categories.
534 548
 	$context['categories'] = array();
535
-	foreach ($cat_tree as $catID => $tree)
536
-		$context['categories'][] = array(
549
+	foreach ($cat_tree as $catID => $tree) {
550
+			$context['categories'][] = array(
537 551
 			'id' => $catID == $curBoard['category'] ? 0 : $catID,
538 552
 			'name' => $tree['node']['name'],
539 553
 			'selected' => $catID == $curBoard['category']
540 554
 		);
555
+	}
541 556
 
542 557
 	$request = $smcFunc['db_query']('', '
543 558
 		SELECT mem.id_member, mem.real_name
@@ -549,14 +564,16 @@  discard block
 block discarded – undo
549 564
 		)
550 565
 	);
551 566
 	$context['board']['moderators'] = array();
552
-	while ($row = $smcFunc['db_fetch_assoc']($request))
553
-		$context['board']['moderators'][$row['id_member']] = $row['real_name'];
567
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
568
+			$context['board']['moderators'][$row['id_member']] = $row['real_name'];
569
+	}
554 570
 	$smcFunc['db_free_result']($request);
555 571
 
556 572
 	$context['board']['moderator_list'] = empty($context['board']['moderators']) ? '' : '&quot;' . implode('&quot;, &quot;', $context['board']['moderators']) . '&quot;';
557 573
 
558
-	if (!empty($context['board']['moderators']))
559
-		list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1);
574
+	if (!empty($context['board']['moderators'])) {
575
+			list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1);
576
+	}
560 577
 
561 578
 	// Get all the groups assigned as moderators
562 579
 	$request = $smcFunc['db_query']('', '
@@ -568,14 +585,16 @@  discard block
 block discarded – undo
568 585
 		)
569 586
 	);
570 587
 	$context['board']['moderator_groups'] = array();
571
-	while ($row = $smcFunc['db_fetch_assoc']($request))
572
-		$context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name'];
588
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
589
+			$context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name'];
590
+	}
573 591
 	$smcFunc['db_free_result']($request);
574 592
 
575 593
 	$context['board']['moderator_groups_list'] = empty($context['board']['moderator_groups']) ? '' : '&quot;' . implode('&quot;, &qout;', $context['board']['moderator_groups']) . '&quot;';
576 594
 
577
-	if (!empty($context['board']['moderator_groups']))
578
-		list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1);
595
+	if (!empty($context['board']['moderator_groups'])) {
596
+			list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1);
597
+	}
579 598
 
580 599
 	// Get all the themes...
581 600
 	$request = $smcFunc['db_query']('', '
@@ -587,8 +606,9 @@  discard block
 block discarded – undo
587 606
 		)
588 607
 	);
589 608
 	$context['themes'] = array();
590
-	while ($row = $smcFunc['db_fetch_assoc']($request))
591
-		$context['themes'][] = $row;
609
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
610
+			$context['themes'][] = $row;
611
+	}
592 612
 	$smcFunc['db_free_result']($request);
593 613
 
594 614
 	if (!isset($_REQUEST['delete']))
@@ -596,8 +616,7 @@  discard block
 block discarded – undo
596 616
 		$context['sub_template'] = 'modify_board';
597 617
 		$context['page_title'] = $txt['boardsEdit'];
598 618
 		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
599
-	}
600
-	else
619
+	} else
601 620
 	{
602 621
 		$context['sub_template'] = 'confirm_board_delete';
603 622
 		$context['page_title'] = $txt['mboards_delete_board'];
@@ -641,8 +660,9 @@  discard block
 block discarded – undo
641 660
 		// Change the boardorder of this board?
642 661
 		elseif (!empty($_POST['placement']) && !empty($_POST['board_order']))
643 662
 		{
644
-			if (!in_array($_POST['placement'], array('before', 'after', 'child')))
645
-				fatal_lang_error('mangled_post', false);
663
+			if (!in_array($_POST['placement'], array('before', 'after', 'child'))) {
664
+							fatal_lang_error('mangled_post', false);
665
+			}
646 666
 
647 667
 			$boardOptions['move_to'] = $_POST['placement'];
648 668
 			$boardOptions['target_board'] = (int) $_POST['board_order'];
@@ -655,13 +675,14 @@  discard block
 block discarded – undo
655 675
 		$boardOptions['access_groups'] = array();
656 676
 		$boardOptions['deny_groups'] = array();
657 677
 
658
-		if (!empty($_POST['groups']))
659
-			foreach ($_POST['groups'] as $group => $action)
678
+		if (!empty($_POST['groups'])) {
679
+					foreach ($_POST['groups'] as $group => $action)
660 680
 			{
661 681
 				if ($action == 'allow')
662 682
 					$boardOptions['access_groups'][] = (int) $group;
663
-				elseif ($action == 'deny')
664
-					$boardOptions['deny_groups'][] = (int) $group;
683
+		} elseif ($action == 'deny') {
684
+									$boardOptions['deny_groups'][] = (int) $group;
685
+				}
665 686
 			}
666 687
 
667 688
 		// People with manage-boards are special.
@@ -673,8 +694,9 @@  discard block
 block discarded – undo
673 694
 		// Secondly, make sure those with super cow powers (like apt-get, or in this case manage boards) are upgraded.
674 695
 		$boardOptions['access_groups'] = array_unique(array_merge($boardOptions['access_groups'], $board_managers));
675 696
 
676
-		if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255)
677
-			fatal_lang_error('too_many_groups', false);
697
+		if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) {
698
+					fatal_lang_error('too_many_groups', false);
699
+		}
678 700
 
679 701
 		// Do not allow HTML tags. Parse the string.
680 702
 		$boardOptions['board_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['board_name']), false, '', $context['description_allowed_tags']);
@@ -685,8 +707,9 @@  discard block
 block discarded – undo
685 707
 		if (isset($_POST['moderator_list']) && is_array($_POST['moderator_list']))
686 708
 		{
687 709
 			$moderators = array();
688
-			foreach ($_POST['moderator_list'] as $moderator)
689
-				$moderators[(int) $moderator] = (int) $moderator;
710
+			foreach ($_POST['moderator_list'] as $moderator) {
711
+							$moderators[(int) $moderator] = (int) $moderator;
712
+			}
690 713
 			$boardOptions['moderators'] = $moderators;
691 714
 		}
692 715
 
@@ -695,8 +718,9 @@  discard block
 block discarded – undo
695 718
 		if (isset($_POST['moderator_group_list']) && is_array($_POST['moderator_group_list']))
696 719
 		{
697 720
 			$moderator_groups = array();
698
-			foreach ($_POST['moderator_group_list'] as $moderator_group)
699
-				$moderator_groups[(int) $moderator_group] = (int) $moderator_group;
721
+			foreach ($_POST['moderator_group_list'] as $moderator_group) {
722
+							$moderator_groups[(int) $moderator_group] = (int) $moderator_group;
723
+			}
700 724
 			$boardOptions['moderator_groups'] = $moderator_groups;
701 725
 		}
702 726
 
@@ -722,56 +746,62 @@  discard block
 block discarded – undo
722 746
 			$smcFunc['db_free_result']($request);
723 747
 
724 748
 			// If we're turning redirection on check the board doesn't have posts in it - if it does don't make it a redirection board.
725
-			if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts)
726
-				unset($boardOptions['redirect']);
749
+			if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) {
750
+							unset($boardOptions['redirect']);
751
+			}
727 752
 			// Reset the redirection count when switching on/off.
728
-			elseif (empty($boardOptions['redirect']) != empty($oldRedirect))
729
-				$boardOptions['num_posts'] = 0;
753
+			elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) {
754
+							$boardOptions['num_posts'] = 0;
755
+			}
730 756
 			// Resetting the count?
731
-			elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect']))
732
-				$boardOptions['num_posts'] = 0;
757
+			elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) {
758
+							$boardOptions['num_posts'] = 0;
759
+			}
733 760
 		}
734 761
 
735 762
 		// Create a new board...
736 763
 		if (isset($_POST['add']))
737 764
 		{
738 765
 			// New boards by default go to the bottom of the category.
739
-			if (empty($_POST['new_cat']))
740
-				$boardOptions['target_category'] = (int) $_POST['cur_cat'];
741
-			if (!isset($boardOptions['move_to']))
742
-				$boardOptions['move_to'] = 'bottom';
766
+			if (empty($_POST['new_cat'])) {
767
+							$boardOptions['target_category'] = (int) $_POST['cur_cat'];
768
+			}
769
+			if (!isset($boardOptions['move_to'])) {
770
+							$boardOptions['move_to'] = 'bottom';
771
+			}
743 772
 
744 773
 			createBoard($boardOptions);
745 774
 		}
746 775
 
747 776
 		// ...or update an existing board.
748
-		else
749
-			modifyBoard($_POST['boardid'], $boardOptions);
750
-	}
751
-	elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children']))
777
+		else {
778
+					modifyBoard($_POST['boardid'], $boardOptions);
779
+		}
780
+	} elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children']))
752 781
 	{
753 782
 		EditBoard();
754 783
 		return;
755
-	}
756
-	elseif (isset($_POST['delete']))
784
+	} elseif (isset($_POST['delete']))
757 785
 	{
758 786
 		// First off - check if we are moving all the current child boards first - before we start deleting!
759 787
 		if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1)
760 788
 		{
761
-			if (empty($_POST['board_to']))
762
-				fatal_lang_error('mboards_delete_board_error');
789
+			if (empty($_POST['board_to'])) {
790
+							fatal_lang_error('mboards_delete_board_error');
791
+			}
763 792
 
764 793
 			deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']);
794
+		} else {
795
+					deleteBoards(array($_POST['boardid']), 0);
765 796
 		}
766
-		else
767
-			deleteBoards(array($_POST['boardid']), 0);
768 797
 	}
769 798
 
770
-	if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions')
771
-		redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']);
772
-	else
773
-		redirectexit('action=admin;area=manageboards');
774
-}
799
+	if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') {
800
+			redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']);
801
+	} else {
802
+			redirectexit('action=admin;area=manageboards');
803
+	}
804
+	}
775 805
 
776 806
 /**
777 807
  * Used to retrieve data for modifying a board category
@@ -808,8 +838,9 @@  discard block
 block discarded – undo
808 838
 	$smcFunc['db_free_result']($request);
809 839
 
810 840
 	// This would probably never happen, but just to be sure.
811
-	if ($cat .= $allowed_sa[1])
812
-		die(str_replace(',', ' to', $cat));
841
+	if ($cat .= $allowed_sa[1]) {
842
+			die(str_replace(',', ' to', $cat));
843
+	}
813 844
 
814 845
 	redirectexit();
815 846
 }
@@ -835,8 +866,9 @@  discard block
 block discarded – undo
835 866
 			'empty_string' => '',
836 867
 		)
837 868
 	);
838
-	while ($row = $smcFunc['db_fetch_assoc']($request))
839
-		$recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name'];
869
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
870
+			$recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name'];
871
+	}
840 872
 	$smcFunc['db_free_result']($request);
841 873
 	
842 874
 	if (!empty($recycle_boards))
@@ -844,9 +876,9 @@  discard block
 block discarded – undo
844 876
 		require_once($sourcedir . '/Subs-Boards.php');
845 877
 		sortBoards($recycle_boards);
846 878
 		$recycle_boards = array('') + $recycle_boards;
879
+	} else {
880
+			$recycle_boards = array('');
847 881
 	}
848
-	else
849
-		$recycle_boards = array('');
850 882
 
851 883
 	// Here and the board settings...
852 884
 	$config_vars = array(
@@ -864,8 +896,9 @@  discard block
 block discarded – undo
864 896
 
865 897
 	call_integration_hook('integrate_modify_board_settings', array(&$config_vars));
866 898
 
867
-	if ($return_config)
868
-		return $config_vars;
899
+	if ($return_config) {
900
+			return $config_vars;
901
+	}
869 902
 
870 903
 	// Needed for the settings template.
871 904
 	require_once($sourcedir . '/ManageServer.php');
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 1 patch
Braces   +266 added lines, -197 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -60,9 +61,11 @@  discard block
 block discarded – undo
60 61
 			'db_mb4'                    => false,
61 62
 			'db_ping'                   => 'mysqli_ping',
62 63
 		);
64
+	}
63 65
 
64
-	if (!empty($db_options['persist']))
65
-		$db_server = 'p:' . $db_server;
66
+	if (!empty($db_options['persist'])) {
67
+			$db_server = 'p:' . $db_server;
68
+	}
66 69
 
67 70
 	$connection = mysqli_init();
68 71
 
@@ -71,24 +74,27 @@  discard block
 block discarded – undo
71 74
 	$success = false;
72 75
 
73 76
 	if ($connection) {
74
-		if (!empty($db_options['port']))
75
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
76
-		else
77
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
77
+		if (!empty($db_options['port'])) {
78
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
79
+		} else {
80
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
81
+		}
78 82
 	}
79 83
 
80 84
 	// Something's wrong, show an error if its fatal (which we assume it is)
81 85
 	if ($success === false)
82 86
 	{
83
-		if (!empty($db_options['non_fatal']))
84
-			return null;
85
-		else
86
-			display_db_error();
87
+		if (!empty($db_options['non_fatal'])) {
88
+					return null;
89
+		} else {
90
+					display_db_error();
91
+		}
87 92
 	}
88 93
 
89 94
 	// Select the database, unless told not to
90
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
91
-		display_db_error();
95
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
96
+			display_db_error();
97
+	}
92 98
 
93 99
 	$smcFunc['db_query']('', 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'',
94 100
 		array(),
@@ -164,34 +170,42 @@  discard block
 block discarded – undo
164 170
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
165 171
 
166 172
 	list ($values, $connection) = $db_callback;
167
-	if (!is_object($connection))
168
-		display_db_error();
173
+	if (!is_object($connection)) {
174
+			display_db_error();
175
+	}
169 176
 
170
-	if ($matches[1] === 'db_prefix')
171
-		return $db_prefix;
177
+	if ($matches[1] === 'db_prefix') {
178
+			return $db_prefix;
179
+	}
172 180
 
173
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
174
-		return $user_info[$matches[1]];
181
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
182
+			return $user_info[$matches[1]];
183
+	}
175 184
 
176
-	if ($matches[1] === 'empty')
177
-		return '\'\'';
185
+	if ($matches[1] === 'empty') {
186
+			return '\'\'';
187
+	}
178 188
 
179
-	if (!isset($matches[2]))
180
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
189
+	if (!isset($matches[2])) {
190
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
191
+	}
181 192
 
182
-	if ($matches[1] === 'literal')
183
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
193
+	if ($matches[1] === 'literal') {
194
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
195
+	}
184 196
 
185
-	if (!isset($values[$matches[2]]))
186
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
197
+	if (!isset($values[$matches[2]])) {
198
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
199
+	}
187 200
 
188 201
 	$replacement = $values[$matches[2]];
189 202
 
190 203
 	switch ($matches[1])
191 204
 	{
192 205
 		case 'int':
193
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
194
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
206
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
207
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
208
+			}
195 209
 			return (string) (int) $replacement;
196 210
 		break;
197 211
 
@@ -203,65 +217,73 @@  discard block
 block discarded – undo
203 217
 		case 'array_int':
204 218
 			if (is_array($replacement))
205 219
 			{
206
-				if (empty($replacement))
207
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220
+				if (empty($replacement)) {
221
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222
+				}
208 223
 
209 224
 				foreach ($replacement as $key => $value)
210 225
 				{
211
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
212
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
226
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
227
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
228
+					}
213 229
 
214 230
 					$replacement[$key] = (string) (int) $value;
215 231
 				}
216 232
 
217 233
 				return implode(', ', $replacement);
234
+			} else {
235
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218 236
 			}
219
-			else
220
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221 237
 
222 238
 		break;
223 239
 
224 240
 		case 'array_string':
225 241
 			if (is_array($replacement))
226 242
 			{
227
-				if (empty($replacement))
228
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
243
+				if (empty($replacement)) {
244
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
245
+				}
229 246
 
230
-				foreach ($replacement as $key => $value)
231
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
247
+				foreach ($replacement as $key => $value) {
248
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
249
+				}
232 250
 
233 251
 				return implode(', ', $replacement);
252
+			} else {
253
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
234 254
 			}
235
-			else
236
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237 255
 		break;
238 256
 
239 257
 		case 'date':
240
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
241
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
242
-			else
243
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
258
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
259
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
260
+			} else {
261
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
262
+			}
244 263
 		break;
245 264
 
246 265
 		case 'time':
247
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
248
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
249
-			else
250
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
267
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
268
+			} else {
269
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+			}
251 271
 		break;
252 272
 
253 273
 		case 'datetime':
254
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
255
-				return 'str_to_date('.
274
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
275
+							return 'str_to_date('.
256 276
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
257 277
 					',\'%Y-%m-%d %h:%i:%s\')';
258
-			else
259
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
278
+			} else {
279
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
280
+			}
260 281
 		break;
261 282
 
262 283
 		case 'float':
263
-			if (!is_numeric($replacement))
264
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
284
+			if (!is_numeric($replacement)) {
285
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
286
+			}
265 287
 			return (string) (float) $replacement;
266 288
 		break;
267 289
 
@@ -275,32 +297,37 @@  discard block
 block discarded – undo
275 297
 		break;
276 298
 
277 299
 		case 'inet':
278
-			if ($replacement == 'null' || $replacement == '')
279
-				return 'null';
280
-			if (!isValidIP($replacement))
281
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
300
+			if ($replacement == 'null' || $replacement == '') {
301
+							return 'null';
302
+			}
303
+			if (!isValidIP($replacement)) {
304
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
305
+			}
282 306
 			//we don't use the native support of mysql > 5.6.2
283 307
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
284 308
 
285 309
 		case 'array_inet':
286 310
 			if (is_array($replacement))
287 311
 			{
288
-				if (empty($replacement))
289
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
312
+				if (empty($replacement)) {
313
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
314
+				}
290 315
 
291 316
 				foreach ($replacement as $key => $value)
292 317
 				{
293
-					if ($replacement == 'null' || $replacement == '')
294
-						$replacement[$key] = 'null';
295
-					if (!isValidIP($value))
296
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
318
+					if ($replacement == 'null' || $replacement == '') {
319
+											$replacement[$key] = 'null';
320
+					}
321
+					if (!isValidIP($value)) {
322
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
323
+					}
297 324
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
298 325
 				}
299 326
 
300 327
 				return implode(', ', $replacement);
328
+			} else {
329
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
301 330
 			}
302
-			else
303
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
304 331
 		break;
305 332
 
306 333
 		default:
@@ -376,22 +403,25 @@  discard block
 block discarded – undo
376 403
 		// Are we in SSI mode?  If so try that username and password first
377 404
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
378 405
 		{
379
-			if (empty($db_persist))
380
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
381
-			else
382
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
406
+			if (empty($db_persist)) {
407
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
408
+			} else {
409
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
410
+			}
383 411
 		}
384 412
 		// Fall back to the regular username and password if need be
385 413
 		if (!$db_connection)
386 414
 		{
387
-			if (empty($db_persist))
388
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
389
-			else
390
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
415
+			if (empty($db_persist)) {
416
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
417
+			} else {
418
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
419
+			}
391 420
 		}
392 421
 
393
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
394
-			$db_connection = false;
422
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
423
+					$db_connection = false;
424
+		}
395 425
 
396 426
 		$connection = $db_connection;
397 427
 	}
@@ -399,18 +429,20 @@  discard block
 block discarded – undo
399 429
 	// One more query....
400 430
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
401 431
 
402
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
403
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
432
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
433
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
434
+	}
404 435
 
405 436
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
406 437
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
407 438
 	{
408 439
 		// Add before LIMIT
409
-		if ($pos = strpos($db_string, 'LIMIT '))
410
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
411
-		else
412
-			// Append it.
440
+		if ($pos = strpos($db_string, 'LIMIT ')) {
441
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
442
+		} else {
443
+					// Append it.
413 444
 			$db_string .= "\n\t\t\tORDER BY null";
445
+		}
414 446
 	}
415 447
 
416 448
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -432,8 +464,9 @@  discard block
 block discarded – undo
432 464
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
433 465
 
434 466
 		// Initialize $db_cache if not already initialized.
435
-		if (!isset($db_cache))
436
-			$db_cache = array();
467
+		if (!isset($db_cache)) {
468
+					$db_cache = array();
469
+		}
437 470
 
438 471
 		if (!empty($_SESSION['debug_redirect']))
439 472
 		{
@@ -459,17 +492,18 @@  discard block
 block discarded – undo
459 492
 		while (true)
460 493
 		{
461 494
 			$pos = strpos($db_string, '\'', $pos + 1);
462
-			if ($pos === false)
463
-				break;
495
+			if ($pos === false) {
496
+							break;
497
+			}
464 498
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
465 499
 
466 500
 			while (true)
467 501
 			{
468 502
 				$pos1 = strpos($db_string, '\'', $pos + 1);
469 503
 				$pos2 = strpos($db_string, '\\', $pos + 1);
470
-				if ($pos1 === false)
471
-					break;
472
-				elseif ($pos2 === false || $pos2 > $pos1)
504
+				if ($pos1 === false) {
505
+									break;
506
+				} elseif ($pos2 === false || $pos2 > $pos1)
473 507
 				{
474 508
 					$pos = $pos1;
475 509
 					break;
@@ -485,29 +519,35 @@  discard block
 block discarded – undo
485 519
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
486 520
 
487 521
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
488
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
489
-			$fail = true;
522
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
523
+					$fail = true;
524
+		}
490 525
 		// Trying to change passwords, slow us down, or something?
491
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
492
-			$fail = true;
493
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
494
-			$fail = true;
526
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
527
+					$fail = true;
528
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
529
+					$fail = true;
530
+		}
495 531
 
496
-		if (!empty($fail) && function_exists('log_error'))
497
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
532
+		if (!empty($fail) && function_exists('log_error')) {
533
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
534
+		}
498 535
 	}
499 536
 
500
-	if (empty($db_unbuffered))
501
-		$ret = @mysqli_query($connection, $db_string);
502
-	else
503
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
537
+	if (empty($db_unbuffered)) {
538
+			$ret = @mysqli_query($connection, $db_string);
539
+	} else {
540
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
541
+	}
504 542
 
505
-	if ($ret === false && empty($db_values['db_error_skip']))
506
-		$ret = smf_db_error($db_string, $connection);
543
+	if ($ret === false && empty($db_values['db_error_skip'])) {
544
+			$ret = smf_db_error($db_string, $connection);
545
+	}
507 546
 
508 547
 	// Debugging.
509
-	if (isset($db_show_debug) && $db_show_debug === true)
510
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
548
+	if (isset($db_show_debug) && $db_show_debug === true) {
549
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
550
+	}
511 551
 
512 552
 	return $ret;
513 553
 }
@@ -554,12 +594,13 @@  discard block
 block discarded – undo
554 594
 	// Decide which connection to use
555 595
 	$connection = $connection === null ? $db_connection : $connection;
556 596
 
557
-	if ($type == 'begin')
558
-		return @mysqli_query($connection, 'BEGIN');
559
-	elseif ($type == 'rollback')
560
-		return @mysqli_query($connection, 'ROLLBACK');
561
-	elseif ($type == 'commit')
562
-		return @mysqli_query($connection, 'COMMIT');
597
+	if ($type == 'begin') {
598
+			return @mysqli_query($connection, 'BEGIN');
599
+	} elseif ($type == 'rollback') {
600
+			return @mysqli_query($connection, 'ROLLBACK');
601
+	} elseif ($type == 'commit') {
602
+			return @mysqli_query($connection, 'COMMIT');
603
+	}
563 604
 
564 605
 	return false;
565 606
 }
@@ -599,8 +640,9 @@  discard block
 block discarded – undo
599 640
 	//    2013: Lost connection to server during query.
600 641
 
601 642
 	// Log the error.
602
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
603
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
643
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
644
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
645
+	}
604 646
 
605 647
 	// Database error auto fixing ;).
606 648
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -609,8 +651,9 @@  discard block
 block discarded – undo
609 651
 		$old_cache = @$modSettings['cache_enable'];
610 652
 		$modSettings['cache_enable'] = '1';
611 653
 
612
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
613
-			$db_last_error = max(@$db_last_error, $temp);
654
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
655
+					$db_last_error = max(@$db_last_error, $temp);
656
+		}
614 657
 
615 658
 		if (@$db_last_error < time() - 3600 * 24 * 3)
616 659
 		{
@@ -626,8 +669,9 @@  discard block
 block discarded – undo
626 669
 					foreach ($tables as $table)
627 670
 					{
628 671
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
629
-						if (trim($table) != '')
630
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
672
+						if (trim($table) != '') {
673
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
674
+						}
631 675
 					}
632 676
 				}
633 677
 
@@ -636,8 +680,9 @@  discard block
 block discarded – undo
636 680
 			// Table crashed.  Let's try to fix it.
637 681
 			elseif ($query_errno == 1016)
638 682
 			{
639
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
640
-					$fix_tables = array('`' . $match[1] . '`');
683
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
684
+									$fix_tables = array('`' . $match[1] . '`');
685
+				}
641 686
 			}
642 687
 			// Indexes crashed.  Should be easy to fix!
643 688
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -656,13 +701,15 @@  discard block
 block discarded – undo
656 701
 
657 702
 			// Make a note of the REPAIR...
658 703
 			cache_put_data('db_last_error', time(), 600);
659
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
660
-				updateSettingsFile(array('db_last_error' => time()));
704
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
705
+							updateSettingsFile(array('db_last_error' => time()));
706
+			}
661 707
 
662 708
 			// Attempt to find and repair the broken table.
663
-			foreach ($fix_tables as $table)
664
-				$smcFunc['db_query']('', "
709
+			foreach ($fix_tables as $table) {
710
+							$smcFunc['db_query']('', "
665 711
 					REPAIR TABLE $table", false, false);
712
+			}
666 713
 
667 714
 			// And send off an email!
668 715
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -671,11 +718,12 @@  discard block
 block discarded – undo
671 718
 
672 719
 			// Try the query again...?
673 720
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
674
-			if ($ret !== false)
675
-				return $ret;
721
+			if ($ret !== false) {
722
+							return $ret;
723
+			}
724
+		} else {
725
+					$modSettings['cache_enable'] = $old_cache;
676 726
 		}
677
-		else
678
-			$modSettings['cache_enable'] = $old_cache;
679 727
 
680 728
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
681 729
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -685,22 +733,25 @@  discard block
 block discarded – undo
685 733
 				// Are we in SSI mode?  If so try that username and password first
686 734
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
687 735
 				{
688
-					if (empty($db_persist))
689
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
690
-					else
691
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
736
+					if (empty($db_persist)) {
737
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
738
+					} else {
739
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
740
+					}
692 741
 				}
693 742
 				// Fall back to the regular username and password if need be
694 743
 				if (!$db_connection)
695 744
 				{
696
-					if (empty($db_persist))
697
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
698
-					else
699
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
745
+					if (empty($db_persist)) {
746
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
747
+					} else {
748
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
749
+					}
700 750
 				}
701 751
 
702
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
703
-					$db_connection = false;
752
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
753
+									$db_connection = false;
754
+				}
704 755
 			}
705 756
 
706 757
 			if ($db_connection)
@@ -711,24 +762,27 @@  discard block
 block discarded – undo
711 762
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
712 763
 
713 764
 					$new_errno = mysqli_errno($db_connection);
714
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
715
-						break;
765
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
766
+											break;
767
+					}
716 768
 				}
717 769
 
718 770
 				// If it failed again, shucks to be you... we're not trying it over and over.
719
-				if ($ret !== false)
720
-					return $ret;
771
+				if ($ret !== false) {
772
+									return $ret;
773
+				}
721 774
 			}
722 775
 		}
723 776
 		// Are they out of space, perhaps?
724 777
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
725 778
 		{
726
-			if (!isset($txt))
727
-				$query_error .= ' - check database storage space.';
728
-			else
779
+			if (!isset($txt)) {
780
+							$query_error .= ' - check database storage space.';
781
+			} else
729 782
 			{
730
-				if (!isset($txt['mysql_error_space']))
731
-					loadLanguage('Errors');
783
+				if (!isset($txt['mysql_error_space'])) {
784
+									loadLanguage('Errors');
785
+				}
732 786
 
733 787
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
734 788
 			}
@@ -736,15 +790,17 @@  discard block
 block discarded – undo
736 790
 	}
737 791
 
738 792
 	// Nothing's defined yet... just die with it.
739
-	if (empty($context) || empty($txt))
740
-		die($query_error);
793
+	if (empty($context) || empty($txt)) {
794
+			die($query_error);
795
+	}
741 796
 
742 797
 	// Show an error message, if possible.
743 798
 	$context['error_title'] = $txt['database_error'];
744
-	if (allowedTo('admin_forum'))
745
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
746
-	else
747
-		$context['error_message'] = $txt['try_again'];
799
+	if (allowedTo('admin_forum')) {
800
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
801
+	} else {
802
+			$context['error_message'] = $txt['try_again'];
803
+	}
748 804
 
749 805
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
750 806
 	{
@@ -776,8 +832,9 @@  discard block
 block discarded – undo
776 832
 	$return_var = null;
777 833
 
778 834
 	// With nothing to insert, simply return.
779
-	if (empty($data))
780
-		return;
835
+	if (empty($data)) {
836
+			return;
837
+	}
781 838
 
782 839
 	// Replace the prefix holder with the actual prefix.
783 840
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -787,23 +844,26 @@  discard block
 block discarded – undo
787 844
 	if (!empty($keys) && (count($keys) > 0) && $returnmode > 0)
788 845
 	{
789 846
 		$with_returning = true;
790
-		if ($returnmode == 2)
791
-			$return_var = array();
847
+		if ($returnmode == 2) {
848
+					$return_var = array();
849
+		}
792 850
 	}
793 851
 
794 852
 	// Inserting data as a single row can be done as a single array.
795
-	if (!is_array($data[array_rand($data)]))
796
-		$data = array($data);
853
+	if (!is_array($data[array_rand($data)])) {
854
+			$data = array($data);
855
+	}
797 856
 
798 857
 	// Create the mold for a single row insert.
799 858
 	$insertData = '(';
800 859
 	foreach ($columns as $columnName => $type)
801 860
 	{
802 861
 		// Are we restricting the length?
803
-		if (strpos($type, 'string-') !== false)
804
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
805
-		else
806
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
862
+		if (strpos($type, 'string-') !== false) {
863
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
864
+		} else {
865
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
866
+		}
807 867
 	}
808 868
 	$insertData = substr($insertData, 0, -2) . ')';
809 869
 
@@ -812,8 +872,9 @@  discard block
 block discarded – undo
812 872
 
813 873
 	// Here's where the variables are injected to the query.
814 874
 	$insertRows = array();
815
-	foreach ($data as $dataRow)
816
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
875
+	foreach ($data as $dataRow) {
876
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
877
+	}
817 878
 
818 879
 	// Determine the method of insertion.
819 880
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -832,8 +893,7 @@  discard block
 block discarded – undo
832 893
 			),
833 894
 			$connection
834 895
 		);
835
-	}
836
-	else //special way for ignore method with returning
896
+	} else //special way for ignore method with returning
837 897
 	{
838 898
 		$count = count($insertRows);
839 899
 		$ai = 0;
@@ -853,19 +913,21 @@  discard block
 block discarded – undo
853 913
 			);
854 914
 			$new_id = $smcFunc['db_insert_id']();
855 915
 			
856
-			if ($last_id != $new_id) //the inserted value was new
916
+			if ($last_id != $new_id) {
917
+				//the inserted value was new
857 918
 			{
858 919
 				$ai = $new_id;
859 920
 			}
860
-			else	// the inserted value already exists we need to find the pk
921
+			} else	// the inserted value already exists we need to find the pk
861 922
 			{
862 923
 				$where_string = '';
863 924
 				$count2 = count($indexed_columns);
864 925
 				for ($x = 0; $x < $count2; $x++)
865 926
 				{
866 927
 					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
867
-					if (($x + 1) < $count2)
868
-						$where_string += ' AND ';
928
+					if (($x + 1) < $count2) {
929
+											$where_string += ' AND ';
930
+					}
869 931
 				}
870 932
 
871 933
 				$request = $smcFunc['db_query']('','
@@ -881,25 +943,27 @@  discard block
 block discarded – undo
881 943
 				}
882 944
 			}
883 945
 			
884
-			if ($returnmode == 1)
885
-				$return_var = $ai;
886
-			else if ($returnmode == 2)
887
-				$return_var[] = $ai;
946
+			if ($returnmode == 1) {
947
+							$return_var = $ai;
948
+			} else if ($returnmode == 2) {
949
+							$return_var[] = $ai;
950
+			}
888 951
 		}
889 952
 	}
890 953
 	
891 954
 
892 955
 	if ($with_returning)
893 956
 	{
894
-		if ($returnmode == 1 && empty($return_var))
895
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
896
-		else if ($returnmode == 2 && empty($return_var))
957
+		if ($returnmode == 1 && empty($return_var)) {
958
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
959
+		} else if ($returnmode == 2 && empty($return_var))
897 960
 		{
898 961
 			$return_var = array();
899 962
 			$count = count($insertRows);
900 963
 			$start = smf_db_insert_id($table, $keys[0]);
901
-			for ($i = 0; $i < $count; $i++ )
902
-				$return_var[] = $start + $i;
964
+			for ($i = 0; $i < $count; $i++ ) {
965
+							$return_var[] = $start + $i;
966
+			}
903 967
 		}
904 968
 		return $return_var;
905 969
 	}
@@ -917,8 +981,9 @@  discard block
 block discarded – undo
917 981
  */
918 982
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
919 983
 {
920
-	if (empty($log_message))
921
-		$log_message = $error_message;
984
+	if (empty($log_message)) {
985
+			$log_message = $error_message;
986
+	}
922 987
 
923 988
 	foreach (debug_backtrace() as $step)
924 989
 	{
@@ -937,12 +1002,14 @@  discard block
 block discarded – undo
937 1002
 	}
938 1003
 
939 1004
 	// A special case - we want the file and line numbers for debugging.
940
-	if ($error_type == 'return')
941
-		return array($file, $line);
1005
+	if ($error_type == 'return') {
1006
+			return array($file, $line);
1007
+	}
942 1008
 
943 1009
 	// Is always a critical error.
944
-	if (function_exists('log_error'))
945
-		log_error($log_message, 'critical', $file, $line);
1010
+	if (function_exists('log_error')) {
1011
+			log_error($log_message, 'critical', $file, $line);
1012
+	}
946 1013
 
947 1014
 	if (function_exists('fatal_error'))
948 1015
 	{
@@ -950,12 +1017,12 @@  discard block
 block discarded – undo
950 1017
 
951 1018
 		// Cannot continue...
952 1019
 		exit;
1020
+	} elseif ($error_type) {
1021
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
1022
+	} else {
1023
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
1024
+	}
953 1025
 	}
954
-	elseif ($error_type)
955
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
956
-	else
957
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
958
-}
959 1026
 
960 1027
 /**
961 1028
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -972,10 +1039,11 @@  discard block
 block discarded – undo
972 1039
 		'\\' => '\\\\',
973 1040
 	);
974 1041
 
975
-	if ($translate_human_wildcards)
976
-		$replacements += array(
1042
+	if ($translate_human_wildcards) {
1043
+			$replacements += array(
977 1044
 			'*' => '%',
978 1045
 		);
1046
+	}
979 1047
 
980 1048
 	return strtr($string, $replacements);
981 1049
 }
@@ -989,8 +1057,9 @@  discard block
 block discarded – undo
989 1057
  */
990 1058
 function smf_is_resource($result)
991 1059
 {
992
-	if ($result instanceof mysqli_result)
993
-		return true;
1060
+	if ($result instanceof mysqli_result) {
1061
+			return true;
1062
+	}
994 1063
 
995 1064
 	return false;
996 1065
 }
Please login to merge, or discard this patch.