1
|
<?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 iCalUtilityFunctions {
|
36
|
|
37
|
private static $baseDelim = null;
|
38
|
|
39
|
private static $parValPrefix = array ( 'MStz' => array( 'utc-', 'utc+', 'gmt-', 'gmt+' )
|
40
|
, 'Proto3' => array( 'fax:', 'cid:', 'sms:', 'tel:', 'urn:' )
|
41
|
, 'Proto4' => array( 'crid:', 'news:', 'pres:' )
|
42
|
, 'Proto6' => array( 'mailto:' ));
|
43
|
|
44
|
public static $geoLatFmt = '%09.6f';
|
45
|
public static $geoLongFmt = '%8.6f';
|
46
|
|
47
|
public static $fmt = array( 'Ymd' => '%04d%02d%02d',
|
48
|
'His' => '%02d%02d%02d',
|
49
|
'dayOfDays' => 'day %d of %d',
|
50
|
'durDHis' => '%a days, %h hours, %i min, %s sec',
|
51
|
'Ymd2' => 'Y-m-d',
|
52
|
'YmdHis2' => 'Y-m-d H:i:s',
|
53
|
'YmdHis2e' => 'Y-m-d H:i:s e',
|
54
|
'YmdHis3' => 'Y-m-d-H-i-s',
|
55
|
'YmdHise' => '%04d-%02d-%02d %02d:%02d:%02d %s',
|
56
|
'YmdTHisO' => 'Y-m-d\TH:i:s O',
|
57
|
'dateKey' => '%04d%02d%02d%02d%02d%02d000',
|
58
|
);
|
59
|
|
60
|
public static $vComps = array( 'vevent', 'vtodo', 'vjournal', 'vfreebusy' );
|
61
|
public static $mComps = array( 'vevent', 'vtodo', 'vjournal', 'vfreebusy', 'valarm', 'vtimezone' );
|
62
|
public static $miscComps = array( 'valarm', 'vtimezone', 'standard', 'daylight' );
|
63
|
public static $tzComps = array( 'vtimezone', 'standard', 'daylight' );
|
64
|
public static $allComps = array( 'vtimezone', 'standard', 'daylight', 'vevent', 'vtodo', 'vjournal', 'vfreebusy', 'valarm' );
|
65
|
|
66
|
public static $mProps1 = array( 'ATTENDEE', 'CATEGORIES', 'CONTACT', 'RELATED-TO', 'RESOURCES' );
|
67
|
public static $mProps2 = array( 'ATTACH', 'ATTENDEE', 'CATEGORIES', 'COMMENT', 'CONTACT', 'DESCRIPTION', 'EXDATE', 'EXRULE',
|
68
|
'FREEBUSY', 'RDATE', 'RELATED-TO', 'RESOURCES', 'RRULE', 'REQUEST-STATUS', 'TZNAME', 'X-PROP' );
|
69
|
public static $dateProps = array( 'DTSTART', 'DTEND', 'DUE', 'CREATED', 'COMPLETED', 'DTSTAMP', 'LAST-MODIFIED', 'RECURRENCE-ID' );
|
70
|
public static $otherProps = array( 'ATTENDEE', 'CATEGORIES', 'CONTACT', 'LOCATION', 'ORGANIZER', 'PRIORITY', 'RELATED-TO', 'RESOURCES', 'STATUS', 'SUMMARY', 'UID', 'URL' );
|
71
|
|
72
|
private static $m_pInstance;
|
73
|
|
74
|
|
75
|
|
76
|
|
77
|
|
78
|
private function __construct() {
|
79
|
$m_pInstance = FALSE;
|
80
|
}
|
81
|
|
82
|
|
83
|
|
84
|
|
85
|
|
86
|
|
87
|
public static function getInstance() {
|
88
|
if (!self::$m_pInstance)
|
89
|
self::$m_pInstance = new iCalUtilityFunctions();
|
90
|
return self::$m_pInstance;
|
91
|
}
|
92
|
|
93
|
|
94
|
|
95
|
|
96
|
|
97
|
|
98
|
|
99
|
|
100
|
|
101
|
public static function _chkDateArr( $datetime, $parno=FALSE ) {
|
102
|
$output = array();
|
103
|
if(( !$parno || ( 6 <= $parno )) && isset( $datetime[3] ) && !isset( $datetime[4] )) {
|
104
|
$temp = $datetime[3];
|
105
|
$datetime[3] = $datetime[4] = $datetime[5] = 0;
|
106
|
$datetime[6] = $temp;
|
107
|
}
|
108
|
foreach( $datetime as $dateKey => $datePart ) {
|
109
|
switch ( $dateKey ) {
|
110
|
case '0': case 'year': $output['year'] = $datePart; break;
|
111
|
case '1': case 'month': $output['month'] = $datePart; break;
|
112
|
case '2': case 'day': $output['day'] = $datePart; break;
|
113
|
}
|
114
|
if( 3 != $parno ) {
|
115
|
switch ( $dateKey ) {
|
116
|
case '0':
|
117
|
case '1':
|
118
|
case '2': break;
|
119
|
case '3': case 'hour': $output['hour'] = $datePart; break;
|
120
|
case '4': case 'min' : $output['min'] = $datePart; break;
|
121
|
case '5': case 'sec' : $output['sec'] = $datePart; break;
|
122
|
case '6': case 'tz' : $output['tz'] = $datePart; break;
|
123
|
}
|
124
|
}
|
125
|
}
|
126
|
if( 3 != $parno ) {
|
127
|
if( !isset( $output['hour'] )) $output['hour'] = 0;
|
128
|
if( !isset( $output['min'] )) $output['min'] = 0;
|
129
|
if( !isset( $output['sec'] )) $output['sec'] = 0;
|
130
|
if( isset( $output['tz'] ) &&
|
131
|
(( '+0000' == $output['tz'] ) || ( '-0000' == $output['tz'] ) || ( '+000000' == $output['tz'] ) || ( '-000000' == $output['tz'] )))
|
132
|
$output['tz'] = 'Z';
|
133
|
}
|
134
|
return $output;
|
135
|
}
|
136
|
|
137
|
|
138
|
|
139
|
|
140
|
|
141
|
|
142
|
|
143
|
|
144
|
|
145
|
|
146
|
|
147
|
|
148
|
public static function _chkdatecfg( $theDate, & $parno, & $params ) {
|
149
|
if( isset( $params['TZID'] ))
|
150
|
$parno = 6;
|
151
|
elseif( isset( $params['VALUE'] ) && ( 'DATE' == $params['VALUE'] ))
|
152
|
$parno = 3;
|
153
|
else {
|
154
|
if( isset( $params['VALUE'] ) && ( 'PERIOD' == $params['VALUE'] ))
|
155
|
$parno = 7;
|
156
|
if( is_array( $theDate )) {
|
157
|
if( isset( $theDate['timestamp'] ))
|
158
|
$tzid = ( isset( $theDate['tz'] )) ? $theDate['tz'] : null;
|
159
|
else
|
160
|
$tzid = ( isset( $theDate['tz'] )) ? $theDate['tz'] : ( 7 == count( $theDate )) ? end( $theDate ) : null;
|
161
|
if( !empty( $tzid )) {
|
162
|
$parno = 7;
|
163
|
if( !iCalUtilityFunctions::_isOffset( $tzid ))
|
164
|
$params['TZID'] = $tzid;
|
165
|
}
|
166
|
elseif( !$parno && ( 3 == count( $theDate )) &&
|
167
|
( isset( $params['VALUE'] ) && ( 'DATE' == $params['VALUE'] )))
|
168
|
$parno = 3;
|
169
|
else
|
170
|
$parno = 6;
|
171
|
}
|
172
|
else {
|
173
|
$date = trim( $theDate );
|
174
|
if( 'Z' == substr( $date, -1 ))
|
175
|
$parno = 7;
|
176
|
elseif((( 8 == strlen( $date ) && ctype_digit( $date )) || ( 11 >= strlen( $date ))) &&
|
177
|
( !isset( $params['VALUE'] ) || !in_array( $params['VALUE'], array( 'DATE-TIME', 'PERIOD' ))))
|
178
|
$parno = 3;
|
179
|
$date = iCalUtilityFunctions::_strdate2date( $date, $parno );
|
180
|
unset( $date['unparsedtext'] );
|
181
|
if( !empty( $date['tz'] )) {
|
182
|
$parno = 7;
|
183
|
if( !iCalUtilityFunctions::_isOffset( $date['tz'] ))
|
184
|
$params['TZID'] = $date['tz'];
|
185
|
}
|
186
|
elseif( empty( $parno ))
|
187
|
$parno = 6;
|
188
|
}
|
189
|
if( isset( $params['TZID'] ))
|
190
|
$parno = 6;
|
191
|
}
|
192
|
}
|
193
|
|
194
|
|
195
|
|
196
|
|
197
|
|
198
|
|
199
|
|
200
|
|
201
|
|
202
|
|
203
|
public static function _cmpfcn( $a, $b ) {
|
204
|
if( empty( $a )) return -1;
|
205
|
if( empty( $b )) return 1;
|
206
|
if( 'vtimezone' == $a->objName ) {
|
207
|
if( 'vtimezone' != $b->objName ) return -1;
|
208
|
elseif( $a->srtk[0] <= $b->srtk[0] ) return -1;
|
209
|
else return 1;
|
210
|
}
|
211
|
elseif( 'vtimezone' == $b->objName ) return 1;
|
212
|
$sortkeys = array( 'year', 'month', 'day', 'hour', 'min', 'sec' );
|
213
|
for( $k = 0; $k < 4 ; $k++ ) {
|
214
|
if( empty( $a->srtk[$k] )) return -1;
|
215
|
elseif( empty( $b->srtk[$k] )) return 1;
|
216
|
if( is_array( $a->srtk[$k] )) {
|
217
|
if( is_array( $b->srtk[$k] )) {
|
218
|
foreach( $sortkeys as $key ) {
|
219
|
if ( !isset( $a->srtk[$k][$key] )) return -1;
|
220
|
elseif( !isset( $b->srtk[$k][$key] )) return 1;
|
221
|
if ( empty( $a->srtk[$k][$key] )) return -1;
|
222
|
elseif( empty( $b->srtk[$k][$key] )) return 1;
|
223
|
if ( $a->srtk[$k][$key] == $b->srtk[$k][$key])
|
224
|
continue;
|
225
|
if (( (int) $a->srtk[$k][$key] ) < ((int) $b->srtk[$k][$key] ))
|
226
|
return -1;
|
227
|
elseif(( (int) $a->srtk[$k][$key] ) > ((int) $b->srtk[$k][$key] ))
|
228
|
return 1;
|
229
|
}
|
230
|
}
|
231
|
else return -1;
|
232
|
}
|
233
|
elseif( is_array( $b->srtk[$k] )) return 1;
|
234
|
elseif( $a->srtk[$k] < $b->srtk[$k] ) return -1;
|
235
|
elseif( $a->srtk[$k] > $b->srtk[$k] ) return 1;
|
236
|
}
|
237
|
return 0;
|
238
|
}
|
239
|
|
240
|
|
241
|
|
242
|
|
243
|
|
244
|
|
245
|
|
246
|
|
247
|
|
248
|
|
249
|
|
250
|
|
251
|
|
252
|
|
253
|
public static function convEolChar( & $text, $nl ) {
|
254
|
|
255
|
if( empty( iCalUtilityFunctions::$baseDelim )) {
|
256
|
iCalUtilityFunctions::$baseDelim = substr( microtime(), 2, 4 );
|
257
|
$base = 'aAbB!cCdD"eEfF#gGhHiIjJ%kKlL&mMnN/oOpP(rRsS)tTuU=vVxX?uUvV*wWzZ-1234_5678|90';
|
258
|
$len = strlen( $base ) - 1;
|
259
|
for( $p = 0; $p < 6; $p++ )
|
260
|
iCalUtilityFunctions::$baseDelim .= $base{mt_rand( 0, $len )};
|
261
|
}
|
262
|
|
263
|
$text = str_replace( array( "\r\n", "\n\r", "\n", "\r" ), iCalUtilityFunctions::$baseDelim, $text );
|
264
|
|
265
|
$text = str_replace( iCalUtilityFunctions::$baseDelim.iCalUtilityFunctions::$baseDelim, iCalUtilityFunctions::$baseDelim.str_pad( '', 75 ).iCalUtilityFunctions::$baseDelim, $text );
|
266
|
|
267
|
$text = str_replace( iCalUtilityFunctions::$baseDelim, $nl, $text );
|
268
|
$text = str_replace( array( $nl.' ', $nl."\t" ), '', $text );
|
269
|
|
270
|
$text = explode( $nl, $text );
|
271
|
return $text;
|
272
|
}
|
273
|
|
274
|
|
275
|
|
276
|
|
277
|
|
278
|
|
279
|
|
280
|
|
281
|
|
282
|
|
283
|
|
284
|
|
285
|
|
286
|
|
287
|
|
288
|
|
289
|
|
290
|
|
291
|
|
292
|
|
293
|
|
294
|
|
295
|
|
296
|
|
297
|
|
298
|
|
299
|
|
300
|
|
301
|
|
302
|
|
303
|
|
304
|
|
305
|
|
306
|
|
307
|
|
308
|
|
309
|
|
310
|
public static function createTimezone( & $calendar, $timezone, $xProp=array(), $from=null, $to=null ) {
|
311
|
if( empty( $timezone ))
|
312
|
return FALSE;
|
313
|
if( !empty( $from ) && !is_int( $from ))
|
314
|
return FALSE;
|
315
|
if( !empty( $to ) && !is_int( $to ))
|
316
|
return FALSE;
|
317
|
try {
|
318
|
$dtz = new DateTimeZone( $timezone );
|
319
|
$transitions = $dtz->getTransitions();
|
320
|
$utcTz = new DateTimeZone( 'UTC' );
|
321
|
}
|
322
|
catch( Exception $e ) { return FALSE; }
|
323
|
if( empty( $from ) || empty( $to )) {
|
324
|
$dates = array_keys( $calendar->getProperty( 'dtstart' ));
|
325
|
if( empty( $dates ))
|
326
|
$dates = array( date( 'Ymd' ));
|
327
|
}
|
328
|
if( ! empty( $from )) {
|
329
|
$dateFrom = new DateTime( "@$from" );
|
330
|
$dateFrom->modify( '-7 month' );
|
331
|
}
|
332
|
else {
|
333
|
$from = reset( $dates );
|
334
|
$dateFrom = new DateTime( $from.'T000000', $dtz );
|
335
|
$dateFrom->modify( '-7 month' );
|
336
|
$dateFrom->setTimezone( $utcTz );
|
337
|
}
|
338
|
$dateFromYmd = $dateFrom->format( iCalUtilityFunctions::$fmt['Ymd2'] );
|
339
|
if( ! empty( $to ))
|
340
|
$dateTo = new DateTime( "@$to" );
|
341
|
else {
|
342
|
$to = end( $dates );
|
343
|
$dateTo = new DateTime( $to.'T235959', $dtz );
|
344
|
$dateTo->modify( '+18 month' );
|
345
|
$dateTo->setTimezone( $utcTz );
|
346
|
}
|
347
|
$dateToYmd = $dateTo->format( iCalUtilityFunctions::$fmt['Ymd2'] );
|
348
|
unset( $dtz );
|
349
|
$transTemp = array();
|
350
|
$prevOffsetfrom = 0;
|
351
|
$stdIx = $dlghtIx = null;
|
352
|
$prevTrans = FALSE;
|
353
|
foreach( $transitions as $tix => $trans ) {
|
354
|
$date = new DateTime( "@{$trans['ts']}" );
|
355
|
$transDateYmd = $date->format( iCalUtilityFunctions::$fmt['Ymd2'] );
|
356
|
if ( $transDateYmd < $dateFromYmd ) {
|
357
|
$prevOffsetfrom = $trans['offset'];
|
358
|
$prevTrans = $trans;
|
359
|
$prevTrans['offsetfrom'] = ( 0 < $tix ) ? $transitions[$tix-1]['offset'] : 0;
|
360
|
continue;
|
361
|
}
|
362
|
if( $transDateYmd > $dateToYmd )
|
363
|
break;
|
364
|
if( !empty( $prevOffsetfrom ) || ( 0 == $prevOffsetfrom )) {
|
365
|
$trans['offsetfrom'] = $prevOffsetfrom;
|
366
|
$date->modify( $trans['offsetfrom'].'seconds' );
|
367
|
$d = $date->format( iCalUtilityFunctions::$fmt['YmdHis3'] );
|
368
|
$d = explode( '-', $d );
|
369
|
$trans['time'] = array( 'year' => (int) $d[0], 'month' => (int) $d[1], 'day' => (int) $d[2], 'hour' => (int) $d[3], 'min' => (int) $d[4], 'sec' => (int) $d[5] );
|
370
|
}
|
371
|
$prevOffsetfrom = $trans['offset'];
|
372
|
if( TRUE !== $trans['isdst'] ) {
|
373
|
if( !empty( $stdIx ) && isset( $transTemp[$stdIx]['offsetfrom'] ) &&
|
374
|
( $transTemp[$stdIx]['abbr'] == $trans['abbr'] ) &&
|
375
|
( $transTemp[$stdIx]['offsetfrom'] == $trans['offsetfrom'] ) &&
|
376
|
( $transTemp[$stdIx]['offset'] == $trans['offset'] )) {
|
377
|
$transTemp[$stdIx]['rdate'][] = $trans['time'];
|
378
|
continue;
|
379
|
}
|
380
|
$stdIx = $tix;
|
381
|
}
|
382
|
else {
|
383
|
if( !empty( $dlghtIx ) && isset( $transTemp[$dlghtIx]['offsetfrom'] ) &&
|
384
|
( $transTemp[$dlghtIx]['abbr'] == $trans['abbr'] ) &&
|
385
|
( $transTemp[$dlghtIx]['offsetfrom'] == $trans['offsetfrom'] ) &&
|
386
|
( $transTemp[$dlghtIx]['offset'] == $trans['offset'] )) {
|
387
|
$transTemp[$dlghtIx]['rdate'][] = $trans['time'];
|
388
|
continue;
|
389
|
}
|
390
|
$dlghtIx = $tix;
|
391
|
}
|
392
|
$transTemp[$tix] = $trans;
|
393
|
}
|
394
|
$tz = $calendar->newComponent( 'vtimezone' );
|
395
|
$tz->setproperty( 'tzid', $timezone );
|
396
|
if( !empty( $xProp )) {
|
397
|
foreach( $xProp as $xPropName => $xPropValue )
|
398
|
if( 'x-' == strtolower( substr( $xPropName, 0, 2 )))
|
399
|
$tz->setproperty( $xPropName, $xPropValue );
|
400
|
}
|
401
|
if( empty( $transTemp )) {
|
402
|
if( $prevTrans ) {
|
403
|
$date = new DateTime( "@{$prevTrans['ts']}" );
|
404
|
$date->modify( $prevTrans['offsetfrom'].'seconds' );
|
405
|
$d = $date->format( iCalUtilityFunctions::$fmt['YmdHis3'] );
|
406
|
$d = explode( '-', $d );
|
407
|
$prevTrans['time'] = array( 'year' => (int) $d[0], 'month' => (int) $d[1], 'day' => (int) $d[2], 'hour' => (int) $d[3], 'min' => (int) $d[4], 'sec' => (int) $d[5] );
|
408
|
$transTemp[0] = $prevTrans;
|
409
|
}
|
410
|
else {
|
411
|
$date = new DateTime( 'now', new DateTimeZone( $timezone ));
|
412
|
$transTemp[0] = array( 'time' => $date->format( iCalUtilityFunctions::$fmt['YmdTHisO'] ),
|
413
|
'offset' => $date->format( 'Z' ),
|
414
|
'offsetfrom' => $date->format( 'Z' ),
|
415
|
'isdst' => FALSE );
|
416
|
}
|
417
|
}
|
418
|
unset( $transitions, $date, $prevTrans );
|
419
|
foreach( $transTemp as $tix => $trans ) {
|
420
|
$type = ( TRUE !== $trans['isdst'] ) ? 'standard' : 'daylight';
|
421
|
$scomp = $tz->newComponent( $type );
|
422
|
$scomp->setProperty( 'dtstart', $trans['time'] );
|
423
|
|
424
|
if( !empty( $trans['abbr'] ))
|
425
|
$scomp->setProperty( 'tzname', $trans['abbr'] );
|
426
|
if( isset( $trans['offsetfrom'] ))
|
427
|
$scomp->setProperty( 'tzoffsetfrom', iCalUtilityFunctions::offsetSec2His( $trans['offsetfrom'] ));
|
428
|
$scomp->setProperty( 'tzoffsetto', iCalUtilityFunctions::offsetSec2His( $trans['offset'] ));
|
429
|
if( isset( $trans['rdate'] ))
|
430
|
$scomp->setProperty( 'RDATE', $trans['rdate'] );
|
431
|
}
|
432
|
return TRUE;
|
433
|
}
|
434
|
|
435
|
|
436
|
|
437
|
|
438
|
|
439
|
|
440
|
|
441
|
|
442
|
|
443
|
|
444
|
|
445
|
|
446
|
public static function _date2strdate( $datetime, $parno=6 ) {
|
447
|
if( !isset( $datetime['year'] ) &&
|
448
|
!isset( $datetime['month'] ) &&
|
449
|
!isset( $datetime['day'] ) &&
|
450
|
!isset( $datetime['hour'] ) &&
|
451
|
!isset( $datetime['min'] ) &&
|
452
|
!isset( $datetime['sec'] ))
|
453
|
return;
|
454
|
$output = null;
|
455
|
foreach( $datetime as $dkey => & $dvalue )
|
456
|
if( 'tz' != $dkey ) $dvalue = (int) $dvalue;
|
457
|
$output = sprintf( iCalUtilityFunctions::$fmt['Ymd'], $datetime['year'], $datetime['month'], $datetime['day'] );
|
458
|
if( 3 == $parno )
|
459
|
return $output;
|
460
|
if( !isset( $datetime['hour'] )) $datetime['hour'] = 0;
|
461
|
if( !isset( $datetime['min'] )) $datetime['min'] = 0;
|
462
|
if( !isset( $datetime['sec'] )) $datetime['sec'] = 0;
|
463
|
$output .= 'T'.sprintf( iCalUtilityFunctions::$fmt['His'], $datetime['hour'], $datetime['min'], $datetime['sec'] );
|
464
|
if( isset( $datetime['tz'] ) && ( '' < trim( $datetime['tz'] ))) {
|
465
|
$datetime['tz'] = trim( $datetime['tz'] );
|
466
|
if( 'Z' == $datetime['tz'] )
|
467
|
$parno = 7;
|
468
|
elseif( iCalUtilityFunctions::_isOffset( $datetime['tz'] )) {
|
469
|
$parno = 7;
|
470
|
$offset = iCalUtilityFunctions::_tz2offset( $datetime['tz'] );
|
471
|
try {
|
472
|
$d = new DateTime( $output, new DateTimeZone( 'UTC' ));
|
473
|
if( 0 != $offset )
|
474
|
$d->modify( "$offset seconds" );
|
475
|
$output = $d->format( 'Ymd\THis' );
|
476
|
}
|
477
|
catch( Exception $e ) {
|
478
|
$output = date( 'Ymd\THis', mktime( $datetime['hour'], $datetime['min'], ($datetime['sec'] - $offset), $datetime['month'], $datetime['day'], $datetime['year'] ));
|
479
|
}
|
480
|
}
|
481
|
if( 7 == $parno )
|
482
|
$output .= 'Z';
|
483
|
}
|
484
|
return $output;
|
485
|
}
|
486
|
|
487
|
|
488
|
|
489
|
|
490
|
|
491
|
|
492
|
|
493
|
|
494
|
public static function _duration2arr( $duration ) {
|
495
|
$seconds = 0;
|
496
|
foreach( $duration as $durKey => $durValue ) {
|
497
|
if( empty( $durValue )) continue;
|
498
|
switch ( $durKey ) {
|
499
|
case '0': case 'week':
|
500
|
$seconds += (((int) $durValue ) * 60 * 60 * 24 * 7 );
|
501
|
break;
|
502
|
case '1': case 'day':
|
503
|
$seconds += (((int) $durValue ) * 60 * 60 * 24 );
|
504
|
break;
|
505
|
case '2': case 'hour':
|
506
|
$seconds += (((int) $durValue ) * 60 * 60 );
|
507
|
break;
|
508
|
case '3': case 'min':
|
509
|
$seconds += (((int) $durValue ) * 60 );
|
510
|
break;
|
511
|
case '4': case 'sec':
|
512
|
$seconds += (int) $durValue;
|
513
|
break;
|
514
|
}
|
515
|
}
|
516
|
$output = array();
|
517
|
$output['week'] = (int) floor( $seconds / ( 60 * 60 * 24 * 7 ));
|
518
|
if(( 0 < $output['week'] ) && ( 0 == ( $seconds % ( 60 * 60 * 24 * 7 ))))
|
519
|
return $output;
|
520
|
unset( $output['week'] );
|
521
|
$output['day'] = (int) floor( $seconds / ( 60 * 60 * 24 ));
|
522
|
$seconds = ( $seconds % ( 60 * 60 * 24 ));
|
523
|
$output['hour'] = (int) floor( $seconds / ( 60 * 60 ));
|
524
|
$seconds = ( $seconds % ( 60 * 60 ));
|
525
|
$output['min'] = (int) floor( $seconds / 60 );
|
526
|
$output['sec'] = ( $seconds % 60 );
|
527
|
if( empty( $output['day'] ))
|
528
|
unset( $output['day'] );
|
529
|
if(( 0 == $output['hour'] ) && ( 0 == $output['min'] ) && ( 0 == $output['sec'] ))
|
530
|
unset( $output['hour'], $output['min'], $output['sec'] );
|
531
|
return $output;
|
532
|
}
|
533
|
|
534
|
|
535
|
|
536
|
|
537
|
|
538
|
|
539
|
|
540
|
|
541
|
|
542
|
|
543
|
public static function _duration2date( $startdate, $duration ) {
|
544
|
$dateOnly = ( isset( $startdate['hour'] ) || isset( $startdate['min'] ) || isset( $startdate['sec'] )) ? FALSE : TRUE;
|
545
|
$startdate['hour'] = ( isset( $startdate['hour'] )) ? $startdate['hour'] : 0;
|
546
|
$startdate['min'] = ( isset( $startdate['min'] )) ? $startdate['min'] : 0;
|
547
|
$startdate['sec'] = ( isset( $startdate['sec'] )) ? $startdate['sec'] : 0;
|
548
|
$dtend = 0;
|
549
|
if( isset( $duration['week'] )) $dtend += ( $duration['week'] * 7 * 24 * 60 * 60 );
|
550
|
if( isset( $duration['day'] )) $dtend += ( $duration['day'] * 24 * 60 * 60 );
|
551
|
if( isset( $duration['hour'] )) $dtend += ( $duration['hour'] * 60 *60 );
|
552
|
if( isset( $duration['min'] )) $dtend += ( $duration['min'] * 60 );
|
553
|
if( isset( $duration['sec'] )) $dtend += $duration['sec'];
|
554
|
$date = date( iCalUtilityFunctions::$fmt['YmdHis3'],
|
555
|
mktime((int) $startdate['hour'], (int) $startdate['min'], (int) ( $startdate['sec'] + $dtend ), (int) $startdate['month'], (int) $startdate['day'], (int) $startdate['year'] ));
|
556
|
$d = explode( '-', $date );
|
557
|
$dtend2 = array( 'year' => $d[0], 'month' => $d[1], 'day' => $d[2], 'hour' => $d[3], 'min' => $d[4], 'sec' => $d[5] );
|
558
|
if( isset( $startdate['tz'] ))
|
559
|
$dtend2['tz'] = $startdate['tz'];
|
560
|
if( $dateOnly && (( 0 == $dtend2['hour'] ) && ( 0 == $dtend2['min'] ) && ( 0 == $dtend2['sec'] )))
|
561
|
unset( $dtend2['hour'], $dtend2['min'], $dtend2['sec'] );
|
562
|
return $dtend2;
|
563
|
}
|
564
|
|
565
|
|
566
|
|
567
|
|
568
|
|
569
|
|
570
|
|
571
|
|
572
|
|
573
|
public static function _durationStr2arr( $duration ) {
|
574
|
$duration = (string) trim( $duration );
|
575
|
while( 'P' != strtoupper( substr( $duration, 0, 1 ))) {
|
576
|
if( 0 < strlen( $duration ))
|
577
|
$duration = substr( $duration, 1 );
|
578
|
else
|
579
|
return false;
|
580
|
}
|
581
|
$duration = substr( $duration, 1 );
|
582
|
$duration = str_replace ( 't', 'T', $duration );
|
583
|
$duration = str_replace ( 'T', '', $duration );
|
584
|
$output = array();
|
585
|
$val = null;
|
586
|
for( $ix=0; $ix < strlen( $duration ); $ix++ ) {
|
587
|
switch( strtoupper( substr( $duration, $ix, 1 ))) {
|
588
|
case 'W':
|
589
|
$output['week'] = $val;
|
590
|
$val = null;
|
591
|
break;
|
592
|
case 'D':
|
593
|
$output['day'] = $val;
|
594
|
$val = null;
|
595
|
break;
|
596
|
case 'H':
|
597
|
$output['hour'] = $val;
|
598
|
$val = null;
|
599
|
break;
|
600
|
case 'M':
|
601
|
$output['min'] = $val;
|
602
|
$val = null;
|
603
|
break;
|
604
|
case 'S':
|
605
|
$output['sec'] = $val;
|
606
|
$val = null;
|
607
|
break;
|
608
|
default:
|
609
|
if( !ctype_digit( substr( $duration, $ix, 1 )))
|
610
|
return false;
|
611
|
else
|
612
|
$val .= substr( $duration, $ix, 1 );
|
613
|
}
|
614
|
}
|
615
|
return iCalUtilityFunctions::_duration2arr( $output );
|
616
|
}
|
617
|
|
618
|
|
619
|
|
620
|
|
621
|
|
622
|
|
623
|
|
624
|
|
625
|
public static function _duration2str( array $duration ) {
|
626
|
if( isset( $duration['week'] ) ||
|
627
|
isset( $duration['day'] ) ||
|
628
|
isset( $duration['hour'] ) ||
|
629
|
isset( $duration['min'] ) ||
|
630
|
isset( $duration['sec'] ))
|
631
|
$ok = TRUE;
|
632
|
else
|
633
|
return;
|
634
|
if( isset( $duration['week'] ) && ( 0 < $duration['week'] ))
|
635
|
return 'P'.$duration['week'].'W';
|
636
|
$output = 'P';
|
637
|
if( isset($duration['day'] ) && ( 0 < $duration['day'] ))
|
638
|
$output .= $duration['day'].'D';
|
639
|
if(( isset( $duration['hour']) && ( 0 < $duration['hour'] )) ||
|
640
|
( isset( $duration['min']) && ( 0 < $duration['min'] )) ||
|
641
|
( isset( $duration['sec']) && ( 0 < $duration['sec'] ))) {
|
642
|
$output .= 'T';
|
643
|
$output .= ( isset( $duration['hour']) && ( 0 < $duration['hour'] )) ? $duration['hour'].'H' : '0H';
|
644
|
$output .= ( isset( $duration['min']) && ( 0 < $duration['min'] )) ? $duration['min']. 'M' : '0M';
|
645
|
$output .= ( isset( $duration['sec']) && ( 0 < $duration['sec'] )) ? $duration['sec']. 'S' : '0S';
|
646
|
}
|
647
|
if( 'P' == $output )
|
648
|
$output = 'PT0H0M0S';
|
649
|
return $output;
|
650
|
}
|
651
|
|
652
|
|
653
|
|
654
|
|
655
|
|
656
|
|
657
|
|
658
|
|
659
|
|
660
|
|
661
|
|
662
|
|
663
|
|
664
|
public static function _existRem( & $array, $expkey, $expval=FALSE, $hitVal=null, $elseVal=null, $preSet=null ) {
|
665
|
if( $preSet )
|
666
|
return $preSet;
|
667
|
if( !is_array( $array ) || ( 0 == count( $array )))
|
668
|
return $elseVal;
|
669
|
foreach( $array as $key => $value ) {
|
670
|
if( strtoupper( $expkey ) == strtoupper( $key )) {
|
671
|
if( !$expval || ( strtoupper( $expval ) == strtoupper( $array[$key] ))) {
|
672
|
unset( $array[$key] );
|
673
|
return $hitVal;
|
674
|
}
|
675
|
}
|
676
|
}
|
677
|
return $elseVal;
|
678
|
}
|
679
|
|
680
|
|
681
|
|
682
|
|
683
|
|
684
|
|
685
|
|
686
|
|
687
|
|
688
|
|
689
|
|
690
|
|
691
|
public static function _inScope( $start, $scopeStart, $end, $scopeEnd, $format ) {
|
692
|
return (( $start->format( $format ) >= $scopeStart->format( $format )) &&
|
693
|
( $end->format( $format ) <= $scopeEnd->format( $format )));
|
694
|
}
|
695
|
|
696
|
|
697
|
|
698
|
|
699
|
|
700
|
|
701
|
|
702
|
|
703
|
|
704
|
public static function _geo2str2( $ll, $format ) {
|
705
|
if( 0.0 < $ll )
|
706
|
$sign = '+';
|
707
|
else
|
708
|
$sign = ( 0.0 > $ll ) ? '-' : '';
|
709
|
return rtrim( rtrim( $sign.sprintf( $format, abs( $ll )), '0' ), '.' );
|
710
|
}
|
711
|
|
712
|
|
713
|
|
714
|
|
715
|
|
716
|
|
717
|
|
718
|
|
719
|
|
720
|
public static function _isArrayDate( $input ) {
|
721
|
if( !is_array( $input ) || isset( $input['week'] ) || isset( $input['timestamp'] ) || ( 3 > count( $input )))
|
722
|
return FALSE;
|
723
|
if( 7 == count( $input ))
|
724
|
return TRUE;
|
725
|
if( isset( $input['year'] ) && isset( $input['month'] ) && isset( $input['day'] ))
|
726
|
return checkdate( (int) $input['month'], (int) $input['day'], (int) $input['year'] );
|
727
|
if( isset( $input['day'] ) || isset( $input['hour'] ) || isset( $input['min'] ) || isset( $input['sec'] ))
|
728
|
return FALSE;
|
729
|
if(( 0 == $input[0] ) || ( 0 == $input[1] ) || ( 0 == $input[2] ))
|
730
|
return FALSE;
|
731
|
if(( 1970 > $input[0] ) || ( 12 < $input[1] ) || ( 31 < $input[2] ))
|
732
|
return FALSE;
|
733
|
if(( isset( $input[0] ) && isset( $input[1] ) && isset( $input[2] )) &&
|
734
|
checkdate((int) $input[1], (int) $input[2], (int) $input[0] ))
|
735
|
return TRUE;
|
736
|
$input = iCalUtilityFunctions::_strdate2date( $input[1].'/'.$input[2].'/'.$input[0], 3 );
|
737
|
if( isset( $input['year'] ) && isset( $input['month'] ) && isset( $input['day'] ))
|
738
|
return checkdate( (int) $input['month'], (int) $input['day'], (int) $input['year'] );
|
739
|
return FALSE;
|
740
|
}
|
741
|
|
742
|
|
743
|
|
744
|
|
745
|
|
746
|
|
747
|
|
748
|
|
749
|
public static function _isArrayTimestampDate( $input ) {
|
750
|
return ( is_array( $input ) && isset( $input['timestamp'] )) ? TRUE : FALSE ;
|
751
|
}
|
752
|
|
753
|
|
754
|
|
755
|
|
756
|
|
757
|
|
758
|
|
759
|
|
760
|
public static function _isOffset( $input ) {
|
761
|
$input = trim( (string) $input );
|
762
|
if( 'Z' == substr( $input, -1 ))
|
763
|
return TRUE;
|
764
|
elseif(( 5 <= strlen( $input )) &&
|
765
|
( in_array( substr( $input, -5, 1 ), array( '+', '-' ))) &&
|
766
|
( '0000' <= substr( $input, -4 )) && ( '9999' >= substr( $input, -4 )))
|
767
|
return TRUE;
|
768
|
elseif(( 7 <= strlen( $input )) &&
|
769
|
( in_array( substr( $input, -7, 1 ), array( '+', '-' ))) &&
|
770
|
( '000000' <= substr( $input, -6 )) && ( '999999' >= substr( $input, -6 )))
|
771
|
return TRUE;
|
772
|
return FALSE;
|
773
|
}
|
774
|
|
775
|
|
776
|
|
777
|
|
778
|
|
779
|
|
780
|
|
781
|
|
782
|
|
783
|
|
784
|
public static function ms2phpTZ( & $timezone ) {
|
785
|
if( empty( $timezone ))
|
786
|
return FALSE;
|
787
|
$search = str_replace( '"', '', $timezone );
|
788
|
$search = str_replace( array('GMT', 'gmt', 'utc' ), 'UTC', $search );
|
789
|
if( '(UTC' != substr( $search, 0, 4 ))
|
790
|
return FALSE;
|
791
|
if( FALSE === ( $pos = strpos( $search, ')' )))
|
792
|
return FALSE;
|
793
|
$pos = strpos( $search, ')' );
|
794
|
$searchOffset = substr( $search, 4, ( $pos - 4 ));
|
795
|
$searchOffset = iCalUtilityFunctions::_tz2offset( str_replace( ':', '', $searchOffset ));
|
796
|
while( ' ' ==substr( $search, ( $pos + 1 )))
|
797
|
$pos += 1;
|
798
|
$searchText = trim( str_replace( array( '(', ')', '&', ',', ' ' ), ' ', substr( $search, ( $pos + 1 )) ));
|
799
|
$searchWords = explode( ' ', $searchText );
|
800
|
$timezone_abbreviations = DateTimeZone::listAbbreviations();
|
801
|
$hits = array();
|
802
|
foreach( $timezone_abbreviations as $name => $transitions ) {
|
803
|
foreach( $transitions as $cnt => $transition ) {
|
804
|
if( empty( $transition['offset'] ) ||
|
805
|
empty( $transition['timezone_id'] ) ||
|
806
|
( $transition['offset'] != $searchOffset ))
|
807
|
continue;
|
808
|
$cWords = explode( '/', $transition['timezone_id'] );
|
809
|
$cPrio = $hitCnt = $rank = 0;
|
810
|
foreach( $cWords as $cWord ) {
|
811
|
if( empty( $cWord ))
|
812
|
continue;
|
813
|
$cPrio += 1;
|
814
|
$sPrio = 0;
|
815
|
foreach( $searchWords as $sWord ) {
|
816
|
if( empty( $sWord ) || ( 'time' == strtolower( $sWord )))
|
817
|
continue;
|
818
|
$sPrio += 1;
|
819
|
if( strtolower( $cWord ) == strtolower( $sWord )) {
|
820
|
$hitCnt += 1;
|
821
|
$rank += ( $cPrio + $sPrio );
|
822
|
}
|
823
|
else
|
824
|
$rank += 10;
|
825
|
}
|
826
|
}
|
827
|
if( 0 < $hitCnt ) {
|
828
|
$hits[$rank][] = $transition['timezone_id'];
|
829
|
}
|
830
|
}
|
831
|
}
|
832
|
unset( $timezone_abbreviations );
|
833
|
if( empty( $hits ))
|
834
|
return FALSE;
|
835
|
ksort( $hits );
|
836
|
foreach( $hits as $rank => $tzs ) {
|
837
|
if( !empty( $tzs )) {
|
838
|
$timezone = reset( $tzs );
|
839
|
return TRUE;
|
840
|
}
|
841
|
}
|
842
|
return FALSE;
|
843
|
}
|
844
|
|
845
|
|
846
|
|
847
|
|
848
|
|
849
|
|
850
|
|
851
|
|
852
|
public static function offsetSec2His( $seconds ) {
|
853
|
if( '-' == substr( $seconds, 0, 1 )) {
|
854
|
$prefix = '-';
|
855
|
$seconds = substr( $seconds, 1 );
|
856
|
}
|
857
|
elseif( '+' == substr( $seconds, 0, 1 )) {
|
858
|
$prefix = '+';
|
859
|
$seconds = substr( $seconds, 1 );
|
860
|
}
|
861
|
else
|
862
|
$prefix = '+';
|
863
|
$output = '';
|
864
|
$hour = (int) floor( $seconds / 3600 );
|
865
|
if( 10 > $hour )
|
866
|
$hour = '0'.$hour;
|
867
|
$seconds = $seconds % 3600;
|
868
|
$min = (int) floor( $seconds / 60 );
|
869
|
if( 10 > $min )
|
870
|
$min = '0'.$min;
|
871
|
$output = $hour.$min;
|
872
|
$seconds = $seconds % 60;
|
873
|
if( 0 < $seconds) {
|
874
|
if( 9 < $seconds)
|
875
|
$output .= $seconds;
|
876
|
else
|
877
|
$output .= '0'.$seconds;
|
878
|
}
|
879
|
return $prefix.$output;
|
880
|
}
|
881
|
|
882
|
|
883
|
|
884
|
|
885
|
|
886
|
|
887
|
|
888
|
|
889
|
|
890
|
|
891
|
|
892
|
|
893
|
|
894
|
|
895
|
|
896
|
|
897
|
|
898
|
|
899
|
|
900
|
|
901
|
public static function _recur2date( & $result, $recur, $wdate, $fcnStart, $fcnEnd=FALSE ) {
|
902
|
if( is_string( $wdate ))
|
903
|
iCalUtilityFunctions::_strDate2arr( $wdate );
|
904
|
elseif( is_a( $wdate, 'DateTime' )) {
|
905
|
$wdate = $wdate->format( iCalUtilityFunctions::$fmt['YmdHis2'] );
|
906
|
iCalUtilityFunctions::_strDate2arr( $wdate );
|
907
|
}
|
908
|
foreach( $wdate as $k => $v ) if( ctype_digit( $v )) $wdate[$k] = (int) $v;
|
909
|
$wdateYMD = sprintf( iCalUtilityFunctions::$fmt['Ymd'], $wdate['year'], $wdate['month'], $wdate['day'] );
|
910
|
$wdateHis = sprintf( iCalUtilityFunctions::$fmt['His'], $wdate['hour'], $wdate['min'], $wdate['sec'] );
|
911
|
$untilHis = $wdateHis;
|
912
|
if( is_string( $fcnStart ))
|
913
|
iCalUtilityFunctions::_strDate2arr( $fcnStart );
|
914
|
elseif( is_a( $fcnStart, 'DateTime' )) {
|
915
|
$fcnStart = $fcnStart->format( iCalUtilityFunctions::$fmt['YmdHis2'] );
|
916
|
iCalUtilityFunctions::_strDate2arr( $fcnStart );
|
917
|
}
|
918
|
foreach( $fcnStart as $k => $v ) if( ctype_digit( $v )) $fcnStart[$k] = (int) $v;
|
919
|
$fcnStartYMD = sprintf( iCalUtilityFunctions::$fmt['Ymd'], $fcnStart['year'], $fcnStart['month'], $fcnStart['day'] );
|
920
|
if( is_string( $fcnEnd ))
|
921
|
iCalUtilityFunctions::_strDate2arr( $fcnEnd );
|
922
|
elseif( is_a( $fcnEnd, 'DateTime' )) {
|
923
|
$fcnEnd = $fcnEnd->format( iCalUtilityFunctions::$fmt['YmdHis2'] );
|
924
|
iCalUtilityFunctions::_strDate2arr( $fcnEnd );
|
925
|
}
|
926
|
if( !$fcnEnd ) {
|
927
|
$fcnEnd = $fcnStart;
|
928
|
$fcnEnd['year'] += 1;
|
929
|
}
|
930
|
foreach( $fcnEnd as $k => $v ) if( ctype_digit( $v )) $fcnEnd[$k] = (int) $v;
|
931
|
$fcnEndYMD = sprintf( iCalUtilityFunctions::$fmt['Ymd'], $fcnEnd['year'], $fcnEnd['month'], $fcnEnd['day'] );
|
932
|
|
933
|
|
934
|
if( !isset( $recur['COUNT'] ) && !isset( $recur['UNTIL'] ))
|
935
|
$recur['UNTIL'] = $fcnEnd;
|
936
|
if( isset( $recur['UNTIL'] )) {
|
937
|
foreach( $recur['UNTIL'] as $k => $v ) if( ctype_digit( $v )) $recur['UNTIL'][$k] = (int) $v;
|
938
|
unset( $recur['UNTIL']['tz'] );
|
939
|
if( $fcnEnd > $recur['UNTIL'] ) {
|
940
|
$fcnEnd = $recur['UNTIL'];
|
941
|
$fcnEndYMD = sprintf( iCalUtilityFunctions::$fmt['Ymd'], $fcnEnd['year'], $fcnEnd['month'], $fcnEnd['day'] );
|
942
|
}
|
943
|
if( isset( $recur['UNTIL']['hour'] ))
|
944
|
$untilHis = sprintf( iCalUtilityFunctions::$fmt['His'], $recur['UNTIL']['hour'], $recur['UNTIL']['min'], $recur['UNTIL']['sec'] );
|
945
|
else
|
946
|
$untilHis = sprintf( iCalUtilityFunctions::$fmt['His'], 23, 59, 59 );
|
947
|
|
948
|
}
|
949
|
|
950
|
if( $wdateYMD > $fcnEndYMD ) {
|
951
|
|
952
|
return array();
|
953
|
}
|
954
|
if( !isset( $recur['FREQ'] ))
|
955
|
$recur['FREQ'] = 'DAILY';
|
956
|
$wkst = ( isset( $recur['WKST'] ) && ( 'SU' == $recur['WKST'] )) ? 24*60*60 : 0;
|
957
|
if( !isset( $recur['INTERVAL'] ))
|
958
|
$recur['INTERVAL'] = 1;
|
959
|
$countcnt = ( !isset( $recur['BYSETPOS'] )) ? 1 : 0;
|
960
|
|
961
|
$step = array();
|
962
|
if( 'YEARLY' == $recur['FREQ'] )
|
963
|
$step['year'] = 1;
|
964
|
elseif( 'MONTHLY' == $recur['FREQ'] )
|
965
|
$step['month'] = 1;
|
966
|
elseif( 'WEEKLY' == $recur['FREQ'] )
|
967
|
$step['day'] = 7;
|
968
|
else
|
969
|
$step['day'] = 1;
|
970
|
if( isset( $step['year'] ) && isset( $recur['BYMONTH'] ))
|
971
|
$step = array( 'month' => 1 );
|
972
|
if( empty( $step ) && isset( $recur['BYWEEKNO'] ))
|
973
|
$step = array( 'day' => 7 );
|
974
|
if( isset( $recur['BYYEARDAY'] ) || isset( $recur['BYMONTHDAY'] ) || isset( $recur['BYDAY'] ))
|
975
|
$step = array( 'day' => 1 );
|
976
|
$intervalarr = array();
|
977
|
if( 1 < $recur['INTERVAL'] ) {
|
978
|
$intervalix = iCalUtilityFunctions::_recurIntervalIx( $recur['FREQ'], $wdate, $wkst );
|
979
|
$intervalarr = array( $intervalix => 0 );
|
980
|
}
|
981
|
if( isset( $recur['BYSETPOS'] )) {
|
982
|
$bysetposymd1 = $bysetposymd2 = $bysetposw1 = $bysetposw2 = array();
|
983
|
|
984
|
if( is_array( $recur['BYSETPOS'] )) {
|
985
|
foreach( $recur['BYSETPOS'] as $bix => $bval )
|
986
|
$recur['BYSETPOS'][$bix] = (int) $bval;
|
987
|
}
|
988
|
else
|
989
|
$recur['BYSETPOS'] = array( (int) $recur['BYSETPOS'] );
|
990
|
if( 'YEARLY' == $recur['FREQ'] ) {
|
991
|
$wdate['month'] = $wdate['day'] = 1;
|
992
|
$wdateYMD = sprintf( iCalUtilityFunctions::$fmt['Ymd'], $wdate['year'], $wdate['month'], $wdate['day'] );
|
993
|
iCalUtilityFunctions::_stepdate( $fcnEnd, $fcnEndYMD, array( 'year' => 1 ));
|
994
|
}
|
995
|
elseif( 'MONTHLY' == $recur['FREQ'] ) {
|
996
|
$wdate['day'] = 1;
|
997
|
$wdateYMD = sprintf( iCalUtilityFunctions::$fmt['Ymd'], $wdate['year'], $wdate['month'], $wdate['day'] );
|
998
|
iCalUtilityFunctions::_stepdate( $fcnEnd, $fcnEndYMD, array( 'month' => 1 ));
|
999
|
}
|
1000
|
else
|
1001
|
iCalUtilityFunctions::_stepdate( $fcnEnd, $fcnEndYMD, $step);
|
1002
|
|
1003
|
$bysetposWold = (int) date( 'W', mktime( 0, 0, $wkst, $wdate['month'], $wdate['day'], $wdate['year'] ));
|
1004
|
$bysetposYold = $wdate['year'];
|
1005
|
$bysetposMold = $wdate['month'];
|
1006
|
$bysetposDold = $wdate['day'];
|
1007
|
}
|
1008
|
else
|
1009
|
iCalUtilityFunctions::_stepdate( $wdate, $wdateYMD, $step);
|
1010
|
$year_old = null;
|
1011
|
static $daynames = array( 'SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA' );
|
1012
|
|
1013
|
|
1014
|
while( TRUE ) {
|
1015
|
|
1016
|
if( $wdateYMD.$wdateHis > $fcnEndYMD.$untilHis )
|
1017
|
break;
|
1018
|
if( isset( $recur['COUNT'] ) && ( $countcnt >= $recur['COUNT'] ))
|
1019
|
break;
|
1020
|
if( $year_old != $wdate['year'] ) {
|
1021
|
$year_old = $wdate['year'];
|
1022
|
$daycnts = array();
|
1023
|
$yeardays = $weekno = 0;
|
1024
|
$yeardaycnt = array();
|
1025
|
foreach( $daynames as $dn )
|
1026
|
$yeardaycnt[$dn] = 0;
|
1027
|
for( $m = 1; $m <= 12; $m++ ) {
|
1028
|
$daycnts[$m] = array();
|
1029
|
$weekdaycnt = array();
|
1030
|
foreach( $daynames as $dn )
|
1031
|
$weekdaycnt[$dn] = 0;
|
1032
|
$mcnt = date( 't', mktime( 0, 0, 0, $m, 1, $wdate['year'] ));
|
1033
|
for( $d = 1; $d <= $mcnt; $d++ ) {
|
1034
|
$daycnts[$m][$d] = array();
|
1035
|
if( isset( $recur['BYYEARDAY'] )) {
|
1036
|
$yeardays++;
|
1037
|
$daycnts[$m][$d]['yearcnt_up'] = $yeardays;
|
1038
|
}
|
1039
|
if( isset( $recur['BYDAY'] )) {
|
1040
|
$day = date( 'w', mktime( 0, 0, 0, $m, $d, $wdate['year'] ));
|
1041
|
$day = $daynames[$day];
|
1042
|
$daycnts[$m][$d]['DAY'] = $day;
|
1043
|
$weekdaycnt[$day]++;
|
1044
|
$daycnts[$m][$d]['monthdayno_up'] = $weekdaycnt[$day];
|
1045
|
$yeardaycnt[$day]++;
|
1046
|
$daycnts[$m][$d]['yeardayno_up'] = $yeardaycnt[$day];
|
1047
|
}
|
1048
|
if( isset( $recur['BYWEEKNO'] ) || ( $recur['FREQ'] == 'WEEKLY' ))
|
1049
|
$daycnts[$m][$d]['weekno_up'] =(int)date('W',mktime(0,0,$wkst,$m,$d,$wdate['year']));
|
1050
|
}
|
1051
|
}
|
1052
|
$daycnt = 0;
|
1053
|
$yeardaycnt = array();
|
1054
|
if( isset( $recur['BYWEEKNO'] ) || ( $recur['FREQ'] == 'WEEKLY' )) {
|
1055
|
$weekno = null;
|
1056
|
for( $d=31; $d > 25; $d-- ) {
|
1057
|
if( !$weekno )
|
1058
|
$weekno = $daycnts[12][$d]['weekno_up'];
|
1059
|
elseif( $weekno < $daycnts[12][$d]['weekno_up'] ) {
|
1060
|
$weekno = $daycnts[12][$d]['weekno_up'];
|
1061
|
break;
|
1062
|
}
|
1063
|
}
|
1064
|
}
|
1065
|
for( $m = 12; $m > 0; $m-- ) {
|
1066
|
$weekdaycnt = array();
|
1067
|
foreach( $daynames as $dn )
|
1068
|
$yeardaycnt[$dn] = $weekdaycnt[$dn] = 0;
|
1069
|
$monthcnt = 0;
|
1070
|
$mcnt = date( 't', mktime( 0, 0, 0, $m, 1, $wdate['year'] ));
|
1071
|
for( $d = $mcnt; $d > 0; $d-- ) {
|
1072
|
if( isset( $recur['BYYEARDAY'] )) {
|
1073
|
$daycnt -= 1;
|
1074
|
$daycnts[$m][$d]['yearcnt_down'] = $daycnt;
|
1075
|
}
|
1076
|
if( isset( $recur['BYMONTHDAY'] )) {
|
1077
|
$monthcnt -= 1;
|
1078
|
$daycnts[$m][$d]['monthcnt_down'] = $monthcnt;
|
1079
|
}
|
1080
|
if( isset( $recur['BYDAY'] )) {
|
1081
|
$day = $daycnts[$m][$d]['DAY'];
|
1082
|
$weekdaycnt[$day] -= 1;
|
1083
|
$daycnts[$m][$d]['monthdayno_down'] = $weekdaycnt[$day];
|
1084
|
$yeardaycnt[$day] -= 1;
|
1085
|
$daycnts[$m][$d]['yeardayno_down'] = $yeardaycnt[$day];
|
1086
|
}
|
1087
|
if( isset( $recur['BYWEEKNO'] ) || ( $recur['FREQ'] == 'WEEKLY' ))
|
1088
|
$daycnts[$m][$d]['weekno_down'] = ($daycnts[$m][$d]['weekno_up'] - $weekno - 1);
|
1089
|
}
|
1090
|
}
|
1091
|
}
|
1092
|
|
1093
|
if( 1 < $recur['INTERVAL'] ) {
|
1094
|
|
1095
|
$intervalix = iCalUtilityFunctions::_recurIntervalIx( $recur['FREQ'], $wdate, $wkst );
|
1096
|
|
1097
|
$currentKey = array_keys( $intervalarr );
|
1098
|
$currentKey = end( $currentKey );
|
1099
|
if( $currentKey != $intervalix )
|
1100
|
$intervalarr = array( $intervalix => ( $intervalarr[$currentKey] + 1 ));
|
1101
|
if(( $recur['INTERVAL'] != $intervalarr[$intervalix] ) &&
|
1102
|
( 0 != $intervalarr[$intervalix] )) {
|
1103
|
|
1104
|
|
1105
|
iCalUtilityFunctions::_stepdate( $wdate, $wdateYMD, $step);
|
1106
|
continue;
|
1107
|
}
|
1108
|
else
|
1109
|
$intervalarr[$intervalix] = 0;
|
1110
|
|
1111
|
}
|
1112
|
$updateOK = TRUE;
|
1113
|
if( $updateOK && isset( $recur['BYMONTH'] ))
|
1114
|
$updateOK = iCalUtilityFunctions::_recurBYcntcheck( $recur['BYMONTH']
|
1115
|
, $wdate['month']
|
1116
|
,($wdate['month'] - 13));
|
1117
|
if( $updateOK && isset( $recur['BYWEEKNO'] ))
|
1118
|
$updateOK = iCalUtilityFunctions::_recurBYcntcheck( $recur['BYWEEKNO']
|
1119
|
, $daycnts[$wdate['month']][$wdate['day']]['weekno_up']
|
1120
|
, $daycnts[$wdate['month']][$wdate['day']]['weekno_down'] );
|
1121
|
if( $updateOK && isset( $recur['BYYEARDAY'] ))
|
1122
|
$updateOK = iCalUtilityFunctions::_recurBYcntcheck( $recur['BYYEARDAY']
|
1123
|
, $daycnts[$wdate['month']][$wdate['day']]['yearcnt_up']
|
1124
|
, $daycnts[$wdate['month']][$wdate['day']]['yearcnt_down'] );
|
1125
|
if( $updateOK && isset( $recur['BYMONTHDAY'] ))
|
1126
|
$updateOK = iCalUtilityFunctions::_recurBYcntcheck( $recur['BYMONTHDAY']
|
1127
|
, $wdate['day']
|
1128
|
, $daycnts[$wdate['month']][$wdate['day']]['monthcnt_down'] );
|
1129
|
|
1130
|
if( $updateOK && isset( $recur['BYDAY'] )) {
|
1131
|
$updateOK = FALSE;
|
1132
|
$m = $wdate['month'];
|
1133
|
$d = $wdate['day'];
|
1134
|
if( isset( $recur['BYDAY']['DAY'] )) {
|
1135
|
$daynoexists = $daynosw = $daynamesw = FALSE;
|
1136
|
if( $recur['BYDAY']['DAY'] == $daycnts[$m][$d]['DAY'] )
|
1137
|
$daynamesw = TRUE;
|
1138
|
if( isset( $recur['BYDAY'][0] )) {
|
1139
|
$daynoexists = TRUE;
|
1140
|
if(( isset( $recur['FREQ'] ) && ( $recur['FREQ'] == 'MONTHLY' )) || isset( $recur['BYMONTH'] ))
|
1141
|
$daynosw = iCalUtilityFunctions::_recurBYcntcheck( $recur['BYDAY'][0]
|
1142
|
, $daycnts[$m][$d]['monthdayno_up']
|
1143
|
, $daycnts[$m][$d]['monthdayno_down'] );
|
1144
|
elseif( isset( $recur['FREQ'] ) && ( $recur['FREQ'] == 'YEARLY' ))
|
1145
|
$daynosw = iCalUtilityFunctions::_recurBYcntcheck( $recur['BYDAY'][0]
|
1146
|
, $daycnts[$m][$d]['yeardayno_up']
|
1147
|
, $daycnts[$m][$d]['yeardayno_down'] );
|
1148
|
}
|
1149
|
if(( $daynoexists && $daynosw && $daynamesw ) ||
|
1150
|
( !$daynoexists && !$daynosw && $daynamesw )) {
|
1151
|
$updateOK = TRUE;
|
1152
|
|
1153
|
}
|
1154
|
|
1155
|
}
|
1156
|
else {
|
1157
|
foreach( $recur['BYDAY'] as $bydayvalue ) {
|
1158
|
$daynoexists = $daynosw = $daynamesw = FALSE;
|
1159
|
if( isset( $bydayvalue['DAY'] ) &&
|
1160
|
( $bydayvalue['DAY'] == $daycnts[$m][$d]['DAY'] ))
|
1161
|
$daynamesw = TRUE;
|
1162
|
if( isset( $bydayvalue[0] )) {
|
1163
|
$daynoexists = TRUE;
|
1164
|
if(( isset( $recur['FREQ'] ) && ( $recur['FREQ'] == 'MONTHLY' )) ||
|
1165
|
isset( $recur['BYMONTH'] ))
|
1166
|
$daynosw = iCalUtilityFunctions::_recurBYcntcheck( $bydayvalue['0']
|
1167
|
, $daycnts[$m][$d]['monthdayno_up']
|
1168
|
, $daycnts[$m][$d]['monthdayno_down'] );
|
1169
|
elseif( isset( $recur['FREQ'] ) && ( $recur['FREQ'] == 'YEARLY' ))
|
1170
|
$daynosw = iCalUtilityFunctions::_recurBYcntcheck( $bydayvalue['0']
|
1171
|
, $daycnts[$m][$d]['yeardayno_up']
|
1172
|
, $daycnts[$m][$d]['yeardayno_down'] );
|
1173
|
}
|
1174
|
|
1175
|
if(( $daynoexists && $daynosw && $daynamesw ) ||
|
1176
|
( !$daynoexists && !$daynosw && $daynamesw )) {
|
1177
|
$updateOK = TRUE;
|
1178
|
break;
|
1179
|
}
|
1180
|
}
|
1181
|
}
|
1182
|
}
|
1183
|
|
1184
|
|
1185
|
if( $updateOK ) {
|
1186
|
if( isset( $recur['BYSETPOS'] ) &&
|
1187
|
( in_array( $recur['FREQ'], array( 'YEARLY', 'MONTHLY', 'WEEKLY', 'DAILY' )))) {
|
1188
|
if( isset( $recur['WEEKLY'] )) {
|
1189
|
if( $bysetposWold == $daycnts[$wdate['month']][$wdate['day']]['weekno_up'] )
|
1190
|
$bysetposw1[] = $wdateYMD;
|
1191
|
else
|
1192
|
$bysetposw2[] = $wdateYMD;
|
1193
|
}
|
1194
|
else {
|
1195
|
if(( isset( $recur['FREQ'] ) && ( 'YEARLY' == $recur['FREQ'] ) &&
|
1196
|
( $bysetposYold == $wdate['year'] )) ||
|
1197
|
( isset( $recur['FREQ'] ) && ( 'MONTHLY' == $recur['FREQ'] ) &&
|
1198
|
(( $bysetposYold == $wdate['year'] ) &&
|
1199
|
( $bysetposMold == $wdate['month'] ))) ||
|
1200
|
( isset( $recur['FREQ'] ) && ( 'DAILY' == $recur['FREQ'] ) &&
|
1201
|
(( $bysetposYold == $wdate['year'] ) &&
|
1202
|
( $bysetposMold == $wdate['month']) &&
|
1203
|
( $bysetposDold == $wdate['day'] )))) {
|
1204
|
|
1205
|
$bysetposymd1[] = $wdateYMD;
|
1206
|
}
|
1207
|
else {
|
1208
|
|
1209
|
$bysetposymd2[] = $wdateYMD;
|
1210
|
}
|
1211
|
}
|
1212
|
}
|
1213
|
else {
|
1214
|
if( checkdate($wdate['month'], $wdate['day'], $wdate['year'] )) {
|
1215
|
|
1216
|
$countcnt++;
|
1217
|
if( $fcnStartYMD <= $wdateYMD ) {
|
1218
|
$result[$wdateYMD] = TRUE;
|
1219
|
|
1220
|
}
|
1221
|
}
|
1222
|
|
1223
|
$updateOK = FALSE;
|
1224
|
}
|
1225
|
}
|
1226
|
|
1227
|
iCalUtilityFunctions::_stepdate( $wdate, $wdateYMD, $step);
|
1228
|
|
1229
|
if( $updateOK && isset( $recur['BYSETPOS'] )) {
|
1230
|
$bysetpos = FALSE;
|
1231
|
if( isset( $recur['FREQ'] ) && ( 'YEARLY' == $recur['FREQ'] ) &&
|
1232
|
( $bysetposYold != $wdate['year'] )) {
|
1233
|
$bysetpos = TRUE;
|
1234
|
$bysetposYold = $wdate['year'];
|
1235
|
}
|
1236
|
elseif( isset( $recur['FREQ'] ) && ( 'MONTHLY' == $recur['FREQ'] &&
|
1237
|
(( $bysetposYold != $wdate['year'] ) || ( $bysetposMold != $wdate['month'] )))) {
|
1238
|
$bysetpos = TRUE;
|
1239
|
$bysetposYold = $wdate['year'];
|
1240
|
$bysetposMold = $wdate['month'];
|
1241
|
}
|
1242
|
elseif( isset( $recur['FREQ'] ) && ( 'WEEKLY' == $recur['FREQ'] )) {
|
1243
|
$weekno = (int) date( 'W', mktime( 0, 0, $wkst, $wdate['month'], $wdate['day'], $wdate['year']));
|
1244
|
if( $bysetposWold != $weekno ) {
|
1245
|
$bysetposWold = $weekno;
|
1246
|
$bysetpos = TRUE;
|
1247
|
}
|
1248
|
}
|
1249
|
elseif( isset( $recur['FREQ'] ) && ( 'DAILY' == $recur['FREQ'] ) &&
|
1250
|
(( $bysetposYold != $wdate['year'] ) ||
|
1251
|
( $bysetposMold != $wdate['month'] ) ||
|
1252
|
( $bysetposDold != $wdate['day'] ))) {
|
1253
|
$bysetpos = TRUE;
|
1254
|
$bysetposYold = $wdate['year'];
|
1255
|
$bysetposMold = $wdate['month'];
|
1256
|
$bysetposDold = $wdate['day'];
|
1257
|
}
|
1258
|
if( $bysetpos ) {
|
1259
|
if( isset( $recur['BYWEEKNO'] )) {
|
1260
|
$bysetposarr1 = & $bysetposw1;
|
1261
|
$bysetposarr2 = & $bysetposw2;
|
1262
|
}
|
1263
|
else {
|
1264
|
$bysetposarr1 = & $bysetposymd1;
|
1265
|
$bysetposarr2 = & $bysetposymd2;
|
1266
|
}
|
1267
|
|
1268
|
foreach( $recur['BYSETPOS'] as $ix ) {
|
1269
|
if( 0 > $ix )
|
1270
|
$ix = ( count( $bysetposarr1 ) + $ix + 1);
|
1271
|
$ix--;
|
1272
|
if( isset( $bysetposarr1[$ix] )) {
|
1273
|
if( $fcnStartYMD <= $bysetposarr1[$ix] ) {
|
1274
|
|
1275
|
|
1276
|
$result[$bysetposarr1[$ix]] = TRUE;
|
1277
|
}
|
1278
|
$countcnt++;
|
1279
|
}
|
1280
|
if( isset( $recur['COUNT'] ) && ( $countcnt >= $recur['COUNT'] ))
|
1281
|
break;
|
1282
|
}
|
1283
|
|
1284
|
$bysetposarr1 = $bysetposarr2;
|
1285
|
$bysetposarr2 = array();
|
1286
|
}
|
1287
|
}
|
1288
|
}
|
1289
|
|
1290
|
}
|
1291
|
|
1292
|
|
1293
|
|
1294
|
|
1295
|
|
1296
|
|
1297
|
|
1298
|
|
1299
|
|
1300
|
|
1301
|
public static function _recurBYcntcheck( $BYvalue, $upValue, $downValue ) {
|
1302
|
if( is_array( $BYvalue ) &&
|
1303
|
( in_array( $upValue, $BYvalue ) || in_array( $downValue, $BYvalue )))
|
1304
|
return TRUE;
|
1305
|
elseif(( $BYvalue == $upValue ) || ( $BYvalue == $downValue ))
|
1306
|
return TRUE;
|
1307
|
else
|
1308
|
return FALSE;
|
1309
|
}
|
1310
|
|
1311
|
|
1312
|
|
1313
|
|
1314
|
|
1315
|
|
1316
|
|
1317
|
|
1318
|
|
1319
|
|
1320
|
public static function _recurIntervalIx( $freq, $date, $wkst ) {
|
1321
|
|
1322
|
switch( $freq ) {
|
1323
|
case 'YEARLY':
|
1324
|
$intervalix = $date['year'];
|
1325
|
break;
|
1326
|
case 'MONTHLY':
|
1327
|
$intervalix = $date['year'].'-'.$date['month'];
|
1328
|
break;
|
1329
|
case 'WEEKLY':
|
1330
|
$intervalix = (int) date( 'W', mktime( 0, 0, $wkst, (int) $date['month'], (int) $date['day'], (int) $date['year'] ));
|
1331
|
break;
|
1332
|
case 'DAILY':
|
1333
|
default:
|
1334
|
$intervalix = $date['year'].'-'.$date['month'].'-'.$date['day'];
|
1335
|
break;
|
1336
|
}
|
1337
|
return $intervalix;
|
1338
|
}
|
1339
|
|
1340
|
|
1341
|
|
1342
|
|
1343
|
|
1344
|
|
1345
|
|
1346
|
|
1347
|
|
1348
|
public static function _recurBydaySort( $bydaya, $bydayb ) {
|
1349
|
static $days = array( 'SU' => 0, 'MO' => 1, 'TU' => 2, 'WE' => 3, 'TH' => 4, 'FR' => 5, 'SA' => 6 );
|
1350
|
return ( $days[substr( $bydaya, -2 )] < $days[substr( $bydayb, -2 )] ) ? -1 : 1;
|
1351
|
}
|
1352
|
|
1353
|
|
1354
|
|
1355
|
|
1356
|
|
1357
|
|
1358
|
|
1359
|
|
1360
|
|
1361
|
|
1362
|
|
1363
|
|
1364
|
|
1365
|
|
1366
|
|
1367
|
public static function _setRexrule( $rexrule ) {
|
1368
|
$input = array();
|
1369
|
if( empty( $rexrule ))
|
1370
|
return $input;
|
1371
|
$rexrule = array_change_key_case( $rexrule, CASE_UPPER );
|
1372
|
foreach( $rexrule as $rexrulelabel => $rexrulevalue ) {
|
1373
|
if( 'UNTIL' != $rexrulelabel )
|
1374
|
$input[$rexrulelabel] = $rexrulevalue;
|
1375
|
else {
|
1376
|
iCalUtilityFunctions::_strDate2arr( $rexrulevalue );
|
1377
|
if( iCalUtilityFunctions::_isArrayTimestampDate( $rexrulevalue ))
|
1378
|
$input[$rexrulelabel] = iCalUtilityFunctions::_timestamp2date( $rexrulevalue, 7, 'UTC' );
|
1379
|
elseif( iCalUtilityFunctions::_isArrayDate( $rexrulevalue )) {
|
1380
|
$parno = ( isset( $rexrulevalue['hour'] ) || isset( $rexrulevalue[4] )) ? 7 : 3;
|
1381
|
$d = iCalUtilityFunctions::_chkDateArr( $rexrulevalue, $parno );
|
1382
|
if(( 3 < $parno ) && isset( $d['tz'] ) && ( 'Z' != $d['tz'] ) && iCalUtilityFunctions::_isOffset( $d['tz'] )) {
|
1383
|
$strdate = sprintf( iCalUtilityFunctions::$fmt['YmdHise'], (int) $d['year'], (int) $d['month'], (int) $d['day'], (int) $d['hour'], (int) $d['min'], (int) $d['sec'], $d['tz'] );
|
1384
|
$input[$rexrulelabel] = iCalUtilityFunctions::_strdate2date( $strdate, 7 );
|
1385
|
unset( $input[$rexrulelabel]['unparsedtext'] );
|
1386
|
}
|
1387
|
else
|
1388
|
$input[$rexrulelabel] = $d;
|
1389
|
}
|
1390
|
elseif( 8 <= strlen( trim( $rexrulevalue ))) {
|
1391
|
$input[$rexrulelabel] = iCalUtilityFunctions::_strdate2date( $rexrulevalue );
|
1392
|
unset( $input['$rexrulelabel']['unparsedtext'] );
|
1393
|
}
|
1394
|
if(( 3 < count( $input[$rexrulelabel] )) && !isset( $input[$rexrulelabel]['tz'] ))
|
1395
|
$input[$rexrulelabel]['tz'] = 'Z';
|
1396
|
}
|
1397
|
}
|
1398
|
|
1399
|
$input2 = array();
|
1400
|
if( isset( $input['FREQ'] ))
|
1401
|
$input2['FREQ'] = $input['FREQ'];
|
1402
|
if( isset( $input['UNTIL'] ))
|
1403
|
$input2['UNTIL'] = $input['UNTIL'];
|
1404
|
elseif( isset( $input['COUNT'] ))
|
1405
|
$input2['COUNT'] = $input['COUNT'];
|
1406
|
if( isset( $input['INTERVAL'] ))
|
1407
|
$input2['INTERVAL'] = $input['INTERVAL'];
|
1408
|
if( isset( $input['BYSECOND'] ))
|
1409
|
$input2['BYSECOND'] = $input['BYSECOND'];
|
1410
|
if( isset( $input['BYMINUTE'] ))
|
1411
|
$input2['BYMINUTE'] = $input['BYMINUTE'];
|
1412
|
if( isset( $input['BYHOUR'] ))
|
1413
|
$input2['BYHOUR'] = $input['BYHOUR'];
|
1414
|
if( isset( $input['BYDAY'] )) {
|
1415
|
if( !is_array( $input['BYDAY'] ))
|
1416
|
$input2['BYDAY'] = strtoupper( $input['BYDAY'] );
|
1417
|
else {
|
1418
|
foreach( $input['BYDAY'] as $BYDAYx => $BYDAYv ) {
|
1419
|
if( 'DAY' == strtoupper( $BYDAYx ))
|
1420
|
$input2['BYDAY']['DAY'] = strtoupper( $BYDAYv );
|
1421
|
elseif( !is_array( $BYDAYv )) {
|
1422
|
$input2['BYDAY'][$BYDAYx] = $BYDAYv;
|
1423
|
}
|
1424
|
else {
|
1425
|
foreach( $BYDAYv as $BYDAYx2 => $BYDAYv2 ) {
|
1426
|
if( 'DAY' == strtoupper( $BYDAYx2 ))
|
1427
|
$input2['BYDAY'][$BYDAYx]['DAY'] = strtoupper( $BYDAYv2 );
|
1428
|
else
|
1429
|
$input2['BYDAY'][$BYDAYx][$BYDAYx2] = $BYDAYv2;
|
1430
|
}
|
1431
|
}
|
1432
|
}
|
1433
|
}
|
1434
|
}
|
1435
|
if( isset( $input['BYMONTHDAY'] ))
|
1436
|
$input2['BYMONTHDAY'] = $input['BYMONTHDAY'];
|
1437
|
if( isset( $input['BYYEARDAY'] ))
|
1438
|
$input2['BYYEARDAY'] = $input['BYYEARDAY'];
|
1439
|
if( isset( $input['BYWEEKNO'] ))
|
1440
|
$input2['BYWEEKNO'] = $input['BYWEEKNO'];
|
1441
|
if( isset( $input['BYMONTH'] ))
|
1442
|
$input2['BYMONTH'] = $input['BYMONTH'];
|
1443
|
if( isset( $input['BYSETPOS'] ))
|
1444
|
$input2['BYSETPOS'] = $input['BYSETPOS'];
|
1445
|
if( isset( $input['WKST'] ))
|
1446
|
$input2['WKST'] = $input['WKST'];
|
1447
|
return $input2;
|
1448
|
}
|
1449
|
|
1450
|
|
1451
|
|
1452
|
|
1453
|
|
1454
|
|
1455
|
|
1456
|
|
1457
|
|
1458
|
|
1459
|
|
1460
|
|
1461
|
|
1462
|
|
1463
|
|
1464
|
|
1465
|
|
1466
|
|
1467
|
|
1468
|
|
1469
|
|
1470
|
|
1471
|
|
1472
|
|
1473
|
|
1474
|
|
1475
|
|
1476
|
|
1477
|
|
1478
|
public static function _setDate( $year, $month=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $tz=FALSE, $params=FALSE, $caller=null, $objName=null, $tzid=FALSE ) {
|
1479
|
$input = $parno = null;
|
1480
|
$localtime = (( 'dtstart' == $caller ) && in_array( $objName, iCalUtilityFunctions::$tzComps )) ? TRUE : FALSE;
|
1481
|
iCalUtilityFunctions::_strDate2arr( $year );
|
1482
|
if( iCalUtilityFunctions::_isArrayDate( $year )) {
|
1483
|
$input['value'] = iCalUtilityFunctions::_chkDateArr( $year, FALSE );
|
1484
|
if( 100 > $input['value']['year'] )
|
1485
|
$input['value']['year'] += 2000;
|
1486
|
if( $localtime )
|
1487
|
unset( $month['VALUE'], $month['TZID'] );
|
1488
|
elseif( !isset( $month['TZID'] ) && isset( $tzid ))
|
1489
|
$month['TZID'] = $tzid;
|
1490
|
if( isset( $input['value']['tz'] ) && iCalUtilityFunctions::_isOffset( $input['value']['tz'] ))
|
1491
|
unset( $month['TZID'] );
|
1492
|
elseif( !isset( $input['value']['tz'] ) && isset( $month['TZID'] ) && iCalUtilityFunctions::_isOffset( $month['TZID'] )) {
|
1493
|
$input['value']['tz'] = $month['TZID'];
|
1494
|
unset( $month['TZID'] );
|
1495
|
}
|
1496
|
$input['params'] = iCalUtilityFunctions::_setParams( $month, array( 'VALUE' => 'DATE-TIME' ));
|
1497
|
$hitval = ( isset( $input['value']['tz'] )) ? 7 : 6;
|
1498
|
$parno = iCalUtilityFunctions::_existRem( $input['params'], 'VALUE', 'DATE-TIME', $hitval );
|
1499
|
$parno = iCalUtilityFunctions::_existRem( $input['params'], 'VALUE', 'DATE', 3, count( $input['value'] ), $parno );
|
1500
|
if( 6 > $parno )
|
1501
|
unset( $input['value']['tz'], $input['params']['TZID'], $tzid );
|
1502
|
if(( 6 <= $parno ) && isset( $input['value']['tz'] ) && ( 'Z' != $input['value']['tz'] ) && iCalUtilityFunctions::_isOffset( $input['value']['tz'] )) {
|
1503
|
$d = $input['value'];
|
1504
|
$strdate = sprintf( iCalUtilityFunctions::$fmt['YmdHise'], (int) $d['year'], (int) $d['month'], (int) $d['day'], (int) $d['hour'], (int) $d['min'], (int) $d['sec'], $d['tz'] );
|
1505
|
$input['value'] = iCalUtilityFunctions::_strdate2date( $strdate, $parno );
|
1506
|
unset( $input['value']['unparsedtext'], $input['params']['TZID'] );
|
1507
|
}
|
1508
|
if( isset( $input['value']['tz'] ) && !iCalUtilityFunctions::_isOffset( $input['value']['tz'] )) {
|
1509
|
$input['params']['TZID'] = $input['value']['tz'];
|
1510
|
unset( $input['value']['tz'] );
|
1511
|
}
|
1512
|
}
|
1513
|
elseif( iCalUtilityFunctions::_isArrayTimestampDate( $year )) {
|
1514
|
if( $localtime ) unset ( $month['VALUE'], $month['TZID'] );
|
1515
|
$input['params'] = iCalUtilityFunctions::_setParams( $month, array( 'VALUE' => 'DATE-TIME' ));
|
1516
|
$parno = iCalUtilityFunctions::_existRem( $input['params'], 'VALUE', 'DATE', 3 );
|
1517
|
$hitval = 7;
|
1518
|
$parno = iCalUtilityFunctions::_existRem( $input['params'], 'VALUE', 'DATE-TIME', $hitval, $parno );
|
1519
|
if( isset( $year['tz'] ) && !empty( $year['tz'] )) {
|
1520
|
if( !iCalUtilityFunctions::_isOffset( $year['tz'] )) {
|
1521
|
$input['params']['TZID'] = $year['tz'];
|
1522
|
unset( $year['tz'], $tzid );
|
1523
|
}
|
1524
|
else {
|
1525
|
if( isset( $input['params']['TZID'] ) && !empty( $input['params']['TZID'] )) {
|
1526
|
if( !iCalUtilityFunctions::_isOffset( $input['params']['TZID'] ))
|
1527
|
unset( $tzid );
|
1528
|
else
|
1529
|
unset( $input['params']['TZID']);
|
1530
|
}
|
1531
|
elseif( isset( $tzid ) && !iCalUtilityFunctions::_isOffset( $tzid ))
|
1532
|
$input['params']['TZID'] = $tzid;
|
1533
|
}
|
1534
|
}
|
1535
|
elseif( isset( $input['params']['TZID'] ) && !empty( $input['params']['TZID'] )) {
|
1536
|
if( iCalUtilityFunctions::_isOffset( $input['params']['TZID'] )) {
|
1537
|
$year['tz'] = $input['params']['TZID'];
|
1538
|
unset( $input['params']['TZID']);
|
1539
|
if( isset( $tzid ) && !empty( $tzid ) && !iCalUtilityFunctions::_isOffset( $tzid ))
|
1540
|
$input['params']['TZID'] = $tzid;
|
1541
|
}
|
1542
|
}
|
1543
|
elseif( isset( $tzid ) && !empty( $tzid )) {
|
1544
|
if( iCalUtilityFunctions::_isOffset( $tzid )) {
|
1545
|
$year['tz'] = $tzid;
|
1546
|
unset( $input['params']['TZID']);
|
1547
|
}
|
1548
|
else
|
1549
|
$input['params']['TZID'] = $tzid;
|
1550
|
}
|
1551
|
$input['value'] = iCalUtilityFunctions::_timestamp2date( $year, $parno );
|
1552
|
}
|
1553
|
elseif( 8 <= strlen( trim((string) $year ))) {
|
1554
|
if( $localtime )
|
1555
|
unset( $month['VALUE'], $month['TZID'] );
|
1556
|
elseif( !isset( $month['TZID'] ) && !empty( $tzid ))
|
1557
|
$month['TZID'] = $tzid;
|
1558
|
$input['params'] = iCalUtilityFunctions::_setParams( $month, array( 'VALUE' => 'DATE-TIME' ));
|
1559
|
$parno = iCalUtilityFunctions::_existRem( $input['params'], 'VALUE', 'DATE-TIME', 7, $parno );
|
1560
|
$parno = iCalUtilityFunctions::_existRem( $input['params'], 'VALUE', 'DATE', 3, $parno, $parno );
|
1561
|
$input['value'] = iCalUtilityFunctions::_strdate2date( $year, $parno );
|
1562
|
if( 3 == $parno )
|
1563
|
unset( $input['value']['tz'], $input['params']['TZID'] );
|
1564
|
unset( $input['value']['unparsedtext'] );
|
1565
|
if( isset( $input['value']['tz'] )) {
|
1566
|
if( iCalUtilityFunctions::_isOffset( $input['value']['tz'] )) {
|
1567
|
$d = $input['value'];
|
1568
|
$strdate = sprintf( iCalUtilityFunctions::$fmt['YmdHise'], (int) $d['year'], (int) $d['month'], (int) $d['day'], (int) $d['hour'], (int) $d['min'], (int) $d['sec'], $d['tz'] );
|
1569
|
$input['value'] = iCalUtilityFunctions::_strdate2date( $strdate, 7 );
|
1570
|
unset( $input['value']['unparsedtext'], $input['params']['TZID'] );
|
1571
|
}
|
1572
|
else {
|
1573
|
$input['params']['TZID'] = $input['value']['tz'];
|
1574
|
unset( $input['value']['tz'] );
|
1575
|
}
|
1576
|
}
|
1577
|
elseif( isset( $input['params']['TZID'] ) && iCalUtilityFunctions::_isOffset( $input['params']['TZID'] )) {
|
1578
|
$d = $input['value'];
|
1579
|
$strdate = sprintf( iCalUtilityFunctions::$fmt['YmdHise'], (int) $d['year'], (int) $d['month'], (int) $d['day'], (int) $d['hour'], (int) $d['min'], (int) $d['sec'], $input['params']['TZID'] );
|
1580
|
$input['value'] = iCalUtilityFunctions::_strdate2date( $strdate, 7 );
|
1581
|
unset( $input['value']['unparsedtext'], $input['params']['TZID'] );
|
1582
|
}
|
1583
|
}
|
1584
|
else {
|
1585
|
if( is_array( $params ))
|
1586
|
$input['params'] = iCalUtilityFunctions::_setParams( $params, array( 'VALUE' => 'DATE-TIME' ));
|
1587
|
elseif( is_array( $tz )) {
|
1588
|
$input['params'] = iCalUtilityFunctions::_setParams( $tz, array( 'VALUE' => 'DATE-TIME' ));
|
1589
|
$tz = FALSE;
|
1590
|
}
|
1591
|
elseif( is_array( $hour )) {
|
1592
|
$input['params'] = iCalUtilityFunctions::_setParams( $hour, array( 'VALUE' => 'DATE-TIME' ));
|
1593
|
$hour = $min = $sec = $tz = FALSE;
|
1594
|
}
|
1595
|
if( $localtime )
|
1596
|
unset ( $input['params']['VALUE'], $input['params']['TZID'] );
|
1597
|
elseif( !isset( $tz ) && !isset( $input['params']['TZID'] ) && !empty( $tzid ))
|
1598
|
$input['params']['TZID'] = $tzid;
|
1599
|
elseif( isset( $tz ) && iCalUtilityFunctions::_isOffset( $tz ))
|
1600
|
unset( $input['params']['TZID'] );
|
1601
|
elseif( isset( $input['params']['TZID'] ) && iCalUtilityFunctions::_isOffset( $input['params']['TZID'] )) {
|
1602
|
$tz = $input['params']['TZID'];
|
1603
|
unset( $input['params']['TZID'] );
|
1604
|
}
|
1605
|
$parno = iCalUtilityFunctions::_existRem( $input['params'], 'VALUE', 'DATE', 3 );
|
1606
|
$hitval = ( iCalUtilityFunctions::_isOffset( $tz )) ? 7 : 6;
|
1607
|
$parno = iCalUtilityFunctions::_existRem( $input['params'], 'VALUE', 'DATE-TIME', $hitval, $parno, $parno );
|
1608
|
$input['value'] = array( 'year' => $year, 'month' => $month, 'day' => $day );
|
1609
|
if( 3 != $parno ) {
|
1610
|
$input['value']['hour'] = ( $hour ) ? $hour : '0';
|
1611
|
$input['value']['min'] = ( $min ) ? $min : '0';
|
1612
|
$input['value']['sec'] = ( $sec ) ? $sec : '0';
|
1613
|
if( !empty( $tz ))
|
1614
|
$input['value']['tz'] = $tz;
|
1615
|
$strdate = iCalUtilityFunctions::_date2strdate( $input['value'], $parno );
|
1616
|
if( !empty( $tz ) && !iCalUtilityFunctions::_isOffset( $tz ))
|
1617
|
$strdate .= ( 'Z' == $tz ) ? $tz : ' '.$tz;
|
1618
|
$input['value'] = iCalUtilityFunctions::_strdate2date( $strdate, $parno );
|
1619
|
unset( $input['value']['unparsedtext'] );
|
1620
|
if( isset( $input['value']['tz'] )) {
|
1621
|
if( iCalUtilityFunctions::_isOffset( $input['value']['tz'] )) {
|
1622
|
$d = $input['value'];
|
1623
|
$strdate = sprintf( iCalUtilityFunctions::$fmt['YmdHise'], (int) $d['year'], (int) $d['month'], (int) $d['day'], (int) $d['hour'], (int) $d['min'], (int) $d['sec'], $d['tz'] );
|
1624
|
$input['value'] = iCalUtilityFunctions::_strdate2date( $strdate, 7 );
|
1625
|
unset( $input['value']['unparsedtext'], $input['params']['TZID'] );
|
1626
|
}
|
1627
|
else {
|
1628
|
$input['params']['TZID'] = $input['value']['tz'];
|
1629
|
unset( $input['value']['tz'] );
|
1630
|
}
|
1631
|
}
|
1632
|
elseif( isset( $input['params']['TZID'] ) && iCalUtilityFunctions::_isOffset( $input['params']['TZID'] )) {
|
1633
|
$d = $input['value'];
|
1634
|
$strdate = sprintf( iCalUtilityFunctions::$fmt['YmdHise'], (int) $d['year'], (int) $d['month'], (int) $d['day'], (int) $d['hour'], (int) $d['min'], (int) $d['sec'], $input['params']['TZID'] );
|
1635
|
$input['value'] = iCalUtilityFunctions::_strdate2date( $strdate, 7 );
|
1636
|
unset( $input['value']['unparsedtext'], $input['params']['TZID'] );
|
1637
|
}
|
1638
|
}
|
1639
|
}
|
1640
|
if(( 3 == $parno ) || ( isset( $input['params']['VALUE'] ) && ( 'DATE' == $input['params']['VALUE'] ))) {
|
1641
|
$input['params']['VALUE'] = 'DATE';
|
1642
|
unset( $input['value']['hour'], $input['value']['min'], $input['value']['sec'], $input['value']['tz'], $input['params']['TZID'] );
|
1643
|
}
|
1644
|
elseif( isset( $input['params']['TZID'] )) {
|
1645
|
if(( 'UTC' == strtoupper( $input['params']['TZID'] )) || ( 'GMT' == strtoupper( $input['params']['TZID'] ))) {
|
1646
|
$input['value']['tz'] = 'Z';
|
1647
|
unset( $input['params']['TZID'] );
|
1648
|
}
|
1649
|
else
|
1650
|
unset( $input['value']['tz'] );
|
1651
|
}
|
1652
|
elseif( isset( $input['value']['tz'] )) {
|
1653
|
if(( 'UTC' == strtoupper( $input['value']['tz'] )) || ( 'GMT' == strtoupper( $input['value']['tz'] )))
|
1654
|
$input['value']['tz'] = 'Z';
|
1655
|
if( 'Z' != $input['value']['tz'] ) {
|
1656
|
$input['params']['TZID'] = $input['value']['tz'];
|
1657
|
unset( $input['value']['tz'] );
|
1658
|
}
|
1659
|
else
|
1660
|
unset( $input['params']['TZID'] );
|
1661
|
}
|
1662
|
if( $localtime )
|
1663
|
unset( $input['value']['tz'], $input['params']['TZID'] );
|
1664
|
return $input;
|
1665
|
}
|
1666
|
|
1667
|
|
1668
|
|
1669
|
|
1670
|
|
1671
|
|
1672
|
|
1673
|
|
1674
|
|
1675
|
|
1676
|
|
1677
|
|
1678
|
|
1679
|
|
1680
|
|
1681
|
|
1682
|
|
1683
|
|
1684
|
|
1685
|
|
1686
|
|
1687
|
|
1688
|
|
1689
|
|
1690
|
|
1691
|
public static function _setDate2( $year, $month=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $params=FALSE ) {
|
1692
|
$input = null;
|
1693
|
iCalUtilityFunctions::_strDate2arr( $year );
|
1694
|
if( iCalUtilityFunctions::_isArrayDate( $year )) {
|
1695
|
$input['value'] = iCalUtilityFunctions::_chkDateArr( $year, 7 );
|
1696
|
if( isset( $input['value']['year'] ) && ( 100 > $input['value']['year'] ))
|
1697
|
$input['value']['year'] += 2000;
|
1698
|
$input['params'] = iCalUtilityFunctions::_setParams( $month, array( 'VALUE' => 'DATE-TIME' ));
|
1699
|
unset( $input['params']['VALUE'] );
|
1700
|
if( isset( $input['value']['tz'] ) && iCalUtilityFunctions::_isOffset( $input['value']['tz'] ))
|
1701
|
$tzid = $input['value']['tz'];
|
1702
|
elseif( isset( $input['params']['TZID'] ) && iCalUtilityFunctions::_isOffset( $input['params']['TZID'] ))
|
1703
|
$tzid = $input['params']['TZID'];
|
1704
|
else
|
1705
|
$tzid = '';
|
1706
|
unset( $input['params']['VALUE'], $input['params']['TZID'] );
|
1707
|
if( !empty( $tzid ) && ( 'Z' != $tzid ) && iCalUtilityFunctions::_isOffset( $tzid )) {
|
1708
|
$d = $input['value'];
|
1709
|
$strdate = sprintf( iCalUtilityFunctions::$fmt['YmdHise'], (int) $d['year'], (int) $d['month'], (int) $d['day'], (int) $d['hour'], (int) $d['min'], (int) $d['sec'], $tzid );
|
1710
|
$input['value'] = iCalUtilityFunctions::_strdate2date( $strdate, 7 );
|
1711
|
unset( $input['value']['unparsedtext'] );
|
1712
|
}
|
1713
|
}
|
1714
|
elseif( iCalUtilityFunctions::_isArrayTimestampDate( $year )) {
|
1715
|
if( isset( $year['tz'] ) && ! iCalUtilityFunctions::_isOffset( $year['tz'] ))
|
1716
|
$year['tz'] = 'UTC';
|
1717
|
elseif( isset( $input['params']['TZID'] ) && iCalUtilityFunctions::_isOffset( $input['params']['TZID'] ))
|
1718
|
$year['tz'] = $input['params']['TZID'];
|
1719
|
else
|
1720
|
$year['tz'] = 'UTC';
|
1721
|
$input['value'] = iCalUtilityFunctions::_timestamp2date( $year, 7 );
|
1722
|
$input['params'] = iCalUtilityFunctions::_setParams( $month, array( 'VALUE' => 'DATE-TIME' ));
|
1723
|
unset( $input['params']['VALUE'], $input['params']['TZID'] );
|
1724
|
}
|
1725
|
elseif( 8 <= strlen( trim((string) $year ))) {
|
1726
|
$input['value'] = iCalUtilityFunctions::_strdate2date( $year, 7 );
|
1727
|
unset( $input['value']['unparsedtext'] );
|
1728
|
$input['params'] = iCalUtilityFunctions::_setParams( $month, array( 'VALUE' => 'DATE-TIME' ));
|
1729
|
if(( !isset( $input['value']['tz'] ) || empty( $input['value']['tz'] )) && isset( $input['params']['TZID'] ) && iCalUtilityFunctions::_isOffset( $input['params']['TZID'] )) {
|
1730
|
$d = $input['value'];
|
1731
|
$strdate = sprintf( iCalUtilityFunctions::$fmt['YmdHise'], (int) $d['year'], (int) $d['month'], (int) $d['day'], (int) $d['hour'], (int) $d['min'], (int) $d['sec'], $input['params']['TZID'] );
|
1732
|
$input['value'] = iCalUtilityFunctions::_strdate2date( $strdate, 7 );
|
1733
|
unset( $input['value']['unparsedtext'] );
|
1734
|
}
|
1735
|
unset( $input['params']['VALUE'], $input['params']['TZID'] );
|
1736
|
}
|
1737
|
else {
|
1738
|
$input['value'] = array( 'year' => $year
|
1739
|
, 'month' => $month
|
1740
|
, 'day' => $day
|
1741
|
, 'hour' => $hour
|
1742
|
, 'min' => $min
|
1743
|
, 'sec' => $sec );
|
1744
|
if( isset( $tz )) $input['value']['tz'] = $tz;
|
1745
|
if(( isset( $tz ) && iCalUtilityFunctions::_isOffset( $tz )) ||
|
1746
|
( isset( $input['params']['TZID'] ) && iCalUtilityFunctions::_isOffset( $input['params']['TZID'] ))) {
|
1747
|
if( !isset( $tz ) && isset( $input['params']['TZID'] ) && iCalUtilityFunctions::_isOffset( $input['params']['TZID'] ))
|
1748
|
$input['value']['tz'] = $input['params']['TZID'];
|
1749
|
unset( $input['params']['TZID'] );
|
1750
|
$strdate = iCalUtilityFunctions::_date2strdate( $input['value'], 7 );
|
1751
|
$input['value'] = iCalUtilityFunctions::_strdate2date( $strdate, 7 );
|
1752
|
unset( $input['value']['unparsedtext'] );
|
1753
|
}
|
1754
|
$input['params'] = iCalUtilityFunctions::_setParams( $params, array( 'VALUE' => 'DATE-TIME' ));
|
1755
|
unset( $input['params']['VALUE'] );
|
1756
|
}
|
1757
|
$parno = iCalUtilityFunctions::_existRem( $input['params'], 'VALUE', 'DATE-TIME', 7 );
|
1758
|
if( !isset( $input['value']['hour'] )) $input['value']['hour'] = 0;
|
1759
|
if( !isset( $input['value']['min'] )) $input['value']['min'] = 0;
|
1760
|
if( !isset( $input['value']['sec'] )) $input['value']['sec'] = 0;
|
1761
|
$input['value']['tz'] = 'Z';
|
1762
|
return $input;
|
1763
|
}
|
1764
|
|
1765
|
|
1766
|
|
1767
|
|
1768
|
|
1769
|
|
1770
|
|
1771
|
|
1772
|
|
1773
|
|
1774
|
|
1775
|
|
1776
|
|
1777
|
public static function _setMval( & $valArr, $value, $params=FALSE, $defaults=FALSE, $index=FALSE ) {
|
1778
|
if( !is_array( $valArr )) $valArr = array();
|
1779
|
if( $index )
|
1780
|
$index = $index - 1;
|
1781
|
elseif( 0 < count( $valArr )) {
|
1782
|
$keys = array_keys( $valArr );
|
1783
|
$index = end( $keys ) + 1;
|
1784
|
}
|
1785
|
else
|
1786
|
$index = 0;
|
1787
|
$valArr[$index] = array( 'value' => $value, 'params' => iCalUtilityFunctions::_setParams( $params, $defaults ));
|
1788
|
ksort( $valArr );
|
1789
|
}
|
1790
|
|
1791
|
|
1792
|
|
1793
|
|
1794
|
|
1795
|
|
1796
|
|
1797
|
|
1798
|
|
1799
|
|
1800
|
|
1801
|
public static function _setParams( $params, $defaults=FALSE ) {
|
1802
|
if( !is_array( $params))
|
1803
|
$params = array();
|
1804
|
$input = array();
|
1805
|
$params = array_change_key_case( $params, CASE_UPPER );
|
1806
|
foreach( $params as $paramKey => $paramValue ) {
|
1807
|
if( is_array( $paramValue )) {
|
1808
|
foreach( $paramValue as $pkey => $pValue ) {
|
1809
|
if(( '"' == substr( $pValue, 0, 1 )) && ( '"' == substr( $pValue, -1 )))
|
1810
|
$paramValue[$pkey] = substr( $pValue, 1, ( strlen( $pValue ) - 2 ));
|
1811
|
}
|
1812
|
}
|
1813
|
elseif(( '"' == substr( $paramValue, 0, 1 )) && ( '"' == substr( $paramValue, -1 )))
|
1814
|
$paramValue = substr( $paramValue, 1, ( strlen( $paramValue ) - 2 ));
|
1815
|
if( 'VALUE' == $paramKey )
|
1816
|
$input['VALUE'] = strtoupper( $paramValue );
|
1817
|
else
|
1818
|
$input[$paramKey] = $paramValue;
|
1819
|
}
|
1820
|
if( is_array( $defaults )) {
|
1821
|
foreach( $defaults as $paramKey => $paramValue ) {
|
1822
|
if( !isset( $input[$paramKey] ))
|
1823
|
$input[$paramKey] = $paramValue;
|
1824
|
}
|
1825
|
}
|
1826
|
return (0 < count( $input )) ? $input : null;
|
1827
|
}
|
1828
|
|
1829
|
|
1830
|
|
1831
|
|
1832
|
|
1833
|
|
1834
|
|
1835
|
|
1836
|
|
1837
|
|
1838
|
|
1839
|
|
1840
|
|
1841
|
|
1842
|
|
1843
|
|
1844
|
public static function _setSortArgs( $c, $sortArg=FALSE ) {
|
1845
|
$c->srtk = array( '0', '0', '0', '0' );
|
1846
|
if( 'vtimezone' == $c->objName ) {
|
1847
|
if( FALSE === ( $c->srtk[0] = $c->getProperty( 'tzid' )))
|
1848
|
$c->srtk[0] = 0;
|
1849
|
return;
|
1850
|
}
|
1851
|
elseif( $sortArg ) {
|
1852
|
if( in_array( $sortArg, iCalUtilityFunctions::$mProps1 )) {
|
1853
|
$propValues = array();
|
1854
|
$c->_getProperties( $sortArg, $propValues );
|
1855
|
if( !empty( $propValues )) {
|
1856
|
$sk = array_keys( $propValues );
|
1857
|
$c->srtk[0] = $sk[0];
|
1858
|
if( 'RELATED-TO' == $sortArg )
|
1859
|
$c->srtk[0] .= $c->getProperty( 'uid' );
|
1860
|
}
|
1861
|
elseif( 'RELATED-TO' == $sortArg )
|
1862
|
$c->srtk[0] = $c->getProperty( 'uid' );
|
1863
|
}
|
1864
|
elseif( FALSE !== ( $d = $c->getProperty( $sortArg ))) {
|
1865
|
$c->srtk[0] = $d;
|
1866
|
if( 'UID' == $sortArg ) {
|
1867
|
if( FALSE !== ( $d = $c->getProperty( 'recurrence-id' ))) {
|
1868
|
$c->srtk[1] = iCalUtilityFunctions::_date2strdate( $d );
|
1869
|
if( FALSE === ( $c->srtk[2] = $c->getProperty( 'sequence' )))
|
1870
|
$c->srtk[2] = PHP_INT_MAX;
|
1871
|
}
|
1872
|
else
|
1873
|
$c->srtk[1] = $c->srtk[2] = PHP_INT_MAX;
|
1874
|
}
|
1875
|
}
|
1876
|
return;
|
1877
|
}
|
1878
|
if( FALSE !== ( $d = $c->getProperty( 'X-CURRENT-DTSTART' ))) {
|
1879
|
$c->srtk[0] = iCalUtilityFunctions::_strdate2date( $d[1] );
|
1880
|
unset( $c->srtk[0]['unparsedtext'] );
|
1881
|
}
|
1882
|
elseif( FALSE === ( $c->srtk[0] = $c->getProperty( 'dtstart' )))
|
1883
|
$c->srtk[0] = 0;
|
1884
|
if( FALSE !== ( $d = $c->getProperty( 'X-CURRENT-DTEND' ))) {
|
1885
|
$c->srtk[1] = iCalUtilityFunctions::_strdate2date( $d[1] );
|
1886
|
unset( $c->srtk[1]['unparsedtext'] );
|
1887
|
}
|
1888
|
elseif( FALSE === ( $c->srtk[1] = $c->getProperty( 'dtend' ))) {
|
1889
|
if( FALSE !== ( $d = $c->getProperty( 'X-CURRENT-DUE' ))) {
|
1890
|
$c->srtk[1] = iCalUtilityFunctions::_strdate2date( $d[1] );
|
1891
|
unset( $c->srtk[1]['unparsedtext'] );
|
1892
|
}
|
1893
|
elseif( FALSE === ( $c->srtk[1] = $c->getProperty( 'due' )))
|
1894
|
if( FALSE === ( $c->srtk[1] = $c->getProperty( 'duration', FALSE, FALSE, TRUE )))
|
1895
|
$c->srtk[1] = 0;
|
1896
|
}
|
1897
|
if( FALSE === ( $c->srtk[2] = $c->getProperty( 'created' )))
|
1898
|
if( FALSE === ( $c->srtk[2] = $c->getProperty( 'dtstamp' )))
|
1899
|
$c->srtk[2] = 0;
|
1900
|
if( FALSE === ( $c->srtk[3] = $c->getProperty( 'uid' )))
|
1901
|
$c->srtk[3] = 0;
|
1902
|
}
|
1903
|
|
1904
|
|
1905
|
|
1906
|
|
1907
|
|
1908
|
|
1909
|
|
1910
|
|
1911
|
|
1912
|
|
1913
|
|
1914
|
|
1915
|
|
1916
|
|
1917
|
|
1918
|
|
1919
|
|
1920
|
|
1921
|
|
1922
|
|
1923
|
|
1924
|
|
1925
|
public static function _size75( $string, $nl ) {
|
1926
|
$tmp = $string;
|
1927
|
$string = '';
|
1928
|
$cCnt = $x = 0;
|
1929
|
while( TRUE ) {
|
1930
|
if( !isset( $tmp[$x] )) {
|
1931
|
$string .= $nl;
|
1932
|
break;
|
1933
|
}
|
1934
|
elseif(( 74 <= $cCnt ) && ( '\\' == $tmp[$x] ) && ( 'n' == $tmp[$x+1] )) {
|
1935
|
$string .= $nl.' \n';
|
1936
|
$x += 2;
|
1937
|
if( !isset( $tmp[$x] )) {
|
1938
|
$string .= $nl;
|
1939
|
break;
|
1940
|
}
|
1941
|
$cCnt = 3;
|
1942
|
}
|
1943
|
elseif( 75 <= $cCnt ) {
|
1944
|
$string .= $nl.' ';
|
1945
|
$cCnt = 1;
|
1946
|
}
|
1947
|
$byte = ord( $tmp[$x] );
|
1948
|
$string .= $tmp[$x];
|
1949
|
switch( TRUE ) {
|
1950
|
case(( $byte >= 0x20 ) && ( $byte <= 0x7F )):
|
1951
|
$cCnt += 1;
|
1952
|
break;
|
1953
|
case(( $byte & 0xE0) == 0xC0 ):
|
1954
|
if( isset( $tmp[$x+1] )) {
|
1955
|
$cCnt += 1;
|
1956
|
$string .= $tmp[$x+1];
|
1957
|
$x += 1;
|
1958
|
}
|
1959
|
break;
|
1960
|
case(( $byte & 0xF0 ) == 0xE0 ):
|
1961
|
if( isset( $tmp[$x+2] )) {
|
1962
|
$cCnt += 1;
|
1963
|
$string .= $tmp[$x+1].$tmp[$x+2];
|
1964
|
$x += 2;
|
1965
|
}
|
1966
|
break;
|
1967
|
case(( $byte & 0xF8 ) == 0xF0 ):
|
1968
|
if( isset( $tmp[$x+3] )) {
|
1969
|
$cCnt += 1;
|
1970
|
$string .= $tmp[$x+1].$tmp[$x+2].$tmp[$x+3];
|
1971
|
$x += 3;
|
1972
|
}
|
1973
|
break;
|
1974
|
case(( $byte & 0xFC ) == 0xF8 ):
|
1975
|
if( isset( $tmp[$x+4] )) {
|
1976
|
$cCnt += 1;
|
1977
|
$string .= $tmp[$x+1].$tmp[$x+2].$tmp[$x+3].$tmp[$x+4];
|
1978
|
$x += 4;
|
1979
|
}
|
1980
|
break;
|
1981
|
case(( $byte & 0xFE ) == 0xFC ):
|
1982
|
if( isset( $tmp[$x+5] )) {
|
1983
|
$cCnt += 1;
|
1984
|
$string .= $tmp[$x+1].$tmp[$x+2].$tmp[$x+3].$tmp[$x+4].$tmp[$x+5];
|
1985
|
$x += 5;
|
1986
|
}
|
1987
|
default:
|
1988
|
break;
|
1989
|
}
|
1990
|
$x += 1;
|
1991
|
}
|
1992
|
return $string;
|
1993
|
}
|
1994
|
|
1995
|
|
1996
|
|
1997
|
|
1998
|
|
1999
|
|
2000
|
|
2001
|
|
2002
|
|
2003
|
|
2004
|
public static function _sortExdate1( $a, $b ) {
|
2005
|
$as = sprintf( iCalUtilityFunctions::$fmt['Ymd'], (int) $a['year'], (int) $a['month'], (int) $a['day'] );
|
2006
|
$as .= ( isset( $a['hour'] )) ? sprintf( iCalUtilityFunctions::$fmt['His'], (int) $a['hour'], (int) $a['min'], (int) $a['sec'] ) : '';
|
2007
|
$bs = sprintf( iCalUtilityFunctions::$fmt['His'], (int) $b['year'], (int) $b['month'], (int) $b['day'] );
|
2008
|
$bs .= ( isset( $b['hour'] )) ? sprintf( iCalUtilityFunctions::$fmt['His'], (int) $b['hour'], (int) $b['min'], (int) $b['sec'] ) : '';
|
2009
|
return strcmp( $as, $bs );
|
2010
|
}
|
2011
|
|
2012
|
|
2013
|
|
2014
|
|
2015
|
|
2016
|
|
2017
|
|
2018
|
|
2019
|
|
2020
|
|
2021
|
public static function _sortExdate2( $a, $b ) {
|
2022
|
$val = reset( $a['value'] );
|
2023
|
$as = sprintf( iCalUtilityFunctions::$fmt['Ymd'], (int) $val['year'], (int) $val['month'], (int) $val['day'] );
|
2024
|
$as .= ( isset( $val['hour'] )) ? sprintf( iCalUtilityFunctions::$fmt['His'], (int) $val['hour'], (int) $val['min'], (int) $val['sec'] ) : '';
|
2025
|
$val = reset( $b['value'] );
|
2026
|
$bs = sprintf( iCalUtilityFunctions::$fmt['Ymd'], (int) $val['year'], (int) $val['month'], (int) $val['day'] );
|
2027
|
$bs .= ( isset( $val['hour'] )) ? sprintf( iCalUtilityFunctions::$fmt['His'], (int) $val['hour'], (int) $val['min'], (int) $val['sec'] ) : '';
|
2028
|
return strcmp( $as, $bs );
|
2029
|
}
|
2030
|
|
2031
|
|
2032
|
|
2033
|
|
2034
|
|
2035
|
|
2036
|
|
2037
|
|
2038
|
|
2039
|
|
2040
|
public static function _sortRdate1( $a, $b ) {
|
2041
|
$val = isset( $a['year'] ) ? $a : $a[0];
|
2042
|
$as = sprintf( iCalUtilityFunctions::$fmt['Ymd'], (int) $val['year'], (int) $val['month'], (int) $val['day'] );
|
2043
|
$as .= ( isset( $val['hour'] )) ? sprintf( iCalUtilityFunctions::$fmt['His'], (int) $val['hour'], (int) $val['min'], (int) $val['sec'] ) : '';
|
2044
|
$val = isset( $b['year'] ) ? $b : $b[0];
|
2045
|
$bs = sprintf( iCalUtilityFunctions::$fmt['Ymd'], (int) $val['year'], (int) $val['month'], (int) $val['day'] );
|
2046
|
$bs .= ( isset( $val['hour'] )) ? sprintf( iCalUtilityFunctions::$fmt['His'], (int) $val['hour'], (int) $val['min'], (int) $val['sec'] ) : '';
|
2047
|
return strcmp( $as, $bs );
|
2048
|
}
|
2049
|
|
2050
|
|
2051
|
|
2052
|
|
2053
|
|
2054
|
|
2055
|
|
2056
|
|
2057
|
|
2058
|
|
2059
|
public static function _sortRdate2( $a, $b ) {
|
2060
|
$val = isset( $a['value'][0]['year'] ) ? $a['value'][0] : $a['value'][0][0];
|
2061
|
if( empty( $val ))
|
2062
|
$as = '';
|
2063
|
else {
|
2064
|
$as = sprintf( iCalUtilityFunctions::$fmt['Ymd'], (int) $val['year'], (int) $val['month'], (int) $val['day'] );
|
2065
|
$as .= ( isset( $val['hour'] )) ? sprintf( iCalUtilityFunctions::$fmt['His'], (int) $val['hour'], (int) $val['min'], (int) $val['sec'] ) : '';
|
2066
|
}
|
2067
|
$val = isset( $b['value'][0]['year'] ) ? $b['value'][0] : $b['value'][0][0];
|
2068
|
if( empty( $val ))
|
2069
|
$bs = '';
|
2070
|
else {
|
2071
|
$bs = sprintf( iCalUtilityFunctions::$fmt['Ymd'], (int) $val['year'], (int) $val['month'], (int) $val['day'] );
|
2072
|
$bs .= ( isset( $val['hour'] )) ? sprintf( iCalUtilityFunctions::$fmt['His'], (int) $val['hour'], (int) $val['min'], (int) $val['sec'] ) : '';
|
2073
|
}
|
2074
|
return strcmp( $as, $bs );
|
2075
|
}
|
2076
|
|
2077
|
|
2078
|
|
2079
|
|
2080
|
|
2081
|
|
2082
|
|
2083
|
|
2084
|
|
2085
|
|
2086
|
public static function _splitContent( & $line, & $propAttr=null ) {
|
2087
|
$attr = array();
|
2088
|
$attrix = -1;
|
2089
|
$clen = strlen( $line );
|
2090
|
$WithinQuotes = FALSE;
|
2091
|
$cix = 0;
|
2092
|
while( FALSE !== substr( $line, $cix, 1 )) {
|
2093
|
if( ! $WithinQuotes && ( ':' == $line[$cix] ) &&
|
2094
|
( substr( $line,$cix, 3 ) != '://' ) &&
|
2095
|
( ! in_array( strtolower( substr( $line,$cix - 6, 4 )), iCalUtilityFunctions::$parValPrefix['MStz'] )) &&
|
2096
|
( ! in_array( strtolower( substr( $line,$cix - 3, 4 )), iCalUtilityFunctions::$parValPrefix['Proto3'] )) &&
|
2097
|
( ! in_array( strtolower( substr( $line,$cix - 4, 5 )), iCalUtilityFunctions::$parValPrefix['Proto4'] )) &&
|
2098
|
( ! in_array( strtolower( substr( $line,$cix - 6, 7 )), iCalUtilityFunctions::$parValPrefix['Proto6'] ))) {
|
2099
|
$attrEnd = TRUE;
|
2100
|
if(( $cix < ( $clen - 4 )) &&
|
2101
|
ctype_digit( substr( $line, $cix+1, 4 ))) {
|
2102
|
for( $c2ix = $cix; 3 < $c2ix; $c2ix-- ) {
|
2103
|
if( '://' == substr( $line, $c2ix - 2, 3 )) {
|
2104
|
$attrEnd = FALSE;
|
2105
|
break;
|
2106
|
}
|
2107
|
}
|
2108
|
}
|
2109
|
if( $attrEnd) {
|
2110
|
$line = substr( $line, ( $cix + 1 ));
|
2111
|
break;
|
2112
|
}
|
2113
|
$cix++;
|
2114
|
}
|
2115
|
if( '"' == $line[$cix] )
|
2116
|
$WithinQuotes = ! $WithinQuotes;
|
2117
|
if( ';' == $line[$cix] )
|
2118
|
$attr[++$attrix] = null;
|
2119
|
else
|
2120
|
$attr[$attrix] .= $line[$cix];
|
2121
|
$cix++;
|
2122
|
}
|
2123
|
|
2124
|
$propAttr = array();
|
2125
|
foreach( $attr as $attribute ) {
|
2126
|
$attrsplit = explode( '=', $attribute, 2 );
|
2127
|
if( 1 < count( $attrsplit ))
|
2128
|
$propAttr[$attrsplit[0]] = $attrsplit[1];
|
2129
|
}
|
2130
|
}
|
2131
|
|
2132
|
|
2133
|
|
2134
|
|
2135
|
|
2136
|
|
2137
|
|
2138
|
|
2139
|
|
2140
|
|
2141
|
|
2142
|
public static function _stepdate( & $date, & $dateYMD, $step=array( 'day' => 1 )) {
|
2143
|
if( !isset( $date['hour'] )) $date['hour'] = 0;
|
2144
|
if( !isset( $date['min'] )) $date['min'] = 0;
|
2145
|
if( !isset( $date['sec'] )) $date['sec'] = 0;
|
2146
|
if( isset( $step['day'] ))
|
2147
|
$mcnt = date( 't', mktime( (int) $date['hour'], (int) $date['min'], (int) $date['sec'], (int) $date['month'], (int) $date['day'], (int) $date['year'] ));
|
2148
|
foreach( $step as $stepix => $stepvalue )
|
2149
|
$date[$stepix] += $stepvalue;
|
2150
|
if( isset( $step['month'] )) {
|
2151
|
if( 12 < $date['month'] ) {
|
2152
|
$date['year'] += 1;
|
2153
|
$date['month'] -= 12;
|
2154
|
}
|
2155
|
}
|
2156
|
elseif( isset( $step['day'] )) {
|
2157
|
if( $mcnt < $date['day'] ) {
|
2158
|
$date['day'] -= $mcnt;
|
2159
|
$date['month'] += 1;
|
2160
|
if( 12 < $date['month'] ) {
|
2161
|
$date['year'] += 1;
|
2162
|
$date['month'] -= 12;
|
2163
|
}
|
2164
|
}
|
2165
|
}
|
2166
|
$dateYMD = sprintf( iCalUtilityFunctions::$fmt['Ymd'], (int) $date['year'], (int) $date['month'], (int) $date['day'] );
|
2167
|
unset( $mcnt );
|
2168
|
}
|
2169
|
|
2170
|
|
2171
|
|
2172
|
|
2173
|
|
2174
|
|
2175
|
|
2176
|
|
2177
|
public static function _strDate2arr( & $input ) {
|
2178
|
if( is_array( $input ))
|
2179
|
return FALSE;
|
2180
|
if( 5 > strlen( (string) $input ))
|
2181
|
return FALSE;
|
2182
|
$work = $input;
|
2183
|
if( 2 == substr_count( $work, '-' ))
|
2184
|
$work = str_replace( '-', '', $work );
|
2185
|
if( 2 == substr_count( $work, '/' ))
|
2186
|
$work = str_replace( '/', '', $work );
|
2187
|
if( !ctype_digit( substr( $work, 0, 8 )))
|
2188
|
return FALSE;
|
2189
|
$temp = array( 'year' => (int) substr( $work, 0, 4 )
|
2190
|
, 'month' => (int) substr( $work, 4, 2 )
|
2191
|
, 'day' => (int) substr( $work, 6, 2 ));
|
2192
|
if( !checkdate( $temp['month'], $temp['day'], $temp['year'] ))
|
2193
|
return FALSE;
|
2194
|
if( 8 == strlen( $work )) {
|
2195
|
$input = $temp;
|
2196
|
return TRUE;
|
2197
|
}
|
2198
|
if(( ' ' == substr( $work, 8, 1 )) || ( 'T' == substr( $work, 8, 1 )) || ( 't' == substr( $work, 8, 1 )))
|
2199
|
$work = substr( $work, 9 );
|
2200
|
elseif( ctype_digit( substr( $work, 8, 1 )))
|
2201
|
$work = substr( $work, 8 );
|
2202
|
else
|
2203
|
return FALSE;
|
2204
|
if( 2 == substr_count( $work, ':' ))
|
2205
|
$work = str_replace( ':', '', $work );
|
2206
|
if( !ctype_digit( substr( $work, 0, 4 )))
|
2207
|
return FALSE;
|
2208
|
$temp['hour'] = substr( $work, 0, 2 );
|
2209
|
$temp['min'] = substr( $work, 2, 2 );
|
2210
|
if((( 0 > $temp['hour'] ) || ( $temp['hour'] > 23 )) ||
|
2211
|
(( 0 > $temp['min'] ) || ( $temp['min'] > 59 )))
|
2212
|
return FALSE;
|
2213
|
if( ctype_digit( substr( $work, 4, 2 ))) {
|
2214
|
$temp['sec'] = substr( $work, 4, 2 );
|
2215
|
if(( 0 > $temp['sec'] ) || ( $temp['sec'] > 59 ))
|
2216
|
return FALSE;
|
2217
|
$len = 6;
|
2218
|
}
|
2219
|
else {
|
2220
|
$temp['sec'] = 0;
|
2221
|
$len = 4;
|
2222
|
}
|
2223
|
if( $len < strlen( $work))
|
2224
|
$temp['tz'] = trim( substr( $work, 6 ));
|
2225
|
$input = $temp;
|
2226
|
return TRUE;
|
2227
|
}
|
2228
|
|
2229
|
|
2230
|
|
2231
|
|
2232
|
|
2233
|
|
2234
|
|
2235
|
|
2236
|
|
2237
|
|
2238
|
|
2239
|
|
2240
|
|
2241
|
|
2242
|
|
2243
|
|
2244
|
public static function _strdate2date( $datetime, $parno=FALSE, $wtz=null ) {
|
2245
|
$unparseddatetime = $datetime;
|
2246
|
$datetime = (string) trim( $datetime );
|
2247
|
$tz = null;
|
2248
|
$offset = 0;
|
2249
|
$tzSts = FALSE;
|
2250
|
$len = strlen( $datetime );
|
2251
|
if( 'Z' == substr( $datetime, -1 )) {
|
2252
|
$tz = 'Z';
|
2253
|
$datetime = trim( substr( $datetime, 0, ( $len - 1 )));
|
2254
|
$tzSts = TRUE;
|
2255
|
}
|
2256
|
if( iCalUtilityFunctions::_isOffset( substr( $datetime, -5, 5 ))) {
|
2257
|
$tz = substr( $datetime, -5, 5 );
|
2258
|
$datetime = trim( substr( $datetime, 0, ($len - 5)));
|
2259
|
}
|
2260
|
elseif( iCalUtilityFunctions::_isOffset( substr( $datetime, -7, 7 ))) {
|
2261
|
$tz = substr( $datetime, -7, 7 );
|
2262
|
$datetime = trim( substr( $datetime, 0, ($len - 7)));
|
2263
|
}
|
2264
|
elseif( empty( $wtz ) && ctype_digit( substr( $datetime, 0, 4 )) && ctype_digit( substr( $datetime, -2, 2 )) && iCalUtilityFunctions::_strDate2arr( $datetime )) {
|
2265
|
$output = $datetime;
|
2266
|
if( !empty( $tz ))
|
2267
|
$output['tz'] = 'Z';
|
2268
|
$output['unparsedtext'] = $unparseddatetime;
|
2269
|
return $output;
|
2270
|
}
|
2271
|
else {
|
2272
|
$cx = $tx = 0;
|
2273
|
$len = strlen( $datetime );
|
2274
|
for( $cx = -1; $cx > ( 9 - $len ); $cx-- ) {
|
2275
|
$char = substr( $datetime, $cx, 1 );
|
2276
|
if(( ' ' == $char ) || ctype_digit( $char ))
|
2277
|
break;
|
2278
|
else
|
2279
|
$tx--;
|
2280
|
}
|
2281
|
if( 0 > $tx ) {
|
2282
|
$tz = substr( $datetime, $tx );
|
2283
|
$datetime = trim( substr( $datetime, 0, $len + $tx ));
|
2284
|
}
|
2285
|
if(( ctype_digit( substr( $datetime, 0, 8 )) && ( 'T' == substr( $datetime, 8, 1 )) && ctype_digit( substr( $datetime, -6, 6 ))) ||
|
2286
|
( ctype_digit( substr( $datetime, 0, 14 ))))
|
2287
|
$tzSts = TRUE;
|
2288
|
}
|
2289
|
if( empty( $tz ) && !empty( $wtz ))
|
2290
|
$tz = $wtz;
|
2291
|
if( 3 == $parno )
|
2292
|
$tz = null;
|
2293
|
if( !empty( $tz )) {
|
2294
|
if(( 'Z' != $tz ) && ( iCalUtilityFunctions::_isOffset( $tz ))) {
|
2295
|
$offset = (string) iCalUtilityFunctions::_tz2offset( $tz ) * -1;
|
2296
|
$tz = 'UTC';
|
2297
|
$tzSts = TRUE;
|
2298
|
}
|
2299
|
elseif( !empty( $wtz ))
|
2300
|
$tzSts = TRUE;
|
2301
|
$tz = trim( $tz );
|
2302
|
if(( 'Z' == $tz ) || ( 'GMT' == strtoupper( $tz )))
|
2303
|
$tz = 'UTC';
|
2304
|
if( 0 < substr_count( $datetime, '-' ))
|
2305
|
$datetime = str_replace( '-', '/', $datetime );
|
2306
|
try {
|
2307
|
$d = new DateTime( $datetime, new DateTimeZone( $tz ));
|
2308
|
if( 0 != $offset )
|
2309
|
$d->modify( $offset.' seconds' );
|
2310
|
$datestring = $d->format( iCalUtilityFunctions::$fmt['YmdHis3'] );
|
2311
|
unset( $d );
|
2312
|
}
|
2313
|
catch( Exception $e ) {
|
2314
|
$datestring = date( iCalUtilityFunctions::$fmt['YmdHis3'], strtotime( $datetime ));
|
2315
|
}
|
2316
|
}
|
2317
|
else
|
2318
|
$datestring = date( iCalUtilityFunctions::$fmt['YmdHis3'], strtotime( $datetime ));
|
2319
|
if( 'UTC' == $tz )
|
2320
|
$tz = 'Z';
|
2321
|
$d = explode( '-', $datestring );
|
2322
|
$output = array( 'year' => $d[0], 'month' => $d[1], 'day' => $d[2] );
|
2323
|
if( !$parno || ( 3 != $parno )) {
|
2324
|
$output['hour'] = $d[3];
|
2325
|
$output['min'] = $d[4];
|
2326
|
$output['sec'] = $d[5];
|
2327
|
if(( $tzSts || ( 7 == $parno )) && !empty( $tz ))
|
2328
|
$output['tz'] = $tz;
|
2329
|
}
|
2330
|
|
2331
|
$output['unparsedtext'] = $unparseddatetime;
|
2332
|
return $output;
|
2333
|
}
|
2334
|
|
2335
|
|
2336
|
|
2337
|
|
2338
|
|
2339
|
|
2340
|
|
2341
|
|
2342
|
|
2343
|
|
2344
|
|
2345
|
public static function _strrep( $string, $format, $nl ) {
|
2346
|
switch( $format ) {
|
2347
|
case 'xcal':
|
2348
|
$string = str_replace( '\n', $nl, $string);
|
2349
|
$string = htmlspecialchars( strip_tags( stripslashes( urldecode ( $string ))));
|
2350
|
break;
|
2351
|
default:
|
2352
|
$pos = 0;
|
2353
|
$specChars = array( 'n', 'N', 'r', ',', ';' );
|
2354
|
while( isset( $string[$pos] )) {
|
2355
|
if( FALSE === ( $pos = strpos( $string, "\\", $pos )))
|
2356
|
break;
|
2357
|
if( !in_array( substr( $string, $pos, 1 ), $specChars )) {
|
2358
|
$string = substr( $string, 0, $pos )."\\".substr( $string, ( $pos + 1 ));
|
2359
|
$pos += 1;
|
2360
|
}
|
2361
|
$pos += 1;
|
2362
|
}
|
2363
|
if( FALSE !== strpos( $string, '"' ))
|
2364
|
$string = str_replace('"', "'", $string);
|
2365
|
if( FALSE !== strpos( $string, ',' ))
|
2366
|
$string = str_replace(',', '\,', $string);
|
2367
|
if( FALSE !== strpos( $string, ';' ))
|
2368
|
$string = str_replace(';', '\;', $string);
|
2369
|
if( FALSE !== strpos( $string, "\r\n" ))
|
2370
|
$string = str_replace( "\r\n", '\n', $string);
|
2371
|
elseif( FALSE !== strpos( $string, "\r" ))
|
2372
|
$string = str_replace( "\r", '\n', $string);
|
2373
|
elseif( FALSE !== strpos( $string, "\n" ))
|
2374
|
$string = str_replace( "\n", '\n', $string);
|
2375
|
if( FALSE !== strpos( $string, '\N' ))
|
2376
|
$string = str_replace( '\N', '\n', $string);
|
2377
|
|
2378
|
$string = str_replace( $nl, '\n', $string);
|
2379
|
break;
|
2380
|
}
|
2381
|
return $string;
|
2382
|
}
|
2383
|
|
2384
|
|
2385
|
|
2386
|
|
2387
|
|
2388
|
|
2389
|
|
2390
|
|
2391
|
public static function _strunrep( $string ) {
|
2392
|
$string = str_replace( '\\\\', '\\', $string);
|
2393
|
$string = str_replace( '\,', ',', $string);
|
2394
|
$string = str_replace( '\;', ';', $string);
|
2395
|
|
2396
|
return $string;
|
2397
|
}
|
2398
|
|
2399
|
|
2400
|
|
2401
|
|
2402
|
|
2403
|
|
2404
|
|
2405
|
|
2406
|
|
2407
|
|
2408
|
|
2409
|
|
2410
|
|
2411
|
public static function _timestamp2date( $timestamp, $parno=6, $wtz=null ) {
|
2412
|
if( is_array( $timestamp )) {
|
2413
|
$tz = ( isset( $timestamp['tz'] )) ? $timestamp['tz'] : $wtz;
|
2414
|
$timestamp = $timestamp['timestamp'];
|
2415
|
}
|
2416
|
$tz = ( isset( $tz )) ? $tz : $wtz;
|
2417
|
$offset = 0;
|
2418
|
if( empty( $tz ) || ( 'Z' == $tz ) || ( 'GMT' == strtoupper( $tz )))
|
2419
|
$tz = 'UTC';
|
2420
|
elseif( iCalUtilityFunctions::_isOffset( $tz )) {
|
2421
|
$offset = iCalUtilityFunctions::_tz2offset( $tz );
|
2422
|
}
|
2423
|
try {
|
2424
|
$d = new DateTime( "@$timestamp" );
|
2425
|
if( 0 != $offset )
|
2426
|
$d->modify( $offset.' seconds' );
|
2427
|
elseif( 'UTC' != $tz )
|
2428
|
$d->setTimezone( new DateTimeZone( $tz ));
|
2429
|
$date = $d->format( iCalUtilityFunctions::$fmt['YmdHis3'] );
|
2430
|
unset( $d );
|
2431
|
}
|
2432
|
catch( Exception $e ) {
|
2433
|
$date = date( iCalUtilityFunctions::$fmt['YmdHis3'], $timestamp );
|
2434
|
}
|
2435
|
$date = explode( '-', $date );
|
2436
|
$output = array( 'year' => $date[0], 'month' => $date[1], 'day' => $date[2] );
|
2437
|
if( 3 != $parno ) {
|
2438
|
$output['hour'] = $date[3];
|
2439
|
$output['min'] = $date[4];
|
2440
|
$output['sec'] = $date[5];
|
2441
|
if(( 'UTC' == $tz ) || ( 0 == $offset ))
|
2442
|
$output['tz'] = 'Z';
|
2443
|
}
|
2444
|
return $output;
|
2445
|
}
|
2446
|
|
2447
|
|
2448
|
|
2449
|
|
2450
|
|
2451
|
|
2452
|
|
2453
|
|
2454
|
|
2455
|
|
2456
|
|
2457
|
|
2458
|
|
2459
|
|
2460
|
public static function transformDateTime( & $date, $tzFrom, $tzTo='UTC', $format = 'Ymd\THis' ) {
|
2461
|
if( is_array( $date ) && isset( $date['timestamp'] )) {
|
2462
|
try {
|
2463
|
$d = new DateTime( "@{$date['timestamp']}" );
|
2464
|
$d->setTimezone(new DateTimeZone( $tzFrom ));
|
2465
|
}
|
2466
|
catch( Exception $e ) { return FALSE; }
|
2467
|
}
|
2468
|
else {
|
2469
|
if( iCalUtilityFunctions::_isArrayDate( $date )) {
|
2470
|
if( isset( $date['tz'] ))
|
2471
|
unset( $date['tz'] );
|
2472
|
$date = iCalUtilityFunctions::_date2strdate( iCalUtilityFunctions::_chkDateArr( $date ));
|
2473
|
}
|
2474
|
if( 'Z' == substr( $date, -1 ))
|
2475
|
$date = substr( $date, 0, ( strlen( $date ) - 2 ));
|
2476
|
try { $d = new DateTime( $date, new DateTimeZone( $tzFrom )); }
|
2477
|
catch( Exception $e ) { return FALSE; }
|
2478
|
}
|
2479
|
try { $d->setTimezone( new DateTimeZone( $tzTo )); }
|
2480
|
catch( Exception $e ) { return FALSE; }
|
2481
|
$date = $d->format( $format );
|
2482
|
return TRUE;
|
2483
|
}
|
2484
|
|
2485
|
|
2486
|
|
2487
|
|
2488
|
|
2489
|
|
2490
|
|
2491
|
|
2492
|
public static function _tz2offset( $tz ) {
|
2493
|
$tz = trim( (string) $tz );
|
2494
|
$offset = 0;
|
2495
|
if((( 5 != strlen( $tz )) && ( 7 != strlen( $tz ))) ||
|
2496
|
(( '+' != substr( $tz, 0, 1 )) && ( '-' != substr( $tz, 0, 1 ))) ||
|
2497
|
(( '0000' >= substr( $tz, 1, 4 )) && ( '9999' < substr( $tz, 1, 4 ))) ||
|
2498
|
(( 7 == strlen( $tz )) && ( '00' > substr( $tz, 5, 2 )) && ( '99' < substr( $tz, 5, 2 ))))
|
2499
|
return $offset;
|
2500
|
$hours2sec = (int) substr( $tz, 1, 2 ) * 3600;
|
2501
|
$min2sec = (int) substr( $tz, 3, 2 ) * 60;
|
2502
|
$sec = ( 7 == strlen( $tz )) ? (int) substr( $tz, -2 ) : '00';
|
2503
|
$offset = $hours2sec + $min2sec + $sec;
|
2504
|
$offset = ('-' == substr( $tz, 0, 1 )) ? $offset * -1 : $offset;
|
2505
|
return $offset;
|
2506
|
}
|
2507
|
}
|