MDL-26030 update filter regex and create unittest for filter mediaplugin
[moodle.git] / theme / styles_debug.php
blob25a50e6a9b2a3817a3a754ad82b3c42e4b0ee3f5
1 <?php
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.
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/>.
18 /**
19 * This file is responsible for serving of individual style sheets in designer mode.
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
27 define('ABORT_AFTER_CONFIG', true);
28 require('../config.php'); // this stops immediately at the beginning of lib/setup.php
30 $themename = min_optional_param('theme', 'standard', 'SAFEDIR');
31 $type = min_optional_param('type', '', 'SAFEDIR');
32 $subtype = min_optional_param('subtype', '', 'SAFEDIR');
33 $sheet = min_optional_param('sheet', '', 'SAFEDIR');
35 if (!defined('THEME_DESIGNER_CACHE_LIFETIME')) {
36 define('THEME_DESIGNER_CACHE_LIFETIME', 4); // this can be also set in config.php
39 if (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 {
44 css_not_found();
47 // no gzip compression when debugging
49 $candidatesheet = "$CFG->dataroot/cache/theme/$themename/designer.ser";
51 if (!file_exists($candidatesheet)) {
52 css_not_found();
55 if (!$css = file_get_contents($candidatesheet)) {
56 css_not_found();
59 $css = unserialize($css);
61 if ($type === 'editor') {
62 if (isset($css['editor'])) {
63 send_uncached_css(implode("\n\n", $css['editor']));
65 } else if ($type === 'ie') {
66 // IE is a sloppy browser with weird limits, sorry
67 if ($subtype === 'plugins') {
68 $sendcss = implode("\n\n", $css['plugins']);
69 $sendcss = str_replace("\n", "\r\n", $sendcss);
70 send_uncached_css($sendcss);
72 } else if ($subtype === 'parents') {
73 $sendcss = array();
74 if (empty($sheet)) {
75 // If not specific parent has been specified as $sheet then build a
76 // collection of @import statements into this one sheet.
77 // We shouldn't ever actually get here, but none the less we'll deal
78 // with it incase we ever do.
79 // @import statements arn't processed until after concurrent CSS requests
80 // making them slightly evil.
81 foreach (array_keys($css['parents']) as $sheet) {
82 $sendcss[] = "@import url(styles_debug.php?theme=$themename&type=$type&subtype=$subtype&sheet=$sheet);";
84 } else {
85 // Build up the CSS for that parent so we can serve it as one file.
86 foreach ($css[$subtype][$sheet] as $parent=>$css) {
87 $sendcss[] = $css;
90 $sendcss = implode("\n\n", $sendcss);
91 $sendcss = str_replace("\n", "\r\n", $sendcss);
92 send_uncached_css($sendcss);
94 } else if ($subtype === 'theme') {
95 $sendcss = implode("\n\n", $css['theme']);
96 $sendcss = str_replace("\n", "\r\n", $sendcss);
97 send_uncached_css($sendcss);
100 } else if ($type === 'plugin') {
101 if (isset($css['plugins'][$subtype])) {
102 send_uncached_css($css['plugins'][$subtype]);
105 } else if ($type === 'parent') {
106 if (isset($css['parents'][$subtype][$sheet])) {
107 send_uncached_css($css['parents'][$subtype][$sheet]);
110 } else if ($type === 'theme') {
111 if (isset($css['theme'][$sheet])) {
112 send_uncached_css($css['theme'][$sheet]);
115 css_not_found();
117 //=================================================================================
118 //=== utility functions ==
119 // we are not using filelib because we need to fine tune all header
120 // parameters to get the best performance.
122 function send_uncached_css($css) {
123 header('Content-Disposition: inline; filename="styles_debug.php"');
124 header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
125 header('Expires: '. gmdate('D, d M Y H:i:s', time() + THEME_DESIGNER_CACHE_LIFETIME) .' GMT');
126 header('Pragma: ');
127 header('Accept-Ranges: none');
128 header('Content-Type: text/css; charset=utf-8');
129 //header('Content-Length: '.strlen($css));
131 echo($css);
132 die;
135 function css_not_found() {
136 header('HTTP/1.0 404 not found');
137 die('CSS was not found, sorry.');