diff --git a/CHANGELOG.md b/CHANGELOG.md index 19baf12..1b57f7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Solspace Calendar Changelog +## 2.0.24 - 2019-08-14 +### Fixed +- Fixed a bug where ICS export was not exporting correctly for Safari. +- Fixed a bug where ICS subscription URL's were no longer working at all. + ## 2.0.23 - 2019-08-13 ### Fixed - Fixed a bug where ICS export was not working correctly when `devMode` was disabled. diff --git a/composer.json b/composer.json index 90b4965..69e4539 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "solspace/craft3-calendar", "description": "The most powerful event management plugin for Craft.", - "version": "2.0.23", + "version": "2.0.24", "type": "craft-plugin", "authors": [ { diff --git a/src/Controllers/ApiController.php b/src/Controllers/ApiController.php index 093eb9e..345a433 100644 --- a/src/Controllers/ApiController.php +++ b/src/Controllers/ApiController.php @@ -9,7 +9,7 @@ class ApiController extends BaseController { - protected $allowAnonymous = ['actionIcs']; + protected $allowAnonymous = ['ics']; /** * @return null @@ -29,11 +29,16 @@ public function actionIcs() ->setLoadOccurrences(false) ->setCalendarId($calendar->id); - $exporter = new ExportCalendarToIcs($eventQuery); + $exporter = new ExportCalendarToIcs($eventQuery); + $exportString = $exporter->output(); header('Content-type: text/calendar; charset=utf-8'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + header('Content-Length: ' . strlen($exportString)); - echo $exporter->output(); + echo $exportString; exit(); } } diff --git a/src/Library/Export/AbstractExportCalendar.php b/src/Library/Export/AbstractExportCalendar.php index 2760c1c..9ac6e90 100644 --- a/src/Library/Export/AbstractExportCalendar.php +++ b/src/Library/Export/AbstractExportCalendar.php @@ -26,25 +26,32 @@ final public function __construct(EventQuery $events, array $options = []) * Collects the exportable string and outputs it * Sets headers to file download and content-type to text/calendar * + * @param bool $asFileUpload + * @param bool $shouldExit + * * @return string */ - final public function export() + final public function export(bool $asFileUpload = true, bool $shouldExit = true) { $exportString = $this->prepareStringForExport(); header('Content-Type: text/calendar; charset=utf-8'); - header('Content-Disposition: attachment; filename="' . time() . '.ics"'); - - header('Content-Description: File Transfer'); - header('Content-Type: text/calendar; charset=utf-8'); - header('Content-Disposition: attachment; filename="' . time() . '.ics"'); - header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . strlen($exportString)); + if ($asFileUpload) { + header('Content-Description: File Transfer'); + header('Content-Disposition: attachment; filename="' . time() . '.ics"'); + header('Content-Transfer-Encoding: binary'); + } + echo $exportString; + + if ($shouldExit) { + exit(); + } } /** diff --git a/src/Variables/CalendarVariable.php b/src/Variables/CalendarVariable.php index 319780e..810a877 100644 --- a/src/Variables/CalendarVariable.php +++ b/src/Variables/CalendarVariable.php @@ -105,11 +105,13 @@ public function event($id, array $options = []) /** * @param EventQuery $events * @param array $options + * + * @return string */ public function export(EventQuery $events, array $options = []) { $exporter = new ExportCalendarToIcs($events, $options); - $exporter->export(); + $exporter->export(true, false); } /** diff --git a/src/codepack/templates/export.html b/src/codepack/templates/export.html index 7ba4176..a23fbc6 100755 --- a/src/codepack/templates/export.html +++ b/src/codepack/templates/export.html @@ -19,4 +19,6 @@ loadOccurrences: false })) -%} +{% header "Content-Type: application/octet-stream" %} +{% header "Content-Transfer-Encoding: binary" %} {{- craft.calendar.export(events) -}}