PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.5.21
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.5.21
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
fluent-booking / vendor / wpfluent / caldav / src / ICal / VEvent.php

VEvent.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 1.5.21, at vendor/wpfluent/caldav/src/ICal/VEvent.php

286 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\Package\CalDav\ICal;
4
5 class VEvent
6 {
7 // phpcs:disable Generic.Arrays.DisallowLongArraySyntax
8
9 const HTML_TEMPLATE = '<p>%s: %s</p>';
10
11 /**
12 * https://www.kanzaki.com/docs/ical/summary.html
13 *
14 * @var string
15 */
16 public $summary;
17
18 /**
19 * https://www.kanzaki.com/docs/ical/dtstart.html
20 *
21 * @var string
22 */
23 public $dtstart;
24
25 /**
26 * https://www.kanzaki.com/docs/ical/dtend.html
27 *
28 * @var string
29 */
30 public $dtend;
31
32 /**
33 * https://www.kanzaki.com/docs/ical/duration.html
34 *
35 * @var string
36 */
37 public $duration;
38
39 /**
40 * https://www.kanzaki.com/docs/ical/dtstamp.html
41 *
42 * @var string
43 */
44 public $dtstamp;
45
46 /**
47 * When the event starts, represented as a timezone-adjusted string
48 *
49 * @var string
50 */
51 public $dtstart_tz;
52
53 /**
54 * When the event ends, represented as a timezone-adjusted string
55 *
56 * @var string
57 */
58 public $dtend_tz;
59
60 /**
61 * https://www.kanzaki.com/docs/ical/uid.html
62 *
63 * @var string
64 */
65 public $uid;
66
67 /**
68 * https://www.kanzaki.com/docs/ical/created.html
69 *
70 * @var string
71 */
72 public $created;
73
74 /**
75 * https://www.kanzaki.com/docs/ical/lastModified.html
76 *
77 * @var string
78 */
79 public $last_modified;
80
81 /**
82 * https://www.kanzaki.com/docs/ical/description.html
83 *
84 * @var string
85 */
86 public $description;
87
88 /**
89 * https://www.kanzaki.com/docs/ical/location.html
90 *
91 * @var string
92 */
93 public $location;
94
95 /**
96 * https://www.kanzaki.com/docs/ical/sequence.html
97 *
98 * @var string
99 */
100 public $sequence;
101
102 /**
103 * https://www.kanzaki.com/docs/ical/status.html
104 *
105 * @var string
106 */
107 public $status;
108
109 /**
110 * https://www.kanzaki.com/docs/ical/transp.html
111 *
112 * @var string
113 */
114 public $transp;
115
116 /**
117 * https://www.kanzaki.com/docs/ical/organizer.html
118 *
119 * @var string
120 */
121 public $organizer;
122
123 /**
124 * https://www.kanzaki.com/docs/ical/attendee.html
125 *
126 * @var string
127 */
128 public $attendee;
129
130 /**
131 * https://www.kanzaki.com/docs/ical/rrule.html
132 *
133 * @var string
134 */
135 public $rrule;
136
137 /**
138 * https://www.kanzaki.com/docs/ical/attach.html
139 *
140 * @var string
141 */
142 public $attach;
143
144 /**
145 * https://www.kanzaki.com/docs/ical/tzid.html
146 *
147 * @var string
148 */
149 public $timezone;
150
151 /**
152 * Manage additional properties
153 *
154 * @var array<string, mixed>
155 */
156 public $additionalProperties = array();
157
158 /**
159 * Creates the Event object
160 *
161 * @param array $data
162 * @return void
163 */
164 public function __construct(array $data = array())
165 {
166 foreach ($data as $key => $value) {
167 $variable = self::snakeCase($key);
168 if (property_exists($this, $variable)) {
169 $this->{$variable} = $this->prepareData($value);
170 } else {
171 $this->additionalProperties[$variable] = $this->prepareData($value);
172 }
173 }
174 }
175
176 /**
177 * Magic getter method
178 *
179 * @param string $additionalPropertyName
180 * @return mixed
181 */
182 public function __get($additionalPropertyName)
183 {
184 if (array_key_exists($additionalPropertyName, $this->additionalProperties)) {
185 return $this->additionalProperties[$additionalPropertyName];
186 }
187
188 return null;
189 }
190
191 /**
192 * Magic isset method
193 *
194 * @param string $name
195 * @return boolean
196 */
197 public function __isset($name)
198 {
199 return is_null($this->$name) === false;
200 }
201
202 /**
203 * Prepares the data for output
204 *
205 * @param mixed $value
206 * @return mixed
207 */
208 protected function prepareData($value)
209 {
210 if (is_string($value)) {
211 return stripslashes(trim(str_replace('\n', "\n", $value)));
212 }
213
214 if (is_array($value)) {
215 return array_map(function ($value) {
216 return $this->prepareData($value);
217 }, $value);
218 }
219
220 return $value;
221 }
222
223 /**
224 * Returns Event data excluding anything blank
225 * within an HTML template
226 *
227 * @param string $html HTML template to use
228 * @return string
229 */
230 public function printData($html = self::HTML_TEMPLATE)
231 {
232 $data = array(
233 'SUMMARY' => $this->summary,
234 'DTSTART' => $this->dtstart,
235 'DTEND' => $this->dtend,
236 'DTSTART_TZ' => $this->dtstart_tz,
237 'DTEND_TZ' => $this->dtend_tz,
238 'DURATION' => $this->duration,
239 'DTSTAMP' => $this->dtstamp,
240 'UID' => $this->uid,
241 'CREATED' => $this->created,
242 'LAST-MODIFIED' => $this->last_modified,
243 'DESCRIPTION' => $this->description,
244 'LOCATION' => $this->location,
245 'SEQUENCE' => $this->sequence,
246 'STATUS' => $this->status,
247 'TRANSP' => $this->transp,
248 'ORGANISER' => $this->organizer,
249 'ATTENDEE(S)' => $this->attendee,
250 );
251
252 // Remove any blank values
253 $data = array_filter($data);
254
255 $output = '';
256
257 foreach ($data as $key => $value) {
258 $output .= sprintf($html, $key, $value);
259 }
260
261 return $output;
262 }
263
264 /**
265 * Converts the given input to snake_case
266 *
267 * @param string $input
268 * @param string $glue
269 * @param string $separator
270 * @return string
271 */
272 protected static function snakeCase($input, $glue = '_', $separator = '-')
273 {
274 $inputSplit = preg_split('/(?<=[a-z])(?=[A-Z])/x', $input);
275
276 if ($inputSplit === false) {
277 return $input;
278 }
279
280 $inputSplit = implode($glue, $inputSplit);
281 $inputSplit = str_replace($separator, $glue, $inputSplit);
282
283 return strtolower($inputSplit);
284 }
285 }
286