diff options
Diffstat (limited to 'includes/common.inc')
-rw-r--r-- | includes/common.inc | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/includes/common.inc b/includes/common.inc index ae42390a4..151135eb9 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -131,20 +131,6 @@ function drupal_clear_path_cache() { } /** - * Given a path alias, return the internal path it represents. - */ -function drupal_get_normal_path($path) { - $result = $path; - if ($src = drupal_lookup_path('source', $path)) { - $result = $src; - } - if (function_exists('custom_url_rewrite')) { - $result = custom_url_rewrite('source', $result, $path); - } - return $result; -} - -/** * Set an HTTP response header for the current page. */ function drupal_set_header($header = NULL) { @@ -1286,13 +1272,6 @@ function _drupal_bootstrap_full() { drupal_set_header('Content-Type: text/html; charset=utf-8'); // Detect string handling method unicode_check(); - // Initialize $_GET['q'] prior to loading modules and invoking hook_init(). - if (!empty($_GET['q'])) { - $_GET['q'] = drupal_get_normal_path(trim($_GET['q'], '/')); - } - else { - $_GET['q'] = drupal_get_normal_path(variable_get('site_frontpage', 'node')); - } // Initialize all enabled modules. module_init(); // Undo magic quotes @@ -1300,3 +1279,43 @@ function _drupal_bootstrap_full() { // Initialize the localization system. $locale = locale_initialize(); } + +/** + * Store the current page in the cache. + * + * We try to store a gzipped version of the cache. This requires the + * PHP zlib extension (http://php.net/manual/en/ref.zlib.php). + * Presence of the extension is checked by testing for the function + * gzencode. There are two compression algorithms: gzip and deflate. + * The majority of all modern browsers support gzip or both of them. + * We thus only deal with the gzip variant and unzip the cache in case + * the browser does not accept gzip encoding. + * + * @see drupal_page_header + */ +function page_set_cache() { + global $user, $base_url; + + if (!$user->uid && $_SERVER['REQUEST_METHOD'] == 'GET') { + // This will fail in some cases, see page_get_cache() for the explanation. + if ($data = ob_get_contents()) { + $cache = TRUE; + if (function_exists('gzencode')) { + // We do not store the data in case the zlib mode is deflate. + // This should be rarely happening. + if (zlib_get_coding_type() == 'deflate') { + $cache = FALSE; + } + else if (zlib_get_coding_type() == FALSE) { + $data = gzencode($data, 9, FORCE_GZIP); + } + // The remaining case is 'gzip' which means the data is + // already compressed and nothing left to do but to store it. + } + ob_end_flush(); + if ($cache && $data) { + cache_set($base_url . request_uri(), $data, CACHE_TEMPORARY, drupal_get_headers()); + } + } + } +} |