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