MDL-20204 first batch of major theme changes, some regressions are still there, expec...
[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
26// no chaching
27define('NO_MOODLE_COOKIES', true); // Session not used here
28define('NO_UPGRADE_CHECK', true); // Ignore upgrade check
29require('../config.php');
30
31$themename = required_param('theme', PARAM_SAFEDIR);
32$type = required_param('type', PARAM_SAFEDIR);
33$subtype = optional_param('subtype', '', PARAM_SAFEDIR);
34$sheet = optional_param('sheet', '', PARAM_SAFEDIR);
35
36if (!file_exists("$CFG->dirroot/theme/$themename/config.php") and !file_exists("$CFG->dataroot/theme/$themename/config.php")) {
37 css_not_found();
38}
39
40if (theme_get_revision() > -1) {
41 //bad luck - this should not happen!
42 css_not_found();
43}
44
45$theme = theme_config::load($themename);
46
47if ($type === 'editor') {
48 $css = $theme->editor_css_content();
49 send_uncached_css($css);
50}
51
52$css = $theme->css_content();
53
54if ($type === 'yui') {
55 send_uncached_css(reset($css['yui']));
56
57} else if ($type === 'plugin') {
58 if (isset($css['plugins'][$subtype])) {
59 send_uncached_css($css['plugins'][$subtype]);
60 }
61
62} else if ($type === 'parent') {
63 if (isset($css['parents'][$subtype][$sheet])) {
64 send_uncached_css($css['parents'][$subtype][$sheet]);
65 }
66
67} else if ($type === 'theme') {
68 if (isset($css['theme'][$sheet])) {
69 send_uncached_css($css['theme'][$sheet]);
70 }
71}
72css_not_found();
73
74//=================================================================================
75//=== utility functions ==
76// we are not using filelib because we need to fine tune all header
77// parameters to get the best performance.
78
79function send_uncached_css($css) {
80 header('Content-Disposition: inline; filename="styles_debug.php"');
81 header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
82 header('Expires: '. gmdate('D, d M Y H:i:s', time() + 2) .' GMT');
83 header('Pragma: ');
84 header('Accept-Ranges: none');
85 header('Content-Type: text/css');
86 header('Content-Length: '.strlen($css));
87
88 while (@ob_end_flush()); //flush the buffers - save memory and disable sid rewrite
89 echo($css);
90 die;
91}
92
93function css_not_found() {
94 header('HTTP/1.0 404 not found');
95 die('CSS was not found, sorry.');
96}