Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
28 changes: 28 additions & 0 deletions Sources/Actions/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use SMF\Calendar\Event;
use SMF\Calendar\EventOccurrence;
use SMF\Calendar\Holiday;
use SMF\Calendar\VTimeZone;
use SMF\Config;
use SMF\Db\DatabaseApi as Db;
use SMF\ErrorHandler;
Expand Down Expand Up @@ -626,8 +627,10 @@ public function export(): void
&& ($occurrence = $event->getOccurrence($_REQUEST['recurrenceid'])) !== false
) {
$file['content'][] = $occurrence->export();
$file['content'][] = VTimeZone::load($occurrence->tzid)->export($occurrence->start, $occurrence->end);
} else {
$file['content'][] = $event->export();
$file['content'][] = VTimeZone::load($event->tzid)->export($event->start, $event->end);
}

$file['filename'] = $event->title . '.ics';
Expand Down Expand Up @@ -656,6 +659,7 @@ public function export(): void
$high_date = (clone $low_date)->add($duration);

$full_event_uids = [];
$tzids = [];

foreach (Event::getOccurrencesInRange($low_date->format('Y-m-d'), $high_date->format('Y-m-d'), true) as $occurrence) {
$event = $occurrence->getParentEvent();
Expand All @@ -674,17 +678,41 @@ public function export(): void
&& $event->getRecurrenceEnd() <= $high_date
)
) {
if (!isset($tzids[$event->tzid])) {
$tzids[$event->tzid] = [
'min' => $event->start,
'max' => $event->end,
];
}

$tzids[$event->tzid]['min'] = $tzids[$event->tzid]['min'] > $event->start ? $event->start : $tzids[$event->tzid]['min'];
$tzids[$event->tzid]['max'] = $tzids[$event->tzid]['max'] < $event->end ? $event->end : $tzids[$event->tzid]['max'];

$file['content'][] = $event->export();
$full_event_ids[] = $event->uid;
}
// Otherwise, export just this occurrence.
else {
if (!isset($tzids[$occurrence->tzid])) {
$tzids[$occurrence->tzid] = [
'min' => $occurrence->start,
'max' => $occurrence->end,
];
}

$tzids[$occurrence->tzid]['min'] = $tzids[$occurrence->tzid]['min'] > $occurrence->start ? $occurrence->start : $tzids[$occurrence->tzid]['min'];
$tzids[$occurrence->tzid]['max'] = $tzids[$occurrence->tzid]['max'] < $occurrence->end ? $occurrence->end : $tzids[$occurrence->tzid]['max'];

$file['content'][] = $occurrence->export();
}

$file['mtime'] = max($file['mtime'], $event->modified_time);
}

foreach ($tzids as $tzid => $range) {
$file['content'][] = VTimeZone::load($tzid)->export($range['min'], $range['max']);
}

$file['filename'] = implode(' ', [Utils::$context['forum_name'], Lang::$txt['events'], $low_date->format('Y-m-d'), $high_date->format('Y-m-d')]) . '.ics';
}

Expand Down
9 changes: 9 additions & 0 deletions Sources/Calendar/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,15 @@ public function export(): string
$filecontents[] = 'EXDATE' . ($this->allday ? ';VALUE=DATE' : '') . ':' . implode(",\r\n ", $this->recurrence_iterator->getExDates());
}

if ($this instanceof Holiday) {
$filecontents[] = 'CATEGORIES:Holidays';
$filecontents[] = 'TRANSP:TRANSPARENT';
} elseif ($this instanceof Birthday) {
$filecontents[] = 'TRANSP:TRANSPARENT';
} else {
$filecontents[] = 'TRANSP:OPAQUE';
}

$filecontents[] = 'END:VEVENT';

// Fit all lines within iCalendar's line width restraint.
Expand Down
9 changes: 9 additions & 0 deletions Sources/Calendar/EventOccurrence.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ public function export(): string
$filecontents[] = 'DTSTART' . ($this->allday ? ';VALUE=DATE' : (!in_array($this->tz, RRule::UTC_SYNONYMS) ? ';TZID=' . $this->tz : '')) . ':' . $this->start->format('Ymd' . ($this->allday ? '' : '\\THis' . (in_array($this->tz, RRule::UTC_SYNONYMS) ? '\\Z' : '')));
$filecontents[] = 'DURATION:' . (string) $this->duration;

if ($this->getParentEvent() instanceof Holiday) {
$filecontents[] = 'CATEGORIES:Holidays';
$filecontents[] = 'TRANSP:TRANSPARENT';
} elseif ($this->getParentEvent() instanceof Birthday) {
$filecontents[] = 'TRANSP:TRANSPARENT';
} else {
$filecontents[] = 'TRANSP:OPAQUE';
}

$filecontents[] = 'END:VEVENT';

foreach ($filecontents as $line_num => $line) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Calendar/RecurrenceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ private function expand(\DateTime $current, ?string $break_after = null): \Gener

foreach ($this->rrule->{$prop} as $value) {
if ($value != $current_value) {
$temp = \DateTime::createFromFormat('Y z H:i:s e', $temp->format('Y ') . ($value - 1) . $temp->format(' H:i:s e'));
$temp = \DateTime::createFromFormat('Y z H:i:s e', $temp->format('Y ') . ($value > 0 ? $value - 1 : $value + ((bool) $temp->format('L') && $value >= -306 ? 366 : 365)) . $temp->format(' H:i:s e'));

yield $temp;

Expand Down
Loading
Loading