summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/inc/icalevent.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/locationinfo/inc/icalevent.inc.php')
-rw-r--r--modules-available/locationinfo/inc/icalevent.inc.php444
1 files changed, 249 insertions, 195 deletions
diff --git a/modules-available/locationinfo/inc/icalevent.inc.php b/modules-available/locationinfo/inc/icalevent.inc.php
index 1fb586ee..c5aea349 100644
--- a/modules-available/locationinfo/inc/icalevent.inc.php
+++ b/modules-available/locationinfo/inc/icalevent.inc.php
@@ -2,199 +2,253 @@
class ICalEvent
{
- // phpcs:disable Generic.Arrays.DisallowLongArraySyntax
-
- const HTML_TEMPLATE = '<p>%s: %s</p>';
-
- /**
- * https://www.kanzaki.com/docs/ical/summary.html
- *
- * @var $summary
- */
- public $summary;
-
- /**
- * https://www.kanzaki.com/docs/ical/dtstart.html
- *
- * @var $dtstart
- */
- public $dtstart;
-
- /**
- * https://www.kanzaki.com/docs/ical/dtend.html
- *
- * @var $dtend
- */
- public $dtend;
-
- /**
- * https://www.kanzaki.com/docs/ical/duration.html
- *
- * @var $duration
- */
- public $duration;
-
- /**
- * https://www.kanzaki.com/docs/ical/dtstamp.html
- *
- * @var $dtstamp
- */
- public $dtstamp;
-
- /**
- * https://www.kanzaki.com/docs/ical/uid.html
- *
- * @var $uid
- */
- public $uid;
-
- /**
- * https://www.kanzaki.com/docs/ical/created.html
- *
- * @var $created
- */
- public $created;
-
- /**
- * https://www.kanzaki.com/docs/ical/lastModified.html
- *
- * @var $lastmodified
- */
- public $lastmodified;
-
- /**
- * https://www.kanzaki.com/docs/ical/description.html
- *
- * @var $description
- */
- public $description;
-
- /**
- * https://www.kanzaki.com/docs/ical/location.html
- *
- * @var $location
- */
- public $location;
-
- /**
- * https://www.kanzaki.com/docs/ical/sequence.html
- *
- * @var $sequence
- */
- public $sequence;
-
- /**
- * https://www.kanzaki.com/docs/ical/status.html
- *
- * @var $status
- */
- public $status;
-
- /**
- * https://www.kanzaki.com/docs/ical/transp.html
- *
- * @var $transp
- */
- public $transp;
-
- /**
- * https://www.kanzaki.com/docs/ical/organizer.html
- *
- * @var $organizer
- */
- public $organizer;
-
- /**
- * https://www.kanzaki.com/docs/ical/attendee.html
- *
- * @var $attendee
- */
- public $attendee;
-
- /**
- * Creates the Event object
- *
- * @param array $data
- * @return void
- */
- public function __construct(array $data = array())
- {
- foreach ($data as $key => $value) {
- $variable = self::snakeCase($key);
- $this->{$variable} = self::prepareData($value);
- }
- }
-
- /**
- * Prepares the data for output
- *
- * @param mixed $value
- * @return mixed
- */
- protected function prepareData($value)
- {
- if (is_string($value)) {
- return stripslashes(trim(str_replace('\n', "\n", $value)));
- } elseif (is_array($value)) {
- return array_map('self::prepareData', $value);
- }
-
- return $value;
- }
-
- /**
- * Returns Event data excluding anything blank
- * within an HTML template
- *
- * @param string $html HTML template to use
- * @return string
- */
- public function printData($html = self::HTML_TEMPLATE)
- {
- $data = array(
- 'SUMMARY' => $this->summary,
- 'DTSTART' => $this->dtstart,
- 'DTEND' => $this->dtend,
- 'DURATION' => $this->duration,
- 'DTSTAMP' => $this->dtstamp,
- 'UID' => $this->uid,
- 'CREATED' => $this->created,
- 'LAST-MODIFIED' => $this->lastmodified,
- 'DESCRIPTION' => $this->description,
- 'LOCATION' => $this->location,
- 'SEQUENCE' => $this->sequence,
- 'STATUS' => $this->status,
- 'TRANSP' => $this->transp,
- 'ORGANISER' => $this->organizer,
- 'ATTENDEE(S)' => $this->attendee,
- );
-
- // Remove any blank values
- $data = array_filter($data);
-
- $output = '';
-
- foreach ($data as $key => $value) {
- $output .= sprintf($html, $key, $value);
- }
-
- return $output;
- }
-
- /**
- * Converts the given input to snake_case
- *
- * @param string $input
- * @param string $glue
- * @param string $separator
- * @return string
- */
- protected static function snakeCase($input, $glue = '_', $separator = '-')
- {
- $input = preg_split('/(?<=[a-z])(?=[A-Z])/x', $input);
- $input = implode($glue, $input);
- $input = str_replace($separator, $glue, $input);
-
- return strtolower($input);
- }
+ // phpcs:disable Generic.Arrays.DisallowLongArraySyntax
+
+ const HTML_TEMPLATE = '<p>%s: %s</p>';
+
+ /**
+ * https://www.kanzaki.com/docs/ical/summary.html
+ *
+ * @var string
+ */
+ public $summary;
+
+ /**
+ * https://www.kanzaki.com/docs/ical/dtstart.html
+ *
+ * @var string
+ */
+ public $dtstart;
+
+ /**
+ * https://www.kanzaki.com/docs/ical/dtend.html
+ *
+ * @var string
+ */
+ public $dtend;
+
+ /**
+ * https://www.kanzaki.com/docs/ical/duration.html
+ *
+ * @var string
+ */
+ public $duration;
+
+ /**
+ * https://www.kanzaki.com/docs/ical/dtstamp.html
+ *
+ * @var string
+ */
+ public $dtstamp;
+
+ /**
+ * When the event starts, represented as a timezone-adjusted string
+ *
+ * @var string
+ */
+ public $dtstart_tz;
+
+ /**
+ * When the event ends, represented as a timezone-adjusted string
+ *
+ * @var string
+ */
+ public $dtend_tz;
+
+ /**
+ * https://www.kanzaki.com/docs/ical/uid.html
+ *
+ * @var string
+ */
+ public $uid;
+
+ /**
+ * https://www.kanzaki.com/docs/ical/created.html
+ *
+ * @var string
+ */
+ public $created;
+
+ /**
+ * https://www.kanzaki.com/docs/ical/lastModified.html
+ *
+ * @var string
+ */
+ public $last_modified;
+
+ /**
+ * https://www.kanzaki.com/docs/ical/description.html
+ *
+ * @var string
+ */
+ public $description;
+
+ /**
+ * https://www.kanzaki.com/docs/ical/location.html
+ *
+ * @var string
+ */
+ public $location;
+
+ /**
+ * https://www.kanzaki.com/docs/ical/sequence.html
+ *
+ * @var string
+ */
+ public $sequence;
+
+ /**
+ * https://www.kanzaki.com/docs/ical/status.html
+ *
+ * @var string
+ */
+ public $status;
+
+ /**
+ * https://www.kanzaki.com/docs/ical/transp.html
+ *
+ * @var string
+ */
+ public $transp;
+
+ /**
+ * https://www.kanzaki.com/docs/ical/organizer.html
+ *
+ * @var string
+ */
+ public $organizer;
+
+ /**
+ * https://www.kanzaki.com/docs/ical/attendee.html
+ *
+ * @var string
+ */
+ public $attendee;
+
+ /**
+ * Manage additional properties
+ *
+ * @var array<string, mixed>
+ */
+ private $additionalProperties = array();
+
+ /**
+ * Creates the Event object
+ *
+ * @param array $data
+ * @return void
+ */
+ public function __construct(array $data = array())
+ {
+ foreach ($data as $key => $value) {
+ $variable = self::snakeCase($key);
+ if (property_exists($this, $variable)) {
+ $this->{$variable} = $this->prepareData($value);
+ } else {
+ $this->additionalProperties[$variable] = $this->prepareData($value);
+ }
+ }
+ }
+
+ /**
+ * Magic getter method
+ *
+ * @param string $additionalPropertyName
+ * @return mixed
+ */
+ public function __get(string $additionalPropertyName)
+ {
+ if (array_key_exists($additionalPropertyName, $this->additionalProperties)) {
+ return $this->additionalProperties[$additionalPropertyName];
+ }
+
+ return null;
+ }
+
+ /**
+ * Magic isset method
+ */
+ public function __isset(string $name): bool
+ {
+ return is_null($this->$name) === false;
+ }
+
+ /**
+ * Prepares the data for output
+ *
+ * @param mixed $value
+ * @return mixed
+ */
+ protected function prepareData($value)
+ {
+ if (is_string($value)) {
+ return stripslashes(trim(str_replace('\n', "\n", $value)));
+ }
+
+ if (is_array($value)) {
+ return array_map(function ($value) {
+ return $this->prepareData($value);
+ }, $value);
+ }
+
+ return $value;
+ }
+
+ /**
+ * Returns Event data excluding anything blank
+ * within an HTML template
+ *
+ * @param string $html HTML template to use
+ * @return string
+ */
+ public function printData($html = self::HTML_TEMPLATE)
+ {
+ $data = array(
+ 'SUMMARY' => $this->summary,
+ 'DTSTART' => $this->dtstart,
+ 'DTEND' => $this->dtend,
+ 'DTSTART_TZ' => $this->dtstart_tz,
+ 'DTEND_TZ' => $this->dtend_tz,
+ 'DURATION' => $this->duration,
+ 'DTSTAMP' => $this->dtstamp,
+ 'UID' => $this->uid,
+ 'CREATED' => $this->created,
+ 'LAST-MODIFIED' => $this->last_modified,
+ 'DESCRIPTION' => $this->description,
+ 'LOCATION' => $this->location,
+ 'SEQUENCE' => $this->sequence,
+ 'STATUS' => $this->status,
+ 'TRANSP' => $this->transp,
+ 'ORGANISER' => $this->organizer,
+ 'ATTENDEE(S)' => $this->attendee,
+ );
+
+ // Remove any blank values
+ $data = array_filter($data);
+
+ $output = '';
+
+ foreach ($data as $key => $value) {
+ $output .= sprintf($html, $key, $value);
+ }
+
+ return $output;
+ }
+
+ /**
+ * Converts the given input to snake_case
+ *
+ * @param string $input
+ * @param string $glue
+ * @param string $separator
+ * @return string
+ */
+ protected static function snakeCase($input, $glue = '_', $separator = '-')
+ {
+ $input = preg_split('/(?<=[a-z])(?=[A-Z])/x', $input);
+ $input = implode($glue, $input);
+ $input = str_replace($separator, $glue, $input);
+
+ return strtolower($input);
+ }
}