You are here

function admin_menu_js_cache in Administration menu 5.3

Same name and namespace in other branches
  1. 8.3 admin_menu.module \admin_menu_js_cache()
  2. 6.3 admin_menu.module \admin_menu_js_cache()

Menu callback; Output administration menu for HTTP caching via AJAX request.

2 string references to 'admin_menu_js_cache'
admin_menu_js in ./admin_menu.module
Implementation of hook_js().
admin_menu_menu in ./admin_menu.module
Implementation of hook_menu().

File

./admin_menu.module, line 231
Render an administrative menu as a dropdown menu at the top of the window.

Code

function admin_menu_js_cache($hash = NULL) {

  // Get the rendered menu.
  $content = admin_menu_output();

  // @todo According to http://www.mnot.net/blog/2006/05/11/browser_caching,
  //   IE will only cache the content when it is compressed.
  // Determine if the client accepts gzipped data.
  if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
    if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== FALSE) {
      $encoding = 'x-gzip';
    }
    elseif (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) {
      $encoding = 'gzip';
    }

    // Perform gzip compression when:
    // 1) the user agent supports gzip compression.
    // 2) Drupal page compression is enabled. Sites may wish to perform the
    //    compression at the web server level (e.g. using mod_deflate).
    // 3) PHP's zlib extension is loaded, but zlib compression is disabled.
    if (isset($encoding) && variable_get('page_compression', TRUE) && extension_loaded('zlib') && zlib_get_coding_type() === FALSE) {

      // Use Vary header to tell caches to keep separate versions of the menu
      // based on user agent capabilities.
      header('Vary: Accept-Encoding');

      // Since we manually perform compression, we are also responsible to
      // send a proper encoding header.
      header('Content-Encoding: ' . $encoding);
      $content = gzencode($content, 9, FORCE_GZIP);
    }
  }
  $expires = time() + 3600 * 24 * 365;
  header('Expires: ' . gmdate('D, d M Y H:i:s', $expires) . ' GMT');
  header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  header('Cache-Control: max-age=' . $expires);
  header('Content-Length: ' . strlen($content));

  // Suppress Devel module.
  $GLOBALS['devel_shutdown'] = FALSE;
  echo $content;
  exit;
}