Skip to content

Instantly share code, notes, and snippets.

@nonoesp
Created February 24, 2022 09:36
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nonoesp/f2d045a21bdf7451144ad8f0503fb6b1 to your computer and use it in GitHub Desktop.
A Laravel view that generates a text/calendar feed you can subscribe to from calendar clients.
<?php
$vCalendar = new \Eluceo\iCal\Component\Calendar('www.nono.ma');
if(isset($item)) {
$collection = $item->collection();
foreach($collection as $i) {
$is_hidden = $i->deleted_at ? "X" : " ";
$is_blog = $i->is_blog ? "X" : " ";
$is_rss = $i->rss ? "X" : " ";
$vEvent = new \Eluceo\iCal\Component\Event();
$vEvent
->setUrl($i->URL())
->setDtStart(new \DateTime($i->published_at))
->setDtEnd(new \DateTime($i->published_at))
->setNoTime(true)
->setSummary($i->title)
->setDescription(
'['.$is_hidden.'] Hidden'.PHP_EOL.
'['.$is_blog.'] Blog'.PHP_EOL.
'['.$is_rss.'] RSS'.PHP_EOL.PHP_EOL.
strip_tags($i->htmlText())
)
;
$vCalendar->addComponent($vEvent);
}
}
// Serve on the web to let calendar clients subscribe
header('Content-Type: text/calendar; charset=utf-8');
// Force download calendar ICS file
// header('Content-Disposition: attachment; filename="cal.ics"');
echo $vCalendar->render();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment