MDL-25505 Tasks: Fix for scheduled task bug on the last day of the month.
[moodle.git] / theme / styles_debug.php
CommitLineData
78946b9b 1<?php
78946b9b
PS
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * This file is responsible for serving of individual style sheets in designer mode.
19 *
574909ef 20 * @package core
78946b9b
PS
21 * @copyright 2009 Petr Skoda (skodak) {@link http://skodak.org}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
2428de82
PS
25// Disable moodle specific debug messages and any errors in output,
26// comment out when debugging or better look into error log!
27define('NO_DEBUG_DISPLAY', true);
73e504bc 28
7829cf79
PS
29define('ABORT_AFTER_CONFIG', true);
30require('../config.php'); // this stops immediately at the beginning of lib/setup.php
0e641c74 31require_once($CFG->dirroot.'/lib/csslib.php');
78946b9b 32
7829cf79 33$themename = min_optional_param('theme', 'standard', 'SAFEDIR');
4399b9d5 34$type = min_optional_param('type', '', 'SAFEDIR');
7829cf79
PS
35$subtype = min_optional_param('subtype', '', 'SAFEDIR');
36$sheet = min_optional_param('sheet', '', 'SAFEDIR');
383b89a1 37$usesvg = (bool)min_optional_param('svg', '1', 'INT');
78946b9b 38
d6b64d15
PS
39if (!defined('THEME_DESIGNER_CACHE_LIFETIME')) {
40 define('THEME_DESIGNER_CACHE_LIFETIME', 4); // this can be also set in config.php
41}
42
73e504bc
PS
43if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
44 // exists
45} else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) {
46 // exists
47} else {
0e641c74 48 css_send_css_not_found();
78946b9b
PS
49}
50
7c986f04
PS
51// no gzip compression when debugging
52
383b89a1
SH
53if ($usesvg) {
54 $candidatesheet = "$CFG->cachedir/theme/$themename/designer.ser";
55} else {
56 // Add to the sheet name, one day we'll be able to just drop this.
57 $candidatesheet = "$CFG->cachedir/theme/$themename/designer_nosvg.ser";
58}
7829cf79 59
2428de82
PS
60$css = false;
61if (is_readable($candidatesheet) and filemtime($candidatesheet) > time() - THEME_DESIGNER_CACHE_LIFETIME) {
62 $css = @unserialize(file_get_contents($candidatesheet));
78946b9b
PS
63}
64
2428de82
PS
65if (!is_array($css)) {
66 // Ok, we need to start normal moodle script, we need to load all libs and $DB.
67 define('ABORT_AFTER_CONFIG_CANCEL', true);
68
69 define('NO_MOODLE_COOKIES', true); // Session not used here.
70 define('NO_UPGRADE_CHECK', true); // Ignore upgrade check.
78946b9b 71
2428de82
PS
72 require("$CFG->dirroot/lib/setup.php");
73 $theme = theme_config::load($themename);
74 $css = $theme->css_content();
75}
78946b9b 76
71be124d
SH
77if ($type === 'editor') {
78 if (isset($css['editor'])) {
0e641c74 79 css_send_uncached_css($css['editor']);
71be124d
SH
80 }
81} else if ($type === 'ie') {
4399b9d5
PS
82 // IE is a sloppy browser with weird limits, sorry
83 if ($subtype === 'plugins') {
0e641c74 84 css_send_uncached_css($css['plugins']);
4399b9d5
PS
85
86 } else if ($subtype === 'parents') {
87 $sendcss = array();
a6338a13
SH
88 if (empty($sheet)) {
89 // If not specific parent has been specified as $sheet then build a
90 // collection of @import statements into this one sheet.
91 // We shouldn't ever actually get here, but none the less we'll deal
92 // with it incase we ever do.
93 // @import statements arn't processed until after concurrent CSS requests
94 // making them slightly evil.
95 foreach (array_keys($css['parents']) as $sheet) {
96 $sendcss[] = "@import url(styles_debug.php?theme=$themename&type=$type&subtype=$subtype&sheet=$sheet);";
97 }
98 } else {
99 // Build up the CSS for that parent so we can serve it as one file.
100 foreach ($css[$subtype][$sheet] as $parent=>$css) {
101 $sendcss[] = $css;
102 }
4399b9d5 103 }
0e641c74 104 css_send_uncached_css($sendcss);
4399b9d5 105 } else if ($subtype === 'theme') {
0e641c74 106 css_send_uncached_css($css['theme']);
4399b9d5 107 }
c09e1a2c
PS
108
109} else if ($type === 'plugin') {
78946b9b 110 if (isset($css['plugins'][$subtype])) {
0e641c74 111 css_send_uncached_css($css['plugins'][$subtype]);
78946b9b
PS
112 }
113
114} else if ($type === 'parent') {
115 if (isset($css['parents'][$subtype][$sheet])) {
0e641c74 116 css_send_uncached_css($css['parents'][$subtype][$sheet]);
78946b9b
PS
117 }
118
119} else if ($type === 'theme') {
120 if (isset($css['theme'][$sheet])) {
0e641c74 121 css_send_uncached_css($css['theme'][$sheet]);
78946b9b
PS
122 }
123}
2428de82 124css_send_css_not_found();