1 |
0aee3c58
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
class vcalendar extends iCalBase {
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
private $calscale;
|
44 |
|
|
private $method;
|
45 |
|
|
private $prodid;
|
46 |
|
|
private $version;
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
private $directory;
|
54 |
|
|
private $filename;
|
55 |
|
|
private $url;
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
private static $headers = array( 'Content-Encoding: gzip',
|
64 |
|
|
'Vary: *',
|
65 |
|
|
'Content-Length: %s',
|
66 |
|
|
'Content-Type: application/calendar+xml; charset=utf-8',
|
67 |
|
|
'Content-Type: text/calendar; charset=utf-8',
|
68 |
|
|
'Content-Disposition: attachment; filename="%s"',
|
69 |
|
|
'Content-Disposition: inline; filename="%s"',
|
70 |
|
|
'Cache-Control: max-age=10',
|
71 |
|
|
);
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
function vcalendar ( $config = array()) {
|
94 |
|
|
$this->_makeVersion();
|
95 |
|
|
$this->calscale = null;
|
96 |
|
|
$this->method = null;
|
97 |
|
|
$this->_makeUnique_id();
|
98 |
|
|
$this->prodid = null;
|
99 |
|
|
$this->xprop = array();
|
100 |
|
|
$this->language = null;
|
101 |
|
|
$this->directory = '.';
|
102 |
|
|
$this->filename = null;
|
103 |
|
|
$this->url = null;
|
104 |
|
|
$this->dtzid = null;
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
if( defined( 'ICAL_LANG' ) && !isset( $config['language'] ))
|
109 |
|
|
$config['language'] = ICAL_LANG;
|
110 |
|
|
if( !isset( $config['allowEmpty'] )) $config['allowEmpty'] = TRUE;
|
111 |
|
|
if( !isset( $config['nl'] )) $config['nl'] = "\r\n";
|
112 |
|
|
if( !isset( $config['format'] )) $config['format'] = 'iCal';
|
113 |
|
|
if( !isset( $config['delimiter'] )) $config['delimiter'] = DIRECTORY_SEPARATOR;
|
114 |
|
|
$this->setConfig( $config );
|
115 |
|
|
$this->xcaldecl = array();
|
116 |
|
|
$this->components = array();
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
public static function iCalcreatorVersion() {
|
127 |
|
|
return trim( substr( ICALCREATOR_VERSION, strpos( ICALCREATOR_VERSION, ' ' )));
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
function createCalscale() {
|
144 |
|
|
if( empty( $this->calscale )) return FALSE;
|
145 |
|
|
switch( $this->format ) {
|
146 |
|
|
case 'xcal':
|
147 |
|
|
return $this->nl.' calscale="'.$this->calscale.'"';
|
148 |
|
|
break;
|
149 |
|
|
default:
|
150 |
|
|
return 'CALSCALE:'.$this->calscale.$this->nl;
|
151 |
|
|
break;
|
152 |
|
|
}
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
function setCalscale( $value ) {
|
164 |
|
|
if( empty( $value )) return FALSE;
|
165 |
|
|
$this->calscale = $value;
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
function createMethod() {
|
182 |
|
|
if( empty( $this->method )) return FALSE;
|
183 |
|
|
switch( $this->format ) {
|
184 |
|
|
case 'xcal':
|
185 |
|
|
return $this->nl.' method="'.$this->method.'"';
|
186 |
|
|
break;
|
187 |
|
|
default:
|
188 |
|
|
return 'METHOD:'.$this->method.$this->nl;
|
189 |
|
|
break;
|
190 |
|
|
}
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
function setMethod( $value ) {
|
202 |
|
|
if( empty( $value )) return FALSE;
|
203 |
|
|
$this->method = $value;
|
204 |
|
|
return TRUE;
|
205 |
|
|
}
|
206 |
|
|
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
function createProdid() {
|
226 |
|
|
if( !isset( $this->prodid ))
|
227 |
|
|
$this->_makeProdid();
|
228 |
|
|
switch( $this->format ) {
|
229 |
|
|
case 'xcal':
|
230 |
|
|
return $this->nl.' prodid="'.$this->prodid.'"';
|
231 |
|
|
break;
|
232 |
|
|
default:
|
233 |
|
|
return $this->_createElement( 'PRODID', '', $this->prodid );
|
234 |
|
|
break;
|
235 |
|
|
}
|
236 |
|
|
}
|
237 |
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
|
|
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
|
245 |
|
|
|
246 |
|
|
|
247 |
|
|
|
248 |
|
|
|
249 |
|
|
|
250 |
|
|
function _makeProdid() {
|
251 |
|
|
$this->prodid = '-//'.$this->unique_id.'//NONSGML kigkonsult.se '.ICALCREATOR_VERSION.'//'.strtoupper( $this->language );
|
252 |
|
|
}
|
253 |
|
|
|
254 |
|
|
|
255 |
|
|
|
256 |
|
|
|
257 |
|
|
|
258 |
|
|
|
259 |
|
|
|
260 |
|
|
|
261 |
|
|
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
|
265 |
|
|
|
266 |
|
|
|
267 |
|
|
function _makeUnique_id() {
|
268 |
|
|
$this->unique_id = ( isset( $_SERVER['SERVER_NAME'] )) ? gethostbyname( $_SERVER['SERVER_NAME'] ) : 'localhost';
|
269 |
|
|
}
|
270 |
|
|
|
271 |
|
|
|
272 |
|
|
|
273 |
|
|
|
274 |
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
|
278 |
|
|
|
279 |
|
|
|
280 |
|
|
|
281 |
|
|
|
282 |
|
|
|
283 |
|
|
|
284 |
|
|
|
285 |
|
|
|
286 |
|
|
|
287 |
|
|
function createVersion() {
|
288 |
|
|
if( empty( $this->version ))
|
289 |
|
|
$this->_makeVersion();
|
290 |
|
|
switch( $this->format ) {
|
291 |
|
|
case 'xcal':
|
292 |
|
|
return $this->nl.' version="'.$this->version.'"';
|
293 |
|
|
break;
|
294 |
|
|
default:
|
295 |
|
|
return 'VERSION:'.$this->version.$this->nl;
|
296 |
|
|
break;
|
297 |
|
|
}
|
298 |
|
|
}
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
|
307 |
|
|
function _makeVersion() {
|
308 |
|
|
$this->version = '2.0';
|
309 |
|
|
}
|
310 |
|
|
|
311 |
|
|
|
312 |
|
|
|
313 |
|
|
|
314 |
|
|
|
315 |
|
|
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
|
319 |
|
|
function setVersion( $value ) {
|
320 |
|
|
if( empty( $value )) return FALSE;
|
321 |
|
|
$this->version = $value;
|
322 |
|
|
return TRUE;
|
323 |
|
|
}
|
324 |
|
|
|
325 |
|
|
|
326 |
|
|
|
327 |
|
|
|
328 |
|
|
|
329 |
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
|
|
|
335 |
|
|
|
336 |
|
|
|
337 |
|
|
|
338 |
|
|
|
339 |
|
|
function deleteProperty( $propName=FALSE, $propix=FALSE ) {
|
340 |
|
|
$propName = ( $propName ) ? strtoupper( $propName ) : 'X-PROP';
|
341 |
|
|
if( !$propix )
|
342 |
|
|
$propix = ( isset( $this->propdelix[$propName] ) && ( 'X-PROP' != $propName )) ? $this->propdelix[$propName] + 2 : 1;
|
343 |
|
|
$this->propdelix[$propName] = --$propix;
|
344 |
|
|
$return = FALSE;
|
345 |
|
|
switch( $propName ) {
|
346 |
|
|
case 'CALSCALE':
|
347 |
|
|
if( isset( $this->calscale )) {
|
348 |
|
|
$this->calscale = null;
|
349 |
|
|
$return = TRUE;
|
350 |
|
|
}
|
351 |
|
|
break;
|
352 |
|
|
case 'METHOD':
|
353 |
|
|
if( isset( $this->method )) {
|
354 |
|
|
$this->method = null;
|
355 |
|
|
$return = TRUE;
|
356 |
|
|
}
|
357 |
|
|
break;
|
358 |
|
|
default:
|
359 |
|
|
$reduced = array();
|
360 |
|
|
if( $propName != 'X-PROP' ) {
|
361 |
|
|
if( !isset( $this->xprop[$propName] )) { unset( $this->propdelix[$propName] ); return FALSE; }
|
362 |
|
|
foreach( $this->xprop as $k => $a ) {
|
363 |
|
|
if(( $k != $propName ) && !empty( $a ))
|
364 |
|
|
$reduced[$k] = $a;
|
365 |
|
|
}
|
366 |
|
|
}
|
367 |
|
|
else {
|
368 |
|
|
if( count( $this->xprop ) <= $propix ) return FALSE;
|
369 |
|
|
$xpropno = 0;
|
370 |
|
|
foreach( $this->xprop as $xpropkey => $xpropvalue ) {
|
371 |
|
|
if( $propix != $xpropno )
|
372 |
|
|
$reduced[$xpropkey] = $xpropvalue;
|
373 |
|
|
$xpropno++;
|
374 |
|
|
}
|
375 |
|
|
}
|
376 |
|
|
$this->xprop = $reduced;
|
377 |
|
|
if( empty( $this->xprop )) {
|
378 |
|
|
unset( $this->propdelix[$propName] );
|
379 |
|
|
return FALSE;
|
380 |
|
|
}
|
381 |
|
|
return TRUE;
|
382 |
|
|
}
|
383 |
|
|
return $return;
|
384 |
|
|
}
|
385 |
|
|
|
386 |
|
|
|
387 |
|
|
|
388 |
|
|
|
389 |
|
|
|
390 |
|
|
|
391 |
|
|
|
392 |
|
|
|
393 |
|
|
|
394 |
|
|
|
395 |
|
|
|
396 |
|
|
|
397 |
|
|
|
398 |
|
|
|
399 |
|
|
|
400 |
|
|
|
401 |
|
|
|
402 |
|
|
|
403 |
|
|
|
404 |
|
|
|
405 |
|
|
|
406 |
|
|
|
407 |
|
|
|
408 |
|
|
|
409 |
|
|
|
410 |
|
|
|
411 |
|
|
|
412 |
|
|
function getProperty( $propName=FALSE, $propix=FALSE, $inclParam=FALSE ) {
|
413 |
|
|
$propName = ( $propName ) ? strtoupper( $propName ) : 'X-PROP';
|
414 |
|
|
if( 'X-PROP' == $propName ) {
|
415 |
|
|
if( empty( $propix ))
|
416 |
|
|
$propix = ( isset( $this->propix[$propName] )) ? $this->propix[$propName] + 2 : 1;
|
417 |
|
|
$this->propix[$propName] = --$propix;
|
418 |
|
|
}
|
419 |
|
|
switch( $propName ) {
|
420 |
|
|
case 'ATTENDEE':
|
421 |
|
|
case 'CATEGORIES':
|
422 |
|
|
case 'CONTACT':
|
423 |
|
|
case 'DTSTART':
|
424 |
|
|
case 'GEOLOCATION':
|
425 |
|
|
case 'LOCATION':
|
426 |
|
|
case 'ORGANIZER':
|
427 |
|
|
case 'PRIORITY':
|
428 |
|
|
case 'RESOURCES':
|
429 |
|
|
case 'STATUS':
|
430 |
|
|
case 'SUMMARY':
|
431 |
|
|
case 'RECURRENCE-ID-UID':
|
432 |
|
|
case 'RELATED-TO':
|
433 |
|
|
case 'R-UID':
|
434 |
|
|
case 'UID':
|
435 |
|
|
case 'URL':
|
436 |
|
|
$output = array();
|
437 |
|
|
foreach ( $this->components as $cix => $component) {
|
438 |
|
|
if( !in_array( $component->objName, iCalUtilityFunctions::$vComps ))
|
439 |
|
|
continue;
|
440 |
|
|
if( in_array( $propName, iCalUtilityFunctions::$mProps1 )) {
|
441 |
|
|
$component->_getProperties( $propName, $output );
|
442 |
|
|
continue;
|
443 |
|
|
}
|
444 |
|
|
elseif(( 3 < strlen( $propName )) && ( 'UID' == substr( $propName, -3 ))) {
|
445 |
|
|
if( FALSE !== ( $content = $component->getProperty( 'RECURRENCE-ID' )))
|
446 |
|
|
$content = $component->getProperty( 'UID' );
|
447 |
|
|
}
|
448 |
|
|
elseif( 'GEOLOCATION' == $propName ) {
|
449 |
|
|
$content = ( FALSE === ( $loc = $component->getProperty( 'LOCATION' ))) ? '' : $loc.' ';
|
450 |
|
|
if( FALSE === ( $geo = $component->getProperty( 'GEO' )))
|
451 |
|
|
continue;
|
452 |
|
|
$content .= iCalUtilityFunctions::_geo2str2( $geo['latitude'], iCalUtilityFunctions::$geoLatFmt ).
|
453 |
|
|
iCalUtilityFunctions::_geo2str2( $geo['longitude'], iCalUtilityFunctions::$geoLongFmt ).'/';
|
454 |
|
|
}
|
455 |
|
|
elseif( FALSE === ( $content = $component->getProperty( $propName )))
|
456 |
|
|
continue;
|
457 |
|
|
if(( FALSE === $content ) || empty( $content ))
|
458 |
|
|
continue;
|
459 |
|
|
elseif( is_array( $content )) {
|
460 |
|
|
if( isset( $content['year'] )) {
|
461 |
|
|
$key = sprintf( iCalUtilityFunctions::$fmt['Ymd'], (int) $content['year'], (int) $content['month'], (int) $content['day'] );
|
462 |
|
|
if( !isset( $output[$key] ))
|
463 |
|
|
$output[$key] = 1;
|
464 |
|
|
else
|
465 |
|
|
$output[$key] += 1;
|
466 |
|
|
}
|
467 |
|
|
else {
|
468 |
|
|
foreach( $content as $partValue => $partCount ) {
|
469 |
|
|
if( !isset( $output[$partValue] ))
|
470 |
|
|
$output[$partValue] = $partCount;
|
471 |
|
|
else
|
472 |
|
|
$output[$partValue] += $partCount;
|
473 |
|
|
}
|
474 |
|
|
}
|
475 |
|
|
}
|
476 |
|
|
elseif( !isset( $output[$content] ))
|
477 |
|
|
$output[$content] = 1;
|
478 |
|
|
else
|
479 |
|
|
$output[$content] += 1;
|
480 |
|
|
}
|
481 |
|
|
if( !empty( $output ))
|
482 |
|
|
ksort( $output );
|
483 |
|
|
return $output;
|
484 |
|
|
break;
|
485 |
|
|
case 'CALSCALE':
|
486 |
|
|
return ( !empty( $this->calscale )) ? $this->calscale : FALSE;
|
487 |
|
|
break;
|
488 |
|
|
case 'METHOD':
|
489 |
|
|
return ( !empty( $this->method )) ? $this->method : FALSE;
|
490 |
|
|
break;
|
491 |
|
|
case 'PRODID':
|
492 |
|
|
if( empty( $this->prodid ))
|
493 |
|
|
$this->_makeProdid();
|
494 |
|
|
return $this->prodid;
|
495 |
|
|
break;
|
496 |
|
|
case 'VERSION':
|
497 |
|
|
return ( !empty( $this->version )) ? $this->version : FALSE;
|
498 |
|
|
break;
|
499 |
|
|
default:
|
500 |
|
|
if( $propName != 'X-PROP' ) {
|
501 |
|
|
if( !isset( $this->xprop[$propName] )) return FALSE;
|
502 |
|
|
return ( $inclParam ) ? array( $propName, $this->xprop[$propName] )
|
503 |
|
|
: array( $propName, $this->xprop[$propName]['value'] );
|
504 |
|
|
}
|
505 |
|
|
else {
|
506 |
|
|
if( empty( $this->xprop )) return FALSE;
|
507 |
|
|
$xpropno = 0;
|
508 |
|
|
foreach( $this->xprop as $xpropkey => $xpropvalue ) {
|
509 |
|
|
if( $propix == $xpropno )
|
510 |
|
|
return ( $inclParam ) ? array( $xpropkey, $this->xprop[$xpropkey] )
|
511 |
|
|
: array( $xpropkey, $this->xprop[$xpropkey]['value'] );
|
512 |
|
|
else
|
513 |
|
|
$xpropno++;
|
514 |
|
|
}
|
515 |
|
|
unset( $this->propix[$propName] );
|
516 |
|
|
return FALSE;
|
517 |
|
|
}
|
518 |
|
|
}
|
519 |
|
|
return FALSE;
|
520 |
|
|
}
|
521 |
|
|
|
522 |
|
|
|
523 |
|
|
|
524 |
|
|
|
525 |
|
|
|
526 |
|
|
|
527 |
|
|
|
528 |
|
|
|
529 |
|
|
|
530 |
|
|
|
531 |
|
|
|
532 |
|
|
|
533 |
|
|
|
534 |
|
|
|
535 |
|
|
function setProperty () {
|
536 |
|
|
$numargs = func_num_args();
|
537 |
|
|
if( 1 > $numargs )
|
538 |
|
|
return FALSE;
|
539 |
|
|
$arglist = func_get_args();
|
540 |
|
|
$arglist[0] = strtoupper( $arglist[0] );
|
541 |
|
|
switch( $arglist[0] ) {
|
542 |
|
|
case 'CALSCALE':
|
543 |
|
|
return $this->setCalscale( $arglist[1] );
|
544 |
|
|
case 'METHOD':
|
545 |
|
|
return $this->setMethod( $arglist[1] );
|
546 |
|
|
case 'VERSION':
|
547 |
|
|
return $this->setVersion( $arglist[1] );
|
548 |
|
|
default:
|
549 |
|
|
if( !isset( $arglist[1] )) $arglist[1] = null;
|
550 |
|
|
if( !isset( $arglist[2] )) $arglist[2] = null;
|
551 |
|
|
return $this->setXprop( $arglist[0], $arglist[1], $arglist[2] );
|
552 |
|
|
}
|
553 |
|
|
return FALSE;
|
554 |
|
|
}
|
555 |
|
|
|
556 |
|
|
|
557 |
|
|
|
558 |
|
|
|
559 |
|
|
|
560 |
|
|
|
561 |
|
|
|
562 |
|
|
|
563 |
|
|
|
564 |
|
|
|
565 |
|
|
|
566 |
|
|
|
567 |
|
|
|
568 |
|
|
|
569 |
|
|
|
570 |
|
|
|
571 |
|
|
|
572 |
|
|
|
573 |
|
|
|
574 |
|
|
|
575 |
|
|
|
576 |
|
|
|
577 |
|
|
|
578 |
|
|
|
579 |
|
|
|
580 |
|
|
function getConfig( $config = FALSE ) {
|
581 |
|
|
if( !$config ) {
|
582 |
|
|
$return = array();
|
583 |
|
|
$return['ALLOWEMPTY'] = $this->getConfig( 'ALLOWEMPTY' );
|
584 |
|
|
$return['DELIMITER'] = $this->getConfig( 'DELIMITER' );
|
585 |
|
|
$return['DIRECTORY'] = $this->getConfig( 'DIRECTORY' );
|
586 |
|
|
$return['FILENAME'] = $this->getConfig( 'FILENAME' );
|
587 |
|
|
$return['DIRFILE'] = $this->getConfig( 'DIRFILE' );
|
588 |
|
|
$return['FILESIZE'] = $this->getConfig( 'FILESIZE' );
|
589 |
|
|
$return['FORMAT'] = $this->getConfig( 'FORMAT' );
|
590 |
|
|
if( FALSE !== ( $lang = $this->getConfig( 'LANGUAGE' )))
|
591 |
|
|
$return['LANGUAGE'] = $lang;
|
592 |
|
|
$return['NEWLINECHAR'] = $this->getConfig( 'NEWLINECHAR' );
|
593 |
|
|
$return['UNIQUE_ID'] = $this->getConfig( 'UNIQUE_ID' );
|
594 |
|
|
if( FALSE !== ( $url = $this->getConfig( 'URL' )))
|
595 |
|
|
$return['URL'] = $url;
|
596 |
|
|
$return['TZID'] = $this->getConfig( 'TZID' );
|
597 |
|
|
return $return;
|
598 |
|
|
}
|
599 |
|
|
switch( strtoupper( $config )) {
|
600 |
|
|
case 'ALLOWEMPTY':
|
601 |
|
|
return $this->allowEmpty;
|
602 |
|
|
break;
|
603 |
|
|
case 'COMPSINFO':
|
604 |
|
|
unset( $this->compix );
|
605 |
|
|
$info = array();
|
606 |
|
|
foreach( $this->components as $cix => $component ) {
|
607 |
|
|
if( empty( $component )) continue;
|
608 |
|
|
$info[$cix]['ordno'] = $cix + 1;
|
609 |
|
|
$info[$cix]['type'] = $component->objName;
|
610 |
|
|
$info[$cix]['uid'] = $component->getProperty( 'uid' );
|
611 |
|
|
$info[$cix]['props'] = $component->getConfig( 'propinfo' );
|
612 |
|
|
$info[$cix]['sub'] = $component->getConfig( 'compsinfo' );
|
613 |
|
|
}
|
614 |
|
|
return $info;
|
615 |
|
|
break;
|
616 |
|
|
case 'DELIMITER':
|
617 |
|
|
return $this->delimiter;
|
618 |
|
|
break;
|
619 |
|
|
case 'DIRECTORY':
|
620 |
|
|
if( empty( $this->directory ) && ( '0' != $this->directory ))
|
621 |
|
|
$this->directory = '.';
|
622 |
|
|
return $this->directory;
|
623 |
|
|
break;
|
624 |
|
|
case 'DIRFILE':
|
625 |
|
|
return $this->getConfig( 'directory' ).$this->getConfig( 'delimiter' ).$this->getConfig( 'filename' );
|
626 |
|
|
break;
|
627 |
|
|
case 'FILEINFO':
|
628 |
|
|
return array( $this->getConfig( 'directory' )
|
629 |
|
|
, $this->getConfig( 'filename' )
|
630 |
|
|
, $this->getConfig( 'filesize' ));
|
631 |
|
|
break;
|
632 |
|
|
case 'FILENAME':
|
633 |
|
|
if( empty( $this->filename ) && ( '0' != $this->filename )) {
|
634 |
|
|
if( 'xcal' == $this->format )
|
635 |
|
|
$this->filename = date( 'YmdHis' ).'.xml';
|
636 |
|
|
else
|
637 |
|
|
$this->filename = date( 'YmdHis' ).'.ics';
|
638 |
|
|
}
|
639 |
|
|
return $this->filename;
|
640 |
|
|
break;
|
641 |
|
|
case 'FILESIZE':
|
642 |
|
|
$size = 0;
|
643 |
|
|
if( empty( $this->url )) {
|
644 |
|
|
$dirfile = $this->getConfig( 'dirfile' );
|
645 |
|
|
if( !is_file( $dirfile ) || ( FALSE === ( $size = filesize( $dirfile ))))
|
646 |
|
|
$size = 0;
|
647 |
|
|
clearstatcache();
|
648 |
|
|
}
|
649 |
|
|
return $size;
|
650 |
|
|
break;
|
651 |
|
|
case 'FORMAT':
|
652 |
|
|
return ( $this->format == 'xcal' ) ? 'xCal' : 'iCal';
|
653 |
|
|
break;
|
654 |
|
|
case 'LANGUAGE':
|
655 |
|
|
|
656 |
|
|
return $this->language;
|
657 |
|
|
break;
|
658 |
|
|
case 'NL':
|
659 |
|
|
case 'NEWLINECHAR':
|
660 |
|
|
return $this->nl;
|
661 |
|
|
break;
|
662 |
|
|
case 'TZID':
|
663 |
|
|
return $this->dtzid;
|
664 |
|
|
break;
|
665 |
|
|
case 'UNIQUE_ID':
|
666 |
|
|
return $this->unique_id;
|
667 |
|
|
break;
|
668 |
|
|
case 'URL':
|
669 |
|
|
if( !empty( $this->url ))
|
670 |
|
|
return $this->url;
|
671 |
|
|
else
|
672 |
|
|
return FALSE;
|
673 |
|
|
break;
|
674 |
|
|
}
|
675 |
|
|
}
|
676 |
|
|
|
677 |
|
|
|
678 |
|
|
|
679 |
|
|
|
680 |
|
|
|
681 |
|
|
|
682 |
|
|
|
683 |
|
|
|
684 |
|
|
|
685 |
|
|
|
686 |
|
|
|
687 |
|
|
|
688 |
|
|
|
689 |
|
|
|
690 |
|
|
|
691 |
|
|
|
692 |
|
|
|
693 |
|
|
|
694 |
|
|
|
695 |
|
|
|
696 |
|
|
|
697 |
|
|
|
698 |
|
|
|
699 |
|
|
|
700 |
|
|
|
701 |
|
|
function setConfig( $config, $value = FALSE) {
|
702 |
|
|
if( is_array( $config )) {
|
703 |
|
|
$config = array_change_key_case( $config, CASE_UPPER );
|
704 |
|
|
if( isset( $config['DELIMITER'] )) {
|
705 |
|
|
if( FALSE === $this->setConfig( 'DELIMITER', $config['DELIMITER'] ))
|
706 |
|
|
return FALSE;
|
707 |
|
|
unset( $config['DELIMITER'] );
|
708 |
|
|
}
|
709 |
|
|
if( isset( $config['DIRECTORY'] )) {
|
710 |
|
|
if( FALSE === $this->setConfig( 'DIRECTORY', $config['DIRECTORY'] ))
|
711 |
|
|
return FALSE;
|
712 |
|
|
unset( $config['DIRECTORY'] );
|
713 |
|
|
}
|
714 |
|
|
foreach( $config as $cKey => $cValue ) {
|
715 |
|
|
if( FALSE === $this->setConfig( $cKey, $cValue ))
|
716 |
|
|
return FALSE;
|
717 |
|
|
}
|
718 |
|
|
return TRUE;
|
719 |
|
|
}
|
720 |
|
|
else
|
721 |
|
|
$res = FALSE;
|
722 |
|
|
$config = strtoupper( $config );
|
723 |
|
|
switch( $config ) {
|
724 |
|
|
case 'ALLOWEMPTY':
|
725 |
|
|
$this->allowEmpty = $value;
|
726 |
|
|
$subcfg = array( 'ALLOWEMPTY' => $value );
|
727 |
|
|
$res = TRUE;
|
728 |
|
|
break;
|
729 |
|
|
case 'DELIMITER':
|
730 |
|
|
$this->delimiter = $value;
|
731 |
|
|
return TRUE;
|
732 |
|
|
break;
|
733 |
|
|
case 'DIRECTORY':
|
734 |
|
|
if( FALSE === ( $value = realpath( rtrim( trim( $value ), $this->delimiter ))))
|
735 |
|
|
return FALSE;
|
736 |
|
|
else {
|
737 |
|
|
|
738 |
|
|
$this->directory = $value;
|
739 |
|
|
$this->url = null;
|
740 |
|
|
return TRUE;
|
741 |
|
|
}
|
742 |
|
|
break;
|
743 |
|
|
case 'FILENAME':
|
744 |
|
|
$value = trim( $value );
|
745 |
|
|
$dirfile = $this->directory.$this->delimiter.$value;
|
746 |
|
|
if( file_exists( $dirfile )) {
|
747 |
|
|
|
748 |
|
|
if( is_readable( $dirfile ) || is_writable( $dirfile )) {
|
749 |
|
|
clearstatcache();
|
750 |
|
|
$this->filename = $value;
|
751 |
|
|
return TRUE;
|
752 |
|
|
}
|
753 |
|
|
else
|
754 |
|
|
return FALSE;
|
755 |
|
|
}
|
756 |
|
|
elseif( is_readable( $this->directory ) || is_writable( $this->directory )) {
|
757 |
|
|
|
758 |
|
|
clearstatcache();
|
759 |
|
|
$this->filename = $value;
|
760 |
|
|
return TRUE;
|
761 |
|
|
}
|
762 |
|
|
else
|
763 |
|
|
return FALSE;
|
764 |
|
|
break;
|
765 |
|
|
case 'FORMAT':
|
766 |
|
|
$value = trim( strtolower( $value ));
|
767 |
|
|
if( 'xcal' == $value ) {
|
768 |
|
|
$this->format = 'xcal';
|
769 |
|
|
$this->attributeDelimiter = $this->nl;
|
770 |
|
|
$this->valueInit = null;
|
771 |
|
|
}
|
772 |
|
|
else {
|
773 |
|
|
$this->format = null;
|
774 |
|
|
$this->attributeDelimiter = ';';
|
775 |
|
|
$this->valueInit = ':';
|
776 |
|
|
}
|
777 |
|
|
$subcfg = array( 'FORMAT' => $value );
|
778 |
|
|
$res = TRUE;
|
779 |
|
|
break;
|
780 |
|
|
case 'LANGUAGE':
|
781 |
|
|
$value = trim( $value );
|
782 |
|
|
$this->language = $value;
|
783 |
|
|
$this->_makeProdid();
|
784 |
|
|
$subcfg = array( 'LANGUAGE' => $value );
|
785 |
|
|
$res = TRUE;
|
786 |
|
|
break;
|
787 |
|
|
case 'NL':
|
788 |
|
|
case 'NEWLINECHAR':
|
789 |
|
|
$this->nl = $value;
|
790 |
|
|
if( 'xcal' == $value ) {
|
791 |
|
|
$this->attributeDelimiter = $this->nl;
|
792 |
|
|
$this->valueInit = null;
|
793 |
|
|
}
|
794 |
|
|
else {
|
795 |
|
|
$this->attributeDelimiter = ';';
|
796 |
|
|
$this->valueInit = ':';
|
797 |
|
|
}
|
798 |
|
|
$subcfg = array( 'NL' => $value );
|
799 |
|
|
$res = TRUE;
|
800 |
|
|
break;
|
801 |
|
|
case 'TZID':
|
802 |
|
|
$this->dtzid = $value;
|
803 |
|
|
$subcfg = array( 'TZID' => $value );
|
804 |
|
|
$res = TRUE;
|
805 |
|
|
break;
|
806 |
|
|
case 'UNIQUE_ID':
|
807 |
|
|
$value = trim( $value );
|
808 |
|
|
$this->unique_id = $value;
|
809 |
|
|
$this->_makeProdid();
|
810 |
|
|
$subcfg = array( 'UNIQUE_ID' => $value );
|
811 |
|
|
$res = TRUE;
|
812 |
|
|
break;
|
813 |
|
|
case 'URL':
|
814 |
|
|
|
815 |
|
|
$value = str_replace( array( 'HTTP://', 'WEBCAL://', 'webcal://' ), 'http://', trim( $value ));
|
816 |
|
|
$value = str_replace( 'HTTPS://', 'https://', trim( $value ));
|
817 |
|
|
if(( 'http://' != substr( $value, 0, 7 )) && ( 'https://' != substr( $value, 0, 8 )))
|
818 |
|
|
return FALSE;
|
819 |
|
|
$this->directory = '.';
|
820 |
|
|
$this->url = $value;
|
821 |
|
|
if( '.ics' != strtolower( substr( $value, -4 )))
|
822 |
|
|
unset( $this->filename );
|
823 |
|
|
else
|
824 |
|
|
$this->filename = basename( $value );
|
825 |
|
|
return TRUE;
|
826 |
|
|
break;
|
827 |
|
|
default:
|
828 |
|
|
return TRUE;
|
829 |
|
|
}
|
830 |
|
|
if( !$res ) return FALSE;
|
831 |
|
|
if( isset( $subcfg ) && !empty( $this->components )) {
|
832 |
|
|
foreach( $subcfg as $cfgkey => $cfgvalue ) {
|
833 |
|
|
foreach( $this->components as $cix => $component ) {
|
834 |
|
|
$res = $component->setConfig( $cfgkey, $cfgvalue, TRUE );
|
835 |
|
|
if( !$res )
|
836 |
|
|
break 2;
|
837 |
|
|
$this->components[$cix] = $component->copy();
|
838 |
|
|
}
|
839 |
|
|
}
|
840 |
|
|
}
|
841 |
|
|
return $res;
|
842 |
|
|
}
|
843 |
|
|
|
844 |
|
|
|
845 |
|
|
|
846 |
|
|
|
847 |
|
|
|
848 |
|
|
|
849 |
|
|
|
850 |
|
|
|
851 |
|
|
|
852 |
|
|
|
853 |
|
|
|
854 |
|
|
|
855 |
|
|
function addComponent( $component ) {
|
856 |
|
|
$this->setComponent( $component );
|
857 |
|
|
}
|
858 |
|
|
|
859 |
|
|
|
860 |
|
|
|
861 |
|
|
|
862 |
|
|
|
863 |
|
|
|
864 |
|
|
|
865 |
|
|
|
866 |
|
|
|
867 |
|
|
|
868 |
|
|
|
869 |
|
|
|
870 |
|
|
function deleteComponent( $arg1, $arg2=FALSE ) {
|
871 |
|
|
$argType = $index = null;
|
872 |
|
|
if ( ctype_digit( (string) $arg1 )) {
|
873 |
|
|
$argType = 'INDEX';
|
874 |
|
|
$index = (int) $arg1 - 1;
|
875 |
|
|
}
|
876 |
|
|
elseif(( strlen( $arg1 ) <= strlen( 'vfreebusy' )) && ( FALSE === strpos( $arg1, '@' ))) {
|
877 |
|
|
$argType = strtolower( $arg1 );
|
878 |
|
|
$index = ( !empty( $arg2 ) && ctype_digit( (string) $arg2 )) ? (( int ) $arg2 - 1 ) : 0;
|
879 |
|
|
}
|
880 |
|
|
$cix1dC = 0;
|
881 |
|
|
foreach ( $this->components as $cix => $component) {
|
882 |
|
|
if( empty( $component )) continue;
|
883 |
|
|
if(( 'INDEX' == $argType ) && ( $index == $cix )) {
|
884 |
|
|
unset( $this->components[$cix] );
|
885 |
|
|
return TRUE;
|
886 |
|
|
}
|
887 |
|
|
elseif( $argType == $component->objName ) {
|
888 |
|
|
if( $index == $cix1dC ) {
|
889 |
|
|
unset( $this->components[$cix] );
|
890 |
|
|
return TRUE;
|
891 |
|
|
}
|
892 |
|
|
$cix1dC++;
|
893 |
|
|
}
|
894 |
|
|
elseif( !$argType && ($arg1 == $component->getProperty( 'uid' ))) {
|
895 |
|
|
unset( $this->components[$cix] );
|
896 |
|
|
return TRUE;
|
897 |
|
|
}
|
898 |
|
|
}
|
899 |
|
|
return FALSE;
|
900 |
|
|
}
|
901 |
|
|
|
902 |
|
|
|
903 |
|
|
|
904 |
|
|
|
905 |
|
|
|
906 |
|
|
|
907 |
|
|
|
908 |
|
|
|
909 |
|
|
|
910 |
|
|
|
911 |
|
|
|
912 |
|
|
|
913 |
|
|
|
914 |
|
|
|
915 |
|
|
|
916 |
|
|
|
917 |
|
|
|
918 |
|
|
|
919 |
|
|
|
920 |
|
|
function getComponent( $arg1=FALSE, $arg2=FALSE ) {
|
921 |
|
|
$index = $argType = null;
|
922 |
|
|
if ( !$arg1 ) {
|
923 |
|
|
$argType = 'INDEX';
|
924 |
|
|
$index = $this->compix['INDEX'] = ( isset( $this->compix['INDEX'] )) ? $this->compix['INDEX'] + 1 : 1;
|
925 |
|
|
}
|
926 |
|
|
elseif( is_array( $arg1 )) {
|
927 |
|
|
$arg2 = implode( '-', array_keys( $arg1 ));
|
928 |
|
|
$index = $this->compix[$arg2] = ( isset( $this->compix[$arg2] )) ? $this->compix[$arg2] + 1 : 1;
|
929 |
|
|
}
|
930 |
|
|
elseif ( ctype_digit( (string) $arg1 )) {
|
931 |
|
|
$argType = 'INDEX';
|
932 |
|
|
$index = (int) $arg1;
|
933 |
|
|
unset( $this->compix );
|
934 |
|
|
}
|
935 |
|
|
elseif(( strlen( $arg1 ) <= strlen( 'vfreebusy' )) && ( FALSE === strpos( $arg1, '@' ))) {
|
936 |
|
|
unset( $this->compix['INDEX'] );
|
937 |
|
|
$argType = strtolower( $arg1 );
|
938 |
|
|
if( !$arg2 )
|
939 |
|
|
$index = $this->compix[$argType] = ( isset( $this->compix[$argType] )) ? $this->compix[$argType] + 1 : 1;
|
940 |
|
|
elseif( isset( $arg2 ) && ctype_digit( (string) $arg2 ))
|
941 |
|
|
$index = (int) $arg2;
|
942 |
|
|
}
|
943 |
|
|
elseif(( strlen( $arg1 ) > strlen( 'vfreebusy' )) && ( FALSE !== strpos( $arg1, '@' ))) {
|
944 |
|
|
if( !$arg2 )
|
945 |
|
|
$index = $this->compix[$arg1] = ( isset( $this->compix[$arg1] )) ? $this->compix[$arg1] + 1 : 1;
|
946 |
|
|
elseif( isset( $arg2 ) && ctype_digit( (string) $arg2 ))
|
947 |
|
|
$index = (int) $arg2;
|
948 |
|
|
}
|
949 |
|
|
if( isset( $index ))
|
950 |
|
|
$index -= 1;
|
951 |
|
|
$ckeys = array_keys( $this->components );
|
952 |
|
|
if( !empty( $index) && ( $index > end( $ckeys )))
|
953 |
|
|
return FALSE;
|
954 |
|
|
$cix1gC = 0;
|
955 |
|
|
foreach ( $this->components as $cix => $component) {
|
956 |
|
|
if( empty( $component )) continue;
|
957 |
|
|
if(( 'INDEX' == $argType ) && ( $index == $cix ))
|
958 |
|
|
return $component->copy();
|
959 |
|
|
elseif( $argType == $component->objName ) {
|
960 |
|
|
if( $index == $cix1gC )
|
961 |
|
|
return $component->copy();
|
962 |
|
|
$cix1gC++;
|
963 |
|
|
}
|
964 |
|
|
elseif( is_array( $arg1 )) {
|
965 |
|
|
$hit = array();
|
966 |
|
|
$arg1 = array_change_key_case( $arg1, CASE_UPPER );
|
967 |
|
|
foreach( $arg1 as $pName => $pValue ) {
|
968 |
|
|
if( !in_array( $pName, iCalUtilityFunctions::$dateProps ) && !in_array( $pName, iCalUtilityFunctions::$otherProps ))
|
969 |
|
|
continue;
|
970 |
|
|
if( in_array( $pName, iCalUtilityFunctions::$mProps1 )) {
|
971 |
|
|
$propValues = array();
|
972 |
|
|
$component->_getProperties( $pName, $propValues );
|
973 |
|
|
$propValues = array_keys( $propValues );
|
974 |
|
|
$hit[] = ( in_array( $pValue, $propValues )) ? TRUE : FALSE;
|
975 |
|
|
continue;
|
976 |
|
|
}
|
977 |
|
|
if( FALSE === ( $value = $component->getProperty( $pName ))) {
|
978 |
|
|
$hit[] = FALSE;
|
979 |
|
|
continue;
|
980 |
|
|
}
|
981 |
|
|
if( 'SUMMARY' == $pName ) {
|
982 |
|
|
$hit[] = ( FALSE !== stripos( $value, $pValue )) ? TRUE : FALSE;
|
983 |
|
|
continue;
|
984 |
|
|
}
|
985 |
|
|
if( in_array( $pName, iCalUtilityFunctions::$dateProps )) {
|
986 |
|
|
$valuedate = sprintf( iCalUtilityFunctions::$fmt['Ymd'], (int) $value['year'], (int) $value['month'], (int) $value['day'] );
|
987 |
|
|
if( 8 < strlen( $pValue )) {
|
988 |
|
|
if( isset( $value['hour'] )) {
|
989 |
|
|
if( 'T' == substr( $pValue, 8, 1 ))
|
990 |
|
|
$pValue = str_replace( 'T', '', $pValue );
|
991 |
|
|
$valuedate .= sprintf( iCalUtilityFunctions::$fmt['His'], (int) $value['hour'], (int) $value['min'], (int) $value['sec'] );
|
992 |
|
|
}
|
993 |
|
|
else
|
994 |
|
|
$pValue = substr( $pValue, 0, 8 );
|
995 |
|
|
}
|
996 |
|
|
$hit[] = ( $pValue == $valuedate ) ? TRUE : FALSE;
|
997 |
|
|
continue;
|
998 |
|
|
}
|
999 |
|
|
elseif( !is_array( $value ))
|
1000 |
|
|
$value = array( $value );
|
1001 |
|
|
foreach( $value as $part ) {
|
1002 |
|
|
$part = ( FALSE !== strpos( $part, ',' )) ? explode( ',', $part ) : array( $part );
|
1003 |
|
|
foreach( $part as $subPart ) {
|
1004 |
|
|
if( $pValue == $subPart ) {
|
1005 |
|
|
$hit[] = TRUE;
|
1006 |
|
|
continue 3;
|
1007 |
|
|
}
|
1008 |
|
|
}
|
1009 |
|
|
}
|
1010 |
|
|
$hit[] = FALSE;
|
1011 |
|
|
}
|
1012 |
|
|
if( in_array( TRUE, $hit )) {
|
1013 |
|
|
if( $index == $cix1gC )
|
1014 |
|
|
return $component->copy();
|
1015 |
|
|
$cix1gC++;
|
1016 |
|
|
}
|
1017 |
|
|
}
|
1018 |
|
|
elseif( !$argType && ($arg1 == $component->getProperty( 'uid' ))) {
|
1019 |
|
|
if( $index == $cix1gC )
|
1020 |
|
|
return $component->copy();
|
1021 |
|
|
$cix1gC++;
|
1022 |
|
|
}
|
1023 |
|
|
}
|
1024 |
|
|
|
1025 |
|
|
unset( $this->compix );
|
1026 |
|
|
return FALSE;
|
1027 |
|
|
}
|
1028 |
|
|
|
1029 |
|
|
|
1030 |
|
|
|
1031 |
|
|
|
1032 |
|
|
|
1033 |
|
|
|
1034 |
|
|
|
1035 |
|
|
|
1036 |
|
|
|
1037 |
|
|
function & newComponent( $compType ) {
|
1038 |
|
|
$config = $this->getConfig();
|
1039 |
|
|
$keys = array_keys( $this->components );
|
1040 |
|
|
$ix = ( empty( $keys )) ? 0 : end( $keys) + 1;
|
1041 |
|
|
switch( strtoupper( $compType )) {
|
1042 |
|
|
case 'EVENT':
|
1043 |
|
|
case 'VEVENT':
|
1044 |
|
|
$this->components[$ix] = new vevent( $config );
|
1045 |
|
|
break;
|
1046 |
|
|
case 'TODO':
|
1047 |
|
|
case 'VTODO':
|
1048 |
|
|
$this->components[$ix] = new vtodo( $config );
|
1049 |
|
|
break;
|
1050 |
|
|
case 'JOURNAL':
|
1051 |
|
|
case 'VJOURNAL':
|
1052 |
|
|
$this->components[$ix] = new vjournal( $config );
|
1053 |
|
|
break;
|
1054 |
|
|
case 'FREEBUSY':
|
1055 |
|
|
case 'VFREEBUSY':
|
1056 |
|
|
$this->components[$ix] = new vfreebusy( $config );
|
1057 |
|
|
break;
|
1058 |
|
|
case 'TIMEZONE':
|
1059 |
|
|
case 'VTIMEZONE':
|
1060 |
|
|
array_unshift( $this->components, new vtimezone( $config ));
|
1061 |
|
|
$ix = 0;
|
1062 |
|
|
break;
|
1063 |
|
|
default:
|
1064 |
|
|
return FALSE;
|
1065 |
|
|
}
|
1066 |
|
|
return $this->components[$ix];
|
1067 |
|
|
}
|
1068 |
|
|
|
1069 |
|
|
|
1070 |
|
|
|
1071 |
|
|
|
1072 |
|
|
|
1073 |
|
|
|
1074 |
|
|
|
1075 |
|
|
|
1076 |
|
|
|
1077 |
|
|
|
1078 |
|
|
|
1079 |
|
|
|
1080 |
|
|
|
1081 |
|
|
|
1082 |
|
|
|
1083 |
|
|
|
1084 |
|
|
|
1085 |
|
|
|
1086 |
|
|
|
1087 |
|
|
|
1088 |
|
|
|
1089 |
|
|
|
1090 |
|
|
|
1091 |
|
|
|
1092 |
|
|
|
1093 |
|
|
|
1094 |
|
|
|
1095 |
|
|
|
1096 |
|
|
|
1097 |
|
|
|
1098 |
|
|
|
1099 |
|
|
|
1100 |
|
|
|
1101 |
|
|
|
1102 |
|
|
|
1103 |
|
|
|
1104 |
|
|
|
1105 |
|
|
|
1106 |
|
|
|
1107 |
|
|
|
1108 |
|
|
|
1109 |
|
|
|
1110 |
|
|
|
1111 |
|
|
|
1112 |
|
|
|
1113 |
|
|
|
1114 |
|
|
|
1115 |
|
|
function selectComponents( $startY=FALSE, $startM=FALSE, $startD=FALSE, $endY=FALSE, $endM=FALSE, $endD=FALSE, $cType=FALSE, $flat=FALSE, $any=TRUE, $split=TRUE ) {
|
1116 |
|
|
|
1117 |
|
|
if( 0 >= count( $this->components )) return FALSE;
|
1118 |
|
|
if( is_array( $startY ))
|
1119 |
|
|
return $this->selectComponents2( $startY );
|
1120 |
|
|
|
1121 |
|
|
if( is_a( $startY, 'DateTime' ) && is_a( $startM, 'DateTime' )) {
|
1122 |
|
|
$endY = $startM->format( 'Y' );
|
1123 |
|
|
$endM = $startM->format( 'm' );
|
1124 |
|
|
$endD = $startM->format( 'd' );
|
1125 |
|
|
$startD = $startY->format( 'd' );
|
1126 |
|
|
$startM = $startY->format( 'm' );
|
1127 |
|
|
$startY = $startY->format( 'Y' );
|
1128 |
|
|
}
|
1129 |
|
|
else {
|
1130 |
|
|
if( ! $startY ) $startY = date( 'Y' );
|
1131 |
|
|
if( ! $startM ) $startM = date( 'm' );
|
1132 |
|
|
if( ! $startD ) $startD = date( 'd' );
|
1133 |
|
|
if( ! $endY ) $endY = $startY;
|
1134 |
|
|
if( ! $endM ) $endM = $startM;
|
1135 |
|
|
if( ! $endD ) $endD = $startD;
|
1136 |
|
|
}
|
1137 |
|
|
|
1138 |
|
|
|
1139 |
|
|
if( empty( $cType ))
|
1140 |
|
|
$cType = iCalUtilityFunctions::$vComps;
|
1141 |
|
|
else {
|
1142 |
|
|
if( ! is_array( $cType ))
|
1143 |
|
|
$cType = array( $cType );
|
1144 |
|
|
$cType = array_map( 'strtolower', $cType );
|
1145 |
|
|
foreach( $cType as $cix => $theType ) {
|
1146 |
|
|
if( !in_array( $theType, iCalUtilityFunctions::$vComps ))
|
1147 |
|
|
$cType[$cix] = 'vevent';
|
1148 |
|
|
}
|
1149 |
|
|
$cType = array_unique( $cType );
|
1150 |
|
|
}
|
1151 |
|
|
if(( FALSE === $flat ) && ( FALSE === $any ))
|
1152 |
|
|
$split = FALSE;
|
1153 |
|
|
if(( TRUE === $flat ) && ( TRUE === $split ))
|
1154 |
|
|
$split = FALSE;
|
1155 |
|
|
|
1156 |
|
|
$result = array();
|
1157 |
|
|
$this->sort( 'UID' );
|
1158 |
|
|
$compUIDcmp = null;
|
1159 |
|
|
$exdatelist = $recurridList = array();
|
1160 |
|
|
$intervalP1D = new DateInterval( 'P1D' );
|
1161 |
|
|
foreach ( $this->components as $cix => $component ) {
|
1162 |
|
|
if( empty( $component )) continue;
|
1163 |
|
|
|
1164 |
|
|
if( !in_array( $component->objName, $cType ))
|
1165 |
|
|
continue;
|
1166 |
|
|
unset( $compStart, $compEnd );
|
1167 |
|
|
|
1168 |
|
|
$prop = $component->getProperty( 'dtstart', FALSE, TRUE );
|
1169 |
|
|
if( empty( $prop ) && ( $component->objName == 'vtodo' ) && ( FALSE === ( $prop = $component->getProperty( 'due', FALSE, TRUE ))))
|
1170 |
|
|
continue;
|
1171 |
|
|
if( empty( $prop ))
|
1172 |
|
|
continue;
|
1173 |
|
|
|
1174 |
|
|
$compUID = $component->getProperty( 'UID' );
|
1175 |
|
|
if( $compUIDcmp != $compUID ) {
|
1176 |
|
|
$compUIDcmp = $compUID;
|
1177 |
|
|
$exdatelist = $recurridList = array();
|
1178 |
|
|
}
|
1179 |
|
|
$recurrid = FALSE;
|
1180 |
|
|
|
1181 |
|
|
$compStart = iCaldateTime::factory( $prop['value'], $prop['params'], $prop['value'] );
|
1182 |
|
|
$dtstartTz = $compStart->getTimezoneName();
|
1183 |
|
|
if( isset( $prop['params']['VALUE'] ) && ( 'DATE' == $prop['params']['VALUE'] ))
|
1184 |
|
|
$compStartHis = '';
|
1185 |
|
|
else {
|
1186 |
|
|
$his = $compStart->getTime();
|
1187 |
|
|
$compStartHis = sprintf( iCalUtilityFunctions::$fmt['His'], (int) $his[0], (int) $his[1], (int) $his[2] );
|
1188 |
|
|
}
|
1189 |
|
|
|
1190 |
|
|
if( FALSE !== ( $prop = $component->getProperty( 'dtend', FALSE, TRUE ))) {
|
1191 |
|
|
$compEnd = iCaldateTime::factory( $prop['value'], $prop['params'], $prop['value'], $dtstartTz );
|
1192 |
|
|
$compEnd->SCbools[ 'dtendExist'] = TRUE;
|
1193 |
|
|
}
|
1194 |
|
|
if( empty( $prop ) && ( $component->objName == 'vtodo' ) && ( FALSE !== ( $prop = $component->getProperty( 'due', FALSE, TRUE )))) {
|
1195 |
|
|
$compEnd = iCaldateTime::factory( $prop['value'], $prop['params'], $prop['value'], $dtstartTz );
|
1196 |
|
|
$compEnd->SCbools[ 'dueExist'] = TRUE;
|
1197 |
|
|
}
|
1198 |
|
|
if( empty( $prop ) && ( FALSE !== ( $prop = $component->getProperty( 'duration', FALSE, TRUE, TRUE )))) {
|
1199 |
|
|
$compEnd = iCaldateTime::factory( $prop['value'], $prop['params'], $prop['value'], $dtstartTz );
|
1200 |
|
|
$compEnd->SCbools[ 'durationExist'] = TRUE;
|
1201 |
|
|
}
|
1202 |
|
|
if( ! empty( $prop ) && ! isset( $prop['value']['hour'] )) {
|
1203 |
|
|
|
1204 |
|
|
|
1205 |
|
|
$compEnd->SCbools[ 'endAllDayEvent'] = TRUE;
|
1206 |
|
|
$compEnd->modify( '-1 day' );
|
1207 |
|
|
$compEnd->setTime( 23, 59, 59 );
|
1208 |
|
|
}
|
1209 |
|
|
unset( $prop );
|
1210 |
|
|
if( empty( $compEnd )) {
|
1211 |
|
|
$compDuration = FALSE;
|
1212 |
|
|
$compEnd = clone $compStart;
|
1213 |
|
|
$compEnd->setTime( 23, 59, 59 );
|
1214 |
|
|
}
|
1215 |
|
|
else {
|
1216 |
|
|
if( $compEnd->format( 'Ymd' ) < $compStart->format( 'Ymd' )) {
|
1217 |
|
|
$compEnd = clone $compStart;
|
1218 |
|
|
$compEnd->setTime( 23, 59, 59 );
|
1219 |
|
|
}
|
1220 |
|
|
$compDuration = $compStart->diff( $compEnd );
|
1221 |
|
|
}
|
1222 |
|
|
|
1223 |
|
|
if( FALSE !== ( $prop = $component->getProperty( 'recurrence-id', FALSE, TRUE ))) {
|
1224 |
|
|
$recurrid = iCaldateTime::factory( $prop['value'], $prop['params'], $prop['value'], $dtstartTz );
|
1225 |
|
|
$rangeSet = ( isset( $prop['params']['RANGE'] ) && ( 'THISANDFUTURE' == $prop['params']['RANGE'] )) ? TRUE : FALSE;
|
1226 |
|
|
$recurridList[$recurrid->key] = array( clone $compStart, clone $compEnd, $compDuration, $rangeSet );
|
1227 |
|
|
|
1228 |
|
|
unset( $prop );
|
1229 |
|
|
continue;
|
1230 |
|
|
}
|
1231 |
|
|
|
1232 |
|
|
ksort( $recurridList, SORT_STRING );
|
1233 |
|
|
|
1234 |
|
|
$fcnStart = clone $compStart;
|
1235 |
|
|
$fcnStart->setDate((int) $startY, (int) $startM, (int) $startD );
|
1236 |
|
|
$fcnStart->setTime( 0, 0, 0 );
|
1237 |
|
|
$fcnEnd = clone $compEnd;
|
1238 |
|
|
$fcnEnd->setDate((int) $endY, (int) $endM, (int) $endD );
|
1239 |
|
|
$fcnEnd->setTime( 23, 59, 59 );
|
1240 |
|
|
|
1241 |
|
|
|
1242 |
|
|
|
1243 |
|
|
|
1244 |
|
|
$workStart = clone $compStart;
|
1245 |
|
|
$workStart->sub( $compDuration ? $compDuration : $intervalP1D );
|
1246 |
|
|
$workEnd = clone $fcnEnd;
|
1247 |
|
|
$workEnd->add( $compDuration ? $compDuration : $intervalP1D );
|
1248 |
|
|
while( FALSE !== ( $prop = $component->getProperty( 'EXRULE' ))) {
|
1249 |
|
|
$exdatelist2 = array();
|
1250 |
|
|
if( isset( $prop['UNTIL']['hour'] )) {
|
1251 |
|
|
$until = iCaldateTime::factory( $prop['UNTIL'], array( 'TZID' => 'UTC' ), null, $dtstartTz );
|
1252 |
|
|
$until = $until->format();
|
1253 |
|
|
iCalUtilityFunctions::_strDate2arr( $until );
|
1254 |
|
|
$prop['UNTIL'] = $until;
|
1255 |
|
|
}
|
1256 |
|
|
iCalUtilityFunctions::_recur2date( $exdatelist2, $prop, $compStart, $workStart, $workEnd );
|
1257 |
|
|
foreach( $exdatelist2 as $k => $v )
|
1258 |
|
|
$exdatelist[$k.$compStartHis] = $v;
|
1259 |
|
|
unset( $until, $exdatelist2 );
|
1260 |
|
|
}
|
1261 |
|
|
while( FALSE !== ( $prop = $component->getProperty( 'EXDATE', FALSE, TRUE ))) {
|
1262 |
|
|
foreach( $prop['value'] as $exdate ) {
|
1263 |
|
|
$exdate = iCaldateTime::factory( $exdate, $prop['params'], $exdate, $dtstartTz );
|
1264 |
|
|
$exdatelist[$exdate->key] = TRUE;
|
1265 |
|
|
}
|
1266 |
|
|
}
|
1267 |
|
|
unset( $prop, $exdate );
|
1268 |
|
|
|
1269 |
|
|
|
1270 |
|
|
|
1271 |
|
|
|
1272 |
|
|
$xRecurrence = 1;
|
1273 |
|
|
if(( ! $any && iCalUtilityFunctions::_inScope( $compStart, $fcnStart, $compStart, $fcnEnd, $compStart->dateFormat )) ||
|
1274 |
|
|
( $any && iCalUtilityFunctions::_inScope( $fcnEnd, $compStart, $fcnStart, $compEnd, $compStart->dateFormat ))) {
|
1275 |
|
|
|
1276 |
|
|
if( $flat ) {
|
1277 |
|
|
if( !$recurrid )
|
1278 |
|
|
$result[$compUID] = $component->copy();
|
1279 |
|
|
}
|
1280 |
|
|
elseif( $split ) {
|
1281 |
|
|
|
1282 |
|
|
if( $compStart->format( iCalUtilityFunctions::$fmt['YmdHis2'] ) < $fcnStart->format( iCalUtilityFunctions::$fmt['YmdHis2'] ))
|
1283 |
|
|
$rstart = clone $fcnStart;
|
1284 |
|
|
else
|
1285 |
|
|
$rstart = clone $compStart;
|
1286 |
|
|
if( $compEnd->format( iCalUtilityFunctions::$fmt['YmdHis2'] ) > $fcnEnd->format( iCalUtilityFunctions::$fmt['YmdHis2'] ))
|
1287 |
|
|
$rend = clone $fcnEnd;
|
1288 |
|
|
else
|
1289 |
|
|
$rend = clone $compEnd;
|
1290 |
|
|
|
1291 |
|
|
if( ! isset( $exdatelist[$rstart->key] )) {
|
1292 |
|
|
if( isset( $recurridList[$rstart->key] )) {
|
1293 |
|
|
$k = $rstart->key;
|
1294 |
|
|
|
1295 |
|
|
$rstart = clone $recurridList[$k][0];
|
1296 |
|
|
$startHis = $rstart->getTime();
|
1297 |
|
|
$rend = clone $rstart;
|
1298 |
|
|
if( FALSE !== $recurridList[$k][2] )
|
1299 |
|
|
$rend->add( $recurridList[$k][2] );
|
1300 |
|
|
elseif( FALSE !== $compDuration )
|
1301 |
|
|
$rend->add( $compDuration );
|
1302 |
|
|
$endHis = $rend->getTime();
|
1303 |
|
|
unset( $recurridList[$k] );
|
1304 |
|
|
}
|
1305 |
|
|
else {
|
1306 |
|
|
$startHis = $compStart->getTime();
|
1307 |
|
|
$endHis = $compEnd->getTime();
|
1308 |
|
|
}
|
1309 |
|
|
|
1310 |
|
|
$cnt = 0;
|
1311 |
|
|
$occurenceDays = 1 + (int) $rstart->diff( $rend )->format( '%a' );
|
1312 |
|
|
while( $rstart->format( iCalUtilityFunctions::$fmt['Ymd2'] ) <= $rend->format( iCalUtilityFunctions::$fmt['Ymd2'] )) {
|
1313 |
|
|
$cnt += 1;
|
1314 |
|
|
if( 1 < $occurenceDays )
|
1315 |
|
|
$component->setProperty( 'X-OCCURENCE', sprintf( iCalUtilityFunctions::$fmt['dayOfDays'], $cnt, $occurenceDays ));
|
1316 |
|
|
if( 1 < $cnt )
|
1317 |
|
|
$rstart->setTime( 0, 0, 0 );
|
1318 |
|
|
else {
|
1319 |
|
|
$rstart->setTime( $startHis[0], $startHis[1], $startHis[2] );
|
1320 |
|
|
$exdatelist[$rstart->key] = $compDuration;
|
1321 |
|
|
}
|
1322 |
|
|
$component->setProperty( 'X-CURRENT-DTSTART', $rstart->format( $compStart->dateFormat ));
|
1323 |
|
|
if( FALSE !== $compDuration ) {
|
1324 |
|
|
$propName = ( isset( $compEnd->SCbools[ 'dueExist'] )) ? 'X-CURRENT-DUE' : 'X-CURRENT-DTEND';
|
1325 |
|
|
if( $cnt < $occurenceDays )
|
1326 |
|
|
$rstart->setTime( 23, 59, 59 );
|
1327 |
|
|
else
|
1328 |
|
|
$rstart->setTime( $endHis[0], $endHis[1], $endHis[2] );
|
1329 |
|
|
$component->setProperty( $propName, $rstart->format( $compEnd->dateFormat ));
|
1330 |
|
|
}
|
1331 |
|
|
$result[(int)$rstart->format( 'Y' )][(int)$rstart->format( 'm' )][(int)$rstart->format( 'd' )][$compUID] = $component->copy();
|
1332 |
|
|
$rstart->add( $intervalP1D );
|
1333 |
|
|
}
|
1334 |
|
|
unset( $cnt, $occurenceDays );
|
1335 |
|
|
}
|
1336 |
|
|
|
1337 |
|
|
unset( $rstart, $rend );
|
1338 |
|
|
}
|
1339 |
|
|
else {
|
1340 |
|
|
$tstart = ( isset( $recurridList[$compStart->key] )) ? clone $recurridList[$k][0] : clone $compStart;
|
1341 |
|
|
|
1342 |
|
|
if( ! $any || ! isset( $exdatelist[$tstart->key] )) {
|
1343 |
|
|
|
1344 |
|
|
$result[(int)$tstart->format( 'Y' )][(int)$tstart->format( 'm' )][(int)$tstart->format( 'd' )][$compUID] = $component->copy();
|
1345 |
|
|
}
|
1346 |
|
|
unset( $tstart );
|
1347 |
|
|
}
|
1348 |
|
|
}
|
1349 |
|
|
|
1350 |
|
|
|
1351 |
|
|
|
1352 |
|
|
if( TRUE === $any ) {
|
1353 |
|
|
$recurlist = array();
|
1354 |
|
|
|
1355 |
|
|
while( FALSE !== ( $prop = $component->getProperty( 'RRULE' ))) {
|
1356 |
|
|
$recurlist2 = array();
|
1357 |
|
|
if( isset( $prop['UNTIL']['hour'] )) {
|
1358 |
|
|
$until = iCaldateTime::factory( $prop['UNTIL'], array( 'TZID' => 'UTC' ), null, $dtstartTz );
|
1359 |
|
|
$until = $until->format();
|
1360 |
|
|
iCalUtilityFunctions::_strDate2arr( $until );
|
1361 |
|
|
$prop['UNTIL'] = $until;
|
1362 |
|
|
}
|
1363 |
|
|
iCalUtilityFunctions::_recur2date( $recurlist2, $prop, $compStart, $workStart, $workEnd );
|
1364 |
|
|
foreach( $recurlist2 as $recurkey => $recurvalue ) {
|
1365 |
|
|
$recurkey .= $compStartHis;
|
1366 |
|
|
if( ! isset( $exdatelist[$recurkey] ))
|
1367 |
|
|
$recurlist[$recurkey] = $compDuration;
|
1368 |
|
|
}
|
1369 |
|
|
unset( $prop, $until, $recurlist2 );
|
1370 |
|
|
}
|
1371 |
|
|
$workStart = clone $fcnStart;
|
1372 |
|
|
$workStart->sub( $compDuration ? $compDuration : $intervalP1D );
|
1373 |
|
|
$format = $compStart->dateFormat;
|
1374 |
|
|
while( FALSE !== ( $prop = $component->getProperty( 'RDATE', FALSE, TRUE ))) {
|
1375 |
|
|
$rdateFmt = ( isset( $prop['params']['VALUE'] )) ? $prop['params']['VALUE'] : 'DATETIME';
|
1376 |
|
|
$params = $prop['params'];
|
1377 |
|
|
$prop = $prop['value'];
|
1378 |
|
|
foreach( $prop as $theRdate ) {
|
1379 |
|
|
if( 'PERIOD' == $rdateFmt ) {
|
1380 |
|
|
$rdate = iCaldateTime::factory( $theRdate[0], $params, $theRdate[0], $dtstartTz );
|
1381 |
|
|
if( ! iCalUtilityFunctions::_inScope( $rdate, $workStart, $rdate, $fcnEnd, $format ) || isset( $exdatelist[$rdate->key] ))
|
1382 |
|
|
continue;
|
1383 |
|
|
if( isset( $theRdate[1]['year'] ))
|
1384 |
|
|
$recurlist[$rdate->key] = $rdate->diff( iCaldateTime::factory( $theRdate[1], $params, $theRdate[1], $dtstartTz ));
|
1385 |
|
|
else
|
1386 |
|
|
$recurlist[$rdate->key] = new DateInterval( iCalUtilityFunctions::_duration2str( $theRdate[1] ));
|
1387 |
|
|
}
|
1388 |
|
|
elseif( 'DATE' == $rdateFmt ) {
|
1389 |
|
|
$rdate = iCaldateTime::factory( $theRdate, array_merge( $params, array( 'TZID' => $dtstartTz )), null, $dtstartTz );
|
1390 |
|
|
if( iCalUtilityFunctions::_inScope( $rdate, $workStart, $rdate, $fcnEnd, $format ) && ! isset( $exdatelist[$rdate->key] ))
|
1391 |
|
|
$recurlist[$rdate->key.$compStartHis] = $compDuration;
|
1392 |
|
|
}
|
1393 |
|
|
else {
|
1394 |
|
|
$rdate = iCaldateTime::factory( $theRdate, $params, $theRdate, $dtstartTz );
|
1395 |
|
|
if( iCalUtilityFunctions::_inScope( $rdate, $workStart, $rdate, $fcnEnd, $format ) && ! isset( $exdatelist[$rdate->key] ))
|
1396 |
|
|
$recurlist[$rdate->key] = $compDuration;
|
1397 |
|
|
}
|
1398 |
|
|
}
|
1399 |
|
|
}
|
1400 |
|
|
unset( $prop, $workStart, $format, $theRdate, $rdate, $rend );
|
1401 |
|
|
foreach( $recurridList as $rKey => $rVal ) {
|
1402 |
|
|
if( isset( $recurlist[$rKey] )) {
|
1403 |
|
|
unset( $recurlist[$rKey] );
|
1404 |
|
|
$recurlist[$rVal[0]->key] = ( FALSE !== $rVal[2] ) ? $rVal[2] : $compDuration;
|
1405 |
|
|
|
1406 |
|
|
}
|
1407 |
|
|
}
|
1408 |
|
|
ksort( $recurlist, SORT_STRING );
|
1409 |
|
|
|
1410 |
|
|
|
1411 |
|
|
|
1412 |
|
|
|
1413 |
|
|
|
1414 |
|
|
if( 0 < count( $recurlist )) {
|
1415 |
|
|
$component2 = $component->copy();
|
1416 |
|
|
$compUID = $component2->getProperty( 'UID' );
|
1417 |
|
|
$workStart = clone $fcnStart;
|
1418 |
|
|
$workStart->sub( $compDuration ? $compDuration : $intervalP1D );
|
1419 |
|
|
$YmdOld = null;
|
1420 |
|
|
foreach( $recurlist as $recurkey => $durvalue ) {
|
1421 |
|
|
if( $YmdOld == substr( $recurkey, 0, 8 ))
|
1422 |
|
|
continue;
|
1423 |
|
|
$YmdOld = substr( $recurkey, 0, 8 );
|
1424 |
|
|
$rstart = clone $compStart;
|
1425 |
|
|
$rstart->setDate((int) substr( $recurkey, 0, 4 ), (int) substr( $recurkey, 4, 2 ), (int) substr( $recurkey, 6, 2 ));
|
1426 |
|
|
$rstart->setTime((int) substr( $recurkey, 8, 2 ), (int) substr( $recurkey, 10, 2 ), (int) substr( $recurkey, 12, 2 ));
|
1427 |
|
|
|
1428 |
|
|
|
1429 |
|
|
if( $flat ) {
|
1430 |
|
|
if( !isset( $result[$compUID] ))
|
1431 |
|
|
$result[$compUID] = $component2->copy();
|
1432 |
|
|
}
|
1433 |
|
|
|
1434 |
|
|
elseif( $split ) {
|
1435 |
|
|
$rend = clone $rstart;
|
1436 |
|
|
if( FALSE !== $durvalue )
|
1437 |
|
|
$rend->add( $durvalue );
|
1438 |
|
|
if( $rend->format( iCalUtilityFunctions::$fmt['Ymd2'] ) > $fcnEnd->format( iCalUtilityFunctions::$fmt['Ymd2'] ))
|
1439 |
|
|
$rend = clone $fcnEnd;
|
1440 |
|
|
|
1441 |
|
|
$xRecurrence += 1;
|
1442 |
|
|
$cnt = 0;
|
1443 |
|
|
$occurenceDays = 1 + (int) $rstart->diff( $rend )->format( '%a' );
|
1444 |
|
|
while( $rstart->format( iCalUtilityFunctions::$fmt['Ymd2'] ) <= $rend->format( iCalUtilityFunctions::$fmt['Ymd2'] )) {
|
1445 |
|
|
$cnt += 1;
|
1446 |
|
|
if( $rstart->format( iCalUtilityFunctions::$fmt['Ymd2'] ) < $fcnStart->format( iCalUtilityFunctions::$fmt['Ymd2'] )) {
|
1447 |
|
|
|
1448 |
|
|
$rstart->add( $intervalP1D );
|
1449 |
|
|
$rstart->setTime( 0, 0, 0 );
|
1450 |
|
|
continue;
|
1451 |
|
|
}
|
1452 |
|
|
elseif( 2 == $cnt )
|
1453 |
|
|
$rstart->setTime( 0, 0, 0 );
|
1454 |
|
|
$component2->setProperty( 'X-RECURRENCE', $xRecurrence );
|
1455 |
|
|
if( 1 < $occurenceDays )
|
1456 |
|
|
$component2->setProperty( 'X-OCCURENCE', sprintf( iCalUtilityFunctions::$fmt['dayOfDays'], $cnt, $occurenceDays ));
|
1457 |
|
|
else
|
1458 |
|
|
$component2->deleteProperty( 'X-OCCURENCE' );
|
1459 |
|
|
$component2->setProperty( 'X-CURRENT-DTSTART', $rstart->format( $compStart->dateFormat ));
|
1460 |
|
|
$propName = ( isset( $compEnd->SCbools[ 'dueExist'] )) ? 'X-CURRENT-DUE' : 'X-CURRENT-DTEND';
|
1461 |
|
|
if( FALSE !== $durvalue ) {
|
1462 |
|
|
if( $cnt < $occurenceDays )
|
1463 |
|
|
$rstart->setTime( 23, 59, 59 );
|
1464 |
|
|
else {
|
1465 |
|
|
$His = $rend->getTime();
|
1466 |
|
|
$rstart->setTime( $His[0], $His[1], $His[2] );
|
1467 |
|
|
}
|
1468 |
|
|
$component2->setProperty( $propName, $rstart->format( $compEnd->dateFormat ));
|
1469 |
|
|
|
1470 |
|
|
}
|
1471 |
|
|
else
|
1472 |
|
|
$component2->deleteProperty( $propName );
|
1473 |
|
|
$result[(int)$rstart->format( 'Y' )][(int)$rstart->format( 'm' )][(int)$rstart->format( 'd' )][$compUID] = $component2->copy();
|
1474 |
|
|
$rstart->add( $intervalP1D );
|
1475 |
|
|
}
|
1476 |
|
|
unset( $rstart, $rend );
|
1477 |
|
|
}
|
1478 |
|
|
elseif( $rstart->format( iCalUtilityFunctions::$fmt['Ymd2'] ) >= $fcnStart->format( iCalUtilityFunctions::$fmt['Ymd2'] )) {
|
1479 |
|
|
$xRecurrence += 1;
|
1480 |
|
|
$component2->setProperty( 'X-RECURRENCE', $xRecurrence );
|
1481 |
|
|
$component2->setProperty( 'X-CURRENT-DTSTART', $rstart->format( $compStart->dateFormat ));
|
1482 |
|
|
$propName = ( isset( $compEnd->SCbools[ 'dueExist'] )) ? 'X-CURRENT-DUE' : 'X-CURRENT-DTEND';
|
1483 |
|
|
if( FALSE !== $durvalue ) {
|
1484 |
|
|
$rstart->add( $durvalue );
|
1485 |
|
|
$component2->setProperty( $propName, $rstart->format( $compEnd->dateFormat ));
|
1486 |
|
|
}
|
1487 |
|
|
else
|
1488 |
|
|
$component2->deleteProperty( $propName );
|
1489 |
|
|
$result[(int)$rstart->format( 'Y' )][(int)$rstart->format( 'm' )][(int)$rstart->format( 'd' )][$compUID] = $component2->copy();
|
1490 |
|
|
}
|
1491 |
|
|
unset( $rstart );
|
1492 |
|
|
}
|
1493 |
|
|
unset( $component2, $xRecurrence, $compUID, $workStart, $rstart );
|
1494 |
|
|
}
|
1495 |
|
|
}
|
1496 |
|
|
unset( $component );
|
1497 |
|
|
}
|
1498 |
|
|
unset( $recurrid, $recurridList, $fcnStart, $fcnEnd, $compStart, $compEnd, $exdatelist, $recurlist );
|
1499 |
|
|
if( 0 >= count( $result ))
|
1500 |
|
|
return FALSE;
|
1501 |
|
|
elseif( !$flat ) {
|
1502 |
|
|
foreach( $result as $y => $yeararr ) {
|
1503 |
|
|
foreach( $yeararr as $m => $montharr ) {
|
1504 |
|
|
foreach( $montharr as $d => $dayarr ) {
|
1505 |
|
|
if( empty( $result[$y][$m][$d] ))
|
1506 |
|
|
unset( $result[$y][$m][$d] );
|
1507 |
|
|
else {
|
1508 |
|
|
$result[$y][$m][$d] = array_values( $dayarr );
|
1509 |
|
|
if( 1 < count( $result[$y][$m][$d] )) {
|
1510 |
|
|
foreach( $result[$y][$m][$d] as & $c )
|
1511 |
|
|
iCalUtilityFunctions::_setSortArgs( $c );
|
1512 |
|
|
usort( $result[$y][$m][$d], array( 'iCalUtilityFunctions', '_cmpfcn' ));
|
1513 |
|
|
}
|
1514 |
|
|
}
|
1515 |
|
|
}
|
1516 |
|
|
if( empty( $result[$y][$m] ))
|
1517 |
|
|
unset( $result[$y][$m] );
|
1518 |
|
|
else
|
1519 |
|
|
ksort( $result[$y][$m] );
|
1520 |
|
|
}
|
1521 |
|
|
if( empty( $result[$y] ))
|
1522 |
|
|
unset( $result[$y] );
|
1523 |
|
|
else
|
1524 |
|
|
ksort( $result[$y] );
|
1525 |
|
|
}
|
1526 |
|
|
if( empty( $result ))
|
1527 |
|
|
unset( $result );
|
1528 |
|
|
else
|
1529 |
|
|
ksort( $result );
|
1530 |
|
|
}
|
1531 |
|
|
if( 0 >= count( $result ))
|
1532 |
|
|
return FALSE;
|
1533 |
|
|
return $result;
|
1534 |
|
|
}
|
1535 |
|
|
|
1536 |
|
|
|
1537 |
|
|
|
1538 |
|
|
|
1539 |
|
|
|
1540 |
|
|
|
1541 |
|
|
|
1542 |
|
|
|
1543 |
|
|
|
1544 |
|
|
|
1545 |
|
|
|
1546 |
|
|
|
1547 |
|
|
|
1548 |
|
|
|
1549 |
|
|
|
1550 |
|
|
|
1551 |
|
|
function selectComponents2( $selectOptions ) {
|
1552 |
|
|
|
1553 |
|
|
$selectOptions = array_change_key_case( $selectOptions, CASE_UPPER );
|
1554 |
|
|
foreach( $this->components as $cix => $component3 ) {
|
1555 |
|
|
if( !in_array( $component3->objName, iCalUtilityFunctions::$vComps ))
|
1556 |
|
|
continue;
|
1557 |
|
|
$uid = $component3->getProperty( 'UID' );
|
1558 |
|
|
foreach( $selectOptions as $propName => $pvalue ) {
|
1559 |
|
|
if( !in_array( $propName, iCalUtilityFunctions::$otherProps ))
|
1560 |
|
|
continue;
|
1561 |
|
|
if( !is_array( $pvalue ))
|
1562 |
|
|
$pvalue = array( $pvalue );
|
1563 |
|
|
if(( 'UID' == $propName ) && in_array( $uid, $pvalue )) {
|
1564 |
|
|
$output[$uid][] = $component3->copy();
|
1565 |
|
|
continue;
|
1566 |
|
|
}
|
1567 |
|
|
elseif( in_array( $propName, iCalUtilityFunctions::$mProps1 )) {
|
1568 |
|
|
$propValues = array();
|
1569 |
|
|
$component3->_getProperties( $propName, $propValues );
|
1570 |
|
|
$propValues = array_keys( $propValues );
|
1571 |
|
|
foreach( $pvalue as $theValue ) {
|
1572 |
|
|
if( in_array( $theValue, $propValues )) {
|
1573 |
|
|
$output[$uid][] = $component3->copy();
|
1574 |
|
|
break;
|
1575 |
|
|
}
|
1576 |
|
|
}
|
1577 |
|
|
continue;
|
1578 |
|
|
}
|
1579 |
|
|
elseif( FALSE === ( $d = $component3->getProperty( $propName )))
|
1580 |
|
|
continue;
|
1581 |
|
|
if( is_array( $d )) {
|
1582 |
|
|
foreach( $d as $part ) {
|
1583 |
|
|
if( in_array( $part, $pvalue ) && !isset( $output[$uid] ))
|
1584 |
|
|
$output[$uid][] = $component3->copy();
|
1585 |
|
|
}
|
1586 |
|
|
}
|
1587 |
|
|
elseif(( 'SUMMARY' == $propName ) && !isset( $output[$uid] )) {
|
1588 |
|
|
foreach( $pvalue as $pval ) {
|
1589 |
|
|
if( FALSE !== stripos( $d, $pval )) {
|
1590 |
|
|
$output[$uid][] = $component3->copy();
|
1591 |
|
|
break;
|
1592 |
|
|
}
|
1593 |
|
|
}
|
1594 |
|
|
}
|
1595 |
|
|
elseif( in_array( $d, $pvalue ) && !isset( $output[$uid] ))
|
1596 |
|
|
$output[$uid][] = $component3->copy();
|
1597 |
|
|
}
|
1598 |
|
|
}
|
1599 |
|
|
if( !empty( $output )) {
|
1600 |
|
|
ksort( $output );
|
1601 |
|
|
$output2 = array();
|
1602 |
|
|
foreach( $output as $uid => $components ) {
|
1603 |
|
|
foreach( $components as $component )
|
1604 |
|
|
$output2[] = $component;
|
1605 |
|
|
}
|
1606 |
|
|
$output = $output2;
|
1607 |
|
|
}
|
1608 |
|
|
return $output;
|
1609 |
|
|
}
|
1610 |
|
|
|
1611 |
|
|
|
1612 |
|
|
|
1613 |
|
|
|
1614 |
|
|
|
1615 |
|
|
|
1616 |
|
|
|
1617 |
|
|
|
1618 |
|
|
|
1619 |
|
|
|
1620 |
|
|
|
1621 |
|
|
|
1622 |
|
|
function replaceComponent( $component ) {
|
1623 |
|
|
if( in_array( $component->objName, iCalUtilityFunctions::$vComps ))
|
1624 |
|
|
return $this->setComponent( $component, $component->getProperty( 'UID' ));
|
1625 |
|
|
if(( 'vtimezone' != $component->objName ) || ( FALSE === ( $tzid = $component->getProperty( 'TZID' ))))
|
1626 |
|
|
return FALSE;
|
1627 |
|
|
foreach( $this->components as $cix => $comp ) {
|
1628 |
|
|
if( 'vtimezone' != $component->objName )
|
1629 |
|
|
continue;
|
1630 |
|
|
if( $tzid == $comp->getComponent( 'TZID' )) {
|
1631 |
|
|
unset( $component->propix, $component->compix );
|
1632 |
|
|
$this->components[$cix] = $component;
|
1633 |
|
|
return TRUE;
|
1634 |
|
|
}
|
1635 |
|
|
}
|
1636 |
|
|
return FALSE;
|
1637 |
|
|
}
|
1638 |
|
|
|
1639 |
|
|
|
1640 |
|
|
|
1641 |
|
|
|
1642 |
|
|
|
1643 |
|
|
|
1644 |
|
|
|
1645 |
|
|
|
1646 |
|
|
|
1647 |
|
|
|
1648 |
|
|
|
1649 |
|
|
|
1650 |
|
|
|
1651 |
|
|
|
1652 |
|
|
|
1653 |
|
|
|
1654 |
|
|
|
1655 |
|
|
function setComponent( $component, $arg1=FALSE, $arg2=FALSE ) {
|
1656 |
|
|
$component->setConfig( $this->getConfig(), FALSE, TRUE );
|
1657 |
|
|
if( !in_array( $component->objName, array( 'valarm', 'vtimezone' ))) {
|
1658 |
|
|
|
1659 |
|
|
$dummy1 = $component->getProperty( 'dtstamp' );
|
1660 |
|
|
$dummy2 = $component->getProperty( 'uid' );
|
1661 |
|
|
}
|
1662 |
|
|
unset( $component->propix, $component->compix );
|
1663 |
|
|
if( !$arg1 ) {
|
1664 |
|
|
$this->components[] = $component->copy();
|
1665 |
|
|
return TRUE;
|
1666 |
|
|
}
|
1667 |
|
|
$argType = $index = null;
|
1668 |
|
|
if ( ctype_digit( (string) $arg1 )) {
|
1669 |
|
|
$argType = 'INDEX';
|
1670 |
|
|
$index = (int) $arg1 - 1;
|
1671 |
|
|
}
|
1672 |
|
|
elseif( in_array( strtolower( $arg1 ), iCalUtilityFunctions::$mComps )) {
|
1673 |
|
|
$argType = strtolower( $arg1 );
|
1674 |
|
|
$index = ( ctype_digit( (string) $arg2 )) ? ((int) $arg2) - 1 : 0;
|
1675 |
|
|
}
|
1676 |
|
|
|
1677 |
|
|
$cix1sC = 0;
|
1678 |
|
|
foreach ( $this->components as $cix => $component2) {
|
1679 |
|
|
if( empty( $component2 )) continue;
|
1680 |
|
|
if(( 'INDEX' == $argType ) && ( $index == $cix )) {
|
1681 |
|
|
$this->components[$cix] = $component->copy();
|
1682 |
|
|
return TRUE;
|
1683 |
|
|
}
|
1684 |
|
|
elseif( $argType == $component2->objName ) {
|
1685 |
|
|
if( $index == $cix1sC ) {
|
1686 |
|
|
$this->components[$cix] = $component->copy();
|
1687 |
|
|
return TRUE;
|
1688 |
|
|
}
|
1689 |
|
|
$cix1sC++;
|
1690 |
|
|
}
|
1691 |
|
|
elseif( !$argType && ( $arg1 == $component2->getProperty( 'uid' ))) {
|
1692 |
|
|
$this->components[$cix] = $component->copy();
|
1693 |
|
|
return TRUE;
|
1694 |
|
|
}
|
1695 |
|
|
}
|
1696 |
|
|
|
1697 |
|
|
if( 'INDEX' == $argType ) {
|
1698 |
|
|
$this->components[$index] = $component->copy();
|
1699 |
|
|
ksort( $this->components, SORT_NUMERIC );
|
1700 |
|
|
}
|
1701 |
|
|
else
|
1702 |
|
|
$this->components[] = $component->copy();
|
1703 |
|
|
return TRUE;
|
1704 |
|
|
}
|
1705 |
|
|
|
1706 |
|
|
|
1707 |
|
|
|
1708 |
|
|
|
1709 |
|
|
|
1710 |
|
|
|
1711 |
|
|
|
1712 |
|
|
|
1713 |
|
|
|
1714 |
|
|
|
1715 |
|
|
|
1716 |
|
|
|
1717 |
|
|
|
1718 |
|
|
|
1719 |
|
|
|
1720 |
|
|
|
1721 |
|
|
function sort( $sortArg=FALSE ) {
|
1722 |
|
|
if( ! is_array( $this->components ) || ( 2 > count( $this->components )))
|
1723 |
|
|
return;
|
1724 |
|
|
if( $sortArg ) {
|
1725 |
|
|
$sortArg = strtoupper( $sortArg );
|
1726 |
|
|
if( ! in_array( $sortArg, iCalUtilityFunctions::$otherProps ) && ( 'DTSTAMP' != $sortArg ))
|
1727 |
|
|
$sortArg = FALSE;
|
1728 |
|
|
}
|
1729 |
|
|
foreach( $this->components as & $c )
|
1730 |
|
|
iCalUtilityFunctions::_setSortArgs( $c, $sortArg );
|
1731 |
|
|
usort( $this->components, array( 'iCalUtilityFunctions', '_cmpfcn' ));
|
1732 |
|
|
}
|
1733 |
|
|
|
1734 |
|
|
|
1735 |
|
|
|
1736 |
|
|
|
1737 |
|
|
|
1738 |
|
|
|
1739 |
|
|
|
1740 |
|
|
|
1741 |
|
|
|
1742 |
|
|
|
1743 |
|
|
|
1744 |
|
|
|
1745 |
|
|
|
1746 |
|
|
|
1747 |
|
|
|
1748 |
|
|
|
1749 |
|
|
|
1750 |
|
|
|
1751 |
|
|
|
1752 |
|
|
|
1753 |
|
|
|
1754 |
|
|
|
1755 |
|
|
|
1756 |
|
|
|
1757 |
|
|
function parse( $unparsedtext=FALSE, $context=null ) {
|
1758 |
|
|
$nl = $this->getConfig( 'nl' );
|
1759 |
|
|
if(( FALSE === $unparsedtext ) || empty( $unparsedtext )) {
|
1760 |
|
|
|
1761 |
|
|
if( FALSE === ( $file = $this->getConfig( 'url' ))) {
|
1762 |
|
|
if( FALSE === ( $file = $this->getConfig( 'dirfile' )))
|
1763 |
|
|
return FALSE;
|
1764 |
|
|
if( ! is_file( $file ))
|
1765 |
|
|
return FALSE;
|
1766 |
|
|
if( ! is_readable( $file ))
|
1767 |
|
|
return FALSE;
|
1768 |
|
|
}
|
1769 |
|
|
|
1770 |
|
|
if( ! empty( $context ) && filter_var( $file, FILTER_VALIDATE_URL ) &&
|
1771 |
|
|
( FALSE === ( $rows = file_get_contents( $file, FALSE, $context ))))
|
1772 |
|
|
return FALSE;
|
1773 |
|
|
elseif( FALSE === ( $rows = file_get_contents( $file )))
|
1774 |
|
|
return FALSE;
|
1775 |
|
|
}
|
1776 |
|
|
elseif( is_array( $unparsedtext ))
|
1777 |
|
|
$rows = implode( '\n'.$nl, $unparsedtext );
|
1778 |
|
|
else
|
1779 |
|
|
$rows = & $unparsedtext;
|
1780 |
|
|
|
1781 |
|
|
$rows = iCalUtilityFunctions::convEolChar( $rows, $nl );
|
1782 |
|
|
|
1783 |
|
|
foreach( $rows as $lix => $line ) {
|
1784 |
|
|
if( FALSE !== stripos( $line, 'BEGIN:VCALENDAR' )) {
|
1785 |
|
|
$rows[$lix] = 'BEGIN:VCALENDAR';
|
1786 |
|
|
break;
|
1787 |
|
|
}
|
1788 |
|
|
unset( $rows[$lix] );
|
1789 |
|
|
}
|
1790 |
|
|
$rcnt = count( $rows );
|
1791 |
|
|
if( 3 > $rcnt )
|
1792 |
|
|
return FALSE;
|
1793 |
|
|
|
1794 |
|
|
$lix = array_keys( $rows );
|
1795 |
|
|
$lix = end( $lix );
|
1796 |
|
|
while( 3 < $lix ) {
|
1797 |
|
|
$tst = trim( $rows[$lix] );
|
1798 |
|
|
if(( '\n' == $tst ) || empty( $tst )) {
|
1799 |
|
|
unset( $rows[$lix] );
|
1800 |
|
|
$lix--;
|
1801 |
|
|
continue;
|
1802 |
|
|
}
|
1803 |
|
|
if( FALSE === stripos( $rows[$lix], 'END:VCALENDAR' ))
|
1804 |
|
|
$rows[] = 'END:VCALENDAR';
|
1805 |
|
|
else
|
1806 |
|
|
$rows[$lix] = 'END:VCALENDAR';
|
1807 |
|
|
break;
|
1808 |
|
|
}
|
1809 |
|
|
$comp = & $this;
|
1810 |
|
|
$calsync = $compsync = 0;
|
1811 |
|
|
|
1812 |
|
|
$config = $this->getConfig();
|
1813 |
|
|
$endtxt = array( 'END:VE', 'END:VF', 'END:VJ', 'END:VT' );
|
1814 |
|
|
foreach( $rows as $lix => $line ) {
|
1815 |
|
|
if( 'BEGIN:VCALENDAR' == strtoupper( substr( $line, 0, 15 ))) {
|
1816 |
|
|
$calsync++;
|
1817 |
|
|
continue;
|
1818 |
|
|
}
|
1819 |
|
|
elseif( 'END:VCALENDAR' == strtoupper( substr( $line, 0, 13 ))) {
|
1820 |
|
|
if( 0 < $compsync )
|
1821 |
|
|
$this->components[] = $comp->copy();
|
1822 |
|
|
$compsync--;
|
1823 |
|
|
$calsync--;
|
1824 |
|
|
break;
|
1825 |
|
|
}
|
1826 |
|
|
elseif( 1 != $calsync )
|
1827 |
|
|
return FALSE;
|
1828 |
|
|
elseif( in_array( strtoupper( substr( $line, 0, 6 )), $endtxt )) {
|
1829 |
|
|
$this->components[] = $comp->copy();
|
1830 |
|
|
$compsync--;
|
1831 |
|
|
continue;
|
1832 |
|
|
}
|
1833 |
|
|
if( 'BEGIN:VEVENT' == strtoupper( substr( $line, 0, 12 ))) {
|
1834 |
|
|
$comp = new vevent( $config );
|
1835 |
|
|
$compsync++;
|
1836 |
|
|
}
|
1837 |
|
|
elseif( 'BEGIN:VFREEBUSY' == strtoupper( substr( $line, 0, 15 ))) {
|
1838 |
|
|
$comp = new vfreebusy( $config );
|
1839 |
|
|
$compsync++;
|
1840 |
|
|
}
|
1841 |
|
|
elseif( 'BEGIN:VJOURNAL' == strtoupper( substr( $line, 0, 14 ))) {
|
1842 |
|
|
$comp = new vjournal( $config );
|
1843 |
|
|
$compsync++;
|
1844 |
|
|
}
|
1845 |
|
|
elseif( 'BEGIN:VTODO' == strtoupper( substr( $line, 0, 11 ))) {
|
1846 |
|
|
$comp = new vtodo( $config );
|
1847 |
|
|
$compsync++;
|
1848 |
|
|
}
|
1849 |
|
|
elseif( 'BEGIN:VTIMEZONE' == strtoupper( substr( $line, 0, 15 ))) {
|
1850 |
|
|
$comp = new vtimezone( $config );
|
1851 |
|
|
$compsync++;
|
1852 |
|
|
}
|
1853 |
|
|
else {
|
1854 |
|
|
$comp->unparsed[] = $line;
|
1855 |
|
|
}
|
1856 |
|
|
}
|
1857 |
|
|
unset( $config, $endtxt );
|
1858 |
|
|
|
1859 |
|
|
if( isset( $this->unparsed ) && is_array( $this->unparsed ) && ( 0 < count( $this->unparsed ))) {
|
1860 |
|
|
|
1861 |
|
|
$propnames = array( 'calscale','method','prodid','version','x-' );
|
1862 |
|
|
$proprows = array();
|
1863 |
|
|
for( $i = 0; $i < count( $this->unparsed ); $i++ ) {
|
1864 |
|
|
$line = rtrim( $this->unparsed[$i], $nl );
|
1865 |
|
|
while( isset( $this->unparsed[$i+1] ) && !empty( $this->unparsed[$i+1] ) && ( ' ' == $this->unparsed[$i+1]{0} ))
|
1866 |
|
|
$line .= rtrim( substr( $this->unparsed[++$i], 1 ), $nl );
|
1867 |
|
|
$proprows[] = $line;
|
1868 |
|
|
}
|
1869 |
|
|
foreach( $proprows as $line ) {
|
1870 |
|
|
if( '\n' == substr( $line, -2 ))
|
1871 |
|
|
$line = substr( $line, 0, -2 );
|
1872 |
|
|
|
1873 |
|
|
$propname = '';
|
1874 |
|
|
$cix = 0;
|
1875 |
|
|
while( FALSE !== ( $char = substr( $line, $cix, 1 ))) {
|
1876 |
|
|
if( in_array( $char, array( ':', ';' )))
|
1877 |
|
|
break;
|
1878 |
|
|
else
|
1879 |
|
|
$propname .= $char;
|
1880 |
|
|
$cix++;
|
1881 |
|
|
}
|
1882 |
|
|
|
1883 |
|
|
if(( 'x-' != strtolower( substr( $propname, 0, 2 ))) && !in_array( strtolower( $propname ), $propnames ))
|
1884 |
|
|
continue;
|
1885 |
|
|
|
1886 |
|
|
if( in_array( strtolower( $propname ), array( 'version', 'prodid' )))
|
1887 |
|
|
continue;
|
1888 |
|
|
|
1889 |
|
|
$line = substr( $line, $cix);
|
1890 |
|
|
|
1891 |
|
|
iCalUtilityFunctions::_splitContent( $line, $propAttr );
|
1892 |
|
|
|
1893 |
|
|
if( FALSE !== strpos( $line, ',' )) {
|
1894 |
|
|
$content = array( 0 => '' );
|
1895 |
|
|
$cix = $lix = 0;
|
1896 |
|
|
while( FALSE !== substr( $line, $lix, 1 )) {
|
1897 |
|
|
if(( 0 < $lix ) && ( ',' == $line[$lix] ) && ( "\\" != $line[( $lix - 1 )])) {
|
1898 |
|
|
$cix++;
|
1899 |
|
|
$content[$cix] = '';
|
1900 |
|
|
}
|
1901 |
|
|
else
|
1902 |
|
|
$content[$cix] .= $line[$lix];
|
1903 |
|
|
$lix++;
|
1904 |
|
|
}
|
1905 |
|
|
if( 1 < count( $content )) {
|
1906 |
|
|
foreach( $content as $cix => $contentPart )
|
1907 |
|
|
$content[$cix] = iCalUtilityFunctions::_strunrep( $contentPart );
|
1908 |
|
|
$this->setProperty( $propname, $content, $propAttr );
|
1909 |
|
|
continue;
|
1910 |
|
|
}
|
1911 |
|
|
else
|
1912 |
|
|
$line = reset( $content );
|
1913 |
|
|
$line = iCalUtilityFunctions::_strunrep( $line );
|
1914 |
|
|
}
|
1915 |
|
|
$this->setProperty( $propname, rtrim( $line, "\x00..\x1F" ), $propAttr );
|
1916 |
|
|
}
|
1917 |
|
|
}
|
1918 |
|
|
unset( $unparsedtext, $rows, $this->unparsed, $proprows );
|
1919 |
|
|
|
1920 |
|
|
if( is_array( $this->components ) && ( 0 < count( $this->components ))) {
|
1921 |
|
|
$ckeys = array_keys( $this->components );
|
1922 |
|
|
foreach( $ckeys as $ckey ) {
|
1923 |
|
|
if( !empty( $this->components[$ckey] ) && !empty( $this->components[$ckey]->unparsed )) {
|
1924 |
|
|
$this->components[$ckey]->parse();
|
1925 |
|
|
}
|
1926 |
|
|
}
|
1927 |
|
|
}
|
1928 |
|
|
else
|
1929 |
|
|
return FALSE;
|
1930 |
|
|
return TRUE;
|
1931 |
|
|
}
|
1932 |
|
|
|
1933 |
|
|
|
1934 |
|
|
|
1935 |
|
|
|
1936 |
|
|
|
1937 |
|
|
|
1938 |
|
|
|
1939 |
|
|
|
1940 |
|
|
|
1941 |
|
|
|
1942 |
|
|
|
1943 |
|
|
|
1944 |
|
|
|
1945 |
|
|
|
1946 |
|
|
|
1947 |
|
|
|
1948 |
|
|
|
1949 |
|
|
|
1950 |
|
|
|
1951 |
|
|
|
1952 |
|
|
function createCalendar() {
|
1953 |
|
|
parent::_createFormat();
|
1954 |
|
|
$calendarInit = $calendarxCaldecl = $calendarStart = $calendar = '';
|
1955 |
|
|
switch( $this->format ) {
|
1956 |
|
|
case 'xcal':
|
1957 |
|
|
$calendarInit = '<?xml version="1.0" encoding="UTF-8"?>'.$this->nl.
|
1958 |
|
|
'<!DOCTYPE vcalendar PUBLIC "-//IETF//DTD XCAL/iCalendar XML//EN"'.$this->nl.
|
1959 |
|
|
'"http://www.ietf.org/internet-drafts/draft-ietf-calsch-many-xcal-01.txt"';
|
1960 |
|
|
$calendarStart = '>'.$this->nl.'<vcalendar';
|
1961 |
|
|
break;
|
1962 |
|
|
default:
|
1963 |
|
|
$calendarStart = 'BEGIN:VCALENDAR'.$this->nl;
|
1964 |
|
|
break;
|
1965 |
|
|
}
|
1966 |
|
|
$calendarStart .= $this->createVersion();
|
1967 |
|
|
$calendarStart .= $this->createProdid();
|
1968 |
|
|
$calendarStart .= $this->createCalscale();
|
1969 |
|
|
$calendarStart .= $this->createMethod();
|
1970 |
|
|
if( 'xcal' == $this->format )
|
1971 |
|
|
$calendarStart .= '>'.$this->nl;
|
1972 |
|
|
$calendar .= $this->createXprop();
|
1973 |
|
|
foreach( $this->components as $component ) {
|
1974 |
|
|
if( empty( $component )) continue;
|
1975 |
|
|
$component->setConfig( $this->getConfig(), FALSE, TRUE );
|
1976 |
|
|
$calendar .= $component->createComponent( $this->xcaldecl );
|
1977 |
|
|
}
|
1978 |
|
|
if(( 'xcal' == $this->format ) && ( 0 < count( $this->xcaldecl ))) {
|
1979 |
|
|
$calendarInit .= ' [';
|
1980 |
|
|
$old_xcaldecl = array();
|
1981 |
|
|
foreach( $this->xcaldecl as $declix => $declPart ) {
|
1982 |
|
|
if(( 0 < count( $old_xcaldecl)) &&
|
1983 |
|
|
isset( $declPart['uri'] ) && isset( $declPart['external'] ) &&
|
1984 |
|
|
isset( $old_xcaldecl['uri'] ) && isset( $old_xcaldecl['external'] ) &&
|
1985 |
|
|
( in_array( $declPart['uri'], $old_xcaldecl['uri'] )) &&
|
1986 |
|
|
( in_array( $declPart['external'], $old_xcaldecl['external'] )))
|
1987 |
|
|
continue;
|
1988 |
|
|
if(( 0 < count( $old_xcaldecl)) &&
|
1989 |
|
|
!isset( $declPart['uri'] ) && !isset( $declPart['uri'] ) &&
|
1990 |
|
|
isset( $declPart['ref'] ) && isset( $old_xcaldecl['ref'] ) &&
|
1991 |
|
|
( in_array( $declPart['ref'], $old_xcaldecl['ref'] )))
|
1992 |
|
|
continue;
|
1993 |
|
|
$calendarxCaldecl .= $this->nl.'<!';
|
1994 |
|
|
foreach( $declPart as $declKey => $declValue ) {
|
1995 |
|
|
switch( $declKey ) {
|
1996 |
|
|
case 'xmldecl':
|
1997 |
|
|
$calendarxCaldecl .= $declValue.' ';
|
1998 |
|
|
break;
|
1999 |
|
|
case 'uri':
|
2000 |
|
|
$calendarxCaldecl .= $declValue.' ';
|
2001 |
|
|
$old_xcaldecl['uri'][] = $declValue;
|
2002 |
|
|
break;
|
2003 |
|
|
case 'ref':
|
2004 |
|
|
$calendarxCaldecl .= $declValue.' ';
|
2005 |
|
|
$old_xcaldecl['ref'][] = $declValue;
|
2006 |
|
|
break;
|
2007 |
|
|
case 'external':
|
2008 |
|
|
$calendarxCaldecl .= '"'.$declValue.'" ';
|
2009 |
|
|
$old_xcaldecl['external'][] = $declValue;
|
2010 |
|
|
break;
|
2011 |
|
|
case 'type':
|
2012 |
|
|
$calendarxCaldecl .= $declValue.' ';
|
2013 |
|
|
break;
|
2014 |
|
|
case 'type2':
|
2015 |
|
|
$calendarxCaldecl .= $declValue;
|
2016 |
|
|
break;
|
2017 |
|
|
}
|
2018 |
|
|
}
|
2019 |
|
|
$calendarxCaldecl .= '>';
|
2020 |
|
|
}
|
2021 |
|
|
$calendarxCaldecl .= $this->nl.']';
|
2022 |
|
|
}
|
2023 |
|
|
switch( $this->format ) {
|
2024 |
|
|
case 'xcal':
|
2025 |
|
|
$calendar .= '</vcalendar>'.$this->nl;
|
2026 |
|
|
break;
|
2027 |
|
|
default:
|
2028 |
|
|
$calendar .= 'END:VCALENDAR'.$this->nl;
|
2029 |
|
|
break;
|
2030 |
|
|
}
|
2031 |
|
|
return $calendarInit.$calendarxCaldecl.$calendarStart.$calendar;
|
2032 |
|
|
}
|
2033 |
|
|
|
2034 |
|
|
|
2035 |
|
|
|
2036 |
|
|
|
2037 |
|
|
|
2038 |
|
|
|
2039 |
|
|
|
2040 |
|
|
|
2041 |
|
|
|
2042 |
|
|
|
2043 |
|
|
|
2044 |
|
|
|
2045 |
|
|
|
2046 |
|
|
|
2047 |
|
|
function returnCalendar( $utf8Encode=FALSE, $gzip=FALSE, $cdType=TRUE ) {
|
2048 |
|
|
$filename = $this->getConfig( 'filename' );
|
2049 |
|
|
$output = $this->createCalendar();
|
2050 |
|
|
if( $utf8Encode )
|
2051 |
|
|
$output = utf8_encode( $output );
|
2052 |
|
|
$fsize = null;
|
2053 |
|
|
if( $gzip ) {
|
2054 |
|
|
$output = gzencode( $output, 9 );
|
2055 |
|
|
$fsize = strlen( $output );
|
2056 |
|
|
header( self::$headers[0] );
|
2057 |
|
|
header( self::$headers[1] );
|
2058 |
|
|
}
|
2059 |
|
|
else {
|
2060 |
|
|
if( FALSE !== ( $temp = tempnam( sys_get_temp_dir(), 'iCr' ))) {
|
2061 |
|
|
if( FALSE !== file_put_contents( $temp, $output ))
|
2062 |
|
|
$fsize = @filesize( $temp );
|
2063 |
|
|
unlink( $temp );
|
2064 |
|
|
}
|
2065 |
|
|
}
|
2066 |
|
|
if( ! empty( $fsize ))
|
2067 |
|
|
header( sprintf( self::$headers[2], $fsize ));
|
2068 |
|
|
if( 'xcal' == $this->format )
|
2069 |
|
|
header( self::$headers[3] );
|
2070 |
|
|
else
|
2071 |
|
|
header( self::$headers[4] );
|
2072 |
|
|
$cdType = ( $cdType ) ? 5 : 6;
|
2073 |
|
|
header( sprintf( self::$headers[$cdType], $filename ));
|
2074 |
|
|
header( self::$headers[7] );
|
2075 |
|
|
echo $output;
|
2076 |
|
|
return TRUE;
|
2077 |
|
|
}
|
2078 |
|
|
|
2079 |
|
|
|
2080 |
|
|
|
2081 |
|
|
|
2082 |
|
|
|
2083 |
|
|
|
2084 |
|
|
|
2085 |
|
|
|
2086 |
|
|
|
2087 |
|
|
function saveCalendar() {
|
2088 |
|
|
$output = $this->createCalendar();
|
2089 |
|
|
if( FALSE === ( $dirfile = $this->getConfig( 'url' )))
|
2090 |
|
|
$dirfile = $this->getConfig( 'dirfile' );
|
2091 |
|
|
return ( FALSE === file_put_contents( $dirfile, $output, LOCK_EX )) ? FALSE : TRUE;
|
2092 |
|
|
}
|
2093 |
|
|
|
2094 |
|
|
|
2095 |
|
|
|
2096 |
|
|
|
2097 |
|
|
|
2098 |
|
|
|
2099 |
|
|
|
2100 |
|
|
|
2101 |
|
|
|
2102 |
|
|
|
2103 |
|
|
|
2104 |
|
|
|
2105 |
|
|
|
2106 |
|
|
function useCachedCalendar( $timeout=3600, $cdType=TRUE ) {
|
2107 |
|
|
if( FALSE === ( $dirfile = $this->getConfig( 'url' )))
|
2108 |
|
|
$dirfile = $this->getConfig( 'dirfile' );
|
2109 |
|
|
if( ! is_file( $dirfile ) || ! is_readable( $dirfile ))
|
2110 |
|
|
return FALSE;
|
2111 |
|
|
if( time() - filemtime( $dirfile ) > $timeout )
|
2112 |
|
|
return FALSE;
|
2113 |
|
|
clearstatcache();
|
2114 |
|
|
$dirfile = $this->getConfig( 'dirfile' );
|
2115 |
|
|
$fsize = @filesize( $dirfile );
|
2116 |
|
|
$filename = $this->getConfig( 'filename' );
|
2117 |
|
|
if( 'xcal' == $this->format )
|
2118 |
|
|
header( self::$headers[3] );
|
2119 |
|
|
else
|
2120 |
|
|
header( self::$headers[4] );
|
2121 |
|
|
if( ! empty( $fsize ))
|
2122 |
|
|
header( sprintf( self::$headers[2], $fsize ));
|
2123 |
|
|
$cdType = ( $cdType ) ? 5 : 6;
|
2124 |
|
|
header( sprintf( self::$headers[$cdType], $filename ));
|
2125 |
|
|
header( self::$headers[7] );
|
2126 |
|
|
if( FALSE === ( $fp = @fopen( $dirfile, 'r' )))
|
2127 |
|
|
return FALSE;
|
2128 |
|
|
fpassthru( $fp );
|
2129 |
|
|
fclose( $fp );
|
2130 |
|
|
return TRUE;
|
2131 |
|
|
}
|
2132 |
|
|
} |