MDL-31529 csslib: third param passed to css_store_css fixed
[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
78946b9b
PS
36$themename = min_optional_param('theme', 'standard', 'SAFEDIR');
37$type = min_optional_param('type', 'all', 'SAFEDIR');
38$rev = min_optional_param('rev', 0, 'INT');
b7009474 39
c724f835 40if (!in_array($type, array('all', 'ie', 'editor', 'plugins', 'parents', 'theme'))) {
78946b9b
PS
41 header('HTTP/1.0 404 not found');
42 die('Theme was not found, sorry.');
b7009474 43}
44
73e504bc
PS
45if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
46 // exists
47} else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) {
48 // exists
49} else {
78946b9b
PS
50 header('HTTP/1.0 404 not found');
51 die('Theme was not found, sorry.');
52}
b7009474 53
78946b9b 54if ($type === 'ie') {
0e641c74 55 css_send_ie_css($themename, $rev);
78946b9b 56}
b7009474 57
365bec4c 58$candidatesheet = "$CFG->cachedir/theme/$themename/css/$type.css";
b7009474 59
78946b9b 60if (file_exists($candidatesheet)) {
aa603b14 61 if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) || !empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
78946b9b
PS
62 // we do not actually need to verify the etag value because our files
63 // never change in cache because we increment the rev parameter
ccc0fff9 64 $lifetime = 60*60*24*30; // 30 days
aa603b14 65 header('HTTP/1.1 304 Not Modified');
ccc0fff9
TL
66 header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT');
67 header('Cache-Control: max-age='.$lifetime);
68 header('Content-Type: text/css; charset=utf-8');
78946b9b
PS
69 die;
70 }
0e641c74 71 css_send_cached_css($candidatesheet, $rev);
b7009474 72}
73
78946b9b
PS
74//=================================================================================
75// ok, now we need to start normal moodle script, we need to load all libs and $DB
76define('ABORT_AFTER_CONFIG_CANCEL', true);
fdeb7fa1 77
78946b9b
PS
78define('NO_MOODLE_COOKIES', true); // Session not used here
79define('NO_UPGRADE_CHECK', true); // Ignore upgrade check
fdeb7fa1 80
78946b9b 81require("$CFG->dirroot/lib/setup.php");
b7009474 82
78946b9b 83$theme = theme_config::load($themename);
fdeb7fa1 84
78946b9b 85if ($type === 'editor') {
7e08c95f 86 $cssfiles = $theme->editor_css_files();
0e641c74 87 css_store_css($theme, $candidatesheet, $cssfiles);
78946b9b 88} else {
045f492c
SH
89 $css = $theme->css_files();
90 $allfiles = array();
78946b9b 91 foreach ($css as $key=>$value) {
045f492c 92 $cssfiles = array();
78946b9b
PS
93 foreach($value as $val) {
94 if (is_array($val)) {
e10f304d 95 foreach ($val as $k=>$v) {
045f492c 96 $cssfiles[] = $v;
e10f304d 97 }
78946b9b 98 } else {
045f492c 99 $cssfiles[] = $val;
78946b9b
PS
100 }
101 }
365bec4c 102 $cssfile = "$CFG->cachedir/theme/$themename/css/$key.css";
0e641c74 103 css_store_css($theme, $cssfile, $cssfiles);
045f492c 104 $allfiles = array_merge($allfiles, $cssfiles);
fdeb7fa1 105 }
365bec4c 106 $cssfile = "$CFG->cachedir/theme/$themename/css/all.css";
0e641c74 107 css_store_css($theme, $cssfile, $allfiles);
045f492c 108}
0e641c74 109css_send_cached_css($candidatesheet, $rev);