root/releases/0.65/_icons/icon.php

Revision 423, 2.1 kB (checked in by sven, 2 years ago)

icons: more phpthumb fiddling
html validation fix

  • Property svn:eol-style set to native
Line 
1 <?php
2
3 // User icon serving script.
4 // Usage: http://URL/{username}/icons/{icon_id}
5
6 // Run includes
7 require_once(dirname(dirname(__FILE__))."/includes.php");
8 $textlib = textlib_get_instance();
9
10 // If an ID number for the file has been specified ...
11 $id = optional_param('id',0,PARAM_INT);
12 $default = false;
13 if (empty($id)) {
14     $default = true;
15 }
16 // ... and the file exists ...
17 if (!$file = get_record('icons','ident',$id)) {
18     $default = true;
19 }
20 // get the user who belongs to this icon..
21 if (empty($file) || !$user = get_record('users','ident',$file->owner)) {
22     $default = true;
23 }
24 if (empty($default)) {
25     $upload_folder = $textlib->substr($user->username,0,1);
26     $filepath = $CFG->dataroot . "icons/" . $upload_folder . "/" . $user->username . "/".$file->filename;
27     if (!file_exists($filepath)) {
28         $default = true;
29     }
30 }
31
32 require_once($CFG->dirroot . 'lib/filelib.php');
33 require_once($CFG->dirroot . 'lib/iconslib.php');
34     
35 if (!empty($default)) {
36     $filepath = $CFG->dirroot.'_icons/data/default.png';
37     $mimetype = 'image/png';
38 } else {
39     $mimetype = mimeinfo('type', $file->filename);
40 }
41
42
43 // Then output some appropriate headers and send the file data!
44
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);
50
51 // if size == 100, leave it.
52 $phpthumbconfig = array();
53 if (!empty($constraint1) && !empty($size1) && ($constraint1 == 'h' || $constraint1 == 'w') && $size1 != 100) {
54     $phpthumb = true;
55     $phpthumbconfig[$constraint1] = $size1;
56 }
57 if (!empty($constraint2) && !empty($size2) && ($constraint2 == 'h' || $constraint2 == 'w') && $size2 != 100) {
58     $phpthumb = true;
59     $phpthumbconfig[$constraint2] = $size2;
60 }
61
62 // user icons are public
63 header("Cache-Control: public");
64
65 if (!empty($phpthumb)) {
66     // let phpthumb manipulate the image
67     spit_phpthumb_image($filepath, $phpthumbconfig);
68 } else {
69     // output the image directly
70     spitfile_with_mtime_check ($filepath, $mimetype);
71 }
72
73 ?>
Note: See TracBrowser for help on using the browser.