corrade-http-templates – Diff between revs 15 and 72
?pathlinks?
Rev 15 | Rev 72 | |||
---|---|---|---|---|
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 notecard using ## |
6 | ## This is a script that can be used to download a notecard using ## |
|
7 | ## Corrade and the "download" Corrde command. ## |
7 | ## Corrade and the "download" Corrde command. ## |
|
8 | ########################################################################### |
8 | ########################################################################### |
|
9 | |
9 | |
|
10 | if(!isset($_POST['uuid'])) return; |
10 | if(!isset($_POST['uuid'])) return; |
|
11 | |
11 | |
|
12 | $uuid = $_POST['uuid']; |
12 | $uuid = $_POST['uuid']; |
|
13 | |
13 | |
|
14 | ########################################################################### |
14 | ########################################################################### |
|
15 | ## CONFIGURATION ## |
15 | ## CONFIGURATION ## |
|
16 | ########################################################################### |
16 | ########################################################################### |
|
17 | |
17 | |
|
18 | require_once('config.php'); |
18 | require_once('config.php'); |
|
19 | require_once('functions.php'); |
19 | require_once('vendor/was/utilities/src/formats/kvp/kvp.php'); |
|
20 | |
20 | |
|
21 | ########################################################################### |
21 | ########################################################################### |
|
22 | ## INTERNALS ## |
22 | ## INTERNALS ## |
|
23 | ########################################################################### |
23 | ########################################################################### |
|
24 | |
24 | |
|
25 | #### |
25 | #### |
|
26 | # I. Download the notecard. |
26 | # I. Download the notecard. |
|
27 | $params = array( |
27 | $params = array( |
|
28 | 'command' => 'download', |
28 | 'command' => 'download', |
|
29 | 'group' => $GROUP, |
29 | 'group' => $GROUP, |
|
30 | 'password' => $PASSWORD, |
30 | 'password' => $PASSWORD, |
|
31 | 'item' => $uuid, |
31 | 'item' => $uuid, |
|
32 | 'type' => 'Notecard' |
32 | 'type' => 'Notecard' |
|
33 | ); |
33 | ); |
|
34 | array_walk($params, |
34 | array_walk($params, |
|
35 | function(&$value, $key) { |
35 | function(&$value, $key) { |
|
36 | $value = rawurlencode($key)."=".rawurlencode($value); |
36 | $value = rawurlencode($key)."=".rawurlencode($value); |
|
37 | } |
37 | } |
|
38 | ); |
38 | ); |
|
39 | $postvars = implode('&', $params); |
39 | $postvars = implode('&', $params); |
|
40 | if (!($curl = curl_init())) { |
40 | if (!($curl = curl_init())) { |
|
41 | print 0; |
41 | print 0; |
|
42 | return; |
42 | return; |
|
43 | } |
43 | } |
|
44 | curl_setopt($curl, CURLOPT_URL, $URL); |
44 | curl_setopt($curl, CURLOPT_URL, $URL); |
|
45 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
45 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
46 | curl_setopt($curl, CURLOPT_POST, true); |
46 | curl_setopt($curl, CURLOPT_POST, true); |
|
47 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
47 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
|
48 | curl_setopt($curl, CURLOPT_ENCODING, true); |
48 | curl_setopt($curl, CURLOPT_ENCODING, true); |
|
49 | $result = curl_exec($curl); |
49 | $result = curl_exec($curl); |
|
50 | curl_close($curl); |
50 | curl_close($curl); |
|
51 | |
51 | |
|
52 | $success = urldecode( |
52 | $success = urldecode( |
|
53 | wasKeyValueGet( |
53 | wasKeyValueGet( |
|
54 | "success", |
54 | "success", |
|
55 | $result |
55 | $result |
|
56 | ) |
56 | ) |
|
57 | ); |
57 | ); |
|
58 | |
58 | |
|
59 | if($success == 'False') { |
59 | if($success == 'False') { |
|
60 | echo 'Unable to download notecard: '.urldecode( |
60 | echo 'Unable to download notecard: '.urldecode( |
|
61 | wasKeyValueGet( |
61 | wasKeyValueGet( |
|
62 | "error", |
62 | "error", |
|
63 | $result |
63 | $result |
|
64 | ) |
64 | ) |
|
65 | ); |
65 | ); |
|
66 | die; |
66 | die; |
|
67 | } |
67 | } |
|
68 | |
68 | |
|
69 | #### |
69 | #### |
|
70 | # II. Return the contents of the notecard. |
70 | # II. Return the contents of the notecard. |
|
71 | echo urldecode( |
71 | echo urldecode( |
|
72 | wasKeyValueGet( |
72 | wasKeyValueGet( |
|
73 | "data", |
73 | "data", |
|
74 | $result |
74 | $result |
|
75 | ) |
75 | ) |
|
76 | ); |
76 | ); |
|
77 | |
77 | |
|
78 | ?> |
78 | ?> |
|
79 | |
79 | |
|
80 | |
80 | |