corrade-http-templates – Diff between revs 6 and 76
?pathlinks?
Rev 6 | Rev 76 | |||
---|---|---|---|---|
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 uses Corrade to fetch the top scripts on a region ## |
6 | ## This is a script uses Corrade to fetch the top scripts on a region ## |
|
7 | ## and then passes that data back as a JSON object to be used with the ## |
7 | ## and then passes that data back as a JSON object to be used with the ## |
|
8 | ## DataTables JQuery extension. ## |
8 | ## DataTables JQuery extension. ## |
|
9 | ########################################################################### |
9 | ########################################################################### |
|
10 | |
10 | |
|
11 | ########################################################################### |
11 | ########################################################################### |
|
12 | ## CONFIGURATION ## |
12 | ## CONFIGURATION ## |
|
13 | ########################################################################### |
13 | ########################################################################### |
|
14 | |
14 | |
|
15 | require_once('config.php'); |
15 | require_once('config.php'); |
|
- | 16 | require_once('vendor/was/utilities/src/formats/kvp/kvp.php'); |
||
16 | require_once('functions.php'); |
17 | require_once('vendor/was/utilities/src/formats/csv/csv.php'); |
|
17 | |
18 | |
|
18 | ########################################################################### |
19 | ########################################################################### |
|
19 | ## INTERNALS ## |
20 | ## INTERNALS ## |
|
20 | ########################################################################### |
21 | ########################################################################### |
|
21 | |
22 | |
|
22 | #### |
23 | #### |
|
23 | # I. Get the top scripts. |
24 | # I. Get the top scripts. |
|
24 | $params = array( |
25 | $params = array( |
|
25 | 'command' => 'getregiontop', |
26 | 'command' => 'getregiontop', |
|
26 | 'group' => $GROUP, |
27 | 'group' => $GROUP, |
|
27 | 'password' => $PASSWORD, |
28 | 'password' => $PASSWORD, |
|
28 | 'type' => 'scripts' |
29 | 'type' => 'scripts' |
|
29 | ); |
30 | ); |
|
30 | array_walk($params, |
31 | array_walk($params, |
|
31 | function(&$value, $key) { |
32 | function(&$value, $key) { |
|
32 | $value = rawurlencode($key)."=".rawurlencode($value); |
33 | $value = rawurlencode($key)."=".rawurlencode($value); |
|
33 | } |
34 | } |
|
34 | ); |
35 | ); |
|
35 | $postvars = implode('&', $params); |
36 | $postvars = implode('&', $params); |
|
36 | if (!($curl = curl_init())) { |
37 | if (!($curl = curl_init())) { |
|
37 | print 0; |
38 | print 0; |
|
38 | return; |
39 | return; |
|
39 | } |
40 | } |
|
40 | curl_setopt($curl, CURLOPT_URL, $URL); |
41 | curl_setopt($curl, CURLOPT_URL, $URL); |
|
41 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
42 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
42 | curl_setopt($curl, CURLOPT_POST, true); |
43 | curl_setopt($curl, CURLOPT_POST, true); |
|
43 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
44 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
|
44 | curl_setopt($curl, CURLOPT_ENCODING, true); |
45 | curl_setopt($curl, CURLOPT_ENCODING, true); |
|
45 | $return = curl_exec($curl); |
46 | $return = curl_exec($curl); |
|
46 | curl_close($curl); |
47 | curl_close($curl); |
|
47 | |
48 | |
|
48 | #### |
49 | #### |
|
49 | # II. Check for success. |
50 | # II. Check for success. |
|
50 | $success = urldecode( |
51 | $success = urldecode( |
|
51 | wasKeyValueGet( |
52 | wasKeyValueGet( |
|
52 | "success", |
53 | "success", |
|
53 | $return |
54 | $return |
|
54 | ) |
55 | ) |
|
55 | ); |
56 | ); |
|
56 | if($success == 'False') { |
57 | if($success == 'False') { |
|
57 | echo 'Unable to query the top scripts.'; |
58 | echo 'Unable to query the top scripts: ' |
|
- | 59 | .urldecode( |
||
- | 60 | wasKeyValueGet( |
||
- | 61 | "error", |
||
- | 62 | $return |
||
- | 63 | ) |
||
- | 64 | ); |
||
58 | die; |
65 | die; |
|
59 | } |
66 | } |
|
60 | |
67 | |
|
61 | #### |
68 | #### |
|
62 | # III. Dump JSON for DataTables. |
69 | # III. Dump JSON for DataTables. |
|
63 | echo json_encode( |
70 | echo json_encode( |
|
64 | array( |
71 | array( |
|
65 | "data" => |
72 | "data" => |
|
66 | array_chunk( |
73 | array_chunk( |
|
67 | wasCSVToArray( |
74 | wasCSVToArray( |
|
68 | urldecode( |
75 | urldecode( |
|
69 | wasKeyValueGet( |
76 | wasKeyValueGet( |
|
70 | "data", |
77 | "data", |
|
71 | $return |
78 | $return |
|
72 | ) |
79 | ) |
|
73 | ) |
80 | ) |
|
74 | ), |
81 | ), |
|
75 | 5 # We split the CSV in 5: score, task name, UUID, Owner and Position |
82 | 5 # We split the CSV in 5: score, task name, UUID, Owner and Position |
|
76 | ) |
83 | ) |
|
77 | ) |
84 | ) |
|
78 | ); |
85 | ); |
|
79 | |
86 | |
|
80 | ?> |
87 | ?> |
|
81 | |
88 | |
|
82 | |
89 | |
|
83 | |
90 | |