| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
define("context","icons"); |
|---|
| 8 |
require_once(dirname(dirname(__FILE__))."/includes.php"); |
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
$id = optional_param('id',0,PARAM_INT); |
|---|
| 12 |
$default = false; |
|---|
| 13 |
if (!$id) { |
|---|
| 14 |
$default = true; |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
if (!$file = get_record('icons','ident',$id)) { |
|---|
| 18 |
$default = true; |
|---|
| 19 |
} |
|---|
| 20 |
|
|---|
| 21 |
if (empty($file) || !$user = get_record('users','ident',$file->owner)) { |
|---|
| 22 |
$default = true; |
|---|
| 23 |
} |
|---|
| 24 |
if (!$default) { |
|---|
| 25 |
$upload_folder = 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 ($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 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 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 |
|
|---|
| 52 |
$phpthumb = false; |
|---|
| 53 |
$phpthumbconfig = array(); |
|---|
| 54 |
if (($constraint1 == 'h' || $constraint1 == 'w') && $size1 != 100) { |
|---|
| 55 |
$phpthumb = true; |
|---|
| 56 |
$phpthumbconfig[$constraint1] = $size1; |
|---|
| 57 |
} |
|---|
| 58 |
if (($constraint2 == 'h' || $constraint2 == 'w') && $size2 != 100) { |
|---|
| 59 |
$phpthumb = true; |
|---|
| 60 |
$phpthumbconfig[$constraint2] = $size2; |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
if (function_exists('apache_setenv')) { |
|---|
| 65 |
@apache_setenv('no-gzip', '1'); |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
header("Pragma: public"); |
|---|
| 70 |
header("Cache-Control: public"); |
|---|
| 71 |
|
|---|
| 72 |
if (!$default && !$phpthumb && ($constraint1 == 'h' || $constraint1 == 'w') && (!$constraint2 || $constraint2 == 'h' || $constraint2 == 'w')) { |
|---|
| 73 |
|
|---|
| 74 |
header($_SERVER['SERVER_PROTOCOL'] . " 301 Moved Permanently"); |
|---|
| 75 |
header("Location: " . $CFG->wwwroot . '_icon/user/' . $id); |
|---|
| 76 |
die(); |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
if ($phpthumb) { |
|---|
| 80 |
|
|---|
| 81 |
spit_phpthumb_image($filepath, $phpthumbconfig); |
|---|
| 82 |
} elseif ($default) { |
|---|
| 83 |
|
|---|
| 84 |
if ($id == -1) { |
|---|
| 85 |
header($_SERVER['SERVER_PROTOCOL'] . " 301 Moved Permanently"); |
|---|
| 86 |
} |
|---|
| 87 |
header("Location: " . $CFG->wwwroot . '_icons/data/default.png'); |
|---|
| 88 |
die(); |
|---|
| 89 |
} else { |
|---|
| 90 |
|
|---|
| 91 |
spitfile_with_mtime_check ($filepath, $mimetype); |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
?> |
|---|