on demand release 2.5beta+
[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 }
383b89a1
SH
41
42 if (strpos($slashargument, '_s/') === 0) {
43 // Can't use SVG
44 $slashargument = substr($slashargument, 3);
45 $usesvg = false;
46 } else {
47 $usesvg = true;
48 }
49
7070b7f2
PS
50 // image must be last because it may contain "/"
51 list($themename, $rev, $type) = explode('/', $slashargument, 3);
52 $themename = min_clean_param($themename, 'SAFEDIR');
53 $rev = min_clean_param($rev, 'INT');
54 $type = min_clean_param($type, 'SAFEDIR');
55
56} else {
57 $themename = min_optional_param('theme', 'standard', 'SAFEDIR');
58 $rev = min_optional_param('rev', 0, 'INT');
59 $type = min_optional_param('type', 'all', 'SAFEDIR');
383b89a1 60 $usesvg = (bool)min_optional_param('svg', '1', 'INT');
7070b7f2 61}
b7009474 62
c724f835 63if (!in_array($type, array('all', 'ie', 'editor', 'plugins', 'parents', 'theme'))) {
78946b9b
PS
64 header('HTTP/1.0 404 not found');
65 die('Theme was not found, sorry.');
b7009474 66}
67
73e504bc
PS
68if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
69 // exists
70} else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) {
71 // exists
72} else {
78946b9b
PS
73 header('HTTP/1.0 404 not found');
74 die('Theme was not found, sorry.');
75}
b7009474 76
78946b9b 77if ($type === 'ie') {
2c61e7cc 78 css_send_ie_css($themename, $rev, $etag, !empty($slashargument));
78946b9b 79}
b7009474 80
383b89a1
SH
81$candidatedir = "$CFG->cachedir/theme/$themename/css";
82$etag = "$themename/$rev/$type";
83if (!$usesvg) {
84 // Add to the sheet name, one day we'll be able to just drop this.
85 $candidatedir .= '/nosvg';
86 $etag .= '/nosvg';
87}
88$candidatesheet = "$candidatedir/$type.css";
89$etag = sha1($etag);
b7009474 90
78946b9b 91if (file_exists($candidatesheet)) {
aa603b14 92 if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) || !empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
78946b9b
PS
93 // we do not actually need to verify the etag value because our files
94 // never change in cache because we increment the rev parameter
869b1255 95 css_send_unmodified(filemtime($candidatesheet), $etag);
78946b9b 96 }
2c61e7cc 97 css_send_cached_css($candidatesheet, $etag);
b7009474 98}
99
78946b9b
PS
100//=================================================================================
101// ok, now we need to start normal moodle script, we need to load all libs and $DB
102define('ABORT_AFTER_CONFIG_CANCEL', true);
fdeb7fa1 103
78946b9b
PS
104define('NO_MOODLE_COOKIES', true); // Session not used here
105define('NO_UPGRADE_CHECK', true); // Ignore upgrade check
fdeb7fa1 106
78946b9b 107require("$CFG->dirroot/lib/setup.php");
b7009474 108
78946b9b 109$theme = theme_config::load($themename);
383b89a1 110$theme->force_svg_use($usesvg);
fdeb7fa1 111
2c61e7cc 112$rev = theme_get_revision();
383b89a1
SH
113
114$etag = "$themename/$rev/$type";
115if (!$usesvg) {
116 // Add to the etag, one day we'll be able to just delete svg nonsense this.
117 $etag .= '/nosvg';
118}
119$etag = sha1($etag);
2c61e7cc 120
78946b9b 121if ($type === 'editor') {
7e08c95f 122 $cssfiles = $theme->editor_css_files();
0e641c74 123 css_store_css($theme, $candidatesheet, $cssfiles);
78946b9b 124} else {
383b89a1
SH
125 $basedir = "$CFG->cachedir/theme/$themename/css";
126 if (!$usesvg) {
127 $basedir .= '/nosvg';
128 }
045f492c
SH
129 $css = $theme->css_files();
130 $allfiles = array();
78946b9b 131 foreach ($css as $key=>$value) {
045f492c 132 $cssfiles = array();
78946b9b
PS
133 foreach($value as $val) {
134 if (is_array($val)) {
e10f304d 135 foreach ($val as $k=>$v) {
045f492c 136 $cssfiles[] = $v;
e10f304d 137 }
78946b9b 138 } else {
045f492c 139 $cssfiles[] = $val;
78946b9b
PS
140 }
141 }
383b89a1 142 $cssfile = "$basedir/$key.css";
0e641c74 143 css_store_css($theme, $cssfile, $cssfiles);
045f492c 144 $allfiles = array_merge($allfiles, $cssfiles);
fdeb7fa1 145 }
383b89a1 146 $cssfile = "$basedir/all.css";
0e641c74 147 css_store_css($theme, $cssfile, $allfiles);
045f492c 148}
979d3207
PS
149
150// verify nothing failed in cache file creation
151clearstatcache();
152if (!file_exists($candidatesheet)) {
153 css_send_css_not_found();
154}
155
2c61e7cc 156css_send_cached_css($candidatesheet, $etag);