function _agenda_parse_event in Agenda 6.2
Same name and namespace in other branches
- 6 agenda.module \_agenda_parse_event()
- 7.2 agenda.module \_agenda_parse_event()
- 7 agenda.module \_agenda_parse_event()
Read useful event information from XML chunk
@access private
Parameters
SimpleXMLElement $xml An event node from a gData feed:
object $block The settings object:
Return value
array Associative array of information about the event
2 calls to _agenda_parse_event()
- agenda_debug in ./
agenda.admin.php - Provide a page to debug a calendar ID that is not working
- agenda_get_events in ./
agenda.module - Given a list of calendar IDs, parse out and return any event data
File
- ./
agenda.module, line 362
Code
function _agenda_parse_event($google_response, $block) {
// Timezone
$tz = new DateTimeZone(isset($block->timezone) ? $block->timezone : variable_get('date_default_timezone_name', date_default_timezone_get()));
// Parse the timestamps
$updated = new DateTime($google_response->updated, $tz);
//check if event is all day by looking from dateTime
$start = new DateTime((string) $google_response->start->dateTime ? $google_response->start->dateTime : $google_response->start->date, $tz);
//need to minus 1 day from end date for all day events because end time is exclusive - https://developers.google.com/google-apps/calendar/v3/reference/events
$end = new DateTime((string) $google_response->end->dateTime ? $google_response->end->dateTime : date('Y-m-d', strtotime($google_response->end->date . " -1 day")), $tz);
$event = array();
$event['title'] = htmlspecialchars((string) $google_response->summary);
$event['where'] = htmlspecialchars((string) $google_response->location);
$event['description'] = _filter_autop(filter_xss((string) $google_response->description));
$event['timezone'] = $block->timezone;
$event['start original'] = (string) $google_response->start->dateTime;
$event['start date'] = format_date(strtotime($start
->format('c')), 'custom', $block->dateformat, $block->timezone);
$event['start time'] = format_date(strtotime($start
->format('c')), 'custom', $block->timeformat, $block->timezone);
$event['start timestamp'] = strtotime($start
->format('c'));
// Use strtotime instead of getTimestamp for < PHP5.3
$event['end original'] = (string) $google_response->end->dateTime;
$event['end date'] = format_date(strtotime($end
->format('c')), 'custom', $block->dateformat, $block->timezone);
$event['end time'] = format_date(strtotime($end
->format('c')), 'custom', $block->timeformat, $block->timezone);
$event['end timestamp'] = strtotime($end
->format('c'));
// Published date and time are not available in v3.
$event['updated'] = format_date(strtotime($updated
->format('c')), 'custom', $block->dateformat, $block->timezone);
$event['url'] = (string) $google_response->htmlLink;
$event['link'] = l($block->linktext, $event['url'] . '&ctz=' . $block->timezone);
// The day the event occurs on (without time) used for grouping
$event['when'] = $start
->format('Y-m-d');
//new fields added for google api v3.
$event['event id'] = $google_response->id;
$event['hangout url'] = $google_response->hangoutLink;
$event['hangout link'] = !empty($block->hangoutlinktext) ? l($block->hangoutlinktext, $event['hangout url']) : NULL;
$event['iCalUID'] = $google_response->iCalUID;
$event['recurringEventId'] = $google_response->recurringEventId;
$event['creator email'] = $google_response->creator->email;
$event['creator displayName'] = $google_response->creator->displayName;
$event['organizer email'] = $google_response->organizer->email;
$event['organizer displayName'] = $google_response->organizer->displayName;
if ($google_response->start->date) {
$event['start time'] = '';
}
if ($google_response->end->date) {
$event['end time'] = '';
}
if ($google_response->start->date && $google_response->end->date) {
$event['allday'] = true;
}
return $event;
}