public function DateiCalParse::import in Date 8
File
- date_api/
lib/ Drupal/ date_api/ DateiCalParse.php, line 123 - Parse iCal data.
Class
- DateiCalParse
- Return an array of iCalendar information from an iCalendar file.
Namespace
Drupal\date_apiCode
public function import($filename) {
// Fetch the iCal data. If file is a URL, use drupal_http_request. fopen
// isn't always configured to allow network connections.
if (substr($filename, 0, 4) == 'http') {
// Fetch the ical data from the specified network location.
$icaldatafetch = drupal_http_request($filename);
// Check the return result.
if ($icaldatafetch->error) {
watchdog('date ical', 'HTTP Request Error importing %filename: @error', array(
'%filename' => $filename,
'@error' => $icaldatafetch->error,
));
return FALSE;
}
// Break the return result into one array entry per lines.
$icaldatafolded = explode("\n", $icaldatafetch->data);
}
else {
$icaldatafolded = @file($filename, FILE_IGNORE_NEW_LINES);
if ($icaldatafolded === FALSE) {
watchdog('date ical', 'Failed to open file: %filename', array(
'%filename' => $filename,
));
return FALSE;
}
}
// Verify this is iCal data.
if (trim($icaldatafolded[0]) != 'BEGIN:VCALENDAR') {
watchdog('date ical', 'Invalid calendar file: %filename', array(
'%filename' => $filename,
));
return FALSE;
}
return $this
->parse($icaldatafolded);
}