@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $year_low = (int) substr($low_date, 0, 4); |
34 | 34 | $year_high = (int) substr($high_date, 0, 4); |
35 | 35 | |
36 | - if($smcFunc['db_title'] != "PostgreSQL") { |
|
36 | + if ($smcFunc['db_title'] != "PostgreSQL") { |
|
37 | 37 | // Collect all of the birthdays for this month. I know, it's a painful query. |
38 | 38 | $result = $smcFunc['db_query']('birthday_array', ' |
39 | 39 | SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | 'year_low' => $year_low . '-%m-%d', |
82 | 82 | 'year_high' => $year_high . '-%m-%d', |
83 | 83 | 'year_low_low_date' => $low_date, |
84 | - 'year_low_high_date' => ($year_low == $year_high ? $high_date : $year_low .'-12-31'), |
|
85 | - 'year_high_low_date' => ($year_low == $year_high ? $low_date : $year_high .'-01-01'), |
|
84 | + 'year_low_high_date' => ($year_low == $year_high ? $high_date : $year_low . '-12-31'), |
|
85 | + 'year_high_low_date' => ($year_low == $year_high ? $low_date : $year_high . '-01-01'), |
|
86 | 86 | 'year_high_high_date' => $high_date, |
87 | 87 | ) |
88 | 88 | ); |
@@ -13,8 +13,9 @@ discard block |
||
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. |
@@ -59,8 +60,7 @@ discard block |
||
59 | 60 | 'max_year' => $year_high, |
60 | 61 | ) |
61 | 62 | ); |
62 | - } |
|
63 | - else |
|
63 | + } else |
|
64 | 64 | { |
65 | 65 | $result = $smcFunc['db_query']('birthday_array', ' |
66 | 66 | SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate |
@@ -90,10 +90,11 @@ discard block |
||
90 | 90 | $bday = array(); |
91 | 91 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
92 | 92 | { |
93 | - if ($year_low != $year_high) |
|
94 | - $age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low; |
|
95 | - else |
|
96 | - $age_year = $year_low; |
|
93 | + if ($year_low != $year_high) { |
|
94 | + $age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low; |
|
95 | + } else { |
|
96 | + $age_year = $year_low; |
|
97 | + } |
|
97 | 98 | |
98 | 99 | $bday[$age_year . substr($row['birthdate'], 4)][] = array( |
99 | 100 | 'id' => $row['id_member'], |
@@ -107,8 +108,9 @@ discard block |
||
107 | 108 | ksort($bday); |
108 | 109 | |
109 | 110 | // Set is_last, so the themes know when to stop placing separators. |
110 | - foreach ($bday as $mday => $array) |
|
111 | - $bday[$mday][count($array) - 1]['is_last'] = true; |
|
111 | + foreach ($bday as $mday => $array) { |
|
112 | + $bday[$mday][count($array) - 1]['is_last'] = true; |
|
113 | + } |
|
112 | 114 | |
113 | 115 | return $bday; |
114 | 116 | } |
@@ -156,8 +158,9 @@ discard block |
||
156 | 158 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
157 | 159 | { |
158 | 160 | // If the attached topic is not approved then for the moment pretend it doesn't exist |
159 | - if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) |
|
160 | - continue; |
|
161 | + if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) { |
|
162 | + continue; |
|
163 | + } |
|
161 | 164 | |
162 | 165 | // Force a censor of the title - as often these are used by others. |
163 | 166 | censorText($row['title'], $use_permissions ? false : true); |
@@ -166,8 +169,9 @@ discard block |
||
166 | 169 | list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
167 | 170 | |
168 | 171 | // Sanity check |
169 | - if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
170 | - continue; |
|
172 | + if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) { |
|
173 | + continue; |
|
174 | + } |
|
171 | 175 | |
172 | 176 | // Get set up for the loop |
173 | 177 | $start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), timezone_open($tz)); |
@@ -231,8 +235,8 @@ discard block |
||
231 | 235 | ); |
232 | 236 | |
233 | 237 | // If we're using permissions (calendar pages?) then just ouput normal contextual style information. |
234 | - if ($use_permissions) |
|
235 | - $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
238 | + if ($use_permissions) { |
|
239 | + $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
236 | 240 | 'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0', |
237 | 241 | 'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>', |
238 | 242 | 'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')), |
@@ -240,9 +244,10 @@ discard block |
||
240 | 244 | 'can_export' => !empty($modSettings['cal_export']) ? true : false, |
241 | 245 | 'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'], |
242 | 246 | )); |
247 | + } |
|
243 | 248 | // Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info. |
244 | - else |
|
245 | - $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
249 | + else { |
|
250 | + $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
246 | 251 | 'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0', |
247 | 252 | 'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>', |
248 | 253 | 'can_edit' => false, |
@@ -252,6 +257,7 @@ discard block |
||
252 | 257 | 'poster' => $row['id_member'], |
253 | 258 | 'allowed_groups' => explode(',', $row['member_groups']), |
254 | 259 | )); |
260 | + } |
|
255 | 261 | |
256 | 262 | date_add($cal_date, date_interval_create_from_date_string('1 day')); |
257 | 263 | } |
@@ -261,8 +267,9 @@ discard block |
||
261 | 267 | // If we're doing normal contextual data, go through and make things clear to the templates ;). |
262 | 268 | if ($use_permissions) |
263 | 269 | { |
264 | - foreach ($events as $mday => $array) |
|
265 | - $events[$mday][count($array) - 1]['is_last'] = true; |
|
270 | + foreach ($events as $mday => $array) { |
|
271 | + $events[$mday][count($array) - 1]['is_last'] = true; |
|
272 | + } |
|
266 | 273 | } |
267 | 274 | |
268 | 275 | ksort($events); |
@@ -282,11 +289,12 @@ discard block |
||
282 | 289 | global $smcFunc; |
283 | 290 | |
284 | 291 | // Get the lowest and highest dates for "all years". |
285 | - if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) |
|
286 | - $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec} |
|
292 | + if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) { |
|
293 | + $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec} |
|
287 | 294 | OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}'; |
288 | - else |
|
289 | - $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}'; |
|
295 | + } else { |
|
296 | + $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}'; |
|
297 | + } |
|
290 | 298 | |
291 | 299 | // Find some holidays... ;). |
292 | 300 | $result = $smcFunc['db_query']('', ' |
@@ -306,10 +314,11 @@ discard block |
||
306 | 314 | $holidays = array(); |
307 | 315 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
308 | 316 | { |
309 | - if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) |
|
310 | - $event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4); |
|
311 | - else |
|
312 | - $event_year = substr($low_date, 0, 4); |
|
317 | + if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) { |
|
318 | + $event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4); |
|
319 | + } else { |
|
320 | + $event_year = substr($low_date, 0, 4); |
|
321 | + } |
|
313 | 322 | |
314 | 323 | $holidays[$event_year . substr($row['event_date'], 4)][] = $row['title']; |
315 | 324 | } |
@@ -335,10 +344,12 @@ discard block |
||
335 | 344 | isAllowedTo('calendar_post'); |
336 | 345 | |
337 | 346 | // No board? No topic?!? |
338 | - if (empty($board)) |
|
339 | - fatal_lang_error('missing_board_id', false); |
|
340 | - if (empty($topic)) |
|
341 | - fatal_lang_error('missing_topic_id', false); |
|
347 | + if (empty($board)) { |
|
348 | + fatal_lang_error('missing_board_id', false); |
|
349 | + } |
|
350 | + if (empty($topic)) { |
|
351 | + fatal_lang_error('missing_topic_id', false); |
|
352 | + } |
|
342 | 353 | |
343 | 354 | // Administrator, Moderator, or owner. Period. |
344 | 355 | if (!allowedTo('admin_forum') && !allowedTo('moderate_board')) |
@@ -356,12 +367,14 @@ discard block |
||
356 | 367 | if ($row = $smcFunc['db_fetch_assoc']($result)) |
357 | 368 | { |
358 | 369 | // Not the owner of the topic. |
359 | - if ($row['id_member_started'] != $user_info['id']) |
|
360 | - fatal_lang_error('not_your_topic', 'user'); |
|
370 | + if ($row['id_member_started'] != $user_info['id']) { |
|
371 | + fatal_lang_error('not_your_topic', 'user'); |
|
372 | + } |
|
361 | 373 | } |
362 | 374 | // Topic/Board doesn't exist..... |
363 | - else |
|
364 | - fatal_lang_error('calendar_no_topic', 'general'); |
|
375 | + else { |
|
376 | + fatal_lang_error('calendar_no_topic', 'general'); |
|
377 | + } |
|
365 | 378 | $smcFunc['db_free_result']($result); |
366 | 379 | } |
367 | 380 | } |
@@ -449,14 +462,16 @@ discard block |
||
449 | 462 | if (!empty($calendarOptions['start_day'])) |
450 | 463 | { |
451 | 464 | $nShift -= $calendarOptions['start_day']; |
452 | - if ($nShift < 0) |
|
453 | - $nShift = 7 + $nShift; |
|
465 | + if ($nShift < 0) { |
|
466 | + $nShift = 7 + $nShift; |
|
467 | + } |
|
454 | 468 | } |
455 | 469 | |
456 | 470 | // Number of rows required to fit the month. |
457 | 471 | $nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7); |
458 | - if (($month_info['last_day']['day_of_month'] + $nShift) % 7) |
|
459 | - $nRows++; |
|
472 | + if (($month_info['last_day']['day_of_month'] + $nShift) % 7) { |
|
473 | + $nRows++; |
|
474 | + } |
|
460 | 475 | |
461 | 476 | // Fetch the arrays for birthdays, posted events, and holidays. |
462 | 477 | $bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array(); |
@@ -469,8 +484,9 @@ discard block |
||
469 | 484 | { |
470 | 485 | $calendarGrid['week_days'][] = $count; |
471 | 486 | $count++; |
472 | - if ($count == 7) |
|
473 | - $count = 0; |
|
487 | + if ($count == 7) { |
|
488 | + $count = 0; |
|
489 | + } |
|
474 | 490 | } |
475 | 491 | |
476 | 492 | // Iterate through each week. |
@@ -487,8 +503,9 @@ discard block |
||
487 | 503 | { |
488 | 504 | $nDay = ($nRow * 7) + $nCol - $nShift + 1; |
489 | 505 | |
490 | - if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) |
|
491 | - $nDay = 0; |
|
506 | + if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) { |
|
507 | + $nDay = 0; |
|
508 | + } |
|
492 | 509 | |
493 | 510 | $date = sprintf('%04d-%02d-%02d', $year, $month, $nDay); |
494 | 511 | |
@@ -506,8 +523,9 @@ discard block |
||
506 | 523 | } |
507 | 524 | |
508 | 525 | // What is the last day of the month? |
509 | - if ($is_previous === true) |
|
510 | - $calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month']; |
|
526 | + if ($is_previous === true) { |
|
527 | + $calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month']; |
|
528 | + } |
|
511 | 529 | |
512 | 530 | // We'll use the shift in the template. |
513 | 531 | $calendarGrid['shift'] = $nShift; |
@@ -541,8 +559,9 @@ discard block |
||
541 | 559 | { |
542 | 560 | // Here we offset accordingly to get things to the real start of a week. |
543 | 561 | $date_diff = $day_of_week - $calendarOptions['start_day']; |
544 | - if ($date_diff < 0) |
|
545 | - $date_diff += 7; |
|
562 | + if ($date_diff < 0) { |
|
563 | + $date_diff += 7; |
|
564 | + } |
|
546 | 565 | $new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400; |
547 | 566 | $day = (int) strftime('%d', $new_timestamp); |
548 | 567 | $month = (int) strftime('%m', $new_timestamp); |
@@ -672,18 +691,20 @@ discard block |
||
672 | 691 | { |
673 | 692 | foreach ($date_events as $event_key => $event_val) |
674 | 693 | { |
675 | - if (in_array($event_val['id'], $temp)) |
|
676 | - unset($calendarGrid['events'][$date][$event_key]); |
|
677 | - else |
|
678 | - $temp[] = $event_val['id']; |
|
694 | + if (in_array($event_val['id'], $temp)) { |
|
695 | + unset($calendarGrid['events'][$date][$event_key]); |
|
696 | + } else { |
|
697 | + $temp[] = $event_val['id']; |
|
698 | + } |
|
679 | 699 | } |
680 | 700 | } |
681 | 701 | |
682 | 702 | // Give birthdays and holidays a friendly format, without the year |
683 | - if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
684 | - $date_format = '%b %d'; |
|
685 | - else |
|
686 | - $date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]); |
|
703 | + if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
704 | + $date_format = '%b %d'; |
|
705 | + } else { |
|
706 | + $date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]); |
|
707 | + } |
|
687 | 708 | |
688 | 709 | foreach (array('birthdays', 'holidays') as $type) |
689 | 710 | { |
@@ -791,8 +812,9 @@ discard block |
||
791 | 812 | // Holidays between now and now + days. |
792 | 813 | for ($i = $now; $i < $now + $days_for_index; $i += 86400) |
793 | 814 | { |
794 | - if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) |
|
795 | - $return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]); |
|
815 | + if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) { |
|
816 | + $return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]); |
|
817 | + } |
|
796 | 818 | } |
797 | 819 | |
798 | 820 | // Happy Birthday, guys and gals! |
@@ -801,8 +823,9 @@ discard block |
||
801 | 823 | $loop_date = strftime('%Y-%m-%d', $i); |
802 | 824 | if (isset($cached_data['birthdays'][$loop_date])) |
803 | 825 | { |
804 | - foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) |
|
805 | - $cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date']; |
|
826 | + foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) { |
|
827 | + $cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date']; |
|
828 | + } |
|
806 | 829 | $return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]); |
807 | 830 | } |
808 | 831 | } |
@@ -814,8 +837,9 @@ discard block |
||
814 | 837 | $loop_date = strftime('%Y-%m-%d', $i); |
815 | 838 | |
816 | 839 | // No events today? Check the next day. |
817 | - if (empty($cached_data['events'][$loop_date])) |
|
818 | - continue; |
|
840 | + if (empty($cached_data['events'][$loop_date])) { |
|
841 | + continue; |
|
842 | + } |
|
819 | 843 | |
820 | 844 | // Loop through all events to add a few last-minute values. |
821 | 845 | foreach ($cached_data['events'][$loop_date] as $ev => $event) |
@@ -828,9 +852,9 @@ discard block |
||
828 | 852 | { |
829 | 853 | unset($cached_data['events'][$loop_date][$ev]); |
830 | 854 | continue; |
855 | + } else { |
|
856 | + $duplicates[$this_event['topic'] . $this_event['title']] = true; |
|
831 | 857 | } |
832 | - else |
|
833 | - $duplicates[$this_event['topic'] . $this_event['title']] = true; |
|
834 | 858 | |
835 | 859 | // Might be set to true afterwards, depending on the permissions. |
836 | 860 | $this_event['can_edit'] = false; |
@@ -838,15 +862,18 @@ discard block |
||
838 | 862 | $this_event['date'] = $loop_date; |
839 | 863 | } |
840 | 864 | |
841 | - if (!empty($cached_data['events'][$loop_date])) |
|
842 | - $return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]); |
|
865 | + if (!empty($cached_data['events'][$loop_date])) { |
|
866 | + $return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]); |
|
867 | + } |
|
843 | 868 | } |
844 | 869 | |
845 | 870 | // Mark the last item so that a list separator can be used in the template. |
846 | - for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) |
|
847 | - $return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]); |
|
848 | - for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) |
|
849 | - $return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]); |
|
871 | + for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) { |
|
872 | + $return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]); |
|
873 | + } |
|
874 | + for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) { |
|
875 | + $return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]); |
|
876 | + } |
|
850 | 877 | |
851 | 878 | return array( |
852 | 879 | 'data' => $return_data, |
@@ -894,37 +921,46 @@ discard block |
||
894 | 921 | if (isset($_POST['start_date'])) |
895 | 922 | { |
896 | 923 | $d = date_parse($_POST['start_date']); |
897 | - if (!empty($d['error_count']) || !empty($d['warning_count'])) |
|
898 | - fatal_lang_error('invalid_date', false); |
|
899 | - if (empty($d['year'])) |
|
900 | - fatal_lang_error('event_year_missing', false); |
|
901 | - if (empty($d['month'])) |
|
902 | - fatal_lang_error('event_month_missing', false); |
|
903 | - } |
|
904 | - elseif (isset($_POST['start_datetime'])) |
|
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 | + } |
|
933 | + } elseif (isset($_POST['start_datetime'])) |
|
905 | 934 | { |
906 | 935 | $d = date_parse($_POST['start_datetime']); |
907 | - if (!empty($d['error_count']) || !empty($d['warning_count'])) |
|
908 | - fatal_lang_error('invalid_date', false); |
|
909 | - if (empty($d['year'])) |
|
910 | - fatal_lang_error('event_year_missing', false); |
|
911 | - if (empty($d['month'])) |
|
912 | - fatal_lang_error('event_month_missing', false); |
|
936 | + if (!empty($d['error_count']) || !empty($d['warning_count'])) { |
|
937 | + fatal_lang_error('invalid_date', false); |
|
938 | + } |
|
939 | + if (empty($d['year'])) { |
|
940 | + fatal_lang_error('event_year_missing', false); |
|
941 | + } |
|
942 | + if (empty($d['month'])) { |
|
943 | + fatal_lang_error('event_month_missing', false); |
|
944 | + } |
|
913 | 945 | } |
914 | 946 | // The 2.0 way |
915 | 947 | else |
916 | 948 | { |
917 | 949 | // No month? No year? |
918 | - if (!isset($_POST['month'])) |
|
919 | - fatal_lang_error('event_month_missing', false); |
|
920 | - if (!isset($_POST['year'])) |
|
921 | - fatal_lang_error('event_year_missing', false); |
|
950 | + if (!isset($_POST['month'])) { |
|
951 | + fatal_lang_error('event_month_missing', false); |
|
952 | + } |
|
953 | + if (!isset($_POST['year'])) { |
|
954 | + fatal_lang_error('event_year_missing', false); |
|
955 | + } |
|
922 | 956 | |
923 | 957 | // Check the month and year... |
924 | - if ($_POST['month'] < 1 || $_POST['month'] > 12) |
|
925 | - fatal_lang_error('invalid_month', false); |
|
926 | - if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) |
|
927 | - fatal_lang_error('invalid_year', false); |
|
958 | + if ($_POST['month'] < 1 || $_POST['month'] > 12) { |
|
959 | + fatal_lang_error('invalid_month', false); |
|
960 | + } |
|
961 | + if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) { |
|
962 | + fatal_lang_error('invalid_year', false); |
|
963 | + } |
|
928 | 964 | } |
929 | 965 | } |
930 | 966 | |
@@ -934,8 +970,9 @@ discard block |
||
934 | 970 | // If they want to us to calculate an end date, make sure it will fit in an acceptable range. |
935 | 971 | if (isset($_POST['span'])) |
936 | 972 | { |
937 | - if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) |
|
938 | - fatal_lang_error('invalid_days_numb', false); |
|
973 | + if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) { |
|
974 | + fatal_lang_error('invalid_days_numb', false); |
|
975 | + } |
|
939 | 976 | } |
940 | 977 | |
941 | 978 | // There is no need to validate the following values if we are just deleting the event. |
@@ -945,24 +982,29 @@ discard block |
||
945 | 982 | if (empty($_POST['start_date']) && empty($_POST['start_datetime'])) |
946 | 983 | { |
947 | 984 | // No day? |
948 | - if (!isset($_POST['day'])) |
|
949 | - fatal_lang_error('event_day_missing', false); |
|
985 | + if (!isset($_POST['day'])) { |
|
986 | + fatal_lang_error('event_day_missing', false); |
|
987 | + } |
|
950 | 988 | |
951 | 989 | // Bad day? |
952 | - if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) |
|
953 | - fatal_lang_error('invalid_date', false); |
|
990 | + if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) { |
|
991 | + fatal_lang_error('invalid_date', false); |
|
992 | + } |
|
954 | 993 | } |
955 | 994 | |
956 | - if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) |
|
957 | - fatal_lang_error('event_title_missing', false); |
|
958 | - elseif (!isset($_POST['evtitle'])) |
|
959 | - $_POST['evtitle'] = $_POST['subject']; |
|
995 | + if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) { |
|
996 | + fatal_lang_error('event_title_missing', false); |
|
997 | + } elseif (!isset($_POST['evtitle'])) { |
|
998 | + $_POST['evtitle'] = $_POST['subject']; |
|
999 | + } |
|
960 | 1000 | |
961 | 1001 | // No title? |
962 | - if ($smcFunc['htmltrim']($_POST['evtitle']) === '') |
|
963 | - fatal_lang_error('no_event_title', false); |
|
964 | - if ($smcFunc['strlen']($_POST['evtitle']) > 100) |
|
965 | - $_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100); |
|
1002 | + if ($smcFunc['htmltrim']($_POST['evtitle']) === '') { |
|
1003 | + fatal_lang_error('no_event_title', false); |
|
1004 | + } |
|
1005 | + if ($smcFunc['strlen']($_POST['evtitle']) > 100) { |
|
1006 | + $_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100); |
|
1007 | + } |
|
966 | 1008 | $_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']); |
967 | 1009 | } |
968 | 1010 | } |
@@ -989,8 +1031,9 @@ discard block |
||
989 | 1031 | ); |
990 | 1032 | |
991 | 1033 | // No results, return false. |
992 | - if ($smcFunc['db_num_rows'] === 0) |
|
993 | - return false; |
|
1034 | + if ($smcFunc['db_num_rows'] === 0) { |
|
1035 | + return false; |
|
1036 | + } |
|
994 | 1037 | |
995 | 1038 | // Grab the results and return. |
996 | 1039 | list ($poster) = $smcFunc['db_fetch_row']($request); |
@@ -1124,8 +1167,9 @@ discard block |
||
1124 | 1167 | call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters)); |
1125 | 1168 | |
1126 | 1169 | $column_clauses = array(); |
1127 | - foreach ($event_columns as $col => $crit) |
|
1128 | - $column_clauses[] = $col . ' = ' . $crit; |
|
1170 | + foreach ($event_columns as $col => $crit) { |
|
1171 | + $column_clauses[] = $col . ' = ' . $crit; |
|
1172 | + } |
|
1129 | 1173 | |
1130 | 1174 | $smcFunc['db_query']('', ' |
1131 | 1175 | UPDATE {db_prefix}calendar |
@@ -1210,8 +1254,9 @@ discard block |
||
1210 | 1254 | ); |
1211 | 1255 | |
1212 | 1256 | // If nothing returned, we are in poo, poo. |
1213 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
1214 | - return false; |
|
1257 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
1258 | + return false; |
|
1259 | + } |
|
1215 | 1260 | |
1216 | 1261 | $row = $smcFunc['db_fetch_assoc']($request); |
1217 | 1262 | $smcFunc['db_free_result']($request); |
@@ -1219,8 +1264,9 @@ discard block |
||
1219 | 1264 | list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
1220 | 1265 | |
1221 | 1266 | // Sanity check |
1222 | - if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
1223 | - return false; |
|
1267 | + if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) { |
|
1268 | + return false; |
|
1269 | + } |
|
1224 | 1270 | |
1225 | 1271 | $return_value = array( |
1226 | 1272 | 'boards' => array(), |
@@ -1357,24 +1403,27 @@ discard block |
||
1357 | 1403 | |
1358 | 1404 | // Set $span, in case we need it |
1359 | 1405 | $span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0); |
1360 | - if ($span > 0) |
|
1361 | - $span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1; |
|
1406 | + if ($span > 0) { |
|
1407 | + $span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1; |
|
1408 | + } |
|
1362 | 1409 | |
1363 | 1410 | // Define the timezone for this event, falling back to the default if not provided |
1364 | - if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
1365 | - $tz = $eventOptions['tz']; |
|
1366 | - elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
1367 | - $tz = $_POST['tz']; |
|
1368 | - else |
|
1369 | - $tz = getUserTimezone(); |
|
1411 | + if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
1412 | + $tz = $eventOptions['tz']; |
|
1413 | + } elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
1414 | + $tz = $_POST['tz']; |
|
1415 | + } else { |
|
1416 | + $tz = getUserTimezone(); |
|
1417 | + } |
|
1370 | 1418 | |
1371 | 1419 | // Is this supposed to be an all day event, or should it have specific start and end times? |
1372 | - if (isset($eventOptions['allday'])) |
|
1373 | - $allday = $eventOptions['allday']; |
|
1374 | - elseif (empty($_POST['allday'])) |
|
1375 | - $allday = false; |
|
1376 | - else |
|
1377 | - $allday = true; |
|
1420 | + if (isset($eventOptions['allday'])) { |
|
1421 | + $allday = $eventOptions['allday']; |
|
1422 | + } elseif (empty($_POST['allday'])) { |
|
1423 | + $allday = false; |
|
1424 | + } else { |
|
1425 | + $allday = true; |
|
1426 | + } |
|
1378 | 1427 | |
1379 | 1428 | // Input might come as individual parameters... |
1380 | 1429 | $start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null); |
@@ -1401,10 +1450,12 @@ discard block |
||
1401 | 1450 | $end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null); |
1402 | 1451 | |
1403 | 1452 | // If the date and time were given in separate strings, combine them |
1404 | - if (empty($start_string) && isset($start_date_string)) |
|
1405 | - $start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : ''); |
|
1406 | - if (empty($end_string) && isset($end_date_string)) |
|
1407 | - $end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : ''); |
|
1453 | + if (empty($start_string) && isset($start_date_string)) { |
|
1454 | + $start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : ''); |
|
1455 | + } |
|
1456 | + if (empty($end_string) && isset($end_date_string)) { |
|
1457 | + $end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : ''); |
|
1458 | + } |
|
1408 | 1459 | |
1409 | 1460 | // If some form of string input was given, override individually defined options with it |
1410 | 1461 | if (isset($start_string)) |
@@ -1495,10 +1546,11 @@ discard block |
||
1495 | 1546 | if ($start_object >= $end_object) |
1496 | 1547 | { |
1497 | 1548 | $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz); |
1498 | - if ($span > 0) |
|
1499 | - date_add($end_object, date_interval_create_from_date_string($span . ' days')); |
|
1500 | - else |
|
1501 | - date_add($end_object, date_interval_create_from_date_string('1 hour')); |
|
1549 | + if ($span > 0) { |
|
1550 | + date_add($end_object, date_interval_create_from_date_string($span . ' days')); |
|
1551 | + } else { |
|
1552 | + date_add($end_object, date_interval_create_from_date_string('1 hour')); |
|
1553 | + } |
|
1502 | 1554 | } |
1503 | 1555 | |
1504 | 1556 | // Is $end_object too late? |
@@ -1511,9 +1563,9 @@ discard block |
||
1511 | 1563 | { |
1512 | 1564 | $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz); |
1513 | 1565 | date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days')); |
1566 | + } else { |
|
1567 | + $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz); |
|
1514 | 1568 | } |
1515 | - else |
|
1516 | - $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz); |
|
1517 | 1569 | } |
1518 | 1570 | } |
1519 | 1571 | |
@@ -1526,8 +1578,7 @@ discard block |
||
1526 | 1578 | $start_time = null; |
1527 | 1579 | $end_time = null; |
1528 | 1580 | $tz = null; |
1529 | - } |
|
1530 | - else |
|
1581 | + } else |
|
1531 | 1582 | { |
1532 | 1583 | $start_time = date_format($start_object, 'H:i:s'); |
1533 | 1584 | $end_time = date_format($end_object, 'H:i:s'); |
@@ -1548,16 +1599,18 @@ discard block |
||
1548 | 1599 | require_once($sourcedir . '/Subs.php'); |
1549 | 1600 | |
1550 | 1601 | // First, try to create a better date format, ignoring the "time" elements. |
1551 | - if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
1552 | - $date_format = '%F'; |
|
1553 | - else |
|
1554 | - $date_format = $matches[0]; |
|
1602 | + if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
1603 | + $date_format = '%F'; |
|
1604 | + } else { |
|
1605 | + $date_format = $matches[0]; |
|
1606 | + } |
|
1555 | 1607 | |
1556 | 1608 | // We want a fairly compact version of the time, but as close as possible to the user's settings. |
1557 | - if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
1558 | - $time_format = '%k:%M'; |
|
1559 | - else |
|
1560 | - $time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
1609 | + if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
1610 | + $time_format = '%k:%M'; |
|
1611 | + } else { |
|
1612 | + $time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
1613 | + } |
|
1561 | 1614 | |
1562 | 1615 | // Should this be an all day event? |
1563 | 1616 | $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; |
@@ -1566,8 +1619,9 @@ discard block |
||
1566 | 1619 | $span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d'); |
1567 | 1620 | |
1568 | 1621 | // We need to have a defined timezone in the steps below |
1569 | - if (empty($row['timezone'])) |
|
1570 | - $row['timezone'] = getUserTimezone(); |
|
1622 | + if (empty($row['timezone'])) { |
|
1623 | + $row['timezone'] = getUserTimezone(); |
|
1624 | + } |
|
1571 | 1625 | |
1572 | 1626 | // Get most of the standard date information for the start and end datetimes |
1573 | 1627 | $start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : '')); |
@@ -1611,8 +1665,9 @@ discard block |
||
1611 | 1665 | $tz_location = timezone_location_get(timezone_open($row['timezone'])); |
1612 | 1666 | |
1613 | 1667 | // Kazakstan |
1614 | - if ($tz_location['country_code'] == 'KZ') |
|
1615 | - $tz_abbrev = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tz_abbrev); |
|
1668 | + if ($tz_location['country_code'] == 'KZ') { |
|
1669 | + $tz_abbrev = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tz_abbrev); |
|
1670 | + } |
|
1616 | 1671 | |
1617 | 1672 | // Russia likes to experiment with time zones |
1618 | 1673 | if ($tz_location['country_code'] == 'RU') |
@@ -1623,8 +1678,9 @@ discard block |
||
1623 | 1678 | } |
1624 | 1679 | |
1625 | 1680 | // Still no good? We'll just mark it as a UTC offset |
1626 | - if (strspn($tz_abbrev, '+-') > 0) |
|
1627 | - $tz_abbrev = 'UTC' . $tz_abbrev; |
|
1681 | + if (strspn($tz_abbrev, '+-') > 0) { |
|
1682 | + $tz_abbrev = 'UTC' . $tz_abbrev; |
|
1683 | + } |
|
1628 | 1684 | } |
1629 | 1685 | |
1630 | 1686 | return array($start, $end, $allday, $span, $tz, $tz_abbrev); |
@@ -1640,8 +1696,9 @@ discard block |
||
1640 | 1696 | { |
1641 | 1697 | global $smcFunc, $context, $sourcedir, $user_info, $modSettings; |
1642 | 1698 | |
1643 | - if (is_null($id_member) && $user_info['is_guest'] == false) |
|
1644 | - $id_member = $context['user']['id']; |
|
1699 | + if (is_null($id_member) && $user_info['is_guest'] == false) { |
|
1700 | + $id_member = $context['user']['id']; |
|
1701 | + } |
|
1645 | 1702 | |
1646 | 1703 | if (isset($id_member)) |
1647 | 1704 | { |
@@ -1657,8 +1714,9 @@ discard block |
||
1657 | 1714 | $smcFunc['db_free_result']($request); |
1658 | 1715 | } |
1659 | 1716 | |
1660 | - if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
1661 | - $timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get(); |
|
1717 | + if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
1718 | + $timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get(); |
|
1719 | + } |
|
1662 | 1720 | |
1663 | 1721 | return $timezone; |
1664 | 1722 | } |
@@ -1687,8 +1745,9 @@ discard block |
||
1687 | 1745 | ) |
1688 | 1746 | ); |
1689 | 1747 | $holidays = array(); |
1690 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1691 | - $holidays[] = $row; |
|
1748 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1749 | + $holidays[] = $row; |
|
1750 | + } |
|
1692 | 1751 | $smcFunc['db_free_result']($request); |
1693 | 1752 | |
1694 | 1753 | return $holidays; |