fixed borked insatll.xml, thanks Dan Marsden!
[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 30$themename = min_optional_param('theme', 'standard', 'SAFEDIR');
4399b9d5 31$type = min_optional_param('type', '', 'SAFEDIR');
7829cf79
PS
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
c09e1a2c 61if ($type === 'ie') {
4399b9d5
PS
62 // IE is a sloppy browser with weird limits, sorry
63 if ($subtype === 'plugins') {
64 $sendcss = implode("\n\n", $css['plugins']);
65 $sendcss = str_replace("\n", "\r\n", $sendcss);
66 send_uncached_css($sendcss);
67
68 } else if ($subtype === 'parents') {
69 $sendcss = array();
70 foreach ($css['parents'] as $parent=>$sheets) {
71 $sendcss = array_merge($sendcss, $sheets);
72 }
73 $sendcss = implode("\n\n", $sendcss);
74 $sendcss = str_replace("\n", "\r\n", $sendcss);
75 send_uncached_css($sendcss);
76
77 } else if ($subtype === 'theme') {
78 $sendcss = implode("\n\n", $css['theme']);
79 $sendcss = str_replace("\n", "\r\n", $sendcss);
80 send_uncached_css($sendcss);
81 }
c09e1a2c
PS
82
83} else if ($type === 'plugin') {
78946b9b
PS
84 if (isset($css['plugins'][$subtype])) {
85 send_uncached_css($css['plugins'][$subtype]);
86 }
87
88} else if ($type === 'parent') {
89 if (isset($css['parents'][$subtype][$sheet])) {
7829cf79 90 send_uncached_css($css['parents'][$subtype][$sheet], 30); // parent sheets are not supposed to change much, right?
78946b9b
PS
91 }
92
93} else if ($type === 'theme') {
94 if (isset($css['theme'][$sheet])) {
95 send_uncached_css($css['theme'][$sheet]);
96 }
97}
98css_not_found();
99
100//=================================================================================
101//=== utility functions ==
102// we are not using filelib because we need to fine tune all header
103// parameters to get the best performance.
104
c09e1a2c 105function send_uncached_css($css) {
78946b9b
PS
106 header('Content-Disposition: inline; filename="styles_debug.php"');
107 header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
c09e1a2c 108 header('Expires: '. gmdate('D, d M Y H:i:s', time() + THEME_DESIGNER_CACHE_LIFETIME) .' GMT');
78946b9b
PS
109 header('Pragma: ');
110 header('Accept-Ranges: none');
111 header('Content-Type: text/css');
7c986f04 112 //header('Content-Length: '.strlen($css));
78946b9b 113
78946b9b
PS
114 echo($css);
115 die;
116}
117
118function css_not_found() {
119 header('HTTP/1.0 404 not found');
120 die('CSS was not found, sorry.');
c09e1a2c
PS
121}
122