mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
javascript MDL-23430 YUI moodle modules are no longer cached if CFG->cachejs is off
This commit is contained in:
parent
deaf04c7b7
commit
77387297f8
@ -145,6 +145,14 @@ class page_requirements_manager {
|
||||
$this->yui3loader->combine = !empty($CFG->yuicomboloading);
|
||||
$this->yui2loader->combine = !empty($CFG->yuicomboloading);
|
||||
|
||||
if (empty($CFG->cachejs)) {
|
||||
$jsrev = -1;
|
||||
} else if (empty($CFG->jsrev)) {
|
||||
$jsrev = 1;
|
||||
} else {
|
||||
$jsrev = $CFG->jsrev;
|
||||
}
|
||||
|
||||
// set up JS YUI loader helper object
|
||||
$this->M_yui_loader = new stdClass();
|
||||
$this->M_yui_loader->base = $this->yui3loader->base;
|
||||
@ -156,12 +164,12 @@ class page_requirements_manager {
|
||||
$this->M_yui_loader->groups = array(
|
||||
'moodle' => array(
|
||||
'name' => 'moodle',
|
||||
'base' => $CFG->httpswwwroot . '/theme/yui_combo.php?moodle/',
|
||||
'base' => $CFG->httpswwwroot . '/theme/yui_combo.php?moodle/'.$jsrev.'/',
|
||||
'comboBase' => $CFG->httpswwwroot . '/theme/yui_combo.php?',
|
||||
'combine' => $this->yui3loader->combine,
|
||||
'filter' => '',
|
||||
'ext' => false,
|
||||
'root' => 'moodle/',
|
||||
'root' => 'moodle/'.$jsrev.'/', // Add the rev to the root path so that we can control caching
|
||||
'patterns' => array(
|
||||
'moodle-' => array(
|
||||
'group' => 'moodle',
|
||||
|
@ -46,6 +46,7 @@ if (substr($parts, -3) === '.js') {
|
||||
}
|
||||
|
||||
$parts = explode('&', $parts);
|
||||
$cache = true;
|
||||
|
||||
foreach ($parts as $part) {
|
||||
if (empty($part)) {
|
||||
@ -63,6 +64,11 @@ foreach ($parts as $part) {
|
||||
//TODO: this is a ugly hack because we should not load any libs here!
|
||||
define('MOODLE_INTERNAL', true);
|
||||
require_once($CFG->libdir.'/moodlelib.php');
|
||||
$revision = (int)array_shift($bits);
|
||||
if ($revision === -1) {
|
||||
// Revision -1 says please don't cache the JS
|
||||
$cache = false;
|
||||
}
|
||||
$frankenstyle = array_shift($bits);
|
||||
$filename = array_pop($bits);
|
||||
$dir = get_component_directory($frankenstyle);
|
||||
@ -100,11 +106,18 @@ foreach ($parts as $part) {
|
||||
$content .= $filecontent;
|
||||
}
|
||||
|
||||
|
||||
combo_send_cached($content, $mimetype);
|
||||
|
||||
if ($cache) {
|
||||
combo_send_cached($content, $mimetype);
|
||||
} else {
|
||||
combo_send_uncached($content, $mimetype);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send the JavaScript cached
|
||||
* @param string $content
|
||||
* @param string $mimetype
|
||||
*/
|
||||
function combo_send_cached($content, $mimetype) {
|
||||
$lifetime = 60*60*24*300; // 300 days === forever
|
||||
|
||||
@ -123,6 +136,26 @@ function combo_send_cached($content, $mimetype) {
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the JavaScript uncached
|
||||
* @param string $content
|
||||
* @param string $mimetype
|
||||
*/
|
||||
function combo_send_uncached($content, $mimetype) {
|
||||
header('Content-Disposition: inline; filename="combo"');
|
||||
header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
|
||||
header('Expires: '. gmdate('D, d M Y H:i:s', time() + 2) .' GMT');
|
||||
header('Pragma: ');
|
||||
header('Accept-Ranges: none');
|
||||
header('Content-Type: '.$mimetype);
|
||||
if (!min_enable_zlib_compression()) {
|
||||
header('Content-Length: '.strlen($content));
|
||||
}
|
||||
|
||||
echo $content;
|
||||
die;
|
||||
}
|
||||
|
||||
function combo_not_found() {
|
||||
header('HTTP/1.0 404 not found');
|
||||
die('Combo resource not found, sorry.');
|
||||
|
Loading…
x
Reference in New Issue
Block a user