3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * This file is responsible for serving the one huge CSS of each theme.
22 * @copyright 2009 Petr Skoda (skodak) {@link http://skodak.org}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 // disable moodle specific debug messages and any errors in output,
28 // comment out when debugging or better look into error log!
29 define('NO_DEBUG_DISPLAY', true);
31 // we need just the values from config.php and minlib.php
32 define('ABORT_AFTER_CONFIG', true);
33 require('../config.php'); // this stops immediately at the beginning of lib/setup.php
34 require_once($CFG->dirroot
.'/lib/csslib.php');
36 if ($slashargument = min_get_slash_argument()) {
37 $slashargument = ltrim($slashargument, '/');
38 if (substr_count($slashargument, '/') < 2) {
41 // image must be last because it may contain "/"
42 list($themename, $rev, $type) = explode('/', $slashargument, 3);
43 $themename = min_clean_param($themename, 'SAFEDIR');
44 $rev = min_clean_param($rev, 'INT');
45 $type = min_clean_param($type, 'SAFEDIR');
48 $themename = min_optional_param('theme', 'standard', 'SAFEDIR');
49 $rev = min_optional_param('rev', 0, 'INT');
50 $type = min_optional_param('type', 'all', 'SAFEDIR');
53 if (!in_array($type, array('all', 'ie', 'editor', 'plugins', 'parents', 'theme'))) {
54 header('HTTP/1.0 404 not found');
55 die('Theme was not found, sorry.');
58 if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
60 } else if (!empty($CFG->themedir
) and file_exists("$CFG->themedir/$themename/config.php")) {
63 header('HTTP/1.0 404 not found');
64 die('Theme was not found, sorry.');
68 css_send_ie_css($themename, $rev, $etag, !empty($slashargument));
71 $candidatesheet = "$CFG->cachedir/theme/$themename/css/$type.css";
72 $etag = sha1("$themename/$rev/$type");
74 if (file_exists($candidatesheet)) {
75 if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) ||
!empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
76 // we do not actually need to verify the etag value because our files
77 // never change in cache because we increment the rev parameter
78 css_send_unmodified(filemtime($candidatesheet), $etag);
80 css_send_cached_css($candidatesheet, $etag);
83 //=================================================================================
84 // ok, now we need to start normal moodle script, we need to load all libs and $DB
85 define('ABORT_AFTER_CONFIG_CANCEL', true);
87 define('NO_MOODLE_COOKIES', true); // Session not used here
88 define('NO_UPGRADE_CHECK', true); // Ignore upgrade check
90 require("$CFG->dirroot/lib/setup.php");
92 $theme = theme_config
::load($themename);
94 $rev = theme_get_revision();
95 $etag = sha1("$themename/$rev/$type");
97 if ($type === 'editor') {
98 $cssfiles = $theme->editor_css_files();
99 css_store_css($theme, $candidatesheet, $cssfiles);
101 $css = $theme->css_files();
103 foreach ($css as $key=>$value) {
105 foreach($value as $val) {
106 if (is_array($val)) {
107 foreach ($val as $k=>$v) {
114 $cssfile = "$CFG->cachedir/theme/$themename/css/$key.css";
115 css_store_css($theme, $cssfile, $cssfiles);
116 $allfiles = array_merge($allfiles, $cssfiles);
118 $cssfile = "$CFG->cachedir/theme/$themename/css/all.css";
119 css_store_css($theme, $cssfile, $allfiles);
122 // verify nothing failed in cache file creation
124 if (!file_exists($candidatesheet)) {
125 css_send_css_not_found();
128 css_send_cached_css($candidatesheet, $etag);