-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathicalendar.php
45 lines (44 loc) · 1.6 KB
/
icalendar.php
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
<?php
// see https://learn.getgrav.org/15/cookbook/plugin-recipes#output-some-php-code-result-in-a-twig-template
namespace Grav\Plugin;
use Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;
/**
* Class IcalendarPlugin
* @package Grav\Plugin
*/
class IcalendarPlugin extends Plugin
{
/**
* @return array
*
* The getSubscribedEvents() gives the core a list of events
* that the plugin wants to listen to. The key of each
* array section is the event that the plugin listens to
* and the value (in the form of an array) contains the
* callable (or function) as well as the priority. The
* higher the number the higher the priority.
*/
public static function getSubscribedEvents()
{
return [
'onTwigExtensions' => ['IcalTwigExtensions', 0] // wichtig, funktioniert sonst nicht !!
];
}
public function IcalTwigExtensions()
{
require_once(__DIR__ . '/classes/EventListTwigExtension.class.php');
// see https://discourse.getgrav.org/t/set-variable-in-twig-extension-class/9193/3
$ext = new EventListTwigExtension();
// add optional dateformat, default 'd.m.Y' 08.07.19
$dateformat = $this->config->get('plugins.icalendar.dateformat','d.m.Y');
$ext->setDateFormat($dateformat);
// DONE: limit (numevents) from config (yaml)
$numevents = $this->config->get('plugins.icalendar.numevents');
$ext->setNumEvents($numevents);
// DONE: Filename from config (yaml) -> relative to DATA_DIR/calendars !
$icsfile = (DATA_DIR . 'calendars/'.$this->config->get('plugins.icalendar.icsfile'));
$ext->setICSfile($icsfile);
$this->grav['twig']->twig->addExtension($ext);
}
}