mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 03:40:37 +02:00
cross-browser cache issues
This commit is contained in:
@@ -18,8 +18,6 @@
|
|||||||
// prevent notices/warnings to break JS source
|
// prevent notices/warnings to break JS source
|
||||||
error_reporting(0);
|
error_reporting(0);
|
||||||
|
|
||||||
session_cache_limiter('private');
|
|
||||||
|
|
||||||
//admin or front-end call
|
//admin or front-end call
|
||||||
if (strpos($_SERVER['QUERY_STRING'], '_admin') !== FALSE)
|
if (strpos($_SERVER['QUERY_STRING'], '_admin') !== FALSE)
|
||||||
{
|
{
|
||||||
@@ -40,7 +38,6 @@ else
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!e_NOCACHE) session_cache_limiter('private');
|
if(!e_NOCACHE) session_cache_limiter('private');
|
||||||
else session_cache_limiter('nocache');
|
|
||||||
|
|
||||||
//output cache if available before calling the api
|
//output cache if available before calling the api
|
||||||
e_jslib_cache_out();
|
e_jslib_cache_out();
|
||||||
@@ -69,7 +66,6 @@ exit;
|
|||||||
*/
|
*/
|
||||||
function e_jslib_cache_out()
|
function e_jslib_cache_out()
|
||||||
{
|
{
|
||||||
if(e_NOCACHE) return;
|
|
||||||
$encoding = e_jslib_browser_enc(); //NOTE - should be called first
|
$encoding = e_jslib_browser_enc(); //NOTE - should be called first
|
||||||
$cacheFile = e_jslib_is_cache($encoding);
|
$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
|
//kill any output buffering - better performance and 304 not modified requirement
|
||||||
while (@ob_end_clean());
|
while (@ob_end_clean());
|
||||||
|
|
||||||
|
/* IT CAUSES GREAT TROUBLES ON SOME BROWSERS!
|
||||||
if (function_exists('date_default_timezone_set'))
|
if (function_exists('date_default_timezone_set'))
|
||||||
{
|
{
|
||||||
date_default_timezone_set('UTC');
|
date_default_timezone_set('UTC');
|
||||||
@@ -89,8 +86,7 @@ function e_jslib_cache_out()
|
|||||||
// send last modified date
|
// send last modified date
|
||||||
//header('Cache-Control: must-revalidate');
|
//header('Cache-Control: must-revalidate');
|
||||||
//header('Last-modified: '.gmdate('r', $lmodified), true);
|
//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
|
// send content type and encoding
|
||||||
header('Content-type: text/javascript', true);
|
header('Content-type: text/javascript', true);
|
||||||
@@ -99,7 +95,9 @@ function e_jslib_cache_out()
|
|||||||
header('Content-Encoding: '.$encoding, true);
|
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;
|
$time = time()+ 365 * 86400;
|
||||||
//header('Expires: '.gmdate('r', $time), true);
|
//header('Expires: '.gmdate('r', $time), true);
|
||||||
header('Expires: '.gmdate("D, d M Y H:i:s", $time).' GMT', 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);
|
header("HTTP/1.1 304 Not Modified", true);
|
||||||
exit;
|
exit;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
$page = @file_get_contents($cacheFile);
|
$page = @file_get_contents($cacheFile);
|
||||||
$etag = md5($page).($encoding ? '-'.$encoding : '');
|
$etag = md5($page).($encoding ? '-'.$encoding : '');
|
||||||
|
|
||||||
@@ -120,7 +118,7 @@ function e_jslib_cache_out()
|
|||||||
header('ETag: '.$etag, true);
|
header('ETag: '.$etag, true);
|
||||||
|
|
||||||
// not modified check by Etag
|
// 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']);
|
$IF_NONE_MATCH = str_replace('"','',$_SERVER['HTTP_IF_NONE_MATCH']);
|
||||||
|
|
||||||
|
@@ -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;
|
$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
|
// 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 = "<script type='text/javascript' src='".e_FILE_ABS."e_jslib.php?{$hash}'></script>\n";
|
$ret = "<script type='text/javascript' src='".e_FILE_ABS."e_jslib.php?{$hash}'></script>\n";
|
||||||
if($return) $ret;
|
if($return) $ret;
|
||||||
echo $ret;
|
echo $ret;
|
||||||
@@ -90,12 +90,10 @@ class e_jslib
|
|||||||
|
|
||||||
// send content type
|
// send content type
|
||||||
header('Content-type: text/javascript', true);
|
header('Content-type: text/javascript', true);
|
||||||
|
$this->content_out($lmodified);
|
||||||
|
|
||||||
if(deftrue('e_NOCACHE'))
|
// IT CAUSES GREAT TROUBLES ON SOME BROWSERS!
|
||||||
{
|
/*
|
||||||
$this->content_out($lmodified);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (function_exists('date_default_timezone_set'))
|
if (function_exists('date_default_timezone_set'))
|
||||||
{
|
{
|
||||||
date_default_timezone_set('UTC');
|
date_default_timezone_set('UTC');
|
||||||
@@ -103,7 +101,7 @@ class e_jslib
|
|||||||
|
|
||||||
|
|
||||||
// send last modified date
|
// 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("D, d M Y H:i:s", $lmodified).' GMT', true);
|
||||||
//if($lmodified) header('Last-modified: '.gmdate('r', $lmodified), true);
|
//if($lmodified) header('Last-modified: '.gmdate('r', $lmodified), true);
|
||||||
|
|
||||||
@@ -124,101 +122,7 @@ class e_jslib
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Output
|
//Output
|
||||||
$this->content_out($lmodified);
|
$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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -227,13 +131,15 @@ class e_jslib
|
|||||||
*/
|
*/
|
||||||
function content_out($lmodified)
|
function content_out($lmodified)
|
||||||
{
|
{
|
||||||
global $pref, $admin_log;
|
global $admin_log;
|
||||||
|
$pref = e107::getPref();
|
||||||
$encoding = $this->browser_enc();
|
$encoding = $this->browser_enc();
|
||||||
|
|
||||||
$contents = ob_get_contents();
|
$contents = ob_get_contents();
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
|
|
||||||
|
if(!deftrue('e_NOCACHE')) header('Cache-Control: must-revalidate', true);
|
||||||
|
|
||||||
$etag = md5($page).($encoding ? '-'.$encoding : '');
|
$etag = md5($page).($encoding ? '-'.$encoding : '');
|
||||||
header('ETag: '.$etag, true);
|
header('ETag: '.$etag, true);
|
||||||
if($encoding) header('Content-Encoding: ' . $encoding);
|
if($encoding) header('Content-Encoding: ' . $encoding);
|
||||||
@@ -290,7 +196,7 @@ class e_jslib
|
|||||||
*/
|
*/
|
||||||
function set_cache($contents, $encoding = '', $lmodified = 0)
|
function set_cache($contents, $encoding = '', $lmodified = 0)
|
||||||
{
|
{
|
||||||
if (!deftrue('e_NOCACHE') && e107::getPref('syscachestatus'))
|
if (e107::getPref('syscachestatus'))
|
||||||
{
|
{
|
||||||
$cacheFile = $this->cache_filename($encoding);
|
$cacheFile = $this->cache_filename($encoding);
|
||||||
if(!$lmodified) $lmodified = time();
|
if(!$lmodified) $lmodified = time();
|
||||||
|
@@ -441,7 +441,11 @@ class e_session
|
|||||||
{
|
{
|
||||||
session_cache_limiter((string) $this->_sessionCacheLimiter);
|
session_cache_limiter((string) $this->_sessionCacheLimiter);
|
||||||
}
|
}
|
||||||
|
elseif(!defined('e_NOCACHE') || !e_NOCACHE)
|
||||||
|
{
|
||||||
|
session_cache_limiter('private');
|
||||||
|
}
|
||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@@ -301,7 +301,7 @@ $etag = md5($page);
|
|||||||
|
|
||||||
//header('Pragma:');
|
//header('Pragma:');
|
||||||
// previously disabled or there is posted data
|
// 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);
|
header("Cache-Control: must-revalidate", true);
|
||||||
if (function_exists('date_default_timezone_set'))
|
if (function_exists('date_default_timezone_set'))
|
||||||
|
Reference in New Issue
Block a user