function _agenda_parse_event in Agenda 7
Same name and namespace in other branches
- 6.2 agenda.module \_agenda_parse_event()
- 6 agenda.module \_agenda_parse_event()
- 7.2 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 305
Code
function _agenda_parse_event($xml, $block) {
$gd = $xml
->children('http://schemas.google.com/g/2005');
// Timezone
$tz = new DateTimeZone($block->timezone);
// Parse the timestamps
$updated = new DateTime($xml->updated, $tz);
$start = new DateTime((string) $gd->when
->attributes()->startTime, $tz);
$end = new DateTime((string) $gd->when
->attributes()->endTime, $tz);
// Work around a bug in Google Calendar which reports
// dates as "<published>0001-12-30T19:04:00.000-04:56</published>"
try {
$published = new DateTime((string) $xml->published, $tz);
} catch (Exception $e) {
$published = new DateTime('now', $tz);
}
// Build up information about the event
$event = array();
$event['title'] = htmlspecialchars((string) $xml->title);
$event['where'] = htmlspecialchars((string) $gd->where
->attributes()->valueString);
$event['description'] = _filter_autop(filter_xss((string) $xml->content));
$event['timezone'] = $block->timezone;
$event['start original'] = (string) $gd->when
->attributes()->startTime;
$event['start date'] = $start
->format($block->dateformat);
$event['start time'] = $start
->format($block->timeformat);
$event['start timestamp'] = strtotime($start
->format('c'));
// Use strtotime instead of getTimestamp for < PHP5.3
$event['end original'] = (string) $gd->when
->attributes()->endTime;
$event['end date'] = $end
->format($block->dateformat);
$event['end time'] = $end
->format($block->timeformat);
$event['end timestamp'] = strtotime($end
->format('c'));
$event['published'] = $published
->format($block->dateformat);
$event['updated'] = $updated
->format($block->dateformat);
$link = (array) $xml->link[0];
$event['url'] = (string) $link['@attributes']['href'];
$event['link'] = l($block->linktext, $event['url']);
// The day the event occurs on (without time) used for grouping
$event['when'] = $start
->format('Y-m-d');
// Hide the start and end times for full day events
if (strlen($gd->when
->attributes()->startTime) === 10) {
$event['start time'] = '';
$event['end time'] = '';
}
// Hide end date if it's the same as the start date
if ($event['start timestamp'] === $event['end timestamp'] - 86400) {
$event['end date'] = '';
}
return $event;
}