Merge branch 'MDL-31432_messaging_popup' of git://github.com/andyjdavis/moodle
[moodle.git] / theme / styles.php
blob5f6fd90ee68e837f197fbeb20d1842f913016be6
1 <?php
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.
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/>.
18 /**
19 * This file is responsible for serving the one huge CSS of each theme.
21 * @package moodlecore
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 $themename = min_optional_param('theme', 'standard', 'SAFEDIR');
37 $type = min_optional_param('type', 'all', 'SAFEDIR');
38 $rev = min_optional_param('rev', 0, 'INT');
40 if (!in_array($type, array('all', 'ie', 'editor', 'plugins', 'parents', 'theme'))) {
41 header('HTTP/1.0 404 not found');
42 die('Theme was not found, sorry.');
45 if (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 {
50 header('HTTP/1.0 404 not found');
51 die('Theme was not found, sorry.');
54 if ($type === 'ie') {
55 css_send_ie_css($themename, $rev);
58 $candidatesheet = "$CFG->cachedir/theme/$themename/css/$type.css";
60 if (file_exists($candidatesheet)) {
61 if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) || !empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
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
64 $lifetime = 60*60*24*30; // 30 days
65 header('HTTP/1.1 304 Not Modified');
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');
69 die;
71 css_send_cached_css($candidatesheet, $rev);
74 //=================================================================================
75 // ok, now we need to start normal moodle script, we need to load all libs and $DB
76 define('ABORT_AFTER_CONFIG_CANCEL', true);
78 define('NO_MOODLE_COOKIES', true); // Session not used here
79 define('NO_UPGRADE_CHECK', true); // Ignore upgrade check
81 require("$CFG->dirroot/lib/setup.php");
83 $theme = theme_config::load($themename);
85 if ($type === 'editor') {
86 $cssfiles = $theme->editor_css_files();
87 css_store_css($theme, $candidatesheet, $cssfiles);
88 } else {
89 $css = $theme->css_files();
90 $allfiles = array();
91 foreach ($css as $key=>$value) {
92 $cssfiles = array();
93 foreach($value as $val) {
94 if (is_array($val)) {
95 foreach ($val as $k=>$v) {
96 $cssfiles[] = $v;
98 } else {
99 $cssfiles[] = $val;
102 $cssfile = "$CFG->cachedir/theme/$themename/css/$key.css";
103 css_store_css($theme, $cssfile, $cssfiles);
104 $allfiles = array_merge($allfiles, $cssfiles);
106 $cssfile = "$CFG->cachedir/theme/$themename/css/all.css";
107 css_store_css($theme, $cssfile, $allfiles);
109 css_send_cached_css($candidatesheet, $rev);