corrade-http-templates – Blame information for rev 12
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
2 | eva | 1 | <?php |
2 | |||
3 | ########################################################################### |
||
4 | ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## |
||
5 | ########################################################################### |
||
6 | ## This is a script that uses Corrade's HTTP server to get the UUID of ## |
||
7 | ## the current region map, then downloads the map as a PNG which then ## |
||
8 | ## gets encoded to a Base64 string and echoed from this script. ## |
||
9 | ########################################################################### |
||
10 | |||
11 | ########################################################################### |
||
12 | ## CONFIGURATION ## |
||
13 | ########################################################################### |
||
14 | |||
12 | eva | 15 | # The configuration file for this script containing the settings. |
16 | require_once('config.php'); |
||
17 | require_once('functions.php'); |
||
2 | eva | 18 | |
19 | ########################################################################### |
||
20 | ## INTERNALS ## |
||
21 | ########################################################################### |
||
22 | |||
23 | #### |
||
24 | # I. Get the UUID of the map image for the current region |
||
25 | $params = array( |
||
26 | 'command' => 'getgridregiondata', |
||
27 | 'group' => $GROUP, |
||
28 | 'password' => $PASSWORD, |
||
29 | 'data' => 'MapImageID' |
||
30 | ); |
||
31 | array_walk($params, |
||
32 | function(&$value, $key) { |
||
33 | $value = urlencode($key)."=".urlencode($value); |
||
34 | } |
||
35 | ); |
||
36 | $postvars = implode('&', $params); |
||
37 | if (!($curl = curl_init())) { |
||
38 | print 0; |
||
39 | return; |
||
40 | } |
||
41 | |||
42 | curl_setopt($curl, CURLOPT_URL, $URL); |
||
43 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
44 | curl_setopt($curl, CURLOPT_POST, true); |
||
45 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
||
46 | $return = curl_exec($curl); |
||
47 | curl_close($curl); |
||
48 | |||
49 | $success = urldecode( |
||
50 | wasKeyValueGet( |
||
51 | "success", |
||
52 | $return |
||
53 | ) |
||
54 | ); |
||
55 | |||
56 | // Unable to retrieve the map image? |
||
57 | if($success == 'False') return -1; |
||
58 | |||
59 | $mapUUID = wasCSVToArray( |
||
60 | urldecode( |
||
61 | wasKeyValueGet( |
||
62 | "data", |
||
63 | $return |
||
64 | ) |
||
65 | ) |
||
66 | )[1]; |
||
67 | |||
68 | #### |
||
69 | # II. Download the map image as a PNG file. |
||
70 | $params = array( |
||
71 | 'command' => 'download', |
||
72 | 'group' => $GROUP, |
||
73 | 'password' => $PASSWORD, |
||
74 | 'item' => $mapUUID, |
||
75 | 'type' => 'Texture', |
||
76 | 'format' => 'Png' |
||
77 | ); |
||
78 | array_walk($params, |
||
79 | function(&$value, $key) { |
||
80 | $value = rawurlencode($key)."=".rawurlencode($value); |
||
81 | } |
||
82 | ); |
||
83 | $postvars = implode('&', $params); |
||
84 | if (!($curl = curl_init())) { |
||
85 | print 0; |
||
86 | return; |
||
87 | } |
||
88 | curl_setopt($curl, CURLOPT_URL, $URL); |
||
89 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
90 | curl_setopt($curl, CURLOPT_POST, true); |
||
91 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
||
92 | $return = curl_exec($curl); |
||
93 | curl_close($curl); |
||
94 | |||
95 | $success = urldecode( |
||
96 | wasKeyValueGet( |
||
97 | "success", |
||
98 | $return |
||
99 | ) |
||
100 | ); |
||
101 | |||
102 | // Unable to download the region map texture? |
||
103 | if($success == 'False') return -1; |
||
104 | |||
105 | #### |
||
106 | # III. Convert the image data to a PNG of size 512x512 |
||
107 | $im = imagescale( |
||
108 | imagecreatefromstring( |
||
109 | base64_decode( |
||
110 | rawurldecode( |
||
111 | wasKeyValueGet( |
||
112 | "data", |
||
113 | $return |
||
114 | ) |
||
115 | ) |
||
116 | ) |
||
117 | ), |
||
118 | 512, |
||
119 | 512 |
||
120 | ); |
||
121 | |||
122 | #### |
||
123 | # VI. Output the Base64 encoded image for AJAX. |
||
124 | ob_start(); |
||
125 | imagepng($im); |
||
126 | $png = ob_get_contents(); |
||
127 | imagedestroy($im); |
||
128 | ob_end_clean(); |
||
129 | |||
130 | echo base64_encode($png); |
||
131 | |||
132 | ?> |
||
133 |