Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'export' option to ICS generation to allow exporting the ICS source rather than creating a base64 link #139

Closed
wants to merge 1 commit into from

Conversation

kodie
Copy link
Contributor

@kodie kodie commented Dec 27, 2021

This should basically take care of #125, #126, and #129.

I've noticed that calendar links on Apple devices can be kind of tricky, and the way that seems to work the best and most consistently is serving a generated ICS file. Currently, this isn't possible because the ICS generator returns a base64 encoded string, however with this newly added option you'd be able to have it return the ICS contents.

For example:

generate-ics.php:

<?php
require_once('autoload.php');
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename=event.ics');
$link = new Spatie\CalendarLinks\Link($title, $start_date, $end_date);
echo $link->ics(array('export' => true));
exit;
?>

Then you could link to that file like this: webcal://mywebsite.com/generate-ics.php and it should work fine for Apple devices.

It should be noted that not all browsers support the webcal protocol, so I use a piece of JavaScript to update my links depending on the browser:

function webcalify(selector) {
  var isApple = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)
  
  if (isApple) {
    var links = document.querySelectorAll(selector || 'a.webcal')
    
    for (var i = 0; i < links.length; i++) {
      var link = links[i]
      var url = link.href
      
      link.href = url.replace(/(^\w+:|^)\/\//, 'webcal://')
    }
  }
}

@spatie-bot
Copy link

Dear contributor,

because this pull request seems to be inactive for quite some time now, I've automatically closed it. If you feel this pull request deserves some attention from my human colleagues feel free to reopen it.

@spatie-bot spatie-bot closed this Apr 28, 2022
@UksusoFF UksusoFF mentioned this pull request Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants