Completed
Pull Request — release-2.1 (#4574)
by Matthew
07:51
created
Sources/tasks/GroupReq-Notify.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
 class GroupReq_Notify_Background extends SMF_BackgroundTask
21 21
 {
22 22
 	/**
23
-     * This executes the task - loads up the information, puts the email in the queue and inserts any alerts as needed.
23
+	 * This executes the task - loads up the information, puts the email in the queue and inserts any alerts as needed.
24 24
 	 * @return bool Always returns true.
25 25
 	 */
26 26
 	public function execute()
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -37,8 +37,9 @@  discard block
 block discarded – undo
37 37
 			)
38 38
 		);
39 39
 		$moderators = array();
40
-		while ($row = $smcFunc['db_fetch_assoc']($request))
41
-			$moderators[] = $row['id_member'];
40
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
41
+					$moderators[] = $row['id_member'];
42
+		}
42 43
 		$smcFunc['db_free_result']($request);
43 44
 
44 45
 		require_once($sourcedir . '/Subs-Members.php');
@@ -59,11 +60,13 @@  discard block
 block discarded – undo
59 60
 			{
60 61
 				if (!empty($prefs[$mod]['request_group']))
61 62
 				{
62
-					if ($prefs[$mod]['request_group'] & 0x01)
63
-						$data['alert'][] = $mod;
63
+					if ($prefs[$mod]['request_group'] & 0x01) {
64
+											$data['alert'][] = $mod;
65
+					}
64 66
 
65
-					if ($prefs[$mod]['request_group'] & 0x02)
66
-						$data['email'][] = $mod;
67
+					if ($prefs[$mod]['request_group'] & 0x02) {
68
+											$data['email'][] = $mod;
69
+					}
67 70
 				}
68 71
 			}
69 72
 
Please login to merge, or discard this patch.
Sources/Calendar.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -240,8 +240,8 @@
 block discarded – undo
240 240
 		$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
241 241
 
242 242
 	$js_time_string = str_replace(
243
-		array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
244
-		array('H',  'G',  'h',  'g',  'i',  'A',  'a',  'h:i:s A', 'H:i', 's',  'H:i:s', 'H:i:s'),
243
+		array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r', '%R', '%S', '%T', '%X'),
244
+		array('H', 'G', 'h', 'g', 'i', 'A', 'a', 'h:i:s A', 'H:i', 's', 'H:i:s', 'H:i:s'),
245 245
 		$time_string
246 246
 	);
247 247
 
Please login to merge, or discard this 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.
Themes/default/Recent.template.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
 	<div id="recent" class="main_section">
22 22
 		<div class="cat_bar">
23 23
 			<h3 class="catbg">
24
-				<span class="xx"></span>',$txt['recent_posts'],'
24
+				<span class="xx"></span>',$txt['recent_posts'], '
25 25
 			</h3>
26 26
 		</div>
27 27
 		<div class="pagesection">', $context['page_index'], '</div>';
Please login to merge, or discard this patch.
Braces   +77 added lines, -54 removed lines patch added patch discarded remove patch
@@ -26,9 +26,10 @@  discard block
 block discarded – undo
26 26
 		</div>
27 27
 		<div class="pagesection">', $context['page_index'], '</div>';
28 28
 
29
-	if (empty($context['posts']))
30
-		echo '
29
+	if (empty($context['posts'])) {
30
+			echo '
31 31
 		<div class="windowbg">', $txt['no_messages'], '</div>';
32
+	}
32 33
 
33 34
 	foreach ($context['posts'] as $post)
34 35
 	{
@@ -41,28 +42,33 @@  discard block
 block discarded – undo
41 42
 			</div>
42 43
 			<div class="list_posts">', $post['message'], '</div>';
43 44
 
44
-		if ($post['can_reply'] || $post['can_quote'] || $post['can_delete'])
45
-			echo '
45
+		if ($post['can_reply'] || $post['can_quote'] || $post['can_delete']) {
46
+					echo '
46 47
 			<ul class="quickbuttons">';
48
+		}
47 49
 
48 50
 		// If they *can* reply?
49
-		if ($post['can_reply'])
50
-			echo '
51
+		if ($post['can_reply']) {
52
+					echo '
51 53
 				<li><a href="', $scripturl, '?action=post;topic=', $post['topic'], '.', $post['start'], '"><span class="generic_icons reply_button"></span>', $txt['reply'], '</a></li>';
54
+		}
52 55
 
53 56
 		// If they *can* quote?
54
-		if ($post['can_quote'])
55
-			echo '
57
+		if ($post['can_quote']) {
58
+					echo '
56 59
 				<li><a href="', $scripturl, '?action=post;topic=', $post['topic'], '.', $post['start'], ';quote=', $post['id'], '"><span class="generic_icons quote"></span>', $txt['quote_action'], '</a></li>';
60
+		}
57 61
 
58 62
 		// How about... even... remove it entirely?!
59
-		if ($post['can_delete'])
60
-			echo '
63
+		if ($post['can_delete']) {
64
+					echo '
61 65
 				<li><a href="', $scripturl, '?action=deletemsg;msg=', $post['id'], ';topic=', $post['topic'], ';recent;', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['remove_message'], '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove'], '</a></li>';
66
+		}
62 67
 
63
-		if ($post['can_reply'] || $post['can_quote'] || $post['can_delete'])
64
-			echo '
68
+		if ($post['can_reply'] || $post['can_quote'] || $post['can_delete']) {
69
+					echo '
65 70
 			</ul>';
71
+		}
66 72
 
67 73
 		echo '
68 74
 		</div><!-- $post[css_class] -->';
@@ -84,12 +90,13 @@  discard block
 block discarded – undo
84 90
 	echo '
85 91
 	<div id="recent" class="main_content">';
86 92
 
87
-	if ($context['showCheckboxes'])
88
-		echo '
93
+	if ($context['showCheckboxes']) {
94
+			echo '
89 95
 		<form action="', $scripturl, '?action=quickmod" method="post" accept-charset="', $context['character_set'], '" name="quickModForm" id="quickModForm">
90 96
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
91 97
 			<input type="hidden" name="qaction" value="markread">
92 98
 			<input type="hidden" name="redirect_url" value="action=unread', (!empty($context['showing_all_topics']) ? ';all' : ''), $context['querystring_board_limits'], '">';
99
+	}
93 100
 
94 101
 	if (!empty($context['topics']))
95 102
 	{
@@ -118,11 +125,12 @@  discard block
 block discarded – undo
118 125
 					</div>';
119 126
 
120 127
 		// Show a "select all" box for quick moderation?
121
-		if ($context['showCheckboxes'])
122
-			echo '
128
+		if ($context['showCheckboxes']) {
129
+					echo '
123 130
 					<div class="moderation">
124 131
 						<input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');">
125 132
 					</div>';
133
+		}
126 134
 
127 135
 		echo '
128 136
 				</div><!-- #topic_header -->
@@ -142,17 +150,20 @@  discard block
 block discarded – undo
142 150
 			echo '
143 151
 							<div class="icons floatright">';
144 152
 
145
-			if ($topic['is_locked'])
146
-				echo '
153
+			if ($topic['is_locked']) {
154
+							echo '
147 155
 								<span class="generic_icons lock"></span>';
156
+			}
148 157
 
149
-			if ($topic['is_sticky'])
150
-				echo '
158
+			if ($topic['is_sticky']) {
159
+							echo '
151 160
 								<span class="generic_icons sticky"></span>';
161
+			}
152 162
 
153
-			if ($topic['is_poll'])
154
-				echo '
163
+			if ($topic['is_poll']) {
164
+							echo '
155 165
 								<span class="generic_icons poll"></span>';
166
+			}
156 167
 
157 168
 			echo '
158 169
 							</div>';
@@ -178,19 +189,21 @@  discard block
 block discarded – undo
178 189
 							', sprintf($txt['last_post_topic'], '<a href="' . $topic['last_post']['href'] . '">' . $topic['last_post']['time'] . '</a>', $topic['last_post']['member']['link']), '
179 190
 						</div>';
180 191
 
181
-			if ($context['showCheckboxes'])
182
-				echo '
192
+			if ($context['showCheckboxes']) {
193
+							echo '
183 194
 						<div class="moderation">
184 195
 							<input type="checkbox" name="topics[]" value="', $topic['id'], '">
185 196
 						</div>';
197
+			}
186 198
 
187 199
 			echo '
188 200
 					</div><!-- $topic[css_class] -->';
189 201
 		}
190 202
 
191
-		if (empty($context['topics']))
192
-			echo '
203
+		if (empty($context['topics'])) {
204
+					echo '
193 205
 					<div style="display: none;"></div>';
206
+		}
194 207
 
195 208
 		echo '
196 209
 				</div><!-- #topic_container -->
@@ -205,25 +218,27 @@  discard block
 block discarded – undo
205 218
 					', $context['page_index'], '
206 219
 				</div>
207 220
 			</div>';
208
-	}
209
-	else
210
-		echo '
221
+	} else {
222
+			echo '
211 223
 			<div class="cat_bar">
212 224
 				<h3 class="catbg centertext">
213 225
 					', $context['showing_all_topics'] ? $txt['topic_alert_none'] : $txt['unread_topics_visit_none'], '
214 226
 				</h3>
215 227
 			</div>';
228
+	}
216 229
 
217
-	if ($context['showCheckboxes'])
218
-		echo '
230
+	if ($context['showCheckboxes']) {
231
+			echo '
219 232
 		</form>';
233
+	}
220 234
 
221 235
 	echo '
222 236
 	</div><!-- #recent -->';
223 237
 
224
-	if (empty($context['no_topic_listing']))
225
-		template_topic_legend();
226
-}
238
+	if (empty($context['no_topic_listing'])) {
239
+			template_topic_legend();
240
+	}
241
+	}
227 242
 
228 243
 /**
229 244
  * Template for showing unread replies (eg new replies to topics you've posted in)
@@ -235,12 +250,13 @@  discard block
 block discarded – undo
235 250
 	echo '
236 251
 	<div id="recent">';
237 252
 
238
-	if ($context['showCheckboxes'])
239
-		echo '
253
+	if ($context['showCheckboxes']) {
254
+			echo '
240 255
 		<form action="', $scripturl, '?action=quickmod" method="post" accept-charset="', $context['character_set'], '" name="quickModForm" id="quickModForm">
241 256
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
242 257
 			<input type="hidden" name="qaction" value="markread">
243 258
 			<input type="hidden" name="redirect_url" value="action=unreadreplies', (!empty($context['showing_all_topics']) ? ';all' : ''), $context['querystring_board_limits'], '">';
259
+	}
244 260
 
245 261
 	if (!empty($context['topics']))
246 262
 	{
@@ -269,11 +285,12 @@  discard block
 block discarded – undo
269 285
 					</div>';
270 286
 
271 287
 		// Show a "select all" box for quick moderation?
272
-		if ($context['showCheckboxes'])
273
-			echo '
288
+		if ($context['showCheckboxes']) {
289
+					echo '
274 290
 					<div class="moderation">
275 291
 						<input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');">
276 292
 					</div>';
293
+		}
277 294
 
278 295
 		echo '
279 296
 				</div><!-- #topic_header -->
@@ -293,17 +310,20 @@  discard block
 block discarded – undo
293 310
 			echo '
294 311
 							<div class="icons floatright">';
295 312
 
296
-			if ($topic['is_locked'])
297
-				echo '
313
+			if ($topic['is_locked']) {
314
+							echo '
298 315
 								<span class="generic_icons lock"></span>';
316
+			}
299 317
 
300
-			if ($topic['is_sticky'])
301
-				echo '
318
+			if ($topic['is_sticky']) {
319
+							echo '
302 320
 								<span class="generic_icons sticky"></span>';
321
+			}
303 322
 
304
-			if ($topic['is_poll'])
305
-				echo '
323
+			if ($topic['is_poll']) {
324
+							echo '
306 325
 								<span class="generic_icons poll"></span>';
326
+			}
307 327
 
308 328
 			echo '
309 329
 							</div>';
@@ -329,11 +349,12 @@  discard block
 block discarded – undo
329 349
 							', sprintf($txt['last_post_topic'], '<a href="' . $topic['last_post']['href'] . '">' . $topic['last_post']['time'] . '</a>', $topic['last_post']['member']['link']), '
330 350
 						</div>';
331 351
 
332
-			if ($context['showCheckboxes'])
333
-				echo '
352
+			if ($context['showCheckboxes']) {
353
+							echo '
334 354
 						<div class="moderation">
335 355
 							<input type="checkbox" name="topics[]" value="', $topic['id'], '">
336 356
 						</div>';
357
+			}
337 358
 
338 359
 			echo '
339 360
 					</div><!-- $topic[css_class] -->';
@@ -350,24 +371,26 @@  discard block
 block discarded – undo
350 371
 					', $context['page_index'], '
351 372
 				</div>
352 373
 			</div>';
353
-	}
354
-	else
355
-		echo '
374
+	} else {
375
+			echo '
356 376
 			<div class="cat_bar">
357 377
 				<h3 class="catbg centertext">
358 378
 					', $context['showing_all_topics'] ? $txt['topic_alert_none'] : $txt['unread_topics_visit_none'], '
359 379
 				</h3>
360 380
 			</div>';
381
+	}
361 382
 
362
-	if ($context['showCheckboxes'])
363
-		echo '
383
+	if ($context['showCheckboxes']) {
384
+			echo '
364 385
 		</form>';
386
+	}
365 387
 
366 388
 	echo '
367 389
 	</div><!-- #recent -->';
368 390
 
369
-	if (empty($context['no_topic_listing']))
370
-		template_topic_legend();
371
-}
391
+	if (empty($context['no_topic_listing'])) {
392
+			template_topic_legend();
393
+	}
394
+	}
372 395
 
373 396
 ?>
374 397
\ No newline at end of file
Please login to merge, or discard this patch.
index.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@
 block discarded – undo
104 104
  *
105 105
  * @param string $class The fully-qualified class name.
106 106
  */
107
-spl_autoload_register(function ($class) use ($sourcedir)
107
+spl_autoload_register(function($class) use ($sourcedir)
108 108
 {
109 109
 	$classMap = array(
110 110
 		'ReCaptcha\\' => 'ReCaptcha/',
Please login to merge, or discard this patch.
Braces   +38 added lines, -26 removed lines patch added patch discarded remove patch
@@ -32,16 +32,18 @@  discard block
 block discarded – undo
32 32
 ob_start();
33 33
 
34 34
 // Do some cleaning, just in case.
35
-foreach (array('db_character_set', 'cachedir') as $variable)
35
+foreach (array('db_character_set', 'cachedir') as $variable) {
36 36
 	if (isset($GLOBALS[$variable]))
37 37
 		unset($GLOBALS[$variable], $GLOBALS[$variable]);
38
+}
38 39
 
39 40
 // Load the settings...
40 41
 require_once(dirname(__FILE__) . '/Settings.php');
41 42
 
42 43
 // Make absolutely sure the cache directory is defined.
43
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
44
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
44 45
 	$cachedir = $boarddir . '/cache';
46
+}
45 47
 
46 48
 // Without those we can't go anywhere
47 49
 require_once($sourcedir . '/QueryString.php');
@@ -51,8 +53,9 @@  discard block
 block discarded – undo
51 53
 require_once($sourcedir . '/Load.php');
52 54
 
53 55
 // If $maintenance is set specifically to 2, then we're upgrading or something.
54
-if (!empty($maintenance) && $maintenance == 2)
56
+if (!empty($maintenance) && $maintenance == 2) {
55 57
 	display_maintenance_message();
58
+}
56 59
 
57 60
 // Create a variable to store some SMF specific functions in.
58 61
 $smcFunc = array();
@@ -67,8 +70,9 @@  discard block
 block discarded – undo
67 70
 cleanRequest();
68 71
 
69 72
 // Seed the random generator.
70
-if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69)
73
+if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) {
71 74
 	smf_seed_generator();
75
+}
72 76
 
73 77
 // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out!
74 78
 if (isset($_GET['scheduled']))
@@ -88,9 +92,9 @@  discard block
 block discarded – undo
88 92
 if (!empty($modSettings['enableCompressedOutput']) && !headers_sent())
89 93
 {
90 94
 	// If zlib is being used, turn off output compression.
91
-	if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler')
92
-		$modSettings['enableCompressedOutput'] = '0';
93
-	else
95
+	if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler') {
96
+			$modSettings['enableCompressedOutput'] = '0';
97
+	} else
94 98
 	{
95 99
 		ob_end_clean();
96 100
 		ob_start('ob_gzhandler');
@@ -182,18 +186,21 @@  discard block
 block discarded – undo
182 186
 	loadPermissions();
183 187
 
184 188
 	// Attachments don't require the entire theme to be loaded.
185
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach')
186
-		detectBrowser();
189
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') {
190
+			detectBrowser();
191
+	}
187 192
 	// Load the current theme.  (note that ?theme=1 will also work, may be used for guest theming.)
188
-	else
189
-		loadTheme();
193
+	else {
194
+			loadTheme();
195
+	}
190 196
 
191 197
 	// Check if the user should be disallowed access.
192 198
 	is_not_banned();
193 199
 
194 200
 	// If we are in a topic and don't have permission to approve it then duck out now.
195
-	if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest']))
196
-		fatal_lang_error('not_a_topic', false);
201
+	if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) {
202
+			fatal_lang_error('not_a_topic', false);
203
+	}
197 204
 
198 205
 	$no_stat_actions = array('clock', 'dlattach', 'findmember', 'jsoption', 'likes', 'loadeditorlocale', 'modifycat', 'requestmembers', 'smstats', 'suggest', 'about:unknown', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewsmfile');
199 206
 	call_integration_hook('integrate_pre_log_stats', array(&$no_stat_actions));
@@ -204,8 +211,9 @@  discard block
 block discarded – undo
204 211
 		writeLog();
205 212
 
206 213
 		// Track forum statistics and hits...?
207
-		if (!empty($modSettings['hitStats']))
208
-			trackStats(array('hits' => '+'));
214
+		if (!empty($modSettings['hitStats'])) {
215
+					trackStats(array('hits' => '+'));
216
+		}
209 217
 	}
210 218
 	unset($no_stat_actions);
211 219
 
@@ -219,13 +227,14 @@  discard block
 block discarded – undo
219 227
 			return ($_REQUEST['action'] == 'login2' ? 'Login2' : ($_REQUEST['action'] == 'logintfa' ? 'LoginTFA' : 'Logout'));
220 228
 		}
221 229
 		// Don't even try it, sonny.
222
-		else
223
-			return 'InMaintenance';
230
+		else {
231
+					return 'InMaintenance';
232
+		}
224 233
 	}
225 234
 	// If guest access is off, a guest can only do one of the very few following actions.
226
-	elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2'))))
227
-		return 'KickGuest';
228
-	elseif (empty($_REQUEST['action']))
235
+	elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2')))) {
236
+			return 'KickGuest';
237
+	} elseif (empty($_REQUEST['action']))
229 238
 	{
230 239
 		// Action and board are both empty... BoardIndex! Unless someone else wants to do something different.
231 240
 		if (empty($board) && empty($topic))
@@ -239,8 +248,9 @@  discard block
 block discarded – undo
239 248
 
240 249
 				$call = call_helper($defaultAction, true);
241 250
 
242
-				if (!empty($call))
243
-					return $call;
251
+				if (!empty($call)) {
252
+									return $call;
253
+				}
244 254
 			}
245 255
 
246 256
 			// No default action huh? then go to our good old BoardIndex.
@@ -370,8 +380,9 @@  discard block
 block discarded – undo
370 380
 
371 381
 			$call = call_helper($fallbackAction, true);
372 382
 
373
-			if (!empty($call))
374
-				return $call;
383
+			if (!empty($call)) {
384
+							return $call;
385
+			}
375 386
 		}
376 387
 
377 388
 		// No fallback action, huh?
@@ -382,8 +393,9 @@  discard block
 block discarded – undo
382 393
 	}
383 394
 
384 395
 	// Otherwise, it was set - so let's go to that action.
385
-	if (!empty($actionArray[$_REQUEST['action']][0]))
386
-		require_once($sourcedir . '/' . $actionArray[$_REQUEST['action']][0]);
396
+	if (!empty($actionArray[$_REQUEST['action']][0])) {
397
+			require_once($sourcedir . '/' . $actionArray[$_REQUEST['action']][0]);
398
+	}
387 399
 
388 400
 	// Do the right thing.
389 401
 	return call_helper($actionArray[$_REQUEST['action']][1], true);
Please login to merge, or discard this patch.
Themes/default/Calendar.template.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
  * Display a list of upcoming events, birthdays, and holidays.
69 69
  *
70 70
  * @param string $grid_name The grid name
71
- * @return void|bool Returns false if the grid doesn't exist.
71
+ * @return false|null Returns false if the grid doesn't exist.
72 72
  */
73 73
 function template_show_upcoming_list($grid_name)
74 74
 {
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
  *
239 239
  * @param string $grid_name The grid name
240 240
  * @param bool $is_mini Is this a mini grid?
241
- * @return void|bool Returns false if the grid doesn't exist.
241
+ * @return false|null Returns false if the grid doesn't exist.
242 242
  */
243 243
 function template_show_month_grid($grid_name, $is_mini = false)
244 244
 {
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
  * Shows a weekly grid
524 524
  *
525 525
  * @param string $grid_name The name of the grid
526
- * @return void|bool Returns false if the grid doesn't exist
526
+ * @return false|null Returns false if the grid doesn't exist
527 527
  */
528 528
 function template_show_week_grid($grid_name)
529 529
 {
Please login to merge, or discard this patch.
Braces   +222 added lines, -162 removed lines patch added patch discarded remove patch
@@ -22,30 +22,32 @@  discard block
 block discarded – undo
22 22
 		<div id="calendar">';
23 23
 
24 24
 	// Show the mini-blocks if they're enabled.
25
-	if (empty($context['blocks_disabled']))
26
-		echo '
25
+	if (empty($context['blocks_disabled'])) {
26
+			echo '
27 27
 			<div id="month_grid">
28 28
 				', template_show_month_grid('prev', true), '
29 29
 				', template_show_month_grid('current', true), '
30 30
 				', template_show_month_grid('next', true), '
31 31
 			</div>';
32
+	}
32 33
 
33 34
 	// What view are we showing?
34
-	if ($context['calendar_view'] == 'viewlist')
35
-		echo '
35
+	if ($context['calendar_view'] == 'viewlist') {
36
+			echo '
36 37
 			<div id="main_grid">
37 38
 				', template_show_upcoming_list('main'), '
38 39
 			</div>';
39
-	elseif ($context['calendar_view'] == 'viewweek')
40
-		echo '
40
+	} elseif ($context['calendar_view'] == 'viewweek') {
41
+			echo '
41 42
 			<div id="main_grid">
42 43
 				', template_show_week_grid('main'), '
43 44
 			</div>';
44
-	else
45
-		echo '
45
+	} else {
46
+			echo '
46 47
 			<div id="main_grid">
47 48
 				', template_show_month_grid('main'), '
48 49
 			</div>';
50
+	}
49 51
 
50 52
 	// Close our wrapper.
51 53
 	echo '
@@ -64,20 +66,22 @@  discard block
 block discarded – undo
64 66
 	global $context, $scripturl, $txt;
65 67
 
66 68
 	// Bail out if we have nothing to work with
67
-	if (!isset($context['calendar_grid_' . $grid_name]))
68
-		return false;
69
+	if (!isset($context['calendar_grid_' . $grid_name])) {
70
+			return false;
71
+	}
69 72
 
70 73
 	// Protect programmer sanity
71 74
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
72 75
 
73 76
 	// Do we want a title?
74
-	if (empty($calendar_data['disable_title']))
75
-		echo '
77
+	if (empty($calendar_data['disable_title'])) {
78
+			echo '
76 79
 			<div class="cat_bar">
77 80
 				<h3 class="catbg centertext largetext">
78 81
 					<a href="', $scripturl, '?action=calendar;viewlist;year=', $calendar_data['start_year'], ';month=', $calendar_data['start_month'], ';day=', $calendar_data['start_day'], '">', $txt['calendar_upcoming'], '</a>
79 82
 				</h3>
80 83
 			</div>';
84
+	}
81 85
 
82 86
 	// Give the user some controls to work with
83 87
 	template_calendar_top($calendar_data);
@@ -100,11 +104,13 @@  discard block
 block discarded – undo
100 104
 					<li class="windowbg">
101 105
 						<strong class="event_title">', $event['link'], '</strong>';
102 106
 
103
-				if ($event['can_edit'])
104
-					echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
107
+				if ($event['can_edit']) {
108
+									echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
109
+				}
105 110
 
106
-				if ($event['can_export'])
107
-					echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
111
+				if ($event['can_export']) {
112
+									echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
113
+				}
108 114
 
109 115
 				echo '
110 116
 						<br>';
@@ -112,14 +118,14 @@  discard block
 block discarded – undo
112 118
 				if (!empty($event['allday']))
113 119
 				{
114 120
 					echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), '</time>', ($event['start_date'] != $event['end_date']) ? ' &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">' . trim($event['end_date_local']) . '</time>' : '';
115
-				}
116
-				else
121
+				} else
117 122
 				{
118 123
 					// Display event info relative to user's local timezone
119 124
 					echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), ', ', trim($event['start_time_local']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
120 125
 
121
-					if ($event['start_date_local'] != $event['end_date_local'])
122
-						echo trim($event['end_date_local']) . ', ';
126
+					if ($event['start_date_local'] != $event['end_date_local']) {
127
+											echo trim($event['end_date_local']) . ', ';
128
+					}
123 129
 
124 130
 					echo trim($event['end_time_local']);
125 131
 
@@ -128,23 +134,27 @@  discard block
 block discarded – undo
128 134
 					{
129 135
 						echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">';
130 136
 
131
-						if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig'])
132
-							echo trim($event['start_date_orig']), ', ';
137
+						if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig']) {
138
+													echo trim($event['start_date_orig']), ', ';
139
+						}
133 140
 
134 141
 						echo trim($event['start_time_orig']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
135 142
 
136
-						if ($event['start_date_orig'] != $event['end_date_orig'])
137
-							echo trim($event['end_date_orig']) . ', ';
143
+						if ($event['start_date_orig'] != $event['end_date_orig']) {
144
+													echo trim($event['end_date_orig']) . ', ';
145
+						}
138 146
 
139 147
 						echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)';
140 148
 					}
141 149
 					// Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion
142
-					else
143
-						echo ' ', $event['tz_abbrev'], '</time>';
150
+					else {
151
+											echo ' ', $event['tz_abbrev'], '</time>';
152
+					}
144 153
 				}
145 154
 
146
-				if (!empty($event['location']))
147
-					echo '<br>', $event['location'];
155
+				if (!empty($event['location'])) {
156
+									echo '<br>', $event['location'];
157
+				}
148 158
 
149 159
 				echo '
150 160
 					</li>';
@@ -176,8 +186,9 @@  discard block
 block discarded – undo
176 186
 
177 187
 			$birthdays = array();
178 188
 
179
-			foreach ($date as $member)
180
-				$birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>';
189
+			foreach ($date as $member) {
190
+							$birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>';
191
+			}
181 192
 
182 193
 			echo implode(', ', $birthdays);
183 194
 
@@ -208,8 +219,9 @@  discard block
 block discarded – undo
208 219
 			$date_local = $date['date_local'];
209 220
 			unset($date['date_local']);
210 221
 
211
-			foreach ($date as $holiday)
212
-				$holidays[] = $holiday . ' (' . $date_local . ')';
222
+			foreach ($date as $holiday) {
223
+							$holidays[] = $holiday . ' (' . $date_local . ')';
224
+			}
213 225
 		}
214 226
 
215 227
 		echo implode(', ', $holidays);
@@ -233,17 +245,19 @@  discard block
 block discarded – undo
233 245
 	global $context, $txt, $scripturl, $modSettings;
234 246
 
235 247
 	// If the grid doesn't exist, no point in proceeding.
236
-	if (!isset($context['calendar_grid_' . $grid_name]))
237
-		return false;
248
+	if (!isset($context['calendar_grid_' . $grid_name])) {
249
+			return false;
250
+	}
238 251
 
239 252
 	// A handy little pointer variable.
240 253
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
241 254
 
242 255
 	// Some conditions for whether or not we should show the week links *here*.
243
-	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false)))
244
-		$show_week_links = true;
245
-	else
246
-		$show_week_links = false;
256
+	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false))) {
257
+			$show_week_links = true;
258
+	} else {
259
+			$show_week_links = false;
260
+	}
247 261
 
248 262
 	// Assuming that we've not disabled it, show the title block!
249 263
 	if (empty($calendar_data['disable_title']))
@@ -253,18 +267,20 @@  discard block
 block discarded – undo
253 267
 				<h3 class="catbg centertext largetext">';
254 268
 
255 269
 		// Previous Link: If we're showing prev / next and it's not a mini-calendar.
256
-		if (empty($calendar_data['previous_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false)
257
-			echo '
270
+		if (empty($calendar_data['previous_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false) {
271
+					echo '
258 272
 					<span class="floatleft">
259 273
 						<a href="', $calendar_data['previous_calendar']['href'], '">&#171;</a>
260 274
 					</span>';
275
+		}
261 276
 
262 277
 		// Next Link: if we're showing prev / next and it's not a mini-calendar.
263
-		if (empty($calendar_data['next_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false)
264
-			echo '
278
+		if (empty($calendar_data['next_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false) {
279
+					echo '
265 280
 					<span class="floatright">
266 281
 						<a href="', $calendar_data['next_calendar']['href'], '">&#187;</a>
267 282
 					</span>';
283
+		}
268 284
 
269 285
 		// Arguably the most exciting part, the title!
270 286
 		echo '
@@ -274,8 +290,9 @@  discard block
 block discarded – undo
274 290
 	}
275 291
 
276 292
 	// Show the controls on main grids
277
-	if ($is_mini === false)
278
-		template_calendar_top($calendar_data);
293
+	if ($is_mini === false) {
294
+			template_calendar_top($calendar_data);
295
+	}
279 296
 
280 297
 	// Finally, the main calendar table.
281 298
 	echo '
@@ -288,14 +305,16 @@  discard block
 block discarded – undo
288 305
 				<tr>';
289 306
 
290 307
 		// If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared!
291
-		if ($show_week_links === true)
292
-			echo '
308
+		if ($show_week_links === true) {
309
+					echo '
293 310
 					<th></th>';
311
+		}
294 312
 
295 313
 		// Now, loop through each actual day of the week.
296
-		foreach ($calendar_data['week_days'] as $day)
297
-			echo '
314
+		foreach ($calendar_data['week_days'] as $day) {
315
+					echo '
298 316
 					<th class="days" scope="col">', !empty($calendar_data['short_day_titles']) || $is_mini === true ? $txt['days_short'][$day] : $txt['days'][$day], '</th>';
317
+		}
299 318
 
300 319
 		echo '
301 320
 				</tr>';
@@ -314,11 +333,12 @@  discard block
 block discarded – undo
314 333
 				<tr class="days_wrapper">';
315 334
 
316 335
 		// This is where we add the actual week link, if enabled on this location.
317
-		if ($show_week_links === true)
318
-			echo '
336
+		if ($show_week_links === true) {
337
+					echo '
319 338
 					<td class="windowbg2 weeks">
320 339
 						<a href="', $scripturl, '?action=calendar;viewweek;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $week['days'][0]['day'], '" title="', $txt['calendar_view_week'], '">&#187;</a>
321 340
 					</td>';
341
+		}
322 342
 
323 343
 		// Now loop through each day in the week we're on.
324 344
 		foreach ($week['days'] as $day)
@@ -335,27 +355,29 @@  discard block
 block discarded – undo
335 355
 				// Additional classes are given for events, holidays, and birthdays.
336 356
 				if (!empty($day['events']) && !empty($calendar_data['highlight']['events']))
337 357
 				{
338
-					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3)))
339
-						$classes[] = 'events';
340
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3)))
341
-						$classes[] = 'events';
358
+					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3))) {
359
+											$classes[] = 'events';
360
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3))) {
361
+											$classes[] = 'events';
362
+					}
342 363
 				}
343 364
 				if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays']))
344 365
 				{
345
-					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3)))
346
-						$classes[] = 'holidays';
347
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3)))
348
-						$classes[] = 'holidays';
366
+					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3))) {
367
+											$classes[] = 'holidays';
368
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3))) {
369
+											$classes[] = 'holidays';
370
+					}
349 371
 				}
350 372
 				if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays']))
351 373
 				{
352
-					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3)))
353
-						$classes[] = 'birthdays';
354
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3)))
355
-						$classes[] = 'birthdays';
374
+					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3))) {
375
+											$classes[] = 'birthdays';
376
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3))) {
377
+											$classes[] = 'birthdays';
378
+					}
356 379
 				}
357
-			}
358
-			else
380
+			} else
359 381
 			{
360 382
 				// Default Classes (either compact or comfortable and disabled).
361 383
 				$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
@@ -374,25 +396,27 @@  discard block
 block discarded – undo
374 396
 				$title_prefix = !empty($day['is_first_of_month']) && $context['current_month'] == $calendar_data['current_month'] && $is_mini === false ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$calendar_data['current_month']] . ' ' : $txt['months_titles'][$calendar_data['current_month']] . ' ') : '';
375 397
 
376 398
 				// The actual day number - be it a link, or just plain old text!
377
-				if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
378
-					echo '
399
+				if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
400
+									echo '
379 401
 						<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
380
-				elseif ($is_mini)
381
-					echo '
402
+				} elseif ($is_mini) {
403
+									echo '
382 404
 						<a href="', $scripturl, '?action=calendar;', $context['calendar_view'], ';year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
383
-				else
384
-					echo '
405
+				} else {
406
+									echo '
385 407
 						<span class="day_text">', $title_prefix, $day['day'], '</span>';
408
+				}
386 409
 
387 410
 				// A lot of stuff, we're not showing on mini-calendars to conserve space.
388 411
 				if ($is_mini === false)
389 412
 				{
390 413
 					// Holidays are always fun, let's show them!
391
-					if (!empty($day['holidays']))
392
-						echo '
414
+					if (!empty($day['holidays'])) {
415
+											echo '
393 416
 						<div class="smalltext holiday">
394 417
 							<span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '
395 418
 						</div>';
419
+					}
396 420
 
397 421
 					// Happy Birthday Dear Member!
398 422
 					if (!empty($day['birthdays']))
@@ -410,15 +434,17 @@  discard block
 block discarded – undo
410 434
 							echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] || ($count == 10 && $use_js_hide) ? '' : ', ';
411 435
 
412 436
 							// 9...10! Let's stop there.
413
-							if ($birthday_count == 10 && $use_js_hide)
414
-								// !!TODO - Inline CSS and JavaScript should be moved.
437
+							if ($birthday_count == 10 && $use_js_hide) {
438
+															// !!TODO - Inline CSS and JavaScript should be moved.
415 439
 								echo '<span class="hidelink" id="bdhidelink_', $day['day'], '">...<br><a href="', $scripturl, '?action=calendar;month=', $calendar_data['current_month'], ';year=', $calendar_data['current_year'], ';showbd" onclick="document.getElementById(\'bdhide_', $day['day'], '\').style.display = \'\'; document.getElementById(\'bdhidelink_', $day['day'], '\').style.display = \'none\'; return false;">(', sprintf($txt['calendar_click_all'], count($day['birthdays'])), ')</a></span><span id="bdhide_', $day['day'], '" style="display: none;">, ';
440
+							}
416 441
 
417 442
 							++$birthday_count;
418 443
 						}
419
-						if ($use_js_hide)
420
-							echo '
444
+						if ($use_js_hide) {
445
+													echo '
421 446
 							</span>';
447
+						}
422 448
 
423 449
 						echo '
424 450
 						</div><!-- .smalltext -->';
@@ -429,8 +455,9 @@  discard block
 block discarded – undo
429 455
 					{
430 456
 						// Sort events by start time (all day events will be listed first)
431 457
 						uasort($day['events'], function($a, $b) {
432
-							if ($a['start_timestamp'] == $b['start_timestamp'])
433
-								return 0;
458
+							if ($a['start_timestamp'] == $b['start_timestamp']) {
459
+															return 0;
460
+							}
434 461
 
435 462
 							return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
436 463
 						});
@@ -450,20 +477,22 @@  discard block
 block discarded – undo
450 477
 								', $event['link'], '<br>
451 478
 								<span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
452 479
 
453
-							if (!empty($event['start_time_local']) && $event['starts_today'] == true)
454
-								echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
455
-							elseif (!empty($event['end_time_local']) && $event['ends_today'] == true)
456
-								echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
457
-							elseif (!empty($event['allday']))
458
-								echo $txt['calendar_allday'];
480
+							if (!empty($event['start_time_local']) && $event['starts_today'] == true) {
481
+															echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
482
+							} elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) {
483
+															echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
484
+							} elseif (!empty($event['allday'])) {
485
+															echo $txt['calendar_allday'];
486
+							}
459 487
 
460 488
 							echo '
461 489
 								</span>';
462 490
 
463
-							if (!empty($event['location']))
464
-								echo '
491
+							if (!empty($event['location'])) {
492
+															echo '
465 493
 								<br>
466 494
 								<span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
495
+							}
467 496
 
468 497
 							if ($event['can_edit'] || $event['can_export'])
469 498
 							{
@@ -471,18 +500,20 @@  discard block
 block discarded – undo
471 500
 								<span class="modify_event_links">';
472 501
 
473 502
 								// If they can edit the event, show an icon they can click on....
474
-								if ($event['can_edit'])
475
-									echo '
503
+								if ($event['can_edit']) {
504
+																	echo '
476 505
 									<a class="modify_event" href="', $event['modify_href'], '">
477 506
 										<span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span>
478 507
 									</a>';
508
+								}
479 509
 
480 510
 								// Exporting!
481
-								if ($event['can_export'])
482
-									echo '
511
+								if ($event['can_export']) {
512
+																	echo '
483 513
 									<a class="modify_event" href="', $event['export_href'], '">
484 514
 										<span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span>
485 515
 									</a>';
516
+								}
486 517
 
487 518
 								echo '
488 519
 								</span><br class="clear">';
@@ -501,10 +532,11 @@  discard block
 block discarded – undo
501 532
 			// Otherwise, assuming it's not a mini-calendar, we can show previous / next month days!
502 533
 			elseif ($is_mini === false)
503 534
 			{
504
-				if (empty($current_month_started) && !empty($context['calendar_grid_prev']))
505
-					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>';
506
-				elseif (!empty($current_month_started) && !empty($context['calendar_grid_next']))
507
-					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
535
+				if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) {
536
+									echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>';
537
+				} elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) {
538
+									echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
539
+				}
508 540
 			}
509 541
 
510 542
 			// Close this day and increase var count.
@@ -534,8 +566,9 @@  discard block
 block discarded – undo
534 566
 	global $context, $txt, $scripturl, $modSettings;
535 567
 
536 568
 	// We might have no reason to proceed, if the variable isn't there.
537
-	if (!isset($context['calendar_grid_' . $grid_name]))
538
-		return false;
569
+	if (!isset($context['calendar_grid_' . $grid_name])) {
570
+			return false;
571
+	}
539 572
 
540 573
 	// Handy pointer.
541 574
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
@@ -552,22 +585,25 @@  discard block
 block discarded – undo
552 585
 					<h3 class="catbg centertext largetext">';
553 586
 
554 587
 			// Previous Week Link...
555
-			if (empty($calendar_data['previous_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
556
-				echo '
588
+			if (empty($calendar_data['previous_calendar']['disabled']) && !empty($calendar_data['show_next_prev'])) {
589
+							echo '
557 590
 						<span class="floatleft">
558 591
 							<a href="', $calendar_data['previous_week']['href'], '">&#171;</a>
559 592
 						</span>';
593
+			}
560 594
 
561 595
 			// Next Week Link...
562
-			if (empty($calendar_data['next_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
563
-				echo '
596
+			if (empty($calendar_data['next_calendar']['disabled']) && !empty($calendar_data['show_next_prev'])) {
597
+							echo '
564 598
 						<span class="floatright">
565 599
 							<a href="', $calendar_data['next_week']['href'], '">&#187;</a>
566 600
 						</span>';
601
+			}
567 602
 
568 603
 			// The Month Title + Week Number...
569
-			if (!empty($calendar_data['week_title']))
570
-				echo $calendar_data['week_title'];
604
+			if (!empty($calendar_data['week_title'])) {
605
+							echo $calendar_data['week_title'];
606
+			}
571 607
 
572 608
 			echo '
573 609
 					</h3>
@@ -608,11 +644,12 @@  discard block
 block discarded – undo
608 644
 						<td class="', implode(' ', $classes), ' act_day">';
609 645
 
610 646
 			// Should the day number be a link?
611
-			if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
612
-				echo '
647
+			if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
648
+							echo '
613 649
 							<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>';
614
-			else
615
-				echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
650
+			} else {
651
+							echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
652
+			}
616 653
 
617 654
 			echo '
618 655
 						</td>
@@ -623,8 +660,9 @@  discard block
 block discarded – undo
623 660
 			{
624 661
 				// Sort events by start time (all day events will be listed first)
625 662
 				uasort($day['events'], function($a, $b) {
626
-					if ($a['start_timestamp'] == $b['start_timestamp'])
627
-						return 0;
663
+					if ($a['start_timestamp'] == $b['start_timestamp']) {
664
+											return 0;
665
+					}
628 666
 					return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
629 667
 				});
630 668
 
@@ -638,35 +676,39 @@  discard block
 block discarded – undo
638 676
 					echo $event['link'], '<br>
639 677
 								<span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
640 678
 
641
-					if (!empty($event['start_time_local']))
642
-						echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
643
-					else
644
-						echo $txt['calendar_allday'];
679
+					if (!empty($event['start_time_local'])) {
680
+											echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
681
+					} else {
682
+											echo $txt['calendar_allday'];
683
+					}
645 684
 
646 685
 					echo '
647 686
 								</span>';
648 687
 
649
-					if (!empty($event['location']))
650
-						echo '<br>
688
+					if (!empty($event['location'])) {
689
+											echo '<br>
651 690
 								<span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
691
+					}
652 692
 
653 693
 					if (!empty($event_icons_needed))
654 694
 					{
655 695
 						echo ' <span class="modify_event_links">';
656 696
 
657 697
 						// If they can edit the event, show a star they can click on....
658
-						if (!empty($event['can_edit']))
659
-							echo '
698
+						if (!empty($event['can_edit'])) {
699
+													echo '
660 700
 									<a class="modify_event" href="', $event['modify_href'], '">
661 701
 										<span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span>
662 702
 									</a>';
703
+						}
663 704
 
664 705
 						// Can we export? Sweet.
665
-						if (!empty($event['can_export']))
666
-							echo '
706
+						if (!empty($event['can_export'])) {
707
+													echo '
667 708
 									<a class="modify_event" href="', $event['export_href'], '">
668 709
 										<span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span>
669 710
 									</a>';
711
+						}
670 712
 
671 713
 						echo '
672 714
 								</span><br class="clear">';
@@ -684,22 +726,23 @@  discard block
 block discarded – undo
684 726
 							</div>
685 727
 							<br class="clear">';
686 728
 				}
687
-			}
688
-			else
729
+			} else
689 730
 			{
690
-				if (!empty($context['can_post']))
691
-					echo '
731
+				if (!empty($context['can_post'])) {
732
+									echo '
692 733
 							<div class="week_add_event">
693 734
 								<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['calendar_post_event'], '</a>
694 735
 							</div>';
736
+				}
695 737
 			}
696 738
 			echo '
697 739
 						</td>
698 740
 						<td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">';
699 741
 
700 742
 			// Show any holidays!
701
-			if (!empty($day['holidays']))
702
-				echo implode('<br>', $day['holidays']);
743
+			if (!empty($day['holidays'])) {
744
+							echo implode('<br>', $day['holidays']);
745
+			}
703 746
 
704 747
 			echo '
705 748
 						</td>
@@ -708,11 +751,12 @@  discard block
 block discarded – undo
708 751
 			// Show any birthdays...
709 752
 			if (!empty($day['birthdays']))
710 753
 			{
711
-				foreach ($day['birthdays'] as $member)
712
-					echo '
754
+				foreach ($day['birthdays'] as $member) {
755
+									echo '
713 756
 							<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], '</a>
714 757
 							', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '
715 758
 							', $member['is_last'] ? '' : '<br>';
759
+				}
716 760
 			}
717 761
 			echo '
718 762
 						</td>
@@ -758,26 +802,27 @@  discard block
 block discarded – undo
758 802
 				<input type="text" name="end_date" id="end_date" maxlength="10" value="', $calendar_data['end_date'], '" tabindex="', $context['tabindex']++, '" class="date_input end" data-type="date">
759 803
 				<input type="submit" class="button" style="float:none" id="view_button" value="', $txt['view'], '">
760 804
 			</form>';
761
-	}
762
-	else
805
+	} else
763 806
 	{
764 807
 		echo'
765 808
 			<form action="', $scripturl, '?action=calendar" id="calendar_navigation" method="post" accept-charset="', $context['character_set'], '">
766 809
 				<select name="month" id="input_month">';
767 810
 
768 811
 		// Show a select box with all the months.
769
-		foreach ($txt['months_short'] as $number => $month)
770
-			echo '
812
+		foreach ($txt['months_short'] as $number => $month) {
813
+					echo '
771 814
 					<option value="', $number, '"', $number == $context['current_month'] ? ' selected' : '', '>', $month, '</option>';
815
+		}
772 816
 
773 817
 		echo '
774 818
 				</select>
775 819
 				<select name="year">';
776 820
 
777 821
 		// Show a link for every year...
778
-		for ($year = $context['calendar_resources']['min_year']; $year <= $context['calendar_resources']['max_year']; $year++)
779
-			echo '
822
+		for ($year = $context['calendar_resources']['min_year']; $year <= $context['calendar_resources']['max_year']; $year++) {
823
+					echo '
780 824
 					<option value="', $year, '"', $year == $context['current_year'] ? ' selected' : '', '>', $year, '</option>';
825
+		}
781 826
 
782 827
 		echo '
783 828
 				</select>
@@ -799,9 +844,10 @@  discard block
 block discarded – undo
799 844
 	echo '
800 845
 		<form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);">';
801 846
 
802
-	if (!empty($context['event']['new']))
803
-		echo '
847
+	if (!empty($context['event']['new'])) {
848
+			echo '
804 849
 			<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
850
+	}
805 851
 
806 852
 	// Start the main table.
807 853
 	echo '
@@ -812,8 +858,8 @@  discard block
 block discarded – undo
812 858
 					</h3>
813 859
 				</div>';
814 860
 
815
-	if (!empty($context['post_error']['messages']))
816
-		echo '
861
+	if (!empty($context['post_error']['messages'])) {
862
+			echo '
817 863
 				<div class="errorbox">
818 864
 					<dl class="event_error">
819 865
 						<dt>
@@ -824,6 +870,7 @@  discard block
 block discarded – undo
824 870
 						</dt>
825 871
 					</dl>
826 872
 				</div>';
873
+	}
827 874
 
828 875
 	echo '
829 876
 				<div class="roundframe noup">
@@ -851,9 +898,10 @@  discard block
 block discarded – undo
851 898
 			echo '
852 899
 									<optgroup label="', $category['name'], '">';
853 900
 
854
-			foreach ($category['boards'] as $board)
855
-				echo '
901
+			foreach ($category['boards'] as $board) {
902
+							echo '
856 903
 										<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
904
+			}
857 905
 			echo '
858 906
 									</optgroup>';
859 907
 		}
@@ -889,9 +937,10 @@  discard block
 block discarded – undo
889 937
 								<span class="label">', $txt['calendar_timezone'], '</span>
890 938
 								<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
891 939
 
892
-	foreach ($context['all_timezones'] as $tz => $tzname)
893
-		echo '
940
+	foreach ($context['all_timezones'] as $tz => $tzname) {
941
+			echo '
894 942
 									<option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
943
+	}
895 944
 
896 945
 	echo '
897 946
 								</select>
@@ -907,9 +956,10 @@  discard block
 block discarded – undo
907 956
 					<input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button">';
908 957
 
909 958
 	// Delete button?
910
-	if (empty($context['event']['new']))
911
-		echo '
959
+	if (empty($context['event']['new'])) {
960
+			echo '
912 961
 					<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button you_sure">';
962
+	}
913 963
 
914 964
 	echo '
915 965
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -937,9 +987,10 @@  discard block
 block discarded – undo
937 987
 		echo '
938 988
 				<td style="padding-', $alt ? 'right' : 'left', ': 1.5em;">';
939 989
 
940
-		foreach ($v as $i)
941
-			echo '
990
+		foreach ($v as $i) {
991
+					echo '
942 992
 					<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '"><br>';
993
+		}
943 994
 
944 995
 		echo '
945 996
 				</td>';
@@ -960,9 +1011,10 @@  discard block
 block discarded – undo
960 1011
 
961 1012
 	foreach ($context['clockicons'] as $t => $v)
962 1013
 	{
963
-		foreach ($v as $i)
964
-			echo '
1014
+		foreach ($v as $i) {
1015
+					echo '
965 1016
 			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1017
+		}
966 1018
 	}
967 1019
 
968 1020
 	echo '
@@ -987,13 +1039,14 @@  discard block
 block discarded – undo
987 1039
 
988 1040
 	foreach ($context['clockicons'] as $t => $v)
989 1041
 	{
990
-		foreach ($v as $i)
991
-			echo '
1042
+		foreach ($v as $i) {
1043
+					echo '
992 1044
 				if (', $t, ' >= ', $i, ')
993 1045
 				{
994 1046
 					turnon.push("', $t, '_', $i, '");
995 1047
 					', $t, ' -= ', $i, ';
996 1048
 				}';
1049
+		}
997 1050
 	}
998 1051
 
999 1052
 	echo '
@@ -1037,9 +1090,10 @@  discard block
 block discarded – undo
1037 1090
 			<tr class="', $alt ? 'windowbg2' : 'windowbg', '">
1038 1091
 				<td>';
1039 1092
 
1040
-		foreach ($v as $i)
1041
-			echo '
1093
+		foreach ($v as $i) {
1094
+					echo '
1042 1095
 					<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
1096
+		}
1043 1097
 
1044 1098
 		echo '
1045 1099
 				</td>
@@ -1061,9 +1115,10 @@  discard block
 block discarded – undo
1061 1115
 
1062 1116
 	foreach ($context['clockicons'] as $t => $v)
1063 1117
 	{
1064
-		foreach ($v as $i)
1065
-			echo '
1118
+		foreach ($v as $i) {
1119
+					echo '
1066 1120
 			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1121
+		}
1067 1122
 	}
1068 1123
 
1069 1124
 	echo '
@@ -1080,13 +1135,14 @@  discard block
 block discarded – undo
1080 1135
 
1081 1136
 	foreach ($context['clockicons'] as $t => $v)
1082 1137
 	{
1083
-		foreach ($v as $i)
1084
-			echo '
1138
+		foreach ($v as $i) {
1139
+					echo '
1085 1140
 				if (', $t, ' >= ', $i, ')
1086 1141
 				{
1087 1142
 					turnon.push("', $t, '_', $i, '");
1088 1143
 					', $t, ' -= ', $i, ';
1089 1144
 				}';
1145
+		}
1090 1146
 	}
1091 1147
 
1092 1148
 	echo '
@@ -1130,9 +1186,10 @@  discard block
 block discarded – undo
1130 1186
 			<tr class="', $alt ? 'windowbg2' : 'windowbg', '">
1131 1187
 				<td>';
1132 1188
 
1133
-		foreach ($v as $i)
1134
-			echo '
1189
+		foreach ($v as $i) {
1190
+					echo '
1135 1191
 					<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
1192
+		}
1136 1193
 
1137 1194
 		echo '
1138 1195
 				</td>
@@ -1148,9 +1205,10 @@  discard block
 block discarded – undo
1148 1205
 
1149 1206
 	foreach ($context['clockicons'] as $t => $v)
1150 1207
 	{
1151
-		foreach ($v as $i)
1152
-			echo '
1208
+		foreach ($v as $i) {
1209
+					echo '
1153 1210
 			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1211
+		}
1154 1212
 	}
1155 1213
 
1156 1214
 	echo '
@@ -1171,13 +1229,14 @@  discard block
 block discarded – undo
1171 1229
 
1172 1230
 	foreach ($context['clockicons'] as $t => $v)
1173 1231
 	{
1174
-		foreach ($v as $i)
1175
-		echo '
1232
+		foreach ($v as $i) {
1233
+				echo '
1176 1234
 				if (', $t, ' >= ', $i, ')
1177 1235
 				{
1178 1236
 					turnon.push("', $t, '_', $i, '");
1179 1237
 					', $t, ' -= ', $i, ';
1180 1238
 				}';
1239
+		}
1181 1240
 	}
1182 1241
 
1183 1242
 	echo '
@@ -1221,9 +1280,10 @@  discard block
 block discarded – undo
1221 1280
 			<tr class="', $alt ? 'windowbg2' : 'windowbg', '">
1222 1281
 				<td>';
1223 1282
 
1224
-		foreach ($v as $i)
1225
-			echo '
1283
+		foreach ($v as $i) {
1284
+					echo '
1226 1285
 					<img src="', $i ? $context['onimg'] : $context['offimg'], '" alt="" style="padding: 2px;">';
1286
+		}
1227 1287
 
1228 1288
 		echo '
1229 1289
 				</td>
Please login to merge, or discard this patch.
other/upgrade.php 4 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@
 block discarded – undo
82 82
 
83 83
 // The helper is crucial. Include it first thing.
84 84
 if (!file_exists($upgrade_path . '/upgrade-helper.php'))
85
-    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.');
85
+	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.');
86 86
 
87 87
 require_once($upgrade_path . '/upgrade-helper.php');
88 88
 
Please login to merge, or discard this patch.
Spacing   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -1661,7 +1661,7 @@  discard block
 block discarded – undo
1661 1661
 
1662 1662
 	// Our custom error handler - does nothing but does stop public errors from XML!
1663 1663
 	set_error_handler(
1664
-		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1664
+		function($errno, $errstr, $errfile, $errline) use ($support_js)
1665 1665
 		{
1666 1666
 			if ($support_js)
1667 1667
 				return true;
@@ -2651,94 +2651,94 @@  discard block
 block discarded – undo
2651 2651
 		// Translation table for the character sets not native for MySQL.
2652 2652
 		$translation_tables = array(
2653 2653
 			'windows-1255' => array(
2654
-				'0x81' => '\'\'',		'0x8A' => '\'\'',		'0x8C' => '\'\'',
2655
-				'0x8D' => '\'\'',		'0x8E' => '\'\'',		'0x8F' => '\'\'',
2656
-				'0x90' => '\'\'',		'0x9A' => '\'\'',		'0x9C' => '\'\'',
2657
-				'0x9D' => '\'\'',		'0x9E' => '\'\'',		'0x9F' => '\'\'',
2658
-				'0xCA' => '\'\'',		'0xD9' => '\'\'',		'0xDA' => '\'\'',
2659
-				'0xDB' => '\'\'',		'0xDC' => '\'\'',		'0xDD' => '\'\'',
2660
-				'0xDE' => '\'\'',		'0xDF' => '\'\'',		'0xFB' => '0xD792',
2661
-				'0xFC' => '0xE282AC',		'0xFF' => '0xD6B2',		'0xC2' => '0xFF',
2662
-				'0x80' => '0xFC',		'0xE2' => '0xFB',		'0xA0' => '0xC2A0',
2663
-				'0xA1' => '0xC2A1',		'0xA2' => '0xC2A2',		'0xA3' => '0xC2A3',
2664
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
2665
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
2666
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
2667
-				'0xAF' => '0xC2AF',		'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',
2668
-				'0xB2' => '0xC2B2',		'0xB3' => '0xC2B3',		'0xB4' => '0xC2B4',
2669
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
2670
-				'0xB8' => '0xC2B8',		'0xB9' => '0xC2B9',		'0xBB' => '0xC2BB',
2671
-				'0xBC' => '0xC2BC',		'0xBD' => '0xC2BD',		'0xBE' => '0xC2BE',
2672
-				'0xBF' => '0xC2BF',		'0xD7' => '0xD7B3',		'0xD1' => '0xD781',
2673
-				'0xD4' => '0xD7B0',		'0xD5' => '0xD7B1',		'0xD6' => '0xD7B2',
2674
-				'0xE0' => '0xD790',		'0xEA' => '0xD79A',		'0xEC' => '0xD79C',
2675
-				'0xED' => '0xD79D',		'0xEE' => '0xD79E',		'0xEF' => '0xD79F',
2676
-				'0xF0' => '0xD7A0',		'0xF1' => '0xD7A1',		'0xF2' => '0xD7A2',
2677
-				'0xF3' => '0xD7A3',		'0xF5' => '0xD7A5',		'0xF6' => '0xD7A6',
2678
-				'0xF7' => '0xD7A7',		'0xF8' => '0xD7A8',		'0xF9' => '0xD7A9',
2679
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
2680
-				'0x86' => '0xE280A0',	'0x87' => '0xE280A1',	'0x89' => '0xE280B0',
2681
-				'0x8B' => '0xE280B9',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
2682
-				'0x95' => '0xE280A2',	'0x97' => '0xE28094',	'0x99' => '0xE284A2',
2683
-				'0xC0' => '0xD6B0',		'0xC1' => '0xD6B1',		'0xC3' => '0xD6B3',
2684
-				'0xC4' => '0xD6B4',		'0xC5' => '0xD6B5',		'0xC6' => '0xD6B6',
2685
-				'0xC7' => '0xD6B7',		'0xC8' => '0xD6B8',		'0xC9' => '0xD6B9',
2686
-				'0xCB' => '0xD6BB',		'0xCC' => '0xD6BC',		'0xCD' => '0xD6BD',
2687
-				'0xCE' => '0xD6BE',		'0xCF' => '0xD6BF',		'0xD0' => '0xD780',
2688
-				'0xD2' => '0xD782',		'0xE3' => '0xD793',		'0xE4' => '0xD794',
2689
-				'0xE5' => '0xD795',		'0xE7' => '0xD797',		'0xE9' => '0xD799',
2690
-				'0xFD' => '0xE2808E',	'0xFE' => '0xE2808F',	'0x92' => '0xE28099',
2691
-				'0x83' => '0xC692',		'0xD3' => '0xD783',		'0x88' => '0xCB86',
2692
-				'0x98' => '0xCB9C',		'0x91' => '0xE28098',	'0x96' => '0xE28093',
2693
-				'0xBA' => '0xC3B7',		'0x9B' => '0xE280BA',	'0xAA' => '0xC397',
2694
-				'0xA4' => '0xE282AA',	'0xE1' => '0xD791',		'0xE6' => '0xD796',
2695
-				'0xE8' => '0xD798',		'0xEB' => '0xD79B',		'0xF4' => '0xD7A4',
2654
+				'0x81' => '\'\'', '0x8A' => '\'\'', '0x8C' => '\'\'',
2655
+				'0x8D' => '\'\'', '0x8E' => '\'\'', '0x8F' => '\'\'',
2656
+				'0x90' => '\'\'', '0x9A' => '\'\'', '0x9C' => '\'\'',
2657
+				'0x9D' => '\'\'', '0x9E' => '\'\'', '0x9F' => '\'\'',
2658
+				'0xCA' => '\'\'', '0xD9' => '\'\'', '0xDA' => '\'\'',
2659
+				'0xDB' => '\'\'', '0xDC' => '\'\'', '0xDD' => '\'\'',
2660
+				'0xDE' => '\'\'', '0xDF' => '\'\'', '0xFB' => '0xD792',
2661
+				'0xFC' => '0xE282AC', '0xFF' => '0xD6B2', '0xC2' => '0xFF',
2662
+				'0x80' => '0xFC', '0xE2' => '0xFB', '0xA0' => '0xC2A0',
2663
+				'0xA1' => '0xC2A1', '0xA2' => '0xC2A2', '0xA3' => '0xC2A3',
2664
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
2665
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
2666
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
2667
+				'0xAF' => '0xC2AF', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1',
2668
+				'0xB2' => '0xC2B2', '0xB3' => '0xC2B3', '0xB4' => '0xC2B4',
2669
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
2670
+				'0xB8' => '0xC2B8', '0xB9' => '0xC2B9', '0xBB' => '0xC2BB',
2671
+				'0xBC' => '0xC2BC', '0xBD' => '0xC2BD', '0xBE' => '0xC2BE',
2672
+				'0xBF' => '0xC2BF', '0xD7' => '0xD7B3', '0xD1' => '0xD781',
2673
+				'0xD4' => '0xD7B0', '0xD5' => '0xD7B1', '0xD6' => '0xD7B2',
2674
+				'0xE0' => '0xD790', '0xEA' => '0xD79A', '0xEC' => '0xD79C',
2675
+				'0xED' => '0xD79D', '0xEE' => '0xD79E', '0xEF' => '0xD79F',
2676
+				'0xF0' => '0xD7A0', '0xF1' => '0xD7A1', '0xF2' => '0xD7A2',
2677
+				'0xF3' => '0xD7A3', '0xF5' => '0xD7A5', '0xF6' => '0xD7A6',
2678
+				'0xF7' => '0xD7A7', '0xF8' => '0xD7A8', '0xF9' => '0xD7A9',
2679
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
2680
+				'0x86' => '0xE280A0', '0x87' => '0xE280A1', '0x89' => '0xE280B0',
2681
+				'0x8B' => '0xE280B9', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
2682
+				'0x95' => '0xE280A2', '0x97' => '0xE28094', '0x99' => '0xE284A2',
2683
+				'0xC0' => '0xD6B0', '0xC1' => '0xD6B1', '0xC3' => '0xD6B3',
2684
+				'0xC4' => '0xD6B4', '0xC5' => '0xD6B5', '0xC6' => '0xD6B6',
2685
+				'0xC7' => '0xD6B7', '0xC8' => '0xD6B8', '0xC9' => '0xD6B9',
2686
+				'0xCB' => '0xD6BB', '0xCC' => '0xD6BC', '0xCD' => '0xD6BD',
2687
+				'0xCE' => '0xD6BE', '0xCF' => '0xD6BF', '0xD0' => '0xD780',
2688
+				'0xD2' => '0xD782', '0xE3' => '0xD793', '0xE4' => '0xD794',
2689
+				'0xE5' => '0xD795', '0xE7' => '0xD797', '0xE9' => '0xD799',
2690
+				'0xFD' => '0xE2808E', '0xFE' => '0xE2808F', '0x92' => '0xE28099',
2691
+				'0x83' => '0xC692', '0xD3' => '0xD783', '0x88' => '0xCB86',
2692
+				'0x98' => '0xCB9C', '0x91' => '0xE28098', '0x96' => '0xE28093',
2693
+				'0xBA' => '0xC3B7', '0x9B' => '0xE280BA', '0xAA' => '0xC397',
2694
+				'0xA4' => '0xE282AA', '0xE1' => '0xD791', '0xE6' => '0xD796',
2695
+				'0xE8' => '0xD798', '0xEB' => '0xD79B', '0xF4' => '0xD7A4',
2696 2696
 				'0xFA' => '0xD7AA',
2697 2697
 			),
2698 2698
 			'windows-1253' => array(
2699
-				'0x81' => '\'\'',			'0x88' => '\'\'',			'0x8A' => '\'\'',
2700
-				'0x8C' => '\'\'',			'0x8D' => '\'\'',			'0x8E' => '\'\'',
2701
-				'0x8F' => '\'\'',			'0x90' => '\'\'',			'0x98' => '\'\'',
2702
-				'0x9A' => '\'\'',			'0x9C' => '\'\'',			'0x9D' => '\'\'',
2703
-				'0x9E' => '\'\'',			'0x9F' => '\'\'',			'0xAA' => '\'\'',
2704
-				'0xD2' => '0xE282AC',			'0xFF' => '0xCE92',			'0xCE' => '0xCE9E',
2705
-				'0xB8' => '0xCE88',		'0xBA' => '0xCE8A',		'0xBC' => '0xCE8C',
2706
-				'0xBE' => '0xCE8E',		'0xBF' => '0xCE8F',		'0xC0' => '0xCE90',
2707
-				'0xC8' => '0xCE98',		'0xCA' => '0xCE9A',		'0xCC' => '0xCE9C',
2708
-				'0xCD' => '0xCE9D',		'0xCF' => '0xCE9F',		'0xDA' => '0xCEAA',
2709
-				'0xE8' => '0xCEB8',		'0xEA' => '0xCEBA',		'0xEC' => '0xCEBC',
2710
-				'0xEE' => '0xCEBE',		'0xEF' => '0xCEBF',		'0xC2' => '0xFF',
2711
-				'0xBD' => '0xC2BD',		'0xED' => '0xCEBD',		'0xB2' => '0xC2B2',
2712
-				'0xA0' => '0xC2A0',		'0xA3' => '0xC2A3',		'0xA4' => '0xC2A4',
2713
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
2714
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
2715
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
2716
-				'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',		'0xB3' => '0xC2B3',
2717
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
2718
-				'0xBB' => '0xC2BB',		'0xE2' => '0xCEB2',		'0x80' => '0xD2',
2719
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
2720
-				'0x86' => '0xE280A0',	'0xA1' => '0xCE85',		'0xA2' => '0xCE86',
2721
-				'0x87' => '0xE280A1',	'0x89' => '0xE280B0',	'0xB9' => '0xCE89',
2722
-				'0x8B' => '0xE280B9',	'0x91' => '0xE28098',	'0x99' => '0xE284A2',
2723
-				'0x92' => '0xE28099',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
2724
-				'0x95' => '0xE280A2',	'0x96' => '0xE28093',	'0x97' => '0xE28094',
2725
-				'0x9B' => '0xE280BA',	'0xAF' => '0xE28095',	'0xB4' => '0xCE84',
2726
-				'0xC1' => '0xCE91',		'0xC3' => '0xCE93',		'0xC4' => '0xCE94',
2727
-				'0xC5' => '0xCE95',		'0xC6' => '0xCE96',		'0x83' => '0xC692',
2728
-				'0xC7' => '0xCE97',		'0xC9' => '0xCE99',		'0xCB' => '0xCE9B',
2729
-				'0xD0' => '0xCEA0',		'0xD1' => '0xCEA1',		'0xD3' => '0xCEA3',
2730
-				'0xD4' => '0xCEA4',		'0xD5' => '0xCEA5',		'0xD6' => '0xCEA6',
2731
-				'0xD7' => '0xCEA7',		'0xD8' => '0xCEA8',		'0xD9' => '0xCEA9',
2732
-				'0xDB' => '0xCEAB',		'0xDC' => '0xCEAC',		'0xDD' => '0xCEAD',
2733
-				'0xDE' => '0xCEAE',		'0xDF' => '0xCEAF',		'0xE0' => '0xCEB0',
2734
-				'0xE1' => '0xCEB1',		'0xE3' => '0xCEB3',		'0xE4' => '0xCEB4',
2735
-				'0xE5' => '0xCEB5',		'0xE6' => '0xCEB6',		'0xE7' => '0xCEB7',
2736
-				'0xE9' => '0xCEB9',		'0xEB' => '0xCEBB',		'0xF0' => '0xCF80',
2737
-				'0xF1' => '0xCF81',		'0xF2' => '0xCF82',		'0xF3' => '0xCF83',
2738
-				'0xF4' => '0xCF84',		'0xF5' => '0xCF85',		'0xF6' => '0xCF86',
2739
-				'0xF7' => '0xCF87',		'0xF8' => '0xCF88',		'0xF9' => '0xCF89',
2740
-				'0xFA' => '0xCF8A',		'0xFB' => '0xCF8B',		'0xFC' => '0xCF8C',
2741
-				'0xFD' => '0xCF8D',		'0xFE' => '0xCF8E',
2699
+				'0x81' => '\'\'', '0x88' => '\'\'', '0x8A' => '\'\'',
2700
+				'0x8C' => '\'\'', '0x8D' => '\'\'', '0x8E' => '\'\'',
2701
+				'0x8F' => '\'\'', '0x90' => '\'\'', '0x98' => '\'\'',
2702
+				'0x9A' => '\'\'', '0x9C' => '\'\'', '0x9D' => '\'\'',
2703
+				'0x9E' => '\'\'', '0x9F' => '\'\'', '0xAA' => '\'\'',
2704
+				'0xD2' => '0xE282AC', '0xFF' => '0xCE92', '0xCE' => '0xCE9E',
2705
+				'0xB8' => '0xCE88', '0xBA' => '0xCE8A', '0xBC' => '0xCE8C',
2706
+				'0xBE' => '0xCE8E', '0xBF' => '0xCE8F', '0xC0' => '0xCE90',
2707
+				'0xC8' => '0xCE98', '0xCA' => '0xCE9A', '0xCC' => '0xCE9C',
2708
+				'0xCD' => '0xCE9D', '0xCF' => '0xCE9F', '0xDA' => '0xCEAA',
2709
+				'0xE8' => '0xCEB8', '0xEA' => '0xCEBA', '0xEC' => '0xCEBC',
2710
+				'0xEE' => '0xCEBE', '0xEF' => '0xCEBF', '0xC2' => '0xFF',
2711
+				'0xBD' => '0xC2BD', '0xED' => '0xCEBD', '0xB2' => '0xC2B2',
2712
+				'0xA0' => '0xC2A0', '0xA3' => '0xC2A3', '0xA4' => '0xC2A4',
2713
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
2714
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
2715
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
2716
+				'0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB3' => '0xC2B3',
2717
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
2718
+				'0xBB' => '0xC2BB', '0xE2' => '0xCEB2', '0x80' => '0xD2',
2719
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
2720
+				'0x86' => '0xE280A0', '0xA1' => '0xCE85', '0xA2' => '0xCE86',
2721
+				'0x87' => '0xE280A1', '0x89' => '0xE280B0', '0xB9' => '0xCE89',
2722
+				'0x8B' => '0xE280B9', '0x91' => '0xE28098', '0x99' => '0xE284A2',
2723
+				'0x92' => '0xE28099', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
2724
+				'0x95' => '0xE280A2', '0x96' => '0xE28093', '0x97' => '0xE28094',
2725
+				'0x9B' => '0xE280BA', '0xAF' => '0xE28095', '0xB4' => '0xCE84',
2726
+				'0xC1' => '0xCE91', '0xC3' => '0xCE93', '0xC4' => '0xCE94',
2727
+				'0xC5' => '0xCE95', '0xC6' => '0xCE96', '0x83' => '0xC692',
2728
+				'0xC7' => '0xCE97', '0xC9' => '0xCE99', '0xCB' => '0xCE9B',
2729
+				'0xD0' => '0xCEA0', '0xD1' => '0xCEA1', '0xD3' => '0xCEA3',
2730
+				'0xD4' => '0xCEA4', '0xD5' => '0xCEA5', '0xD6' => '0xCEA6',
2731
+				'0xD7' => '0xCEA7', '0xD8' => '0xCEA8', '0xD9' => '0xCEA9',
2732
+				'0xDB' => '0xCEAB', '0xDC' => '0xCEAC', '0xDD' => '0xCEAD',
2733
+				'0xDE' => '0xCEAE', '0xDF' => '0xCEAF', '0xE0' => '0xCEB0',
2734
+				'0xE1' => '0xCEB1', '0xE3' => '0xCEB3', '0xE4' => '0xCEB4',
2735
+				'0xE5' => '0xCEB5', '0xE6' => '0xCEB6', '0xE7' => '0xCEB7',
2736
+				'0xE9' => '0xCEB9', '0xEB' => '0xCEBB', '0xF0' => '0xCF80',
2737
+				'0xF1' => '0xCF81', '0xF2' => '0xCF82', '0xF3' => '0xCF83',
2738
+				'0xF4' => '0xCF84', '0xF5' => '0xCF85', '0xF6' => '0xCF86',
2739
+				'0xF7' => '0xCF87', '0xF8' => '0xCF88', '0xF9' => '0xCF89',
2740
+				'0xFA' => '0xCF8A', '0xFB' => '0xCF8B', '0xFC' => '0xCF8C',
2741
+				'0xFD' => '0xCF8D', '0xFE' => '0xCF8E',
2742 2742
 			),
2743 2743
 		);
2744 2744
 
@@ -3638,7 +3638,7 @@  discard block
 block discarded – undo
3638 3638
 
3639 3639
 		if ($active < 600)
3640 3640
 			echo '
3641
-				', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '';
3641
+				', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'], ' ', $txt['upgrade_run_script2'], '';
3642 3642
 
3643 3643
 		if ($active > $upcontext['inactive_timeout'])
3644 3644
 			echo '
@@ -3840,7 +3840,7 @@  discard block
 block discarded – undo
3840 3840
 			<form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
3841 3841
 			<input type="hidden" name="backup_done" id="backup_done" value="0">
3842 3842
 			<strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong>
3843
-			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12') , 'px; overflow: auto;">
3843
+			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12'), 'px; overflow: auto;">
3844 3844
 			<span id="debuginfo"></span>
3845 3845
 			</div>';
3846 3846
 
@@ -4341,7 +4341,7 @@  discard block
 block discarded – undo
4341 4341
 			<form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
4342 4342
 			<input type="hidden" name="utf8_done" id="utf8_done" value="0">
4343 4343
 			<strong>', $txt['upgrade_completed'], ' <span id="tab_done">', $upcontext['cur_table_num'], '</span> ', $txt['upgrade_outof'], ' ', $upcontext['table_count'], ' ', $txt['upgrade_tables'], '</strong>
4344
-			<div id="debug_section" style="height: ', ($is_debug ? '97' : '12') , 'px; overflow: auto;">
4344
+			<div id="debug_section" style="height: ', ($is_debug ? '97' : '12'), 'px; overflow: auto;">
4345 4345
 			<span id="debuginfo"></span>
4346 4346
 			</div>';
4347 4347
 
@@ -4442,7 +4442,7 @@  discard block
 block discarded – undo
4442 4442
 			<form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
4443 4443
 			<input type="hidden" name="json_done" id="json_done" value="0">
4444 4444
 			<strong>', $txt['upgrade_completed'], ' <span id="tab_done">', $upcontext['cur_table_num'], '</span> ', $txt['upgrade_outof'], ' ', $upcontext['table_count'], ' ', $txt['upgrade_tables'], '</strong>
4445
-			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12') , 'px; overflow: auto;">
4445
+			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12'), 'px; overflow: auto;">
4446 4446
 			<span id="debuginfo"></span>
4447 4447
 			</div>';
4448 4448
 
Please login to merge, or discard this patch.
Doc Comments   +14 added lines, -1 removed lines patch added patch discarded remove patch
@@ -489,6 +489,9 @@  discard block
 block discarded – undo
489 489
 	}
490 490
 
491 491
 // Used to direct the user to another location.
492
+/**
493
+ * @param string $location
494
+ */
492 495
 function redirectLocation($location, $addForm = true)
493 496
 {
494 497
 	global $upgradeurl, $upcontext, $command_line;
@@ -1711,6 +1714,9 @@  discard block
 block discarded – undo
1711 1714
 	return addslashes(preg_replace(array('~^\.([/\\\]|$)~', '~[/]+~', '~[\\\]+~', '~[/\\\]$~'), array($install_path . '$1', '/', '\\', ''), $path));
1712 1715
 }
1713 1716
 
1717
+/**
1718
+ * @param string $filename
1719
+ */
1714 1720
 function parse_sql($filename)
1715 1721
 {
1716 1722
 	global $db_prefix, $db_collation, $boarddir, $boardurl, $command_line, $file_steps, $step_progress, $custom_warning;
@@ -1745,6 +1751,10 @@  discard block
 block discarded – undo
1745 1751
 
1746 1752
 	// Our custom error handler - does nothing but does stop public errors from XML!
1747 1753
 	set_error_handler(
1754
+
1755
+		/**
1756
+		 * @param string $errno
1757
+		 */
1748 1758
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1749 1759
 		{
1750 1760
 			if ($support_js)
@@ -1959,6 +1969,9 @@  discard block
 block discarded – undo
1959 1969
 	return true;
1960 1970
 }
1961 1971
 
1972
+/**
1973
+ * @param string $string
1974
+ */
1962 1975
 function upgrade_query($string, $unbuffered = false)
1963 1976
 {
1964 1977
 	global $db_connection, $db_server, $db_user, $db_passwd, $db_type, $command_line, $upcontext, $upgradeurl, $modSettings;
@@ -4712,7 +4725,7 @@  discard block
 block discarded – undo
4712 4725
  * @param int $setSize The amount of entries after which to update the database.
4713 4726
  *
4714 4727
  * newCol needs to be a varbinary(16) null able field
4715
- * @return bool
4728
+ * @return boolean|null
4716 4729
  */
4717 4730
 function MySQLConvertOldIp($targetTable, $oldCol, $newCol, $limit = 50000, $setSize = 100)
4718 4731
 {
Please login to merge, or discard this patch.
Braces   +898 added lines, -659 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
 
@@ -107,11 +108,14 @@  discard block
 block discarded – undo
107 108
 	ini_set('default_socket_timeout', 900);
108 109
 }
109 110
 // Clean the upgrade path if this is from the client.
110
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
111
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
111
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
112
+	for ($i = 1;
113
+}
114
+$i < $_SERVER['argc']; $i++)
112 115
 	{
113
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
114
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
116
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
117
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
118
+		}
115 119
 	}
116 120
 
117 121
 // Are we from the client?
@@ -119,16 +123,17 @@  discard block
 block discarded – undo
119 123
 {
120 124
 	$command_line = true;
121 125
 	$disable_security = true;
122
-}
123
-else
126
+} else {
124 127
 	$command_line = false;
128
+}
125 129
 
126 130
 // Load this now just because we can.
127 131
 require_once($upgrade_path . '/Settings.php');
128 132
 
129 133
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
130
-if (isset($language))
134
+if (isset($language)) {
131 135
 	$language = str_ireplace('-utf8', '', $language);
136
+}
132 137
 
133 138
 // Are we logged in?
134 139
 if (isset($upgradeData))
@@ -136,10 +141,12 @@  discard block
 block discarded – undo
136 141
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
137 142
 
138 143
 	// Check for sensible values.
139
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
140
-		$upcontext['user']['started'] = time();
141
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
142
-		$upcontext['user']['updated'] = 0;
144
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
145
+			$upcontext['user']['started'] = time();
146
+	}
147
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
148
+			$upcontext['user']['updated'] = 0;
149
+	}
143 150
 
144 151
 	$upcontext['started'] = $upcontext['user']['started'];
145 152
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -204,8 +211,9 @@  discard block
 block discarded – undo
204 211
 			'db_error_skip' => true,
205 212
 		)
206 213
 	);
207
-	while ($row = $smcFunc['db_fetch_assoc']($request))
208
-		$modSettings[$row['variable']] = $row['value'];
214
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
215
+			$modSettings[$row['variable']] = $row['value'];
216
+	}
209 217
 	$smcFunc['db_free_result']($request);
210 218
 }
211 219
 
@@ -215,10 +223,12 @@  discard block
 block discarded – undo
215 223
 	$modSettings['theme_url'] = 'Themes/default';
216 224
 	$modSettings['images_url'] = 'Themes/default/images';
217 225
 }
218
-if (!isset($settings['default_theme_url']))
226
+if (!isset($settings['default_theme_url'])) {
219 227
 	$settings['default_theme_url'] = $modSettings['theme_url'];
220
-if (!isset($settings['default_theme_dir']))
228
+}
229
+if (!isset($settings['default_theme_dir'])) {
221 230
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
231
+}
222 232
 
223 233
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
224 234
 // Default title...
@@ -236,13 +246,15 @@  discard block
 block discarded – undo
236 246
 	$support_js = $upcontext['upgrade_status']['js'];
237 247
 
238 248
 	// Only set this if the upgrader status says so.
239
-	if (empty($is_debug))
240
-		$is_debug = $upcontext['upgrade_status']['debug'];
249
+	if (empty($is_debug)) {
250
+			$is_debug = $upcontext['upgrade_status']['debug'];
251
+	}
241 252
 
242 253
 	// Load the language.
243
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
244
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
245
-}
254
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
255
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
256
+	}
257
+	}
246 258
 // Set the defaults.
247 259
 else
248 260
 {
@@ -260,15 +272,18 @@  discard block
 block discarded – undo
260 272
 }
261 273
 
262 274
 // If this isn't the first stage see whether they are logging in and resuming.
263
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
275
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
264 276
 	checkLogin();
277
+}
265 278
 
266
-if ($command_line)
279
+if ($command_line) {
267 280
 	cmdStep0();
281
+}
268 282
 
269 283
 // Don't error if we're using xml.
270
-if (isset($_GET['xml']))
284
+if (isset($_GET['xml'])) {
271 285
 	$upcontext['return_error'] = true;
286
+}
272 287
 
273 288
 // Loop through all the steps doing each one as required.
274 289
 $upcontext['overall_percent'] = 0;
@@ -289,9 +304,9 @@  discard block
 block discarded – undo
289 304
 		}
290 305
 
291 306
 		// Call the step and if it returns false that means pause!
292
-		if (function_exists($step[2]) && $step[2]() === false)
293
-			break;
294
-		elseif (function_exists($step[2])) {
307
+		if (function_exists($step[2]) && $step[2]() === false) {
308
+					break;
309
+		} elseif (function_exists($step[2])) {
295 310
 			//Start each new step with this unset, so the 'normal' template is called first
296 311
 			unset($_GET['xml']);
297 312
 			//Clear out warnings at the start of each step
@@ -337,17 +352,18 @@  discard block
 block discarded – undo
337 352
 		// This should not happen my dear... HELP ME DEVELOPERS!!
338 353
 		if (!empty($command_line))
339 354
 		{
340
-			if (function_exists('debug_print_backtrace'))
341
-				debug_print_backtrace();
355
+			if (function_exists('debug_print_backtrace')) {
356
+							debug_print_backtrace();
357
+			}
342 358
 
343 359
 			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.';
344 360
 			flush();
345 361
 			die();
346 362
 		}
347 363
 
348
-		if (!isset($_GET['xml']))
349
-			template_upgrade_above();
350
-		else
364
+		if (!isset($_GET['xml'])) {
365
+					template_upgrade_above();
366
+		} else
351 367
 		{
352 368
 			header('content-type: text/xml; charset=UTF-8');
353 369
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -369,25 +385,29 @@  discard block
 block discarded – undo
369 385
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
370 386
 
371 387
 			// Custom stuff to pass back?
372
-			if (!empty($upcontext['query_string']))
373
-				$upcontext['form_url'] .= $upcontext['query_string'];
388
+			if (!empty($upcontext['query_string'])) {
389
+							$upcontext['form_url'] .= $upcontext['query_string'];
390
+			}
374 391
 
375 392
 			// Call the appropriate subtemplate
376
-			if (is_callable('template_' . $upcontext['sub_template']))
377
-				call_user_func('template_' . $upcontext['sub_template']);
378
-			else
379
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
393
+			if (is_callable('template_' . $upcontext['sub_template'])) {
394
+							call_user_func('template_' . $upcontext['sub_template']);
395
+			} else {
396
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
397
+			}
380 398
 		}
381 399
 
382 400
 		// Was there an error?
383
-		if (!empty($upcontext['forced_error_message']))
384
-			echo $upcontext['forced_error_message'];
401
+		if (!empty($upcontext['forced_error_message'])) {
402
+					echo $upcontext['forced_error_message'];
403
+		}
385 404
 
386 405
 		// Show the footer.
387
-		if (!isset($_GET['xml']))
388
-			template_upgrade_below();
389
-		else
390
-			template_xml_below();
406
+		if (!isset($_GET['xml'])) {
407
+					template_upgrade_below();
408
+		} else {
409
+					template_xml_below();
410
+		}
391 411
 	}
392 412
 
393 413
 
@@ -399,15 +419,19 @@  discard block
 block discarded – undo
399 419
 		$seconds = intval($active % 60);
400 420
 
401 421
 		$totalTime = '';
402
-		if ($hours > 0)
403
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
404
-		if ($minutes > 0)
405
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
406
-		if ($seconds > 0)
407
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
422
+		if ($hours > 0) {
423
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
424
+		}
425
+		if ($minutes > 0) {
426
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
427
+		}
428
+		if ($seconds > 0) {
429
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
430
+		}
408 431
 
409
-		if (!empty($totalTime))
410
-			echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
432
+		if (!empty($totalTime)) {
433
+					echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
434
+		}
411 435
 	}
412 436
 
413 437
 	// Bang - gone!
@@ -428,8 +452,9 @@  discard block
 block discarded – undo
428 452
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
429 453
 		while ($entry = $dir->read())
430 454
 		{
431
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
432
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
455
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
456
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
457
+			}
433 458
 		}
434 459
 		$dir->close();
435 460
 	}
@@ -464,10 +489,11 @@  discard block
 block discarded – undo
464 489
 	}
465 490
 
466 491
 		// Override the language file?
467
-		if (isset($_GET['lang_file']))
468
-			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
469
-		elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
470
-			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
492
+		if (isset($_GET['lang_file'])) {
493
+					$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
494
+		} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
495
+					$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
496
+		}
471 497
 
472 498
 		// Make sure it exists, if it doesn't reset it.
473 499
 		if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -476,8 +502,9 @@  discard block
 block discarded – undo
476 502
 			list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
477 503
 
478 504
 			// If we have english and some other language, use the other language.  We Americans hate english :P.
479
-			if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
480
-				list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
505
+			if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
506
+							list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
507
+			}
481 508
 		}
482 509
 
483 510
 		// And now include the actual language file itself.
@@ -494,8 +521,9 @@  discard block
 block discarded – undo
494 521
 	global $upgradeurl, $upcontext, $command_line;
495 522
 
496 523
 	// Command line users can't be redirected.
497
-	if ($command_line)
498
-		upgradeExit(true);
524
+	if ($command_line) {
525
+			upgradeExit(true);
526
+	}
499 527
 
500 528
 	// Are we providing the core info?
501 529
 	if ($addForm)
@@ -521,12 +549,14 @@  discard block
 block discarded – undo
521 549
 	define('SMF', 1);
522 550
 
523 551
 	// Start the session.
524
-	if (@ini_get('session.save_handler') == 'user')
525
-		@ini_set('session.save_handler', 'files');
552
+	if (@ini_get('session.save_handler') == 'user') {
553
+			@ini_set('session.save_handler', 'files');
554
+	}
526 555
 	@session_start();
527 556
 
528
-	if (empty($smcFunc))
529
-		$smcFunc = array();
557
+	if (empty($smcFunc)) {
558
+			$smcFunc = array();
559
+	}
530 560
 
531 561
 	// We need this for authentication and some upgrade code
532 562
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -553,24 +583,27 @@  discard block
 block discarded – undo
553 583
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
554 584
 
555 585
 		// Make the connection...
556
-		if (empty($db_connection))
557
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
558
-		else
559
-			// If we've returned here, ping/reconnect to be safe
586
+		if (empty($db_connection)) {
587
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
588
+		} else {
589
+					// If we've returned here, ping/reconnect to be safe
560 590
 			$smcFunc['db_ping']($db_connection);
591
+		}
561 592
 
562 593
 		// Oh dear god!!
563
-		if ($db_connection === null)
564
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
594
+		if ($db_connection === null) {
595
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
596
+		}
565 597
 
566
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
567
-			$smcFunc['db_query']('', '
598
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
599
+					$smcFunc['db_query']('', '
568 600
 			SET NAMES {string:db_character_set}',
569 601
 			array(
570 602
 				'db_error_skip' => true,
571 603
 				'db_character_set' => $db_character_set,
572 604
 			)
573 605
 		);
606
+		}
574 607
 
575 608
 		// Load the modSettings data...
576 609
 		$request = $smcFunc['db_query']('', '
@@ -581,11 +614,11 @@  discard block
 block discarded – undo
581 614
 			)
582 615
 		);
583 616
 		$modSettings = array();
584
-		while ($row = $smcFunc['db_fetch_assoc']($request))
585
-			$modSettings[$row['variable']] = $row['value'];
617
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
618
+					$modSettings[$row['variable']] = $row['value'];
619
+		}
586 620
 		$smcFunc['db_free_result']($request);
587
-	}
588
-	else
621
+	} else
589 622
 	{
590 623
 		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.');
591 624
 	}
@@ -599,9 +632,10 @@  discard block
 block discarded – undo
599 632
 		cleanRequest();
600 633
 	}
601 634
 
602
-	if (!isset($_GET['substep']))
603
-		$_GET['substep'] = 0;
604
-}
635
+	if (!isset($_GET['substep'])) {
636
+			$_GET['substep'] = 0;
637
+	}
638
+	}
605 639
 
606 640
 function initialize_inputs()
607 641
 {
@@ -631,8 +665,9 @@  discard block
 block discarded – undo
631 665
 		$dh = opendir(dirname(__FILE__));
632 666
 		while ($file = readdir($dh))
633 667
 		{
634
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
635
-				@unlink(dirname(__FILE__) . '/' . $file);
668
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
669
+							@unlink(dirname(__FILE__) . '/' . $file);
670
+			}
636 671
 		}
637 672
 		closedir($dh);
638 673
 
@@ -661,8 +696,9 @@  discard block
 block discarded – undo
661 696
 	$temp = 'upgrade_php?step';
662 697
 	while (strlen($temp) > 4)
663 698
 	{
664
-		if (isset($_GET[$temp]))
665
-			unset($_GET[$temp]);
699
+		if (isset($_GET[$temp])) {
700
+					unset($_GET[$temp]);
701
+		}
666 702
 		$temp = substr($temp, 1);
667 703
 	}
668 704
 
@@ -689,32 +725,39 @@  discard block
 block discarded – undo
689 725
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
690 726
 
691 727
 	// Need legacy scripts?
692
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
693
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
694
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
695
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
696
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
697
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
728
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
729
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
730
+	}
731
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
732
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
733
+	}
734
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
735
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
736
+	}
698 737
 
699 738
 	// We don't need "-utf8" files anymore...
700 739
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
701 740
 
702 741
 	// This needs to exist!
703
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
704
-		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>]');
705
-	else
706
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
742
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
743
+			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>]');
744
+	} else {
745
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
746
+	}
707 747
 
708
-	if (!$check)
709
-		// 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.
748
+	if (!$check) {
749
+			// 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.
710 750
 		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.');
751
+	}
711 752
 
712 753
 	// Do they meet the install requirements?
713
-	if (!php_version_check())
714
-		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.');
754
+	if (!php_version_check()) {
755
+			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.');
756
+	}
715 757
 
716
-	if (!db_version_check())
717
-		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.');
758
+	if (!db_version_check()) {
759
+			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.');
760
+	}
718 761
 
719 762
 	// Do some checks to make sure they have proper privileges
720 763
 	db_extend('packages');
@@ -729,14 +772,16 @@  discard block
 block discarded – undo
729 772
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
730 773
 
731 774
 	// Sorry... we need CREATE, ALTER and DROP
732
-	if (!$create || !$alter || !$drop)
733
-		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.');
775
+	if (!$create || !$alter || !$drop) {
776
+			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.');
777
+	}
734 778
 
735 779
 	// Do a quick version spot check.
736 780
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
737 781
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
738
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
739
-		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.');
782
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
783
+			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.');
784
+	}
740 785
 
741 786
 	// What absolutely needs to be writable?
742 787
 	$writable_files = array(
@@ -745,12 +790,13 @@  discard block
 block discarded – undo
745 790
 	);
746 791
 
747 792
 	// Only check for minified writable files if we have it enabled or not set.
748
-	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files']))
749
-		$writable_files += array(
793
+	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) {
794
+			$writable_files += array(
750 795
 			$modSettings['theme_dir'] . '/css/minified.css',
751 796
 			$modSettings['theme_dir'] . '/scripts/minified.js',
752 797
 			$modSettings['theme_dir'] . '/scripts/minified_deferred.js',
753 798
 		);
799
+	}
754 800
 
755 801
 	// Do we need to add this setting?
756 802
 	$need_settings_update = empty($modSettings['custom_avatar_dir']);
@@ -762,12 +808,13 @@  discard block
 block discarded – undo
762 808
 	quickFileWritable($custom_av_dir);
763 809
 
764 810
 	// Are we good now?
765
-	if (!is_writable($custom_av_dir))
766
-		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));
767
-	elseif ($need_settings_update)
811
+	if (!is_writable($custom_av_dir)) {
812
+			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));
813
+	} elseif ($need_settings_update)
768 814
 	{
769
-		if (!function_exists('cache_put_data'))
770
-			require_once($sourcedir . '/Load.php');
815
+		if (!function_exists('cache_put_data')) {
816
+					require_once($sourcedir . '/Load.php');
817
+		}
771 818
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
772 819
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
773 820
 	}
@@ -776,28 +823,33 @@  discard block
 block discarded – undo
776 823
 
777 824
 	// Check the cache directory.
778 825
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
779
-	if (!file_exists($cachedir_temp))
780
-		@mkdir($cachedir_temp);
781
-	if (!file_exists($cachedir_temp))
782
-		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.');
783
-
784
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
785
-		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>.');
786
-	elseif (!isset($_GET['skiplang']))
826
+	if (!file_exists($cachedir_temp)) {
827
+			@mkdir($cachedir_temp);
828
+	}
829
+	if (!file_exists($cachedir_temp)) {
830
+			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.');
831
+	}
832
+
833
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
834
+			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>.');
835
+	} elseif (!isset($_GET['skiplang']))
787 836
 	{
788 837
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
789 838
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
790 839
 
791
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
792
-			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>]');
840
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
841
+					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>]');
842
+		}
793 843
 	}
794 844
 
795
-	if (!makeFilesWritable($writable_files))
796
-		return false;
845
+	if (!makeFilesWritable($writable_files)) {
846
+			return false;
847
+	}
797 848
 
798 849
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
799
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
800
-		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.');
850
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
851
+			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.');
852
+	}
801 853
 
802 854
 	// Upgrade the agreement.
803 855
 	elseif (isset($modSettings['agreement']))
@@ -808,8 +860,8 @@  discard block
 block discarded – undo
808 860
 	}
809 861
 
810 862
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
811
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
812
-		$upcontext['warning'] = '
863
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
864
+			$upcontext['warning'] = '
813 865
 			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>
814 866
 			<ul>
815 867
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -817,19 +869,23 @@  discard block
 block discarded – undo
817 869
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
818 870
 			</ul>
819 871
 			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.';
872
+	}
820 873
 
821 874
 	// Confirm mbstring is loaded...
822
-	if (!extension_loaded('mbstring'))
823
-		return throw_error($txt['install_no_mbstring']);
875
+	if (!extension_loaded('mbstring')) {
876
+			return throw_error($txt['install_no_mbstring']);
877
+	}
824 878
 
825 879
 	// Check for https stream support.
826 880
 	$supported_streams = stream_get_wrappers();
827
-	if (!in_array('https', $supported_streams))
828
-		$upcontext['custom_warning'] = $txt['install_no_https'];
881
+	if (!in_array('https', $supported_streams)) {
882
+			$upcontext['custom_warning'] = $txt['install_no_https'];
883
+	}
829 884
 
830 885
 	// Either we're logged in or we're going to present the login.
831
-	if (checkLogin())
832
-		return true;
886
+	if (checkLogin()) {
887
+			return true;
888
+	}
833 889
 
834 890
 	$upcontext += createToken('login');
835 891
 
@@ -843,15 +899,17 @@  discard block
 block discarded – undo
843 899
 	global $smcFunc, $db_type, $support_js;
844 900
 
845 901
 	// Don't bother if the security is disabled.
846
-	if ($disable_security)
847
-		return true;
902
+	if ($disable_security) {
903
+			return true;
904
+	}
848 905
 
849 906
 	// Are we trying to login?
850 907
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
851 908
 	{
852 909
 		// If we've disabled security pick a suitable name!
853
-		if (empty($_POST['user']))
854
-			$_POST['user'] = 'Administrator';
910
+		if (empty($_POST['user'])) {
911
+					$_POST['user'] = 'Administrator';
912
+		}
855 913
 
856 914
 		// Before 2.0 these column names were different!
857 915
 		$oldDB = false;
@@ -866,16 +924,17 @@  discard block
 block discarded – undo
866 924
 					'db_error_skip' => true,
867 925
 				)
868 926
 			);
869
-			if ($smcFunc['db_num_rows']($request) != 0)
870
-				$oldDB = true;
927
+			if ($smcFunc['db_num_rows']($request) != 0) {
928
+							$oldDB = true;
929
+			}
871 930
 			$smcFunc['db_free_result']($request);
872 931
 		}
873 932
 
874 933
 		// Get what we believe to be their details.
875 934
 		if (!$disable_security)
876 935
 		{
877
-			if ($oldDB)
878
-				$request = $smcFunc['db_query']('', '
936
+			if ($oldDB) {
937
+							$request = $smcFunc['db_query']('', '
879 938
 					SELECT id_member, memberName AS member_name, passwd, id_group,
880 939
 					additionalGroups AS additional_groups, lngfile
881 940
 					FROM {db_prefix}members
@@ -885,8 +944,8 @@  discard block
 block discarded – undo
885 944
 						'db_error_skip' => true,
886 945
 					)
887 946
 				);
888
-			else
889
-				$request = $smcFunc['db_query']('', '
947
+			} else {
948
+							$request = $smcFunc['db_query']('', '
890 949
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
891 950
 					FROM {db_prefix}members
892 951
 					WHERE member_name = {string:member_name}',
@@ -895,6 +954,7 @@  discard block
 block discarded – undo
895 954
 						'db_error_skip' => true,
896 955
 					)
897 956
 				);
957
+			}
898 958
 			if ($smcFunc['db_num_rows']($request) != 0)
899 959
 			{
900 960
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -902,16 +962,17 @@  discard block
 block discarded – undo
902 962
 				$groups = explode(',', $addGroups);
903 963
 				$groups[] = $id_group;
904 964
 
905
-				foreach ($groups as $k => $v)
906
-					$groups[$k] = (int) $v;
965
+				foreach ($groups as $k => $v) {
966
+									$groups[$k] = (int) $v;
967
+				}
907 968
 
908 969
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
909 970
 
910 971
 				// We don't use "-utf8" anymore...
911 972
 				$user_language = str_ireplace('-utf8', '', $user_language);
973
+			} else {
974
+							$upcontext['username_incorrect'] = true;
912 975
 			}
913
-			else
914
-				$upcontext['username_incorrect'] = true;
915 976
 			$smcFunc['db_free_result']($request);
916 977
 		}
917 978
 		$upcontext['username'] = $_POST['user'];
@@ -921,13 +982,14 @@  discard block
 block discarded – undo
921 982
 		{
922 983
 			$upcontext['upgrade_status']['js'] = 1;
923 984
 			$support_js = 1;
985
+		} else {
986
+					$support_js = 0;
924 987
 		}
925
-		else
926
-			$support_js = 0;
927 988
 
928 989
 		// Note down the version we are coming from.
929
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
930
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
990
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
991
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
992
+		}
931 993
 
932 994
 		// Didn't get anywhere?
933 995
 		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']))
@@ -961,15 +1023,15 @@  discard block
 block discarded – undo
961 1023
 							'db_error_skip' => true,
962 1024
 						)
963 1025
 					);
964
-					if ($smcFunc['db_num_rows']($request) == 0)
965
-						return throw_error('You need to be an admin to perform an upgrade!');
1026
+					if ($smcFunc['db_num_rows']($request) == 0) {
1027
+											return throw_error('You need to be an admin to perform an upgrade!');
1028
+					}
966 1029
 					$smcFunc['db_free_result']($request);
967 1030
 				}
968 1031
 
969 1032
 				$upcontext['user']['id'] = $id_member;
970 1033
 				$upcontext['user']['name'] = $name;
971
-			}
972
-			else
1034
+			} else
973 1035
 			{
974 1036
 				$upcontext['user']['id'] = 1;
975 1037
 				$upcontext['user']['name'] = 'Administrator';
@@ -985,11 +1047,11 @@  discard block
 block discarded – undo
985 1047
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
986 1048
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
987 1049
 
988
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
989
-					$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'] . '.';
990
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
991
-					$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'] . '.';
992
-				else
1050
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
1051
+									$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'] . '.';
1052
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
1053
+									$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'] . '.';
1054
+				} else
993 1055
 				{
994 1056
 					// Set this as the new language.
995 1057
 					$upcontext['language'] = $user_language;
@@ -1033,8 +1095,9 @@  discard block
 block discarded – undo
1033 1095
 	unset($member_columns);
1034 1096
 
1035 1097
 	// If we've not submitted then we're done.
1036
-	if (empty($_POST['upcont']))
1037
-		return false;
1098
+	if (empty($_POST['upcont'])) {
1099
+			return false;
1100
+	}
1038 1101
 
1039 1102
 	// Firstly, if they're enabling SM stat collection just do it.
1040 1103
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -1054,16 +1117,17 @@  discard block
 block discarded – undo
1054 1117
 				fwrite($fp, $out);
1055 1118
 
1056 1119
 				$return_data = '';
1057
-				while (!feof($fp))
1058
-					$return_data .= fgets($fp, 128);
1120
+				while (!feof($fp)) {
1121
+									$return_data .= fgets($fp, 128);
1122
+				}
1059 1123
 
1060 1124
 				fclose($fp);
1061 1125
 
1062 1126
 				// Get the unique site ID.
1063 1127
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1064 1128
 
1065
-				if (!empty($ID[1]))
1066
-					$smcFunc['db_insert']('replace',
1129
+				if (!empty($ID[1])) {
1130
+									$smcFunc['db_insert']('replace',
1067 1131
 						$db_prefix . 'settings',
1068 1132
 						array('variable' => 'string', 'value' => 'string'),
1069 1133
 						array(
@@ -1072,9 +1136,9 @@  discard block
 block discarded – undo
1072 1136
 						),
1073 1137
 						array('variable')
1074 1138
 					);
1139
+				}
1075 1140
 			}
1076
-		}
1077
-		else
1141
+		} else
1078 1142
 		{
1079 1143
 			$smcFunc['db_insert']('replace',
1080 1144
 				$db_prefix . 'settings',
@@ -1085,8 +1149,8 @@  discard block
 block discarded – undo
1085 1149
 		}
1086 1150
 	}
1087 1151
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1088
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1089
-		$smcFunc['db_query']('', '
1152
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1153
+			$smcFunc['db_query']('', '
1090 1154
 			DELETE FROM {db_prefix}settings
1091 1155
 			WHERE variable = {string:enable_sm_stats}',
1092 1156
 			array(
@@ -1094,6 +1158,7 @@  discard block
 block discarded – undo
1094 1158
 				'db_error_skip' => true,
1095 1159
 			)
1096 1160
 		);
1161
+	}
1097 1162
 
1098 1163
 	// Deleting old karma stuff?
1099 1164
 	if (!empty($_POST['delete_karma']))
@@ -1108,20 +1173,22 @@  discard block
 block discarded – undo
1108 1173
 		);
1109 1174
 
1110 1175
 		// Cleaning up old karma member settings.
1111
-		if ($upcontext['karma_installed']['good'])
1112
-			$smcFunc['db_query']('', '
1176
+		if ($upcontext['karma_installed']['good']) {
1177
+					$smcFunc['db_query']('', '
1113 1178
 				ALTER TABLE {db_prefix}members
1114 1179
 				DROP karma_good',
1115 1180
 				array()
1116 1181
 			);
1182
+		}
1117 1183
 
1118 1184
 		// Does karma bad was enable?
1119
-		if ($upcontext['karma_installed']['bad'])
1120
-			$smcFunc['db_query']('', '
1185
+		if ($upcontext['karma_installed']['bad']) {
1186
+					$smcFunc['db_query']('', '
1121 1187
 				ALTER TABLE {db_prefix}members
1122 1188
 				DROP karma_bad',
1123 1189
 				array()
1124 1190
 			);
1191
+		}
1125 1192
 
1126 1193
 		// Cleaning up old karma permissions.
1127 1194
 		$smcFunc['db_query']('', '
@@ -1139,32 +1206,37 @@  discard block
 block discarded – undo
1139 1206
 	}
1140 1207
 
1141 1208
 	// Emptying the error log?
1142
-	if (!empty($_POST['empty_error']))
1143
-		$smcFunc['db_query']('truncate_table', '
1209
+	if (!empty($_POST['empty_error'])) {
1210
+			$smcFunc['db_query']('truncate_table', '
1144 1211
 			TRUNCATE {db_prefix}log_errors',
1145 1212
 			array(
1146 1213
 			)
1147 1214
 		);
1215
+	}
1148 1216
 
1149 1217
 	$changes = array();
1150 1218
 
1151 1219
 	// Add proxy settings.
1152
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1153
-		$changes += array(
1220
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1221
+			$changes += array(
1154 1222
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1155 1223
 			'image_proxy_maxsize' => 5190,
1156 1224
 			'image_proxy_enabled' => 0,
1157 1225
 		);
1226
+	}
1158 1227
 
1159 1228
 	// If $boardurl reflects https, set force_ssl
1160
-	if (!function_exists('cache_put_data'))
1161
-		require_once($sourcedir . '/Load.php');
1162
-	if (stripos($boardurl, 'https://') !== false)
1163
-		updateSettings(array('force_ssl' => '1'));
1229
+	if (!function_exists('cache_put_data')) {
1230
+			require_once($sourcedir . '/Load.php');
1231
+	}
1232
+	if (stripos($boardurl, 'https://') !== false) {
1233
+			updateSettings(array('force_ssl' => '1'));
1234
+	}
1164 1235
 
1165 1236
 	// If we're overriding the language follow it through.
1166
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1167
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1237
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1238
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1239
+	}
1168 1240
 
1169 1241
 	if (!empty($_POST['maint']))
1170 1242
 	{
@@ -1176,26 +1248,29 @@  discard block
 block discarded – undo
1176 1248
 		{
1177 1249
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1178 1250
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1179
-		}
1180
-		else
1251
+		} else
1181 1252
 		{
1182 1253
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1183 1254
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1184 1255
 		}
1185 1256
 	}
1186 1257
 
1187
-	if ($command_line)
1188
-		echo ' * Updating Settings.php...';
1258
+	if ($command_line) {
1259
+			echo ' * Updating Settings.php...';
1260
+	}
1189 1261
 
1190 1262
 	// Fix some old paths.
1191
-	if (substr($boarddir, 0, 1) == '.')
1192
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1263
+	if (substr($boarddir, 0, 1) == '.') {
1264
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1265
+	}
1193 1266
 
1194
-	if (substr($sourcedir, 0, 1) == '.')
1195
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1267
+	if (substr($sourcedir, 0, 1) == '.') {
1268
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1269
+	}
1196 1270
 
1197
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1198
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1271
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1272
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1273
+	}
1199 1274
 
1200 1275
 	// If they have a "host:port" setup for the host, split that into separate values
1201 1276
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1206,32 +1281,36 @@  discard block
 block discarded – undo
1206 1281
 		$changes['db_server'] = '\'' . $db_server . '\'';
1207 1282
 
1208 1283
 		// Only set this if we're not using the default port
1209
-		if ($db_port != ini_get('mysqli.default_port'))
1210
-			$changes['db_port'] = (int) $db_port;
1211
-	}
1212
-	elseif (!empty($db_port))
1284
+		if ($db_port != ini_get('mysqli.default_port')) {
1285
+					$changes['db_port'] = (int) $db_port;
1286
+		}
1287
+	} elseif (!empty($db_port))
1213 1288
 	{
1214 1289
 		// If db_port is set and is the same as the default, set it to ''
1215 1290
 		if ($db_type == 'mysql')
1216 1291
 		{
1217
-			if ($db_port == ini_get('mysqli.default_port'))
1218
-				$changes['db_port'] = '\'\'';
1219
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1220
-				$changes['db_port'] = '\'\'';
1292
+			if ($db_port == ini_get('mysqli.default_port')) {
1293
+							$changes['db_port'] = '\'\'';
1294
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1295
+							$changes['db_port'] = '\'\'';
1296
+			}
1221 1297
 		}
1222 1298
 	}
1223 1299
 
1224 1300
 	// Maybe we haven't had this option yet?
1225
-	if (empty($packagesdir))
1226
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1301
+	if (empty($packagesdir)) {
1302
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1303
+	}
1227 1304
 
1228 1305
 	// Add support for $tasksdir var.
1229
-	if (empty($tasksdir))
1230
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1306
+	if (empty($tasksdir)) {
1307
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1308
+	}
1231 1309
 
1232 1310
 	// Make sure we fix the language as well.
1233
-	if (stristr($language, '-utf8'))
1234
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1311
+	if (stristr($language, '-utf8')) {
1312
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1313
+	}
1235 1314
 
1236 1315
 	// @todo Maybe change the cookie name if going to 1.1, too?
1237 1316
 
@@ -1242,8 +1321,9 @@  discard block
 block discarded – undo
1242 1321
 	// Tell Settings.php to store db_last_error.php in the cache
1243 1322
 	move_db_last_error_to_cachedir();
1244 1323
 
1245
-	if ($command_line)
1246
-		echo ' Successful.' . "\n";
1324
+	if ($command_line) {
1325
+			echo ' Successful.' . "\n";
1326
+	}
1247 1327
 
1248 1328
 	// Are we doing debug?
1249 1329
 	if (isset($_POST['debug']))
@@ -1253,8 +1333,9 @@  discard block
 block discarded – undo
1253 1333
 	}
1254 1334
 
1255 1335
 	// If we're not backing up then jump one.
1256
-	if (empty($_POST['backup']))
1257
-		$upcontext['current_step']++;
1336
+	if (empty($_POST['backup'])) {
1337
+			$upcontext['current_step']++;
1338
+	}
1258 1339
 
1259 1340
 	// If we've got here then let's proceed to the next step!
1260 1341
 	return true;
@@ -1269,8 +1350,9 @@  discard block
 block discarded – undo
1269 1350
 	$upcontext['page_title'] = $txt['backup_database'];
1270 1351
 
1271 1352
 	// Done it already - js wise?
1272
-	if (!empty($_POST['backup_done']))
1273
-		return true;
1353
+	if (!empty($_POST['backup_done'])) {
1354
+			return true;
1355
+	}
1274 1356
 
1275 1357
 	// Some useful stuff here.
1276 1358
 	db_extend();
@@ -1284,9 +1366,10 @@  discard block
 block discarded – undo
1284 1366
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1285 1367
 
1286 1368
 	$table_names = array();
1287
-	foreach ($tables as $table)
1288
-		if (substr($table, 0, 7) !== 'backup_')
1369
+	foreach ($tables as $table) {
1370
+			if (substr($table, 0, 7) !== 'backup_')
1289 1371
 			$table_names[] = $table;
1372
+	}
1290 1373
 
1291 1374
 	$upcontext['table_count'] = count($table_names);
1292 1375
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1296,12 +1379,14 @@  discard block
 block discarded – undo
1296 1379
 	$file_steps = $upcontext['table_count'];
1297 1380
 
1298 1381
 	// What ones have we already done?
1299
-	foreach ($table_names as $id => $table)
1300
-		if ($id < $_GET['substep'])
1382
+	foreach ($table_names as $id => $table) {
1383
+			if ($id < $_GET['substep'])
1301 1384
 			$upcontext['previous_tables'][] = $table;
1385
+	}
1302 1386
 
1303
-	if ($command_line)
1304
-		echo 'Backing Up Tables.';
1387
+	if ($command_line) {
1388
+			echo 'Backing Up Tables.';
1389
+	}
1305 1390
 
1306 1391
 	// If we don't support javascript we backup here.
1307 1392
 	if (!$support_js || isset($_GET['xml']))
@@ -1320,8 +1405,9 @@  discard block
 block discarded – undo
1320 1405
 			backupTable($table_names[$substep]);
1321 1406
 
1322 1407
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1323
-			if (isset($_GET['xml']))
1324
-				return upgradeExit();
1408
+			if (isset($_GET['xml'])) {
1409
+							return upgradeExit();
1410
+			}
1325 1411
 		}
1326 1412
 
1327 1413
 		if ($command_line)
@@ -1354,9 +1440,10 @@  discard block
 block discarded – undo
1354 1440
 
1355 1441
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1356 1442
 
1357
-	if ($command_line)
1358
-		echo ' done.';
1359
-}
1443
+	if ($command_line) {
1444
+			echo ' done.';
1445
+	}
1446
+	}
1360 1447
 
1361 1448
 // Step 2: Everything.
1362 1449
 function DatabaseChanges()
@@ -1365,8 +1452,9 @@  discard block
 block discarded – undo
1365 1452
 	global $upcontext, $support_js, $db_type;
1366 1453
 
1367 1454
 	// Have we just completed this?
1368
-	if (!empty($_POST['database_done']))
1369
-		return true;
1455
+	if (!empty($_POST['database_done'])) {
1456
+			return true;
1457
+	}
1370 1458
 
1371 1459
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1372 1460
 	$upcontext['page_title'] = $txt['database_changes'];
@@ -1381,15 +1469,16 @@  discard block
 block discarded – undo
1381 1469
 	);
1382 1470
 
1383 1471
 	// How many files are there in total?
1384
-	if (isset($_GET['filecount']))
1385
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1386
-	else
1472
+	if (isset($_GET['filecount'])) {
1473
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1474
+	} else
1387 1475
 	{
1388 1476
 		$upcontext['file_count'] = 0;
1389 1477
 		foreach ($files as $file)
1390 1478
 		{
1391
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1392
-				$upcontext['file_count']++;
1479
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1480
+							$upcontext['file_count']++;
1481
+			}
1393 1482
 		}
1394 1483
 	}
1395 1484
 
@@ -1399,9 +1488,9 @@  discard block
 block discarded – undo
1399 1488
 	$upcontext['cur_file_num'] = 0;
1400 1489
 	foreach ($files as $file)
1401 1490
 	{
1402
-		if ($did_not_do)
1403
-			$did_not_do--;
1404
-		else
1491
+		if ($did_not_do) {
1492
+					$did_not_do--;
1493
+		} else
1405 1494
 		{
1406 1495
 			$upcontext['cur_file_num']++;
1407 1496
 			$upcontext['cur_file_name'] = $file[0];
@@ -1428,12 +1517,13 @@  discard block
 block discarded – undo
1428 1517
 					// Flag to move on to the next.
1429 1518
 					$upcontext['completed_step'] = true;
1430 1519
 					// Did we complete the whole file?
1431
-					if ($nextFile)
1432
-						$upcontext['current_debug_item_num'] = -1;
1520
+					if ($nextFile) {
1521
+											$upcontext['current_debug_item_num'] = -1;
1522
+					}
1433 1523
 					return upgradeExit();
1524
+				} elseif ($support_js) {
1525
+									break;
1434 1526
 				}
1435
-				elseif ($support_js)
1436
-					break;
1437 1527
 			}
1438 1528
 			// Set the progress bar to be right as if we had - even if we hadn't...
1439 1529
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1459,8 +1549,9 @@  discard block
 block discarded – undo
1459 1549
 	global $user_info, $maintenance, $smcFunc, $db_type, $txt;
1460 1550
 
1461 1551
 	// Now it's nice to have some of the basic SMF source files.
1462
-	if (!isset($_GET['ssi']) && !$command_line)
1463
-		redirectLocation('&ssi=1');
1552
+	if (!isset($_GET['ssi']) && !$command_line) {
1553
+			redirectLocation('&ssi=1');
1554
+	}
1464 1555
 
1465 1556
 	$upcontext['sub_template'] = 'upgrade_complete';
1466 1557
 	$upcontext['page_title'] = $txt['upgrade_complete'];
@@ -1476,14 +1567,16 @@  discard block
 block discarded – undo
1476 1567
 	// Are we in maintenance mode?
1477 1568
 	if (isset($upcontext['user']['main']))
1478 1569
 	{
1479
-		if ($command_line)
1480
-			echo ' * ';
1570
+		if ($command_line) {
1571
+					echo ' * ';
1572
+		}
1481 1573
 		$upcontext['removed_maintenance'] = true;
1482 1574
 		$changes['maintenance'] = $upcontext['user']['main'];
1483 1575
 	}
1484 1576
 	// Otherwise if somehow we are in 2 let's go to 1.
1485
-	elseif (!empty($maintenance) && $maintenance == 2)
1486
-		$changes['maintenance'] = 1;
1577
+	elseif (!empty($maintenance) && $maintenance == 2) {
1578
+			$changes['maintenance'] = 1;
1579
+	}
1487 1580
 
1488 1581
 	// Wipe this out...
1489 1582
 	$upcontext['user'] = array();
@@ -1498,9 +1591,9 @@  discard block
 block discarded – undo
1498 1591
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1499 1592
 
1500 1593
 	// Now is the perfect time to fetch the SM files.
1501
-	if ($command_line)
1502
-		cli_scheduled_fetchSMfiles();
1503
-	else
1594
+	if ($command_line) {
1595
+			cli_scheduled_fetchSMfiles();
1596
+	} else
1504 1597
 	{
1505 1598
 		require_once($sourcedir . '/ScheduledTasks.php');
1506 1599
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1508,8 +1601,9 @@  discard block
 block discarded – undo
1508 1601
 	}
1509 1602
 
1510 1603
 	// Log what we've done.
1511
-	if (empty($user_info['id']))
1512
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1604
+	if (empty($user_info['id'])) {
1605
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1606
+	}
1513 1607
 
1514 1608
 	// Log the action manually, so CLI still works.
1515 1609
 	$smcFunc['db_insert']('',
@@ -1528,8 +1622,9 @@  discard block
 block discarded – undo
1528 1622
 
1529 1623
 	// Save the current database version.
1530 1624
 	$server_version = $smcFunc['db_server_info']();
1531
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1532
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1625
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1626
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1627
+	}
1533 1628
 
1534 1629
 	if ($command_line)
1535 1630
 	{
@@ -1541,8 +1636,9 @@  discard block
 block discarded – undo
1541 1636
 
1542 1637
 	// Make sure it says we're done.
1543 1638
 	$upcontext['overall_percent'] = 100;
1544
-	if (isset($upcontext['step_progress']))
1545
-		unset($upcontext['step_progress']);
1639
+	if (isset($upcontext['step_progress'])) {
1640
+			unset($upcontext['step_progress']);
1641
+	}
1546 1642
 
1547 1643
 	$_GET['substep'] = 0;
1548 1644
 	return false;
@@ -1553,8 +1649,9 @@  discard block
 block discarded – undo
1553 1649
 {
1554 1650
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1555 1651
 
1556
-	if (empty($modSettings['time_format']))
1557
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1652
+	if (empty($modSettings['time_format'])) {
1653
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1654
+	}
1558 1655
 
1559 1656
 	// What files do we want to get
1560 1657
 	$request = $smcFunc['db_query']('', '
@@ -1588,8 +1685,9 @@  discard block
 block discarded – undo
1588 1685
 		$file_data = fetch_web_data($url);
1589 1686
 
1590 1687
 		// If we got an error - give up - the site might be down.
1591
-		if ($file_data === false)
1592
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1688
+		if ($file_data === false) {
1689
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1690
+		}
1593 1691
 
1594 1692
 		// Save the file to the database.
1595 1693
 		$smcFunc['db_query']('substring', '
@@ -1631,8 +1729,9 @@  discard block
 block discarded – undo
1631 1729
 	$themeData = array();
1632 1730
 	foreach ($values as $variable => $value)
1633 1731
 	{
1634
-		if (!isset($value) || $value === null)
1635
-			$value = 0;
1732
+		if (!isset($value) || $value === null) {
1733
+					$value = 0;
1734
+		}
1636 1735
 
1637 1736
 		$themeData[] = array(0, 1, $variable, $value);
1638 1737
 	}
@@ -1661,8 +1760,9 @@  discard block
 block discarded – undo
1661 1760
 
1662 1761
 	foreach ($values as $variable => $value)
1663 1762
 	{
1664
-		if (empty($modSettings[$value[0]]))
1665
-			continue;
1763
+		if (empty($modSettings[$value[0]])) {
1764
+					continue;
1765
+		}
1666 1766
 
1667 1767
 		$smcFunc['db_query']('', '
1668 1768
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1748,19 +1848,21 @@  discard block
 block discarded – undo
1748 1848
 	set_error_handler(
1749 1849
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1750 1850
 		{
1751
-			if ($support_js)
1752
-				return true;
1753
-			else
1754
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1851
+			if ($support_js) {
1852
+							return true;
1853
+			} else {
1854
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1855
+			}
1755 1856
 		}
1756 1857
 	);
1757 1858
 
1758 1859
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1759 1860
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1760
-	if ($db_type == 'mysql')
1761
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1762
-	else
1763
-		$db_collation = '';
1861
+	if ($db_type == 'mysql') {
1862
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1863
+	} else {
1864
+			$db_collation = '';
1865
+	}
1764 1866
 
1765 1867
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1766 1868
 
@@ -1772,8 +1874,9 @@  discard block
 block discarded – undo
1772 1874
 	$last_step = '';
1773 1875
 
1774 1876
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1775
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1776
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1877
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1878
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1879
+	}
1777 1880
 
1778 1881
 	// Count the total number of steps within this file - for progress.
1779 1882
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1793,15 +1896,18 @@  discard block
 block discarded – undo
1793 1896
 		$do_current = $substep >= $_GET['substep'];
1794 1897
 
1795 1898
 		// Get rid of any comments in the beginning of the line...
1796
-		if (substr(trim($line), 0, 2) === '/*')
1797
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1899
+		if (substr(trim($line), 0, 2) === '/*') {
1900
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1901
+		}
1798 1902
 
1799 1903
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1800
-		if ($is_debug && !$support_js && $command_line)
1801
-			flush();
1904
+		if ($is_debug && !$support_js && $command_line) {
1905
+					flush();
1906
+		}
1802 1907
 
1803
-		if (trim($line) === '')
1804
-			continue;
1908
+		if (trim($line) === '') {
1909
+					continue;
1910
+		}
1805 1911
 
1806 1912
 		if (trim(substr($line, 0, 3)) === '---')
1807 1913
 		{
@@ -1811,8 +1917,9 @@  discard block
 block discarded – undo
1811 1917
 			if (trim($current_data) != '' && $type !== '}')
1812 1918
 			{
1813 1919
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1814
-				if ($command_line)
1815
-					echo $upcontext['error_message'];
1920
+				if ($command_line) {
1921
+									echo $upcontext['error_message'];
1922
+				}
1816 1923
 			}
1817 1924
 
1818 1925
 			if ($type == ' ')
@@ -1830,17 +1937,18 @@  discard block
 block discarded – undo
1830 1937
 				if ($do_current)
1831 1938
 				{
1832 1939
 					$upcontext['actioned_items'][] = $last_step;
1833
-					if ($command_line)
1834
-						echo ' * ';
1940
+					if ($command_line) {
1941
+											echo ' * ';
1942
+					}
1835 1943
 				}
1836
-			}
1837
-			elseif ($type == '#')
1944
+			} elseif ($type == '#')
1838 1945
 			{
1839 1946
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1840 1947
 
1841 1948
 				$upcontext['current_debug_item_num']++;
1842
-				if (trim($line) != '---#')
1843
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1949
+				if (trim($line) != '---#') {
1950
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1951
+				}
1844 1952
 
1845 1953
 				// Have we already done something?
1846 1954
 				if (isset($_GET['xml']) && $done_something)
@@ -1851,34 +1959,36 @@  discard block
 block discarded – undo
1851 1959
 
1852 1960
 				if ($do_current)
1853 1961
 				{
1854
-					if (trim($line) == '---#' && $command_line)
1855
-						echo ' done.', $endl;
1856
-					elseif ($command_line)
1857
-						echo ' +++ ', rtrim(substr($line, 4));
1858
-					elseif (trim($line) != '---#')
1962
+					if (trim($line) == '---#' && $command_line) {
1963
+											echo ' done.', $endl;
1964
+					} elseif ($command_line) {
1965
+											echo ' +++ ', rtrim(substr($line, 4));
1966
+					} elseif (trim($line) != '---#')
1859 1967
 					{
1860
-						if ($is_debug)
1861
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1968
+						if ($is_debug) {
1969
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1970
+						}
1862 1971
 					}
1863 1972
 				}
1864 1973
 
1865 1974
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1866 1975
 				{
1867
-					if ($command_line)
1868
-						echo ' * ';
1869
-					else
1870
-						$upcontext['actioned_items'][] = $last_step;
1976
+					if ($command_line) {
1977
+											echo ' * ';
1978
+					} else {
1979
+											$upcontext['actioned_items'][] = $last_step;
1980
+					}
1871 1981
 				}
1872 1982
 
1873 1983
 				// Small step - only if we're actually doing stuff.
1874
-				if ($do_current)
1875
-					nextSubstep(++$substep);
1876
-				else
1877
-					$substep++;
1878
-			}
1879
-			elseif ($type == '{')
1880
-				$current_type = 'code';
1881
-			elseif ($type == '}')
1984
+				if ($do_current) {
1985
+									nextSubstep(++$substep);
1986
+				} else {
1987
+									$substep++;
1988
+				}
1989
+			} elseif ($type == '{') {
1990
+							$current_type = 'code';
1991
+			} elseif ($type == '}')
1882 1992
 			{
1883 1993
 				$current_type = 'sql';
1884 1994
 
@@ -1891,8 +2001,9 @@  discard block
 block discarded – undo
1891 2001
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1892 2002
 				{
1893 2003
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1894
-					if ($command_line)
1895
-						echo $upcontext['error_message'];
2004
+					if ($command_line) {
2005
+											echo $upcontext['error_message'];
2006
+					}
1896 2007
 				}
1897 2008
 
1898 2009
 				// Done with code!
@@ -1972,8 +2083,9 @@  discard block
 block discarded – undo
1972 2083
 	$db_unbuffered = false;
1973 2084
 
1974 2085
 	// Failure?!
1975
-	if ($result !== false)
1976
-		return $result;
2086
+	if ($result !== false) {
2087
+			return $result;
2088
+	}
1977 2089
 
1978 2090
 	$db_error_message = $smcFunc['db_error']($db_connection);
1979 2091
 	// If MySQL we do something more clever.
@@ -2001,54 +2113,61 @@  discard block
 block discarded – undo
2001 2113
 			{
2002 2114
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
2003 2115
 				$result = mysqli_query($db_connection, $string);
2004
-				if ($result !== false)
2005
-					return $result;
2116
+				if ($result !== false) {
2117
+									return $result;
2118
+				}
2006 2119
 			}
2007
-		}
2008
-		elseif ($mysqli_errno == 2013)
2120
+		} elseif ($mysqli_errno == 2013)
2009 2121
 		{
2010 2122
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
2011 2123
 			mysqli_select_db($db_connection, $db_name);
2012 2124
 			if ($db_connection)
2013 2125
 			{
2014 2126
 				$result = mysqli_query($db_connection, $string);
2015
-				if ($result !== false)
2016
-					return $result;
2127
+				if ($result !== false) {
2128
+									return $result;
2129
+				}
2017 2130
 			}
2018 2131
 		}
2019 2132
 		// Duplicate column name... should be okay ;).
2020
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
2021
-			return false;
2133
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2134
+					return false;
2135
+		}
2022 2136
 		// Duplicate insert... make sure it's the proper type of query ;).
2023
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
2024
-			return false;
2137
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2138
+					return false;
2139
+		}
2025 2140
 		// Creating an index on a non-existent column.
2026
-		elseif ($mysqli_errno == 1072)
2027
-			return false;
2028
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
2029
-			return false;
2141
+		elseif ($mysqli_errno == 1072) {
2142
+					return false;
2143
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2144
+					return false;
2145
+		}
2030 2146
 	}
2031 2147
 	// If a table already exists don't go potty.
2032 2148
 	else
2033 2149
 	{
2034 2150
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
2035 2151
 		{
2036
-			if (strpos($db_error_message, 'exist') !== false)
2037
-				return true;
2038
-		}
2039
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2152
+			if (strpos($db_error_message, 'exist') !== false) {
2153
+							return true;
2154
+			}
2155
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
2040 2156
 		{
2041
-			if (strpos($db_error_message, 'duplicate') !== false)
2042
-				return true;
2157
+			if (strpos($db_error_message, 'duplicate') !== false) {
2158
+							return true;
2159
+			}
2043 2160
 		}
2044 2161
 	}
2045 2162
 
2046 2163
 	// Get the query string so we pass everything.
2047 2164
 	$query_string = '';
2048
-	foreach ($_GET as $k => $v)
2049
-		$query_string .= ';' . $k . '=' . $v;
2050
-	if (strlen($query_string) != 0)
2051
-		$query_string = '?' . substr($query_string, 1);
2165
+	foreach ($_GET as $k => $v) {
2166
+			$query_string .= ';' . $k . '=' . $v;
2167
+	}
2168
+	if (strlen($query_string) != 0) {
2169
+			$query_string = '?' . substr($query_string, 1);
2170
+	}
2052 2171
 
2053 2172
 	if ($command_line)
2054 2173
 	{
@@ -2103,16 +2222,18 @@  discard block
 block discarded – undo
2103 2222
 			{
2104 2223
 				$found |= 1;
2105 2224
 				// Do some checks on the data if we have it set.
2106
-				if (isset($change['col_type']))
2107
-					$found &= $change['col_type'] === $column['type'];
2108
-				if (isset($change['null_allowed']))
2109
-					$found &= $column['null'] == $change['null_allowed'];
2110
-				if (isset($change['default']))
2111
-					$found &= $change['default'] === $column['default'];
2225
+				if (isset($change['col_type'])) {
2226
+									$found &= $change['col_type'] === $column['type'];
2227
+				}
2228
+				if (isset($change['null_allowed'])) {
2229
+									$found &= $column['null'] == $change['null_allowed'];
2230
+				}
2231
+				if (isset($change['default'])) {
2232
+									$found &= $change['default'] === $column['default'];
2233
+				}
2112 2234
 			}
2113 2235
 		}
2114
-	}
2115
-	elseif ($change['type'] === 'index')
2236
+	} elseif ($change['type'] === 'index')
2116 2237
 	{
2117 2238
 		$request = upgrade_query('
2118 2239
 			SHOW INDEX
@@ -2121,9 +2242,10 @@  discard block
 block discarded – undo
2121 2242
 		{
2122 2243
 			$cur_index = array();
2123 2244
 
2124
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2125
-				if ($row['Key_name'] === $change['name'])
2245
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2246
+							if ($row['Key_name'] === $change['name'])
2126 2247
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2248
+			}
2127 2249
 
2128 2250
 			ksort($cur_index, SORT_NUMERIC);
2129 2251
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2133,14 +2255,17 @@  discard block
 block discarded – undo
2133 2255
 	}
2134 2256
 
2135 2257
 	// If we're trying to add and it's added, we're done.
2136
-	if ($found && in_array($change['method'], array('add', 'change')))
2137
-		return true;
2258
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2259
+			return true;
2260
+	}
2138 2261
 	// Otherwise if we're removing and it wasn't found we're also done.
2139
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2140
-		return true;
2262
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2263
+			return true;
2264
+	}
2141 2265
 	// Otherwise is it just a test?
2142
-	elseif ($is_test)
2143
-		return false;
2266
+	elseif ($is_test) {
2267
+			return false;
2268
+	}
2144 2269
 
2145 2270
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2146 2271
 	$running = false;
@@ -2151,8 +2276,9 @@  discard block
 block discarded – undo
2151 2276
 			SHOW FULL PROCESSLIST');
2152 2277
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2153 2278
 		{
2154
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2155
-				$found = true;
2279
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2280
+							$found = true;
2281
+			}
2156 2282
 		}
2157 2283
 
2158 2284
 		// Can't find it? Then we need to run it fools!
@@ -2164,8 +2290,9 @@  discard block
 block discarded – undo
2164 2290
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2165 2291
 				' . $change['text'], true) !== false;
2166 2292
 
2167
-			if (!$success)
2168
-				return false;
2293
+			if (!$success) {
2294
+							return false;
2295
+			}
2169 2296
 
2170 2297
 			// Return
2171 2298
 			$running = true;
@@ -2207,8 +2334,9 @@  discard block
 block discarded – undo
2207 2334
 			'db_error_skip' => true,
2208 2335
 		)
2209 2336
 	);
2210
-	if ($smcFunc['db_num_rows']($request) === 0)
2211
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2337
+	if ($smcFunc['db_num_rows']($request) === 0) {
2338
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2339
+	}
2212 2340
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2213 2341
 	$smcFunc['db_free_result']($request);
2214 2342
 
@@ -2230,18 +2358,19 @@  discard block
 block discarded – undo
2230 2358
 			)
2231 2359
 		);
2232 2360
 		// No results? Just forget it all together.
2233
-		if ($smcFunc['db_num_rows']($request) === 0)
2234
-			unset($table_row['Collation']);
2235
-		else
2236
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2361
+		if ($smcFunc['db_num_rows']($request) === 0) {
2362
+					unset($table_row['Collation']);
2363
+		} else {
2364
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2365
+		}
2237 2366
 		$smcFunc['db_free_result']($request);
2238 2367
 	}
2239 2368
 
2240 2369
 	if ($column_fix)
2241 2370
 	{
2242 2371
 		// Make sure there are no NULL's left.
2243
-		if ($null_fix)
2244
-			$smcFunc['db_query']('', '
2372
+		if ($null_fix) {
2373
+					$smcFunc['db_query']('', '
2245 2374
 				UPDATE {db_prefix}' . $change['table'] . '
2246 2375
 				SET ' . $change['column'] . ' = {string:default}
2247 2376
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2250,6 +2379,7 @@  discard block
 block discarded – undo
2250 2379
 					'db_error_skip' => true,
2251 2380
 				)
2252 2381
 			);
2382
+		}
2253 2383
 
2254 2384
 		// Do the actual alteration.
2255 2385
 		$smcFunc['db_query']('', '
@@ -2278,8 +2408,9 @@  discard block
 block discarded – undo
2278 2408
 	}
2279 2409
 
2280 2410
 	// Not a column we need to check on?
2281
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2282
-		return;
2411
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2412
+			return;
2413
+	}
2283 2414
 
2284 2415
 	// Break it up you (six|seven).
2285 2416
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2298,13 +2429,13 @@  discard block
 block discarded – undo
2298 2429
 				'new_name' => $temp[2],
2299 2430
 		));
2300 2431
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2301
-		if ($smcFunc['db_num_rows'] != 1)
2302
-			return;
2432
+		if ($smcFunc['db_num_rows'] != 1) {
2433
+					return;
2434
+		}
2303 2435
 
2304 2436
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2305 2437
 		$smcFunc['db_free_result']($request);
2306
-	}
2307
-	else
2438
+	} else
2308 2439
 	{
2309 2440
 		// Do this the old fashion, sure method way.
2310 2441
 		$request = $smcFunc['db_query']('', '
@@ -2315,21 +2446,24 @@  discard block
 block discarded – undo
2315 2446
 		));
2316 2447
 		// Mayday!
2317 2448
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2318
-		if ($smcFunc['db_num_rows'] == 0)
2319
-			return;
2449
+		if ($smcFunc['db_num_rows'] == 0) {
2450
+					return;
2451
+		}
2320 2452
 
2321 2453
 		// Oh where, oh where has my little field gone. Oh where can it be...
2322
-		while ($row = $smcFunc['db_query']($request))
2323
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2454
+		while ($row = $smcFunc['db_query']($request)) {
2455
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2324 2456
 			{
2325 2457
 				$current_type = $row['Type'];
2458
+		}
2326 2459
 				break;
2327 2460
 			}
2328 2461
 	}
2329 2462
 
2330 2463
 	// If this doesn't match, the column may of been altered for a reason.
2331
-	if (trim($current_type) != trim($temp[3]))
2332
-		$temp[3] = $current_type;
2464
+	if (trim($current_type) != trim($temp[3])) {
2465
+			$temp[3] = $current_type;
2466
+	}
2333 2467
 
2334 2468
 	// Piece this back together.
2335 2469
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2341,8 +2475,9 @@  discard block
 block discarded – undo
2341 2475
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2342 2476
 	global $step_progress, $is_debug, $upcontext;
2343 2477
 
2344
-	if ($_GET['substep'] < $substep)
2345
-		$_GET['substep'] = $substep;
2478
+	if ($_GET['substep'] < $substep) {
2479
+			$_GET['substep'] = $substep;
2480
+	}
2346 2481
 
2347 2482
 	if ($command_line)
2348 2483
 	{
@@ -2355,29 +2490,33 @@  discard block
 block discarded – undo
2355 2490
 	}
2356 2491
 
2357 2492
 	@set_time_limit(300);
2358
-	if (function_exists('apache_reset_timeout'))
2359
-		@apache_reset_timeout();
2493
+	if (function_exists('apache_reset_timeout')) {
2494
+			@apache_reset_timeout();
2495
+	}
2360 2496
 
2361
-	if (time() - $start_time <= $timeLimitThreshold)
2362
-		return;
2497
+	if (time() - $start_time <= $timeLimitThreshold) {
2498
+			return;
2499
+	}
2363 2500
 
2364 2501
 	// Do we have some custom step progress stuff?
2365 2502
 	if (!empty($step_progress))
2366 2503
 	{
2367 2504
 		$upcontext['substep_progress'] = 0;
2368 2505
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2369
-		if ($step_progress['current'] > $step_progress['total'])
2370
-			$upcontext['substep_progress'] = 99.9;
2371
-		else
2372
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2506
+		if ($step_progress['current'] > $step_progress['total']) {
2507
+					$upcontext['substep_progress'] = 99.9;
2508
+		} else {
2509
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2510
+		}
2373 2511
 
2374 2512
 		// Make it nicely rounded.
2375 2513
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2376 2514
 	}
2377 2515
 
2378 2516
 	// If this is XML we just exit right away!
2379
-	if (isset($_GET['xml']))
2380
-		return upgradeExit();
2517
+	if (isset($_GET['xml'])) {
2518
+			return upgradeExit();
2519
+	}
2381 2520
 
2382 2521
 	// We're going to pause after this!
2383 2522
 	$upcontext['pause'] = true;
@@ -2385,13 +2524,15 @@  discard block
 block discarded – undo
2385 2524
 	$upcontext['query_string'] = '';
2386 2525
 	foreach ($_GET as $k => $v)
2387 2526
 	{
2388
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2389
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2527
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2528
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2529
+		}
2390 2530
 	}
2391 2531
 
2392 2532
 	// Custom warning?
2393
-	if (!empty($custom_warning))
2394
-		$upcontext['custom_warning'] = $custom_warning;
2533
+	if (!empty($custom_warning)) {
2534
+			$upcontext['custom_warning'] = $custom_warning;
2535
+	}
2395 2536
 
2396 2537
 	upgradeExit();
2397 2538
 }
@@ -2406,25 +2547,26 @@  discard block
 block discarded – undo
2406 2547
 	ob_implicit_flush(true);
2407 2548
 	@set_time_limit(600);
2408 2549
 
2409
-	if (!isset($_SERVER['argv']))
2410
-		$_SERVER['argv'] = array();
2550
+	if (!isset($_SERVER['argv'])) {
2551
+			$_SERVER['argv'] = array();
2552
+	}
2411 2553
 	$_GET['maint'] = 1;
2412 2554
 
2413 2555
 	foreach ($_SERVER['argv'] as $i => $arg)
2414 2556
 	{
2415
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2416
-			$_GET['lang'] = $match[1];
2417
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2418
-			continue;
2419
-		elseif ($arg == '--no-maintenance')
2420
-			$_GET['maint'] = 0;
2421
-		elseif ($arg == '--debug')
2422
-			$is_debug = true;
2423
-		elseif ($arg == '--backup')
2424
-			$_POST['backup'] = 1;
2425
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2426
-			$_GET['conv'] = 1;
2427
-		elseif ($i != 0)
2557
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2558
+					$_GET['lang'] = $match[1];
2559
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2560
+					continue;
2561
+		} elseif ($arg == '--no-maintenance') {
2562
+					$_GET['maint'] = 0;
2563
+		} elseif ($arg == '--debug') {
2564
+					$is_debug = true;
2565
+		} elseif ($arg == '--backup') {
2566
+					$_POST['backup'] = 1;
2567
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2568
+					$_GET['conv'] = 1;
2569
+		} elseif ($i != 0)
2428 2570
 		{
2429 2571
 			echo 'SMF Command-line Upgrader
2430 2572
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2438,10 +2580,12 @@  discard block
 block discarded – undo
2438 2580
 		}
2439 2581
 	}
2440 2582
 
2441
-	if (!php_version_check())
2442
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2443
-	if (!db_version_check())
2444
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2583
+	if (!php_version_check()) {
2584
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2585
+	}
2586
+	if (!db_version_check()) {
2587
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2588
+	}
2445 2589
 
2446 2590
 	// Do some checks to make sure they have proper privileges
2447 2591
 	db_extend('packages');
@@ -2456,34 +2600,39 @@  discard block
 block discarded – undo
2456 2600
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2457 2601
 
2458 2602
 	// Sorry... we need CREATE, ALTER and DROP
2459
-	if (!$create || !$alter || !$drop)
2460
-		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);
2603
+	if (!$create || !$alter || !$drop) {
2604
+			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);
2605
+	}
2461 2606
 
2462 2607
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2463 2608
 		&& @file_exists($sourcedir . '/QueryString.php')
2464 2609
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2465
-	if (!$check && !isset($modSettings['smfVersion']))
2466
-		print_error('Error: Some files are missing or out-of-date.', true);
2610
+	if (!$check && !isset($modSettings['smfVersion'])) {
2611
+			print_error('Error: Some files are missing or out-of-date.', true);
2612
+	}
2467 2613
 
2468 2614
 	// Do a quick version spot check.
2469 2615
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2470 2616
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2471
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2472
-		print_error('Error: Some files have not yet been updated properly.');
2617
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2618
+			print_error('Error: Some files have not yet been updated properly.');
2619
+	}
2473 2620
 
2474 2621
 	// Make sure Settings.php is writable.
2475 2622
 	quickFileWritable($boarddir . '/Settings.php');
2476
-	if (!is_writable($boarddir . '/Settings.php'))
2477
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2623
+	if (!is_writable($boarddir . '/Settings.php')) {
2624
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2625
+	}
2478 2626
 
2479 2627
 	// Make sure Settings_bak.php is writable.
2480 2628
 	quickFileWritable($boarddir . '/Settings_bak.php');
2481
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2482
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2629
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2630
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2631
+	}
2483 2632
 
2484
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2485
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2486
-	elseif (isset($modSettings['agreement']))
2633
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2634
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2635
+	} elseif (isset($modSettings['agreement']))
2487 2636
 	{
2488 2637
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2489 2638
 		fwrite($fp, $modSettings['agreement']);
@@ -2493,36 +2642,42 @@  discard block
 block discarded – undo
2493 2642
 	// Make sure Themes is writable.
2494 2643
 	quickFileWritable($modSettings['theme_dir']);
2495 2644
 
2496
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2497
-		print_error('Error: Unable to obtain write access to "Themes".');
2645
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2646
+			print_error('Error: Unable to obtain write access to "Themes".');
2647
+	}
2498 2648
 
2499 2649
 	// Make sure cache directory exists and is writable!
2500 2650
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2501
-	if (!file_exists($cachedir_temp))
2502
-		@mkdir($cachedir_temp);
2651
+	if (!file_exists($cachedir_temp)) {
2652
+			@mkdir($cachedir_temp);
2653
+	}
2503 2654
 
2504 2655
 	// Make sure the cache temp dir is writable.
2505 2656
 	quickFileWritable($cachedir_temp);
2506 2657
 
2507
-	if (!is_writable($cachedir_temp))
2508
-		print_error('Error: Unable to obtain write access to "cache".', true);
2658
+	if (!is_writable($cachedir_temp)) {
2659
+			print_error('Error: Unable to obtain write access to "cache".', true);
2660
+	}
2509 2661
 
2510 2662
 	// Make sure db_last_error.php is writable.
2511 2663
 	quickFileWritable($cachedir_temp . '/db_last_error.php');
2512
-	if (!is_writable($cachedir_temp . '/db_last_error.php'))
2513
-		print_error('Error: Unable to obtain write access to "db_last_error.php".');
2664
+	if (!is_writable($cachedir_temp . '/db_last_error.php')) {
2665
+			print_error('Error: Unable to obtain write access to "db_last_error.php".');
2666
+	}
2514 2667
 
2515
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2516
-		print_error('Error: Unable to find language files!', true);
2517
-	else
2668
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2669
+			print_error('Error: Unable to find language files!', true);
2670
+	} else
2518 2671
 	{
2519 2672
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2520 2673
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2521 2674
 
2522
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2523
-			print_error('Error: Language files out of date.', true);
2524
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2525
-			print_error('Error: Install language is missing for selected language.', true);
2675
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2676
+					print_error('Error: Language files out of date.', true);
2677
+		}
2678
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2679
+					print_error('Error: Install language is missing for selected language.', true);
2680
+		}
2526 2681
 
2527 2682
 		// Otherwise include it!
2528 2683
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2542,8 +2697,9 @@  discard block
 block discarded – undo
2542 2697
 	global $db_prefix, $db_type, $command_line, $support_js, $txt;
2543 2698
 
2544 2699
 	// Done it already?
2545
-	if (!empty($_POST['utf8_done']))
2546
-		return true;
2700
+	if (!empty($_POST['utf8_done'])) {
2701
+			return true;
2702
+	}
2547 2703
 
2548 2704
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2549 2705
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2556,8 +2712,7 @@  discard block
 block discarded – undo
2556 2712
 		);
2557 2713
 
2558 2714
 		return true;
2559
-	}
2560
-	else
2715
+	} else
2561 2716
 	{
2562 2717
 		$upcontext['page_title'] = $txt['converting_utf8'];
2563 2718
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2601,8 +2756,9 @@  discard block
 block discarded – undo
2601 2756
 			)
2602 2757
 		);
2603 2758
 		$db_charsets = array();
2604
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2605
-			$db_charsets[] = $row['Charset'];
2759
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2760
+					$db_charsets[] = $row['Charset'];
2761
+		}
2606 2762
 
2607 2763
 		$smcFunc['db_free_result']($request);
2608 2764
 
@@ -2638,13 +2794,15 @@  discard block
 block discarded – undo
2638 2794
 		// If there's a fulltext index, we need to drop it first...
2639 2795
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2640 2796
 		{
2641
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2642
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2797
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2798
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2643 2799
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2800
+			}
2644 2801
 			$smcFunc['db_free_result']($request);
2645 2802
 
2646
-			if (isset($upcontext['fulltext_index']))
2647
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2803
+			if (isset($upcontext['fulltext_index'])) {
2804
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2805
+			}
2648 2806
 		}
2649 2807
 
2650 2808
 		// Drop it and make a note...
@@ -2834,8 +2992,9 @@  discard block
 block discarded – undo
2834 2992
 			$replace = '%field%';
2835 2993
 
2836 2994
 			// Build a huge REPLACE statement...
2837
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2838
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2995
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2996
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2997
+			}
2839 2998
 		}
2840 2999
 
2841 3000
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2845,9 +3004,10 @@  discard block
 block discarded – undo
2845 3004
 		$upcontext['table_count'] = count($queryTables);
2846 3005
 
2847 3006
 		// What ones have we already done?
2848
-		foreach ($queryTables as $id => $table)
2849
-			if ($id < $_GET['substep'])
3007
+		foreach ($queryTables as $id => $table) {
3008
+					if ($id < $_GET['substep'])
2850 3009
 				$upcontext['previous_tables'][] = $table;
3010
+		}
2851 3011
 
2852 3012
 		$upcontext['cur_table_num'] = $_GET['substep'];
2853 3013
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2884,8 +3044,9 @@  discard block
 block discarded – undo
2884 3044
 			nextSubstep($substep);
2885 3045
 
2886 3046
 			// Just to make sure it doesn't time out.
2887
-			if (function_exists('apache_reset_timeout'))
2888
-				@apache_reset_timeout();
3047
+			if (function_exists('apache_reset_timeout')) {
3048
+							@apache_reset_timeout();
3049
+			}
2889 3050
 
2890 3051
 			$table_charsets = array();
2891 3052
 
@@ -2908,8 +3069,9 @@  discard block
 block discarded – undo
2908 3069
 
2909 3070
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2910 3071
 						if ($charset != 'utf8') {
2911
-							if (!isset($table_charsets[$charset]))
2912
-								$table_charsets[$charset] = array();
3072
+							if (!isset($table_charsets[$charset])) {
3073
+															$table_charsets[$charset] = array();
3074
+							}
2913 3075
 
2914 3076
 							$table_charsets[$charset][] = $column_info;
2915 3077
 						}
@@ -2950,10 +3112,11 @@  discard block
 block discarded – undo
2950 3112
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2951 3113
 				{
2952 3114
 					$update = '';
2953
-					foreach ($table_charsets as $charset => $columns)
2954
-						foreach ($columns as $column)
3115
+					foreach ($table_charsets as $charset => $columns) {
3116
+											foreach ($columns as $column)
2955 3117
 							$update .= '
2956 3118
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3119
+					}
2957 3120
 
2958 3121
 					$smcFunc['db_query']('', '
2959 3122
 						UPDATE {raw:table_name}
@@ -2978,8 +3141,9 @@  discard block
 block discarded – undo
2978 3141
 			// Now do the actual conversion (if still needed).
2979 3142
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2980 3143
 			{
2981
-				if ($command_line)
2982
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3144
+				if ($command_line) {
3145
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3146
+				}
2983 3147
 
2984 3148
 				$smcFunc['db_query']('', '
2985 3149
 					ALTER TABLE {raw:table_name}
@@ -2989,12 +3153,14 @@  discard block
 block discarded – undo
2989 3153
 					)
2990 3154
 				);
2991 3155
 
2992
-				if ($command_line)
2993
-					echo " done.\n";
3156
+				if ($command_line) {
3157
+									echo " done.\n";
3158
+				}
2994 3159
 			}
2995 3160
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2996
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
2997
-				return upgradeExit();
3161
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3162
+							return upgradeExit();
3163
+			}
2998 3164
 		}
2999 3165
 
3000 3166
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -3023,8 +3189,8 @@  discard block
 block discarded – undo
3023 3189
 		);
3024 3190
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3025 3191
 		{
3026
-			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)
3027
-				$smcFunc['db_query']('', '
3192
+			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) {
3193
+							$smcFunc['db_query']('', '
3028 3194
 					UPDATE {db_prefix}log_actions
3029 3195
 					SET extra = {string:extra}
3030 3196
 					WHERE id_action = {int:current_action}',
@@ -3033,6 +3199,7 @@  discard block
 block discarded – undo
3033 3199
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
3034 3200
 					)
3035 3201
 				);
3202
+			}
3036 3203
 		}
3037 3204
 		$smcFunc['db_free_result']($request);
3038 3205
 
@@ -3054,15 +3221,17 @@  discard block
 block discarded – undo
3054 3221
 	// First thing's first - did we already do this?
3055 3222
 	if (!empty($modSettings['json_done']))
3056 3223
 	{
3057
-		if ($command_line)
3058
-			return DeleteUpgrade();
3059
-		else
3060
-			return true;
3224
+		if ($command_line) {
3225
+					return DeleteUpgrade();
3226
+		} else {
3227
+					return true;
3228
+		}
3061 3229
 	}
3062 3230
 
3063 3231
 	// Done it already - js wise?
3064
-	if (!empty($_POST['json_done']))
3065
-		return true;
3232
+	if (!empty($_POST['json_done'])) {
3233
+			return true;
3234
+	}
3066 3235
 
3067 3236
 	// List of tables affected by this function
3068 3237
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3094,12 +3263,14 @@  discard block
 block discarded – undo
3094 3263
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3095 3264
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3096 3265
 
3097
-	foreach ($keys as $id => $table)
3098
-		if ($id < $_GET['substep'])
3266
+	foreach ($keys as $id => $table) {
3267
+			if ($id < $_GET['substep'])
3099 3268
 			$upcontext['previous_tables'][] = $table;
3269
+	}
3100 3270
 
3101
-	if ($command_line)
3102
-		echo 'Converting data from serialize() to json_encode().';
3271
+	if ($command_line) {
3272
+			echo 'Converting data from serialize() to json_encode().';
3273
+	}
3103 3274
 
3104 3275
 	if (!$support_js || isset($_GET['xml']))
3105 3276
 	{
@@ -3139,8 +3310,9 @@  discard block
 block discarded – undo
3139 3310
 
3140 3311
 				// Loop through and fix these...
3141 3312
 				$new_settings = array();
3142
-				if ($command_line)
3143
-					echo "\n" . 'Fixing some settings...';
3313
+				if ($command_line) {
3314
+									echo "\n" . 'Fixing some settings...';
3315
+				}
3144 3316
 
3145 3317
 				foreach ($serialized_settings as $var)
3146 3318
 				{
@@ -3148,22 +3320,24 @@  discard block
 block discarded – undo
3148 3320
 					{
3149 3321
 						// Attempt to unserialize the setting
3150 3322
 						$temp = @safe_unserialize($modSettings[$var]);
3151
-						if (!$temp && $command_line)
3152
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3153
-						elseif ($temp !== false)
3154
-							$new_settings[$var] = json_encode($temp);
3323
+						if (!$temp && $command_line) {
3324
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3325
+						} elseif ($temp !== false) {
3326
+													$new_settings[$var] = json_encode($temp);
3327
+						}
3155 3328
 					}
3156 3329
 				}
3157 3330
 
3158 3331
 				// Update everything at once
3159
-				if (!function_exists('cache_put_data'))
3160
-					require_once($sourcedir . '/Load.php');
3332
+				if (!function_exists('cache_put_data')) {
3333
+									require_once($sourcedir . '/Load.php');
3334
+				}
3161 3335
 				updateSettings($new_settings, true);
3162 3336
 
3163
-				if ($command_line)
3164
-					echo ' done.';
3165
-			}
3166
-			elseif ($table == 'themes')
3337
+				if ($command_line) {
3338
+									echo ' done.';
3339
+				}
3340
+			} elseif ($table == 'themes')
3167 3341
 			{
3168 3342
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3169 3343
 				$query = $smcFunc['db_query']('', '
@@ -3182,10 +3356,11 @@  discard block
 block discarded – undo
3182 3356
 
3183 3357
 						if ($command_line)
3184 3358
 						{
3185
-							if ($temp === false)
3186
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3187
-							else
3188
-								echo "\n" . 'Fixing admin preferences...';
3359
+							if ($temp === false) {
3360
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3361
+							} else {
3362
+															echo "\n" . 'Fixing admin preferences...';
3363
+							}
3189 3364
 						}
3190 3365
 
3191 3366
 						if ($temp !== false)
@@ -3207,15 +3382,15 @@  discard block
 block discarded – undo
3207 3382
 								)
3208 3383
 							);
3209 3384
 
3210
-							if ($command_line)
3211
-								echo ' done.';
3385
+							if ($command_line) {
3386
+															echo ' done.';
3387
+							}
3212 3388
 						}
3213 3389
 					}
3214 3390
 
3215 3391
 					$smcFunc['db_free_result']($query);
3216 3392
 				}
3217
-			}
3218
-			else
3393
+			} else
3219 3394
 			{
3220 3395
 				// First item is always the key...
3221 3396
 				$key = $info[0];
@@ -3226,8 +3401,7 @@  discard block
 block discarded – undo
3226 3401
 				{
3227 3402
 					$col_select = $info[1];
3228 3403
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3229
-				}
3230
-				else
3404
+				} else
3231 3405
 				{
3232 3406
 					$col_select = implode(', ', $info);
3233 3407
 				}
@@ -3260,8 +3434,7 @@  discard block
 block discarded – undo
3260 3434
 								if ($temp === false && $command_line)
3261 3435
 								{
3262 3436
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3263
-								}
3264
-								else
3437
+								} else
3265 3438
 								{
3266 3439
 									$row[$col] = json_encode($temp);
3267 3440
 
@@ -3286,16 +3459,18 @@  discard block
 block discarded – undo
3286 3459
 						}
3287 3460
 					}
3288 3461
 
3289
-					if ($command_line)
3290
-						echo ' done.';
3462
+					if ($command_line) {
3463
+											echo ' done.';
3464
+					}
3291 3465
 
3292 3466
 					// Free up some memory...
3293 3467
 					$smcFunc['db_free_result']($query);
3294 3468
 				}
3295 3469
 			}
3296 3470
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3297
-			if (isset($_GET['xml']))
3298
-				return upgradeExit();
3471
+			if (isset($_GET['xml'])) {
3472
+							return upgradeExit();
3473
+			}
3299 3474
 		}
3300 3475
 
3301 3476
 		if ($command_line)
@@ -3310,8 +3485,9 @@  discard block
 block discarded – undo
3310 3485
 
3311 3486
 		$_GET['substep'] = 0;
3312 3487
 		// Make sure we move on!
3313
-		if ($command_line)
3314
-			return DeleteUpgrade();
3488
+		if ($command_line) {
3489
+					return DeleteUpgrade();
3490
+		}
3315 3491
 
3316 3492
 		return true;
3317 3493
 	}
@@ -3368,14 +3544,16 @@  discard block
 block discarded – undo
3368 3544
 	global $upcontext, $txt, $settings;
3369 3545
 
3370 3546
 	// Don't call me twice!
3371
-	if (!empty($upcontext['chmod_called']))
3372
-		return;
3547
+	if (!empty($upcontext['chmod_called'])) {
3548
+			return;
3549
+	}
3373 3550
 
3374 3551
 	$upcontext['chmod_called'] = true;
3375 3552
 
3376 3553
 	// Nothing?
3377
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3378
-		return;
3554
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3555
+			return;
3556
+	}
3379 3557
 
3380 3558
 	// Was it a problem with Windows?
3381 3559
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3407,11 +3585,12 @@  discard block
 block discarded – undo
3407 3585
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\');
3408 3586
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3409 3587
 
3410
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3411
-		echo '
3588
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3589
+			echo '
3412 3590
 					content.write(\'<hr>\n\t\t\t\');
3413 3591
 					content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\');
3414 3592
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3593
+	}
3415 3594
 
3416 3595
 	echo '
3417 3596
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3419,17 +3598,19 @@  discard block
 block discarded – undo
3419 3598
 				}
3420 3599
 			</script>';
3421 3600
 
3422
-	if (!empty($upcontext['chmod']['ftp_error']))
3423
-		echo '
3601
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3602
+			echo '
3424 3603
 			<div class="error_message red">
3425 3604
 				', $txt['upgrade_ftp_error'], '<br><br>
3426 3605
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3427 3606
 			</div>
3428 3607
 			<br>';
3608
+	}
3429 3609
 
3430
-	if (empty($upcontext['chmod_in_form']))
3431
-		echo '
3610
+	if (empty($upcontext['chmod_in_form'])) {
3611
+			echo '
3432 3612
 	<form action="', $upcontext['form_url'], '" method="post">';
3613
+	}
3433 3614
 
3434 3615
 	echo '
3435 3616
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3464,10 +3645,11 @@  discard block
 block discarded – undo
3464 3645
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button"></div>
3465 3646
 	</div>';
3466 3647
 
3467
-	if (empty($upcontext['chmod_in_form']))
3468
-		echo '
3648
+	if (empty($upcontext['chmod_in_form'])) {
3649
+			echo '
3469 3650
 	</form>';
3470
-}
3651
+	}
3652
+	}
3471 3653
 
3472 3654
 function template_upgrade_above()
3473 3655
 {
@@ -3527,9 +3709,10 @@  discard block
 block discarded – undo
3527 3709
 				<h2>', $txt['upgrade_progress'], '</h2>
3528 3710
 				<ul>';
3529 3711
 
3530
-	foreach ($upcontext['steps'] as $num => $step)
3531
-		echo '
3712
+	foreach ($upcontext['steps'] as $num => $step) {
3713
+			echo '
3532 3714
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3715
+	}
3533 3716
 
3534 3717
 	echo '
3535 3718
 					</ul>
@@ -3542,8 +3725,8 @@  discard block
 block discarded – undo
3542 3725
 				</div>
3543 3726
 			</div>';
3544 3727
 
3545
-	if (isset($upcontext['step_progress']))
3546
-		echo '
3728
+	if (isset($upcontext['step_progress'])) {
3729
+			echo '
3547 3730
 				<br>
3548 3731
 				<br>
3549 3732
 				<div id="progress_bar_step">
@@ -3552,6 +3735,7 @@  discard block
 block discarded – undo
3552 3735
 						<span>', $txt['upgrade_step_progress'], '</span>
3553 3736
 					</div>
3554 3737
 				</div>';
3738
+	}
3555 3739
 
3556 3740
 	echo '
3557 3741
 				<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>
@@ -3582,32 +3766,36 @@  discard block
 block discarded – undo
3582 3766
 {
3583 3767
 	global $upcontext, $txt;
3584 3768
 
3585
-	if (!empty($upcontext['pause']))
3586
-		echo '
3769
+	if (!empty($upcontext['pause'])) {
3770
+			echo '
3587 3771
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3588 3772
 
3589 3773
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3590 3774
 								<h3>
3591 3775
 									', $txt['upgrade_paused_overload'], '
3592 3776
 								</h3>';
3777
+	}
3593 3778
 
3594
-	if (!empty($upcontext['custom_warning']))
3595
-		echo '
3779
+	if (!empty($upcontext['custom_warning'])) {
3780
+			echo '
3596 3781
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3597 3782
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3598 3783
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3599 3784
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3600 3785
 								</div>';
3786
+	}
3601 3787
 
3602 3788
 	echo '
3603 3789
 								<div class="righttext" style="margin: 1ex;">';
3604 3790
 
3605
-	if (!empty($upcontext['continue']))
3606
-		echo '
3791
+	if (!empty($upcontext['continue'])) {
3792
+			echo '
3607 3793
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">';
3608
-	if (!empty($upcontext['skip']))
3609
-		echo '
3794
+	}
3795
+	if (!empty($upcontext['skip'])) {
3796
+			echo '
3610 3797
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">';
3798
+	}
3611 3799
 
3612 3800
 	echo '
3613 3801
 								</div>
@@ -3657,11 +3845,12 @@  discard block
 block discarded – undo
3657 3845
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3658 3846
 	<smf>';
3659 3847
 
3660
-	if (!empty($upcontext['get_data']))
3661
-		foreach ($upcontext['get_data'] as $k => $v)
3848
+	if (!empty($upcontext['get_data'])) {
3849
+			foreach ($upcontext['get_data'] as $k => $v)
3662 3850
 			echo '
3663 3851
 		<get key="', $k, '">', $v, '</get>';
3664
-}
3852
+	}
3853
+	}
3665 3854
 
3666 3855
 function template_xml_below()
3667 3856
 {
@@ -3702,8 +3891,8 @@  discard block
 block discarded – undo
3702 3891
 	template_chmod();
3703 3892
 
3704 3893
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3705
-	if ($upcontext['is_large_forum'])
3706
-		echo '
3894
+	if ($upcontext['is_large_forum']) {
3895
+			echo '
3707 3896
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3708 3897
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3709 3898
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3711,10 +3900,11 @@  discard block
 block discarded – undo
3711 3900
 				', $txt['upgrade_warning_lots_data'], '
3712 3901
 			</div>
3713 3902
 		</div>';
3903
+	}
3714 3904
 
3715 3905
 	// A warning message?
3716
-	if (!empty($upcontext['warning']))
3717
-		echo '
3906
+	if (!empty($upcontext['warning'])) {
3907
+			echo '
3718 3908
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3719 3909
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3720 3910
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3722,6 +3912,7 @@  discard block
 block discarded – undo
3722 3912
 				', $upcontext['warning'], '
3723 3913
 			</div>
3724 3914
 		</div>';
3915
+	}
3725 3916
 
3726 3917
 	// Paths are incorrect?
3727 3918
 	echo '
@@ -3737,20 +3928,22 @@  discard block
 block discarded – undo
3737 3928
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3738 3929
 	{
3739 3930
 		$ago = time() - $upcontext['started'];
3740
-		if ($ago < 60)
3741
-			$ago = $ago . ' seconds';
3742
-		elseif ($ago < 3600)
3743
-			$ago = (int) ($ago / 60) . ' minutes';
3744
-		else
3745
-			$ago = (int) ($ago / 3600) . ' hours';
3931
+		if ($ago < 60) {
3932
+					$ago = $ago . ' seconds';
3933
+		} elseif ($ago < 3600) {
3934
+					$ago = (int) ($ago / 60) . ' minutes';
3935
+		} else {
3936
+					$ago = (int) ($ago / 3600) . ' hours';
3937
+		}
3746 3938
 
3747 3939
 		$active = time() - $upcontext['updated'];
3748
-		if ($active < 60)
3749
-			$updated = $active . ' seconds';
3750
-		elseif ($active < 3600)
3751
-			$updated = (int) ($active / 60) . ' minutes';
3752
-		else
3753
-			$updated = (int) ($active / 3600) . ' hours';
3940
+		if ($active < 60) {
3941
+					$updated = $active . ' seconds';
3942
+		} elseif ($active < 3600) {
3943
+					$updated = (int) ($active / 60) . ' minutes';
3944
+		} else {
3945
+					$updated = (int) ($active / 3600) . ' hours';
3946
+		}
3754 3947
 
3755 3948
 		echo '
3756 3949
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3759,16 +3952,18 @@  discard block
 block discarded – undo
3759 3952
 			<div style="padding-left: 6ex;">
3760 3953
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3761 3954
 
3762
-		if ($active < 600)
3763
-			echo '
3955
+		if ($active < 600) {
3956
+					echo '
3764 3957
 				', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '';
3958
+		}
3765 3959
 
3766
-		if ($active > $upcontext['inactive_timeout'])
3767
-			echo '
3960
+		if ($active > $upcontext['inactive_timeout']) {
3961
+					echo '
3768 3962
 				<br><br>',$txt['upgrade_run'], '';
3769
-		else
3770
-			echo '
3963
+		} else {
3964
+					echo '
3771 3965
 				<br><br>', $txt['upgrade_script_timeout'], ' ', $upcontext['user']['name'], ' ', $txt['upgrade_script_timeout2'], ' ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3966
+		}
3772 3967
 
3773 3968
 		echo '
3774 3969
 			</div>
@@ -3784,9 +3979,10 @@  discard block
 block discarded – undo
3784 3979
 					<td>
3785 3980
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>';
3786 3981
 
3787
-	if (!empty($upcontext['username_incorrect']))
3788
-		echo '
3982
+	if (!empty($upcontext['username_incorrect'])) {
3983
+			echo '
3789 3984
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_username'], '</div>';
3985
+	}
3790 3986
 
3791 3987
 	echo '
3792 3988
 					</td>
@@ -3797,9 +3993,10 @@  discard block
 block discarded – undo
3797 3993
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '>
3798 3994
 						<input type="hidden" name="hash_passwrd" value="">';
3799 3995
 
3800
-	if (!empty($upcontext['password_failed']))
3801
-		echo '
3996
+	if (!empty($upcontext['password_failed'])) {
3997
+			echo '
3802 3998
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_password'], '</div>';
3999
+	}
3803 4000
 
3804 4001
 	echo '
3805 4002
 					</td>
@@ -3870,8 +4067,8 @@  discard block
 block discarded – undo
3870 4067
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3871 4068
 
3872 4069
 	// Warning message?
3873
-	if (!empty($upcontext['upgrade_options_warning']))
3874
-		echo '
4070
+	if (!empty($upcontext['upgrade_options_warning'])) {
4071
+			echo '
3875 4072
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3876 4073
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3877 4074
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3879,6 +4076,7 @@  discard block
 block discarded – undo
3879 4076
 				', $upcontext['upgrade_options_warning'], '
3880 4077
 			</div>
3881 4078
 		</div>';
4079
+	}
3882 4080
 
3883 4081
 	echo '
3884 4082
 				<table>
@@ -3921,8 +4119,8 @@  discard block
 block discarded – undo
3921 4119
 						</td>
3922 4120
 					</tr>';
3923 4121
 
3924
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3925
-		echo '
4122
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4123
+			echo '
3926 4124
 					<tr valign="top">
3927 4125
 						<td width="2%">
3928 4126
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1">
@@ -3931,6 +4129,7 @@  discard block
 block discarded – undo
3931 4129
 							<label for="delete_karma">', $txt['upgrade_delete_karma'], '</label>
3932 4130
 						</td>
3933 4131
 					</tr>';
4132
+	}
3934 4133
 
3935 4134
 	echo '
3936 4135
 					<tr valign="top">
@@ -3968,10 +4167,11 @@  discard block
 block discarded – undo
3968 4167
 			</div>';
3969 4168
 
3970 4169
 	// Dont any tables so far?
3971
-	if (!empty($upcontext['previous_tables']))
3972
-		foreach ($upcontext['previous_tables'] as $table)
4170
+	if (!empty($upcontext['previous_tables'])) {
4171
+			foreach ($upcontext['previous_tables'] as $table)
3973 4172
 			echo '
3974 4173
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4174
+	}
3975 4175
 
3976 4176
 	echo '
3977 4177
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -4008,12 +4208,13 @@  discard block
 block discarded – undo
4008 4208
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4009 4209
 
4010 4210
 		// If debug flood the screen.
4011
-		if ($is_debug)
4012
-			echo '
4211
+		if ($is_debug) {
4212
+					echo '
4013 4213
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4014 4214
 
4015 4215
 				if (document.getElementById(\'debug_section\').scrollHeight)
4016 4216
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4217
+		}
4017 4218
 
4018 4219
 		echo '
4019 4220
 				// Get the next update...
@@ -4046,8 +4247,9 @@  discard block
 block discarded – undo
4046 4247
 {
4047 4248
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold, $txt;
4048 4249
 
4049
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
4050
-		$is_debug = true;
4250
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4251
+			$is_debug = true;
4252
+	}
4051 4253
 
4052 4254
 	echo '
4053 4255
 		<h3>', $txt['upgrade_db_changes'], '</h3>
@@ -4062,8 +4264,9 @@  discard block
 block discarded – undo
4062 4264
 	{
4063 4265
 		foreach ($upcontext['actioned_items'] as $num => $item)
4064 4266
 		{
4065
-			if ($num != 0)
4066
-				echo ' Successful!';
4267
+			if ($num != 0) {
4268
+							echo ' Successful!';
4269
+			}
4067 4270
 			echo '<br>' . $item;
4068 4271
 		}
4069 4272
 		if (!empty($upcontext['changes_complete']))
@@ -4076,28 +4279,32 @@  discard block
 block discarded – undo
4076 4279
 				$seconds = intval($active % 60);
4077 4280
 
4078 4281
 				$totalTime = '';
4079
-				if ($hours > 0)
4080
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4081
-				if ($minutes > 0)
4082
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4083
-				if ($seconds > 0)
4084
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4282
+				if ($hours > 0) {
4283
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4284
+				}
4285
+				if ($minutes > 0) {
4286
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4287
+				}
4288
+				if ($seconds > 0) {
4289
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4290
+				}
4085 4291
 			}
4086 4292
 
4087
-			if ($is_debug && !empty($totalTime))
4088
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
4089
-			else
4090
-				echo ' Successful!<br><br>';
4293
+			if ($is_debug && !empty($totalTime)) {
4294
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4295
+			} else {
4296
+							echo ' Successful!<br><br>';
4297
+			}
4091 4298
 
4092 4299
 			echo '<span id="commess" style="font-weight: bold;">', $txt['upgrade_db_complete'], '</span><br>';
4093 4300
 		}
4094
-	}
4095
-	else
4301
+	} else
4096 4302
 	{
4097 4303
 		// Tell them how many files we have in total.
4098
-		if ($upcontext['file_count'] > 1)
4099
-			echo '
4304
+		if ($upcontext['file_count'] > 1) {
4305
+					echo '
4100 4306
 		<strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4307
+		}
4101 4308
 
4102 4309
 		echo '
4103 4310
 		<h3 id="info2"><strong>', $txt['upgrade_executing'], '</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> ', $txt['upgrade_of'], ' <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -4113,19 +4320,23 @@  discard block
 block discarded – undo
4113 4320
 				$seconds = intval($active % 60);
4114 4321
 
4115 4322
 				$totalTime = '';
4116
-				if ($hours > 0)
4117
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4118
-				if ($minutes > 0)
4119
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4120
-				if ($seconds > 0)
4121
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4323
+				if ($hours > 0) {
4324
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4325
+				}
4326
+				if ($minutes > 0) {
4327
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4328
+				}
4329
+				if ($seconds > 0) {
4330
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4331
+				}
4122 4332
 			}
4123 4333
 
4124 4334
 			echo '
4125 4335
 			<br><span id="upgradeCompleted">';
4126 4336
 
4127
-			if (!empty($totalTime))
4128
-				echo 'Completed in ', $totalTime, '<br>';
4337
+			if (!empty($totalTime)) {
4338
+							echo 'Completed in ', $totalTime, '<br>';
4339
+			}
4129 4340
 
4130 4341
 			echo '</span>
4131 4342
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -4162,9 +4373,10 @@  discard block
 block discarded – undo
4162 4373
 			var getData = "";
4163 4374
 			var debugItems = ', $upcontext['debug_items'], ';';
4164 4375
 
4165
-		if ($is_debug)
4166
-			echo '
4376
+		if ($is_debug) {
4377
+					echo '
4167 4378
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4379
+		}
4168 4380
 
4169 4381
 		echo '
4170 4382
 			function getNextItem()
@@ -4204,9 +4416,10 @@  discard block
 block discarded – undo
4204 4416
 						document.getElementById("error_block").style.display = "";
4205 4417
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4206 4418
 
4207
-	if ($is_debug)
4208
-		echo '
4419
+	if ($is_debug) {
4420
+			echo '
4209 4421
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4422
+	}
4210 4423
 
4211 4424
 	echo '
4212 4425
 					}
@@ -4227,9 +4440,10 @@  discard block
 block discarded – undo
4227 4440
 						document.getElementById("error_block").style.display = "";
4228 4441
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4229 4442
 
4230
-	if ($is_debug)
4231
-		echo '
4443
+	if ($is_debug) {
4444
+			echo '
4232 4445
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4446
+	}
4233 4447
 
4234 4448
 	echo '
4235 4449
 					}
@@ -4288,8 +4502,8 @@  discard block
 block discarded – undo
4288 4502
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4289 4503
 				{';
4290 4504
 
4291
-		if ($is_debug)
4292
-			echo '
4505
+		if ($is_debug) {
4506
+					echo '
4293 4507
 					document.getElementById(\'debug_section\').style.display = "none";
4294 4508
 
4295 4509
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4307,6 +4521,7 @@  discard block
 block discarded – undo
4307 4521
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4308 4522
 
4309 4523
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4524
+		}
4310 4525
 
4311 4526
 		echo '
4312 4527
 
@@ -4314,9 +4529,10 @@  discard block
 block discarded – undo
4314 4529
 					document.getElementById(\'contbutt\').disabled = 0;
4315 4530
 					document.getElementById(\'database_done\').value = 1;';
4316 4531
 
4317
-		if ($upcontext['file_count'] > 1)
4318
-			echo '
4532
+		if ($upcontext['file_count'] > 1) {
4533
+					echo '
4319 4534
 					document.getElementById(\'info1\').style.display = "none";';
4535
+		}
4320 4536
 
4321 4537
 		echo '
4322 4538
 					document.getElementById(\'info2\').style.display = "none";
@@ -4329,9 +4545,10 @@  discard block
 block discarded – undo
4329 4545
 					lastItem = 0;
4330 4546
 					prevFile = curFile;';
4331 4547
 
4332
-		if ($is_debug)
4333
-			echo '
4548
+		if ($is_debug) {
4549
+					echo '
4334 4550
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4551
+		}
4335 4552
 
4336 4553
 		echo '
4337 4554
 					getNextItem();
@@ -4339,8 +4556,8 @@  discard block
 block discarded – undo
4339 4556
 				}';
4340 4557
 
4341 4558
 		// If debug scroll the screen.
4342
-		if ($is_debug)
4343
-			echo '
4559
+		if ($is_debug) {
4560
+					echo '
4344 4561
 				if (iLastSubStepProgress == -1)
4345 4562
 				{
4346 4563
 					// Give it consistent dots.
@@ -4359,6 +4576,7 @@  discard block
 block discarded – undo
4359 4576
 
4360 4577
 				if (document.getElementById(\'debug_section\').scrollHeight)
4361 4578
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4579
+		}
4362 4580
 
4363 4581
 		echo '
4364 4582
 				// Update the page.
@@ -4419,9 +4637,10 @@  discard block
 block discarded – undo
4419 4637
 			}';
4420 4638
 
4421 4639
 		// Start things off assuming we've not errored.
4422
-		if (empty($upcontext['error_message']))
4423
-			echo '
4640
+		if (empty($upcontext['error_message'])) {
4641
+					echo '
4424 4642
 			getNextItem();';
4643
+		}
4425 4644
 
4426 4645
 		echo '
4427 4646
 		//# sourceURL=dynamicScript-dbch.js
@@ -4439,18 +4658,21 @@  discard block
 block discarded – undo
4439 4658
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4440 4659
 	<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>';
4441 4660
 
4442
-	if (!empty($upcontext['error_message']))
4443
-		echo '
4661
+	if (!empty($upcontext['error_message'])) {
4662
+			echo '
4444 4663
 	<error>', $upcontext['error_message'], '</error>';
4664
+	}
4445 4665
 
4446
-	if (!empty($upcontext['error_string']))
4447
-		echo '
4666
+	if (!empty($upcontext['error_string'])) {
4667
+			echo '
4448 4668
 	<sql>', $upcontext['error_string'], '</sql>';
4669
+	}
4449 4670
 
4450
-	if ($is_debug)
4451
-		echo '
4671
+	if ($is_debug) {
4672
+			echo '
4452 4673
 	<curtime>', time(), '</curtime>';
4453
-}
4674
+	}
4675
+	}
4454 4676
 
4455 4677
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4456 4678
 function template_convert_utf8()
@@ -4469,18 +4691,20 @@  discard block
 block discarded – undo
4469 4691
 			</div>';
4470 4692
 
4471 4693
 	// Done any tables so far?
4472
-	if (!empty($upcontext['previous_tables']))
4473
-		foreach ($upcontext['previous_tables'] as $table)
4694
+	if (!empty($upcontext['previous_tables'])) {
4695
+			foreach ($upcontext['previous_tables'] as $table)
4474 4696
 			echo '
4475 4697
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4698
+	}
4476 4699
 
4477 4700
 	echo '
4478 4701
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4479 4702
 
4480 4703
 	// If we dropped their index, let's let them know
4481
-	if ($upcontext['dropping_index'])
4482
-		echo '
4704
+	if ($upcontext['dropping_index']) {
4705
+			echo '
4483 4706
 				<br><span id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_fulltext'], '</span>';
4707
+	}
4484 4708
 
4485 4709
 	// Completion notification
4486 4710
 	echo '
@@ -4517,12 +4741,13 @@  discard block
 block discarded – undo
4517 4741
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4518 4742
 
4519 4743
 		// If debug flood the screen.
4520
-		if ($is_debug)
4521
-			echo '
4744
+		if ($is_debug) {
4745
+					echo '
4522 4746
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4523 4747
 
4524 4748
 				if (document.getElementById(\'debug_section\').scrollHeight)
4525 4749
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4750
+		}
4526 4751
 
4527 4752
 		echo '
4528 4753
 				// Get the next update...
@@ -4570,19 +4795,21 @@  discard block
 block discarded – undo
4570 4795
 			</div>';
4571 4796
 
4572 4797
 	// Dont any tables so far?
4573
-	if (!empty($upcontext['previous_tables']))
4574
-		foreach ($upcontext['previous_tables'] as $table)
4798
+	if (!empty($upcontext['previous_tables'])) {
4799
+			foreach ($upcontext['previous_tables'] as $table)
4575 4800
 			echo '
4576 4801
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4802
+	}
4577 4803
 
4578 4804
 	echo '
4579 4805
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4580 4806
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_json_completed'], '</span>';
4581 4807
 
4582 4808
 	// Try to make sure substep was reset.
4583
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4584
-		echo '
4809
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4810
+			echo '
4585 4811
 			<input type="hidden" name="substep" id="substep" value="0">';
4812
+	}
4586 4813
 
4587 4814
 	// Continue please!
4588 4815
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4615,12 +4842,13 @@  discard block
 block discarded – undo
4615 4842
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4616 4843
 
4617 4844
 		// If debug flood the screen.
4618
-		if ($is_debug)
4619
-			echo '
4845
+		if ($is_debug) {
4846
+					echo '
4620 4847
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4621 4848
 
4622 4849
 				if (document.getElementById(\'debug_section\').scrollHeight)
4623 4850
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4851
+		}
4624 4852
 
4625 4853
 		echo '
4626 4854
 				// Get the next update...
@@ -4656,8 +4884,8 @@  discard block
 block discarded – undo
4656 4884
 	<h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>.  ', $txt['upgrade_done3'], '</h3>
4657 4885
 	<form action="', $boardurl, '/index.php">';
4658 4886
 
4659
-	if (!empty($upcontext['can_delete_script']))
4660
-		echo '
4887
+	if (!empty($upcontext['can_delete_script'])) {
4888
+			echo '
4661 4889
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], '</label> <em>', $txt['upgrade_delete_server'], '</em>
4662 4890
 			<script>
4663 4891
 				function doTheDelete(theCheck)
@@ -4669,6 +4897,7 @@  discard block
 block discarded – undo
4669 4897
 				}
4670 4898
 			</script>
4671 4899
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4900
+	}
4672 4901
 
4673 4902
 	$active = time() - $upcontext['started'];
4674 4903
 	$hours = floor($active / 3600);
@@ -4678,16 +4907,20 @@  discard block
 block discarded – undo
4678 4907
 	if ($is_debug)
4679 4908
 	{
4680 4909
 		$totalTime = '';
4681
-		if ($hours > 0)
4682
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4683
-		if ($minutes > 0)
4684
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4685
-		if ($seconds > 0)
4686
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4910
+		if ($hours > 0) {
4911
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4912
+		}
4913
+		if ($minutes > 0) {
4914
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4915
+		}
4916
+		if ($seconds > 0) {
4917
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4918
+		}
4687 4919
 	}
4688 4920
 
4689
-	if ($is_debug && !empty($totalTime))
4690
-		echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4921
+	if ($is_debug && !empty($totalTime)) {
4922
+			echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4923
+	}
4691 4924
 
4692 4925
 	echo '<br>
4693 4926
 			', sprintf($txt['upgrade_problems'], 'http://simplemachines.org'), '<br>
@@ -4714,8 +4947,9 @@  discard block
 block discarded – undo
4714 4947
 
4715 4948
 	$current_substep = $_GET['substep'];
4716 4949
 
4717
-	if (empty($_GET['a']))
4718
-		$_GET['a'] = 0;
4950
+	if (empty($_GET['a'])) {
4951
+			$_GET['a'] = 0;
4952
+	}
4719 4953
 	$step_progress['name'] = 'Converting ips';
4720 4954
 	$step_progress['current'] = $_GET['a'];
4721 4955
 
@@ -4758,16 +4992,19 @@  discard block
 block discarded – undo
4758 4992
 				'empty' => '',
4759 4993
 				'limit' => $limit,
4760 4994
 		));
4761
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4762
-			$arIp[] = $row[$oldCol];
4995
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4996
+					$arIp[] = $row[$oldCol];
4997
+		}
4763 4998
 		$smcFunc['db_free_result']($request);
4764 4999
 
4765 5000
 		// Special case, null ip could keep us in a loop.
4766
-		if (is_null($arIp[0]))
4767
-			unset($arIp[0]);
5001
+		if (is_null($arIp[0])) {
5002
+					unset($arIp[0]);
5003
+		}
4768 5004
 
4769
-		if (empty($arIp))
4770
-			$is_done = true;
5005
+		if (empty($arIp)) {
5006
+					$is_done = true;
5007
+		}
4771 5008
 
4772 5009
 		$updates = array();
4773 5010
 		$cases = array();
@@ -4776,16 +5013,18 @@  discard block
 block discarded – undo
4776 5013
 		{
4777 5014
 			$arIp[$i] = trim($arIp[$i]);
4778 5015
 
4779
-			if (empty($arIp[$i]))
4780
-				continue;
5016
+			if (empty($arIp[$i])) {
5017
+							continue;
5018
+			}
4781 5019
 
4782 5020
 			$updates['ip' . $i] = $arIp[$i];
4783 5021
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4784 5022
 
4785 5023
 			if ($setSize > 0 && $i % $setSize === 0)
4786 5024
 			{
4787
-				if (count($updates) == 1)
4788
-					continue;
5025
+				if (count($updates) == 1) {
5026
+									continue;
5027
+				}
4789 5028
 
4790 5029
 				$updates['whereSet'] = array_values($updates);
4791 5030
 				$smcFunc['db_query']('', '
@@ -4819,8 +5058,7 @@  discard block
 block discarded – undo
4819 5058
 							'ip' => $ip
4820 5059
 					));
4821 5060
 				}
4822
-			}
4823
-			else
5061
+			} else
4824 5062
 			{
4825 5063
 				$updates['whereSet'] = array_values($updates);
4826 5064
 				$smcFunc['db_query']('', '
@@ -4834,9 +5072,9 @@  discard block
 block discarded – undo
4834 5072
 					$updates
4835 5073
 				);
4836 5074
 			}
5075
+		} else {
5076
+					$is_done = true;
4837 5077
 		}
4838
-		else
4839
-			$is_done = true;
4840 5078
 
4841 5079
 		$_GET['a'] += $limit;
4842 5080
 		$step_progress['current'] = $_GET['a'];
@@ -4862,10 +5100,11 @@  discard block
 block discarded – undo
4862 5100
 
4863 5101
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4864 5102
 
4865
-	if (isset($columns[$column]))
4866
-		return $columns[$column];
4867
-	else
4868
-		return null;
4869
-}
5103
+	if (isset($columns[$column])) {
5104
+			return $columns[$column];
5105
+	} else {
5106
+			return null;
5107
+	}
5108
+	}
4870 5109
 
4871 5110
 ?>
4872 5111
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Class-CurlFetchWeb.php 3 patches
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -94,12 +94,12 @@  discard block
 block discarded – undo
94 94
 	public $headers;
95 95
 
96 96
 	/**
97
-	* Start the curl object
98
-	* - allow for user override values
99
-	*
100
-	* @param array $options An array of cURL options
101
-	* @param int $max_redirect Maximum number of redirects
102
-	*/
97
+	 * Start the curl object
98
+	 * - allow for user override values
99
+	 *
100
+	 * @param array $options An array of cURL options
101
+	 * @param int $max_redirect Maximum number of redirects
102
+	 */
103 103
 	public function __construct($options = array(), $max_redirect = 3)
104 104
 	{
105 105
 		// Initialize class variables
@@ -108,16 +108,16 @@  discard block
 block discarded – undo
108 108
 	}
109 109
 
110 110
 	/**
111
-	* Main calling function,
112
-	*  - will request the page data from a given $url
113
-	*  - optionally will post data to the page form if post data is supplied
114
-	*  - passed arrays will be converted to a post string joined with &'s
115
-	*  - calls set_options to set the curl opts array values based on the defaults and user input
116
-	*
117
-	* @param string $url the site we are going to fetch
118
-	* @param array $post_data any post data as form name => value
119
-	* @return object An instance of the curl_fetch_web_data class
120
-	*/
111
+	 * Main calling function,
112
+	 *  - will request the page data from a given $url
113
+	 *  - optionally will post data to the page form if post data is supplied
114
+	 *  - passed arrays will be converted to a post string joined with &'s
115
+	 *  - calls set_options to set the curl opts array values based on the defaults and user input
116
+	 *
117
+	 * @param string $url the site we are going to fetch
118
+	 * @param array $post_data any post data as form name => value
119
+	 * @return object An instance of the curl_fetch_web_data class
120
+	 */
121 121
 	public function get_url_data($url, $post_data = array())
122 122
 	{
123 123
 		// POSTing some data perhaps?
@@ -134,14 +134,14 @@  discard block
 block discarded – undo
134 134
 	}
135 135
 
136 136
 	/**
137
-	* Makes the actual cURL call
138
-	*  - stores responses (url, code, error, headers, body) in the response array
139
-	*  - detects 301, 302, 307 codes and will redirect to the given response header location
140
-	*
141
-	* @param string $url The site to fetch
142
-	* @param bool $redirect Whether or not this was a redirect request
143
-	* @return void|bool Sets various properties of the class or returns false if the URL isn't specified
144
-	*/
137
+	 * Makes the actual cURL call
138
+	 *  - stores responses (url, code, error, headers, body) in the response array
139
+	 *  - detects 301, 302, 307 codes and will redirect to the given response header location
140
+	 *
141
+	 * @param string $url The site to fetch
142
+	 * @param bool $redirect Whether or not this was a redirect request
143
+	 * @return void|bool Sets various properties of the class or returns false if the URL isn't specified
144
+	 */
145 145
 	private function curl_request($url, $redirect = false)
146 146
 	{
147 147
 		// we do have a url I hope
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
 	}
194 194
 
195 195
 	/**
196
-	* Used if being redirected to ensure we have a fully qualified address
197
-	*
198
-	* @param string $last_url The URL we went to
199
-	* @param string $new_url The URL we were redirected to
200
-	* @return string The new URL that was in the HTTP header
201
-	*/
196
+	 * Used if being redirected to ensure we have a fully qualified address
197
+	 *
198
+	 * @param string $last_url The URL we went to
199
+	 * @param string $new_url The URL we were redirected to
200
+	 * @return string The new URL that was in the HTTP header
201
+	 */
202 202
 	private function get_redirect_url($last_url = '', $new_url = '')
203 203
 	{
204 204
 		// Get the elements for these urls
@@ -216,13 +216,13 @@  discard block
 block discarded – undo
216 216
 	}
217 217
 
218 218
 	/**
219
-	* Used to return the results to the calling program
220
-	*  - called as ->result() will return the full final array
221
-	*  - called as ->result('body') to just return the page source of the result
222
-	*
223
-	* @param string $area Used to return an area such as body, header, error
224
-	* @return string The response
225
-	*/
219
+	 * Used to return the results to the calling program
220
+	 *  - called as ->result() will return the full final array
221
+	 *  - called as ->result('body') to just return the page source of the result
222
+	 *
223
+	 * @param string $area Used to return an area such as body, header, error
224
+	 * @return string The response
225
+	 */
226 226
 	public function result($area = '')
227 227
 	{
228 228
 		$max_result = count($this->response) - 1;
@@ -235,13 +235,13 @@  discard block
 block discarded – undo
235 235
 	}
236 236
 
237 237
 	/**
238
-	* Will return all results from all loops (redirects)
239
-	*  - Can be called as ->result_raw(x) where x is a specific loop results.
240
-	*  - Call as ->result_raw() for everything.
241
-	*
242
-	* @param string $response_number Which response we want to get
243
-	* @return array|string The entire response array or just the specified response
244
-	*/
238
+	 * Will return all results from all loops (redirects)
239
+	 *  - Can be called as ->result_raw(x) where x is a specific loop results.
240
+	 *  - Call as ->result_raw() for everything.
241
+	 *
242
+	 * @param string $response_number Which response we want to get
243
+	 * @return array|string The entire response array or just the specified response
244
+	 */
245 245
 	public function result_raw($response_number = '')
246 246
 	{
247 247
 		if (!is_numeric($response_number))
@@ -254,13 +254,13 @@  discard block
 block discarded – undo
254 254
 	}
255 255
 
256 256
 	/**
257
-	* Takes supplied POST data and url encodes it
258
-	*  - forms the date (for post) in to a string var=xyz&var2=abc&var3=123
259
-	*  - drops vars with @ since we don't support sending files (uploading)
260
-	*
261
-	* @param array|string $post_data The raw POST data
262
-	* @return string A string of post data
263
-	*/
257
+	 * Takes supplied POST data and url encodes it
258
+	 *  - forms the date (for post) in to a string var=xyz&var2=abc&var3=123
259
+	 *  - drops vars with @ since we don't support sending files (uploading)
260
+	 *
261
+	 * @param array|string $post_data The raw POST data
262
+	 * @return string A string of post data
263
+	 */
264 264
 	private function build_post_data($post_data)
265 265
 	{
266 266
 		if (is_array($post_data))
@@ -279,11 +279,11 @@  discard block
 block discarded – undo
279 279
 	}
280 280
 
281 281
 	/**
282
-	* Sets the final cURL options for the current call
283
-	*  - overwrites our default values with user supplied ones or appends new user ones to what we have
284
-	*  - sets the callback function now that $this is existing
285
-	* @return void
286
-	*/
282
+	 * Sets the final cURL options for the current call
283
+	 *  - overwrites our default values with user supplied ones or appends new user ones to what we have
284
+	 *  - sets the callback function now that $this is existing
285
+	 * @return void
286
+	 */
287 287
 	private function set_options()
288 288
 	{
289 289
 		// Callback to parse the returned headers, if any
@@ -308,12 +308,12 @@  discard block
 block discarded – undo
308 308
 	}
309 309
 
310 310
 	/**
311
-	* Called to initiate a redirect from a 301, 302 or 307 header
312
-	*  - resets the cURL options for the loop, sets the referrer flag
313
-	*
314
-	* @param string $target_url The URL we want to redirect to
315
-	* @param string $referer_url The URL that we're redirecting from
316
-	*/
311
+	 * Called to initiate a redirect from a 301, 302 or 307 header
312
+	 *  - resets the cURL options for the loop, sets the referrer flag
313
+	 *
314
+	 * @param string $target_url The URL we want to redirect to
315
+	 * @param string $referer_url The URL that we're redirecting from
316
+	 */
317 317
 	private function redirect($target_url, $referer_url)
318 318
 	{
319 319
 		// no no I last saw that over there ... really, 301, 302, 307
@@ -323,13 +323,13 @@  discard block
 block discarded – undo
323 323
 	}
324 324
 
325 325
 	/**
326
-	* Callback function to parse returned headers
327
-	*  - lowercases everything to make it consistent
328
-	*
329
-	* @param type $cr Not sure what this is used for?
330
-	* @param string $header The header
331
-	* @return int The length of the header
332
-	*/
326
+	 * Callback function to parse returned headers
327
+	 *  - lowercases everything to make it consistent
328
+	 *
329
+	 * @param type $cr Not sure what this is used for?
330
+	 * @param string $header The header
331
+	 * @return int The length of the header
332
+	 */
333 333
 	private function header_callback($cr, $header)
334 334
 	{
335 335
 		$_header = trim($header);
Please login to merge, or discard this patch.
Braces   +30 added lines, -24 removed lines patch added patch discarded remove patch
@@ -10,8 +10,9 @@  discard block
 block discarded – undo
10 10
  * @version 2.1 Beta 4
11 11
  */
12 12
 
13
-if (!defined('SMF'))
13
+if (!defined('SMF')) {
14 14
 	die('No direct access...');
15
+}
15 16
 
16 17
 /**
17 18
  * Class curl_fetch_web_data
@@ -121,10 +122,11 @@  discard block
 block discarded – undo
121 122
 	public function get_url_data($url, $post_data = array())
122 123
 	{
123 124
 		// POSTing some data perhaps?
124
-		if (!empty($post_data) && is_array($post_data))
125
-			$this->post_data = $this->build_post_data($post_data);
126
-		elseif (!empty($post_data))
127
-			$this->post_data = trim($post_data);
125
+		if (!empty($post_data) && is_array($post_data)) {
126
+					$this->post_data = $this->build_post_data($post_data);
127
+		} elseif (!empty($post_data)) {
128
+					$this->post_data = trim($post_data);
129
+		}
128 130
 
129 131
 		// set the options and get it
130 132
 		$this->set_options();
@@ -145,10 +147,11 @@  discard block
 block discarded – undo
145 147
 	private function curl_request($url, $redirect = false)
146 148
 	{
147 149
 		// we do have a url I hope
148
-		if ($url == '')
149
-			return false;
150
-		else
151
-			$this->options[CURLOPT_URL] = $url;
150
+		if ($url == '') {
151
+					return false;
152
+		} else {
153
+					$this->options[CURLOPT_URL] = $url;
154
+		}
152 155
 
153 156
 		// if we have not already been redirected, set it up so we can if needed
154 157
 		if (!$redirect)
@@ -228,10 +231,11 @@  discard block
 block discarded – undo
228 231
 		$max_result = count($this->response) - 1;
229 232
 
230 233
 		// just return a specifed area or the entire result?
231
-		if ($area == '')
232
-			return $this->response[$max_result];
233
-		else
234
-			return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result];
234
+		if ($area == '') {
235
+					return $this->response[$max_result];
236
+		} else {
237
+					return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result];
238
+		}
235 239
 	}
236 240
 
237 241
 	/**
@@ -244,9 +248,9 @@  discard block
 block discarded – undo
244 248
 	*/
245 249
 	public function result_raw($response_number = '')
246 250
 	{
247
-		if (!is_numeric($response_number))
248
-			return $this->response;
249
-		else
251
+		if (!is_numeric($response_number)) {
252
+					return $this->response;
253
+		} else
250 254
 		{
251 255
 			$response_number = min($response_number, count($this->response) - 1);
252 256
 			return $this->response[$response_number];
@@ -268,13 +272,14 @@  discard block
 block discarded – undo
268 272
 			$postvars = array();
269 273
 
270 274
 			// build the post data, drop ones with leading @'s since those can be used to send files, we don't support that.
271
-			foreach ($post_data as $name => $value)
272
-				$postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value);
275
+			foreach ($post_data as $name => $value) {
276
+							$postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value);
277
+			}
273 278
 
274 279
 			return implode('&', $postvars);
280
+		} else {
281
+					return $post_data;
275 282
 		}
276
-		else
277
-			return $post_data;
278 283
 
279 284
 	}
280 285
 
@@ -295,9 +300,9 @@  discard block
 block discarded – undo
295 300
 			$keys = array_merge(array_keys($this->default_options), array_keys($this->user_options));
296 301
 			$vals = array_merge($this->default_options, $this->user_options);
297 302
 			$this->options = array_combine($keys, $vals);
303
+		} else {
304
+					$this->options = $this->default_options;
298 305
 		}
299
-		else
300
-			$this->options = $this->default_options;
301 306
 
302 307
 		// POST data options, here we don't allow any overide
303 308
 		if (isset($this->post_data))
@@ -336,8 +341,9 @@  discard block
 block discarded – undo
336 341
 		$temp = explode(': ', $_header, 2);
337 342
 
338 343
 		// set proper headers only
339
-		if (isset($temp[0]) && isset($temp[1]))
340
-			$this->headers[strtolower($temp[0])] = strtolower(trim($temp[1]));
344
+		if (isset($temp[0]) && isset($temp[1])) {
345
+					$this->headers[strtolower($temp[0])] = strtolower(trim($temp[1]));
346
+		}
341 347
 
342 348
 		// return the length of what was passed unless you want a Failed writing header error ;)
343 349
 		return strlen($header);
Please login to merge, or discard this patch.
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
 	*  - calls set_options to set the curl opts array values based on the defaults and user input
116 116
 	*
117 117
 	* @param string $url the site we are going to fetch
118
-	* @param array $post_data any post data as form name => value
119
-	* @return object An instance of the curl_fetch_web_data class
118
+	* @param string $post_data any post data as form name => value
119
+	* @return curl_fetch_web_data An instance of the curl_fetch_web_data class
120 120
 	*/
121 121
 	public function get_url_data($url, $post_data = array())
122 122
 	{
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	*
141 141
 	* @param string $url The site to fetch
142 142
 	* @param bool $redirect Whether or not this was a redirect request
143
-	* @return void|bool Sets various properties of the class or returns false if the URL isn't specified
143
+	* @return false|null Sets various properties of the class or returns false if the URL isn't specified
144 144
 	*/
145 145
 	private function curl_request($url, $redirect = false)
146 146
 	{
Please login to merge, or discard this patch.
Sources/News.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
 			{
838 838
 				uasort($loaded_attachments, function($a, $b) {
839 839
 					if ($a['filesize'] == $b['filesize'])
840
-					        return 0;
840
+							return 0;
841 841
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
842 842
 				});
843 843
 			}
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
 			{
1243 1243
 				uasort($loaded_attachments, function($a, $b) {
1244 1244
 					if ($a['filesize'] == $b['filesize'])
1245
-					        return 0;
1245
+							return 0;
1246 1246
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
1247 1247
 				});
1248 1248
 			}
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 		$smcFunc['db_free_result']($request);
166 166
 
167 167
 		$feed_meta['title'] = ' - ' . strip_tags($board_info['name']);
168
-		$feed_meta['source'] .= '?board=' . $board . '.0' ;
168
+		$feed_meta['source'] .= '?board=' . $board . '.0';
169 169
 
170 170
 		$query_this_board = 'b.id_board = ' . $board;
171 171
 
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 
390 390
 		foreach ($xml_data as $item)
391 391
 		{
392
-			$link = array_filter($item['content'], function ($e) { return ($e['tag'] == 'link'); });
392
+			$link = array_filter($item['content'], function($e) { return ($e['tag'] == 'link'); });
393 393
 			$link = array_pop($link);
394 394
 
395 395
 			echo '
Please login to merge, or discard this patch.
Braces   +226 added lines, -185 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
  * Outputs xml data representing recent information or a profile.
@@ -37,8 +38,9 @@  discard block
 block discarded – undo
37 38
 	global $query_this_board, $smcFunc, $forum_version, $settings;
38 39
 
39 40
 	// If it's not enabled, die.
40
-	if (empty($modSettings['xmlnews_enable']))
41
-		obExit(false);
41
+	if (empty($modSettings['xmlnews_enable'])) {
42
+			obExit(false);
43
+	}
42 44
 
43 45
 	loadLanguage('Stats');
44 46
 
@@ -64,8 +66,9 @@  discard block
 block discarded – undo
64 66
 	if (!empty($_REQUEST['c']) && empty($board))
65 67
 	{
66 68
 		$_REQUEST['c'] = explode(',', $_REQUEST['c']);
67
-		foreach ($_REQUEST['c'] as $i => $c)
68
-			$_REQUEST['c'][$i] = (int) $c;
69
+		foreach ($_REQUEST['c'] as $i => $c) {
70
+					$_REQUEST['c'][$i] = (int) $c;
71
+		}
69 72
 
70 73
 		if (count($_REQUEST['c']) == 1)
71 74
 		{
@@ -101,18 +104,20 @@  discard block
 block discarded – undo
101 104
 		}
102 105
 		$smcFunc['db_free_result']($request);
103 106
 
104
-		if (!empty($boards))
105
-			$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
107
+		if (!empty($boards)) {
108
+					$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
109
+		}
106 110
 
107 111
 		// Try to limit the number of messages we look through.
108
-		if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15)
109
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5);
110
-	}
111
-	elseif (!empty($_REQUEST['boards']))
112
+		if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) {
113
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5);
114
+		}
115
+	} elseif (!empty($_REQUEST['boards']))
112 116
 	{
113 117
 		$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
114
-		foreach ($_REQUEST['boards'] as $i => $b)
115
-			$_REQUEST['boards'][$i] = (int) $b;
118
+		foreach ($_REQUEST['boards'] as $i => $b) {
119
+					$_REQUEST['boards'][$i] = (int) $b;
120
+		}
116 121
 
117 122
 		$request = $smcFunc['db_query']('', '
118 123
 			SELECT b.id_board, b.num_posts, b.name
@@ -128,29 +133,32 @@  discard block
 block discarded – undo
128 133
 
129 134
 		// Either the board specified doesn't exist or you have no access.
130 135
 		$num_boards = $smcFunc['db_num_rows']($request);
131
-		if ($num_boards == 0)
132
-			fatal_lang_error('no_board');
136
+		if ($num_boards == 0) {
137
+					fatal_lang_error('no_board');
138
+		}
133 139
 
134 140
 		$total_posts = 0;
135 141
 		$boards = array();
136 142
 		while ($row = $smcFunc['db_fetch_assoc']($request))
137 143
 		{
138
-			if ($num_boards == 1)
139
-				$feed_meta['title'] = ' - ' . strip_tags($row['name']);
144
+			if ($num_boards == 1) {
145
+							$feed_meta['title'] = ' - ' . strip_tags($row['name']);
146
+			}
140 147
 
141 148
 			$boards[] = $row['id_board'];
142 149
 			$total_posts += $row['num_posts'];
143 150
 		}
144 151
 		$smcFunc['db_free_result']($request);
145 152
 
146
-		if (!empty($boards))
147
-			$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
153
+		if (!empty($boards)) {
154
+					$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
155
+		}
148 156
 
149 157
 		// The more boards, the more we're going to look through...
150
-		if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12)
151
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5);
152
-	}
153
-	elseif (!empty($board))
158
+		if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) {
159
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5);
160
+		}
161
+	} elseif (!empty($board))
154 162
 	{
155 163
 		$request = $smcFunc['db_query']('', '
156 164
 			SELECT num_posts
@@ -170,10 +178,10 @@  discard block
 block discarded – undo
170 178
 		$query_this_board = 'b.id_board = ' . $board;
171 179
 
172 180
 		// Try to look through just a few messages, if at all possible.
173
-		if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10)
174
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5);
175
-	}
176
-	else
181
+		if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) {
182
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5);
183
+		}
184
+	} else
177 185
 	{
178 186
 		$query_this_board = '{query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
179 187
 			AND b.id_board != ' . $modSettings['recycle_board'] : '');
@@ -196,30 +204,35 @@  discard block
 block discarded – undo
196 204
 	// Easy adding of sub actions
197 205
  	call_integration_hook('integrate_xmlfeeds', array(&$subActions));
198 206
 
199
-	if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']]))
200
-		$_GET['sa'] = 'recent';
207
+	if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) {
208
+			$_GET['sa'] = 'recent';
209
+	}
201 210
 
202 211
 	// We only want some information, not all of it.
203 212
 	$cachekey = array($xml_format, $_GET['action'], $_GET['limit'], $_GET['sa']);
204
-	foreach (array('board', 'boards', 'c') as $var)
205
-		if (isset($_REQUEST[$var]))
213
+	foreach (array('board', 'boards', 'c') as $var) {
214
+			if (isset($_REQUEST[$var]))
206 215
 			$cachekey[] = $_REQUEST[$var];
216
+	}
207 217
 	$cachekey = md5($smcFunc['json_encode']($cachekey) . (!empty($query_this_board) ? $query_this_board : ''));
208 218
 	$cache_t = microtime();
209 219
 
210 220
 	// Get the associative array representing the xml.
211
-	if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3))
212
-		$xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240);
221
+	if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) {
222
+			$xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240);
223
+	}
213 224
 	if (empty($xml_data))
214 225
 	{
215 226
 		$call = call_helper($subActions[$_GET['sa']][0], true);
216 227
 
217
-		if (!empty($call))
218
-			$xml_data = call_user_func($call, $xml_format);
228
+		if (!empty($call)) {
229
+					$xml_data = call_user_func($call, $xml_format);
230
+		}
219 231
 
220 232
 		if (!empty($modSettings['cache_enable']) && (($user_info['is_guest'] && $modSettings['cache_enable'] >= 3)
221
-		|| (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2))))
222
-			cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240);
233
+		|| (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2)))) {
234
+					cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240);
235
+		}
223 236
 	}
224 237
 
225 238
 	$feed_meta['title'] = $smcFunc['htmlspecialchars'](strip_tags($context['forum_name'])) . (isset($feed_meta['title']) ? $feed_meta['title'] : '');
@@ -259,43 +272,49 @@  discard block
 block discarded – undo
259 272
 	call_integration_hook('integrate_xml_data', array(&$xml_data, &$feed_meta, &$namespaces, &$extraFeedTags, &$forceCdataKeys, &$nsKeys, $xml_format, $_GET['sa']));
260 273
 
261 274
 	// These can't be empty
262
-	foreach (array('title', 'desc', 'source') as $mkey)
263
-		$feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey];
275
+	foreach (array('title', 'desc', 'source') as $mkey) {
276
+			$feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey];
277
+	}
264 278
 
265 279
 	// Sanitize basic feed metadata values
266
-	foreach ($feed_meta as $mkey => $mvalue)
267
-		$feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey])));
280
+	foreach ($feed_meta as $mkey => $mvalue) {
281
+			$feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey])));
282
+	}
268 283
 
269 284
 	$ns_string = '';
270 285
 	if (!empty($namespaces[$xml_format]))
271 286
 	{
272
-		foreach ($namespaces[$xml_format] as $nsprefix => $nsurl)
273
-			$ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"';
287
+		foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) {
288
+					$ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"';
289
+		}
274 290
 	}
275 291
 
276 292
 	$extraFeedTags_string = '';
277 293
 	if (!empty($extraFeedTags[$xml_format]))
278 294
 	{
279 295
 		$indent = "\t" . ($xml_format !== 'atom' ? "\t" : '');
280
-		foreach ($extraFeedTags[$xml_format] as $extraTag)
281
-			$extraFeedTags_string .= "\n" . $indent . $extraTag;
296
+		foreach ($extraFeedTags[$xml_format] as $extraTag) {
297
+					$extraFeedTags_string .= "\n" . $indent . $extraTag;
298
+		}
282 299
 	}
283 300
 
284 301
 	// This is an xml file....
285 302
 	ob_end_clean();
286
-	if (!empty($modSettings['enableCompressedOutput']))
287
-		@ob_start('ob_gzhandler');
288
-	else
289
-		ob_start();
303
+	if (!empty($modSettings['enableCompressedOutput'])) {
304
+			@ob_start('ob_gzhandler');
305
+	} else {
306
+			ob_start();
307
+	}
290 308
 
291
-	if ($xml_format == 'smf' || isset($_REQUEST['debug']))
292
-		header('content-type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
293
-	elseif ($xml_format == 'rss' || $xml_format == 'rss2')
294
-		header('content-type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
295
-	elseif ($xml_format == 'atom')
296
-		header('content-type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
297
-	elseif ($xml_format == 'rdf')
298
-		header('content-type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
309
+	if ($xml_format == 'smf' || isset($_REQUEST['debug'])) {
310
+			header('content-type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
311
+	} elseif ($xml_format == 'rss' || $xml_format == 'rss2') {
312
+			header('content-type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
313
+	} elseif ($xml_format == 'atom') {
314
+			header('content-type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
315
+	} elseif ($xml_format == 'rdf') {
316
+			header('content-type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
317
+	}
299 318
 
300 319
 	// First, output the xml header.
301 320
 	echo '<?xml version="1.0" encoding="', $context['character_set'], '"?' . '>';
@@ -303,10 +322,11 @@  discard block
 block discarded – undo
303 322
 	// Are we outputting an rss feed or one with more information?
304 323
 	if ($xml_format == 'rss' || $xml_format == 'rss2')
305 324
 	{
306
-		if ($xml_format == 'rss2')
307
-			foreach ($_REQUEST as $var => $val)
325
+		if ($xml_format == 'rss2') {
326
+					foreach ($_REQUEST as $var => $val)
308 327
 				if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
309 328
 					$url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val);
329
+		}
310 330
 
311 331
 		// Start with an RSS 2.0 header.
312 332
 		echo '
@@ -327,9 +347,10 @@  discard block
 block discarded – undo
327 347
 		<language>' . $feed_meta['language'] . '</language>' : '';
328 348
 
329 349
 		// RSS2 calls for this.
330
-		if ($xml_format == 'rss2')
331
-			echo '
350
+		if ($xml_format == 'rss2') {
351
+					echo '
332 352
 		<atom:link rel="self" type="application/rss+xml" href="', $scripturl, !empty($url_parts) ? '?' . implode(';', $url_parts) : '', '" />';
353
+		}
333 354
 
334 355
 		echo $extraFeedTags_string;
335 356
 
@@ -340,12 +361,12 @@  discard block
 block discarded – undo
340 361
 		echo '
341 362
 	</channel>
342 363
 </rss>';
343
-	}
344
-	elseif ($xml_format == 'atom')
364
+	} elseif ($xml_format == 'atom')
345 365
 	{
346
-		foreach ($_REQUEST as $var => $val)
347
-			if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
366
+		foreach ($_REQUEST as $var => $val) {
367
+					if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
348 368
 				$url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val);
369
+		}
349 370
 
350 371
 		echo '
351 372
 <feed', $ns_string, !empty($feed_meta['language']) ? ' xml:lang="' . $feed_meta['language'] . '"' : '', '>
@@ -371,8 +392,7 @@  discard block
 block discarded – undo
371 392
 
372 393
 		echo '
373 394
 </feed>';
374
-	}
375
-	elseif ($xml_format == 'rdf')
395
+	} elseif ($xml_format == 'rdf')
376 396
 	{
377 397
 		echo '
378 398
 <rdf:RDF', $ns_string, '>
@@ -437,13 +457,15 @@  discard block
 block discarded – undo
437 457
 {
438 458
 	global $modSettings, $context, $scripturl;
439 459
 
440
-	if (substr($val, 0, strlen($scripturl)) != $scripturl)
441
-		return $val;
460
+	if (substr($val, 0, strlen($scripturl)) != $scripturl) {
461
+			return $val;
462
+	}
442 463
 
443 464
 	call_integration_hook('integrate_fix_url', array(&$val));
444 465
 
445
-	if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd']))
446
-		return $val;
466
+	if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) {
467
+			return $val;
468
+	}
447 469
 
448 470
 	$val = preg_replace_callback('~\b' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$~', function($m) use ($scripturl)
449 471
 		{
@@ -466,8 +488,9 @@  discard block
 block discarded – undo
466 488
 	global $smcFunc;
467 489
 
468 490
 	// Do we even need to do this?
469
-	if (strpbrk($data, '<>&') == false && $force !== true)
470
-		return $data;
491
+	if (strpbrk($data, '<>&') == false && $force !== true) {
492
+			return $data;
493
+	}
471 494
 
472 495
 	$cdata = '<![CDATA[';
473 496
 
@@ -477,49 +500,55 @@  discard block
 block discarded – undo
477 500
 			$smcFunc['strpos']($data, '&', $pos),
478 501
 			$smcFunc['strpos']($data, ']', $pos),
479 502
 		);
480
-		if ($ns != '')
481
-			$positions[] = $smcFunc['strpos']($data, '<', $pos);
503
+		if ($ns != '') {
504
+					$positions[] = $smcFunc['strpos']($data, '<', $pos);
505
+		}
482 506
 		foreach ($positions as $k => $dummy)
483 507
 		{
484
-			if ($dummy === false)
485
-				unset($positions[$k]);
508
+			if ($dummy === false) {
509
+							unset($positions[$k]);
510
+			}
486 511
 		}
487 512
 
488 513
 		$old = $pos;
489 514
 		$pos = empty($positions) ? $n : min($positions);
490 515
 
491
-		if ($pos - $old > 0)
492
-			$cdata .= $smcFunc['substr']($data, $old, $pos - $old);
493
-		if ($pos >= $n)
494
-			break;
516
+		if ($pos - $old > 0) {
517
+					$cdata .= $smcFunc['substr']($data, $old, $pos - $old);
518
+		}
519
+		if ($pos >= $n) {
520
+					break;
521
+		}
495 522
 
496 523
 		if ($smcFunc['substr']($data, $pos, 1) == '<')
497 524
 		{
498 525
 			$pos2 = $smcFunc['strpos']($data, '>', $pos);
499
-			if ($pos2 === false)
500
-				$pos2 = $n;
501
-			if ($smcFunc['substr']($data, $pos + 1, 1) == '/')
502
-				$cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA[';
503
-			else
504
-				$cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '<![CDATA[';
526
+			if ($pos2 === false) {
527
+							$pos2 = $n;
528
+			}
529
+			if ($smcFunc['substr']($data, $pos + 1, 1) == '/') {
530
+							$cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA[';
531
+			} else {
532
+							$cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '<![CDATA[';
533
+			}
505 534
 			$pos = $pos2 + 1;
506
-		}
507
-		elseif ($smcFunc['substr']($data, $pos, 1) == ']')
535
+		} elseif ($smcFunc['substr']($data, $pos, 1) == ']')
508 536
 		{
509 537
 			$cdata .= ']]>&#093;<![CDATA[';
510 538
 			$pos++;
511
-		}
512
-		elseif ($smcFunc['substr']($data, $pos, 1) == '&')
539
+		} elseif ($smcFunc['substr']($data, $pos, 1) == '&')
513 540
 		{
514 541
 			$pos2 = $smcFunc['strpos']($data, ';', $pos);
515
-			if ($pos2 === false)
516
-				$pos2 = $n;
542
+			if ($pos2 === false) {
543
+							$pos2 = $n;
544
+			}
517 545
 			$ent = $smcFunc['substr']($data, $pos + 1, $pos2 - $pos - 1);
518 546
 
519
-			if ($smcFunc['substr']($data, $pos + 1, 1) == '#')
520
-				$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
521
-			elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot')))
522
-				$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
547
+			if ($smcFunc['substr']($data, $pos + 1, 1) == '#') {
548
+							$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
549
+			} elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) {
550
+							$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
551
+			}
523 552
 
524 553
 			$pos = $pos2 + 1;
525 554
 		}
@@ -559,8 +588,9 @@  discard block
 block discarded – undo
559 588
 		'gender',
560 589
 		'blurb',
561 590
 	);
562
-	if ($xml_format != 'atom')
563
-		$keysToCdata[] = 'category';
591
+	if ($xml_format != 'atom') {
592
+			$keysToCdata[] = 'category';
593
+	}
564 594
 
565 595
 	if (!empty($forceCdataKeys))
566 596
 	{
@@ -577,8 +607,9 @@  discard block
 block discarded – undo
577 607
 		$attrs = isset($element['attributes']) ? $element['attributes'] : null;
578 608
 
579 609
 		// Skip it, it's been set to null.
580
-		if ($key === null || ($val === null && $attrs === null))
581
-			continue;
610
+		if ($key === null || ($val === null && $attrs === null)) {
611
+					continue;
612
+		}
582 613
 
583 614
 		$forceCdata = in_array($key, $forceCdataKeys);
584 615
 		$ns = !empty($nsKeys[$key]) ? $nsKeys[$key] : '';
@@ -591,16 +622,16 @@  discard block
 block discarded – undo
591 622
 
592 623
 		if (!empty($attrs))
593 624
 		{
594
-			foreach ($attrs as $attr_key => $attr_value)
595
-				echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"';
625
+			foreach ($attrs as $attr_key => $attr_value) {
626
+							echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"';
627
+			}
596 628
 		}
597 629
 
598 630
 		// If it's empty, simply output an empty element.
599 631
 		if (empty($val))
600 632
 		{
601 633
 			echo ' />';
602
-		}
603
-		else
634
+		} else
604 635
 		{
605 636
 			echo '>';
606 637
 
@@ -612,11 +643,13 @@  discard block
 block discarded – undo
612 643
 				echo "\n", str_repeat("\t", $i);
613 644
 			}
614 645
 			// A string with returns in it.... show this as a multiline element.
615
-			elseif (strpos($val, "\n") !== false)
616
-				echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i);
646
+			elseif (strpos($val, "\n") !== false) {
647
+							echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i);
648
+			}
617 649
 			// A simple string.
618
-			else
619
-				echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val);
650
+			else {
651
+							echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val);
652
+			}
620 653
 
621 654
 			// Ending tag.
622 655
 			echo '</', $key, '>';
@@ -636,8 +669,9 @@  discard block
 block discarded – undo
636 669
 {
637 670
 	global $scripturl, $smcFunc;
638 671
 
639
-	if (!allowedTo('view_mlist'))
640
-		return array();
672
+	if (!allowedTo('view_mlist')) {
673
+			return array();
674
+	}
641 675
 
642 676
 	// Find the most recent members.
643 677
 	$request = $smcFunc['db_query']('', '
@@ -656,8 +690,8 @@  discard block
 block discarded – undo
656 690
 		$guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['date_registered']) . ':member=' . $row['id_member'];
657 691
 
658 692
 		// Make the data look rss-ish.
659
-		if ($xml_format == 'rss' || $xml_format == 'rss2')
660
-			$data[] = array(
693
+		if ($xml_format == 'rss' || $xml_format == 'rss2') {
694
+					$data[] = array(
661 695
 				'tag' => 'item',
662 696
 				'content' => array(
663 697
 					array(
@@ -685,8 +719,8 @@  discard block
 block discarded – undo
685 719
 					),
686 720
 				),
687 721
 			);
688
-		elseif ($xml_format == 'rdf')
689
-			$data[] = array(
722
+		} elseif ($xml_format == 'rdf') {
723
+					$data[] = array(
690 724
 				'tag' => 'item',
691 725
 				'attributes' => array('rdf:about' => $scripturl . '?action=profile;u=' . $row['id_member']),
692 726
 				'content' => array(
@@ -704,8 +738,8 @@  discard block
 block discarded – undo
704 738
 					),
705 739
 				),
706 740
 			);
707
-		elseif ($xml_format == 'atom')
708
-			$data[] = array(
741
+		} elseif ($xml_format == 'atom') {
742
+					$data[] = array(
709 743
 				'tag' => 'entry',
710 744
 				'content' => array(
711 745
 					array(
@@ -734,9 +768,10 @@  discard block
 block discarded – undo
734 768
 					),
735 769
 				),
736 770
 			);
771
+		}
737 772
 		// More logical format for the data, but harder to apply.
738
-		else
739
-			$data[] = array(
773
+		else {
774
+					$data[] = array(
740 775
 				'tag' => 'member',
741 776
 				'content' => array(
742 777
 					array(
@@ -757,6 +792,7 @@  discard block
 block discarded – undo
757 792
 					),
758 793
 				),
759 794
 			);
795
+		}
760 796
 	}
761 797
 	$smcFunc['db_free_result']($request);
762 798
 
@@ -817,22 +853,24 @@  discard block
 block discarded – undo
817 853
 		if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
818 854
 		{
819 855
 			$smcFunc['db_free_result']($request);
820
-			if (empty($_REQUEST['boards']) && empty($board))
821
-				unset($context['optimize_msg']['lowest']);
822
-			else
823
-				$context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg';
856
+			if (empty($_REQUEST['boards']) && empty($board)) {
857
+							unset($context['optimize_msg']['lowest']);
858
+			} else {
859
+							$context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg';
860
+			}
824 861
 			$context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg';
825 862
 			$loops++;
863
+		} else {
864
+					$done = true;
826 865
 		}
827
-		else
828
-			$done = true;
829 866
 	}
830 867
 	$data = array();
831 868
 	while ($row = $smcFunc['db_fetch_assoc']($request))
832 869
 	{
833 870
 		// Limit the length of the message, if the option is set.
834
-		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
835
-			$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
871
+		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) {
872
+					$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
873
+		}
836 874
 
837 875
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
838 876
 
@@ -859,8 +897,9 @@  discard block
 block discarded – undo
859 897
 			while ($attach = $smcFunc['db_fetch_assoc']($attach_request))
860 898
 			{
861 899
 				// Include approved attachments only
862
-				if ($attach['approved'])
863
-					$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
900
+				if ($attach['approved']) {
901
+									$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
902
+				}
864 903
 			}
865 904
 			$smcFunc['db_free_result']($attach_request);
866 905
 
@@ -868,16 +907,17 @@  discard block
 block discarded – undo
868 907
 			if (!empty($loaded_attachments))
869 908
 			{
870 909
 				uasort($loaded_attachments, function($a, $b) {
871
-					if ($a['filesize'] == $b['filesize'])
872
-					        return 0;
910
+					if ($a['filesize'] == $b['filesize']) {
911
+										        return 0;
912
+					}
873 913
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
874 914
 				});
915
+			} else {
916
+							$loaded_attachments = null;
875 917
 			}
876
-			else
877
-				$loaded_attachments = null;
918
+		} else {
919
+					$loaded_attachments = null;
878 920
 		}
879
-		else
880
-			$loaded_attachments = null;
881 921
 
882 922
 		// Create a GUID for this topic using the tag URI scheme
883 923
 		$guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':topic=' . $row['id_topic'];
@@ -894,9 +934,9 @@  discard block
 block discarded – undo
894 934
 					'length' => $attachment['filesize'],
895 935
 					'type' => $attachment['mime_type'],
896 936
 				);
937
+			} else {
938
+							$enclosure = null;
897 939
 			}
898
-			else
899
-				$enclosure = null;
900 940
 
901 941
 			$data[] = array(
902 942
 				'tag' => 'item',
@@ -942,8 +982,7 @@  discard block
 block discarded – undo
942 982
 					),
943 983
 				),
944 984
 			);
945
-		}
946
-		elseif ($xml_format == 'rdf')
985
+		} elseif ($xml_format == 'rdf')
947 986
 		{
948 987
 			$data[] = array(
949 988
 				'tag' => 'item',
@@ -967,8 +1006,7 @@  discard block
 block discarded – undo
967 1006
 					),
968 1007
 				),
969 1008
 			);
970
-		}
971
-		elseif ($xml_format == 'atom')
1009
+		} elseif ($xml_format == 'atom')
972 1010
 		{
973 1011
 			// Only one attachment allowed
974 1012
 			if (!empty($loaded_attachments))
@@ -980,9 +1018,9 @@  discard block
 block discarded – undo
980 1018
 					'length' => $attachment['filesize'],
981 1019
 					'type' => $attachment['mime_type'],
982 1020
 				);
1021
+			} else {
1022
+							$enclosure = null;
983 1023
 			}
984
-			else
985
-				$enclosure = null;
986 1024
 
987 1025
 			$data[] = array(
988 1026
 				'tag' => 'entry',
@@ -1082,9 +1120,9 @@  discard block
 block discarded – undo
1082 1120
 						)
1083 1121
 					);
1084 1122
 				}
1123
+			} else {
1124
+							$attachments = null;
1085 1125
 			}
1086
-			else
1087
-				$attachments = null;
1088 1126
 
1089 1127
 			$data[] = array(
1090 1128
 				'tag' => 'article',
@@ -1202,22 +1240,25 @@  discard block
 block discarded – undo
1202 1240
 		if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
1203 1241
 		{
1204 1242
 			$smcFunc['db_free_result']($request);
1205
-			if (empty($_REQUEST['boards']) && empty($board))
1206
-				unset($context['optimize_msg']['lowest']);
1207
-			else
1208
-				$context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2';
1243
+			if (empty($_REQUEST['boards']) && empty($board)) {
1244
+							unset($context['optimize_msg']['lowest']);
1245
+			} else {
1246
+							$context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2';
1247
+			}
1209 1248
 			$loops++;
1249
+		} else {
1250
+					$done = true;
1210 1251
 		}
1211
-		else
1212
-			$done = true;
1213 1252
 	}
1214 1253
 	$messages = array();
1215
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1216
-		$messages[] = $row['id_msg'];
1254
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1255
+			$messages[] = $row['id_msg'];
1256
+	}
1217 1257
 	$smcFunc['db_free_result']($request);
1218 1258
 
1219
-	if (empty($messages))
1220
-		return array();
1259
+	if (empty($messages)) {
1260
+			return array();
1261
+	}
1221 1262
 
1222 1263
 	// Find the most recent posts this user can see.
1223 1264
 	$request = $smcFunc['db_query']('', '
@@ -1247,8 +1288,9 @@  discard block
 block discarded – undo
1247 1288
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1248 1289
 	{
1249 1290
 		// Limit the length of the message, if the option is set.
1250
-		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
1251
-			$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
1291
+		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) {
1292
+					$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
1293
+		}
1252 1294
 
1253 1295
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
1254 1296
 
@@ -1275,8 +1317,9 @@  discard block
 block discarded – undo
1275 1317
 			while ($attach = $smcFunc['db_fetch_assoc']($attach_request))
1276 1318
 			{
1277 1319
 				// Include approved attachments only
1278
-				if ($attach['approved'])
1279
-					$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
1320
+				if ($attach['approved']) {
1321
+									$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
1322
+				}
1280 1323
 			}
1281 1324
 			$smcFunc['db_free_result']($attach_request);
1282 1325
 
@@ -1284,16 +1327,17 @@  discard block
 block discarded – undo
1284 1327
 			if (!empty($loaded_attachments))
1285 1328
 			{
1286 1329
 				uasort($loaded_attachments, function($a, $b) {
1287
-					if ($a['filesize'] == $b['filesize'])
1288
-					        return 0;
1330
+					if ($a['filesize'] == $b['filesize']) {
1331
+										        return 0;
1332
+					}
1289 1333
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
1290 1334
 				});
1335
+			} else {
1336
+							$loaded_attachments = null;
1291 1337
 			}
1292
-			else
1293
-				$loaded_attachments = null;
1338
+		} else {
1339
+					$loaded_attachments = null;
1294 1340
 		}
1295
-		else
1296
-			$loaded_attachments = null;
1297 1341
 
1298 1342
 		// Create a GUID for this post using the tag URI scheme
1299 1343
 		$guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':msg=' . $row['id_msg'];
@@ -1310,9 +1354,9 @@  discard block
 block discarded – undo
1310 1354
 					'length' => $attachment['filesize'],
1311 1355
 					'type' => $attachment['mime_type'],
1312 1356
 				);
1357
+			} else {
1358
+							$enclosure = null;
1313 1359
 			}
1314
-			else
1315
-				$enclosure = null;
1316 1360
 
1317 1361
 			$data[] = array(
1318 1362
 				'tag' => 'item',
@@ -1358,8 +1402,7 @@  discard block
 block discarded – undo
1358 1402
 					),
1359 1403
 				),
1360 1404
 			);
1361
-		}
1362
-		elseif ($xml_format == 'rdf')
1405
+		} elseif ($xml_format == 'rdf')
1363 1406
 		{
1364 1407
 			$data[] = array(
1365 1408
 				'tag' => 'item',
@@ -1383,8 +1426,7 @@  discard block
 block discarded – undo
1383 1426
 					),
1384 1427
 				),
1385 1428
 			);
1386
-		}
1387
-		elseif ($xml_format == 'atom')
1429
+		} elseif ($xml_format == 'atom')
1388 1430
 		{
1389 1431
 			// Only one attachment allowed
1390 1432
 			if (!empty($loaded_attachments))
@@ -1396,9 +1438,9 @@  discard block
 block discarded – undo
1396 1438
 					'length' => $attachment['filesize'],
1397 1439
 					'type' => $attachment['mime_type'],
1398 1440
 				);
1441
+			} else {
1442
+							$enclosure = null;
1399 1443
 			}
1400
-			else
1401
-				$enclosure = null;
1402 1444
 
1403 1445
 			$data[] = array(
1404 1446
 				'tag' => 'entry',
@@ -1498,9 +1540,9 @@  discard block
 block discarded – undo
1498 1540
 						)
1499 1541
 					);
1500 1542
 				}
1543
+			} else {
1544
+							$attachments = null;
1501 1545
 			}
1502
-			else
1503
-				$attachments = null;
1504 1546
 
1505 1547
 			$data[] = array(
1506 1548
 				'tag' => 'recent-post',
@@ -1619,14 +1661,16 @@  discard block
 block discarded – undo
1619 1661
 	global $scripturl, $memberContext, $user_profile, $user_info;
1620 1662
 
1621 1663
 	// You must input a valid user....
1622
-	if (empty($_GET['u']) || !loadMemberData((int) $_GET['u']))
1623
-		return array();
1664
+	if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) {
1665
+			return array();
1666
+	}
1624 1667
 
1625 1668
 	// Make sure the id is a number and not "I like trying to hack the database".
1626 1669
 	$_GET['u'] = (int) $_GET['u'];
1627 1670
 	// Load the member's contextual information!
1628
-	if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view'))
1629
-		return array();
1671
+	if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) {
1672
+			return array();
1673
+	}
1630 1674
 
1631 1675
 	// Okay, I admit it, I'm lazy.  Stupid $_GET['u'] is long and hard to type.
1632 1676
 	$profile = &$memberContext[$_GET['u']];
@@ -1668,8 +1712,7 @@  discard block
 block discarded – undo
1668 1712
 				),
1669 1713
 			)
1670 1714
 		);
1671
-	}
1672
-	elseif ($xml_format == 'rdf')
1715
+	} elseif ($xml_format == 'rdf')
1673 1716
 	{
1674 1717
 		$data[] = array(
1675 1718
 			'tag' => 'item',
@@ -1693,8 +1736,7 @@  discard block
 block discarded – undo
1693 1736
 				),
1694 1737
 			)
1695 1738
 		);
1696
-	}
1697
-	elseif ($xml_format == 'atom')
1739
+	} elseif ($xml_format == 'atom')
1698 1740
 	{
1699 1741
 		$data[] = array(
1700 1742
 			'tag' => 'entry',
@@ -1747,8 +1789,7 @@  discard block
 block discarded – undo
1747 1789
 				),
1748 1790
 			)
1749 1791
 		);
1750
-	}
1751
-	else
1792
+	} else
1752 1793
 	{
1753 1794
 		$data = array(
1754 1795
 			array(
Please login to merge, or discard this patch.
Sources/ManageAttachments.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1542,7 +1542,7 @@  discard block
 block discarded – undo
1542 1542
 					'no_msg' => 0,
1543 1543
 					'substep' => $_GET['substep'],
1544 1544
 					'ignore_ids' => $ignore_ids,
1545
-					'attach_thumb' => array(0,3),
1545
+					'attach_thumb' => array(0, 3),
1546 1546
 				)
1547 1547
 			);
1548 1548
 			
@@ -1572,7 +1572,7 @@  discard block
 block discarded – undo
1572 1572
 					array(
1573 1573
 						'to_remove' => $to_remove,
1574 1574
 						'no_member' => 0,
1575
-						'attach_thumb' => array(0,3),
1575
+						'attach_thumb' => array(0, 3),
1576 1576
 					)
1577 1577
 				);
1578 1578
 
Please login to merge, or discard this patch.
Braces   +429 added lines, -325 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
  * The main 'Attachments and Avatars' management function.
@@ -63,10 +64,11 @@  discard block
 block discarded – undo
63 64
 	call_integration_hook('integrate_manage_attachments', array(&$subActions));
64 65
 
65 66
 	// Pick the correct sub-action.
66
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
67
-		$context['sub_action'] = $_REQUEST['sa'];
68
-	else
69
-		$context['sub_action'] = 'browse';
67
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
68
+			$context['sub_action'] = $_REQUEST['sa'];
69
+	} else {
70
+			$context['sub_action'] = 'browse';
71
+	}
70 72
 
71 73
 	// Default page title is good.
72 74
 	$context['page_title'] = $txt['attachments_avatars'];
@@ -94,20 +96,20 @@  discard block
 block discarded – undo
94 96
 	$context['attachmentUploadDir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
95 97
 
96 98
 	// If not set, show a default path for the base directory
97
-	if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments']))
98
-		if (is_dir($modSettings['attachmentUploadDir'][1]))
99
+	if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments'])) {
100
+			if (is_dir($modSettings['attachmentUploadDir'][1]))
99 101
 			$modSettings['basedirectory_for_attachments'] = $modSettings['attachmentUploadDir'][1];
100
-
101
-	else
102
-		$modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir'];
102
+	} else {
103
+			$modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir'];
104
+	}
103 105
 
104 106
 	$context['valid_upload_dir'] = is_dir($context['attachmentUploadDir']) && is_writable($context['attachmentUploadDir']);
105 107
 
106
-	if (!empty($modSettings['automanage_attachments']))
107
-		$context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']);
108
-
109
-	else
110
-		$context['valid_basedirectory'] = true;
108
+	if (!empty($modSettings['automanage_attachments'])) {
109
+			$context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']);
110
+	} else {
111
+			$context['valid_basedirectory'] = true;
112
+	}
111 113
 
112 114
 	// A bit of razzle dazzle with the $txt strings. :)
113 115
 	$txt['attachment_path'] = $context['attachmentUploadDir'];
@@ -185,8 +187,9 @@  discard block
 block discarded – undo
185 187
 
186 188
 	call_integration_hook('integrate_modify_attachment_settings', array(&$config_vars));
187 189
 
188
-	if ($return_config)
189
-		return $config_vars;
190
+	if ($return_config) {
191
+			return $config_vars;
192
+	}
190 193
 
191 194
 	// These are very likely to come in handy! (i.e. without them we're doomed!)
192 195
 	require_once($sourcedir . '/ManagePermissions.php');
@@ -197,21 +200,24 @@  discard block
 block discarded – undo
197 200
 	{
198 201
 		checkSession();
199 202
 
200
-		if (isset($_POST['attachmentUploadDir']))
201
-			unset($_POST['attachmentUploadDir']);
203
+		if (isset($_POST['attachmentUploadDir'])) {
204
+					unset($_POST['attachmentUploadDir']);
205
+		}
202 206
 
203 207
 		if (!empty($_POST['use_subdirectories_for_attachments']))
204 208
 		{
205
-			if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments']))
206
-				$_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
209
+			if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments'])) {
210
+							$_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
211
+			}
207 212
 
208 213
 			if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($modSettings['attachment_basedirectories']))
209 214
 			{
210
-				if (!is_array($modSettings['attachment_basedirectories']))
211
-					$modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true);
215
+				if (!is_array($modSettings['attachment_basedirectories'])) {
216
+									$modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true);
217
+				}
218
+			} else {
219
+							$modSettings['attachment_basedirectories'] = array();
212 220
 			}
213
-			else
214
-				$modSettings['attachment_basedirectories'] = array();
215 221
 
216 222
 			if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($_POST['basedirectory_for_attachments']) && !in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']))
217 223
 			{
@@ -219,8 +225,9 @@  discard block
 block discarded – undo
219 225
 
220 226
 				if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachmentUploadDir']))
221 227
 				{
222
-					if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments']))
223
-						$_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments'];
228
+					if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) {
229
+											$_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments'];
230
+					}
224 231
 				}
225 232
 
226 233
 				if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']))
@@ -336,8 +343,9 @@  discard block
 block discarded – undo
336 343
 
337 344
 	call_integration_hook('integrate_modify_avatar_settings', array(&$config_vars));
338 345
 
339
-	if ($return_config)
340
-		return $config_vars;
346
+	if ($return_config) {
347
+			return $config_vars;
348
+	}
341 349
 
342 350
 	// We need this file for the settings template.
343 351
 	require_once($sourcedir . '/ManageServer.php');
@@ -348,17 +356,21 @@  discard block
 block discarded – undo
348 356
 		checkSession();
349 357
 
350 358
 		// These settings cannot be left empty!
351
-		if (empty($_POST['custom_avatar_dir']))
352
-			$_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar';
359
+		if (empty($_POST['custom_avatar_dir'])) {
360
+					$_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar';
361
+		}
353 362
 
354
-		if (empty($_POST['custom_avatar_url']))
355
-			$_POST['custom_avatar_url'] = $boardurl . '/custom_avatar';
363
+		if (empty($_POST['custom_avatar_url'])) {
364
+					$_POST['custom_avatar_url'] = $boardurl . '/custom_avatar';
365
+		}
356 366
 
357
-		if (empty($_POST['avatar_directory']))
358
-			$_POST['avatar_directory'] = $boarddir . '/avatars';
367
+		if (empty($_POST['avatar_directory'])) {
368
+					$_POST['avatar_directory'] = $boarddir . '/avatars';
369
+		}
359 370
 
360
-		if (empty($_POST['avatar_url']))
361
-			$_POST['avatar_url'] = $boardurl . '/avatars';
371
+		if (empty($_POST['avatar_url'])) {
372
+					$_POST['avatar_url'] = $boardurl . '/avatars';
373
+		}
362 374
 
363 375
 		call_integration_hook('integrate_save_avatar_settings');
364 376
 
@@ -406,11 +418,13 @@  discard block
 block discarded – undo
406 418
 	$list_title = $txt['attachment_manager_browse_files'] . ': ';
407 419
 	foreach ($titles as $browse_type => $details)
408 420
 	{
409
-		if ($browse_type != 'attachments')
410
-			$list_title .= ' | ';
421
+		if ($browse_type != 'attachments') {
422
+					$list_title .= ' | ';
423
+		}
411 424
 
412
-		if ($context['browse_type'] == $browse_type)
413
-			$list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt="&gt;"> ';
425
+		if ($context['browse_type'] == $browse_type) {
426
+					$list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt="&gt;"> ';
427
+		}
414 428
 
415 429
 		$list_title .= '<a href="' . $scripturl . $details[0] . '">' . $details[1] . '</a>';
416 430
 	}
@@ -446,28 +460,33 @@  discard block
 block discarded – undo
446 460
 						$link = '<a href="';
447 461
 
448 462
 						// In case of a custom avatar URL attachments have a fixed directory.
449
-						if ($rowData['attachment_type'] == 1)
450
-							$link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']);
463
+						if ($rowData['attachment_type'] == 1) {
464
+													$link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']);
465
+						}
451 466
 
452 467
 						// By default avatars are downloaded almost as attachments.
453
-						elseif ($context['browse_type'] == 'avatars')
454
-							$link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']);
468
+						elseif ($context['browse_type'] == 'avatars') {
469
+													$link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']);
470
+						}
455 471
 
456 472
 						// Normal attachments are always linked to a topic ID.
457
-						else
458
-							$link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']);
473
+						else {
474
+													$link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']);
475
+						}
459 476
 
460 477
 						$link .= '"';
461 478
 
462 479
 						// Show a popup on click if it's a picture and we know its dimensions.
463
-						if (!empty($rowData['width']) && !empty($rowData['height']))
464
-							$link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20);
480
+						if (!empty($rowData['width']) && !empty($rowData['height'])) {
481
+													$link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20);
482
+						}
465 483
 
466 484
 						$link .= sprintf('>%1$s</a>', preg_replace('~&amp;#(\\\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\\\1;', $smcFunc['htmlspecialchars']($rowData['filename'])));
467 485
 
468 486
 						// Show the dimensions.
469
-						if (!empty($rowData['width']) && !empty($rowData['height']))
470
-							$link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']);
487
+						if (!empty($rowData['width']) && !empty($rowData['height'])) {
488
+													$link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']);
489
+						}
471 490
 
472 491
 						return $link;
473 492
 					},
@@ -500,12 +519,14 @@  discard block
 block discarded – undo
500 519
 					'function' => function($rowData) use ($scripturl, $smcFunc)
501 520
 					{
502 521
 						// In case of an attachment, return the poster of the attachment.
503
-						if (empty($rowData['id_member']))
504
-							return $smcFunc['htmlspecialchars']($rowData['poster_name']);
522
+						if (empty($rowData['id_member'])) {
523
+													return $smcFunc['htmlspecialchars']($rowData['poster_name']);
524
+						}
505 525
 
506 526
 						// Otherwise it must be an avatar, return the link to the owner of it.
507
-						else
508
-							return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']);
527
+						else {
528
+													return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']);
529
+						}
509 530
 					},
510 531
 				),
511 532
 				'sort' => array(
@@ -524,8 +545,9 @@  discard block
 block discarded – undo
524 545
 						$date = empty($rowData['poster_time']) ? $txt['never'] : timeformat($rowData['poster_time']);
525 546
 
526 547
 						// Add a link to the topic in case of an attachment.
527
-						if ($context['browse_type'] !== 'avatars')
528
-							$date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']);
548
+						if ($context['browse_type'] !== 'avatars') {
549
+													$date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']);
550
+						}
529 551
 
530 552
 						return $date;
531 553
 					},
@@ -610,8 +632,8 @@  discard block
 block discarded – undo
610 632
 	global $smcFunc, $txt;
611 633
 
612 634
 	// Choose a query depending on what we are viewing.
613
-	if ($browse_type === 'avatars')
614
-		$request = $smcFunc['db_query']('', '
635
+	if ($browse_type === 'avatars') {
636
+			$request = $smcFunc['db_query']('', '
615 637
 			SELECT
616 638
 				{string:blank_text} AS id_msg, COALESCE(mem.real_name, {string:not_applicable_text}) AS poster_name,
617 639
 				mem.last_login AS poster_time, 0 AS id_topic, a.id_member, a.id_attach, a.filename, a.file_hash, a.attachment_type,
@@ -630,8 +652,8 @@  discard block
 block discarded – undo
630 652
 				'per_page' => $items_per_page,
631 653
 			)
632 654
 		);
633
-	else
634
-		$request = $smcFunc['db_query']('', '
655
+	} else {
656
+			$request = $smcFunc['db_query']('', '
635 657
 			SELECT
636 658
 				m.id_msg, COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_topic, m.id_member,
637 659
 				a.id_attach, a.filename, a.file_hash, a.attachment_type, a.size, a.width, a.height, a.downloads, mf.subject, t.id_board
@@ -650,9 +672,11 @@  discard block
 block discarded – undo
650 672
 				'per_page' => $items_per_page,
651 673
 			)
652 674
 		);
675
+	}
653 676
 	$files = array();
654
-	while ($row = $smcFunc['db_fetch_assoc']($request))
655
-		$files[] = $row;
677
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
678
+			$files[] = $row;
679
+	}
656 680
 	$smcFunc['db_free_result']($request);
657 681
 
658 682
 	return $files;
@@ -670,8 +694,8 @@  discard block
 block discarded – undo
670 694
 	global $smcFunc;
671 695
 
672 696
 	// Depending on the type of file, different queries are used.
673
-	if ($browse_type === 'avatars')
674
-		$request = $smcFunc['db_query']('', '
697
+	if ($browse_type === 'avatars') {
698
+			$request = $smcFunc['db_query']('', '
675 699
 		SELECT COUNT(*)
676 700
 		FROM {db_prefix}attachments
677 701
 		WHERE id_member != {int:guest_id_member}',
@@ -679,8 +703,8 @@  discard block
 block discarded – undo
679 703
 			'guest_id_member' => 0,
680 704
 		)
681 705
 	);
682
-	else
683
-		$request = $smcFunc['db_query']('', '
706
+	} else {
707
+			$request = $smcFunc['db_query']('', '
684 708
 			SELECT COUNT(*) AS num_attach
685 709
 			FROM {db_prefix}attachments AS a
686 710
 				INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
@@ -693,6 +717,7 @@  discard block
 block discarded – undo
693 717
 				'guest_id_member' => 0,
694 718
 			)
695 719
 		);
720
+	}
696 721
 
697 722
 	list ($num_files) = $smcFunc['db_fetch_row']($request);
698 723
 	$smcFunc['db_free_result']($request);
@@ -775,12 +800,14 @@  discard block
 block discarded – undo
775 800
 	$current_dir_size /= 1024;
776 801
 
777 802
 	// If they specified a limit only....
778
-	if (!empty($modSettings['attachmentDirSizeLimit']))
779
-		$context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2);
803
+	if (!empty($modSettings['attachmentDirSizeLimit'])) {
804
+			$context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2);
805
+	}
780 806
 	$context['attachment_current_size'] = comma_format($current_dir_size, 2);
781 807
 
782
-	if (!empty($modSettings['attachmentDirFileLimit']))
783
-		$context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0);
808
+	if (!empty($modSettings['attachmentDirFileLimit'])) {
809
+			$context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0);
810
+	}
784 811
 	$context['attachment_current_files'] = comma_format($current_dir_files, 0);
785 812
 
786 813
 	$context['attach_multiple_dirs'] = count($attach_dirs) > 1 ? true : false;
@@ -817,8 +844,8 @@  discard block
 block discarded – undo
817 844
 		$messages = removeAttachments(array('attachment_type' => 0, 'poster_time' => (time() - 24 * 60 * 60 * $_POST['age'])), 'messages', true);
818 845
 
819 846
 		// Update the messages to reflect the change.
820
-		if (!empty($messages) && !empty($_POST['notice']))
821
-			$smcFunc['db_query']('', '
847
+		if (!empty($messages) && !empty($_POST['notice'])) {
848
+					$smcFunc['db_query']('', '
822 849
 				UPDATE {db_prefix}messages
823 850
 				SET body = CONCAT(body, {string:notice})
824 851
 				WHERE id_msg IN ({array_int:messages})',
@@ -827,8 +854,8 @@  discard block
 block discarded – undo
827 854
 					'notice' => '<br><br>' . $_POST['notice'],
828 855
 				)
829 856
 			);
830
-	}
831
-	else
857
+		}
858
+	} else
832 859
 	{
833 860
 		// Remove all the old avatars.
834 861
 		removeAttachments(array('not_id_member' => 0, 'last_login' => (time() - 24 * 60 * 60 * $_POST['age'])), 'members');
@@ -853,8 +880,8 @@  discard block
 block discarded – undo
853 880
 	$messages = removeAttachments(array('attachment_type' => 0, 'size' => 1024 * $_POST['size']), 'messages', true);
854 881
 
855 882
 	// And make a note on the post.
856
-	if (!empty($messages) && !empty($_POST['notice']))
857
-		$smcFunc['db_query']('', '
883
+	if (!empty($messages) && !empty($_POST['notice'])) {
884
+			$smcFunc['db_query']('', '
858 885
 			UPDATE {db_prefix}messages
859 886
 			SET body = CONCAT(body, {string:notice})
860 887
 			WHERE id_msg IN ({array_int:messages})',
@@ -863,6 +890,7 @@  discard block
 block discarded – undo
863 890
 				'notice' => '<br><br>' . $_POST['notice'],
864 891
 			)
865 892
 		);
893
+	}
866 894
 
867 895
 	redirectexit('action=admin;area=manageattachments;sa=maintenance');
868 896
 }
@@ -882,16 +910,17 @@  discard block
 block discarded – undo
882 910
 	{
883 911
 		$attachments = array();
884 912
 		// There must be a quicker way to pass this safety test??
885
-		foreach ($_POST['remove'] as $removeID => $dummy)
886
-			$attachments[] = (int) $removeID;
913
+		foreach ($_POST['remove'] as $removeID => $dummy) {
914
+					$attachments[] = (int) $removeID;
915
+		}
887 916
 
888 917
 		// If the attachments are from a 3rd party, let them remove it. Hooks should remove their ids from the array.
889 918
 		$filesRemoved = false;
890 919
 		call_integration_hook('integrate_attachment_remove', array(&$filesRemoved, $attachments));
891 920
 
892
-		if ($_REQUEST['type'] == 'avatars' && !empty($attachments))
893
-			removeAttachments(array('id_attach' => $attachments));
894
-		else if (!empty($attachments))
921
+		if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) {
922
+					removeAttachments(array('id_attach' => $attachments));
923
+		} else if (!empty($attachments))
895 924
 		{
896 925
 			$messages = removeAttachments(array('id_attach' => $attachments), 'messages', true);
897 926
 
@@ -930,12 +959,13 @@  discard block
 block discarded – undo
930 959
 
931 960
 	$messages = removeAttachments(array('attachment_type' => 0), '', true);
932 961
 
933
-	if (!isset($_POST['notice']))
934
-		$_POST['notice'] = $txt['attachment_delete_admin'];
962
+	if (!isset($_POST['notice'])) {
963
+			$_POST['notice'] = $txt['attachment_delete_admin'];
964
+	}
935 965
 
936 966
 	// Add the notice on the end of the changed messages.
937
-	if (!empty($messages))
938
-		$smcFunc['db_query']('', '
967
+	if (!empty($messages)) {
968
+			$smcFunc['db_query']('', '
939 969
 			UPDATE {db_prefix}messages
940 970
 			SET body = CONCAT(body, {string:deleted_message})
941 971
 			WHERE id_msg IN ({array_int:messages})',
@@ -944,6 +974,7 @@  discard block
 block discarded – undo
944 974
 				'deleted_message' => '<br><br>' . $_POST['notice'],
945 975
 			)
946 976
 		);
977
+	}
947 978
 
948 979
 	redirectexit('action=admin;area=manageattachments;sa=maintenance');
949 980
 }
@@ -982,24 +1013,26 @@  discard block
 block discarded – undo
982 1013
 			$is_not = substr($real_type, 0, 4) == 'not_';
983 1014
 			$type = $is_not ? substr($real_type, 4) : $real_type;
984 1015
 
985
-			if (in_array($type, array('id_member', 'id_attach', 'id_msg')))
986
-				$new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')';
987
-			elseif ($type == 'attachment_type')
988
-				$new_condition[] = 'a.attachment_type = {int:' . $real_type . '}';
989
-			elseif ($type == 'poster_time')
990
-				$new_condition[] = 'm.poster_time < {int:' . $real_type . '}';
991
-			elseif ($type == 'last_login')
992
-				$new_condition[] = 'mem.last_login < {int:' . $real_type . '}';
993
-			elseif ($type == 'size')
994
-				$new_condition[] = 'a.size > {int:' . $real_type . '}';
995
-			elseif ($type == 'id_topic')
996
-				$new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')';
1016
+			if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) {
1017
+							$new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')';
1018
+			} elseif ($type == 'attachment_type') {
1019
+							$new_condition[] = 'a.attachment_type = {int:' . $real_type . '}';
1020
+			} elseif ($type == 'poster_time') {
1021
+							$new_condition[] = 'm.poster_time < {int:' . $real_type . '}';
1022
+			} elseif ($type == 'last_login') {
1023
+							$new_condition[] = 'mem.last_login < {int:' . $real_type . '}';
1024
+			} elseif ($type == 'size') {
1025
+							$new_condition[] = 'a.size > {int:' . $real_type . '}';
1026
+			} elseif ($type == 'id_topic') {
1027
+							$new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')';
1028
+			}
997 1029
 
998 1030
 			// Add the parameter!
999 1031
 			$query_parameter[$real_type] = $restriction;
1000 1032
 
1001
-			if ($type == 'do_logging')
1002
-				$do_logging = $condition['id_attach'];
1033
+			if ($type == 'do_logging') {
1034
+							$do_logging = $condition['id_attach'];
1035
+			}
1003 1036
 		}
1004 1037
 		$condition = implode(' AND ', $new_condition);
1005 1038
 	}
@@ -1031,15 +1064,15 @@  discard block
 block discarded – undo
1031 1064
 			// wasn't it obvious? :P
1032 1065
 			// @todo look again at this.
1033 1066
 			@unlink($modSettings['custom_avatar_dir'] . '/' . $row['filename']);
1034
-		}
1035
-		else
1067
+		} else
1036 1068
 		{
1037 1069
 			$filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
1038 1070
 			@unlink($filename);
1039 1071
 
1040 1072
 			// If this was a thumb, the parent attachment should know about it.
1041
-			if (!empty($row['id_parent']))
1042
-				$parents[] = $row['id_parent'];
1073
+			if (!empty($row['id_parent'])) {
1074
+							$parents[] = $row['id_parent'];
1075
+			}
1043 1076
 
1044 1077
 			// If this attachments has a thumb, remove it as well.
1045 1078
 			if (!empty($row['id_thumb']) && $autoThumbRemoval)
@@ -1051,8 +1084,9 @@  discard block
 block discarded – undo
1051 1084
 		}
1052 1085
 
1053 1086
 		// Make a list.
1054
-		if ($return_affected_messages && empty($row['attachment_type']))
1055
-			$msgs[] = $row['id_msg'];
1087
+		if ($return_affected_messages && empty($row['attachment_type'])) {
1088
+					$msgs[] = $row['id_msg'];
1089
+		}
1056 1090
 
1057 1091
 		$attach[] = $row['id_attach'];
1058 1092
 	}
@@ -1060,8 +1094,8 @@  discard block
 block discarded – undo
1060 1094
 
1061 1095
 	// Removed attachments don't have to be updated anymore.
1062 1096
 	$parents = array_diff($parents, $attach);
1063
-	if (!empty($parents))
1064
-		$smcFunc['db_query']('', '
1097
+	if (!empty($parents)) {
1098
+			$smcFunc['db_query']('', '
1065 1099
 			UPDATE {db_prefix}attachments
1066 1100
 			SET id_thumb = {int:no_thumb}
1067 1101
 			WHERE id_attach IN ({array_int:parent_attachments})',
@@ -1070,6 +1104,7 @@  discard block
 block discarded – undo
1070 1104
 				'no_thumb' => 0,
1071 1105
 			)
1072 1106
 		);
1107
+	}
1073 1108
 
1074 1109
 	if (!empty($do_logging))
1075 1110
 	{
@@ -1086,31 +1121,34 @@  discard block
 block discarded – undo
1086 1121
 			)
1087 1122
 		);
1088 1123
 
1089
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1090
-			logAction(
1124
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1125
+					logAction(
1091 1126
 				'remove_attach',
1092 1127
 				array(
1093 1128
 					'message' => $row['id_msg'],
1094 1129
 					'filename' => preg_replace('~&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])),
1095 1130
 				)
1096 1131
 			);
1132
+		}
1097 1133
 		$smcFunc['db_free_result']($request);
1098 1134
 	}
1099 1135
 
1100
-	if (!empty($attach))
1101
-		$smcFunc['db_query']('', '
1136
+	if (!empty($attach)) {
1137
+			$smcFunc['db_query']('', '
1102 1138
 			DELETE FROM {db_prefix}attachments
1103 1139
 			WHERE id_attach IN ({array_int:attachment_list})',
1104 1140
 			array(
1105 1141
 				'attachment_list' => $attach,
1106 1142
 			)
1107 1143
 		);
1144
+	}
1108 1145
 
1109 1146
 	call_integration_hook('integrate_remove_attachments', array($attach));
1110 1147
 
1111
-	if ($return_affected_messages)
1112
-		return array_unique($msgs);
1113
-}
1148
+	if ($return_affected_messages) {
1149
+			return array_unique($msgs);
1150
+	}
1151
+	}
1114 1152
 
1115 1153
 /**
1116 1154
  * This function should find attachments in the database that no longer exist and clear them, and fix filesize issues.
@@ -1122,8 +1160,9 @@  discard block
 block discarded – undo
1122 1160
 	checkSession('get');
1123 1161
 
1124 1162
 	// If we choose cancel, redirect right back.
1125
-	if (isset($_POST['cancel']))
1126
-		redirectexit('action=admin;area=manageattachments;sa=maintenance');
1163
+	if (isset($_POST['cancel'])) {
1164
+			redirectexit('action=admin;area=manageattachments;sa=maintenance');
1165
+	}
1127 1166
 
1128 1167
 	// Try give us a while to sort this out...
1129 1168
 	@set_time_limit(600);
@@ -1140,13 +1179,15 @@  discard block
 block discarded – undo
1140 1179
 		if (isset($_GET['fixErrors']))
1141 1180
 		{
1142 1181
 			// Nothing?
1143
-			if (empty($_POST['to_fix']))
1144
-				redirectexit('action=admin;area=manageattachments;sa=maintenance');
1182
+			if (empty($_POST['to_fix'])) {
1183
+							redirectexit('action=admin;area=manageattachments;sa=maintenance');
1184
+			}
1145 1185
 
1146 1186
 			$_SESSION['attachments_to_fix'] = array();
1147 1187
 			// @todo No need to do this I think.
1148
-			foreach ($_POST['to_fix'] as $value)
1149
-				$_SESSION['attachments_to_fix'][] = $value;
1188
+			foreach ($_POST['to_fix'] as $value) {
1189
+							$_SESSION['attachments_to_fix'][] = $value;
1190
+			}
1150 1191
 		}
1151 1192
 	}
1152 1193
 
@@ -1213,13 +1254,14 @@  discard block
 block discarded – undo
1213 1254
 					}
1214 1255
 				}
1215 1256
 			}
1216
-			if ($smcFunc['db_num_rows']($result) != 0)
1217
-				$to_fix[] = 'missing_thumbnail_parent';
1257
+			if ($smcFunc['db_num_rows']($result) != 0) {
1258
+							$to_fix[] = 'missing_thumbnail_parent';
1259
+			}
1218 1260
 			$smcFunc['db_free_result']($result);
1219 1261
 
1220 1262
 			// Do we need to delete what we have?
1221
-			if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix))
1222
-				$smcFunc['db_query']('', '
1263
+			if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) {
1264
+							$smcFunc['db_query']('', '
1223 1265
 					DELETE FROM {db_prefix}attachments
1224 1266
 					WHERE id_attach IN ({array_int:to_remove})
1225 1267
 						AND attachment_type = {int:attachment_type}',
@@ -1228,6 +1270,7 @@  discard block
 block discarded – undo
1228 1270
 						'attachment_type' => 3,
1229 1271
 					)
1230 1272
 				);
1273
+			}
1231 1274
 
1232 1275
 			pauseAttachmentMaintenance($to_fix, $thumbnails);
1233 1276
 		}
@@ -1272,13 +1315,14 @@  discard block
 block discarded – undo
1272 1315
 				$to_update[] = $row['id_attach'];
1273 1316
 				$context['repair_errors']['parent_missing_thumbnail']++;
1274 1317
 			}
1275
-			if ($smcFunc['db_num_rows']($result) != 0)
1276
-				$to_fix[] = 'parent_missing_thumbnail';
1318
+			if ($smcFunc['db_num_rows']($result) != 0) {
1319
+							$to_fix[] = 'parent_missing_thumbnail';
1320
+			}
1277 1321
 			$smcFunc['db_free_result']($result);
1278 1322
 
1279 1323
 			// Do we need to delete what we have?
1280
-			if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix))
1281
-				$smcFunc['db_query']('', '
1324
+			if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) {
1325
+							$smcFunc['db_query']('', '
1282 1326
 					UPDATE {db_prefix}attachments
1283 1327
 					SET id_thumb = {int:no_thumb}
1284 1328
 					WHERE id_attach IN ({array_int:to_update})',
@@ -1287,6 +1331,7 @@  discard block
 block discarded – undo
1287 1331
 						'no_thumb' => 0,
1288 1332
 					)
1289 1333
 				);
1334
+			}
1290 1335
 
1291 1336
 			pauseAttachmentMaintenance($to_fix, $thumbnails);
1292 1337
 		}
@@ -1324,10 +1369,11 @@  discard block
 block discarded – undo
1324 1369
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1325 1370
 			{
1326 1371
 				// Get the filename.
1327
-				if ($row['attachment_type'] == 1)
1328
-					$filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename'];
1329
-				else
1330
-					$filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
1372
+				if ($row['attachment_type'] == 1) {
1373
+									$filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename'];
1374
+				} else {
1375
+									$filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
1376
+				}
1331 1377
 
1332 1378
 				// File doesn't exist?
1333 1379
 				if (!file_exists($filename))
@@ -1339,15 +1385,16 @@  discard block
 block discarded – undo
1339 1385
 						$attachment_name = $row['id_attach'] . '_' . $row['file_hash'] . '.dat';
1340 1386
 
1341 1387
 						// Loop through the other folders.
1342
-						foreach ($modSettings['attachmentUploadDir'] as $id => $dir)
1343
-							if (file_exists($dir . '/' . $attachment_name))
1388
+						foreach ($modSettings['attachmentUploadDir'] as $id => $dir) {
1389
+													if (file_exists($dir . '/' . $attachment_name))
1344 1390
 							{
1345 1391
 								$context['repair_errors']['wrong_folder']++;
1392
+						}
1346 1393
 								$errors_found[] = 'wrong_folder';
1347 1394
 
1348 1395
 								// Are we going to fix this now?
1349
-								if ($fix_errors && in_array('wrong_folder', $to_fix))
1350
-									$smcFunc['db_query']('', '
1396
+								if ($fix_errors && in_array('wrong_folder', $to_fix)) {
1397
+																	$smcFunc['db_query']('', '
1351 1398
 										UPDATE {db_prefix}attachments
1352 1399
 										SET id_folder = {int:new_folder}
1353 1400
 										WHERE id_attach = {int:id_attach}',
@@ -1356,6 +1403,7 @@  discard block
 block discarded – undo
1356 1403
 											'id_attach' => $row['id_attach'],
1357 1404
 										)
1358 1405
 									);
1406
+								}
1359 1407
 
1360 1408
 								continue 2;
1361 1409
 							}
@@ -1364,8 +1412,7 @@  discard block
 block discarded – undo
1364 1412
 					$to_remove[] = $row['id_attach'];
1365 1413
 					$context['repair_errors']['file_missing_on_disk']++;
1366 1414
 					$errors_found[] = 'file_missing_on_disk';
1367
-				}
1368
-				elseif (filesize($filename) == 0)
1415
+				} elseif (filesize($filename) == 0)
1369 1416
 				{
1370 1417
 					$context['repair_errors']['file_size_of_zero']++;
1371 1418
 					$errors_found[] = 'file_size_of_zero';
@@ -1376,8 +1423,7 @@  discard block
 block discarded – undo
1376 1423
 						$to_remove[] = $row['id_attach'];
1377 1424
 						@unlink($filename);
1378 1425
 					}
1379
-				}
1380
-				elseif (filesize($filename) != $row['size'])
1426
+				} elseif (filesize($filename) != $row['size'])
1381 1427
 				{
1382 1428
 					$context['repair_errors']['file_wrong_size']++;
1383 1429
 					$errors_found[] = 'file_wrong_size';
@@ -1398,14 +1444,18 @@  discard block
 block discarded – undo
1398 1444
 				}
1399 1445
 			}
1400 1446
 
1401
-			if (in_array('file_missing_on_disk', $errors_found))
1402
-				$to_fix[] = 'file_missing_on_disk';
1403
-			if (in_array('file_size_of_zero', $errors_found))
1404
-				$to_fix[] = 'file_size_of_zero';
1405
-			if (in_array('file_wrong_size', $errors_found))
1406
-				$to_fix[] = 'file_wrong_size';
1407
-			if (in_array('wrong_folder', $errors_found))
1408
-				$to_fix[] = 'wrong_folder';
1447
+			if (in_array('file_missing_on_disk', $errors_found)) {
1448
+							$to_fix[] = 'file_missing_on_disk';
1449
+			}
1450
+			if (in_array('file_size_of_zero', $errors_found)) {
1451
+							$to_fix[] = 'file_size_of_zero';
1452
+			}
1453
+			if (in_array('file_wrong_size', $errors_found)) {
1454
+							$to_fix[] = 'file_wrong_size';
1455
+			}
1456
+			if (in_array('wrong_folder', $errors_found)) {
1457
+							$to_fix[] = 'wrong_folder';
1458
+			}
1409 1459
 			$smcFunc['db_free_result']($result);
1410 1460
 
1411 1461
 			// Do we need to delete what we have?
@@ -1475,20 +1525,22 @@  discard block
 block discarded – undo
1475 1525
 				// If we are repairing remove the file from disk now.
1476 1526
 				if ($fix_errors && in_array('avatar_no_member', $to_fix))
1477 1527
 				{
1478
-					if ($row['attachment_type'] == 1)
1479
-						$filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename'];
1480
-					else
1481
-						$filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
1528
+					if ($row['attachment_type'] == 1) {
1529
+											$filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename'];
1530
+					} else {
1531
+											$filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
1532
+					}
1482 1533
 					@unlink($filename);
1483 1534
 				}
1484 1535
 			}
1485
-			if ($smcFunc['db_num_rows']($result) != 0)
1486
-				$to_fix[] = 'avatar_no_member';
1536
+			if ($smcFunc['db_num_rows']($result) != 0) {
1537
+							$to_fix[] = 'avatar_no_member';
1538
+			}
1487 1539
 			$smcFunc['db_free_result']($result);
1488 1540
 
1489 1541
 			// Do we need to delete what we have?
1490
-			if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix))
1491
-				$smcFunc['db_query']('', '
1542
+			if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) {
1543
+							$smcFunc['db_query']('', '
1492 1544
 					DELETE FROM {db_prefix}attachments
1493 1545
 					WHERE id_attach IN ({array_int:to_remove})
1494 1546
 						AND id_member != {int:no_member}
@@ -1499,6 +1551,7 @@  discard block
 block discarded – undo
1499 1551
 						'no_msg' => 0,
1500 1552
 					)
1501 1553
 				);
1554
+			}
1502 1555
 
1503 1556
 			pauseAttachmentMaintenance($to_fix, $thumbnails);
1504 1557
 		}
@@ -1558,13 +1611,14 @@  discard block
 block discarded – undo
1558 1611
 					@unlink($filename);
1559 1612
 				}
1560 1613
 			}
1561
-			if ($smcFunc['db_num_rows']($result) != 0)
1562
-				$to_fix[] = 'attachment_no_msg';
1614
+			if ($smcFunc['db_num_rows']($result) != 0) {
1615
+							$to_fix[] = 'attachment_no_msg';
1616
+			}
1563 1617
 			$smcFunc['db_free_result']($result);
1564 1618
 
1565 1619
 			// Do we need to delete what we have?
1566
-			if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix))
1567
-				$smcFunc['db_query']('', '
1620
+			if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) {
1621
+							$smcFunc['db_query']('', '
1568 1622
 					DELETE FROM {db_prefix}attachments
1569 1623
 					WHERE id_attach IN ({array_int:to_remove})
1570 1624
 						AND id_member = {int:no_member}
@@ -1575,6 +1629,7 @@  discard block
 block discarded – undo
1575 1629
 						'attach_thumb' => array(0,3),
1576 1630
 					)
1577 1631
 				);
1632
+			}
1578 1633
 
1579 1634
 			pauseAttachmentMaintenance($to_fix, $thumbnails);
1580 1635
 		}
@@ -1598,8 +1653,9 @@  discard block
 block discarded – undo
1598 1653
 			{
1599 1654
 				while ($file = readdir($dir))
1600 1655
 				{
1601
-					if (in_array($file, array('.', '..', '.htaccess', 'index.php')))
1602
-						continue;
1656
+					if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) {
1657
+											continue;
1658
+					}
1603 1659
 
1604 1660
 					if ($files_checked <= $current_check)
1605 1661
 					{
@@ -1607,8 +1663,9 @@  discard block
 block discarded – undo
1607 1663
 						if (strpos($file, 'post_tmp_') !== false)
1608 1664
 						{
1609 1665
 							// Temp file is more than 5 hours old!
1610
-							if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1611
-								@unlink($attach_dir . '/' . $file);
1666
+							if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1667
+															@unlink($attach_dir . '/' . $file);
1668
+							}
1612 1669
 						}
1613 1670
 						// That should be an attachment, let's check if we have it in the database
1614 1671
 						elseif (strpos($file, '_') !== false)
@@ -1630,8 +1687,7 @@  discard block
 block discarded – undo
1630 1687
 									if ($fix_errors && in_array('files_without_attachment', $to_fix))
1631 1688
 									{
1632 1689
 										@unlink($attach_dir . '/' . $file);
1633
-									}
1634
-									else
1690
+									} else
1635 1691
 									{
1636 1692
 										$context['repair_errors']['files_without_attachment']++;
1637 1693
 										$to_fix[] = 'files_without_attachment';
@@ -1639,14 +1695,12 @@  discard block
 block discarded – undo
1639 1695
 								}
1640 1696
 								$smcFunc['db_free_result']($request);
1641 1697
 							}
1642
-						}
1643
-						else
1698
+						} else
1644 1699
 						{
1645 1700
 							if ($fix_errors && in_array('files_without_attachment', $to_fix))
1646 1701
 							{
1647 1702
 								@unlink($attach_dir . '/' . $file);
1648
-							}
1649
-							else
1703
+							} else
1650 1704
 							{
1651 1705
 								$context['repair_errors']['files_without_attachment']++;
1652 1706
 								$to_fix[] = 'files_without_attachment';
@@ -1655,8 +1709,9 @@  discard block
 block discarded – undo
1655 1709
 					}
1656 1710
 					$current_check++;
1657 1711
 					$_GET['substep'] = $current_check;
1658
-					if ($current_check - $files_checked >= $max_checks)
1659
-						pauseAttachmentMaintenance($to_fix);
1712
+					if ($current_check - $files_checked >= $max_checks) {
1713
+											pauseAttachmentMaintenance($to_fix);
1714
+					}
1660 1715
 				}
1661 1716
 				closedir($dir);
1662 1717
 			}
@@ -1692,12 +1747,14 @@  discard block
 block discarded – undo
1692 1747
 
1693 1748
 	// Try get more time...
1694 1749
 	@set_time_limit(600);
1695
-	if (function_exists('apache_reset_timeout'))
1696
-		@apache_reset_timeout();
1750
+	if (function_exists('apache_reset_timeout')) {
1751
+			@apache_reset_timeout();
1752
+	}
1697 1753
 
1698 1754
 	// Have we already used our maximum time?
1699
-	if ((time() - $time_start) < 3 || $context['starting_substep'] == $_GET['substep'])
1700
-		return;
1755
+	if ((time() - $time_start) < 3 || $context['starting_substep'] == $_GET['substep']) {
1756
+			return;
1757
+	}
1701 1758
 
1702 1759
 	$context['continue_get_data'] = '?action=admin;area=manageattachments;sa=repair' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1703 1760
 	$context['page_title'] = $txt['not_done_title'];
@@ -1709,10 +1766,11 @@  discard block
 block discarded – undo
1709 1766
 	$context[$context['admin_menu_name']]['current_subsection'] = 'maintenance';
1710 1767
 
1711 1768
 	// Change these two if more steps are added!
1712
-	if (empty($max_substep))
1713
-		$context['continue_percent'] = round(($_GET['step'] * 100) / 25);
1714
-	else
1715
-		$context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25);
1769
+	if (empty($max_substep)) {
1770
+			$context['continue_percent'] = round(($_GET['step'] * 100) / 25);
1771
+	} else {
1772
+			$context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25);
1773
+	}
1716 1774
 
1717 1775
 	// Never more than 100%!
1718 1776
 	$context['continue_percent'] = min($context['continue_percent'], 100);
@@ -1754,15 +1812,17 @@  discard block
 block discarded – undo
1754 1812
 				'attachment_type' => 0,
1755 1813
 			)
1756 1814
 		);
1757
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1758
-			$attachments[] = $row['id_attach'];
1815
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1816
+					$attachments[] = $row['id_attach'];
1817
+		}
1759 1818
 		$smcFunc['db_free_result']($request);
1819
+	} elseif (!empty($_GET['aid'])) {
1820
+			$attachments[] = (int) $_GET['aid'];
1760 1821
 	}
1761
-	elseif (!empty($_GET['aid']))
1762
-		$attachments[] = (int) $_GET['aid'];
1763 1822
 
1764
-	if (empty($attachments))
1765
-		fatal_lang_error('no_access', false);
1823
+	if (empty($attachments)) {
1824
+			fatal_lang_error('no_access', false);
1825
+	}
1766 1826
 
1767 1827
 	// Now we have some ID's cleaned and ready to approve, but first - let's check we have permission!
1768 1828
 	$allowed_boards = boardsAllowedTo('approve_posts');
@@ -1795,17 +1855,18 @@  discard block
 block discarded – undo
1795 1855
 	}
1796 1856
 	$smcFunc['db_free_result']($request);
1797 1857
 
1798
-	if (empty($attachments))
1799
-		fatal_lang_error('no_access', false);
1858
+	if (empty($attachments)) {
1859
+			fatal_lang_error('no_access', false);
1860
+	}
1800 1861
 
1801 1862
 	// Finally, we are there. Follow through!
1802 1863
 	if ($is_approve)
1803 1864
 	{
1804 1865
 		// Checked and deemed worthy.
1805 1866
 		ApproveAttachments($attachments);
1867
+	} else {
1868
+			removeAttachments(array('id_attach' => $attachments, 'do_logging' => true));
1806 1869
 	}
1807
-	else
1808
-		removeAttachments(array('id_attach' => $attachments, 'do_logging' => true));
1809 1870
 
1810 1871
 	// Return to the topic....
1811 1872
 	redirectexit($redirect);
@@ -1821,8 +1882,9 @@  discard block
 block discarded – undo
1821 1882
 {
1822 1883
 	global $smcFunc;
1823 1884
 
1824
-	if (empty($attachments))
1825
-		return 0;
1885
+	if (empty($attachments)) {
1886
+			return 0;
1887
+	}
1826 1888
 
1827 1889
 	// For safety, check for thumbnails...
1828 1890
 	$request = $smcFunc['db_query']('', '
@@ -1841,15 +1903,17 @@  discard block
 block discarded – undo
1841 1903
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1842 1904
 	{
1843 1905
 		// Update the thumbnail too...
1844
-		if (!empty($row['id_thumb']))
1845
-			$attachments[] = $row['id_thumb'];
1906
+		if (!empty($row['id_thumb'])) {
1907
+					$attachments[] = $row['id_thumb'];
1908
+		}
1846 1909
 
1847 1910
 		$attachments[] = $row['id_attach'];
1848 1911
 	}
1849 1912
 	$smcFunc['db_free_result']($request);
1850 1913
 
1851
-	if (empty($attachments))
1852
-		return 0;
1914
+	if (empty($attachments)) {
1915
+			return 0;
1916
+	}
1853 1917
 
1854 1918
 	// Approving an attachment is not hard - it's easy.
1855 1919
 	$smcFunc['db_query']('', '
@@ -1875,14 +1939,15 @@  discard block
 block discarded – undo
1875 1939
 		)
1876 1940
 	);
1877 1941
 
1878
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1879
-		logAction(
1942
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1943
+			logAction(
1880 1944
 			'approve_attach',
1881 1945
 			array(
1882 1946
 				'message' => $row['id_msg'],
1883 1947
 				'filename' => preg_replace('~&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])),
1884 1948
 			)
1885 1949
 		);
1950
+	}
1886 1951
 	$smcFunc['db_free_result']($request);
1887 1952
 
1888 1953
 	// Remove from the approval queue.
@@ -1905,11 +1970,11 @@  discard block
 block discarded – undo
1905 1970
 	global $modSettings, $scripturl, $context, $txt, $sourcedir, $boarddir, $smcFunc, $settings;
1906 1971
 
1907 1972
 	// Since this needs to be done eventually.
1908
-	if (!isset($modSettings['attachment_basedirectories']))
1909
-		$modSettings['attachment_basedirectories'] = array();
1910
-
1911
-	elseif (!is_array($modSettings['attachment_basedirectories']))
1912
-		$modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true);
1973
+	if (!isset($modSettings['attachment_basedirectories'])) {
1974
+			$modSettings['attachment_basedirectories'] = array();
1975
+	} elseif (!is_array($modSettings['attachment_basedirectories'])) {
1976
+			$modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true);
1977
+	}
1913 1978
 
1914 1979
 	$errors = array();
1915 1980
 
@@ -1924,8 +1989,9 @@  discard block
 block discarded – undo
1924 1989
 		{
1925 1990
 			$error = '';
1926 1991
 			$id = (int) $id;
1927
-			if ($id < 1)
1928
-				continue;
1992
+			if ($id < 1) {
1993
+							continue;
1994
+			}
1929 1995
 
1930 1996
 			// Sorry, these dirs are NOT valid
1931 1997
 			$invalid_dirs = array($boarddir, $settings['default_theme_dir'], $sourcedir);
@@ -1944,8 +2010,7 @@  discard block
 block discarded – undo
1944 2010
 				{
1945 2011
 						$errors[] = $path . ': ' . $txt['attach_dir_duplicate_msg'];
1946 2012
 						continue;
1947
-				}
1948
-				elseif (empty($path))
2013
+				} elseif (empty($path))
1949 2014
 				{
1950 2015
 					// Ignore this and set $id to one less
1951 2016
 					continue;
@@ -1953,10 +2018,11 @@  discard block
 block discarded – undo
1953 2018
 
1954 2019
 				// OK, so let's try to create it then.
1955 2020
 				require_once($sourcedir . '/Subs-Attachments.php');
1956
-				if (automanage_attachments_create_directory($path))
1957
-					$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
1958
-				else
1959
-					$errors[] = $path . ': ' . $txt[$context['dir_creation_error']];
2021
+				if (automanage_attachments_create_directory($path)) {
2022
+									$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
2023
+				} else {
2024
+									$errors[] = $path . ': ' . $txt[$context['dir_creation_error']];
2025
+				}
1960 2026
 			}
1961 2027
 
1962 2028
 			// Changing a directory name?
@@ -1969,8 +2035,7 @@  discard block
 block discarded – undo
1969 2035
 						$errors[] = $path . ': ' . $txt['attach_dir_no_rename'];
1970 2036
 						$path = $modSettings['attachmentUploadDir'][$id];
1971 2037
 					}
1972
-				}
1973
-				else
2038
+				} else
1974 2039
 				{
1975 2040
 					$errors[] = $path . ': ' . $txt['attach_dir_exists_msg'];
1976 2041
 					$path = $modSettings['attachmentUploadDir'][$id];
@@ -1995,12 +2060,13 @@  discard block
 block discarded – undo
1995 2060
 				$path = $modSettings['attachmentUploadDir'][$id];
1996 2061
 
1997 2062
 				// It's not a good idea to delete the current directory.
1998
-				if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir']))
1999
-					$errors[] = $path . ': ' . $txt['attach_dir_is_current'];
2063
+				if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) {
2064
+									$errors[] = $path . ': ' . $txt['attach_dir_is_current'];
2065
+				}
2000 2066
 				// Or the current base directory
2001
-				elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id])
2002
-					$errors[] = $path . ': ' . $txt['attach_dir_is_current_bd'];
2003
-				else
2067
+				elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) {
2068
+									$errors[] = $path . ': ' . $txt['attach_dir_is_current_bd'];
2069
+				} else
2004 2070
 				{
2005 2071
 					// Let's not try to delete a path with files in it.
2006 2072
 					$request = $smcFunc['db_query']('', '
@@ -2019,17 +2085,18 @@  discard block
 block discarded – undo
2019 2085
 					if (!empty($modSettings['attachment_basedirectories']))
2020 2086
 					{
2021 2087
 						// Count any sub-folders.
2022
-						foreach ($modSettings['attachmentUploadDir'] as $sub)
2023
-							if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false)
2088
+						foreach ($modSettings['attachmentUploadDir'] as $sub) {
2089
+													if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false)
2024 2090
 								$num_attach++;
2091
+						}
2025 2092
 					}
2026 2093
 
2027 2094
 					// It's safe to delete. So try to delete the folder also
2028 2095
 					if ($num_attach == 0)
2029 2096
 					{
2030
-						if (is_dir($path))
2031
-							$doit = true;
2032
-						elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path))
2097
+						if (is_dir($path)) {
2098
+													$doit = true;
2099
+						} elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path))
2033 2100
 						{
2034 2101
 							$doit = true;
2035 2102
 							$path = $boarddir . DIRECTORY_SEPARATOR . $path;
@@ -2039,8 +2106,9 @@  discard block
 block discarded – undo
2039 2106
 						{
2040 2107
 							unlink($path . '/.htaccess');
2041 2108
 							unlink($path . '/index.php');
2042
-							if (!@rmdir($path))
2043
-								$error = $path . ': ' . $txt['attach_dir_no_delete'];
2109
+							if (!@rmdir($path)) {
2110
+															$error = $path . ': ' . $txt['attach_dir_no_delete'];
2111
+							}
2044 2112
 						}
2045 2113
 
2046 2114
 						// Remove it from the base directory list.
@@ -2050,14 +2118,15 @@  discard block
 block discarded – undo
2050 2118
 							updateSettings(array('attachment_basedirectories' => $smcFunc['json_encode']($modSettings['attachment_basedirectories'])));
2051 2119
 							$modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true);
2052 2120
 						}
2121
+					} else {
2122
+											$error = $path . ': ' . $txt['attach_dir_no_remove'];
2053 2123
 					}
2054
-					else
2055
-						$error = $path . ': ' . $txt['attach_dir_no_remove'];
2056 2124
 
2057
-					if (empty($error))
2058
-						continue;
2059
-					else
2060
-						$errors[] = $error;
2125
+					if (empty($error)) {
2126
+											continue;
2127
+					} else {
2128
+											$errors[] = $error;
2129
+					}
2061 2130
 				}
2062 2131
 			}
2063 2132
 
@@ -2065,23 +2134,26 @@  discard block
 block discarded – undo
2065 2134
 		}
2066 2135
 
2067 2136
 		// We need to make sure the current directory is right.
2068
-		if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir']))
2069
-			$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
2137
+		if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) {
2138
+					$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
2139
+		}
2070 2140
 
2071 2141
 		// Find the current directory if there's no value carried,
2072 2142
 		if (empty($_POST['current_dir']) || empty($new_dirs[$_POST['current_dir']]))
2073 2143
 		{
2074
-			if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir']))
2075
-				$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
2076
-			else
2077
-				$_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir']));
2144
+			if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) {
2145
+							$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
2146
+			} else {
2147
+							$_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir']));
2148
+			}
2078 2149
 		}
2079 2150
 
2080 2151
 		// If the user wishes to go back, update the last_dir array
2081 2152
 		if ($_POST['current_dir'] != $modSettings['currentAttachmentUploadDir'] && !empty($modSettings['last_attachments_directory']) && (isset($modSettings['last_attachments_directory'][$_POST['current_dir']]) || isset($modSettings['last_attachments_directory'][0])))
2082 2153
 		{
2083
-			if (!is_array($modSettings['last_attachments_directory']))
2084
-				$modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true);
2154
+			if (!is_array($modSettings['last_attachments_directory'])) {
2155
+							$modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true);
2156
+			}
2085 2157
 			$num = substr(strrchr($modSettings['attachmentUploadDir'][$_POST['current_dir']], '_'), 1);
2086 2158
 
2087 2159
 			if (is_numeric($num))
@@ -2089,16 +2161,18 @@  discard block
 block discarded – undo
2089 2161
 				// Need to find the base folder.
2090 2162
 				$bid = -1;
2091 2163
 				$use_subdirectories_for_attachments = 0;
2092
-				if (!empty($modSettings['attachment_basedirectories']))
2093
-					foreach ($modSettings['attachment_basedirectories'] as $bid => $base)
2164
+				if (!empty($modSettings['attachment_basedirectories'])) {
2165
+									foreach ($modSettings['attachment_basedirectories'] as $bid => $base)
2094 2166
 						if (strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $base . DIRECTORY_SEPARATOR) !== false)
2095 2167
 						{
2096 2168
 							$use_subdirectories_for_attachments = 1;
2169
+				}
2097 2170
 							break;
2098 2171
 						}
2099 2172
 
2100
-				if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false)
2101
-					$bid = 0;
2173
+				if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) {
2174
+									$bid = 0;
2175
+				}
2102 2176
 
2103 2177
 				$modSettings['last_attachments_directory'][$bid] = (int) $num;
2104 2178
 				$modSettings['basedirectory_for_attachments'] = !empty($modSettings['basedirectory_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : '';
@@ -2117,8 +2191,8 @@  discard block
 block discarded – undo
2117 2191
 			// We might need to reset the paths. This loop will just loop through once.
2118 2192
 			foreach ($new_dirs as $id => $dir)
2119 2193
 			{
2120
-				if ($id != 1)
2121
-					$smcFunc['db_query']('', '
2194
+				if ($id != 1) {
2195
+									$smcFunc['db_query']('', '
2122 2196
 						UPDATE {db_prefix}attachments
2123 2197
 						SET id_folder = {int:default_folder}
2124 2198
 						WHERE id_folder = {int:current_folder}',
@@ -2127,14 +2201,14 @@  discard block
 block discarded – undo
2127 2201
 							'current_folder' => $id,
2128 2202
 						)
2129 2203
 					);
2204
+				}
2130 2205
 
2131 2206
 				$update = array(
2132 2207
 					'currentAttachmentUploadDir' => 1,
2133 2208
 					'attachmentUploadDir' => $smcFunc['json_encode'](array(1 => $dir)),
2134 2209
 				);
2135 2210
 			}
2136
-		}
2137
-		else
2211
+		} else
2138 2212
 		{
2139 2213
 			// Save it to the database.
2140 2214
 			$update = array(
@@ -2143,11 +2217,13 @@  discard block
 block discarded – undo
2143 2217
 			);
2144 2218
 		}
2145 2219
 
2146
-		if (!empty($update))
2147
-			updateSettings($update);
2220
+		if (!empty($update)) {
2221
+					updateSettings($update);
2222
+		}
2148 2223
 
2149
-		if (!empty($errors))
2150
-			$_SESSION['errors']['dir'] = $errors;
2224
+		if (!empty($errors)) {
2225
+					$_SESSION['errors']['dir'] = $errors;
2226
+		}
2151 2227
 
2152 2228
 		redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']);
2153 2229
 	}
@@ -2161,10 +2237,11 @@  discard block
 block discarded – undo
2161 2237
 		$_POST['current_base_dir'] = isset($_POST['current_base_dir']) ? (int) $_POST['current_base_dir'] : 1;
2162 2238
 		if (empty($_POST['new_base_dir']) && !empty($_POST['current_base_dir']))
2163 2239
 		{
2164
-			if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']])
2165
-				$update = (array(
2240
+			if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) {
2241
+							$update = (array(
2166 2242
 					'basedirectory_for_attachments' => $modSettings['attachmentUploadDir'][$_POST['current_base_dir']],
2167 2243
 				));
2244
+			}
2168 2245
 		}
2169 2246
 
2170 2247
 		if (isset($_POST['base_dir']))
@@ -2212,13 +2289,15 @@  discard block
 block discarded – undo
2212 2289
 
2213 2290
 			if (!in_array($_POST['new_base_dir'], $modSettings['attachmentUploadDir']))
2214 2291
 			{
2215
-				if (!automanage_attachments_create_directory($_POST['new_base_dir']))
2216
-					$errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create'];
2292
+				if (!automanage_attachments_create_directory($_POST['new_base_dir'])) {
2293
+									$errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create'];
2294
+				}
2217 2295
 			}
2218 2296
 
2219 2297
 			$modSettings['currentAttachmentUploadDir'] = array_search($_POST['new_base_dir'], $modSettings['attachmentUploadDir']);
2220
-			if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories']))
2221
-				$modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir'];
2298
+			if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) {
2299
+							$modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir'];
2300
+			}
2222 2301
 			ksort($modSettings['attachment_basedirectories']);
2223 2302
 
2224 2303
 			$update = (array(
@@ -2228,11 +2307,13 @@  discard block
 block discarded – undo
2228 2307
 			));
2229 2308
 		}
2230 2309
 
2231
-		if (!empty($errors))
2232
-			$_SESSION['errors']['base'] = $errors;
2310
+		if (!empty($errors)) {
2311
+					$_SESSION['errors']['base'] = $errors;
2312
+		}
2233 2313
 
2234
-		if (!empty($update))
2235
-			updateSettings($update);
2314
+		if (!empty($update)) {
2315
+					updateSettings($update);
2316
+		}
2236 2317
 
2237 2318
 		redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']);
2238 2319
 	}
@@ -2242,13 +2323,15 @@  discard block
 block discarded – undo
2242 2323
 		if (is_array($_SESSION['errors']))
2243 2324
 		{
2244 2325
 			$errors = array();
2245
-			if (!empty($_SESSION['errors']['dir']))
2246
-				foreach ($_SESSION['errors']['dir'] as $error)
2326
+			if (!empty($_SESSION['errors']['dir'])) {
2327
+							foreach ($_SESSION['errors']['dir'] as $error)
2247 2328
 					$errors['dir'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES);
2329
+			}
2248 2330
 
2249
-			if (!empty($_SESSION['errors']['base']))
2250
-				foreach ($_SESSION['errors']['base'] as $error)
2331
+			if (!empty($_SESSION['errors']['base'])) {
2332
+							foreach ($_SESSION['errors']['base'] as $error)
2251 2333
 					$errors['base'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES);
2334
+			}
2252 2335
 		}
2253 2336
 		unset($_SESSION['errors']);
2254 2337
 	}
@@ -2458,8 +2541,9 @@  discard block
 block discarded – undo
2458 2541
 	foreach ($modSettings['attachmentUploadDir'] as $id => $dir)
2459 2542
 	{
2460 2543
 		// If there aren't any attachments in this directory this won't exist.
2461
-		if (!isset($expected_files[$id]))
2462
-			$expected_files[$id] = 0;
2544
+		if (!isset($expected_files[$id])) {
2545
+					$expected_files[$id] = 0;
2546
+		}
2463 2547
 
2464 2548
 		// Check if the directory is doing okay.
2465 2549
 		list ($status, $error, $files) = attachDirStatus($dir, $expected_files[$id]);
@@ -2472,10 +2556,11 @@  discard block
 block discarded – undo
2472 2556
 			$is_base_dir = in_array($dir, $modSettings['attachment_basedirectories']);
2473 2557
 
2474 2558
 			// Count any sub-folders.
2475
-			foreach ($modSettings['attachmentUploadDir'] as $sid => $sub)
2476
-				if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false)
2559
+			foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) {
2560
+							if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false)
2477 2561
 				{
2478 2562
 					$expected_files[$id]++;
2563
+			}
2479 2564
 					$sub_dirs++;
2480 2565
 				}
2481 2566
 		}
@@ -2493,8 +2578,8 @@  discard block
 block discarded – undo
2493 2578
 	}
2494 2579
 
2495 2580
 	// Just stick a new directory on at the bottom.
2496
-	if (isset($_REQUEST['new_path']))
2497
-		$attachdirs[] = array(
2581
+	if (isset($_REQUEST['new_path'])) {
2582
+			$attachdirs[] = array(
2498 2583
 			'id' => max(array_merge(array_keys($expected_files), array_keys($modSettings['attachmentUploadDir']))) + 1,
2499 2584
 			'current' => false,
2500 2585
 			'path' => '',
@@ -2502,6 +2587,7 @@  discard block
 block discarded – undo
2502 2587
 			'num_files' => '',
2503 2588
 			'status' => '',
2504 2589
 		);
2590
+	}
2505 2591
 
2506 2592
 	return $attachdirs;
2507 2593
 }
@@ -2514,8 +2600,9 @@  discard block
 block discarded – undo
2514 2600
 {
2515 2601
 	global $modSettings, $txt;
2516 2602
 
2517
-	if (empty($modSettings['attachment_basedirectories']))
2518
-		return;
2603
+	if (empty($modSettings['attachment_basedirectories'])) {
2604
+			return;
2605
+	}
2519 2606
 
2520 2607
 	$basedirs = array();
2521 2608
 	// Get a list of the base directories.
@@ -2523,16 +2610,18 @@  discard block
 block discarded – undo
2523 2610
 	{
2524 2611
 		// Loop through the attach directory array to count any sub-directories
2525 2612
 		$expected_dirs = 0;
2526
-		foreach ($modSettings['attachmentUploadDir'] as $sid => $sub)
2527
-			if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false)
2613
+		foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) {
2614
+					if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false)
2528 2615
 				$expected_dirs++;
2616
+		}
2529 2617
 
2530
-		if (!is_dir($dir))
2531
-			$status = 'does_not_exist';
2532
-		elseif (!is_writeable($dir))
2533
-			$status = 'not_writable';
2534
-		else
2535
-			$status = 'ok';
2618
+		if (!is_dir($dir)) {
2619
+					$status = 'does_not_exist';
2620
+		} elseif (!is_writeable($dir)) {
2621
+					$status = 'not_writable';
2622
+		} else {
2623
+					$status = 'ok';
2624
+		}
2536 2625
 
2537 2626
 		$basedirs[] = array(
2538 2627
 			'id' => $id,
@@ -2543,14 +2632,15 @@  discard block
 block discarded – undo
2543 2632
 		);
2544 2633
 	}
2545 2634
 
2546
-	if (isset($_REQUEST['new_base_path']))
2547
-		$basedirs[] = array(
2635
+	if (isset($_REQUEST['new_base_path'])) {
2636
+			$basedirs[] = array(
2548 2637
 			'id' => '',
2549 2638
 			'current' => false,
2550 2639
 			'path' => '<input type="text" name="new_base_dir" value="" size="40">',
2551 2640
 			'num_dirs' => '',
2552 2641
 			'status' => '',
2553 2642
 		);
2643
+	}
2554 2644
 
2555 2645
 	return $basedirs;
2556 2646
 }
@@ -2566,10 +2656,11 @@  discard block
 block discarded – undo
2566 2656
  */
2567 2657
 function attachDirStatus($dir, $expected_files)
2568 2658
 {
2569
-	if (!is_dir($dir))
2570
-		return array('does_not_exist', true, '');
2571
-	elseif (!is_writable($dir))
2572
-		return array('not_writable', true, '');
2659
+	if (!is_dir($dir)) {
2660
+			return array('does_not_exist', true, '');
2661
+	} elseif (!is_writable($dir)) {
2662
+			return array('not_writable', true, '');
2663
+	}
2573 2664
 
2574 2665
 	// Everything is okay so far, start to scan through the directory.
2575 2666
 	$num_files = 0;
@@ -2577,22 +2668,26 @@  discard block
 block discarded – undo
2577 2668
 	while ($file = $dir_handle->read())
2578 2669
 	{
2579 2670
 		// Now do we have a real file here?
2580
-		if (in_array($file, array('.', '..', '.htaccess', 'index.php')))
2581
-			continue;
2671
+		if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) {
2672
+					continue;
2673
+		}
2582 2674
 
2583 2675
 		$num_files++;
2584 2676
 	}
2585 2677
 	$dir_handle->close();
2586 2678
 
2587
-	if ($num_files < $expected_files)
2588
-		return array('files_missing', true, $num_files);
2679
+	if ($num_files < $expected_files) {
2680
+			return array('files_missing', true, $num_files);
2681
+	}
2589 2682
 	// Empty?
2590
-	elseif ($expected_files == 0)
2591
-		return array('unused', false, $num_files);
2683
+	elseif ($expected_files == 0) {
2684
+			return array('unused', false, $num_files);
2685
+	}
2592 2686
 	// All good!
2593
-	else
2594
-		return array('ok', false, $num_files);
2595
-}
2687
+	else {
2688
+			return array('ok', false, $num_files);
2689
+	}
2690
+	}
2596 2691
 
2597 2692
 /**
2598 2693
  * Maintance function to move attachments from one directory to another
@@ -2604,10 +2699,11 @@  discard block
 block discarded – undo
2604 2699
 	checkSession();
2605 2700
 
2606 2701
 	$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
2607
-	if (!empty($modSettings['attachment_basedirectories']))
2608
-		$modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true);
2609
-	else
2610
-		$modSettings['basedirectory_for_attachments'] = array();
2702
+	if (!empty($modSettings['attachment_basedirectories'])) {
2703
+			$modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true);
2704
+	} else {
2705
+			$modSettings['basedirectory_for_attachments'] = array();
2706
+	}
2611 2707
 
2612 2708
 	$_POST['from'] = (int) $_POST['from'];
2613 2709
 	$_POST['auto'] = !empty($_POST['auto']) ? (int) $_POST['auto'] : 0;
@@ -2621,11 +2717,13 @@  discard block
 block discarded – undo
2621 2717
 	$total_moved = 0;
2622 2718
 	$total_not_moved = 0;
2623 2719
 
2624
-	if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to'])))
2625
-		$results[] = $txt['attachment_transfer_no_dir'];
2720
+	if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) {
2721
+			$results[] = $txt['attachment_transfer_no_dir'];
2722
+	}
2626 2723
 
2627
-	if ($_POST['from'] == $_POST['to'])
2628
-		$results[] = $txt['attachment_transfer_same_dir'];
2724
+	if ($_POST['from'] == $_POST['to']) {
2725
+			$results[] = $txt['attachment_transfer_same_dir'];
2726
+	}
2629 2727
 
2630 2728
 	if (empty($results))
2631 2729
 	{
@@ -2644,8 +2742,9 @@  discard block
 block discarded – undo
2644 2742
 		$smcFunc['db_free_result']($request);
2645 2743
 		$total_progress -= $start;
2646 2744
 
2647
-		if ($total_progress < 1)
2648
-			$results[] = $txt['attachment_transfer_no_find'];
2745
+		if ($total_progress < 1) {
2746
+					$results[] = $txt['attachment_transfer_no_find'];
2747
+		}
2649 2748
 	}
2650 2749
 
2651 2750
 	if (empty($results))
@@ -2661,9 +2760,9 @@  discard block
 block discarded – undo
2661 2760
 
2662 2761
 			automanage_attachments_check_directory();
2663 2762
 			$new_dir = $modSettings['currentAttachmentUploadDir'];
2763
+		} else {
2764
+					$new_dir = $_POST['to'];
2664 2765
 		}
2665
-		else
2666
-			$new_dir = $_POST['to'];
2667 2766
 
2668 2767
 		$modSettings['currentAttachmentUploadDir'] = $new_dir;
2669 2768
 
@@ -2671,8 +2770,9 @@  discard block
 block discarded – undo
2671 2770
 		while ($break == false)
2672 2771
 		{
2673 2772
 			@set_time_limit(300);
2674
-			if (function_exists('apache_reset_timeout'))
2675
-				@apache_reset_timeout();
2773
+			if (function_exists('apache_reset_timeout')) {
2774
+							@apache_reset_timeout();
2775
+			}
2676 2776
 
2677 2777
 			// If limits are set, get the file count and size for the destination folder
2678 2778
 			if ($dir_files <= 0 && (!empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit'])))
@@ -2708,13 +2808,15 @@  discard block
 block discarded – undo
2708 2808
 
2709 2809
 			if ($smcFunc['db_num_rows']($request) === 0)
2710 2810
 			{
2711
-				if (empty($current_progress))
2712
-					$results[] = $txt['attachment_transfer_no_find'];
2811
+				if (empty($current_progress)) {
2812
+									$results[] = $txt['attachment_transfer_no_find'];
2813
+				}
2713 2814
 				break;
2714 2815
 			}
2715 2816
 
2716
-			if ($smcFunc['db_num_rows']($request) < $limit)
2717
-				$break = true;
2817
+			if ($smcFunc['db_num_rows']($request) < $limit) {
2818
+							$break = true;
2819
+			}
2718 2820
 
2719 2821
 			// Move them
2720 2822
 			$moved = array();
@@ -2738,8 +2840,9 @@  discard block
 block discarded – undo
2738 2840
 							automanage_attachments_by_space();
2739 2841
 
2740 2842
 							$results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]);
2741
-							if (!empty($total_not_moved))
2742
-								$results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved);
2843
+							if (!empty($total_not_moved)) {
2844
+															$results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved);
2845
+							}
2743 2846
 
2744 2847
 							$dir_files = 0;
2745 2848
 							$total_moved = 0;
@@ -2747,8 +2850,7 @@  discard block
 block discarded – undo
2747 2850
 
2748 2851
 							$break = false;
2749 2852
 							break;
2750
-						}
2751
-						else
2853
+						} else
2752 2854
 						{
2753 2855
 							// Hmm, not in auto. Time to bail out then...
2754 2856
 							$results[] = $txt['attachment_transfer_no_room'];
@@ -2763,9 +2865,9 @@  discard block
 block discarded – undo
2763 2865
 					$total_moved++;
2764 2866
 					$current_progress++;
2765 2867
 					$moved[] = $row['id_attach'];
2868
+				} else {
2869
+									$total_not_moved++;
2766 2870
 				}
2767
-				else
2768
-					$total_not_moved++;
2769 2871
 			}
2770 2872
 			$smcFunc['db_free_result']($request);
2771 2873
 
@@ -2803,13 +2905,15 @@  discard block
 block discarded – undo
2803 2905
 		}
2804 2906
 
2805 2907
 		$results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]);
2806
-		if (!empty($total_not_moved))
2807
-			$results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved);
2908
+		if (!empty($total_not_moved)) {
2909
+					$results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved);
2910
+		}
2808 2911
 	}
2809 2912
 
2810 2913
 	$_SESSION['results'] = $results;
2811
-	if (file_exists($boarddir . '/progress.php'))
2812
-		unlink($boarddir . '/progress.php');
2914
+	if (file_exists($boarddir . '/progress.php')) {
2915
+			unlink($boarddir . '/progress.php');
2916
+	}
2813 2917
 
2814 2918
 	redirectexit('action=admin;area=manageattachments;sa=maintenance#transfer');
2815 2919
 }
Please login to merge, or discard this patch.