Created
February 24, 2022 09:36
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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