1 | <?php |
---|
2 | if (!$sig_name = $_GET['s']) |
---|
3 | { |
---|
4 | $sig_name = 'default'; |
---|
5 | } |
---|
6 | $sig_name = str_replace('.', '', $sig_name); |
---|
7 | $sig_name = str_replace('/', '', $sig_name); |
---|
8 | |
---|
9 | function errorPic($string) |
---|
10 | { |
---|
11 | $im = imagecreate(200, 60); |
---|
12 | $black = imagecolorallocate($im, 0, 0, 0); |
---|
13 | $red = imagecolorallocate($im, 250, 200, 20); |
---|
14 | imagefill($im, 1, 1, $black); |
---|
15 | imagestring($im, 3, 10, 10, 'Error: '.$string, $red); |
---|
16 | header('Content-Type: image/jpeg'); |
---|
17 | imagejpeg($im); |
---|
18 | exit; |
---|
19 | } |
---|
20 | |
---|
21 | if (!$plt_id = intval($_GET['i'])) |
---|
22 | { |
---|
23 | errorPic('No pilot id specified.'); |
---|
24 | } |
---|
25 | require_once("common/includes/class.pilot.php"); |
---|
26 | require_once("common/includes/class.corp.php"); |
---|
27 | require_once("common/includes/class.alliance.php"); |
---|
28 | require_once("common/includes/class.killlist.php"); |
---|
29 | |
---|
30 | $pilot = new Pilot($plt_id); |
---|
31 | if (!$pilot->exists()) |
---|
32 | { |
---|
33 | errorPic('That pilot doesnt exist.'); |
---|
34 | } |
---|
35 | $pilot->getPortraitURL(128); |
---|
36 | $corp = $pilot->getCorp(); |
---|
37 | $alliance = $corp->getAlliance(); |
---|
38 | |
---|
39 | // we dont generate pictures for non-member |
---|
40 | if (ALLIANCE_ID && $alliance->getID() != ALLIANCE_ID) |
---|
41 | { |
---|
42 | errorPic('Wrong alliance.'); |
---|
43 | } |
---|
44 | elseif (CORP_ID && $corp->getID() != CORP_ID) |
---|
45 | { |
---|
46 | errorPic('Wrong corporation.'); |
---|
47 | } |
---|
48 | |
---|
49 | $id = abs(crc32($sig_name)); |
---|
50 | // check for cached version |
---|
51 | if (file_exists('cache/data/sig_'.$id.'_'.$plt_id)) |
---|
52 | { |
---|
53 | $age = filemtime('cache/data/sig_'.$id.'_'.$plt_id); |
---|
54 | |
---|
55 | // cache files for 30 minutes |
---|
56 | if (time() - $age < 30*60) |
---|
57 | { |
---|
58 | if (file_exists('mods/signature_generator/signatures/'.$sig_name.'/typ.png')) |
---|
59 | { |
---|
60 | header('Content-Type: image/png'); |
---|
61 | } |
---|
62 | else |
---|
63 | { |
---|
64 | header('Content-Type: image/jpeg'); |
---|
65 | } |
---|
66 | readfile('cache/data/sig_'.$id.'_'.$plt_id); |
---|
67 | return; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | $pid = $pilot->getExternalID(); |
---|
72 | if (file_exists('cache/portraits/'.$pid.'_256.jpg')) |
---|
73 | { |
---|
74 | touch('cache/portraits/'.$pid.'_256.jpg'); |
---|
75 | } |
---|
76 | else |
---|
77 | { |
---|
78 | // in case of a dead eve server we only want to wait 5 seconds |
---|
79 | @ini_set('default_socket_timeout', 5); |
---|
80 | $file = @file_get_contents('http://img.eve.is/serv.asp?s=256&c='.$pid); |
---|
81 | if ($img = @imagecreatefromstring($file)) |
---|
82 | { |
---|
83 | $fp = fopen('cache/portraits/'.$pid.'_256.jpg', 'w'); |
---|
84 | fwrite($fp, $file); |
---|
85 | fclose($fp); |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | // try alternative access via fsockopen |
---|
90 | // happens if allow_url_fopen wrapper is false |
---|
91 | require_once('class.http.php'); |
---|
92 | |
---|
93 | $url = 'http://img.eve.is/serv.asp?s=256&c='.$pid; |
---|
94 | $http = new http_request($url); |
---|
95 | $file = $http->get_content(); |
---|
96 | |
---|
97 | if ($img = @imagecreatefromstring($file)) |
---|
98 | { |
---|
99 | $fp = fopen('cache/portraits/'.$id.'_256.jpg', 'w'); |
---|
100 | fwrite($fp, $file); |
---|
101 | } |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | // check template |
---|
107 | if (!is_dir('mods/signature_generator/signatures/'.$sig_name)) |
---|
108 | { |
---|
109 | errorPic('Template not found.'); |
---|
110 | } |
---|
111 | |
---|
112 | // let the template do the work, we just output $im |
---|
113 | require('mods/signature_generator/signatures/'.$sig_name.'/'.$sig_name.'.php'); |
---|
114 | |
---|
115 | if (file_exists('mods/signature_generator/signatures/'.$sig_name.'/typ.png')) |
---|
116 | { |
---|
117 | header('Content-Type: image/png'); |
---|
118 | imagepng($im, 'cache/data/sig_'.$id.'_'.$plt_id); |
---|
119 | } |
---|
120 | else |
---|
121 | { |
---|
122 | header('Content-Type: image/jpeg'); |
---|
123 | imagejpeg($im, 'cache/data/sig_'.$id.'_'.$plt_id, 90); |
---|
124 | } |
---|
125 | readfile('cache/data/sig_'.$id.'_'.$plt_id); |
---|
126 | ?> |
---|