2009-07-01 05:54:26 +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/>.
|
|
|
|
|
|
|
|
/**
|
2009-12-16 18:00:58 +00:00
|
|
|
* This file is responsible for serving the one huge CSS of each theme.
|
2009-07-01 05:54:26 +00:00
|
|
|
*
|
2013-04-27 13:22:59 +02:00
|
|
|
* @package core
|
2009-12-16 18:00:58 +00:00
|
|
|
* @copyright 2009 Petr Skoda (skodak) {@link http://skodak.org}
|
2009-07-01 05:54:26 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2009-12-23 18:52:42 +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-16 18:00:58 +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
|
2011-10-26 18:05:03 +13:00
|
|
|
require_once($CFG->dirroot.'/lib/csslib.php');
|
2009-07-01 05:54:26 +00:00
|
|
|
|
2012-05-05 15:25:20 +02:00
|
|
|
if ($slashargument = min_get_slash_argument()) {
|
|
|
|
$slashargument = ltrim($slashargument, '/');
|
|
|
|
if (substr_count($slashargument, '/') < 2) {
|
2013-04-18 15:49:19 +12:00
|
|
|
css_send_css_not_found();
|
2012-05-05 15:25:20 +02:00
|
|
|
}
|
2012-11-28 18:15:54 +13:00
|
|
|
|
|
|
|
if (strpos($slashargument, '_s/') === 0) {
|
|
|
|
// Can't use SVG
|
|
|
|
$slashargument = substr($slashargument, 3);
|
|
|
|
$usesvg = false;
|
|
|
|
} else {
|
|
|
|
$usesvg = true;
|
|
|
|
}
|
|
|
|
|
2013-04-18 15:49:19 +12:00
|
|
|
$chunk = null;
|
|
|
|
if (preg_match('#/(chunk(\d+)(/|$))#', $slashargument, $matches)) {
|
|
|
|
$chunk = (int)$matches[2];
|
|
|
|
$slashargument = str_replace($matches[1], '', $slashargument);
|
|
|
|
}
|
|
|
|
|
2012-05-05 15:25:20 +02:00
|
|
|
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');
|
|
|
|
$rev = min_optional_param('rev', 0, 'INT');
|
|
|
|
$type = min_optional_param('type', 'all', 'SAFEDIR');
|
2013-04-18 15:49:19 +12:00
|
|
|
$chunk = min_optional_param('chunk', null, 'INT');
|
2012-11-28 18:15:54 +13:00
|
|
|
$usesvg = (bool)min_optional_param('svg', '1', 'INT');
|
2012-05-05 15:25:20 +02:00
|
|
|
}
|
2009-07-01 05:54:26 +00:00
|
|
|
|
2010-01-05 17:29:43 +00:00
|
|
|
if (!in_array($type, array('all', 'ie', 'editor', 'plugins', 'parents', 'theme'))) {
|
2009-12-16 18:00:58 +00:00
|
|
|
header('HTTP/1.0 404 not found');
|
|
|
|
die('Theme was not found, sorry.');
|
2009-07-01 05:54:26 +00:00
|
|
|
}
|
|
|
|
|
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-16 18:00:58 +00:00
|
|
|
header('HTTP/1.0 404 not found');
|
|
|
|
die('Theme was not found, sorry.');
|
|
|
|
}
|
2009-07-01 05:54:26 +00:00
|
|
|
|
2009-12-16 18:00:58 +00:00
|
|
|
if ($type === 'ie') {
|
2012-05-05 17:06:58 +02:00
|
|
|
css_send_ie_css($themename, $rev, $etag, !empty($slashargument));
|
2009-12-16 18:00:58 +00:00
|
|
|
}
|
2009-07-01 05:54:26 +00:00
|
|
|
|
2012-11-28 18:15:54 +13:00
|
|
|
$candidatedir = "$CFG->cachedir/theme/$themename/css";
|
|
|
|
$etag = "$themename/$rev/$type";
|
2013-04-18 15:49:19 +12:00
|
|
|
$candidatename = $type;
|
2012-11-28 18:15:54 +13:00
|
|
|
if (!$usesvg) {
|
|
|
|
// Add to the sheet name, one day we'll be able to just drop this.
|
|
|
|
$candidatedir .= '/nosvg';
|
|
|
|
$etag .= '/nosvg';
|
|
|
|
}
|
2013-04-18 15:49:19 +12:00
|
|
|
if ($chunk !== null) {
|
|
|
|
$etag .= '/chunk'.$chunk;
|
|
|
|
$candidatename .= '.'.$chunk;
|
|
|
|
}
|
|
|
|
$candidatesheet = "$candidatedir/$candidatename.css";
|
2012-11-28 18:15:54 +13:00
|
|
|
$etag = sha1($etag);
|
2009-07-01 05:54:26 +00:00
|
|
|
|
2009-12-16 18:00:58 +00:00
|
|
|
if (file_exists($candidatesheet)) {
|
2011-08-19 16:32:30 +02:00
|
|
|
if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) || !empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
|
2009-12-16 18:00:58 +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:23:51 +02:00
|
|
|
css_send_unmodified(filemtime($candidatesheet), $etag);
|
2009-12-16 18:00:58 +00:00
|
|
|
}
|
2012-05-05 17:06:58 +02:00
|
|
|
css_send_cached_css($candidatesheet, $etag);
|
2009-07-01 05:54:26 +00:00
|
|
|
}
|
|
|
|
|
2009-12-16 18:00:58 +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);
|
2009-07-07 05:05:06 +00:00
|
|
|
|
2009-12-16 18:00:58 +00:00
|
|
|
define('NO_MOODLE_COOKIES', true); // Session not used here
|
|
|
|
define('NO_UPGRADE_CHECK', true); // Ignore upgrade check
|
2009-07-07 05:05:06 +00:00
|
|
|
|
2009-12-16 18:00:58 +00:00
|
|
|
require("$CFG->dirroot/lib/setup.php");
|
2009-07-01 05:54:26 +00:00
|
|
|
|
2009-12-16 18:00:58 +00:00
|
|
|
$theme = theme_config::load($themename);
|
2012-11-28 18:15:54 +13:00
|
|
|
$theme->force_svg_use($usesvg);
|
2009-07-07 05:05:06 +00:00
|
|
|
|
2012-05-05 17:06:58 +02:00
|
|
|
$rev = theme_get_revision();
|
2012-11-28 18:15:54 +13:00
|
|
|
|
|
|
|
$etag = "$themename/$rev/$type";
|
|
|
|
if (!$usesvg) {
|
|
|
|
// Add to the etag, one day we'll be able to just delete svg nonsense this.
|
|
|
|
$etag .= '/nosvg';
|
|
|
|
}
|
|
|
|
$etag = sha1($etag);
|
2012-05-05 17:06:58 +02:00
|
|
|
|
2009-12-16 18:00:58 +00:00
|
|
|
if ($type === 'editor') {
|
2012-02-07 13:54:54 +08:00
|
|
|
$cssfiles = $theme->editor_css_files();
|
2011-10-26 18:05:03 +13:00
|
|
|
css_store_css($theme, $candidatesheet, $cssfiles);
|
2009-12-16 18:00:58 +00:00
|
|
|
} else {
|
2013-04-18 15:49:19 +12:00
|
|
|
// IE requests plugins/parents/theme instead of all at once.
|
2012-11-28 18:15:54 +13:00
|
|
|
$basedir = "$CFG->cachedir/theme/$themename/css";
|
|
|
|
if (!$usesvg) {
|
|
|
|
$basedir .= '/nosvg';
|
|
|
|
}
|
2010-05-19 02:15:16 +00:00
|
|
|
$css = $theme->css_files();
|
|
|
|
$allfiles = array();
|
2013-04-18 15:49:19 +12:00
|
|
|
$relroot = preg_replace('|^http.?://[^/]+|', '', $CFG->wwwroot);
|
2009-12-16 18:00:58 +00:00
|
|
|
foreach ($css as $key=>$value) {
|
2013-04-18 15:49:19 +12:00
|
|
|
if (!empty($slashargument)) {
|
2013-04-24 13:52:48 +12:00
|
|
|
if ($usesvg) {
|
|
|
|
$chunkurl = "{$relroot}/theme/styles.php/{$themename}/{$rev}/{$key}";
|
|
|
|
} else {
|
|
|
|
$chunkurl = "{$relroot}/theme/styles.php/_s/{$themename}/{$rev}/{$key}";
|
|
|
|
}
|
2013-04-18 15:49:19 +12:00
|
|
|
} else {
|
2013-04-24 13:52:48 +12:00
|
|
|
if ($usesvg) {
|
|
|
|
$chunkurl = "{$relroot}/theme/styles.php?theme={$themename}&rev={$rev}&type={$key}";
|
|
|
|
} else {
|
|
|
|
$chunkurl = "{$relroot}/theme/styles.php?theme={$themename}&rev={$rev}&type={$key}&svg=0";
|
|
|
|
}
|
2013-04-18 15:49:19 +12:00
|
|
|
}
|
2010-05-19 02:15:16 +00:00
|
|
|
$cssfiles = array();
|
2009-12-16 18:00:58 +00:00
|
|
|
foreach($value as $val) {
|
|
|
|
if (is_array($val)) {
|
2010-01-05 21:45:51 +00:00
|
|
|
foreach ($val as $k=>$v) {
|
2010-05-19 02:15:16 +00:00
|
|
|
$cssfiles[] = $v;
|
2010-01-05 21:45:51 +00:00
|
|
|
}
|
2009-12-16 18:00:58 +00:00
|
|
|
} else {
|
2010-05-19 02:15:16 +00:00
|
|
|
$cssfiles[] = $val;
|
2009-12-16 18:00:58 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 18:15:54 +13:00
|
|
|
$cssfile = "$basedir/$key.css";
|
2013-04-18 15:49:19 +12:00
|
|
|
css_store_css($theme, $cssfile, $cssfiles, true, $chunkurl);
|
2010-05-19 02:15:16 +00:00
|
|
|
$allfiles = array_merge($allfiles, $cssfiles);
|
2009-07-07 05:05:06 +00:00
|
|
|
}
|
2012-11-28 18:15:54 +13:00
|
|
|
$cssfile = "$basedir/all.css";
|
2011-10-26 18:05:03 +13:00
|
|
|
css_store_css($theme, $cssfile, $allfiles);
|
2010-05-19 02:15:16 +00:00
|
|
|
}
|
2012-05-07 17:35:09 +02:00
|
|
|
|
|
|
|
// verify nothing failed in cache file creation
|
|
|
|
clearstatcache();
|
|
|
|
if (!file_exists($candidatesheet)) {
|
|
|
|
css_send_css_not_found();
|
|
|
|
}
|
|
|
|
|
2012-05-05 17:06:58 +02:00
|
|
|
css_send_cached_css($candidatesheet, $etag);
|