. /** * This file is serving optimised JS * * @package moodlecore * @copyright 2010 Petr Skoda (skodak) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ // we need just the values from config.php and minlib.php define('ABORT_AFTER_CONFIG', true); require('../config.php'); // this stops immediately at the beginning of lib/setup.php $file = min_optional_param('file', '', 'SAFEPATH'); $rev = min_optional_param('rev', 0, 'INT'); $jspath = $CFG->dirroot.$file; if (empty($file) or strpos($file, '/') !== 0 or !preg_match('/\.js$/', $file) or !file_exists($jspath)) { header('HTTP/1.0 404 not found'); die('JS file was not found, sorry.'); } send_cached_js($jspath); //================================================================================= //=== utility functions == // we are not using filelib because we need to fine tune all header // parameters to get the best performance. function send_cached_js($jspath) { $lifetime = 60*60*24*20; header('Content-Disposition: inline; filename="javascript.php"'); header('Last-Modified: '. gmdate('D, d M Y H:i:s', filemtime($jspath)) .' GMT'); header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT'); header('Pragma: '); header('Accept-Ranges: none'); header('Content-Type: application/x-javascript'); if (!min_enable_zlib_compression()) { header('Content-Length: '.filesize($jspath)); } readfile($jspath); die; }