function agenda_get_events in Agenda 6.2
Same name and namespace in other branches
- 6 agenda.module \agenda_get_events()
- 7.2 agenda.module \agenda_get_events()
- 7 agenda.module \agenda_get_events()
Given a list of calendar IDs, parse out and return any event data
@access private
Parameters
array $block The block settings object:
bool $cacheaction Whether to interact with the cache:
1 call to agenda_get_events()
- agenda_display_block in ./
agenda.module - Generate the themed agenda block
File
- ./
agenda.module, line 295
Code
function agenda_get_events($block, $cache = TRUE) {
// Check the cache
if ($cache) {
$cache_key = 'agenda_block_' . $block->bid;
$eventdata = cache_get($cache_key, 'cache');
if ($eventdata->expire > time()) {
return $eventdata->data;
}
}
// Get the calendars
$calendars = preg_split('@\\r\\n?|\\n@', $block->calendars);
$calendars = array_map('trim', $calendars);
if (empty($calendars)) {
return FALSE;
}
// Otherwise parse the calendars
$eventdata = array();
foreach ($calendars as $calindex => $googleid) {
list($address, $token) = _agenda_parse_googleid($googleid);
$calendar = _agenda_load_google($address, $token, $block);
// If we fail to load the XML, handle it
if (!$calendar) {
watchdog('agenda', 'Unable to load the calendar feed (@feed) for block @bid', array(
'@feed' => $googleid,
'@bid' => $block->bid,
));
continue;
}
// Parse out the event details
foreach ($calendar
->getItems() as $google_event) {
$event = _agenda_parse_event($google_event, $block);
if (!$event) {
continue;
}
$event['index'] = (int) $calindex;
$event['calendar'] = (string) $calendar->summary;
$eventdata[] = $event;
}
}
// Sort the events by date
$timestamps = array();
foreach ($eventdata as $event) {
$timestamps[] = $event['start timestamp'];
}
array_multisort($timestamps, SORT_NUMERIC, $eventdata);
// Cache our data
if ($cache) {
$expires = time() + $block->cachetime;
cache_set($cache_key, $eventdata, 'cache', $expires);
}
return $eventdata;
}