diff options
author | RaindropsSys <contact@minteck.org> | 2023-03-21 16:21:21 +0100 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-03-21 16:21:21 +0100 |
commit | 475c5731bf3362b6ac8d2dc5d5b43e4b4a6117bd (patch) | |
tree | 2cff46debf9c1e13892e7babff9deb6874ecb4b2 /includes/composer/ical/ical.php | |
parent | 7ccc2de87f9e25c715dc09b9aba4eb5c66f80424 (diff) | |
download | pluralconnect-475c5731bf3362b6ac8d2dc5d5b43e4b4a6117bd.tar.gz pluralconnect-475c5731bf3362b6ac8d2dc5d5b43e4b4a6117bd.tar.bz2 pluralconnect-475c5731bf3362b6ac8d2dc5d5b43e4b4a6117bd.zip |
Updated 26 files and added 1074 files (automated)
Diffstat (limited to 'includes/composer/ical/ical.php')
-rw-r--r-- | includes/composer/ical/ical.php | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/includes/composer/ical/ical.php b/includes/composer/ical/ical.php new file mode 100644 index 0000000..84d637c --- /dev/null +++ b/includes/composer/ical/ical.php @@ -0,0 +1,69 @@ +<?php declare(strict_types=1); + +require_once('icalEvent.php'); + +class iCal +{ + public $Events = array(); + + public function __construct(string $content) + { + $isUrl = strpos($content, 'http') === 0 && filter_var($content, FILTER_VALIDATE_URL); + $isFile = strpos($content, "\n") === false && file_exists($content); + + if ($isUrl || $isFile) + { + $this->parse(file_get_contents($content)); + } + } + + protected function parse(string $content) : iCal + { + $content = str_replace("\r\n ", '', $content); + + preg_match_all('`BEGIN:VEVENT(.+)END:VEVENT`Us', $content, $matches); + foreach($matches[0] as $eventContent) + { + $this->Events[] = new iCalEvent($eventContent); + } + + return $this; + } + + public function getEventsAfterDate(string $date) : array + { + $output = array(); + + $date = strtotime($date); + foreach ($this->Events as $event) + { + $eventTimestamp = strtotime($event->startDateTime); + if ($eventTimestamp >= $date) + { + $output[] = $event; + } + } + + asort($output); + return $output; + } + + public function getActiveEvents() : array + { + $output = array(); + + $currentDate = strtotime(date('Y-m-d')); + foreach ($this->Events as $event) + { + $eventStartTimestamp = strtotime($event->startDateTime); + $eventEndTimestamp = strtotime($event->endDateTime); + if ($currentDate >= $eventStartTimestamp && $currentDate <= $eventEndTimestamp) + { + $output[] = $event; + } + } + + asort($output); + return $output; + } +}
\ No newline at end of file |