corrade-http-templates – Diff between revs 2 and 11
?pathlinks?
Rev 2 | Rev 11 | |||
---|---|---|---|---|
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 | |
- | ||
10 | if(!isset($_POST['uuid'])) return; |
- | ||
11 | |
- | ||
12 | $uuid = $_POST['uuid']; |
- | ||
13 | |
9 | |
|
14 | ########################################################################### |
10 | ########################################################################### |
|
15 | ## CONFIGURATION ## |
11 | ## CONFIGURATION ## |
|
16 | ########################################################################### |
12 | ########################################################################### |
|
17 | |
- | ||
18 | # Set this to the name of the group. |
- | ||
19 | $GROUP = 'My Group'; |
13 | |
|
20 | # Set this to the group password. |
14 | require_once('config.php'); |
|
21 | $PASSWORD = 'mypassword'; |
- | ||
22 | # Set this to Corrade's HTTP Server URL. |
- | ||
23 | $URL = 'http://corrade.hostname:8080'; |
15 | require_once('functions.php'); |
|
24 | |
16 | |
|
25 | ########################################################################### |
17 | ########################################################################### |
|
26 | ## INTERNALS ## |
18 | ## INTERNALS ## |
|
27 | ########################################################################### |
19 | ########################################################################### |
|
28 | |
- | ||
29 | ########################################################################### |
- | ||
30 | ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## |
- | ||
31 | ########################################################################### |
20 | |
|
32 | function wasKeyValueGet($key, $data) { |
21 | if(!isset($_POST['uuid'])) return; |
|
33 | return array_reduce( |
- | ||
34 | explode( |
- | ||
35 | "&", |
- | ||
36 | $data |
- | ||
37 | ), |
- | ||
38 | function($o, $p) { |
- | ||
39 | $x = explode("=", $p); |
- | ||
40 | return array_shift($x) != $o ? $o : array_shift($x); |
- | ||
41 | }, |
- | ||
42 | $key |
- | ||
43 | ); |
- | ||
44 | } |
22 | $uuid = $_POST['uuid']; |
|
45 | |
23 | |
|
46 | #### |
24 | #### |
|
47 | # II. Download the map image as a PNG file. |
25 | # I. Download the map image as a PNG file. |
|
48 | $params = array( |
26 | $params = array( |
|
49 | 'command' => 'download', |
27 | 'command' => 'download', |
|
50 | 'group' => $GROUP, |
28 | 'group' => $GROUP, |
|
51 | 'password' => $PASSWORD, |
29 | 'password' => $PASSWORD, |
|
52 | 'item' => $uuid, |
30 | 'item' => $uuid, |
|
53 | 'type' => 'Texture', |
31 | 'type' => 'Texture', |
|
54 | 'format' => 'Png' |
32 | 'format' => 'Png' |
|
55 | ); |
33 | ); |
|
56 | array_walk($params, |
34 | array_walk($params, |
|
57 | function(&$value, $key) { |
35 | function(&$value, $key) { |
|
58 | $value = rawurlencode($key)."=".rawurlencode($value); |
36 | $value = rawurlencode($key)."=".rawurlencode($value); |
|
59 | } |
37 | } |
|
60 | ); |
38 | ); |
|
61 | $postvars = implode('&', $params); |
39 | $postvars = implode('&', $params); |
|
62 | if (!($curl = curl_init())) { |
40 | if (!($curl = curl_init())) { |
|
63 | print 0; |
41 | print 0; |
|
64 | return; |
42 | return; |
|
65 | } |
43 | } |
|
66 | curl_setopt($curl, CURLOPT_URL, $URL); |
44 | curl_setopt($curl, CURLOPT_URL, $URL); |
|
67 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
45 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
68 | curl_setopt($curl, CURLOPT_POST, true); |
46 | curl_setopt($curl, CURLOPT_POST, true); |
|
69 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
47 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
|
70 | $return = curl_exec($curl); |
48 | $return = curl_exec($curl); |
|
71 | curl_close($curl); |
49 | curl_close($curl); |
|
72 | |
50 | |
|
73 | $success = urldecode( |
51 | $success = urldecode( |
|
74 | wasKeyValueGet( |
52 | wasKeyValueGet( |
|
75 | "success", |
53 | "success", |
|
76 | $return |
54 | $return |
|
77 | ) |
55 | ) |
|
78 | ); |
56 | ); |
|
79 | |
57 | |
|
80 | if($success == 'False') { |
58 | if($success == 'False') { |
|
81 | echo 'Unable to download texture: '.urldecode( |
59 | echo 'Unable to download texture: '.urldecode( |
|
82 | wasKeyValueGet( |
60 | wasKeyValueGet( |
|
83 | "success", |
61 | "success", |
|
84 | $return |
62 | $return |
|
85 | ) |
63 | ) |
|
86 | ); |
64 | ); |
|
87 | die; |
65 | die; |
|
88 | } |
66 | } |
|
89 | |
67 | |
|
90 | #### |
68 | #### |
|
91 | # III. Convert the image data to a PNG of size 512x512 |
69 | # II. Convert the image data to a PNG of size 512x512 |
|
92 | $im = imagescale( |
70 | $im = imagescale( |
|
93 | imagecreatefromstring( |
71 | imagecreatefromstring( |
|
94 | base64_decode( |
72 | base64_decode( |
|
95 | rawurldecode( |
73 | rawurldecode( |
|
96 | wasKeyValueGet( |
74 | wasKeyValueGet( |
|
97 | "data", |
75 | "data", |
|
98 | $return |
76 | $return |
|
99 | ) |
77 | ) |
|
100 | ) |
78 | ) |
|
101 | ) |
79 | ) |
|
102 | ), |
80 | ), |
|
103 | 512, |
81 | 512, |
|
104 | 512 |
82 | 512 |
|
105 | ); |
83 | ); |
|
106 | |
84 | |
|
107 | #### |
85 | #### |
|
108 | # IV. Output the Base64 encoded image for AJAX. |
86 | # III. Output the Base64 encoded image for AJAX. |
|
109 | ob_start(); |
87 | ob_start(); |
|
110 | imagepng($im); |
88 | imagepng($im); |
|
111 | $png = ob_get_contents(); |
89 | $png = ob_get_contents(); |
|
112 | imagedestroy($im); |
90 | imagedestroy($im); |
|
113 | ob_end_clean(); |
91 | ob_end_clean(); |
|
114 | |
92 | |
|
115 | echo base64_encode($png); |
93 | echo base64_encode($png); |
|
116 | |
94 | |
|
117 | ?> |
95 | ?> |
|
118 | |
96 | |
|
119 | |
97 | |