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

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