コード例 #1
0
ファイル: agenda.admin.php プロジェクト: xtpclark/ppclc
/**
 * Provide a page to debug a calendar ID that is not working
 */
function agenda_debug($bid)
{
    $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.');
    // 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
    list($address, $token) = _agenda_parse_googleid($googleid);
    $source = _agenda_feed_url($address, $token, $block);
    $output[] = t('Fetching feed from <em>%source</em>', array('%source' => $source));
    // Load the XML
    $calendar = _agenda_load_xml($address, $token, $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('&raquo; Discarding %title because %start is older than %old', array('%title' => $event['title'], '%start' => 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)));
    // Now take all of our debug data and theme it up, starting with the logs
    $debug_log = theme('item_list', array('items' => $output));
    // Build a table of all of the events found
    $event_table = '';
    if (count($eventdata)) {
        $first_row = array_slice($eventdata, 0, 1);
        $event_table = theme('table', array('header' => array_keys($first_row[0]), 'rows' => $eventdata, 'sticky' => FALSE));
    }
    // Render
    return array('title' => array('#markup' => '<h2>' . t('Debugging %calendar block', array('%calendar' => $block->title)) . '</h2>'), 'debug_log' => array('#markup' => $debug_log, '#prefix' => '<h3>Log</h3><div id="agenda-debug-log">', '#suffix' => '</div>'), 'event_table' => array('#markup' => $event_table, '#prefix' => '<h3>Events</h3><div id="agenda-debug-table">', '#suffix' => '</div>'), '#attached' => array('css' => array(drupal_get_path('module', 'agenda') . '/agenda.css')));
}
コード例 #2
0
ファイル: agenda.admin.php プロジェクト: dvoineu/drupal7
/**
 * Provide a page to debug a calendar ID that is not working
 */
function agenda_debug($bid)
{
    $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.');
    // Find calendar sources
    $block = agenda_settings($bid);
    $debug_title = array('#markup' => '<h2>' . t('Debugging %calendar block', array('%calendar' => $block->title)) . ' - ' . l('Edit', 'admin/config/services/agenda/' . $bid . '/configure', array('query' => drupal_get_destination())) . '</h2>');
    $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));
    }
    $timeMin = date('Y-m-d', strtotime($block->start)) . 'T00:00:00' . date('P');
    $timeMax = date('Y-m-d', strtotime($block->end)) . 'T00:00:00' . date('P');
    $output[] = t('Using Agenda Block start value of %blockStart converted for Google API to %timeMin', array('%blockStart' => $block->start, '%timeMin' => $timeMin));
    $output[] = t('Using Agenda Block end value of %blockEnd converted for Google API to %timeMax', array('%blockEnd' => $block->end, '%timeMax' => $timeMax));
    $output[] = t('Maximum number of events to fetch: %maxEvents', array('%maxEvents' => $block->maxevents));
    $output[] = t('Timezone: %timezone', array('%timezone' => $block->timezone));
    $googlekey = !empty($block->googleapi_override) ? $block->googleapi_override : variable_get('agenda_googleapi', '');
    $output[] = t('Using Google API Key: %googlekey', array('%googlekey' => $googlekey));
    // Load the calendar
    list($address, $token) = _agenda_parse_googleid($googleid);
    // Load the XML
    $calendar = _agenda_load_google($address, $token, $block);
    if (!$calendar) {
        $output[] = t('<strong>Warning</strong>: Failed');
        return theme('item_list', $output, NULL, 'ul', array('id' => 'agenda-debug'));
    }
    $output[] = t('Loaded Calendar successfully');
    // Find the events
    $calendar_events = $calendar->getItems();
    $number_of_events = count($calendar_events);
    $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!');
        $debug_log = theme('item_list', array('items' => $output));
        return array('title' => array('#markup' => '<h2>' . t('Debugging %calendar block', array('%calendar' => $block->title)) . ' - ' . l('Edit', 'admin/config/services/agenda/' . $bid . '/configure') . '</h2>'), 'debug_log' => array('#markup' => $debug_log, '#prefix' => '<h3>Log</h3><div id="agenda-debug-log">', '#suffix' => '</div>'), '#attached' => array('css' => array(drupal_get_path('module', 'agenda') . '/agenda.css')));
    }
    // Parse the events
    $i = 0;
    $eventdata = array();
    foreach ($calendar_events as $event) {
        $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('&raquo; Discarding %title because %start is older than %old', array('%title' => $event['title'], '%start' => 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)));
    // Now take all of our debug data and theme it up, starting with the logs
    $debug_log = theme('item_list', array('items' => $output));
    // Build a table of all of the events found
    $event_table = '';
    if (count($eventdata)) {
        $first_row = array_slice($eventdata, 0, 1);
        $event_table = theme('table', array('header' => array_keys($first_row[0]), 'rows' => $eventdata, 'sticky' => TRUE));
    }
    // Render
    return array('title' => $debug_title, 'debug_log' => array('#markup' => $debug_log, '#prefix' => '<h3>Log</h3><div id="agenda-debug-log">', '#suffix' => '</div>'), 'event_table' => array('#markup' => $event_table, '#prefix' => '<h3>Events</h3><div id="agenda-debug-table">', '#suffix' => '</div>'), '#attached' => array('css' => array(drupal_get_path('module', 'agenda') . '/agenda.css')));
}