'\\\\', ',' => '\,', ';' => '\;', "\r" => '', "\n" => '\n' ); $text = str_replace(array_keys($rep_array), array_values($rep_array), $text); return $text; } function ical_split_long_lines($text) { $parts = str_split($text, 70); $line = array_shift($parts); foreach ($parts as $part) { $part = utf8_encode($part); $line .= "\r\n $part"; } return $line; } function list_to_ical( $d, $events ) { $lines = array( 'BEGIN:VCALENDAR', 'VERSION:2.0', 'X-WR-CALNAME:Dev8D 2010 Events', 'PRODID:-//XMLEVENT//Events//EN', 'X-WR-TIMEZONE:Europe/London', 'CALSCALE:GREGORIAN', 'METHOD:PUBLISH', 'BEGIN:VTIMEZONE', 'TZID:Europe/London', 'BEGIN:DAYLIGHT', 'TZOFFSETFROM:+0000', 'RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU', 'DTSTART:19810329T010000', 'TZNAME:GMT+01:00', 'TZOFFSETTO:+0100', 'END:DAYLIGHT', 'BEGIN:STANDARD', 'TZOFFSETFROM:+0100', 'RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU', 'DTSTART:19961027T020000', 'TZNAME:GMT', 'TZOFFSETTO:+0000', 'END:STANDARD', 'END:VTIMEZONE', ); foreach( $events as $event_id ) { $lines[] = to_ical_vevent( $d, $event_id ); } $lines[] = 'END:VCALENDAR'; return implode("\r\n", $lines); } function to_ical_vevent($d,$event_id) { $event = $d["Event"][$event_id]; $dstart = preg_split( '/[- :TZ]/', $event["cal:dtstart"][0] ); $dend = preg_split( '/[- :TZ]/', $event["cal:dtend"][0] ); $d_format = 'TZID=Europe/London:%04d%02d%02dT%02d%02d%02d'; $start_line = "DTSTART;".sprintf($d_format, $dstart[0],$dstart[1],$dstart[2],$dstart[3],$dstart[4], 0); $end_line = "DTEND;".sprintf($d_format, $dend[0],$dend[1],$dend[2],$dend[3],$dend[4], 0); $title = ical_escape($event['cal:summary'][0]); $summary = ical_split_long_lines("SUMMARY:$title"); #$description = ical_escape($event['cal:description'][0]); #$description_line = ical_split_long_lines("DESCRIPTION:$description"); $location = $d["Location"][$event["swc:hasLocation"][0]]; $location_line = null; if (!empty($location)) { $location_line = 'LOCATION:' . $location["rdfs:label"][0]; } $lines[] = 'BEGIN:VEVENT'; $lines[] = "UID:".ical_escape($event_id); $lines[] = $start_line; $lines[] = $end_line; $lines[] = $summary; #$lines[] = $description_line; $lines[] = 'SEQUENCE:0'; #$lines[] = 'URL:' . $this->data['url']; if (!is_null($location_line)) { $lines[] = $location_line; } $lines[] = "END:VEVENT"; return implode("\r\n", $lines); }