corrade-http-templates – Blame information for rev 18
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
15 | eva | 1 | <?php |
2 | |||
3 | ########################################################################### |
||
4 | ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## |
||
5 | ########################################################################### |
||
6 | ## This is a script that can be used to download a texture using Corrade ## |
||
7 | ## and the "download" Corrde command. ## |
||
8 | ########################################################################### |
||
9 | |||
10 | if(!isset($_POST['uuid'])) return; |
||
11 | |||
12 | $uuid = $_POST['uuid']; |
||
13 | |||
14 | ########################################################################### |
||
15 | ## CONFIGURATION ## |
||
16 | ########################################################################### |
||
17 | |||
18 | require_once('config.php'); |
||
19 | require_once('functions.php'); |
||
20 | |||
21 | ########################################################################### |
||
22 | ## INTERNALS ## |
||
23 | ########################################################################### |
||
24 | |||
25 | |||
26 | #### |
||
27 | # I. Resolve the inventory UUID to an asset UUID. |
||
28 | $params = array( |
||
29 | 'command' => 'getinventorydata', |
||
30 | 'group' => $GROUP, |
||
31 | 'password' => $PASSWORD, |
||
32 | 'item' => $uuid, |
||
33 | 'data' => 'AssetUUID' |
||
34 | ); |
||
35 | array_walk($params, |
||
36 | function(&$value, $key) { |
||
37 | $value = rawurlencode($key)."=".rawurlencode($value); |
||
38 | } |
||
39 | ); |
||
40 | $postvars = implode('&', $params); |
||
41 | if (!($curl = curl_init())) { |
||
42 | print 0; |
||
43 | return; |
||
44 | } |
||
45 | curl_setopt($curl, CURLOPT_URL, $URL); |
||
46 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
47 | curl_setopt($curl, CURLOPT_POST, true); |
||
48 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
||
49 | curl_setopt($curl, CURLOPT_ENCODING, true); |
||
50 | $result = curl_exec($curl); |
||
51 | curl_close($curl); |
||
52 | |||
53 | $success = urldecode( |
||
54 | wasKeyValueGet( |
||
55 | "success", |
||
56 | $result |
||
57 | ) |
||
58 | ); |
||
59 | |||
60 | if($success == 'False') { |
||
61 | echo 'Unable to get inventory UUID: '.urldecode( |
||
62 | wasKeyValueGet( |
||
63 | "error", |
||
64 | $result |
||
65 | ) |
||
66 | ); |
||
67 | die; |
||
68 | } |
||
69 | |||
70 | $data = str_getcsv( |
||
71 | urldecode( |
||
72 | wasKeyValueGet( |
||
73 | "data", |
||
74 | $result |
||
75 | ) |
||
76 | ) |
||
77 | ); |
||
78 | |||
79 | $data = array_combine( |
||
80 | wasArrayStride( |
||
81 | $data, |
||
82 | 2 |
||
83 | ), |
||
84 | wasArrayStride( |
||
85 | array_slice( |
||
86 | $data, |
||
87 | 1 |
||
88 | ), |
||
89 | 2 |
||
90 | ) |
||
91 | ); |
||
92 | |||
93 | if(!trim($data['AssetUUID'])) { |
||
94 | echo 'Could not retrieve asset UUID'; |
||
95 | die; |
||
96 | } |
||
97 | |||
98 | #### |
||
99 | # II. Download the image as a PNG file. |
||
100 | $params = array( |
||
101 | 'command' => 'download', |
||
102 | 'group' => $GROUP, |
||
103 | 'password' => $PASSWORD, |
||
104 | 'item' => $data['AssetUUID'], |
||
105 | 'type' => 'Texture', |
||
106 | 'format' => 'Png' |
||
107 | ); |
||
108 | array_walk($params, |
||
109 | function(&$value, $key) { |
||
110 | $value = rawurlencode($key)."=".rawurlencode($value); |
||
111 | } |
||
112 | ); |
||
113 | $postvars = implode('&', $params); |
||
114 | if (!($curl = curl_init())) { |
||
115 | print 0; |
||
116 | return; |
||
117 | } |
||
118 | curl_setopt($curl, CURLOPT_URL, $URL); |
||
119 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
120 | curl_setopt($curl, CURLOPT_POST, true); |
||
121 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
||
122 | curl_setopt($curl, CURLOPT_ENCODING, true); |
||
123 | $result = curl_exec($curl); |
||
124 | curl_close($curl); |
||
125 | |||
126 | $success = urldecode( |
||
127 | wasKeyValueGet( |
||
128 | "success", |
||
129 | $result |
||
130 | ) |
||
131 | ); |
||
132 | |||
133 | if($success == 'False') { |
||
134 | echo 'Unable to download texture: '.urldecode( |
||
135 | wasKeyValueGet( |
||
136 | "error", |
||
137 | $result |
||
138 | ) |
||
139 | ); |
||
140 | die; |
||
141 | } |
||
142 | |||
143 | #### |
||
144 | # III. Convert the image data to a PNG of size 512x512 |
||
145 | $im = imagescale( |
||
146 | imagecreatefromstring( |
||
147 | base64_decode( |
||
148 | rawurldecode( |
||
149 | wasKeyValueGet( |
||
150 | "data", |
||
151 | $result |
||
152 | ) |
||
153 | ) |
||
154 | ) |
||
155 | ), |
||
156 | 512, |
||
157 | 512 |
||
158 | ); |
||
159 | |||
160 | #### |
||
161 | # IV. Output the Base64 encoded image for AJAX. |
||
162 | ob_start(); |
||
163 | imagepng($im); |
||
164 | $png = ob_get_contents(); |
||
165 | imagedestroy($im); |
||
166 | ob_end_clean(); |
||
167 | |||
168 | echo base64_encode($png); |
||
169 | |||
170 | ?> |
||
171 |