2009-12-20 21:50:46 +00:00
|
|
|
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file is responsible for serving the one huge CSS of each theme.
|
|
|
|
*
|
2012-05-05 18:16:50 +02:00
|
|
|
* @package core
|
2009-12-20 21:50:46 +00:00
|
|
|
* @copyright 2009 Petr Skoda (skodak) {@link http://skodak.org}
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2009-12-20 23:06:57 +00:00
|
|
|
|
2011-11-19 11:23:28 +01:00
|
|
|
// 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);
|
|
|
|
|
2009-12-20 23:06:57 +00:00
|
|
|
// we need just the values from config.php and minlib.php
|
|
|
|
define('ABORT_AFTER_CONFIG', true);
|
|
|
|
require('../config.php'); // this stops immediately at the beginning of lib/setup.php
|
2012-05-05 18:16:50 +02:00
|
|
|
require_once("$CFG->dirroot/lib/jslib.php");
|
2009-12-20 23:06:57 +00:00
|
|
|
|
2012-05-05 15:31:27 +02:00
|
|
|
if ($slashargument = min_get_slash_argument()) {
|
|
|
|
$slashargument = ltrim($slashargument, '/');
|
|
|
|
if (substr_count($slashargument, '/') < 2) {
|
2014-08-12 14:06:37 +12:00
|
|
|
header('HTTP/1.0 404 not found');
|
|
|
|
die('Slash argument must contain both a revision and a file path');
|
2012-05-05 15:31:27 +02:00
|
|
|
}
|
|
|
|
// image must be last because it may contain "/"
|
|
|
|
list($themename, $rev, $type) = explode('/', $slashargument, 3);
|
|
|
|
$themename = min_clean_param($themename, 'SAFEDIR');
|
|
|
|
$rev = min_clean_param($rev, 'INT');
|
|
|
|
$type = min_clean_param($type, 'SAFEDIR');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$themename = min_optional_param('theme', 'standard', 'SAFEDIR');
|
2013-07-12 23:17:22 +02:00
|
|
|
$rev = min_optional_param('rev', -1, 'INT');
|
2012-05-05 15:31:27 +02:00
|
|
|
$type = min_optional_param('type', 'head', 'RAW');
|
|
|
|
}
|
2010-01-05 23:22:16 +00:00
|
|
|
|
2023-09-06 16:12:19 +10:00
|
|
|
if (!min_is_revision_valid_and_current($rev)) {
|
|
|
|
// If the rev is invalid, normalise it to -1 to disable all caching.
|
|
|
|
$rev = -1;
|
|
|
|
}
|
|
|
|
|
2010-02-07 13:08:46 +00:00
|
|
|
if ($type !== 'head' and $type !== 'footer') {
|
2010-01-05 23:22:16 +00:00
|
|
|
header('HTTP/1.0 404 not found');
|
|
|
|
die('Theme was not found, sorry.');
|
|
|
|
}
|
|
|
|
|
2009-12-23 18:52:42 +00:00
|
|
|
if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
|
|
|
|
// exists
|
|
|
|
} else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) {
|
|
|
|
// exists
|
|
|
|
} else {
|
2009-12-20 23:06:57 +00:00
|
|
|
header('HTTP/1.0 404 not found');
|
|
|
|
die('Theme was not found, sorry.');
|
|
|
|
}
|
|
|
|
|
2013-07-13 00:05:58 +02:00
|
|
|
$candidate = "$CFG->localcachedir/theme/$rev/$themename/javascript_$type.js";
|
2013-07-12 23:17:22 +02:00
|
|
|
$etag = sha1("$rev/$themename/$type");
|
2009-12-20 23:06:57 +00:00
|
|
|
|
2013-07-12 23:17:22 +02:00
|
|
|
if ($rev > 0 and file_exists($candidate)) {
|
2011-08-19 16:32:30 +02:00
|
|
|
if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) || !empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
|
2009-12-20 23:06:57 +00:00
|
|
|
// we do not actually need to verify the etag value because our files
|
|
|
|
// never change in cache because we increment the rev parameter
|
2012-05-05 18:16:50 +02:00
|
|
|
js_send_unmodified(filemtime($candidate), $etag);
|
2009-12-20 23:06:57 +00:00
|
|
|
}
|
2012-05-05 18:16:50 +02:00
|
|
|
js_send_cached($candidate, $etag);
|
2009-12-20 23:06:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// ok, now we need to start normal moodle script, we need to load all libs and $DB
|
|
|
|
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");
|
|
|
|
|
|
|
|
$theme = theme_config::load($themename);
|
2013-07-12 23:17:22 +02:00
|
|
|
$themerev = theme_get_revision();
|
2009-12-20 23:06:57 +00:00
|
|
|
|
2013-07-12 23:17:22 +02:00
|
|
|
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));
|
|
|
|
}
|
2012-05-05 16:54:06 +02:00
|
|
|
|
2013-07-13 00:05:58 +02:00
|
|
|
make_localcache_directory('theme', false);
|
2013-07-12 23:17:22 +02:00
|
|
|
|
2013-08-01 23:20:24 +02:00
|
|
|
js_write_cache_file_content($candidate, core_minify::js_files($theme->javascript_files($type)));
|
2013-07-12 23:17:22 +02:00
|
|
|
// Verify nothing failed in cache file creation.
|
|
|
|
clearstatcache();
|
|
|
|
if (file_exists($candidate)) {
|
|
|
|
js_send_cached($candidate, $etag);
|
2010-05-19 02:15:16 +00:00
|
|
|
}
|
2012-05-07 17:35:09 +02:00
|
|
|
|
|
|
|
js_send_uncached($theme->javascript_content($type));
|