MDL-25589 removing extra align value
[moodle.git] / theme / yui_image.php
CommitLineData
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
28define('ABORT_AFTER_CONFIG', true);
29require('../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);
2a102b90
SH
34$version = array_shift($parts);
35
3b17690c 36if ($version == 'moodle' && count($parts) >= 3) {
78bfb562
PS
37 //TODO: this is a ugly hack because we should not load any libs here!
38 define('MOODLE_INTERNAL', true);
3b17690c
SH
39 require_once($CFG->libdir.'/moodlelib.php');
40 $frankenstyle = array_shift($parts);
41 $module = array_shift($parts);
42 $image = array_pop($parts);
43 $subdir = join('/', $parts);
44 $dir = get_component_directory($frankenstyle);
45 $imagepath = $dir.'/yui/'.$module.'/assets/skins/sam/'.$image;
46} else if ($version == 'gallery' && count($parts)==3) {
2a102b90
SH
47 list($module, $version, $image) = $parts;
48 $imagepath = "$CFG->dirroot/lib/yui/gallery/$module/$version/assets/skins/sam/$image";
49} else if (count($parts) == 1 && ($version == $CFG->yui3version || $version == $CFG->yui2version)) {
50 list($image) = $parts;
51 if ($version == $CFG->yui3version) {
52 $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui3version/build/assets/skins/sam/$image";
53 } else {
54 $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui2version/build/assets/skins/sam/$image";
55 }
60f2c866
PS
56} else {
57 yui_image_not_found();
58}
59
60if (!file_exists($imagepath)) {
61 yui_image_not_found();
62}
63
64yui_image_cached($imagepath);
65
66
67
68function yui_image_cached($imagepath) {
69 $lifetime = 60*60*24*300; // 300 days === forever
70 $pathinfo = pathinfo($imagepath);
71 $imagename = $pathinfo['filename'].'.'.$pathinfo['extension'];
72
73 switch($pathinfo['extension']) {
74 case 'gif' : $mimetype = 'image/gif'; break;
75 case 'png' : $mimetype = 'image/png'; break;
76 case 'jpg' : $mimetype = 'image/jpeg'; break;
77 case 'jpeg' : $mimetype = 'image/jpeg'; break;
78 case 'ico' : $mimetype = 'image/vnd.microsoft.icon'; break;
79 default: $mimetype = 'document/unknown';
80 }
81
82 header('Content-Disposition: inline; filename="'.$imagename.'"');
83 header('Last-Modified: '. gmdate('D, d M Y H:i:s', filemtime($imagepath)) .' GMT');
84 header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT');
85 header('Pragma: ');
945f19f7 86 header('Cache-Control: max-age=315360000');
60f2c866
PS
87 header('Accept-Ranges: none');
88 header('Content-Type: '.$mimetype);
89 header('Content-Length: '.filesize($imagepath));
90
7c986f04
PS
91 // no need to gzip already compressed images ;-)
92
60f2c866
PS
93 readfile($imagepath);
94 die;
95}
96
97function yui_image_not_found() {
98 header('HTTP/1.0 404 not found');
99 die('Image was not found, sorry.');
100}