3 // User icon serving script.
4 // Usage: http://URL/_icon/user/{icon_id}
7 define("context","icons");
8 require_once(dirname(dirname(__FILE__
))."/includes.php");
10 // If an ID number for the file has been specified ...
11 $id = optional_param('id',0,PARAM_INT
);
16 // ... and the file exists ...
17 if (!$file = get_record('icons','ident',$id)) {
20 // get the user who belongs to this icon..
21 if (empty($file) ||
!$user = get_record('users','ident',$file->owner
)) {
25 $upload_folder = substr($user->username
,0,1);
26 $filepath = $CFG->dataroot
. "icons/" . $upload_folder . "/" . $user->username
. "/".$file->filename
;
27 if (!file_exists($filepath)) {
32 require_once($CFG->dirroot
. 'lib/filelib.php');
33 require_once($CFG->dirroot
. 'lib/iconslib.php');
36 $filepath = $CFG->dirroot
.'_icons/data/default.png';
37 $mimetype = 'image/png';
39 $mimetype = mimeinfo('type', $file->filename
);
43 // Then output some appropriate headers and send the file data!
45 // see if we must resize it.
46 $constraint1 = strtolower(optional_param('constraint1'));
47 $size1 = optional_param('size1', PARAM_INT
);
48 $constraint2 = strtolower(optional_param('constraint2'));
49 $size2 = optional_param('size2', PARAM_INT
);
51 // if size == 100, leave it.
53 $phpthumbconfig = array();
54 if (($constraint1 == 'h' ||
$constraint1 == 'w') && $size1 != 100) {
56 $phpthumbconfig[$constraint1] = $size1;
58 if (($constraint2 == 'h' ||
$constraint2 == 'w') && $size2 != 100) {
60 $phpthumbconfig[$constraint2] = $size2;
63 // images most likely don't want compressing, and this will kill the Vary header
64 if (function_exists('apache_setenv')) { // apparently @ isn't enough to make php ignore this failing
65 @apache_setenv
('no-gzip', '1');
68 // user icons are public
69 header("Pragma: public");
70 header("Cache-Control: public");
72 if (!$default && !$phpthumb && ($constraint1 == 'h' ||
$constraint1 == 'w') && (!$constraint2 ||
$constraint2 == 'h' ||
$constraint2 == 'w')) {
73 // 100 pixels requested, redirect to attributeless icon url for cacheability fun
74 header($_SERVER['SERVER_PROTOCOL'] . " 301 Moved Permanently");
75 header("Location: " . $CFG->wwwroot
. '_icon/user/' . $id);
80 // let phpthumb manipulate the image
81 spit_phpthumb_image($filepath, $phpthumbconfig);
83 // no manipulation and default icon
85 header($_SERVER['SERVER_PROTOCOL'] . " 301 Moved Permanently");
87 header("Location: " . $CFG->wwwroot
. '_icons/data/default.png');
90 // output the image directly
91 spitfile_with_mtime_check ($filepath, $mimetype);