@@ -25,316 +25,316 @@ discard block |
||
25 | 25 | */ |
26 | 26 | class MimeDir extends Parser |
27 | 27 | { |
28 | - /** |
|
29 | - * The input stream. |
|
30 | - * |
|
31 | - * @var resource |
|
32 | - */ |
|
33 | - protected $input; |
|
34 | - |
|
35 | - /** |
|
36 | - * Root component. |
|
37 | - * |
|
38 | - * @var Component |
|
39 | - */ |
|
40 | - protected $root; |
|
41 | - |
|
42 | - /** |
|
43 | - * By default all input will be assumed to be UTF-8. |
|
44 | - * |
|
45 | - * However, both iCalendar and vCard might be encoded using different |
|
46 | - * character sets. The character set is usually set in the mime-type. |
|
47 | - * |
|
48 | - * If this is the case, use setEncoding to specify that a different |
|
49 | - * encoding will be used. If this is set, the parser will automatically |
|
50 | - * convert all incoming data to UTF-8. |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $charset = 'UTF-8'; |
|
55 | - |
|
56 | - /** |
|
57 | - * The list of character sets we support when decoding. |
|
58 | - * |
|
59 | - * This would be a const expression but for now we need to support PHP 5.5 |
|
60 | - */ |
|
61 | - protected static $SUPPORTED_CHARSETS = [ |
|
62 | - 'UTF-8', |
|
63 | - 'ISO-8859-1', |
|
64 | - 'Windows-1252', |
|
65 | - ]; |
|
66 | - |
|
67 | - /** |
|
68 | - * Parses an iCalendar or vCard file. |
|
69 | - * |
|
70 | - * Pass a stream or a string. If null is parsed, the existing buffer is |
|
71 | - * used. |
|
72 | - * |
|
73 | - * @param string|resource|null $input |
|
74 | - * @param int $options |
|
75 | - * |
|
76 | - * @return \Sabre\VObject\Document |
|
77 | - */ |
|
78 | - public function parse($input = null, $options = 0) |
|
79 | - { |
|
80 | - $this->root = null; |
|
81 | - |
|
82 | - if (!is_null($input)) { |
|
83 | - $this->setInput($input); |
|
84 | - } |
|
85 | - |
|
86 | - if (0 !== $options) { |
|
87 | - $this->options = $options; |
|
88 | - } |
|
89 | - |
|
90 | - $this->parseDocument(); |
|
91 | - |
|
92 | - return $this->root; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * By default all input will be assumed to be UTF-8. |
|
97 | - * |
|
98 | - * However, both iCalendar and vCard might be encoded using different |
|
99 | - * character sets. The character set is usually set in the mime-type. |
|
100 | - * |
|
101 | - * If this is the case, use setEncoding to specify that a different |
|
102 | - * encoding will be used. If this is set, the parser will automatically |
|
103 | - * convert all incoming data to UTF-8. |
|
104 | - * |
|
105 | - * @param string $charset |
|
106 | - */ |
|
107 | - public function setCharset($charset) |
|
108 | - { |
|
109 | - if (!in_array($charset, self::$SUPPORTED_CHARSETS)) { |
|
110 | - throw new \InvalidArgumentException('Unsupported encoding. (Supported encodings: '.implode(', ', self::$SUPPORTED_CHARSETS).')'); |
|
111 | - } |
|
112 | - $this->charset = $charset; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Sets the input buffer. Must be a string or stream. |
|
117 | - * |
|
118 | - * @param resource|string $input |
|
119 | - */ |
|
120 | - public function setInput($input) |
|
121 | - { |
|
122 | - // Resetting the parser |
|
123 | - $this->lineIndex = 0; |
|
124 | - $this->startLine = 0; |
|
125 | - |
|
126 | - if (is_string($input)) { |
|
127 | - // Converting to a stream. |
|
128 | - $stream = fopen('php://temp', 'r+'); |
|
129 | - fwrite($stream, $input); |
|
130 | - rewind($stream); |
|
131 | - $this->input = $stream; |
|
132 | - } elseif (is_resource($input)) { |
|
133 | - $this->input = $input; |
|
134 | - } else { |
|
135 | - throw new \InvalidArgumentException('This parser can only read from strings or streams.'); |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Parses an entire document. |
|
141 | - */ |
|
142 | - protected function parseDocument() |
|
143 | - { |
|
144 | - $line = $this->readLine(); |
|
145 | - |
|
146 | - // BOM is ZERO WIDTH NO-BREAK SPACE (U+FEFF). |
|
147 | - // It's 0xEF 0xBB 0xBF in UTF-8 hex. |
|
148 | - if (3 <= strlen($line) |
|
149 | - && 0xef === ord($line[0]) |
|
150 | - && 0xbb === ord($line[1]) |
|
151 | - && 0xbf === ord($line[2])) { |
|
152 | - $line = substr($line, 3); |
|
153 | - } |
|
154 | - |
|
155 | - switch (strtoupper($line)) { |
|
156 | - case 'BEGIN:VCALENDAR': |
|
157 | - $class = VCalendar::$componentMap['VCALENDAR']; |
|
158 | - break; |
|
159 | - case 'BEGIN:VCARD': |
|
160 | - $class = VCard::$componentMap['VCARD']; |
|
161 | - break; |
|
162 | - default: |
|
163 | - throw new ParseException('This parser only supports VCARD and VCALENDAR files'); |
|
164 | - } |
|
165 | - |
|
166 | - $this->root = new $class([], false); |
|
167 | - |
|
168 | - while (true) { |
|
169 | - // Reading until we hit END: |
|
170 | - try { |
|
171 | - $line = $this->readLine(); |
|
172 | - } catch (EofException $oEx) { |
|
173 | - $line = 'END:'.$this->root->name; |
|
174 | - } |
|
175 | - if ('END:' === strtoupper(substr($line, 0, 4))) { |
|
176 | - break; |
|
177 | - } |
|
178 | - $result = $this->parseLine($line); |
|
179 | - if ($result) { |
|
180 | - $this->root->add($result); |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - $name = strtoupper(substr($line, 4)); |
|
185 | - if ($name !== $this->root->name) { |
|
186 | - throw new ParseException('Invalid MimeDir file. expected: "END:'.$this->root->name.'" got: "END:'.$name.'"'); |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Parses a line, and if it hits a component, it will also attempt to parse |
|
192 | - * the entire component. |
|
193 | - * |
|
194 | - * @param string $line Unfolded line |
|
195 | - * |
|
196 | - * @return Node |
|
197 | - */ |
|
198 | - protected function parseLine($line) |
|
199 | - { |
|
200 | - // Start of a new component |
|
201 | - if ('BEGIN:' === strtoupper(substr($line, 0, 6))) { |
|
202 | - if (substr($line, 6) === $this->root->name) { |
|
203 | - throw new ParseException('Invalid MimeDir file. Unexpected component: "'.$line.'" in document type '.$this->root->name); |
|
204 | - } |
|
205 | - $component = $this->root->createComponent(substr($line, 6), [], false); |
|
206 | - |
|
207 | - while (true) { |
|
208 | - // Reading until we hit END: |
|
209 | - $line = $this->readLine(); |
|
210 | - if ('END:' === strtoupper(substr($line, 0, 4))) { |
|
211 | - break; |
|
212 | - } |
|
213 | - $result = $this->parseLine($line); |
|
214 | - if ($result) { |
|
215 | - $component->add($result); |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - $name = strtoupper(substr($line, 4)); |
|
220 | - if ($name !== $component->name) { |
|
221 | - throw new ParseException('Invalid MimeDir file. expected: "END:'.$component->name.'" got: "END:'.$name.'"'); |
|
222 | - } |
|
223 | - |
|
224 | - return $component; |
|
225 | - } else { |
|
226 | - // Property reader |
|
227 | - $property = $this->readProperty($line); |
|
228 | - if (!$property) { |
|
229 | - // Ignored line |
|
230 | - return false; |
|
231 | - } |
|
232 | - |
|
233 | - return $property; |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * We need to look ahead 1 line every time to see if we need to 'unfold' |
|
239 | - * the next line. |
|
240 | - * |
|
241 | - * If that was not the case, we store it here. |
|
242 | - * |
|
243 | - * @var string|null |
|
244 | - */ |
|
245 | - protected $lineBuffer; |
|
246 | - |
|
247 | - /** |
|
248 | - * The real current line number. |
|
249 | - */ |
|
250 | - protected $lineIndex = 0; |
|
251 | - |
|
252 | - /** |
|
253 | - * In the case of unfolded lines, this property holds the line number for |
|
254 | - * the start of the line. |
|
255 | - * |
|
256 | - * @var int |
|
257 | - */ |
|
258 | - protected $startLine = 0; |
|
259 | - |
|
260 | - /** |
|
261 | - * Contains a 'raw' representation of the current line. |
|
262 | - * |
|
263 | - * @var string |
|
264 | - */ |
|
265 | - protected $rawLine; |
|
266 | - |
|
267 | - /** |
|
268 | - * Reads a single line from the buffer. |
|
269 | - * |
|
270 | - * This method strips any newlines and also takes care of unfolding. |
|
271 | - * |
|
272 | - * @throws \Sabre\VObject\EofException |
|
273 | - * |
|
274 | - * @return string |
|
275 | - */ |
|
276 | - protected function readLine() |
|
277 | - { |
|
278 | - if (!\is_null($this->lineBuffer)) { |
|
279 | - $rawLine = $this->lineBuffer; |
|
280 | - $this->lineBuffer = null; |
|
281 | - } else { |
|
282 | - do { |
|
283 | - $eof = \feof($this->input); |
|
284 | - |
|
285 | - $rawLine = \fgets($this->input); |
|
286 | - |
|
287 | - if ($eof || (\feof($this->input) && false === $rawLine)) { |
|
288 | - throw new EofException('End of document reached prematurely'); |
|
289 | - } |
|
290 | - if (false === $rawLine) { |
|
291 | - throw new ParseException('Error reading from input stream'); |
|
292 | - } |
|
293 | - $rawLine = \rtrim($rawLine, "\r\n"); |
|
294 | - } while ('' === $rawLine); // Skipping empty lines |
|
295 | - ++$this->lineIndex; |
|
296 | - } |
|
297 | - $line = $rawLine; |
|
298 | - |
|
299 | - $this->startLine = $this->lineIndex; |
|
300 | - |
|
301 | - // Looking ahead for folded lines. |
|
302 | - while (true) { |
|
303 | - $nextLine = \rtrim(\fgets($this->input), "\r\n"); |
|
304 | - ++$this->lineIndex; |
|
305 | - if (!$nextLine) { |
|
306 | - break; |
|
307 | - } |
|
308 | - if ("\t" === $nextLine[0] || ' ' === $nextLine[0]) { |
|
309 | - $curLine = \substr($nextLine, 1); |
|
310 | - $line .= $curLine; |
|
311 | - $rawLine .= "\n ".$curLine; |
|
312 | - } else { |
|
313 | - $this->lineBuffer = $nextLine; |
|
314 | - break; |
|
315 | - } |
|
316 | - } |
|
317 | - $this->rawLine = $rawLine; |
|
318 | - |
|
319 | - return $line; |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Reads a property or component from a line. |
|
324 | - */ |
|
325 | - protected function readProperty($line) |
|
326 | - { |
|
327 | - if ($this->options & self::OPTION_FORGIVING) { |
|
328 | - $propNameToken = 'A-Z0-9\-\._\\/'; |
|
329 | - } else { |
|
330 | - $propNameToken = 'A-Z0-9\-\.'; |
|
331 | - } |
|
332 | - |
|
333 | - $paramNameToken = 'A-Z0-9\-'; |
|
334 | - $safeChar = '^";:,'; |
|
335 | - $qSafeChar = '^"'; |
|
336 | - |
|
337 | - $regex = "/ |
|
28 | + /** |
|
29 | + * The input stream. |
|
30 | + * |
|
31 | + * @var resource |
|
32 | + */ |
|
33 | + protected $input; |
|
34 | + |
|
35 | + /** |
|
36 | + * Root component. |
|
37 | + * |
|
38 | + * @var Component |
|
39 | + */ |
|
40 | + protected $root; |
|
41 | + |
|
42 | + /** |
|
43 | + * By default all input will be assumed to be UTF-8. |
|
44 | + * |
|
45 | + * However, both iCalendar and vCard might be encoded using different |
|
46 | + * character sets. The character set is usually set in the mime-type. |
|
47 | + * |
|
48 | + * If this is the case, use setEncoding to specify that a different |
|
49 | + * encoding will be used. If this is set, the parser will automatically |
|
50 | + * convert all incoming data to UTF-8. |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $charset = 'UTF-8'; |
|
55 | + |
|
56 | + /** |
|
57 | + * The list of character sets we support when decoding. |
|
58 | + * |
|
59 | + * This would be a const expression but for now we need to support PHP 5.5 |
|
60 | + */ |
|
61 | + protected static $SUPPORTED_CHARSETS = [ |
|
62 | + 'UTF-8', |
|
63 | + 'ISO-8859-1', |
|
64 | + 'Windows-1252', |
|
65 | + ]; |
|
66 | + |
|
67 | + /** |
|
68 | + * Parses an iCalendar or vCard file. |
|
69 | + * |
|
70 | + * Pass a stream or a string. If null is parsed, the existing buffer is |
|
71 | + * used. |
|
72 | + * |
|
73 | + * @param string|resource|null $input |
|
74 | + * @param int $options |
|
75 | + * |
|
76 | + * @return \Sabre\VObject\Document |
|
77 | + */ |
|
78 | + public function parse($input = null, $options = 0) |
|
79 | + { |
|
80 | + $this->root = null; |
|
81 | + |
|
82 | + if (!is_null($input)) { |
|
83 | + $this->setInput($input); |
|
84 | + } |
|
85 | + |
|
86 | + if (0 !== $options) { |
|
87 | + $this->options = $options; |
|
88 | + } |
|
89 | + |
|
90 | + $this->parseDocument(); |
|
91 | + |
|
92 | + return $this->root; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * By default all input will be assumed to be UTF-8. |
|
97 | + * |
|
98 | + * However, both iCalendar and vCard might be encoded using different |
|
99 | + * character sets. The character set is usually set in the mime-type. |
|
100 | + * |
|
101 | + * If this is the case, use setEncoding to specify that a different |
|
102 | + * encoding will be used. If this is set, the parser will automatically |
|
103 | + * convert all incoming data to UTF-8. |
|
104 | + * |
|
105 | + * @param string $charset |
|
106 | + */ |
|
107 | + public function setCharset($charset) |
|
108 | + { |
|
109 | + if (!in_array($charset, self::$SUPPORTED_CHARSETS)) { |
|
110 | + throw new \InvalidArgumentException('Unsupported encoding. (Supported encodings: '.implode(', ', self::$SUPPORTED_CHARSETS).')'); |
|
111 | + } |
|
112 | + $this->charset = $charset; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Sets the input buffer. Must be a string or stream. |
|
117 | + * |
|
118 | + * @param resource|string $input |
|
119 | + */ |
|
120 | + public function setInput($input) |
|
121 | + { |
|
122 | + // Resetting the parser |
|
123 | + $this->lineIndex = 0; |
|
124 | + $this->startLine = 0; |
|
125 | + |
|
126 | + if (is_string($input)) { |
|
127 | + // Converting to a stream. |
|
128 | + $stream = fopen('php://temp', 'r+'); |
|
129 | + fwrite($stream, $input); |
|
130 | + rewind($stream); |
|
131 | + $this->input = $stream; |
|
132 | + } elseif (is_resource($input)) { |
|
133 | + $this->input = $input; |
|
134 | + } else { |
|
135 | + throw new \InvalidArgumentException('This parser can only read from strings or streams.'); |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Parses an entire document. |
|
141 | + */ |
|
142 | + protected function parseDocument() |
|
143 | + { |
|
144 | + $line = $this->readLine(); |
|
145 | + |
|
146 | + // BOM is ZERO WIDTH NO-BREAK SPACE (U+FEFF). |
|
147 | + // It's 0xEF 0xBB 0xBF in UTF-8 hex. |
|
148 | + if (3 <= strlen($line) |
|
149 | + && 0xef === ord($line[0]) |
|
150 | + && 0xbb === ord($line[1]) |
|
151 | + && 0xbf === ord($line[2])) { |
|
152 | + $line = substr($line, 3); |
|
153 | + } |
|
154 | + |
|
155 | + switch (strtoupper($line)) { |
|
156 | + case 'BEGIN:VCALENDAR': |
|
157 | + $class = VCalendar::$componentMap['VCALENDAR']; |
|
158 | + break; |
|
159 | + case 'BEGIN:VCARD': |
|
160 | + $class = VCard::$componentMap['VCARD']; |
|
161 | + break; |
|
162 | + default: |
|
163 | + throw new ParseException('This parser only supports VCARD and VCALENDAR files'); |
|
164 | + } |
|
165 | + |
|
166 | + $this->root = new $class([], false); |
|
167 | + |
|
168 | + while (true) { |
|
169 | + // Reading until we hit END: |
|
170 | + try { |
|
171 | + $line = $this->readLine(); |
|
172 | + } catch (EofException $oEx) { |
|
173 | + $line = 'END:'.$this->root->name; |
|
174 | + } |
|
175 | + if ('END:' === strtoupper(substr($line, 0, 4))) { |
|
176 | + break; |
|
177 | + } |
|
178 | + $result = $this->parseLine($line); |
|
179 | + if ($result) { |
|
180 | + $this->root->add($result); |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + $name = strtoupper(substr($line, 4)); |
|
185 | + if ($name !== $this->root->name) { |
|
186 | + throw new ParseException('Invalid MimeDir file. expected: "END:'.$this->root->name.'" got: "END:'.$name.'"'); |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Parses a line, and if it hits a component, it will also attempt to parse |
|
192 | + * the entire component. |
|
193 | + * |
|
194 | + * @param string $line Unfolded line |
|
195 | + * |
|
196 | + * @return Node |
|
197 | + */ |
|
198 | + protected function parseLine($line) |
|
199 | + { |
|
200 | + // Start of a new component |
|
201 | + if ('BEGIN:' === strtoupper(substr($line, 0, 6))) { |
|
202 | + if (substr($line, 6) === $this->root->name) { |
|
203 | + throw new ParseException('Invalid MimeDir file. Unexpected component: "'.$line.'" in document type '.$this->root->name); |
|
204 | + } |
|
205 | + $component = $this->root->createComponent(substr($line, 6), [], false); |
|
206 | + |
|
207 | + while (true) { |
|
208 | + // Reading until we hit END: |
|
209 | + $line = $this->readLine(); |
|
210 | + if ('END:' === strtoupper(substr($line, 0, 4))) { |
|
211 | + break; |
|
212 | + } |
|
213 | + $result = $this->parseLine($line); |
|
214 | + if ($result) { |
|
215 | + $component->add($result); |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + $name = strtoupper(substr($line, 4)); |
|
220 | + if ($name !== $component->name) { |
|
221 | + throw new ParseException('Invalid MimeDir file. expected: "END:'.$component->name.'" got: "END:'.$name.'"'); |
|
222 | + } |
|
223 | + |
|
224 | + return $component; |
|
225 | + } else { |
|
226 | + // Property reader |
|
227 | + $property = $this->readProperty($line); |
|
228 | + if (!$property) { |
|
229 | + // Ignored line |
|
230 | + return false; |
|
231 | + } |
|
232 | + |
|
233 | + return $property; |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * We need to look ahead 1 line every time to see if we need to 'unfold' |
|
239 | + * the next line. |
|
240 | + * |
|
241 | + * If that was not the case, we store it here. |
|
242 | + * |
|
243 | + * @var string|null |
|
244 | + */ |
|
245 | + protected $lineBuffer; |
|
246 | + |
|
247 | + /** |
|
248 | + * The real current line number. |
|
249 | + */ |
|
250 | + protected $lineIndex = 0; |
|
251 | + |
|
252 | + /** |
|
253 | + * In the case of unfolded lines, this property holds the line number for |
|
254 | + * the start of the line. |
|
255 | + * |
|
256 | + * @var int |
|
257 | + */ |
|
258 | + protected $startLine = 0; |
|
259 | + |
|
260 | + /** |
|
261 | + * Contains a 'raw' representation of the current line. |
|
262 | + * |
|
263 | + * @var string |
|
264 | + */ |
|
265 | + protected $rawLine; |
|
266 | + |
|
267 | + /** |
|
268 | + * Reads a single line from the buffer. |
|
269 | + * |
|
270 | + * This method strips any newlines and also takes care of unfolding. |
|
271 | + * |
|
272 | + * @throws \Sabre\VObject\EofException |
|
273 | + * |
|
274 | + * @return string |
|
275 | + */ |
|
276 | + protected function readLine() |
|
277 | + { |
|
278 | + if (!\is_null($this->lineBuffer)) { |
|
279 | + $rawLine = $this->lineBuffer; |
|
280 | + $this->lineBuffer = null; |
|
281 | + } else { |
|
282 | + do { |
|
283 | + $eof = \feof($this->input); |
|
284 | + |
|
285 | + $rawLine = \fgets($this->input); |
|
286 | + |
|
287 | + if ($eof || (\feof($this->input) && false === $rawLine)) { |
|
288 | + throw new EofException('End of document reached prematurely'); |
|
289 | + } |
|
290 | + if (false === $rawLine) { |
|
291 | + throw new ParseException('Error reading from input stream'); |
|
292 | + } |
|
293 | + $rawLine = \rtrim($rawLine, "\r\n"); |
|
294 | + } while ('' === $rawLine); // Skipping empty lines |
|
295 | + ++$this->lineIndex; |
|
296 | + } |
|
297 | + $line = $rawLine; |
|
298 | + |
|
299 | + $this->startLine = $this->lineIndex; |
|
300 | + |
|
301 | + // Looking ahead for folded lines. |
|
302 | + while (true) { |
|
303 | + $nextLine = \rtrim(\fgets($this->input), "\r\n"); |
|
304 | + ++$this->lineIndex; |
|
305 | + if (!$nextLine) { |
|
306 | + break; |
|
307 | + } |
|
308 | + if ("\t" === $nextLine[0] || ' ' === $nextLine[0]) { |
|
309 | + $curLine = \substr($nextLine, 1); |
|
310 | + $line .= $curLine; |
|
311 | + $rawLine .= "\n ".$curLine; |
|
312 | + } else { |
|
313 | + $this->lineBuffer = $nextLine; |
|
314 | + break; |
|
315 | + } |
|
316 | + } |
|
317 | + $this->rawLine = $rawLine; |
|
318 | + |
|
319 | + return $line; |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Reads a property or component from a line. |
|
324 | + */ |
|
325 | + protected function readProperty($line) |
|
326 | + { |
|
327 | + if ($this->options & self::OPTION_FORGIVING) { |
|
328 | + $propNameToken = 'A-Z0-9\-\._\\/'; |
|
329 | + } else { |
|
330 | + $propNameToken = 'A-Z0-9\-\.'; |
|
331 | + } |
|
332 | + |
|
333 | + $paramNameToken = 'A-Z0-9\-'; |
|
334 | + $safeChar = '^";:,'; |
|
335 | + $qSafeChar = '^"'; |
|
336 | + |
|
337 | + $regex = "/ |
|
338 | 338 | ^(?P<name> [$propNameToken]+ ) (?=[;:]) # property name |
339 | 339 | | |
340 | 340 | (?<=:)(?P<propValue> .+)$ # property value |
@@ -347,337 +347,337 @@ discard block |
||
347 | 347 | ) (?=[;:,]) |
348 | 348 | /xi"; |
349 | 349 | |
350 | - //echo $regex, "\n"; exit(); |
|
351 | - preg_match_all($regex, $line, $matches, PREG_SET_ORDER); |
|
350 | + //echo $regex, "\n"; exit(); |
|
351 | + preg_match_all($regex, $line, $matches, PREG_SET_ORDER); |
|
352 | 352 | |
353 | - $property = [ |
|
354 | - 'name' => null, |
|
355 | - 'parameters' => [], |
|
356 | - 'value' => null, |
|
357 | - ]; |
|
353 | + $property = [ |
|
354 | + 'name' => null, |
|
355 | + 'parameters' => [], |
|
356 | + 'value' => null, |
|
357 | + ]; |
|
358 | 358 | |
359 | - $lastParam = null; |
|
359 | + $lastParam = null; |
|
360 | 360 | |
361 | - /* |
|
361 | + /* |
|
362 | 362 | * Looping through all the tokens. |
363 | 363 | * |
364 | 364 | * Note that we are looping through them in reverse order, because if a |
365 | 365 | * sub-pattern matched, the subsequent named patterns will not show up |
366 | 366 | * in the result. |
367 | 367 | */ |
368 | - foreach ($matches as $match) { |
|
369 | - if (isset($match['paramValue'])) { |
|
370 | - if ($match['paramValue'] && '"' === $match['paramValue'][0]) { |
|
371 | - $value = substr($match['paramValue'], 1, -1); |
|
372 | - } else { |
|
373 | - $value = $match['paramValue']; |
|
374 | - } |
|
375 | - |
|
376 | - $value = $this->unescapeParam($value); |
|
377 | - |
|
378 | - if (is_null($lastParam)) { |
|
379 | - if ($this->options & self::OPTION_IGNORE_INVALID_LINES) { |
|
380 | - // When the property can't be matched and the configuration |
|
381 | - // option is set to ignore invalid lines, we ignore this line |
|
382 | - // This can happen when servers provide faulty data as iCloud |
|
383 | - // frequently does with X-APPLE-STRUCTURED-LOCATION |
|
384 | - continue; |
|
385 | - } |
|
386 | - throw new ParseException('Invalid Mimedir file. Line starting at '.$this->startLine.' did not follow iCalendar/vCard conventions'); |
|
387 | - } |
|
388 | - if (is_null($property['parameters'][$lastParam])) { |
|
389 | - $property['parameters'][$lastParam] = $value; |
|
390 | - } elseif (is_array($property['parameters'][$lastParam])) { |
|
391 | - $property['parameters'][$lastParam][] = $value; |
|
392 | - } elseif ($property['parameters'][$lastParam] === $value) { |
|
393 | - // When the current value of the parameter is the same as the |
|
394 | - // new one, then we can leave the current parameter as it is. |
|
395 | - } else { |
|
396 | - $property['parameters'][$lastParam] = [ |
|
397 | - $property['parameters'][$lastParam], |
|
398 | - $value, |
|
399 | - ]; |
|
400 | - } |
|
401 | - continue; |
|
402 | - } |
|
403 | - if (isset($match['paramName'])) { |
|
404 | - $lastParam = strtoupper($match['paramName']); |
|
405 | - if (!isset($property['parameters'][$lastParam])) { |
|
406 | - $property['parameters'][$lastParam] = null; |
|
407 | - } |
|
408 | - continue; |
|
409 | - } |
|
410 | - if (isset($match['propValue'])) { |
|
411 | - $property['value'] = $match['propValue']; |
|
412 | - continue; |
|
413 | - } |
|
414 | - if (isset($match['name']) && $match['name']) { |
|
415 | - $property['name'] = strtoupper($match['name']); |
|
416 | - continue; |
|
417 | - } |
|
418 | - |
|
419 | - // @codeCoverageIgnoreStart |
|
420 | - throw new \LogicException('This code should not be reachable'); |
|
421 | - // @codeCoverageIgnoreEnd |
|
422 | - } |
|
423 | - |
|
424 | - if (is_null($property['value'])) { |
|
425 | - $property['value'] = ''; |
|
426 | - } |
|
427 | - if (!$property['name']) { |
|
428 | - if ($this->options & self::OPTION_IGNORE_INVALID_LINES) { |
|
429 | - return false; |
|
430 | - } |
|
431 | - throw new ParseException('Invalid Mimedir file. Line starting at '.$this->startLine.' did not follow iCalendar/vCard conventions'); |
|
432 | - } |
|
433 | - |
|
434 | - // vCard 2.1 states that parameters may appear without a name, and only |
|
435 | - // a value. We can deduce the value based on its name. |
|
436 | - // |
|
437 | - // Our parser will get those as parameters without a value instead, so |
|
438 | - // we're filtering these parameters out first. |
|
439 | - $namedParameters = []; |
|
440 | - $namelessParameters = []; |
|
441 | - |
|
442 | - foreach ($property['parameters'] as $name => $value) { |
|
443 | - if (!is_null($value)) { |
|
444 | - $namedParameters[$name] = $value; |
|
445 | - } else { |
|
446 | - $namelessParameters[] = $name; |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - $propObj = $this->root->createProperty($property['name'], null, $namedParameters); |
|
451 | - |
|
452 | - foreach ($namelessParameters as $namelessParameter) { |
|
453 | - $propObj->add(null, $namelessParameter); |
|
454 | - } |
|
455 | - |
|
456 | - if (isset($propObj['ENCODING']) && 'QUOTED-PRINTABLE' === strtoupper($propObj['ENCODING'])) { |
|
457 | - $propObj->setQuotedPrintableValue($this->extractQuotedPrintableValue()); |
|
458 | - } else { |
|
459 | - $charset = $this->charset; |
|
460 | - if (Document::VCARD21 === $this->root->getDocumentType() && isset($propObj['CHARSET'])) { |
|
461 | - // vCard 2.1 allows the character set to be specified per property. |
|
462 | - $charset = (string) $propObj['CHARSET']; |
|
463 | - } |
|
464 | - switch (strtolower($charset)) { |
|
465 | - case 'utf-8': |
|
466 | - break; |
|
467 | - case 'windows-1252': |
|
468 | - case 'iso-8859-1': |
|
469 | - $property['value'] = mb_convert_encoding($property['value'], 'UTF-8', $charset); |
|
470 | - break; |
|
471 | - default: |
|
472 | - throw new ParseException('Unsupported CHARSET: '.$propObj['CHARSET']); |
|
473 | - } |
|
474 | - $propObj->setRawMimeDirValue($property['value']); |
|
475 | - } |
|
476 | - |
|
477 | - return $propObj; |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * Unescapes a property value. |
|
482 | - * |
|
483 | - * vCard 2.1 says: |
|
484 | - * * Semi-colons must be escaped in some property values, specifically |
|
485 | - * ADR, ORG and N. |
|
486 | - * * Semi-colons must be escaped in parameter values, because semi-colons |
|
487 | - * are also use to separate values. |
|
488 | - * * No mention of escaping backslashes with another backslash. |
|
489 | - * * newlines are not escaped either, instead QUOTED-PRINTABLE is used to |
|
490 | - * span values over more than 1 line. |
|
491 | - * |
|
492 | - * vCard 3.0 says: |
|
493 | - * * (rfc2425) Backslashes, newlines (\n or \N) and comma's must be |
|
494 | - * escaped, all time time. |
|
495 | - * * Comma's are used for delimiters in multiple values |
|
496 | - * * (rfc2426) Adds to to this that the semi-colon MUST also be escaped, |
|
497 | - * as in some properties semi-colon is used for separators. |
|
498 | - * * Properties using semi-colons: N, ADR, GEO, ORG |
|
499 | - * * Both ADR and N's individual parts may be broken up further with a |
|
500 | - * comma. |
|
501 | - * * Properties using commas: NICKNAME, CATEGORIES |
|
502 | - * |
|
503 | - * vCard 4.0 (rfc6350) says: |
|
504 | - * * Commas must be escaped. |
|
505 | - * * Semi-colons may be escaped, an unescaped semi-colon _may_ be a |
|
506 | - * delimiter, depending on the property. |
|
507 | - * * Backslashes must be escaped |
|
508 | - * * Newlines must be escaped as either \N or \n. |
|
509 | - * * Some compound properties may contain multiple parts themselves, so a |
|
510 | - * comma within a semi-colon delimited property may also be unescaped |
|
511 | - * to denote multiple parts _within_ the compound property. |
|
512 | - * * Text-properties using semi-colons: N, ADR, ORG, CLIENTPIDMAP. |
|
513 | - * * Text-properties using commas: NICKNAME, RELATED, CATEGORIES, PID. |
|
514 | - * |
|
515 | - * Even though the spec says that commas must always be escaped, the |
|
516 | - * example for GEO in Section 6.5.2 seems to violate this. |
|
517 | - * |
|
518 | - * iCalendar 2.0 (rfc5545) says: |
|
519 | - * * Commas or semi-colons may be used as delimiters, depending on the |
|
520 | - * property. |
|
521 | - * * Commas, semi-colons, backslashes, newline (\N or \n) are always |
|
522 | - * escaped, unless they are delimiters. |
|
523 | - * * Colons shall not be escaped. |
|
524 | - * * Commas can be considered the 'default delimiter' and is described as |
|
525 | - * the delimiter in cases where the order of the multiple values is |
|
526 | - * insignificant. |
|
527 | - * * Semi-colons are described as the delimiter for 'structured values'. |
|
528 | - * They are specifically used in Semi-colons are used as a delimiter in |
|
529 | - * REQUEST-STATUS, RRULE, GEO and EXRULE. EXRULE is deprecated however. |
|
530 | - * |
|
531 | - * Now for the parameters |
|
532 | - * |
|
533 | - * If delimiter is not set (empty string) this method will just return a string. |
|
534 | - * If it's a comma or a semi-colon the string will be split on those |
|
535 | - * characters, and always return an array. |
|
536 | - * |
|
537 | - * @param string $input |
|
538 | - * @param string $delimiter |
|
539 | - * |
|
540 | - * @return string|string[] |
|
541 | - */ |
|
542 | - public static function unescapeValue($input, $delimiter = ';') |
|
543 | - { |
|
544 | - $regex = '# (?: (\\\\ (?: \\\\ | N | n | ; | , ) )'; |
|
545 | - if ($delimiter) { |
|
546 | - $regex .= ' | ('.$delimiter.')'; |
|
547 | - } |
|
548 | - $regex .= ') #x'; |
|
549 | - |
|
550 | - $matches = preg_split($regex, $input, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
|
551 | - |
|
552 | - $resultArray = []; |
|
553 | - $result = ''; |
|
554 | - |
|
555 | - foreach ($matches as $match) { |
|
556 | - switch ($match) { |
|
557 | - case '\\\\': |
|
558 | - $result .= '\\'; |
|
559 | - break; |
|
560 | - case '\N': |
|
561 | - case '\n': |
|
562 | - $result .= "\n"; |
|
563 | - break; |
|
564 | - case '\;': |
|
565 | - $result .= ';'; |
|
566 | - break; |
|
567 | - case '\,': |
|
568 | - $result .= ','; |
|
569 | - break; |
|
570 | - case $delimiter: |
|
571 | - $resultArray[] = $result; |
|
572 | - $result = ''; |
|
573 | - break; |
|
574 | - default: |
|
575 | - $result .= $match; |
|
576 | - break; |
|
577 | - } |
|
578 | - } |
|
579 | - |
|
580 | - $resultArray[] = $result; |
|
581 | - |
|
582 | - return $delimiter ? $resultArray : $result; |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * Unescapes a parameter value. |
|
587 | - * |
|
588 | - * vCard 2.1: |
|
589 | - * * Does not mention a mechanism for this. In addition, double quotes |
|
590 | - * are never used to wrap values. |
|
591 | - * * This means that parameters can simply not contain colons or |
|
592 | - * semi-colons. |
|
593 | - * |
|
594 | - * vCard 3.0 (rfc2425, rfc2426): |
|
595 | - * * Parameters _may_ be surrounded by double quotes. |
|
596 | - * * If this is not the case, semi-colon, colon and comma may simply not |
|
597 | - * occur (the comma used for multiple parameter values though). |
|
598 | - * * If it is surrounded by double-quotes, it may simply not contain |
|
599 | - * double-quotes. |
|
600 | - * * This means that a parameter can in no case encode double-quotes, or |
|
601 | - * newlines. |
|
602 | - * |
|
603 | - * vCard 4.0 (rfc6350) |
|
604 | - * * Behavior seems to be identical to vCard 3.0 |
|
605 | - * |
|
606 | - * iCalendar 2.0 (rfc5545) |
|
607 | - * * Behavior seems to be identical to vCard 3.0 |
|
608 | - * |
|
609 | - * Parameter escaping mechanism (rfc6868) : |
|
610 | - * * This rfc describes a new way to escape parameter values. |
|
611 | - * * New-line is encoded as ^n |
|
612 | - * * ^ is encoded as ^^. |
|
613 | - * * " is encoded as ^' |
|
614 | - * |
|
615 | - * @param string $input |
|
616 | - */ |
|
617 | - private function unescapeParam($input) |
|
618 | - { |
|
619 | - return |
|
620 | - preg_replace_callback( |
|
621 | - '#(\^(\^|n|\'))#', |
|
622 | - function ($matches) { |
|
623 | - switch ($matches[2]) { |
|
624 | - case 'n': |
|
625 | - return "\n"; |
|
626 | - case '^': |
|
627 | - return '^'; |
|
628 | - case '\'': |
|
629 | - return '"'; |
|
630 | - |
|
631 | - // @codeCoverageIgnoreStart |
|
632 | - } |
|
633 | - // @codeCoverageIgnoreEnd |
|
634 | - }, |
|
635 | - $input |
|
636 | - ); |
|
637 | - } |
|
638 | - |
|
639 | - /** |
|
640 | - * Gets the full quoted printable value. |
|
641 | - * |
|
642 | - * We need a special method for this, because newlines have both a meaning |
|
643 | - * in vCards, and in QuotedPrintable. |
|
644 | - * |
|
645 | - * This method does not do any decoding. |
|
646 | - * |
|
647 | - * @return string |
|
648 | - */ |
|
649 | - private function extractQuotedPrintableValue() |
|
650 | - { |
|
651 | - // We need to parse the raw line again to get the start of the value. |
|
652 | - // |
|
653 | - // We are basically looking for the first colon (:), but we need to |
|
654 | - // skip over the parameters first, as they may contain one. |
|
655 | - $regex = '/^ |
|
368 | + foreach ($matches as $match) { |
|
369 | + if (isset($match['paramValue'])) { |
|
370 | + if ($match['paramValue'] && '"' === $match['paramValue'][0]) { |
|
371 | + $value = substr($match['paramValue'], 1, -1); |
|
372 | + } else { |
|
373 | + $value = $match['paramValue']; |
|
374 | + } |
|
375 | + |
|
376 | + $value = $this->unescapeParam($value); |
|
377 | + |
|
378 | + if (is_null($lastParam)) { |
|
379 | + if ($this->options & self::OPTION_IGNORE_INVALID_LINES) { |
|
380 | + // When the property can't be matched and the configuration |
|
381 | + // option is set to ignore invalid lines, we ignore this line |
|
382 | + // This can happen when servers provide faulty data as iCloud |
|
383 | + // frequently does with X-APPLE-STRUCTURED-LOCATION |
|
384 | + continue; |
|
385 | + } |
|
386 | + throw new ParseException('Invalid Mimedir file. Line starting at '.$this->startLine.' did not follow iCalendar/vCard conventions'); |
|
387 | + } |
|
388 | + if (is_null($property['parameters'][$lastParam])) { |
|
389 | + $property['parameters'][$lastParam] = $value; |
|
390 | + } elseif (is_array($property['parameters'][$lastParam])) { |
|
391 | + $property['parameters'][$lastParam][] = $value; |
|
392 | + } elseif ($property['parameters'][$lastParam] === $value) { |
|
393 | + // When the current value of the parameter is the same as the |
|
394 | + // new one, then we can leave the current parameter as it is. |
|
395 | + } else { |
|
396 | + $property['parameters'][$lastParam] = [ |
|
397 | + $property['parameters'][$lastParam], |
|
398 | + $value, |
|
399 | + ]; |
|
400 | + } |
|
401 | + continue; |
|
402 | + } |
|
403 | + if (isset($match['paramName'])) { |
|
404 | + $lastParam = strtoupper($match['paramName']); |
|
405 | + if (!isset($property['parameters'][$lastParam])) { |
|
406 | + $property['parameters'][$lastParam] = null; |
|
407 | + } |
|
408 | + continue; |
|
409 | + } |
|
410 | + if (isset($match['propValue'])) { |
|
411 | + $property['value'] = $match['propValue']; |
|
412 | + continue; |
|
413 | + } |
|
414 | + if (isset($match['name']) && $match['name']) { |
|
415 | + $property['name'] = strtoupper($match['name']); |
|
416 | + continue; |
|
417 | + } |
|
418 | + |
|
419 | + // @codeCoverageIgnoreStart |
|
420 | + throw new \LogicException('This code should not be reachable'); |
|
421 | + // @codeCoverageIgnoreEnd |
|
422 | + } |
|
423 | + |
|
424 | + if (is_null($property['value'])) { |
|
425 | + $property['value'] = ''; |
|
426 | + } |
|
427 | + if (!$property['name']) { |
|
428 | + if ($this->options & self::OPTION_IGNORE_INVALID_LINES) { |
|
429 | + return false; |
|
430 | + } |
|
431 | + throw new ParseException('Invalid Mimedir file. Line starting at '.$this->startLine.' did not follow iCalendar/vCard conventions'); |
|
432 | + } |
|
433 | + |
|
434 | + // vCard 2.1 states that parameters may appear without a name, and only |
|
435 | + // a value. We can deduce the value based on its name. |
|
436 | + // |
|
437 | + // Our parser will get those as parameters without a value instead, so |
|
438 | + // we're filtering these parameters out first. |
|
439 | + $namedParameters = []; |
|
440 | + $namelessParameters = []; |
|
441 | + |
|
442 | + foreach ($property['parameters'] as $name => $value) { |
|
443 | + if (!is_null($value)) { |
|
444 | + $namedParameters[$name] = $value; |
|
445 | + } else { |
|
446 | + $namelessParameters[] = $name; |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + $propObj = $this->root->createProperty($property['name'], null, $namedParameters); |
|
451 | + |
|
452 | + foreach ($namelessParameters as $namelessParameter) { |
|
453 | + $propObj->add(null, $namelessParameter); |
|
454 | + } |
|
455 | + |
|
456 | + if (isset($propObj['ENCODING']) && 'QUOTED-PRINTABLE' === strtoupper($propObj['ENCODING'])) { |
|
457 | + $propObj->setQuotedPrintableValue($this->extractQuotedPrintableValue()); |
|
458 | + } else { |
|
459 | + $charset = $this->charset; |
|
460 | + if (Document::VCARD21 === $this->root->getDocumentType() && isset($propObj['CHARSET'])) { |
|
461 | + // vCard 2.1 allows the character set to be specified per property. |
|
462 | + $charset = (string) $propObj['CHARSET']; |
|
463 | + } |
|
464 | + switch (strtolower($charset)) { |
|
465 | + case 'utf-8': |
|
466 | + break; |
|
467 | + case 'windows-1252': |
|
468 | + case 'iso-8859-1': |
|
469 | + $property['value'] = mb_convert_encoding($property['value'], 'UTF-8', $charset); |
|
470 | + break; |
|
471 | + default: |
|
472 | + throw new ParseException('Unsupported CHARSET: '.$propObj['CHARSET']); |
|
473 | + } |
|
474 | + $propObj->setRawMimeDirValue($property['value']); |
|
475 | + } |
|
476 | + |
|
477 | + return $propObj; |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * Unescapes a property value. |
|
482 | + * |
|
483 | + * vCard 2.1 says: |
|
484 | + * * Semi-colons must be escaped in some property values, specifically |
|
485 | + * ADR, ORG and N. |
|
486 | + * * Semi-colons must be escaped in parameter values, because semi-colons |
|
487 | + * are also use to separate values. |
|
488 | + * * No mention of escaping backslashes with another backslash. |
|
489 | + * * newlines are not escaped either, instead QUOTED-PRINTABLE is used to |
|
490 | + * span values over more than 1 line. |
|
491 | + * |
|
492 | + * vCard 3.0 says: |
|
493 | + * * (rfc2425) Backslashes, newlines (\n or \N) and comma's must be |
|
494 | + * escaped, all time time. |
|
495 | + * * Comma's are used for delimiters in multiple values |
|
496 | + * * (rfc2426) Adds to to this that the semi-colon MUST also be escaped, |
|
497 | + * as in some properties semi-colon is used for separators. |
|
498 | + * * Properties using semi-colons: N, ADR, GEO, ORG |
|
499 | + * * Both ADR and N's individual parts may be broken up further with a |
|
500 | + * comma. |
|
501 | + * * Properties using commas: NICKNAME, CATEGORIES |
|
502 | + * |
|
503 | + * vCard 4.0 (rfc6350) says: |
|
504 | + * * Commas must be escaped. |
|
505 | + * * Semi-colons may be escaped, an unescaped semi-colon _may_ be a |
|
506 | + * delimiter, depending on the property. |
|
507 | + * * Backslashes must be escaped |
|
508 | + * * Newlines must be escaped as either \N or \n. |
|
509 | + * * Some compound properties may contain multiple parts themselves, so a |
|
510 | + * comma within a semi-colon delimited property may also be unescaped |
|
511 | + * to denote multiple parts _within_ the compound property. |
|
512 | + * * Text-properties using semi-colons: N, ADR, ORG, CLIENTPIDMAP. |
|
513 | + * * Text-properties using commas: NICKNAME, RELATED, CATEGORIES, PID. |
|
514 | + * |
|
515 | + * Even though the spec says that commas must always be escaped, the |
|
516 | + * example for GEO in Section 6.5.2 seems to violate this. |
|
517 | + * |
|
518 | + * iCalendar 2.0 (rfc5545) says: |
|
519 | + * * Commas or semi-colons may be used as delimiters, depending on the |
|
520 | + * property. |
|
521 | + * * Commas, semi-colons, backslashes, newline (\N or \n) are always |
|
522 | + * escaped, unless they are delimiters. |
|
523 | + * * Colons shall not be escaped. |
|
524 | + * * Commas can be considered the 'default delimiter' and is described as |
|
525 | + * the delimiter in cases where the order of the multiple values is |
|
526 | + * insignificant. |
|
527 | + * * Semi-colons are described as the delimiter for 'structured values'. |
|
528 | + * They are specifically used in Semi-colons are used as a delimiter in |
|
529 | + * REQUEST-STATUS, RRULE, GEO and EXRULE. EXRULE is deprecated however. |
|
530 | + * |
|
531 | + * Now for the parameters |
|
532 | + * |
|
533 | + * If delimiter is not set (empty string) this method will just return a string. |
|
534 | + * If it's a comma or a semi-colon the string will be split on those |
|
535 | + * characters, and always return an array. |
|
536 | + * |
|
537 | + * @param string $input |
|
538 | + * @param string $delimiter |
|
539 | + * |
|
540 | + * @return string|string[] |
|
541 | + */ |
|
542 | + public static function unescapeValue($input, $delimiter = ';') |
|
543 | + { |
|
544 | + $regex = '# (?: (\\\\ (?: \\\\ | N | n | ; | , ) )'; |
|
545 | + if ($delimiter) { |
|
546 | + $regex .= ' | ('.$delimiter.')'; |
|
547 | + } |
|
548 | + $regex .= ') #x'; |
|
549 | + |
|
550 | + $matches = preg_split($regex, $input, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
|
551 | + |
|
552 | + $resultArray = []; |
|
553 | + $result = ''; |
|
554 | + |
|
555 | + foreach ($matches as $match) { |
|
556 | + switch ($match) { |
|
557 | + case '\\\\': |
|
558 | + $result .= '\\'; |
|
559 | + break; |
|
560 | + case '\N': |
|
561 | + case '\n': |
|
562 | + $result .= "\n"; |
|
563 | + break; |
|
564 | + case '\;': |
|
565 | + $result .= ';'; |
|
566 | + break; |
|
567 | + case '\,': |
|
568 | + $result .= ','; |
|
569 | + break; |
|
570 | + case $delimiter: |
|
571 | + $resultArray[] = $result; |
|
572 | + $result = ''; |
|
573 | + break; |
|
574 | + default: |
|
575 | + $result .= $match; |
|
576 | + break; |
|
577 | + } |
|
578 | + } |
|
579 | + |
|
580 | + $resultArray[] = $result; |
|
581 | + |
|
582 | + return $delimiter ? $resultArray : $result; |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * Unescapes a parameter value. |
|
587 | + * |
|
588 | + * vCard 2.1: |
|
589 | + * * Does not mention a mechanism for this. In addition, double quotes |
|
590 | + * are never used to wrap values. |
|
591 | + * * This means that parameters can simply not contain colons or |
|
592 | + * semi-colons. |
|
593 | + * |
|
594 | + * vCard 3.0 (rfc2425, rfc2426): |
|
595 | + * * Parameters _may_ be surrounded by double quotes. |
|
596 | + * * If this is not the case, semi-colon, colon and comma may simply not |
|
597 | + * occur (the comma used for multiple parameter values though). |
|
598 | + * * If it is surrounded by double-quotes, it may simply not contain |
|
599 | + * double-quotes. |
|
600 | + * * This means that a parameter can in no case encode double-quotes, or |
|
601 | + * newlines. |
|
602 | + * |
|
603 | + * vCard 4.0 (rfc6350) |
|
604 | + * * Behavior seems to be identical to vCard 3.0 |
|
605 | + * |
|
606 | + * iCalendar 2.0 (rfc5545) |
|
607 | + * * Behavior seems to be identical to vCard 3.0 |
|
608 | + * |
|
609 | + * Parameter escaping mechanism (rfc6868) : |
|
610 | + * * This rfc describes a new way to escape parameter values. |
|
611 | + * * New-line is encoded as ^n |
|
612 | + * * ^ is encoded as ^^. |
|
613 | + * * " is encoded as ^' |
|
614 | + * |
|
615 | + * @param string $input |
|
616 | + */ |
|
617 | + private function unescapeParam($input) |
|
618 | + { |
|
619 | + return |
|
620 | + preg_replace_callback( |
|
621 | + '#(\^(\^|n|\'))#', |
|
622 | + function ($matches) { |
|
623 | + switch ($matches[2]) { |
|
624 | + case 'n': |
|
625 | + return "\n"; |
|
626 | + case '^': |
|
627 | + return '^'; |
|
628 | + case '\'': |
|
629 | + return '"'; |
|
630 | + |
|
631 | + // @codeCoverageIgnoreStart |
|
632 | + } |
|
633 | + // @codeCoverageIgnoreEnd |
|
634 | + }, |
|
635 | + $input |
|
636 | + ); |
|
637 | + } |
|
638 | + |
|
639 | + /** |
|
640 | + * Gets the full quoted printable value. |
|
641 | + * |
|
642 | + * We need a special method for this, because newlines have both a meaning |
|
643 | + * in vCards, and in QuotedPrintable. |
|
644 | + * |
|
645 | + * This method does not do any decoding. |
|
646 | + * |
|
647 | + * @return string |
|
648 | + */ |
|
649 | + private function extractQuotedPrintableValue() |
|
650 | + { |
|
651 | + // We need to parse the raw line again to get the start of the value. |
|
652 | + // |
|
653 | + // We are basically looking for the first colon (:), but we need to |
|
654 | + // skip over the parameters first, as they may contain one. |
|
655 | + $regex = '/^ |
|
656 | 656 | (?: [^:])+ # Anything but a colon |
657 | 657 | (?: "[^"]")* # A parameter in double quotes |
658 | 658 | : # start of the value we really care about |
659 | 659 | (.*)$ |
660 | 660 | /xs'; |
661 | 661 | |
662 | - preg_match($regex, $this->rawLine, $matches); |
|
663 | - |
|
664 | - $value = $matches[1]; |
|
665 | - // Removing the first whitespace character from every line. Kind of |
|
666 | - // like unfolding, but we keep the newline. |
|
667 | - $value = str_replace("\n ", "\n", $value); |
|
668 | - |
|
669 | - // Microsoft products don't always correctly fold lines, they may be |
|
670 | - // missing a whitespace. So if 'forgiving' is turned on, we will take |
|
671 | - // those as well. |
|
672 | - if ($this->options & self::OPTION_FORGIVING) { |
|
673 | - while ('=' === substr($value, -1) && $this->lineBuffer) { |
|
674 | - // Reading the line |
|
675 | - $this->readLine(); |
|
676 | - // Grabbing the raw form |
|
677 | - $value .= "\n".$this->rawLine; |
|
678 | - } |
|
679 | - } |
|
680 | - |
|
681 | - return $value; |
|
682 | - } |
|
662 | + preg_match($regex, $this->rawLine, $matches); |
|
663 | + |
|
664 | + $value = $matches[1]; |
|
665 | + // Removing the first whitespace character from every line. Kind of |
|
666 | + // like unfolding, but we keep the newline. |
|
667 | + $value = str_replace("\n ", "\n", $value); |
|
668 | + |
|
669 | + // Microsoft products don't always correctly fold lines, they may be |
|
670 | + // missing a whitespace. So if 'forgiving' is turned on, we will take |
|
671 | + // those as well. |
|
672 | + if ($this->options & self::OPTION_FORGIVING) { |
|
673 | + while ('=' === substr($value, -1) && $this->lineBuffer) { |
|
674 | + // Reading the line |
|
675 | + $this->readLine(); |
|
676 | + // Grabbing the raw form |
|
677 | + $value .= "\n".$this->rawLine; |
|
678 | + } |
|
679 | + } |
|
680 | + |
|
681 | + return $value; |
|
682 | + } |
|
683 | 683 | } |
@@ -16,86 +16,86 @@ |
||
16 | 16 | */ |
17 | 17 | class VJournal extends VObject\Component |
18 | 18 | { |
19 | - /** |
|
20 | - * Returns true or false depending on if the event falls in the specified |
|
21 | - * time-range. This is used for filtering purposes. |
|
22 | - * |
|
23 | - * The rules used to determine if an event falls within the specified |
|
24 | - * time-range is based on the CalDAV specification. |
|
25 | - * |
|
26 | - * @return bool |
|
27 | - */ |
|
28 | - public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) |
|
29 | - { |
|
30 | - $dtstart = isset($this->DTSTART) ? $this->DTSTART->getDateTime() : null; |
|
31 | - if ($dtstart) { |
|
32 | - $effectiveEnd = $dtstart; |
|
33 | - if (!$this->DTSTART->hasTime()) { |
|
34 | - $effectiveEnd = $effectiveEnd->modify('+1 day'); |
|
35 | - } |
|
19 | + /** |
|
20 | + * Returns true or false depending on if the event falls in the specified |
|
21 | + * time-range. This is used for filtering purposes. |
|
22 | + * |
|
23 | + * The rules used to determine if an event falls within the specified |
|
24 | + * time-range is based on the CalDAV specification. |
|
25 | + * |
|
26 | + * @return bool |
|
27 | + */ |
|
28 | + public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) |
|
29 | + { |
|
30 | + $dtstart = isset($this->DTSTART) ? $this->DTSTART->getDateTime() : null; |
|
31 | + if ($dtstart) { |
|
32 | + $effectiveEnd = $dtstart; |
|
33 | + if (!$this->DTSTART->hasTime()) { |
|
34 | + $effectiveEnd = $effectiveEnd->modify('+1 day'); |
|
35 | + } |
|
36 | 36 | |
37 | - return $start <= $effectiveEnd && $end > $dtstart; |
|
38 | - } |
|
37 | + return $start <= $effectiveEnd && $end > $dtstart; |
|
38 | + } |
|
39 | 39 | |
40 | - return false; |
|
41 | - } |
|
40 | + return false; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * A simple list of validation rules. |
|
45 | - * |
|
46 | - * This is simply a list of properties, and how many times they either |
|
47 | - * must or must not appear. |
|
48 | - * |
|
49 | - * Possible values per property: |
|
50 | - * * 0 - Must not appear. |
|
51 | - * * 1 - Must appear exactly once. |
|
52 | - * * + - Must appear at least once. |
|
53 | - * * * - Can appear any number of times. |
|
54 | - * * ? - May appear, but not more than once. |
|
55 | - * |
|
56 | - * @var array |
|
57 | - */ |
|
58 | - public function getValidationRules() |
|
59 | - { |
|
60 | - return [ |
|
61 | - 'UID' => 1, |
|
62 | - 'DTSTAMP' => 1, |
|
43 | + /** |
|
44 | + * A simple list of validation rules. |
|
45 | + * |
|
46 | + * This is simply a list of properties, and how many times they either |
|
47 | + * must or must not appear. |
|
48 | + * |
|
49 | + * Possible values per property: |
|
50 | + * * 0 - Must not appear. |
|
51 | + * * 1 - Must appear exactly once. |
|
52 | + * * + - Must appear at least once. |
|
53 | + * * * - Can appear any number of times. |
|
54 | + * * ? - May appear, but not more than once. |
|
55 | + * |
|
56 | + * @var array |
|
57 | + */ |
|
58 | + public function getValidationRules() |
|
59 | + { |
|
60 | + return [ |
|
61 | + 'UID' => 1, |
|
62 | + 'DTSTAMP' => 1, |
|
63 | 63 | |
64 | - 'CLASS' => '?', |
|
65 | - 'CREATED' => '?', |
|
66 | - 'DTSTART' => '?', |
|
67 | - 'LAST-MODIFIED' => '?', |
|
68 | - 'ORGANIZER' => '?', |
|
69 | - 'RECURRENCE-ID' => '?', |
|
70 | - 'SEQUENCE' => '?', |
|
71 | - 'STATUS' => '?', |
|
72 | - 'SUMMARY' => '?', |
|
73 | - 'URL' => '?', |
|
64 | + 'CLASS' => '?', |
|
65 | + 'CREATED' => '?', |
|
66 | + 'DTSTART' => '?', |
|
67 | + 'LAST-MODIFIED' => '?', |
|
68 | + 'ORGANIZER' => '?', |
|
69 | + 'RECURRENCE-ID' => '?', |
|
70 | + 'SEQUENCE' => '?', |
|
71 | + 'STATUS' => '?', |
|
72 | + 'SUMMARY' => '?', |
|
73 | + 'URL' => '?', |
|
74 | 74 | |
75 | - 'RRULE' => '?', |
|
75 | + 'RRULE' => '?', |
|
76 | 76 | |
77 | - 'ATTACH' => '*', |
|
78 | - 'ATTENDEE' => '*', |
|
79 | - 'CATEGORIES' => '*', |
|
80 | - 'COMMENT' => '*', |
|
81 | - 'CONTACT' => '*', |
|
82 | - 'DESCRIPTION' => '*', |
|
83 | - 'EXDATE' => '*', |
|
84 | - 'RELATED-TO' => '*', |
|
85 | - 'RDATE' => '*', |
|
86 | - ]; |
|
87 | - } |
|
77 | + 'ATTACH' => '*', |
|
78 | + 'ATTENDEE' => '*', |
|
79 | + 'CATEGORIES' => '*', |
|
80 | + 'COMMENT' => '*', |
|
81 | + 'CONTACT' => '*', |
|
82 | + 'DESCRIPTION' => '*', |
|
83 | + 'EXDATE' => '*', |
|
84 | + 'RELATED-TO' => '*', |
|
85 | + 'RDATE' => '*', |
|
86 | + ]; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * This method should return a list of default property values. |
|
91 | - * |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - protected function getDefaults() |
|
95 | - { |
|
96 | - return [ |
|
97 | - 'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(), |
|
98 | - 'DTSTAMP' => gmdate('Ymd\\THis\\Z'), |
|
99 | - ]; |
|
100 | - } |
|
89 | + /** |
|
90 | + * This method should return a list of default property values. |
|
91 | + * |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + protected function getDefaults() |
|
95 | + { |
|
96 | + return [ |
|
97 | + 'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(), |
|
98 | + 'DTSTAMP' => gmdate('Ymd\\THis\\Z'), |
|
99 | + ]; |
|
100 | + } |
|
101 | 101 | } |
@@ -17,133 +17,133 @@ |
||
17 | 17 | */ |
18 | 18 | class VAvailability extends VObject\Component |
19 | 19 | { |
20 | - /** |
|
21 | - * Returns true or false depending on if the event falls in the specified |
|
22 | - * time-range. This is used for filtering purposes. |
|
23 | - * |
|
24 | - * The rules used to determine if an event falls within the specified |
|
25 | - * time-range is based on: |
|
26 | - * |
|
27 | - * https://tools.ietf.org/html/draft-daboo-calendar-availability-05#section-3.1 |
|
28 | - * |
|
29 | - * @return bool |
|
30 | - */ |
|
31 | - public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) |
|
32 | - { |
|
33 | - list($effectiveStart, $effectiveEnd) = $this->getEffectiveStartEnd(); |
|
20 | + /** |
|
21 | + * Returns true or false depending on if the event falls in the specified |
|
22 | + * time-range. This is used for filtering purposes. |
|
23 | + * |
|
24 | + * The rules used to determine if an event falls within the specified |
|
25 | + * time-range is based on: |
|
26 | + * |
|
27 | + * https://tools.ietf.org/html/draft-daboo-calendar-availability-05#section-3.1 |
|
28 | + * |
|
29 | + * @return bool |
|
30 | + */ |
|
31 | + public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) |
|
32 | + { |
|
33 | + list($effectiveStart, $effectiveEnd) = $this->getEffectiveStartEnd(); |
|
34 | 34 | |
35 | - return |
|
36 | - (is_null($effectiveStart) || $start < $effectiveEnd) && |
|
37 | - (is_null($effectiveEnd) || $end > $effectiveStart) |
|
38 | - ; |
|
39 | - } |
|
35 | + return |
|
36 | + (is_null($effectiveStart) || $start < $effectiveEnd) && |
|
37 | + (is_null($effectiveEnd) || $end > $effectiveStart) |
|
38 | + ; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Returns the 'effective start' and 'effective end' of this VAVAILABILITY |
|
43 | - * component. |
|
44 | - * |
|
45 | - * We use the DTSTART and DTEND or DURATION to determine this. |
|
46 | - * |
|
47 | - * The returned value is an array containing DateTimeImmutable instances. |
|
48 | - * If either the start or end is 'unbounded' its value will be null |
|
49 | - * instead. |
|
50 | - * |
|
51 | - * @return array |
|
52 | - */ |
|
53 | - public function getEffectiveStartEnd() |
|
54 | - { |
|
55 | - $effectiveStart = null; |
|
56 | - $effectiveEnd = null; |
|
41 | + /** |
|
42 | + * Returns the 'effective start' and 'effective end' of this VAVAILABILITY |
|
43 | + * component. |
|
44 | + * |
|
45 | + * We use the DTSTART and DTEND or DURATION to determine this. |
|
46 | + * |
|
47 | + * The returned value is an array containing DateTimeImmutable instances. |
|
48 | + * If either the start or end is 'unbounded' its value will be null |
|
49 | + * instead. |
|
50 | + * |
|
51 | + * @return array |
|
52 | + */ |
|
53 | + public function getEffectiveStartEnd() |
|
54 | + { |
|
55 | + $effectiveStart = null; |
|
56 | + $effectiveEnd = null; |
|
57 | 57 | |
58 | - if (isset($this->DTSTART)) { |
|
59 | - $effectiveStart = $this->DTSTART->getDateTime(); |
|
60 | - } |
|
61 | - if (isset($this->DTEND)) { |
|
62 | - $effectiveEnd = $this->DTEND->getDateTime(); |
|
63 | - } elseif ($effectiveStart && isset($this->DURATION)) { |
|
64 | - $effectiveEnd = $effectiveStart->add(VObject\DateTimeParser::parseDuration($this->DURATION)); |
|
65 | - } |
|
58 | + if (isset($this->DTSTART)) { |
|
59 | + $effectiveStart = $this->DTSTART->getDateTime(); |
|
60 | + } |
|
61 | + if (isset($this->DTEND)) { |
|
62 | + $effectiveEnd = $this->DTEND->getDateTime(); |
|
63 | + } elseif ($effectiveStart && isset($this->DURATION)) { |
|
64 | + $effectiveEnd = $effectiveStart->add(VObject\DateTimeParser::parseDuration($this->DURATION)); |
|
65 | + } |
|
66 | 66 | |
67 | - return [$effectiveStart, $effectiveEnd]; |
|
68 | - } |
|
67 | + return [$effectiveStart, $effectiveEnd]; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * A simple list of validation rules. |
|
72 | - * |
|
73 | - * This is simply a list of properties, and how many times they either |
|
74 | - * must or must not appear. |
|
75 | - * |
|
76 | - * Possible values per property: |
|
77 | - * * 0 - Must not appear. |
|
78 | - * * 1 - Must appear exactly once. |
|
79 | - * * + - Must appear at least once. |
|
80 | - * * * - Can appear any number of times. |
|
81 | - * * ? - May appear, but not more than once. |
|
82 | - * |
|
83 | - * @var array |
|
84 | - */ |
|
85 | - public function getValidationRules() |
|
86 | - { |
|
87 | - return [ |
|
88 | - 'UID' => 1, |
|
89 | - 'DTSTAMP' => 1, |
|
70 | + /** |
|
71 | + * A simple list of validation rules. |
|
72 | + * |
|
73 | + * This is simply a list of properties, and how many times they either |
|
74 | + * must or must not appear. |
|
75 | + * |
|
76 | + * Possible values per property: |
|
77 | + * * 0 - Must not appear. |
|
78 | + * * 1 - Must appear exactly once. |
|
79 | + * * + - Must appear at least once. |
|
80 | + * * * - Can appear any number of times. |
|
81 | + * * ? - May appear, but not more than once. |
|
82 | + * |
|
83 | + * @var array |
|
84 | + */ |
|
85 | + public function getValidationRules() |
|
86 | + { |
|
87 | + return [ |
|
88 | + 'UID' => 1, |
|
89 | + 'DTSTAMP' => 1, |
|
90 | 90 | |
91 | - 'BUSYTYPE' => '?', |
|
92 | - 'CLASS' => '?', |
|
93 | - 'CREATED' => '?', |
|
94 | - 'DESCRIPTION' => '?', |
|
95 | - 'DTSTART' => '?', |
|
96 | - 'LAST-MODIFIED' => '?', |
|
97 | - 'ORGANIZER' => '?', |
|
98 | - 'PRIORITY' => '?', |
|
99 | - 'SEQUENCE' => '?', |
|
100 | - 'SUMMARY' => '?', |
|
101 | - 'URL' => '?', |
|
102 | - 'DTEND' => '?', |
|
103 | - 'DURATION' => '?', |
|
91 | + 'BUSYTYPE' => '?', |
|
92 | + 'CLASS' => '?', |
|
93 | + 'CREATED' => '?', |
|
94 | + 'DESCRIPTION' => '?', |
|
95 | + 'DTSTART' => '?', |
|
96 | + 'LAST-MODIFIED' => '?', |
|
97 | + 'ORGANIZER' => '?', |
|
98 | + 'PRIORITY' => '?', |
|
99 | + 'SEQUENCE' => '?', |
|
100 | + 'SUMMARY' => '?', |
|
101 | + 'URL' => '?', |
|
102 | + 'DTEND' => '?', |
|
103 | + 'DURATION' => '?', |
|
104 | 104 | |
105 | - 'CATEGORIES' => '*', |
|
106 | - 'COMMENT' => '*', |
|
107 | - 'CONTACT' => '*', |
|
108 | - ]; |
|
109 | - } |
|
105 | + 'CATEGORIES' => '*', |
|
106 | + 'COMMENT' => '*', |
|
107 | + 'CONTACT' => '*', |
|
108 | + ]; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Validates the node for correctness. |
|
113 | - * |
|
114 | - * The following options are supported: |
|
115 | - * Node::REPAIR - May attempt to automatically repair the problem. |
|
116 | - * Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes. |
|
117 | - * Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes. |
|
118 | - * |
|
119 | - * This method returns an array with detected problems. |
|
120 | - * Every element has the following properties: |
|
121 | - * |
|
122 | - * * level - problem level. |
|
123 | - * * message - A human-readable string describing the issue. |
|
124 | - * * node - A reference to the problematic node. |
|
125 | - * |
|
126 | - * The level means: |
|
127 | - * 1 - The issue was repaired (only happens if REPAIR was turned on). |
|
128 | - * 2 - A warning. |
|
129 | - * 3 - An error. |
|
130 | - * |
|
131 | - * @param int $options |
|
132 | - * |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - public function validate($options = 0) |
|
136 | - { |
|
137 | - $result = parent::validate($options); |
|
111 | + /** |
|
112 | + * Validates the node for correctness. |
|
113 | + * |
|
114 | + * The following options are supported: |
|
115 | + * Node::REPAIR - May attempt to automatically repair the problem. |
|
116 | + * Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes. |
|
117 | + * Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes. |
|
118 | + * |
|
119 | + * This method returns an array with detected problems. |
|
120 | + * Every element has the following properties: |
|
121 | + * |
|
122 | + * * level - problem level. |
|
123 | + * * message - A human-readable string describing the issue. |
|
124 | + * * node - A reference to the problematic node. |
|
125 | + * |
|
126 | + * The level means: |
|
127 | + * 1 - The issue was repaired (only happens if REPAIR was turned on). |
|
128 | + * 2 - A warning. |
|
129 | + * 3 - An error. |
|
130 | + * |
|
131 | + * @param int $options |
|
132 | + * |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + public function validate($options = 0) |
|
136 | + { |
|
137 | + $result = parent::validate($options); |
|
138 | 138 | |
139 | - if (isset($this->DTEND) && isset($this->DURATION)) { |
|
140 | - $result[] = [ |
|
141 | - 'level' => 3, |
|
142 | - 'message' => 'DTEND and DURATION cannot both be present', |
|
143 | - 'node' => $this, |
|
144 | - ]; |
|
145 | - } |
|
139 | + if (isset($this->DTEND) && isset($this->DURATION)) { |
|
140 | + $result[] = [ |
|
141 | + 'level' => 3, |
|
142 | + 'message' => 'DTEND and DURATION cannot both be present', |
|
143 | + 'node' => $this, |
|
144 | + ]; |
|
145 | + } |
|
146 | 146 | |
147 | - return $result; |
|
148 | - } |
|
147 | + return $result; |
|
148 | + } |
|
149 | 149 | } |
@@ -22,507 +22,507 @@ |
||
22 | 22 | */ |
23 | 23 | class VCalendar extends VObject\Document |
24 | 24 | { |
25 | - /** |
|
26 | - * The default name for this component. |
|
27 | - * |
|
28 | - * This should be 'VCALENDAR' or 'VCARD'. |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - public static $defaultName = 'VCALENDAR'; |
|
33 | - |
|
34 | - /** |
|
35 | - * This is a list of components, and which classes they should map to. |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - public static $componentMap = [ |
|
40 | - 'VCALENDAR' => self::class, |
|
41 | - 'VALARM' => VAlarm::class, |
|
42 | - 'VEVENT' => VEvent::class, |
|
43 | - 'VFREEBUSY' => VFreeBusy::class, |
|
44 | - 'VAVAILABILITY' => VAvailability::class, |
|
45 | - 'AVAILABLE' => Available::class, |
|
46 | - 'VJOURNAL' => VJournal::class, |
|
47 | - 'VTIMEZONE' => VTimeZone::class, |
|
48 | - 'VTODO' => VTodo::class, |
|
49 | - ]; |
|
50 | - |
|
51 | - /** |
|
52 | - * List of value-types, and which classes they map to. |
|
53 | - * |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - public static $valueMap = [ |
|
57 | - 'BINARY' => VObject\Property\Binary::class, |
|
58 | - 'BOOLEAN' => VObject\Property\Boolean::class, |
|
59 | - 'CAL-ADDRESS' => VObject\Property\ICalendar\CalAddress::class, |
|
60 | - 'DATE' => VObject\Property\ICalendar\Date::class, |
|
61 | - 'DATE-TIME' => VObject\Property\ICalendar\DateTime::class, |
|
62 | - 'DURATION' => VObject\Property\ICalendar\Duration::class, |
|
63 | - 'FLOAT' => VObject\Property\FloatValue::class, |
|
64 | - 'INTEGER' => VObject\Property\IntegerValue::class, |
|
65 | - 'PERIOD' => VObject\Property\ICalendar\Period::class, |
|
66 | - 'RECUR' => VObject\Property\ICalendar\Recur::class, |
|
67 | - 'TEXT' => VObject\Property\Text::class, |
|
68 | - 'TIME' => VObject\Property\Time::class, |
|
69 | - 'UNKNOWN' => VObject\Property\Unknown::class, // jCard / jCal-only. |
|
70 | - 'URI' => VObject\Property\Uri::class, |
|
71 | - 'UTC-OFFSET' => VObject\Property\UtcOffset::class, |
|
72 | - ]; |
|
73 | - |
|
74 | - /** |
|
75 | - * List of properties, and which classes they map to. |
|
76 | - * |
|
77 | - * @var array |
|
78 | - */ |
|
79 | - public static $propertyMap = [ |
|
80 | - // Calendar properties |
|
81 | - 'CALSCALE' => VObject\Property\FlatText::class, |
|
82 | - 'METHOD' => VObject\Property\FlatText::class, |
|
83 | - 'PRODID' => VObject\Property\FlatText::class, |
|
84 | - 'VERSION' => VObject\Property\FlatText::class, |
|
85 | - |
|
86 | - // Component properties |
|
87 | - 'ATTACH' => VObject\Property\Uri::class, |
|
88 | - 'CATEGORIES' => VObject\Property\Text::class, |
|
89 | - 'CLASS' => VObject\Property\FlatText::class, |
|
90 | - 'COMMENT' => VObject\Property\FlatText::class, |
|
91 | - 'DESCRIPTION' => VObject\Property\FlatText::class, |
|
92 | - 'GEO' => VObject\Property\FloatValue::class, |
|
93 | - 'LOCATION' => VObject\Property\FlatText::class, |
|
94 | - 'PERCENT-COMPLETE' => VObject\Property\IntegerValue::class, |
|
95 | - 'PRIORITY' => VObject\Property\IntegerValue::class, |
|
96 | - 'RESOURCES' => VObject\Property\Text::class, |
|
97 | - 'STATUS' => VObject\Property\FlatText::class, |
|
98 | - 'SUMMARY' => VObject\Property\FlatText::class, |
|
99 | - |
|
100 | - // Date and Time Component Properties |
|
101 | - 'COMPLETED' => VObject\Property\ICalendar\DateTime::class, |
|
102 | - 'DTEND' => VObject\Property\ICalendar\DateTime::class, |
|
103 | - 'DUE' => VObject\Property\ICalendar\DateTime::class, |
|
104 | - 'DTSTART' => VObject\Property\ICalendar\DateTime::class, |
|
105 | - 'DURATION' => VObject\Property\ICalendar\Duration::class, |
|
106 | - 'FREEBUSY' => VObject\Property\ICalendar\Period::class, |
|
107 | - 'TRANSP' => VObject\Property\FlatText::class, |
|
108 | - |
|
109 | - // Time Zone Component Properties |
|
110 | - 'TZID' => VObject\Property\FlatText::class, |
|
111 | - 'TZNAME' => VObject\Property\FlatText::class, |
|
112 | - 'TZOFFSETFROM' => VObject\Property\UtcOffset::class, |
|
113 | - 'TZOFFSETTO' => VObject\Property\UtcOffset::class, |
|
114 | - 'TZURL' => VObject\Property\Uri::class, |
|
115 | - |
|
116 | - // Relationship Component Properties |
|
117 | - 'ATTENDEE' => VObject\Property\ICalendar\CalAddress::class, |
|
118 | - 'CONTACT' => VObject\Property\FlatText::class, |
|
119 | - 'ORGANIZER' => VObject\Property\ICalendar\CalAddress::class, |
|
120 | - 'RECURRENCE-ID' => VObject\Property\ICalendar\DateTime::class, |
|
121 | - 'RELATED-TO' => VObject\Property\FlatText::class, |
|
122 | - 'URL' => VObject\Property\Uri::class, |
|
123 | - 'UID' => VObject\Property\FlatText::class, |
|
124 | - |
|
125 | - // Recurrence Component Properties |
|
126 | - 'EXDATE' => VObject\Property\ICalendar\DateTime::class, |
|
127 | - 'RDATE' => VObject\Property\ICalendar\DateTime::class, |
|
128 | - 'RRULE' => VObject\Property\ICalendar\Recur::class, |
|
129 | - 'EXRULE' => VObject\Property\ICalendar\Recur::class, // Deprecated since rfc5545 |
|
130 | - |
|
131 | - // Alarm Component Properties |
|
132 | - 'ACTION' => VObject\Property\FlatText::class, |
|
133 | - 'REPEAT' => VObject\Property\IntegerValue::class, |
|
134 | - 'TRIGGER' => VObject\Property\ICalendar\Duration::class, |
|
135 | - |
|
136 | - // Change Management Component Properties |
|
137 | - 'CREATED' => VObject\Property\ICalendar\DateTime::class, |
|
138 | - 'DTSTAMP' => VObject\Property\ICalendar\DateTime::class, |
|
139 | - 'LAST-MODIFIED' => VObject\Property\ICalendar\DateTime::class, |
|
140 | - 'SEQUENCE' => VObject\Property\IntegerValue::class, |
|
141 | - |
|
142 | - // Request Status |
|
143 | - 'REQUEST-STATUS' => VObject\Property\Text::class, |
|
144 | - |
|
145 | - // Additions from draft-daboo-valarm-extensions-04 |
|
146 | - 'ALARM-AGENT' => VObject\Property\Text::class, |
|
147 | - 'ACKNOWLEDGED' => VObject\Property\ICalendar\DateTime::class, |
|
148 | - 'PROXIMITY' => VObject\Property\Text::class, |
|
149 | - 'DEFAULT-ALARM' => VObject\Property\Boolean::class, |
|
150 | - |
|
151 | - // Additions from draft-daboo-calendar-availability-05 |
|
152 | - 'BUSYTYPE' => VObject\Property\Text::class, |
|
153 | - ]; |
|
154 | - |
|
155 | - /** |
|
156 | - * Returns the current document type. |
|
157 | - * |
|
158 | - * @return int |
|
159 | - */ |
|
160 | - public function getDocumentType() |
|
161 | - { |
|
162 | - return self::ICALENDAR20; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Returns a list of all 'base components'. For instance, if an Event has |
|
167 | - * a recurrence rule, and one instance is overridden, the overridden event |
|
168 | - * will have the same UID, but will be excluded from this list. |
|
169 | - * |
|
170 | - * VTIMEZONE components will always be excluded. |
|
171 | - * |
|
172 | - * @param string $componentName filter by component name |
|
173 | - * |
|
174 | - * @return VObject\Component[] |
|
175 | - */ |
|
176 | - public function getBaseComponents($componentName = null) |
|
177 | - { |
|
178 | - $isBaseComponent = function ($component) { |
|
179 | - if (!$component instanceof VObject\Component) { |
|
180 | - return false; |
|
181 | - } |
|
182 | - if ('VTIMEZONE' === $component->name) { |
|
183 | - return false; |
|
184 | - } |
|
185 | - if (isset($component->{'RECURRENCE-ID'})) { |
|
186 | - return false; |
|
187 | - } |
|
188 | - |
|
189 | - return true; |
|
190 | - }; |
|
191 | - |
|
192 | - if ($componentName) { |
|
193 | - // Early exit |
|
194 | - return array_filter( |
|
195 | - $this->select($componentName), |
|
196 | - $isBaseComponent |
|
197 | - ); |
|
198 | - } |
|
199 | - |
|
200 | - $components = []; |
|
201 | - foreach ($this->children as $childGroup) { |
|
202 | - foreach ($childGroup as $child) { |
|
203 | - if (!$child instanceof Component) { |
|
204 | - // If one child is not a component, they all are so we skip |
|
205 | - // the entire group. |
|
206 | - continue 2; |
|
207 | - } |
|
208 | - if ($isBaseComponent($child)) { |
|
209 | - $components[] = $child; |
|
210 | - } |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - return $components; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Returns the first component that is not a VTIMEZONE, and does not have |
|
219 | - * an RECURRENCE-ID. |
|
220 | - * |
|
221 | - * If there is no such component, null will be returned. |
|
222 | - * |
|
223 | - * @param string $componentName filter by component name |
|
224 | - * |
|
225 | - * @return VObject\Component|null |
|
226 | - */ |
|
227 | - public function getBaseComponent($componentName = null) |
|
228 | - { |
|
229 | - $isBaseComponent = function ($component) { |
|
230 | - if (!$component instanceof VObject\Component) { |
|
231 | - return false; |
|
232 | - } |
|
233 | - if ('VTIMEZONE' === $component->name) { |
|
234 | - return false; |
|
235 | - } |
|
236 | - if (isset($component->{'RECURRENCE-ID'})) { |
|
237 | - return false; |
|
238 | - } |
|
239 | - |
|
240 | - return true; |
|
241 | - }; |
|
242 | - |
|
243 | - if ($componentName) { |
|
244 | - foreach ($this->select($componentName) as $child) { |
|
245 | - if ($isBaseComponent($child)) { |
|
246 | - return $child; |
|
247 | - } |
|
248 | - } |
|
249 | - |
|
250 | - return null; |
|
251 | - } |
|
252 | - |
|
253 | - // Searching all components |
|
254 | - foreach ($this->children as $childGroup) { |
|
255 | - foreach ($childGroup as $child) { |
|
256 | - if ($isBaseComponent($child)) { |
|
257 | - return $child; |
|
258 | - } |
|
259 | - } |
|
260 | - } |
|
261 | - |
|
262 | - return null; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Expand all events in this VCalendar object and return a new VCalendar |
|
267 | - * with the expanded events. |
|
268 | - * |
|
269 | - * If this calendar object, has events with recurrence rules, this method |
|
270 | - * can be used to expand the event into multiple sub-events. |
|
271 | - * |
|
272 | - * Each event will be stripped from its recurrence information, and only |
|
273 | - * the instances of the event in the specified timerange will be left |
|
274 | - * alone. |
|
275 | - * |
|
276 | - * In addition, this method will cause timezone information to be stripped, |
|
277 | - * and normalized to UTC. |
|
278 | - * |
|
279 | - * @param DateTimeZone $timeZone reference timezone for floating dates and |
|
280 | - * times |
|
281 | - * |
|
282 | - * @return VCalendar |
|
283 | - */ |
|
284 | - public function expand(DateTimeInterface $start, DateTimeInterface $end, DateTimeZone $timeZone = null) |
|
285 | - { |
|
286 | - $newChildren = []; |
|
287 | - $recurringEvents = []; |
|
288 | - |
|
289 | - if (!$timeZone) { |
|
290 | - $timeZone = new DateTimeZone('UTC'); |
|
291 | - } |
|
292 | - |
|
293 | - $stripTimezones = function (Component $component) use ($timeZone, &$stripTimezones) { |
|
294 | - foreach ($component->children() as $componentChild) { |
|
295 | - if ($componentChild instanceof Property\ICalendar\DateTime && $componentChild->hasTime()) { |
|
296 | - $dt = $componentChild->getDateTimes($timeZone); |
|
297 | - // We only need to update the first timezone, because |
|
298 | - // setDateTimes will match all other timezones to the |
|
299 | - // first. |
|
300 | - $dt[0] = $dt[0]->setTimeZone(new DateTimeZone('UTC')); |
|
301 | - $componentChild->setDateTimes($dt); |
|
302 | - } elseif ($componentChild instanceof Component) { |
|
303 | - $stripTimezones($componentChild); |
|
304 | - } |
|
305 | - } |
|
306 | - |
|
307 | - return $component; |
|
308 | - }; |
|
309 | - |
|
310 | - foreach ($this->children() as $child) { |
|
311 | - if ($child instanceof Property && 'PRODID' !== $child->name) { |
|
312 | - // We explicitly want to ignore PRODID, because we want to |
|
313 | - // overwrite it with our own. |
|
314 | - $newChildren[] = clone $child; |
|
315 | - } elseif ($child instanceof Component && 'VTIMEZONE' !== $child->name) { |
|
316 | - // We're also stripping all VTIMEZONE objects because we're |
|
317 | - // converting everything to UTC. |
|
318 | - if ('VEVENT' === $child->name && (isset($child->{'RECURRENCE-ID'}) || isset($child->RRULE) || isset($child->RDATE))) { |
|
319 | - // Handle these a bit later. |
|
320 | - $uid = (string) $child->UID; |
|
321 | - if (!$uid) { |
|
322 | - throw new InvalidDataException('Every VEVENT object must have a UID property'); |
|
323 | - } |
|
324 | - if (isset($recurringEvents[$uid])) { |
|
325 | - $recurringEvents[$uid][] = clone $child; |
|
326 | - } else { |
|
327 | - $recurringEvents[$uid] = [clone $child]; |
|
328 | - } |
|
329 | - } elseif ('VEVENT' === $child->name && $child->isInTimeRange($start, $end)) { |
|
330 | - $newChildren[] = $stripTimezones(clone $child); |
|
331 | - } |
|
332 | - } |
|
333 | - } |
|
334 | - |
|
335 | - foreach ($recurringEvents as $events) { |
|
336 | - try { |
|
337 | - $it = new EventIterator($events, null, $timeZone); |
|
338 | - } catch (NoInstancesException $e) { |
|
339 | - // This event is recurring, but it doesn't have a single |
|
340 | - // instance. We are skipping this event from the output |
|
341 | - // entirely. |
|
342 | - continue; |
|
343 | - } |
|
344 | - $it->fastForward($start); |
|
345 | - |
|
346 | - while ($it->valid() && $it->getDTStart() < $end) { |
|
347 | - if ($it->getDTEnd() > $start) { |
|
348 | - $newChildren[] = $stripTimezones($it->getEventObject()); |
|
349 | - } |
|
350 | - $it->next(); |
|
351 | - } |
|
352 | - } |
|
353 | - |
|
354 | - return new self($newChildren); |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * This method should return a list of default property values. |
|
359 | - * |
|
360 | - * @return array |
|
361 | - */ |
|
362 | - protected function getDefaults() |
|
363 | - { |
|
364 | - return [ |
|
365 | - 'VERSION' => '2.0', |
|
366 | - 'PRODID' => '-//Sabre//Sabre VObject '.VObject\Version::VERSION.'//EN', |
|
367 | - 'CALSCALE' => 'GREGORIAN', |
|
368 | - ]; |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * A simple list of validation rules. |
|
373 | - * |
|
374 | - * This is simply a list of properties, and how many times they either |
|
375 | - * must or must not appear. |
|
376 | - * |
|
377 | - * Possible values per property: |
|
378 | - * * 0 - Must not appear. |
|
379 | - * * 1 - Must appear exactly once. |
|
380 | - * * + - Must appear at least once. |
|
381 | - * * * - Can appear any number of times. |
|
382 | - * * ? - May appear, but not more than once. |
|
383 | - * |
|
384 | - * @var array |
|
385 | - */ |
|
386 | - public function getValidationRules() |
|
387 | - { |
|
388 | - return [ |
|
389 | - 'PRODID' => 1, |
|
390 | - 'VERSION' => 1, |
|
391 | - |
|
392 | - 'CALSCALE' => '?', |
|
393 | - 'METHOD' => '?', |
|
394 | - ]; |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * Validates the node for correctness. |
|
399 | - * |
|
400 | - * The following options are supported: |
|
401 | - * Node::REPAIR - May attempt to automatically repair the problem. |
|
402 | - * Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes. |
|
403 | - * Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes. |
|
404 | - * |
|
405 | - * This method returns an array with detected problems. |
|
406 | - * Every element has the following properties: |
|
407 | - * |
|
408 | - * * level - problem level. |
|
409 | - * * message - A human-readable string describing the issue. |
|
410 | - * * node - A reference to the problematic node. |
|
411 | - * |
|
412 | - * The level means: |
|
413 | - * 1 - The issue was repaired (only happens if REPAIR was turned on). |
|
414 | - * 2 - A warning. |
|
415 | - * 3 - An error. |
|
416 | - * |
|
417 | - * @param int $options |
|
418 | - * |
|
419 | - * @return array |
|
420 | - */ |
|
421 | - public function validate($options = 0) |
|
422 | - { |
|
423 | - $warnings = parent::validate($options); |
|
424 | - |
|
425 | - if ($ver = $this->VERSION) { |
|
426 | - if ('2.0' !== (string) $ver) { |
|
427 | - $warnings[] = [ |
|
428 | - 'level' => 3, |
|
429 | - 'message' => 'Only iCalendar version 2.0 as defined in rfc5545 is supported.', |
|
430 | - 'node' => $this, |
|
431 | - ]; |
|
432 | - } |
|
433 | - } |
|
434 | - |
|
435 | - $uidList = []; |
|
436 | - $componentsFound = 0; |
|
437 | - $componentTypes = []; |
|
438 | - |
|
439 | - foreach ($this->children() as $child) { |
|
440 | - if ($child instanceof Component) { |
|
441 | - ++$componentsFound; |
|
442 | - |
|
443 | - if (!in_array($child->name, ['VEVENT', 'VTODO', 'VJOURNAL'])) { |
|
444 | - continue; |
|
445 | - } |
|
446 | - $componentTypes[] = $child->name; |
|
447 | - |
|
448 | - $uid = (string) $child->UID; |
|
449 | - $isMaster = isset($child->{'RECURRENCE-ID'}) ? 0 : 1; |
|
450 | - if (isset($uidList[$uid])) { |
|
451 | - ++$uidList[$uid]['count']; |
|
452 | - if ($isMaster && $uidList[$uid]['hasMaster']) { |
|
453 | - $warnings[] = [ |
|
454 | - 'level' => 3, |
|
455 | - 'message' => 'More than one master object was found for the object with UID '.$uid, |
|
456 | - 'node' => $this, |
|
457 | - ]; |
|
458 | - } |
|
459 | - $uidList[$uid]['hasMaster'] += $isMaster; |
|
460 | - } else { |
|
461 | - $uidList[$uid] = [ |
|
462 | - 'count' => 1, |
|
463 | - 'hasMaster' => $isMaster, |
|
464 | - ]; |
|
465 | - } |
|
466 | - } |
|
467 | - } |
|
468 | - |
|
469 | - if (0 === $componentsFound) { |
|
470 | - $warnings[] = [ |
|
471 | - 'level' => 3, |
|
472 | - 'message' => 'An iCalendar object must have at least 1 component.', |
|
473 | - 'node' => $this, |
|
474 | - ]; |
|
475 | - } |
|
476 | - |
|
477 | - if ($options & self::PROFILE_CALDAV) { |
|
478 | - if (count($uidList) > 1) { |
|
479 | - $warnings[] = [ |
|
480 | - 'level' => 3, |
|
481 | - 'message' => 'A calendar object on a CalDAV server may only have components with the same UID.', |
|
482 | - 'node' => $this, |
|
483 | - ]; |
|
484 | - } |
|
485 | - if (0 === count($componentTypes)) { |
|
486 | - $warnings[] = [ |
|
487 | - 'level' => 3, |
|
488 | - 'message' => 'A calendar object on a CalDAV server must have at least 1 component (VTODO, VEVENT, VJOURNAL).', |
|
489 | - 'node' => $this, |
|
490 | - ]; |
|
491 | - } |
|
492 | - if (count(array_unique($componentTypes)) > 1) { |
|
493 | - $warnings[] = [ |
|
494 | - 'level' => 3, |
|
495 | - 'message' => 'A calendar object on a CalDAV server may only have 1 type of component (VEVENT, VTODO or VJOURNAL).', |
|
496 | - 'node' => $this, |
|
497 | - ]; |
|
498 | - } |
|
499 | - |
|
500 | - if (isset($this->METHOD)) { |
|
501 | - $warnings[] = [ |
|
502 | - 'level' => 3, |
|
503 | - 'message' => 'A calendar object on a CalDAV server MUST NOT have a METHOD property.', |
|
504 | - 'node' => $this, |
|
505 | - ]; |
|
506 | - } |
|
507 | - } |
|
508 | - |
|
509 | - return $warnings; |
|
510 | - } |
|
511 | - |
|
512 | - /** |
|
513 | - * Returns all components with a specific UID value. |
|
514 | - * |
|
515 | - * @return array |
|
516 | - */ |
|
517 | - public function getByUID($uid) |
|
518 | - { |
|
519 | - return array_filter($this->getComponents(), function ($item) use ($uid) { |
|
520 | - if (!$itemUid = $item->select('UID')) { |
|
521 | - return false; |
|
522 | - } |
|
523 | - $itemUid = current($itemUid)->getValue(); |
|
524 | - |
|
525 | - return $uid === $itemUid; |
|
526 | - }); |
|
527 | - } |
|
25 | + /** |
|
26 | + * The default name for this component. |
|
27 | + * |
|
28 | + * This should be 'VCALENDAR' or 'VCARD'. |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + public static $defaultName = 'VCALENDAR'; |
|
33 | + |
|
34 | + /** |
|
35 | + * This is a list of components, and which classes they should map to. |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + public static $componentMap = [ |
|
40 | + 'VCALENDAR' => self::class, |
|
41 | + 'VALARM' => VAlarm::class, |
|
42 | + 'VEVENT' => VEvent::class, |
|
43 | + 'VFREEBUSY' => VFreeBusy::class, |
|
44 | + 'VAVAILABILITY' => VAvailability::class, |
|
45 | + 'AVAILABLE' => Available::class, |
|
46 | + 'VJOURNAL' => VJournal::class, |
|
47 | + 'VTIMEZONE' => VTimeZone::class, |
|
48 | + 'VTODO' => VTodo::class, |
|
49 | + ]; |
|
50 | + |
|
51 | + /** |
|
52 | + * List of value-types, and which classes they map to. |
|
53 | + * |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + public static $valueMap = [ |
|
57 | + 'BINARY' => VObject\Property\Binary::class, |
|
58 | + 'BOOLEAN' => VObject\Property\Boolean::class, |
|
59 | + 'CAL-ADDRESS' => VObject\Property\ICalendar\CalAddress::class, |
|
60 | + 'DATE' => VObject\Property\ICalendar\Date::class, |
|
61 | + 'DATE-TIME' => VObject\Property\ICalendar\DateTime::class, |
|
62 | + 'DURATION' => VObject\Property\ICalendar\Duration::class, |
|
63 | + 'FLOAT' => VObject\Property\FloatValue::class, |
|
64 | + 'INTEGER' => VObject\Property\IntegerValue::class, |
|
65 | + 'PERIOD' => VObject\Property\ICalendar\Period::class, |
|
66 | + 'RECUR' => VObject\Property\ICalendar\Recur::class, |
|
67 | + 'TEXT' => VObject\Property\Text::class, |
|
68 | + 'TIME' => VObject\Property\Time::class, |
|
69 | + 'UNKNOWN' => VObject\Property\Unknown::class, // jCard / jCal-only. |
|
70 | + 'URI' => VObject\Property\Uri::class, |
|
71 | + 'UTC-OFFSET' => VObject\Property\UtcOffset::class, |
|
72 | + ]; |
|
73 | + |
|
74 | + /** |
|
75 | + * List of properties, and which classes they map to. |
|
76 | + * |
|
77 | + * @var array |
|
78 | + */ |
|
79 | + public static $propertyMap = [ |
|
80 | + // Calendar properties |
|
81 | + 'CALSCALE' => VObject\Property\FlatText::class, |
|
82 | + 'METHOD' => VObject\Property\FlatText::class, |
|
83 | + 'PRODID' => VObject\Property\FlatText::class, |
|
84 | + 'VERSION' => VObject\Property\FlatText::class, |
|
85 | + |
|
86 | + // Component properties |
|
87 | + 'ATTACH' => VObject\Property\Uri::class, |
|
88 | + 'CATEGORIES' => VObject\Property\Text::class, |
|
89 | + 'CLASS' => VObject\Property\FlatText::class, |
|
90 | + 'COMMENT' => VObject\Property\FlatText::class, |
|
91 | + 'DESCRIPTION' => VObject\Property\FlatText::class, |
|
92 | + 'GEO' => VObject\Property\FloatValue::class, |
|
93 | + 'LOCATION' => VObject\Property\FlatText::class, |
|
94 | + 'PERCENT-COMPLETE' => VObject\Property\IntegerValue::class, |
|
95 | + 'PRIORITY' => VObject\Property\IntegerValue::class, |
|
96 | + 'RESOURCES' => VObject\Property\Text::class, |
|
97 | + 'STATUS' => VObject\Property\FlatText::class, |
|
98 | + 'SUMMARY' => VObject\Property\FlatText::class, |
|
99 | + |
|
100 | + // Date and Time Component Properties |
|
101 | + 'COMPLETED' => VObject\Property\ICalendar\DateTime::class, |
|
102 | + 'DTEND' => VObject\Property\ICalendar\DateTime::class, |
|
103 | + 'DUE' => VObject\Property\ICalendar\DateTime::class, |
|
104 | + 'DTSTART' => VObject\Property\ICalendar\DateTime::class, |
|
105 | + 'DURATION' => VObject\Property\ICalendar\Duration::class, |
|
106 | + 'FREEBUSY' => VObject\Property\ICalendar\Period::class, |
|
107 | + 'TRANSP' => VObject\Property\FlatText::class, |
|
108 | + |
|
109 | + // Time Zone Component Properties |
|
110 | + 'TZID' => VObject\Property\FlatText::class, |
|
111 | + 'TZNAME' => VObject\Property\FlatText::class, |
|
112 | + 'TZOFFSETFROM' => VObject\Property\UtcOffset::class, |
|
113 | + 'TZOFFSETTO' => VObject\Property\UtcOffset::class, |
|
114 | + 'TZURL' => VObject\Property\Uri::class, |
|
115 | + |
|
116 | + // Relationship Component Properties |
|
117 | + 'ATTENDEE' => VObject\Property\ICalendar\CalAddress::class, |
|
118 | + 'CONTACT' => VObject\Property\FlatText::class, |
|
119 | + 'ORGANIZER' => VObject\Property\ICalendar\CalAddress::class, |
|
120 | + 'RECURRENCE-ID' => VObject\Property\ICalendar\DateTime::class, |
|
121 | + 'RELATED-TO' => VObject\Property\FlatText::class, |
|
122 | + 'URL' => VObject\Property\Uri::class, |
|
123 | + 'UID' => VObject\Property\FlatText::class, |
|
124 | + |
|
125 | + // Recurrence Component Properties |
|
126 | + 'EXDATE' => VObject\Property\ICalendar\DateTime::class, |
|
127 | + 'RDATE' => VObject\Property\ICalendar\DateTime::class, |
|
128 | + 'RRULE' => VObject\Property\ICalendar\Recur::class, |
|
129 | + 'EXRULE' => VObject\Property\ICalendar\Recur::class, // Deprecated since rfc5545 |
|
130 | + |
|
131 | + // Alarm Component Properties |
|
132 | + 'ACTION' => VObject\Property\FlatText::class, |
|
133 | + 'REPEAT' => VObject\Property\IntegerValue::class, |
|
134 | + 'TRIGGER' => VObject\Property\ICalendar\Duration::class, |
|
135 | + |
|
136 | + // Change Management Component Properties |
|
137 | + 'CREATED' => VObject\Property\ICalendar\DateTime::class, |
|
138 | + 'DTSTAMP' => VObject\Property\ICalendar\DateTime::class, |
|
139 | + 'LAST-MODIFIED' => VObject\Property\ICalendar\DateTime::class, |
|
140 | + 'SEQUENCE' => VObject\Property\IntegerValue::class, |
|
141 | + |
|
142 | + // Request Status |
|
143 | + 'REQUEST-STATUS' => VObject\Property\Text::class, |
|
144 | + |
|
145 | + // Additions from draft-daboo-valarm-extensions-04 |
|
146 | + 'ALARM-AGENT' => VObject\Property\Text::class, |
|
147 | + 'ACKNOWLEDGED' => VObject\Property\ICalendar\DateTime::class, |
|
148 | + 'PROXIMITY' => VObject\Property\Text::class, |
|
149 | + 'DEFAULT-ALARM' => VObject\Property\Boolean::class, |
|
150 | + |
|
151 | + // Additions from draft-daboo-calendar-availability-05 |
|
152 | + 'BUSYTYPE' => VObject\Property\Text::class, |
|
153 | + ]; |
|
154 | + |
|
155 | + /** |
|
156 | + * Returns the current document type. |
|
157 | + * |
|
158 | + * @return int |
|
159 | + */ |
|
160 | + public function getDocumentType() |
|
161 | + { |
|
162 | + return self::ICALENDAR20; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Returns a list of all 'base components'. For instance, if an Event has |
|
167 | + * a recurrence rule, and one instance is overridden, the overridden event |
|
168 | + * will have the same UID, but will be excluded from this list. |
|
169 | + * |
|
170 | + * VTIMEZONE components will always be excluded. |
|
171 | + * |
|
172 | + * @param string $componentName filter by component name |
|
173 | + * |
|
174 | + * @return VObject\Component[] |
|
175 | + */ |
|
176 | + public function getBaseComponents($componentName = null) |
|
177 | + { |
|
178 | + $isBaseComponent = function ($component) { |
|
179 | + if (!$component instanceof VObject\Component) { |
|
180 | + return false; |
|
181 | + } |
|
182 | + if ('VTIMEZONE' === $component->name) { |
|
183 | + return false; |
|
184 | + } |
|
185 | + if (isset($component->{'RECURRENCE-ID'})) { |
|
186 | + return false; |
|
187 | + } |
|
188 | + |
|
189 | + return true; |
|
190 | + }; |
|
191 | + |
|
192 | + if ($componentName) { |
|
193 | + // Early exit |
|
194 | + return array_filter( |
|
195 | + $this->select($componentName), |
|
196 | + $isBaseComponent |
|
197 | + ); |
|
198 | + } |
|
199 | + |
|
200 | + $components = []; |
|
201 | + foreach ($this->children as $childGroup) { |
|
202 | + foreach ($childGroup as $child) { |
|
203 | + if (!$child instanceof Component) { |
|
204 | + // If one child is not a component, they all are so we skip |
|
205 | + // the entire group. |
|
206 | + continue 2; |
|
207 | + } |
|
208 | + if ($isBaseComponent($child)) { |
|
209 | + $components[] = $child; |
|
210 | + } |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + return $components; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Returns the first component that is not a VTIMEZONE, and does not have |
|
219 | + * an RECURRENCE-ID. |
|
220 | + * |
|
221 | + * If there is no such component, null will be returned. |
|
222 | + * |
|
223 | + * @param string $componentName filter by component name |
|
224 | + * |
|
225 | + * @return VObject\Component|null |
|
226 | + */ |
|
227 | + public function getBaseComponent($componentName = null) |
|
228 | + { |
|
229 | + $isBaseComponent = function ($component) { |
|
230 | + if (!$component instanceof VObject\Component) { |
|
231 | + return false; |
|
232 | + } |
|
233 | + if ('VTIMEZONE' === $component->name) { |
|
234 | + return false; |
|
235 | + } |
|
236 | + if (isset($component->{'RECURRENCE-ID'})) { |
|
237 | + return false; |
|
238 | + } |
|
239 | + |
|
240 | + return true; |
|
241 | + }; |
|
242 | + |
|
243 | + if ($componentName) { |
|
244 | + foreach ($this->select($componentName) as $child) { |
|
245 | + if ($isBaseComponent($child)) { |
|
246 | + return $child; |
|
247 | + } |
|
248 | + } |
|
249 | + |
|
250 | + return null; |
|
251 | + } |
|
252 | + |
|
253 | + // Searching all components |
|
254 | + foreach ($this->children as $childGroup) { |
|
255 | + foreach ($childGroup as $child) { |
|
256 | + if ($isBaseComponent($child)) { |
|
257 | + return $child; |
|
258 | + } |
|
259 | + } |
|
260 | + } |
|
261 | + |
|
262 | + return null; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Expand all events in this VCalendar object and return a new VCalendar |
|
267 | + * with the expanded events. |
|
268 | + * |
|
269 | + * If this calendar object, has events with recurrence rules, this method |
|
270 | + * can be used to expand the event into multiple sub-events. |
|
271 | + * |
|
272 | + * Each event will be stripped from its recurrence information, and only |
|
273 | + * the instances of the event in the specified timerange will be left |
|
274 | + * alone. |
|
275 | + * |
|
276 | + * In addition, this method will cause timezone information to be stripped, |
|
277 | + * and normalized to UTC. |
|
278 | + * |
|
279 | + * @param DateTimeZone $timeZone reference timezone for floating dates and |
|
280 | + * times |
|
281 | + * |
|
282 | + * @return VCalendar |
|
283 | + */ |
|
284 | + public function expand(DateTimeInterface $start, DateTimeInterface $end, DateTimeZone $timeZone = null) |
|
285 | + { |
|
286 | + $newChildren = []; |
|
287 | + $recurringEvents = []; |
|
288 | + |
|
289 | + if (!$timeZone) { |
|
290 | + $timeZone = new DateTimeZone('UTC'); |
|
291 | + } |
|
292 | + |
|
293 | + $stripTimezones = function (Component $component) use ($timeZone, &$stripTimezones) { |
|
294 | + foreach ($component->children() as $componentChild) { |
|
295 | + if ($componentChild instanceof Property\ICalendar\DateTime && $componentChild->hasTime()) { |
|
296 | + $dt = $componentChild->getDateTimes($timeZone); |
|
297 | + // We only need to update the first timezone, because |
|
298 | + // setDateTimes will match all other timezones to the |
|
299 | + // first. |
|
300 | + $dt[0] = $dt[0]->setTimeZone(new DateTimeZone('UTC')); |
|
301 | + $componentChild->setDateTimes($dt); |
|
302 | + } elseif ($componentChild instanceof Component) { |
|
303 | + $stripTimezones($componentChild); |
|
304 | + } |
|
305 | + } |
|
306 | + |
|
307 | + return $component; |
|
308 | + }; |
|
309 | + |
|
310 | + foreach ($this->children() as $child) { |
|
311 | + if ($child instanceof Property && 'PRODID' !== $child->name) { |
|
312 | + // We explicitly want to ignore PRODID, because we want to |
|
313 | + // overwrite it with our own. |
|
314 | + $newChildren[] = clone $child; |
|
315 | + } elseif ($child instanceof Component && 'VTIMEZONE' !== $child->name) { |
|
316 | + // We're also stripping all VTIMEZONE objects because we're |
|
317 | + // converting everything to UTC. |
|
318 | + if ('VEVENT' === $child->name && (isset($child->{'RECURRENCE-ID'}) || isset($child->RRULE) || isset($child->RDATE))) { |
|
319 | + // Handle these a bit later. |
|
320 | + $uid = (string) $child->UID; |
|
321 | + if (!$uid) { |
|
322 | + throw new InvalidDataException('Every VEVENT object must have a UID property'); |
|
323 | + } |
|
324 | + if (isset($recurringEvents[$uid])) { |
|
325 | + $recurringEvents[$uid][] = clone $child; |
|
326 | + } else { |
|
327 | + $recurringEvents[$uid] = [clone $child]; |
|
328 | + } |
|
329 | + } elseif ('VEVENT' === $child->name && $child->isInTimeRange($start, $end)) { |
|
330 | + $newChildren[] = $stripTimezones(clone $child); |
|
331 | + } |
|
332 | + } |
|
333 | + } |
|
334 | + |
|
335 | + foreach ($recurringEvents as $events) { |
|
336 | + try { |
|
337 | + $it = new EventIterator($events, null, $timeZone); |
|
338 | + } catch (NoInstancesException $e) { |
|
339 | + // This event is recurring, but it doesn't have a single |
|
340 | + // instance. We are skipping this event from the output |
|
341 | + // entirely. |
|
342 | + continue; |
|
343 | + } |
|
344 | + $it->fastForward($start); |
|
345 | + |
|
346 | + while ($it->valid() && $it->getDTStart() < $end) { |
|
347 | + if ($it->getDTEnd() > $start) { |
|
348 | + $newChildren[] = $stripTimezones($it->getEventObject()); |
|
349 | + } |
|
350 | + $it->next(); |
|
351 | + } |
|
352 | + } |
|
353 | + |
|
354 | + return new self($newChildren); |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * This method should return a list of default property values. |
|
359 | + * |
|
360 | + * @return array |
|
361 | + */ |
|
362 | + protected function getDefaults() |
|
363 | + { |
|
364 | + return [ |
|
365 | + 'VERSION' => '2.0', |
|
366 | + 'PRODID' => '-//Sabre//Sabre VObject '.VObject\Version::VERSION.'//EN', |
|
367 | + 'CALSCALE' => 'GREGORIAN', |
|
368 | + ]; |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * A simple list of validation rules. |
|
373 | + * |
|
374 | + * This is simply a list of properties, and how many times they either |
|
375 | + * must or must not appear. |
|
376 | + * |
|
377 | + * Possible values per property: |
|
378 | + * * 0 - Must not appear. |
|
379 | + * * 1 - Must appear exactly once. |
|
380 | + * * + - Must appear at least once. |
|
381 | + * * * - Can appear any number of times. |
|
382 | + * * ? - May appear, but not more than once. |
|
383 | + * |
|
384 | + * @var array |
|
385 | + */ |
|
386 | + public function getValidationRules() |
|
387 | + { |
|
388 | + return [ |
|
389 | + 'PRODID' => 1, |
|
390 | + 'VERSION' => 1, |
|
391 | + |
|
392 | + 'CALSCALE' => '?', |
|
393 | + 'METHOD' => '?', |
|
394 | + ]; |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * Validates the node for correctness. |
|
399 | + * |
|
400 | + * The following options are supported: |
|
401 | + * Node::REPAIR - May attempt to automatically repair the problem. |
|
402 | + * Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes. |
|
403 | + * Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes. |
|
404 | + * |
|
405 | + * This method returns an array with detected problems. |
|
406 | + * Every element has the following properties: |
|
407 | + * |
|
408 | + * * level - problem level. |
|
409 | + * * message - A human-readable string describing the issue. |
|
410 | + * * node - A reference to the problematic node. |
|
411 | + * |
|
412 | + * The level means: |
|
413 | + * 1 - The issue was repaired (only happens if REPAIR was turned on). |
|
414 | + * 2 - A warning. |
|
415 | + * 3 - An error. |
|
416 | + * |
|
417 | + * @param int $options |
|
418 | + * |
|
419 | + * @return array |
|
420 | + */ |
|
421 | + public function validate($options = 0) |
|
422 | + { |
|
423 | + $warnings = parent::validate($options); |
|
424 | + |
|
425 | + if ($ver = $this->VERSION) { |
|
426 | + if ('2.0' !== (string) $ver) { |
|
427 | + $warnings[] = [ |
|
428 | + 'level' => 3, |
|
429 | + 'message' => 'Only iCalendar version 2.0 as defined in rfc5545 is supported.', |
|
430 | + 'node' => $this, |
|
431 | + ]; |
|
432 | + } |
|
433 | + } |
|
434 | + |
|
435 | + $uidList = []; |
|
436 | + $componentsFound = 0; |
|
437 | + $componentTypes = []; |
|
438 | + |
|
439 | + foreach ($this->children() as $child) { |
|
440 | + if ($child instanceof Component) { |
|
441 | + ++$componentsFound; |
|
442 | + |
|
443 | + if (!in_array($child->name, ['VEVENT', 'VTODO', 'VJOURNAL'])) { |
|
444 | + continue; |
|
445 | + } |
|
446 | + $componentTypes[] = $child->name; |
|
447 | + |
|
448 | + $uid = (string) $child->UID; |
|
449 | + $isMaster = isset($child->{'RECURRENCE-ID'}) ? 0 : 1; |
|
450 | + if (isset($uidList[$uid])) { |
|
451 | + ++$uidList[$uid]['count']; |
|
452 | + if ($isMaster && $uidList[$uid]['hasMaster']) { |
|
453 | + $warnings[] = [ |
|
454 | + 'level' => 3, |
|
455 | + 'message' => 'More than one master object was found for the object with UID '.$uid, |
|
456 | + 'node' => $this, |
|
457 | + ]; |
|
458 | + } |
|
459 | + $uidList[$uid]['hasMaster'] += $isMaster; |
|
460 | + } else { |
|
461 | + $uidList[$uid] = [ |
|
462 | + 'count' => 1, |
|
463 | + 'hasMaster' => $isMaster, |
|
464 | + ]; |
|
465 | + } |
|
466 | + } |
|
467 | + } |
|
468 | + |
|
469 | + if (0 === $componentsFound) { |
|
470 | + $warnings[] = [ |
|
471 | + 'level' => 3, |
|
472 | + 'message' => 'An iCalendar object must have at least 1 component.', |
|
473 | + 'node' => $this, |
|
474 | + ]; |
|
475 | + } |
|
476 | + |
|
477 | + if ($options & self::PROFILE_CALDAV) { |
|
478 | + if (count($uidList) > 1) { |
|
479 | + $warnings[] = [ |
|
480 | + 'level' => 3, |
|
481 | + 'message' => 'A calendar object on a CalDAV server may only have components with the same UID.', |
|
482 | + 'node' => $this, |
|
483 | + ]; |
|
484 | + } |
|
485 | + if (0 === count($componentTypes)) { |
|
486 | + $warnings[] = [ |
|
487 | + 'level' => 3, |
|
488 | + 'message' => 'A calendar object on a CalDAV server must have at least 1 component (VTODO, VEVENT, VJOURNAL).', |
|
489 | + 'node' => $this, |
|
490 | + ]; |
|
491 | + } |
|
492 | + if (count(array_unique($componentTypes)) > 1) { |
|
493 | + $warnings[] = [ |
|
494 | + 'level' => 3, |
|
495 | + 'message' => 'A calendar object on a CalDAV server may only have 1 type of component (VEVENT, VTODO or VJOURNAL).', |
|
496 | + 'node' => $this, |
|
497 | + ]; |
|
498 | + } |
|
499 | + |
|
500 | + if (isset($this->METHOD)) { |
|
501 | + $warnings[] = [ |
|
502 | + 'level' => 3, |
|
503 | + 'message' => 'A calendar object on a CalDAV server MUST NOT have a METHOD property.', |
|
504 | + 'node' => $this, |
|
505 | + ]; |
|
506 | + } |
|
507 | + } |
|
508 | + |
|
509 | + return $warnings; |
|
510 | + } |
|
511 | + |
|
512 | + /** |
|
513 | + * Returns all components with a specific UID value. |
|
514 | + * |
|
515 | + * @return array |
|
516 | + */ |
|
517 | + public function getByUID($uid) |
|
518 | + { |
|
519 | + return array_filter($this->getComponents(), function ($item) use ($uid) { |
|
520 | + if (!$itemUid = $item->select('UID')) { |
|
521 | + return false; |
|
522 | + } |
|
523 | + $itemUid = current($itemUid)->getValue(); |
|
524 | + |
|
525 | + return $uid === $itemUid; |
|
526 | + }); |
|
527 | + } |
|
528 | 528 | } |
@@ -18,121 +18,121 @@ |
||
18 | 18 | */ |
19 | 19 | class VAlarm extends VObject\Component |
20 | 20 | { |
21 | - /** |
|
22 | - * Returns a DateTime object when this alarm is going to trigger. |
|
23 | - * |
|
24 | - * This ignores repeated alarm, only the first trigger is returned. |
|
25 | - * |
|
26 | - * @return DateTimeImmutable |
|
27 | - */ |
|
28 | - public function getEffectiveTriggerTime() |
|
29 | - { |
|
30 | - $trigger = $this->TRIGGER; |
|
31 | - if (!isset($trigger['VALUE']) || 'DURATION' === strtoupper($trigger['VALUE'])) { |
|
32 | - $triggerDuration = VObject\DateTimeParser::parseDuration($this->TRIGGER); |
|
33 | - $related = (isset($trigger['RELATED']) && 'END' == strtoupper($trigger['RELATED'])) ? 'END' : 'START'; |
|
21 | + /** |
|
22 | + * Returns a DateTime object when this alarm is going to trigger. |
|
23 | + * |
|
24 | + * This ignores repeated alarm, only the first trigger is returned. |
|
25 | + * |
|
26 | + * @return DateTimeImmutable |
|
27 | + */ |
|
28 | + public function getEffectiveTriggerTime() |
|
29 | + { |
|
30 | + $trigger = $this->TRIGGER; |
|
31 | + if (!isset($trigger['VALUE']) || 'DURATION' === strtoupper($trigger['VALUE'])) { |
|
32 | + $triggerDuration = VObject\DateTimeParser::parseDuration($this->TRIGGER); |
|
33 | + $related = (isset($trigger['RELATED']) && 'END' == strtoupper($trigger['RELATED'])) ? 'END' : 'START'; |
|
34 | 34 | |
35 | - $parentComponent = $this->parent; |
|
36 | - if ('START' === $related) { |
|
37 | - if ('VTODO' === $parentComponent->name) { |
|
38 | - $propName = 'DUE'; |
|
39 | - } else { |
|
40 | - $propName = 'DTSTART'; |
|
41 | - } |
|
35 | + $parentComponent = $this->parent; |
|
36 | + if ('START' === $related) { |
|
37 | + if ('VTODO' === $parentComponent->name) { |
|
38 | + $propName = 'DUE'; |
|
39 | + } else { |
|
40 | + $propName = 'DTSTART'; |
|
41 | + } |
|
42 | 42 | |
43 | - $effectiveTrigger = $parentComponent->$propName->getDateTime(); |
|
44 | - $effectiveTrigger = $effectiveTrigger->add($triggerDuration); |
|
45 | - } else { |
|
46 | - if ('VTODO' === $parentComponent->name) { |
|
47 | - $endProp = 'DUE'; |
|
48 | - } elseif ('VEVENT' === $parentComponent->name) { |
|
49 | - $endProp = 'DTEND'; |
|
50 | - } else { |
|
51 | - throw new InvalidDataException('time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT'); |
|
52 | - } |
|
43 | + $effectiveTrigger = $parentComponent->$propName->getDateTime(); |
|
44 | + $effectiveTrigger = $effectiveTrigger->add($triggerDuration); |
|
45 | + } else { |
|
46 | + if ('VTODO' === $parentComponent->name) { |
|
47 | + $endProp = 'DUE'; |
|
48 | + } elseif ('VEVENT' === $parentComponent->name) { |
|
49 | + $endProp = 'DTEND'; |
|
50 | + } else { |
|
51 | + throw new InvalidDataException('time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT'); |
|
52 | + } |
|
53 | 53 | |
54 | - if (isset($parentComponent->$endProp)) { |
|
55 | - $effectiveTrigger = $parentComponent->$endProp->getDateTime(); |
|
56 | - $effectiveTrigger = $effectiveTrigger->add($triggerDuration); |
|
57 | - } elseif (isset($parentComponent->DURATION)) { |
|
58 | - $effectiveTrigger = $parentComponent->DTSTART->getDateTime(); |
|
59 | - $duration = VObject\DateTimeParser::parseDuration($parentComponent->DURATION); |
|
60 | - $effectiveTrigger = $effectiveTrigger->add($duration); |
|
61 | - $effectiveTrigger = $effectiveTrigger->add($triggerDuration); |
|
62 | - } else { |
|
63 | - $effectiveTrigger = $parentComponent->DTSTART->getDateTime(); |
|
64 | - $effectiveTrigger = $effectiveTrigger->add($triggerDuration); |
|
65 | - } |
|
66 | - } |
|
67 | - } else { |
|
68 | - $effectiveTrigger = $trigger->getDateTime(); |
|
69 | - } |
|
54 | + if (isset($parentComponent->$endProp)) { |
|
55 | + $effectiveTrigger = $parentComponent->$endProp->getDateTime(); |
|
56 | + $effectiveTrigger = $effectiveTrigger->add($triggerDuration); |
|
57 | + } elseif (isset($parentComponent->DURATION)) { |
|
58 | + $effectiveTrigger = $parentComponent->DTSTART->getDateTime(); |
|
59 | + $duration = VObject\DateTimeParser::parseDuration($parentComponent->DURATION); |
|
60 | + $effectiveTrigger = $effectiveTrigger->add($duration); |
|
61 | + $effectiveTrigger = $effectiveTrigger->add($triggerDuration); |
|
62 | + } else { |
|
63 | + $effectiveTrigger = $parentComponent->DTSTART->getDateTime(); |
|
64 | + $effectiveTrigger = $effectiveTrigger->add($triggerDuration); |
|
65 | + } |
|
66 | + } |
|
67 | + } else { |
|
68 | + $effectiveTrigger = $trigger->getDateTime(); |
|
69 | + } |
|
70 | 70 | |
71 | - return $effectiveTrigger; |
|
72 | - } |
|
71 | + return $effectiveTrigger; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Returns true or false depending on if the event falls in the specified |
|
76 | - * time-range. This is used for filtering purposes. |
|
77 | - * |
|
78 | - * The rules used to determine if an event falls within the specified |
|
79 | - * time-range is based on the CalDAV specification. |
|
80 | - * |
|
81 | - * @param DateTime $start |
|
82 | - * @param DateTime $end |
|
83 | - * |
|
84 | - * @return bool |
|
85 | - */ |
|
86 | - public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) |
|
87 | - { |
|
88 | - $effectiveTrigger = $this->getEffectiveTriggerTime(); |
|
74 | + /** |
|
75 | + * Returns true or false depending on if the event falls in the specified |
|
76 | + * time-range. This is used for filtering purposes. |
|
77 | + * |
|
78 | + * The rules used to determine if an event falls within the specified |
|
79 | + * time-range is based on the CalDAV specification. |
|
80 | + * |
|
81 | + * @param DateTime $start |
|
82 | + * @param DateTime $end |
|
83 | + * |
|
84 | + * @return bool |
|
85 | + */ |
|
86 | + public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) |
|
87 | + { |
|
88 | + $effectiveTrigger = $this->getEffectiveTriggerTime(); |
|
89 | 89 | |
90 | - if (isset($this->DURATION)) { |
|
91 | - $duration = VObject\DateTimeParser::parseDuration($this->DURATION); |
|
92 | - $repeat = (string) $this->REPEAT; |
|
93 | - if (!$repeat) { |
|
94 | - $repeat = 1; |
|
95 | - } |
|
90 | + if (isset($this->DURATION)) { |
|
91 | + $duration = VObject\DateTimeParser::parseDuration($this->DURATION); |
|
92 | + $repeat = (string) $this->REPEAT; |
|
93 | + if (!$repeat) { |
|
94 | + $repeat = 1; |
|
95 | + } |
|
96 | 96 | |
97 | - $period = new \DatePeriod($effectiveTrigger, $duration, (int) $repeat); |
|
97 | + $period = new \DatePeriod($effectiveTrigger, $duration, (int) $repeat); |
|
98 | 98 | |
99 | - foreach ($period as $occurrence) { |
|
100 | - if ($start <= $occurrence && $end > $occurrence) { |
|
101 | - return true; |
|
102 | - } |
|
103 | - } |
|
99 | + foreach ($period as $occurrence) { |
|
100 | + if ($start <= $occurrence && $end > $occurrence) { |
|
101 | + return true; |
|
102 | + } |
|
103 | + } |
|
104 | 104 | |
105 | - return false; |
|
106 | - } else { |
|
107 | - return $start <= $effectiveTrigger && $end > $effectiveTrigger; |
|
108 | - } |
|
109 | - } |
|
105 | + return false; |
|
106 | + } else { |
|
107 | + return $start <= $effectiveTrigger && $end > $effectiveTrigger; |
|
108 | + } |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * A simple list of validation rules. |
|
113 | - * |
|
114 | - * This is simply a list of properties, and how many times they either |
|
115 | - * must or must not appear. |
|
116 | - * |
|
117 | - * Possible values per property: |
|
118 | - * * 0 - Must not appear. |
|
119 | - * * 1 - Must appear exactly once. |
|
120 | - * * + - Must appear at least once. |
|
121 | - * * * - Can appear any number of times. |
|
122 | - * * ? - May appear, but not more than once. |
|
123 | - * |
|
124 | - * @var array |
|
125 | - */ |
|
126 | - public function getValidationRules() |
|
127 | - { |
|
128 | - return [ |
|
129 | - 'ACTION' => 1, |
|
130 | - 'TRIGGER' => 1, |
|
111 | + /** |
|
112 | + * A simple list of validation rules. |
|
113 | + * |
|
114 | + * This is simply a list of properties, and how many times they either |
|
115 | + * must or must not appear. |
|
116 | + * |
|
117 | + * Possible values per property: |
|
118 | + * * 0 - Must not appear. |
|
119 | + * * 1 - Must appear exactly once. |
|
120 | + * * + - Must appear at least once. |
|
121 | + * * * - Can appear any number of times. |
|
122 | + * * ? - May appear, but not more than once. |
|
123 | + * |
|
124 | + * @var array |
|
125 | + */ |
|
126 | + public function getValidationRules() |
|
127 | + { |
|
128 | + return [ |
|
129 | + 'ACTION' => 1, |
|
130 | + 'TRIGGER' => 1, |
|
131 | 131 | |
132 | - 'DURATION' => '?', |
|
133 | - 'REPEAT' => '?', |
|
132 | + 'DURATION' => '?', |
|
133 | + 'REPEAT' => '?', |
|
134 | 134 | |
135 | - 'ATTACH' => '?', |
|
136 | - ]; |
|
137 | - } |
|
135 | + 'ATTACH' => '?', |
|
136 | + ]; |
|
137 | + } |
|
138 | 138 | } |
@@ -16,166 +16,166 @@ |
||
16 | 16 | */ |
17 | 17 | class VTodo extends VObject\Component |
18 | 18 | { |
19 | - /** |
|
20 | - * Returns true or false depending on if the event falls in the specified |
|
21 | - * time-range. This is used for filtering purposes. |
|
22 | - * |
|
23 | - * The rules used to determine if an event falls within the specified |
|
24 | - * time-range is based on the CalDAV specification. |
|
25 | - * |
|
26 | - * @return bool |
|
27 | - */ |
|
28 | - public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) |
|
29 | - { |
|
30 | - $dtstart = isset($this->DTSTART) ? $this->DTSTART->getDateTime() : null; |
|
31 | - $duration = isset($this->DURATION) ? VObject\DateTimeParser::parseDuration($this->DURATION) : null; |
|
32 | - $due = isset($this->DUE) ? $this->DUE->getDateTime() : null; |
|
33 | - $completed = isset($this->COMPLETED) ? $this->COMPLETED->getDateTime() : null; |
|
34 | - $created = isset($this->CREATED) ? $this->CREATED->getDateTime() : null; |
|
19 | + /** |
|
20 | + * Returns true or false depending on if the event falls in the specified |
|
21 | + * time-range. This is used for filtering purposes. |
|
22 | + * |
|
23 | + * The rules used to determine if an event falls within the specified |
|
24 | + * time-range is based on the CalDAV specification. |
|
25 | + * |
|
26 | + * @return bool |
|
27 | + */ |
|
28 | + public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) |
|
29 | + { |
|
30 | + $dtstart = isset($this->DTSTART) ? $this->DTSTART->getDateTime() : null; |
|
31 | + $duration = isset($this->DURATION) ? VObject\DateTimeParser::parseDuration($this->DURATION) : null; |
|
32 | + $due = isset($this->DUE) ? $this->DUE->getDateTime() : null; |
|
33 | + $completed = isset($this->COMPLETED) ? $this->COMPLETED->getDateTime() : null; |
|
34 | + $created = isset($this->CREATED) ? $this->CREATED->getDateTime() : null; |
|
35 | 35 | |
36 | - if ($dtstart) { |
|
37 | - if ($duration) { |
|
38 | - $effectiveEnd = $dtstart->add($duration); |
|
36 | + if ($dtstart) { |
|
37 | + if ($duration) { |
|
38 | + $effectiveEnd = $dtstart->add($duration); |
|
39 | 39 | |
40 | - return $start <= $effectiveEnd && $end > $dtstart; |
|
41 | - } elseif ($due) { |
|
42 | - return |
|
43 | - ($start < $due || $start <= $dtstart) && |
|
44 | - ($end > $dtstart || $end >= $due); |
|
45 | - } else { |
|
46 | - return $start <= $dtstart && $end > $dtstart; |
|
47 | - } |
|
48 | - } |
|
49 | - if ($due) { |
|
50 | - return $start < $due && $end >= $due; |
|
51 | - } |
|
52 | - if ($completed && $created) { |
|
53 | - return |
|
54 | - ($start <= $created || $start <= $completed) && |
|
55 | - ($end >= $created || $end >= $completed); |
|
56 | - } |
|
57 | - if ($completed) { |
|
58 | - return $start <= $completed && $end >= $completed; |
|
59 | - } |
|
60 | - if ($created) { |
|
61 | - return $end > $created; |
|
62 | - } |
|
40 | + return $start <= $effectiveEnd && $end > $dtstart; |
|
41 | + } elseif ($due) { |
|
42 | + return |
|
43 | + ($start < $due || $start <= $dtstart) && |
|
44 | + ($end > $dtstart || $end >= $due); |
|
45 | + } else { |
|
46 | + return $start <= $dtstart && $end > $dtstart; |
|
47 | + } |
|
48 | + } |
|
49 | + if ($due) { |
|
50 | + return $start < $due && $end >= $due; |
|
51 | + } |
|
52 | + if ($completed && $created) { |
|
53 | + return |
|
54 | + ($start <= $created || $start <= $completed) && |
|
55 | + ($end >= $created || $end >= $completed); |
|
56 | + } |
|
57 | + if ($completed) { |
|
58 | + return $start <= $completed && $end >= $completed; |
|
59 | + } |
|
60 | + if ($created) { |
|
61 | + return $end > $created; |
|
62 | + } |
|
63 | 63 | |
64 | - return true; |
|
65 | - } |
|
64 | + return true; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * A simple list of validation rules. |
|
69 | - * |
|
70 | - * This is simply a list of properties, and how many times they either |
|
71 | - * must or must not appear. |
|
72 | - * |
|
73 | - * Possible values per property: |
|
74 | - * * 0 - Must not appear. |
|
75 | - * * 1 - Must appear exactly once. |
|
76 | - * * + - Must appear at least once. |
|
77 | - * * * - Can appear any number of times. |
|
78 | - * * ? - May appear, but not more than once. |
|
79 | - * |
|
80 | - * @var array |
|
81 | - */ |
|
82 | - public function getValidationRules() |
|
83 | - { |
|
84 | - return [ |
|
85 | - 'UID' => 1, |
|
86 | - 'DTSTAMP' => 1, |
|
67 | + /** |
|
68 | + * A simple list of validation rules. |
|
69 | + * |
|
70 | + * This is simply a list of properties, and how many times they either |
|
71 | + * must or must not appear. |
|
72 | + * |
|
73 | + * Possible values per property: |
|
74 | + * * 0 - Must not appear. |
|
75 | + * * 1 - Must appear exactly once. |
|
76 | + * * + - Must appear at least once. |
|
77 | + * * * - Can appear any number of times. |
|
78 | + * * ? - May appear, but not more than once. |
|
79 | + * |
|
80 | + * @var array |
|
81 | + */ |
|
82 | + public function getValidationRules() |
|
83 | + { |
|
84 | + return [ |
|
85 | + 'UID' => 1, |
|
86 | + 'DTSTAMP' => 1, |
|
87 | 87 | |
88 | - 'CLASS' => '?', |
|
89 | - 'COMPLETED' => '?', |
|
90 | - 'CREATED' => '?', |
|
91 | - 'DESCRIPTION' => '?', |
|
92 | - 'DTSTART' => '?', |
|
93 | - 'GEO' => '?', |
|
94 | - 'LAST-MODIFIED' => '?', |
|
95 | - 'LOCATION' => '?', |
|
96 | - 'ORGANIZER' => '?', |
|
97 | - 'PERCENT' => '?', |
|
98 | - 'PRIORITY' => '?', |
|
99 | - 'RECURRENCE-ID' => '?', |
|
100 | - 'SEQUENCE' => '?', |
|
101 | - 'STATUS' => '?', |
|
102 | - 'SUMMARY' => '?', |
|
103 | - 'URL' => '?', |
|
88 | + 'CLASS' => '?', |
|
89 | + 'COMPLETED' => '?', |
|
90 | + 'CREATED' => '?', |
|
91 | + 'DESCRIPTION' => '?', |
|
92 | + 'DTSTART' => '?', |
|
93 | + 'GEO' => '?', |
|
94 | + 'LAST-MODIFIED' => '?', |
|
95 | + 'LOCATION' => '?', |
|
96 | + 'ORGANIZER' => '?', |
|
97 | + 'PERCENT' => '?', |
|
98 | + 'PRIORITY' => '?', |
|
99 | + 'RECURRENCE-ID' => '?', |
|
100 | + 'SEQUENCE' => '?', |
|
101 | + 'STATUS' => '?', |
|
102 | + 'SUMMARY' => '?', |
|
103 | + 'URL' => '?', |
|
104 | 104 | |
105 | - 'RRULE' => '?', |
|
106 | - 'DUE' => '?', |
|
107 | - 'DURATION' => '?', |
|
105 | + 'RRULE' => '?', |
|
106 | + 'DUE' => '?', |
|
107 | + 'DURATION' => '?', |
|
108 | 108 | |
109 | - 'ATTACH' => '*', |
|
110 | - 'ATTENDEE' => '*', |
|
111 | - 'CATEGORIES' => '*', |
|
112 | - 'COMMENT' => '*', |
|
113 | - 'CONTACT' => '*', |
|
114 | - 'EXDATE' => '*', |
|
115 | - 'REQUEST-STATUS' => '*', |
|
116 | - 'RELATED-TO' => '*', |
|
117 | - 'RESOURCES' => '*', |
|
118 | - 'RDATE' => '*', |
|
119 | - ]; |
|
120 | - } |
|
109 | + 'ATTACH' => '*', |
|
110 | + 'ATTENDEE' => '*', |
|
111 | + 'CATEGORIES' => '*', |
|
112 | + 'COMMENT' => '*', |
|
113 | + 'CONTACT' => '*', |
|
114 | + 'EXDATE' => '*', |
|
115 | + 'REQUEST-STATUS' => '*', |
|
116 | + 'RELATED-TO' => '*', |
|
117 | + 'RESOURCES' => '*', |
|
118 | + 'RDATE' => '*', |
|
119 | + ]; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Validates the node for correctness. |
|
124 | - * |
|
125 | - * The following options are supported: |
|
126 | - * Node::REPAIR - May attempt to automatically repair the problem. |
|
127 | - * |
|
128 | - * This method returns an array with detected problems. |
|
129 | - * Every element has the following properties: |
|
130 | - * |
|
131 | - * * level - problem level. |
|
132 | - * * message - A human-readable string describing the issue. |
|
133 | - * * node - A reference to the problematic node. |
|
134 | - * |
|
135 | - * The level means: |
|
136 | - * 1 - The issue was repaired (only happens if REPAIR was turned on) |
|
137 | - * 2 - An inconsequential issue |
|
138 | - * 3 - A severe issue. |
|
139 | - * |
|
140 | - * @param int $options |
|
141 | - * |
|
142 | - * @return array |
|
143 | - */ |
|
144 | - public function validate($options = 0) |
|
145 | - { |
|
146 | - $result = parent::validate($options); |
|
147 | - if (isset($this->DUE) && isset($this->DTSTART)) { |
|
148 | - $due = $this->DUE; |
|
149 | - $dtStart = $this->DTSTART; |
|
122 | + /** |
|
123 | + * Validates the node for correctness. |
|
124 | + * |
|
125 | + * The following options are supported: |
|
126 | + * Node::REPAIR - May attempt to automatically repair the problem. |
|
127 | + * |
|
128 | + * This method returns an array with detected problems. |
|
129 | + * Every element has the following properties: |
|
130 | + * |
|
131 | + * * level - problem level. |
|
132 | + * * message - A human-readable string describing the issue. |
|
133 | + * * node - A reference to the problematic node. |
|
134 | + * |
|
135 | + * The level means: |
|
136 | + * 1 - The issue was repaired (only happens if REPAIR was turned on) |
|
137 | + * 2 - An inconsequential issue |
|
138 | + * 3 - A severe issue. |
|
139 | + * |
|
140 | + * @param int $options |
|
141 | + * |
|
142 | + * @return array |
|
143 | + */ |
|
144 | + public function validate($options = 0) |
|
145 | + { |
|
146 | + $result = parent::validate($options); |
|
147 | + if (isset($this->DUE) && isset($this->DTSTART)) { |
|
148 | + $due = $this->DUE; |
|
149 | + $dtStart = $this->DTSTART; |
|
150 | 150 | |
151 | - if ($due->getValueType() !== $dtStart->getValueType()) { |
|
152 | - $result[] = [ |
|
153 | - 'level' => 3, |
|
154 | - 'message' => 'The value type (DATE or DATE-TIME) must be identical for DUE and DTSTART', |
|
155 | - 'node' => $due, |
|
156 | - ]; |
|
157 | - } elseif ($due->getDateTime() < $dtStart->getDateTime()) { |
|
158 | - $result[] = [ |
|
159 | - 'level' => 3, |
|
160 | - 'message' => 'DUE must occur after DTSTART', |
|
161 | - 'node' => $due, |
|
162 | - ]; |
|
163 | - } |
|
164 | - } |
|
151 | + if ($due->getValueType() !== $dtStart->getValueType()) { |
|
152 | + $result[] = [ |
|
153 | + 'level' => 3, |
|
154 | + 'message' => 'The value type (DATE or DATE-TIME) must be identical for DUE and DTSTART', |
|
155 | + 'node' => $due, |
|
156 | + ]; |
|
157 | + } elseif ($due->getDateTime() < $dtStart->getDateTime()) { |
|
158 | + $result[] = [ |
|
159 | + 'level' => 3, |
|
160 | + 'message' => 'DUE must occur after DTSTART', |
|
161 | + 'node' => $due, |
|
162 | + ]; |
|
163 | + } |
|
164 | + } |
|
165 | 165 | |
166 | - return $result; |
|
167 | - } |
|
166 | + return $result; |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * This method should return a list of default property values. |
|
171 | - * |
|
172 | - * @return array |
|
173 | - */ |
|
174 | - protected function getDefaults() |
|
175 | - { |
|
176 | - return [ |
|
177 | - 'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(), |
|
178 | - 'DTSTAMP' => date('Ymd\\THis\\Z'), |
|
179 | - ]; |
|
180 | - } |
|
169 | + /** |
|
170 | + * This method should return a list of default property values. |
|
171 | + * |
|
172 | + * @return array |
|
173 | + */ |
|
174 | + protected function getDefaults() |
|
175 | + { |
|
176 | + return [ |
|
177 | + 'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(), |
|
178 | + 'DTSTAMP' => date('Ymd\\THis\\Z'), |
|
179 | + ]; |
|
180 | + } |
|
181 | 181 | } |
@@ -17,77 +17,77 @@ |
||
17 | 17 | */ |
18 | 18 | class VFreeBusy extends VObject\Component |
19 | 19 | { |
20 | - /** |
|
21 | - * Checks based on the contained FREEBUSY information, if a timeslot is |
|
22 | - * available. |
|
23 | - * |
|
24 | - * @return bool |
|
25 | - */ |
|
26 | - public function isFree(DateTimeInterface $start, DatetimeInterface $end) |
|
27 | - { |
|
28 | - foreach ($this->select('FREEBUSY') as $freebusy) { |
|
29 | - // We are only interested in FBTYPE=BUSY (the default), |
|
30 | - // FBTYPE=BUSY-TENTATIVE or FBTYPE=BUSY-UNAVAILABLE. |
|
31 | - if (isset($freebusy['FBTYPE']) && 'BUSY' !== strtoupper(substr((string) $freebusy['FBTYPE'], 0, 4))) { |
|
32 | - continue; |
|
33 | - } |
|
20 | + /** |
|
21 | + * Checks based on the contained FREEBUSY information, if a timeslot is |
|
22 | + * available. |
|
23 | + * |
|
24 | + * @return bool |
|
25 | + */ |
|
26 | + public function isFree(DateTimeInterface $start, DatetimeInterface $end) |
|
27 | + { |
|
28 | + foreach ($this->select('FREEBUSY') as $freebusy) { |
|
29 | + // We are only interested in FBTYPE=BUSY (the default), |
|
30 | + // FBTYPE=BUSY-TENTATIVE or FBTYPE=BUSY-UNAVAILABLE. |
|
31 | + if (isset($freebusy['FBTYPE']) && 'BUSY' !== strtoupper(substr((string) $freebusy['FBTYPE'], 0, 4))) { |
|
32 | + continue; |
|
33 | + } |
|
34 | 34 | |
35 | - // The freebusy component can hold more than 1 value, separated by |
|
36 | - // commas. |
|
37 | - $periods = explode(',', (string) $freebusy); |
|
35 | + // The freebusy component can hold more than 1 value, separated by |
|
36 | + // commas. |
|
37 | + $periods = explode(',', (string) $freebusy); |
|
38 | 38 | |
39 | - foreach ($periods as $period) { |
|
40 | - // Every period is formatted as [start]/[end]. The start is an |
|
41 | - // absolute UTC time, the end may be an absolute UTC time, or |
|
42 | - // duration (relative) value. |
|
43 | - list($busyStart, $busyEnd) = explode('/', $period); |
|
39 | + foreach ($periods as $period) { |
|
40 | + // Every period is formatted as [start]/[end]. The start is an |
|
41 | + // absolute UTC time, the end may be an absolute UTC time, or |
|
42 | + // duration (relative) value. |
|
43 | + list($busyStart, $busyEnd) = explode('/', $period); |
|
44 | 44 | |
45 | - $busyStart = VObject\DateTimeParser::parse($busyStart); |
|
46 | - $busyEnd = VObject\DateTimeParser::parse($busyEnd); |
|
47 | - if ($busyEnd instanceof \DateInterval) { |
|
48 | - $busyEnd = $busyStart->add($busyEnd); |
|
49 | - } |
|
45 | + $busyStart = VObject\DateTimeParser::parse($busyStart); |
|
46 | + $busyEnd = VObject\DateTimeParser::parse($busyEnd); |
|
47 | + if ($busyEnd instanceof \DateInterval) { |
|
48 | + $busyEnd = $busyStart->add($busyEnd); |
|
49 | + } |
|
50 | 50 | |
51 | - if ($start < $busyEnd && $end > $busyStart) { |
|
52 | - return false; |
|
53 | - } |
|
54 | - } |
|
55 | - } |
|
51 | + if ($start < $busyEnd && $end > $busyStart) { |
|
52 | + return false; |
|
53 | + } |
|
54 | + } |
|
55 | + } |
|
56 | 56 | |
57 | - return true; |
|
58 | - } |
|
57 | + return true; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * A simple list of validation rules. |
|
62 | - * |
|
63 | - * This is simply a list of properties, and how many times they either |
|
64 | - * must or must not appear. |
|
65 | - * |
|
66 | - * Possible values per property: |
|
67 | - * * 0 - Must not appear. |
|
68 | - * * 1 - Must appear exactly once. |
|
69 | - * * + - Must appear at least once. |
|
70 | - * * * - Can appear any number of times. |
|
71 | - * * ? - May appear, but not more than once. |
|
72 | - * |
|
73 | - * @var array |
|
74 | - */ |
|
75 | - public function getValidationRules() |
|
76 | - { |
|
77 | - return [ |
|
78 | - 'UID' => 1, |
|
79 | - 'DTSTAMP' => 1, |
|
60 | + /** |
|
61 | + * A simple list of validation rules. |
|
62 | + * |
|
63 | + * This is simply a list of properties, and how many times they either |
|
64 | + * must or must not appear. |
|
65 | + * |
|
66 | + * Possible values per property: |
|
67 | + * * 0 - Must not appear. |
|
68 | + * * 1 - Must appear exactly once. |
|
69 | + * * + - Must appear at least once. |
|
70 | + * * * - Can appear any number of times. |
|
71 | + * * ? - May appear, but not more than once. |
|
72 | + * |
|
73 | + * @var array |
|
74 | + */ |
|
75 | + public function getValidationRules() |
|
76 | + { |
|
77 | + return [ |
|
78 | + 'UID' => 1, |
|
79 | + 'DTSTAMP' => 1, |
|
80 | 80 | |
81 | - 'CONTACT' => '?', |
|
82 | - 'DTSTART' => '?', |
|
83 | - 'DTEND' => '?', |
|
84 | - 'ORGANIZER' => '?', |
|
85 | - 'URL' => '?', |
|
81 | + 'CONTACT' => '?', |
|
82 | + 'DTSTART' => '?', |
|
83 | + 'DTEND' => '?', |
|
84 | + 'ORGANIZER' => '?', |
|
85 | + 'URL' => '?', |
|
86 | 86 | |
87 | - 'ATTENDEE' => '*', |
|
88 | - 'COMMENT' => '*', |
|
89 | - 'FREEBUSY' => '*', |
|
90 | - 'REQUEST-STATUS' => '*', |
|
91 | - ]; |
|
92 | - } |
|
87 | + 'ATTENDEE' => '*', |
|
88 | + 'COMMENT' => '*', |
|
89 | + 'FREEBUSY' => '*', |
|
90 | + 'REQUEST-STATUS' => '*', |
|
91 | + ]; |
|
92 | + } |
|
93 | 93 | } |
@@ -18,123 +18,123 @@ |
||
18 | 18 | */ |
19 | 19 | class VEvent extends VObject\Component |
20 | 20 | { |
21 | - /** |
|
22 | - * Returns true or false depending on if the event falls in the specified |
|
23 | - * time-range. This is used for filtering purposes. |
|
24 | - * |
|
25 | - * The rules used to determine if an event falls within the specified |
|
26 | - * time-range is based on the CalDAV specification. |
|
27 | - * |
|
28 | - * @return bool |
|
29 | - */ |
|
30 | - public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) |
|
31 | - { |
|
32 | - if ($this->RRULE) { |
|
33 | - try { |
|
34 | - $it = new EventIterator($this, null, $start->getTimezone()); |
|
35 | - } catch (NoInstancesException $e) { |
|
36 | - // If we've caught this exception, there are no instances |
|
37 | - // for the event that fall into the specified time-range. |
|
38 | - return false; |
|
39 | - } |
|
21 | + /** |
|
22 | + * Returns true or false depending on if the event falls in the specified |
|
23 | + * time-range. This is used for filtering purposes. |
|
24 | + * |
|
25 | + * The rules used to determine if an event falls within the specified |
|
26 | + * time-range is based on the CalDAV specification. |
|
27 | + * |
|
28 | + * @return bool |
|
29 | + */ |
|
30 | + public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) |
|
31 | + { |
|
32 | + if ($this->RRULE) { |
|
33 | + try { |
|
34 | + $it = new EventIterator($this, null, $start->getTimezone()); |
|
35 | + } catch (NoInstancesException $e) { |
|
36 | + // If we've caught this exception, there are no instances |
|
37 | + // for the event that fall into the specified time-range. |
|
38 | + return false; |
|
39 | + } |
|
40 | 40 | |
41 | - $it->fastForward($start); |
|
41 | + $it->fastForward($start); |
|
42 | 42 | |
43 | - // We fast-forwarded to a spot where the end-time of the |
|
44 | - // recurrence instance exceeded the start of the requested |
|
45 | - // time-range. |
|
46 | - // |
|
47 | - // If the starttime of the recurrence did not exceed the |
|
48 | - // end of the time range as well, we have a match. |
|
49 | - return $it->getDTStart() < $end && $it->getDTEnd() > $start; |
|
50 | - } |
|
43 | + // We fast-forwarded to a spot where the end-time of the |
|
44 | + // recurrence instance exceeded the start of the requested |
|
45 | + // time-range. |
|
46 | + // |
|
47 | + // If the starttime of the recurrence did not exceed the |
|
48 | + // end of the time range as well, we have a match. |
|
49 | + return $it->getDTStart() < $end && $it->getDTEnd() > $start; |
|
50 | + } |
|
51 | 51 | |
52 | - $effectiveStart = $this->DTSTART->getDateTime($start->getTimezone()); |
|
53 | - if (isset($this->DTEND)) { |
|
54 | - // The DTEND property is considered non inclusive. So for a 3 day |
|
55 | - // event in july, dtstart and dtend would have to be July 1st and |
|
56 | - // July 4th respectively. |
|
57 | - // |
|
58 | - // See: |
|
59 | - // http://tools.ietf.org/html/rfc5545#page-54 |
|
60 | - $effectiveEnd = $this->DTEND->getDateTime($end->getTimezone()); |
|
61 | - } elseif (isset($this->DURATION)) { |
|
62 | - $effectiveEnd = $effectiveStart->add(VObject\DateTimeParser::parseDuration($this->DURATION)); |
|
63 | - } elseif (!$this->DTSTART->hasTime()) { |
|
64 | - $effectiveEnd = $effectiveStart->modify('+1 day'); |
|
65 | - } else { |
|
66 | - $effectiveEnd = $effectiveStart; |
|
67 | - } |
|
52 | + $effectiveStart = $this->DTSTART->getDateTime($start->getTimezone()); |
|
53 | + if (isset($this->DTEND)) { |
|
54 | + // The DTEND property is considered non inclusive. So for a 3 day |
|
55 | + // event in july, dtstart and dtend would have to be July 1st and |
|
56 | + // July 4th respectively. |
|
57 | + // |
|
58 | + // See: |
|
59 | + // http://tools.ietf.org/html/rfc5545#page-54 |
|
60 | + $effectiveEnd = $this->DTEND->getDateTime($end->getTimezone()); |
|
61 | + } elseif (isset($this->DURATION)) { |
|
62 | + $effectiveEnd = $effectiveStart->add(VObject\DateTimeParser::parseDuration($this->DURATION)); |
|
63 | + } elseif (!$this->DTSTART->hasTime()) { |
|
64 | + $effectiveEnd = $effectiveStart->modify('+1 day'); |
|
65 | + } else { |
|
66 | + $effectiveEnd = $effectiveStart; |
|
67 | + } |
|
68 | 68 | |
69 | - return |
|
70 | - ($start < $effectiveEnd) && ($end > $effectiveStart) |
|
71 | - ; |
|
72 | - } |
|
69 | + return |
|
70 | + ($start < $effectiveEnd) && ($end > $effectiveStart) |
|
71 | + ; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * This method should return a list of default property values. |
|
76 | - * |
|
77 | - * @return array |
|
78 | - */ |
|
79 | - protected function getDefaults() |
|
80 | - { |
|
81 | - return [ |
|
82 | - 'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(), |
|
83 | - 'DTSTAMP' => gmdate('Ymd\\THis\\Z'), |
|
84 | - ]; |
|
85 | - } |
|
74 | + /** |
|
75 | + * This method should return a list of default property values. |
|
76 | + * |
|
77 | + * @return array |
|
78 | + */ |
|
79 | + protected function getDefaults() |
|
80 | + { |
|
81 | + return [ |
|
82 | + 'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(), |
|
83 | + 'DTSTAMP' => gmdate('Ymd\\THis\\Z'), |
|
84 | + ]; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * A simple list of validation rules. |
|
89 | - * |
|
90 | - * This is simply a list of properties, and how many times they either |
|
91 | - * must or must not appear. |
|
92 | - * |
|
93 | - * Possible values per property: |
|
94 | - * * 0 - Must not appear. |
|
95 | - * * 1 - Must appear exactly once. |
|
96 | - * * + - Must appear at least once. |
|
97 | - * * * - Can appear any number of times. |
|
98 | - * * ? - May appear, but not more than once. |
|
99 | - * |
|
100 | - * @var array |
|
101 | - */ |
|
102 | - public function getValidationRules() |
|
103 | - { |
|
104 | - $hasMethod = isset($this->parent->METHOD); |
|
87 | + /** |
|
88 | + * A simple list of validation rules. |
|
89 | + * |
|
90 | + * This is simply a list of properties, and how many times they either |
|
91 | + * must or must not appear. |
|
92 | + * |
|
93 | + * Possible values per property: |
|
94 | + * * 0 - Must not appear. |
|
95 | + * * 1 - Must appear exactly once. |
|
96 | + * * + - Must appear at least once. |
|
97 | + * * * - Can appear any number of times. |
|
98 | + * * ? - May appear, but not more than once. |
|
99 | + * |
|
100 | + * @var array |
|
101 | + */ |
|
102 | + public function getValidationRules() |
|
103 | + { |
|
104 | + $hasMethod = isset($this->parent->METHOD); |
|
105 | 105 | |
106 | - return [ |
|
107 | - 'UID' => 1, |
|
108 | - 'DTSTAMP' => 1, |
|
109 | - 'DTSTART' => $hasMethod ? '?' : '1', |
|
110 | - 'CLASS' => '?', |
|
111 | - 'CREATED' => '?', |
|
112 | - 'DESCRIPTION' => '?', |
|
113 | - 'GEO' => '?', |
|
114 | - 'LAST-MODIFIED' => '?', |
|
115 | - 'LOCATION' => '?', |
|
116 | - 'ORGANIZER' => '?', |
|
117 | - 'PRIORITY' => '?', |
|
118 | - 'SEQUENCE' => '?', |
|
119 | - 'STATUS' => '?', |
|
120 | - 'SUMMARY' => '?', |
|
121 | - 'TRANSP' => '?', |
|
122 | - 'URL' => '?', |
|
123 | - 'RECURRENCE-ID' => '?', |
|
124 | - 'RRULE' => '?', |
|
125 | - 'DTEND' => '?', |
|
126 | - 'DURATION' => '?', |
|
106 | + return [ |
|
107 | + 'UID' => 1, |
|
108 | + 'DTSTAMP' => 1, |
|
109 | + 'DTSTART' => $hasMethod ? '?' : '1', |
|
110 | + 'CLASS' => '?', |
|
111 | + 'CREATED' => '?', |
|
112 | + 'DESCRIPTION' => '?', |
|
113 | + 'GEO' => '?', |
|
114 | + 'LAST-MODIFIED' => '?', |
|
115 | + 'LOCATION' => '?', |
|
116 | + 'ORGANIZER' => '?', |
|
117 | + 'PRIORITY' => '?', |
|
118 | + 'SEQUENCE' => '?', |
|
119 | + 'STATUS' => '?', |
|
120 | + 'SUMMARY' => '?', |
|
121 | + 'TRANSP' => '?', |
|
122 | + 'URL' => '?', |
|
123 | + 'RECURRENCE-ID' => '?', |
|
124 | + 'RRULE' => '?', |
|
125 | + 'DTEND' => '?', |
|
126 | + 'DURATION' => '?', |
|
127 | 127 | |
128 | - 'ATTACH' => '*', |
|
129 | - 'ATTENDEE' => '*', |
|
130 | - 'CATEGORIES' => '*', |
|
131 | - 'COMMENT' => '*', |
|
132 | - 'CONTACT' => '*', |
|
133 | - 'EXDATE' => '*', |
|
134 | - 'REQUEST-STATUS' => '*', |
|
135 | - 'RELATED-TO' => '*', |
|
136 | - 'RESOURCES' => '*', |
|
137 | - 'RDATE' => '*', |
|
138 | - ]; |
|
139 | - } |
|
128 | + 'ATTACH' => '*', |
|
129 | + 'ATTENDEE' => '*', |
|
130 | + 'CATEGORIES' => '*', |
|
131 | + 'COMMENT' => '*', |
|
132 | + 'CONTACT' => '*', |
|
133 | + 'EXDATE' => '*', |
|
134 | + 'REQUEST-STATUS' => '*', |
|
135 | + 'RELATED-TO' => '*', |
|
136 | + 'RESOURCES' => '*', |
|
137 | + 'RDATE' => '*', |
|
138 | + ]; |
|
139 | + } |
|
140 | 140 | } |
@@ -16,48 +16,48 @@ |
||
16 | 16 | */ |
17 | 17 | class VTimeZone extends VObject\Component |
18 | 18 | { |
19 | - /** |
|
20 | - * Returns the PHP DateTimeZone for this VTIMEZONE component. |
|
21 | - * |
|
22 | - * If we can't accurately determine the timezone, this method will return |
|
23 | - * UTC. |
|
24 | - * |
|
25 | - * @return \DateTimeZone |
|
26 | - */ |
|
27 | - public function getTimeZone() |
|
28 | - { |
|
29 | - return VObject\TimeZoneUtil::getTimeZone((string) $this->TZID, $this->root); |
|
30 | - } |
|
19 | + /** |
|
20 | + * Returns the PHP DateTimeZone for this VTIMEZONE component. |
|
21 | + * |
|
22 | + * If we can't accurately determine the timezone, this method will return |
|
23 | + * UTC. |
|
24 | + * |
|
25 | + * @return \DateTimeZone |
|
26 | + */ |
|
27 | + public function getTimeZone() |
|
28 | + { |
|
29 | + return VObject\TimeZoneUtil::getTimeZone((string) $this->TZID, $this->root); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * A simple list of validation rules. |
|
34 | - * |
|
35 | - * This is simply a list of properties, and how many times they either |
|
36 | - * must or must not appear. |
|
37 | - * |
|
38 | - * Possible values per property: |
|
39 | - * * 0 - Must not appear. |
|
40 | - * * 1 - Must appear exactly once. |
|
41 | - * * + - Must appear at least once. |
|
42 | - * * * - Can appear any number of times. |
|
43 | - * * ? - May appear, but not more than once. |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - public function getValidationRules() |
|
48 | - { |
|
49 | - return [ |
|
50 | - 'TZID' => 1, |
|
32 | + /** |
|
33 | + * A simple list of validation rules. |
|
34 | + * |
|
35 | + * This is simply a list of properties, and how many times they either |
|
36 | + * must or must not appear. |
|
37 | + * |
|
38 | + * Possible values per property: |
|
39 | + * * 0 - Must not appear. |
|
40 | + * * 1 - Must appear exactly once. |
|
41 | + * * + - Must appear at least once. |
|
42 | + * * * - Can appear any number of times. |
|
43 | + * * ? - May appear, but not more than once. |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + public function getValidationRules() |
|
48 | + { |
|
49 | + return [ |
|
50 | + 'TZID' => 1, |
|
51 | 51 | |
52 | - 'LAST-MODIFIED' => '?', |
|
53 | - 'TZURL' => '?', |
|
52 | + 'LAST-MODIFIED' => '?', |
|
53 | + 'TZURL' => '?', |
|
54 | 54 | |
55 | - // At least 1 STANDARD or DAYLIGHT must appear. |
|
56 | - // |
|
57 | - // The validator is not specific yet to pick this up, so these |
|
58 | - // rules are too loose. |
|
59 | - 'STANDARD' => '*', |
|
60 | - 'DAYLIGHT' => '*', |
|
61 | - ]; |
|
62 | - } |
|
55 | + // At least 1 STANDARD or DAYLIGHT must appear. |
|
56 | + // |
|
57 | + // The validator is not specific yet to pick this up, so these |
|
58 | + // rules are too loose. |
|
59 | + 'STANDARD' => '*', |
|
60 | + 'DAYLIGHT' => '*', |
|
61 | + ]; |
|
62 | + } |
|
63 | 63 | } |