forked from andig/videodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
img.php
106 lines (90 loc) · 2.88 KB
/
img.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* Image loader
*
* Loads an image from the net and creates a chachefile for it.
*
* @package videoDB
* @author Andreas Gohr <[email protected]>
* @version $Id: img.php,v 2.29 2013/03/10 16:24:32 andig2 Exp $
*/
require_once './core/functions.php';
require_once './core/httpclient.php';
/*
* Note:
*
* We don't clear overage thumbnails. Instead,
* the table entries will be replaced when an image is finally available
*/
// since we don't need session functionality, use this as workaround
// for php bug #22526 session_start/popen hang
session_write_close();
/**
* amazon workaround for 1 pixel transparent images
*/
function checkAmazonSmallImage($url, $ext, $file)
{
if (preg_match('/^(.+)L(Z{7,}.+)$/', $url, $m))
{
if (list($width, $height, $type, $attr) = getimagesize($file)) {
if ($width <= 1) {
$smallurl = $m[1].'M'.$m[2];
if (cache_file_exists($smallurl, $cache_file, CACHE_IMG, $ext) ||
download($smallurl, $cache_file)) {
copy($cache_file, $file);
}
}
}
}
}
// default - no url given or no image
$file = img();
// Get imgurl for the actor
if ($name)
{
require_once './engines/engines.php';
// name given
$name = html_entity_decode($name);
$result = engineActor($name, $actorid, engineGetActorEngine($actorid));
if (!empty($result)) {
$url = $result[0][1];
}
if (preg_match('/nohs(-[f|m])?.gif$/', $url)) {
// imdb no-image picture
$url = '';
}
// write actor last checked record
// NOTE: this is only called if the template preparation has determined the actor record needs checking
{
// write only if HTTP lookup physically successful
$SQL = 'REPLACE '.TBL_ACTORS." (name, imgurl, actorid, checked)
VALUES ('".addslashes($name)."', '".addslashes($url)."', '".addslashes($actorid)."', NOW())";
runSQL($SQL);
}
}
// Get cached image for the given url
if (preg_match('/\.(jpe?g|gif|png)$/i', $url, $matches))
{
// calculate cache filename if we're not looking into the cache again- otherwise this is done by cache_file_exists
// $file is further needed for downloading the file
// This is only effective if function is enabled in getThumbnail function
# if ($cache_ignore) $file = cache_get_filename($url, CACHE_IMG, $matches[1]));
// does the cache file exist?
if (cache_file_exists($url, $targetfile, CACHE_IMG, $matches[1])) {
// amazon workaround for 1 pixel transparent images
checkAmazonSmallImage($url, $matches[1], $targetfile);
}
// try to download and make sure it's really an image
else {
download($url, $targetfile);
}
// double-check this is really an image
if (@exif_imagetype($targetfile)) {
// success- the result is an actual image
$file = $targetfile;
}
}
// fix url for redirect
$file = preg_replace('/img\.php$/', $file, $_SERVER['PHP_SELF']);
header('Location: '.$file);
?>