forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
styles_debug.php
109 lines (92 loc) · 3.71 KB
/
styles_debug.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file is responsible for serving of individual style sheets in designer mode.
*
* @package moodlecore
* @copyright 2009 Petr Skoda (skodak) {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('ABORT_AFTER_CONFIG', true);
require('../config.php'); // this stops immediately at the beginning of lib/setup.php
require_once($CFG->dirroot.'/lib/csslib.php');
$themename = min_optional_param('theme', 'standard', 'SAFEDIR');
$type = min_optional_param('type', '', 'SAFEDIR');
$subtype = min_optional_param('subtype', '', 'SAFEDIR');
$sheet = min_optional_param('sheet', '', 'SAFEDIR');
if (!defined('THEME_DESIGNER_CACHE_LIFETIME')) {
define('THEME_DESIGNER_CACHE_LIFETIME', 4); // this can be also set in config.php
}
if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
// exists
} else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) {
// exists
} else {
css_send_css_not_found();
}
// no gzip compression when debugging
$candidatesheet = "$CFG->cachedir/theme/$themename/designer.ser";
if (!file_exists($candidatesheet)) {
css_send_css_not_found();
}
if (!$css = file_get_contents($candidatesheet)) {
css_send_css_not_found();
}
$css = unserialize($css);
if ($type === 'editor') {
if (isset($css['editor'])) {
css_send_uncached_css($css['editor']);
}
} else if ($type === 'ie') {
// IE is a sloppy browser with weird limits, sorry
if ($subtype === 'plugins') {
css_send_uncached_css($css['plugins']);
} else if ($subtype === 'parents') {
$sendcss = array();
if (empty($sheet)) {
// If not specific parent has been specified as $sheet then build a
// collection of @import statements into this one sheet.
// We shouldn't ever actually get here, but none the less we'll deal
// with it incase we ever do.
// @import statements arn't processed until after concurrent CSS requests
// making them slightly evil.
foreach (array_keys($css['parents']) as $sheet) {
$sendcss[] = "@import url(styles_debug.php?theme=$themename&type=$type&subtype=$subtype&sheet=$sheet);";
}
} else {
// Build up the CSS for that parent so we can serve it as one file.
foreach ($css[$subtype][$sheet] as $parent=>$css) {
$sendcss[] = $css;
}
}
css_send_uncached_css($sendcss);
} else if ($subtype === 'theme') {
css_send_uncached_css($css['theme']);
}
} else if ($type === 'plugin') {
if (isset($css['plugins'][$subtype])) {
css_send_uncached_css($css['plugins'][$subtype]);
}
} else if ($type === 'parent') {
if (isset($css['parents'][$subtype][$sheet])) {
css_send_uncached_css($css['parents'][$subtype][$sheet]);
}
} else if ($type === 'theme') {
if (isset($css['theme'][$sheet])) {
css_send_uncached_css($css['theme'][$sheet]);
}
}
css_send_css_not_found();