-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCalendarExport.php
More file actions
55 lines (48 loc) · 1.94 KB
/
CalendarExport.php
File metadata and controls
55 lines (48 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Grav\Plugin;
use Grav\Common\Grav;
class CalendarExport extends \Grav\Common\Twig\TwigExtension
{
public function getName()
{
return 'CalendarExport';
}
public function getFunctions() : array
{
return [
new \Twig_SimpleFunction('phpCalendarExport', [$this, 'calendarExport']),
];
}
public static function calendarExport(){
$page = Grav::instance()['page'];
$name = $page->value("folder");
$collection = $page->evaluate(['@page.descendants' => '/data/events'])->routable();
if($name != "all") {
$group = $page->evaluate(['@taxonomy.skupina' => $name]);
$collection->intersect($group);
}
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: atachment; filename=zbm_calendar_'. $name .'.ics');
echo "BEGIN:VCALENDAR\r\n";
echo "VERSION:2.0\r\n";
echo "PRODID:". $page->id() ."/v1/zabiny.club//cs-CZ\r\n";
echo "CALSCALE:GREGORIAN\r\n";
echo "X-WR-TIMEZONE:Europe/Prague\r\n";
echo "X-PUBLISHED-TTL:PT1H\r\n";
echo "REFRESH-INTERVAL;VALUE=DURATION:P1H\r\n";
foreach ($collection as $event) {
echo "BEGIN:VEVENT\r\n";
echo "UID:". $event->value("header.id") ."\r\n";
echo "DTSTAMP:". date('Ymd\THis', $event->modified()) ."\r\n";
echo "DTSTART;VALUE=DATE:". date("Ymd", strtotime($event->value("header.start")))."\r\n";
echo "DTEND;VALUE=DATE:". date("Ymd", strtotime($event->value("header.end") . "+ 1 day"))."\r\n";
echo "SUMMARY:". $event->value("header.title") ."\r\n";
echo "LOCATION:". $event->value("header.place") ."\r\n";
echo "URL:". $event->url(true) ."\r\n";
echo "DESCRIPTION:". $event->url(true) ."\r\n";
echo "END:VEVENT\r\n";
}
echo "END:VCALENDAR\r\n";
}
}
?>