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 of yui images
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 $path = min_optional_param('file', '', 'SAFEPATH');
33 $parts = explode('/', $path);
34 if (count($parts) != 2) {
35 yui_image_not_found();
37 list($version, $image) = $parts;
39 if ($version == $CFG->yui3version
) {
40 $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui3version/build/assets/skins/sam/$image";
41 } else if ($version == $CFG->yui2version
) {
42 $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui2version/build/assets/skins/sam/$image";
44 yui_image_not_found();
47 if (!file_exists($imagepath)) {
48 yui_image_not_found();
51 yui_image_cached($imagepath);
55 function yui_image_cached($imagepath) {
56 $lifetime = 60*60*24*300; // 300 days === forever
57 $pathinfo = pathinfo($imagepath);
58 $imagename = $pathinfo['filename'].'.'.$pathinfo['extension'];
60 switch($pathinfo['extension']) {
61 case 'gif' : $mimetype = 'image/gif'; break;
62 case 'png' : $mimetype = 'image/png'; break;
63 case 'jpg' : $mimetype = 'image/jpeg'; break;
64 case 'jpeg' : $mimetype = 'image/jpeg'; break;
65 case 'ico' : $mimetype = 'image/vnd.microsoft.icon'; break;
66 default: $mimetype = 'document/unknown';
69 header('Content-Disposition: inline; filename="'.$imagename.'"');
70 header('Last-Modified: '. gmdate('D, d M Y H:i:s', filemtime($imagepath)) .' GMT');
71 header('Expires: '. gmdate('D, d M Y H:i:s', time() +
$lifetime) .' GMT');
73 header('Cache-Control: max-age=315360000');
74 header('Accept-Ranges: none');
75 header('Content-Type: '.$mimetype);
76 header('Content-Length: '.filesize($imagepath));
78 // no need to gzip already compressed images ;-)
84 function yui_image_not_found() {
85 header('HTTP/1.0 404 not found');
86 die('Image was not found, sorry.');