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