aboutsummaryrefslogtreecommitdiff
path: root/mod/lightbox/thumbnail.php
blob: aa6675f2165f0b72316e9590c60a39a4e8fdba90 (plain)
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 image thumbnail
 *
 * @package ElggLightbox
 */

// Get engine
require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");

// Get entity GUID
$guid = (int) get_input('guid', 0);

// Get thumbnail size
$size = get_input('size', 'small');

// Get image or album cover
$entity = new LightboxPluginImage($guid);
if (!$entity->guid) {
	exit;
}


// Get entity thumbnail
switch ($size) {
	case "small":
		$thumb = $entity->thumbnail;
		break;
	case "medium":
		$thumb = $entity->smallthumb;
		break;
	case "large":
	default:
		$thumb = $entity->largethumb;
		break;
}

// Grab the file
if ($thumb && !empty($thumb)) {
	$readfile = new ElggFile();
	$readfile->owner_guid = $entity->owner_guid;
	$readfile->setFilename($thumb);
	$mime = $entity->getMimeType();
	$contents = $readfile->grabFile();

	// caching images for 10 days
	header("Content-type: $mime");
	header('Expires: ' . date('r',time() + 864000));
	header("Pragma: public", true);
	header("Cache-Control: public", true);
	header("Content-Length: " . strlen($contents));

	echo $contents;
	exit;
}