|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 // we need just the values from config.php and minlib.php 00028 define('ABORT_AFTER_CONFIG', true); 00029 require('../config.php'); // this stops immediately at the beginning of lib/setup.php 00030 00031 $path = min_optional_param('file', '', 'SAFEPATH'); 00032 00033 $parts = explode('/', $path); 00034 $version = array_shift($parts); 00035 00036 if ($version == 'moodle' && count($parts) >= 3) { 00037 //TODO: this is a ugly hack because we should not load any libs here! 00038 define('MOODLE_INTERNAL', true); 00039 require_once($CFG->libdir.'/moodlelib.php'); 00040 $frankenstyle = array_shift($parts); 00041 $module = array_shift($parts); 00042 $image = array_pop($parts); 00043 $subdir = join('/', $parts); 00044 $dir = get_component_directory($frankenstyle); 00045 $imagepath = $dir.'/yui/'.$module.'/assets/skins/sam/'.$image; 00046 } else if ($version == 'gallery' && count($parts)==3) { 00047 list($module, $version, $image) = $parts; 00048 $imagepath = "$CFG->dirroot/lib/yui/gallery/$module/$version/assets/skins/sam/$image"; 00049 } else if (count($parts) == 1 && ($version == $CFG->yui3version || $version == $CFG->yui2version)) { 00050 list($image) = $parts; 00051 if ($version == $CFG->yui3version) { 00052 $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui3version/build/assets/skins/sam/$image"; 00053 } else { 00054 $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui2version/build/assets/skins/sam/$image"; 00055 } 00056 } else { 00057 yui_image_not_found(); 00058 } 00059 00060 if (!file_exists($imagepath)) { 00061 yui_image_not_found(); 00062 } 00063 00064 yui_image_cached($imagepath); 00065 00066 00067 00068 function yui_image_cached($imagepath) { 00069 $lifetime = 60*60*24*300; // 300 days === forever 00070 $pathinfo = pathinfo($imagepath); 00071 $imagename = $pathinfo['filename'].'.'.$pathinfo['extension']; 00072 00073 switch($pathinfo['extension']) { 00074 case 'gif' : $mimetype = 'image/gif'; break; 00075 case 'png' : $mimetype = 'image/png'; break; 00076 case 'jpg' : $mimetype = 'image/jpeg'; break; 00077 case 'jpeg' : $mimetype = 'image/jpeg'; break; 00078 case 'ico' : $mimetype = 'image/vnd.microsoft.icon'; break; 00079 default: $mimetype = 'document/unknown'; 00080 } 00081 00082 header('Content-Disposition: inline; filename="'.$imagename.'"'); 00083 header('Last-Modified: '. gmdate('D, d M Y H:i:s', filemtime($imagepath)) .' GMT'); 00084 header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT'); 00085 header('Pragma: '); 00086 header('Cache-Control: max-age=315360000'); 00087 header('Accept-Ranges: none'); 00088 header('Content-Type: '.$mimetype); 00089 header('Content-Length: '.filesize($imagepath)); 00090 00091 // no need to gzip already compressed images ;-) 00092 00093 readfile($imagepath); 00094 die; 00095 } 00096 00097 function yui_image_not_found() { 00098 header('HTTP/1.0 404 not found'); 00099 die('Image was not found, sorry.'); 00100 }