3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * This file is responsible for serving the one huge CSS of each theme.
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 // we need just the values from config.php and minlib.php
28 define('ABORT_AFTER_CONFIG', true);
29 require('../config.php'); // this stops immediately at the beginning of lib/setup.php
31 $themename = min_optional_param('theme', 'standard', 'SAFEDIR');
32 $rev = min_optional_param('rev', 0, 'INT');
34 if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
36 } else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) {
39 header('HTTP/1.0 404 not found');
40 die('Theme was not found, sorry.');
43 $candidate = "$CFG->dataroot/cache/theme/$themename/javascript.js";
45 if ($rev > -1 and file_exists($candidate)) {
46 if (!empty($_SERVER['HTTP_IF_NONE_MATCH'])) {
47 // we do not actually need to verify the etag value because our files
48 // never change in cache because we increment the rev parameter
49 header('HTTP/1.1 304 Not Modified');
52 send_cached_js($candidate, $rev);
55 //=================================================================================
56 // ok, now we need to start normal moodle script, we need to load all libs and $DB
57 define('ABORT_AFTER_CONFIG_CANCEL', true);
59 define('NO_MOODLE_COOKIES', true); // Session not used here
60 define('NO_UPGRADE_CHECK', true); // Ignore upgrade check
62 require("$CFG->dirroot/lib/setup.php");
64 $theme = theme_config::load($themename);
66 $js = $theme->javascript_content();
68 check_dir_exists(dirname($candidate), true, true);
69 $fp = fopen($candidate, 'w');
72 send_cached_js($candidate);
75 send_uncached_js($js);
78 //=================================================================================
79 //=== utility functions ==
80 // we are not using filelib because we need to fine tune all header
81 // parameters to get the best performance.
83 function send_cached_js($jspath) {
84 $lifetime = 60*60*24*20;
86 header('Content-Disposition: inline; filename="javascripts.php"');
87 header('Last-Modified: '. gmdate('D, d M Y H:i:s', filemtime($jspath)) .' GMT');
88 header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT');
90 header('Accept-Ranges: none');
91 header('Content-Type: application/x-javascript');
92 if (!min_enable_zlib_compression()) {
93 header('Content-Length: '.filesize($jspath));
100 function send_uncached_js($js) {
101 header('Content-Disposition: inline; filename="javascripts.php"');
102 header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
103 header('Expires: '. gmdate('D, d M Y H:i:s', time() + 2) .' GMT');
105 header('Accept-Ranges: none');
106 header('Content-Type: application/x-javascript');
107 header('Content-Length: '.strlen($js));