24 include_once(
'./Services/Calendar/classes/iCal/class.ilICalUtils.php');
25 include_once(
'./Services/Calendar/classes/class.ilDateTime.php');
26 include_once(
'./Services/Calendar/classes/class.ilCalendarEntry.php');
27 include_once(
'./Services/Calendar/classes/class.ilTimeZone.php');
28 include_once(
'./Services/Calendar/classes/class.ilTimeZoneException.php');
30 include_once(
'./Services/Calendar/classes/iCal/class.ilICalComponent.php');
31 include_once(
'./Services/Calendar/classes/iCal/class.ilICalProperty.php');
32 include_once(
'./Services/Calendar/classes/iCal/class.ilICalParameter.php');
33 include_once(
'./Services/Calendar/classes/iCal/class.ilICalValue.php');
35 include_once
'./Services/Calendar/exceptions/class.ilICalParserException.php';
74 if (
$a_type == self::INPUT_STRING) {
75 $this->ical = $a_ical;
76 } elseif (
$a_type == self::INPUT_FILE) {
77 $this->
file = $a_ical;
78 $this->ical = file_get_contents($a_ical);
80 if (!strlen($this->ical)) {
83 #$GLOBALS['ilLog']->write(__METHOD__.': Ical content: '. $this->ical); 85 $this->log =
$GLOBALS[
'DIC']->logger()->cal();
97 include_once(
'./Services/Calendar/classes/class.ilCalendarCategory.php');
113 if (count($lines) == 1) {
117 for (
$i = 0;
$i < count($lines);
$i++) {
122 while (isset($lines[
$i + $offset]) and
126 $line = $line . substr($lines[
$i + $offset], 1);
143 return $this->container[count($this->container) - 1];
154 $this->container =
array($a_container);
164 return array_pop($this->container);
175 $this->container[] = $a_container;
186 switch (trim($line)) {
187 case 'BEGIN:VCALENDAR':
188 $this->log->debug(
'BEGIN VCALENDAR');
192 case 'END:VCALENDAR':
193 $this->log->debug(
'END VCALENDAR');
197 $this->log->debug(
'BEGIN VEVENT');
202 $this->log->debug(
'END VEVENT');
209 case 'BEGIN:VTIMEZONE':
210 $this->log->debug(
'BEGIN VTIMEZONE');
215 case 'END:VTIMEZONE':
216 $this->log->debug(
'END VTIMEZONE');
218 if ($tzid = $this->
getContainer()->getItemsByName(
'TZID')) {
219 $this->default_timezone = $this->
getTZ($tzid[0]->getValue());
225 if (strpos(trim($line),
'BEGIN') === 0) {
226 $this->log->info(
'Do not handling line:' . $line);
229 if (strpos(trim($line),
'X-WR-TIMEZONE') === 0) {
230 list($param, $value) = $this->
splitLine($line);
231 $this->default_timezone = $this->
getTZ($value);
250 if ($splitted_param = explode(
';', $a_param_part)) {
252 foreach ($splitted_param as $param) {
255 $items[
$counter][
'value'] = $a_value_part;
258 if ($splitted_param_values = explode(
'=', $param)) {
259 $items[
$counter][
'param'] = $splitted_param_values[0];
260 $items[
$counter][
'value'] = $splitted_param_values[1];
268 $substituted_values = str_replace(
'\;',
'', $a_value_part);
271 if ($splitted_values = explode(
';', $substituted_values)) {
273 foreach ($splitted_values as $value) {
275 if ($splitted_value_values = explode(
'=', $value)) {
276 $values[
$counter][
'param'] = $splitted_value_values[0];
277 $values[
$counter][
'value'] = $splitted_value_values[1];
284 if (!count($items)) {
285 $this->log->write(__METHOD__ .
': Cannot parse parameter: ' . $a_param_part .
', value: ' . $a_value_part);
291 foreach ($items as $item) {
303 if (count($values) > 1) {
304 foreach ($values as $value) {
305 $value =
new ilICalValue($value[
'param'], $value[
'value']);
329 if (preg_match(
'/([^:]+):(.*)/', $a_line, $matches)) {
330 return array($matches[1],$matches[2]);
332 $this->log->write(__METHOD__ .
': Found invalid parameter: ' . $a_line);
343 protected function tokenize($a_string, $a_tokenizer)
345 return explode($a_tokenizer, $a_string);
353 protected function getTZ($a_timezone)
355 $parts = explode(
'/', $a_timezone);
356 $tz = array_pop($parts);
357 $continent = array_pop($parts);
359 if (isset($continent) and $continent) {
360 $timezone = $continent .
'/' .
$tz;
362 $timezone = $a_timezone;
366 if ($this->default_timezone->getIdentifier() == $timezone) {
369 $this->log->write(__METHOD__ .
': Found new timezone: ' . $timezone);
373 $this->log->write(__METHOD__ .
': Found invalid timezone: ' . $timezone);
388 $this->log->write(__METHOD__ .
': Found invalid timezone: ' . $timezone);
400 $this->default_timezone->restoreTZ();
413 foreach ($this->
getContainer()->getItemsByName(
'SUMMARY',
false) as $item) {
414 if (is_a($item,
'ilICalProperty')) {
415 $entry->setTitle($this->
purgeString($item->getValue()));
420 foreach ($this->
getContainer()->getItemsByName(
'DESCRIPTION',
false) as $item) {
421 if (is_a($item,
'ilICalProperty')) {
422 $entry->setDescription($this->
purgeString($item->getValue()));
428 foreach ($this->
getContainer()->getItemsByName(
'LOCATION',
false) as $item) {
429 if (is_a($item,
'ilICalProperty')) {
430 $entry->setLocation($this->
purgeString($item->getValue()));
435 foreach ($this->
getContainer()->getItemsByName(
'DTSTART') as $start) {
437 foreach ($start->getItemsByName(
'VALUE') as
$type) {
438 if (
$type->getValue() ==
'DATE') {
443 foreach ($start->getItemsByName(
'TZID') as $param) {
444 $start_tz = $this->
getTZ($param->getValue());
455 $start_tz->getIdentifier()
458 $entry->setStart($start);
459 $entry->setFullday($fullday);
464 foreach ($end->getItemsByName(
'VALUE') as
$type) {
465 if (
$type->getValue() ==
'DATE') {
470 foreach ($end->getItemsByName(
'TZID') as $param) {
471 $end_tz = $this->
getTZ($param->getValue());
483 $end_tz->getIdentifier()
486 $entry->setEnd($end);
487 $entry->setFullday($fullday);
490 if (!$entry->getStart() instanceof
ilDateTime) {
491 $this->log->warning(
'Cannot find start date. Event ignored.');
500 $entry->setEnd($entry->getStart());
506 $entry->setAutoGenerated(
true);
510 include_once(
'./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
516 foreach ($this->
getContainer()->getItemsByName(
'RRULE') as $recurrence) {
517 #var_dump("<pre>",$recurrence,"</pre>"); 520 include_once(
'./Services/Calendar/classes/class.ilCalendarRecurrence.php');
522 $rec->setEntryId($entry->getEntryId());
524 foreach ($recurrence->getItemsByName(
'FREQ') as $freq) {
525 switch ($freq->getValue()) {
530 $rec->setFrequenceType((
string) $freq->getValue());
534 $this->log->write(__METHOD__ .
': Cannot handle recurring event of type: ' . $freq->getValue());
539 foreach ($recurrence->getItemsByName(
'COUNT') as $value) {
540 $rec->setFrequenceUntilCount((
string) $value->getValue());
543 foreach ($recurrence->getItemsByName(
'UNTIL') as $until) {
547 foreach ($recurrence->getItemsByName(
'INTERVAL') as $value) {
548 $rec->setInterval((
string) $value->getValue());
551 foreach ($recurrence->getItemsByName(
'BYDAY') as $value) {
552 $rec->setBYDAY((
string) $value->getValue());
555 foreach ($recurrence->getItemsByName(
'BYWEEKNO') as $value) {
556 $rec->setBYWEEKNO((
string) $value->getValue());
559 foreach ($recurrence->getItemsByName(
'BYMONTH') as $value) {
560 $rec->setBYMONTH((
string) $value->getValue());
563 foreach ($recurrence->getItemsByName(
'BYMONTHDAY') as $value) {
564 $rec->setBYMONTHDAY((
string) $value->getValue());
567 foreach ($recurrence->getItemsByName(
'BYYEARDAY') as $value) {
568 $rec->setBYYEARDAY((
string) $value->getValue());
571 foreach ($recurrence->getItemsByName(
'BYSETPOS') as $value) {
572 $rec->setBYSETPOS((
string) $value->getValue());
575 foreach ($recurrence->getItemsByName(
'WKST') as $value) {
576 $rec->setWeekstart((
string) $value->getValue());
590 $a_string = str_replace(
"\;",
";", $a_string);
591 $a_string = str_replace(
"\,",
",", $a_string);
592 $a_string = str_replace(
"\:",
":", $a_string);
Model for a calendar entry.
This class offers methods for timezone handling.
splitLine($a_line)
parse parameters
switchTZ()
Switch timezone to given timezone.
storeItems($a_param_part, $a_value_part)
store items
setCategoryId($a_id)
set category id
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
switchTZ(ilTimeZone $timezone)
Switch timezone.
Stores calendar categories.
writeEvent()
write a new event
Represents a ical property.
Used for storage og multiple values E.g RRULE:FREQ=WEEKLY;COUNT=20;INTERVAL=2;BYDAY=TU.
tokenize($a_string, $a_tokenizer)
tokenize string
Class for TimeZone exceptions.
Reload workbook from saved file
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
increment($a_type, $a_count=1)
increment
Create styles array
The data for the language used.
Represents a ical component.
addAssignment($a_cal_cat_id)
add assignment
static _getInstance($a_tz='')
get instance by timezone
This class represents a ical parameter E.g VALUE=DATETIME.
getContainer()
get container
__construct($a_ical, $a_type)
Constructor.
setContainer($a_container)
set container
pushContainer($a_container)
push container
getTZ($a_timezone)
get timezone
parseLine($line)
parse a line
purgeString($a_string)
purge string
Abstract base class for all ical items (Component, Parameter and Value)