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 of individual style sheets in designer mode.
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 define('ABORT_AFTER_CONFIG', true);
28 require('../config.php'); // this stops immediately at the beginning of lib/setup.php
29 require_once($CFG->dirroot
.'/lib/csslib.php');
31 $themename = min_optional_param('theme', 'standard', 'SAFEDIR');
32 $type = min_optional_param('type', '', 'SAFEDIR');
33 $subtype = min_optional_param('subtype', '', 'SAFEDIR');
34 $sheet = min_optional_param('sheet', '', 'SAFEDIR');
35 $usesvg = (bool)min_optional_param('svg', '1', 'INT');
37 if (!defined('THEME_DESIGNER_CACHE_LIFETIME')) {
38 define('THEME_DESIGNER_CACHE_LIFETIME', 4); // this can be also set in config.php
41 if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
43 } else if (!empty($CFG->themedir
) and file_exists("$CFG->themedir/$themename/config.php")) {
46 css_send_css_not_found();
49 // no gzip compression when debugging
52 $candidatesheet = "$CFG->cachedir/theme/$themename/designer.ser";
54 // Add to the sheet name, one day we'll be able to just drop this.
55 $candidatesheet = "$CFG->cachedir/theme/$themename/designer_nosvg.ser";
58 if (!file_exists($candidatesheet)) {
60 css_send_css_not_found();
63 if (!$css = file_get_contents($candidatesheet)) {
64 css_send_css_not_found();
67 $css = unserialize($css);
69 if ($type === 'editor') {
70 if (isset($css['editor'])) {
71 css_send_uncached_css($css['editor']);
73 } else if ($type === 'ie') {
74 // IE is a sloppy browser with weird limits, sorry
75 if ($subtype === 'plugins') {
76 css_send_uncached_css($css['plugins']);
78 } else if ($subtype === 'parents') {
81 // If not specific parent has been specified as $sheet then build a
82 // collection of @import statements into this one sheet.
83 // We shouldn't ever actually get here, but none the less we'll deal
84 // with it incase we ever do.
85 // @import statements arn't processed until after concurrent CSS requests
86 // making them slightly evil.
87 foreach (array_keys($css['parents']) as $sheet) {
88 $sendcss[] = "@import url(styles_debug.php?theme=$themename&type=$type&subtype=$subtype&sheet=$sheet);";
91 // Build up the CSS for that parent so we can serve it as one file.
92 foreach ($css[$subtype][$sheet] as $parent=>$css) {
96 css_send_uncached_css($sendcss);
97 } else if ($subtype === 'theme') {
98 css_send_uncached_css($css['theme']);
101 } else if ($type === 'plugin') {
102 if (isset($css['plugins'][$subtype])) {
103 css_send_uncached_css($css['plugins'][$subtype]);
106 } else if ($type === 'parent') {
107 if (isset($css['parents'][$subtype][$sheet])) {
108 css_send_uncached_css($css['parents'][$subtype][$sheet]);
111 } else if ($type === 'theme') {
112 if (isset($css['theme'][$sheet])) {
113 css_send_uncached_css($css['theme'][$sheet]);
116 css_send_css_not_found();