125
125
$this->setRawNode('noDataMessage', $this->getSanitizer()->getParam('noDataMessage', $this->getSanitizer()->getParam('noDataMessage', null)));
126
126
$this->setRawNode('styleSheet', $this->getSanitizer()->getParam('styleSheet', $this->getSanitizer()->getParam('styleSheet', null)));
128
$this->setOption('useEventTimezone', $this->getSanitizer()->getCheckbox('useEventTimezone'));
129
$this->setOption('useCalendarTimezone', $this->getSanitizer()->getCheckbox('useCalendarTimezone'));
130
$this->setOption('windowsFormatCalendar', $this->getSanitizer()->getCheckbox('windowsFormatCalendar'));
128
132
$this->validate();
129
133
$this->saveWidget();
267
271
// Prepare the items array, sorting it and removing any items that have expired.
268
272
$.each(items, function(index, element) {
269
273
// Parse the item and add it to the array if it has not finished yet
270
var endDate = moment(element.endDate, "X");
274
var endDate = moment(element.endDate);
272
276
if (endDate.isAfter(now)) {
273
if (moment(element.startDate, "X").isBefore(now)) {
277
if (moment(element.startDate).isBefore(now)) {
274
278
parsedItems.push(element.currentEventItem);
276
280
parsedItems.push(element.item);
369
373
// Create an ICal helper and pass it the contents of the file.
374
$iCal = new ICal(false, [
375
'replaceWindowsTimeZoneIds' => ($this->getSetting('replaceWindowsTimeZoneIds', 0) == 1)
373
379
$iCal->initString($feed);
377
383
throw new ConfigurationException(__('The iCal provided is not valid, please choose a valid feed'));
386
// Before we parse anything - should we use the calendar timezone as a base for our calculations?
387
if ($this->getSetting('useCalendarTimezone') == 1) {
388
$iCal->defaultTimeZone = $iCal->calendarTimeZone();
380
391
// We've got something at least, so prepare the template
382
393
preg_match_all('/\[.*?\]/', $template, $matches);
400
410
$this->getLog()->debug('Start of day is ' . $startOfDay->toDateTimeString());
401
411
$this->getLog()->debug('End of day is ' . $endOfDay->toDateTimeString());
413
// Force timezone of each event?
414
$useEventTimezone = $this->getSetting('useEventTimezone', 1);
403
416
// Go through each event returned
404
417
foreach ($iCal->eventsFromInterval($this->getOption('customInterval', '1 week')) as $event) {
405
418
/** @var \ICal\Event $event */
406
$startDt = Date::createFromFormat('U', $iCal->iCalDateToUnixTimestamp($event->dtstart));
407
$endDt = Date::createFromFormat('U', $iCal->iCalDateToUnixTimestamp($event->dtend));
409
if ($excludeAllDay && $startDt->equalTo($startOfDay) && $endDt->equalTo($endOfDay))
419
$startDt = Date::instance($iCal->iCalDateToDateTime($event->dtstart, $useEventTimezone));
420
$endDt = Date::instance($iCal->iCalDateToDateTime($event->dtend, $useEventTimezone));
422
$this->getLog()->debug('Event with ' . $startDt->format('c') . ' / ' . $endDt->format('c') . '. diff in days = ' . $endDt->diff($startDt)->days);
424
if ($excludeAllDay && ($endDt->diff($startDt)->days >= 1))
412
427
// Substitute for all matches in the template
413
$rowString = $this->substituteForEvent($matches, $template, $iCal, $dateFormat, $event);
428
$rowString = $this->substituteForEvent($matches, $template, $startDt, $endDt, $dateFormat, $event);
415
430
if ($currentEventTemplate != '') {
416
$currentEventRow = $this->substituteForEvent($currentEventMatches, $currentEventTemplate, $iCal, $dateFormat, $event);
431
$currentEventRow = $this->substituteForEvent($currentEventMatches, $currentEventTemplate, $startDt, $endDt, $dateFormat, $event);
418
433
$currentEventRow = $rowString;
422
'startDate' => $iCal->iCalDateToUnixTimestamp($event->dtstart),
423
'endDate' => $iCal->iCalDateToUnixTimestamp($event->dtend),
437
'startDate' => $startDt->format('c'),
438
'endDate' => $endDt->format('c'),
424
439
'item' => $rowString,
425
440
'currentEventItem' => $currentEventRow
433
448
* @param $matches
450
* @param Date $startDt
436
452
* @param $dateFormat
440
private function substituteForEvent($matches, $string, $iCal, $dateFormat, $event)
456
private function substituteForEvent($matches, $string, $startDt, $endDt, $dateFormat, $event)
442
458
// Run through all [] substitutes in $matches
443
459
foreach ($matches[0] as $sub) {
464
480
case '[StartDate]':
465
$replace = $iCal->iCalDateToDateTime($event->dtstart, true)->format($dateFormat);
481
$replace = $startDt->format($dateFormat);
468
484
case '[EndDate]':
469
$replace = $iCal->iCalDateToDateTime($event->dtend, true)->format($dateFormat);
485
$replace = $endDt->format($dateFormat);