1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Elgg profile icon cache/bypass |
4
|
|
|
* |
5
|
|
|
* |
6
|
|
|
* @package ElggProfile |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
// won't be able to serve anything if no joindate or guid |
10
|
|
|
if (!isset($_GET['joindate']) || !isset($_GET['guid'])) { |
11
|
|
|
header("HTTP/1.1 404 Not Found"); |
12
|
|
|
exit; |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
$join_date = (int)$_GET['joindate']; |
16
|
|
|
$last_cache = empty($_GET['lastcache']) ? 0 : (int)$_GET['lastcache']; // icontime |
17
|
|
|
$guid = (int)$_GET['guid']; |
18
|
|
|
|
19
|
|
|
// If is the same ETag, content didn't changed. |
20
|
|
|
$etag = $last_cache . $guid; |
21
|
|
View Code Duplication |
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"$etag\"") { |
22
|
|
|
header("HTTP/1.1 304 Not Modified"); |
23
|
|
|
exit; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$base_dir = dirname(dirname(dirname(__FILE__))); |
27
|
|
|
|
28
|
|
|
// Get DB settings |
29
|
|
|
require_once $base_dir . '/engine/settings.php'; |
30
|
|
|
require_once $base_dir . '/vendor/autoload.php'; |
31
|
|
|
|
32
|
|
|
global $CONFIG; |
33
|
|
|
|
34
|
|
|
$size = "medium"; |
35
|
|
|
if (!empty($_GET['size'])) { |
36
|
|
|
$size = strtolower($_GET['size']); |
37
|
|
View Code Duplication |
if (!in_array($size, array('large', 'medium', 'small', 'tiny', 'master', 'topbar'))) { |
38
|
|
|
$size = "medium"; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$path = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR; |
43
|
|
|
|
44
|
|
|
$data_root = call_user_func(function () use ($CONFIG) { |
45
|
|
|
if (isset($CONFIG->dataroot)) { |
46
|
|
|
return rtrim($CONFIG->dataroot, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// must get from DB |
50
|
|
|
$conf = new \Elgg\Database\Config($CONFIG); |
51
|
|
|
$db = new \Elgg\Database($conf, new \Elgg\Logger(new \Elgg\PluginHooksService())); |
52
|
|
|
|
53
|
|
|
try { |
54
|
|
|
$row = $db->getDataRow(" |
55
|
|
|
SELECT `value` |
56
|
|
|
FROM {$db->getTablePrefix()}datalists |
57
|
|
|
WHERE `name` = 'dataroot' |
58
|
|
|
"); |
59
|
|
|
if (!$row) { |
|
|
|
|
60
|
|
|
return ""; |
61
|
|
|
} |
62
|
|
|
} catch (\DatabaseException $e) { |
63
|
|
|
// we're going to let the engine figure out what's happening... |
64
|
|
|
return ''; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return rtrim($row->value, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
68
|
|
|
}); |
69
|
|
|
|
70
|
|
|
if ($data_root) { |
71
|
|
|
$locator = new \Elgg\EntityDirLocator($guid); |
72
|
|
|
$user_path = $data_root . $locator->getPath(); |
73
|
|
|
|
74
|
|
|
$filename = $user_path . "profile/{$guid}{$size}.jpg"; |
75
|
|
|
$filesize = @filesize($filename); |
76
|
|
|
|
77
|
|
|
if ($filesize) { |
78
|
|
|
header("Content-type: image/jpeg"); |
79
|
|
|
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+6 months")), true); |
80
|
|
|
header("Pragma: public"); |
81
|
|
|
header("Cache-Control: public"); |
82
|
|
|
header("Content-Length: $filesize"); |
83
|
|
|
header("ETag: \"$etag\""); |
84
|
|
|
readfile($filename); |
85
|
|
|
exit; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
// something went wrong so load engine and try to forward to default icon |
90
|
|
|
require_once $base_dir . "/engine/start.php"; |
91
|
|
|
elgg_log("Profile icon direct failed.", "WARNING"); |
92
|
|
|
//GCchange - Troy T. Lawson - appears that size is not being set prior to this call |
93
|
|
|
//so i set it manually. This is part of the cometchat fix. Does not appear to cause problems anywhere else |
94
|
|
|
$size = "tiny"; |
95
|
|
|
forward("_graphics/icons/user/default{$size}.gif"); |
96
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.