diff --git a/theme/image.php b/theme/image.php index 9659b91ed01..58b564bafe4 100644 --- a/theme/image.php +++ b/theme/image.php @@ -68,6 +68,7 @@ if (file_exists("$CFG->dirroot/theme/$themename/config.php")) { } $candidatelocation = "$CFG->cachedir/theme/$themename/pix/$component"; +$etag = sha1("$themename/$component/$rev/$image"); if ($rev > -1) { if (file_exists("$candidatelocation/$image.error")) { @@ -96,15 +97,16 @@ if ($rev > -1) { if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) || !empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { // we do not actually need to verify the etag value because our files // never change in cache because we increment the rev parameter - $lifetime = 60*60*24*30; // 30 days + $lifetime = 60*60*24*60; // 60 days only - the revision may get incremented quite often $mimetype = get_contenttype_from_ext($ext); header('HTTP/1.1 304 Not Modified'); header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT'); header('Cache-Control: public, max-age='.$lifetime); header('Content-Type: '.$mimetype); + header('Etag: '.$etag); die; } - send_cached_image($cacheimage, $rev); + send_cached_image($cacheimage, $etag); } } @@ -121,6 +123,7 @@ $theme = theme_config::load($themename); $imagefile = $theme->resolve_image_location($image, $component); $rev = theme_get_revision(); +$etag = sha1("$themename/$component/$rev/$image"); if (empty($imagefile) or !is_readable($imagefile)) { if ($rev > -1) { @@ -144,7 +147,7 @@ if ($rev > -1) { } copy($imagefile, $cacheimage); } - send_cached_image($cacheimage, $rev); + send_cached_image($cacheimage, $etag); } else { send_uncached_image($imagefile); @@ -156,19 +159,19 @@ if ($rev > -1) { // we are not using filelib because we need to fine tune all header // parameters to get the best performance. -function send_cached_image($imagepath, $rev) { +function send_cached_image($imagepath, $etag) { global $CFG; require("$CFG->dirroot/lib/xsendfilelib.php"); - $lifetime = 60*60*24*30; // 30 days + $lifetime = 60*60*24*60; // 60 days only - the revision may get incremented quite often $pathinfo = pathinfo($imagepath); $imagename = $pathinfo['filename'].'.'.$pathinfo['extension']; $mimetype = get_contenttype_from_ext($pathinfo['extension']); - header('Etag: '.md5("$rev/$imagepath")); + header('Etag: '.$etag); header('Content-Disposition: inline; filename="'.$imagename.'"'); - header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT'); + header('Last-Modified: '. gmdate('D, d M Y H:i:s', filemtime($imagepath)) .' GMT'); header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT'); header('Pragma: '); header('Cache-Control: public, max-age='.$lifetime);