1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* iCalendar plugin for Craft CMS 3.x |
|
|
|
|
4
|
|
|
* |
5
|
|
|
* Tools for parsing & formatting the RFC 2445 iCalendar (.ics) specification |
6
|
|
|
* |
7
|
|
|
* @link https://nystudio107.com |
|
|
|
|
8
|
|
|
* @copyright Copyright (c) 2018 nystudio107 |
|
|
|
|
9
|
|
|
*/ |
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace nystudio107\icalendar; |
12
|
|
|
|
13
|
|
|
use Craft; |
14
|
|
|
use craft\base\Plugin; |
15
|
|
|
use craft\web\twig\variables\CraftVariable; |
16
|
|
|
use nystudio107\icalendar\services\Convert as ConvertService; |
17
|
|
|
use nystudio107\icalendar\services\Parse as ParseService; |
18
|
|
|
use nystudio107\icalendar\twigextensions\ICalendarTwigExtension; |
19
|
|
|
use nystudio107\icalendar\variables\ICalendarVariable; |
20
|
|
|
use yii\base\Event; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class ICalendar |
24
|
|
|
* |
25
|
|
|
* @author nystudio107 |
|
|
|
|
26
|
|
|
* @package ICalendar |
|
|
|
|
27
|
|
|
* @since 1.0.0 |
|
|
|
|
28
|
|
|
* |
29
|
|
|
* @property ConvertService $convert |
|
|
|
|
30
|
|
|
* @property ParseService $parse |
|
|
|
|
31
|
|
|
*/ |
|
|
|
|
32
|
|
|
class ICalendar extends Plugin |
33
|
|
|
{ |
34
|
|
|
// Static Properties |
35
|
|
|
// ========================================================================= |
36
|
|
|
|
37
|
|
|
/** |
|
|
|
|
38
|
|
|
* @var ?ICalendar |
39
|
|
|
*/ |
40
|
|
|
public static ?ICalendar $plugin = null; |
41
|
|
|
|
42
|
|
|
/** |
|
|
|
|
43
|
|
|
* @var ?ICalendarVariable |
44
|
|
|
*/ |
45
|
|
|
public static ?ICalendarVariable $variable = null; |
46
|
|
|
|
47
|
|
|
// Public Properties |
48
|
|
|
// ========================================================================= |
49
|
|
|
|
50
|
|
|
/** |
|
|
|
|
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
public string $schemaVersion = '1.0.0'; |
54
|
|
|
|
55
|
|
|
/** |
|
|
|
|
56
|
|
|
* @var bool |
57
|
|
|
*/ |
58
|
|
|
public bool $hasCpSection = false; |
59
|
|
|
|
60
|
|
|
/** |
|
|
|
|
61
|
|
|
* @var bool |
62
|
|
|
*/ |
63
|
|
|
public bool $hasCpSettings = false; |
64
|
|
|
|
65
|
|
|
// Public Methods |
66
|
|
|
// ========================================================================= |
67
|
|
|
|
68
|
|
|
/** |
|
|
|
|
69
|
|
|
* @inheritdoc |
70
|
|
|
*/ |
71
|
|
|
public function __construct($id, $parent = null, array $config = []) |
72
|
|
|
{ |
73
|
|
|
$config['components'] = [ |
74
|
|
|
'convert' => ConvertService::class, |
75
|
|
|
'parse' => ParseService::class, |
76
|
|
|
]; |
77
|
|
|
|
78
|
|
|
parent::__construct($id, $parent, $config); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
|
|
|
|
82
|
|
|
* @inheritdoc |
83
|
|
|
*/ |
|
|
|
|
84
|
|
|
public function init(): void |
85
|
|
|
{ |
86
|
|
|
parent::init(); |
87
|
|
|
self::$plugin = $this; |
88
|
|
|
self::$variable = new ICalendarVariable(); |
89
|
|
|
// Register Twig extension |
90
|
|
|
Craft::$app->view->registerTwigExtension(new ICalendarTwigExtension()); |
91
|
|
|
// Register variable |
92
|
|
|
Event::on( |
93
|
|
|
CraftVariable::class, |
94
|
|
|
CraftVariable::EVENT_INIT, |
95
|
|
|
static function(Event $event) { |
|
|
|
|
96
|
|
|
/** @var CraftVariable $variable */ |
|
|
|
|
97
|
|
|
$variable = $event->sender; |
98
|
|
|
$variable->set('icalendar', self::$variable); |
99
|
|
|
} |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
Craft::info( |
103
|
|
|
Craft::t( |
104
|
|
|
'icalendar', |
105
|
|
|
'{name} plugin loaded', |
106
|
|
|
['name' => $this->name] |
107
|
|
|
), |
108
|
|
|
__METHOD__ |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
// Protected Methods |
113
|
|
|
// ========================================================================= |
114
|
|
|
} |
115
|
|
|
|