MDL-21392 it is possible to have settings without Save button
[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
78946b9b 29
7829cf79
PS
30$themename = min_optional_param('theme', 'standard', 'SAFEDIR');
31$type = min_optional_param('type', 'all', 'SAFEDIR');
32$subtype = min_optional_param('subtype', '', 'SAFEDIR');
33$sheet = min_optional_param('sheet', '', 'SAFEDIR');
78946b9b 34
d6b64d15
PS
35if (!defined('THEME_DESIGNER_CACHE_LIFETIME')) {
36 define('THEME_DESIGNER_CACHE_LIFETIME', 4); // this can be also set in config.php
37}
38
73e504bc
PS
39if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
40 // exists
41} else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) {
42 // exists
43} else {
78946b9b
PS
44 css_not_found();
45}
46
7c986f04
PS
47// no gzip compression when debugging
48
7829cf79
PS
49$candidatesheet = "$CFG->dataroot/cache/theme/$themename/designer.ser";
50
51if (!file_exists($candidatesheet)) {
78946b9b
PS
52 css_not_found();
53}
54
7829cf79
PS
55if (!$css = file_get_contents($candidatesheet)) {
56 css_not_found();
78946b9b
PS
57}
58
7829cf79 59$css = unserialize($css);
78946b9b 60
c724f835 61if ($type === 'plugin') {
78946b9b
PS
62 if (isset($css['plugins'][$subtype])) {
63 send_uncached_css($css['plugins'][$subtype]);
64 }
65
66} else if ($type === 'parent') {
67 if (isset($css['parents'][$subtype][$sheet])) {
7829cf79 68 send_uncached_css($css['parents'][$subtype][$sheet], 30); // parent sheets are not supposed to change much, right?
78946b9b
PS
69 }
70
71} else if ($type === 'theme') {
72 if (isset($css['theme'][$sheet])) {
73 send_uncached_css($css['theme'][$sheet]);
74 }
75}
76css_not_found();
77
78//=================================================================================
79//=== utility functions ==
80// we are not using filelib because we need to fine tune all header
81// parameters to get the best performance.
82
d6b64d15 83function send_uncached_css($css, $lifetime = THEME_DESIGNER_CACHE_LIFETIME) {
78946b9b
PS
84 header('Content-Disposition: inline; filename="styles_debug.php"');
85 header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
7829cf79 86 header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT');
78946b9b
PS
87 header('Pragma: ');
88 header('Accept-Ranges: none');
89 header('Content-Type: text/css');
7c986f04 90 //header('Content-Length: '.strlen($css));
78946b9b 91
78946b9b
PS
92 echo($css);
93 die;
94}
95
96function css_not_found() {
97 header('HTTP/1.0 404 not found');
98 die('CSS was not found, sorry.');
99}