on-demand release 2.4rc1
[moodle.git] / theme / styles.php
CommitLineData
b7009474 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
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.
9//
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.
14//
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/>.
17
18/**
78946b9b 19 * This file is responsible for serving the one huge CSS of each theme.
b7009474 20 *
21 * @package moodlecore
78946b9b 22 * @copyright 2009 Petr Skoda (skodak) {@link http://skodak.org}
b7009474 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
73e504bc 26
c198390a
PS
27// disable moodle specific debug messages and any errors in output,
28// comment out when debugging or better look into error log!
29define('NO_DEBUG_DISPLAY', true);
30
78946b9b
PS
31// we need just the values from config.php and minlib.php
32define('ABORT_AFTER_CONFIG', true);
33require('../config.php'); // this stops immediately at the beginning of lib/setup.php
0e641c74 34require_once($CFG->dirroot.'/lib/csslib.php');
b7009474 35
7070b7f2
PS
36if ($slashargument = min_get_slash_argument()) {
37 $slashargument = ltrim($slashargument, '/');
38 if (substr_count($slashargument, '/') < 2) {
39 image_not_found();
40 }
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');
46
47} else {
48 $themename = min_optional_param('theme', 'standard', 'SAFEDIR');
49 $rev = min_optional_param('rev', 0, 'INT');
50 $type = min_optional_param('type', 'all', 'SAFEDIR');
51}
b7009474 52
c724f835 53if (!in_array($type, array('all', 'ie', 'editor', 'plugins', 'parents', 'theme'))) {
78946b9b
PS
54 header('HTTP/1.0 404 not found');
55 die('Theme was not found, sorry.');
b7009474 56}
57
73e504bc
PS
58if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
59 // exists
60} else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) {
61 // exists
62} else {
78946b9b
PS
63 header('HTTP/1.0 404 not found');
64 die('Theme was not found, sorry.');
65}
b7009474 66
78946b9b 67if ($type === 'ie') {
2c61e7cc 68 css_send_ie_css($themename, $rev, $etag, !empty($slashargument));
78946b9b 69}
b7009474 70
365bec4c 71$candidatesheet = "$CFG->cachedir/theme/$themename/css/$type.css";
2c61e7cc 72$etag = sha1("$themename/$rev/$type");
b7009474 73
78946b9b 74if (file_exists($candidatesheet)) {
aa603b14 75 if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) || !empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
78946b9b
PS
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
869b1255 78 css_send_unmodified(filemtime($candidatesheet), $etag);
78946b9b 79 }
2c61e7cc 80 css_send_cached_css($candidatesheet, $etag);
b7009474 81}
82
78946b9b
PS
83//=================================================================================
84// ok, now we need to start normal moodle script, we need to load all libs and $DB
85define('ABORT_AFTER_CONFIG_CANCEL', true);
fdeb7fa1 86
78946b9b
PS
87define('NO_MOODLE_COOKIES', true); // Session not used here
88define('NO_UPGRADE_CHECK', true); // Ignore upgrade check
fdeb7fa1 89
78946b9b 90require("$CFG->dirroot/lib/setup.php");
b7009474 91
78946b9b 92$theme = theme_config::load($themename);
fdeb7fa1 93
2c61e7cc
PS
94$rev = theme_get_revision();
95$etag = sha1("$themename/$rev/$type");
96
78946b9b 97if ($type === 'editor') {
7e08c95f 98 $cssfiles = $theme->editor_css_files();
0e641c74 99 css_store_css($theme, $candidatesheet, $cssfiles);
78946b9b 100} else {
045f492c
SH
101 $css = $theme->css_files();
102 $allfiles = array();
78946b9b 103 foreach ($css as $key=>$value) {
045f492c 104 $cssfiles = array();
78946b9b
PS
105 foreach($value as $val) {
106 if (is_array($val)) {
e10f304d 107 foreach ($val as $k=>$v) {
045f492c 108 $cssfiles[] = $v;
e10f304d 109 }
78946b9b 110 } else {
045f492c 111 $cssfiles[] = $val;
78946b9b
PS
112 }
113 }
365bec4c 114 $cssfile = "$CFG->cachedir/theme/$themename/css/$key.css";
0e641c74 115 css_store_css($theme, $cssfile, $cssfiles);
045f492c 116 $allfiles = array_merge($allfiles, $cssfiles);
fdeb7fa1 117 }
365bec4c 118 $cssfile = "$CFG->cachedir/theme/$themename/css/all.css";
0e641c74 119 css_store_css($theme, $cssfile, $allfiles);
045f492c 120}
979d3207
PS
121
122// verify nothing failed in cache file creation
123clearstatcache();
124if (!file_exists($candidatesheet)) {
125 css_send_css_not_found();
126}
127
2c61e7cc 128css_send_cached_css($candidatesheet, $etag);