Completed
Push — release-2.1 ( 286127...e6c696 )
by Mathias
11s
created
Sources/Subs-Calendar.php 2 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -1459,8 +1459,6 @@
 block discarded – undo
1459 1459
  * Helper function for getEventRange, getEventProperties, getNewEventDatetimes, etc.
1460 1460
  *
1461 1461
  * @param array $row A database row representing an event from the calendar table
1462
- * @param string $date_format Tells timeformat() how to format the date values for display to the user
1463
- * @param string $time_format Tells timeformat() how to format the time values for display to the user
1464 1462
  * @return array An array containing the start and end date and time properties for the event
1465 1463
  */
1466 1464
 function buildEventDatetimes($row)
Please login to merge, or discard this patch.
Braces   +206 added lines, -149 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Get all birthdays within the given time range.
@@ -61,10 +62,11 @@  discard block
 block discarded – undo
61 62
 	$bday = array();
62 63
 	while ($row = $smcFunc['db_fetch_assoc']($result))
63 64
 	{
64
-		if ($year_low != $year_high)
65
-			$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
66
-		else
67
-			$age_year = $year_low;
65
+		if ($year_low != $year_high) {
66
+					$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
67
+		} else {
68
+					$age_year = $year_low;
69
+		}
68 70
 
69 71
 		$bday[$age_year . substr($row['birthdate'], 4)][] = array(
70 72
 			'id' => $row['id_member'],
@@ -76,8 +78,9 @@  discard block
 block discarded – undo
76 78
 	$smcFunc['db_free_result']($result);
77 79
 
78 80
 	// Set is_last, so the themes know when to stop placing separators.
79
-	foreach ($bday as $mday => $array)
80
-		$bday[$mday][count($array) - 1]['is_last'] = true;
81
+	foreach ($bday as $mday => $array) {
82
+			$bday[$mday][count($array) - 1]['is_last'] = true;
83
+	}
81 84
 
82 85
 	return $bday;
83 86
 }
@@ -125,8 +128,9 @@  discard block
 block discarded – undo
125 128
 	while ($row = $smcFunc['db_fetch_assoc']($result))
126 129
 	{
127 130
 		// If the attached topic is not approved then for the moment pretend it doesn't exist
128
-		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved'])
129
-			continue;
131
+		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) {
132
+					continue;
133
+		}
130 134
 
131 135
 		// Force a censor of the title - as often these are used by others.
132 136
 		censorText($row['title'], $use_permissions ? false : true);
@@ -137,8 +141,9 @@  discard block
 block discarded – undo
137 141
 		list($start, $end, $allday, $span, $tz_abbrev) = buildEventDatetimes($row);
138 142
 
139 143
 		// Sanity check
140
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
141
-			continue;
144
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
145
+					continue;
146
+		}
142 147
 
143 148
 		// Get set up for the loop
144 149
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), timezone_open($tz));
@@ -202,8 +207,8 @@  discard block
 block discarded – undo
202 207
 			);
203 208
 
204 209
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
205
-			if ($use_permissions)
206
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
210
+			if ($use_permissions) {
211
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
207 212
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
208 213
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
209 214
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -211,9 +216,10 @@  discard block
 block discarded – undo
211 216
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
212 217
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
213 218
 				));
219
+			}
214 220
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
215
-			else
216
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
221
+			else {
222
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
217 223
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
218 224
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
219 225
 					'can_edit' => false,
@@ -223,6 +229,7 @@  discard block
 block discarded – undo
223 229
 					'poster' => $row['id_member'],
224 230
 					'allowed_groups' => explode(',', $row['member_groups']),
225 231
 				));
232
+			}
226 233
 
227 234
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
228 235
 		}
@@ -232,8 +239,9 @@  discard block
 block discarded – undo
232 239
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
233 240
 	if ($use_permissions)
234 241
 	{
235
-		foreach ($events as $mday => $array)
236
-			$events[$mday][count($array) - 1]['is_last'] = true;
242
+		foreach ($events as $mday => $array) {
243
+					$events[$mday][count($array) - 1]['is_last'] = true;
244
+		}
237 245
 	}
238 246
 
239 247
 	return $events;
@@ -251,11 +259,12 @@  discard block
 block discarded – undo
251 259
 	global $smcFunc;
252 260
 
253 261
 	// Get the lowest and highest dates for "all years".
254
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
255
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
262
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
263
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
256 264
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
257
-	else
258
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
265
+	} else {
266
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
267
+	}
259 268
 
260 269
 	// Find some holidays... ;).
261 270
 	$result = $smcFunc['db_query']('', '
@@ -275,10 +284,11 @@  discard block
 block discarded – undo
275 284
 	$holidays = array();
276 285
 	while ($row = $smcFunc['db_fetch_assoc']($result))
277 286
 	{
278
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
279
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
280
-		else
281
-			$event_year = substr($low_date, 0, 4);
287
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
288
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
289
+		} else {
290
+					$event_year = substr($low_date, 0, 4);
291
+		}
282 292
 
283 293
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
284 294
 	}
@@ -302,10 +312,12 @@  discard block
 block discarded – undo
302 312
 	isAllowedTo('calendar_post');
303 313
 
304 314
 	// No board?  No topic?!?
305
-	if (empty($board))
306
-		fatal_lang_error('missing_board_id', false);
307
-	if (empty($topic))
308
-		fatal_lang_error('missing_topic_id', false);
315
+	if (empty($board)) {
316
+			fatal_lang_error('missing_board_id', false);
317
+	}
318
+	if (empty($topic)) {
319
+			fatal_lang_error('missing_topic_id', false);
320
+	}
309 321
 
310 322
 	// Administrator, Moderator, or owner.  Period.
311 323
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -323,12 +335,14 @@  discard block
 block discarded – undo
323 335
 		if ($row = $smcFunc['db_fetch_assoc']($result))
324 336
 		{
325 337
 			// Not the owner of the topic.
326
-			if ($row['id_member_started'] != $user_info['id'])
327
-				fatal_lang_error('not_your_topic', 'user');
338
+			if ($row['id_member_started'] != $user_info['id']) {
339
+							fatal_lang_error('not_your_topic', 'user');
340
+			}
328 341
 		}
329 342
 		// Topic/Board doesn't exist.....
330
-		else
331
-			fatal_lang_error('calendar_no_topic', 'general');
343
+		else {
344
+					fatal_lang_error('calendar_no_topic', 'general');
345
+		}
332 346
 		$smcFunc['db_free_result']($result);
333 347
 	}
334 348
 }
@@ -416,14 +430,16 @@  discard block
 block discarded – undo
416 430
 	if (!empty($calendarOptions['start_day']))
417 431
 	{
418 432
 		$nShift -= $calendarOptions['start_day'];
419
-		if ($nShift < 0)
420
-			$nShift = 7 + $nShift;
433
+		if ($nShift < 0) {
434
+					$nShift = 7 + $nShift;
435
+		}
421 436
 	}
422 437
 
423 438
 	// Number of rows required to fit the month.
424 439
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
425
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
426
-		$nRows++;
440
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
441
+			$nRows++;
442
+	}
427 443
 
428 444
 	// Fetch the arrays for birthdays, posted events, and holidays.
429 445
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -436,8 +452,9 @@  discard block
 block discarded – undo
436 452
 	{
437 453
 		$calendarGrid['week_days'][] = $count;
438 454
 		$count++;
439
-		if ($count == 7)
440
-			$count = 0;
455
+		if ($count == 7) {
456
+					$count = 0;
457
+		}
441 458
 	}
442 459
 
443 460
 	// Iterate through each week.
@@ -454,8 +471,9 @@  discard block
 block discarded – undo
454 471
 		{
455 472
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
456 473
 
457
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
458
-				$nDay = 0;
474
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
475
+							$nDay = 0;
476
+			}
459 477
 
460 478
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
461 479
 
@@ -473,8 +491,9 @@  discard block
 block discarded – undo
473 491
 	}
474 492
 
475 493
 	// What is the last day of the month?
476
-	if ($is_previous === true)
477
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
494
+	if ($is_previous === true) {
495
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
496
+	}
478 497
 
479 498
 	// We'll use the shift in the template.
480 499
 	$calendarGrid['shift'] = $nShift;
@@ -508,8 +527,9 @@  discard block
 block discarded – undo
508 527
 	{
509 528
 		// Here we offset accordingly to get things to the real start of a week.
510 529
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
511
-		if ($date_diff < 0)
512
-			$date_diff += 7;
530
+		if ($date_diff < 0) {
531
+					$date_diff += 7;
532
+		}
513 533
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
514 534
 		$day = (int) strftime('%d', $new_timestamp);
515 535
 		$month = (int) strftime('%m', $new_timestamp);
@@ -660,8 +680,9 @@  discard block
 block discarded – undo
660 680
 	// Holidays between now and now + days.
661 681
 	for ($i = $now; $i < $now + $days_for_index; $i += 86400)
662 682
 	{
663
-		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
664
-			$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
683
+		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
684
+					$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
685
+		}
665 686
 	}
666 687
 
667 688
 	// Happy Birthday, guys and gals!
@@ -670,8 +691,9 @@  discard block
 block discarded – undo
670 691
 		$loop_date = strftime('%Y-%m-%d', $i);
671 692
 		if (isset($cached_data['birthdays'][$loop_date]))
672 693
 		{
673
-			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
674
-				$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
694
+			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
695
+							$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
696
+			}
675 697
 			$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
676 698
 		}
677 699
 	}
@@ -683,8 +705,9 @@  discard block
 block discarded – undo
683 705
 		$loop_date = strftime('%Y-%m-%d', $i);
684 706
 
685 707
 		// No events today? Check the next day.
686
-		if (empty($cached_data['events'][$loop_date]))
687
-			continue;
708
+		if (empty($cached_data['events'][$loop_date])) {
709
+					continue;
710
+		}
688 711
 
689 712
 		// Loop through all events to add a few last-minute values.
690 713
 		foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -697,9 +720,9 @@  discard block
 block discarded – undo
697 720
 			{
698 721
 				unset($cached_data['events'][$loop_date][$ev]);
699 722
 				continue;
723
+			} else {
724
+							$duplicates[$this_event['topic'] . $this_event['title']] = true;
700 725
 			}
701
-			else
702
-				$duplicates[$this_event['topic'] . $this_event['title']] = true;
703 726
 
704 727
 			// Might be set to true afterwards, depending on the permissions.
705 728
 			$this_event['can_edit'] = false;
@@ -707,15 +730,18 @@  discard block
 block discarded – undo
707 730
 			$this_event['date'] = $loop_date;
708 731
 		}
709 732
 
710
-		if (!empty($cached_data['events'][$loop_date]))
711
-			$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
733
+		if (!empty($cached_data['events'][$loop_date])) {
734
+					$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
735
+		}
712 736
 	}
713 737
 
714 738
 	// Mark the last item so that a list separator can be used in the template.
715
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
716
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
717
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
718
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
739
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
740
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
741
+	}
742
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
743
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
744
+	}
719 745
 
720 746
 	return array(
721 747
 		'data' => $return_data,
@@ -763,37 +789,46 @@  discard block
 block discarded – undo
763 789
 		if (isset($_POST['start_date']))
764 790
 		{
765 791
 			$d = date_parse($_POST['start_date']);
766
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
767
-				fatal_lang_error('invalid_date', false);
768
-			if (empty($d['year']))
769
-				fatal_lang_error('event_year_missing', false);
770
-			if (empty($d['month']))
771
-				fatal_lang_error('event_month_missing', false);
772
-		}
773
-		elseif (isset($_POST['start_datetime']))
792
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
793
+							fatal_lang_error('invalid_date', false);
794
+			}
795
+			if (empty($d['year'])) {
796
+							fatal_lang_error('event_year_missing', false);
797
+			}
798
+			if (empty($d['month'])) {
799
+							fatal_lang_error('event_month_missing', false);
800
+			}
801
+		} elseif (isset($_POST['start_datetime']))
774 802
 		{
775 803
 			$d = date_parse($_POST['start_datetime']);
776
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
777
-				fatal_lang_error('invalid_date', false);
778
-			if (empty($d['year']))
779
-				fatal_lang_error('event_year_missing', false);
780
-			if (empty($d['month']))
781
-				fatal_lang_error('event_month_missing', false);
804
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
805
+							fatal_lang_error('invalid_date', false);
806
+			}
807
+			if (empty($d['year'])) {
808
+							fatal_lang_error('event_year_missing', false);
809
+			}
810
+			if (empty($d['month'])) {
811
+							fatal_lang_error('event_month_missing', false);
812
+			}
782 813
 		}
783 814
 		// The 2.0 way
784 815
 		else
785 816
 		{
786 817
 			// No month?  No year?
787
-			if (!isset($_POST['month']))
788
-				fatal_lang_error('event_month_missing', false);
789
-			if (!isset($_POST['year']))
790
-				fatal_lang_error('event_year_missing', false);
818
+			if (!isset($_POST['month'])) {
819
+							fatal_lang_error('event_month_missing', false);
820
+			}
821
+			if (!isset($_POST['year'])) {
822
+							fatal_lang_error('event_year_missing', false);
823
+			}
791 824
 
792 825
 			// Check the month and year...
793
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
794
-				fatal_lang_error('invalid_month', false);
795
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
796
-				fatal_lang_error('invalid_year', false);
826
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
827
+							fatal_lang_error('invalid_month', false);
828
+			}
829
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
830
+							fatal_lang_error('invalid_year', false);
831
+			}
797 832
 		}
798 833
 	}
799 834
 
@@ -803,8 +838,9 @@  discard block
 block discarded – undo
803 838
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
804 839
 	if (isset($_POST['span']))
805 840
 	{
806
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
807
-			fatal_lang_error('invalid_days_numb', false);
841
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
842
+					fatal_lang_error('invalid_days_numb', false);
843
+		}
808 844
 	}
809 845
 
810 846
 	// There is no need to validate the following values if we are just deleting the event.
@@ -814,24 +850,29 @@  discard block
 block discarded – undo
814 850
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
815 851
 		{
816 852
 			// No day?
817
-			if (!isset($_POST['day']))
818
-				fatal_lang_error('event_day_missing', false);
853
+			if (!isset($_POST['day'])) {
854
+							fatal_lang_error('event_day_missing', false);
855
+			}
819 856
 
820 857
 			// Bad day?
821
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
822
-				fatal_lang_error('invalid_date', false);
858
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
859
+							fatal_lang_error('invalid_date', false);
860
+			}
823 861
 		}
824 862
 
825
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
826
-			fatal_lang_error('event_title_missing', false);
827
-		elseif (!isset($_POST['evtitle']))
828
-			$_POST['evtitle'] = $_POST['subject'];
863
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
864
+					fatal_lang_error('event_title_missing', false);
865
+		} elseif (!isset($_POST['evtitle'])) {
866
+					$_POST['evtitle'] = $_POST['subject'];
867
+		}
829 868
 
830 869
 		// No title?
831
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
832
-			fatal_lang_error('no_event_title', false);
833
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
834
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
870
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
871
+					fatal_lang_error('no_event_title', false);
872
+		}
873
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
874
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
875
+		}
835 876
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
836 877
 	}
837 878
 }
@@ -858,8 +899,9 @@  discard block
 block discarded – undo
858 899
 	);
859 900
 
860 901
 	// No results, return false.
861
-	if ($smcFunc['db_num_rows'] === 0)
862
-		return false;
902
+	if ($smcFunc['db_num_rows'] === 0) {
903
+			return false;
904
+	}
863 905
 
864 906
 	// Grab the results and return.
865 907
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -995,8 +1037,9 @@  discard block
 block discarded – undo
995 1037
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
996 1038
 
997 1039
 	$column_clauses = array();
998
-	foreach ($event_columns as $col => $crit)
999
-		$column_clauses[] = $col . ' = ' . $crit;
1040
+	foreach ($event_columns as $col => $crit) {
1041
+			$column_clauses[] = $col . ' = ' . $crit;
1042
+	}
1000 1043
 
1001 1044
 	$smcFunc['db_query']('', '
1002 1045
 		UPDATE {db_prefix}calendar
@@ -1081,8 +1124,9 @@  discard block
 block discarded – undo
1081 1124
 	);
1082 1125
 
1083 1126
 	// If nothing returned, we are in poo, poo.
1084
-	if ($smcFunc['db_num_rows']($request) === 0)
1085
-		return false;
1127
+	if ($smcFunc['db_num_rows']($request) === 0) {
1128
+			return false;
1129
+	}
1086 1130
 
1087 1131
 	$row = $smcFunc['db_fetch_assoc']($request);
1088 1132
 	$smcFunc['db_free_result']($request);
@@ -1090,8 +1134,9 @@  discard block
 block discarded – undo
1090 1134
 	list($start, $end, $allday, $span, $tz_abbrev) = buildEventDatetimes($row);
1091 1135
 
1092 1136
 	// Sanity check
1093
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1094
-		return false;
1137
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1138
+			return false;
1139
+	}
1095 1140
 
1096 1141
 	$return_value = array(
1097 1142
 		'boards' => array(),
@@ -1161,10 +1206,11 @@  discard block
 block discarded – undo
1161 1206
 	$allday = isset($_REQUEST['allday']) ? 1 : (isset($_REQUEST['start_time']) ? 0 : 1);
1162 1207
 	$span = isset($_REQUEST['span']) && filter_var($_REQUEST['span'], FILTER_VALIDATE_INT, array('options' => array('min_range' => 0))) ? $_REQUEST['span'] : 1;
1163 1208
 
1164
-	if (!empty($_REQUEST['tz']) && in_array($_REQUEST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1165
-		$tz = $_REQUEST['tz'];
1166
-	else
1167
-		$tz = getUserTimezone();
1209
+	if (!empty($_REQUEST['tz']) && in_array($_REQUEST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1210
+			$tz = $_REQUEST['tz'];
1211
+	} else {
1212
+			$tz = getUserTimezone();
1213
+	}
1168 1214
 
1169 1215
 	// Was the input given as individual parameters?
1170 1216
 	$start_year = isset($_REQUEST['year']) ? $_REQUEST['year'] : $today['year'];
@@ -1275,24 +1321,27 @@  discard block
 block discarded – undo
1275 1321
 
1276 1322
 	// Set $span, in case we need it
1277 1323
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1278
-	if ($span > 0)
1279
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1324
+	if ($span > 0) {
1325
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1326
+	}
1280 1327
 
1281 1328
 	// Define the timezone for this event, falling back to the default if not provided
1282
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1283
-		$tz = $eventOptions['tz'];
1284
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1285
-		$tz = $_POST['tz'];
1286
-	else
1287
-		$tz = getUserTimezone();
1329
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1330
+			$tz = $eventOptions['tz'];
1331
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1332
+			$tz = $_POST['tz'];
1333
+	} else {
1334
+			$tz = getUserTimezone();
1335
+	}
1288 1336
 
1289 1337
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1290
-	if (isset($eventOptions['allday']))
1291
-		$allday = $eventOptions['allday'];
1292
-	elseif (empty($_POST['allday']))
1293
-		$allday = false;
1294
-	else
1295
-		$allday = true;
1338
+	if (isset($eventOptions['allday'])) {
1339
+			$allday = $eventOptions['allday'];
1340
+	} elseif (empty($_POST['allday'])) {
1341
+			$allday = false;
1342
+	} else {
1343
+			$allday = true;
1344
+	}
1296 1345
 
1297 1346
 	// Input might come as individual parameters...
1298 1347
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1319,10 +1368,12 @@  discard block
 block discarded – undo
1319 1368
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1320 1369
 
1321 1370
 	// If the date and time were given in separate strings, combine them
1322
-	if (empty($start_string) && isset($start_date_string))
1323
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1324
-	if (empty($end_string) && isset($end_date_string))
1325
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1371
+	if (empty($start_string) && isset($start_date_string)) {
1372
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1373
+	}
1374
+	if (empty($end_string) && isset($end_date_string)) {
1375
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1376
+	}
1326 1377
 
1327 1378
 	// If some form of string input was given, override individually defined options with it
1328 1379
 	if (isset($start_string))
@@ -1413,10 +1464,11 @@  discard block
 block discarded – undo
1413 1464
 	if ($start_object >= $end_object)
1414 1465
 	{
1415 1466
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1416
-		if ($span > 0)
1417
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1418
-		else
1419
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1467
+		if ($span > 0) {
1468
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1469
+		} else {
1470
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1471
+		}
1420 1472
 	}
1421 1473
 
1422 1474
 	// Is $end_object too late?
@@ -1430,9 +1482,9 @@  discard block
 block discarded – undo
1430 1482
 			{
1431 1483
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1432 1484
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1485
+			} else {
1486
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1433 1487
 			}
1434
-			else
1435
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1436 1488
 		}
1437 1489
 	}
1438 1490
 
@@ -1445,8 +1497,7 @@  discard block
 block discarded – undo
1445 1497
 		$start_time = null;
1446 1498
 		$end_time = null;
1447 1499
 		$tz = null;
1448
-	}
1449
-	else
1500
+	} else
1450 1501
 	{
1451 1502
 		$start_time = date_format($start_object, 'H:i:s');
1452 1503
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1469,19 +1520,22 @@  discard block
 block discarded – undo
1469 1520
 	require_once($sourcedir . '/Subs.php');
1470 1521
 
1471 1522
 	// First, try to create a better date format, ignoring the "time" elements.
1472
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1473
-		$date_format = '%F';
1474
-	else
1475
-		$date_format = $matches[0];
1523
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1524
+			$date_format = '%F';
1525
+	} else {
1526
+			$date_format = $matches[0];
1527
+	}
1476 1528
 
1477
-	if (empty($row['timezone']))
1478
-		$row['timezone'] = getUserTimezone();
1529
+	if (empty($row['timezone'])) {
1530
+			$row['timezone'] = getUserTimezone();
1531
+	}
1479 1532
 
1480 1533
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1481
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1482
-		$time_format = '%k:%M';
1483
-	else
1484
-		$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1534
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1535
+			$time_format = '%k:%M';
1536
+	} else {
1537
+			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1538
+	}
1485 1539
 
1486 1540
 	$allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false;
1487 1541
 
@@ -1527,8 +1581,9 @@  discard block
 block discarded – undo
1527 1581
 {
1528 1582
 	global $smcFunc, $context, $sourcedir, $user_info;
1529 1583
 
1530
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1531
-		$id_member = $context['user']['id'];
1584
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1585
+			$id_member = $context['user']['id'];
1586
+	}
1532 1587
 
1533 1588
 	if (isset($id_member))
1534 1589
 	{
@@ -1544,8 +1599,9 @@  discard block
 block discarded – undo
1544 1599
 		$smcFunc['db_free_result']($request);
1545 1600
 	}
1546 1601
 
1547
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1548
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1602
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1603
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1604
+	}
1549 1605
 
1550 1606
 	return $timezone;
1551 1607
 }
@@ -1574,8 +1630,9 @@  discard block
 block discarded – undo
1574 1630
 		)
1575 1631
 	);
1576 1632
 	$holidays = array();
1577
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1578
-		$holidays[] = $row;
1633
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1634
+			$holidays[] = $row;
1635
+	}
1579 1636
 	$smcFunc['db_free_result']($request);
1580 1637
 
1581 1638
 	return $holidays;
Please login to merge, or discard this patch.
other/install.php 1 patch
Braces   +438 added lines, -326 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -83,12 +84,14 @@  discard block
 block discarded – undo
83 84
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
84 85
 
85 86
 			// Is it reserved?
86
-			if ($value == 'pg_')
87
-				return $txt['error_db_prefix_reserved'];
87
+			if ($value == 'pg_') {
88
+							return $txt['error_db_prefix_reserved'];
89
+			}
88 90
 
89 91
 			// Is the prefix numeric?
90
-			if (preg_match('~^\d~', $value))
91
-				return $txt['error_db_prefix_numeric'];
92
+			if (preg_match('~^\d~', $value)) {
93
+							return $txt['error_db_prefix_numeric'];
94
+			}
92 95
 
93 96
 			return true;
94 97
 		},
@@ -135,10 +138,11 @@  discard block
 block discarded – undo
135 138
 		$incontext['skip'] = false;
136 139
 
137 140
 		// Call the step and if it returns false that means pause!
138
-		if (function_exists($step[2]) && $step[2]() === false)
139
-			break;
140
-		elseif (function_exists($step[2]))
141
-			$incontext['current_step']++;
141
+		if (function_exists($step[2]) && $step[2]() === false) {
142
+					break;
143
+		} elseif (function_exists($step[2])) {
144
+					$incontext['current_step']++;
145
+		}
142 146
 
143 147
 		// No warnings pass on.
144 148
 		$incontext['warning'] = '';
@@ -154,12 +158,14 @@  discard block
 block discarded – undo
154 158
 	global $databases, $incontext;
155 159
 
156 160
 	// Just so people using older versions of PHP aren't left in the cold.
157
-	if (!isset($_SERVER['PHP_SELF']))
158
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
161
+	if (!isset($_SERVER['PHP_SELF'])) {
162
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
163
+	}
159 164
 
160 165
 	// Turn off magic quotes runtime and enable error reporting.
161
-	if (function_exists('set_magic_quotes_runtime'))
162
-		@set_magic_quotes_runtime(0);
166
+	if (function_exists('set_magic_quotes_runtime')) {
167
+			@set_magic_quotes_runtime(0);
168
+	}
163 169
 	error_reporting(E_ALL);
164 170
 
165 171
 	// Fun.  Low PHP version...
@@ -173,21 +179,23 @@  discard block
 block discarded – undo
173 179
 	{
174 180
 		ob_start();
175 181
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
178
-		if (function_exists('session_start'))
179
-			@session_start();
180
-	}
181
-	else
182
+		if (ini_get('session.save_handler') == 'user') {
183
+					@ini_set('session.save_handler', 'files');
184
+		}
185
+		if (function_exists('session_start')) {
186
+					@session_start();
187
+		}
188
+	} else
182 189
 	{
183 190
 		ob_start('ob_gzhandler');
184 191
 
185
-		if (ini_get('session.save_handler') == 'user')
186
-			@ini_set('session.save_handler', 'files');
192
+		if (ini_get('session.save_handler') == 'user') {
193
+					@ini_set('session.save_handler', 'files');
194
+		}
187 195
 		session_start();
188 196
 
189
-		if (!headers_sent())
190
-			echo '<!DOCTYPE html>
197
+		if (!headers_sent()) {
198
+					echo '<!DOCTYPE html>
191 199
 <html>
192 200
 	<head>
193 201
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -196,6 +204,7 @@  discard block
 block discarded – undo
196 204
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
197 205
 	</body>
198 206
 </html>';
207
+		}
199 208
 		exit;
200 209
 	}
201 210
 
@@ -204,16 +213,18 @@  discard block
 block discarded – undo
204 213
 	{
205 214
 		$incontext['remote_files_available'] = false;
206 215
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
207
-		if ($test)
208
-			$incontext['remote_files_available'] = true;
216
+		if ($test) {
217
+					$incontext['remote_files_available'] = true;
218
+		}
209 219
 		@fclose($test);
210 220
 	}
211 221
 
212 222
 	// Add slashes, as long as they aren't already being added.
213
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
214
-		foreach ($_POST as $k => $v)
223
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
224
+			foreach ($_POST as $k => $v)
215 225
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
216 226
 				$_POST[$k] = addslashes($v);
227
+	}
217 228
 
218 229
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
219 230
 	if (isset($_GET['delete']))
@@ -234,8 +245,7 @@  discard block
 block discarded – undo
234 245
 			$ftp->close();
235 246
 
236 247
 			unset($_SESSION['installer_temp_ftp']);
237
-		}
238
-		else
248
+		} else
239 249
 		{
240 250
 			@unlink(__FILE__);
241 251
 
@@ -256,10 +266,11 @@  discard block
 block discarded – undo
256 266
 	{
257 267
 		// Get PHP's default timezone, if set
258 268
 		$ini_tz = ini_get('date.timezone');
259
-		if (!empty($ini_tz))
260
-			$timezone_id = $ini_tz;
261
-		else
262
-			$timezone_id = '';
269
+		if (!empty($ini_tz)) {
270
+					$timezone_id = $ini_tz;
271
+		} else {
272
+					$timezone_id = '';
273
+		}
263 274
 
264 275
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
265 276
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -289,8 +300,9 @@  discard block
 block discarded – undo
289 300
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
290 301
 		while ($entry = $dir->read())
291 302
 		{
292
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
293
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
303
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
304
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
305
+			}
294 306
 		}
295 307
 		$dir->close();
296 308
 	}
@@ -325,10 +337,11 @@  discard block
 block discarded – undo
325 337
 	}
326 338
 
327 339
 	// Override the language file?
328
-	if (isset($_GET['lang_file']))
329
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
330
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
331
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
340
+	if (isset($_GET['lang_file'])) {
341
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
342
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
343
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
344
+	}
332 345
 
333 346
 	// Make sure it exists, if it doesn't reset it.
334 347
 	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']))
@@ -337,8 +350,9 @@  discard block
 block discarded – undo
337 350
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
338 351
 
339 352
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
340
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
341
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
353
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
354
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
355
+		}
342 356
 	}
343 357
 
344 358
 	// And now include the actual language file itself.
@@ -351,15 +365,18 @@  discard block
 block discarded – undo
351 365
 	global $db_prefix, $db_connection, $sourcedir;
352 366
 	global $smcFunc, $modSettings, $db_type, $db_name, $db_user, $db_persist;
353 367
 
354
-	if (empty($sourcedir))
355
-		$sourcedir = dirname(__FILE__) . '/Sources';
368
+	if (empty($sourcedir)) {
369
+			$sourcedir = dirname(__FILE__) . '/Sources';
370
+	}
356 371
 
357 372
 	// Need this to check whether we need the database password.
358 373
 	require(dirname(__FILE__) . '/Settings.php');
359
-	if (!defined('SMF'))
360
-		define('SMF', 1);
361
-	if (empty($smcFunc))
362
-		$smcFunc = array();
374
+	if (!defined('SMF')) {
375
+			define('SMF', 1);
376
+	}
377
+	if (empty($smcFunc)) {
378
+			$smcFunc = array();
379
+	}
363 380
 
364 381
 	$modSettings['disableQueryCheck'] = true;
365 382
 
@@ -367,8 +384,9 @@  discard block
 block discarded – undo
367 384
 	if (!$db_connection)
368 385
 	{
369 386
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
370
-		if (version_compare(PHP_VERSION, '5', '<'))
371
-			require_once($sourcedir . '/Subs-Compat.php');
387
+		if (version_compare(PHP_VERSION, '5', '<')) {
388
+					require_once($sourcedir . '/Subs-Compat.php');
389
+		}
372 390
 
373 391
 		$db_options = array('persist' => $db_persist);
374 392
 		$port = '';
@@ -379,19 +397,20 @@  discard block
 block discarded – undo
379 397
 			if ($db_type == 'mysql' || $db_type == 'mysqli')
380 398
 			{
381 399
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
382
-			}
383
-			elseif ($db_type == 'postgresql')
400
+			} elseif ($db_type == 'postgresql')
384 401
 			{
385 402
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
386 403
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
387 404
 			}
388 405
 		}
389 406
 
390
-		if (!empty($port))
391
-			$db_options['port'] = $port;
407
+		if (!empty($port)) {
408
+					$db_options['port'] = $port;
409
+		}
392 410
 
393
-		if (!$db_connection)
394
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
411
+		if (!$db_connection) {
412
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
413
+		}
395 414
 	}
396 415
 }
397 416
 
@@ -419,8 +438,9 @@  discard block
 block discarded – undo
419 438
 		// @todo REMOVE THIS!!
420 439
 		else
421 440
 		{
422
-			if (function_exists('doStep' . $_GET['step']))
423
-				call_user_func('doStep' . $_GET['step']);
441
+			if (function_exists('doStep' . $_GET['step'])) {
442
+							call_user_func('doStep' . $_GET['step']);
443
+			}
424 444
 		}
425 445
 		// Show the footer.
426 446
 		template_install_below();
@@ -438,8 +458,9 @@  discard block
 block discarded – undo
438 458
 	$incontext['sub_template'] = 'welcome_message';
439 459
 
440 460
 	// Done the submission?
441
-	if (isset($_POST['contbutt']))
442
-		return true;
461
+	if (isset($_POST['contbutt'])) {
462
+			return true;
463
+	}
443 464
 
444 465
 	// See if we think they have already installed it?
445 466
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -447,14 +468,17 @@  discard block
 block discarded – undo
447 468
 		$probably_installed = 0;
448 469
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
449 470
 		{
450
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
451
-				$probably_installed++;
452
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
453
-				$probably_installed++;
471
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
472
+							$probably_installed++;
473
+			}
474
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
475
+							$probably_installed++;
476
+			}
454 477
 		}
455 478
 
456
-		if ($probably_installed == 2)
457
-			$incontext['warning'] = $txt['error_already_installed'];
479
+		if ($probably_installed == 2) {
480
+					$incontext['warning'] = $txt['error_already_installed'];
481
+		}
458 482
 	}
459 483
 
460 484
 	// Is some database support even compiled in?
@@ -469,8 +493,7 @@  discard block
 block discarded – undo
469 493
 				$databases[$key]['supported'] = false;
470 494
 				$notFoundSQLFile = true;
471 495
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
472
-			}
473
-			else
496
+			} else
474 497
 			{
475 498
 				$db_type = $key;
476 499
 				$incontext['supported_databases'][] = $db;
@@ -479,29 +502,36 @@  discard block
 block discarded – undo
479 502
 	}
480 503
 
481 504
 	// Check the PHP version.
482
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>')))
483
-		$error = 'error_php_too_low';
505
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) {
506
+			$error = 'error_php_too_low';
507
+	}
484 508
 	// Make sure we have a supported database
485
-	elseif (empty($incontext['supported_databases']))
486
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
509
+	elseif (empty($incontext['supported_databases'])) {
510
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
511
+	}
487 512
 	// How about session support?  Some crazy sysadmin remove it?
488
-	elseif (!function_exists('session_start'))
489
-		$error = 'error_session_missing';
513
+	elseif (!function_exists('session_start')) {
514
+			$error = 'error_session_missing';
515
+	}
490 516
 	// Make sure they uploaded all the files.
491
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
492
-		$error = 'error_missing_files';
517
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
518
+			$error = 'error_missing_files';
519
+	}
493 520
 	// Very simple check on the session.save_path for Windows.
494 521
 	// @todo Move this down later if they don't use database-driven sessions?
495
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
496
-		$error = 'error_session_save_path';
522
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
523
+			$error = 'error_session_save_path';
524
+	}
497 525
 
498 526
 	// Since each of the three messages would look the same, anyway...
499
-	if (isset($error))
500
-		$incontext['error'] = $txt[$error];
527
+	if (isset($error)) {
528
+			$incontext['error'] = $txt[$error];
529
+	}
501 530
 
502 531
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
503
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
504
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
532
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
533
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
534
+	}
505 535
 
506 536
 	return false;
507 537
 }
@@ -524,15 +554,18 @@  discard block
 block discarded – undo
524 554
 		'agreement.txt',
525 555
 		'Settings.php'
526 556
 	);
527
-	if (file_exists(dirname(__FILE__) . '/Settings_bak.php'))
528
-		$writable_files[] = 'Settings_bak.php';
557
+	if (file_exists(dirname(__FILE__) . '/Settings_bak.php')) {
558
+			$writable_files[] = 'Settings_bak.php';
559
+	}
529 560
 
530
-	foreach ($incontext['detected_languages'] as $lang => $temp)
531
-		$extra_files[] = 'Themes/default/languages/' . $lang;
561
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
562
+			$extra_files[] = 'Themes/default/languages/' . $lang;
563
+	}
532 564
 
533 565
 	// With mod_security installed, we could attempt to fix it with .htaccess.
534
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
535
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
566
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
567
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
568
+	}
536 569
 
537 570
 	$failed_files = array();
538 571
 
@@ -548,12 +581,14 @@  discard block
 block discarded – undo
548 581
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
549 582
 
550 583
 				// Well, 755 hopefully worked... if not, try 777.
551
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
552
-					$failed_files[] = $file;
584
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
585
+									$failed_files[] = $file;
586
+				}
553 587
 			}
554 588
 		}
555
-		foreach ($extra_files as $file)
556
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
589
+		foreach ($extra_files as $file) {
590
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
591
+		}
557 592
 	}
558 593
 	// Windows is trickier.  Let's try opening for r+...
559 594
 	else
@@ -563,30 +598,35 @@  discard block
 block discarded – undo
563 598
 		foreach ($writable_files as $file)
564 599
 		{
565 600
 			// Folders can't be opened for write... but the index.php in them can ;)
566
-			if (is_dir(dirname(__FILE__) . '/' . $file))
567
-				$file .= '/index.php';
601
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
602
+							$file .= '/index.php';
603
+			}
568 604
 
569 605
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
570 606
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
571 607
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
572 608
 
573 609
 			// Hmm, okay, try just for write in that case...
574
-			if (!is_resource($fp))
575
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
610
+			if (!is_resource($fp)) {
611
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
612
+			}
576 613
 
577
-			if (!is_resource($fp))
578
-				$failed_files[] = $file;
614
+			if (!is_resource($fp)) {
615
+							$failed_files[] = $file;
616
+			}
579 617
 
580 618
 			@fclose($fp);
581 619
 		}
582
-		foreach ($extra_files as $file)
583
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
620
+		foreach ($extra_files as $file) {
621
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
622
+		}
584 623
 	}
585 624
 
586 625
 	$failure = count($failed_files) >= 1;
587 626
 
588
-	if (!isset($_SERVER))
589
-		return !$failure;
627
+	if (!isset($_SERVER)) {
628
+			return !$failure;
629
+	}
590 630
 
591 631
 	// Put the list into context.
592 632
 	$incontext['failed_files'] = $failed_files;
@@ -634,19 +674,23 @@  discard block
 block discarded – undo
634 674
 
635 675
 		if (!isset($ftp) || $ftp->error !== false)
636 676
 		{
637
-			if (!isset($ftp))
638
-				$ftp = new ftp_connection(null);
677
+			if (!isset($ftp)) {
678
+							$ftp = new ftp_connection(null);
679
+			}
639 680
 			// Save the error so we can mess with listing...
640
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
641
-				$incontext['ftp_errors'][] = $ftp->last_message;
681
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
682
+							$incontext['ftp_errors'][] = $ftp->last_message;
683
+			}
642 684
 
643 685
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
644 686
 
645
-			if (empty($_POST['ftp_path']) && $found_path)
646
-				$_POST['ftp_path'] = $detect_path;
687
+			if (empty($_POST['ftp_path']) && $found_path) {
688
+							$_POST['ftp_path'] = $detect_path;
689
+			}
647 690
 
648
-			if (!isset($_POST['ftp_username']))
649
-				$_POST['ftp_username'] = $username;
691
+			if (!isset($_POST['ftp_username'])) {
692
+							$_POST['ftp_username'] = $username;
693
+			}
650 694
 
651 695
 			// Set the username etc, into context.
652 696
 			$incontext['ftp'] = array(
@@ -658,8 +702,7 @@  discard block
 block discarded – undo
658 702
 			);
659 703
 
660 704
 			return false;
661
-		}
662
-		else
705
+		} else
663 706
 		{
664 707
 			$_SESSION['installer_temp_ftp'] = array(
665 708
 				'server' => $_POST['ftp_server'],
@@ -673,10 +716,12 @@  discard block
 block discarded – undo
673 716
 
674 717
 			foreach ($failed_files as $file)
675 718
 			{
676
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
677
-					$ftp->chmod($file, 0755);
678
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
679
-					$ftp->chmod($file, 0777);
719
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
720
+									$ftp->chmod($file, 0755);
721
+				}
722
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
723
+									$ftp->chmod($file, 0777);
724
+				}
680 725
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
681 726
 				{
682 727
 					$failed_files_updated[] = $file;
@@ -731,15 +776,17 @@  discard block
 block discarded – undo
731 776
 
732 777
 			if (!$foundOne)
733 778
 			{
734
-				if (isset($db['default_host']))
735
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
779
+				if (isset($db['default_host'])) {
780
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
781
+				}
736 782
 				if (isset($db['default_user']))
737 783
 				{
738 784
 					$incontext['db']['user'] = ini_get($db['default_user']);
739 785
 					$incontext['db']['name'] = ini_get($db['default_user']);
740 786
 				}
741
-				if (isset($db['default_password']))
742
-					$incontext['db']['pass'] = ini_get($db['default_password']);
787
+				if (isset($db['default_password'])) {
788
+									$incontext['db']['pass'] = ini_get($db['default_password']);
789
+				}
743 790
 
744 791
 				// For simplicity and less confusion, leave the port blank by default
745 792
 				$incontext['db']['port'] = '';
@@ -758,10 +805,10 @@  discard block
 block discarded – undo
758 805
 		$incontext['db']['server'] = $_POST['db_server'];
759 806
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
760 807
 
761
-		if (!empty($_POST['db_port']))
762
-			$incontext['db']['port'] = $_POST['db_port'];
763
-	}
764
-	else
808
+		if (!empty($_POST['db_port'])) {
809
+					$incontext['db']['port'] = $_POST['db_port'];
810
+		}
811
+	} else
765 812
 	{
766 813
 		$incontext['db']['prefix'] = 'smf_';
767 814
 	}
@@ -797,10 +844,11 @@  discard block
 block discarded – undo
797 844
 		if (!empty($_POST['db_port']))
798 845
 		{
799 846
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
800
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
801
-				$vars['db_port'] = (int) $_POST['db_port'];
802
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
803
-				$vars['db_port'] = (int) $_POST['db_port'];
847
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
848
+							$vars['db_port'] = (int) $_POST['db_port'];
849
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
850
+							$vars['db_port'] = (int) $_POST['db_port'];
851
+			}
804 852
 		}
805 853
 
806 854
 		// God I hope it saved!
@@ -813,8 +861,9 @@  discard block
 block discarded – undo
813 861
 		// Make sure it works.
814 862
 		require(dirname(__FILE__) . '/Settings.php');
815 863
 
816
-		if (empty($sourcedir))
817
-			$sourcedir = dirname(__FILE__) . '/Sources';
864
+		if (empty($sourcedir)) {
865
+					$sourcedir = dirname(__FILE__) . '/Sources';
866
+		}
818 867
 
819 868
 		// Better find the database file!
820 869
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -824,18 +873,21 @@  discard block
 block discarded – undo
824 873
 		}
825 874
 
826 875
 		// Now include it for database functions!
827
-		if (!defined('SMF'))
828
-			define('SMF', 1);
876
+		if (!defined('SMF')) {
877
+					define('SMF', 1);
878
+		}
829 879
 
830 880
 		$modSettings['disableQueryCheck'] = true;
831
-		if (empty($smcFunc))
832
-			$smcFunc = array();
881
+		if (empty($smcFunc)) {
882
+					$smcFunc = array();
883
+		}
833 884
 
834 885
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
835 886
 
836 887
 		// What - running PHP4? The shame!
837
-		if (version_compare(PHP_VERSION, '5', '<'))
838
-			require_once($sourcedir . '/Subs-Compat.php');
888
+		if (version_compare(PHP_VERSION, '5', '<')) {
889
+					require_once($sourcedir . '/Subs-Compat.php');
890
+		}
839 891
 
840 892
 		// Attempt a connection.
841 893
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -923,12 +975,14 @@  discard block
 block discarded – undo
923 975
 	$incontext['page_title'] = $txt['install_settings'];
924 976
 
925 977
 	// Let's see if we got the database type correct.
926
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
927
-		$db_type = $_POST['db_type'];
978
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
979
+			$db_type = $_POST['db_type'];
980
+	}
928 981
 
929 982
 	// Else we'd better be able to get the connection.
930
-	else
931
-		load_database();
983
+	else {
984
+			load_database();
985
+	}
932 986
 
933 987
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
934 988
 
@@ -948,12 +1002,14 @@  discard block
 block discarded – undo
948 1002
 	// Submitting?
949 1003
 	if (isset($_POST['boardurl']))
950 1004
 	{
951
-		if (substr($_POST['boardurl'], -10) == '/index.php')
952
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
953
-		elseif (substr($_POST['boardurl'], -1) == '/')
954
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
955
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
956
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1005
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1006
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1007
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1008
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1009
+		}
1010
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1011
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1012
+		}
957 1013
 
958 1014
 		// Save these variables.
959 1015
 		$vars = array(
@@ -984,10 +1040,10 @@  discard block
 block discarded – undo
984 1040
 			{
985 1041
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
986 1042
 				return false;
987
-			}
988
-			else
989
-				// Set the character set here.
1043
+			} else {
1044
+							// Set the character set here.
990 1045
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1046
+			}
991 1047
 		}
992 1048
 
993 1049
 		// Good, skip on.
@@ -1007,8 +1063,9 @@  discard block
 block discarded – undo
1007 1063
 	$incontext['continue'] = 1;
1008 1064
 
1009 1065
 	// Already done?
1010
-	if (isset($_POST['pop_done']))
1011
-		return true;
1066
+	if (isset($_POST['pop_done'])) {
1067
+			return true;
1068
+	}
1012 1069
 
1013 1070
 	// Reload settings.
1014 1071
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1026,8 +1083,9 @@  discard block
 block discarded – undo
1026 1083
 	$modSettings = array();
1027 1084
 	if ($result !== false)
1028 1085
 	{
1029
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1030
-			$modSettings[$row['variable']] = $row['value'];
1086
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1087
+					$modSettings[$row['variable']] = $row['value'];
1088
+		}
1031 1089
 		$smcFunc['db_free_result']($result);
1032 1090
 
1033 1091
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1040,20 +1098,22 @@  discard block
 block discarded – undo
1040 1098
 	$modSettings['disableQueryCheck'] = true;
1041 1099
 
1042 1100
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1043
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1044
-		$smcFunc['db_query']('', '
1101
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1102
+			$smcFunc['db_query']('', '
1045 1103
 			SET NAMES {string:utf8}',
1046 1104
 			array(
1047 1105
 				'db_error_skip' => true,
1048 1106
 				'utf8' => 'utf8',
1049 1107
 			)
1050 1108
 		);
1109
+	}
1051 1110
 
1052 1111
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1053
-	if (substr(__DIR__, -1) == '\\')
1054
-		$attachdir = __DIR__ . 'attachments';
1055
-	else
1056
-		$attachdir = __DIR__ . '/attachments';
1112
+	if (substr(__DIR__, -1) == '\\') {
1113
+			$attachdir = __DIR__ . 'attachments';
1114
+	} else {
1115
+			$attachdir = __DIR__ . '/attachments';
1116
+	}
1057 1117
 
1058 1118
 	$replaces = array(
1059 1119
 		'{$db_prefix}' => $db_prefix,
@@ -1070,8 +1130,9 @@  discard block
 block discarded – undo
1070 1130
 
1071 1131
 	foreach ($txt as $key => $value)
1072 1132
 	{
1073
-		if (substr($key, 0, 8) == 'default_')
1074
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1133
+		if (substr($key, 0, 8) == 'default_') {
1134
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1135
+		}
1075 1136
 	}
1076 1137
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1077 1138
 
@@ -1086,8 +1147,9 @@  discard block
 block discarded – undo
1086 1147
 
1087 1148
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1088 1149
 		{
1089
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1090
-				$engines[] = $row['Engine'];
1150
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1151
+							$engines[] = $row['Engine'];
1152
+			}
1091 1153
 		}
1092 1154
 
1093 1155
 		// Done with this now
@@ -1111,8 +1173,7 @@  discard block
 block discarded – undo
1111 1173
 			$replaces['START TRANSACTION;'] = '';
1112 1174
 			$replaces['COMMIT;'] = '';
1113 1175
 		}
1114
-	}
1115
-	else
1176
+	} else
1116 1177
 	{
1117 1178
 		$has_innodb = false;
1118 1179
 	}
@@ -1134,21 +1195,24 @@  discard block
 block discarded – undo
1134 1195
 	foreach ($sql_lines as $count => $line)
1135 1196
 	{
1136 1197
 		// No comments allowed!
1137
-		if (substr(trim($line), 0, 1) != '#')
1138
-			$current_statement .= "\n" . rtrim($line);
1198
+		if (substr(trim($line), 0, 1) != '#') {
1199
+					$current_statement .= "\n" . rtrim($line);
1200
+		}
1139 1201
 
1140 1202
 		// Is this the end of the query string?
1141
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1142
-			continue;
1203
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1204
+					continue;
1205
+		}
1143 1206
 
1144 1207
 		// Does this table already exist?  If so, don't insert more data into it!
1145 1208
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1146 1209
 		{
1147 1210
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1148
-			if (!empty($matches[0]))
1149
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1150
-			else
1151
-				$incontext['sql_results']['insert_dups']++;
1211
+			if (!empty($matches[0])) {
1212
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1213
+			} else {
1214
+							$incontext['sql_results']['insert_dups']++;
1215
+			}
1152 1216
 
1153 1217
 			$current_statement = '';
1154 1218
 			continue;
@@ -1157,8 +1221,9 @@  discard block
 block discarded – undo
1157 1221
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1158 1222
 		{
1159 1223
 			// Use the appropriate function based on the DB type
1160
-			if ($db_type == 'mysql' || $db_type =='mysqli')
1161
-				$db_errorno = $db_type . '_errno';
1224
+			if ($db_type == 'mysql' || $db_type =='mysqli') {
1225
+							$db_errorno = $db_type . '_errno';
1226
+			}
1162 1227
 
1163 1228
 			// Error 1050: Table already exists!
1164 1229
 			// @todo Needs to be made better!
@@ -1173,18 +1238,18 @@  discard block
 block discarded – undo
1173 1238
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1174 1239
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1175 1240
 			}
1176
-		}
1177
-		else
1241
+		} else
1178 1242
 		{
1179
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1180
-				$incontext['sql_results']['tables']++;
1181
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1243
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1244
+							$incontext['sql_results']['tables']++;
1245
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1182 1246
 			{
1183 1247
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1184
-				if (!empty($matches[0]))
1185
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1186
-				else
1187
-					$incontext['sql_results']['inserts']++;
1248
+				if (!empty($matches[0])) {
1249
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1250
+				} else {
1251
+									$incontext['sql_results']['inserts']++;
1252
+				}
1188 1253
 			}
1189 1254
 		}
1190 1255
 
@@ -1197,15 +1262,17 @@  discard block
 block discarded – undo
1197 1262
 	// Sort out the context for the SQL.
1198 1263
 	foreach ($incontext['sql_results'] as $key => $number)
1199 1264
 	{
1200
-		if ($number == 0)
1201
-			unset($incontext['sql_results'][$key]);
1202
-		else
1203
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1265
+		if ($number == 0) {
1266
+					unset($incontext['sql_results'][$key]);
1267
+		} else {
1268
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1269
+		}
1204 1270
 	}
1205 1271
 
1206 1272
 	// Make sure UTF will be used globally.
1207
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1208
-		$newSettings[] = array('global_character_set', 'UTF-8');
1273
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1274
+			$newSettings[] = array('global_character_set', 'UTF-8');
1275
+	}
1209 1276
 
1210 1277
 	// Maybe we can auto-detect better cookie settings?
1211 1278
 	preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
@@ -1216,16 +1283,20 @@  discard block
 block discarded – undo
1216 1283
 		$globalCookies = false;
1217 1284
 
1218 1285
 		// Okay... let's see.  Using a subdomain other than www.? (not a perfect check.)
1219
-		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
1220
-			$globalCookies = true;
1286
+		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) {
1287
+					$globalCookies = true;
1288
+		}
1221 1289
 		// If there's a / in the middle of the path, or it starts with ~... we want local.
1222
-		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
1223
-			$localCookies = true;
1290
+		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) {
1291
+					$localCookies = true;
1292
+		}
1224 1293
 
1225
-		if ($globalCookies)
1226
-			$newSettings[] = array('globalCookies', '1');
1227
-		if ($localCookies)
1228
-			$newSettings[] = array('localCookies', '1');
1294
+		if ($globalCookies) {
1295
+					$newSettings[] = array('globalCookies', '1');
1296
+		}
1297
+		if ($localCookies) {
1298
+					$newSettings[] = array('localCookies', '1');
1299
+		}
1229 1300
 	}
1230 1301
 
1231 1302
 	// Are we allowing stat collection?
@@ -1241,32 +1312,36 @@  discard block
 block discarded – undo
1241 1312
 			fwrite($fp, $out);
1242 1313
 
1243 1314
 			$return_data = '';
1244
-			while (!feof($fp))
1245
-				$return_data .= fgets($fp, 128);
1315
+			while (!feof($fp)) {
1316
+							$return_data .= fgets($fp, 128);
1317
+			}
1246 1318
 
1247 1319
 			fclose($fp);
1248 1320
 
1249 1321
 			// Get the unique site ID.
1250 1322
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1251 1323
 
1252
-			if (!empty($ID[1]))
1253
-				$newSettings[] = array('allow_sm_stats', $ID[1]);
1324
+			if (!empty($ID[1])) {
1325
+							$newSettings[] = array('allow_sm_stats', $ID[1]);
1326
+			}
1254 1327
 		}
1255 1328
 	}
1256 1329
 
1257 1330
 	// Are we enabling SSL?
1258
-	if (!empty($_POST['force_ssl']))
1259
-		$newSettings[] = array('force_ssl', 2);
1331
+	if (!empty($_POST['force_ssl'])) {
1332
+			$newSettings[] = array('force_ssl', 2);
1333
+	}
1260 1334
 
1261 1335
 	// Setting a timezone is required.
1262 1336
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1263 1337
 	{
1264 1338
 		// Get PHP's default timezone, if set
1265 1339
 		$ini_tz = ini_get('date.timezone');
1266
-		if (!empty($ini_tz))
1267
-			$timezone_id = $ini_tz;
1268
-		else
1269
-			$timezone_id = '';
1340
+		if (!empty($ini_tz)) {
1341
+					$timezone_id = $ini_tz;
1342
+		} else {
1343
+					$timezone_id = '';
1344
+		}
1270 1345
 
1271 1346
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1272 1347
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1275,8 +1350,9 @@  discard block
 block discarded – undo
1275 1350
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1276 1351
 		}
1277 1352
 
1278
-		if (date_default_timezone_set($timezone_id))
1279
-			$newSettings[] = array('default_timezone', $timezone_id);
1353
+		if (date_default_timezone_set($timezone_id)) {
1354
+					$newSettings[] = array('default_timezone', $timezone_id);
1355
+		}
1280 1356
 	}
1281 1357
 
1282 1358
 	if (!empty($newSettings))
@@ -1307,16 +1383,18 @@  discard block
 block discarded – undo
1307 1383
 	}
1308 1384
 
1309 1385
 	// MySQL specific stuff
1310
-	if (substr($db_type, 0, 5) != 'mysql')
1311
-		return false;
1386
+	if (substr($db_type, 0, 5) != 'mysql') {
1387
+			return false;
1388
+	}
1312 1389
 
1313 1390
 	// Find database user privileges.
1314 1391
 	$privs = array();
1315 1392
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1316 1393
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1317 1394
 	{
1318
-		if ($row['Privilege'] == 'Alter')
1319
-			$privs[] = $row['Privilege'];
1395
+		if ($row['Privilege'] == 'Alter') {
1396
+					$privs[] = $row['Privilege'];
1397
+		}
1320 1398
 	}
1321 1399
 	$smcFunc['db_free_result']($get_privs);
1322 1400
 
@@ -1346,8 +1424,9 @@  discard block
 block discarded – undo
1346 1424
 	$incontext['continue'] = 1;
1347 1425
 
1348 1426
 	// Skipping?
1349
-	if (!empty($_POST['skip']))
1350
-		return true;
1427
+	if (!empty($_POST['skip'])) {
1428
+			return true;
1429
+	}
1351 1430
 
1352 1431
 	// Need this to check whether we need the database password.
1353 1432
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1361,18 +1440,22 @@  discard block
 block discarded – undo
1361 1440
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1362 1441
 		function($string){
1363 1442
 			global $sourcedir;
1364
-			if (function_exists('mb_strtolower'))
1365
-				return mb_strtolower($string, 'UTF-8');
1443
+			if (function_exists('mb_strtolower')) {
1444
+							return mb_strtolower($string, 'UTF-8');
1445
+			}
1366 1446
 			require_once($sourcedir . '/Subs-Charset.php');
1367 1447
 			return utf8_strtolower($string);
1368 1448
 		};
1369 1449
 
1370
-	if (!isset($_POST['username']))
1371
-		$_POST['username'] = '';
1372
-	if (!isset($_POST['email']))
1373
-		$_POST['email'] = '';
1374
-	if (!isset($_POST['server_email']))
1375
-		$_POST['server_email'] = '';
1450
+	if (!isset($_POST['username'])) {
1451
+			$_POST['username'] = '';
1452
+	}
1453
+	if (!isset($_POST['email'])) {
1454
+			$_POST['email'] = '';
1455
+	}
1456
+	if (!isset($_POST['server_email'])) {
1457
+			$_POST['server_email'] = '';
1458
+	}
1376 1459
 
1377 1460
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1378 1461
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1391,8 +1474,9 @@  discard block
 block discarded – undo
1391 1474
 			'admin_group' => 1,
1392 1475
 		)
1393 1476
 	);
1394
-	if ($smcFunc['db_num_rows']($request) != 0)
1395
-		$incontext['skip'] = 1;
1477
+	if ($smcFunc['db_num_rows']($request) != 0) {
1478
+			$incontext['skip'] = 1;
1479
+	}
1396 1480
 	$smcFunc['db_free_result']($request);
1397 1481
 
1398 1482
 	// Trying to create an account?
@@ -1423,8 +1507,9 @@  discard block
 block discarded – undo
1423 1507
 		}
1424 1508
 
1425 1509
 		// Update the webmaster's email?
1426
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1427
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1510
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1511
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1512
+		}
1428 1513
 
1429 1514
 		// Work out whether we're going to have dodgy characters and remove them.
1430 1515
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1447,32 +1532,27 @@  discard block
 block discarded – undo
1447 1532
 			$smcFunc['db_free_result']($result);
1448 1533
 
1449 1534
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1450
-		}
1451
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1535
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1452 1536
 		{
1453 1537
 			// Try the previous step again.
1454 1538
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1455 1539
 			return false;
1456
-		}
1457
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1540
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1458 1541
 		{
1459 1542
 			// Try the previous step again.
1460 1543
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1461 1544
 			return false;
1462
-		}
1463
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1545
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1464 1546
 		{
1465 1547
 			// One step back, this time fill out a proper admin email address.
1466 1548
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1467 1549
 			return false;
1468
-		}
1469
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1550
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1470 1551
 		{
1471 1552
 			// One step back, this time fill out a proper admin email address.
1472 1553
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1473 1554
 			return false;
1474
-		}
1475
-		elseif ($_POST['username'] != '')
1555
+		} elseif ($_POST['username'] != '')
1476 1556
 		{
1477 1557
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1478 1558
 
@@ -1547,17 +1627,19 @@  discard block
 block discarded – undo
1547 1627
 	require_once($sourcedir . '/Subs-Auth.php');
1548 1628
 
1549 1629
 	// Bring a warning over.
1550
-	if (!empty($incontext['account_existed']))
1551
-		$incontext['warning'] = $incontext['account_existed'];
1630
+	if (!empty($incontext['account_existed'])) {
1631
+			$incontext['warning'] = $incontext['account_existed'];
1632
+	}
1552 1633
 
1553
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1554
-		$smcFunc['db_query']('', '
1634
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1635
+			$smcFunc['db_query']('', '
1555 1636
 			SET NAMES {string:db_character_set}',
1556 1637
 			array(
1557 1638
 				'db_character_set' => $db_character_set,
1558 1639
 				'db_error_skip' => true,
1559 1640
 			)
1560 1641
 		);
1642
+	}
1561 1643
 
1562 1644
 	// As track stats is by default enabled let's add some activity.
1563 1645
 	$smcFunc['db_insert']('ignore',
@@ -1578,14 +1660,16 @@  discard block
 block discarded – undo
1578 1660
 	// Only proceed if we can load the data.
1579 1661
 	if ($request)
1580 1662
 	{
1581
-		while ($row = $smcFunc['db_fetch_row']($request))
1582
-			$modSettings[$row[0]] = $row[1];
1663
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1664
+					$modSettings[$row[0]] = $row[1];
1665
+		}
1583 1666
 		$smcFunc['db_free_result']($request);
1584 1667
 	}
1585 1668
 
1586 1669
 	// Automatically log them in ;)
1587
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1588
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1670
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1671
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1672
+	}
1589 1673
 
1590 1674
 	$result = $smcFunc['db_query']('', '
1591 1675
 		SELECT value
@@ -1596,13 +1680,14 @@  discard block
 block discarded – undo
1596 1680
 			'db_error_skip' => true,
1597 1681
 		)
1598 1682
 	);
1599
-	if ($smcFunc['db_num_rows']($result) != 0)
1600
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1683
+	if ($smcFunc['db_num_rows']($result) != 0) {
1684
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1685
+	}
1601 1686
 	$smcFunc['db_free_result']($result);
1602 1687
 
1603
-	if (empty($db_sessions))
1604
-		$_SESSION['admin_time'] = time();
1605
-	else
1688
+	if (empty($db_sessions)) {
1689
+			$_SESSION['admin_time'] = time();
1690
+	} else
1606 1691
 	{
1607 1692
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1608 1693
 
@@ -1626,8 +1711,9 @@  discard block
 block discarded – undo
1626 1711
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1627 1712
 		function($string){
1628 1713
 			global $sourcedir;
1629
-			if (function_exists('mb_strtolower'))
1630
-				return mb_strtolower($string, 'UTF-8');
1714
+			if (function_exists('mb_strtolower')) {
1715
+							return mb_strtolower($string, 'UTF-8');
1716
+			}
1631 1717
 			require_once($sourcedir . '/Subs-Charset.php');
1632 1718
 			return utf8_strtolower($string);
1633 1719
 		};
@@ -1643,8 +1729,9 @@  discard block
 block discarded – undo
1643 1729
 		)
1644 1730
 	);
1645 1731
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1646
-	if ($smcFunc['db_num_rows']($request) > 0)
1647
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1732
+	if ($smcFunc['db_num_rows']($request) > 0) {
1733
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1734
+	}
1648 1735
 	$smcFunc['db_free_result']($request);
1649 1736
 
1650 1737
 	// Now is the perfect time to fetch the SM files.
@@ -1663,8 +1750,9 @@  discard block
 block discarded – undo
1663 1750
 
1664 1751
 	// Check if we need some stupid MySQL fix.
1665 1752
 	$server_version = $smcFunc['db_server_info']();
1666
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1667
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1753
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1754
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1755
+	}
1668 1756
 
1669 1757
 	// Some final context for the template.
1670 1758
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1684,8 +1772,9 @@  discard block
 block discarded – undo
1684 1772
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1685 1773
 
1686 1774
 	// @todo Do we just want to read the file in clean, and split it this way always?
1687
-	if (count($settingsArray) == 1)
1688
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1775
+	if (count($settingsArray) == 1) {
1776
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1777
+	}
1689 1778
 
1690 1779
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1691 1780
 	{
@@ -1700,19 +1789,22 @@  discard block
 block discarded – undo
1700 1789
 			continue;
1701 1790
 		}
1702 1791
 
1703
-		if (trim($settingsArray[$i]) == '?' . '>')
1704
-			$settingsArray[$i] = '';
1792
+		if (trim($settingsArray[$i]) == '?' . '>') {
1793
+					$settingsArray[$i] = '';
1794
+		}
1705 1795
 
1706 1796
 		// Don't trim or bother with it if it's not a variable.
1707
-		if (substr($settingsArray[$i], 0, 1) != '$')
1708
-			continue;
1797
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1798
+					continue;
1799
+		}
1709 1800
 
1710 1801
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1711 1802
 
1712
-		foreach ($vars as $var => $val)
1713
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1803
+		foreach ($vars as $var => $val) {
1804
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1714 1805
 			{
1715 1806
 				$comment = strstr($settingsArray[$i], '#');
1807
+		}
1716 1808
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1717 1809
 				unset($vars[$var]);
1718 1810
 			}
@@ -1722,36 +1814,41 @@  discard block
 block discarded – undo
1722 1814
 	if (!empty($vars))
1723 1815
 	{
1724 1816
 		$settingsArray[$i++] = '';
1725
-		foreach ($vars as $var => $val)
1726
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1817
+		foreach ($vars as $var => $val) {
1818
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1819
+		}
1727 1820
 	}
1728 1821
 
1729 1822
 	// Blank out the file - done to fix a oddity with some servers.
1730 1823
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1731
-	if (!$fp)
1732
-		return false;
1824
+	if (!$fp) {
1825
+			return false;
1826
+	}
1733 1827
 	fclose($fp);
1734 1828
 
1735 1829
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1736 1830
 
1737 1831
 	// Gotta have one of these ;)
1738
-	if (trim($settingsArray[0]) != '<?php')
1739
-		fwrite($fp, "<?php\n");
1832
+	if (trim($settingsArray[0]) != '<?php') {
1833
+			fwrite($fp, "<?php\n");
1834
+	}
1740 1835
 
1741 1836
 	$lines = count($settingsArray);
1742 1837
 	for ($i = 0; $i < $lines - 1; $i++)
1743 1838
 	{
1744 1839
 		// Don't just write a bunch of blank lines.
1745
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1746
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1840
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1841
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1842
+		}
1747 1843
 	}
1748 1844
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1749 1845
 	fclose($fp);
1750 1846
 
1751 1847
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1752 1848
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1753
-	if (function_exists('opcache_invalidate'))
1754
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1849
+	if (function_exists('opcache_invalidate')) {
1850
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1851
+	}
1755 1852
 
1756 1853
 	return true;
1757 1854
 }
@@ -1776,9 +1873,9 @@  discard block
 block discarded – undo
1776 1873
 	SecFilterScanPOST Off
1777 1874
 </IfModule>';
1778 1875
 
1779
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1780
-		return true;
1781
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1876
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1877
+			return true;
1878
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1782 1879
 	{
1783 1880
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1784 1881
 
@@ -1790,29 +1887,28 @@  discard block
 block discarded – undo
1790 1887
 				fwrite($ht_handle, $htaccess_addition);
1791 1888
 				fclose($ht_handle);
1792 1889
 				return true;
1890
+			} else {
1891
+							return false;
1793 1892
 			}
1794
-			else
1795
-				return false;
1893
+		} else {
1894
+					return true;
1796 1895
 		}
1797
-		else
1798
-			return true;
1799
-	}
1800
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1801
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1802
-	elseif (is_writable(dirname(__FILE__)))
1896
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1897
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1898
+	} elseif (is_writable(dirname(__FILE__)))
1803 1899
 	{
1804 1900
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1805 1901
 		{
1806 1902
 			fwrite($ht_handle, $htaccess_addition);
1807 1903
 			fclose($ht_handle);
1808 1904
 			return true;
1905
+		} else {
1906
+					return false;
1809 1907
 		}
1810
-		else
1908
+	} else {
1811 1909
 			return false;
1812 1910
 	}
1813
-	else
1814
-		return false;
1815
-}
1911
+	}
1816 1912
 
1817 1913
 function template_install_above()
1818 1914
 {
@@ -1850,9 +1946,10 @@  discard block
 block discarded – undo
1850 1946
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1851 1947
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1852 1948
 
1853
-		foreach ($incontext['detected_languages'] as $lang => $name)
1854
-			echo '
1949
+		foreach ($incontext['detected_languages'] as $lang => $name) {
1950
+					echo '
1855 1951
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
1952
+		}
1856 1953
 
1857 1954
 		echo '
1858 1955
 								</select>
@@ -1872,9 +1969,10 @@  discard block
 block discarded – undo
1872 1969
 						<h2>', $txt['upgrade_progress'], '</h2>
1873 1970
 						<ul>';
1874 1971
 
1875
-	foreach ($incontext['steps'] as $num => $step)
1876
-		echo '
1972
+	foreach ($incontext['steps'] as $num => $step) {
1973
+			echo '
1877 1974
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
1975
+	}
1878 1976
 
1879 1977
 	echo '
1880 1978
 						</ul>
@@ -1899,20 +1997,23 @@  discard block
 block discarded – undo
1899 1997
 		echo '
1900 1998
 								<div>';
1901 1999
 
1902
-		if (!empty($incontext['continue']))
1903
-			echo '
2000
+		if (!empty($incontext['continue'])) {
2001
+					echo '
1904 2002
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1905
-		if (!empty($incontext['skip']))
1906
-			echo '
2003
+		}
2004
+		if (!empty($incontext['skip'])) {
2005
+					echo '
1907 2006
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
2007
+		}
1908 2008
 		echo '
1909 2009
 								</div>';
1910 2010
 	}
1911 2011
 
1912 2012
 	// Show the closing form tag and other data only if not in the last step
1913
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1914
-		echo '
2013
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2014
+			echo '
1915 2015
 							</form>';
2016
+	}
1916 2017
 
1917 2018
 	echo '
1918 2019
 						</div>
@@ -1947,13 +2048,15 @@  discard block
 block discarded – undo
1947 2048
 		</div>';
1948 2049
 
1949 2050
 	// Show the warnings, or not.
1950
-	if (template_warning_divs())
1951
-		echo '
2051
+	if (template_warning_divs()) {
2052
+			echo '
1952 2053
 		<h3>', $txt['install_all_lovely'], '</h3>';
2054
+	}
1953 2055
 
1954 2056
 	// Say we want the continue button!
1955
-	if (empty($incontext['error']))
1956
-		$incontext['continue'] = 1;
2057
+	if (empty($incontext['error'])) {
2058
+			$incontext['continue'] = 1;
2059
+	}
1957 2060
 
1958 2061
 	// For the latest version stuff.
1959 2062
 	echo '
@@ -1987,8 +2090,8 @@  discard block
 block discarded – undo
1987 2090
 	global $txt, $incontext;
1988 2091
 
1989 2092
 	// Errors are very serious..
1990
-	if (!empty($incontext['error']))
1991
-		echo '
2093
+	if (!empty($incontext['error'])) {
2094
+			echo '
1992 2095
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1993 2096
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1994 2097
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -1996,9 +2099,10 @@  discard block
 block discarded – undo
1996 2099
 				', $incontext['error'], '
1997 2100
 			</div>
1998 2101
 		</div>';
2102
+	}
1999 2103
 	// A warning message?
2000
-	elseif (!empty($incontext['warning']))
2001
-		echo '
2104
+	elseif (!empty($incontext['warning'])) {
2105
+			echo '
2002 2106
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
2003 2107
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2004 2108
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -2006,6 +2110,7 @@  discard block
 block discarded – undo
2006 2110
 				', $incontext['warning'], '
2007 2111
 			</div>
2008 2112
 		</div>';
2113
+	}
2009 2114
 
2010 2115
 	return empty($incontext['error']) && empty($incontext['warning']);
2011 2116
 }
@@ -2021,27 +2126,30 @@  discard block
 block discarded – undo
2021 2126
 			<li>', $incontext['failed_files']), '</li>
2022 2127
 		</ul>';
2023 2128
 
2024
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2025
-		echo '
2129
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2130
+			echo '
2026 2131
 		<hr>
2027 2132
 		<p>', $txt['chmod_linux_info'], '</p>
2028 2133
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2134
+	}
2029 2135
 
2030 2136
 	// This is serious!
2031
-	if (!template_warning_divs())
2032
-		return;
2137
+	if (!template_warning_divs()) {
2138
+			return;
2139
+	}
2033 2140
 
2034 2141
 	echo '
2035 2142
 		<hr>
2036 2143
 		<p>', $txt['ftp_setup_info'], '</p>';
2037 2144
 
2038
-	if (!empty($incontext['ftp_errors']))
2039
-		echo '
2145
+	if (!empty($incontext['ftp_errors'])) {
2146
+			echo '
2040 2147
 		<div class="error_message">
2041 2148
 			', $txt['error_ftp_no_connect'], '<br><br>
2042 2149
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2043 2150
 		</div>
2044 2151
 		<br>';
2152
+	}
2045 2153
 
2046 2154
 	echo '
2047 2155
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2101,17 +2209,17 @@  discard block
 block discarded – undo
2101 2209
 				<td>
2102 2210
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2103 2211
 
2104
-	foreach ($incontext['supported_databases'] as $key => $db)
2105
-			echo '
2212
+	foreach ($incontext['supported_databases'] as $key => $db) {
2213
+				echo '
2106 2214
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2215
+	}
2107 2216
 
2108 2217
 	echo '
2109 2218
 					</select>
2110 2219
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2111 2220
 				</td>
2112 2221
 			</tr>';
2113
-	}
2114
-	else
2222
+	} else
2115 2223
 	{
2116 2224
 		echo '
2117 2225
 			<tr style="display: none;">
@@ -2303,9 +2411,10 @@  discard block
 block discarded – undo
2303 2411
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2304 2412
 				<ul>';
2305 2413
 
2306
-		foreach ($incontext['failures'] as $line => $fail)
2307
-			echo '
2414
+		foreach ($incontext['failures'] as $line => $fail) {
2415
+					echo '
2308 2416
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2417
+		}
2309 2418
 
2310 2419
 		echo '
2311 2420
 				</ul>';
@@ -2366,15 +2475,16 @@  discard block
 block discarded – undo
2366 2475
 			</tr>
2367 2476
 		</table>';
2368 2477
 
2369
-	if ($incontext['require_db_confirm'])
2370
-		echo '
2478
+	if ($incontext['require_db_confirm']) {
2479
+			echo '
2371 2480
 		<h2>', $txt['user_settings_database'], '</h2>
2372 2481
 		<p>', $txt['user_settings_database_info'], '</p>
2373 2482
 
2374 2483
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2375 2484
 			<input type="password" name="password3" size="30" class="input_password" />
2376 2485
 		</div>';
2377
-}
2486
+	}
2487
+	}
2378 2488
 
2379 2489
 // Tell them it's done, and to delete.
2380 2490
 function template_delete_install()
@@ -2387,14 +2497,15 @@  discard block
 block discarded – undo
2387 2497
 	template_warning_divs();
2388 2498
 
2389 2499
 	// Install directory still writable?
2390
-	if ($incontext['dir_still_writable'])
2391
-		echo '
2500
+	if ($incontext['dir_still_writable']) {
2501
+			echo '
2392 2502
 		<em>', $txt['still_writable'], '</em><br>
2393 2503
 		<br>';
2504
+	}
2394 2505
 
2395 2506
 	// Don't show the box if it's like 99% sure it won't work :P.
2396
-	if ($incontext['probably_delete_install'])
2397
-		echo '
2507
+	if ($incontext['probably_delete_install']) {
2508
+			echo '
2398 2509
 		<div style="margin: 1ex; font-weight: bold;">
2399 2510
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" class="input_check" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
2400 2511
 		</div>
@@ -2410,6 +2521,7 @@  discard block
 block discarded – undo
2410 2521
 			}
2411 2522
 		</script>
2412 2523
 		<br>';
2524
+	}
2413 2525
 
2414 2526
 	echo '
2415 2527
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.
Themes/default/Display.template.php 1 patch
Braces   +221 added lines, -151 removed lines patch added patch discarded remove patch
@@ -51,11 +51,13 @@  discard block
 block discarded – undo
51 51
 				<p>';
52 52
 
53 53
 		// Show just numbers...?
54
-		if ($settings['display_who_viewing'] == 1)
55
-				echo count($context['view_members']), ' ', count($context['view_members']) == 1 ? $txt['who_member'] : $txt['members'];
54
+		if ($settings['display_who_viewing'] == 1) {
55
+						echo count($context['view_members']), ' ', count($context['view_members']) == 1 ? $txt['who_member'] : $txt['members'];
56
+		}
56 57
 		// Or show the actual people viewing the topic?
57
-		else
58
-			echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . ((empty($context['view_num_hidden']) || $context['can_moderate_forum']) ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
58
+		else {
59
+					echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . ((empty($context['view_num_hidden']) || $context['can_moderate_forum']) ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
60
+		}
59 61
 
60 62
 		// Now show how many guests are here too.
61 63
 		echo $txt['who_and'], $context['view_num_guests'], ' ', $context['view_num_guests'] == 1 ? $txt['guest'] : $txt['guests'], $txt['who_viewing_topic'], '
@@ -93,10 +95,11 @@  discard block
 block discarded – undo
93 95
 						<dt class="', $option['voted_this'] ? ' voted' : '', '">', $option['option'], '</dt>
94 96
 						<dd class="statsbar', $option['voted_this'] ? ' voted' : '', '">';
95 97
 
96
-				if ($context['allow_results_view'])
97
-					echo '
98
+				if ($context['allow_results_view']) {
99
+									echo '
98 100
 							', $option['bar_ndt'], '
99 101
 							<span class="percentage">', $option['votes'], ' (', $option['percent'], '%)</span>';
102
+				}
100 103
 
101 104
 				echo '
102 105
 						</dd>';
@@ -105,9 +108,10 @@  discard block
 block discarded – undo
105 108
 			echo '
106 109
 					</dl>';
107 110
 
108
-			if ($context['allow_results_view'])
109
-				echo '
111
+			if ($context['allow_results_view']) {
112
+							echo '
110 113
 						<p><strong>', $txt['poll_total_voters'], ':</strong> ', $context['poll']['total_votes'], '</p>';
114
+			}
111 115
 		}
112 116
 		// They are allowed to vote! Go to it!
113 117
 		else
@@ -116,17 +120,19 @@  discard block
 block discarded – undo
116 120
 						<form action="', $scripturl, '?action=vote;topic=', $context['current_topic'], '.', $context['start'], ';poll=', $context['poll']['id'], '" method="post" accept-charset="', $context['character_set'], '">';
117 121
 
118 122
 			// Show a warning if they are allowed more than one option.
119
-			if ($context['poll']['allowed_warning'])
120
-				echo '
123
+			if ($context['poll']['allowed_warning']) {
124
+							echo '
121 125
 							<p class="smallpadding">', $context['poll']['allowed_warning'], '</p>';
126
+			}
122 127
 
123 128
 			echo '
124 129
 							<ul class="options">';
125 130
 
126 131
 			// Show each option with its button - a radio likely.
127
-			foreach ($context['poll']['options'] as $option)
128
-				echo '
132
+			foreach ($context['poll']['options'] as $option) {
133
+							echo '
129 134
 								<li>', $option['vote_button'], ' <label for="', $option['id'], '">', $option['option'], '</label></li>';
135
+			}
130 136
 
131 137
 			echo '
132 138
 							</ul>
@@ -138,9 +144,10 @@  discard block
 block discarded – undo
138 144
 		}
139 145
 
140 146
 		// Is the clock ticking?
141
-		if (!empty($context['poll']['expire_time']))
142
-			echo '
147
+		if (!empty($context['poll']['expire_time'])) {
148
+					echo '
143 149
 						<p><strong>', ($context['poll']['is_expired'] ? $txt['poll_expired_on'] : $txt['poll_expires_on']), ':</strong> ', $context['poll']['expire_time'], '</p>';
150
+		}
144 151
 
145 152
 		echo '
146 153
 					</div>
@@ -170,11 +177,13 @@  discard block
 block discarded – undo
170 177
 					<li>
171 178
 						<b class="event_title"><a href="', $scripturl, '?action=calendar;event=', $event['id'], '">', $event['title'], '</a></b>';
172 179
 
173
-			if ($event['can_edit'])
174
-				echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
180
+			if ($event['can_edit']) {
181
+							echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
182
+			}
175 183
 
176
-			if ($event['can_export'])
177
-				echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
184
+			if ($event['can_export']) {
185
+							echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
186
+			}
178 187
 
179 188
 			echo '
180 189
 						<br>';
@@ -182,14 +191,14 @@  discard block
 block discarded – undo
182 191
 			if (!empty($event['allday']))
183 192
 			{
184 193
 				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>' : '';
185
-			}
186
-			else
194
+			} else
187 195
 			{
188 196
 				// Display event info relative to user's local timezone
189 197
 				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'] . '">';
190 198
 
191
-				if ($event['start_date_local'] != $event['end_date_local'])
192
-					echo trim($event['end_date_local']) . ', ';
199
+				if ($event['start_date_local'] != $event['end_date_local']) {
200
+									echo trim($event['end_date_local']) . ', ';
201
+				}
193 202
 
194 203
 				echo trim($event['end_time_local']);
195 204
 
@@ -198,23 +207,27 @@  discard block
 block discarded – undo
198 207
 				{
199 208
 					echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">';
200 209
 
201
-					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'])
202
-						echo trim($event['start_date_orig']), ', ';
210
+					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']) {
211
+											echo trim($event['start_date_orig']), ', ';
212
+					}
203 213
 
204 214
 					echo trim($event['start_time_orig']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
205 215
 
206
-					if ($event['start_date_orig'] != $event['end_date_orig'])
207
-						echo trim($event['end_date_orig']) . ', ';
216
+					if ($event['start_date_orig'] != $event['end_date_orig']) {
217
+											echo trim($event['end_date_orig']) . ', ';
218
+					}
208 219
 
209 220
 					echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)';
210 221
 				}
211 222
 				// Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion
212
-				else
213
-					echo ' ', $event['tz_abbrev'], '</time>';
223
+				else {
224
+									echo ' ', $event['tz_abbrev'], '</time>';
225
+				}
214 226
 			}
215 227
 
216
-			if (!empty($event['location']))
217
-				echo '<br>', $event['location'];
228
+			if (!empty($event['location'])) {
229
+							echo '<br>', $event['location'];
230
+			}
218 231
 
219 232
 			echo '
220 233
 					</li>';
@@ -252,8 +265,9 @@  discard block
 block discarded – undo
252 265
 	$context['removableMessageIDs'] = array();
253 266
 
254 267
 	// Get all the messages...
255
-	while ($message = $context['get_message']())
256
-		template_single_post($message);
268
+	while ($message = $context['get_message']()) {
269
+			template_single_post($message);
270
+	}
257 271
 
258 272
 	echo '
259 273
 				</form>
@@ -290,8 +304,9 @@  discard block
 block discarded – undo
290 304
 			<div id="display_jump_to">&nbsp;</div>';
291 305
 
292 306
 	// Show quickreply
293
-	if ($context['can_reply'])
294
-	template_quickreply();
307
+	if ($context['can_reply']) {
308
+		template_quickreply();
309
+	}
295 310
 
296 311
 	// User action pop on mobile screen (or actually small screen), this uses responsive css does not check mobile device.
297 312
 	echo '
@@ -304,8 +319,8 @@  discard block
 block discarded – undo
304 319
 			</div>';
305 320
 
306 321
 	// Show the moderation button & pop only if user can moderate
307
-	if ($context['can_moderate_forum'] || $context['user']['is_mod'])
308
-		echo '
322
+	if ($context['can_moderate_forum'] || $context['user']['is_mod']) {
323
+			echo '
309 324
 			<div id="mobile_moderation" class="popup_container">
310 325
 				<div class="popup_window description">
311 326
 					<div class="popup_heading">', $txt['mobile_moderation'],'
@@ -315,6 +330,7 @@  discard block
 block discarded – undo
315 330
 					</div>
316 331
 				</div>
317 332
 			</div>';
333
+	}
318 334
 
319 335
 		echo '
320 336
 				<script>';
@@ -438,9 +454,10 @@  discard block
 block discarded – undo
438 454
 						});
439 455
 					}';
440 456
 
441
-	if (!empty($context['ignoredMsgs']))
442
-		echo '
457
+	if (!empty($context['ignoredMsgs'])) {
458
+			echo '
443 459
 					ignore_toggles([', implode(', ', $context['ignoredMsgs']), '], ', JavaScriptEscape($txt['show_ignore_user_post']), ');';
460
+	}
444 461
 
445 462
 	echo '
446 463
 				</script>';
@@ -457,8 +474,9 @@  discard block
 block discarded – undo
457 474
 
458 475
 	$ignoring = false;
459 476
 
460
-	if ($message['can_remove'])
461
-		$context['removableMessageIDs'][] = $message['id'];
477
+	if ($message['can_remove']) {
478
+			$context['removableMessageIDs'][] = $message['id'];
479
+	}
462 480
 
463 481
 	// Are we ignoring this message?
464 482
 	if (!empty($message['is_ignored']))
@@ -484,9 +502,10 @@  discard block
 block discarded – undo
484 502
 							<div class="custom_fields_above_member">
485 503
 								<ul class="nolist">';
486 504
 
487
-		foreach ($message['custom_fields']['above_member'] as $custom)
488
-			echo '
505
+		foreach ($message['custom_fields']['above_member'] as $custom) {
506
+					echo '
489 507
 									<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
508
+		}
490 509
 
491 510
 		echo '
492 511
 								</ul>
@@ -497,9 +516,10 @@  discard block
 block discarded – undo
497 516
 									<h4>';
498 517
 
499 518
 	// Show online and offline buttons?
500
-	if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest'])
501
-		echo '
519
+	if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest']) {
520
+			echo '
502 521
 								', $context['can_send_pm'] ? '<a href="' . $message['member']['online']['href'] . '" title="' . $message['member']['online']['label'] . '">' : '', '<span class="' . ($message['member']['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $message['member']['online']['text'] . '"></span>', $context['can_send_pm'] ? '</a>' : '';
522
+	}
503 523
 
504 524
 
505 525
 	// Show a link to the member's profile.
@@ -512,51 +532,59 @@  discard block
 block discarded – undo
512 532
 
513 533
 
514 534
 	// Show the user's avatar.
515
-	if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']))
516
-		echo '
535
+	if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image'])) {
536
+			echo '
517 537
 								<li class="avatar">
518 538
 									<a href="', $message['member']['href'], '">', $message['member']['avatar']['image'], '</a>
519 539
 								</li>';
540
+	}
520 541
 
521 542
 	// Are there any custom fields below the avatar?
522
-	if (!empty($message['custom_fields']['below_avatar']))
523
-		foreach ($message['custom_fields']['below_avatar'] as $custom)
543
+	if (!empty($message['custom_fields']['below_avatar'])) {
544
+			foreach ($message['custom_fields']['below_avatar'] as $custom)
524 545
 			echo '
525 546
 								<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
547
+	}
526 548
 
527 549
 	// Show the post group icons, but not for guests.
528
-	if (!$message['member']['is_guest'])
529
-		echo '
550
+	if (!$message['member']['is_guest']) {
551
+			echo '
530 552
 								<li class="icons">', $message['member']['group_icons'], '</li>';
553
+	}
531 554
 
532 555
 	// Show the member's primary group (like 'Administrator') if they have one.
533
-	if (!empty($message['member']['group']))
534
-		echo '
556
+	if (!empty($message['member']['group'])) {
557
+			echo '
535 558
 								<li class="membergroup">', $message['member']['group'], '</li>';
559
+	}
536 560
 
537 561
 	// Show the member's custom title, if they have one.
538
-	if (!empty($message['member']['title']))
539
-		echo '
562
+	if (!empty($message['member']['title'])) {
563
+			echo '
540 564
 								<li class="title">', $message['member']['title'], '</li>';
565
+	}
541 566
 
542 567
 	// Don't show these things for guests.
543 568
 	if (!$message['member']['is_guest'])
544 569
 	{
545 570
 
546 571
 		// Show the post group if and only if they have no other group or the option is on, and they are in a post group.
547
-		if ((empty($modSettings['hide_post_group']) || empty($message['member']['group'])) && !empty($message['member']['post_group']))
548
-			echo '
572
+		if ((empty($modSettings['hide_post_group']) || empty($message['member']['group'])) && !empty($message['member']['post_group'])) {
573
+					echo '
549 574
 								<li class="postgroup">', $message['member']['post_group'], '</li>';
575
+		}
550 576
 
551 577
 		// Show how many posts they have made.
552
-		if (!isset($context['disabled_fields']['posts']))
553
-			echo '
578
+		if (!isset($context['disabled_fields']['posts'])) {
579
+					echo '
554 580
 								<li class="postcount">', $txt['member_postcount'], ': ', $message['member']['posts'], '</li>';
581
+		}
555 582
 
556 583
 		// Show their personal text?
557
-		if (!empty($modSettings['show_blurb']) && !empty($message['member']['blurb']))
558
-			echo '
584
+		if (!empty($modSettings['show_blurb']) && !empty($message['member']['blurb'])) {
585
+					echo '
559 586
 								<li class="blurb">', $message['member']['blurb'], '</li>';
587
+		}
560 588
 
561 589
 		// Any custom fields to show as icons?
562 590
 		if (!empty($message['custom_fields']['icons']))
@@ -565,9 +593,10 @@  discard block
 block discarded – undo
565 593
 								<li class="im_icons">
566 594
 									<ol>';
567 595
 
568
-			foreach ($message['custom_fields']['icons'] as $custom)
569
-				echo '
596
+			foreach ($message['custom_fields']['icons'] as $custom) {
597
+							echo '
570 598
 										<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
599
+			}
571 600
 
572 601
 			echo '
573 602
 									</ol>
@@ -582,19 +611,22 @@  discard block
 block discarded – undo
582 611
 									<ol class="profile_icons">';
583 612
 
584 613
 			// Don't show an icon if they haven't specified a website.
585
-			if (!empty($message['member']['website']['url']) && !isset($context['disabled_fields']['website']))
586
-				echo '
614
+			if (!empty($message['member']['website']['url']) && !isset($context['disabled_fields']['website'])) {
615
+							echo '
587 616
 										<li><a href="', $message['member']['website']['url'], '" title="' . $message['member']['website']['title'] . '" target="_blank" class="new_win">', ($settings['use_image_buttons'] ? '<span class="generic_icons www centericon" title="' . $message['member']['website']['title'] . '"></span>' : $txt['www']), '</a></li>';
617
+			}
588 618
 
589 619
 			// Since we know this person isn't a guest, you *can* message them.
590
-			if ($context['can_send_pm'])
591
-				echo '
620
+			if ($context['can_send_pm']) {
621
+							echo '
592 622
 										<li><a href="', $scripturl, '?action=pm;sa=send;u=', $message['member']['id'], '" title="', $message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline'], '">', $settings['use_image_buttons'] ? '<span class="generic_icons im_' . ($message['member']['online']['is_online'] ? 'on' : 'off') . ' centericon" title="' . ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']) . '"></span> ' : ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']), '</a></li>';
623
+			}
593 624
 
594 625
 			// Show the email if necessary
595
-			if (!empty($message['member']['email']) && $message['member']['show_email'])
596
-				echo '
626
+			if (!empty($message['member']['email']) && $message['member']['show_email']) {
627
+							echo '
597 628
 										<li class="email"><a href="mailto:' . $message['member']['email'] . '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="generic_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a></li>';
629
+			}
598 630
 
599 631
 				echo '
600 632
 									</ol>
@@ -602,48 +634,56 @@  discard block
 block discarded – undo
602 634
 		}
603 635
 
604 636
 		// Any custom fields for standard placement?
605
-		if (!empty($message['custom_fields']['standard']))
606
-			foreach ($message['custom_fields']['standard'] as $custom)
637
+		if (!empty($message['custom_fields']['standard'])) {
638
+					foreach ($message['custom_fields']['standard'] as $custom)
607 639
 				echo '
608 640
 								<li class="custom ', $custom['col_name'] ,'">', $custom['title'], ': ', $custom['value'], '</li>';
641
+		}
609 642
 
610 643
 	}
611 644
 	// Otherwise, show the guest's email.
612
-	elseif (!empty($message['member']['email']) && $message['member']['show_email'])
613
-		echo '
645
+	elseif (!empty($message['member']['email']) && $message['member']['show_email']) {
646
+			echo '
614 647
 								<li class="email"><a href="mailto:' . $message['member']['email'] . '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="generic_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a></li>';
648
+	}
615 649
 
616 650
 	// Show the IP to this user for this post - because you can moderate?
617
-	if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip']))
618
-		echo '
651
+	if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip'])) {
652
+			echo '
619 653
 								<li class="poster_ip"><a href="', $scripturl, '?action=', !empty($message['member']['is_guest']) ? 'trackip' : 'profile;area=tracking;sa=ip;u=' . $message['member']['id'], ';searchip=', $message['member']['ip'], '">', $message['member']['ip'], '</a> <a href="', $scripturl, '?action=helpadmin;help=see_admin_ip" onclick="return reqOverlayDiv(this.href);" class="help">(?)</a></li>';
654
+	}
620 655
 
621 656
 	// Or, should we show it because this is you?
622
-	elseif ($message['can_see_ip'])
623
-		echo '
657
+	elseif ($message['can_see_ip']) {
658
+			echo '
624 659
 								<li class="poster_ip"><a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $message['member']['ip'], '</a></li>';
660
+	}
625 661
 
626 662
 	// Okay, are you at least logged in? Then we can show something about why IPs are logged...
627
-	elseif (!$context['user']['is_guest'])
628
-		echo '
663
+	elseif (!$context['user']['is_guest']) {
664
+			echo '
629 665
 								<li class="poster_ip"><a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $txt['logged'], '</a></li>';
666
+	}
630 667
 
631 668
 	// Otherwise, you see NOTHING!
632
-	else
633
-		echo '
669
+	else {
670
+			echo '
634 671
 								<li class="poster_ip">', $txt['logged'], '</li>';
672
+	}
635 673
 
636 674
 	// Are we showing the warning status?
637 675
 	// Don't show these things for guests.
638
-	if (!$message['member']['is_guest'] && $message['member']['can_see_warning'])
639
-		echo '
676
+	if (!$message['member']['is_guest'] && $message['member']['can_see_warning']) {
677
+			echo '
640 678
 								<li class="warning">', $context['can_issue_warning'] ? '<a href="' . $scripturl . '?action=profile;area=issuewarning;u=' . $message['member']['id'] . '">' : '', '<span class="generic_icons warning_', $message['member']['warning_status'], '"></span> ', $context['can_issue_warning'] ? '</a>' : '', '<span class="warn_', $message['member']['warning_status'], '">', $txt['warn_' . $message['member']['warning_status']], '</span></li>';
679
+	}
641 680
 
642 681
 	// Are there any custom fields to show at the bottom of the poster info?
643
-	if (!empty($message['custom_fields']['bottom_poster']))
644
-		foreach ($message['custom_fields']['bottom_poster'] as $custom)
682
+	if (!empty($message['custom_fields']['bottom_poster'])) {
683
+			foreach ($message['custom_fields']['bottom_poster'] as $custom)
645 684
 			echo '
646 685
 									<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
686
+	}
647 687
 
648 688
 	// Poster info ends.
649 689
 	echo '
@@ -672,9 +712,10 @@  discard block
 block discarded – undo
672 712
 	echo '
673 713
 									<span class="smalltext modified" id="modified_', $message['id'], '">';
674 714
 
675
-	if (!empty($modSettings['show_modify']) && !empty($message['modified']['name']))
676
-		echo
715
+	if (!empty($modSettings['show_modify']) && !empty($message['modified']['name'])) {
716
+			echo
677 717
 										$message['modified']['last_edit_text'];
718
+	}
678 719
 
679 720
 	echo '
680 721
 									</span>';
@@ -685,22 +726,24 @@  discard block
 block discarded – undo
685 726
 							</div>';
686 727
 
687 728
 	// Ignoring this user? Hide the post.
688
-	if ($ignoring)
689
-		echo '
729
+	if ($ignoring) {
730
+			echo '
690 731
 							<div id="msg_', $message['id'], '_ignored_prompt">
691 732
 								', $txt['ignoring_user'], '
692 733
 								<a href="#" id="msg_', $message['id'], '_ignored_link" style="display: none;">', $txt['show_ignore_user_post'], '</a>
693 734
 							</div>';
735
+	}
694 736
 
695 737
 	// Show the post itself, finally!
696 738
 	echo '
697 739
 							<div class="post">';
698 740
 
699
-	if (!$message['approved'] && $message['member']['id'] != 0 && $message['member']['id'] == $context['user']['id'])
700
-		echo '
741
+	if (!$message['approved'] && $message['member']['id'] != 0 && $message['member']['id'] == $context['user']['id']) {
742
+			echo '
701 743
 								<div class="approve_post">
702 744
 									', $txt['post_awaiting_approval'], '
703 745
 								</div>';
746
+	}
704 747
 	echo '
705 748
 								<div class="inner" data-msgid="', $message['id'], '" id="msg_', $message['id'], '"', $ignoring ? ' style="display:none;"' : '', '>', $message['body'], '</div>
706 749
 							</div>';
@@ -717,9 +760,9 @@  discard block
 block discarded – undo
717 760
 		foreach ($message['attachment'] as $attachment)
718 761
 		{
719 762
 			// Do we want this attachment to not be showed here?
720
-			if (!empty($modSettings['dont_show_attach_under_post']) && !empty($context['show_attach_under_post'][$attachment['id']]))
721
-				continue;
722
-			elseif (!$div_output)
763
+			if (!empty($modSettings['dont_show_attach_under_post']) && !empty($context['show_attach_under_post'][$attachment['id']])) {
764
+							continue;
765
+			} elseif (!$div_output)
723 766
 			{
724 767
 				$div_output = true;
725 768
 
@@ -735,9 +778,10 @@  discard block
 block discarded – undo
735 778
 								<fieldset>
736 779
 									<legend>', $txt['attach_awaiting_approve'];
737 780
 
738
-				if ($context['can_approve'])
739
-					echo '
781
+				if ($context['can_approve']) {
782
+									echo '
740 783
 										&nbsp;[<a href="', $scripturl, '?action=attachapprove;sa=all;mid=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['approve_all'], '</a>]';
784
+				}
741 785
 
742 786
 				echo '
743 787
 									</legend>';
@@ -751,12 +795,13 @@  discard block
 block discarded – undo
751 795
 				echo '
752 796
 										<div class="attachments_top">';
753 797
 
754
-				if ($attachment['thumbnail']['has_thumb'])
755
-					echo '
798
+				if ($attachment['thumbnail']['has_thumb']) {
799
+									echo '
756 800
 											<a href="', $attachment['href'], ';image" id="link_', $attachment['id'], '" onclick="', $attachment['thumbnail']['javascript'], '"><img src="', $attachment['thumbnail']['href'], '" alt="" id="thumb_', $attachment['id'], '" class="atc_img"></a>';
757
-				else
758
-					echo '
801
+				} else {
802
+									echo '
759 803
 											<img src="' . $attachment['href'] . ';image" alt="" width="' . $attachment['width'] . '" height="' . $attachment['height'] . '" class="atc_img">';
804
+				}
760 805
 
761 806
 				echo '
762 807
 										</div>';
@@ -766,9 +811,10 @@  discard block
 block discarded – undo
766 811
 										<div class="attachments_bot">
767 812
 											<a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.png" class="centericon" alt="*">&nbsp;' . $attachment['name'] . '</a> ';
768 813
 
769
-			if (!$attachment['is_approved'] && $context['can_approve'])
770
-				echo '
814
+			if (!$attachment['is_approved'] && $context['can_approve']) {
815
+							echo '
771 816
 											[<a href="', $scripturl, '?action=attachapprove;sa=approve;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['approve'], '</a>]&nbsp;|&nbsp;[<a href="', $scripturl, '?action=attachapprove;sa=reject;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['delete'], '</a>] ';
817
+			}
772 818
 			echo '
773 819
 											<br>', $attachment['size'], ($attachment['is_image'] ? ', ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . '<br>' . sprintf($txt['attach_viewed'], $attachment['downloads']) : '<br>' . sprintf($txt['attach_downloaded'], $attachment['downloads'])), '
774 820
 										</div>';
@@ -777,33 +823,38 @@  discard block
 block discarded – undo
777 823
 									</div>';
778 824
 
779 825
 			// Next attachment line ?
780
-			if (++$i % $attachments_per_line === 0)
781
-				echo '
826
+			if (++$i % $attachments_per_line === 0) {
827
+							echo '
782 828
 									<br>';
829
+			}
783 830
 		}
784 831
 
785 832
 		// If we had unapproved attachments clean up.
786
-		if ($last_approved_state == 0)
787
-			echo '
833
+		if ($last_approved_state == 0) {
834
+					echo '
788 835
 								</fieldset>';
836
+		}
789 837
 
790 838
 		// Only do this if we output a div above - otherwise it'll break things
791
-		if ($div_output)
792
-			echo '
839
+		if ($div_output) {
840
+					echo '
793 841
 							</div>';
842
+		}
794 843
 	}
795 844
 
796 845
 	// And stuff below the attachments.
797
-	if ($context['can_report_moderator'] || !empty($context['can_see_likes']) || !empty($context['can_like']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote'])
798
-	echo '
846
+	if ($context['can_report_moderator'] || !empty($context['can_see_likes']) || !empty($context['can_like']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote']) {
847
+		echo '
799 848
 							<div class="under_message">';
849
+	}
800 850
 
801 851
 	// Maybe they want to report this post to the moderator(s)?
802
-	if ($context['can_report_moderator'])
803
-		echo '
852
+	if ($context['can_report_moderator']) {
853
+			echo '
804 854
 								<ul class="floatright smalltext">
805 855
 									<li class="report_link"><a href="', $scripturl, '?action=reporttm;topic=', $context['current_topic'], '.', $message['counter'], ';msg=', $message['id'], '">', $txt['report_to_mod'], '</a></li>
806 856
 								</ul>';
857
+	}
807 858
 
808 859
 	// What about likes?
809 860
 	if (!empty($modSettings['enable_likes']))
@@ -844,78 +895,91 @@  discard block
 block discarded – undo
844 895
 								<ul class="quickbuttons">';
845 896
 
846 897
 		// Can they quote? if so they can select and quote as well!
847
-		if ($context['can_quote'])
848
-			echo '
898
+		if ($context['can_quote']) {
899
+					echo '
849 900
 									<li><a href="', $scripturl, '?action=post;quote=', $message['id'], ';topic=', $context['current_topic'], '.', $context['start'], ';last_msg=', $context['topic_last_message'], '" onclick="return oQuickReply.quote(', $message['id'], ');"><span class="generic_icons quote"></span>', $txt['quote_action'], '</a></li>
850 901
 									<li style="display:none;" id="quoteSelected_', $message['id'], '"><a href="javascript:void(0)"><span class="generic_icons quote_selected"></span>', $txt['quote_selected_action'] ,'</a></li>';
902
+		}
851 903
 
852 904
 		// Can the user modify the contents of this post? Show the modify inline image.
853
-		if ($message['can_modify'])
854
-			echo '
905
+		if ($message['can_modify']) {
906
+					echo '
855 907
 									<li class="quick_edit"><a title="', $txt['modify_msg'], '" class="modifybutton" id="modify_button_', $message['id'], '" onclick="oQuickModify.modifyMsg(\'', $message['id'], '\', \'', !empty($modSettings['toggle_subject']), '\')"><span class="generic_icons quick_edit_button"></span>', $txt['quick_edit'], '</a></li>';
908
+		}
856 909
 
857
-		if ($message['can_approve'] || $message['can_unapprove'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'])
858
-			echo '
910
+		if ($message['can_approve'] || $message['can_unapprove'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg']) {
911
+					echo '
859 912
 									<li class="post_options">', $txt['post_options'];
913
+		}
860 914
 
861 915
 		echo '
862 916
 										<ul>';
863 917
 
864 918
 		// Can the user modify the contents of this post?
865
-		if ($message['can_modify'])
866
-			echo '
919
+		if ($message['can_modify']) {
920
+					echo '
867 921
 											<li><a href="', $scripturl, '?action=post;msg=', $message['id'], ';topic=', $context['current_topic'], '.', $context['start'], '"><span class="generic_icons modify_button"></span>', $txt['modify'], '</a></li>';
922
+		}
868 923
 
869 924
 		// How about... even... remove it entirely?!
870
-		if ($context['can_delete'] && ($context['topic_first_message'] == $message['id']))
871
-			echo '
925
+		if ($context['can_delete'] && ($context['topic_first_message'] == $message['id'])) {
926
+					echo '
872 927
 											<li><a href="', $scripturl, '?action=removetopic2;topic=', $context['current_topic'], '.', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['are_sure_remove_topic'], '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove_topic'],'</a></li>';
873
-		elseif ($message['can_remove'] && ($context['topic_first_message'] != $message['id']))
874
-			echo '
928
+		} elseif ($message['can_remove'] && ($context['topic_first_message'] != $message['id'])) {
929
+					echo '
875 930
 											<li><a href="', $scripturl, '?action=deletemsg;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['remove_message_question'] ,'" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove'], '</a></li>';
931
+		}
876 932
 
877 933
 		// What about splitting it off the rest of the topic?
878
-		if ($context['can_split'] && !empty($context['real_num_replies']))
879
-			echo '
934
+		if ($context['can_split'] && !empty($context['real_num_replies'])) {
935
+					echo '
880 936
 											<li><a href="', $scripturl, '?action=splittopics;topic=', $context['current_topic'], '.0;at=', $message['id'], '"><span class="generic_icons split_button"></span>', $txt['split'], '</a></li>';
937
+		}
881 938
 
882 939
 		// Can we issue a warning because of this post? Remember, we can't give guests warnings.
883
-		if ($context['can_issue_warning'] && !$message['is_message_author'] && !$message['member']['is_guest'])
884
-			echo '
940
+		if ($context['can_issue_warning'] && !$message['is_message_author'] && !$message['member']['is_guest']) {
941
+					echo '
885 942
 											<li><a href="', $scripturl, '?action=profile;area=issuewarning;u=', $message['member']['id'], ';msg=', $message['id'], '"><span class="generic_icons warn_button"></span>', $txt['issue_warning'], '</a></li>';
943
+		}
886 944
 
887 945
 		// Can we restore topics?
888
-		if ($context['can_restore_msg'])
889
-			echo '
946
+		if ($context['can_restore_msg']) {
947
+					echo '
890 948
 											<li><a href="', $scripturl, '?action=restoretopic;msgs=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons restore_button"></span>', $txt['restore_message'], '</a></li>';
949
+		}
891 950
 
892 951
 		// Maybe we can approve it, maybe we should?
893
-		if ($message['can_approve'])
894
-			echo '
952
+		if ($message['can_approve']) {
953
+					echo '
895 954
 											<li><a href="', $scripturl, '?action=moderate;area=postmod;sa=approve;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons approve_button"></span>', $txt['approve'], '</a></li>';
955
+		}
896 956
 
897 957
 		// Maybe we can unapprove it?
898
-		if ($message['can_unapprove'])
899
-			echo '
958
+		if ($message['can_unapprove']) {
959
+					echo '
900 960
 											<li><a href="', $scripturl, '?action=moderate;area=postmod;sa=approve;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons unapprove_button"></span>', $txt['unapprove'], '</a></li>';
961
+		}
901 962
 
902 963
 		echo '
903 964
 										</ul>
904 965
 									</li>';
905 966
 
906 967
 		// Show a checkbox for quick moderation?
907
-		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && $message['can_remove'])
908
-			echo '
968
+		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && $message['can_remove']) {
969
+					echo '
909 970
 									<li style="display: none;" id="in_topic_mod_check_', $message['id'], '"></li>';
971
+		}
910 972
 
911
-		if ($message['can_approve'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'])
912
-			echo '
973
+		if ($message['can_approve'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg']) {
974
+					echo '
913 975
 								</ul>';
976
+		}
914 977
 	}
915 978
 
916
-	if ($context['can_report_moderator'] || !empty($context['can_see_likes']) || !empty($context['can_like']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote'])
917
-	echo '
979
+	if ($context['can_report_moderator'] || !empty($context['can_see_likes']) || !empty($context['can_like']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote']) {
980
+		echo '
918 981
 							</div>';
982
+	}
919 983
 
920 984
 	echo '
921 985
 						</div>
@@ -928,9 +992,10 @@  discard block
 block discarded – undo
928 992
 							<div class="custom_fields_above_signature">
929 993
 								<ul class="nolist">';
930 994
 
931
-		foreach ($message['custom_fields']['above_signature'] as $custom)
932
-			echo '
995
+		foreach ($message['custom_fields']['above_signature'] as $custom) {
996
+					echo '
933 997
 									<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
998
+		}
934 999
 
935 1000
 		echo '
936 1001
 								</ul>
@@ -938,9 +1003,10 @@  discard block
 block discarded – undo
938 1003
 	}
939 1004
 
940 1005
 	// Show the member's signature?
941
-	if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled'])
942
-		echo '
1006
+	if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled']) {
1007
+			echo '
943 1008
 							<div class="signature" id="msg_', $message['id'], '_signature"', $ignoring ? ' style="display:none;"' : '', '>', $message['member']['signature'], '</div>';
1009
+	}
944 1010
 
945 1011
 
946 1012
 	// Are there any custom profile fields for below the signature?
@@ -950,9 +1016,10 @@  discard block
 block discarded – undo
950 1016
 							<div class="custom_fields_below_signature">
951 1017
 								<ul class="nolist">';
952 1018
 
953
-		foreach ($message['custom_fields']['below_signature'] as $custom)
954
-			echo '
1019
+		foreach ($message['custom_fields']['below_signature'] as $custom) {
1020
+					echo '
955 1021
 									<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
1022
+		}
956 1023
 
957 1024
 		echo '
958 1025
 								</ul>
@@ -1000,8 +1067,8 @@  discard block
 block discarded – undo
1000 1067
 						<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '">';
1001 1068
 
1002 1069
 		// Guests just need more.
1003
-		if ($context['user']['is_guest'])
1004
-			echo '
1070
+		if ($context['user']['is_guest']) {
1071
+					echo '
1005 1072
 						<dl id="post_header">
1006 1073
 							<dt>
1007 1074
 								', $txt['name'], ':
@@ -1016,6 +1083,7 @@  discard block
 block discarded – undo
1016 1083
 								<input type="email" name="email" size="25" value="', $context['email'], '" tabindex="', $context['tabindex']++, '" class="input_text" required>
1017 1084
 							</dd>
1018 1085
 						</dl>';
1086
+		}
1019 1087
 
1020 1088
 		echo '
1021 1089
 						', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message'), '
@@ -1063,8 +1131,8 @@  discard block
 block discarded – undo
1063 1131
 		<br class="clear">';
1064 1132
 
1065 1133
 	// draft autosave available and the user has it enabled?
1066
-	if (!empty($context['drafts_autosave']))
1067
-		echo '
1134
+	if (!empty($context['drafts_autosave'])) {
1135
+			echo '
1068 1136
 			<script>
1069 1137
 				var oDraftAutoSave = new smf_DraftAutoSave({
1070 1138
 					sSelf: \'oDraftAutoSave\',
@@ -1076,10 +1144,12 @@  discard block
 block discarded – undo
1076 1144
 					iFreq: ', (empty($modSettings['masterAutoSaveDraftsDelay']) ? 60000 : $modSettings['masterAutoSaveDraftsDelay'] * 1000), '
1077 1145
 				});
1078 1146
 			</script>';
1147
+	}
1079 1148
 
1080
-	if ($context['show_spellchecking'])
1081
-		echo '
1149
+	if ($context['show_spellchecking']) {
1150
+			echo '
1082 1151
 			<form action="', $scripturl, '?action=spellcheck" method="post" accept-charset="', $context['character_set'], '" name="spell_form" id="spell_form" target="spellWindow"><input type="hidden" name="spellstring" value=""></form>';
1152
+	}
1083 1153
 
1084 1154
 	echo '
1085 1155
 				<script>
Please login to merge, or discard this patch.
Themes/default/Calendar.template.php 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -253,9 +253,9 @@  discard block
 block discarded – undo
253 253
 					{
254 254
 						// Sort events by start time (all day events will be listed first)
255 255
 						uasort($day['events'], function ($a, $b) {
256
-						    if ($a['start_timestamp'] == $b['start_timestamp'])
257
-						        return 0;
258
-						    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
256
+							if ($a['start_timestamp'] == $b['start_timestamp'])
257
+								return 0;
258
+							return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
259 259
 						});
260 260
 
261 261
 						echo '
@@ -436,9 +436,9 @@  discard block
 block discarded – undo
436 436
 							{
437 437
 								// Sort events by start time (all day events will be listed first)
438 438
 								uasort($day['events'], function ($a, $b) {
439
-								    if ($a['start_timestamp'] == $b['start_timestamp'])
440
-								        return 0;
441
-								    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
439
+									if ($a['start_timestamp'] == $b['start_timestamp'])
440
+										return 0;
441
+									return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
442 442
 								});
443 443
 
444 444
 								foreach ($day['events'] as $event)
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -172,23 +172,23 @@  discard block
 block discarded – undo
172 172
 				// Additional classes are given for events, holidays, and birthdays.
173 173
 				if (!empty($day['events']) && !empty($calendar_data['highlight']['events']))
174 174
 				{
175
-					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1,3)))
175
+					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3)))
176 176
 						$classes[] = 'events';
177
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2,3)))
177
+					elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3)))
178 178
 						$classes[] = 'events';
179 179
 				}
180 180
 				if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays']))
181 181
 				{
182
-					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1,3)))
182
+					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3)))
183 183
 						$classes[] = 'holidays';
184
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2,3)))
184
+					elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3)))
185 185
 						$classes[] = 'holidays';
186 186
 				}
187 187
 				if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays']))
188 188
 				{
189
-					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1,3)))
189
+					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3)))
190 190
 						$classes[] = 'birthdays';
191
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2,3)))
191
+					elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3)))
192 192
 						$classes[] = 'birthdays';
193 193
 				}
194 194
 			}
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 					if (!empty($day['events']))
253 253
 					{
254 254
 						// Sort events by start time (all day events will be listed first)
255
-						uasort($day['events'], function ($a, $b) {
255
+						uasort($day['events'], function($a, $b) {
256 256
 						    if ($a['start_timestamp'] == $b['start_timestamp'])
257 257
 						        return 0;
258 258
 						    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 			elseif ($is_mini === false)
319 319
 			{
320 320
 				if (empty($current_month_started) && !empty($context['calendar_grid_prev']))
321
-					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>';
321
+					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>';
322 322
 				elseif (!empty($current_month_started) && !empty($context['calendar_grid_next']))
323 323
 					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>';
324 324
 			}
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
 							if (!empty($day['events']))
436 436
 							{
437 437
 								// Sort events by start time (all day events will be listed first)
438
-								uasort($day['events'], function ($a, $b) {
438
+								uasort($day['events'], function($a, $b) {
439 439
 								    if ($a['start_timestamp'] == $b['start_timestamp'])
440 440
 								        return 0;
441 441
 								    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 						<div>
639 639
 							<span class="label">', $txt['calendar_post_in'], '</span>
640 640
 							<input type="checkbox" style="vertical-align: middle;" class="input_check" name="link_to_board"', (!empty($context['event']['board']) ? ' checked' : ''), ' onclick="toggleLinked(this.form);">
641
-							<select name="board"', empty($context['event']['board']) ? ' disabled' : '' , '>';
641
+							<select name="board"', empty($context['event']['board']) ? ' disabled' : '', '>';
642 642
 		foreach ($context['event']['categories'] as $category)
643 643
 		{
644 644
 			echo '
Please login to merge, or discard this patch.
Braces   +124 added lines, -93 removed lines patch added patch discarded remove patch
@@ -40,8 +40,7 @@  discard block
 block discarded – undo
40 40
 				', template_show_week_grid('main'), '
41 41
 			</div>
42 42
 		';
43
-	}
44
-	else
43
+	} else
45 44
 	{
46 45
 		echo '
47 46
 			<div id="main_grid">
@@ -67,17 +66,19 @@  discard block
 block discarded – undo
67 66
 	global $context, $settings, $txt, $scripturl, $modSettings;
68 67
 
69 68
 	// If the grid doesn't exist, no point in proceeding.
70
-	if (!isset($context['calendar_grid_' . $grid_name]))
71
-		return false;
69
+	if (!isset($context['calendar_grid_' . $grid_name])) {
70
+			return false;
71
+	}
72 72
 
73 73
 	// A handy little pointer variable.
74 74
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
75 75
 
76 76
 	// Some conditions for whether or not we should show the week links *here*.
77
-	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)))
78
-		$show_week_links = true;
79
-	else
80
-		$show_week_links = false;
77
+	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))) {
78
+			$show_week_links = true;
79
+	} else {
80
+			$show_week_links = false;
81
+	}
81 82
 
82 83
 	// Assuming that we've not disabled it, show the title block!
83 84
 	if (empty($calendar_data['disable_title']))
@@ -124,8 +125,9 @@  discard block
 block discarded – undo
124 125
 		echo '<tr>';
125 126
 
126 127
 		// If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared!
127
-		if ($show_week_links === true)
128
-			echo '<th>&nbsp;</th>';
128
+		if ($show_week_links === true) {
129
+					echo '<th>&nbsp;</th>';
130
+		}
129 131
 
130 132
 		// Now, loop through each actual day of the week.
131 133
 		foreach ($calendar_data['week_days'] as $day)
@@ -172,29 +174,32 @@  discard block
 block discarded – undo
172 174
 				// Additional classes are given for events, holidays, and birthdays.
173 175
 				if (!empty($day['events']) && !empty($calendar_data['highlight']['events']))
174 176
 				{
175
-					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1,3)))
176
-						$classes[] = 'events';
177
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2,3)))
178
-						$classes[] = 'events';
177
+					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1,3))) {
178
+											$classes[] = 'events';
179
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2,3))) {
180
+											$classes[] = 'events';
181
+					}
179 182
 				}
180 183
 				if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays']))
181 184
 				{
182
-					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1,3)))
183
-						$classes[] = 'holidays';
184
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2,3)))
185
-						$classes[] = 'holidays';
185
+					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1,3))) {
186
+											$classes[] = 'holidays';
187
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2,3))) {
188
+											$classes[] = 'holidays';
189
+					}
186 190
 				}
187 191
 				if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays']))
188 192
 				{
189
-					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1,3)))
190
-						$classes[] = 'birthdays';
191
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2,3)))
192
-						$classes[] = 'birthdays';
193
+					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1,3))) {
194
+											$classes[] = 'birthdays';
195
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2,3))) {
196
+											$classes[] = 'birthdays';
197
+					}
193 198
 				}
194
-			}
195
-			else
196
-				// Default Classes (either compact or comfortable and disabled).
199
+			} else {
200
+							// Default Classes (either compact or comfortable and disabled).
197 201
 				$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
202
+			}
198 203
 				$classes[] = 'disabled';
199 204
 
200 205
 			// Now, implode the classes for each day.
@@ -208,17 +213,19 @@  discard block
 block discarded – undo
208 213
 				$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']] . ' ') : '';
209 214
 
210 215
 				// The actual day number - be it a link, or just plain old text!
211
-				if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
212
-					echo '<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>';
213
-				else
214
-					echo '<span class="day_text">', $title_prefix, $day['day'], '</span>';
216
+				if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
217
+									echo '<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>';
218
+				} else {
219
+									echo '<span class="day_text">', $title_prefix, $day['day'], '</span>';
220
+				}
215 221
 
216 222
 				// A lot of stuff, we're not showing on mini-calendars to conserve space.
217 223
 				if ($is_mini === false)
218 224
 				{
219 225
 					// Holidays are always fun, let's show them!
220
-					if (!empty($day['holidays']))
221
-						echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
226
+					if (!empty($day['holidays'])) {
227
+											echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
228
+					}
222 229
 
223 230
 					// Happy Birthday Dear, Member!
224 231
 					if (!empty($day['birthdays']))
@@ -236,14 +243,16 @@  discard block
 block discarded – undo
236 243
 							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) ? '' : ', ';
237 244
 
238 245
 							// 9...10! Let's stop there.
239
-							if ($birthday_count == 10 && $use_js_hide)
240
-								// !!TODO - Inline CSS and JavaScript should be moved.
246
+							if ($birthday_count == 10 && $use_js_hide) {
247
+															// !!TODO - Inline CSS and JavaScript should be moved.
241 248
 								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;">, ';
249
+							}
242 250
 
243 251
 							++$birthday_count;
244 252
 						}
245
-						if ($use_js_hide)
246
-							echo '</span>';
253
+						if ($use_js_hide) {
254
+													echo '</span>';
255
+						}
247 256
 
248 257
 						echo '</div>';
249 258
 					}
@@ -253,8 +262,9 @@  discard block
 block discarded – undo
253 262
 					{
254 263
 						// Sort events by start time (all day events will be listed first)
255 264
 						uasort($day['events'], function ($a, $b) {
256
-						    if ($a['start_timestamp'] == $b['start_timestamp'])
257
-						        return 0;
265
+						    if ($a['start_timestamp'] == $b['start_timestamp']) {
266
+						    						        return 0;
267
+						    }
258 268
 						    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
259 269
 						});
260 270
 
@@ -270,17 +280,19 @@  discard block
 block discarded – undo
270 280
 
271 281
 							echo '<div class="event_wrapper', $event['starts_today'] == true ? ' event_starts_today' : '', $event['ends_today'] == true ? ' event_ends_today' : '', $event['allday'] == true ? ' allday' : '', $event['is_selected'] ? ' sel_event' : '', '">', $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
272 282
 
273
-							if (!empty($event['start_time_local']) && $event['starts_today'] == true)
274
-								echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
275
-							elseif (!empty($event['end_time_local']) && $event['ends_today'] == true)
276
-								echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
277
-							elseif (!empty($event['allday']))
278
-								echo $txt['calendar_allday'];
283
+							if (!empty($event['start_time_local']) && $event['starts_today'] == true) {
284
+															echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
285
+							} elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) {
286
+															echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
287
+							} elseif (!empty($event['allday'])) {
288
+															echo $txt['calendar_allday'];
289
+							}
279 290
 
280 291
 							echo '</span>';
281 292
 
282
-							if (!empty($event['location']))
283
-								echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
293
+							if (!empty($event['location'])) {
294
+															echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
295
+							}
284 296
 
285 297
 							if ($event['can_edit'] || $event['can_export'])
286 298
 							{
@@ -317,10 +329,11 @@  discard block
 block discarded – undo
317 329
 			// Otherwise, assuming it's not a mini-calendar, we can show previous / next month days!
318 330
 			elseif ($is_mini === false)
319 331
 			{
320
-				if (empty($current_month_started) && !empty($context['calendar_grid_prev']))
321
-					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>';
322
-				elseif (!empty($current_month_started) && !empty($context['calendar_grid_next']))
323
-					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>';
332
+				if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) {
333
+									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>';
334
+				} elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) {
335
+									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>';
336
+				}
324 337
 			}
325 338
 
326 339
 			// Close this day and increase var count.
@@ -332,8 +345,9 @@  discard block
 block discarded – undo
332 345
 	}
333 346
 
334 347
 	// Quick Month Navigation + Post Event Link on Main Grids!
335
-	if ($is_mini === false)
336
-		template_calendar_base($show_week_links === true ? 8 : 7);
348
+	if ($is_mini === false) {
349
+			template_calendar_base($show_week_links === true ? 8 : 7);
350
+	}
337 351
 
338 352
 	// The end of our main table.
339 353
 	echo '</table>';
@@ -350,8 +364,9 @@  discard block
 block discarded – undo
350 364
 	global $context, $settings, $txt, $scripturl, $modSettings;
351 365
 
352 366
 	// We might have no reason to proceed, if the variable isn't there.
353
-	if (!isset($context['calendar_grid_' . $grid_name]))
354
-		return false;
367
+	if (!isset($context['calendar_grid_' . $grid_name])) {
368
+			return false;
369
+	}
355 370
 
356 371
 	// Handy pointer.
357 372
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
@@ -387,8 +402,9 @@  discard block
 block discarded – undo
387 402
 					}
388 403
 
389 404
 					// The Month Title + Week Number...
390
-					if (!empty($calendar_data['week_title']))
391
-							echo $calendar_data['week_title'];
405
+					if (!empty($calendar_data['week_title'])) {
406
+												echo $calendar_data['week_title'];
407
+					}
392 408
 
393 409
 					echo '
394 410
 					</h3>
@@ -424,10 +440,11 @@  discard block
 block discarded – undo
424 440
 						<tr class="days_wrapper">
425 441
 							<td class="', implode(' ', $classes), ' act_day">';
426 442
 							// Should the day number be a link?
427
-							if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
428
-								echo '<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>';
429
-							else
430
-								echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
443
+							if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
444
+															echo '<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>';
445
+							} else {
446
+															echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
447
+							}
431 448
 
432 449
 							echo '</td>
433 450
 							<td class="', implode(' ', $classes), '', empty($day['events']) ? (' disabled' . ($context['can_post'] ? ' week_post' : '')) : ' events', ' event_col" data-css-prefix="' . $txt['events'] . ' ', (empty($day['events']) && empty($context['can_post'])) ? $txt['none'] : '', '">';
@@ -436,8 +453,9 @@  discard block
 block discarded – undo
436 453
 							{
437 454
 								// Sort events by start time (all day events will be listed first)
438 455
 								uasort($day['events'], function ($a, $b) {
439
-								    if ($a['start_timestamp'] == $b['start_timestamp'])
440
-								        return 0;
456
+								    if ($a['start_timestamp'] == $b['start_timestamp']) {
457
+								    								        return 0;
458
+								    }
441 459
 								    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
442 460
 								});
443 461
 
@@ -449,15 +467,17 @@  discard block
 block discarded – undo
449 467
 
450 468
 									echo $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
451 469
 
452
-									if (!empty($event['start_time_local']))
453
-										echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
454
-									else
455
-										echo $txt['calendar_allday'];
470
+									if (!empty($event['start_time_local'])) {
471
+																			echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
472
+									} else {
473
+																			echo $txt['calendar_allday'];
474
+									}
456 475
 
457 476
 									echo '</span>';
458 477
 
459
-									if (!empty($event['location']))
460
-										echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
478
+									if (!empty($event['location'])) {
479
+																			echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
480
+									}
461 481
 
462 482
 									if (!empty($event_icons_needed))
463 483
 									{
@@ -494,8 +514,7 @@  discard block
 block discarded – undo
494 514
 									</div>
495 515
 									<br class="clear">';
496 516
 								}
497
-							}
498
-							else
517
+							} else
499 518
 							{
500 519
 								if (!empty($context['can_post']))
501 520
 								{
@@ -508,8 +527,9 @@  discard block
 block discarded – undo
508 527
 							echo '</td>
509 528
 							<td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">';
510 529
 							// Show any holidays!
511
-							if (!empty($day['holidays']))
512
-								echo implode('<br>', $day['holidays']);
530
+							if (!empty($day['holidays'])) {
531
+															echo implode('<br>', $day['holidays']);
532
+							}
513 533
 
514 534
 							echo '</td>
515 535
 							<td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', ' birthday_col" data-css-prefix="' . $txt['birthdays'] . ' ">';
@@ -529,8 +549,9 @@  discard block
 block discarded – undo
529 549
 				}
530 550
 
531 551
 				// We'll show the lower column after our last month is shown.
532
-				if ($iteration == $num_months)
533
-					template_calendar_base(4);
552
+				if ($iteration == $num_months) {
553
+									template_calendar_base(4);
554
+				}
534 555
 
535 556
 				// Increase iteration for loop counting.
536 557
 				++$iteration;
@@ -592,8 +613,9 @@  discard block
 block discarded – undo
592 613
 	echo '
593 614
 		<form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);smc_saveEntities(\'postevent\', [\'evtitle\']);" style="margin: 0;">';
594 615
 
595
-	if (!empty($context['event']['new']))
596
-		echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
616
+	if (!empty($context['event']['new'])) {
617
+			echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
618
+	}
597 619
 
598 620
 	// Start the main table.
599 621
 	echo '
@@ -643,9 +665,10 @@  discard block
 block discarded – undo
643 665
 		{
644 666
 			echo '
645 667
 								<optgroup label="', $category['name'], '">';
646
-			foreach ($category['boards'] as $board)
647
-				echo '
668
+			foreach ($category['boards'] as $board) {
669
+							echo '
648 670
 									<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
671
+			}
649 672
 			echo '
650 673
 								</optgroup>';
651 674
 		}
@@ -681,9 +704,10 @@  discard block
 block discarded – undo
681 704
 							<span class="label">', $txt['calendar_timezone'], '</span>
682 705
 							<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
683 706
 
684
-	foreach ($context['all_timezones'] as $tz => $tzname)
685
-		echo '
707
+	foreach ($context['all_timezones'] as $tz => $tzname) {
708
+			echo '
686 709
 								<option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
710
+	}
687 711
 
688 712
 	echo '
689 713
 							</select>
@@ -698,9 +722,10 @@  discard block
 block discarded – undo
698 722
 	echo '
699 723
 				<input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button_submit">';
700 724
 	// Delete button?
701
-	if (empty($context['event']['new']))
702
-		echo '
725
+	if (empty($context['event']['new'])) {
726
+			echo '
703 727
 				<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button_submit you_sure">';
728
+	}
704 729
 
705 730
 	echo '
706 731
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -744,9 +769,10 @@  discard block
 block discarded – undo
744 769
 
745 770
 		foreach ($context['clockicons'] as $t => $v)
746 771
 		{
747
-			foreach ($v as $i)
748
-				echo '
772
+			foreach ($v as $i) {
773
+							echo '
749 774
 			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
775
+			}
750 776
 		}
751 777
 
752 778
 		echo '
@@ -771,13 +797,14 @@  discard block
 block discarded – undo
771 797
 
772 798
 		foreach ($context['clockicons'] as $t => $v)
773 799
 		{
774
-			foreach ($v as $i)
775
-				echo '
800
+			foreach ($v as $i) {
801
+							echo '
776 802
 			if (', $t, ' >= ', $i, ')
777 803
 			{
778 804
 				turnon.push("', $t, '_', $i, '");
779 805
 				', $t, ' -= ', $i, ';
780 806
 			}';
807
+			}
781 808
 		}
782 809
 
783 810
 		echo '
@@ -841,9 +868,10 @@  discard block
 block discarded – undo
841 868
 
842 869
 	foreach ($context['clockicons'] as $t => $v)
843 870
 	{
844
-		foreach ($v as $i)
845
-			echo '
871
+		foreach ($v as $i) {
872
+					echo '
846 873
 		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
874
+		}
847 875
 	}
848 876
 
849 877
 	echo '
@@ -860,13 +888,14 @@  discard block
 block discarded – undo
860 888
 
861 889
 	foreach ($context['clockicons'] as $t => $v)
862 890
 	{
863
-		foreach ($v as $i)
864
-			echo '
891
+		foreach ($v as $i) {
892
+					echo '
865 893
 		if (', $t, ' >= ', $i, ')
866 894
 		{
867 895
 			turnon.push("', $t, '_', $i, '");
868 896
 			', $t, ' -= ', $i, ';
869 897
 		}';
898
+		}
870 899
 	}
871 900
 
872 901
 	echo '
@@ -925,9 +954,10 @@  discard block
 block discarded – undo
925 954
 
926 955
 	foreach ($context['clockicons'] as $t => $v)
927 956
 	{
928
-		foreach ($v as $i)
929
-			echo '
957
+		foreach ($v as $i) {
958
+					echo '
930 959
 		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
960
+		}
931 961
 	}
932 962
 
933 963
 	echo '
@@ -948,13 +978,14 @@  discard block
 block discarded – undo
948 978
 
949 979
 	foreach ($context['clockicons'] as $t => $v)
950 980
 	{
951
-		foreach ($v as $i)
952
-		echo '
981
+		foreach ($v as $i) {
982
+				echo '
953 983
 		if (', $t, ' >= ', $i, ')
954 984
 		{
955 985
 			turnon.push("', $t, '_', $i, '");
956 986
 			', $t, ' -= ', $i, ';
957 987
 		}';
988
+		}
958 989
 	}
959 990
 
960 991
 	echo '
Please login to merge, or discard this patch.
Themes/default/Post.template.php 1 patch
Braces   +98 added lines, -67 removed lines patch added patch discarded remove patch
@@ -22,22 +22,24 @@  discard block
 block discarded – undo
22 22
 		<script>';
23 23
 
24 24
 	// When using Go Back due to fatal_error, allow the form to be re-submitted with changes.
25
-	if (isBrowser('is_firefox'))
26
-		echo '
25
+	if (isBrowser('is_firefox')) {
26
+			echo '
27 27
 			window.addEventListener("pageshow", reActivate, false);';
28
+	}
28 29
 
29 30
 	// Start with message icons - and any missing from this theme.
30 31
 	echo '
31 32
 			var icon_urls = {';
32
-	foreach ($context['icons'] as $icon)
33
-		echo '
33
+	foreach ($context['icons'] as $icon) {
34
+			echo '
34 35
 				\'', $icon['value'], '\': \'', $icon['url'], '\'', $icon['is_last'] ? '' : ',';
36
+	}
35 37
 	echo '
36 38
 			};';
37 39
 
38 40
 	// If this is a poll - use some javascript to ensure the user doesn't create a poll with illegal option combinations.
39
-	if ($context['make_poll'])
40
-		echo '
41
+	if ($context['make_poll']) {
42
+			echo '
41 43
 			var pollOptionNum = 0, pollTabIndex;
42 44
 			var pollOptionId = ', $context['last_choice_id'], ';
43 45
 			function addPollOption()
@@ -56,11 +58,13 @@  discard block
 block discarded – undo
56 58
 
57 59
 				setOuterHTML(document.getElementById(\'pollMoreOptions\'), ', JavaScriptEscape('<dt><label for="options-'), ' + pollOptionId + ', JavaScriptEscape('">' . $txt['option'] . ' '), ' + pollOptionNum + ', JavaScriptEscape('</label>:</dt><dd><input type="text" name="options['), ' + pollOptionId + ', JavaScriptEscape(']" id="options-'), ' + pollOptionId + ', JavaScriptEscape('" value="" size="80" maxlength="255" tabindex="'), ' + pollTabIndex + ', JavaScriptEscape('" class="input_text"></dd><p id="pollMoreOptions"></p>'), ');
58 60
 			}';
61
+	}
59 62
 
60 63
 	// If we are making a calendar event we want to ensure we show the current days in a month etc... this is done here.
61
-	if ($context['make_event'])
62
-		echo '
64
+	if ($context['make_event']) {
65
+			echo '
63 66
 			var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];';
67
+	}
64 68
 
65 69
 	// End of the javascript, start the form and display the link tree.
66 70
 	echo '
@@ -80,9 +84,10 @@  discard block
 block discarded – undo
80 84
 				</div>
81 85
 			</div><br>';
82 86
 
83
-	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board'])))
84
-		echo '
87
+	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board']))) {
88
+			echo '
85 89
 			<input type="hidden" name="eventid" value="', $context['event']['id'], '">';
90
+	}
86 91
 
87 92
 	// Start the main table.
88 93
 	echo '
@@ -117,26 +122,28 @@  discard block
 block discarded – undo
117 122
 	}
118 123
 
119 124
 	// If it's locked, show a message to warn the replier.
120
-	if (!empty($context['locked']))
121
-	echo '
125
+	if (!empty($context['locked'])) {
126
+		echo '
122 127
 					<p class="errorbox">
123 128
 						', $txt['topic_locked_no_reply'], '
124 129
 					</p>';
130
+	}
125 131
 
126
-	if (!empty($modSettings['drafts_post_enabled']))
127
-		echo '
132
+	if (!empty($modSettings['drafts_post_enabled'])) {
133
+			echo '
128 134
 					<div id="draft_section" class="infobox"', isset($context['draft_saved']) ? '' : ' style="display: none;"', '>',
129 135
 						sprintf($txt['draft_saved'], $scripturl . '?action=profile;u=' . $context['user']['id'] . ';area=showdrafts'), '
130 136
 						', (!empty($modSettings['drafts_keep_days']) ? ' <strong>' . sprintf($txt['draft_save_warning'], $modSettings['drafts_keep_days']) . '</strong>' : ''), '
131 137
 					</div>';
138
+	}
132 139
 
133 140
 	// The post header... important stuff
134 141
 	echo '
135 142
 					<dl id="post_header">';
136 143
 
137 144
 	// Custom posting fields.
138
-	if (!empty($context['posting_fields']) && is_array($context['posting_fields']))
139
-		foreach ($context['posting_fields'] as $pf)
145
+	if (!empty($context['posting_fields']) && is_array($context['posting_fields'])) {
146
+			foreach ($context['posting_fields'] as $pf)
140 147
 			echo '
141 148
 						<dt>
142 149
 							', $pf['dt'] ,'
@@ -144,6 +151,7 @@  discard block
 block discarded – undo
144 151
 						<dd>
145 152
 							', $pf['dd'] ,'
146 153
 						</dd>';
154
+	}
147 155
 
148 156
 
149 157
 	// Guests have to put in their name and email...
@@ -157,14 +165,15 @@  discard block
 block discarded – undo
157 165
 							<input type="text" name="guestname" size="25" value="', $context['name'], '" tabindex="', $context['tabindex']++, '" class="input_text">
158 166
 						</dd>';
159 167
 
160
-		if (empty($modSettings['guest_post_no_email']))
161
-			echo '
168
+		if (empty($modSettings['guest_post_no_email'])) {
169
+					echo '
162 170
 						<dt>
163 171
 							<span', isset($context['post_error']['no_email']) || isset($context['post_error']['bad_email']) ? ' class="error"' : '', ' id="caption_email">', $txt['email'], ':</span>
164 172
 						</dt>
165 173
 						<dd>
166 174
 							<input type="email" name="email" size="25" value="', $context['email'], '" tabindex="', $context['tabindex']++, '" class="input_text" required>
167 175
 						</dd>';
176
+		}
168 177
 	}
169 178
 
170 179
 	// Now show the subject box for this post.
@@ -182,9 +191,10 @@  discard block
 block discarded – undo
182 191
 							<select name="icon" id="icon" onchange="showimage()">';
183 192
 
184 193
 	// Loop through each message icon allowed, adding it to the drop down list.
185
-	foreach ($context['icons'] as $icon)
186
-		echo '
194
+	foreach ($context['icons'] as $icon) {
195
+			echo '
187 196
 								<option value="', $icon['value'], '"', $icon['value'] == $context['icon'] ? ' selected' : '', '>', $icon['name'], '</option>';
197
+	}
188 198
 
189 199
 	echo '
190 200
 							</select>
@@ -219,9 +229,10 @@  discard block
 block discarded – undo
219 229
 				{
220 230
 					echo '
221 231
 										<optgroup label="', $category['name'], '">';
222
-					foreach ($category['boards'] as $board)
223
-						echo '
232
+					foreach ($category['boards'] as $board) {
233
+											echo '
224 234
 											<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
235
+					}
225 236
 					echo '
226 237
 										</optgroup>';
227 238
 				}
@@ -257,9 +268,10 @@  discard block
 block discarded – undo
257 268
 									<span class="label">', $txt['calendar_timezone'], '</span>
258 269
 									<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
259 270
 
260
-			foreach ($context['all_timezones'] as $tz => $tzname)
261
-				echo '
271
+			foreach ($context['all_timezones'] as $tz => $tzname) {
272
+							echo '
262 273
 										<option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
274
+			}
263 275
 
264 276
 			echo '
265 277
 									</select>
@@ -325,14 +337,15 @@  discard block
 block discarded – undo
325 337
 									<input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked' : '', ' class="input_check">
326 338
 								</dd>';
327 339
 
328
-		if ($context['poll_options']['guest_vote_enabled'])
329
-			echo '
340
+		if ($context['poll_options']['guest_vote_enabled']) {
341
+					echo '
330 342
 								<dt>
331 343
 									<label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label>
332 344
 								</dt>
333 345
 								<dd>
334 346
 									<input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll_options']['guest_vote']) ? ' checked' : '', ' class="input_check">
335 347
 								</dd>';
348
+		}
336 349
 
337 350
 		echo '
338 351
 								<dt>
@@ -353,8 +366,8 @@  discard block
 block discarded – undo
353 366
 					', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
354 367
 
355 368
 	// If we're editing and displaying edit details, show a box where they can say why
356
-	if (isset($context['editing']) && $modSettings['show_modify'])
357
-		echo '
369
+	if (isset($context['editing']) && $modSettings['show_modify']) {
370
+			echo '
358 371
 					<dl>
359 372
 						<dt class="clear">
360 373
 							<span id="caption_edit_reason">', $txt['reason_for_edit'], ':</span>
@@ -363,20 +376,23 @@  discard block
 block discarded – undo
363 376
 							<input type="text" name="modify_reason"', isset($context['last_modified_reason']) ? ' value="' . $context['last_modified_reason'] . '"' : '', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text">
364 377
 						</dd>
365 378
 					</dl>';
379
+	}
366 380
 
367 381
 	// If this message has been edited in the past - display when it was.
368
-	if (isset($context['last_modified']))
369
-		echo '
382
+	if (isset($context['last_modified'])) {
383
+			echo '
370 384
 					<div class="padding smalltext">
371 385
 						', $context['last_modified_text'], '
372 386
 					</div>';
387
+	}
373 388
 
374 389
 	// If the admin has enabled the hiding of the additional options - show a link and image for it.
375
-	if (!empty($modSettings['additional_options_collapsable']))
376
-		echo '
390
+	if (!empty($modSettings['additional_options_collapsable'])) {
391
+			echo '
377 392
 					<div id="postAdditionalOptionsHeader">
378 393
 						<strong><a href="#" id="postMoreExpandLink"> ', $context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt'], '</a></strong>
379 394
 					</div>';
395
+	}
380 396
 
381 397
 	echo '
382 398
 					<div id="postAdditionalOptions">';
@@ -408,19 +424,21 @@  discard block
 block discarded – undo
408 424
 								<input type="hidden" name="attach_del[]" value="0">
409 425
 								', $txt['uncheck_unwatchd_attach'], ':
410 426
 							</dd>';
411
-		foreach ($context['current_attachments'] as $attachment)
412
-			echo '
427
+		foreach ($context['current_attachments'] as $attachment) {
428
+					echo '
413 429
 							<dd class="smalltext">
414 430
 								<label for="attachment_', $attachment['attachID'], '"><input type="checkbox" id="attachment_', $attachment['attachID'], '" name="attach_del[]" value="', $attachment['attachID'], '"', empty($attachment['unchecked']) ? ' checked' : '', ' class="input_check"> ', $attachment['name'], (empty($attachment['approved']) ? ' (' . $txt['awaiting_approval'] . ')' : ''),
415 431
 								!empty($modSettings['attachmentPostLimit']) || !empty($modSettings['attachmentSizeLimit']) ? sprintf($txt['attach_kb'], comma_format(round(max($attachment['size'], 1028) / 1028), 0)) : '', '</label>
416 432
 							</dd>';
433
+		}
417 434
 
418 435
 		echo '
419 436
 						</dl>';
420 437
 
421
-		if (!empty($context['files_in_session_warning']))
422
-			echo '
438
+		if (!empty($context['files_in_session_warning'])) {
439
+					echo '
423 440
 						<div class="smalltext">', $context['files_in_session_warning'], '</div>';
441
+		}
424 442
 	}
425 443
 
426 444
 	// Is the user allowed to post any additional ones? If so give them the boxes to do it!
@@ -473,8 +491,8 @@  discard block
 block discarded – undo
473 491
 								', empty($modSettings['attachmentSizeLimit']) ? '' : ('<input type="hidden" name="MAX_FILE_SIZE" value="' . $modSettings['attachmentSizeLimit'] * 1028 . '">');
474 492
 
475 493
 		// Show more boxes if they aren't approaching that limit.
476
-		if ($context['num_allowed_attachments'] > 1)
477
-			echo '
494
+		if ($context['num_allowed_attachments'] > 1) {
495
+					echo '
478 496
 										<script>
479 497
 											var allowed_attachments = ', $context['num_allowed_attachments'], ';
480 498
 											var current_attachment = 1;
@@ -495,9 +513,10 @@  discard block
 block discarded – undo
495 513
 									</div>
496 514
 								</div>
497 515
 							</dd>';
498
-		else
499
-			echo '
516
+		} else {
517
+					echo '
500 518
 							</dd>';
519
+		}
501 520
 
502 521
 		// Add any template changes for an alternative upload system here.
503 522
 		call_integration_hook('integrate_upload_template');
@@ -506,21 +525,25 @@  discard block
 block discarded – undo
506 525
 							<dd class="smalltext">';
507 526
 
508 527
 		// Show some useful information such as allowed extensions, maximum size and amount of attachments allowed.
509
-		if (!empty($modSettings['attachmentCheckExtensions']))
510
-			echo '
528
+		if (!empty($modSettings['attachmentCheckExtensions'])) {
529
+					echo '
511 530
 								', $txt['allowed_types'], ': ', $context['allowed_extensions'], '<br>';
531
+		}
512 532
 
513
-		if (!empty($context['attachment_restrictions']))
514
-			echo '
533
+		if (!empty($context['attachment_restrictions'])) {
534
+					echo '
515 535
 								', $txt['attach_restrictions'], ' ', implode(', ', $context['attachment_restrictions']), '<br>';
536
+		}
516 537
 
517
-		if ($context['num_allowed_attachments'] == 0)
518
-			echo '
538
+		if ($context['num_allowed_attachments'] == 0) {
539
+					echo '
519 540
 								', $txt['attach_limit_nag'], '<br>';
541
+		}
520 542
 
521
-		if (!$context['can_post_attachment_unapproved'])
522
-			echo '
543
+		if (!$context['can_post_attachment_unapproved']) {
544
+					echo '
523 545
 								<span class="alert">', $txt['attachment_requires_approval'], '</span>', '<br>';
546
+		}
524 547
 
525 548
 		echo '
526 549
 							</dd>
@@ -543,10 +566,11 @@  discard block
 block discarded – undo
543 566
 							<dt><strong>', $txt['subject'], '</strong></dt>
544 567
 							<dd><strong>', $txt['draft_saved_on'], '</strong></dd>';
545 568
 
546
-		foreach ($context['drafts'] as $draft)
547
-			echo '
569
+		foreach ($context['drafts'] as $draft) {
570
+					echo '
548 571
 							<dt>', $draft['link'], '</dt>
549 572
 							<dd>', $draft['poster_time'], '</dd>';
573
+		}
550 574
 		echo '
551 575
 						</dl>
552 576
 					</div>';
@@ -571,9 +595,10 @@  discard block
 block discarded – undo
571 595
 						', template_control_richedit_buttons($context['post_box_name']);
572 596
 
573 597
 	// Option to delete an event if user is editing one.
574
-	if ($context['make_event'] && !$context['event']['new'])
575
-		echo '
598
+	if ($context['make_event'] && !$context['event']['new']) {
599
+			echo '
576 600
 						<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['event_delete_confirm'] ,'" class="button_submit you_sure">';
601
+	}
577 602
 
578 603
 	echo '
579 604
 					</span>
@@ -582,9 +607,10 @@  discard block
 block discarded – undo
582 607
 			<br class="clear">';
583 608
 
584 609
 	// Assuming this isn't a new topic pass across the last message id.
585
-	if (isset($context['topic_last_message']))
586
-		echo '
610
+	if (isset($context['topic_last_message'])) {
611
+			echo '
587 612
 			<input type="hidden" name="last_msg" value="', $context['topic_last_message'], '">';
613
+	}
588 614
 
589 615
 	echo '
590 616
 			<input type="hidden" name="additional_options" id="additional_options" value="', $context['show_additional_options'] ? '1' : '0', '">
@@ -726,9 +752,10 @@  discard block
 block discarded – undo
726 752
 
727 753
 						newPostsHTML += \'<div class="windowbg\' + (++reply_counter % 2 == 0 ? \'2\' : \'\') + \'"><div id="msg\' + newPosts[i].getAttribute("id") + \'"><div class="floatleft"><h5>', $txt['posted_by'], ': \' + newPosts[i].getElementsByTagName("poster")[0].firstChild.nodeValue + \'</h5><span class="smalltext">&#171;&nbsp;<strong>', $txt['on'], ':</strong> \' + newPosts[i].getElementsByTagName("time")[0].firstChild.nodeValue + \'&nbsp;&#187;</span> <span class="new_posts" id="image_new_\' + newPosts[i].getAttribute("id") + \'">', $txt['new'], '</span></div>\';';
728 754
 
729
-	if ($context['can_quote'])
730
-		echo '
755
+	if ($context['can_quote']) {
756
+			echo '
731 757
 						newPostsHTML += \'<ul class="quickbuttons" id="msg_\' + newPosts[i].getAttribute("id") + \'_quote"><li><a href="#postmodify" onclick="return insertQuoteFast(\\\'\' + newPosts[i].getAttribute("id") + \'\\\');" class="quote_button"><span>', $txt['quote'], '</span><\' + \'/a></li></ul>\';';
758
+	}
732 759
 
733 760
 	echo '
734 761
 						newPostsHTML += \'<br class="clear">\';
@@ -771,8 +798,8 @@  discard block
 block discarded – undo
771 798
 			}';
772 799
 
773 800
 	// Code for showing and hiding additional options.
774
-	if (!empty($modSettings['additional_options_collapsable']))
775
-		echo '
801
+	if (!empty($modSettings['additional_options_collapsable'])) {
802
+			echo '
776 803
 			var oSwapAdditionalOptions = new smc_Toggle({
777 804
 				bToggleEnabled: true,
778 805
 				bCurrentlyCollapsed: ', $context['show_additional_options'] ? 'false' : 'true', ',
@@ -800,10 +827,11 @@  discard block
 block discarded – undo
800 827
 					}
801 828
 				]
802 829
 			});';
830
+	}
803 831
 
804 832
 	// Code for showing and hiding drafts
805
-	if (!empty($context['drafts']))
806
-		echo '
833
+	if (!empty($context['drafts'])) {
834
+			echo '
807 835
 			var oSwapDraftOptions = new smc_Toggle({
808 836
 				bToggleEnabled: true,
809 837
 				bCurrentlyCollapsed: true,
@@ -825,6 +853,7 @@  discard block
 block discarded – undo
825 853
 					}
826 854
 				]
827 855
 			});';
856
+	}
828 857
 
829 858
 	echo '
830 859
 			var oEditorID = "', $context['post_box_name'] ,'";
@@ -845,8 +874,9 @@  discard block
 block discarded – undo
845 874
 		foreach ($context['previous_posts'] as $post)
846 875
 		{
847 876
 			$ignoring = false;
848
-			if (!empty($post['is_ignored']))
849
-				$ignored_posts[] = $ignoring = $post['id'];
877
+			if (!empty($post['is_ignored'])) {
878
+							$ignored_posts[] = $ignoring = $post['id'];
879
+			}
850 880
 
851 881
 			echo '
852 882
 			<div class="windowbg">
@@ -1029,10 +1059,10 @@  discard block
 block discarded – undo
1029 1059
 		<div id="temporary_posting_area" style="display: none;"></div>
1030 1060
 		<script>';
1031 1061
 
1032
-	if ($context['close_window'])
1033
-		echo '
1062
+	if ($context['close_window']) {
1063
+			echo '
1034 1064
 			window.close();';
1035
-	else
1065
+	} else
1036 1066
 	{
1037 1067
 		// Lucky for us, Internet Explorer has an "innerText" feature which basically converts entities <--> text. Use it if possible ;).
1038 1068
 		echo '
@@ -1086,11 +1116,12 @@  discard block
 block discarded – undo
1086 1116
 				</p>
1087 1117
 				<ul>';
1088 1118
 
1089
-	foreach ($context['groups'] as $group)
1090
-		echo '
1119
+	foreach ($context['groups'] as $group) {
1120
+			echo '
1091 1121
 					<li>
1092 1122
 						<label for="who_', $group['id'], '"><input type="checkbox" name="who[', $group['id'], ']" id="who_', $group['id'], '" value="', $group['id'], '" checked class="input_check"> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em>
1093 1123
 					</li>';
1124
+	}
1094 1125
 
1095 1126
 	echo '
1096 1127
 					<li>
Please login to merge, or discard this patch.
Sources/Subs-Db-mysqli.php 1 patch
Braces   +246 added lines, -180 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysqli_fetch_assoc')
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysqli_fetch_assoc') {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -58,9 +59,11 @@  discard block
 block discarded – undo
58 59
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
59 60
 			'db_is_resource'            => 'smf_is_resource',
60 61
 		);
62
+	}
61 63
 
62
-	if (!empty($db_options['persist']))
63
-		$db_server = 'p:' . $db_server;
64
+	if (!empty($db_options['persist'])) {
65
+			$db_server = 'p:' . $db_server;
66
+	}
64 67
 
65 68
 	$connection = mysqli_init();
66 69
 	
@@ -69,31 +72,35 @@  discard block
 block discarded – undo
69 72
 	$success = false;
70 73
 	
71 74
 	if ($connection) {
72
-		if (!empty($db_options['port']))
73
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'] , null ,$flags);
74
-		else
75
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd,'', 0, null, $flags);
75
+		if (!empty($db_options['port'])) {
76
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'] , null ,$flags);
77
+		} else {
78
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd,'', 0, null, $flags);
79
+		}
76 80
 	}
77 81
 
78 82
 	// Something's wrong, show an error if its fatal (which we assume it is)
79 83
 	if ($success === false)
80 84
 	{
81
-		if (!empty($db_options['non_fatal']))
82
-			return null;
83
-		else
84
-			display_db_error();
85
+		if (!empty($db_options['non_fatal'])) {
86
+					return null;
87
+		} else {
88
+					display_db_error();
89
+		}
85 90
 	}
86 91
 
87 92
 	// Select the database, unless told not to
88
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
89
-		display_db_error();
93
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
94
+			display_db_error();
95
+	}
90 96
 
91 97
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
92
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
93
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
98
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
99
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
94 100
 		array(),
95 101
 		false
96 102
 	);
103
+	}
97 104
 
98 105
 	return $connection;
99 106
 }
@@ -164,37 +171,46 @@  discard block
 block discarded – undo
164 171
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
165 172
 
166 173
 	list ($values, $connection) = $db_callback;
167
-	if (!is_object($connection))
168
-		display_db_error();
174
+	if (!is_object($connection)) {
175
+			display_db_error();
176
+	}
169 177
 
170
-	if ($matches[1] === 'db_prefix')
171
-		return $db_prefix;
178
+	if ($matches[1] === 'db_prefix') {
179
+			return $db_prefix;
180
+	}
172 181
 
173
-	if ($matches[1] === 'query_see_board')
174
-		return $user_info['query_see_board'];
182
+	if ($matches[1] === 'query_see_board') {
183
+			return $user_info['query_see_board'];
184
+	}
175 185
 
176
-	if ($matches[1] === 'query_wanna_see_board')
177
-		return $user_info['query_wanna_see_board'];
186
+	if ($matches[1] === 'query_wanna_see_board') {
187
+			return $user_info['query_wanna_see_board'];
188
+	}
178 189
 
179
-	if ($matches[1] === 'empty')
180
-		return '\'\'';
190
+	if ($matches[1] === 'empty') {
191
+			return '\'\'';
192
+	}
181 193
 
182
-	if (!isset($matches[2]))
183
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
194
+	if (!isset($matches[2])) {
195
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
196
+	}
184 197
 
185
-	if ($matches[1] === 'literal')
186
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
198
+	if ($matches[1] === 'literal') {
199
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
200
+	}
187 201
 
188
-	if (!isset($values[$matches[2]]))
189
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
202
+	if (!isset($values[$matches[2]])) {
203
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
204
+	}
190 205
 
191 206
 	$replacement = $values[$matches[2]];
192 207
 
193 208
 	switch ($matches[1])
194 209
 	{
195 210
 		case 'int':
196
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
197
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
211
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
212
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			}
198 214
 			return (string) (int) $replacement;
199 215
 		break;
200 216
 
@@ -206,56 +222,63 @@  discard block
 block discarded – undo
206 222
 		case 'array_int':
207 223
 			if (is_array($replacement))
208 224
 			{
209
-				if (empty($replacement))
210
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+				if (empty($replacement)) {
226
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227
+				}
211 228
 
212 229
 				foreach ($replacement as $key => $value)
213 230
 				{
214
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
215
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
232
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+					}
216 234
 
217 235
 					$replacement[$key] = (string) (int) $value;
218 236
 				}
219 237
 
220 238
 				return implode(', ', $replacement);
239
+			} else {
240
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221 241
 			}
222
-			else
223
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224 242
 
225 243
 		break;
226 244
 
227 245
 		case 'array_string':
228 246
 			if (is_array($replacement))
229 247
 			{
230
-				if (empty($replacement))
231
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
248
+				if (empty($replacement)) {
249
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
250
+				}
232 251
 
233
-				foreach ($replacement as $key => $value)
234
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
252
+				foreach ($replacement as $key => $value) {
253
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
254
+				}
235 255
 
236 256
 				return implode(', ', $replacement);
257
+			} else {
258
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237 259
 			}
238
-			else
239
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240 260
 		break;
241 261
 
242 262
 		case 'date':
243
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
244
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
245
-			else
246
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
263
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
264
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
265
+			} else {
266
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
267
+			}
247 268
 		break;
248 269
 
249 270
 		case 'time':
250
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
251
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
252
-			else
253
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
271
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
272
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
273
+			} else {
274
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
275
+			}
254 276
 		break;
255 277
 
256 278
 		case 'float':
257
-			if (!is_numeric($replacement))
258
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
279
+			if (!is_numeric($replacement)) {
280
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
281
+			}
259 282
 			return (string) (float) $replacement;
260 283
 		break;
261 284
 
@@ -269,32 +292,37 @@  discard block
 block discarded – undo
269 292
 		break;
270 293
 
271 294
 		case 'inet':
272
-			if ($replacement == 'null' || $replacement == '')
273
-				return 'null';
274
-			if (!isValidIP($replacement))
275
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
295
+			if ($replacement == 'null' || $replacement == '') {
296
+							return 'null';
297
+			}
298
+			if (!isValidIP($replacement)) {
299
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
300
+			}
276 301
 			//we don't use the native support of mysql > 5.6.2
277 302
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
278 303
 
279 304
 		case 'array_inet':
280 305
 			if (is_array($replacement))
281 306
 			{
282
-				if (empty($replacement))
283
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
307
+				if (empty($replacement)) {
308
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
309
+				}
284 310
 
285 311
 				foreach ($replacement as $key => $value)
286 312
 				{
287
-					if ($replacement == 'null' || $replacement == '')
288
-						$replacement[$key] = 'null';
289
-					if (!isValidIP($value))
290
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
313
+					if ($replacement == 'null' || $replacement == '') {
314
+											$replacement[$key] = 'null';
315
+					}
316
+					if (!isValidIP($value)) {
317
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
318
+					}
291 319
 					$replacement[$key] =  sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
292 320
 				}
293 321
 
294 322
 				return implode(', ', $replacement);
323
+			} else {
324
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
295 325
 			}
296
-			else
297
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
298 326
 		break;
299 327
 
300 328
 		default:
@@ -370,22 +398,25 @@  discard block
 block discarded – undo
370 398
 		// Are we in SSI mode?  If so try that username and password first
371 399
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
372 400
 		{
373
-			if (empty($db_persist))
374
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
375
-			else
376
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
401
+			if (empty($db_persist)) {
402
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
403
+			} else {
404
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
405
+			}
377 406
 		}
378 407
 		// Fall back to the regular username and password if need be
379 408
 		if (!$db_connection)
380 409
 		{
381
-			if (empty($db_persist))
382
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
383
-			else
384
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
410
+			if (empty($db_persist)) {
411
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
412
+			} else {
413
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
414
+			}
385 415
 		}
386 416
 
387
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
388
-			$db_connection = false;
417
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
418
+					$db_connection = false;
419
+		}
389 420
 
390 421
 		$connection = $db_connection;
391 422
 	}
@@ -393,18 +424,20 @@  discard block
 block discarded – undo
393 424
 	// One more query....
394 425
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
395 426
 
396
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
397
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
427
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
428
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
429
+	}
398 430
 
399 431
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
400 432
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
401 433
 	{
402 434
 		// Add before LIMIT
403
-		if ($pos = strpos($db_string, 'LIMIT '))
404
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
405
-		else
406
-			// Append it.
435
+		if ($pos = strpos($db_string, 'LIMIT ')) {
436
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
437
+		} else {
438
+					// Append it.
407 439
 			$db_string .= "\n\t\t\tORDER BY null";
440
+		}
408 441
 	}
409 442
 
410 443
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -426,8 +459,9 @@  discard block
 block discarded – undo
426 459
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
427 460
 
428 461
 		// Initialize $db_cache if not already initialized.
429
-		if (!isset($db_cache))
430
-			$db_cache = array();
462
+		if (!isset($db_cache)) {
463
+					$db_cache = array();
464
+		}
431 465
 
432 466
 		if (!empty($_SESSION['debug_redirect']))
433 467
 		{
@@ -453,17 +487,18 @@  discard block
 block discarded – undo
453 487
 		while (true)
454 488
 		{
455 489
 			$pos = strpos($db_string, '\'', $pos + 1);
456
-			if ($pos === false)
457
-				break;
490
+			if ($pos === false) {
491
+							break;
492
+			}
458 493
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
459 494
 
460 495
 			while (true)
461 496
 			{
462 497
 				$pos1 = strpos($db_string, '\'', $pos + 1);
463 498
 				$pos2 = strpos($db_string, '\\', $pos + 1);
464
-				if ($pos1 === false)
465
-					break;
466
-				elseif ($pos2 === false || $pos2 > $pos1)
499
+				if ($pos1 === false) {
500
+									break;
501
+				} elseif ($pos2 === false || $pos2 > $pos1)
467 502
 				{
468 503
 					$pos = $pos1;
469 504
 					break;
@@ -479,29 +514,35 @@  discard block
 block discarded – undo
479 514
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
480 515
 
481 516
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
482
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
483
-			$fail = true;
517
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
518
+					$fail = true;
519
+		}
484 520
 		// Trying to change passwords, slow us down, or something?
485
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
486
-			$fail = true;
487
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
488
-			$fail = true;
521
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
522
+					$fail = true;
523
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
524
+					$fail = true;
525
+		}
489 526
 
490
-		if (!empty($fail) && function_exists('log_error'))
491
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
527
+		if (!empty($fail) && function_exists('log_error')) {
528
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
529
+		}
492 530
 	}
493 531
 
494
-	if (empty($db_unbuffered))
495
-		$ret = @mysqli_query($connection, $db_string);
496
-	else
497
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
532
+	if (empty($db_unbuffered)) {
533
+			$ret = @mysqli_query($connection, $db_string);
534
+	} else {
535
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
536
+	}
498 537
 
499
-	if ($ret === false && empty($db_values['db_error_skip']))
500
-		$ret = smf_db_error($db_string, $connection);
538
+	if ($ret === false && empty($db_values['db_error_skip'])) {
539
+			$ret = smf_db_error($db_string, $connection);
540
+	}
501 541
 
502 542
 	// Debugging.
503
-	if (isset($db_show_debug) && $db_show_debug === true)
504
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
543
+	if (isset($db_show_debug) && $db_show_debug === true) {
544
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
545
+	}
505 546
 
506 547
 	return $ret;
507 548
 }
@@ -550,12 +591,13 @@  discard block
 block discarded – undo
550 591
 	// Decide which connection to use
551 592
 	$connection = $connection === null ? $db_connection : $connection;
552 593
 
553
-	if ($type == 'begin')
554
-		return @mysqli_query($connection, 'BEGIN');
555
-	elseif ($type == 'rollback')
556
-		return @mysqli_query($connection, 'ROLLBACK');
557
-	elseif ($type == 'commit')
558
-		return @mysqli_query($connection, 'COMMIT');
594
+	if ($type == 'begin') {
595
+			return @mysqli_query($connection, 'BEGIN');
596
+	} elseif ($type == 'rollback') {
597
+			return @mysqli_query($connection, 'ROLLBACK');
598
+	} elseif ($type == 'commit') {
599
+			return @mysqli_query($connection, 'COMMIT');
600
+	}
559 601
 
560 602
 	return false;
561 603
 }
@@ -595,8 +637,9 @@  discard block
 block discarded – undo
595 637
 	//    2013: Lost connection to server during query.
596 638
 
597 639
 	// Log the error.
598
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
599
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
640
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
641
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
642
+	}
600 643
 
601 644
 	// Database error auto fixing ;).
602 645
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -605,8 +648,9 @@  discard block
 block discarded – undo
605 648
 		$old_cache = @$modSettings['cache_enable'];
606 649
 		$modSettings['cache_enable'] = '1';
607 650
 
608
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
609
-			$db_last_error = max(@$db_last_error, $temp);
651
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
652
+					$db_last_error = max(@$db_last_error, $temp);
653
+		}
610 654
 
611 655
 		if (@$db_last_error < time() - 3600 * 24 * 3)
612 656
 		{
@@ -622,8 +666,9 @@  discard block
 block discarded – undo
622 666
 					foreach ($tables as $table)
623 667
 					{
624 668
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
625
-						if (trim($table) != '')
626
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
669
+						if (trim($table) != '') {
670
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
671
+						}
627 672
 					}
628 673
 				}
629 674
 
@@ -632,8 +677,9 @@  discard block
 block discarded – undo
632 677
 			// Table crashed.  Let's try to fix it.
633 678
 			elseif ($query_errno == 1016)
634 679
 			{
635
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
636
-					$fix_tables = array('`' . $match[1] . '`');
680
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
681
+									$fix_tables = array('`' . $match[1] . '`');
682
+				}
637 683
 			}
638 684
 			// Indexes crashed.  Should be easy to fix!
639 685
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -652,13 +698,15 @@  discard block
 block discarded – undo
652 698
 
653 699
 			// Make a note of the REPAIR...
654 700
 			cache_put_data('db_last_error', time(), 600);
655
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
656
-				updateSettingsFile(array('db_last_error' => time()));
701
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
702
+							updateSettingsFile(array('db_last_error' => time()));
703
+			}
657 704
 
658 705
 			// Attempt to find and repair the broken table.
659
-			foreach ($fix_tables as $table)
660
-				$smcFunc['db_query']('', "
706
+			foreach ($fix_tables as $table) {
707
+							$smcFunc['db_query']('', "
661 708
 					REPAIR TABLE $table", false, false);
709
+			}
662 710
 
663 711
 			// And send off an email!
664 712
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -667,11 +715,12 @@  discard block
 block discarded – undo
667 715
 
668 716
 			// Try the query again...?
669 717
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
670
-			if ($ret !== false)
671
-				return $ret;
718
+			if ($ret !== false) {
719
+							return $ret;
720
+			}
721
+		} else {
722
+					$modSettings['cache_enable'] = $old_cache;
672 723
 		}
673
-		else
674
-			$modSettings['cache_enable'] = $old_cache;
675 724
 
676 725
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
677 726
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -681,22 +730,25 @@  discard block
 block discarded – undo
681 730
 				// Are we in SSI mode?  If so try that username and password first
682 731
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
683 732
 				{
684
-					if (empty($db_persist))
685
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
686
-					else
687
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
733
+					if (empty($db_persist)) {
734
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
735
+					} else {
736
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
737
+					}
688 738
 				}
689 739
 				// Fall back to the regular username and password if need be
690 740
 				if (!$db_connection)
691 741
 				{
692
-					if (empty($db_persist))
693
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
694
-					else
695
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
742
+					if (empty($db_persist)) {
743
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
744
+					} else {
745
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
746
+					}
696 747
 				}
697 748
 
698
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
699
-					$db_connection = false;
749
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
750
+									$db_connection = false;
751
+				}
700 752
 			}
701 753
 
702 754
 			if ($db_connection)
@@ -707,24 +759,27 @@  discard block
 block discarded – undo
707 759
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
708 760
 
709 761
 					$new_errno = mysqli_errno($db_connection);
710
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
711
-						break;
762
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
763
+											break;
764
+					}
712 765
 				}
713 766
 
714 767
 				// If it failed again, shucks to be you... we're not trying it over and over.
715
-				if ($ret !== false)
716
-					return $ret;
768
+				if ($ret !== false) {
769
+									return $ret;
770
+				}
717 771
 			}
718 772
 		}
719 773
 		// Are they out of space, perhaps?
720 774
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
721 775
 		{
722
-			if (!isset($txt))
723
-				$query_error .= ' - check database storage space.';
724
-			else
776
+			if (!isset($txt)) {
777
+							$query_error .= ' - check database storage space.';
778
+			} else
725 779
 			{
726
-				if (!isset($txt['mysql_error_space']))
727
-					loadLanguage('Errors');
780
+				if (!isset($txt['mysql_error_space'])) {
781
+									loadLanguage('Errors');
782
+				}
728 783
 
729 784
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
730 785
 			}
@@ -732,15 +787,17 @@  discard block
 block discarded – undo
732 787
 	}
733 788
 
734 789
 	// Nothing's defined yet... just die with it.
735
-	if (empty($context) || empty($txt))
736
-		die($query_error);
790
+	if (empty($context) || empty($txt)) {
791
+			die($query_error);
792
+	}
737 793
 
738 794
 	// Show an error message, if possible.
739 795
 	$context['error_title'] = $txt['database_error'];
740
-	if (allowedTo('admin_forum'))
741
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
742
-	else
743
-		$context['error_message'] = $txt['try_again'];
796
+	if (allowedTo('admin_forum')) {
797
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
798
+	} else {
799
+			$context['error_message'] = $txt['try_again'];
800
+	}
744 801
 
745 802
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
746 803
 	{
@@ -769,25 +826,28 @@  discard block
 block discarded – undo
769 826
 	$connection = $connection === null ? $db_connection : $connection;
770 827
 
771 828
 	// With nothing to insert, simply return.
772
-	if (empty($data))
773
-		return;
829
+	if (empty($data)) {
830
+			return;
831
+	}
774 832
 
775 833
 	// Replace the prefix holder with the actual prefix.
776 834
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
777 835
 
778 836
 	// Inserting data as a single row can be done as a single array.
779
-	if (!is_array($data[array_rand($data)]))
780
-		$data = array($data);
837
+	if (!is_array($data[array_rand($data)])) {
838
+			$data = array($data);
839
+	}
781 840
 
782 841
 	// Create the mold for a single row insert.
783 842
 	$insertData = '(';
784 843
 	foreach ($columns as $columnName => $type)
785 844
 	{
786 845
 		// Are we restricting the length?
787
-		if (strpos($type, 'string-') !== false)
788
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
789
-		else
790
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
846
+		if (strpos($type, 'string-') !== false) {
847
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
848
+		} else {
849
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
850
+		}
791 851
 	}
792 852
 	$insertData = substr($insertData, 0, -2) . ')';
793 853
 
@@ -796,8 +856,9 @@  discard block
 block discarded – undo
796 856
 
797 857
 	// Here's where the variables are injected to the query.
798 858
 	$insertRows = array();
799
-	foreach ($data as $dataRow)
800
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
859
+	foreach ($data as $dataRow) {
860
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
861
+	}
801 862
 
802 863
 	// Determine the method of insertion.
803 864
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -828,8 +889,9 @@  discard block
 block discarded – undo
828 889
  */
829 890
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
830 891
 {
831
-	if (empty($log_message))
832
-		$log_message = $error_message;
892
+	if (empty($log_message)) {
893
+			$log_message = $error_message;
894
+	}
833 895
 
834 896
 	foreach (debug_backtrace() as $step)
835 897
 	{
@@ -848,12 +910,14 @@  discard block
 block discarded – undo
848 910
 	}
849 911
 
850 912
 	// A special case - we want the file and line numbers for debugging.
851
-	if ($error_type == 'return')
852
-		return array($file, $line);
913
+	if ($error_type == 'return') {
914
+			return array($file, $line);
915
+	}
853 916
 
854 917
 	// Is always a critical error.
855
-	if (function_exists('log_error'))
856
-		log_error($log_message, 'critical', $file, $line);
918
+	if (function_exists('log_error')) {
919
+			log_error($log_message, 'critical', $file, $line);
920
+	}
857 921
 
858 922
 	if (function_exists('fatal_error'))
859 923
 	{
@@ -861,12 +925,12 @@  discard block
 block discarded – undo
861 925
 
862 926
 		// Cannot continue...
863 927
 		exit;
928
+	} elseif ($error_type) {
929
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
930
+	} else {
931
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
932
+	}
864 933
 	}
865
-	elseif ($error_type)
866
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
867
-	else
868
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
869
-}
870 934
 
871 935
 /**
872 936
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -883,10 +947,11 @@  discard block
 block discarded – undo
883 947
 		'\\' => '\\\\',
884 948
 	);
885 949
 
886
-	if ($translate_human_wildcards)
887
-		$replacements += array(
950
+	if ($translate_human_wildcards) {
951
+			$replacements += array(
888 952
 			'*' => '%',
889 953
 		);
954
+	}
890 955
 
891 956
 	return strtr($string, $replacements);
892 957
 }
@@ -900,8 +965,9 @@  discard block
 block discarded – undo
900 965
  */
901 966
 function smf_is_resource($result)
902 967
 {
903
-	if ($result instanceof mysqli_result)
904
-		return true;
968
+	if ($result instanceof mysqli_result) {
969
+			return true;
970
+	}
905 971
 
906 972
 	return false;
907 973
 }
Please login to merge, or discard this patch.
Sources/Post.php 2 patches
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -259,8 +259,8 @@  discard block
 block discarded – undo
259 259
 			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
260 260
 
261 261
 		$js_time_string = str_replace(
262
-			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
263
-			array('H',  'G',  'h',  'g',  'i',  'A',  'a',  'h:i:s A', 'H:i', 's',  'H:i:s', 'H:i:s'),
262
+			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r', '%R', '%S', '%T', '%X'),
263
+			array('H', 'G', 'h', 'g', 'i', 'A', 'a', 'h:i:s A', 'H:i', 's', 'H:i:s', 'H:i:s'),
264 264
 			$time_string
265 265
 		);
266 266
 
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
 				{
856 856
 					// It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
857 857
 					if ($i % 4 == 0)
858
-						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m)
858
+						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
859 859
 						{
860 860
 							return '[html]' . preg_replace('~<br\s?/?' . '>~i', '&lt;br /&gt;<br>', "$m[1]") . '[/html]';
861 861
 						}, $parts[$i]);
@@ -952,7 +952,7 @@  discard block
 block discarded – undo
952 952
 				{
953 953
 					// Since, they don't belong here. Let's inform the user that they exist..
954 954
 					if (!empty($topic))
955
-						$delete_url = $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
955
+						$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
956 956
 					else
957 957
 						$delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp';
958 958
 
@@ -960,7 +960,7 @@  discard block
 block discarded – undo
960 960
 					$file_list = array();
961 961
 					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
962 962
 						if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
963
-							$file_list[] =  $attachment['name'];
963
+							$file_list[] = $attachment['name'];
964 964
 
965 965
 					$_SESSION['temp_attachments']['post']['files'] = $file_list;
966 966
 					$file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>';
@@ -968,7 +968,7 @@  discard block
 block discarded – undo
968 968
 					if (!empty($_SESSION['temp_attachments']['post']['msg']))
969 969
 					{
970 970
 						// We have a message id, so we can link back to the old topic they were trying to edit..
971
-						$goback_url = $scripturl . '?action=post' .(!empty($_SESSION['temp_attachments']['post']['msg']) ? (';msg=' . $_SESSION['temp_attachments']['post']['msg']) : '') . (!empty($_SESSION['temp_attachments']['post']['last_msg']) ? (';last_msg=' . $_SESSION['temp_attachments']['post']['last_msg']) : '') . ';topic=' . $_SESSION['temp_attachments']['post']['topic'] . ';additionalOptions';
971
+						$goback_url = $scripturl . '?action=post' . (!empty($_SESSION['temp_attachments']['post']['msg']) ? (';msg=' . $_SESSION['temp_attachments']['post']['msg']) : '') . (!empty($_SESSION['temp_attachments']['post']['last_msg']) ? (';last_msg=' . $_SESSION['temp_attachments']['post']['last_msg']) : '') . ';topic=' . $_SESSION['temp_attachments']['post']['topic'] . ';additionalOptions';
972 972
 
973 973
 						$post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list));
974 974
 						$context['ignore_temp_attachments'] = true;
@@ -1255,55 +1255,55 @@  discard block
 block discarded – undo
1255 1255
 		foreach ($context['current_attachments'] as $key => $mock)
1256 1256
 			addInlineJavaScript('
1257 1257
 	current_attachments.push({
1258
-		name: '. JavaScriptEscape($mock['name']) .',
1259
-		size: '. $mock['size'] .',
1260
-		attachID: '. $mock['attachID'] .',
1261
-		approved: '. $mock['approved'] .',
1262
-		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') .',
1263
-		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) .'
1258
+		name: '. JavaScriptEscape($mock['name']) . ',
1259
+		size: '. $mock['size'] . ',
1260
+		attachID: '. $mock['attachID'] . ',
1261
+		approved: '. $mock['approved'] . ',
1262
+		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ',
1263
+		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . '
1264 1264
 	});', true);
1265 1265
 	}
1266 1266
 
1267 1267
 	// File Upload.
1268 1268
 	if ($context['can_post_attachment'])
1269 1269
 	{
1270
-		$acceptedFiles = implode(',', array_map(function($val) use($smcFunc) { return '.'. $smcFunc['htmltrim']($val);} , explode(',', $context['allowed_extensions'])));
1270
+		$acceptedFiles = implode(',', array_map(function($val) use($smcFunc) { return '.' . $smcFunc['htmltrim']($val); } , explode(',', $context['allowed_extensions'])));
1271 1271
 
1272 1272
 		loadJavaScriptFile('dropzone.min.js', array('defer' => true), 'smf_dropzone');
1273 1273
 		loadJavaScriptFile('smf_fileUpload.js', array('defer' => true), 'smf_fileUpload');
1274 1274
 		addInlineJavaScript('
1275 1275
 	$(function() {
1276 1276
 		smf_fileUpload({
1277
-			dictDefaultMessage : '. JavaScriptEscape($txt['attach_drop_zone']) .',
1278
-			dictFallbackMessage : '. JavaScriptEscape($txt['attach_drop_zone_no']) .',
1279
-			dictCancelUpload : '. JavaScriptEscape($txt['modify_cancel']) .',
1280
-			genericError: '. JavaScriptEscape($txt['attach_php_error']) .',
1281
-			text_attachLeft: '. JavaScriptEscape($txt['attached_attachedLeft']) .',
1282
-			text_deleteAttach: '. JavaScriptEscape($txt['attached_file_delete']) .',
1283
-			text_attachDeleted: '. JavaScriptEscape($txt['attached_file_deleted']) .',
1284
-			text_insertBBC: '. JavaScriptEscape($txt['attached_insertBBC']) .',
1285
-			text_attachUploaded: '. JavaScriptEscape($txt['attached_file_uploaded']) .',
1286
-			text_attach_unlimited: '. JavaScriptEscape($txt['attach_drop_unlimited']) .',
1287
-			dictMaxFilesExceeded: '. JavaScriptEscape($txt['more_attachments_error']) .',
1288
-			dictInvalidFileType: '. JavaScriptEscape(sprintf($txt['cant_upload_type'], $context['allowed_extensions'])) .',
1289
-			dictFileTooBig: '. JavaScriptEscape(sprintf($txt['file_too_big'], comma_format($modSettings['attachmentSizeLimit'], 0))) .',
1290
-			maxTotalSize: '. JavaScriptEscape($txt['attach_max_total_file_size_current']) .',
1291
-			acceptedFiles: '. JavaScriptEscape($acceptedFiles) .',
1292
-			maxFilesize: '. (!empty($modSettings['attachmentSizeLimit']) ? $modSettings['attachmentSizeLimit'] : 'null') .',
1293
-			thumbnailWidth: '.(!empty($modSettings['attachmentThumbWidth']) ? $modSettings['attachmentThumbWidth'] : 'null') .',
1294
-			thumbnailHeight: '.(!empty($modSettings['attachmentThumbHeight']) ? $modSettings['attachmentThumbHeight'] : 'null') .',
1295
-			maxFiles: '. (!empty($context['num_allowed_attachments']) ? $context['num_allowed_attachments'] : 'null') .',
1296
-			text_totalMaxSize: '. JavaScriptEscape($txt['attach_max_total_file_size_current']) .',
1297
-			text_max_size_progress: '. JavaScriptEscape($txt['attach_max_size_progress']) .',
1298
-			limitMultiFileUploadSize:'. round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)) * 1024 .',
1299
-			maxLimitReferenceUploadSize: '. $modSettings['attachmentPostLimit'] * 1024 .',
1277
+			dictDefaultMessage : '. JavaScriptEscape($txt['attach_drop_zone']) . ',
1278
+			dictFallbackMessage : '. JavaScriptEscape($txt['attach_drop_zone_no']) . ',
1279
+			dictCancelUpload : '. JavaScriptEscape($txt['modify_cancel']) . ',
1280
+			genericError: '. JavaScriptEscape($txt['attach_php_error']) . ',
1281
+			text_attachLeft: '. JavaScriptEscape($txt['attached_attachedLeft']) . ',
1282
+			text_deleteAttach: '. JavaScriptEscape($txt['attached_file_delete']) . ',
1283
+			text_attachDeleted: '. JavaScriptEscape($txt['attached_file_deleted']) . ',
1284
+			text_insertBBC: '. JavaScriptEscape($txt['attached_insertBBC']) . ',
1285
+			text_attachUploaded: '. JavaScriptEscape($txt['attached_file_uploaded']) . ',
1286
+			text_attach_unlimited: '. JavaScriptEscape($txt['attach_drop_unlimited']) . ',
1287
+			dictMaxFilesExceeded: '. JavaScriptEscape($txt['more_attachments_error']) . ',
1288
+			dictInvalidFileType: '. JavaScriptEscape(sprintf($txt['cant_upload_type'], $context['allowed_extensions'])) . ',
1289
+			dictFileTooBig: '. JavaScriptEscape(sprintf($txt['file_too_big'], comma_format($modSettings['attachmentSizeLimit'], 0))) . ',
1290
+			maxTotalSize: '. JavaScriptEscape($txt['attach_max_total_file_size_current']) . ',
1291
+			acceptedFiles: '. JavaScriptEscape($acceptedFiles) . ',
1292
+			maxFilesize: '. (!empty($modSettings['attachmentSizeLimit']) ? $modSettings['attachmentSizeLimit'] : 'null') . ',
1293
+			thumbnailWidth: '.(!empty($modSettings['attachmentThumbWidth']) ? $modSettings['attachmentThumbWidth'] : 'null') . ',
1294
+			thumbnailHeight: '.(!empty($modSettings['attachmentThumbHeight']) ? $modSettings['attachmentThumbHeight'] : 'null') . ',
1295
+			maxFiles: '. (!empty($context['num_allowed_attachments']) ? $context['num_allowed_attachments'] : 'null') . ',
1296
+			text_totalMaxSize: '. JavaScriptEscape($txt['attach_max_total_file_size_current']) . ',
1297
+			text_max_size_progress: '. JavaScriptEscape($txt['attach_max_size_progress']) . ',
1298
+			limitMultiFileUploadSize:'. round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)) * 1024 . ',
1299
+			maxLimitReferenceUploadSize: '. $modSettings['attachmentPostLimit'] * 1024 . ',
1300 1300
 		});
1301 1301
 	});', true);
1302 1302
 	}
1303 1303
 
1304 1304
 	// Knowing the current board ID might be handy.
1305 1305
 	addInlineJavaScript('
1306
-	var current_board = '. (empty($context['current_board']) ? 'null' : $context['current_board']) .';', false);
1306
+	var current_board = '. (empty($context['current_board']) ? 'null' : $context['current_board']) . ';', false);
1307 1307
 
1308 1308
 	// Finally, load the template.
1309 1309
 	if (!isset($_REQUEST['xml']))
@@ -1721,7 +1721,7 @@  discard block
 block discarded – undo
1721 1721
 	}
1722 1722
 
1723 1723
 	// Coming from the quickReply?
1724
-	if(isset($_POST['quickReply']))
1724
+	if (isset($_POST['quickReply']))
1725 1725
 		$_POST['message'] = $_POST['quickReply'];
1726 1726
 
1727 1727
 	// Check the subject and message.
@@ -2510,7 +2510,7 @@  discard block
 block discarded – undo
2510 2510
 		FROM {db_prefix}messages AS m
2511 2511
 			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
2512 2512
 		WHERE m.id_topic = {int:current_topic}' . (isset($_REQUEST['msg']) ? '
2513
-			AND m.id_msg < {int:id_msg}' : '') .(!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
2513
+			AND m.id_msg < {int:id_msg}' : '') . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
2514 2514
 			AND m.approved = {int:approved}') . '
2515 2515
 		ORDER BY m.id_msg DESC' . $limit,
2516 2516
 		array(
Please login to merge, or discard this patch.
Braces   +664 added lines, -515 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Handles showing the post screen, loading the post to be modified, and loading any post quoted.
@@ -35,12 +36,14 @@  discard block
 block discarded – undo
35 36
 	global $sourcedir, $smcFunc, $language;
36 37
 
37 38
 	loadLanguage('Post');
38
-	if (!empty($modSettings['drafts_post_enabled']))
39
-		loadLanguage('Drafts');
39
+	if (!empty($modSettings['drafts_post_enabled'])) {
40
+			loadLanguage('Drafts');
41
+	}
40 42
 
41 43
 	// You can't reply with a poll... hacker.
42
-	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
43
-		unset($_REQUEST['poll']);
44
+	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) {
45
+			unset($_REQUEST['poll']);
46
+	}
44 47
 
45 48
 	// Posting an event?
46 49
 	$context['make_event'] = isset($_REQUEST['calendar']);
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 	$context['auto_notify'] = !empty($context['notify_prefs']['msg_auto_notify']);
56 59
 
57 60
 	// You must be posting to *some* board.
58
-	if (empty($board) && !$context['make_event'])
59
-		fatal_lang_error('no_board', false);
61
+	if (empty($board) && !$context['make_event']) {
62
+			fatal_lang_error('no_board', false);
63
+	}
60 64
 
61 65
 	require_once($sourcedir . '/Subs-Post.php');
62 66
 
@@ -79,10 +83,11 @@  discard block
 block discarded – undo
79 83
 			array(
80 84
 				'msg' => (int) $_REQUEST['msg'],
81 85
 		));
82
-		if ($smcFunc['db_num_rows']($request) != 1)
83
-			unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
84
-		else
85
-			list ($topic) = $smcFunc['db_fetch_row']($request);
86
+		if ($smcFunc['db_num_rows']($request) != 1) {
87
+					unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
88
+		} else {
89
+					list ($topic) = $smcFunc['db_fetch_row']($request);
90
+		}
86 91
 		$smcFunc['db_free_result']($request);
87 92
 	}
88 93
 
@@ -109,33 +114,36 @@  discard block
 block discarded – undo
109 114
 		$smcFunc['db_free_result']($request);
110 115
 
111 116
 		// If this topic already has a poll, they sure can't add another.
112
-		if (isset($_REQUEST['poll']) && $pollID > 0)
113
-			unset($_REQUEST['poll']);
117
+		if (isset($_REQUEST['poll']) && $pollID > 0) {
118
+					unset($_REQUEST['poll']);
119
+		}
114 120
 
115 121
 		if (empty($_REQUEST['msg']))
116 122
 		{
117
-			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
118
-				is_not_guest();
123
+			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) {
124
+							is_not_guest();
125
+			}
119 126
 
120 127
 			// By default the reply will be approved...
121 128
 			$context['becomes_approved'] = true;
122 129
 			if ($id_member_poster != $user_info['id'] || $user_info['is_guest'])
123 130
 			{
124
-				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
125
-					$context['becomes_approved'] = false;
126
-				else
127
-					isAllowedTo('post_reply_any');
128
-			}
129
-			elseif (!allowedTo('post_reply_any'))
131
+				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
132
+									$context['becomes_approved'] = false;
133
+				} else {
134
+									isAllowedTo('post_reply_any');
135
+				}
136
+			} elseif (!allowedTo('post_reply_any'))
130 137
 			{
131
-				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any')))
132
-					$context['becomes_approved'] = false;
133
-				else
134
-					isAllowedTo('post_reply_own');
138
+				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) {
139
+									$context['becomes_approved'] = false;
140
+				} else {
141
+									isAllowedTo('post_reply_own');
142
+				}
135 143
 			}
144
+		} else {
145
+					$context['becomes_approved'] = true;
136 146
 		}
137
-		else
138
-			$context['becomes_approved'] = true;
139 147
 
140 148
 		$context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
141 149
 		$context['can_sticky'] = allowedTo('make_sticky');
@@ -147,18 +155,19 @@  discard block
 block discarded – undo
147 155
 		$context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
148 156
 
149 157
 		// Check whether this is a really old post being bumped...
150
-		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
151
-			$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
152
-	}
153
-	else
158
+		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) {
159
+					$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
160
+		}
161
+	} else
154 162
 	{
155 163
 		$context['becomes_approved'] = true;
156 164
 		if ((!$context['make_event'] || !empty($board)))
157 165
 		{
158
-			if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
159
-				$context['becomes_approved'] = false;
160
-			else
161
-				isAllowedTo('post_new');
166
+			if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
167
+							$context['becomes_approved'] = false;
168
+			} else {
169
+							isAllowedTo('post_new');
170
+			}
162 171
 		}
163 172
 
164 173
 		$locked = 0;
@@ -196,20 +205,24 @@  discard block
 block discarded – undo
196 205
 	}
197 206
 
198 207
 	// Don't allow a post if it's locked and you aren't all powerful.
199
-	if ($locked && !allowedTo('moderate_board'))
200
-		fatal_lang_error('topic_locked', false);
208
+	if ($locked && !allowedTo('moderate_board')) {
209
+			fatal_lang_error('topic_locked', false);
210
+	}
201 211
 	// Check the users permissions - is the user allowed to add or post a poll?
202 212
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
203 213
 	{
204 214
 		// New topic, new poll.
205
-		if (empty($topic))
206
-			isAllowedTo('poll_post');
215
+		if (empty($topic)) {
216
+					isAllowedTo('poll_post');
217
+		}
207 218
 		// This is an old topic - but it is yours!  Can you add to it?
208
-		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
209
-			isAllowedTo('poll_add_own');
219
+		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) {
220
+					isAllowedTo('poll_add_own');
221
+		}
210 222
 		// If you're not the owner, can you add to any poll?
211
-		else
212
-			isAllowedTo('poll_add_any');
223
+		else {
224
+					isAllowedTo('poll_add_any');
225
+		}
213 226
 
214 227
 		require_once($sourcedir . '/Subs-Members.php');
215 228
 		$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
@@ -238,8 +251,9 @@  discard block
 block discarded – undo
238 251
 	if ($context['make_event'])
239 252
 	{
240 253
 		// They might want to pick a board.
241
-		if (!isset($context['current_board']))
242
-			$context['current_board'] = 0;
254
+		if (!isset($context['current_board'])) {
255
+					$context['current_board'] = 0;
256
+		}
243 257
 
244 258
 		// Start loading up the event info.
245 259
 		$context['event'] = array();
@@ -253,10 +267,11 @@  discard block
 block discarded – undo
253 267
 		isAllowedTo('calendar_post');
254 268
 
255 269
 		// We want a fairly compact version of the time, but as close as possible to the user's settings.
256
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
257
-			$time_string = '%k:%M';
258
-		else
259
-			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
270
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
271
+					$time_string = '%k:%M';
272
+		} else {
273
+					$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
274
+		}
260 275
 
261 276
 		$js_time_string = str_replace(
262 277
 			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -278,8 +293,7 @@  discard block
 block discarded – undo
278 293
 			require_once($sourcedir . '/Subs-Calendar.php');
279 294
 			$eventProperties = getEventProperties($context['event']['id']);
280 295
 			$context['event'] = array_merge($context['event'], $eventProperties);
281
-		}
282
-		else
296
+		} else
283 297
 		{
284 298
 			// Get the current event information.
285 299
 			require_once($sourcedir . '/Subs-Calendar.php');
@@ -287,15 +301,18 @@  discard block
 block discarded – undo
287 301
 			$context['event'] = array_merge($context['event'], $eventProperties);
288 302
 
289 303
 			// Make sure the year and month are in the valid range.
290
-			if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
291
-				fatal_lang_error('invalid_month', false);
292
-			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
293
-				fatal_lang_error('invalid_year', false);
304
+			if ($context['event']['month'] < 1 || $context['event']['month'] > 12) {
305
+							fatal_lang_error('invalid_month', false);
306
+			}
307
+			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) {
308
+							fatal_lang_error('invalid_year', false);
309
+			}
294 310
 
295 311
 			// Get a list of boards they can post in.
296 312
 			$boards = boardsAllowedTo('post_new');
297
-			if (empty($boards))
298
-				fatal_lang_error('cannot_post_new', 'user');
313
+			if (empty($boards)) {
314
+							fatal_lang_error('cannot_post_new', 'user');
315
+			}
299 316
 
300 317
 			// Load a list of boards for this event in the context.
301 318
 			require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -414,10 +431,11 @@  discard block
 block discarded – undo
414 431
 
415 432
 			if (!empty($context['new_replies']))
416 433
 			{
417
-				if ($context['new_replies'] == 1)
418
-					$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
419
-				else
420
-					$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
434
+				if ($context['new_replies'] == 1) {
435
+									$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
436
+				} else {
437
+									$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
438
+				}
421 439
 
422 440
 				$post_errors[] = 'new_replies';
423 441
 
@@ -429,9 +447,9 @@  discard block
 block discarded – undo
429 447
 	// Get a response prefix (like 'Re:') in the default forum language.
430 448
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
431 449
 	{
432
-		if ($language === $user_info['language'])
433
-			$context['response_prefix'] = $txt['response_prefix'];
434
-		else
450
+		if ($language === $user_info['language']) {
451
+					$context['response_prefix'] = $txt['response_prefix'];
452
+		} else
435 453
 		{
436 454
 			loadLanguage('index', $language, false);
437 455
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -444,8 +462,9 @@  discard block
 block discarded – undo
444 462
 	// Do we have a body, but an error happened.
445 463
 	if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error']))
446 464
 	{
447
-		if (isset($_REQUEST['quickReply']))
448
-			$_REQUEST['message'] = $_REQUEST['quickReply'];
465
+		if (isset($_REQUEST['quickReply'])) {
466
+					$_REQUEST['message'] = $_REQUEST['quickReply'];
467
+		}
449 468
 
450 469
 		// Validate inputs.
451 470
 		if (empty($context['post_error']))
@@ -453,15 +472,17 @@  discard block
 block discarded – undo
453 472
 			// This means they didn't click Post and get an error.
454 473
 			$really_previewing = true;
455 474
 
456
-		}
457
-		else
475
+		} else
458 476
 		{
459
-			if (!isset($_REQUEST['subject']))
460
-				$_REQUEST['subject'] = '';
461
-			if (!isset($_REQUEST['message']))
462
-				$_REQUEST['message'] = '';
463
-			if (!isset($_REQUEST['icon']))
464
-				$_REQUEST['icon'] = 'xx';
477
+			if (!isset($_REQUEST['subject'])) {
478
+							$_REQUEST['subject'] = '';
479
+			}
480
+			if (!isset($_REQUEST['message'])) {
481
+							$_REQUEST['message'] = '';
482
+			}
483
+			if (!isset($_REQUEST['icon'])) {
484
+							$_REQUEST['icon'] = 'xx';
485
+			}
465 486
 
466 487
 			// They are previewing if they asked to preview (i.e. came from quick reply).
467 488
 			$really_previewing = !empty($_POST['preview']);
@@ -477,8 +498,9 @@  discard block
 block discarded – undo
477 498
 		$form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
478 499
 
479 500
 		// Make sure the subject isn't too long - taking into account special characters.
480
-		if ($smcFunc['strlen']($form_subject) > 100)
481
-			$form_subject = $smcFunc['substr']($form_subject, 0, 100);
501
+		if ($smcFunc['strlen']($form_subject) > 100) {
502
+					$form_subject = $smcFunc['substr']($form_subject, 0, 100);
503
+		}
482 504
 
483 505
 		if (isset($_REQUEST['poll']))
484 506
 		{
@@ -490,8 +512,9 @@  discard block
 block discarded – undo
490 512
 			$_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
491 513
 			foreach ($_POST['options'] as $option)
492 514
 			{
493
-				if (trim($option) == '')
494
-					continue;
515
+				if (trim($option) == '') {
516
+									continue;
517
+				}
495 518
 
496 519
 				$context['choices'][] = array(
497 520
 					'id' => $choice_id++,
@@ -553,13 +576,14 @@  discard block
 block discarded – undo
553 576
 				$context['preview_subject'] = $form_subject;
554 577
 
555 578
 				censorText($context['preview_subject']);
579
+			} else {
580
+							$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
556 581
 			}
557
-			else
558
-				$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
559 582
 
560 583
 			// Protect any CDATA blocks.
561
-			if (isset($_REQUEST['xml']))
562
-				$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
584
+			if (isset($_REQUEST['xml'])) {
585
+							$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
586
+			}
563 587
 		}
564 588
 
565 589
 		// Set up the checkboxes.
@@ -598,29 +622,32 @@  discard block
 block discarded – undo
598 622
 			);
599 623
 			// The message they were trying to edit was most likely deleted.
600 624
 			// @todo Change this error message?
601
-			if ($smcFunc['db_num_rows']($request) == 0)
602
-				fatal_lang_error('no_board', false);
625
+			if ($smcFunc['db_num_rows']($request) == 0) {
626
+							fatal_lang_error('no_board', false);
627
+			}
603 628
 			$row = $smcFunc['db_fetch_assoc']($request);
604 629
 
605 630
 			$attachment_stuff = array($row);
606
-			while ($row2 = $smcFunc['db_fetch_assoc']($request))
607
-				$attachment_stuff[] = $row2;
631
+			while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
632
+							$attachment_stuff[] = $row2;
633
+			}
608 634
 			$smcFunc['db_free_result']($request);
609 635
 
610 636
 			if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
611 637
 			{
612 638
 				// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
613
-				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
614
-					fatal_lang_error('modify_post_time_passed', false);
615
-				elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
616
-					isAllowedTo('modify_replies');
617
-				else
618
-					isAllowedTo('modify_own');
639
+				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
640
+									fatal_lang_error('modify_post_time_passed', false);
641
+				} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
642
+									isAllowedTo('modify_replies');
643
+				} else {
644
+									isAllowedTo('modify_own');
645
+				}
646
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
647
+							isAllowedTo('modify_replies');
648
+			} else {
649
+							isAllowedTo('modify_any');
619 650
 			}
620
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
621
-				isAllowedTo('modify_replies');
622
-			else
623
-				isAllowedTo('modify_any');
624 651
 
625 652
 			if ($context['can_announce'] && !empty($row['id_action']))
626 653
 			{
@@ -644,8 +671,9 @@  discard block
 block discarded – undo
644 671
 
645 672
 				while ($row = $smcFunc['db_fetch_assoc']($request))
646 673
 				{
647
-					if ($row['filesize'] <= 0)
648
-						continue;
674
+					if ($row['filesize'] <= 0) {
675
+											continue;
676
+					}
649 677
 					$context['current_attachments'][$row['id_attach']] = array(
650 678
 						'name' => $smcFunc['htmlspecialchars']($row['filename']),
651 679
 						'size' => $row['filesize'],
@@ -715,29 +743,32 @@  discard block
 block discarded – undo
715 743
 			)
716 744
 		);
717 745
 		// The message they were trying to edit was most likely deleted.
718
-		if ($smcFunc['db_num_rows']($request) == 0)
719
-			fatal_lang_error('no_message', false);
746
+		if ($smcFunc['db_num_rows']($request) == 0) {
747
+					fatal_lang_error('no_message', false);
748
+		}
720 749
 		$row = $smcFunc['db_fetch_assoc']($request);
721 750
 
722 751
 		$attachment_stuff = array($row);
723
-		while ($row2 = $smcFunc['db_fetch_assoc']($request))
724
-			$attachment_stuff[] = $row2;
752
+		while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
753
+					$attachment_stuff[] = $row2;
754
+		}
725 755
 		$smcFunc['db_free_result']($request);
726 756
 
727 757
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
728 758
 		{
729 759
 			// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
730
-			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
731
-				fatal_lang_error('modify_post_time_passed', false);
732
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
733
-				isAllowedTo('modify_replies');
734
-			else
735
-				isAllowedTo('modify_own');
760
+			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
761
+							fatal_lang_error('modify_post_time_passed', false);
762
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
763
+							isAllowedTo('modify_replies');
764
+			} else {
765
+							isAllowedTo('modify_own');
766
+			}
767
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
768
+					isAllowedTo('modify_replies');
769
+		} else {
770
+					isAllowedTo('modify_any');
736 771
 		}
737
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
738
-			isAllowedTo('modify_replies');
739
-		else
740
-			isAllowedTo('modify_any');
741 772
 
742 773
 		if ($context['can_announce'] && !empty($row['id_action']))
743 774
 		{
@@ -764,15 +795,17 @@  discard block
 block discarded – undo
764 795
 		$context['icon'] = $row['icon'];
765 796
 
766 797
 		// Show an "approve" box if the user can approve it, and the message isn't approved.
767
-		if (!$row['approved'] && !$context['show_approval'])
768
-			$context['show_approval'] = allowedTo('approve_posts');
798
+		if (!$row['approved'] && !$context['show_approval']) {
799
+					$context['show_approval'] = allowedTo('approve_posts');
800
+		}
769 801
 
770 802
 		// Sort the attachments so they are in the order saved
771 803
 		$temp = array();
772 804
 		foreach ($attachment_stuff as $attachment)
773 805
 		{
774
-			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
775
-				$temp[$attachment['id_attach']] = $attachment;
806
+			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) {
807
+							$temp[$attachment['id_attach']] = $attachment;
808
+			}
776 809
 
777 810
 		}
778 811
 		ksort($temp);
@@ -834,14 +867,16 @@  discard block
 block discarded – undo
834 867
 					'is_approved' => 1,
835 868
 				)
836 869
 			);
837
-			if ($smcFunc['db_num_rows']($request) == 0)
838
-				fatal_lang_error('quoted_post_deleted', false);
870
+			if ($smcFunc['db_num_rows']($request) == 0) {
871
+							fatal_lang_error('quoted_post_deleted', false);
872
+			}
839 873
 			list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
840 874
 			$smcFunc['db_free_result']($request);
841 875
 
842 876
 			// Add 'Re: ' to the front of the quoted subject.
843
-			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
844
-				$form_subject = $context['response_prefix'] . $form_subject;
877
+			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
878
+							$form_subject = $context['response_prefix'] . $form_subject;
879
+			}
845 880
 
846 881
 			// Censor the message and subject.
847 882
 			censorText($form_message);
@@ -854,10 +889,11 @@  discard block
 block discarded – undo
854 889
 				for ($i = 0, $n = count($parts); $i < $n; $i++)
855 890
 				{
856 891
 					// It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
857
-					if ($i % 4 == 0)
858
-						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m)
892
+					if ($i % 4 == 0) {
893
+											$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m)
859 894
 						{
860 895
 							return '[html]' . preg_replace('~<br\s?/?' . '>~i', '&lt;br /&gt;<br>', "$m[1]") . '[/html]';
896
+					}
861 897
 						}, $parts[$i]);
862 898
 				}
863 899
 				$form_message = implode('', $parts);
@@ -866,8 +902,9 @@  discard block
 block discarded – undo
866 902
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
867 903
 
868 904
 			// Remove any nested quotes, if necessary.
869
-			if (!empty($modSettings['removeNestedQuotes']))
870
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
905
+			if (!empty($modSettings['removeNestedQuotes'])) {
906
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
907
+			}
871 908
 
872 909
 			// Add a quote string on the front and end.
873 910
 			$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
@@ -879,15 +916,15 @@  discard block
 block discarded – undo
879 916
 			$form_subject = $first_subject;
880 917
 
881 918
 			// Add 'Re: ' to the front of the subject.
882
-			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
883
-				$form_subject = $context['response_prefix'] . $form_subject;
919
+			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
920
+							$form_subject = $context['response_prefix'] . $form_subject;
921
+			}
884 922
 
885 923
 			// Censor the subject.
886 924
 			censorText($form_subject);
887 925
 
888 926
 			$form_message = '';
889
-		}
890
-		else
927
+		} else
891 928
 		{
892 929
 			$form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
893 930
 			$form_message = '';
@@ -905,13 +942,15 @@  discard block
 block discarded – undo
905 942
 		if (isset($_REQUEST['msg']))
906 943
 		{
907 944
 			$context['attachments']['quantity'] = count($context['current_attachments']);
908
-			foreach ($context['current_attachments'] as $attachment)
909
-				$context['attachments']['total_size'] += $attachment['size'];
945
+			foreach ($context['current_attachments'] as $attachment) {
946
+							$context['attachments']['total_size'] += $attachment['size'];
947
+			}
910 948
 		}
911 949
 
912 950
 		// A bit of house keeping first.
913
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
914
-			unset($_SESSION['temp_attachments']);
951
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
952
+					unset($_SESSION['temp_attachments']);
953
+		}
915 954
 
916 955
 		if (!empty($_SESSION['temp_attachments']))
917 956
 		{
@@ -920,9 +959,10 @@  discard block
 block discarded – undo
920 959
 			{
921 960
 				foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
922 961
 				{
923
-					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
924
-						if (file_exists($attachment['tmp_name']))
962
+					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) {
963
+											if (file_exists($attachment['tmp_name']))
925 964
 							unlink($attachment['tmp_name']);
965
+					}
926 966
 				}
927 967
 				$post_errors[] = 'temp_attachments_gone';
928 968
 				$_SESSION['temp_attachments'] = array();
@@ -936,8 +976,9 @@  discard block
 block discarded – undo
936 976
 					// See if any files still exist before showing the warning message and the files attached.
937 977
 					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
938 978
 					{
939
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
940
-							continue;
979
+						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
980
+													continue;
981
+						}
941 982
 
942 983
 						if (file_exists($attachment['tmp_name']))
943 984
 						{
@@ -947,20 +988,21 @@  discard block
 block discarded – undo
947 988
 							break;
948 989
 						}
949 990
 					}
950
-				}
951
-				else
991
+				} else
952 992
 				{
953 993
 					// Since, they don't belong here. Let's inform the user that they exist..
954
-					if (!empty($topic))
955
-						$delete_url = $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
956
-					else
957
-						$delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp';
994
+					if (!empty($topic)) {
995
+											$delete_url = $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
996
+					} else {
997
+											$delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp';
998
+					}
958 999
 
959 1000
 					// Compile a list of the files to show the user.
960 1001
 					$file_list = array();
961
-					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
962
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
1002
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
1003
+											if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
963 1004
 							$file_list[] =  $attachment['name'];
1005
+					}
964 1006
 
965 1007
 					$_SESSION['temp_attachments']['post']['files'] = $file_list;
966 1008
 					$file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>';
@@ -972,8 +1014,7 @@  discard block
 block discarded – undo
972 1014
 
973 1015
 						$post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list));
974 1016
 						$context['ignore_temp_attachments'] = true;
975
-					}
976
-					else
1017
+					} else
977 1018
 					{
978 1019
 						$post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list));
979 1020
 						$context['ignore_temp_attachments'] = true;
@@ -981,16 +1022,19 @@  discard block
 block discarded – undo
981 1022
 				}
982 1023
 			}
983 1024
 
984
-			if (!empty($context['we_are_history']))
985
-				$post_errors[] = $context['we_are_history'];
1025
+			if (!empty($context['we_are_history'])) {
1026
+							$post_errors[] = $context['we_are_history'];
1027
+			}
986 1028
 
987 1029
 			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
988 1030
 			{
989
-				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
990
-					break;
1031
+				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) {
1032
+									break;
1033
+				}
991 1034
 
992
-				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
993
-					continue;
1035
+				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1036
+									continue;
1037
+				}
994 1038
 
995 1039
 				if ($attachID == 'initial_error')
996 1040
 				{
@@ -1005,15 +1049,17 @@  discard block
 block discarded – undo
1005 1049
 				{
1006 1050
 					$txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : '';
1007 1051
 					$txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
1008
-					foreach ($attachment['errors'] as $error)
1009
-						$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1052
+					foreach ($attachment['errors'] as $error) {
1053
+											$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1054
+					}
1010 1055
 					$txt['error_attach_errors'] .= '</div>';
1011 1056
 					$post_errors[] = 'attach_errors';
1012 1057
 
1013 1058
 					// Take out the trash.
1014 1059
 					unset($_SESSION['temp_attachments'][$attachID]);
1015
-					if (file_exists($attachment['tmp_name']))
1016
-						unlink($attachment['tmp_name']);
1060
+					if (file_exists($attachment['tmp_name'])) {
1061
+											unlink($attachment['tmp_name']);
1062
+					}
1017 1063
 					continue;
1018 1064
 				}
1019 1065
 
@@ -1026,8 +1072,9 @@  discard block
 block discarded – undo
1026 1072
 
1027 1073
 				$context['attachments']['quantity']++;
1028 1074
 				$context['attachments']['total_size'] += $attachment['size'];
1029
-				if (!isset($context['files_in_session_warning']))
1030
-					$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1075
+				if (!isset($context['files_in_session_warning'])) {
1076
+									$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1077
+				}
1031 1078
 
1032 1079
 				$context['current_attachments'][$attachID] = array(
1033 1080
 					'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>',
@@ -1055,8 +1102,9 @@  discard block
 block discarded – undo
1055 1102
 	}
1056 1103
 
1057 1104
 	// If they came from quick reply, and have to enter verification details, give them some notice.
1058
-	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
1059
-		$post_errors[] = 'need_qr_verification';
1105
+	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) {
1106
+			$post_errors[] = 'need_qr_verification';
1107
+	}
1060 1108
 
1061 1109
 	/*
1062 1110
 	 * There are two error types: serious and minor. Serious errors
@@ -1073,52 +1121,56 @@  discard block
 block discarded – undo
1073 1121
 	{
1074 1122
 		loadLanguage('Errors');
1075 1123
 		$context['error_type'] = 'minor';
1076
-		foreach ($post_errors as $post_error)
1077
-			if (is_array($post_error))
1124
+		foreach ($post_errors as $post_error) {
1125
+					if (is_array($post_error))
1078 1126
 			{
1079 1127
 				$post_error_id = $post_error[0];
1128
+		}
1080 1129
 				$context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]);
1081 1130
 
1082 1131
 				// If it's not a minor error flag it as such.
1083
-				if (!in_array($post_error_id, $minor_errors))
1084
-					$context['error_type'] = 'serious';
1085
-			}
1086
-			else
1132
+				if (!in_array($post_error_id, $minor_errors)) {
1133
+									$context['error_type'] = 'serious';
1134
+				}
1135
+			} else
1087 1136
 			{
1088 1137
 				$context['post_error'][$post_error] = $txt['error_' . $post_error];
1089 1138
 
1090 1139
 				// If it's not a minor error flag it as such.
1091
-				if (!in_array($post_error, $minor_errors))
1092
-					$context['error_type'] = 'serious';
1140
+				if (!in_array($post_error, $minor_errors)) {
1141
+									$context['error_type'] = 'serious';
1142
+				}
1093 1143
 			}
1094 1144
 	}
1095 1145
 
1096 1146
 	// What are you doing? Posting a poll, modifying, previewing, new post, or reply...
1097
-	if (isset($_REQUEST['poll']))
1098
-		$context['page_title'] = $txt['new_poll'];
1099
-	elseif ($context['make_event'])
1100
-		$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1101
-	elseif (isset($_REQUEST['msg']))
1102
-		$context['page_title'] = $txt['modify_msg'];
1103
-	elseif (isset($_REQUEST['subject'], $context['preview_subject']))
1104
-		$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1105
-	elseif (empty($topic))
1106
-		$context['page_title'] = $txt['start_new_topic'];
1107
-	else
1108
-		$context['page_title'] = $txt['post_reply'];
1147
+	if (isset($_REQUEST['poll'])) {
1148
+			$context['page_title'] = $txt['new_poll'];
1149
+	} elseif ($context['make_event']) {
1150
+			$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1151
+	} elseif (isset($_REQUEST['msg'])) {
1152
+			$context['page_title'] = $txt['modify_msg'];
1153
+	} elseif (isset($_REQUEST['subject'], $context['preview_subject'])) {
1154
+			$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1155
+	} elseif (empty($topic)) {
1156
+			$context['page_title'] = $txt['start_new_topic'];
1157
+	} else {
1158
+			$context['page_title'] = $txt['post_reply'];
1159
+	}
1109 1160
 
1110 1161
 	// Build the link tree.
1111
-	if (empty($topic))
1112
-		$context['linktree'][] = array(
1162
+	if (empty($topic)) {
1163
+			$context['linktree'][] = array(
1113 1164
 			'name' => '<em>' . $txt['start_new_topic'] . '</em>'
1114 1165
 		);
1115
-	else
1116
-		$context['linktree'][] = array(
1166
+	} else {
1167
+			$context['linktree'][] = array(
1117 1168
 			'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
1118 1169
 			'name' => $form_subject,
1119 1170
 			'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>',
1120 1171
 			'extra_after' => '<span><strong class="nav">)</strong></span>'
1121 1172
 		);
1173
+	}
1122 1174
 
1123 1175
 	$context['subject'] = addcslashes($form_subject, '"');
1124 1176
 	$context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
@@ -1162,8 +1214,9 @@  discard block
 block discarded – undo
1162 1214
 	// Message icons - customized icons are off?
1163 1215
 	$context['icons'] = getMessageIcons($board);
1164 1216
 
1165
-	if (!empty($context['icons']))
1166
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1217
+	if (!empty($context['icons'])) {
1218
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1219
+	}
1167 1220
 
1168 1221
 	// Are we starting a poll? if set the poll icon as selected if its available
1169 1222
 	if (isset($_REQUEST['poll']))
@@ -1183,8 +1236,9 @@  discard block
 block discarded – undo
1183 1236
 	for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
1184 1237
 	{
1185 1238
 		$context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
1186
-		if ($context['icons'][$i]['selected'])
1187
-			$context['icon_url'] = $context['icons'][$i]['url'];
1239
+		if ($context['icons'][$i]['selected']) {
1240
+					$context['icon_url'] = $context['icons'][$i]['url'];
1241
+		}
1188 1242
 	}
1189 1243
 	if (empty($context['icon_url']))
1190 1244
 	{
@@ -1198,8 +1252,9 @@  discard block
 block discarded – undo
1198 1252
 		));
1199 1253
 	}
1200 1254
 
1201
-	if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
1202
-		getTopic();
1255
+	if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) {
1256
+			getTopic();
1257
+	}
1203 1258
 
1204 1259
 	// If the user can post attachments prepare the warning labels.
1205 1260
 	if ($context['can_post_attachment'])
@@ -1210,15 +1265,17 @@  discard block
 block discarded – undo
1210 1265
 		$context['attachment_restrictions'] = array();
1211 1266
 		$context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
1212 1267
 		$attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
1213
-		foreach ($attachmentRestrictionTypes as $type)
1214
-			if (!empty($modSettings[$type]))
1268
+		foreach ($attachmentRestrictionTypes as $type) {
1269
+					if (!empty($modSettings[$type]))
1215 1270
 			{
1216 1271
 				$context['attachment_restrictions'][] = sprintf($txt['attach_restrict_' . $type . ($modSettings[$type] >= 1024 ? '_MB' : '')], comma_format($modSettings[$type], 0));
1272
+		}
1217 1273
 				// Show some numbers. If they exist.
1218
-				if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0)
1219
-					$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1220
-				elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0)
1221
-					$context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)), 0));
1274
+				if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0) {
1275
+									$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1276
+				} elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0) {
1277
+									$context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)), 0));
1278
+				}
1222 1279
 			}
1223 1280
 	}
1224 1281
 
@@ -1252,8 +1309,8 @@  discard block
 block discarded – undo
1252 1309
 
1253 1310
 	if (!empty($context['current_attachments']))
1254 1311
 	{
1255
-		foreach ($context['current_attachments'] as $key => $mock)
1256
-			addInlineJavaScript('
1312
+		foreach ($context['current_attachments'] as $key => $mock) {
1313
+					addInlineJavaScript('
1257 1314
 	current_attachments.push({
1258 1315
 		name: '. JavaScriptEscape($mock['name']) .',
1259 1316
 		size: '. $mock['size'] .',
@@ -1262,6 +1319,7 @@  discard block
 block discarded – undo
1262 1319
 		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') .',
1263 1320
 		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) .'
1264 1321
 	});', true);
1322
+		}
1265 1323
 	}
1266 1324
 
1267 1325
 	// File Upload.
@@ -1306,8 +1364,9 @@  discard block
 block discarded – undo
1306 1364
 	var current_board = '. (empty($context['current_board']) ? 'null' : $context['current_board']) .';', false);
1307 1365
 
1308 1366
 	// Finally, load the template.
1309
-	if (!isset($_REQUEST['xml']))
1310
-		loadTemplate('Post');
1367
+	if (!isset($_REQUEST['xml'])) {
1368
+			loadTemplate('Post');
1369
+	}
1311 1370
 
1312 1371
 	call_integration_hook('integrate_post_end');
1313 1372
 }
@@ -1328,13 +1387,14 @@  discard block
 block discarded – undo
1328 1387
 	// Sneaking off, are we?
1329 1388
 	if (empty($_POST) && empty($topic))
1330 1389
 	{
1331
-		if (empty($_SERVER['CONTENT_LENGTH']))
1332
-			redirectexit('action=post;board=' . $board . '.0');
1333
-		else
1334
-			fatal_lang_error('post_upload_error', false);
1390
+		if (empty($_SERVER['CONTENT_LENGTH'])) {
1391
+					redirectexit('action=post;board=' . $board . '.0');
1392
+		} else {
1393
+					fatal_lang_error('post_upload_error', false);
1394
+		}
1395
+	} elseif (empty($_POST) && !empty($topic)) {
1396
+			redirectexit('action=post;topic=' . $topic . '.0');
1335 1397
 	}
1336
-	elseif (empty($_POST) && !empty($topic))
1337
-		redirectexit('action=post;topic=' . $topic . '.0');
1338 1398
 
1339 1399
 	// No need!
1340 1400
 	$context['robot_no_index'] = true;
@@ -1346,8 +1406,9 @@  discard block
 block discarded – undo
1346 1406
 	$post_errors = array();
1347 1407
 
1348 1408
 	// If the session has timed out, let the user re-submit their form.
1349
-	if (checkSession('post', '', false) != '')
1350
-		$post_errors[] = 'session_timeout';
1409
+	if (checkSession('post', '', false) != '') {
1410
+			$post_errors[] = 'session_timeout';
1411
+	}
1351 1412
 
1352 1413
 	// Wrong verification code?
1353 1414
 	if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))
@@ -1357,33 +1418,38 @@  discard block
 block discarded – undo
1357 1418
 			'id' => 'post',
1358 1419
 		);
1359 1420
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
1360
-		if (is_array($context['require_verification']))
1361
-			$post_errors = array_merge($post_errors, $context['require_verification']);
1421
+		if (is_array($context['require_verification'])) {
1422
+					$post_errors = array_merge($post_errors, $context['require_verification']);
1423
+		}
1362 1424
 	}
1363 1425
 
1364 1426
 	require_once($sourcedir . '/Subs-Post.php');
1365 1427
 	loadLanguage('Post');
1366 1428
 
1367 1429
 	// Drafts enabled and needed?
1368
-	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
1369
-		require_once($sourcedir . '/Drafts.php');
1430
+	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) {
1431
+			require_once($sourcedir . '/Drafts.php');
1432
+	}
1370 1433
 
1371 1434
 	// First check to see if they are trying to delete any current attachments.
1372 1435
 	if (isset($_POST['attach_del']))
1373 1436
 	{
1374 1437
 		$keep_temp = array();
1375 1438
 		$keep_ids = array();
1376
-		foreach ($_POST['attach_del'] as $dummy)
1377
-			if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1439
+		foreach ($_POST['attach_del'] as $dummy) {
1440
+					if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1378 1441
 				$keep_temp[] = $dummy;
1379
-			else
1380
-				$keep_ids[] = (int) $dummy;
1442
+		}
1443
+			else {
1444
+							$keep_ids[] = (int) $dummy;
1445
+			}
1381 1446
 
1382
-		if (isset($_SESSION['temp_attachments']))
1383
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1447
+		if (isset($_SESSION['temp_attachments'])) {
1448
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1384 1449
 			{
1385 1450
 				if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1386 1451
 					continue;
1452
+		}
1387 1453
 
1388 1454
 				unset($_SESSION['temp_attachments'][$attachID]);
1389 1455
 				unlink($attachment['tmp_name']);
@@ -1425,24 +1491,28 @@  discard block
 block discarded – undo
1425 1491
 		$smcFunc['db_free_result']($request);
1426 1492
 
1427 1493
 		// Though the topic should be there, it might have vanished.
1428
-		if (!is_array($topic_info))
1429
-			fatal_lang_error('topic_doesnt_exist', 404);
1494
+		if (!is_array($topic_info)) {
1495
+					fatal_lang_error('topic_doesnt_exist', 404);
1496
+		}
1430 1497
 
1431 1498
 		// Did this topic suddenly move? Just checking...
1432
-		if ($topic_info['id_board'] != $board)
1433
-			fatal_lang_error('not_a_topic');
1499
+		if ($topic_info['id_board'] != $board) {
1500
+					fatal_lang_error('not_a_topic');
1501
+		}
1434 1502
 	}
1435 1503
 
1436 1504
 	// Replying to a topic?
1437 1505
 	if (!empty($topic) && !isset($_REQUEST['msg']))
1438 1506
 	{
1439 1507
 		// Don't allow a post if it's locked.
1440
-		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
1441
-			fatal_lang_error('topic_locked', false);
1508
+		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) {
1509
+					fatal_lang_error('topic_locked', false);
1510
+		}
1442 1511
 
1443 1512
 		// Sorry, multiple polls aren't allowed... yet.  You should stop giving me ideas :P.
1444
-		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
1445
-			unset($_REQUEST['poll']);
1513
+		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) {
1514
+					unset($_REQUEST['poll']);
1515
+		}
1446 1516
 
1447 1517
 		// Do the permissions and approval stuff...
1448 1518
 		$becomesApproved = true;
@@ -1458,44 +1528,43 @@  discard block
 block discarded – undo
1458 1528
 
1459 1529
 			// Set a nice session var...
1460 1530
 			$_SESSION['becomesUnapproved'] = true;
1461
-		}
1462
-
1463
-		elseif ($topic_info['id_member_started'] != $user_info['id'])
1531
+		} elseif ($topic_info['id_member_started'] != $user_info['id'])
1464 1532
 		{
1465
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
1466
-				$becomesApproved = false;
1467
-
1468
-			else
1469
-				isAllowedTo('post_reply_any');
1470
-		}
1471
-		elseif (!allowedTo('post_reply_any'))
1533
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
1534
+							$becomesApproved = false;
1535
+			} else {
1536
+							isAllowedTo('post_reply_any');
1537
+			}
1538
+		} elseif (!allowedTo('post_reply_any'))
1472 1539
 		{
1473
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
1474
-				$becomesApproved = false;
1475
-
1476
-			else
1477
-				isAllowedTo('post_reply_own');
1540
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) {
1541
+							$becomesApproved = false;
1542
+			} else {
1543
+							isAllowedTo('post_reply_own');
1544
+			}
1478 1545
 		}
1479 1546
 
1480 1547
 		if (isset($_POST['lock']))
1481 1548
 		{
1482 1549
 			// Nothing is changed to the lock.
1483
-			if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1484
-				unset($_POST['lock']);
1550
+			if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1551
+							unset($_POST['lock']);
1552
+			}
1485 1553
 
1486 1554
 			// You're have no permission to lock this topic.
1487
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1488
-				unset($_POST['lock']);
1555
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1556
+							unset($_POST['lock']);
1557
+			}
1489 1558
 
1490 1559
 			// You are allowed to (un)lock your own topic only.
1491 1560
 			elseif (!allowedTo('lock_any'))
1492 1561
 			{
1493 1562
 				// You cannot override a moderator lock.
1494
-				if ($topic_info['locked'] == 1)
1495
-					unset($_POST['lock']);
1496
-
1497
-				else
1498
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1563
+				if ($topic_info['locked'] == 1) {
1564
+									unset($_POST['lock']);
1565
+				} else {
1566
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1567
+				}
1499 1568
 			}
1500 1569
 			// Hail mighty moderator, (un)lock this topic immediately.
1501 1570
 			else
@@ -1503,19 +1572,21 @@  discard block
 block discarded – undo
1503 1572
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1504 1573
 
1505 1574
 				// Did someone (un)lock this while you were posting?
1506
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1507
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1575
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1576
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1577
+				}
1508 1578
 			}
1509 1579
 		}
1510 1580
 
1511 1581
 		// So you wanna (un)sticky this...let's see.
1512
-		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
1513
-			unset($_POST['sticky']);
1514
-		elseif (isset($_POST['sticky']))
1582
+		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) {
1583
+					unset($_POST['sticky']);
1584
+		} elseif (isset($_POST['sticky']))
1515 1585
 		{
1516 1586
 			// Did someone (un)sticky this while you were posting?
1517
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1518
-				$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1587
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1588
+							$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1589
+			}
1519 1590
 		}
1520 1591
 
1521 1592
 		// If drafts are enabled, then pass this off
@@ -1542,26 +1613,31 @@  discard block
 block discarded – undo
1542 1613
 
1543 1614
 		// Do like, the permissions, for safety and stuff...
1544 1615
 		$becomesApproved = true;
1545
-		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
1546
-			$becomesApproved = false;
1547
-		else
1548
-			isAllowedTo('post_new');
1616
+		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
1617
+					$becomesApproved = false;
1618
+		} else {
1619
+					isAllowedTo('post_new');
1620
+		}
1549 1621
 
1550 1622
 		if (isset($_POST['lock']))
1551 1623
 		{
1552 1624
 			// New topics are by default not locked.
1553
-			if (empty($_POST['lock']))
1554
-				unset($_POST['lock']);
1625
+			if (empty($_POST['lock'])) {
1626
+							unset($_POST['lock']);
1627
+			}
1555 1628
 			// Besides, you need permission.
1556
-			elseif (!allowedTo(array('lock_any', 'lock_own')))
1557
-				unset($_POST['lock']);
1629
+			elseif (!allowedTo(array('lock_any', 'lock_own'))) {
1630
+							unset($_POST['lock']);
1631
+			}
1558 1632
 			// A moderator-lock (1) can override a user-lock (2).
1559
-			else
1560
-				$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1633
+			else {
1634
+							$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1635
+			}
1561 1636
 		}
1562 1637
 
1563
-		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky')))
1564
-			unset($_POST['sticky']);
1638
+		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) {
1639
+					unset($_POST['sticky']);
1640
+		}
1565 1641
 
1566 1642
 		// Saving your new topic as a draft first?
1567 1643
 		if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft']))
@@ -1586,31 +1662,37 @@  discard block
 block discarded – undo
1586 1662
 				'id_msg' => $_REQUEST['msg'],
1587 1663
 			)
1588 1664
 		);
1589
-		if ($smcFunc['db_num_rows']($request) == 0)
1590
-			fatal_lang_error('cant_find_messages', false);
1665
+		if ($smcFunc['db_num_rows']($request) == 0) {
1666
+					fatal_lang_error('cant_find_messages', false);
1667
+		}
1591 1668
 		$row = $smcFunc['db_fetch_assoc']($request);
1592 1669
 		$smcFunc['db_free_result']($request);
1593 1670
 
1594
-		if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
1595
-			fatal_lang_error('topic_locked', false);
1671
+		if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) {
1672
+					fatal_lang_error('topic_locked', false);
1673
+		}
1596 1674
 
1597 1675
 		if (isset($_POST['lock']))
1598 1676
 		{
1599 1677
 			// Nothing changes to the lock status.
1600
-			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1601
-				unset($_POST['lock']);
1678
+			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1679
+							unset($_POST['lock']);
1680
+			}
1602 1681
 			// You're simply not allowed to (un)lock this.
1603
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1604
-				unset($_POST['lock']);
1682
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1683
+							unset($_POST['lock']);
1684
+			}
1605 1685
 			// You're only allowed to lock your own topics.
1606 1686
 			elseif (!allowedTo('lock_any'))
1607 1687
 			{
1608 1688
 				// You're not allowed to break a moderator's lock.
1609
-				if ($topic_info['locked'] == 1)
1610
-					unset($_POST['lock']);
1689
+				if ($topic_info['locked'] == 1) {
1690
+									unset($_POST['lock']);
1691
+				}
1611 1692
 				// Lock it with a soft lock or unlock it.
1612
-				else
1613
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1693
+				else {
1694
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1695
+				}
1614 1696
 			}
1615 1697
 			// You must be the moderator.
1616 1698
 			else
@@ -1618,44 +1700,46 @@  discard block
 block discarded – undo
1618 1700
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1619 1701
 
1620 1702
 				// Did someone (un)lock this while you were posting?
1621
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1622
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1703
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1704
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1705
+				}
1623 1706
 			}
1624 1707
 		}
1625 1708
 
1626 1709
 		// Change the sticky status of this topic?
1627
-		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
1628
-			unset($_POST['sticky']);
1629
-		elseif (isset($_POST['sticky']))
1710
+		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) {
1711
+					unset($_POST['sticky']);
1712
+		} elseif (isset($_POST['sticky']))
1630 1713
 		{
1631 1714
 			// Did someone (un)sticky this while you were posting?
1632
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1633
-				$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1715
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1716
+							$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1717
+			}
1634 1718
 		}
1635 1719
 
1636 1720
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
1637 1721
 		{
1638
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
1639
-				fatal_lang_error('modify_post_time_passed', false);
1640
-			elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
1641
-				isAllowedTo('modify_replies');
1642
-			else
1643
-				isAllowedTo('modify_own');
1644
-		}
1645
-		elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1722
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
1723
+							fatal_lang_error('modify_post_time_passed', false);
1724
+			} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
1725
+							isAllowedTo('modify_replies');
1726
+			} else {
1727
+							isAllowedTo('modify_own');
1728
+			}
1729
+		} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1646 1730
 		{
1647 1731
 			isAllowedTo('modify_replies');
1648 1732
 
1649 1733
 			// If you're modifying a reply, I say it better be logged...
1650 1734
 			$moderationAction = true;
1651
-		}
1652
-		else
1735
+		} else
1653 1736
 		{
1654 1737
 			isAllowedTo('modify_any');
1655 1738
 
1656 1739
 			// Log it, assuming you're not modifying your own post.
1657
-			if ($row['id_member'] != $user_info['id'])
1658
-				$moderationAction = true;
1740
+			if ($row['id_member'] != $user_info['id']) {
1741
+							$moderationAction = true;
1742
+			}
1659 1743
 		}
1660 1744
 
1661 1745
 		// If drafts are enabled, then lets send this off to save
@@ -1692,20 +1776,24 @@  discard block
 block discarded – undo
1692 1776
 		$_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
1693 1777
 		$_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
1694 1778
 
1695
-		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
1696
-			$post_errors[] = 'no_name';
1697
-		if ($smcFunc['strlen']($_POST['guestname']) > 25)
1698
-			$post_errors[] = 'long_name';
1779
+		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') {
1780
+					$post_errors[] = 'no_name';
1781
+		}
1782
+		if ($smcFunc['strlen']($_POST['guestname']) > 25) {
1783
+					$post_errors[] = 'long_name';
1784
+		}
1699 1785
 
1700 1786
 		if (empty($modSettings['guest_post_no_email']))
1701 1787
 		{
1702 1788
 			// Only check if they changed it!
1703 1789
 			if (!isset($row) || $row['poster_email'] != $_POST['email'])
1704 1790
 			{
1705
-				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
1706
-					$post_errors[] = 'no_email';
1707
-				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
1708
-					$post_errors[] = 'bad_email';
1791
+				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) {
1792
+									$post_errors[] = 'no_email';
1793
+				}
1794
+				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
1795
+									$post_errors[] = 'bad_email';
1796
+				}
1709 1797
 			}
1710 1798
 
1711 1799
 			// Now make sure this email address is not banned from posting.
@@ -1721,75 +1809,89 @@  discard block
 block discarded – undo
1721 1809
 	}
1722 1810
 
1723 1811
 	// Coming from the quickReply?
1724
-	if(isset($_POST['quickReply']))
1725
-		$_POST['message'] = $_POST['quickReply'];
1812
+	if(isset($_POST['quickReply'])) {
1813
+			$_POST['message'] = $_POST['quickReply'];
1814
+	}
1726 1815
 
1727 1816
 	// Check the subject and message.
1728
-	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
1729
-		$post_errors[] = 'no_subject';
1730
-	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
1731
-		$post_errors[] = 'no_message';
1732
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
1733
-		$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1734
-	else
1817
+	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') {
1818
+			$post_errors[] = 'no_subject';
1819
+	}
1820
+	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') {
1821
+			$post_errors[] = 'no_message';
1822
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) {
1823
+			$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1824
+	} else
1735 1825
 	{
1736 1826
 		// Prepare the message a bit for some additional testing.
1737 1827
 		$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
1738 1828
 
1739 1829
 		// Preparse code. (Zef)
1740
-		if ($user_info['is_guest'])
1741
-			$user_info['name'] = $_POST['guestname'];
1830
+		if ($user_info['is_guest']) {
1831
+					$user_info['name'] = $_POST['guestname'];
1832
+		}
1742 1833
 		preparsecode($_POST['message']);
1743 1834
 
1744 1835
 		// Let's see if there's still some content left without the tags.
1745
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
1746
-			$post_errors[] = 'no_message';
1836
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) {
1837
+					$post_errors[] = 'no_message';
1838
+		}
1839
+	}
1840
+	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') {
1841
+			$post_errors[] = 'no_event';
1747 1842
 	}
1748
-	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
1749
-		$post_errors[] = 'no_event';
1750 1843
 	// You are not!
1751
-	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
1752
-		fatal_error('Knave! Masquerader! Charlatan!', false);
1844
+	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) {
1845
+			fatal_error('Knave! Masquerader! Charlatan!', false);
1846
+	}
1753 1847
 
1754 1848
 	// Validate the poll...
1755 1849
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
1756 1850
 	{
1757
-		if (!empty($topic) && !isset($_REQUEST['msg']))
1758
-			fatal_lang_error('no_access', false);
1851
+		if (!empty($topic) && !isset($_REQUEST['msg'])) {
1852
+					fatal_lang_error('no_access', false);
1853
+		}
1759 1854
 
1760 1855
 		// This is a new topic... so it's a new poll.
1761
-		if (empty($topic))
1762
-			isAllowedTo('poll_post');
1856
+		if (empty($topic)) {
1857
+					isAllowedTo('poll_post');
1858
+		}
1763 1859
 		// Can you add to your own topics?
1764
-		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
1765
-			isAllowedTo('poll_add_own');
1860
+		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) {
1861
+					isAllowedTo('poll_add_own');
1862
+		}
1766 1863
 		// Can you add polls to any topic, then?
1767
-		else
1768
-			isAllowedTo('poll_add_any');
1864
+		else {
1865
+					isAllowedTo('poll_add_any');
1866
+		}
1769 1867
 
1770
-		if (!isset($_POST['question']) || trim($_POST['question']) == '')
1771
-			$post_errors[] = 'no_question';
1868
+		if (!isset($_POST['question']) || trim($_POST['question']) == '') {
1869
+					$post_errors[] = 'no_question';
1870
+		}
1772 1871
 
1773 1872
 		$_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
1774 1873
 
1775 1874
 		// Get rid of empty ones.
1776
-		foreach ($_POST['options'] as $k => $option)
1777
-			if ($option == '')
1875
+		foreach ($_POST['options'] as $k => $option) {
1876
+					if ($option == '')
1778 1877
 				unset($_POST['options'][$k], $_POST['options'][$k]);
1878
+		}
1779 1879
 
1780 1880
 		// What are you going to vote between with one choice?!?
1781
-		if (count($_POST['options']) < 2)
1782
-			$post_errors[] = 'poll_few';
1783
-		elseif (count($_POST['options']) > 256)
1784
-			$post_errors[] = 'poll_many';
1881
+		if (count($_POST['options']) < 2) {
1882
+					$post_errors[] = 'poll_few';
1883
+		} elseif (count($_POST['options']) > 256) {
1884
+					$post_errors[] = 'poll_many';
1885
+		}
1785 1886
 	}
1786 1887
 
1787 1888
 	if ($posterIsGuest)
1788 1889
 	{
1789 1890
 		// If user is a guest, make sure the chosen name isn't taken.
1790 1891
 		require_once($sourcedir . '/Subs-Members.php');
1791
-		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
1792
-			$post_errors[] = 'bad_name';
1892
+		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) {
1893
+					$post_errors[] = 'bad_name';
1894
+		}
1793 1895
 	}
1794 1896
 	// If the user isn't a guest, get his or her name and email.
1795 1897
 	elseif (!isset($_REQUEST['msg']))
@@ -1820,8 +1922,9 @@  discard block
 block discarded – undo
1820 1922
 	}
1821 1923
 
1822 1924
 	// Make sure the user isn't spamming the board.
1823
-	if (!isset($_REQUEST['msg']))
1824
-		spamProtection('post');
1925
+	if (!isset($_REQUEST['msg'])) {
1926
+			spamProtection('post');
1927
+	}
1825 1928
 
1826 1929
 	// At about this point, we're posting and that's that.
1827 1930
 	ignore_user_abort(true);
@@ -1834,32 +1937,36 @@  discard block
 block discarded – undo
1834 1937
 	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
1835 1938
 
1836 1939
 	// At this point, we want to make sure the subject isn't too long.
1837
-	if ($smcFunc['strlen']($_POST['subject']) > 100)
1838
-		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
1940
+	if ($smcFunc['strlen']($_POST['subject']) > 100) {
1941
+			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
1942
+	}
1839 1943
 
1840 1944
 	// Same with the "why did you edit this" text.
1841
-	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
1842
-		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
1945
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
1946
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
1947
+	}
1843 1948
 
1844 1949
 	// Make the poll...
1845 1950
 	if (isset($_REQUEST['poll']))
1846 1951
 	{
1847 1952
 		// Make sure that the user has not entered a ridiculous number of options..
1848
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
1849
-			$_POST['poll_max_votes'] = 1;
1850
-		elseif ($_POST['poll_max_votes'] > count($_POST['options']))
1851
-			$_POST['poll_max_votes'] = count($_POST['options']);
1852
-		else
1853
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
1953
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
1954
+					$_POST['poll_max_votes'] = 1;
1955
+		} elseif ($_POST['poll_max_votes'] > count($_POST['options'])) {
1956
+					$_POST['poll_max_votes'] = count($_POST['options']);
1957
+		} else {
1958
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
1959
+		}
1854 1960
 
1855 1961
 		$_POST['poll_expire'] = (int) $_POST['poll_expire'];
1856 1962
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
1857 1963
 
1858 1964
 		// Just set it to zero if it's not there..
1859
-		if (!isset($_POST['poll_hide']))
1860
-			$_POST['poll_hide'] = 0;
1861
-		else
1862
-			$_POST['poll_hide'] = (int) $_POST['poll_hide'];
1965
+		if (!isset($_POST['poll_hide'])) {
1966
+					$_POST['poll_hide'] = 0;
1967
+		} else {
1968
+					$_POST['poll_hide'] = (int) $_POST['poll_hide'];
1969
+		}
1863 1970
 		$_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
1864 1971
 
1865 1972
 		$_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
@@ -1868,16 +1975,19 @@  discard block
 block discarded – undo
1868 1975
 		{
1869 1976
 			require_once($sourcedir . '/Subs-Members.php');
1870 1977
 			$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
1871
-			if (!in_array(-1, $allowedVoteGroups['allowed']))
1872
-				$_POST['poll_guest_vote'] = 0;
1978
+			if (!in_array(-1, $allowedVoteGroups['allowed'])) {
1979
+							$_POST['poll_guest_vote'] = 0;
1980
+			}
1873 1981
 		}
1874 1982
 
1875 1983
 		// If the user tries to set the poll too far in advance, don't let them.
1876
-		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
1877
-			fatal_lang_error('poll_range_error', false);
1984
+		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
1985
+					fatal_lang_error('poll_range_error', false);
1986
+		}
1878 1987
 		// Don't allow them to select option 2 for hidden results if it's not time limited.
1879
-		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
1880
-			$_POST['poll_hide'] = 1;
1988
+		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
1989
+					$_POST['poll_hide'] = 1;
1990
+		}
1881 1991
 
1882 1992
 		// Clean up the question and answers.
1883 1993
 		$_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']);
@@ -1891,13 +2001,15 @@  discard block
 block discarded – undo
1891 2001
 	{
1892 2002
 		$attachIDs = array();
1893 2003
 		$attach_errors = array();
1894
-		if (!empty($context['we_are_history']))
1895
-			$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2004
+		if (!empty($context['we_are_history'])) {
2005
+					$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2006
+		}
1896 2007
 
1897 2008
 		foreach ($_SESSION['temp_attachments'] as  $attachID => $attachment)
1898 2009
 		{
1899
-			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1900
-				continue;
2010
+			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
2011
+							continue;
2012
+			}
1901 2013
 
1902 2014
 			// If there was an initial error just show that message.
1903 2015
 			if ($attachID == 'initial_error')
@@ -1926,12 +2038,13 @@  discard block
 block discarded – undo
1926 2038
 				if (createAttachment($attachmentOptions))
1927 2039
 				{
1928 2040
 					$attachIDs[] = $attachmentOptions['id'];
1929
-					if (!empty($attachmentOptions['thumb']))
1930
-						$attachIDs[] = $attachmentOptions['thumb'];
2041
+					if (!empty($attachmentOptions['thumb'])) {
2042
+											$attachIDs[] = $attachmentOptions['thumb'];
2043
+					}
1931 2044
 				}
2045
+			} else {
2046
+							$attach_errors[] = '<dt>&nbsp;</dt>';
1932 2047
 			}
1933
-			else
1934
-				$attach_errors[] = '<dt>&nbsp;</dt>';
1935 2048
 
1936 2049
 			if (!empty($attachmentOptions['errors']))
1937 2050
 			{
@@ -1943,14 +2056,16 @@  discard block
 block discarded – undo
1943 2056
 					if (!is_array($error))
1944 2057
 					{
1945 2058
 						$attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
1946
-						if (in_array($error, $log_these))
1947
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2059
+						if (in_array($error, $log_these)) {
2060
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2061
+						}
2062
+					} else {
2063
+											$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
1948 2064
 					}
1949
-					else
1950
-						$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
1951 2065
 				}
1952
-				if (file_exists($attachment['tmp_name']))
1953
-					unlink($attachment['tmp_name']);
2066
+				if (file_exists($attachment['tmp_name'])) {
2067
+									unlink($attachment['tmp_name']);
2068
+				}
1954 2069
 			}
1955 2070
 		}
1956 2071
 		unset($_SESSION['temp_attachments']);
@@ -1991,24 +2106,24 @@  discard block
 block discarded – undo
1991 2106
 		);
1992 2107
 
1993 2108
 		call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
2109
+	} else {
2110
+			$id_poll = 0;
1994 2111
 	}
1995
-	else
1996
-		$id_poll = 0;
1997 2112
 
1998 2113
 	// Creating a new topic?
1999 2114
 	$newTopic = empty($_REQUEST['msg']) && empty($topic);
2000 2115
 
2001 2116
 	// Check the icon.
2002
-	if (!isset($_POST['icon']))
2003
-		$_POST['icon'] = 'xx';
2004
-
2005
-	else
2117
+	if (!isset($_POST['icon'])) {
2118
+			$_POST['icon'] = 'xx';
2119
+	} else
2006 2120
 	{
2007 2121
 		$_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']);
2008 2122
 
2009 2123
 		// Need to figure it out if this is a valid icon name.
2010
-		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')))
2011
-			$_POST['icon'] = 'xx';
2124
+		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) {
2125
+					$_POST['icon'] = 'xx';
2126
+		}
2012 2127
 	}
2013 2128
 
2014 2129
 	// Collect all parameters for the creation or modification of a post.
@@ -2049,8 +2164,9 @@  discard block
 block discarded – undo
2049 2164
 		}
2050 2165
 
2051 2166
 		// This will save some time...
2052
-		if (empty($approve_has_changed))
2053
-			unset($msgOptions['approved']);
2167
+		if (empty($approve_has_changed)) {
2168
+					unset($msgOptions['approved']);
2169
+		}
2054 2170
 
2055 2171
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2056 2172
 	}
@@ -2059,8 +2175,9 @@  discard block
 block discarded – undo
2059 2175
 	{
2060 2176
 		createPost($msgOptions, $topicOptions, $posterOptions);
2061 2177
 
2062
-		if (isset($topicOptions['id']))
2063
-			$topic = $topicOptions['id'];
2178
+		if (isset($topicOptions['id'])) {
2179
+					$topic = $topicOptions['id'];
2180
+		}
2064 2181
 	}
2065 2182
 
2066 2183
 	// Assign the previously uploaded attachments to the brand new message.
@@ -2072,8 +2189,9 @@  discard block
 block discarded – undo
2072 2189
 	}
2073 2190
 
2074 2191
 	// If we had a draft for this, its time to remove it since it was just posted
2075
-	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft']))
2076
-		DeleteDraft($_POST['id_draft']);
2192
+	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) {
2193
+			DeleteDraft($_POST['id_draft']);
2194
+	}
2077 2195
 
2078 2196
 	// Editing or posting an event?
2079 2197
 	if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
@@ -2092,8 +2210,7 @@  discard block
 block discarded – undo
2092 2210
 			'member' => $user_info['id'],
2093 2211
 		);
2094 2212
 		insertEvent($eventOptions);
2095
-	}
2096
-	elseif (isset($_POST['calendar']))
2213
+	} elseif (isset($_POST['calendar']))
2097 2214
 	{
2098 2215
 		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
2099 2216
 
@@ -2121,14 +2238,15 @@  discard block
 block discarded – undo
2121 2238
 		}
2122 2239
 
2123 2240
 		// Delete it?
2124
-		if (isset($_REQUEST['deleteevent']))
2125
-			$smcFunc['db_query']('', '
2241
+		if (isset($_REQUEST['deleteevent'])) {
2242
+					$smcFunc['db_query']('', '
2126 2243
 				DELETE FROM {db_prefix}calendar
2127 2244
 				WHERE id_event = {int:id_event}',
2128 2245
 				array(
2129 2246
 					'id_event' => $_REQUEST['eventid'],
2130 2247
 				)
2131 2248
 			);
2249
+		}
2132 2250
 		// ... or just update it?
2133 2251
 		else
2134 2252
 		{
@@ -2170,9 +2288,8 @@  discard block
 block discarded – undo
2170 2288
 			array($user_info['id'], $topic, 0),
2171 2289
 			array('id_member', 'id_topic', 'id_board')
2172 2290
 		);
2173
-	}
2174
-	elseif (!$newTopic)
2175
-		$smcFunc['db_query']('', '
2291
+	} elseif (!$newTopic) {
2292
+			$smcFunc['db_query']('', '
2176 2293
 			DELETE FROM {db_prefix}log_notify
2177 2294
 			WHERE id_member = {int:current_member}
2178 2295
 				AND id_topic = {int:current_topic}',
@@ -2181,16 +2298,20 @@  discard block
 block discarded – undo
2181 2298
 				'current_topic' => $topic,
2182 2299
 			)
2183 2300
 		);
2301
+	}
2184 2302
 
2185 2303
 	// Log an act of moderation - modifying.
2186
-	if (!empty($moderationAction))
2187
-		logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2304
+	if (!empty($moderationAction)) {
2305
+			logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2306
+	}
2188 2307
 
2189
-	if (isset($_POST['lock']) && $_POST['lock'] != 2)
2190
-		logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2308
+	if (isset($_POST['lock']) && $_POST['lock'] != 2) {
2309
+			logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2310
+	}
2191 2311
 
2192
-	if (isset($_POST['sticky']))
2193
-		logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2312
+	if (isset($_POST['sticky'])) {
2313
+			logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2314
+	}
2194 2315
 
2195 2316
 	// Returning to the topic?
2196 2317
 	if (!empty($_REQUEST['goback']))
@@ -2209,26 +2330,31 @@  discard block
 block discarded – undo
2209 2330
 		);
2210 2331
 	}
2211 2332
 
2212
-	if ($board_info['num_topics'] == 0)
2213
-		cache_put_data('board-' . $board, null, 120);
2333
+	if ($board_info['num_topics'] == 0) {
2334
+			cache_put_data('board-' . $board, null, 120);
2335
+	}
2214 2336
 
2215 2337
 	call_integration_hook('integrate_post2_end');
2216 2338
 
2217
-	if (!empty($_POST['announce_topic']))
2218
-		redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2339
+	if (!empty($_POST['announce_topic'])) {
2340
+			redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2341
+	}
2219 2342
 
2220
-	if (!empty($_POST['move']) && allowedTo('move_any'))
2221
-		redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2343
+	if (!empty($_POST['move']) && allowedTo('move_any')) {
2344
+			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2345
+	}
2222 2346
 
2223 2347
 	// Return to post if the mod is on.
2224
-	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
2225
-		redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2226
-	elseif (!empty($_REQUEST['goback']))
2227
-		redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2348
+	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) {
2349
+			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2350
+	} elseif (!empty($_REQUEST['goback'])) {
2351
+			redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2352
+	}
2228 2353
 	// Dut-dut-duh-duh-DUH-duh-dut-duh-duh!  *dances to the Final Fantasy Fanfare...*
2229
-	else
2230
-		redirectexit('board=' . $board . '.0');
2231
-}
2354
+	else {
2355
+			redirectexit('board=' . $board . '.0');
2356
+	}
2357
+	}
2232 2358
 
2233 2359
 /**
2234 2360
  * Handle the announce topic function (action=announce).
@@ -2246,8 +2372,9 @@  discard block
 block discarded – undo
2246 2372
 
2247 2373
 	validateSession();
2248 2374
 
2249
-	if (empty($topic))
2250
-		fatal_lang_error('topic_gone', false);
2375
+	if (empty($topic)) {
2376
+			fatal_lang_error('topic_gone', false);
2377
+	}
2251 2378
 
2252 2379
 	loadLanguage('Post');
2253 2380
 	loadTemplate('Post');
@@ -2274,8 +2401,9 @@  discard block
 block discarded – undo
2274 2401
 	global $txt, $context, $topic, $board, $board_info, $smcFunc;
2275 2402
 
2276 2403
 	$groups = array_merge($board_info['groups'], array(1));
2277
-	foreach ($groups as $id => $group)
2278
-		$groups[$id] = (int) $group;
2404
+	foreach ($groups as $id => $group) {
2405
+			$groups[$id] = (int) $group;
2406
+	}
2279 2407
 
2280 2408
 	$context['groups'] = array();
2281 2409
 	if (in_array(0, $groups))
@@ -2318,8 +2446,9 @@  discard block
 block discarded – undo
2318 2446
 			'group_list' => $groups,
2319 2447
 		)
2320 2448
 	);
2321
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2322
-		$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2449
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2450
+			$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2451
+	}
2323 2452
 	$smcFunc['db_free_result']($request);
2324 2453
 
2325 2454
 	// Get the subject of the topic we're about to announce.
@@ -2361,16 +2490,19 @@  discard block
 block discarded – undo
2361 2490
 	$context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
2362 2491
 	$groups = array_merge($board_info['groups'], array(1));
2363 2492
 
2364
-	if (isset($_POST['membergroups']))
2365
-		$_POST['who'] = explode(',', $_POST['membergroups']);
2493
+	if (isset($_POST['membergroups'])) {
2494
+			$_POST['who'] = explode(',', $_POST['membergroups']);
2495
+	}
2366 2496
 
2367 2497
 	// Check whether at least one membergroup was selected.
2368
-	if (empty($_POST['who']))
2369
-		fatal_lang_error('no_membergroup_selected');
2498
+	if (empty($_POST['who'])) {
2499
+			fatal_lang_error('no_membergroup_selected');
2500
+	}
2370 2501
 
2371 2502
 	// Make sure all membergroups are integers and can access the board of the announcement.
2372
-	foreach ($_POST['who'] as $id => $mg)
2373
-		$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2503
+	foreach ($_POST['who'] as $id => $mg) {
2504
+			$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2505
+	}
2374 2506
 
2375 2507
 	// Get the topic subject and censor it.
2376 2508
 	$request = $smcFunc['db_query']('', '
@@ -2416,12 +2548,13 @@  discard block
 block discarded – undo
2416 2548
 	if ($smcFunc['db_num_rows']($request) == 0)
2417 2549
 	{
2418 2550
 		logAction('announce_topic', array('topic' => $topic), 'user');
2419
-		if (!empty($_REQUEST['move']) && allowedTo('move_any'))
2420
-			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2421
-		elseif (!empty($_REQUEST['goback']))
2422
-			redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2423
-		else
2424
-			redirectexit('board=' . $board . '.0');
2551
+		if (!empty($_REQUEST['move']) && allowedTo('move_any')) {
2552
+					redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2553
+		} elseif (!empty($_REQUEST['goback'])) {
2554
+					redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2555
+		} else {
2556
+					redirectexit('board=' . $board . '.0');
2557
+		}
2425 2558
 	}
2426 2559
 
2427 2560
 	$announcements = array();
@@ -2440,8 +2573,9 @@  discard block
 block discarded – undo
2440 2573
 	foreach ($rows as $row)
2441 2574
 	{
2442 2575
 		// Force them to have it?
2443
-		if (empty($prefs[$row['id_member']]['announcements']))
2444
-			continue;
2576
+		if (empty($prefs[$row['id_member']]['announcements'])) {
2577
+					continue;
2578
+		}
2445 2579
 
2446 2580
 		$cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
2447 2581
 
@@ -2469,8 +2603,9 @@  discard block
 block discarded – undo
2469 2603
 	}
2470 2604
 
2471 2605
 	// For each language send a different mail - low priority...
2472
-	foreach ($announcements as $lang => $mail)
2473
-		sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2606
+	foreach ($announcements as $lang => $mail) {
2607
+			sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2608
+	}
2474 2609
 
2475 2610
 	$context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
2476 2611
 
@@ -2480,9 +2615,10 @@  discard block
 block discarded – undo
2480 2615
 	$context['sub_template'] = 'announcement_send';
2481 2616
 
2482 2617
 	// Go back to the correct language for the user ;).
2483
-	if (!empty($modSettings['userLanguage']))
2484
-		loadLanguage('Post');
2485
-}
2618
+	if (!empty($modSettings['userLanguage'])) {
2619
+			loadLanguage('Post');
2620
+	}
2621
+	}
2486 2622
 
2487 2623
 /**
2488 2624
  * Get the topic for display purposes.
@@ -2495,12 +2631,13 @@  discard block
 block discarded – undo
2495 2631
 {
2496 2632
 	global $topic, $modSettings, $context, $smcFunc, $counter, $options;
2497 2633
 
2498
-	if (isset($_REQUEST['xml']))
2499
-		$limit = '
2634
+	if (isset($_REQUEST['xml'])) {
2635
+			$limit = '
2500 2636
 		LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
2501
-	else
2502
-		$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2637
+	} else {
2638
+			$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2503 2639
 		LIMIT ' . (int) $modSettings['topicSummaryPosts'];
2640
+	}
2504 2641
 
2505 2642
 	// If you're modifying, get only those posts before the current one. (otherwise get all.)
2506 2643
 	$request = $smcFunc['db_query']('', '
@@ -2538,8 +2675,9 @@  discard block
 block discarded – undo
2538 2675
 			'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
2539 2676
 		);
2540 2677
 
2541
-		if (!empty($context['new_replies']))
2542
-			$context['new_replies']--;
2678
+		if (!empty($context['new_replies'])) {
2679
+					$context['new_replies']--;
2680
+		}
2543 2681
 	}
2544 2682
 	$smcFunc['db_free_result']($request);
2545 2683
 }
@@ -2556,8 +2694,9 @@  discard block
 block discarded – undo
2556 2694
 	global $sourcedir, $smcFunc;
2557 2695
 
2558 2696
 	loadLanguage('Post');
2559
-	if (!isset($_REQUEST['xml']))
2560
-		loadTemplate('Post');
2697
+	if (!isset($_REQUEST['xml'])) {
2698
+			loadTemplate('Post');
2699
+	}
2561 2700
 
2562 2701
 	include_once($sourcedir . '/Subs-Post.php');
2563 2702
 
@@ -2588,8 +2727,9 @@  discard block
 block discarded – undo
2588 2727
 	$smcFunc['db_free_result']($request);
2589 2728
 
2590 2729
 	$context['sub_template'] = 'quotefast';
2591
-	if (!empty($row))
2592
-		$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2730
+	if (!empty($row)) {
2731
+			$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2732
+	}
2593 2733
 
2594 2734
 	if (!empty($can_view_post))
2595 2735
 	{
@@ -2622,8 +2762,9 @@  discard block
 block discarded – undo
2622 2762
 		}
2623 2763
 
2624 2764
 		// Remove any nested quotes.
2625
-		if (!empty($modSettings['removeNestedQuotes']))
2626
-			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2765
+		if (!empty($modSettings['removeNestedQuotes'])) {
2766
+					$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2767
+		}
2627 2768
 
2628 2769
 		$lb = "\n";
2629 2770
 
@@ -2649,14 +2790,14 @@  discard block
 block discarded – undo
2649 2790
 				'time' => '',
2650 2791
 			),
2651 2792
 		);
2652
-	}
2653
-	else
2654
-		$context['quote'] = array(
2793
+	} else {
2794
+			$context['quote'] = array(
2655 2795
 			'xml' => '',
2656 2796
 			'mozilla' => '',
2657 2797
 			'text' => '',
2658 2798
 		);
2659
-}
2799
+	}
2800
+	}
2660 2801
 
2661 2802
 /**
2662 2803
  * Used to edit the body or subject of a message inline
@@ -2668,8 +2809,9 @@  discard block
 block discarded – undo
2668 2809
 	global $user_info, $context, $smcFunc, $language, $board_info;
2669 2810
 
2670 2811
 	// We have to have a topic!
2671
-	if (empty($topic))
2672
-		obExit(false);
2812
+	if (empty($topic)) {
2813
+			obExit(false);
2814
+	}
2673 2815
 
2674 2816
 	checkSession('get');
2675 2817
 	require_once($sourcedir . '/Subs-Post.php');
@@ -2695,31 +2837,35 @@  discard block
 block discarded – undo
2695 2837
 			'guest_id' => 0,
2696 2838
 		)
2697 2839
 	);
2698
-	if ($smcFunc['db_num_rows']($request) == 0)
2699
-		fatal_lang_error('no_board', false);
2840
+	if ($smcFunc['db_num_rows']($request) == 0) {
2841
+			fatal_lang_error('no_board', false);
2842
+	}
2700 2843
 	$row = $smcFunc['db_fetch_assoc']($request);
2701 2844
 	$smcFunc['db_free_result']($request);
2702 2845
 
2703 2846
 	// Change either body or subject requires permissions to modify messages.
2704 2847
 	if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
2705 2848
 	{
2706
-		if (!empty($row['locked']))
2707
-			isAllowedTo('moderate_board');
2849
+		if (!empty($row['locked'])) {
2850
+					isAllowedTo('moderate_board');
2851
+		}
2708 2852
 
2709 2853
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
2710 2854
 		{
2711
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
2712
-				fatal_lang_error('modify_post_time_passed', false);
2713
-			elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
2714
-				isAllowedTo('modify_replies');
2715
-			else
2716
-				isAllowedTo('modify_own');
2855
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
2856
+							fatal_lang_error('modify_post_time_passed', false);
2857
+			} elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
2858
+							isAllowedTo('modify_replies');
2859
+			} else {
2860
+							isAllowedTo('modify_own');
2861
+			}
2717 2862
 		}
2718 2863
 		// Otherwise, they're locked out; someone who can modify the replies is needed.
2719
-		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
2720
-			isAllowedTo('modify_replies');
2721
-		else
2722
-			isAllowedTo('modify_any');
2864
+		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
2865
+					isAllowedTo('modify_replies');
2866
+		} else {
2867
+					isAllowedTo('modify_any');
2868
+		}
2723 2869
 
2724 2870
 		// Only log this action if it wasn't your message.
2725 2871
 		$moderationAction = $row['id_member'] != $user_info['id'];
@@ -2731,10 +2877,10 @@  discard block
 block discarded – undo
2731 2877
 		$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
2732 2878
 
2733 2879
 		// Maximum number of characters.
2734
-		if ($smcFunc['strlen']($_POST['subject']) > 100)
2735
-			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2736
-	}
2737
-	elseif (isset($_POST['subject']))
2880
+		if ($smcFunc['strlen']($_POST['subject']) > 100) {
2881
+					$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2882
+		}
2883
+	} elseif (isset($_POST['subject']))
2738 2884
 	{
2739 2885
 		$post_errors[] = 'no_subject';
2740 2886
 		unset($_POST['subject']);
@@ -2746,13 +2892,11 @@  discard block
 block discarded – undo
2746 2892
 		{
2747 2893
 			$post_errors[] = 'no_message';
2748 2894
 			unset($_POST['message']);
2749
-		}
2750
-		elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2895
+		} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2751 2896
 		{
2752 2897
 			$post_errors[] = 'long_message';
2753 2898
 			unset($_POST['message']);
2754
-		}
2755
-		else
2899
+		} else
2756 2900
 		{
2757 2901
 			$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
2758 2902
 
@@ -2768,31 +2912,34 @@  discard block
 block discarded – undo
2768 2912
 
2769 2913
 	if (isset($_POST['lock']))
2770 2914
 	{
2771
-		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
2772
-			unset($_POST['lock']);
2773
-		elseif (!allowedTo('lock_any'))
2915
+		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) {
2916
+					unset($_POST['lock']);
2917
+		} elseif (!allowedTo('lock_any'))
2774 2918
 		{
2775
-			if ($row['locked'] == 1)
2776
-				unset($_POST['lock']);
2777
-			else
2778
-				$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
2919
+			if ($row['locked'] == 1) {
2920
+							unset($_POST['lock']);
2921
+			} else {
2922
+							$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
2923
+			}
2924
+		} elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
2925
+					unset($_POST['lock']);
2926
+		} else {
2927
+					$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2779 2928
 		}
2780
-		elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
2781
-			unset($_POST['lock']);
2782
-		else
2783
-			$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2784 2929
 	}
2785 2930
 
2786
-	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
2787
-		unset($_POST['sticky']);
2931
+	if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
2932
+			unset($_POST['sticky']);
2933
+	}
2788 2934
 
2789 2935
 	if (isset($_POST['modify_reason']))
2790 2936
 	{
2791 2937
 		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
2792 2938
 
2793 2939
 		// Maximum number of characters.
2794
-		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
2795
-			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2940
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
2941
+					$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2942
+		}
2796 2943
 	}
2797 2944
 
2798 2945
 	if (empty($post_errors))
@@ -2829,8 +2976,9 @@  discard block
 block discarded – undo
2829 2976
 			}
2830 2977
 		}
2831 2978
 		// If nothing was changed there's no need to add an entry to the moderation log.
2832
-		else
2833
-			$moderationAction = false;
2979
+		else {
2980
+					$moderationAction = false;
2981
+		}
2834 2982
 
2835 2983
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2836 2984
 
@@ -2848,9 +2996,9 @@  discard block
 block discarded – undo
2848 2996
 			// Get the proper (default language) response prefix first.
2849 2997
 			if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
2850 2998
 			{
2851
-				if ($language === $user_info['language'])
2852
-					$context['response_prefix'] = $txt['response_prefix'];
2853
-				else
2999
+				if ($language === $user_info['language']) {
3000
+									$context['response_prefix'] = $txt['response_prefix'];
3001
+				} else
2854 3002
 				{
2855 3003
 					loadLanguage('index', $language, false);
2856 3004
 					$context['response_prefix'] = $txt['response_prefix'];
@@ -2872,8 +3020,9 @@  discard block
 block discarded – undo
2872 3020
 			);
2873 3021
 		}
2874 3022
 
2875
-		if (!empty($moderationAction))
2876
-			logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3023
+		if (!empty($moderationAction)) {
3024
+					logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3025
+		}
2877 3026
 	}
2878 3027
 
2879 3028
 	if (isset($_REQUEST['xml']))
@@ -2914,8 +3063,7 @@  discard block
 block discarded – undo
2914 3063
 			);
2915 3064
 
2916 3065
 			censorText($context['message']['subject']);
2917
-		}
2918
-		else
3066
+		} else
2919 3067
 		{
2920 3068
 			$context['message'] = array(
2921 3069
 				'id' => $row['id_msg'],
@@ -2927,15 +3075,16 @@  discard block
 block discarded – undo
2927 3075
 			loadLanguage('Errors');
2928 3076
 			foreach ($post_errors as $post_error)
2929 3077
 			{
2930
-				if ($post_error == 'long_message')
2931
-					$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
2932
-				else
2933
-					$context['message']['errors'][] = $txt['error_' . $post_error];
3078
+				if ($post_error == 'long_message') {
3079
+									$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3080
+				} else {
3081
+									$context['message']['errors'][] = $txt['error_' . $post_error];
3082
+				}
2934 3083
 			}
2935 3084
 		}
3085
+	} else {
3086
+			obExit(false);
3087
+	}
2936 3088
 	}
2937
-	else
2938
-		obExit(false);
2939
-}
2940 3089
 
2941 3090
 ?>
2942 3091
\ No newline at end of file
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   +105 added lines, -83 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Show the calendar.
@@ -47,12 +48,14 @@  discard block
 block discarded – undo
47 48
 		'post' => 'CalendarPost',
48 49
 	);
49 50
 
50
-	if (isset($_GET['sa']) && isset($subActions[$_GET['sa']]))
51
-		return call_helper($subActions[$_GET['sa']]);
51
+	if (isset($_GET['sa']) && isset($subActions[$_GET['sa']])) {
52
+			return call_helper($subActions[$_GET['sa']]);
53
+	}
52 54
 
53 55
 	// You can't do anything if the calendar is off.
54
-	if (empty($modSettings['cal_enabled']))
55
-		fatal_lang_error('calendar_off', false);
56
+	if (empty($modSettings['cal_enabled'])) {
57
+			fatal_lang_error('calendar_off', false);
58
+	}
56 59
 
57 60
 	// This is gonna be needed...
58 61
 	loadTemplate('Calendar');
@@ -97,8 +100,9 @@  discard block
 block discarded – undo
97 100
 	$context['view_week'] = isset($_GET['viewweek']);
98 101
 
99 102
 	// Don't let search engines index weekly calendar pages.
100
-	if ($context['view_week'])
101
-		$context['robot_no_index'] = true;
103
+	if ($context['view_week']) {
104
+			$context['robot_no_index'] = true;
105
+	}
102 106
 
103 107
 	// Get the current day of month...
104 108
 	require_once($sourcedir . '/Subs-Calendar.php');
@@ -112,17 +116,20 @@  discard block
 block discarded – undo
112 116
 	);
113 117
 
114 118
 	// Make sure the year and month are in valid ranges.
115
-	if ($curPage['month'] < 1 || $curPage['month'] > 12)
116
-		fatal_lang_error('invalid_month', false);
117
-	if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear'])
118
-		fatal_lang_error('invalid_year', false);
119
+	if ($curPage['month'] < 1 || $curPage['month'] > 12) {
120
+			fatal_lang_error('invalid_month', false);
121
+	}
122
+	if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear']) {
123
+			fatal_lang_error('invalid_year', false);
124
+	}
119 125
 	// If we have a day clean that too.
120 126
 	if ($context['view_week'])
121 127
 	{
122 128
 		// Note $isValid is -1 < PHP 5.1
123 129
 		$isValid = mktime(0, 0, 0, $curPage['month'], $curPage['day'], $curPage['year']);
124
-		if ($curPage['day'] > 31 || !$isValid || $isValid == -1)
125
-			fatal_lang_error('invalid_day', false);
130
+		if ($curPage['day'] > 31 || !$isValid || $isValid == -1) {
131
+					fatal_lang_error('invalid_day', false);
132
+		}
126 133
 	}
127 134
 
128 135
 	// Load all the context information needed to show the calendar grid.
@@ -144,21 +151,24 @@  discard block
 block discarded – undo
144 151
 	);
145 152
 
146 153
 	// Load up the main view.
147
-	if ($context['view_week'])
148
-		$context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
149
-	else
150
-		$context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
154
+	if ($context['view_week']) {
155
+			$context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
156
+	} else {
157
+			$context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
158
+	}
151 159
 
152 160
 	// Load up the previous and next months.
153 161
 	$context['calendar_grid_current'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
154 162
 
155 163
 	// Only show previous month if it isn't pre-January of the min-year
156
-	if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1)
157
-		$context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
164
+	if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1) {
165
+			$context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
166
+	}
158 167
 
159 168
 	// Only show next month if it isn't post-December of the max-year
160
-	if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12)
161
-		$context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
169
+	if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12) {
170
+			$context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
171
+	}
162 172
 
163 173
 	// Basic template stuff.
164 174
 	$context['allow_calendar_event'] = allowedTo('calendar_post');
@@ -191,17 +201,19 @@  discard block
 block discarded – undo
191 201
 		'name' => $txt['months'][$context['current_month']] . ' ' . $context['current_year']
192 202
 	);
193 203
 	// If applicable, add the current week to the linktree.
194
-	if ($context['view_week'])
195
-		$context['linktree'][] = array(
204
+	if ($context['view_week']) {
205
+			$context['linktree'][] = array(
196 206
 			'url' => $scripturl . '?action=calendar;viewweek;year=' . $context['current_year'] . ';month=' . $context['current_month'] . ';day=' . $context['current_day'],
197 207
 			'name' => $context['calendar_grid_main']['week_title'],
198 208
 		);
209
+	}
199 210
 
200 211
 	// Build the calendar button array.
201 212
 	$context['calendar_buttons'] = array();
202 213
 
203
-	if ($context['can_post'])
204
-		$context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']);
214
+	if ($context['can_post']) {
215
+			$context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']);
216
+	}
205 217
 
206 218
 	// Allow mods to add additional buttons here
207 219
 	call_integration_hook('integrate_calendar_buttons');
@@ -230,14 +242,16 @@  discard block
 block discarded – undo
230 242
 	require_once($sourcedir . '/Subs.php');
231 243
 
232 244
 	// Cast this for safety...
233
-	if (isset($_REQUEST['eventid']))
234
-		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
245
+	if (isset($_REQUEST['eventid'])) {
246
+			$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
247
+	}
235 248
 
236 249
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
237
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
238
-		$time_string = '%k:%M';
239
-	else
240
-		$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
250
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
251
+			$time_string = '%k:%M';
252
+	} else {
253
+			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
254
+	}
241 255
 
242 256
 	$js_time_string = str_replace(
243 257
 		array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -251,12 +265,14 @@  discard block
 block discarded – undo
251 265
 		checkSession();
252 266
 
253 267
 		// Validate the post...
254
-		if (!isset($_POST['link_to_board']))
255
-			validateEventPost();
268
+		if (!isset($_POST['link_to_board'])) {
269
+					validateEventPost();
270
+		}
256 271
 
257 272
 		// If you're not allowed to edit any events, you have to be the poster.
258
-		if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any'))
259
-			isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
273
+		if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any')) {
274
+					isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
275
+		}
260 276
 
261 277
 		// New - and directing?
262 278
 		if (isset($_POST['link_to_board']) || empty($modSettings['cal_allow_unlinked']))
@@ -279,8 +295,9 @@  discard block
 block discarded – undo
279 295
 		}
280 296
 
281 297
 		// Deleting...
282
-		elseif (isset($_REQUEST['deleteevent']))
283
-			removeEvent($_REQUEST['eventid']);
298
+		elseif (isset($_REQUEST['deleteevent'])) {
299
+					removeEvent($_REQUEST['eventid']);
300
+		}
284 301
 
285 302
 		// ... or just update it?
286 303
 		else
@@ -302,14 +319,12 @@  discard block
 block discarded – undo
302 319
 			$d = date_parse($_POST['start_date']);
303 320
 			$year = $d['year'];
304 321
 			$month = $d['month'];
305
-		}
306
-		elseif (isset($_POST['start_datetime']))
322
+		} elseif (isset($_POST['start_datetime']))
307 323
 		{
308 324
 			$d = date_parse($_POST['start_datetime']);
309 325
 			$year = $d['year'];
310 326
 			$month = $d['month'];
311
-		}
312
-		else
327
+		} else
313 328
 		{
314 329
 			$today = getdate();
315 330
 			$year = isset($_POST['year']) ? $_POST['year'] : $today['year'];
@@ -342,13 +357,13 @@  discard block
 block discarded – undo
342 357
 		$context['event'] = array_merge($context['event'], $eventDatetimes);
343 358
 
344 359
 		$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']));
345
-	}
346
-	else
360
+	} else
347 361
 	{
348 362
 		$context['event'] = getEventProperties($_REQUEST['eventid']);
349 363
 
350
-		if ($context['event'] === false)
351
-			fatal_lang_error('no_access', false);
364
+		if ($context['event'] === false) {
365
+					fatal_lang_error('no_access', false);
366
+		}
352 367
 
353 368
 		// If it has a board, then they should be editing it within the topic.
354 369
 		if (!empty($context['event']['topic']['id']) && !empty($context['event']['topic']['first_msg']))
@@ -359,10 +374,11 @@  discard block
 block discarded – undo
359 374
 		}
360 375
 
361 376
 		// Make sure the user is allowed to edit this event.
362
-		if ($context['event']['member'] != $user_info['id'])
363
-			isAllowedTo('calendar_edit_any');
364
-		elseif (!allowedTo('calendar_edit_any'))
365
-			isAllowedTo('calendar_edit_own');
377
+		if ($context['event']['member'] != $user_info['id']) {
378
+					isAllowedTo('calendar_edit_any');
379
+		} elseif (!allowedTo('calendar_edit_any')) {
380
+					isAllowedTo('calendar_edit_own');
381
+		}
366 382
 	}
367 383
 
368 384
 	// An all day event? Set up some nice defaults in case the user wants to change that
@@ -396,8 +412,7 @@  discard block
 block discarded – undo
396 412
 	{
397 413
 		// You can post new events but can't link them to anything...
398 414
 		$context['event']['categories'] = array();
399
-	}
400
-	else
415
+	} else
401 416
 	{
402 417
 		// Load the list of boards and categories in the context.
403 418
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -484,12 +499,14 @@  discard block
 block discarded – undo
484 499
 	global $smcFunc, $sourcedir, $forum_version, $modSettings, $webmaster_email, $mbname;
485 500
 
486 501
 	// You can't export if the calendar export feature is off.
487
-	if (empty($modSettings['cal_export']))
488
-		fatal_lang_error('calendar_export_off', false);
502
+	if (empty($modSettings['cal_export'])) {
503
+			fatal_lang_error('calendar_export_off', false);
504
+	}
489 505
 
490 506
 	// Goes without saying that this is required.
491
-	if (!isset($_REQUEST['eventid']))
492
-		fatal_lang_error('no_access', false);
507
+	if (!isset($_REQUEST['eventid'])) {
508
+			fatal_lang_error('no_access', false);
509
+	}
493 510
 
494 511
 	// This is kinda wanted.
495 512
 	require_once($sourcedir . '/Subs-Calendar.php');
@@ -497,15 +514,17 @@  discard block
 block discarded – undo
497 514
 	// Load up the event in question and check it exists.
498 515
 	$event = getEventProperties($_REQUEST['eventid']);
499 516
 
500
-	if ($event === false)
501
-		fatal_lang_error('no_access', false);
517
+	if ($event === false) {
518
+			fatal_lang_error('no_access', false);
519
+	}
502 520
 
503 521
 	// Check the title isn't too long - iCal requires some formatting if so.
504 522
 	$title = str_split($event['title'], 30);
505 523
 	foreach ($title as $id => $line)
506 524
 	{
507
-		if ($id != 0)
508
-			$title[$id] = ' ' . $title[$id];
525
+		if ($id != 0) {
526
+					$title[$id] = ' ' . $title[$id];
527
+		}
509 528
 		$title[$id] .= "\n";
510 529
 	}
511 530
 
@@ -518,8 +537,7 @@  discard block
 block discarded – undo
518 537
 	{
519 538
 		$datestart = date_format($start_date, 'Ymd\THis');
520 539
 		$dateend = date_format($end_date, 'Ymd\THis');
521
-	}
522
-	else
540
+	} else
523 541
 	{
524 542
 		$datestart = date_format($start_date, 'Ymd');
525 543
 
@@ -540,15 +558,18 @@  discard block
 block discarded – undo
540 558
 	$filecontents .= 'DTSTART' . (!empty($event['start_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $datestart . "\n";
541 559
 
542 560
 	// event has a duration
543
-	if ($event['start_iso_gmdate'] != $event['end_iso_gmdate'])
544
-		$filecontents .= 'DTEND' . (!empty($event['end_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $dateend . "\n";
561
+	if ($event['start_iso_gmdate'] != $event['end_iso_gmdate']) {
562
+			$filecontents .= 'DTEND' . (!empty($event['end_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $dateend . "\n";
563
+	}
545 564
 
546 565
 	// event has changed? advance the sequence for this UID
547
-	if ($event['sequence'] > 0)
548
-		$filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
566
+	if ($event['sequence'] > 0) {
567
+			$filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
568
+	}
549 569
 
550
-	if (!empty($event['location']))
551
-		$filecontents .= 'LOCATION:' . str_replace(',', '\,', $event['location']) . "\n";
570
+	if (!empty($event['location'])) {
571
+			$filecontents .= 'LOCATION:' . str_replace(',', '\,', $event['location']) . "\n";
572
+	}
552 573
 
553 574
 	$filecontents .= 'SUMMARY:' . implode('', $title);
554 575
 	$filecontents .= 'UID:' . $event['eventid'] . '@' . str_replace(' ', '-', $mbname) . "\n";
@@ -557,23 +578,26 @@  discard block
 block discarded – undo
557 578
 
558 579
 	// Send some standard headers.
559 580
 	ob_end_clean();
560
-	if (!empty($modSettings['enableCompressedOutput']))
561
-		@ob_start('ob_gzhandler');
562
-	else
563
-		ob_start();
581
+	if (!empty($modSettings['enableCompressedOutput'])) {
582
+			@ob_start('ob_gzhandler');
583
+	} else {
584
+			ob_start();
585
+	}
564 586
 
565 587
 	// Send the file headers
566 588
 	header('Pragma: ');
567 589
 	header('Cache-Control: no-cache');
568
-	if (!isBrowser('gecko'))
569
-		header('Content-Transfer-Encoding: binary');
590
+	if (!isBrowser('gecko')) {
591
+			header('Content-Transfer-Encoding: binary');
592
+	}
570 593
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
571 594
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . 'GMT');
572 595
 	header('Accept-Ranges: bytes');
573 596
 	header('Connection: close');
574 597
 	header('Content-Disposition: attachment; filename="' . $event['title'] . '.ics"');
575
-	if (empty($modSettings['enableCompressedOutput']))
576
-		header('Content-Length: ' . $smcFunc['strlen']($filecontents));
598
+	if (empty($modSettings['enableCompressedOutput'])) {
599
+			header('Content-Length: ' . $smcFunc['strlen']($filecontents));
600
+	}
577 601
 
578 602
 	// This is a calendar item!
579 603
 	header('Content-Type: text/calendar');
@@ -612,20 +636,17 @@  discard block
 block discarded – undo
612 636
 		$context['sub_template'] = 'bcd';
613 637
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock;bcd', 'name' => 'BCD');
614 638
 		$context['clockicons'] = safe_unserialize(base64_decode('YTo2OntzOjI6ImgxIjthOjI6e2k6MDtpOjI7aToxO2k6MTt9czoyOiJoMiI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjI6Im0xIjthOjM6e2k6MDtpOjQ7aToxO2k6MjtpOjI7aToxO31zOjI6Im0yIjthOjQ6e2k6MDtpOjg7aToxO2k6NDtpOjI7aToyO2k6MztpOjE7fXM6MjoiczEiO2E6Mzp7aTowO2k6NDtpOjE7aToyO2k6MjtpOjE7fXM6MjoiczIiO2E6NDp7aTowO2k6ODtpOjE7aTo0O2k6MjtpOjI7aTozO2k6MTt9fQ=='));
615
-	}
616
-	elseif (!$omfg && !isset($_REQUEST['time']))
639
+	} elseif (!$omfg && !isset($_REQUEST['time']))
617 640
 	{
618 641
 		$context['sub_template'] = 'hms';
619 642
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock', 'name' => 'Binary');
620 643
 		$context['clockicons'] = safe_unserialize(base64_decode('YTozOntzOjE6ImgiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czoxOiJtIjthOjY6e2k6MDtpOjMyO2k6MTtpOjE2O2k6MjtpOjg7aTozO2k6NDtpOjQ7aToyO2k6NTtpOjE7fXM6MToicyI7YTo2OntpOjA7aTozMjtpOjE7aToxNjtpOjI7aTo4O2k6MztpOjQ7aTo0O2k6MjtpOjU7aToxO319'));
621
-	}
622
-	elseif ($omfg)
644
+	} elseif ($omfg)
623 645
 	{
624 646
 		$context['sub_template'] = 'omfg';
625 647
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock;omfg', 'name' => 'OMFG');
626 648
 		$context['clockicons'] = safe_unserialize(base64_decode('YTo2OntzOjQ6InllYXIiO2E6Nzp7aTowO2k6NjQ7aToxO2k6MzI7aToyO2k6MTY7aTozO2k6ODtpOjQ7aTo0O2k6NTtpOjI7aTo2O2k6MTt9czo1OiJtb250aCI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjM6ImRheSI7YTo1OntpOjA7aToxNjtpOjE7aTo4O2k6MjtpOjQ7aTozO2k6MjtpOjQ7aToxO31zOjQ6ImhvdXIiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czozOiJtaW4iO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9czozOiJzZWMiO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9fQ=='));
627
-	}
628
-	elseif (isset($_REQUEST['time']))
649
+	} elseif (isset($_REQUEST['time']))
629 650
 	{
630 651
 		$context['sub_template'] = 'thetime';
631 652
 		$time = getdate($_REQUEST['time'] == 'now' ? time() : (int) $_REQUEST['time']);
@@ -685,12 +706,13 @@  discard block
 block discarded – undo
685 706
 			),
686 707
 		);
687 708
 
688
-		foreach ($context['clockicons'] as $t => $vs)
689
-			foreach ($vs as $v => $dumb)
709
+		foreach ($context['clockicons'] as $t => $vs) {
710
+					foreach ($vs as $v => $dumb)
690 711
 			{
691 712
 				if ($$t >= $v)
692 713
 				{
693 714
 					$$t -= $v;
715
+		}
694 716
 					$context['clockicons'][$t][$v] = true;
695 717
 				}
696 718
 			}
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 1 patch
Braces   +230 added lines, -168 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc')
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc') {
38
+			$smcFunc += array(
38 39
 			'db_query' => 'smf_db_query',
39 40
 			'db_quote' => 'smf_db_quote',
40 41
 			'db_fetch_assoc' => 'mysql_fetch_assoc',
@@ -58,36 +59,42 @@  discard block
 block discarded – undo
58 59
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
59 60
 			'db_is_resource' => 'is_resource',
60 61
 		);
62
+	}
61 63
 
62
-	if (!empty($db_options['port']))
63
-		$db_server .= ':' . $db_options['port'];
64
+	if (!empty($db_options['port'])) {
65
+			$db_server .= ':' . $db_options['port'];
66
+	}
64 67
 	
65 68
 	$flags = 2; //#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
66 69
 
67
-	if (!empty($db_options['persist']))
68
-		$connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags);
69
-	else
70
-		$connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags);
70
+	if (!empty($db_options['persist'])) {
71
+			$connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags);
72
+	} else {
73
+			$connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags);
74
+	}
71 75
 
72 76
 	// Something's wrong, show an error if its fatal (which we assume it is)
73 77
 	if (!$connection)
74 78
 	{
75
-		if (!empty($db_options['non_fatal']))
76
-			return null;
77
-		else
78
-			display_db_error();
79
+		if (!empty($db_options['non_fatal'])) {
80
+					return null;
81
+		} else {
82
+					display_db_error();
83
+		}
79 84
 	}
80 85
 
81 86
 	// Select the database, unless told not to
82
-	if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal']))
83
-		display_db_error();
87
+	if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal'])) {
88
+			display_db_error();
89
+	}
84 90
 
85 91
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
86
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
87
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
92
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
93
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
88 94
 		array(),
89 95
 		false
90 96
 	);
97
+	}
91 98
 
92 99
 	return $connection;
93 100
 }
@@ -134,37 +141,46 @@  discard block
 block discarded – undo
134 141
 	list ($values, $connection) = $db_callback;
135 142
 
136 143
 	// Connection gone???  This should *never* happen at this point, yet it does :'(
137
-	if (!is_resource($connection))
138
-		display_db_error();
144
+	if (!is_resource($connection)) {
145
+			display_db_error();
146
+	}
139 147
 
140
-	if ($matches[1] === 'db_prefix')
141
-		return $db_prefix;
148
+	if ($matches[1] === 'db_prefix') {
149
+			return $db_prefix;
150
+	}
142 151
 
143
-	if ($matches[1] === 'query_see_board')
144
-		return $user_info['query_see_board'];
152
+	if ($matches[1] === 'query_see_board') {
153
+			return $user_info['query_see_board'];
154
+	}
145 155
 
146
-	if ($matches[1] === 'query_wanna_see_board')
147
-		return $user_info['query_wanna_see_board'];
156
+	if ($matches[1] === 'query_wanna_see_board') {
157
+			return $user_info['query_wanna_see_board'];
158
+	}
148 159
 
149
-	if ($matches[1] === 'empty')
150
-		return '\'\'';
160
+	if ($matches[1] === 'empty') {
161
+			return '\'\'';
162
+	}
151 163
 
152
-	if (!isset($matches[2]))
153
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
164
+	if (!isset($matches[2])) {
165
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
166
+	}
154 167
 
155
-	if ($matches[1] === 'literal')
156
-		return '\'' . mysql_real_escape_string($matches[2], $connection) . '\'';
168
+	if ($matches[1] === 'literal') {
169
+			return '\'' . mysql_real_escape_string($matches[2], $connection) . '\'';
170
+	}
157 171
 
158
-	if (!isset($values[$matches[2]]))
159
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
172
+	if (!isset($values[$matches[2]])) {
173
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
174
+	}
160 175
 
161 176
 	$replacement = $values[$matches[2]];
162 177
 
163 178
 	switch ($matches[1])
164 179
 	{
165 180
 		case 'int':
166
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
167
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
182
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183
+			}
168 184
 			return (string) (int) $replacement;
169 185
 		break;
170 186
 
@@ -176,56 +192,63 @@  discard block
 block discarded – undo
176 192
 		case 'array_int':
177 193
 			if (is_array($replacement))
178 194
 			{
179
-				if (empty($replacement))
180
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
195
+				if (empty($replacement)) {
196
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
197
+				}
181 198
 
182 199
 				foreach ($replacement as $key => $value)
183 200
 				{
184
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
185
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
201
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
202
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
203
+					}
186 204
 
187 205
 					$replacement[$key] = (string) (int) $value;
188 206
 				}
189 207
 
190 208
 				return implode(', ', $replacement);
209
+			} else {
210
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
191 211
 			}
192
-			else
193
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
194 212
 
195 213
 		break;
196 214
 
197 215
 		case 'array_string':
198 216
 			if (is_array($replacement))
199 217
 			{
200
-				if (empty($replacement))
201
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218
+				if (empty($replacement)) {
219
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220
+				}
202 221
 
203
-				foreach ($replacement as $key => $value)
204
-					$replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection));
222
+				foreach ($replacement as $key => $value) {
223
+									$replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection));
224
+				}
205 225
 
206 226
 				return implode(', ', $replacement);
227
+			} else {
228
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
207 229
 			}
208
-			else
209
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
210 230
 		break;
211 231
 
212 232
 		case 'date':
213
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
214
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
215
-			else
216
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
234
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
235
+			} else {
236
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237
+			}
217 238
 		break;
218 239
 
219 240
 		case 'time':
220
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
221
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
222
-			else
223
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
241
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
242
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
243
+			} else {
244
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
245
+			}
224 246
 		break;
225 247
 
226 248
 		case 'float':
227
-			if (!is_numeric($replacement))
228
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249
+			if (!is_numeric($replacement)) {
250
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
251
+			}
229 252
 			return (string) (float) $replacement;
230 253
 		break;
231 254
 
@@ -239,32 +262,37 @@  discard block
 block discarded – undo
239 262
 		break;
240 263
 
241 264
 		case 'inet':
242
-			if ($replacement == 'null' || $replacement == '')
243
-				return 'null';
244
-			if (!isValidIP($replacement))
245
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265
+			if ($replacement == 'null' || $replacement == '') {
266
+							return 'null';
267
+			}
268
+			if (!isValidIP($replacement)) {
269
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+			}
246 271
 			//we don't use the native support of mysql > 5.6.2
247 272
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
248 273
 
249 274
 		case 'array_inet':
250 275
 			if (is_array($replacement))
251 276
 			{
252
-				if (empty($replacement))
253
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
277
+				if (empty($replacement)) {
278
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
279
+				}
254 280
 
255 281
 				foreach ($replacement as $key => $value)
256 282
 				{
257
-					if ($replacement == 'null' || $replacement == '')
258
-						$replacement[$key] = 'null';
259
-					if (!isValidIP($value))
260
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
283
+					if ($replacement == 'null' || $replacement == '') {
284
+											$replacement[$key] = 'null';
285
+					}
286
+					if (!isValidIP($value)) {
287
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
288
+					}
261 289
 					$replacement[$key] =  sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
262 290
 				}
263 291
 
264 292
 				return implode(', ', $replacement);
293
+			} else {
294
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265 295
 			}
266
-			else
267
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
268 296
 		break;
269 297
 
270 298
 		default:
@@ -335,18 +363,20 @@  discard block
 block discarded – undo
335 363
 	// One more query....
336 364
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
337 365
 
338
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
339
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
366
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
367
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
368
+	}
340 369
 
341 370
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
342 371
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
343 372
 	{
344 373
 		// Add before LIMIT
345
-		if ($pos = strpos($db_string, 'LIMIT '))
346
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
347
-		else
348
-			// Append it.
374
+		if ($pos = strpos($db_string, 'LIMIT ')) {
375
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
376
+		} else {
377
+					// Append it.
349 378
 			$db_string .= "\n\t\t\tORDER BY null";
379
+		}
350 380
 	}
351 381
 
352 382
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -368,8 +398,9 @@  discard block
 block discarded – undo
368 398
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
369 399
 
370 400
 		// Initialize $db_cache if not already initialized.
371
-		if (!isset($db_cache))
372
-			$db_cache = array();
401
+		if (!isset($db_cache)) {
402
+					$db_cache = array();
403
+		}
373 404
 
374 405
 		if (!empty($_SESSION['debug_redirect']))
375 406
 		{
@@ -395,17 +426,18 @@  discard block
 block discarded – undo
395 426
 		while (true)
396 427
 		{
397 428
 			$pos = strpos($db_string, '\'', $pos + 1);
398
-			if ($pos === false)
399
-				break;
429
+			if ($pos === false) {
430
+							break;
431
+			}
400 432
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
401 433
 
402 434
 			while (true)
403 435
 			{
404 436
 				$pos1 = strpos($db_string, '\'', $pos + 1);
405 437
 				$pos2 = strpos($db_string, '\\', $pos + 1);
406
-				if ($pos1 === false)
407
-					break;
408
-				elseif ($pos2 === false || $pos2 > $pos1)
438
+				if ($pos1 === false) {
439
+									break;
440
+				} elseif ($pos2 === false || $pos2 > $pos1)
409 441
 				{
410 442
 					$pos = $pos1;
411 443
 					break;
@@ -421,29 +453,35 @@  discard block
 block discarded – undo
421 453
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
422 454
 
423 455
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
424
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
425
-			$fail = true;
456
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
457
+					$fail = true;
458
+		}
426 459
 		// Trying to change passwords, slow us down, or something?
427
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
428
-			$fail = true;
429
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
430
-			$fail = true;
460
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
461
+					$fail = true;
462
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
463
+					$fail = true;
464
+		}
431 465
 
432
-		if (!empty($fail) && function_exists('log_error'))
433
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
466
+		if (!empty($fail) && function_exists('log_error')) {
467
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
468
+		}
434 469
 	}
435 470
 
436
-	if (empty($db_unbuffered))
437
-		$ret = @mysql_query($db_string, $connection);
438
-	else
439
-		$ret = @mysql_unbuffered_query($db_string, $connection);
471
+	if (empty($db_unbuffered)) {
472
+			$ret = @mysql_query($db_string, $connection);
473
+	} else {
474
+			$ret = @mysql_unbuffered_query($db_string, $connection);
475
+	}
440 476
 
441
-	if ($ret === false && empty($db_values['db_error_skip']))
442
-		$ret = smf_db_error($db_string, $connection);
477
+	if ($ret === false && empty($db_values['db_error_skip'])) {
478
+			$ret = smf_db_error($db_string, $connection);
479
+	}
443 480
 
444 481
 	// Debugging.
445
-	if (isset($db_show_debug) && $db_show_debug === true)
446
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
482
+	if (isset($db_show_debug) && $db_show_debug === true) {
483
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
484
+	}
447 485
 
448 486
 	return $ret;
449 487
 }
@@ -492,12 +530,13 @@  discard block
 block discarded – undo
492 530
 	// Decide which connection to use
493 531
 	$connection = $connection === null ? $db_connection : $connection;
494 532
 
495
-	if ($type == 'begin')
496
-		return @mysql_query('BEGIN', $connection);
497
-	elseif ($type == 'rollback')
498
-		return @mysql_query('ROLLBACK', $connection);
499
-	elseif ($type == 'commit')
500
-		return @mysql_query('COMMIT', $connection);
533
+	if ($type == 'begin') {
534
+			return @mysql_query('BEGIN', $connection);
535
+	} elseif ($type == 'rollback') {
536
+			return @mysql_query('ROLLBACK', $connection);
537
+	} elseif ($type == 'commit') {
538
+			return @mysql_query('COMMIT', $connection);
539
+	}
501 540
 
502 541
 	return false;
503 542
 }
@@ -537,8 +576,9 @@  discard block
 block discarded – undo
537 576
 	//    2013: Lost connection to server during query.
538 577
 
539 578
 	// Log the error.
540
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
541
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
579
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
580
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
581
+	}
542 582
 
543 583
 	// Database error auto fixing ;).
544 584
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -547,8 +587,9 @@  discard block
 block discarded – undo
547 587
 		$old_cache = @$modSettings['cache_enable'];
548 588
 		$modSettings['cache_enable'] = '1';
549 589
 
550
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
551
-			$db_last_error = max(@$db_last_error, $temp);
590
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
591
+					$db_last_error = max(@$db_last_error, $temp);
592
+		}
552 593
 
553 594
 		if (@$db_last_error < time() - 3600 * 24 * 3)
554 595
 		{
@@ -564,8 +605,9 @@  discard block
 block discarded – undo
564 605
 					foreach ($tables as $table)
565 606
 					{
566 607
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
567
-						if (trim($table) != '')
568
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
608
+						if (trim($table) != '') {
609
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
610
+						}
569 611
 					}
570 612
 				}
571 613
 
@@ -574,8 +616,9 @@  discard block
 block discarded – undo
574 616
 			// Table crashed.  Let's try to fix it.
575 617
 			elseif ($query_errno == 1016)
576 618
 			{
577
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
578
-					$fix_tables = array('`' . $match[1] . '`');
619
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
620
+									$fix_tables = array('`' . $match[1] . '`');
621
+				}
579 622
 			}
580 623
 			// Indexes crashed.  Should be easy to fix!
581 624
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -594,13 +637,15 @@  discard block
 block discarded – undo
594 637
 
595 638
 			// Make a note of the REPAIR...
596 639
 			cache_put_data('db_last_error', time(), 600);
597
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
598
-				updateSettingsFile(array('db_last_error' => time()));
640
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
641
+							updateSettingsFile(array('db_last_error' => time()));
642
+			}
599 643
 
600 644
 			// Attempt to find and repair the broken table.
601
-			foreach ($fix_tables as $table)
602
-				$smcFunc['db_query']('', "
645
+			foreach ($fix_tables as $table) {
646
+							$smcFunc['db_query']('', "
603 647
 					REPAIR TABLE $table", false, false);
648
+			}
604 649
 
605 650
 			// And send off an email!
606 651
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -609,11 +654,12 @@  discard block
 block discarded – undo
609 654
 
610 655
 			// Try the query again...?
611 656
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
612
-			if ($ret !== false)
613
-				return $ret;
657
+			if ($ret !== false) {
658
+							return $ret;
659
+			}
660
+		} else {
661
+					$modSettings['cache_enable'] = $old_cache;
614 662
 		}
615
-		else
616
-			$modSettings['cache_enable'] = $old_cache;
617 663
 
618 664
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
619 665
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -623,22 +669,25 @@  discard block
 block discarded – undo
623 669
 				// Are we in SSI mode?  If so try that username and password first
624 670
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
625 671
 				{
626
-					if (empty($db_persist))
627
-						$db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd);
628
-					else
629
-						$db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd);
672
+					if (empty($db_persist)) {
673
+											$db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd);
674
+					} else {
675
+											$db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd);
676
+					}
630 677
 				}
631 678
 				// Fall back to the regular username and password if need be
632 679
 				if (!$db_connection)
633 680
 				{
634
-					if (empty($db_persist))
635
-						$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
636
-					else
637
-						$db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
681
+					if (empty($db_persist)) {
682
+											$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
683
+					} else {
684
+											$db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
685
+					}
638 686
 				}
639 687
 
640
-				if (!$db_connection || !@mysql_select_db($db_name, $db_connection))
641
-					$db_connection = false;
688
+				if (!$db_connection || !@mysql_select_db($db_name, $db_connection)) {
689
+									$db_connection = false;
690
+				}
642 691
 			}
643 692
 
644 693
 			if ($db_connection)
@@ -649,24 +698,27 @@  discard block
 block discarded – undo
649 698
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
650 699
 
651 700
 					$new_errno = mysql_errno($db_connection);
652
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
653
-						break;
701
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
702
+											break;
703
+					}
654 704
 				}
655 705
 
656 706
 				// If it failed again, shucks to be you... we're not trying it over and over.
657
-				if ($ret !== false)
658
-					return $ret;
707
+				if ($ret !== false) {
708
+									return $ret;
709
+				}
659 710
 			}
660 711
 		}
661 712
 		// Are they out of space, perhaps?
662 713
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
663 714
 		{
664
-			if (!isset($txt))
665
-				$query_error .= ' - check database storage space.';
666
-			else
715
+			if (!isset($txt)) {
716
+							$query_error .= ' - check database storage space.';
717
+			} else
667 718
 			{
668
-				if (!isset($txt['mysql_error_space']))
669
-					loadLanguage('Errors');
719
+				if (!isset($txt['mysql_error_space'])) {
720
+									loadLanguage('Errors');
721
+				}
670 722
 
671 723
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
672 724
 			}
@@ -674,15 +726,17 @@  discard block
 block discarded – undo
674 726
 	}
675 727
 
676 728
 	// Nothing's defined yet... just die with it.
677
-	if (empty($context) || empty($txt))
678
-		die($query_error);
729
+	if (empty($context) || empty($txt)) {
730
+			die($query_error);
731
+	}
679 732
 
680 733
 	// Show an error message, if possible.
681 734
 	$context['error_title'] = $txt['database_error'];
682
-	if (allowedTo('admin_forum'))
683
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
684
-	else
685
-		$context['error_message'] = $txt['try_again'];
735
+	if (allowedTo('admin_forum')) {
736
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
737
+	} else {
738
+			$context['error_message'] = $txt['try_again'];
739
+	}
686 740
 
687 741
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
688 742
 	{
@@ -711,25 +765,28 @@  discard block
 block discarded – undo
711 765
 	$connection = $connection === null ? $db_connection : $connection;
712 766
 
713 767
 	// With nothing to insert, simply return.
714
-	if (empty($data))
715
-		return;
768
+	if (empty($data)) {
769
+			return;
770
+	}
716 771
 
717 772
 	// Replace the prefix holder with the actual prefix.
718 773
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
719 774
 
720 775
 	// Inserting data as a single row can be done as a single array.
721
-	if (!is_array($data[array_rand($data)]))
722
-		$data = array($data);
776
+	if (!is_array($data[array_rand($data)])) {
777
+			$data = array($data);
778
+	}
723 779
 
724 780
 	// Create the mold for a single row insert.
725 781
 	$insertData = '(';
726 782
 	foreach ($columns as $columnName => $type)
727 783
 	{
728 784
 		// Are we restricting the length?
729
-		if (strpos($type, 'string-') !== false)
730
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
731
-		else
732
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
785
+		if (strpos($type, 'string-') !== false) {
786
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
787
+		} else {
788
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
789
+		}
733 790
 	}
734 791
 	$insertData = substr($insertData, 0, -2) . ')';
735 792
 
@@ -738,8 +795,9 @@  discard block
 block discarded – undo
738 795
 
739 796
 	// Here's where the variables are injected to the query.
740 797
 	$insertRows = array();
741
-	foreach ($data as $dataRow)
742
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
798
+	foreach ($data as $dataRow) {
799
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
800
+	}
743 801
 
744 802
 	// Determine the method of insertion.
745 803
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -770,8 +828,9 @@  discard block
 block discarded – undo
770 828
  */
771 829
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
772 830
 {
773
-	if (empty($log_message))
774
-		$log_message = $error_message;
831
+	if (empty($log_message)) {
832
+			$log_message = $error_message;
833
+	}
775 834
 
776 835
 	foreach (debug_backtrace() as $step)
777 836
 	{
@@ -790,12 +849,14 @@  discard block
 block discarded – undo
790 849
 	}
791 850
 
792 851
 	// A special case - we want the file and line numbers for debugging.
793
-	if ($error_type == 'return')
794
-		return array($file, $line);
852
+	if ($error_type == 'return') {
853
+			return array($file, $line);
854
+	}
795 855
 
796 856
 	// Is always a critical error.
797
-	if (function_exists('log_error'))
798
-		log_error($log_message, 'critical', $file, $line);
857
+	if (function_exists('log_error')) {
858
+			log_error($log_message, 'critical', $file, $line);
859
+	}
799 860
 
800 861
 	if (function_exists('fatal_error'))
801 862
 	{
@@ -803,12 +864,12 @@  discard block
 block discarded – undo
803 864
 
804 865
 		// Cannot continue...
805 866
 		exit;
867
+	} elseif ($error_type) {
868
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
869
+	} else {
870
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
871
+	}
806 872
 	}
807
-	elseif ($error_type)
808
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
809
-	else
810
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
811
-}
812 873
 
813 874
 /**
814 875
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -825,10 +886,11 @@  discard block
 block discarded – undo
825 886
 		'\\' => '\\\\',
826 887
 	);
827 888
 
828
-	if ($translate_human_wildcards)
829
-		$replacements += array(
889
+	if ($translate_human_wildcards) {
890
+			$replacements += array(
830 891
 			'*' => '%',
831 892
 		);
893
+	}
832 894
 
833 895
 	return strtr($string, $replacements);
834 896
 }
Please login to merge, or discard this patch.