corrade-http-templates – Blame information for rev 82

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