summaryrefslogtreecommitdiff
path: root/includes/composer/ical/icalEvent.php
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-03-21 16:21:21 +0100
committerRaindropsSys <contact@minteck.org>2023-03-21 16:21:21 +0100
commit475c5731bf3362b6ac8d2dc5d5b43e4b4a6117bd (patch)
tree2cff46debf9c1e13892e7babff9deb6874ecb4b2 /includes/composer/ical/icalEvent.php
parent7ccc2de87f9e25c715dc09b9aba4eb5c66f80424 (diff)
downloadpluralconnect-475c5731bf3362b6ac8d2dc5d5b43e4b4a6117bd.tar.gz
pluralconnect-475c5731bf3362b6ac8d2dc5d5b43e4b4a6117bd.tar.bz2
pluralconnect-475c5731bf3362b6ac8d2dc5d5b43e4b4a6117bd.zip
Updated 26 files and added 1074 files (automated)
Diffstat (limited to 'includes/composer/ical/icalEvent.php')
-rw-r--r--includes/composer/ical/icalEvent.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/includes/composer/ical/icalEvent.php b/includes/composer/ical/icalEvent.php
new file mode 100644
index 0000000..a2791c2
--- /dev/null
+++ b/includes/composer/ical/icalEvent.php
@@ -0,0 +1,56 @@
+<?php declare(strict_types=1);
+
+class iCalEvent
+{
+ public $title;
+ public $description;
+ public $startDateTime;
+ public $endDateTime;
+ public $location;
+ public $created;
+ public $lastModified;
+
+ public function __construct(string $eventContent)
+ {
+ $this->parseEvent($eventContent);
+ }
+
+ protected function parseEvent(string $eventContent) : iCalEvent
+ {
+ $content = str_replace("\r\n ", '', $eventContent);
+
+ $this->title = $this->getEventDetail($content, "SUMMARY:");
+ $this->description = $this->getEventDetail($content, "DESCRIPTION:");
+ $this->startDateTime = $this->getEventDateTime($content, "DTSTART");
+ $this->endDateTime = $this->getEventDateTime($content, "DTEND");
+ $this->location = $this->getEventDetail($content, "LOCATION:");
+ $this->created = date('d.m.Y H:i', strtotime($this->getEventDetail($content, "CREATED:")));
+ $this->lastModified = date('d.m.Y H:i', strtotime($this->getEventDetail($content, "LAST-MODIFIED:")));
+
+ return $this;
+ }
+
+ protected function getEventDetail(string $eventContent, string $eventDetailKey) : string
+ {
+ $output = "";
+
+ if (preg_match('`^' . $eventDetailKey . '(.*)$`m', $eventContent, $match))
+ {
+ $output = trim($match[1]);
+ }
+
+ return $output;
+ }
+
+ protected function getEventDateTime(string $eventContent, string $eventDetailKey) : string
+ {
+ $output = "";
+
+ if (preg_match('`^' . $eventDetailKey . '(?:;.+)?:([0-9]+(T[0-9]+Z?)?)`m', $eventContent, $match))
+ {
+ $output = date('d.m.Y H:i', strtotime($match[1]));
+ }
+
+ return $output;
+ }
+} \ No newline at end of file