corrade-http-templates – Blame information for rev 15
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
15 | 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 retrieve information on an ## |
||
7 | ## inventory item by calling the "getinventorydata" Corrade command. ## |
||
8 | ########################################################################### |
||
9 | |||
10 | if(!isset($_POST['uuid']) || !isset($_POST['data'])) return; |
||
11 | |||
12 | $uuid = $_POST['uuid']; |
||
13 | $data = $_POST['data']; |
||
14 | |||
15 | ########################################################################### |
||
16 | ## CONFIGURATION ## |
||
17 | ########################################################################### |
||
18 | |||
19 | require_once('config.php'); |
||
20 | require_once('functions.php'); |
||
21 | |||
22 | ########################################################################### |
||
23 | ## INTERNALS ## |
||
24 | ########################################################################### |
||
25 | |||
26 | #### |
||
27 | # I. Resolve the inventory UUID to an asset UUID. |
||
28 | $params = array( |
||
29 | 'command' => 'getinventorydata', |
||
30 | 'group' => $GROUP, |
||
31 | 'password' => $PASSWORD, |
||
32 | 'item' => $uuid, |
||
33 | 'data' => wasArrayToCSV($data) |
||
34 | ); |
||
35 | array_walk($params, |
||
36 | function(&$value, $key) { |
||
37 | $value = rawurlencode($key)."=".rawurlencode($value); |
||
38 | } |
||
39 | ); |
||
40 | $postvars = implode('&', $params); |
||
41 | if (!($curl = curl_init())) { |
||
42 | print 0; |
||
43 | return; |
||
44 | } |
||
45 | curl_setopt($curl, CURLOPT_URL, $URL); |
||
46 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
47 | curl_setopt($curl, CURLOPT_POST, true); |
||
48 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
||
49 | curl_setopt($curl, CURLOPT_ENCODING, true); |
||
50 | $result = curl_exec($curl); |
||
51 | curl_close($curl); |
||
52 | |||
53 | $success = urldecode( |
||
54 | wasKeyValueGet( |
||
55 | "success", |
||
56 | $result |
||
57 | ) |
||
58 | ); |
||
59 | |||
60 | if($success == 'False') { |
||
61 | echo 'Unable to get inventory UUID: '.urldecode( |
||
62 | wasKeyValueGet( |
||
63 | "error", |
||
64 | $result |
||
65 | ) |
||
66 | ); |
||
67 | die; |
||
68 | } |
||
69 | |||
70 | #### |
||
71 | # II. Get the returned data and build an associative array. |
||
72 | $data = str_getcsv( |
||
73 | urldecode( |
||
74 | wasKeyValueGet( |
||
75 | "data", |
||
76 | $result |
||
77 | ) |
||
78 | ) |
||
79 | ); |
||
80 | |||
81 | $data = array_combine( |
||
82 | wasArrayStride( |
||
83 | $data, |
||
84 | 2 |
||
85 | ), |
||
86 | wasArrayStride( |
||
87 | array_slice( |
||
88 | $data, |
||
89 | 1 |
||
90 | ), |
||
91 | 2 |
||
92 | ) |
||
93 | ); |
||
94 | |||
95 | #### |
||
96 | # III. Dump the JSON for AJAX. |
||
97 | echo json_encode( |
||
98 | array( |
||
99 | $data |
||
100 | ) |
||
101 | ); |
||
102 | |||
103 | ?> |
||
104 |