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

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 74 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 uses Corrade's: ## 6 ## This is a script that uses Corrade's: ##
7 ## * getregiondata ## 7 ## * getregiondata ##
8 ## * getavatarpositions ## 8 ## * getavatarpositions ##
9 ## * download ## 9 ## * download ##
10 ## commands in order to display the positions of avatars on the region. ## 10 ## commands in order to display the positions of avatars on the region. ##
11 ########################################################################### 11 ###########################################################################
12   12  
13 ########################################################################### 13 ###########################################################################
14 ## CONFIGURATION ## 14 ## CONFIGURATION ##
15 ########################################################################### 15 ###########################################################################
16   16  
17 require_once('config.php'); 17 require_once('config.php');
18 require_once('vendor/was/utilities/src/formats/kvp/kvp.php'); 18 require_once('vendor/was/utilities/src/formats/kvp/kvp.php');
19 require_once('vendor/was/utilities/src/formats/csv/csv.php'); 19 require_once('vendor/was/utilities/src/formats/csv/csv.php');
20 require_once('vendor/was/utilities/src/mathematics/algebra.php'); 20 require_once('vendor/was/utilities/src/mathematics/algebra.php');
21 require_once('vendor/was/utilities/src/lsl/lsl.php'); 21 require_once('vendor/was/utilities/src/lsl/lsl.php');
22   22  
23 ########################################################################### 23 ###########################################################################
24 ## INTERNALS ## 24 ## INTERNALS ##
25 ########################################################################### 25 ###########################################################################
26   26  
27 #### 27 ####
28 # I. Get the UUID of the map image for the current region 28 # I. Get the UUID of the map image for the current region
29 $params = array( 29 $params = array(
30 'command' => 'getgridregiondata', 30 'command' => 'getgridregiondata',
31 'group' => $GROUP, 31 'group' => $GROUP,
32 'password' => $PASSWORD, 32 'password' => $PASSWORD,
33 'data' => 'MapImageID' 33 'data' => 'MapImageID'
34 ); 34 );
35 array_walk($params, 35 array_walk($params,
36 function(&$value, $key) { 36 function(&$value, $key) {
37 $value = rawurlencode($key)."=".rawurlencode($value); 37 $value = urlencode($key)."=".urlencode($value);
38 } 38 }
39 ); 39 );
40 $postvars = implode('&', $params); 40 $postvars = implode('&', $params);
41 if (!($curl = curl_init())) { 41 if (!($curl = curl_init())) {
42 print 0; 42 print 0;
43 return; 43 return;
44 } 44 }
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 $return = curl_exec($curl); 51 $return = 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 $return 57 $return
58 ) 58 )
59 ); 59 );
60   60  
61 if($success == 'False') { 61 if($success == 'False') {
62 echo 'Unable to get the region map image.'; 62 echo 'Unable to get the region map image.';
63 die; 63 die;
64 } 64 }
65   65  
66 $mapUUID = wasCSVToArray( 66 $mapUUID = wasCSVToArray(
67 urldecode( 67 urldecode(
68 wasKeyValueGet( 68 wasKeyValueGet(
69 "data", 69 "data",
70 $return 70 $return
71 ) 71 )
72 ) 72 )
73 )[1]; 73 )[1];
74   74  
75 #### 75 ####
76 # II. Download the map image as a PNG file. 76 # II. Download the map image as a PNG file.
77 $params = array( 77 $params = array(
78 'command' => 'download', 78 'command' => 'download',
79 'group' => $GROUP, 79 'group' => $GROUP,
80 'password' => $PASSWORD, 80 'password' => $PASSWORD,
81 'item' => $mapUUID, 81 'item' => $mapUUID,
82 'type' => 'Texture', 82 'type' => 'Texture',
83 'format' => 'Png' 83 'format' => 'Png'
84 ); 84 );
85 array_walk($params, 85 array_walk($params,
86 function(&$value, $key) { 86 function(&$value, $key) {
87 $value = rawurlencode($key)."=".rawurlencode($value); 87 $value = urlencode($key)."=".urlencode($value);
88 } 88 }
89 ); 89 );
90 $postvars = implode('&', $params); 90 $postvars = implode('&', $params);
91 if (!($curl = curl_init())) { 91 if (!($curl = curl_init())) {
92 print 0; 92 print 0;
93 return; 93 return;
94 } 94 }
95 curl_setopt($curl, CURLOPT_URL, $URL); 95 curl_setopt($curl, CURLOPT_URL, $URL);
96 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 96 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
97 curl_setopt($curl, CURLOPT_POST, true); 97 curl_setopt($curl, CURLOPT_POST, true);
98 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); 98 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
99 curl_setopt($curl, CURLOPT_ENCODING, true); 99 curl_setopt($curl, CURLOPT_ENCODING, true);
100 $return = curl_exec($curl); 100 $return = curl_exec($curl);
101 curl_close($curl); 101 curl_close($curl);
102   102  
103 if($success == 'False') { 103 if($success == 'False') {
104 echo 'Unable to download the region map texture.'; 104 echo 'Unable to download the region map texture.';
105 die; 105 die;
106 } 106 }
107   107  
108   108  
109 #### 109 ####
110 # III. Convert the image data to a PNG of size 512x512 110 # III. Convert the image data to a PNG of size 512x512
111 $im = imagescale( 111 $im = imagescale(
112 imagecreatefromstring( 112 imagecreatefromstring(
113 base64_decode( 113 base64_decode(
114 urldecode( 114 urldecode(
115 wasKeyValueGet( 115 wasKeyValueGet(
116 "data", 116 "data",
117 $return 117 $return
118 ) 118 )
119 ) 119 )
120 ) 120 )
121 ), 121 ),
122 512, 122 512,
123 512 123 512
124 ); 124 );
125   125  
126 #### 126 ####
127 # IV. Get the avatar positions on the map. 127 # IV. Get the avatar positions on the map.
128 $params = array( 128 $params = array(
129 'command' => 'getavatarpositions', 129 'command' => 'getavatarpositions',
130 'group' => $GROUP, 130 'group' => $GROUP,
131 'password' => $PASSWORD, 131 'password' => $PASSWORD,
132 'entity' => 'region' 132 'entity' => 'region'
133 ); 133 );
134 array_walk($params, 134 array_walk($params,
135 function(&$value, $key) { 135 function(&$value, $key) {
136 $value = rawurlencode($key)."=".rawurlencode($value); 136 $value = urlencode($key)."=".urlencode($value);
137 } 137 }
138 ); 138 );
139 $postvars = implode('&', $params); 139 $postvars = implode('&', $params);
140 if (!($curl = curl_init())) { 140 if (!($curl = curl_init())) {
141 print 0; 141 print 0;
142 return; 142 return;
143 } 143 }
144 curl_setopt($curl, CURLOPT_URL, $URL); 144 curl_setopt($curl, CURLOPT_URL, $URL);
145 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 145 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
146 curl_setopt($curl, CURLOPT_POST, true); 146 curl_setopt($curl, CURLOPT_POST, true);
147 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); 147 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
148 curl_setopt($curl, CURLOPT_ENCODING, true); 148 curl_setopt($curl, CURLOPT_ENCODING, true);
149 $return = curl_exec($curl); 149 $return = curl_exec($curl);
150 curl_close($curl); 150 curl_close($curl);
151   151  
152 $success = urldecode( 152 $success = urldecode(
153 wasKeyValueGet( 153 wasKeyValueGet(
154 "success", 154 "success",
155 $return 155 $return
156 ) 156 )
157 ); 157 );
158   158  
159 if($success == 'False') { 159 if($success == 'False') {
160 echo 'Unable to get the avatars positions.'; 160 echo 'Unable to get the avatars positions.';
161 die; 161 die;
162 } 162 }
163   163  
164   164  
165 #### 165 ####
166 # V. Display the coordinates on the map. 166 # V. Display the coordinates on the map.
167 array_walk( 167 array_walk(
168 array_chunk( 168 array_chunk(
169 wasCSVToArray( 169 wasCSVToArray(
170 urldecode( 170 urldecode(
171 wasKeyValueGet( 171 wasKeyValueGet(
172 "data", 172 "data",
173 $return 173 $return
174 ) 174 )
175 ) 175 )
176 ), 176 ),
177 3 177 3
178 ), 178 ),
179 function(&$value, $key) use(&$im) { 179 function(&$value, $key) use(&$im) {
180 if(count($value) != 3) return; 180 if(count($value) != 3) return;
181 $components = wasLSLVectorToArray($value[2]); 181 $components = wasLSLVectorToArray($value[2]);
182 if(count($components) != 3) return; 182 if(count($components) != 3) return;
183 $x = mapValueToRange($components[0], 0, 255, 0, 512); 183 $x = mapValueToRange($components[0], 0, 255, 0, 512);
184 $y = 512 - mapValueToRange($components[1], 0, 255, 0, 512); 184 $y = 512 - mapValueToRange($components[1], 0, 255, 0, 512);
185 imagefilledellipse( 185 imagefilledellipse(
186 $im, 186 $im,
187 $x, 187 $x,
188 $y, 188 $y,
189 8, 189 8,
190 8, 190 8,
191 imagecolorallocate( 191 imagecolorallocate(
192 $im, 192 $im,
193 0, 193 0,
194 0, 194 0,
195 0 195 0
196 ) 196 )
197 ); 197 );
198 imagefilledellipse( 198 imagefilledellipse(
199 $im, 199 $im,
200 $x, 200 $x,
201 $y, 201 $y,
202 6, 202 6,
203 6, 203 6,
204 imagecolorallocate( 204 imagecolorallocate(
205 $im, 205 $im,
206 0, 206 0,
207 255, 207 255,
208 0 208 0
209 ) 209 )
210 ); 210 );
211 } 211 }
212 ); 212 );
213   213  
214 #### 214 ####
215 # VI. Output the Base64 encoded image for AJAX. 215 # VI. Output the Base64 encoded image for AJAX.
216 ob_start(); 216 ob_start();
217 imagepng($im); 217 imagepng($im);
218 $png = ob_get_contents(); 218 $png = ob_get_contents();
219 imagedestroy($im); 219 imagedestroy($im);
220 ob_end_clean(); 220 ob_end_clean();
221   221  
222 echo base64_encode($png); 222 echo base64_encode($png);
223   223  
224 ?> 224 ?>
225   225  
226   226