function date_ical_import in Date 7.2
Same name and namespace in other branches
- 5.2 date_api_ical.inc \date_ical_import()
- 5 date_api_ical.inc \date_ical_import()
- 5 date_ical.inc \date_ical_import()
- 6.2 date_api_ical.inc \date_ical_import()
- 6 date_api_ical.inc \date_ical_import()
- 7.3 date_api/date_api_ical.inc \date_ical_import()
- 7 date_api/date_api_ical.inc \date_ical_import()
Return an array of iCalendar information from an iCalendar file.
No timezone adjustment is performed in the import since the timezone conversion needed will vary depending on whether the value is being imported into the database (when it needs to be converted to UTC), is being viewed on a site that has user-configurable timezones (when it needs to be converted to the user's timezone), if it needs to be converted to the site timezone, or if it is a date without a timezone which should not have any timezone conversion applied.
Properties that have dates and times are converted to sub-arrays like: 'datetime' => Date in YYYY-MM-DD HH:MM format, not timezone adjusted. 'all_day' => Whether this is an all-day event. 'tz' => The timezone of the date, could be blank for absolute times that should get no timezone conversion.
Exception dates can have muliple values and are returned as arrayslike the above for each exception date.
Most other properties are returned as PROPERTY => VALUE.
Each item in the VCALENDAR will return an array like: [0] => Array ( [TYPE] => VEVENT [UID] => 104 [SUMMARY] => An example event [URL] => http://example.com/node/1 [DTSTART] => Array ( [datetime] => 1997-09-07 09:00:00 [all_day] => 0 [tz] => US/Eastern ) [DTEND] => Array ( [datetime] => 1997-09-07 11:00:00 [all_day] => 0 [tz] => US/Eastern ) [RRULE] => Array ( [FREQ] => Array ( [0] => MONTHLY ) [BYDAY] => Array ( [0] => 1SU [1] => -1SU ) ) [EXDATE] => Array ( [0] = Array ( [datetime] => 1997-09-21 09:00:00 [all_day] => 0 [tz] => US/Eastern ) [1] = Array ( [datetime] => 1997-10-05 09:00:00 [all_day] => 0 [tz] => US/Eastern ) ) [RDATE] => Array ( [0] = Array ( [datetime] => 1997-09-21 09:00:00 [all_day] => 0 [tz] => US/Eastern ) [1] = Array ( [datetime] => 1997-10-05 09:00:00 [all_day] => 0 [tz] => US/Eastern ) ) )
@todo Figure out how to handle this if subgroups are nested, like a VALARM nested inside a VEVENT.
Parameters
string $filename: Location (local or remote) of a valid iCalendar file.
Return value
array An array with all the elements from the ical.
File
- date_api/
date_api_ical.inc, line 92 - Parse iCal data.
Code
function date_ical_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 date_ical_parse($icaldatafolded);
}