You are here

function devel_shutdown in Devel 5

Same name and namespace in other branches
  1. 6 devel.module \devel_shutdown()
  2. 7 devel.module \devel_shutdown()

See devel_init() which registers this function as a shutdown function. Displays developer information in the footer.

1 string reference to 'devel_shutdown'
devel_init in ./devel.module
Implementation of hook_init(). Avoids custom error handling for better behavior when stepping though in a debugger.

File

./devel.module, line 524

Code

function devel_shutdown() {
  global $queries, $memory_init, $user;
  $output = '';

  // Set $GLOBALS['devel_shutdown'] = FALSE in order to supress the
  // devel footer for a page.  Not necessary if your page outputs any
  // of the Content-type http headers tested below (e.g. text/xml,
  // text/javascript, etc).  This is is advised where applicable.
  if ($GLOBALS['devel_shutdown'] !== FALSE) {

    // Try not to break non html pages.
    if (function_exists('drupal_get_headers')) {
      $headers = drupal_get_headers();
      $formats = array(
        'xml',
        'javascript',
        'json',
        'plain',
        'image',
        'application',
        'x-comma-separated-values',
      );
      foreach ($formats as $format) {
        if (strstr($headers, $format)) {
          return;
        }
      }
    }

    // don't append to CLI scripts
    if (empty($_SERVER['REQUEST_METHOD'])) {
      return;
    }
    if (isset($user) && user_access('access devel information')) {
      list($counts, $query_summary) = devel_query_summary();

      // Query log off, timer on.
      if (!variable_get('devel_query_display', 0) && variable_get('dev_timer', 0)) {
        $output = '<div class="dev-timer">' . devel_timer() . ' ' . $query_summary . '</div>';
      }

      // Query log on.
      $sum = 0;
      if (variable_get('devel_query_display', FALSE)) {
        $output .= '<div class="dev-query">';
        $output .= $query_summary;
        if (function_exists('theme_table')) {
          $txt .= t(' Queries taking longer than %threshold ms and queries executed more than once, are <span class="marker">highlighted</span>.', array(
            '%threshold' => variable_get('devel_execution', 5),
          ));
          if (variable_get('dev_timer', 0)) {
            $txt .= devel_timer();
          }
          $output .= $txt . devel_query_table($queries, $counts);
        }
        else {
          $output .= $txt;
          ob_start();
          dprint_r($queries);
          $output .= ob_get_clean();
        }
        $output .= '</div>';
      }
      if (variable_get('dev_mem', FALSE) && function_exists('memory_get_usage')) {
        $memory_shutdown = memory_get_usage();
        $list = array();
        foreach (array(
          'devel_init()' => $memory_init,
          'devel_shutdown()' => $memory_shutdown,
        ) as $type => $value) {
          $list[] = t('Memory used at %type: %value MB', array(
            '%type' => $type,
            '%value' => round($value / 1024 / 1024, 2),
          ));
        }
        $output .= '<div class="dev-memory-usage"><h3>' . 'Memory usage:' . '</h3>' . theme('item_list', $list) . '</div>';
      }

      // TODO: gzip this text if we are sending a gzip page. see drupal_page_header().
      if ($output) {
        print $output;
      }
    }
  }
  devel_store_queries();
}