Completed
Push — release-2.1 ( 8364ab...05f921 )
by Mathias
08:23
created
Sources/Subs-Calendar.php 1 patch
Braces   +215 added lines, -157 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.
@@ -60,8 +61,7 @@  discard block
 block discarded – undo
60 61
 				'max_year' => $year_high,
61 62
 			)
62 63
 		);
63
-	}
64
-	else
64
+	} else
65 65
 	{
66 66
 		$result = $smcFunc['db_query']('birthday_array', '
67 67
 			SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate
@@ -91,10 +91,11 @@  discard block
 block discarded – undo
91 91
 	$bday = array();
92 92
 	while ($row = $smcFunc['db_fetch_assoc']($result))
93 93
 	{
94
-		if ($year_low != $year_high)
95
-			$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
-		else
97
-			$age_year = $year_low;
94
+		if ($year_low != $year_high) {
95
+					$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
+		} else {
97
+					$age_year = $year_low;
98
+		}
98 99
 
99 100
 		$bday[$age_year . substr($row['birthdate'], 4)][] = array(
100 101
 			'id' => $row['id_member'],
@@ -108,8 +109,9 @@  discard block
 block discarded – undo
108 109
 	ksort($bday);
109 110
 
110 111
 	// Set is_last, so the themes know when to stop placing separators.
111
-	foreach ($bday as $mday => $array)
112
-		$bday[$mday][count($array) - 1]['is_last'] = true;
112
+	foreach ($bday as $mday => $array) {
113
+			$bday[$mday][count($array) - 1]['is_last'] = true;
114
+	}
113 115
 
114 116
 	return $bday;
115 117
 }
@@ -157,8 +159,9 @@  discard block
 block discarded – undo
157 159
 	while ($row = $smcFunc['db_fetch_assoc']($result))
158 160
 	{
159 161
 		// If the attached topic is not approved then for the moment pretend it doesn't exist
160
-		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved'])
161
-			continue;
162
+		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) {
163
+					continue;
164
+		}
162 165
 
163 166
 		// Force a censor of the title - as often these are used by others.
164 167
 		censorText($row['title'], $use_permissions ? false : true);
@@ -167,8 +170,9 @@  discard block
 block discarded – undo
167 170
 		list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
168 171
 
169 172
 		// Sanity check
170
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
171
-			continue;
173
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
174
+					continue;
175
+		}
172 176
 
173 177
 		// Get set up for the loop
174 178
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), timezone_open($tz));
@@ -232,8 +236,8 @@  discard block
 block discarded – undo
232 236
 			);
233 237
 
234 238
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
235
-			if ($use_permissions)
236
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
239
+			if ($use_permissions) {
240
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
237 241
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
238 242
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
239 243
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -241,9 +245,10 @@  discard block
 block discarded – undo
241 245
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
242 246
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
243 247
 				));
248
+			}
244 249
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
245
-			else
246
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
250
+			else {
251
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
247 252
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
248 253
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
249 254
 					'can_edit' => false,
@@ -253,6 +258,7 @@  discard block
 block discarded – undo
253 258
 					'poster' => $row['id_member'],
254 259
 					'allowed_groups' => explode(',', $row['member_groups']),
255 260
 				));
261
+			}
256 262
 
257 263
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
258 264
 		}
@@ -262,8 +268,9 @@  discard block
 block discarded – undo
262 268
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
263 269
 	if ($use_permissions)
264 270
 	{
265
-		foreach ($events as $mday => $array)
266
-			$events[$mday][count($array) - 1]['is_last'] = true;
271
+		foreach ($events as $mday => $array) {
272
+					$events[$mday][count($array) - 1]['is_last'] = true;
273
+		}
267 274
 	}
268 275
 
269 276
 	ksort($events);
@@ -283,11 +290,12 @@  discard block
 block discarded – undo
283 290
 	global $smcFunc;
284 291
 
285 292
 	// Get the lowest and highest dates for "all years".
286
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
287
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
293
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
294
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
288 295
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
289
-	else
290
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
296
+	} else {
297
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
298
+	}
291 299
 
292 300
 	// Find some holidays... ;).
293 301
 	$result = $smcFunc['db_query']('', '
@@ -307,10 +315,11 @@  discard block
 block discarded – undo
307 315
 	$holidays = array();
308 316
 	while ($row = $smcFunc['db_fetch_assoc']($result))
309 317
 	{
310
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
311
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
312
-		else
313
-			$event_year = substr($low_date, 0, 4);
318
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
319
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
320
+		} else {
321
+					$event_year = substr($low_date, 0, 4);
322
+		}
314 323
 
315 324
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
316 325
 	}
@@ -336,10 +345,12 @@  discard block
 block discarded – undo
336 345
 	isAllowedTo('calendar_post');
337 346
 
338 347
 	// No board?  No topic?!?
339
-	if (empty($board))
340
-		fatal_lang_error('missing_board_id', false);
341
-	if (empty($topic))
342
-		fatal_lang_error('missing_topic_id', false);
348
+	if (empty($board)) {
349
+			fatal_lang_error('missing_board_id', false);
350
+	}
351
+	if (empty($topic)) {
352
+			fatal_lang_error('missing_topic_id', false);
353
+	}
343 354
 
344 355
 	// Administrator, Moderator, or owner.  Period.
345 356
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -357,12 +368,14 @@  discard block
 block discarded – undo
357 368
 		if ($row = $smcFunc['db_fetch_assoc']($result))
358 369
 		{
359 370
 			// Not the owner of the topic.
360
-			if ($row['id_member_started'] != $user_info['id'])
361
-				fatal_lang_error('not_your_topic', 'user');
371
+			if ($row['id_member_started'] != $user_info['id']) {
372
+							fatal_lang_error('not_your_topic', 'user');
373
+			}
362 374
 		}
363 375
 		// Topic/Board doesn't exist.....
364
-		else
365
-			fatal_lang_error('calendar_no_topic', 'general');
376
+		else {
377
+					fatal_lang_error('calendar_no_topic', 'general');
378
+		}
366 379
 		$smcFunc['db_free_result']($result);
367 380
 	}
368 381
 }
@@ -450,14 +463,16 @@  discard block
 block discarded – undo
450 463
 	if (!empty($calendarOptions['start_day']))
451 464
 	{
452 465
 		$nShift -= $calendarOptions['start_day'];
453
-		if ($nShift < 0)
454
-			$nShift = 7 + $nShift;
466
+		if ($nShift < 0) {
467
+					$nShift = 7 + $nShift;
468
+		}
455 469
 	}
456 470
 
457 471
 	// Number of rows required to fit the month.
458 472
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
459
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
460
-		$nRows++;
473
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
474
+			$nRows++;
475
+	}
461 476
 
462 477
 	// Fetch the arrays for birthdays, posted events, and holidays.
463 478
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -470,8 +485,9 @@  discard block
 block discarded – undo
470 485
 	{
471 486
 		$calendarGrid['week_days'][] = $count;
472 487
 		$count++;
473
-		if ($count == 7)
474
-			$count = 0;
488
+		if ($count == 7) {
489
+					$count = 0;
490
+		}
475 491
 	}
476 492
 
477 493
 	// Iterate through each week.
@@ -488,8 +504,9 @@  discard block
 block discarded – undo
488 504
 		{
489 505
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
490 506
 
491
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
492
-				$nDay = 0;
507
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
508
+							$nDay = 0;
509
+			}
493 510
 
494 511
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
495 512
 
@@ -507,8 +524,9 @@  discard block
 block discarded – undo
507 524
 	}
508 525
 
509 526
 	// What is the last day of the month?
510
-	if ($is_previous === true)
511
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
527
+	if ($is_previous === true) {
528
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
529
+	}
512 530
 
513 531
 	// We'll use the shift in the template.
514 532
 	$calendarGrid['shift'] = $nShift;
@@ -542,8 +560,9 @@  discard block
 block discarded – undo
542 560
 	{
543 561
 		// Here we offset accordingly to get things to the real start of a week.
544 562
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
545
-		if ($date_diff < 0)
546
-			$date_diff += 7;
563
+		if ($date_diff < 0) {
564
+					$date_diff += 7;
565
+		}
547 566
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
548 567
 		$day = (int) strftime('%d', $new_timestamp);
549 568
 		$month = (int) strftime('%m', $new_timestamp);
@@ -673,18 +692,20 @@  discard block
 block discarded – undo
673 692
 	{
674 693
 		foreach ($date_events as $event_key => $event_val)
675 694
 		{
676
-			if (in_array($event_val['id'], $temp))
677
-				unset($calendarGrid['events'][$date][$event_key]);
678
-			else
679
-				$temp[] = $event_val['id'];
695
+			if (in_array($event_val['id'], $temp)) {
696
+							unset($calendarGrid['events'][$date][$event_key]);
697
+			} else {
698
+							$temp[] = $event_val['id'];
699
+			}
680 700
 		}
681 701
 	}
682 702
 
683 703
 	// Give birthdays and holidays a friendly format, without the year
684
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
685
-		$date_format = '%b %d';
686
-	else
687
-		$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
704
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
705
+			$date_format = '%b %d';
706
+	} else {
707
+			$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
708
+	}
688 709
 
689 710
 	foreach (array('birthdays', 'holidays') as $type)
690 711
 	{
@@ -779,8 +800,9 @@  discard block
 block discarded – undo
779 800
 	// Holidays between now and now + days.
780 801
 	for ($i = $now; $i < $now + $days_for_index; $i += 86400)
781 802
 	{
782
-		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
783
-			$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
803
+		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
804
+					$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
805
+		}
784 806
 	}
785 807
 
786 808
 	// Happy Birthday, guys and gals!
@@ -789,8 +811,9 @@  discard block
 block discarded – undo
789 811
 		$loop_date = strftime('%Y-%m-%d', $i);
790 812
 		if (isset($cached_data['birthdays'][$loop_date]))
791 813
 		{
792
-			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
793
-				$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
814
+			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
815
+							$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
816
+			}
794 817
 			$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
795 818
 		}
796 819
 	}
@@ -802,8 +825,9 @@  discard block
 block discarded – undo
802 825
 		$loop_date = strftime('%Y-%m-%d', $i);
803 826
 
804 827
 		// No events today? Check the next day.
805
-		if (empty($cached_data['events'][$loop_date]))
806
-			continue;
828
+		if (empty($cached_data['events'][$loop_date])) {
829
+					continue;
830
+		}
807 831
 
808 832
 		// Loop through all events to add a few last-minute values.
809 833
 		foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -816,9 +840,9 @@  discard block
 block discarded – undo
816 840
 			{
817 841
 				unset($cached_data['events'][$loop_date][$ev]);
818 842
 				continue;
843
+			} else {
844
+							$duplicates[$this_event['topic'] . $this_event['title']] = true;
819 845
 			}
820
-			else
821
-				$duplicates[$this_event['topic'] . $this_event['title']] = true;
822 846
 
823 847
 			// Might be set to true afterwards, depending on the permissions.
824 848
 			$this_event['can_edit'] = false;
@@ -826,15 +850,18 @@  discard block
 block discarded – undo
826 850
 			$this_event['date'] = $loop_date;
827 851
 		}
828 852
 
829
-		if (!empty($cached_data['events'][$loop_date]))
830
-			$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
853
+		if (!empty($cached_data['events'][$loop_date])) {
854
+					$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
855
+		}
831 856
 	}
832 857
 
833 858
 	// Mark the last item so that a list separator can be used in the template.
834
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
835
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
836
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
837
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
859
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
860
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
861
+	}
862
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
863
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
864
+	}
838 865
 
839 866
 	return array(
840 867
 		'data' => $return_data,
@@ -882,37 +909,46 @@  discard block
 block discarded – undo
882 909
 		if (isset($_POST['start_date']))
883 910
 		{
884 911
 			$d = date_parse($_POST['start_date']);
885
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
886
-				fatal_lang_error('invalid_date', false);
887
-			if (empty($d['year']))
888
-				fatal_lang_error('event_year_missing', false);
889
-			if (empty($d['month']))
890
-				fatal_lang_error('event_month_missing', false);
891
-		}
892
-		elseif (isset($_POST['start_datetime']))
912
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
913
+							fatal_lang_error('invalid_date', false);
914
+			}
915
+			if (empty($d['year'])) {
916
+							fatal_lang_error('event_year_missing', false);
917
+			}
918
+			if (empty($d['month'])) {
919
+							fatal_lang_error('event_month_missing', false);
920
+			}
921
+		} elseif (isset($_POST['start_datetime']))
893 922
 		{
894 923
 			$d = date_parse($_POST['start_datetime']);
895
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
896
-				fatal_lang_error('invalid_date', false);
897
-			if (empty($d['year']))
898
-				fatal_lang_error('event_year_missing', false);
899
-			if (empty($d['month']))
900
-				fatal_lang_error('event_month_missing', false);
924
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
925
+							fatal_lang_error('invalid_date', false);
926
+			}
927
+			if (empty($d['year'])) {
928
+							fatal_lang_error('event_year_missing', false);
929
+			}
930
+			if (empty($d['month'])) {
931
+							fatal_lang_error('event_month_missing', false);
932
+			}
901 933
 		}
902 934
 		// The 2.0 way
903 935
 		else
904 936
 		{
905 937
 			// No month?  No year?
906
-			if (!isset($_POST['month']))
907
-				fatal_lang_error('event_month_missing', false);
908
-			if (!isset($_POST['year']))
909
-				fatal_lang_error('event_year_missing', false);
938
+			if (!isset($_POST['month'])) {
939
+							fatal_lang_error('event_month_missing', false);
940
+			}
941
+			if (!isset($_POST['year'])) {
942
+							fatal_lang_error('event_year_missing', false);
943
+			}
910 944
 
911 945
 			// Check the month and year...
912
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
913
-				fatal_lang_error('invalid_month', false);
914
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
915
-				fatal_lang_error('invalid_year', false);
946
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
947
+							fatal_lang_error('invalid_month', false);
948
+			}
949
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
950
+							fatal_lang_error('invalid_year', false);
951
+			}
916 952
 		}
917 953
 	}
918 954
 
@@ -922,8 +958,9 @@  discard block
 block discarded – undo
922 958
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
923 959
 	if (isset($_POST['span']))
924 960
 	{
925
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
926
-			fatal_lang_error('invalid_days_numb', false);
961
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
962
+					fatal_lang_error('invalid_days_numb', false);
963
+		}
927 964
 	}
928 965
 
929 966
 	// There is no need to validate the following values if we are just deleting the event.
@@ -933,24 +970,29 @@  discard block
 block discarded – undo
933 970
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
934 971
 		{
935 972
 			// No day?
936
-			if (!isset($_POST['day']))
937
-				fatal_lang_error('event_day_missing', false);
973
+			if (!isset($_POST['day'])) {
974
+							fatal_lang_error('event_day_missing', false);
975
+			}
938 976
 
939 977
 			// Bad day?
940
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
941
-				fatal_lang_error('invalid_date', false);
978
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
979
+							fatal_lang_error('invalid_date', false);
980
+			}
942 981
 		}
943 982
 
944
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
945
-			fatal_lang_error('event_title_missing', false);
946
-		elseif (!isset($_POST['evtitle']))
947
-			$_POST['evtitle'] = $_POST['subject'];
983
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
984
+					fatal_lang_error('event_title_missing', false);
985
+		} elseif (!isset($_POST['evtitle'])) {
986
+					$_POST['evtitle'] = $_POST['subject'];
987
+		}
948 988
 
949 989
 		// No title?
950
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
951
-			fatal_lang_error('no_event_title', false);
952
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
953
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
990
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
991
+					fatal_lang_error('no_event_title', false);
992
+		}
993
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
994
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
995
+		}
954 996
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
955 997
 	}
956 998
 }
@@ -977,8 +1019,9 @@  discard block
 block discarded – undo
977 1019
 	);
978 1020
 
979 1021
 	// No results, return false.
980
-	if ($smcFunc['db_num_rows'] === 0)
981
-		return false;
1022
+	if ($smcFunc['db_num_rows'] === 0) {
1023
+			return false;
1024
+	}
982 1025
 
983 1026
 	// Grab the results and return.
984 1027
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -1112,8 +1155,9 @@  discard block
 block discarded – undo
1112 1155
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
1113 1156
 
1114 1157
 	$column_clauses = array();
1115
-	foreach ($event_columns as $col => $crit)
1116
-		$column_clauses[] = $col . ' = ' . $crit;
1158
+	foreach ($event_columns as $col => $crit) {
1159
+			$column_clauses[] = $col . ' = ' . $crit;
1160
+	}
1117 1161
 
1118 1162
 	$smcFunc['db_query']('', '
1119 1163
 		UPDATE {db_prefix}calendar
@@ -1198,8 +1242,9 @@  discard block
 block discarded – undo
1198 1242
 	);
1199 1243
 
1200 1244
 	// If nothing returned, we are in poo, poo.
1201
-	if ($smcFunc['db_num_rows']($request) === 0)
1202
-		return false;
1245
+	if ($smcFunc['db_num_rows']($request) === 0) {
1246
+			return false;
1247
+	}
1203 1248
 
1204 1249
 	$row = $smcFunc['db_fetch_assoc']($request);
1205 1250
 	$smcFunc['db_free_result']($request);
@@ -1207,8 +1252,9 @@  discard block
 block discarded – undo
1207 1252
 	list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
1208 1253
 
1209 1254
 	// Sanity check
1210
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1211
-		return false;
1255
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1256
+			return false;
1257
+	}
1212 1258
 
1213 1259
 	$return_value = array(
1214 1260
 		'boards' => array(),
@@ -1345,24 +1391,27 @@  discard block
 block discarded – undo
1345 1391
 
1346 1392
 	// Set $span, in case we need it
1347 1393
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1348
-	if ($span > 0)
1349
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1394
+	if ($span > 0) {
1395
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1396
+	}
1350 1397
 
1351 1398
 	// Define the timezone for this event, falling back to the default if not provided
1352
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1353
-		$tz = $eventOptions['tz'];
1354
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1355
-		$tz = $_POST['tz'];
1356
-	else
1357
-		$tz = getUserTimezone();
1399
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1400
+			$tz = $eventOptions['tz'];
1401
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1402
+			$tz = $_POST['tz'];
1403
+	} else {
1404
+			$tz = getUserTimezone();
1405
+	}
1358 1406
 
1359 1407
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1360
-	if (isset($eventOptions['allday']))
1361
-		$allday = $eventOptions['allday'];
1362
-	elseif (empty($_POST['allday']))
1363
-		$allday = false;
1364
-	else
1365
-		$allday = true;
1408
+	if (isset($eventOptions['allday'])) {
1409
+			$allday = $eventOptions['allday'];
1410
+	} elseif (empty($_POST['allday'])) {
1411
+			$allday = false;
1412
+	} else {
1413
+			$allday = true;
1414
+	}
1366 1415
 
1367 1416
 	// Input might come as individual parameters...
1368 1417
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1389,10 +1438,12 @@  discard block
 block discarded – undo
1389 1438
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1390 1439
 
1391 1440
 	// If the date and time were given in separate strings, combine them
1392
-	if (empty($start_string) && isset($start_date_string))
1393
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1394
-	if (empty($end_string) && isset($end_date_string))
1395
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1441
+	if (empty($start_string) && isset($start_date_string)) {
1442
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1443
+	}
1444
+	if (empty($end_string) && isset($end_date_string)) {
1445
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1446
+	}
1396 1447
 
1397 1448
 	// If some form of string input was given, override individually defined options with it
1398 1449
 	if (isset($start_string))
@@ -1483,10 +1534,11 @@  discard block
 block discarded – undo
1483 1534
 	if ($start_object >= $end_object)
1484 1535
 	{
1485 1536
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1486
-		if ($span > 0)
1487
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1488
-		else
1489
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1537
+		if ($span > 0) {
1538
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1539
+		} else {
1540
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1541
+		}
1490 1542
 	}
1491 1543
 
1492 1544
 	// Is $end_object too late?
@@ -1499,9 +1551,9 @@  discard block
 block discarded – undo
1499 1551
 			{
1500 1552
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1501 1553
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1554
+			} else {
1555
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1502 1556
 			}
1503
-			else
1504
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1505 1557
 		}
1506 1558
 	}
1507 1559
 
@@ -1514,8 +1566,7 @@  discard block
 block discarded – undo
1514 1566
 		$start_time = null;
1515 1567
 		$end_time = null;
1516 1568
 		$tz = null;
1517
-	}
1518
-	else
1569
+	} else
1519 1570
 	{
1520 1571
 		$start_time = date_format($start_object, 'H:i:s');
1521 1572
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1536,16 +1587,18 @@  discard block
 block discarded – undo
1536 1587
 	require_once($sourcedir . '/Subs.php');
1537 1588
 
1538 1589
 	// First, try to create a better date format, ignoring the "time" elements.
1539
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1540
-		$date_format = '%F';
1541
-	else
1542
-		$date_format = $matches[0];
1590
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1591
+			$date_format = '%F';
1592
+	} else {
1593
+			$date_format = $matches[0];
1594
+	}
1543 1595
 
1544 1596
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1545
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1546
-		$time_format = '%k:%M';
1547
-	else
1548
-		$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1597
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1598
+			$time_format = '%k:%M';
1599
+	} else {
1600
+			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1601
+	}
1549 1602
 
1550 1603
 	// Should this be an all day event?
1551 1604
 	$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;
@@ -1554,8 +1607,9 @@  discard block
 block discarded – undo
1554 1607
 	$span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d');
1555 1608
 
1556 1609
 	// We need to have a defined timezone in the steps below
1557
-	if (empty($row['timezone']))
1558
-		$row['timezone'] = getUserTimezone();
1610
+	if (empty($row['timezone'])) {
1611
+			$row['timezone'] = getUserTimezone();
1612
+	}
1559 1613
 
1560 1614
 	// Get most of the standard date information for the start and end datetimes
1561 1615
 	$start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''));
@@ -1607,8 +1661,9 @@  discard block
 block discarded – undo
1607 1661
 	global $smcFunc, $context, $user_info, $modSettings;
1608 1662
 	static $member_cache = array();
1609 1663
 
1610
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1611
-		$id_member = $context['user']['id'];
1664
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1665
+			$id_member = $context['user']['id'];
1666
+	}
1612 1667
 
1613 1668
 	//check if the cache got the data
1614 1669
 	if (isset($id_member) && isset($member_cache[$id_member]))
@@ -1630,11 +1685,13 @@  discard block
 block discarded – undo
1630 1685
 		$smcFunc['db_free_result']($request);
1631 1686
 	}
1632 1687
 
1633
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1634
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1688
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1689
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1690
+	}
1635 1691
 
1636
-	if (isset($id_member))
1637
-		$member_cache[$id_member] = $timezone;
1692
+	if (isset($id_member)) {
1693
+			$member_cache[$id_member] = $timezone;
1694
+	}
1638 1695
 
1639 1696
 	return $timezone;
1640 1697
 }
@@ -1663,8 +1720,9 @@  discard block
 block discarded – undo
1663 1720
 		)
1664 1721
 	);
1665 1722
 	$holidays = array();
1666
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1667
-		$holidays[] = $row;
1723
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1724
+			$holidays[] = $row;
1725
+	}
1668 1726
 	$smcFunc['db_free_result']($request);
1669 1727
 
1670 1728
 	return $holidays;
Please login to merge, or discard this patch.
Sources/DbSearch-postgresql.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -38,12 +38,12 @@  discard block
 block discarded – undo
38 38
 	$version = $smcFunc['db_get_version']();
39 39
 	// if we got a Beta Version
40 40
 	if (stripos($version, 'beta') !== false)
41
-		$version = substr($version, 0, stripos($version, 'beta')).'.0';
41
+		$version = substr($version, 0, stripos($version, 'beta')) . '.0';
42 42
 	// or RC
43 43
 	if (stripos($version, 'rc') !== false)
44
-		$version = substr($version, 0, stripos($version, 'rc')).'.0';
44
+		$version = substr($version, 0, stripos($version, 'rc')) . '.0';
45 45
 
46
-	if (version_compare($version,'9.5.0','>='))
46
+	if (version_compare($version, '9.5.0', '>='))
47 47
 		$smcFunc['db_support_ignore'] = true;
48 48
 }
49 49
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
  */
56 56
 function smf_db_search_support($search_type)
57 57
 {
58
-	$supported_types = array('custom','fulltext');
58
+	$supported_types = array('custom', 'fulltext');
59 59
 
60 60
 	return in_array($search_type, $supported_types);
61 61
 }
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
 	if (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0)
110 110
 	{
111 111
 		$db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string);
112
-		if ($smcFunc['db_support_ignore']){
112
+		if ($smcFunc['db_support_ignore']) {
113 113
 			//pg style "INSERT INTO.... ON CONFLICT DO NOTHING"
114
-			$db_string = $db_string.' ON CONFLICT DO NOTHING';
114
+			$db_string = $db_string . ' ON CONFLICT DO NOTHING';
115 115
 		}
116 116
 		else
117 117
 		{
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 		$language_ftx = $modSettings['search_language'];
169 169
 	else
170 170
 	{
171
-		$request = $smcFunc['db_query']('','
171
+		$request = $smcFunc['db_query']('', '
172 172
 			SELECT cfgname FROM pg_ts_config WHERE oid = current_setting({string:default_language})::regconfig',
173 173
 			array(
174 174
 			'default_language' => 'default_text_search_config'
Please login to merge, or discard this patch.
Braces   +25 added lines, -19 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Add the file functions to the $smcFunc array.
@@ -23,29 +24,33 @@  discard block
 block discarded – undo
23 24
 {
24 25
 	global $smcFunc;
25 26
 
26
-	if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_search_query')
27
-		$smcFunc += array(
27
+	if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_search_query') {
28
+			$smcFunc += array(
28 29
 			'db_search_query' => 'smf_db_search_query',
29 30
 			'db_search_support' => 'smf_db_search_support',
30 31
 			'db_create_word_search' => 'smf_db_create_word_search',
31 32
 			'db_support_ignore' => false,
32 33
 			'db_search_language' => 'smf_db_search_language',
33 34
 		);
35
+	}
34 36
 
35 37
 	db_extend();
36 38
 
37 39
 	//pg 9.5 got ignore support
38 40
 	$version = $smcFunc['db_get_version']();
39 41
 	// if we got a Beta Version
40
-	if (stripos($version, 'beta') !== false)
41
-		$version = substr($version, 0, stripos($version, 'beta')).'.0';
42
+	if (stripos($version, 'beta') !== false) {
43
+			$version = substr($version, 0, stripos($version, 'beta')).'.0';
44
+	}
42 45
 	// or RC
43
-	if (stripos($version, 'rc') !== false)
44
-		$version = substr($version, 0, stripos($version, 'rc')).'.0';
46
+	if (stripos($version, 'rc') !== false) {
47
+			$version = substr($version, 0, stripos($version, 'rc')).'.0';
48
+	}
45 49
 
46
-	if (version_compare($version,'9.5.0','>='))
47
-		$smcFunc['db_support_ignore'] = true;
48
-}
50
+	if (version_compare($version,'9.5.0','>=')) {
51
+			$smcFunc['db_support_ignore'] = true;
52
+	}
53
+	}
49 54
 
50 55
 /**
51 56
  * This function will tell you whether this database type supports this search type.
@@ -104,16 +109,16 @@  discard block
 block discarded – undo
104 109
 		),
105 110
 	);
106 111
 
107
-	if (isset($replacements[$identifier]))
108
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
112
+	if (isset($replacements[$identifier])) {
113
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
114
+	}
109 115
 	if (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0)
110 116
 	{
111 117
 		$db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string);
112 118
 		if ($smcFunc['db_support_ignore']){
113 119
 			//pg style "INSERT INTO.... ON CONFLICT DO NOTHING"
114 120
 			$db_string = $db_string.' ON CONFLICT DO NOTHING';
115
-		}
116
-		else
121
+		} else
117 122
 		{
118 123
 			// Don't error on multi-insert.
119 124
 			$db_values['db_error_skip'] = true;
@@ -121,8 +126,9 @@  discard block
 block discarded – undo
121 126
 	}
122 127
 	
123 128
 	//fix double quotes
124
-	if ($identifier == 'insert_into_log_messages_fulltext')
125
-		$db_values = str_replace('"', "'", $db_values);
129
+	if ($identifier == 'insert_into_log_messages_fulltext') {
130
+			$db_values = str_replace('"', "'", $db_values);
131
+	}
126 132
 
127 133
 	$return = $smcFunc['db_query']('', $db_string,
128 134
 		$db_values, $connection
@@ -164,9 +170,9 @@  discard block
 block discarded – undo
164 170
 	
165 171
 	$language_ftx = 'english';
166 172
 	
167
-	if (!empty($modSettings['search_language']))
168
-		$language_ftx = $modSettings['search_language'];
169
-	else
173
+	if (!empty($modSettings['search_language'])) {
174
+			$language_ftx = $modSettings['search_language'];
175
+	} else
170 176
 	{
171 177
 		$request = $smcFunc['db_query']('','
172 178
 			SELECT cfgname FROM pg_ts_config WHERE oid = current_setting({string:default_language})::regconfig',
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -256,8 +256,8 @@  discard block
 block discarded – undo
256 256
 
257 257
 		case 'datetime':
258 258
 			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
259
-				return 'str_to_date('.
260
-					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
259
+				return 'str_to_date(' .
260
+					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) .
261 261
 					',\'%Y-%m-%d %h:%i:%s\')';
262 262
 			else
263 263
 				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 		$connection
825 825
 	);
826 826
 
827
-	if(!empty($keys) && (count($keys) > 0) && ($method === '' || $method === 'insert') && $returnmode > 0)
827
+	if (!empty($keys) && (count($keys) > 0) && ($method === '' || $method === 'insert') && $returnmode > 0)
828 828
 	{
829 829
 		if ($returnmode == 1)
830 830
 			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
 			$return_var = array();
834 834
 			$count = count($insertRows);
835 835
 			$start = smf_db_insert_id($table, $keys[0]);
836
-			for ($i = 0; $i < $count; $i++ )
836
+			for ($i = 0; $i < $count; $i++)
837 837
 				$return_var[] = $start + $i;
838 838
 		}
839 839
 		return $return_var;
Please login to merge, or discard this patch.
Braces   +251 added lines, -185 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 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;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -60,9 +61,11 @@  discard block
 block discarded – undo
60 61
 			'db_mb4'                    => false,
61 62
 			'db_ping'                   => 'mysqli_ping',
62 63
 		);
64
+	}
63 65
 
64
-	if (!empty($db_options['persist']))
65
-		$db_server = 'p:' . $db_server;
66
+	if (!empty($db_options['persist'])) {
67
+			$db_server = 'p:' . $db_server;
68
+	}
66 69
 
67 70
 	$connection = mysqli_init();
68 71
 
@@ -71,24 +74,27 @@  discard block
 block discarded – undo
71 74
 	$success = false;
72 75
 
73 76
 	if ($connection) {
74
-		if (!empty($db_options['port']))
75
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
76
-		else
77
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
77
+		if (!empty($db_options['port'])) {
78
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
79
+		} else {
80
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
81
+		}
78 82
 	}
79 83
 
80 84
 	// Something's wrong, show an error if its fatal (which we assume it is)
81 85
 	if ($success === false)
82 86
 	{
83
-		if (!empty($db_options['non_fatal']))
84
-			return null;
85
-		else
86
-			display_db_error();
87
+		if (!empty($db_options['non_fatal'])) {
88
+					return null;
89
+		} else {
90
+					display_db_error();
91
+		}
87 92
 	}
88 93
 
89 94
 	// Select the database, unless told not to
90
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
91
-		display_db_error();
95
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
96
+			display_db_error();
97
+	}
92 98
 
93 99
 	$smcFunc['db_query']('', 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'',
94 100
 		array(),
@@ -164,38 +170,46 @@  discard block
 block discarded – undo
164 170
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
165 171
 
166 172
 	list ($values, $connection) = $db_callback;
167
-	if (!is_object($connection))
168
-		display_db_error();
173
+	if (!is_object($connection)) {
174
+			display_db_error();
175
+	}
169 176
 
170
-	if ($matches[1] === 'db_prefix')
171
-		return $db_prefix;
177
+	if ($matches[1] === 'db_prefix') {
178
+			return $db_prefix;
179
+	}
172 180
 
173 181
 	if (!empty($user_info))
174 182
 	{
175
-		foreach (array_keys($user_info) as $key)
176
-			if (strpos($key, 'query_') !== false && $key === $matches[1])
183
+		foreach (array_keys($user_info) as $key) {
184
+					if (strpos($key, 'query_') !== false && $key === $matches[1])
177 185
 				return $user_info[$matches[1]];
186
+		}
178 187
 	}
179 188
 
180
-	if ($matches[1] === 'empty')
181
-		return '\'\'';
189
+	if ($matches[1] === 'empty') {
190
+			return '\'\'';
191
+	}
182 192
 
183
-	if (!isset($matches[2]))
184
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
193
+	if (!isset($matches[2])) {
194
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
195
+	}
185 196
 
186
-	if ($matches[1] === 'literal')
187
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
197
+	if ($matches[1] === 'literal') {
198
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
199
+	}
188 200
 
189
-	if (!isset($values[$matches[2]]))
190
-		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__);
201
+	if (!isset($values[$matches[2]])) {
202
+			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__);
203
+	}
191 204
 
192 205
 	$replacement = $values[$matches[2]];
193 206
 
194 207
 	switch ($matches[1])
195 208
 	{
196 209
 		case 'int':
197
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
198
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
210
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
211
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
212
+			}
199 213
 			return (string) (int) $replacement;
200 214
 		break;
201 215
 
@@ -207,65 +221,73 @@  discard block
 block discarded – undo
207 221
 		case 'array_int':
208 222
 			if (is_array($replacement))
209 223
 			{
210
-				if (empty($replacement))
211
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224
+				if (empty($replacement)) {
225
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
226
+				}
212 227
 
213 228
 				foreach ($replacement as $key => $value)
214 229
 				{
215
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
216
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
230
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
231
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
232
+					}
217 233
 
218 234
 					$replacement[$key] = (string) (int) $value;
219 235
 				}
220 236
 
221 237
 				return implode(', ', $replacement);
238
+			} else {
239
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222 240
 			}
223
-			else
224
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225 241
 
226 242
 		break;
227 243
 
228 244
 		case 'array_string':
229 245
 			if (is_array($replacement))
230 246
 			{
231
-				if (empty($replacement))
232
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
247
+				if (empty($replacement)) {
248
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249
+				}
233 250
 
234
-				foreach ($replacement as $key => $value)
235
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
251
+				foreach ($replacement as $key => $value) {
252
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
253
+				}
236 254
 
237 255
 				return implode(', ', $replacement);
256
+			} else {
257
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
238 258
 			}
239
-			else
240
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
241 259
 		break;
242 260
 
243 261
 		case 'date':
244
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
245
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
246
-			else
247
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
262
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
263
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
264
+			} else {
265
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+			}
248 267
 		break;
249 268
 
250 269
 		case 'time':
251
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
252
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
253
-			else
254
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
271
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
272
+			} else {
273
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
274
+			}
255 275
 		break;
256 276
 
257 277
 		case 'datetime':
258
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
259
-				return 'str_to_date('.
278
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
279
+							return 'str_to_date('.
260 280
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
261 281
 					',\'%Y-%m-%d %h:%i:%s\')';
262
-			else
263
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
282
+			} else {
283
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
284
+			}
264 285
 		break;
265 286
 
266 287
 		case 'float':
267
-			if (!is_numeric($replacement))
268
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
288
+			if (!is_numeric($replacement)) {
289
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
290
+			}
269 291
 			return (string) (float) $replacement;
270 292
 		break;
271 293
 
@@ -279,32 +301,37 @@  discard block
 block discarded – undo
279 301
 		break;
280 302
 
281 303
 		case 'inet':
282
-			if ($replacement == 'null' || $replacement == '')
283
-				return 'null';
284
-			if (!isValidIP($replacement))
285
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
304
+			if ($replacement == 'null' || $replacement == '') {
305
+							return 'null';
306
+			}
307
+			if (!isValidIP($replacement)) {
308
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
309
+			}
286 310
 			//we don't use the native support of mysql > 5.6.2
287 311
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
288 312
 
289 313
 		case 'array_inet':
290 314
 			if (is_array($replacement))
291 315
 			{
292
-				if (empty($replacement))
293
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
316
+				if (empty($replacement)) {
317
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
318
+				}
294 319
 
295 320
 				foreach ($replacement as $key => $value)
296 321
 				{
297
-					if ($replacement == 'null' || $replacement == '')
298
-						$replacement[$key] = 'null';
299
-					if (!isValidIP($value))
300
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
322
+					if ($replacement == 'null' || $replacement == '') {
323
+											$replacement[$key] = 'null';
324
+					}
325
+					if (!isValidIP($value)) {
326
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
327
+					}
301 328
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
302 329
 				}
303 330
 
304 331
 				return implode(', ', $replacement);
332
+			} else {
333
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
305 334
 			}
306
-			else
307
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
308 335
 		break;
309 336
 
310 337
 		default:
@@ -380,22 +407,25 @@  discard block
 block discarded – undo
380 407
 		// Are we in SSI mode?  If so try that username and password first
381 408
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
382 409
 		{
383
-			if (empty($db_persist))
384
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
385
-			else
386
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
410
+			if (empty($db_persist)) {
411
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
412
+			} else {
413
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
414
+			}
387 415
 		}
388 416
 		// Fall back to the regular username and password if need be
389 417
 		if (!$db_connection)
390 418
 		{
391
-			if (empty($db_persist))
392
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
393
-			else
394
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
419
+			if (empty($db_persist)) {
420
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
421
+			} else {
422
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
423
+			}
395 424
 		}
396 425
 
397
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
398
-			$db_connection = false;
426
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
427
+					$db_connection = false;
428
+		}
399 429
 
400 430
 		$connection = $db_connection;
401 431
 	}
@@ -403,18 +433,20 @@  discard block
 block discarded – undo
403 433
 	// One more query....
404 434
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
405 435
 
406
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
407
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
436
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
437
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
438
+	}
408 439
 
409 440
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
410 441
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
411 442
 	{
412 443
 		// Add before LIMIT
413
-		if ($pos = strpos($db_string, 'LIMIT '))
414
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
415
-		else
416
-			// Append it.
444
+		if ($pos = strpos($db_string, 'LIMIT ')) {
445
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
446
+		} else {
447
+					// Append it.
417 448
 			$db_string .= "\n\t\t\tORDER BY null";
449
+		}
418 450
 	}
419 451
 
420 452
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -436,8 +468,9 @@  discard block
 block discarded – undo
436 468
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
437 469
 
438 470
 		// Initialize $db_cache if not already initialized.
439
-		if (!isset($db_cache))
440
-			$db_cache = array();
471
+		if (!isset($db_cache)) {
472
+					$db_cache = array();
473
+		}
441 474
 
442 475
 		if (!empty($_SESSION['debug_redirect']))
443 476
 		{
@@ -463,17 +496,18 @@  discard block
 block discarded – undo
463 496
 		while (true)
464 497
 		{
465 498
 			$pos = strpos($db_string, '\'', $pos + 1);
466
-			if ($pos === false)
467
-				break;
499
+			if ($pos === false) {
500
+							break;
501
+			}
468 502
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
469 503
 
470 504
 			while (true)
471 505
 			{
472 506
 				$pos1 = strpos($db_string, '\'', $pos + 1);
473 507
 				$pos2 = strpos($db_string, '\\', $pos + 1);
474
-				if ($pos1 === false)
475
-					break;
476
-				elseif ($pos2 === false || $pos2 > $pos1)
508
+				if ($pos1 === false) {
509
+									break;
510
+				} elseif ($pos2 === false || $pos2 > $pos1)
477 511
 				{
478 512
 					$pos = $pos1;
479 513
 					break;
@@ -489,29 +523,35 @@  discard block
 block discarded – undo
489 523
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
490 524
 
491 525
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
492
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
493
-			$fail = true;
526
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
527
+					$fail = true;
528
+		}
494 529
 		// Trying to change passwords, slow us down, or something?
495
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
496
-			$fail = true;
497
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
498
-			$fail = true;
530
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
531
+					$fail = true;
532
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
533
+					$fail = true;
534
+		}
499 535
 
500
-		if (!empty($fail) && function_exists('log_error'))
501
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
536
+		if (!empty($fail) && function_exists('log_error')) {
537
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
538
+		}
502 539
 	}
503 540
 
504
-	if (empty($db_unbuffered))
505
-		$ret = @mysqli_query($connection, $db_string);
506
-	else
507
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
541
+	if (empty($db_unbuffered)) {
542
+			$ret = @mysqli_query($connection, $db_string);
543
+	} else {
544
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
545
+	}
508 546
 
509
-	if ($ret === false && empty($db_values['db_error_skip']))
510
-		$ret = smf_db_error($db_string, $connection);
547
+	if ($ret === false && empty($db_values['db_error_skip'])) {
548
+			$ret = smf_db_error($db_string, $connection);
549
+	}
511 550
 
512 551
 	// Debugging.
513
-	if (isset($db_show_debug) && $db_show_debug === true)
514
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
552
+	if (isset($db_show_debug) && $db_show_debug === true) {
553
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
554
+	}
515 555
 
516 556
 	return $ret;
517 557
 }
@@ -558,12 +598,13 @@  discard block
 block discarded – undo
558 598
 	// Decide which connection to use
559 599
 	$connection = $connection === null ? $db_connection : $connection;
560 600
 
561
-	if ($type == 'begin')
562
-		return @mysqli_query($connection, 'BEGIN');
563
-	elseif ($type == 'rollback')
564
-		return @mysqli_query($connection, 'ROLLBACK');
565
-	elseif ($type == 'commit')
566
-		return @mysqli_query($connection, 'COMMIT');
601
+	if ($type == 'begin') {
602
+			return @mysqli_query($connection, 'BEGIN');
603
+	} elseif ($type == 'rollback') {
604
+			return @mysqli_query($connection, 'ROLLBACK');
605
+	} elseif ($type == 'commit') {
606
+			return @mysqli_query($connection, 'COMMIT');
607
+	}
567 608
 
568 609
 	return false;
569 610
 }
@@ -603,8 +644,9 @@  discard block
 block discarded – undo
603 644
 	//    2013: Lost connection to server during query.
604 645
 
605 646
 	// Log the error.
606
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
607
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
647
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
648
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
649
+	}
608 650
 
609 651
 	// Database error auto fixing ;).
610 652
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -613,8 +655,9 @@  discard block
 block discarded – undo
613 655
 		$old_cache = @$modSettings['cache_enable'];
614 656
 		$modSettings['cache_enable'] = '1';
615 657
 
616
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
617
-			$db_last_error = max(@$db_last_error, $temp);
658
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
659
+					$db_last_error = max(@$db_last_error, $temp);
660
+		}
618 661
 
619 662
 		if (@$db_last_error < time() - 3600 * 24 * 3)
620 663
 		{
@@ -630,8 +673,9 @@  discard block
 block discarded – undo
630 673
 					foreach ($tables as $table)
631 674
 					{
632 675
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
633
-						if (trim($table) != '')
634
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
676
+						if (trim($table) != '') {
677
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
678
+						}
635 679
 					}
636 680
 				}
637 681
 
@@ -640,8 +684,9 @@  discard block
 block discarded – undo
640 684
 			// Table crashed.  Let's try to fix it.
641 685
 			elseif ($query_errno == 1016)
642 686
 			{
643
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
644
-					$fix_tables = array('`' . $match[1] . '`');
687
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
688
+									$fix_tables = array('`' . $match[1] . '`');
689
+				}
645 690
 			}
646 691
 			// Indexes crashed.  Should be easy to fix!
647 692
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -660,13 +705,15 @@  discard block
 block discarded – undo
660 705
 
661 706
 			// Make a note of the REPAIR...
662 707
 			cache_put_data('db_last_error', time(), 600);
663
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
664
-				updateSettingsFile(array('db_last_error' => time()));
708
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
709
+							updateSettingsFile(array('db_last_error' => time()));
710
+			}
665 711
 
666 712
 			// Attempt to find and repair the broken table.
667
-			foreach ($fix_tables as $table)
668
-				$smcFunc['db_query']('', "
713
+			foreach ($fix_tables as $table) {
714
+							$smcFunc['db_query']('', "
669 715
 					REPAIR TABLE $table", false, false);
716
+			}
670 717
 
671 718
 			// And send off an email!
672 719
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -675,11 +722,12 @@  discard block
 block discarded – undo
675 722
 
676 723
 			// Try the query again...?
677 724
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
678
-			if ($ret !== false)
679
-				return $ret;
725
+			if ($ret !== false) {
726
+							return $ret;
727
+			}
728
+		} else {
729
+					$modSettings['cache_enable'] = $old_cache;
680 730
 		}
681
-		else
682
-			$modSettings['cache_enable'] = $old_cache;
683 731
 
684 732
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
685 733
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -689,22 +737,25 @@  discard block
 block discarded – undo
689 737
 				// Are we in SSI mode?  If so try that username and password first
690 738
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
691 739
 				{
692
-					if (empty($db_persist))
693
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
694
-					else
695
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
740
+					if (empty($db_persist)) {
741
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
742
+					} else {
743
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
744
+					}
696 745
 				}
697 746
 				// Fall back to the regular username and password if need be
698 747
 				if (!$db_connection)
699 748
 				{
700
-					if (empty($db_persist))
701
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
702
-					else
703
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
749
+					if (empty($db_persist)) {
750
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
751
+					} else {
752
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
753
+					}
704 754
 				}
705 755
 
706
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
707
-					$db_connection = false;
756
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
757
+									$db_connection = false;
758
+				}
708 759
 			}
709 760
 
710 761
 			if ($db_connection)
@@ -715,24 +766,27 @@  discard block
 block discarded – undo
715 766
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
716 767
 
717 768
 					$new_errno = mysqli_errno($db_connection);
718
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
719
-						break;
769
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
770
+											break;
771
+					}
720 772
 				}
721 773
 
722 774
 				// If it failed again, shucks to be you... we're not trying it over and over.
723
-				if ($ret !== false)
724
-					return $ret;
775
+				if ($ret !== false) {
776
+									return $ret;
777
+				}
725 778
 			}
726 779
 		}
727 780
 		// Are they out of space, perhaps?
728 781
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
729 782
 		{
730
-			if (!isset($txt))
731
-				$query_error .= ' - check database storage space.';
732
-			else
783
+			if (!isset($txt)) {
784
+							$query_error .= ' - check database storage space.';
785
+			} else
733 786
 			{
734
-				if (!isset($txt['mysql_error_space']))
735
-					loadLanguage('Errors');
787
+				if (!isset($txt['mysql_error_space'])) {
788
+									loadLanguage('Errors');
789
+				}
736 790
 
737 791
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
738 792
 			}
@@ -740,15 +794,17 @@  discard block
 block discarded – undo
740 794
 	}
741 795
 
742 796
 	// Nothing's defined yet... just die with it.
743
-	if (empty($context) || empty($txt))
744
-		die($query_error);
797
+	if (empty($context) || empty($txt)) {
798
+			die($query_error);
799
+	}
745 800
 
746 801
 	// Show an error message, if possible.
747 802
 	$context['error_title'] = $txt['database_error'];
748
-	if (allowedTo('admin_forum'))
749
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
750
-	else
751
-		$context['error_message'] = $txt['try_again'];
803
+	if (allowedTo('admin_forum')) {
804
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
805
+	} else {
806
+			$context['error_message'] = $txt['try_again'];
807
+	}
752 808
 
753 809
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
754 810
 	{
@@ -778,25 +834,28 @@  discard block
 block discarded – undo
778 834
 	$connection = $connection === null ? $db_connection : $connection;
779 835
 
780 836
 	// With nothing to insert, simply return.
781
-	if (empty($data))
782
-		return;
837
+	if (empty($data)) {
838
+			return;
839
+	}
783 840
 
784 841
 	// Replace the prefix holder with the actual prefix.
785 842
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
786 843
 
787 844
 	// Inserting data as a single row can be done as a single array.
788
-	if (!is_array($data[array_rand($data)]))
789
-		$data = array($data);
845
+	if (!is_array($data[array_rand($data)])) {
846
+			$data = array($data);
847
+	}
790 848
 
791 849
 	// Create the mold for a single row insert.
792 850
 	$insertData = '(';
793 851
 	foreach ($columns as $columnName => $type)
794 852
 	{
795 853
 		// Are we restricting the length?
796
-		if (strpos($type, 'string-') !== false)
797
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
798
-		else
799
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
854
+		if (strpos($type, 'string-') !== false) {
855
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
856
+		} else {
857
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
858
+		}
800 859
 	}
801 860
 	$insertData = substr($insertData, 0, -2) . ')';
802 861
 
@@ -805,8 +864,9 @@  discard block
 block discarded – undo
805 864
 
806 865
 	// Here's where the variables are injected to the query.
807 866
 	$insertRows = array();
808
-	foreach ($data as $dataRow)
809
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
867
+	foreach ($data as $dataRow) {
868
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
869
+	}
810 870
 
811 871
 	// Determine the method of insertion.
812 872
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -826,15 +886,16 @@  discard block
 block discarded – undo
826 886
 
827 887
 	if(!empty($keys) && (count($keys) > 0) && ($method === '' || $method === 'insert') && $returnmode > 0)
828 888
 	{
829
-		if ($returnmode == 1)
830
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
831
-		else if ($returnmode == 2)
889
+		if ($returnmode == 1) {
890
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
891
+		} else if ($returnmode == 2)
832 892
 		{
833 893
 			$return_var = array();
834 894
 			$count = count($insertRows);
835 895
 			$start = smf_db_insert_id($table, $keys[0]);
836
-			for ($i = 0; $i < $count; $i++ )
837
-				$return_var[] = $start + $i;
896
+			for ($i = 0; $i < $count; $i++ ) {
897
+							$return_var[] = $start + $i;
898
+			}
838 899
 		}
839 900
 		return $return_var;
840 901
 	}
@@ -852,8 +913,9 @@  discard block
 block discarded – undo
852 913
  */
853 914
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
854 915
 {
855
-	if (empty($log_message))
856
-		$log_message = $error_message;
916
+	if (empty($log_message)) {
917
+			$log_message = $error_message;
918
+	}
857 919
 
858 920
 	foreach (debug_backtrace() as $step)
859 921
 	{
@@ -872,12 +934,14 @@  discard block
 block discarded – undo
872 934
 	}
873 935
 
874 936
 	// A special case - we want the file and line numbers for debugging.
875
-	if ($error_type == 'return')
876
-		return array($file, $line);
937
+	if ($error_type == 'return') {
938
+			return array($file, $line);
939
+	}
877 940
 
878 941
 	// Is always a critical error.
879
-	if (function_exists('log_error'))
880
-		log_error($log_message, 'critical', $file, $line);
942
+	if (function_exists('log_error')) {
943
+			log_error($log_message, 'critical', $file, $line);
944
+	}
881 945
 
882 946
 	if (function_exists('fatal_error'))
883 947
 	{
@@ -885,12 +949,12 @@  discard block
 block discarded – undo
885 949
 
886 950
 		// Cannot continue...
887 951
 		exit;
952
+	} elseif ($error_type) {
953
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
954
+	} else {
955
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
956
+	}
888 957
 	}
889
-	elseif ($error_type)
890
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
891
-	else
892
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
893
-}
894 958
 
895 959
 /**
896 960
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -907,10 +971,11 @@  discard block
 block discarded – undo
907 971
 		'\\' => '\\\\',
908 972
 	);
909 973
 
910
-	if ($translate_human_wildcards)
911
-		$replacements += array(
974
+	if ($translate_human_wildcards) {
975
+			$replacements += array(
912 976
 			'*' => '%',
913 977
 		);
978
+	}
914 979
 
915 980
 	return strtr($string, $replacements);
916 981
 }
@@ -924,8 +989,9 @@  discard block
 block discarded – undo
924 989
  */
925 990
 function smf_is_resource($result)
926 991
 {
927
-	if ($result instanceof mysqli_result)
928
-		return true;
992
+	if ($result instanceof mysqli_result) {
993
+			return true;
994
+	}
929 995
 
930 996
 	return false;
931 997
 }
Please login to merge, or discard this patch.
Sources/Subs-Boards.php 1 patch
Braces   +247 added lines, -175 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
  * Mark a board or multiple boards read.
@@ -28,14 +29,16 @@  discard block
 block discarded – undo
28 29
 	global $user_info, $modSettings, $smcFunc;
29 30
 
30 31
 	// Force $boards to be an array.
31
-	if (!is_array($boards))
32
-		$boards = array($boards);
33
-	else
34
-		$boards = array_unique($boards);
32
+	if (!is_array($boards)) {
33
+			$boards = array($boards);
34
+	} else {
35
+			$boards = array_unique($boards);
36
+	}
35 37
 
36 38
 	// No boards, nothing to mark as read.
37
-	if (empty($boards))
38
-		return;
39
+	if (empty($boards)) {
40
+			return;
41
+	}
39 42
 
40 43
 	// Allow the user to mark a board as unread.
41 44
 	if ($unread)
@@ -65,8 +68,9 @@  discard block
 block discarded – undo
65 68
 	else
66 69
 	{
67 70
 		$markRead = array();
68
-		foreach ($boards as $board)
69
-			$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $board);
71
+		foreach ($boards as $board) {
72
+					$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $board);
73
+		}
70 74
 
71 75
 		// Update log_mark_read and log_boards.
72 76
 		$smcFunc['db_insert']('replace',
@@ -99,8 +103,9 @@  discard block
 block discarded – undo
99 103
 	list ($lowest_topic) = $smcFunc['db_fetch_row']($result);
100 104
 	$smcFunc['db_free_result']($result);
101 105
 
102
-	if (empty($lowest_topic))
103
-		return;
106
+	if (empty($lowest_topic)) {
107
+			return;
108
+	}
104 109
 
105 110
 	// @todo SLOW This query seems to eat it sometimes.
106 111
 	$result = $smcFunc['db_query']('', '
@@ -118,12 +123,13 @@  discard block
 block discarded – undo
118 123
 		)
119 124
 	);
120 125
 	$topics = array();
121
-	while ($row = $smcFunc['db_fetch_assoc']($result))
122
-		$topics[] = $row['id_topic'];
126
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
127
+			$topics[] = $row['id_topic'];
128
+	}
123 129
 	$smcFunc['db_free_result']($result);
124 130
 
125
-	if (!empty($topics))
126
-		$smcFunc['db_query']('', '
131
+	if (!empty($topics)) {
132
+			$smcFunc['db_query']('', '
127 133
 			DELETE FROM {db_prefix}log_topics
128 134
 			WHERE id_member = {int:current_member}
129 135
 				AND id_topic IN ({array_int:topic_list})',
@@ -132,7 +138,8 @@  discard block
 block discarded – undo
132 138
 				'topic_list' => $topics,
133 139
 			)
134 140
 		);
135
-}
141
+	}
142
+	}
136 143
 
137 144
 /**
138 145
  * Mark one or more boards as read.
@@ -157,23 +164,26 @@  discard block
 block discarded – undo
157 164
 			)
158 165
 		);
159 166
 		$boards = array();
160
-		while ($row = $smcFunc['db_fetch_assoc']($result))
161
-			$boards[] = $row['id_board'];
167
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
168
+					$boards[] = $row['id_board'];
169
+		}
162 170
 		$smcFunc['db_free_result']($result);
163 171
 
164
-		if (!empty($boards))
165
-			markBoardsRead($boards, isset($_REQUEST['unread']));
172
+		if (!empty($boards)) {
173
+					markBoardsRead($boards, isset($_REQUEST['unread']));
174
+		}
166 175
 
167 176
 		$_SESSION['id_msg_last_visit'] = $modSettings['maxMsgID'];
168
-		if (!empty($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'action=unread') !== false)
169
-			redirectexit('action=unread');
177
+		if (!empty($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'action=unread') !== false) {
178
+					redirectexit('action=unread');
179
+		}
170 180
 
171
-		if (isset($_SESSION['topicseen_cache']))
172
-			$_SESSION['topicseen_cache'] = array();
181
+		if (isset($_SESSION['topicseen_cache'])) {
182
+					$_SESSION['topicseen_cache'] = array();
183
+		}
173 184
 
174 185
 		redirectexit();
175
-	}
176
-	elseif (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'unreadreplies')
186
+	} elseif (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'unreadreplies')
177 187
 	{
178 188
 		// Make sure all the topics are integers!
179 189
 		$topics = array_map('intval', explode('-', $_REQUEST['topics']));
@@ -189,13 +199,15 @@  discard block
 block discarded – undo
189 199
 			)
190 200
 		);
191 201
 		$logged_topics = array();
192
-		while ($row = $smcFunc['db_fetch_assoc']($request))
193
-			$logged_topics[$row['id_topic']] = $row['unwatched'];
202
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
203
+					$logged_topics[$row['id_topic']] = $row['unwatched'];
204
+		}
194 205
 		$smcFunc['db_free_result']($request);
195 206
 
196 207
 		$markRead = array();
197
-		foreach ($topics as $id_topic)
198
-			$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $id_topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
208
+		foreach ($topics as $id_topic) {
209
+					$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $id_topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
210
+		}
199 211
 
200 212
 		$smcFunc['db_insert']('replace',
201 213
 			'{db_prefix}log_topics',
@@ -204,8 +216,9 @@  discard block
 block discarded – undo
204 216
 			array('id_member', 'id_topic')
205 217
 		);
206 218
 
207
-		if (isset($_SESSION['topicseen_cache']))
208
-			$_SESSION['topicseen_cache'] = array();
219
+		if (isset($_SESSION['topicseen_cache'])) {
220
+					$_SESSION['topicseen_cache'] = array();
221
+		}
209 222
 
210 223
 		redirectexit('action=unreadreplies');
211 224
 	}
@@ -230,11 +243,13 @@  discard block
 block discarded – undo
230 243
 		if (!empty($_GET['t']))
231 244
 		{
232 245
 			// If they read the whole topic, go back to the beginning.
233
-			if ($_GET['t'] >= $topicinfo['id_last_msg'])
234
-				$earlyMsg = 0;
246
+			if ($_GET['t'] >= $topicinfo['id_last_msg']) {
247
+							$earlyMsg = 0;
248
+			}
235 249
 			// If they want to mark the whole thing read, same.
236
-			elseif ($_GET['t'] <= $topicinfo['id_first_msg'])
237
-				$earlyMsg = 0;
250
+			elseif ($_GET['t'] <= $topicinfo['id_first_msg']) {
251
+							$earlyMsg = 0;
252
+			}
238 253
 			// Otherwise, get the latest message before the named one.
239 254
 			else
240 255
 			{
@@ -255,9 +270,9 @@  discard block
 block discarded – undo
255 270
 			}
256 271
 		}
257 272
 		// Marking read from first page?  That's the whole topic.
258
-		elseif ($_REQUEST['start'] == 0)
259
-			$earlyMsg = 0;
260
-		else
273
+		elseif ($_REQUEST['start'] == 0) {
274
+					$earlyMsg = 0;
275
+		} else
261 276
 		{
262 277
 			$result = $smcFunc['db_query']('', '
263 278
 				SELECT id_msg
@@ -285,8 +300,7 @@  discard block
 block discarded – undo
285 300
 		);
286 301
 
287 302
 		redirectexit('board=' . $board . '.0');
288
-	}
289
-	else
303
+	} else
290 304
 	{
291 305
 		$categories = array();
292 306
 		$boards = array();
@@ -294,17 +308,20 @@  discard block
 block discarded – undo
294 308
 		if (isset($_REQUEST['c']))
295 309
 		{
296 310
 			$_REQUEST['c'] = explode(',', $_REQUEST['c']);
297
-			foreach ($_REQUEST['c'] as $c)
298
-				$categories[] = (int) $c;
311
+			foreach ($_REQUEST['c'] as $c) {
312
+							$categories[] = (int) $c;
313
+			}
299 314
 		}
300 315
 		if (isset($_REQUEST['boards']))
301 316
 		{
302 317
 			$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
303
-			foreach ($_REQUEST['boards'] as $b)
304
-				$boards[] = (int) $b;
318
+			foreach ($_REQUEST['boards'] as $b) {
319
+							$boards[] = (int) $b;
320
+			}
321
+		}
322
+		if (!empty($board)) {
323
+					$boards[] = (int) $board;
305 324
 		}
306
-		if (!empty($board))
307
-			$boards[] = (int) $board;
308 325
 
309 326
 		if (isset($_REQUEST['children']) && !empty($boards))
310 327
 		{
@@ -324,9 +341,10 @@  discard block
 block discarded – undo
324 341
 					'board_list' => $boards,
325 342
 				)
326 343
 			);
327
-			while ($row = $smcFunc['db_fetch_assoc']($request))
328
-				if (in_array($row['id_parent'], $boards))
344
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
345
+							if (in_array($row['id_parent'], $boards))
329 346
 					$boards[] = $row['id_board'];
347
+			}
330 348
 			$smcFunc['db_free_result']($request);
331 349
 		}
332 350
 
@@ -343,8 +361,9 @@  discard block
 block discarded – undo
343 361
 			$clauseParameters['board_list'] = $boards;
344 362
 		}
345 363
 
346
-		if (empty($clauses))
347
-			redirectexit();
364
+		if (empty($clauses)) {
365
+					redirectexit();
366
+		}
348 367
 
349 368
 		$request = $smcFunc['db_query']('', '
350 369
 			SELECT b.id_board
@@ -355,19 +374,22 @@  discard block
 block discarded – undo
355 374
 			))
356 375
 		);
357 376
 		$boards = array();
358
-		while ($row = $smcFunc['db_fetch_assoc']($request))
359
-			$boards[] = $row['id_board'];
377
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
378
+					$boards[] = $row['id_board'];
379
+		}
360 380
 		$smcFunc['db_free_result']($request);
361 381
 
362
-		if (empty($boards))
363
-			redirectexit();
382
+		if (empty($boards)) {
383
+					redirectexit();
384
+		}
364 385
 
365 386
 		markBoardsRead($boards, isset($_REQUEST['unread']));
366 387
 
367 388
 		foreach ($boards as $b)
368 389
 		{
369
-			if (isset($_SESSION['topicseen_cache'][$b]))
370
-				$_SESSION['topicseen_cache'][$b] = array();
390
+			if (isset($_SESSION['topicseen_cache'][$b])) {
391
+							$_SESSION['topicseen_cache'][$b] = array();
392
+			}
371 393
 		}
372 394
 
373 395
 		if (!isset($_REQUEST['unread']))
@@ -385,8 +407,9 @@  discard block
 block discarded – undo
385 407
 			if ($smcFunc['db_num_rows']($result) > 0)
386 408
 			{
387 409
 				$logBoardInserts = array();
388
-				while ($row = $smcFunc['db_fetch_assoc']($result))
389
-					$logBoardInserts[] = array($modSettings['maxMsgID'], $user_info['id'], $row['id_board']);
410
+				while ($row = $smcFunc['db_fetch_assoc']($result)) {
411
+									$logBoardInserts[] = array($modSettings['maxMsgID'], $user_info['id'], $row['id_board']);
412
+				}
390 413
 
391 414
 				$smcFunc['db_insert']('replace',
392 415
 					'{db_prefix}log_boards',
@@ -397,17 +420,18 @@  discard block
 block discarded – undo
397 420
 			}
398 421
 			$smcFunc['db_free_result']($result);
399 422
 
400
-			if (empty($board))
401
-				redirectexit();
402
-			else
403
-				redirectexit('board=' . $board . '.0');
404
-		}
405
-		else
423
+			if (empty($board)) {
424
+							redirectexit();
425
+			} else {
426
+							redirectexit('board=' . $board . '.0');
427
+			}
428
+		} else
406 429
 		{
407
-			if (empty($board_info['parent']))
408
-				redirectexit();
409
-			else
410
-				redirectexit('board=' . $board_info['parent'] . '.0');
430
+			if (empty($board_info['parent'])) {
431
+							redirectexit();
432
+			} else {
433
+							redirectexit('board=' . $board_info['parent'] . '.0');
434
+			}
411 435
 		}
412 436
 	}
413 437
 }
@@ -432,11 +456,13 @@  discard block
 block discarded – undo
432 456
 			'selected_message' => (int) $messageID,
433 457
 		)
434 458
 	);
435
-	if ($smcFunc['db_num_rows']($result) > 0)
436
-		list ($memberID) = $smcFunc['db_fetch_row']($result);
459
+	if ($smcFunc['db_num_rows']($result) > 0) {
460
+			list ($memberID) = $smcFunc['db_fetch_row']($result);
461
+	}
437 462
 	// The message doesn't even exist.
438
-	else
439
-		$memberID = 0;
463
+	else {
464
+			$memberID = 0;
465
+	}
440 466
 	$smcFunc['db_free_result']($result);
441 467
 
442 468
 	return (int) $memberID;
@@ -457,8 +483,9 @@  discard block
 block discarded – undo
457 483
 	getBoardTree();
458 484
 
459 485
 	// Make sure given boards and categories exist.
460
-	if (!isset($boards[$board_id]) || (isset($boardOptions['target_board']) && !isset($boards[$boardOptions['target_board']])) || (isset($boardOptions['target_category']) && !isset($cat_tree[$boardOptions['target_category']])))
461
-		fatal_lang_error('no_board');
486
+	if (!isset($boards[$board_id]) || (isset($boardOptions['target_board']) && !isset($boards[$boardOptions['target_board']])) || (isset($boardOptions['target_category']) && !isset($cat_tree[$boardOptions['target_category']]))) {
487
+			fatal_lang_error('no_board');
488
+	}
462 489
 
463 490
 	$id = $board_id;
464 491
 	call_integration_hook('integrate_pre_modify_board', array($id, &$boardOptions));
@@ -486,8 +513,9 @@  discard block
 block discarded – undo
486 513
 			$child_level = 0;
487 514
 			$id_parent = 0;
488 515
 			$after = 0;
489
-			foreach ($cat_tree[$id_cat]['children'] as $id_board => $dummy)
490
-				$after = max($after, $boards[$id_board]['order']);
516
+			foreach ($cat_tree[$id_cat]['children'] as $id_board => $dummy) {
517
+							$after = max($after, $boards[$id_board]['order']);
518
+			}
491 519
 		}
492 520
 
493 521
 		// Make the board a child of a given board.
@@ -498,17 +526,19 @@  discard block
 block discarded – undo
498 526
 			$id_parent = $boardOptions['target_board'];
499 527
 
500 528
 			// People can be creative, in many ways...
501
-			if (isChildOf($id_parent, $board_id))
502
-				fatal_lang_error('mboards_parent_own_child_error', false);
503
-			elseif ($id_parent == $board_id)
504
-				fatal_lang_error('mboards_board_own_child_error', false);
529
+			if (isChildOf($id_parent, $board_id)) {
530
+							fatal_lang_error('mboards_parent_own_child_error', false);
531
+			} elseif ($id_parent == $board_id) {
532
+							fatal_lang_error('mboards_board_own_child_error', false);
533
+			}
505 534
 
506 535
 			$after = $boards[$boardOptions['target_board']]['order'];
507 536
 
508 537
 			// Check if there are already children and (if so) get the max board order.
509
-			if (!empty($boards[$id_parent]['tree']['children']) && empty($boardOptions['move_first_child']))
510
-				foreach ($boards[$id_parent]['tree']['children'] as $childBoard_id => $dummy)
538
+			if (!empty($boards[$id_parent]['tree']['children']) && empty($boardOptions['move_first_child'])) {
539
+							foreach ($boards[$id_parent]['tree']['children'] as $childBoard_id => $dummy)
511 540
 					$after = max($after, $boards[$childBoard_id]['order']);
541
+			}
512 542
 		}
513 543
 
514 544
 		// Place a board before or after another board, on the same child level.
@@ -521,8 +551,9 @@  discard block
 block discarded – undo
521 551
 		}
522 552
 
523 553
 		// Oops...?
524
-		else
525
-			trigger_error('modifyBoard(): The move_to value \'' . $boardOptions['move_to'] . '\' is incorrect', E_USER_ERROR);
554
+		else {
555
+					trigger_error('modifyBoard(): The move_to value \'' . $boardOptions['move_to'] . '\' is incorrect', E_USER_ERROR);
556
+		}
526 557
 
527 558
 		// Get a list of children of this board.
528 559
 		$childList = array();
@@ -531,14 +562,16 @@  discard block
 block discarded – undo
531 562
 		// See if there are changes that affect children.
532 563
 		$childUpdates = array();
533 564
 		$levelDiff = $child_level - $boards[$board_id]['level'];
534
-		if ($levelDiff != 0)
535
-			$childUpdates[] = 'child_level = child_level ' . ($levelDiff > 0 ? '+ ' : '') . '{int:level_diff}';
536
-		if ($id_cat != $boards[$board_id]['category'])
537
-			$childUpdates[] = 'id_cat = {int:category}';
565
+		if ($levelDiff != 0) {
566
+					$childUpdates[] = 'child_level = child_level ' . ($levelDiff > 0 ? '+ ' : '') . '{int:level_diff}';
567
+		}
568
+		if ($id_cat != $boards[$board_id]['category']) {
569
+					$childUpdates[] = 'id_cat = {int:category}';
570
+		}
538 571
 
539 572
 		// Fix the children of this board.
540
-		if (!empty($childList) && !empty($childUpdates))
541
-			$smcFunc['db_query']('', '
573
+		if (!empty($childList) && !empty($childUpdates)) {
574
+					$smcFunc['db_query']('', '
542 575
 				UPDATE {db_prefix}boards
543 576
 				SET ' . implode(',
544 577
 					', $childUpdates) . '
@@ -549,6 +582,7 @@  discard block
 block discarded – undo
549 582
 					'level_diff' => $levelDiff,
550 583
 				)
551 584
 			);
585
+		}
552 586
 
553 587
 		// Make some room for this spot.
554 588
 		$smcFunc['db_query']('', '
@@ -644,8 +678,8 @@  discard block
 block discarded – undo
644 678
 	call_integration_hook('integrate_modify_board', array($id, $boardOptions, &$boardUpdates, &$boardUpdateParameters));
645 679
 
646 680
 	// Do the updates (if any).
647
-	if (!empty($boardUpdates))
648
-		$smcFunc['db_query']('', '
681
+	if (!empty($boardUpdates)) {
682
+			$smcFunc['db_query']('', '
649 683
 			UPDATE {db_prefix}boards
650 684
 			SET
651 685
 				' . implode(',
@@ -655,6 +689,7 @@  discard block
 block discarded – undo
655 689
 				'selected_board' => $board_id,
656 690
 			))
657 691
 		);
692
+	}
658 693
 
659 694
 	// Set moderators of this board.
660 695
 	if (isset($boardOptions['moderators']) || isset($boardOptions['moderator_string']) || isset($boardOptions['moderator_groups']) || isset($boardOptions['moderator_group_string']))
@@ -679,13 +714,15 @@  discard block
 block discarded – undo
679 714
 			{
680 715
 				$moderators[$k] = trim($moderators[$k]);
681 716
 
682
-				if (strlen($moderators[$k]) == 0)
683
-					unset($moderators[$k]);
717
+				if (strlen($moderators[$k]) == 0) {
718
+									unset($moderators[$k]);
719
+				}
684 720
 			}
685 721
 
686 722
 			// Find all the id_member's for the member_name's in the list.
687
-			if (empty($boardOptions['moderators']))
688
-				$boardOptions['moderators'] = array();
723
+			if (empty($boardOptions['moderators'])) {
724
+							$boardOptions['moderators'] = array();
725
+			}
689 726
 			if (!empty($moderators))
690 727
 			{
691 728
 				$request = $smcFunc['db_query']('', '
@@ -698,8 +735,9 @@  discard block
 block discarded – undo
698 735
 						'limit' => count($moderators),
699 736
 					)
700 737
 				);
701
-				while ($row = $smcFunc['db_fetch_assoc']($request))
702
-					$boardOptions['moderators'][] = $row['id_member'];
738
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
739
+									$boardOptions['moderators'][] = $row['id_member'];
740
+				}
703 741
 				$smcFunc['db_free_result']($request);
704 742
 			}
705 743
 		}
@@ -708,8 +746,9 @@  discard block
 block discarded – undo
708 746
 		if (!empty($boardOptions['moderators']))
709 747
 		{
710 748
 			$inserts = array();
711
-			foreach ($boardOptions['moderators'] as $moderator)
712
-				$inserts[] = array($board_id, $moderator);
749
+			foreach ($boardOptions['moderators'] as $moderator) {
750
+							$inserts[] = array($board_id, $moderator);
751
+			}
713 752
 
714 753
 			$smcFunc['db_insert']('insert',
715 754
 				'{db_prefix}moderators',
@@ -739,14 +778,16 @@  discard block
 block discarded – undo
739 778
 			{
740 779
 				$moderator_groups[$k] = trim($moderator_groups[$k]);
741 780
 
742
-				if (strlen($moderator_groups[$k]) == 0)
743
-					unset($moderator_groups[$k]);
781
+				if (strlen($moderator_groups[$k]) == 0) {
782
+									unset($moderator_groups[$k]);
783
+				}
744 784
 			}
745 785
 
746 786
 			/* 	Find all the id_group's for all the group names in the list
747 787
 				But skip any invalid ones (invisible/post groups/Administrator/Moderator) */
748
-			if (empty($boardOptions['moderator_groups']))
749
-				$boardOptions['moderator_groups'] = array();
788
+			if (empty($boardOptions['moderator_groups'])) {
789
+							$boardOptions['moderator_groups'] = array();
790
+			}
750 791
 			if (!empty($moderator_groups))
751 792
 			{
752 793
 				$request = $smcFunc['db_query']('', '
@@ -777,8 +818,9 @@  discard block
 block discarded – undo
777 818
 		if (!empty($boardOptions['moderator_groups']))
778 819
 		{
779 820
 			$inserts = array();
780
-			foreach ($boardOptions['moderator_groups'] as $moderator_group)
781
-				$inserts[] = array($board_id, $moderator_group);
821
+			foreach ($boardOptions['moderator_groups'] as $moderator_group) {
822
+							$inserts[] = array($board_id, $moderator_group);
823
+			}
782 824
 
783 825
 			$smcFunc['db_insert']('insert',
784 826
 				'{db_prefix}moderator_groups',
@@ -792,14 +834,16 @@  discard block
 block discarded – undo
792 834
 		updateSettings(array('settings_updated' => time()));
793 835
 	}
794 836
 
795
-	if (isset($boardOptions['move_to']))
796
-		reorderBoards();
837
+	if (isset($boardOptions['move_to'])) {
838
+			reorderBoards();
839
+	}
797 840
 
798 841
 	clean_cache('data');
799 842
 
800
-	if (empty($boardOptions['dont_log']))
801
-		logAction('edit_board', array('board' => $board_id), 'admin');
802
-}
843
+	if (empty($boardOptions['dont_log'])) {
844
+			logAction('edit_board', array('board' => $board_id), 'admin');
845
+	}
846
+	}
803 847
 
804 848
 /**
805 849
  * Create a new board and set its properties and position.
@@ -815,11 +859,13 @@  discard block
 block discarded – undo
815 859
 	global $boards, $smcFunc;
816 860
 
817 861
 	// Trigger an error if one of the required values is not set.
818
-	if (!isset($boardOptions['board_name']) || trim($boardOptions['board_name']) == '' || !isset($boardOptions['move_to']) || !isset($boardOptions['target_category']))
819
-		trigger_error('createBoard(): One or more of the required options is not set', E_USER_ERROR);
862
+	if (!isset($boardOptions['board_name']) || trim($boardOptions['board_name']) == '' || !isset($boardOptions['move_to']) || !isset($boardOptions['target_category'])) {
863
+			trigger_error('createBoard(): One or more of the required options is not set', E_USER_ERROR);
864
+	}
820 865
 
821
-	if (in_array($boardOptions['move_to'], array('child', 'before', 'after')) && !isset($boardOptions['target_board']))
822
-		trigger_error('createBoard(): Target board is not set', E_USER_ERROR);
866
+	if (in_array($boardOptions['move_to'], array('child', 'before', 'after')) && !isset($boardOptions['target_board'])) {
867
+			trigger_error('createBoard(): Target board is not set', E_USER_ERROR);
868
+	}
823 869
 
824 870
 	// Set every optional value to its default value.
825 871
 	$boardOptions += array(
@@ -853,8 +899,9 @@  discard block
 block discarded – undo
853 899
 		1
854 900
 	);
855 901
 
856
-	if (empty($board_id))
857
-		return 0;
902
+	if (empty($board_id)) {
903
+			return 0;
904
+	}
858 905
 
859 906
 	// Change the board according to the given specifications.
860 907
 	modifyBoard($board_id, $boardOptions);
@@ -917,8 +964,9 @@  discard block
 block discarded – undo
917 964
 	global $sourcedir, $boards, $smcFunc;
918 965
 
919 966
 	// No boards to delete? Return!
920
-	if (empty($boards_to_remove))
921
-		return;
967
+	if (empty($boards_to_remove)) {
968
+			return;
969
+	}
922 970
 
923 971
 	getBoardTree();
924 972
 
@@ -929,12 +977,14 @@  discard block
 block discarded – undo
929 977
 	{
930 978
 		// Get a list of the child boards that will also be removed.
931 979
 		$child_boards_to_remove = array();
932
-		foreach ($boards_to_remove as $board_to_remove)
933
-			recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']);
980
+		foreach ($boards_to_remove as $board_to_remove) {
981
+					recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']);
982
+		}
934 983
 
935 984
 		// Merge the children with their parents.
936
-		if (!empty($child_boards_to_remove))
937
-			$boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove));
985
+		if (!empty($child_boards_to_remove)) {
986
+					$boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove));
987
+		}
938 988
 	}
939 989
 	// Move the children to a safe home.
940 990
 	else
@@ -942,10 +992,11 @@  discard block
 block discarded – undo
942 992
 		foreach ($boards_to_remove as $id_board)
943 993
 		{
944 994
 			// @todo Separate category?
945
-			if ($moveChildrenTo === 0)
946
-				fixChildren($id_board, 0, 0);
947
-			else
948
-				fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo);
995
+			if ($moveChildrenTo === 0) {
996
+							fixChildren($id_board, 0, 0);
997
+			} else {
998
+							fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo);
999
+			}
949 1000
 		}
950 1001
 	}
951 1002
 
@@ -959,8 +1010,9 @@  discard block
 block discarded – undo
959 1010
 		)
960 1011
 	);
961 1012
 	$topics = array();
962
-	while ($row = $smcFunc['db_fetch_assoc']($request))
963
-		$topics[] = $row['id_topic'];
1013
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1014
+			$topics[] = $row['id_topic'];
1015
+	}
964 1016
 	$smcFunc['db_free_result']($request);
965 1017
 
966 1018
 	require_once($sourcedir . '/RemoveTopic.php');
@@ -1048,8 +1100,9 @@  discard block
 block discarded – undo
1048 1100
 	clean_cache('data');
1049 1101
 
1050 1102
 	// Let's do some serious logging.
1051
-	foreach ($boards_to_remove as $id_board)
1052
-		logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin');
1103
+	foreach ($boards_to_remove as $id_board) {
1104
+			logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin');
1105
+	}
1053 1106
 
1054 1107
 	reorderBoards();
1055 1108
 }
@@ -1068,8 +1121,8 @@  discard block
 block discarded – undo
1068 1121
 	$board_order = 0;
1069 1122
 	foreach ($cat_tree as $catID => $dummy)
1070 1123
 	{
1071
-		foreach ($boardList[$catID] as $boardID)
1072
-			if ($boards[$boardID]['order'] != ++$board_order)
1124
+		foreach ($boardList[$catID] as $boardID) {
1125
+					if ($boards[$boardID]['order'] != ++$board_order)
1073 1126
 				$smcFunc['db_query']('', '
1074 1127
 					UPDATE {db_prefix}boards
1075 1128
 					SET board_order = {int:new_order}
@@ -1079,6 +1132,7 @@  discard block
 block discarded – undo
1079 1132
 						'selected_board' => $boardID,
1080 1133
 					)
1081 1134
 				);
1135
+		}
1082 1136
 	}
1083 1137
 
1084 1138
 	// Empty the board order cache
@@ -1107,8 +1161,9 @@  discard block
 block discarded – undo
1107 1161
 		)
1108 1162
 	);
1109 1163
 	$children = array();
1110
-	while ($row = $smcFunc['db_fetch_assoc']($result))
1111
-		$children[] = $row['id_board'];
1164
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
1165
+			$children[] = $row['id_board'];
1166
+	}
1112 1167
 	$smcFunc['db_free_result']($result);
1113 1168
 
1114 1169
 	// ...and set it to a new parent and child_level.
@@ -1124,9 +1179,10 @@  discard block
 block discarded – undo
1124 1179
 	);
1125 1180
 
1126 1181
 	// Recursively fix the children of the children.
1127
-	foreach ($children as $child)
1128
-		fixChildren($child, $newLevel + 1, $child);
1129
-}
1182
+	foreach ($children as $child) {
1183
+			fixChildren($child, $newLevel + 1, $child);
1184
+	}
1185
+	}
1130 1186
 
1131 1187
 /**
1132 1188
  * Tries to load up the entire board order and category very very quickly
@@ -1143,8 +1199,9 @@  discard block
 block discarded – undo
1143 1199
 		'boards' => array(),
1144 1200
 	);
1145 1201
 
1146
-	if (!empty($tree_order['boards']))
1147
-		return $tree_order;
1202
+	if (!empty($tree_order['boards'])) {
1203
+			return $tree_order;
1204
+	}
1148 1205
 
1149 1206
 	if (($cached = cache_get_data('board_order', 86400)) !== null)
1150 1207
 	{
@@ -1160,8 +1217,9 @@  discard block
 block discarded – undo
1160 1217
 	);
1161 1218
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1162 1219
 	{
1163
-		if (!in_array($row['id_cat'], $tree_order['cats']))
1164
-			$tree_order['cats'][] = $row['id_cat'];
1220
+		if (!in_array($row['id_cat'], $tree_order['cats'])) {
1221
+					$tree_order['cats'][] = $row['id_cat'];
1222
+		}
1165 1223
 		$tree_order['boards'][] = $row['id_board'];
1166 1224
 	}
1167 1225
 	$smcFunc['db_free_result']($request);
@@ -1181,16 +1239,19 @@  discard block
 block discarded – undo
1181 1239
 	$tree = getTreeOrder();
1182 1240
 
1183 1241
 	$ordered = array();
1184
-	foreach ($tree['boards'] as $board)
1185
-		if (!empty($boards[$board]))
1242
+	foreach ($tree['boards'] as $board) {
1243
+			if (!empty($boards[$board]))
1186 1244
 		{
1187 1245
 			$ordered[$board] = $boards[$board];
1246
+	}
1188 1247
 
1189
-			if (is_array($ordered[$board]) && !empty($ordered[$board]['boards']))
1190
-				sortBoards($ordered[$board]['boards']);
1248
+			if (is_array($ordered[$board]) && !empty($ordered[$board]['boards'])) {
1249
+							sortBoards($ordered[$board]['boards']);
1250
+			}
1191 1251
 
1192
-			if (is_array($ordered[$board]) && !empty($ordered[$board]['children']))
1193
-				sortBoards($ordered[$board]['children']);
1252
+			if (is_array($ordered[$board]) && !empty($ordered[$board]['children'])) {
1253
+							sortBoards($ordered[$board]['children']);
1254
+			}
1194 1255
 		}
1195 1256
 
1196 1257
 	$boards = $ordered;
@@ -1206,12 +1267,14 @@  discard block
 block discarded – undo
1206 1267
 	$tree = getTreeOrder();
1207 1268
 
1208 1269
 	$ordered = array();
1209
-	foreach ($tree['cats'] as $cat)
1210
-		if (!empty($categories[$cat]))
1270
+	foreach ($tree['cats'] as $cat) {
1271
+			if (!empty($categories[$cat]))
1211 1272
 		{
1212 1273
 			$ordered[$cat] = $categories[$cat];
1213
-			if (!empty($ordered[$cat]['boards']))
1214
-				sortBoards($ordered[$cat]['boards']);
1274
+	}
1275
+			if (!empty($ordered[$cat]['boards'])) {
1276
+							sortBoards($ordered[$cat]['boards']);
1277
+			}
1215 1278
 		}
1216 1279
 
1217 1280
 	$categories = $ordered;
@@ -1227,8 +1290,9 @@  discard block
 block discarded – undo
1227 1290
 {
1228 1291
 	global $smcFunc, $scripturl, $txt;
1229 1292
 
1230
-	if (empty($boards))
1231
-		return array();
1293
+	if (empty($boards)) {
1294
+			return array();
1295
+	}
1232 1296
 
1233 1297
 	$request = $smcFunc['db_query']('', '
1234 1298
 		SELECT mem.id_member, mem.real_name, mo.id_board
@@ -1242,8 +1306,9 @@  discard block
 block discarded – undo
1242 1306
 	$moderators = array();
1243 1307
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1244 1308
 	{
1245
-		if (empty($moderators[$row['id_board']]))
1246
-			$moderators[$row['id_board']] = array();
1309
+		if (empty($moderators[$row['id_board']])) {
1310
+					$moderators[$row['id_board']] = array();
1311
+		}
1247 1312
 
1248 1313
 		$moderators[$row['id_board']][] = array(
1249 1314
 			'id' => $row['id_member'],
@@ -1267,8 +1332,9 @@  discard block
 block discarded – undo
1267 1332
 {
1268 1333
 	global $smcFunc, $scripturl, $txt;
1269 1334
 
1270
-	if (empty($boards))
1271
-		return array();
1335
+	if (empty($boards)) {
1336
+			return array();
1337
+	}
1272 1338
 
1273 1339
 	$request = $smcFunc['db_query']('', '
1274 1340
 		SELECT mg.id_group, mg.group_name, bg.id_board
@@ -1282,8 +1348,9 @@  discard block
 block discarded – undo
1282 1348
 	$groups = array();
1283 1349
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1284 1350
 	{
1285
-		if (empty($groups[$row['id_board']]))
1286
-			$groups[$row['id_board']] = array();
1351
+		if (empty($groups[$row['id_board']])) {
1352
+					$groups[$row['id_board']] = array();
1353
+		}
1287 1354
 
1288 1355
 		$groups[$row['id_board']][] = array(
1289 1356
 			'id' => $row['id_group'],
@@ -1358,8 +1425,9 @@  discard block
 block discarded – undo
1358 1425
 
1359 1426
 		if (!empty($row['id_board']))
1360 1427
 		{
1361
-			if ($row['child_level'] != $curLevel)
1362
-				$prevBoard = 0;
1428
+			if ($row['child_level'] != $curLevel) {
1429
+							$prevBoard = 0;
1430
+			}
1363 1431
 
1364 1432
 			$boards[$row['id_board']] = array(
1365 1433
 				'id' => $row['id_board'],
@@ -1391,16 +1459,16 @@  discard block
 block discarded – undo
1391 1459
 					'children' => array()
1392 1460
 				);
1393 1461
 				$boards[$row['id_board']]['tree'] = &$cat_tree[$row['id_cat']]['children'][$row['id_board']];
1394
-			}
1395
-			else
1462
+			} else
1396 1463
 			{
1397 1464
 				// Parent doesn't exist!
1398
-				if (!isset($boards[$row['id_parent']]['tree']))
1399
-					fatal_lang_error('no_valid_parent', false, array($row['board_name']));
1465
+				if (!isset($boards[$row['id_parent']]['tree'])) {
1466
+									fatal_lang_error('no_valid_parent', false, array($row['board_name']));
1467
+				}
1400 1468
 
1401 1469
 				// Wrong childlevel...we can silently fix this...
1402
-				if ($boards[$row['id_parent']]['tree']['node']['level'] != $row['child_level'] - 1)
1403
-					$smcFunc['db_query']('', '
1470
+				if ($boards[$row['id_parent']]['tree']['node']['level'] != $row['child_level'] - 1) {
1471
+									$smcFunc['db_query']('', '
1404 1472
 						UPDATE {db_prefix}boards
1405 1473
 						SET child_level = {int:new_child_level}
1406 1474
 						WHERE id_board = {int:selected_board}',
@@ -1409,6 +1477,7 @@  discard block
 block discarded – undo
1409 1477
 							'selected_board' => $row['id_board'],
1410 1478
 						)
1411 1479
 					);
1480
+				}
1412 1481
 
1413 1482
 				$boards[$row['id_parent']]['tree']['children'][$row['id_board']] = array(
1414 1483
 					'node' => &$boards[$row['id_board']],
@@ -1442,8 +1511,9 @@  discard block
 block discarded – undo
1442 1511
  */
1443 1512
 function recursiveBoards(&$_boardList, &$_tree)
1444 1513
 {
1445
-	if (empty($_tree['children']))
1446
-		return;
1514
+	if (empty($_tree['children'])) {
1515
+			return;
1516
+	}
1447 1517
 
1448 1518
 	foreach ($_tree['children'] as $id => $node)
1449 1519
 	{
@@ -1462,11 +1532,13 @@  discard block
 block discarded – undo
1462 1532
 {
1463 1533
 	global $boards;
1464 1534
 
1465
-	if (empty($boards[$child]['parent']))
1466
-		return false;
1535
+	if (empty($boards[$child]['parent'])) {
1536
+			return false;
1537
+	}
1467 1538
 
1468
-	if ($boards[$child]['parent'] == $parent)
1469
-		return true;
1539
+	if ($boards[$child]['parent'] == $parent) {
1540
+			return true;
1541
+	}
1470 1542
 
1471 1543
 	return isChildOf($boards[$child]['parent'], $parent);
1472 1544
 }
Please login to merge, or discard this patch.
Sources/Display.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 		call_integration_hook('integrate_poll_buttons');
825 825
 	}
826 826
 	
827
-	if(!empty($_REQUEST['page_id']))
827
+	if (!empty($_REQUEST['page_id']))
828 828
 		$start_char = substr($_REQUEST['page_id'], 0, 1);
829 829
 	else
830 830
 		$start_char = null;
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
 			SELECT id_msg, id_member, approved
887 887
 			FROM {db_prefix}messages
888 888
 			WHERE id_topic = {int:current_topic} 
889
-			AND id_msg '. $page_operator . ' {int:page_id}'. (!$modSettings['postmod_active'] || $approve_posts ? '' : '
889
+			AND id_msg '. $page_operator . ' {int:page_id}' . (!$modSettings['postmod_active'] || $approve_posts ? '' : '
890 890
 			AND (approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ')') . '
891 891
 			ORDER BY id_msg ' . ($ascending ? '' : 'DESC') . ($context['messages_per_page'] == -1 ? '' : '
892 892
 			LIMIT {int:limit}'),
Please login to merge, or discard this patch.
Braces   +349 added lines, -263 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * The central part of the board - topic display.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	global $messages_request, $language, $smcFunc;
35 36
 
36 37
 	// What are you gonna display if these are empty?!
37
-	if (empty($topic))
38
-		fatal_lang_error('no_board', false);
38
+	if (empty($topic)) {
39
+			fatal_lang_error('no_board', false);
40
+	}
39 41
 
40 42
 	// Load the proper template.
41 43
 	loadTemplate('Display');
@@ -52,15 +54,17 @@  discard block
 block discarded – undo
52 54
 	$context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
53 55
 
54 56
 	// Let's do some work on what to search index.
55
-	if (count($_GET) > 2)
56
-		foreach ($_GET as $k => $v)
57
+	if (count($_GET) > 2) {
58
+			foreach ($_GET as $k => $v)
57 59
 		{
58 60
 			if (!in_array($k, array('topic', 'board', 'start', session_name())))
59 61
 				$context['robot_no_index'] = true;
62
+	}
60 63
 		}
61 64
 
62
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
63
-		$context['robot_no_index'] = true;
65
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
66
+			$context['robot_no_index'] = true;
67
+	}
64 68
 
65 69
 	// Find the previous or next topic.  Make a fuss if there are no more.
66 70
 	if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next'))
@@ -172,8 +176,9 @@  discard block
 block discarded – undo
172 176
 			$topic_parameters
173 177
 	);
174 178
 
175
-	if ($smcFunc['db_num_rows']($request) == 0)
176
-		fatal_lang_error('not_a_topic', false, 404);
179
+	if ($smcFunc['db_num_rows']($request) == 0) {
180
+			fatal_lang_error('not_a_topic', false, 404);
181
+	}
177 182
 	$context['topicinfo'] = $smcFunc['db_fetch_assoc']($request);
178 183
 	$smcFunc['db_free_result']($request);
179 184
 
@@ -210,8 +215,9 @@  discard block
 block discarded – undo
210 215
 	$context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0;
211 216
 
212 217
 	// Add up unapproved replies to get real number of replies...
213
-	if ($modSettings['postmod_active'] && $approve_posts)
214
-		$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
218
+	if ($modSettings['postmod_active'] && $approve_posts) {
219
+			$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
220
+	}
215 221
 
216 222
 	// If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing.
217 223
 	if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts)
@@ -231,11 +237,11 @@  discard block
 block discarded – undo
231 237
 		$smcFunc['db_free_result']($request);
232 238
 
233 239
 		$context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0);
240
+	} elseif ($user_info['is_guest']) {
241
+			$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
242
+	} else {
243
+			$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
234 244
 	}
235
-	elseif ($user_info['is_guest'])
236
-		$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
237
-	else
238
-		$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
239 245
 
240 246
 	// The start isn't a number; it's information about what to do, where to go.
241 247
 	if (!is_numeric($_REQUEST['start']))
@@ -248,8 +254,7 @@  discard block
 block discarded – undo
248 254
 			{
249 255
 				$context['start_from'] = $context['total_visible_posts'] - 1;
250 256
 				$_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0;
251
-			}
252
-			else
257
+			} else
253 258
 			{
254 259
 				// Find the earliest unread message in the topic. (the use of topics here is just for both tables.)
255 260
 				$request = $smcFunc['db_query']('', '
@@ -277,9 +282,9 @@  discard block
 block discarded – undo
277 282
 		if (substr($_REQUEST['start'], 0, 4) == 'from')
278 283
 		{
279 284
 			$timestamp = (int) substr($_REQUEST['start'], 4);
280
-			if ($timestamp === 0)
281
-				$_REQUEST['start'] = 0;
282
-			else
285
+			if ($timestamp === 0) {
286
+							$_REQUEST['start'] = 0;
287
+			} else
283 288
 			{
284 289
 				// Find the number of messages posted before said time...
285 290
 				$request = $smcFunc['db_query']('', '
@@ -307,11 +312,11 @@  discard block
 block discarded – undo
307 312
 		elseif (substr($_REQUEST['start'], 0, 3) == 'msg')
308 313
 		{
309 314
 			$virtual_msg = (int) substr($_REQUEST['start'], 3);
310
-			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg'])
311
-				$context['start_from'] = $context['total_visible_posts'] - 1;
312
-			elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg'])
313
-				$context['start_from'] = 0;
314
-			else
315
+			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) {
316
+							$context['start_from'] = $context['total_visible_posts'] - 1;
317
+			} elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) {
318
+							$context['start_from'] = 0;
319
+			} else
315 320
 			{
316 321
 				// Find the start value for that message......
317 322
 				$request = $smcFunc['db_query']('', '
@@ -394,21 +399,25 @@  discard block
 block discarded – undo
394 399
 		);
395 400
 		while ($row = $smcFunc['db_fetch_assoc']($request))
396 401
 		{
397
-			if (empty($row['id_member']))
398
-				continue;
402
+			if (empty($row['id_member'])) {
403
+							continue;
404
+			}
399 405
 
400
-			if (!empty($row['online_color']))
401
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
402
-			else
403
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
406
+			if (!empty($row['online_color'])) {
407
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
408
+			} else {
409
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
410
+			}
404 411
 
405 412
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
406
-			if ($is_buddy)
407
-				$link = '<strong>' . $link . '</strong>';
413
+			if ($is_buddy) {
414
+							$link = '<strong>' . $link . '</strong>';
415
+			}
408 416
 
409 417
 			// Add them both to the list and to the more detailed list.
410
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
411
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
418
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
419
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
420
+			}
412 421
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
413 422
 				'id' => $row['id_member'],
414 423
 				'username' => $row['member_name'],
@@ -420,8 +429,9 @@  discard block
 block discarded – undo
420 429
 				'hidden' => empty($row['show_online']),
421 430
 			);
422 431
 
423
-			if (empty($row['show_online']))
424
-				$context['view_num_hidden']++;
432
+			if (empty($row['show_online'])) {
433
+							$context['view_num_hidden']++;
434
+			}
425 435
 		}
426 436
 
427 437
 		// The number of guests is equal to the rows minus the ones we actually used ;).
@@ -435,11 +445,13 @@  discard block
 block discarded – undo
435 445
 
436 446
 	// If all is set, but not allowed... just unset it.
437 447
 	$can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages'];
438
-	if (isset($_REQUEST['all']) && !$can_show_all)
439
-		unset($_REQUEST['all']);
448
+	if (isset($_REQUEST['all']) && !$can_show_all) {
449
+			unset($_REQUEST['all']);
450
+	}
440 451
 	// Otherwise, it must be allowed... so pretend start was -1.
441
-	elseif (isset($_REQUEST['all']))
442
-		$_REQUEST['start'] = -1;
452
+	elseif (isset($_REQUEST['all'])) {
453
+			$_REQUEST['start'] = -1;
454
+	}
443 455
 
444 456
 	// Construct allowing for the .START method...
445 457
 	$context['start'] = $_REQUEST['start'];
@@ -475,14 +487,16 @@  discard block
 block discarded – undo
475 487
 	if (!empty($board_info['moderators']))
476 488
 	{
477 489
 		// Add a link for each moderator...
478
-		foreach ($board_info['moderators'] as $mod)
479
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
490
+		foreach ($board_info['moderators'] as $mod) {
491
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
492
+		}
480 493
 	}
481 494
 	if (!empty($board_info['moderator_groups']))
482 495
 	{
483 496
 		// Add a link for each moderator group as well...
484
-		foreach ($board_info['moderator_groups'] as $mod_group)
485
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
497
+		foreach ($board_info['moderator_groups'] as $mod_group) {
498
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
499
+		}
486 500
 	}
487 501
 
488 502
 	if (!empty($context['link_moderators']))
@@ -513,9 +527,9 @@  discard block
 block discarded – undo
513 527
 	// For quick reply we need a response prefix in the default forum language.
514 528
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600)))
515 529
 	{
516
-		if ($language === $user_info['language'])
517
-			$context['response_prefix'] = $txt['response_prefix'];
518
-		else
530
+		if ($language === $user_info['language']) {
531
+					$context['response_prefix'] = $txt['response_prefix'];
532
+		} else
519 533
 		{
520 534
 			loadLanguage('index', $language, false);
521 535
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -547,8 +561,9 @@  discard block
 block discarded – undo
547 561
 			list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
548 562
 
549 563
 			// Sanity check
550
-			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
551
-				continue;
564
+			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
565
+							continue;
566
+			}
552 567
 
553 568
 			$linked_calendar_event = array(
554 569
 				'id' => $row['id_event'],
@@ -597,8 +612,9 @@  discard block
 block discarded – undo
597 612
 		}
598 613
 		$smcFunc['db_free_result']($request);
599 614
 
600
-		if (!empty($context['linked_calendar_events']))
601
-			$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
615
+		if (!empty($context['linked_calendar_events'])) {
616
+					$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
617
+		}
602 618
 	}
603 619
 
604 620
 	// Create the poll info if it exists.
@@ -661,8 +677,9 @@  discard block
 block discarded – undo
661 677
 		$smcFunc['db_free_result']($request);
662 678
 		
663 679
 		// Got we multi choice?
664
-		if ($pollinfo['max_votes'] > 1)
665
-			$realtotal = $pollinfo['total'];
680
+		if ($pollinfo['max_votes'] > 1) {
681
+					$realtotal = $pollinfo['total'];
682
+		}
666 683
 
667 684
 		// If this is a guest we need to do our best to work out if they have voted, and what they voted for.
668 685
 		if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote'))
@@ -675,20 +692,21 @@  discard block
 block discarded – undo
675 692
 				foreach ($guestinfo as $i => $guestvoted)
676 693
 				{
677 694
 					$guestvoted = explode(',', $guestvoted);
678
-					if ($guestvoted[0] == $context['topicinfo']['id_poll'])
679
-						break;
695
+					if ($guestvoted[0] == $context['topicinfo']['id_poll']) {
696
+											break;
697
+					}
680 698
 				}
681 699
 				// Has the poll been reset since guest voted?
682 700
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
683 701
 				{
684 702
 					// Remove the poll info from the cookie to allow guest to vote again
685 703
 					unset($guestinfo[$i]);
686
-					if (!empty($guestinfo))
687
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
688
-					else
689
-						unset($_COOKIE['guest_poll_vote']);
690
-				}
691
-				else
704
+					if (!empty($guestinfo)) {
705
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
706
+					} else {
707
+											unset($_COOKIE['guest_poll_vote']);
708
+					}
709
+				} else
692 710
 				{
693 711
 					// What did they vote for?
694 712
 					unset($guestvoted[0], $guestvoted[1]);
@@ -802,35 +820,43 @@  discard block
 block discarded – undo
802 820
 		// Build the poll moderation button array.
803 821
 		$context['poll_buttons'] = array();
804 822
 
805
-		if ($context['allow_return_vote'])
806
-			$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
823
+		if ($context['allow_return_vote']) {
824
+					$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
825
+		}
807 826
 
808
-		if ($context['show_view_results_button'])
809
-			$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
827
+		if ($context['show_view_results_button']) {
828
+					$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
829
+		}
810 830
 
811
-		if ($context['allow_change_vote'])
812
-			$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
831
+		if ($context['allow_change_vote']) {
832
+					$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
833
+		}
813 834
 
814
-		if ($context['allow_lock_poll'])
815
-			$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
835
+		if ($context['allow_lock_poll']) {
836
+					$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
837
+		}
816 838
 
817
-		if ($context['allow_edit_poll'])
818
-			$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
839
+		if ($context['allow_edit_poll']) {
840
+					$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
841
+		}
819 842
 
820
-		if ($context['can_remove_poll'])
821
-			$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
843
+		if ($context['can_remove_poll']) {
844
+					$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
845
+		}
822 846
 
823 847
 		// Allow mods to add additional buttons here
824 848
 		call_integration_hook('integrate_poll_buttons');
825 849
 	}
826 850
 	
827
-	if(!empty($_REQUEST['page_id']))
828
-		$start_char = substr($_REQUEST['page_id'], 0, 1);
829
-	else
830
-		$start_char = null;
851
+	if(!empty($_REQUEST['page_id'])) {
852
+			$start_char = substr($_REQUEST['page_id'], 0, 1);
853
+	} else {
854
+			$start_char = null;
855
+	}
831 856
 
832
-	if ($start_char === 'M' || $start_char === 'L')
833
-		$page_id = substr($_REQUEST['page_id'], 1);
857
+	if ($start_char === 'M' || $start_char === 'L') {
858
+			$page_id = substr($_REQUEST['page_id'], 1);
859
+	}
834 860
 
835 861
 	$limit = $context['messages_per_page'];
836 862
  
@@ -866,8 +892,7 @@  discard block
 block discarded – undo
866 892
 				'max' => $limit,
867 893
 			)
868 894
 		);
869
-	}
870
-	else //next or before page
895
+	} else //next or before page
871 896
 	{
872 897
 		$firstIndex = 0;
873 898
 		
@@ -875,8 +900,7 @@  discard block
 block discarded – undo
875 900
 		{
876 901
 			$ascending = true;
877 902
 			$page_operator = '>';
878
-		}
879
-		else
903
+		} else
880 904
 		{
881 905
 			$ascending = false;
882 906
 			$page_operator = '<';
@@ -906,14 +930,16 @@  discard block
 block discarded – undo
906 930
 	$all_posters = array();
907 931
 	while ($row = $smcFunc['db_fetch_assoc']($request))
908 932
 	{
909
-		if (!empty($row['id_member']))
910
-			$all_posters[$row['id_msg']] = $row['id_member'];
933
+		if (!empty($row['id_member'])) {
934
+					$all_posters[$row['id_msg']] = $row['id_member'];
935
+		}
911 936
 		$messages[] = $row['id_msg'];
912 937
 	}
913 938
 	
914 939
 	// Before Page bring in the right order
915
-	if (!empty($start_char) && $start_char === 'L')
916
-		krsort($messages);
940
+	if (!empty($start_char) && $start_char === 'L') {
941
+			krsort($messages);
942
+	}
917 943
 	
918 944
 	// Construct the page index, allowing for the .START method...
919 945
 	$page_options = array(
@@ -935,8 +961,9 @@  discard block
 block discarded – undo
935 961
 			$_REQUEST['start'] = 0;
936 962
 		}
937 963
 		// They aren't using it, but the *option* is there, at least.
938
-		else
939
-			$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
964
+		else {
965
+					$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
966
+		}
940 967
 	}
941 968
 	
942 969
 	$smcFunc['db_free_result']($request);
@@ -948,8 +975,9 @@  discard block
 block discarded – undo
948 975
 	if (!$user_info['is_guest'] && !empty($messages))
949 976
 	{
950 977
 		$mark_at_msg = max($messages);
951
-		if ($mark_at_msg >= $context['topicinfo']['id_last_msg'])
952
-			$mark_at_msg = $modSettings['maxMsgID'];
978
+		if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) {
979
+					$mark_at_msg = $modSettings['maxMsgID'];
980
+		}
953 981
 		if ($mark_at_msg >= $context['topicinfo']['new_from'])
954 982
 		{
955 983
 			$smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace',
@@ -981,8 +1009,9 @@  discard block
 block discarded – undo
981 1009
 		while ($row = $smcFunc['db_fetch_assoc']($request))
982 1010
 		{
983 1011
 			// Find if this topic is marked for notification...
984
-			if (!empty($row['id_topic']))
985
-				$context['is_marked_notify'] = true;
1012
+			if (!empty($row['id_topic'])) {
1013
+							$context['is_marked_notify'] = true;
1014
+			}
986 1015
 
987 1016
 			// Only do this once, but mark the notifications as "not sent yet" for next time.
988 1017
 			if (!empty($row['sent']) && $do_once)
@@ -1004,8 +1033,9 @@  discard block
 block discarded – undo
1004 1033
 		}
1005 1034
 
1006 1035
 		// Have we recently cached the number of new topics in this board, and it's still a lot?
1007
-		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5)
1008
-			$_SESSION['topicseen_cache'][$board]--;
1036
+		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) {
1037
+					$_SESSION['topicseen_cache'][$board]--;
1038
+		}
1009 1039
 		// Mark board as seen if this is the only new topic.
1010 1040
 		elseif (isset($_REQUEST['topicseen']))
1011 1041
 		{
@@ -1029,14 +1059,16 @@  discard block
 block discarded – undo
1029 1059
 			$smcFunc['db_free_result']($request);
1030 1060
 
1031 1061
 			// If there're no real new topics in this board, mark the board as seen.
1032
-			if (empty($numNewTopics))
1033
-				$_REQUEST['boardseen'] = true;
1034
-			else
1035
-				$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1062
+			if (empty($numNewTopics)) {
1063
+							$_REQUEST['boardseen'] = true;
1064
+			} else {
1065
+							$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1066
+			}
1036 1067
 		}
1037 1068
 		// Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often.
1038
-		elseif (isset($_SESSION['topicseen_cache'][$board]))
1039
-			$_SESSION['topicseen_cache'][$board]--;
1069
+		elseif (isset($_SESSION['topicseen_cache'][$board])) {
1070
+					$_SESSION['topicseen_cache'][$board]--;
1071
+		}
1040 1072
 
1041 1073
 		// Mark board as seen if we came using last post link from BoardIndex. (or other places...)
1042 1074
 		if (isset($_REQUEST['boardseen']))
@@ -1093,23 +1125,26 @@  discard block
 block discarded – undo
1093 1125
 			$temp = array();
1094 1126
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1095 1127
 			{
1096
-				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1097
-					continue;
1128
+				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1129
+									continue;
1130
+				}
1098 1131
 
1099 1132
 				$temp[$row['id_attach']] = $row;
1100 1133
 				$temp[$row['id_attach']]['topic'] = $topic;
1101 1134
 				$temp[$row['id_attach']]['board'] = $board;
1102 1135
 
1103
-				if (!isset($context['loaded_attachments'][$row['id_msg']]))
1104
-					$context['loaded_attachments'][$row['id_msg']] = array();
1136
+				if (!isset($context['loaded_attachments'][$row['id_msg']])) {
1137
+									$context['loaded_attachments'][$row['id_msg']] = array();
1138
+				}
1105 1139
 			}
1106 1140
 			$smcFunc['db_free_result']($request);
1107 1141
 
1108 1142
 			// This is better than sorting it with the query...
1109 1143
 			ksort($temp);
1110 1144
 
1111
-			foreach ($temp as $row)
1112
-				$context['loaded_attachments'][$row['id_msg']][] = $row;
1145
+			foreach ($temp as $row) {
1146
+							$context['loaded_attachments'][$row['id_msg']][] = $row;
1147
+			}
1113 1148
 		}
1114 1149
 
1115 1150
 		$msg_parameters = array(
@@ -1136,21 +1171,23 @@  discard block
 block discarded – undo
1136 1171
 		);
1137 1172
 
1138 1173
 		// And the likes
1139
-		if (!empty($modSettings['enable_likes']))
1140
-			$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1174
+		if (!empty($modSettings['enable_likes'])) {
1175
+					$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1176
+		}
1141 1177
 
1142 1178
 		// Go to the last message if the given time is beyond the time of the last message.
1143
-		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies'])
1144
-			$context['start_from'] = $context['topicinfo']['num_replies'];
1179
+		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) {
1180
+					$context['start_from'] = $context['topicinfo']['num_replies'];
1181
+		}
1145 1182
 
1146 1183
 		// Since the anchor information is needed on the top of the page we load these variables beforehand.
1147 1184
 		$context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
1148
-		if (empty($options['view_newest_first']))
1149
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1150
-		else
1151
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1152
-	}
1153
-	else
1185
+		if (empty($options['view_newest_first'])) {
1186
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1187
+		} else {
1188
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1189
+		}
1190
+	} else
1154 1191
 	{
1155 1192
 		$messages_request = false;
1156 1193
 		$context['first_message'] = 0;
@@ -1186,8 +1223,9 @@  discard block
 block discarded – undo
1186 1223
 		'can_see_likes' => 'likes_view',
1187 1224
 		'can_like' => 'likes_like',
1188 1225
 	);
1189
-	foreach ($common_permissions as $contextual => $perm)
1190
-		$context[$contextual] = allowedTo($perm);
1226
+	foreach ($common_permissions as $contextual => $perm) {
1227
+			$context[$contextual] = allowedTo($perm);
1228
+	}
1191 1229
 
1192 1230
 	// Permissions with _any/_own versions.  $context[YYY] => ZZZ_any/_own.
1193 1231
 	$anyown_permissions = array(
@@ -1200,8 +1238,9 @@  discard block
 block discarded – undo
1200 1238
 		'can_reply_unapproved' => 'post_unapproved_replies',
1201 1239
 		'can_view_warning' => 'profile_warning',
1202 1240
 	);
1203
-	foreach ($anyown_permissions as $contextual => $perm)
1204
-		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1241
+	foreach ($anyown_permissions as $contextual => $perm) {
1242
+			$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1243
+	}
1205 1244
 
1206 1245
 	if (!$user_info['is_admin'] && !$modSettings['topic_move_any'])
1207 1246
 	{
@@ -1247,8 +1286,9 @@  discard block
 block discarded – undo
1247 1286
 	// Check if the draft functions are enabled and that they have permission to use them (for quick reply.)
1248 1287
 	$context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply'];
1249 1288
 	$context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']);
1250
-	if (!empty($context['drafts_save']))
1251
-		loadLanguage('Drafts');
1289
+	if (!empty($context['drafts_save'])) {
1290
+			loadLanguage('Drafts');
1291
+	}
1252 1292
 
1253 1293
 	// When was the last time this topic was replied to?  Should we warn them about it?
1254 1294
 	if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky']))
@@ -1309,26 +1349,31 @@  discard block
 block discarded – undo
1309 1349
 	// Message icons - customized icons are off?
1310 1350
 	$context['icons'] = getMessageIcons($board);
1311 1351
 
1312
-	if (!empty($context['icons']))
1313
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1352
+	if (!empty($context['icons'])) {
1353
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1354
+	}
1314 1355
 
1315 1356
 	// Build the normal button array.
1316 1357
 	$context['normal_buttons'] = array();
1317 1358
 
1318
-	if ($context['can_reply'])
1319
-		$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1359
+	if ($context['can_reply']) {
1360
+			$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1361
+	}
1320 1362
 
1321
-	if ($context['can_add_poll'])
1322
-		$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1363
+	if ($context['can_add_poll']) {
1364
+			$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1365
+	}
1323 1366
 
1324
-	if ($context['can_mark_unread'])
1325
-		$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1367
+	if ($context['can_mark_unread']) {
1368
+			$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1369
+	}
1326 1370
 
1327
-	if ($context['can_print'])
1328
-		$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1371
+	if ($context['can_print']) {
1372
+			$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1373
+	}
1329 1374
 
1330
-	if ($context['can_set_notify'])
1331
-		$context['normal_buttons']['notify'] = array(
1375
+	if ($context['can_set_notify']) {
1376
+			$context['normal_buttons']['notify'] = array(
1332 1377
 			'text' => 'notify_topic_' . $context['topic_notification_mode'],
1333 1378
 			'sub_buttons' => array(
1334 1379
 				array(
@@ -1350,38 +1395,47 @@  discard block
 block discarded – undo
1350 1395
 				),
1351 1396
 			),
1352 1397
 		);
1398
+	}
1353 1399
 
1354 1400
 	// Build the mod button array
1355 1401
 	$context['mod_buttons'] = array();
1356 1402
 
1357
-	if ($context['can_move'])
1358
-		$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1403
+	if ($context['can_move']) {
1404
+			$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1405
+	}
1359 1406
 
1360
-	if ($context['can_delete'])
1361
-		$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1407
+	if ($context['can_delete']) {
1408
+			$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1409
+	}
1362 1410
 
1363
-	if ($context['can_lock'])
1364
-		$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1411
+	if ($context['can_lock']) {
1412
+			$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1413
+	}
1365 1414
 
1366
-	if ($context['can_sticky'])
1367
-		$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1415
+	if ($context['can_sticky']) {
1416
+			$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1417
+	}
1368 1418
 
1369
-	if ($context['can_merge'])
1370
-		$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1419
+	if ($context['can_merge']) {
1420
+			$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1421
+	}
1371 1422
 
1372
-	if ($context['calendar_post'])
1373
-		$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1423
+	if ($context['calendar_post']) {
1424
+			$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1425
+	}
1374 1426
 
1375 1427
 	// Restore topic. eh?  No monkey business.
1376
-	if ($context['can_restore_topic'])
1377
-		$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1428
+	if ($context['can_restore_topic']) {
1429
+			$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1430
+	}
1378 1431
 
1379 1432
 	// Show a message in case a recently posted message became unapproved.
1380 1433
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
1381 1434
 
1382 1435
 	// Don't want to show this forever...
1383
-	if ($context['becomesUnapproved'])
1384
-		unset($_SESSION['becomesUnapproved']);
1436
+	if ($context['becomesUnapproved']) {
1437
+			unset($_SESSION['becomesUnapproved']);
1438
+	}
1385 1439
 
1386 1440
 	// Allow adding new mod buttons easily.
1387 1441
 	// Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used
@@ -1390,12 +1444,14 @@  discard block
 block discarded – undo
1390 1444
 	call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons']));
1391 1445
 
1392 1446
 	// Load the drafts js file
1393
-	if ($context['drafts_autosave'])
1394
-		loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1447
+	if ($context['drafts_autosave']) {
1448
+			loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1449
+	}
1395 1450
 
1396 1451
 	// Spellcheck
1397
-	if ($context['show_spellchecking'])
1398
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1452
+	if ($context['show_spellchecking']) {
1453
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1454
+	}
1399 1455
 
1400 1456
 	// topic.js
1401 1457
 	loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic');
@@ -1429,16 +1485,19 @@  discard block
 block discarded – undo
1429 1485
 	static $counter = null;
1430 1486
 
1431 1487
 	// If the query returned false, bail.
1432
-	if ($messages_request == false)
1433
-		return false;
1488
+	if ($messages_request == false) {
1489
+			return false;
1490
+	}
1434 1491
 
1435 1492
 	// Remember which message this is.  (ie. reply #83)
1436
-	if ($counter === null || $reset)
1437
-		$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1493
+	if ($counter === null || $reset) {
1494
+			$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1495
+	}
1438 1496
 
1439 1497
 	// Start from the beginning...
1440
-	if ($reset)
1441
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1498
+	if ($reset) {
1499
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1500
+	}
1442 1501
 
1443 1502
 	// Attempt to get the next message.
1444 1503
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
@@ -1452,19 +1511,21 @@  discard block
 block discarded – undo
1452 1511
 	if (empty($context['icon_sources']))
1453 1512
 	{
1454 1513
 		$context['icon_sources'] = array();
1455
-		foreach ($context['stable_icons'] as $icon)
1456
-			$context['icon_sources'][$icon] = 'images_url';
1514
+		foreach ($context['stable_icons'] as $icon) {
1515
+					$context['icon_sources'][$icon] = 'images_url';
1516
+		}
1457 1517
 	}
1458 1518
 
1459 1519
 	// Message Icon Management... check the images exist.
1460 1520
 	if (empty($modSettings['messageIconChecks_disable']))
1461 1521
 	{
1462 1522
 		// If the current icon isn't known, then we need to do something...
1463
-		if (!isset($context['icon_sources'][$message['icon']]))
1464
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1523
+		if (!isset($context['icon_sources'][$message['icon']])) {
1524
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1525
+		}
1526
+	} elseif (!isset($context['icon_sources'][$message['icon']])) {
1527
+			$context['icon_sources'][$message['icon']] = 'images_url';
1465 1528
 	}
1466
-	elseif (!isset($context['icon_sources'][$message['icon']]))
1467
-		$context['icon_sources'][$message['icon']] = 'images_url';
1468 1529
 
1469 1530
 	// If you're a lazy bum, you probably didn't give a subject...
1470 1531
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1489,8 +1550,7 @@  discard block
 block discarded – undo
1489 1550
 		$memberContext[$message['id_member']]['email'] = $message['poster_email'];
1490 1551
 		$memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum');
1491 1552
 		$memberContext[$message['id_member']]['is_guest'] = true;
1492
-	}
1493
-	else
1553
+	} else
1494 1554
 	{
1495 1555
 		// Define this here to make things a bit more readable
1496 1556
 		$can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own'));
@@ -1513,8 +1573,9 @@  discard block
 block discarded – undo
1513 1573
 	$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
1514 1574
 
1515 1575
 	// If it's in the recycle bin we need to override whatever icon we did have.
1516
-	if (!empty($board_info['recycle']))
1517
-		$message['icon'] = 'recycled';
1576
+	if (!empty($board_info['recycle'])) {
1577
+			$message['icon'] = 'recycled';
1578
+	}
1518 1579
 
1519 1580
 	require_once($sourcedir . '/Subs-Attachments.php');
1520 1581
 
@@ -1558,32 +1619,36 @@  discard block
 block discarded – undo
1558 1619
 	}
1559 1620
 
1560 1621
 	// Are likes enable?
1561
-	if (!empty($modSettings['enable_likes']))
1562
-		$output['likes'] = array(
1622
+	if (!empty($modSettings['enable_likes'])) {
1623
+			$output['likes'] = array(
1563 1624
 			'count' => $message['likes'],
1564 1625
 			'you' => in_array($message['id_msg'], $context['my_likes']),
1565 1626
 			'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']),
1566 1627
 		);
1628
+	}
1567 1629
 
1568 1630
 	// Is this user the message author?
1569 1631
 	$output['is_message_author'] = $message['id_member'] == $user_info['id'];
1570
-	if (!empty($output['modified']['name']))
1571
-		$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1632
+	if (!empty($output['modified']['name'])) {
1633
+			$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1634
+	}
1572 1635
 
1573 1636
 	// Did they give a reason for editing?
1574
-	if (!empty($output['modified']['name']) && !empty($output['modified']['reason']))
1575
-		$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1637
+	if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) {
1638
+			$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1639
+	}
1576 1640
 
1577 1641
 	// Any custom profile fields?
1578
-	if (!empty($memberContext[$message['id_member']]['custom_fields']))
1579
-		foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1642
+	if (!empty($memberContext[$message['id_member']]['custom_fields'])) {
1643
+			foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1580 1644
 			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1645
+	}
1581 1646
 
1582
-	if (empty($options['view_newest_first']))
1583
-		$counter++;
1584
-
1585
-	else
1586
-		$counter--;
1647
+	if (empty($options['view_newest_first'])) {
1648
+			$counter++;
1649
+	} else {
1650
+			$counter--;
1651
+	}
1587 1652
 
1588 1653
 	call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter));
1589 1654
 
@@ -1609,21 +1674,23 @@  discard block
 block discarded – undo
1609 1674
 	$context['no_last_modified'] = true;
1610 1675
 
1611 1676
 	// Prevent a preview image from being displayed twice.
1612
-	if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview'))
1613
-		return;
1677
+	if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) {
1678
+			return;
1679
+	}
1614 1680
 
1615 1681
 	// Make sure some attachment was requested!
1616
-	if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id']))
1617
-		fatal_lang_error('no_access', false);
1682
+	if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) {
1683
+			fatal_lang_error('no_access', false);
1684
+	}
1618 1685
 
1619 1686
 	$_REQUEST['attach'] = isset($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : (int) $_REQUEST['id'];
1620 1687
 
1621 1688
 	// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
1622 1689
 	$attachRequest = null;
1623 1690
 	call_integration_hook('integrate_download_request', array(&$attachRequest));
1624
-	if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest))
1625
-		$request = $attachRequest;
1626
-	else
1691
+	if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) {
1692
+			$request = $attachRequest;
1693
+	} else
1627 1694
 	{
1628 1695
 		// This checks only the current board for $board/$topic's permissions.
1629 1696
 		isAllowedTo('view_attachments');
@@ -1644,19 +1711,21 @@  discard block
 block discarded – undo
1644 1711
 		);
1645 1712
 	}
1646 1713
 
1647
-	if ($smcFunc['db_num_rows']($request) == 0)
1648
-		fatal_lang_error('no_access', false);
1714
+	if ($smcFunc['db_num_rows']($request) == 0) {
1715
+			fatal_lang_error('no_access', false);
1716
+	}
1649 1717
 
1650 1718
 	list ($id_folder, $real_filename, $file_hash, $file_ext, $id_attach, $attachment_type, $mime_type, $is_approved, $id_member) = $smcFunc['db_fetch_row']($request);
1651 1719
 	$smcFunc['db_free_result']($request);
1652 1720
 
1653 1721
 	// If it isn't yet approved, do they have permission to view it?
1654
-	if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3))
1655
-		isAllowedTo('approve_posts');
1722
+	if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) {
1723
+			isAllowedTo('approve_posts');
1724
+	}
1656 1725
 
1657 1726
 	// Update the download counter (unless it's a thumbnail).
1658
-	if ($attachment_type != 3)
1659
-		$smcFunc['db_query']('attach_download_increase', '
1727
+	if ($attachment_type != 3) {
1728
+			$smcFunc['db_query']('attach_download_increase', '
1660 1729
 			UPDATE LOW_PRIORITY {db_prefix}attachments
1661 1730
 			SET downloads = downloads + 1
1662 1731
 			WHERE id_attach = {int:id_attach}',
@@ -1664,15 +1733,15 @@  discard block
 block discarded – undo
1664 1733
 				'id_attach' => $id_attach,
1665 1734
 			)
1666 1735
 		);
1736
+	}
1667 1737
 
1668 1738
 	$filename = getAttachmentFilename($real_filename, $_REQUEST['attach'], $id_folder, false, $file_hash);
1669 1739
 
1670 1740
 	// This is done to clear any output that was made before now.
1671 1741
 	ob_end_clean();
1672
-	if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java')))
1673
-		@ob_start('ob_gzhandler');
1674
-
1675
-	else
1742
+	if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) {
1743
+			@ob_start('ob_gzhandler');
1744
+	} else
1676 1745
 	{
1677 1746
 		ob_start();
1678 1747
 		header('Content-Encoding: none');
@@ -1715,8 +1784,9 @@  discard block
 block discarded – undo
1715 1784
 	// Send the attachment headers.
1716 1785
 	header('Pragma: ');
1717 1786
 
1718
-	if (!isBrowser('gecko'))
1719
-		header('Content-Transfer-Encoding: binary');
1787
+	if (!isBrowser('gecko')) {
1788
+			header('Content-Transfer-Encoding: binary');
1789
+	}
1720 1790
 
1721 1791
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
1722 1792
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT');
@@ -1725,18 +1795,19 @@  discard block
 block discarded – undo
1725 1795
 	header('ETag: ' . $eTag);
1726 1796
 
1727 1797
 	// Make sure the mime type warrants an inline display.
1728
-	if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0)
1729
-		unset($_REQUEST['image']);
1798
+	if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) {
1799
+			unset($_REQUEST['image']);
1800
+	}
1730 1801
 
1731 1802
 	// Does this have a mime type?
1732
-	elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff'))))
1733
-		header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp')));
1734
-
1735
-	else
1803
+	elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) {
1804
+			header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp')));
1805
+	} else
1736 1806
 	{
1737 1807
 		header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
1738
-		if (isset($_REQUEST['image']))
1739
-			unset($_REQUEST['image']);
1808
+		if (isset($_REQUEST['image'])) {
1809
+					unset($_REQUEST['image']);
1810
+		}
1740 1811
 	}
1741 1812
 
1742 1813
 	// Convert the file to UTF-8, cuz most browsers dig that.
@@ -1744,23 +1815,22 @@  discard block
 block discarded – undo
1744 1815
 	$disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline';
1745 1816
 
1746 1817
 	// Different browsers like different standards...
1747
-	if (isBrowser('firefox'))
1748
-		header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
1749
-
1750
-	elseif (isBrowser('opera'))
1751
-		header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
1752
-
1753
-	elseif (isBrowser('ie'))
1754
-		header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
1755
-
1756
-	else
1757
-		header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
1818
+	if (isBrowser('firefox')) {
1819
+			header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
1820
+	} elseif (isBrowser('opera')) {
1821
+			header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
1822
+	} elseif (isBrowser('ie')) {
1823
+			header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
1824
+	} else {
1825
+			header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
1826
+	}
1758 1827
 
1759 1828
 	// If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE.
1760
-	if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff')))
1761
-		header('Cache-Control: no-cache');
1762
-	else
1763
-		header('Cache-Control: max-age=' . (525600 * 60) . ', private');
1829
+	if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) {
1830
+			header('Cache-Control: no-cache');
1831
+	} else {
1832
+			header('Cache-Control: max-age=' . (525600 * 60) . ', private');
1833
+	}
1764 1834
 
1765 1835
 	header('Content-Length: ' . filesize($filename));
1766 1836
 
@@ -1770,20 +1840,23 @@  discard block
 block discarded – undo
1770 1840
 	// Recode line endings for text files, if enabled.
1771 1841
 	if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file_ext, array('txt', 'css', 'htm', 'html', 'php', 'xml')))
1772 1842
 	{
1773
-		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false)
1774
-			$callback = function($buffer)
1843
+		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) {
1844
+					$callback = function($buffer)
1775 1845
 			{
1776 1846
 				return preg_replace('~[\r]?\n~', "\r\n", $buffer);
1847
+		}
1777 1848
 			};
1778
-		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false)
1779
-			$callback = function($buffer)
1849
+		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) {
1850
+					$callback = function($buffer)
1780 1851
 			{
1781 1852
 				return preg_replace('~[\r]?\n~', "\r", $buffer);
1853
+		}
1782 1854
 			};
1783
-		else
1784
-			$callback = function($buffer)
1855
+		else {
1856
+					$callback = function($buffer)
1785 1857
 			{
1786 1858
 				return preg_replace('~[\r]?\n~', "\n", $buffer);
1859
+		}
1787 1860
 			};
1788 1861
 	}
1789 1862
 
@@ -1791,23 +1864,26 @@  discard block
 block discarded – undo
1791 1864
 	if (filesize($filename) > 4194304)
1792 1865
 	{
1793 1866
 		// Forcibly end any output buffering going on.
1794
-		while (@ob_get_level() > 0)
1795
-			@ob_end_clean();
1867
+		while (@ob_get_level() > 0) {
1868
+					@ob_end_clean();
1869
+		}
1796 1870
 
1797 1871
 		$fp = fopen($filename, 'rb');
1798 1872
 		while (!feof($fp))
1799 1873
 		{
1800
-			if (isset($callback))
1801
-				echo $callback(fread($fp, 8192));
1802
-			else
1803
-				echo fread($fp, 8192);
1874
+			if (isset($callback)) {
1875
+							echo $callback(fread($fp, 8192));
1876
+			} else {
1877
+							echo fread($fp, 8192);
1878
+			}
1804 1879
 			flush();
1805 1880
 		}
1806 1881
 		fclose($fp);
1807 1882
 	}
1808 1883
 	// On some of the less-bright hosts, readfile() is disabled.  It's just a faster, more byte safe, version of what's in the if.
1809
-	elseif (isset($callback) || @readfile($filename) === null)
1810
-		echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename);
1884
+	elseif (isset($callback) || @readfile($filename) === null) {
1885
+			echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename);
1886
+	}
1811 1887
 
1812 1888
 	obExit(false);
1813 1889
 }
@@ -1820,8 +1896,9 @@  discard block
 block discarded – undo
1820 1896
  */
1821 1897
 function approved_attach_sort($a, $b)
1822 1898
 {
1823
-	if ($a['is_approved'] == $b['is_approved'])
1824
-		return 0;
1899
+	if ($a['is_approved'] == $b['is_approved']) {
1900
+			return 0;
1901
+	}
1825 1902
 
1826 1903
 	return $a['is_approved'] > $b['is_approved'] ? -1 : 1;
1827 1904
 }
@@ -1838,16 +1915,19 @@  discard block
 block discarded – undo
1838 1915
 
1839 1916
 	require_once($sourcedir . '/RemoveTopic.php');
1840 1917
 
1841
-	if (empty($_REQUEST['msgs']))
1842
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1918
+	if (empty($_REQUEST['msgs'])) {
1919
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1920
+	}
1843 1921
 
1844 1922
 	$messages = array();
1845
-	foreach ($_REQUEST['msgs'] as $dummy)
1846
-		$messages[] = (int) $dummy;
1923
+	foreach ($_REQUEST['msgs'] as $dummy) {
1924
+			$messages[] = (int) $dummy;
1925
+	}
1847 1926
 
1848 1927
 	// We are restoring messages. We handle this in another place.
1849
-	if (isset($_REQUEST['restore_selected']))
1850
-		redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1928
+	if (isset($_REQUEST['restore_selected'])) {
1929
+			redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1930
+	}
1851 1931
 	if (isset($_REQUEST['split_selection']))
1852 1932
 	{
1853 1933
 		$request = $smcFunc['db_query']('', '
@@ -1866,8 +1946,9 @@  discard block
 block discarded – undo
1866 1946
 	}
1867 1947
 
1868 1948
 	// Allowed to delete any message?
1869
-	if (allowedTo('delete_any'))
1870
-		$allowed_all = true;
1949
+	if (allowedTo('delete_any')) {
1950
+			$allowed_all = true;
1951
+	}
1871 1952
 	// Allowed to delete replies to their messages?
1872 1953
 	elseif (allowedTo('delete_replies'))
1873 1954
 	{
@@ -1884,13 +1965,14 @@  discard block
 block discarded – undo
1884 1965
 		$smcFunc['db_free_result']($request);
1885 1966
 
1886 1967
 		$allowed_all = $starter == $user_info['id'];
1968
+	} else {
1969
+			$allowed_all = false;
1887 1970
 	}
1888
-	else
1889
-		$allowed_all = false;
1890 1971
 
1891 1972
 	// Make sure they're allowed to delete their own messages, if not any.
1892
-	if (!$allowed_all)
1893
-		isAllowedTo('delete_own');
1973
+	if (!$allowed_all) {
1974
+			isAllowedTo('delete_own');
1975
+	}
1894 1976
 
1895 1977
 	// Allowed to remove which messages?
1896 1978
 	$request = $smcFunc['db_query']('', '
@@ -1910,8 +1992,9 @@  discard block
 block discarded – undo
1910 1992
 	$messages = array();
1911 1993
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1912 1994
 	{
1913
-		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
1914
-			continue;
1995
+		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
1996
+					continue;
1997
+		}
1915 1998
 
1916 1999
 		$messages[$row['id_msg']] = array($row['subject'], $row['id_member']);
1917 2000
 	}
@@ -1934,17 +2017,20 @@  discard block
 block discarded – undo
1934 2017
 	foreach ($messages as $message => $info)
1935 2018
 	{
1936 2019
 		// Just skip the first message - if it's not the last.
1937
-		if ($message == $first_message && $message != $last_message)
1938
-			continue;
2020
+		if ($message == $first_message && $message != $last_message) {
2021
+					continue;
2022
+		}
1939 2023
 		// If the first message is going then don't bother going back to the topic as we're effectively deleting it.
1940
-		elseif ($message == $first_message)
1941
-			$topicGone = true;
2024
+		elseif ($message == $first_message) {
2025
+					$topicGone = true;
2026
+		}
1942 2027
 
1943 2028
 		removeMessage($message);
1944 2029
 
1945 2030
 		// Log this moderation action ;).
1946
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
1947
-			logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
2031
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
2032
+					logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
2033
+		}
1948 2034
 	}
1949 2035
 
1950 2036
 	redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']);
Please login to merge, or discard this patch.
Sources/ManageNews.php 1 patch
Braces   +140 added lines, -102 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The news dispatcher; doesn't do anything, just delegates.
@@ -67,8 +68,9 @@  discard block
 block discarded – undo
67 68
 	);
68 69
 
69 70
 	// Force the right area...
70
-	if (substr($_REQUEST['sa'], 0, 7) == 'mailing')
71
-		$context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers';
71
+	if (substr($_REQUEST['sa'], 0, 7) == 'mailing') {
72
+			$context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers';
73
+	}
72 74
 
73 75
 	call_helper($subActions[$_REQUEST['sa']][0]);
74 76
 }
@@ -99,9 +101,10 @@  discard block
 block discarded – undo
99 101
 		$temp_news = explode("\n", $modSettings['news']);
100 102
 
101 103
 		// Remove the items that were selected.
102
-		foreach ($temp_news as $i => $news)
103
-			if (in_array($i, $_POST['remove']))
104
+		foreach ($temp_news as $i => $news) {
105
+					if (in_array($i, $_POST['remove']))
104 106
 				unset($temp_news[$i]);
107
+		}
105 108
 
106 109
 		// Update the database.
107 110
 		updateSettings(array('news' => implode("\n", $temp_news)));
@@ -117,9 +120,9 @@  discard block
 block discarded – undo
117 120
 
118 121
 		foreach ($_POST['news'] as $i => $news)
119 122
 		{
120
-			if (trim($news) == '')
121
-				unset($_POST['news'][$i]);
122
-			else
123
+			if (trim($news) == '') {
124
+							unset($_POST['news'][$i]);
125
+			} else
123 126
 			{
124 127
 				$_POST['news'][$i] = $smcFunc['htmlspecialchars']($_POST['news'][$i], ENT_QUOTES);
125 128
 				preparsecode($_POST['news'][$i]);
@@ -154,11 +157,12 @@  discard block
 block discarded – undo
154 157
 				'data' => array(
155 158
 					'function' => function($news)
156 159
 					{
157
-						if (is_numeric($news['id']))
158
-							return '<textarea id="data_' . $news['id'] . '" rows="3" cols="50" name="news[]" class="padding block">' . $news['unparsed'] . '</textarea>
160
+						if (is_numeric($news['id'])) {
161
+													return '<textarea id="data_' . $news['id'] . '" rows="3" cols="50" name="news[]" class="padding block">' . $news['unparsed'] . '</textarea>
159 162
 							<div class="floatleft" id="preview_' . $news['id'] . '"></div>';
160
-						else
161
-							return $news['unparsed'];
163
+						} else {
164
+													return $news['unparsed'];
165
+						}
162 166
 					},
163 167
 					'style' => 'width: 50%;',
164 168
 				),
@@ -183,10 +187,11 @@  discard block
 block discarded – undo
183 187
 				'data' => array(
184 188
 					'function' => function($news)
185 189
 					{
186
-						if (is_numeric($news['id']))
187
-							return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '" class="input_check">';
188
-						else
189
-							return '';
190
+						if (is_numeric($news['id'])) {
191
+													return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '" class="input_check">';
192
+						} else {
193
+													return '';
194
+						}
190 195
 					},
191 196
 					'class' => 'centercol',
192 197
 				),
@@ -280,12 +285,13 @@  discard block
 block discarded – undo
280 285
 
281 286
 	$admin_current_news = array();
282 287
 	// Ready the current news.
283
-	foreach (explode("\n", $modSettings['news']) as $id => $line)
284
-		$admin_current_news[$id] = array(
288
+	foreach (explode("\n", $modSettings['news']) as $id => $line) {
289
+			$admin_current_news[$id] = array(
285 290
 			'id' => $id,
286 291
 			'unparsed' => un_preparsecode($line),
287 292
 			'parsed' => preg_replace('~<([/]?)form[^>]*?[>]*>~i', '<em class="smalltext">&lt;$1form&gt;</em>', parse_bbc($line)),
288 293
 		);
294
+	}
289 295
 
290 296
 	$admin_current_news['last'] = array(
291 297
 		'id' => 'last',
@@ -352,10 +358,11 @@  discard block
 block discarded – undo
352 358
 			'member_count' => 0,
353 359
 		);
354 360
 
355
-		if ($row['min_posts'] == -1)
356
-			$normalGroups[$row['id_group']] = $row['id_group'];
357
-		else
358
-			$postGroups[$row['id_group']] = $row['id_group'];
361
+		if ($row['min_posts'] == -1) {
362
+					$normalGroups[$row['id_group']] = $row['id_group'];
363
+		} else {
364
+					$postGroups[$row['id_group']] = $row['id_group'];
365
+		}
359 366
 	}
360 367
 	$smcFunc['db_free_result']($request);
361 368
 
@@ -371,8 +378,9 @@  discard block
 block discarded – undo
371 378
 				'post_group_list' => $postGroups,
372 379
 			)
373 380
 		);
374
-		while ($row = $smcFunc['db_fetch_assoc']($query))
375
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
381
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
382
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
383
+		}
376 384
 		$smcFunc['db_free_result']($query);
377 385
 	}
378 386
 
@@ -388,8 +396,9 @@  discard block
 block discarded – undo
388 396
 				'normal_group_list' => $normalGroups,
389 397
 			)
390 398
 		);
391
-		while ($row = $smcFunc['db_fetch_assoc']($query))
392
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
399
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
400
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
401
+		}
393 402
 		$smcFunc['db_free_result']($query);
394 403
 
395 404
 		// Also do those who have it as an additional membergroup - this ones more yucky...
@@ -406,8 +415,9 @@  discard block
 block discarded – undo
406 415
 				'blank_string' => '',
407 416
 			)
408 417
 		);
409
-		while ($row = $smcFunc['db_fetch_assoc']($query))
410
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
418
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
419
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
420
+		}
411 421
 		$smcFunc['db_free_result']($query);
412 422
 	}
413 423
 
@@ -458,10 +468,11 @@  discard block
 block discarded – undo
458 468
 	{
459 469
 		$context[$key] = !empty($_REQUEST[$post]) ? $_REQUEST[$post] : '';
460 470
 
461
-		if (empty($context[$key]) && empty($_REQUEST['xml']))
462
-			$context['post_error']['messages'][] = $txt['error_no_' . $post];
463
-		elseif (!empty($_REQUEST['xml']))
464
-			continue;
471
+		if (empty($context[$key]) && empty($_REQUEST['xml'])) {
472
+					$context['post_error']['messages'][] = $txt['error_no_' . $post];
473
+		} elseif (!empty($_REQUEST['xml'])) {
474
+					continue;
475
+		}
465 476
 
466 477
 		preparsecode($context[$key]);
467 478
 		if ($html)
@@ -540,10 +551,12 @@  discard block
 block discarded – undo
540 551
 
541 552
 	// Start by finding any members!
542 553
 	$toClean = array();
543
-	if (!empty($_POST['members']))
544
-		$toClean[] = 'members';
545
-	if (!empty($_POST['exclude_members']))
546
-		$toClean[] = 'exclude_members';
554
+	if (!empty($_POST['members'])) {
555
+			$toClean[] = 'members';
556
+	}
557
+	if (!empty($_POST['exclude_members'])) {
558
+			$toClean[] = 'exclude_members';
559
+	}
547 560
 	if (!empty($toClean))
548 561
 	{
549 562
 		require_once($sourcedir . '/Subs-Auth.php');
@@ -555,11 +568,13 @@  discard block
 block discarded – undo
555 568
 			preg_match_all('~"([^"]+)"~', $_POST[$type], $matches);
556 569
 			$_POST[$type] = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST[$type]))));
557 570
 
558
-			foreach ($_POST[$type] as $index => $member)
559
-				if (strlen(trim($member)) > 0)
571
+			foreach ($_POST[$type] as $index => $member) {
572
+							if (strlen(trim($member)) > 0)
560 573
 					$_POST[$type][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($member)));
561
-				else
562
-					unset($_POST[$type][$index]);
574
+			}
575
+				else {
576
+									unset($_POST[$type][$index]);
577
+				}
563 578
 
564 579
 			// Find the members
565 580
 			$_POST[$type] = implode(',', array_keys(findMembers($_POST[$type])));
@@ -569,16 +584,18 @@  discard block
 block discarded – undo
569 584
 	if (isset($_POST['member_list']) && is_array($_POST['member_list']))
570 585
 	{
571 586
 		$members = array();
572
-		foreach ($_POST['member_list'] as $member_id)
573
-			$members[] = (int) $member_id;
587
+		foreach ($_POST['member_list'] as $member_id) {
588
+					$members[] = (int) $member_id;
589
+		}
574 590
 		$_POST['members'] = implode(',', $members);
575 591
 	}
576 592
 
577 593
 	if (isset($_POST['exclude_member_list']) && is_array($_POST['exclude_member_list']))
578 594
 	{
579 595
 		$members = array();
580
-		foreach ($_POST['exclude_member_list'] as $member_id)
581
-			$members[] = (int) $member_id;
596
+		foreach ($_POST['exclude_member_list'] as $member_id) {
597
+					$members[] = (int) $member_id;
598
+		}
582 599
 		$_POST['exclude_members'] = implode(',', $members);
583 600
 	}
584 601
 
@@ -602,8 +619,9 @@  discard block
 block discarded – undo
602 619
 			'current_time' => time(),
603 620
 		)
604 621
 	);
605
-	while ($row = $smcFunc['db_fetch_assoc']($request))
606
-		$context['recipients']['exclude_members'][] = $row['id_member'];
622
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
623
+			$context['recipients']['exclude_members'][] = $row['id_member'];
624
+	}
607 625
 	$smcFunc['db_free_result']($request);
608 626
 
609 627
 	$request = $smcFunc['db_query']('', '
@@ -638,8 +656,9 @@  discard block
 block discarded – undo
638 656
 			WHERE email_address IN(' . implode(', ', $condition_array) . ')',
639 657
 			$condition_array_params
640 658
 		);
641
-		while ($row = $smcFunc['db_fetch_assoc']($request))
642
-			$context['recipients']['exclude_members'][] = $row['id_member'];
659
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
660
+					$context['recipients']['exclude_members'][] = $row['id_member'];
661
+		}
643 662
 		$smcFunc['db_free_result']($request);
644 663
 	}
645 664
 
@@ -657,10 +676,11 @@  discard block
 block discarded – undo
657 676
 		);
658 677
 		while ($row = $smcFunc['db_fetch_assoc']($request))
659 678
 		{
660
-			if (in_array(3, $context['recipients']))
661
-				$context['recipients']['exclude_members'][] = $row['identifier'];
662
-			else
663
-				$context['recipients']['members'][] = $row['identifier'];
679
+			if (in_array(3, $context['recipients'])) {
680
+							$context['recipients']['exclude_members'][] = $row['identifier'];
681
+			} else {
682
+							$context['recipients']['members'][] = $row['identifier'];
683
+			}
664 684
 		}
665 685
 		$smcFunc['db_free_result']($request);
666 686
 	}
@@ -707,8 +727,9 @@  discard block
 block discarded – undo
707 727
 	$num_at_once = 1000;
708 728
 
709 729
 	// If by PM's I suggest we half the above number.
710
-	if (!empty($_POST['send_pm']))
711
-		$num_at_once /= 2;
730
+	if (!empty($_POST['send_pm'])) {
731
+			$num_at_once /= 2;
732
+	}
712 733
 
713 734
 	checkSession();
714 735
 
@@ -731,8 +752,7 @@  discard block
 block discarded – undo
731 752
 		);
732 753
 		list ($context['total_members']) = $smcFunc['db_fetch_row']($request);
733 754
 		$smcFunc['db_free_result']($request);
734
-	}
735
-	else
755
+	} else
736 756
 	{
737 757
 		$context['total_members'] = (int) $_REQUEST['total_members'];
738 758
 	}
@@ -750,32 +770,35 @@  discard block
 block discarded – undo
750 770
 	if (!empty($_POST['exclude_members']))
751 771
 	{
752 772
 		$members = explode(',', $_POST['exclude_members']);
753
-		foreach ($members as $member)
754
-			if ($member >= $context['start'])
773
+		foreach ($members as $member) {
774
+					if ($member >= $context['start'])
755 775
 				$context['recipients']['exclude_members'][] = (int) $member;
776
+		}
756 777
 	}
757 778
 
758 779
 	// What about members we *must* do?
759 780
 	if (!empty($_POST['members']))
760 781
 	{
761 782
 		$members = explode(',', $_POST['members']);
762
-		foreach ($members as $member)
763
-			if ($member >= $context['start'])
783
+		foreach ($members as $member) {
784
+					if ($member >= $context['start'])
764 785
 				$context['recipients']['members'][] = (int) $member;
786
+		}
765 787
 	}
766 788
 	// Cleaning groups is simple - although deal with both checkbox and commas.
767 789
 	if (isset($_POST['groups']))
768 790
 	{
769 791
 		if (is_array($_POST['groups']))
770 792
 		{
771
-			foreach ($_POST['groups'] as $group => $dummy)
772
-				$context['recipients']['groups'][] = (int) $group;
773
-		}
774
-		else
793
+			foreach ($_POST['groups'] as $group => $dummy) {
794
+							$context['recipients']['groups'][] = (int) $group;
795
+			}
796
+		} else
775 797
 		{
776 798
 			$groups = explode(',', $_POST['groups']);
777
-			foreach ($groups as $group)
778
-				$context['recipients']['groups'][] = (int) $group;
799
+			foreach ($groups as $group) {
800
+							$context['recipients']['groups'][] = (int) $group;
801
+			}
779 802
 		}
780 803
 	}
781 804
 	// Same for excluded groups
@@ -783,15 +806,17 @@  discard block
 block discarded – undo
783 806
 	{
784 807
 		if (is_array($_POST['exclude_groups']))
785 808
 		{
786
-			foreach ($_POST['exclude_groups'] as $group => $dummy)
787
-				$context['recipients']['exclude_groups'][] = (int) $group;
809
+			foreach ($_POST['exclude_groups'] as $group => $dummy) {
810
+							$context['recipients']['exclude_groups'][] = (int) $group;
811
+			}
788 812
 		}
789 813
 		// Ignore an empty string - we don't want to exclude "Regular Members" unless it's specifically selected
790 814
 		elseif ($_POST['exclude_groups'] != '')
791 815
 		{
792 816
 			$groups = explode(',', $_POST['exclude_groups']);
793
-			foreach ($groups as $group)
794
-				$context['recipients']['exclude_groups'][] = (int) $group;
817
+			foreach ($groups as $group) {
818
+							$context['recipients']['exclude_groups'][] = (int) $group;
819
+			}
795 820
 		}
796 821
 	}
797 822
 	// Finally - emails!
@@ -801,14 +826,16 @@  discard block
 block discarded – undo
801 826
 		foreach ($addressed as $curmem)
802 827
 		{
803 828
 			$curmem = trim($curmem);
804
-			if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL))
805
-				$context['recipients']['emails'][$curmem] = $curmem;
829
+			if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL)) {
830
+							$context['recipients']['emails'][$curmem] = $curmem;
831
+			}
806 832
 		}
807 833
 	}
808 834
 
809 835
 	// If we're only cleaning drop out here.
810
-	if ($clean_only)
811
-		return;
836
+	if ($clean_only) {
837
+			return;
838
+	}
812 839
 
813 840
 	require_once($sourcedir . '/Subs-Post.php');
814 841
 
@@ -824,16 +851,18 @@  discard block
 block discarded – undo
824 851
 	if (!$context['send_pm'] && !empty($_POST['send_html']))
825 852
 	{
826 853
 		// Prepare the message for HTML.
827
-		if (!empty($_POST['parse_html']))
828
-			$_POST['message'] = str_replace(array("\n", '  '), array('<br>' . "\n", '&nbsp; '), $_POST['message']);
854
+		if (!empty($_POST['parse_html'])) {
855
+					$_POST['message'] = str_replace(array("\n", '  '), array('<br>' . "\n", '&nbsp; '), $_POST['message']);
856
+		}
829 857
 
830 858
 		// This is here to prevent spam filters from tagging this as spam.
831 859
 		if (preg_match('~\<html~i', $_POST['message']) == 0)
832 860
 		{
833
-			if (preg_match('~\<body~i', $_POST['message']) == 0)
834
-				$_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>';
835
-			else
836
-				$_POST['message'] = '<html>' . $_POST['message'] . '</html>';
861
+			if (preg_match('~\<body~i', $_POST['message']) == 0) {
862
+							$_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>';
863
+			} else {
864
+							$_POST['message'] = '<html>' . $_POST['message'] . '</html>';
865
+			}
837 866
 		}
838 867
 	}
839 868
 
@@ -887,15 +916,17 @@  discard block
 block discarded – undo
887 916
 	foreach ($context['recipients']['emails'] as $k => $email)
888 917
 	{
889 918
 		// Done as many as we can?
890
-		if ($i >= $num_at_once)
891
-			break;
919
+		if ($i >= $num_at_once) {
920
+					break;
921
+		}
892 922
 
893 923
 		// Don't sent it twice!
894 924
 		unset($context['recipients']['emails'][$k]);
895 925
 
896 926
 		// Dammit - can't PM emails!
897
-		if ($context['send_pm'])
898
-			continue;
927
+		if ($context['send_pm']) {
928
+					continue;
929
+		}
899 930
 
900 931
 		$to_member = array(
901 932
 			$email,
@@ -929,8 +960,9 @@  discard block
 block discarded – undo
929 960
 					$queryBuild[] = 'mem.id_post_group = {int:group_' . $group . '}';
930 961
 				}
931 962
 			}
932
-			if (!empty($queryBuild))
933
-			$sendQuery .= implode(' OR ', $queryBuild);
963
+			if (!empty($queryBuild)) {
964
+						$sendQuery .= implode(' OR ', $queryBuild);
965
+			}
934 966
 		}
935 967
 		if (!empty($context['recipients']['members']))
936 968
 		{
@@ -949,8 +981,9 @@  discard block
 block discarded – undo
949 981
 		}
950 982
 
951 983
 		// Anything to exclude?
952
-		if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups']))
953
-			$sendQuery .= ' AND mem.id_group != {int:regular_group}';
984
+		if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups'])) {
985
+					$sendQuery .= ' AND mem.id_group != {int:regular_group}';
986
+		}
954 987
 		if (!empty($context['recipients']['exclude_members']))
955 988
 		{
956 989
 			$sendQuery .= ' AND mem.id_member NOT IN ({array_int:exclude_members})';
@@ -986,21 +1019,24 @@  discard block
 block discarded – undo
986 1019
 		foreach ($rows as $row)
987 1020
 		{
988 1021
 			// Force them to have it?
989
-			if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements']))
990
-				continue;
1022
+			if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements'])) {
1023
+							continue;
1024
+			}
991 1025
 
992 1026
 			// What groups are we looking at here?
993
-			if (empty($row['additional_groups']))
994
-				$groups = array($row['id_group'], $row['id_post_group']);
995
-			else
996
-				$groups = array_merge(
1027
+			if (empty($row['additional_groups'])) {
1028
+							$groups = array($row['id_group'], $row['id_post_group']);
1029
+			} else {
1030
+							$groups = array_merge(
997 1031
 					array($row['id_group'], $row['id_post_group']),
998 1032
 					explode(',', $row['additional_groups'])
999 1033
 				);
1034
+			}
1000 1035
 
1001 1036
 			// Excluded groups?
1002
-			if (array_intersect($groups, $context['recipients']['exclude_groups']))
1003
-				continue;
1037
+			if (array_intersect($groups, $context['recipients']['exclude_groups'])) {
1038
+							continue;
1039
+			}
1004 1040
 
1005 1041
 			// We might need this
1006 1042
 			$cleanMemberName = empty($_POST['send_html']) || $context['send_pm'] ? un_htmlspecialchars($row['real_name']) : $row['real_name'];
@@ -1023,10 +1059,11 @@  discard block
 block discarded – undo
1023 1059
 				), $_POST['subject']);
1024 1060
 
1025 1061
 			// Send the actual email - or a PM!
1026
-			if (!$context['send_pm'])
1027
-				sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5);
1028
-			else
1029
-				sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message);
1062
+			if (!$context['send_pm']) {
1063
+							sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5);
1064
+			} else {
1065
+							sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message);
1066
+			}
1030 1067
 		}
1031 1068
 	}
1032 1069
 
@@ -1076,8 +1113,9 @@  discard block
 block discarded – undo
1076 1113
 
1077 1114
 	call_integration_hook('integrate_modify_news_settings', array(&$config_vars));
1078 1115
 
1079
-	if ($return_config)
1080
-		return $config_vars;
1116
+	if ($return_config) {
1117
+			return $config_vars;
1118
+	}
1081 1119
 
1082 1120
 	$context['page_title'] = $txt['admin_edit_news'] . ' - ' . $txt['settings'];
1083 1121
 	$context['sub_template'] = 'show_settings';
Please login to merge, or discard this patch.