Commit | Line | Data |
---|---|---|
60f2c866 PS |
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 of yui images | |
20 | * | |
21 | * @package moodlecore | |
22 | * @copyright 2009 Petr Skoda (skodak) {@link http://skodak.org} | |
23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
24 | */ | |
25 | ||
26 | ||
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 | |
30 | ||
31 | $path = min_optional_param('file', '', 'SAFEPATH'); | |
32 | ||
33 | $parts = explode('/', $path); | |
34 | if (count($parts) != 2) { | |
35 | yui_image_not_found(); | |
36 | } | |
37 | list($version, $image) = $parts; | |
38 | ||
39 | if ($version == $CFG->yui3version) { | |
aa42314d | 40 | $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui3version/build/assets/skins/sam/$image"; |
60f2c866 | 41 | } else if ($version == $CFG->yui2version) { |
aa42314d | 42 | $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui2version/build/assets/skins/sam/$image"; |
60f2c866 PS |
43 | } else { |
44 | yui_image_not_found(); | |
45 | } | |
46 | ||
47 | if (!file_exists($imagepath)) { | |
48 | yui_image_not_found(); | |
49 | } | |
50 | ||
51 | yui_image_cached($imagepath); | |
52 | ||
53 | ||
54 | ||
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']; | |
59 | ||
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'; | |
67 | } | |
68 | ||
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'); | |
72 | header('Pragma: '); | |
945f19f7 | 73 | header('Cache-Control: max-age=315360000'); |
60f2c866 PS |
74 | header('Accept-Ranges: none'); |
75 | header('Content-Type: '.$mimetype); | |
76 | header('Content-Length: '.filesize($imagepath)); | |
77 | ||
7c986f04 PS |
78 | // no need to gzip already compressed images ;-) |
79 | ||
60f2c866 PS |
80 | readfile($imagepath); |
81 | die; | |
82 | } | |
83 | ||
84 | function yui_image_not_found() { | |
85 | header('HTTP/1.0 404 not found'); | |
86 | die('Image was not found, sorry.'); | |
87 | } |