forked from kevinjardine/videolist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
thumbnail.php
55 lines (46 loc) · 1.35 KB
/
thumbnail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
* Elgg file thumbnail
*
* @package ElggFile
*/
// Get engine
require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
// Get videolist item GUID
$guid = (int) get_input('guid', 0);
// Get file thumbnail size
$size = get_input('size', 'small');
$item = get_entity($guid);
if (!elgg_instanceof($item, 'object', 'videolist_item')) {
exit;
}
$readfile = new ElggFile();
$readfile->owner_guid = $item->owner_guid;
$readfile->setFilename("videolist/{$item->guid}.jpg");
if ($readfile->exists()) {
$contents = $readfile->grabFile();
$content_length = strlen($contents);
header("Content-type: image/jpeg");
// cache image for 10 days
header('Expires: ' . date('r', time() + 864000));
header("Pragma: public", true);
header("Cache-Control: public", true);
} else {
// icon was deleted
// stop using this script to fetch thumb
$ignore_access = elgg_set_ignore_access(true);
$item->deleteMetadata('thumbnail');
elgg_set_ignore_access($ignore_access);
if (in_array($size, array('tiny', 'medium', 'small'))) {
$filename = elgg_get_plugins_path() . "videolist/graphics/videolist_icon_$size.png";
$contents = file_get_contents($filename);
$content_length = strlen($contents);
header("Content-type: image/jpeg");
} else {
header('Status: 404 Not Found');
exit;
}
}
header("Content-Length: $content_length");
echo $contents;
exit;