mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
Merge branch 'w29_MDL-40563_m26_themecaching' of https://github.com/skodak/moodle
This commit is contained in:
commit
5b0804c4b1
@ -59,7 +59,7 @@ if ($slashargument = min_get_slash_argument()) {
|
||||
}
|
||||
|
||||
if (empty($component) or $component === 'moodle' or $component === 'core') {
|
||||
$component = 'moodle';
|
||||
$component = 'core';
|
||||
}
|
||||
|
||||
if (empty($image)) {
|
||||
@ -74,12 +74,12 @@ if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
|
||||
image_not_found();
|
||||
}
|
||||
|
||||
$candidatelocation = "$CFG->cachedir/theme/$themename/pix/$component";
|
||||
$etag = sha1("$themename/$component/$rev/$image");
|
||||
$candidatelocation = "$CFG->cachedir/theme/$rev/$themename/pix/$component";
|
||||
$etag = sha1("$rev/$themename/$component/$image");
|
||||
|
||||
if ($rev > -1) {
|
||||
if ($rev > 0) {
|
||||
if (file_exists("$candidatelocation/$image.error")) {
|
||||
// this is a major speedup if there are multiple missing images,
|
||||
// This is a major speedup if there are multiple missing images,
|
||||
// the only problem is that random requests may pollute our cache.
|
||||
image_not_found();
|
||||
}
|
||||
@ -130,26 +130,37 @@ define('NO_UPGRADE_CHECK', true); // Ignore upgrade check
|
||||
require("$CFG->dirroot/lib/setup.php");
|
||||
|
||||
$theme = theme_config::load($themename);
|
||||
$rev = theme_get_revision();
|
||||
$etag = sha1("$themename/$component/$rev/$image");
|
||||
$themerev = theme_get_revision();
|
||||
|
||||
if ($themerev <= 0 or $rev != $themerev) {
|
||||
// Do not send caching headers if they do not request current revision,
|
||||
// we do not want to pollute browser caches with outdated images.
|
||||
$imagefile = $theme->resolve_image_location($image, $component, $usesvg);
|
||||
if (empty($imagefile) or !is_readable($imagefile)) {
|
||||
image_not_found();
|
||||
}
|
||||
send_uncached_image($imagefile);
|
||||
}
|
||||
|
||||
make_cache_directory('theme', false);
|
||||
|
||||
// We're not using SVG and there is no cached version of this file (in any format).
|
||||
// As we're going to be caching a format other than svg, and because svg use is conditional we need to ensure that at the same
|
||||
// time we cache a version of the SVG if it exists. If we don't do this other users who ask for SVG would not ever get it as
|
||||
// there is a cached image already of another format.
|
||||
// Remember this only gets run once before any candidate exists, and only if we want a cached revision.
|
||||
if (!$usesvg && $rev > -1) {
|
||||
if (!$usesvg) {
|
||||
$imagefile = $theme->resolve_image_location($image, $component, true);
|
||||
if (!empty($imagefile) && is_readable($imagefile)) {
|
||||
$cacheimage = cache_image($image, $imagefile, $candidatelocation);
|
||||
$pathinfo = pathinfo($imagefile);
|
||||
// There is no SVG equivilant, we've just successfully cached an image of another format.
|
||||
// There is no SVG equivalent, we've just successfully cached an image of another format.
|
||||
if ($pathinfo['extension'] !== 'svg') {
|
||||
// Serve the file as we would in a normal request.
|
||||
if (connection_aborted()) {
|
||||
die;
|
||||
}
|
||||
// make sure nothing failed
|
||||
// Make sure nothing failed.
|
||||
clearstatcache();
|
||||
if (file_exists($cacheimage)) {
|
||||
send_cached_image($cacheimage, $etag);
|
||||
@ -163,28 +174,24 @@ if (!$usesvg && $rev > -1) {
|
||||
// Either SVG was requested or we've cached a SVG version and are ready to serve a regular format.
|
||||
$imagefile = $theme->resolve_image_location($image, $component, $usesvg);
|
||||
if (empty($imagefile) or !is_readable($imagefile)) {
|
||||
if ($rev > -1) {
|
||||
if (!file_exists($candidatelocation)) {
|
||||
@mkdir($candidatelocation, $CFG->directorypermissions, true);
|
||||
}
|
||||
// make note we can not find this file
|
||||
$cacheimage = "$candidatelocation/$image.error";
|
||||
$fp = fopen($cacheimage, 'w');
|
||||
fclose($fp);
|
||||
if (!file_exists($candidatelocation)) {
|
||||
@mkdir($candidatelocation, $CFG->directorypermissions, true);
|
||||
}
|
||||
// Make note we can not find this file.
|
||||
$cacheimage = "$candidatelocation/$image.error";
|
||||
$fp = fopen($cacheimage, 'w');
|
||||
fclose($fp);
|
||||
image_not_found();
|
||||
}
|
||||
|
||||
if ($rev > -1) {
|
||||
$cacheimage = cache_image($image, $imagefile, $candidatelocation);
|
||||
if (connection_aborted()) {
|
||||
die;
|
||||
}
|
||||
// make sure nothing failed
|
||||
clearstatcache();
|
||||
if (file_exists($cacheimage)) {
|
||||
send_cached_image($cacheimage, $etag);
|
||||
}
|
||||
$cacheimage = cache_image($image, $imagefile, $candidatelocation);
|
||||
if (connection_aborted()) {
|
||||
die;
|
||||
}
|
||||
// Make sure nothing failed.
|
||||
clearstatcache();
|
||||
if (file_exists($cacheimage)) {
|
||||
send_cached_image($cacheimage, $etag);
|
||||
}
|
||||
|
||||
send_uncached_image($imagefile);
|
||||
|
@ -45,7 +45,7 @@ if ($slashargument = min_get_slash_argument()) {
|
||||
|
||||
} else {
|
||||
$themename = min_optional_param('theme', 'standard', 'SAFEDIR');
|
||||
$rev = min_optional_param('rev', 0, 'INT');
|
||||
$rev = min_optional_param('rev', -1, 'INT');
|
||||
$type = min_optional_param('type', 'head', 'RAW');
|
||||
}
|
||||
|
||||
@ -63,10 +63,10 @@ if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
|
||||
die('Theme was not found, sorry.');
|
||||
}
|
||||
|
||||
$candidate = "$CFG->cachedir/theme/$themename/javascript_$type.js";
|
||||
$etag = sha1("$themename/$rev/$type");
|
||||
$candidate = "$CFG->cachedir/theme/$rev/$themename/javascript_$type.js";
|
||||
$etag = sha1("$rev/$themename/$type");
|
||||
|
||||
if ($rev > -1 and file_exists($candidate)) {
|
||||
if ($rev > 0 and file_exists($candidate)) {
|
||||
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
|
||||
@ -85,17 +85,21 @@ define('NO_UPGRADE_CHECK', true); // Ignore upgrade check
|
||||
require("$CFG->dirroot/lib/setup.php");
|
||||
|
||||
$theme = theme_config::load($themename);
|
||||
$themerev = theme_get_revision();
|
||||
|
||||
$rev = theme_get_revision();
|
||||
$etag = sha1("$themename/$rev/$type");
|
||||
if ($themerev <= 0 or $rev != $themerev) {
|
||||
// Do not send caching headers if they do not request current revision,
|
||||
// we do not want to pollute browser caches with outdated JS.
|
||||
js_send_uncached($theme->javascript_content($type));
|
||||
}
|
||||
|
||||
if ($rev > -1) {
|
||||
js_write_cache_file_content($candidate, js_minify($theme->javascript_files($type)));
|
||||
// verify nothing failed in cache file creation
|
||||
clearstatcache();
|
||||
if (file_exists($candidate)) {
|
||||
js_send_cached($candidate, $etag);
|
||||
}
|
||||
make_cache_directory('theme', false);
|
||||
|
||||
js_write_cache_file_content($candidate, js_minify($theme->javascript_files($type)));
|
||||
// Verify nothing failed in cache file creation.
|
||||
clearstatcache();
|
||||
if (file_exists($candidate)) {
|
||||
js_send_cached($candidate, $etag);
|
||||
}
|
||||
|
||||
js_send_uncached($theme->javascript_content($type));
|
||||
|
@ -62,11 +62,7 @@ if ($component === 'core') {
|
||||
}
|
||||
|
||||
} else {
|
||||
define('ABORT_AFTER_CONFIG_CANCEL', true);
|
||||
define('NO_MOODLE_COOKIES', true); // Session not used here.
|
||||
define('NO_UPGRADE_CHECK', true); // Ignore upgrade check.
|
||||
require("$CFG->dirroot/lib/setup.php");
|
||||
$componentdir = get_component_directory($component);
|
||||
$componentdir = core_component::get_component_directory($component);
|
||||
}
|
||||
|
||||
if (!file_exists($componentdir) or !file_exists("$componentdir/jquery/plugins.php")) {
|
||||
|
@ -32,6 +32,10 @@ define('ABORT_AFTER_CONFIG', true);
|
||||
require('../config.php'); // this stops immediately at the beginning of lib/setup.php
|
||||
require_once($CFG->dirroot.'/lib/csslib.php');
|
||||
|
||||
if (!defined('THEME_DESIGNER_CACHE_LIFETIME')) {
|
||||
define('THEME_DESIGNER_CACHE_LIFETIME', 4); // this can be also set in config.php
|
||||
}
|
||||
|
||||
if ($slashargument = min_get_slash_argument()) {
|
||||
$slashargument = ltrim($slashargument, '/');
|
||||
if (substr_count($slashargument, '/') < 2) {
|
||||
@ -71,8 +75,7 @@ if ($type === 'editor') {
|
||||
} else if ($type === 'all') {
|
||||
// We're fine.
|
||||
} else {
|
||||
header('HTTP/1.0 404 not found');
|
||||
die('Theme was not found, sorry.');
|
||||
css_send_css_not_found();
|
||||
}
|
||||
|
||||
if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
|
||||
@ -84,8 +87,8 @@ if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
|
||||
die('Theme was not found, sorry.');
|
||||
}
|
||||
|
||||
$candidatedir = "$CFG->cachedir/theme/$themename/css";
|
||||
$etag = "$themename/$rev/$type";
|
||||
$candidatedir = "$CFG->cachedir/theme/$rev/$themename/css";
|
||||
$etag = "$rev/$themename/$type";
|
||||
$candidatename = $type;
|
||||
if (!$usesvg) {
|
||||
// Add to the sheet name, one day we'll be able to just drop this.
|
||||
@ -121,26 +124,39 @@ require("$CFG->dirroot/lib/setup.php");
|
||||
$theme = theme_config::load($themename);
|
||||
$theme->force_svg_use($usesvg);
|
||||
|
||||
$rev = theme_get_revision();
|
||||
$themerev = theme_get_revision();
|
||||
|
||||
$etag = "$themename/$rev/$type";
|
||||
if (!$usesvg) {
|
||||
// Add to the etag, one day we'll be able to just delete svg nonsense this.
|
||||
$etag .= '/nosvg';
|
||||
$cache = true;
|
||||
if ($themerev <= 0 or $themerev != $rev) {
|
||||
$rev = $themerev;
|
||||
$cache = false;
|
||||
|
||||
$candidatedir = "$CFG->cachedir/theme/$rev/$themename/css";
|
||||
$etag = "$rev/$themename/$type";
|
||||
$candidatename = $type;
|
||||
if (!$usesvg) {
|
||||
// Add to the sheet name, one day we'll be able to just drop this.
|
||||
$candidatedir .= '/nosvg';
|
||||
$etag .= '/nosvg';
|
||||
}
|
||||
|
||||
if ($chunk !== null) {
|
||||
$etag .= '/chunk'.$chunk;
|
||||
$candidatename .= '.'.$chunk;
|
||||
}
|
||||
$candidatesheet = "$candidatedir/$candidatename.css";
|
||||
$etag = sha1($etag);
|
||||
}
|
||||
$etag = sha1($etag);
|
||||
|
||||
make_cache_directory('theme', false);
|
||||
|
||||
if ($type === 'editor') {
|
||||
$cssfiles = $theme->editor_css_files();
|
||||
css_store_css($theme, $candidatesheet, $cssfiles);
|
||||
css_store_css($theme, "$candidatedir/editor.css", $cssfiles, false);
|
||||
|
||||
} else {
|
||||
// IE requests plugins/parents/theme instead of all at once.
|
||||
$basedir = "$CFG->cachedir/theme/$themename/css";
|
||||
if (!$usesvg) {
|
||||
$basedir .= '/nosvg';
|
||||
}
|
||||
// Older IEs require smaller chunks.
|
||||
$css = $theme->css_files();
|
||||
$allfiles = array();
|
||||
$relroot = preg_replace('|^http.?://[^/]+|', '', $CFG->wwwroot);
|
||||
if (!empty($slashargument)) {
|
||||
if ($usesvg) {
|
||||
@ -156,8 +172,8 @@ if ($type === 'editor') {
|
||||
}
|
||||
}
|
||||
$cssfiles = array();
|
||||
foreach ($css as $key=>$value) {
|
||||
foreach($value as $val) {
|
||||
foreach ($css as $key => $value) {
|
||||
foreach ($value as $val) {
|
||||
if (is_array($val)) {
|
||||
foreach ($val as $k=>$v) {
|
||||
$cssfiles[] = $v;
|
||||
@ -167,13 +183,24 @@ if ($type === 'editor') {
|
||||
}
|
||||
}
|
||||
}
|
||||
css_store_css($theme, "$basedir/all.css", $cssfiles, true, $chunkurl);
|
||||
css_store_css($theme, "$candidatedir/all.css", $cssfiles, true, $chunkurl);
|
||||
}
|
||||
|
||||
// verify nothing failed in cache file creation
|
||||
clearstatcache();
|
||||
if (!file_exists($candidatesheet)) {
|
||||
css_send_css_not_found();
|
||||
}
|
||||
// We need to send at least something, IE does not get it chunked properly but who cares.
|
||||
$css = '';
|
||||
foreach ($cssfiles as $file) {
|
||||
$css .= file_get_contents($file)."\n";
|
||||
}
|
||||
css_send_uncached_css($css, false);
|
||||
|
||||
css_send_cached_css($candidatesheet, $etag);
|
||||
} else if (!$cache) {
|
||||
// Do not pollute browser caches if invalid revision requested.
|
||||
css_send_uncached_css(file_get_contents($candidatesheet), false);
|
||||
|
||||
} else {
|
||||
// This is the expected result!
|
||||
css_send_cached_css($candidatesheet, $etag);
|
||||
}
|
||||
|
@ -22,6 +22,9 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
// Disable moodle specific debug messages and any errors in output,
|
||||
// comment out when debugging or better look into error log!
|
||||
define('NO_DEBUG_DISPLAY', true);
|
||||
|
||||
define('ABORT_AFTER_CONFIG', true);
|
||||
require('../config.php'); // this stops immediately at the beginning of lib/setup.php
|
||||
@ -54,16 +57,22 @@ if ($usesvg) {
|
||||
$candidatesheet = "$CFG->cachedir/theme/$themename/designer_nosvg.ser";
|
||||
}
|
||||
|
||||
if (!file_exists($candidatesheet)) {
|
||||
|
||||
css_send_css_not_found();
|
||||
$css = false;
|
||||
if (is_readable($candidatesheet) and filemtime($candidatesheet) > time() - THEME_DESIGNER_CACHE_LIFETIME) {
|
||||
$css = @unserialize(file_get_contents($candidatesheet));
|
||||
}
|
||||
|
||||
if (!$css = file_get_contents($candidatesheet)) {
|
||||
css_send_css_not_found();
|
||||
}
|
||||
if (!is_array($css)) {
|
||||
// Ok, we need to start normal moodle script, we need to load all libs and $DB.
|
||||
define('ABORT_AFTER_CONFIG_CANCEL', true);
|
||||
|
||||
$css = unserialize($css);
|
||||
define('NO_MOODLE_COOKIES', true); // Session not used here.
|
||||
define('NO_UPGRADE_CHECK', true); // Ignore upgrade check.
|
||||
|
||||
require("$CFG->dirroot/lib/setup.php");
|
||||
$theme = theme_config::load($themename);
|
||||
$css = $theme->css_content();
|
||||
}
|
||||
|
||||
if ($type === 'editor') {
|
||||
if (isset($css['editor'])) {
|
||||
@ -112,4 +121,4 @@ if ($type === 'editor') {
|
||||
css_send_uncached_css($css['theme'][$sheet]);
|
||||
}
|
||||
}
|
||||
css_send_css_not_found();
|
||||
css_send_css_not_found();
|
||||
|
@ -87,12 +87,6 @@ foreach ($parts as $part) {
|
||||
$content .= "\n// Incorrect moodle module inclusion. Not enough component information in {$part}.\n";
|
||||
continue;
|
||||
}
|
||||
if (!defined('ABORT_AFTER_CONFIG_CANCEL')) {
|
||||
define('ABORT_AFTER_CONFIG_CANCEL', true);
|
||||
define('NO_UPGRADE_CHECK', true);
|
||||
define('NO_MOODLE_COOKIES', true);
|
||||
require($CFG->libdir.'/setup.php');
|
||||
}
|
||||
$revision = (int)array_shift($bits);
|
||||
if ($revision === -1) {
|
||||
// Revision -1 says please don't cache the JS
|
||||
@ -101,7 +95,7 @@ foreach ($parts as $part) {
|
||||
$frankenstyle = array_shift($bits);
|
||||
$filename = array_pop($bits);
|
||||
$modulename = $bits[0];
|
||||
$dir = get_component_directory($frankenstyle);
|
||||
$dir = core_component::get_component_directory($frankenstyle);
|
||||
|
||||
// For shifted YUI modules, we need the YUI module name in frankenstyle format.
|
||||
$frankenstylemodulename = join('-', array($version, $frankenstyle, $modulename));
|
||||
|
@ -41,17 +41,11 @@ $etag = sha1($path);
|
||||
$parts = explode('/', $path);
|
||||
$version = array_shift($parts);
|
||||
if ($version == 'moodle' && count($parts) >= 3) {
|
||||
if (!defined('ABORT_AFTER_CONFIG_CANCEL')) {
|
||||
define('ABORT_AFTER_CONFIG_CANCEL', true);
|
||||
define('NO_UPGRADE_CHECK', true);
|
||||
define('NO_MOODLE_COOKIES', true);
|
||||
require($CFG->libdir.'/setup.php');
|
||||
}
|
||||
$frankenstyle = array_shift($parts);
|
||||
$module = array_shift($parts);
|
||||
$image = array_pop($parts);
|
||||
$subdir = join('/', $parts);
|
||||
$dir = get_component_directory($frankenstyle);
|
||||
$dir = core_component::get_component_directory($frankenstyle);
|
||||
|
||||
// For shifted YUI modules, we need the YUI module name in frankenstyle format.
|
||||
$frankenstylemodulename = join('-', array($version, $frankenstyle, $module));
|
||||
|
Loading…
x
Reference in New Issue
Block a user