function devel_shutdown_real

Same name in other branches
  1. 7.x-1.x devel.module \devel_shutdown_real()

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

1 string reference to 'devel_shutdown_real'
devel_shutdown in ./devel.module
See devel_start() which registers this function as a shutdown function.

File

./devel.module, line 854

Code

function devel_shutdown_real() {
    global $queries, $memory_init, $user;
    $output = $txt = '';
    // 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 (!isset($GLOBALS['devel_shutdown']) && !isset($GLOBALS['devel_redirecting'])) {
        // 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',
                'csv',
                'x-comma-separated-values',
            );
            foreach ($formats as $format) {
                if (strstr($headers, $format)) {
                    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;
                // calling theme() during shutdown is very bad if registry gets rebuilt like when making a change on  admin/build/modules
                // so we check for presence of theme registry before calling theme()
                if (function_exists('theme_get_registry') && theme_get_registry()) {
                    $txt = t_safe(' 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;
                    $output .= '</div>';
                    $output .= devel_query_table($queries, $counts);
                }
                else {
                    $output .= $txt;
                    $output .= '</div>';
                    ob_start();
                    dprint_r($queries);
                    $output .= ob_get_clean();
                }
            }
            if (variable_get('dev_mem', FALSE) && function_exists('memory_get_usage')) {
                $memory_shutdown = memory_get_usage();
                $args = array(
                    '@memory_init' => round($memory_init / 1024 / 1024, 2),
                    '@memory_shutdown' => round($memory_shutdown / 1024 / 1024, 2),
                );
                $msg = '<div class="dev-memory-usage"><h3>Memory usage:</h3> Memory used at: devel_init()=<strong>@memory_init</strong> MB, devel_shutdown()=<strong>@memory_shutdown</strong> MB.</div>';
                // theme() may not be available. not t() either.
                $output .= t_safe($msg, $args);
            }
            $output .= devel_xhprof_link_show();
            // TODO: gzip this text if we are sending a gzip page. see drupal_page_header().
        }
        if ($output) {
            print $output;
        }
    }
    devel_store_queries();
}