aboutsummaryrefslogtreecommitdiff
path: root/thumbnail.php
blob: 113262960742a82634862eaaa5cd680f70074105 (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
56
57
<?php

	/**
	 * Tidypics Thumbnail
	 * 
	 */

	include_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
	
	// Get file GUID
	$file_guid = (int) get_input('file_guid');
	
	// Get file thumbnail size
	$size = get_input('size');
	// only 3 possibilities
	if ($size != 'small' && $size != 'thumb') {
		$size = 'large';
	}
	error_log('size is ' . $size);
	
	// Get file entity
	$file = get_entity($file_guid);
	if (!$file)
		forward('mod/tidypics/graphics/img_error.jpg');
	
	if ($file->getSubtype() != "image")
		forward('mod/tidypics/graphics/img_error.jpg');
	
	// Get filename
	if ($size == "thumb") {
		$thumbfile = $file->thumbnail;
	} else if ($size == "small") {
		$thumbfile = $file->smallthumb;
	} else {
		$thumbfile = $file->largethumb;
	}
	error_log('filename is ' . $thumbfile);
	
	if (!$thumbfile)
		forward('mod/tidypics/graphics/img_error.jpg');
	
	// create Elgg File object
	$readfile = new ElggFile();
	$readfile->owner_guid = $file->owner_guid;
	$readfile->setFilename($thumbfile);
	$contents = $readfile->grabFile();

	// send error image if file could not be read
	if (!$contents) {
		forward('mod/tidypics/graphics/img_error.jpg');
	}

	// Return the thumbnail and exit
	header("Content-type: image");
	echo $contents;
	exit;
?>