corrade-http-templates – Diff between revs 72 and 82

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