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';
 
   73                 if($a_type == self::INPUT_STRING)
 
   75                         $this->ical = $a_ical;
 
   77                 elseif($a_type == self::INPUT_FILE)
 
   79                         $this->file = $a_ical;
 
   80                         $this->ical = file_get_contents($a_ical);
 
   82                         if(!strlen($this->ical))
 
   86                         #$GLOBALS['ilLog']->write(__METHOD__.': Ical content: '. $this->ical); 
  100                 include_once(
'./Services/Calendar/classes/class.ilCalendarCategory.php');
 
  116                 if(count(lines) == 1)
 
  121                 for($i = 0; $i < count($lines); $i++)
 
  127                         while(isset($lines[$i + $offset]) and
 
  132                                 $line = $line.substr($lines[$i + $offset],1);
 
  149                 return $this->container[count($this->container) - 1];
 
  160                 $this->container = array($a_container);
 
  170                 return array_pop($this->container);
 
  181                 $this->container[] = $a_container;
 
  194                         case 'BEGIN:VCALENDAR':
 
  195                                 $this->log->write(__METHOD__.
': BEGIN VCALENDAR');
 
  199                         case 'END:VCALENDAR':
 
  200                                 $this->log->write(__METHOD__.
': END VCALENDAR');
 
  204                                 $this->log->write(__METHOD__.
': BEGIN VEVENT');
 
  209                                 $this->log->write(__METHOD__.
': END VEVENT');
 
  216                         case 'BEGIN:VTIMEZONE':
 
  217                                 $this->log->write(__METHOD__.
': BEGIN VTIMEZONE');
 
  222                         case 'END:VTIMEZONE':
 
  223                                 $this->log->write(__METHOD__.
': END VTIMEZONE');
 
  225                                 if($tzid = $this->
getContainer()->getItemsByName(
'TZID'))
 
  227                                         $this->default_timezone = $this->
getTZ($tzid[0]->getValue());
 
  233                                 if(strpos(trim($line),
'BEGIN') === 0)
 
  235                                         $this->log->write(__METHOD__.
': Do not handling line:'.$line);
 
  238                                 if(strpos(trim($line),
'X-WR-TIMEZONE') === 0)
 
  240                                         list($param,$value) = $this->
splitLine($line);
 
  241                                         $this->default_timezone = $this->
getTZ($value);
 
  245                                         list($params,$values) = $this->
splitLine($line);
 
  263                 if($splitted_param = explode(
';',$a_param_part))
 
  266                         foreach($splitted_param as $param)
 
  270                                         $items[$counter][
'param'] = $param;
 
  271                                         $items[$counter][
'value'] = $a_value_part; 
 
  276                                         if($splitted_param_values = explode(
'=',$param))
 
  278                                                 $items[$counter][
'param'] = $splitted_param_values[0];
 
  279                                                 $items[$counter][
'value'] = $splitted_param_values[1];
 
  287                 $substituted_values = str_replace(
'\;',
'',$a_value_part);
 
  290                 if($splitted_values = explode(
';',$substituted_values))
 
  293                         foreach($splitted_values as $value)
 
  296                                 if($splitted_value_values = explode(
'=',$value))
 
  298                                         $values[$counter][
'param'] = $splitted_value_values[0];
 
  299                                         $values[$counter][
'value'] = $splitted_value_values[1];
 
  308                         $this->log->write(__METHOD__.
': Cannot parse parameter: '.$a_param_part.
', value: '.$a_value_part);
 
  314                 foreach($items as $item)
 
  329                                 if(count($values) > 1)
 
  331                                         foreach($values as $value)
 
  333                                                 $value = 
new ilICalValue($value[
'param'],$value[
'value']);
 
  359                 if(preg_match(
'/([^:]+):(.*)/',$a_line,$matches))
 
  361                         return array($matches[1],$matches[2]);
 
  365                         $this->log->write(__METHOD__.
': Found invalid parameter: '.$a_line);
 
  376         protected function tokenize($a_string,$a_tokenizer)
 
  378                 return explode($a_tokenizer,$a_string); 
 
  386         protected function getTZ($a_timezone)
 
  388                 $parts = explode(
'/',$a_timezone);
 
  389                 $tz = array_pop($parts);
 
  390                 $continent = array_pop($parts);
 
  392                 if(isset($continent) and $continent)
 
  394                         $timezone = $continent.
'/'.$tz;
 
  398                         $timezone = $a_timezone;
 
  403                         if($this->default_timezone->getIdentifier() == $timezone)
 
  409                                 $this->log->write(__METHOD__.
': Found new timezone: '.$timezone);
 
  415                         $this->log->write(__METHOD__.
': Found invalid timezone: '.$timezone);
 
  434                         $this->log->write(__METHOD__.
': Found invalid timezone: '.$timezone);
 
  446                 $this->default_timezone->restoreTZ();
 
  459                 foreach($this->
getContainer()->getItemsByName(
'SUMMARY',
false) as $item)
 
  461                         if(is_a($item,
'ilICalProperty'))
 
  463                                 $entry->setTitle($this->
purgeString($item->getValue()));
 
  468                 foreach($this->
getContainer()->getItemsByName(
'DESCRIPTION',
false) as $item)
 
  470                         if(is_a($item,
'ilICalProperty'))
 
  472                                 $entry->setDescription($this->
purgeString($item->getValue()));
 
  478                 foreach($this->
getContainer()->getItemsByName(
'LOCATION',
false) as $item)
 
  480                         if(is_a($item,
'ilICalProperty'))
 
  482                                 $entry->setLocation($this->
purgeString($item->getValue()));
 
  487                 foreach($this->
getContainer()->getItemsByName(
'DTSTART') as $start)
 
  490                         foreach($start->getItemsByName(
'VALUE') as $type)
 
  492                                 if($type->getValue() == 
'DATE')
 
  498                         foreach($start->getItemsByName(
'TZID') as $param)
 
  500                                 $start_tz = $this->
getTZ($param->getValue());
 
  504                                 $start = 
new ilDate($start->getValue(),
 
  511                                         $start_tz->getIdentifier());
 
  513                         $entry->setStart($start);
 
  514                         $entry->setFullday($fullday);
 
  517                 foreach($this->
getContainer()->getItemsByName(
'DTEND') as $end)
 
  520                         foreach($end->getItemsByName(
'VALUE') as $type)
 
  522                                 if($type->getValue() == 
'DATE')
 
  528                         foreach($end->getItemsByName(
'TZID') as $param)
 
  530                                 $end_tz = $this->
getTZ($param->getValue());
 
  534                                 $end = 
new ilDate($end->getValue(),
 
  542                                         $end_tz->getIdentifier());
 
  544                         $entry->setEnd($end);
 
  545                         $entry->setFullday($fullday);
 
  550                         $entry->setAutoGenerated(
true);
 
  554                 include_once(
'./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
 
  560                 foreach($this->
getContainer()->getItemsByName(
'RRULE') as $recurrence)
 
  562                         #var_dump("<pre>",$recurrence,"</pre>"); 
  565                         include_once(
'./Services/Calendar/classes/class.ilCalendarRecurrence.php');
 
  567                         $rec->setEntryId($entry->getEntryId());
 
  569                         foreach($recurrence->getItemsByName(
'FREQ') as $freq)
 
  571                                 switch($freq->getValue())
 
  577                                                 $rec->setFrequenceType((
string) $freq->getValue());
 
  581                                                 $this->log->write(__METHOD__.
': Cannot handle recurring event of type: '.$freq->getValue());
 
  586                         foreach($recurrence->getItemsByName(
'COUNT') as $value)
 
  588                                 $rec->setFrequenceUntilCount((
string) $value->getValue());
 
  591                         foreach($recurrence->getItemsByName(
'UNTIL') as $until)
 
  596                         foreach($recurrence->getItemsByName(
'INTERVAL') as $value)
 
  598                                 $rec->setInterval((
string) $value->getValue());
 
  601                         foreach($recurrence->getItemsByName(
'BYDAY') as $value)
 
  603                                 $rec->setBYDAY((
string) $value->getValue());
 
  606                         foreach($recurrence->getItemsByName(
'BYWEEKNO') as $value)
 
  608                                 $rec->setBYWEEKNO((
string) $value->getValue());
 
  611                         foreach($recurrence->getItemsByName(
'BYMONTH') as $value)
 
  613                                 $rec->setBYMONTH((
string) $value->getValue());
 
  616                         foreach($recurrence->getItemsByName(
'BYMONTHDAY') as $value)
 
  618                                 $rec->setBYMONTHDAY((
string) $value->getValue());
 
  621                         foreach($recurrence->getItemsByName(
'BYYEARDAY') as $value)
 
  623                                 $rec->setBYYEARDAY((
string) $value->getValue());
 
  626                         foreach($recurrence->getItemsByName(
'BYSETPOS') as $value)
 
  628                                 $rec->setBYSETPOS((
string) $value->getValue());
 
  631                         foreach($recurrence->getItemsByName(
'WKST') as $value)
 
  633                                 $rec->setWeekstart((
string) $value->getValue());
 
  647                 $a_string = str_replace(
"\;",
";",$a_string);
 
  648                 $a_string = str_replace(
"\,",
",",$a_string);
 
  649                 $a_string = str_replace(
"\:",
":",$a_string);