b7009474 |
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 the CSS of each theme. |
20 | * |
21 | * It should not be linked to directly. Instead, it gets included by |
22 | * theme/themename/styles.php. See theme/standard/styles.php as an example. |
23 | * |
24 | * In this script, we are serving the styles for theme $themename, but we are |
25 | * serving them on behalf of theme $fortheme. |
26 | * |
27 | * To understand this, image that the currently selected theme is standardwhite. |
28 | * This theme uses both its own stylesheets, and also the ones from the standard theme. |
29 | * So, when we are serving theme/standard/styles.php, we need to use the config in |
30 | * theme/standardwhite/config.php to control the settings. This is controled by the |
31 | * for=... parameter in the URL. |
32 | * |
33 | * In case you are wondering, in the above scenario, we have to serve the standard |
34 | * theme CSS with a URL like theme/standard/styles.php, so that relative links from |
35 | * the CSS to images in the theme folder will work. |
36 | * |
37 | * @package moodlecore |
38 | * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} |
39 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
40 | */ |
41 | |
42 | if (empty($themename)) { |
43 | die('Direct access to this script is forbidden.'); |
44 | // This script should only be required by theme/themename/styles.php. |
45 | } |
46 | |
47 | // These may already be defined if we got here via style_sheet_setup in lib/deprecatedlib.php |
48 | if (!defined('NO_MOODLE_COOKIES')) { |
49 | define('NO_MOODLE_COOKIES', true); // Session not used here |
50 | } |
51 | if (!defined('NO_UPGRADE_CHECK')) { |
52 | define('NO_UPGRADE_CHECK', true); // Ignore upgrade check |
53 | } |
54 | require_once(dirname(__FILE__) . '/../config.php'); |
55 | |
56 | |
57 | $fortheme = required_param('for', PARAM_FILE); |
fdeb7fa1 |
58 | $pluginsheets = optional_param('pluginsheets', '', PARAM_BOOL); |
b7009474 |
59 | |
40427883 |
60 | // Load the configuration of the selected theme. (See comment at the top of the file.) |
61 | $PAGE->force_theme($fortheme); |
62 | |
b7009474 |
63 | $DEFAULT_SHEET_LIST = array('styles_layout', 'styles_fonts', 'styles_color'); |
64 | |
65 | // Fix for IE6 caching - we don't want the filemtime('styles.php'), instead use now. |
66 | $lastmodified = time(); |
67 | |
68 | // Set the correct content type. (Should we also be specifying charset here?) |
aa6c1ced |
69 | header('Content-type: text/css'); |
40427883 |
70 | header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $lastmodified) . ' GMT'); |
71 | header('Pragma: '); |
72 | |
73 | // Set the caching for these style sheets |
74 | if (debugging('', DEBUG_DEVELOPER)) { // Use very short caching time |
75 | header('Cache-Control: max-age=60'); // One minute |
76 | header('Expires: ' . gmdate("D, d M Y H:i:s", $lastmodified + 60) . ' GMT'); |
77 | } else if ($themename == 'standard') { // Give this one extra long caching MDL-19953 |
78 | header('Cache-Control: max-age=172801'); // Two days plus one second |
79 | header('Expires: ' . gmdate("D, d M Y H:i:s", $lastmodified + 172801) . ' GMT'); |
80 | } else { // Use whatever time the theme has set |
81 | header('Cache-Control: max-age='.$THEME->csslifetime); |
82 | header('Expires: ' . gmdate("D, d M Y H:i:s", $lastmodified + $THEME->csslifetime) . ' GMT'); |
b7009474 |
83 | } |
84 | |
85 | if (!empty($showdeprecatedstylesheetsetupwarning)) { |
86 | echo <<<END |
87 | |
88 | /*************************************************************** |
89 | *************************************************************** |
90 | **** **** |
91 | **** WARNING! This theme uses an old-fashioned styles.php **** |
92 | **** file. It should be updated by copying styles.php from **** |
93 | **** the standard theme of a recent version of Moodle. **** |
94 | **** **** |
95 | *************************************************************** |
96 | ***************************************************************/ |
97 | |
98 | |
99 | |
100 | END; |
101 | } |
102 | |
fdeb7fa1 |
103 | // This is a bit tricky, but the following initialisation code may output |
104 | // notices or debug developer warnings (for example, if the theme uses some |
105 | // Deprecated settings in it config.php file. Therefore start a CSS comment |
106 | // so that any debugging output does not break the CSS. This comment is closed |
107 | // below. |
108 | echo '/*'; |
109 | |
110 | |
b7009474 |
111 | |
fdeb7fa1 |
112 | // We will build up a list of CSS file path names, then concatenate them all. |
113 | $files = array(); |
114 | |
115 | // If this theme wants plugin sheets, include them. Do this first, so styles |
116 | // here can be overridden by theme CSS. |
117 | if ($pluginsheets) { |
118 | foreach ($THEME->pluginsheets as $plugintype) { |
1a192cf0 |
119 | $files = array_merge($files, get_sheets_for_plugin_type($plugintype)); |
fdeb7fa1 |
120 | } |
121 | } |
122 | |
b7009474 |
123 | // Now work out which stylesheets we shold be serving from this theme. |
124 | if ($themename == $fortheme) { |
125 | $themesheets = $THEME->sheets; |
126 | |
127 | } else if (!empty($THEME->parent) && $themename == $THEME->parent) { |
128 | if ($THEME->parentsheets === true) { |
129 | // Use all the sheets we have. |
130 | $themesheets = $DEFAULT_SHEET_LIST; |
131 | } else if (!empty($THEME->parentsheets)) { |
132 | $themesheets = $THEME->parentsheets; |
133 | } else { |
fdeb7fa1 |
134 | $themesheets = array(); |
b7009474 |
135 | } |
136 | |
137 | } else if ($themename == 'standard') { |
138 | if ($THEME->standardsheets === true) { |
139 | // Use all the sheets we have. |
140 | $themesheets = $DEFAULT_SHEET_LIST; |
141 | } else if (!empty($THEME->standardsheets)) { |
142 | $themesheets = $THEME->standardsheets; |
143 | } else { |
fdeb7fa1 |
144 | $themesheets = array(); |
b7009474 |
145 | } |
146 | } |
147 | |
fdeb7fa1 |
148 | // Conver the theme stylessheet names to file names. |
b7009474 |
149 | foreach ($themesheets as $sheet) { |
150 | $files[] = $CFG->themedir . '/' . $themename . '/' . $sheet . '.css'; |
151 | } |
152 | |
b7009474 |
153 | if (empty($files)) { |
fdeb7fa1 |
154 | echo " The $fortheme theme does not require anything from the $themename theme. */\n\n"; |
b7009474 |
155 | exit; |
156 | } |
157 | |
158 | // Output a commen with a summary of the included files. |
159 | echo <<<END |
fdeb7fa1 |
160 | |
b7009474 |
161 | * Styles from theme '$themename' for theme '$fortheme' |
162 | * |
163 | * Files included here: |
164 | * |
165 | |
166 | END; |
fdeb7fa1 |
167 | $toreplace = array($CFG->dirroot . '/', $CFG->themedir . '/'); |
b7009474 |
168 | foreach ($files as $file) { |
169 | echo ' * ' . str_replace($toreplace, '', $file) . "\n"; |
170 | } |
171 | echo " */\n\n"; |
172 | |
173 | if (!empty($THEME->cssoutputfunction)) { |
fdeb7fa1 |
174 | call_user_func($THEME->cssoutputfunction, $files, $toreplace); |
b7009474 |
175 | |
176 | } else { |
177 | foreach ($files as $file) { |
178 | $shortname = str_replace($toreplace, '', $file); |
179 | echo '/******* ' . $shortname . " start *******/\n\n"; |
180 | @include_once($file); |
181 | echo '/******* ' . $shortname . " end *******/\n\n"; |
182 | } |
183 | } |
184 | |
185 | function get_sheets_for_plugin_type($type) { |
186 | $files = array(); |
187 | $mods = get_plugin_list($type); |
188 | foreach ($mods as $moddir) { |
189 | $file = $moddir . '/styles.php'; |
190 | if (file_exists($file)) { |
191 | $files[] = $file; |
192 | } |
193 | } |
194 | return $files; |
195 | } |