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); |
58 | $lang = optional_param('lang', '', PARAM_FILE); |
59 | |
60 | $CACHE_LIFETIME = 1800; // Cache stylesheets for half an hour. |
61 | $DEFAULT_SHEET_LIST = array('styles_layout', 'styles_fonts', 'styles_color'); |
62 | |
63 | // Fix for IE6 caching - we don't want the filemtime('styles.php'), instead use now. |
64 | $lastmodified = time(); |
65 | |
66 | // Set the correct content type. (Should we also be specifying charset here?) |
67 | header('Content-type: text/css'); |
68 | if (!debugging('', DEBUG_DEVELOPER)) { |
69 | // Do not send caching headers for developer. (This makes it easy to edit themes. |
70 | // You don't have to keep clearing the browser cache.) |
71 | header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $lastmodified) . ' GMT'); |
72 | header('Expires: ' . gmdate("D, d M Y H:i:s", $lastmodified + $CACHE_LIFETIME) . ' GMT'); |
73 | header('Cache-Control: max-age=' . $lifetime); |
74 | header('Pragma: '); |
75 | } |
76 | |
77 | if (!empty($showdeprecatedstylesheetsetupwarning)) { |
78 | echo <<<END |
79 | |
80 | /*************************************************************** |
81 | *************************************************************** |
82 | **** **** |
83 | **** WARNING! This theme uses an old-fashioned styles.php **** |
84 | **** file. It should be updated by copying styles.php from **** |
85 | **** the standard theme of a recent version of Moodle. **** |
86 | **** **** |
87 | *************************************************************** |
88 | ***************************************************************/ |
89 | |
90 | |
91 | |
92 | END; |
93 | } |
94 | |
95 | // Load the configuration of the selected theme. (See comment at the top of the file.) |
96 | $PAGE->force_theme($fortheme); |
97 | |
98 | // Now work out which stylesheets we shold be serving from this theme. |
99 | if ($themename == $fortheme) { |
100 | $themesheets = $THEME->sheets; |
101 | |
102 | } else if (!empty($THEME->parent) && $themename == $THEME->parent) { |
103 | if ($THEME->parentsheets === true) { |
104 | // Use all the sheets we have. |
105 | $themesheets = $DEFAULT_SHEET_LIST; |
106 | } else if (!empty($THEME->parentsheets)) { |
107 | $themesheets = $THEME->parentsheets; |
108 | } else { |
109 | echo "/* The current theme does not require anything from the standard theme. */\n\n"; |
110 | exit; |
111 | } |
112 | |
113 | } else if ($themename == 'standard') { |
114 | if ($THEME->standardsheets === true) { |
115 | // Use all the sheets we have. |
116 | $themesheets = $DEFAULT_SHEET_LIST; |
117 | } else if (!empty($THEME->standardsheets)) { |
118 | $themesheets = $THEME->standardsheets; |
119 | } else { |
120 | echo "/* The current theme does not require anything from the standard theme. */\n\n"; |
121 | exit; |
122 | } |
123 | } |
124 | |
125 | // Conver the sheet names to file names. |
126 | $files = array(); |
127 | foreach ($themesheets as $sheet) { |
128 | $files[] = $CFG->themedir . '/' . $themename . '/' . $sheet . '.css'; |
129 | } |
130 | |
131 | // If this is the standard theme, then also include the styles.php files from |
132 | // each of the plugins, as determined by the theme settings. |
133 | if ($themename == 'standard') { |
134 | if (!empty($THEME->modsheets)) { |
135 | $files += get_sheets_for_plugin_type('mod'); |
136 | } |
137 | |
138 | if (!empty($THEME->blocksheets)) { |
139 | $files += get_sheets_for_plugin_type('block'); |
140 | } |
141 | |
142 | if (!empty($THEME->courseformatsheets)) { |
143 | $files += get_sheets_for_plugin_type('format'); |
144 | } |
145 | |
146 | if (!empty($THEME->gradereportsheets)) { |
147 | $files += get_sheets_for_plugin_type('gradereport'); |
148 | } |
149 | |
150 | if (!empty($THEME->langsheets) && $lang) { |
151 | $file = $CFG->dirroot . '/lang/' . $lang . '/styles.php'; |
152 | if (file_exists($file)) { |
153 | $files[] = $file; |
154 | } |
155 | } |
156 | } |
157 | |
158 | if (empty($files)) { |
159 | echo "/* The current theme does not require anything from this theme. */\n\n"; |
160 | exit; |
161 | } |
162 | |
163 | // Output a commen with a summary of the included files. |
164 | echo <<<END |
165 | /* |
166 | * Styles from theme '$themename' for theme '$fortheme' |
167 | * |
168 | * Files included here: |
169 | * |
170 | |
171 | END; |
172 | $toreplace = array($CFG->dirroot, $CFG->themedir); |
173 | foreach ($files as $file) { |
174 | echo ' * ' . str_replace($toreplace, '', $file) . "\n"; |
175 | } |
176 | echo " */\n\n"; |
177 | |
178 | if (!empty($THEME->cssoutputfunction)) { |
179 | call_user_func($THEME->cssoutputfunction, $files); |
180 | |
181 | } else { |
182 | foreach ($files as $file) { |
183 | $shortname = str_replace($toreplace, '', $file); |
184 | echo '/******* ' . $shortname . " start *******/\n\n"; |
185 | @include_once($file); |
186 | echo '/******* ' . $shortname . " end *******/\n\n"; |
187 | } |
188 | } |
189 | |
190 | function get_sheets_for_plugin_type($type) { |
191 | $files = array(); |
192 | $mods = get_plugin_list($type); |
193 | foreach ($mods as $moddir) { |
194 | $file = $moddir . '/styles.php'; |
195 | if (file_exists($file)) { |
196 | $files[] = $file; |
197 | } |
198 | } |
199 | return $files; |
200 | } |