root/devel/mod/profile_photo/img.php

Revision 1537, 2.6 kB (checked in by renato, 10 months ago)

Setting prop svn:eol-style in profile_photo files.

  • Property svn:eol-style set to native
Line 
1 <?php
2
3 // User icon serving script.
4 // Usage: http://URL/_icon/user/{icon_id}
5
6 // Run includes
7 //define("context","icons");
8 require_once("../../includes.php");
9
10 global $CFG;
11
12 // If an ID number for the file has been specified ...
13 $id = optional_param('id',0,PARAM_INT);
14 $default = false;
15 if (!$id) {
16     $default = true;
17 }
18 // ... and the file exists ...
19 if (!$file = get_record('profile_data','ident',$id)) {
20     $default = true;
21 }
22 if (!$default) {
23     $filepath = $CFG->dataroot . $file->value;
24     if (!file_exists($filepath)) {
25         $default = true;
26     }
27 }
28
29 require_once($CFG->dirroot . 'lib/filelib.php');
30 require_once($CFG->dirroot . 'lib/iconslib.php');
31     
32 if ($default) {
33     $filepath = $CFG->dirroot.'_icons/data/default.png';
34     $mimetype = 'image/png';
35 } else {
36     $mimetype = mimeinfo('type', $file->value);
37 }
38
39
40 // Then output some appropriate headers and send the file data!
41
42 // see if we must resize it.
43 $constraint1 = strtolower(optional_param('constraint1'));
44 $size1 = optional_param('size1', PARAM_INT);
45 $constraint2 = strtolower(optional_param('constraint2'));
46 $size2 = optional_param('size2', PARAM_INT);
47
48 // if size == 100, leave it.
49 $phpthumb = false;
50 $phpthumbconfig = array();
51 if (($constraint1 == 'h' || $constraint1 == 'w') && $size1 != 100) {
52     $phpthumb = true;
53     $phpthumbconfig[$constraint1] = $size1;
54 }
55 if (($constraint2 == 'h' || $constraint2 == 'w') && $size2 != 100) {
56     $phpthumb = true;
57     $phpthumbconfig[$constraint2] = $size2;
58 }
59
60 // images most likely don't want compressing, and this will kill the Vary header
61 if (function_exists('apache_setenv')) { // apparently @ isn't enough to make php ignore this failing
62     @apache_setenv('no-gzip', '1');
63 }
64
65 // user icons are public
66 header("Pragma: public");
67 header("Cache-Control: public");
68
69 if (!$default && !$phpthumb && ($constraint1 == 'h' || $constraint1 == 'w') && (!$constraint2 || $constraint2 == 'h' || $constraint2 == 'w')) {
70     // 100 pixels requested, redirect to attributeless icon url for cacheability fun
71     header($_SERVER['SERVER_PROTOCOL'] . " 301 Moved Permanently");
72     header("Location: " . $CFG->wwwroot . '_icon/user/' . $id);
73     die();
74 }
75
76 if ($phpthumb) {
77     // let phpthumb manipulate the image
78     spit_phpthumb_image($filepath, $phpthumbconfig);
79 } elseif ($default) {
80     // no manipulation and default icon
81     if ($id == -1) {
82         header($_SERVER['SERVER_PROTOCOL'] . " 301 Moved Permanently");
83     }
84     header("Location: " . $CFG->wwwroot . '_icons/data/default.png');
85     die();
86 } else {
87     // output the image directly
88     spitfile_with_mtime_check ($filepath, $mimetype);
89 }
90
91 ?>
Note: See TracBrowser for help on using the browser.