on-demand release 2.4rc1
[moodle.git] / theme / styles_debug.php
CommitLineData
78946b9b
PS
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/**
19 * This file is responsible for serving of individual style sheets in designer mode.
20 *
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
24 */
25
73e504bc 26
7829cf79
PS
27define('ABORT_AFTER_CONFIG', true);
28require('../config.php'); // this stops immediately at the beginning of lib/setup.php
0e641c74 29require_once($CFG->dirroot.'/lib/csslib.php');
78946b9b 30
7829cf79 31$themename = min_optional_param('theme', 'standard', 'SAFEDIR');
4399b9d5 32$type = min_optional_param('type', '', 'SAFEDIR');
7829cf79
PS
33$subtype = min_optional_param('subtype', '', 'SAFEDIR');
34$sheet = min_optional_param('sheet', '', 'SAFEDIR');
78946b9b 35
d6b64d15
PS
36if (!defined('THEME_DESIGNER_CACHE_LIFETIME')) {
37 define('THEME_DESIGNER_CACHE_LIFETIME', 4); // this can be also set in config.php
38}
39
73e504bc
PS
40if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
41 // exists
42} else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) {
43 // exists
44} else {
0e641c74 45 css_send_css_not_found();
78946b9b
PS
46}
47
7c986f04
PS
48// no gzip compression when debugging
49
365bec4c 50$candidatesheet = "$CFG->cachedir/theme/$themename/designer.ser";
7829cf79
PS
51
52if (!file_exists($candidatesheet)) {
0e641c74 53 css_send_css_not_found();
78946b9b
PS
54}
55
7829cf79 56if (!$css = file_get_contents($candidatesheet)) {
0e641c74 57 css_send_css_not_found();
78946b9b
PS
58}
59
7829cf79 60$css = unserialize($css);
78946b9b 61
71be124d
SH
62if ($type === 'editor') {
63 if (isset($css['editor'])) {
0e641c74 64 css_send_uncached_css($css['editor']);
71be124d
SH
65 }
66} else if ($type === 'ie') {
4399b9d5
PS
67 // IE is a sloppy browser with weird limits, sorry
68 if ($subtype === 'plugins') {
0e641c74 69 css_send_uncached_css($css['plugins']);
4399b9d5
PS
70
71 } else if ($subtype === 'parents') {
72 $sendcss = array();
a6338a13
SH
73 if (empty($sheet)) {
74 // If not specific parent has been specified as $sheet then build a
75 // collection of @import statements into this one sheet.
76 // We shouldn't ever actually get here, but none the less we'll deal
77 // with it incase we ever do.
78 // @import statements arn't processed until after concurrent CSS requests
79 // making them slightly evil.
80 foreach (array_keys($css['parents']) as $sheet) {
81 $sendcss[] = "@import url(styles_debug.php?theme=$themename&type=$type&subtype=$subtype&sheet=$sheet);";
82 }
83 } else {
84 // Build up the CSS for that parent so we can serve it as one file.
85 foreach ($css[$subtype][$sheet] as $parent=>$css) {
86 $sendcss[] = $css;
87 }
4399b9d5 88 }
0e641c74 89 css_send_uncached_css($sendcss);
4399b9d5 90 } else if ($subtype === 'theme') {
0e641c74 91 css_send_uncached_css($css['theme']);
4399b9d5 92 }
c09e1a2c
PS
93
94} else if ($type === 'plugin') {
78946b9b 95 if (isset($css['plugins'][$subtype])) {
0e641c74 96 css_send_uncached_css($css['plugins'][$subtype]);
78946b9b
PS
97 }
98
99} else if ($type === 'parent') {
100 if (isset($css['parents'][$subtype][$sheet])) {
0e641c74 101 css_send_uncached_css($css['parents'][$subtype][$sheet]);
78946b9b
PS
102 }
103
104} else if ($type === 'theme') {
105 if (isset($css['theme'][$sheet])) {
0e641c74 106 css_send_uncached_css($css['theme'][$sheet]);
78946b9b
PS
107 }
108}
0e641c74 109css_send_css_not_found();