| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
require_once(dirname(dirname(__FILE__))."/includes.php"); |
|---|
| 8 |
$textlib = textlib_get_instance(); |
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
$id = optional_param('id',0,PARAM_INT); |
|---|
| 12 |
$default = false; |
|---|
| 13 |
if (empty($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 (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 |
if (!empty($default)) { |
|---|
| 33 |
$filepath = path.'_icons/data/default.png'; |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
$tstamp = filemtime($filepath); |
|---|
| 37 |
$lm = gmdate("D, d M Y H:i:s", $tstamp) . " GMT"; |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
if (array_key_exists('HTTP_IF_MODIFIED_SINCE',$_SERVER)) { |
|---|
| 41 |
$if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']); |
|---|
| 42 |
if ($if_modified_since == $lm) { |
|---|
| 43 |
header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified"); |
|---|
| 44 |
exit; |
|---|
| 45 |
} |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
if ($tstamp < time()) { |
|---|
| 50 |
header("Last-Modified: " . $lm); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
require_once($CFG->dirroot.'lib/filelib.php'); |
|---|
| 55 |
$mimetype = mimeinfo('type',$file->filename); |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
$constraint1 = strtolower(optional_param('constraint1')); |
|---|
| 59 |
$size1 = optional_param('size1'); |
|---|
| 60 |
$constraint2 = strtolower(optional_param('constraint2')); |
|---|
| 61 |
$size2 = optional_param('size2'); |
|---|
| 62 |
|
|---|
| 63 |
$url = $CFG->wwwroot.'units/phpthumb/phpThumb.php?src='.urlencode($filepath); |
|---|
| 64 |
|
|---|
| 65 |
if (!empty($constraint1) && !empty($size1) && ($constraint1 == 'h' || $constraint1 = 'w') && $size1 != 100) { |
|---|
| 66 |
$url .= '&'.$constraint1.'='.$size1; |
|---|
| 67 |
$phpthumb = true; |
|---|
| 68 |
} |
|---|
| 69 |
if (!empty($constraint2) && !empty($size2) && ($constraint2 == 'h' || $constraint2 = 'w') && $size2 != 100) { |
|---|
| 70 |
$url .= '&'.$constraint2.'='.$size2; |
|---|
| 71 |
$phpthumb = true; |
|---|
| 72 |
} |
|---|
| 73 |
if (!empty($phpthumb)) { |
|---|
| 74 |
header("Location: $url"); |
|---|
| 75 |
exit; |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
header("Cache-Control: private"); |
|---|
| 80 |
|
|---|
| 81 |
header("Content-type: $mimetype"); |
|---|
| 82 |
readfile($filepath); |
|---|
| 83 |
|
|---|
| 84 |
?> |
|---|