@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | class CreatePost_Notify_Background extends SMF_BackgroundTask |
19 | 19 | { |
20 | 20 | /** |
21 | - * This handles notifications when a new post is created - new topic, reply, quotes and mentions. |
|
21 | + * This handles notifications when a new post is created - new topic, reply, quotes and mentions. |
|
22 | 22 | * @return bool Always returns true |
23 | 23 | */ |
24 | 24 | public function execute() |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | |
107 | 107 | // Don't send a notification if the watching member ignored the member who made the action. |
108 | 108 | if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list']))) |
109 | - continue; |
|
109 | + continue; |
|
110 | 110 | if (!in_array($type, array('reply', 'topic')) && $notify_types == 2 && $member != $data['id_member_started']) |
111 | 111 | continue; |
112 | 112 | elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id']) |
@@ -73,8 +73,9 @@ discard block |
||
73 | 73 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
74 | 74 | { |
75 | 75 | $groups = array_merge(array($row['id_group'], $row['id_post_group']), (empty($row['additional_groups']) ? array() : explode(',', $row['additional_groups']))); |
76 | - if (!in_array(1, $groups) && count(array_intersect($groups, explode(',', $row['member_groups']))) == 0) |
|
77 | - continue; |
|
76 | + if (!in_array(1, $groups) && count(array_intersect($groups, explode(',', $row['member_groups']))) == 0) { |
|
77 | + continue; |
|
78 | + } |
|
78 | 79 | |
79 | 80 | $members[] = $row['id_member']; |
80 | 81 | $watched[$row['id_member']] = $row; |
@@ -82,8 +83,9 @@ discard block |
||
82 | 83 | |
83 | 84 | $smcFunc['db_free_result']($request); |
84 | 85 | |
85 | - if (empty($members)) |
|
86 | - return true; |
|
86 | + if (empty($members)) { |
|
87 | + return true; |
|
88 | + } |
|
87 | 89 | |
88 | 90 | $members = array_unique($members); |
89 | 91 | $prefs = getNotifyPrefs($members, '', true); |
@@ -105,20 +107,23 @@ discard block |
||
105 | 107 | $notify_types = !empty($prefs[$member]['msg_notify_type']) ? $prefs[$member]['msg_notify_type'] : 1; |
106 | 108 | |
107 | 109 | // Don't send a notification if the watching member ignored the member who made the action. |
108 | - if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list']))) |
|
109 | - continue; |
|
110 | - if (!in_array($type, array('reply', 'topic')) && $notify_types == 2 && $member != $data['id_member_started']) |
|
111 | - continue; |
|
112 | - elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id']) |
|
113 | - continue; |
|
114 | - elseif (!in_array($type, array('reply', 'topic')) && $notify_types == 3) |
|
115 | - continue; |
|
116 | - elseif ($notify_types == 4) |
|
117 | - continue; |
|
110 | + if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list']))) { |
|
111 | + continue; |
|
112 | + } |
|
113 | + if (!in_array($type, array('reply', 'topic')) && $notify_types == 2 && $member != $data['id_member_started']) { |
|
114 | + continue; |
|
115 | + } elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id']) { |
|
116 | + continue; |
|
117 | + } elseif (!in_array($type, array('reply', 'topic')) && $notify_types == 3) { |
|
118 | + continue; |
|
119 | + } elseif ($notify_types == 4) { |
|
120 | + continue; |
|
121 | + } |
|
118 | 122 | |
119 | 123 | if ($frequency > 2 || (!empty($frequency) && $data['sent']) || in_array($member, $done_members) |
120 | - || (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only']))) |
|
121 | - continue; |
|
124 | + || (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only']))) { |
|
125 | + continue; |
|
126 | + } |
|
122 | 127 | |
123 | 128 | // Watched topic? |
124 | 129 | if (!empty($data['id_topic']) && $type != 'topic' && !empty($prefs[$member])) |
@@ -128,10 +133,12 @@ discard block |
||
128 | 133 | |
129 | 134 | if ($type == 'reply') |
130 | 135 | { |
131 | - if (!empty($prefs[$member]['msg_receive_body'])) |
|
132 | - $message_type .= '_body'; |
|
133 | - if (!empty($frequency)) |
|
134 | - $message_type .= '_once'; |
|
136 | + if (!empty($prefs[$member]['msg_receive_body'])) { |
|
137 | + $message_type .= '_body'; |
|
138 | + } |
|
139 | + if (!empty($frequency)) { |
|
140 | + $message_type .= '_once'; |
|
141 | + } |
|
135 | 142 | } |
136 | 143 | |
137 | 144 | $content_type = 'topic'; |
@@ -144,12 +151,14 @@ discard block |
||
144 | 151 | $content_type = 'board'; |
145 | 152 | |
146 | 153 | $message_type = !empty($frequency) ? 'notify_boards_once' : 'notify_boards'; |
147 | - if (!empty($prefs[$member]['msg_receive_body'])) |
|
148 | - $message_type .= '_body'; |
|
154 | + if (!empty($prefs[$member]['msg_receive_body'])) { |
|
155 | + $message_type .= '_body'; |
|
156 | + } |
|
149 | 157 | } |
150 | 158 | // If neither of the above, this might be a redundent row due to the OR clause in our SQL query, skip |
151 | - else |
|
152 | - continue; |
|
159 | + else { |
|
160 | + continue; |
|
161 | + } |
|
153 | 162 | |
154 | 163 | if ($pref & 0x02) |
155 | 164 | { |
@@ -212,14 +221,15 @@ discard block |
||
212 | 221 | ); |
213 | 222 | |
214 | 223 | // Insert the alerts if any |
215 | - if (!empty($alert_rows)) |
|
216 | - $smcFunc['db_insert']('', |
|
224 | + if (!empty($alert_rows)) { |
|
225 | + $smcFunc['db_insert']('', |
|
217 | 226 | '{db_prefix}user_alerts', |
218 | 227 | array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string', |
219 | 228 | 'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'), |
220 | 229 | $alert_rows, |
221 | 230 | array() |
222 | 231 | ); |
232 | + } |
|
223 | 233 | |
224 | 234 | return true; |
225 | 235 | } |
@@ -230,8 +240,9 @@ discard block |
||
230 | 240 | |
231 | 241 | foreach ($quotedMembers as $id => $member) |
232 | 242 | { |
233 | - if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote'])) |
|
234 | - continue; |
|
243 | + if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote'])) { |
|
244 | + continue; |
|
245 | + } |
|
235 | 246 | |
236 | 247 | $done_members[] = $id; |
237 | 248 | |
@@ -283,32 +294,35 @@ discard block |
||
283 | 294 | { |
284 | 295 | if (preg_match('/\[quote(.*)?\]/i', $block, $matches)) |
285 | 296 | { |
286 | - if ($quote_level == 0) |
|
287 | - $message .= '[quote' . $matches[1] . ']'; |
|
297 | + if ($quote_level == 0) { |
|
298 | + $message .= '[quote' . $matches[1] . ']'; |
|
299 | + } |
|
288 | 300 | $quote_level++; |
289 | - } |
|
290 | - elseif (preg_match('/\[\/quote\]/i', $block)) |
|
301 | + } elseif (preg_match('/\[\/quote\]/i', $block)) |
|
291 | 302 | { |
292 | - if ($quote_level <= 1) |
|
293 | - $message .= '[/quote]'; |
|
303 | + if ($quote_level <= 1) { |
|
304 | + $message .= '[/quote]'; |
|
305 | + } |
|
294 | 306 | if ($quote_level >= 1) |
295 | 307 | { |
296 | 308 | $quote_level--; |
297 | 309 | $message .= "\n"; |
298 | 310 | } |
311 | + } elseif ($quote_level <= 1) { |
|
312 | + $message .= $block; |
|
299 | 313 | } |
300 | - elseif ($quote_level <= 1) |
|
301 | - $message .= $block; |
|
302 | 314 | } |
303 | 315 | |
304 | 316 | preg_match_all('/\[quote.*?link=msg=([0-9]+).*?\]/i', $message, $matches); |
305 | 317 | |
306 | 318 | $id_msgs = $matches[1]; |
307 | - foreach ($id_msgs as $k => $id_msg) |
|
308 | - $id_msgs[$k] = (int) $id_msg; |
|
319 | + foreach ($id_msgs as $k => $id_msg) { |
|
320 | + $id_msgs[$k] = (int) $id_msg; |
|
321 | + } |
|
309 | 322 | |
310 | - if (empty($id_msgs)) |
|
311 | - return array(); |
|
323 | + if (empty($id_msgs)) { |
|
324 | + return array(); |
|
325 | + } |
|
312 | 326 | |
313 | 327 | // Get the messages |
314 | 328 | $request = $smcFunc['db_query']('', ' |
@@ -326,8 +340,9 @@ discard block |
||
326 | 340 | $members = array(); |
327 | 341 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
328 | 342 | { |
329 | - if ($posterOptions['id'] == $row['id_member']) |
|
330 | - continue; |
|
343 | + if ($posterOptions['id'] == $row['id_member']) { |
|
344 | + continue; |
|
345 | + } |
|
331 | 346 | |
332 | 347 | $members[$row['id_member']] = $row; |
333 | 348 | } |
@@ -341,10 +356,11 @@ discard block |
||
341 | 356 | |
342 | 357 | foreach ($members as $id => $member) |
343 | 358 | { |
344 | - if (!empty($prefs[$id]['msg_mention'])) |
|
345 | - $done_members[] = $id; |
|
346 | - else |
|
347 | - continue; |
|
359 | + if (!empty($prefs[$id]['msg_mention'])) { |
|
360 | + $done_members[] = $id; |
|
361 | + } else { |
|
362 | + continue; |
|
363 | + } |
|
348 | 364 | |
349 | 365 | // Alerts' emails are always instant |
350 | 366 | if ($prefs[$id]['msg_mention'] & 0x02) |
@@ -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. |
@@ -60,8 +61,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | { |
@@ -792,8 +813,9 @@ discard block |
||
792 | 813 | // Holidays between now and now + days. |
793 | 814 | for ($i = $now; $i < $now + $days_for_index; $i += 86400) |
794 | 815 | { |
795 | - if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) |
|
796 | - $return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]); |
|
816 | + if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) { |
|
817 | + $return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]); |
|
818 | + } |
|
797 | 819 | } |
798 | 820 | |
799 | 821 | // Happy Birthday, guys and gals! |
@@ -802,8 +824,9 @@ discard block |
||
802 | 824 | $loop_date = strftime('%Y-%m-%d', $i); |
803 | 825 | if (isset($cached_data['birthdays'][$loop_date])) |
804 | 826 | { |
805 | - foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) |
|
806 | - $cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date']; |
|
827 | + foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) { |
|
828 | + $cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date']; |
|
829 | + } |
|
807 | 830 | $return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]); |
808 | 831 | } |
809 | 832 | } |
@@ -815,8 +838,9 @@ discard block |
||
815 | 838 | $loop_date = strftime('%Y-%m-%d', $i); |
816 | 839 | |
817 | 840 | // No events today? Check the next day. |
818 | - if (empty($cached_data['events'][$loop_date])) |
|
819 | - continue; |
|
841 | + if (empty($cached_data['events'][$loop_date])) { |
|
842 | + continue; |
|
843 | + } |
|
820 | 844 | |
821 | 845 | // Loop through all events to add a few last-minute values. |
822 | 846 | foreach ($cached_data['events'][$loop_date] as $ev => $event) |
@@ -829,9 +853,9 @@ discard block |
||
829 | 853 | { |
830 | 854 | unset($cached_data['events'][$loop_date][$ev]); |
831 | 855 | continue; |
856 | + } else { |
|
857 | + $duplicates[$this_event['topic'] . $this_event['title']] = true; |
|
832 | 858 | } |
833 | - else |
|
834 | - $duplicates[$this_event['topic'] . $this_event['title']] = true; |
|
835 | 859 | |
836 | 860 | // Might be set to true afterwards, depending on the permissions. |
837 | 861 | $this_event['can_edit'] = false; |
@@ -839,15 +863,18 @@ discard block |
||
839 | 863 | $this_event['date'] = $loop_date; |
840 | 864 | } |
841 | 865 | |
842 | - if (!empty($cached_data['events'][$loop_date])) |
|
843 | - $return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]); |
|
866 | + if (!empty($cached_data['events'][$loop_date])) { |
|
867 | + $return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]); |
|
868 | + } |
|
844 | 869 | } |
845 | 870 | |
846 | 871 | // Mark the last item so that a list separator can be used in the template. |
847 | - for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) |
|
848 | - $return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]); |
|
849 | - for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) |
|
850 | - $return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]); |
|
872 | + for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) { |
|
873 | + $return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]); |
|
874 | + } |
|
875 | + for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) { |
|
876 | + $return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]); |
|
877 | + } |
|
851 | 878 | |
852 | 879 | return array( |
853 | 880 | 'data' => $return_data, |
@@ -895,37 +922,46 @@ discard block |
||
895 | 922 | if (isset($_POST['start_date'])) |
896 | 923 | { |
897 | 924 | $d = date_parse($_POST['start_date']); |
898 | - if (!empty($d['error_count']) || !empty($d['warning_count'])) |
|
899 | - fatal_lang_error('invalid_date', false); |
|
900 | - if (empty($d['year'])) |
|
901 | - fatal_lang_error('event_year_missing', false); |
|
902 | - if (empty($d['month'])) |
|
903 | - fatal_lang_error('event_month_missing', false); |
|
904 | - } |
|
905 | - elseif (isset($_POST['start_datetime'])) |
|
925 | + if (!empty($d['error_count']) || !empty($d['warning_count'])) { |
|
926 | + fatal_lang_error('invalid_date', false); |
|
927 | + } |
|
928 | + if (empty($d['year'])) { |
|
929 | + fatal_lang_error('event_year_missing', false); |
|
930 | + } |
|
931 | + if (empty($d['month'])) { |
|
932 | + fatal_lang_error('event_month_missing', false); |
|
933 | + } |
|
934 | + } elseif (isset($_POST['start_datetime'])) |
|
906 | 935 | { |
907 | 936 | $d = date_parse($_POST['start_datetime']); |
908 | - if (!empty($d['error_count']) || !empty($d['warning_count'])) |
|
909 | - fatal_lang_error('invalid_date', false); |
|
910 | - if (empty($d['year'])) |
|
911 | - fatal_lang_error('event_year_missing', false); |
|
912 | - if (empty($d['month'])) |
|
913 | - fatal_lang_error('event_month_missing', false); |
|
937 | + if (!empty($d['error_count']) || !empty($d['warning_count'])) { |
|
938 | + fatal_lang_error('invalid_date', false); |
|
939 | + } |
|
940 | + if (empty($d['year'])) { |
|
941 | + fatal_lang_error('event_year_missing', false); |
|
942 | + } |
|
943 | + if (empty($d['month'])) { |
|
944 | + fatal_lang_error('event_month_missing', false); |
|
945 | + } |
|
914 | 946 | } |
915 | 947 | // The 2.0 way |
916 | 948 | else |
917 | 949 | { |
918 | 950 | // No month? No year? |
919 | - if (!isset($_POST['month'])) |
|
920 | - fatal_lang_error('event_month_missing', false); |
|
921 | - if (!isset($_POST['year'])) |
|
922 | - fatal_lang_error('event_year_missing', false); |
|
951 | + if (!isset($_POST['month'])) { |
|
952 | + fatal_lang_error('event_month_missing', false); |
|
953 | + } |
|
954 | + if (!isset($_POST['year'])) { |
|
955 | + fatal_lang_error('event_year_missing', false); |
|
956 | + } |
|
923 | 957 | |
924 | 958 | // Check the month and year... |
925 | - if ($_POST['month'] < 1 || $_POST['month'] > 12) |
|
926 | - fatal_lang_error('invalid_month', false); |
|
927 | - if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) |
|
928 | - fatal_lang_error('invalid_year', false); |
|
959 | + if ($_POST['month'] < 1 || $_POST['month'] > 12) { |
|
960 | + fatal_lang_error('invalid_month', false); |
|
961 | + } |
|
962 | + if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) { |
|
963 | + fatal_lang_error('invalid_year', false); |
|
964 | + } |
|
929 | 965 | } |
930 | 966 | } |
931 | 967 | |
@@ -935,8 +971,9 @@ discard block |
||
935 | 971 | // If they want to us to calculate an end date, make sure it will fit in an acceptable range. |
936 | 972 | if (isset($_POST['span'])) |
937 | 973 | { |
938 | - if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) |
|
939 | - fatal_lang_error('invalid_days_numb', false); |
|
974 | + if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) { |
|
975 | + fatal_lang_error('invalid_days_numb', false); |
|
976 | + } |
|
940 | 977 | } |
941 | 978 | |
942 | 979 | // There is no need to validate the following values if we are just deleting the event. |
@@ -946,24 +983,29 @@ discard block |
||
946 | 983 | if (empty($_POST['start_date']) && empty($_POST['start_datetime'])) |
947 | 984 | { |
948 | 985 | // No day? |
949 | - if (!isset($_POST['day'])) |
|
950 | - fatal_lang_error('event_day_missing', false); |
|
986 | + if (!isset($_POST['day'])) { |
|
987 | + fatal_lang_error('event_day_missing', false); |
|
988 | + } |
|
951 | 989 | |
952 | 990 | // Bad day? |
953 | - if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) |
|
954 | - fatal_lang_error('invalid_date', false); |
|
991 | + if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) { |
|
992 | + fatal_lang_error('invalid_date', false); |
|
993 | + } |
|
955 | 994 | } |
956 | 995 | |
957 | - if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) |
|
958 | - fatal_lang_error('event_title_missing', false); |
|
959 | - elseif (!isset($_POST['evtitle'])) |
|
960 | - $_POST['evtitle'] = $_POST['subject']; |
|
996 | + if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) { |
|
997 | + fatal_lang_error('event_title_missing', false); |
|
998 | + } elseif (!isset($_POST['evtitle'])) { |
|
999 | + $_POST['evtitle'] = $_POST['subject']; |
|
1000 | + } |
|
961 | 1001 | |
962 | 1002 | // No title? |
963 | - if ($smcFunc['htmltrim']($_POST['evtitle']) === '') |
|
964 | - fatal_lang_error('no_event_title', false); |
|
965 | - if ($smcFunc['strlen']($_POST['evtitle']) > 100) |
|
966 | - $_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100); |
|
1003 | + if ($smcFunc['htmltrim']($_POST['evtitle']) === '') { |
|
1004 | + fatal_lang_error('no_event_title', false); |
|
1005 | + } |
|
1006 | + if ($smcFunc['strlen']($_POST['evtitle']) > 100) { |
|
1007 | + $_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100); |
|
1008 | + } |
|
967 | 1009 | $_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']); |
968 | 1010 | } |
969 | 1011 | } |
@@ -990,8 +1032,9 @@ discard block |
||
990 | 1032 | ); |
991 | 1033 | |
992 | 1034 | // No results, return false. |
993 | - if ($smcFunc['db_num_rows'] === 0) |
|
994 | - return false; |
|
1035 | + if ($smcFunc['db_num_rows'] === 0) { |
|
1036 | + return false; |
|
1037 | + } |
|
995 | 1038 | |
996 | 1039 | // Grab the results and return. |
997 | 1040 | list ($poster) = $smcFunc['db_fetch_row']($request); |
@@ -1125,8 +1168,9 @@ discard block |
||
1125 | 1168 | call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters)); |
1126 | 1169 | |
1127 | 1170 | $column_clauses = array(); |
1128 | - foreach ($event_columns as $col => $crit) |
|
1129 | - $column_clauses[] = $col . ' = ' . $crit; |
|
1171 | + foreach ($event_columns as $col => $crit) { |
|
1172 | + $column_clauses[] = $col . ' = ' . $crit; |
|
1173 | + } |
|
1130 | 1174 | |
1131 | 1175 | $smcFunc['db_query']('', ' |
1132 | 1176 | UPDATE {db_prefix}calendar |
@@ -1211,8 +1255,9 @@ discard block |
||
1211 | 1255 | ); |
1212 | 1256 | |
1213 | 1257 | // If nothing returned, we are in poo, poo. |
1214 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
1215 | - return false; |
|
1258 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
1259 | + return false; |
|
1260 | + } |
|
1216 | 1261 | |
1217 | 1262 | $row = $smcFunc['db_fetch_assoc']($request); |
1218 | 1263 | $smcFunc['db_free_result']($request); |
@@ -1220,8 +1265,9 @@ discard block |
||
1220 | 1265 | list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
1221 | 1266 | |
1222 | 1267 | // Sanity check |
1223 | - if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
1224 | - return false; |
|
1268 | + if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) { |
|
1269 | + return false; |
|
1270 | + } |
|
1225 | 1271 | |
1226 | 1272 | $return_value = array( |
1227 | 1273 | 'boards' => array(), |
@@ -1358,24 +1404,27 @@ discard block |
||
1358 | 1404 | |
1359 | 1405 | // Set $span, in case we need it |
1360 | 1406 | $span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0); |
1361 | - if ($span > 0) |
|
1362 | - $span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1; |
|
1407 | + if ($span > 0) { |
|
1408 | + $span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1; |
|
1409 | + } |
|
1363 | 1410 | |
1364 | 1411 | // Define the timezone for this event, falling back to the default if not provided |
1365 | - if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
1366 | - $tz = $eventOptions['tz']; |
|
1367 | - elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
1368 | - $tz = $_POST['tz']; |
|
1369 | - else |
|
1370 | - $tz = getUserTimezone(); |
|
1412 | + if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
1413 | + $tz = $eventOptions['tz']; |
|
1414 | + } elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
1415 | + $tz = $_POST['tz']; |
|
1416 | + } else { |
|
1417 | + $tz = getUserTimezone(); |
|
1418 | + } |
|
1371 | 1419 | |
1372 | 1420 | // Is this supposed to be an all day event, or should it have specific start and end times? |
1373 | - if (isset($eventOptions['allday'])) |
|
1374 | - $allday = $eventOptions['allday']; |
|
1375 | - elseif (empty($_POST['allday'])) |
|
1376 | - $allday = false; |
|
1377 | - else |
|
1378 | - $allday = true; |
|
1421 | + if (isset($eventOptions['allday'])) { |
|
1422 | + $allday = $eventOptions['allday']; |
|
1423 | + } elseif (empty($_POST['allday'])) { |
|
1424 | + $allday = false; |
|
1425 | + } else { |
|
1426 | + $allday = true; |
|
1427 | + } |
|
1379 | 1428 | |
1380 | 1429 | // Input might come as individual parameters... |
1381 | 1430 | $start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null); |
@@ -1402,10 +1451,12 @@ discard block |
||
1402 | 1451 | $end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null); |
1403 | 1452 | |
1404 | 1453 | // If the date and time were given in separate strings, combine them |
1405 | - if (empty($start_string) && isset($start_date_string)) |
|
1406 | - $start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : ''); |
|
1407 | - if (empty($end_string) && isset($end_date_string)) |
|
1408 | - $end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : ''); |
|
1454 | + if (empty($start_string) && isset($start_date_string)) { |
|
1455 | + $start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : ''); |
|
1456 | + } |
|
1457 | + if (empty($end_string) && isset($end_date_string)) { |
|
1458 | + $end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : ''); |
|
1459 | + } |
|
1409 | 1460 | |
1410 | 1461 | // If some form of string input was given, override individually defined options with it |
1411 | 1462 | if (isset($start_string)) |
@@ -1496,10 +1547,11 @@ discard block |
||
1496 | 1547 | if ($start_object >= $end_object) |
1497 | 1548 | { |
1498 | 1549 | $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz); |
1499 | - if ($span > 0) |
|
1500 | - date_add($end_object, date_interval_create_from_date_string($span . ' days')); |
|
1501 | - else |
|
1502 | - date_add($end_object, date_interval_create_from_date_string('1 hour')); |
|
1550 | + if ($span > 0) { |
|
1551 | + date_add($end_object, date_interval_create_from_date_string($span . ' days')); |
|
1552 | + } else { |
|
1553 | + date_add($end_object, date_interval_create_from_date_string('1 hour')); |
|
1554 | + } |
|
1503 | 1555 | } |
1504 | 1556 | |
1505 | 1557 | // Is $end_object too late? |
@@ -1512,9 +1564,9 @@ discard block |
||
1512 | 1564 | { |
1513 | 1565 | $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz); |
1514 | 1566 | date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days')); |
1567 | + } else { |
|
1568 | + $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz); |
|
1515 | 1569 | } |
1516 | - else |
|
1517 | - $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz); |
|
1518 | 1570 | } |
1519 | 1571 | } |
1520 | 1572 | |
@@ -1527,8 +1579,7 @@ discard block |
||
1527 | 1579 | $start_time = null; |
1528 | 1580 | $end_time = null; |
1529 | 1581 | $tz = null; |
1530 | - } |
|
1531 | - else |
|
1582 | + } else |
|
1532 | 1583 | { |
1533 | 1584 | $start_time = date_format($start_object, 'H:i:s'); |
1534 | 1585 | $end_time = date_format($end_object, 'H:i:s'); |
@@ -1549,16 +1600,18 @@ discard block |
||
1549 | 1600 | require_once($sourcedir . '/Subs.php'); |
1550 | 1601 | |
1551 | 1602 | // First, try to create a better date format, ignoring the "time" elements. |
1552 | - if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
1553 | - $date_format = '%F'; |
|
1554 | - else |
|
1555 | - $date_format = $matches[0]; |
|
1603 | + if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
1604 | + $date_format = '%F'; |
|
1605 | + } else { |
|
1606 | + $date_format = $matches[0]; |
|
1607 | + } |
|
1556 | 1608 | |
1557 | 1609 | // We want a fairly compact version of the time, but as close as possible to the user's settings. |
1558 | - if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
1559 | - $time_format = '%k:%M'; |
|
1560 | - else |
|
1561 | - $time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
1610 | + if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
1611 | + $time_format = '%k:%M'; |
|
1612 | + } else { |
|
1613 | + $time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
1614 | + } |
|
1562 | 1615 | |
1563 | 1616 | // Should this be an all day event? |
1564 | 1617 | $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; |
@@ -1567,8 +1620,9 @@ discard block |
||
1567 | 1620 | $span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d'); |
1568 | 1621 | |
1569 | 1622 | // We need to have a defined timezone in the steps below |
1570 | - if (empty($row['timezone'])) |
|
1571 | - $row['timezone'] = getUserTimezone(); |
|
1623 | + if (empty($row['timezone'])) { |
|
1624 | + $row['timezone'] = getUserTimezone(); |
|
1625 | + } |
|
1572 | 1626 | |
1573 | 1627 | // Get most of the standard date information for the start and end datetimes |
1574 | 1628 | $start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : '')); |
@@ -1612,8 +1666,9 @@ discard block |
||
1612 | 1666 | $tz_location = timezone_location_get(timezone_open($row['timezone'])); |
1613 | 1667 | |
1614 | 1668 | // Kazakstan |
1615 | - if ($tz_location['country_code'] == 'KZ') |
|
1616 | - $tz_abbrev = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tz_abbrev); |
|
1669 | + if ($tz_location['country_code'] == 'KZ') { |
|
1670 | + $tz_abbrev = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tz_abbrev); |
|
1671 | + } |
|
1617 | 1672 | |
1618 | 1673 | // Russia likes to experiment with time zones |
1619 | 1674 | if ($tz_location['country_code'] == 'RU') |
@@ -1624,8 +1679,9 @@ discard block |
||
1624 | 1679 | } |
1625 | 1680 | |
1626 | 1681 | // Still no good? We'll just mark it as a UTC offset |
1627 | - if (strspn($tz_abbrev, '+-') > 0) |
|
1628 | - $tz_abbrev = 'UTC' . $tz_abbrev; |
|
1682 | + if (strspn($tz_abbrev, '+-') > 0) { |
|
1683 | + $tz_abbrev = 'UTC' . $tz_abbrev; |
|
1684 | + } |
|
1629 | 1685 | } |
1630 | 1686 | |
1631 | 1687 | return array($start, $end, $allday, $span, $tz, $tz_abbrev); |
@@ -1642,8 +1698,9 @@ discard block |
||
1642 | 1698 | global $smcFunc, $context, $sourcedir, $user_info, $modSettings; |
1643 | 1699 | static $member_cache = array(); |
1644 | 1700 | |
1645 | - if (is_null($id_member) && $user_info['is_guest'] == false) |
|
1646 | - $id_member = $context['user']['id']; |
|
1701 | + if (is_null($id_member) && $user_info['is_guest'] == false) { |
|
1702 | + $id_member = $context['user']['id']; |
|
1703 | + } |
|
1647 | 1704 | |
1648 | 1705 | //check if the cache got the data |
1649 | 1706 | if (isset($id_member) && isset($member_cache[$id_member])) |
@@ -1665,11 +1722,13 @@ discard block |
||
1665 | 1722 | $smcFunc['db_free_result']($request); |
1666 | 1723 | } |
1667 | 1724 | |
1668 | - if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
1669 | - $timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get(); |
|
1725 | + if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
1726 | + $timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get(); |
|
1727 | + } |
|
1670 | 1728 | |
1671 | - if (isset($id_member)) |
|
1672 | - $member_cache[$id_member] = $timezone; |
|
1729 | + if (isset($id_member)) { |
|
1730 | + $member_cache[$id_member] = $timezone; |
|
1731 | + } |
|
1673 | 1732 | |
1674 | 1733 | return $timezone; |
1675 | 1734 | } |
@@ -1698,8 +1757,9 @@ discard block |
||
1698 | 1757 | ) |
1699 | 1758 | ); |
1700 | 1759 | $holidays = array(); |
1701 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1702 | - $holidays[] = $row; |
|
1760 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1761 | + $holidays[] = $row; |
|
1762 | + } |
|
1703 | 1763 | $smcFunc['db_free_result']($request); |
1704 | 1764 | |
1705 | 1765 | return $holidays; |