From 0c794e2fb45d2d3c3fb3a42dac7f4d126cc39cbc Mon Sep 17 00:00:00 2001 From: secretr Date: Fri, 14 Jan 2011 12:19:03 +0000 Subject: [PATCH] cross-browser cache issues --- e107_files/e_jslib.php | 18 ++-- e107_handlers/jslib_handler.php | 116 +++-------------------- e107_handlers/session_handler.php | 6 +- e107_themes/templates/footer_default.php | 2 +- 4 files changed, 25 insertions(+), 117 deletions(-) diff --git a/e107_files/e_jslib.php b/e107_files/e_jslib.php index 6a89ebefa..951256847 100644 --- a/e107_files/e_jslib.php +++ b/e107_files/e_jslib.php @@ -18,8 +18,6 @@ // prevent notices/warnings to break JS source error_reporting(0); -session_cache_limiter('private'); - //admin or front-end call if (strpos($_SERVER['QUERY_STRING'], '_admin') !== FALSE) { @@ -40,7 +38,6 @@ else } if(!e_NOCACHE) session_cache_limiter('private'); -else session_cache_limiter('nocache'); //output cache if available before calling the api e_jslib_cache_out(); @@ -69,7 +66,6 @@ exit; */ function e_jslib_cache_out() { - if(e_NOCACHE) return; $encoding = e_jslib_browser_enc(); //NOTE - should be called first $cacheFile = e_jslib_is_cache($encoding); @@ -78,6 +74,7 @@ function e_jslib_cache_out() //kill any output buffering - better performance and 304 not modified requirement while (@ob_end_clean()); + /* IT CAUSES GREAT TROUBLES ON SOME BROWSERS! if (function_exists('date_default_timezone_set')) { date_default_timezone_set('UTC'); @@ -89,8 +86,7 @@ function e_jslib_cache_out() // send last modified date //header('Cache-Control: must-revalidate'); //header('Last-modified: '.gmdate('r', $lmodified), true); - if($lmodified) header('Last-modified: '.gmdate("D, d M Y H:i:s", $lmodified).' GMT', true); - + if($lmodified) header('Last-modified: '.gmdate("D, d M Y H:i:s", $lmodified).' GMT', true);*/ // send content type and encoding header('Content-type: text/javascript', true); @@ -99,7 +95,9 @@ function e_jslib_cache_out() header('Content-Encoding: '.$encoding, true); } - // Expire header - 1 year + if (!e_NOCACHE) header("Cache-Control: must-revalidate", true); + + /*// Expire header - 1 year $time = time()+ 365 * 86400; //header('Expires: '.gmdate('r', $time), true); header('Expires: '.gmdate("D, d M Y H:i:s", $time).' GMT', true); @@ -111,8 +109,8 @@ function e_jslib_cache_out() { header("HTTP/1.1 304 Not Modified", true); exit; - } - + }*/ + $page = @file_get_contents($cacheFile); $etag = md5($page).($encoding ? '-'.$encoding : ''); @@ -120,7 +118,7 @@ function e_jslib_cache_out() header('ETag: '.$etag, true); // not modified check by Etag - if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) + if (!e_NOCACHE && isset($_SERVER['HTTP_IF_NONE_MATCH'])) { $IF_NONE_MATCH = str_replace('"','',$_SERVER['HTTP_IF_NONE_MATCH']); diff --git a/e107_handlers/jslib_handler.php b/e107_handlers/jslib_handler.php index c1db9029b..2f60ca493 100644 --- a/e107_handlers/jslib_handler.php +++ b/e107_handlers/jslib_handler.php @@ -35,7 +35,7 @@ class e_jslib { $hash = md5(serialize(varset($pref['e_jslib'])).e107::getPref('e_jslib_browser_cache', 0).THEME.e_LANGUAGE.ADMIN).'_'.$where; // TODO disable cache in debug mod - $hash .= (e107::getPref('e_jslib_nocache') ? '_nocache' : '').(e107::getPref('e_jslib_gzip') ? '' : '_nogzip'); + $hash .= (e107::getPref('e_jslib_nocache') || deftrue('e_NOCACHE') ? '_nocache' : '').(e107::getPref('e_jslib_gzip') ? '' : '_nogzip'); $ret = "\n"; if($return) $ret; echo $ret; @@ -90,12 +90,10 @@ class e_jslib // send content type header('Content-type: text/javascript', true); + $this->content_out($lmodified); - if(deftrue('e_NOCACHE')) - { - $this->content_out($lmodified); - } - + // IT CAUSES GREAT TROUBLES ON SOME BROWSERS! + /* if (function_exists('date_default_timezone_set')) { date_default_timezone_set('UTC'); @@ -103,7 +101,7 @@ class e_jslib // send last modified date - header('Cache-Control: must-revalidate', true); + if(deftrue('e_NOCACHE')) header('Cache-Control: must-revalidate', true); if($lmodified) header('Last-modified: '.gmdate("D, d M Y H:i:s", $lmodified).' GMT', true); //if($lmodified) header('Last-modified: '.gmdate('r', $lmodified), true); @@ -124,101 +122,7 @@ class e_jslib } //Output - $this->content_out($lmodified); - /* - //array - uses the same format as $core_jslib - if (!isset($THEME_CORE_JSLIB) || ! is_array($THEME_CORE_JSLIB)) - $THEME_CORE_JSLIB = array(); - - //array - uses the same format as $core_jslib - if (!isset($THEME_JSLIB) || ! is_array($THEME_JSLIB)) - $THEME_JSLIB = array(); - - //available values - admin,front,all,none - $core_jslib = array( //FIXME - core jslib prefs, debug options - 'jslib/prototype/prototype.js' => 'all' , - 'jslib/scriptaculous/scriptaculous.js' => 'all', - 'jslib/scriptaculous/effects.js' => 'all', - 'jslib/e107.js.php' => 'all' - //'jslib/core/decorate.js' => 'all' - ); - - $core_jslib = array_merge($core_jslib, $THEME_CORE_JSLIB, varsettrue($pref['e_jslib_core'], array())); - $where_now = $eplug_admin ? 'admin' : 'front'; - - //1. Core libs - prototype + scriptaculous effects - echo "// Prototype/Scriptaculous/Core libraries \n"; - foreach ($core_jslib as $core_path => $where) - { - if ($where != 'all' && $where != $where_now) - continue; - - if (substr($core_path, - 4) == '.php') - { - include_once (e_FILE . '/' . trim($core_path, '/')); - echo "\n\n"; - } - else - { - echo file_get_contents(e_FILE . '/' . trim($core_path, '/')); - echo "\n\n"; - } - } - - //2. Plugins output - all 3-rd party libs - if (varsettrue($pref['e_jslib_plugin'])) - { - foreach ($pref['e_jslib_plugin'] as $plugin_name => $plugin_libs) - { - if ($plugin_libs) - { - foreach ($plugin_libs as $plugin_lib => $where) - { - //available values - admin,front,all - if ($where != 'all' && $where != $where_now) - continue; - - $lib_path = $plugin_name . '/' . trim($plugin_lib, '/'); - - echo "// $plugin_name libraries \n\n"; - - if (substr($plugin_lib, - 4) == '.php') - { - include_once (e_PLUGIN . $lib_path); - echo "\n\n"; - } - else - { - echo file_get_contents(e_PLUGIN . $lib_path); - echo "\n\n"; - } - } - } - } - } - - //3. Theme libs - if (varset($THEME_JSLIB) && is_array($THEME_JSLIB)) - { - echo "// Theme libraries \n\n"; - foreach ($THEME_JSLIB as $lib_path => $where) - { - if ($where != 'all' && $where != $where_now) - continue; - - if (substr($lib_path, - 4) == '.php') - { - include_once (THEME . '/' . trim($lib_path, '/')); - echo "\n\n"; - } - else - { - echo file_get_contents(THEME . '/' . trim($lib_path, '/')); - echo "\n\n"; - } - } - } -*/ + $this->content_out($lmodified);*/ } /** @@ -227,13 +131,15 @@ class e_jslib */ function content_out($lmodified) { - global $pref, $admin_log; - + global $admin_log; + $pref = e107::getPref(); $encoding = $this->browser_enc(); $contents = ob_get_contents(); ob_end_clean(); + if(!deftrue('e_NOCACHE')) header('Cache-Control: must-revalidate', true); + $etag = md5($page).($encoding ? '-'.$encoding : ''); header('ETag: '.$etag, true); if($encoding) header('Content-Encoding: ' . $encoding); @@ -290,7 +196,7 @@ class e_jslib */ function set_cache($contents, $encoding = '', $lmodified = 0) { - if (!deftrue('e_NOCACHE') && e107::getPref('syscachestatus')) + if (e107::getPref('syscachestatus')) { $cacheFile = $this->cache_filename($encoding); if(!$lmodified) $lmodified = time(); diff --git a/e107_handlers/session_handler.php b/e107_handlers/session_handler.php index 4b686d44f..e16fdc668 100644 --- a/e107_handlers/session_handler.php +++ b/e107_handlers/session_handler.php @@ -441,7 +441,11 @@ class e_session { session_cache_limiter((string) $this->_sessionCacheLimiter); } - + elseif(!defined('e_NOCACHE') || !e_NOCACHE) + { + session_cache_limiter('private'); + } + session_start(); return $this; diff --git a/e107_themes/templates/footer_default.php b/e107_themes/templates/footer_default.php index 5d3531bd8..5c059085f 100644 --- a/e107_themes/templates/footer_default.php +++ b/e107_themes/templates/footer_default.php @@ -301,7 +301,7 @@ $etag = md5($page); //header('Pragma:'); // previously disabled or there is posted data -if(!deftrue('e_NOCACHE') && empty($_POST)) +if(!deftrue('e_NOCACHE') && $_SERVER['REQUEST_METHOD'] === 'GET') { header("Cache-Control: must-revalidate", true); if (function_exists('date_default_timezone_set'))