function agenda_debug in Agenda 6
Same name and namespace in other branches
- 6.2 agenda.admin.php \agenda_debug()
- 7.2 agenda.admin.php \agenda_debug()
- 7 agenda.admin.php \agenda_debug()
Provide a page to debug a calendar ID that is not working
1 string reference to 'agenda_debug'
- agenda_menu in ./
agenda.module - Implementation of hook_menu().
File
- ./
agenda.admin.php, line 310 - Administration interface for the agenda module
Code
function agenda_debug($bid) {
drupal_add_css(drupal_get_path('module', 'agenda') . '/agenda.css');
$output = array();
// Date check (http://drupal.org/node/545174)
$output[] = t('Checking server time: %date', array(
'%date' => gmdate('r'),
));
$output[] = t('Checking real UTC time via NTP: %date', array(
'%date' => gmdate('r', agenda_debug_ntp_time('0.pool.ntp.org')),
));
$output[] = t('Ensure these values are approximately the same, otherwise your system is incorrectly configured and agenda will be unable to calculate dates properly.');
// Timezone
global $user;
if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
$timezone = $user->timezone;
$output[] = t('Using per-user defined timezones! Make sure your accounts timezone setting is correct!');
}
else {
$output[] = t('Using site wide timezone settings (user configurable timezones are disabled).');
$timezone = variable_get('date_default_timezone', 0);
}
$output[] = t('Using timezone offset: @timezone', array(
'@timezone' => $timezone,
));
if (module_exists('date_api')) {
$output[] = t('Using the DateAPI for better timezone handling. Using timezone %name.', array(
'%name' => variable_get('date_default_timezone_name', 'No Timezone Set!'),
));
}
// Find calendar sources
$block = agenda_settings($bid);
$output[] = t('Reading calendar input:');
$output[] = '<pre>' . htmlspecialchars($block->calendars) . '</pre>';
$calendars = preg_split('@\\r\\n?|\\n@', $block->calendars);
$calendars = array_map('trim', $calendars);
$output[] = t('Found following calendars:');
$output[] = sprintf('<pre>%s</pre>', print_r($calendars, TRUE));
$googleid = $calendars[0];
if (count($calendars) > 1) {
$output[] = t('Multiple calendars found, debugging with the first calendar: %googleid', array(
'%googleid' => $googleid,
));
}
// Load the calendar
$source = _agenda_feed_url($googleid, $block);
$output[] = t('Fetching feed from <em>%source</em>', array(
'%source' => $source,
));
// Load the XML
$calendar = _agenda_load_xml($googleid, $block);
if (!$calendar) {
$output[] = t('<strong>Warning</strong>: Failed to load XML');
return theme('item_list', $output, NULL, 'ul', array(
'id' => 'agenda-debug',
));
}
$output[] = t('Loaded XML successfully');
// Find the events
$number_of_events = count($calendar->entry);
$output[] = t('Found @count events', array(
'@count' => $number_of_events,
));
if ($number_of_events === 0) {
$output[] = t('<strong>Warning</strong>: Nothing to do with empty calendar, stopping!');
return theme('item_list', $output, NULL, 'ul', array(
'id' => 'agenda-debug',
));
}
// Parse the events
$i = 0;
$eventdata = array();
foreach ($calendar->entry as $event) {
$output[] = t('Loading event @number which is @size bytes', array(
'@number' => ++$i,
'@size' => strlen($event
->asXml()),
));
$output[] = sprintf("<pre>%s</pre>", htmlspecialchars($event
->asXml()));
$thisevent = _agenda_parse_event($event, $block);
if (!$thisevent) {
$output[] = t('<strong>Warning</strong>: Failed to parse event!');
continue;
}
$output[] = t('Successfully parsed event:');
$output[] = '<pre>' . print_r($thisevent, TRUE) . '</pre>';
$eventdata[] = $thisevent;
}
$output[] = t('Parsed @success/@total events successfully', array(
'@success' => count($eventdata),
'@total' => $number_of_events,
));
$output[] = t('Begin filtering based on date: string provided (@old) which has timestamp (@timestamp) which has date (@date).', array(
'@old' => $what_is_old = agenda_variable_get($bid, 'start', '-1 day'),
'@timestamp' => $what_is_old_ts = strtotime($what_is_old),
'@date' => format_date($what_is_old_ts),
));
foreach ($eventdata as $key => $event) {
if ($event['start timestamp'] < $what_is_old_ts) {
$output[] = t('» Discarding %title because %when is older than %old', array(
'%title' => $event['title'],
'%when' => format_date($event['start timestamp'], 'small'),
'%old' => format_date($what_is_old_ts, 'small'),
));
unset($eventdata[$key]);
}
}
$output[] = t('Finished. Started with @total events, will display @display events', array(
'@total' => $number_of_events,
'@display' => count($eventdata),
));
$html = theme('item_list', $output, NULL, 'ul', array(
'id' => 'agenda-debug',
));
if (count($eventdata)) {
$first = array_slice($eventdata, 0, 1);
$html .= theme('table', array_keys($first[0]), $eventdata);
}
return $html;
}