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');
 
   69                 if($a_type == self::INPUT_STRING)
 
   71                         $this->ical = $a_ical;
 
   73                 elseif($a_type == self::INPUT_FILE)
 
   75                         $this->file = $a_ical;
 
   76                         $this->ical = file_get_contents($a_ical);
 
   90                 include_once(
'./Services/Calendar/classes/class.ilCalendarCategory.php');
 
  105                 for($i = 0; $i < count($lines); $i++)
 
  111                         while(isset($lines[$i + $offset]) and
 
  116                                 $line = $line.substr($lines[$i + $offset],1);
 
  133                 return $this->container[count($this->container) - 1];
 
  144                 $this->container = array($a_container);
 
  154                 return array_pop($this->container);
 
  165                 $this->container[] = $a_container;
 
  178                         case 'BEGIN:VCALENDAR':
 
  179                                 $this->log->write(__METHOD__.
': BEGIN VCALENDAR');
 
  183                         case 'END:VCALENDAR':
 
  184                                 $this->log->write(__METHOD__.
': END VCALENDAR');
 
  188                                 $this->log->write(__METHOD__.
': BEGIN VEVENT');
 
  193                                 $this->log->write(__METHOD__.
': END VEVENT');
 
  200                         case 'BEGIN:VTIMEZONE':
 
  201                                 $this->log->write(__METHOD__.
': BEGIN VTIMEZONE');
 
  206                         case 'END:VTIMEZONE':
 
  207                                 $this->log->write(__METHOD__.
': END VTIMEZONE');
 
  209                                 if($tzid = $this->
getContainer()->getItemsByName(
'TZID'))
 
  211                                         $this->default_timezone = $this->
getTZ($tzid[0]->getValue());
 
  217                                 if(strpos(trim($line),
'BEGIN') === 0)
 
  219                                         $this->log->write(__METHOD__.
': Do not handling line:'.$line);
 
  222                                 list($params,$values) = $this->
splitLine($line);
 
  239                 if($splitted_param = explode(
';',$a_param_part))
 
  242                         foreach($splitted_param as $param)
 
  246                                         $items[$counter][
'param'] = $param;
 
  247                                         $items[$counter][
'value'] = $a_value_part; 
 
  252                                         if($splitted_param_values = explode(
'=',$param))
 
  254                                                 $items[$counter][
'param'] = $splitted_param_values[0];
 
  255                                                 $items[$counter][
'value'] = $splitted_param_values[1];
 
  263                 $substituted_values = str_replace(
'\;',
'',$a_value_part);
 
  266                 if($splitted_values = explode(
';',$substituted_values))
 
  269                         foreach($splitted_values as $value)
 
  272                                 if($splitted_value_values = explode(
'=',$value))
 
  274                                         $values[$counter][
'param'] = $splitted_value_values[0];
 
  275                                         $values[$counter][
'value'] = $splitted_value_values[1];
 
  284                         $this->log->write(__METHOD__.
': Cannot parse parameter: '.$a_param_part.
', value: '.$a_value_part);
 
  290                 foreach($items as $item)
 
  299                                 if(count($values) > 1)
 
  301                                         foreach($values as $value)
 
  303                                                 $value = 
new ilICalValue($value[
'param'],$value[
'value']);
 
  329                 if(preg_match(
'/([^:]+):(.*)/',$a_line,$matches))
 
  331                         return array($matches[1],$matches[2]);
 
  335                         $this->log->write(__METHOD__.
': Found invalid parameter: '.$a_line);
 
  346         protected function tokenize($a_string,$a_tokenizer)
 
  348                 return explode($a_tokenizer,$a_string); 
 
  356         protected function getTZ($a_timezone)
 
  358                 $parts = explode(
'/',$a_timezone);
 
  359                 $tz = array_pop($parts);
 
  360                 $continent = array_pop($parts);
 
  362                 if(isset($continent) and $continent)
 
  364                         $timezone = $continent.
'/'.$tz;
 
  368                         $timezone = $a_timezone;
 
  373                         if($this->default_timezone->getIdentifier() == $timezone)
 
  379                                 $this->log->write(__METHOD__.
': Found new timezone: '.$timezone);
 
  385                         $this->log->write(__METHOD__.
': Found invalid timezone: '.$timezone);
 
  404                         $this->log->write(__METHOD__.
': Found invalid timezone: '.$timezone);
 
  416                 $this->default_timezone->restoreTZ();
 
  429                 foreach($this->
getContainer()->getItemsByName(
'SUMMARY',
false) as $item)
 
  431                         if(is_a($item,
'ilICalProperty'))
 
  433                                 $entry->setTitle($this->
purgeString($item->getValue()));
 
  438                 foreach($this->
getContainer()->getItemsByName(
'DESCRIPTION',
false) as $item)
 
  440                         if(is_a($item,
'ilICalProperty'))
 
  442                                 $entry->setDescription($this->
purgeString($item->getValue()));
 
  448                 foreach($this->
getContainer()->getItemsByName(
'LOCATION',
false) as $item)
 
  450                         if(is_a($item,
'ilICalProperty'))
 
  452                                 $entry->setLocation($this->
purgeString($item->getValue()));
 
  457                 foreach($this->
getContainer()->getItemsByName(
'DTSTART') as $start)
 
  460                         foreach($start->getItemsByName(
'VALUE') as $type)
 
  462                                 if($type->getValue() == 
'DATE')
 
  468                         foreach($start->getItemsByName(
'TZID') as $param)
 
  470                                 $start_tz = $this->
getTZ($param->getValue());
 
  474                                 $start = 
new ilDate($start->getValue(),
 
  481                                         $start_tz->getIdentifier());
 
  483                         $entry->setStart($start);
 
  484                         $entry->setFullday($fullday);
 
  487                 foreach($this->
getContainer()->getItemsByName(
'DTEND') as $end)
 
  490                         foreach($end->getItemsByName(
'VALUE') as $type)
 
  492                                 if($type->getValue() == 
'DATE')
 
  498                         foreach($end->getItemsByName(
'TZID') as $param)
 
  500                                 $end_tz = $this->
getTZ($param->getValue());
 
  504                                 $end = 
new ilDate($end->getValue(),
 
  511                                         $end_tz->getIdentifier());
 
  513                         $entry->setEnd($end);
 
  514                         $entry->setFullday($fullday);
 
  519                 include_once(
'./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
 
  525                 foreach($this->
getContainer()->getItemsByName(
'RRULE') as $recurrence)
 
  527                         #var_dump("<pre>",$recurrence,"</pre>"); 
  530                         include_once(
'./Services/Calendar/classes/class.ilCalendarRecurrence.php');
 
  532                         $rec->setEntryId($entry->getEntryId());
 
  534                         foreach($recurrence->getItemsByName(
'FREQ') as $freq)
 
  536                                 switch($freq->getValue())
 
  542                                                 $rec->setFrequenceType($freq->getValue());
 
  546                                                 $this->log->write(__METHOD__.
': Cannot handle recurring event of type: '.$freq->getValue());
 
  551                         foreach($recurrence->getItemsByName(
'COUNT') as $value)
 
  553                                 $rec->setFrequenceUntilCount($value->getValue());
 
  556                         foreach($recurrence->getItemsByName(
'UNTIL') as $until)
 
  561                         foreach($recurrence->getItemsByName(
'INTERVAL') as $value)
 
  563                                 $rec->setInterval($value->getValue());
 
  566                         foreach($recurrence->getItemsByName(
'BYDAY') as $value)
 
  568                                 $rec->setBYDAY($value->getValue());
 
  571                         foreach($recurrence->getItemsByName(
'BYWEEKNO') as $value)
 
  573                                 $rec->setBYWEEKNO($value->getValue());
 
  576                         foreach($recurrence->getItemsByName(
'BYMONTH') as $value)
 
  578                                 $rec->setBYMONTH($value->getValue());
 
  581                         foreach($recurrence->getItemsByName(
'BYMONTHDAY') as $value)
 
  583                                 $rec->setBYMONTHDAY($value->getValue());
 
  586                         foreach($recurrence->getItemsByName(
'BYYEARDAY') as $value)
 
  588                                 $rec->setBYYEARDAY($value->getValue());
 
  591                         foreach($recurrence->getItemsByName(
'BYSETPOS') as $value)
 
  593                                 $rec->setBYSETPOS($value->getValue());
 
  596                         foreach($recurrence->getItemsByName(
'WKST') as $value)
 
  598                                 $rec->setWeekstart($value->getValue());
 
  612                 $a_string = str_replace(
"\;",
";",$a_string);
 
  613                 $a_string = str_replace(
"\,",
",",$a_string);
 
  614                 $a_string = str_replace(
"\:",
":",$a_string);